titan-agent 7.0.0 → 7.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +54 -2
- package/dist/agent/agent.js +55 -10
- package/dist/agent/agent.js.map +1 -1
- package/dist/agent/contextManager.js +1 -1
- package/dist/agent/contextManager.js.map +1 -1
- package/dist/agent/honestyGuard.js +66 -0
- package/dist/agent/honestyGuard.js.map +1 -0
- package/dist/agent/selfCritique.js +101 -0
- package/dist/agent/selfCritique.js.map +1 -0
- package/dist/agent/toolSearch.js +9 -2
- package/dist/agent/toolSearch.js.map +1 -1
- package/dist/agent/trajectoryLogger.js +19 -2
- package/dist/agent/trajectoryLogger.js.map +1 -1
- package/dist/analytics/collector.js +1 -1
- package/dist/analytics/collector.js.map +1 -1
- package/dist/config/schema.js +32 -0
- package/dist/config/schema.js.map +1 -1
- package/dist/eval/harness.js +4 -1
- package/dist/eval/harness.js.map +1 -1
- package/dist/gateway/server.js +24 -8
- package/dist/gateway/server.js.map +1 -1
- package/dist/gateway/slashCommands.js +31 -0
- package/dist/gateway/slashCommands.js.map +1 -1
- package/dist/mcp/agentTools.js +135 -0
- package/dist/mcp/agentTools.js.map +1 -0
- package/dist/mcp/server.js +19 -2
- package/dist/mcp/server.js.map +1 -1
- package/dist/memory/graph.js +2 -0
- package/dist/memory/graph.js.map +1 -1
- package/dist/providers/errorTaxonomy.js +4 -0
- package/dist/providers/errorTaxonomy.js.map +1 -1
- package/dist/providers/moa.js +151 -0
- package/dist/providers/moa.js.map +1 -0
- package/dist/providers/modelCapabilities.js +65 -2
- package/dist/providers/modelCapabilities.js.map +1 -1
- package/dist/providers/ollama.js +1 -0
- package/dist/providers/ollama.js.map +1 -1
- package/dist/providers/openai_compat.js +14 -2
- package/dist/providers/openai_compat.js.map +1 -1
- package/dist/providers/router.js +3 -1
- package/dist/providers/router.js.map +1 -1
- package/dist/utils/benchMode.js +8 -0
- package/dist/utils/benchMode.js.map +1 -0
- package/dist/utils/constants.js +1 -1
- package/dist/utils/constants.js.map +1 -1
- package/package.json +26 -26
- package/ui/dist/assets/AboutYouMemory-57X5SqHQ.js +1 -0
- package/ui/dist/assets/AuditPanel-AyB8ciLZ.js +1 -0
- package/ui/dist/assets/AutonomyPanel-wmVPr-n3.js +1 -0
- package/ui/dist/assets/AutopilotPanel-CbLy4lJP.js +1 -0
- package/ui/dist/assets/AutoresearchPanel-DxRO1rBF.js +1 -0
- package/ui/dist/assets/BackupPanel-BUh9rQ-3.js +1 -0
- package/ui/dist/assets/BrowserPanel-OqKwGrIL.js +1 -0
- package/ui/dist/assets/CPActivity-DGfS7EY3.js +1 -0
- package/ui/dist/assets/CPAgentDetail-p0Kvzhhb.js +1 -0
- package/ui/dist/assets/CPAgents-B6wSSQZM.js +1 -0
- package/ui/dist/assets/CPApprovals-CYv9Do0i.js +1 -0
- package/ui/dist/assets/CPCosts-Dx6Q71rN.js +1 -0
- package/ui/dist/assets/CPDashboard-DA8-tE-l.js +1 -0
- package/ui/dist/assets/CPFiles-BJ49tzai.js +1 -0
- package/ui/dist/assets/CPGoals-h0dKL5V_.js +1 -0
- package/ui/dist/assets/CPInbox-CDvefgNH.js +1 -0
- package/ui/dist/assets/CPIssueDetail-CnmLzzDD.js +1 -0
- package/ui/dist/assets/CPIssues-DknAIMyl.js +1 -0
- package/ui/dist/assets/CPLayout-C2nqgkmY.js +2 -0
- package/ui/dist/assets/CPOrg-tDbHFphX.js +1 -0
- package/ui/dist/assets/CPRuns-UlrIURqG.js +1 -0
- package/ui/dist/assets/CPSocial-B-gHgvEw.js +1 -0
- package/ui/dist/assets/CPVoice-CJy938ZF.js +1 -0
- package/ui/dist/assets/ChannelsPanel-DLbxg1zO.js +1 -0
- package/ui/dist/assets/CheckpointsPanel-BB6TT0aE.js +1 -0
- package/ui/dist/assets/CommandPostHub-fIslwU_t.js +2 -0
- package/ui/dist/assets/ConfirmDialog-6hcNjmAh.js +9 -0
- package/ui/dist/assets/CronPanel-DLpw3Y25.js +1 -0
- package/ui/dist/assets/DataTable-KVqtDzvP.js +1 -0
- package/ui/dist/assets/DreamPanel-lcMXpbEb.js +5 -0
- package/ui/dist/assets/EmptyState-D-Dg8B8r.js +1 -0
- package/ui/dist/assets/EvalHarnessPanel-BKzRiiQw.js +2 -0
- package/ui/dist/assets/EvalPanel-Dtodacmj.js +1 -0
- package/ui/dist/assets/FileViewer-DjcVKkO2.js +60 -0
- package/ui/dist/assets/FilesPanel-BI90Pplh.js +1 -0
- package/ui/dist/assets/FleetPanel-tr0wjAwr.js +1 -0
- package/ui/dist/assets/HomelabPanel-m8vMm5rE.js +1 -0
- package/ui/dist/assets/InfraView-3WriJnyE.js +2 -0
- package/ui/dist/assets/IntegrationsPanel-BmL70fOw.js +1 -0
- package/ui/dist/assets/IntelligenceView-BGVxCKD3.js +2 -0
- package/ui/dist/assets/LearningPanel-CrYLQ6eV.js +1 -0
- package/ui/dist/assets/LiveStudio-CnW3eZYF.js +2 -0
- package/ui/dist/assets/LogsPanel-DbShr4Ic.js +1 -0
- package/ui/dist/assets/McpPanel-uMYEsPI4.js +1 -0
- package/ui/dist/assets/MemoryGraphPanel-C7-Z8f0v.js +1 -0
- package/ui/dist/assets/MemoryTaxonomyPanel-KrxN8U1G.js +1 -0
- package/ui/dist/assets/MemoryWikiPanel-DI3q6IHC.js +1 -0
- package/ui/dist/assets/MeshPanel-D4-g2tlu.js +1 -0
- package/ui/dist/assets/MissionCanvas-D8cjakJe.js +61 -0
- package/ui/dist/assets/MissionChat-BvqCUf1E.js +3 -0
- package/ui/dist/assets/MissionLibrary-CZoJQ9WD.js +1 -0
- package/ui/dist/assets/MissionStart-CXCq-_AD.js +1 -0
- package/ui/dist/assets/NvidiaPanel-BfI1K5Pg.js +1 -0
- package/ui/dist/assets/OrganismPanel-B7Gm9pP-.js +1 -0
- package/ui/dist/assets/OverviewPanel-B9tKWRK2.js +1 -0
- package/ui/dist/assets/PageHeader-CH85uoZG.js +1 -0
- package/ui/dist/assets/PersonaProfilesPanel-BPi8fl-U.js +3 -0
- package/ui/dist/assets/PersonasPanel-Dwr7sycT.js +1 -0
- package/ui/dist/assets/PhoneDeskPanel-D7qc6wUI.js +1 -0
- package/ui/dist/assets/RecipesPanel-DcqPWRSU.js +1 -0
- package/ui/dist/assets/SecurityPanel-Bv_B9Ahf.js +1 -0
- package/ui/dist/assets/SelfImprovePanel-Ca4rGwEG.js +1 -0
- package/ui/dist/assets/SelfProposalsPanel-DteMSASq.js +1 -0
- package/ui/dist/assets/SessionsPanel-BdbbKTbL.js +1 -0
- package/ui/dist/assets/SessionsTab-BJipiVJs.js +1 -0
- package/ui/dist/assets/SettingsPanel-mV7ykOCc.js +1 -0
- package/ui/dist/assets/SettingsView-Bu_wYTT5.js +2 -0
- package/ui/dist/assets/SkeletonLoader-9H7QWa9E.js +1 -0
- package/ui/dist/assets/SkillsPanel-CHwX2kDR.js +1 -0
- package/ui/dist/assets/SomaView-Bpsm4ZW7.js +5 -0
- package/ui/dist/assets/SomaView-Dghh9om4.css +1 -0
- package/ui/dist/assets/StatCard-wmSgMAM3.js +1 -0
- package/ui/dist/assets/TeamsPanel-XJiHxdDX.js +1 -0
- package/ui/dist/assets/TelemetryPanel-_pmGVxpO.js +1 -0
- package/ui/dist/assets/TitanCanvas-Cb7KG80W.css +1 -0
- package/ui/dist/assets/TitanCanvas-CmLy7p2N.js +883 -0
- package/ui/dist/assets/ToolsView-PHizHZBx.js +2 -0
- package/ui/dist/assets/TraceViewer-CYAzIcfB.js +1 -0
- package/ui/dist/assets/TracesPanel-CRSN_dzK.js +1 -0
- package/ui/dist/assets/TrainingPanel-B9rcuMsV.js +1 -0
- package/ui/dist/assets/VoiceOverlay-BL_ns1ZA.js +7 -0
- package/ui/dist/assets/VramPanel-BNPQ06_9.js +1 -0
- package/ui/dist/assets/WatchView-BgAkNnur.js +13 -0
- package/ui/dist/assets/WorkTab-RRpPpEOg.js +1 -0
- package/ui/dist/assets/WorkflowBuilderPanel-BPHIH8pf.js +1 -0
- package/ui/dist/assets/WorkflowsPanel-DqtmT0NB.js +1 -0
- package/ui/dist/assets/approvalHeadline-BRg3ReTi.js +1 -0
- package/ui/dist/assets/archive-DcK9HrbE.js +1 -0
- package/ui/dist/assets/arrow-left-4c2FnES1.js +1 -0
- package/ui/dist/assets/book-open-Ds_yciQm.js +1 -0
- package/ui/dist/assets/bot-CWDCc265.js +1 -0
- package/ui/dist/assets/chart-column-hhZMdCgB.js +1 -0
- package/ui/dist/assets/chevron-right-A_pvnRh_.js +1 -0
- package/ui/dist/assets/circle-check-big-C-JUM7wb.js +1 -0
- package/ui/dist/assets/circle-stop-yZuG9ZAE.js +1 -0
- package/ui/dist/assets/clipboard-list-C2HUEjZc.js +1 -0
- package/ui/dist/assets/clock-DSPgndSD.js +1 -0
- package/ui/dist/assets/clsx-CjueKrWZ.js +1 -0
- package/ui/dist/assets/createLucideIcon-qnlrxww7.js +1 -0
- package/ui/dist/assets/database-C1SgHa8T.js +1 -0
- package/ui/dist/assets/dollar-sign-D9siqK91.js +1 -0
- package/ui/dist/assets/download-CJZWQNfV.js +1 -0
- package/ui/dist/assets/external-link-CpQLWKKE.js +1 -0
- package/ui/dist/assets/file-text-BbGTi-Po.js +1 -0
- package/ui/dist/assets/flask-conical-B1YVft4E.js +1 -0
- package/ui/dist/assets/folder-EbR-w2Mq.js +1 -0
- package/ui/dist/assets/funnel-D2Dkn8Pf.js +1 -0
- package/ui/dist/assets/git-branch-CQ2yNSzU.js +1 -0
- package/ui/dist/assets/git-pull-request-BxL5wlGX.js +1 -0
- package/ui/dist/assets/index-Cz8190xO.css +2 -0
- package/ui/dist/assets/index-WI-E4I3h.js +243 -0
- package/ui/dist/assets/jsx-runtime-B15e6lOy.js +1 -0
- package/ui/dist/assets/layers-BPu5SRjI.js +1 -0
- package/ui/dist/assets/legacy-BIzifT-t.js +3 -0
- package/ui/dist/assets/lightbulb-BY7CpMte.js +1 -0
- package/ui/dist/assets/link-VDQkrGJw.js +1 -0
- package/ui/dist/assets/list-todo-DfnNUV_T.js +1 -0
- package/ui/dist/assets/message-square-BpzrINHz.js +1 -0
- package/ui/dist/assets/mic-De6oZFaV.js +1 -0
- package/ui/dist/assets/missions-y-qg_f9b.js +1 -0
- package/ui/dist/assets/network-CM7y1ats.js +1 -0
- package/ui/dist/assets/pause-C4TDJSfA.js +1 -0
- package/ui/dist/assets/pencil-Dd_vzHE-.js +1 -0
- package/ui/dist/assets/play-9WxZWVHA.js +1 -0
- package/ui/dist/assets/plug-Dm25Wbrc.js +1 -0
- package/ui/dist/assets/plus-CHryCIkk.js +1 -0
- package/ui/dist/assets/radio-D-XnoAVu.js +1 -0
- package/ui/dist/assets/refresh-cw-Disd5wRB.js +1 -0
- package/ui/dist/assets/rotate-ccw-Cw1T2W1T.js +1 -0
- package/ui/dist/assets/save-DP7oNar2.js +1 -0
- package/ui/dist/assets/search-aNVcX-nv.js +1 -0
- package/ui/dist/assets/send-D7iQD57b.js +1 -0
- package/ui/dist/assets/server-DFfeYjoM.js +1 -0
- package/ui/dist/assets/settings-5NWXzgyY.js +1 -0
- package/ui/dist/assets/shared-DLz_Jtg3.js +1 -0
- package/ui/dist/assets/shield-check-Cd50jCAn.js +1 -0
- package/ui/dist/assets/square-DlcoJ1ZM.js +1 -0
- package/ui/dist/assets/terminal-DgFz2Vsf.js +1 -0
- package/ui/dist/assets/test-tube-BimtS92_.js +1 -0
- package/ui/dist/assets/toggle-right-BMaR-sfT.js +1 -0
- package/ui/dist/assets/trash-2-CwUv7ww1.js +1 -0
- package/ui/dist/assets/trending-up-Ba9TwEow.js +1 -0
- package/ui/dist/assets/trophy-Gfv1QC45.js +1 -0
- package/ui/dist/assets/volume-2-BVlfVl2U.js +1 -0
- package/ui/dist/assets/wifi-off-CWLeusSV.js +1 -0
- package/ui/dist/assets/zoom-out-DeggJ7RM.js +1 -0
- package/ui/dist/index.html +4 -2
- package/ui/dist/sw.js +1 -1
- package/ui/dist/assets/AboutYouMemory-CZKEOd_O.js +0 -11
- package/ui/dist/assets/AuditPanel-Bu71N5Er.js +0 -1
- package/ui/dist/assets/AutonomyPanel-DB-39dX4.js +0 -11
- package/ui/dist/assets/AutopilotPanel-Cj8oKxWv.js +0 -1
- package/ui/dist/assets/AutoresearchPanel-3s8pjm6Z.js +0 -6
- package/ui/dist/assets/BackupPanel-EUQJMJE7.js +0 -1
- package/ui/dist/assets/BrowserPanel-Beo4F5Ar.js +0 -6
- package/ui/dist/assets/Button-MdXmb4_n.js +0 -1
- package/ui/dist/assets/CPActivity-B1Se9VVc.js +0 -1
- package/ui/dist/assets/CPAgentDetail-BYji6tT8.js +0 -1
- package/ui/dist/assets/CPAgents-BSUKucTe.js +0 -1
- package/ui/dist/assets/CPApprovals-B4v0em6e.js +0 -1
- package/ui/dist/assets/CPCosts-9ikh61Kv.js +0 -1
- package/ui/dist/assets/CPDashboard-sOok2T5v.js +0 -1
- package/ui/dist/assets/CPFiles-DB2nY5JE.js +0 -1
- package/ui/dist/assets/CPGoals-8Z1yOY8e.js +0 -1
- package/ui/dist/assets/CPInbox-Cq6-UY8F.js +0 -11
- package/ui/dist/assets/CPIssueDetail-NAGfmJg8.js +0 -1
- package/ui/dist/assets/CPIssues-BzX6Rckx.js +0 -1
- package/ui/dist/assets/CPLayout-BcRM6QSg.js +0 -2
- package/ui/dist/assets/CPOrg-B7DQ4UQP.js +0 -1
- package/ui/dist/assets/CPRuns-D-cpPw_M.js +0 -1
- package/ui/dist/assets/CPSocial-DshtmcK0.js +0 -11
- package/ui/dist/assets/CPVoice-DfXRnQVU.js +0 -1
- package/ui/dist/assets/ChannelsPanel-BnaTOeyf.js +0 -1
- package/ui/dist/assets/CheckpointsPanel-C62naE4U.js +0 -1
- package/ui/dist/assets/CommandPostHub-B_L1CAss.js +0 -24
- package/ui/dist/assets/ConfirmDialog-VErHWAbo.js +0 -1
- package/ui/dist/assets/CronPanel-BwMrrZ5d.js +0 -1
- package/ui/dist/assets/DataTable-BCqSUuN7.js +0 -1
- package/ui/dist/assets/DreamPanel-BNAcCLBB.js +0 -15
- package/ui/dist/assets/EmptyState-D9kQf1PX.js +0 -1
- package/ui/dist/assets/EvalHarnessPanel-BaMLdBNm.js +0 -2
- package/ui/dist/assets/EvalPanel-CW-SSjtg.js +0 -1
- package/ui/dist/assets/FileViewer-BL00nsd7.js +0 -61
- package/ui/dist/assets/FilesPanel-CeC6YUSd.js +0 -16
- package/ui/dist/assets/FleetPanel-EyWF7l3W.js +0 -1
- package/ui/dist/assets/HomelabPanel-BRfKRYe7.js +0 -6
- package/ui/dist/assets/InfraView-Jmqhg_Yc.js +0 -2
- package/ui/dist/assets/InlineEditableField-DgMrLDj1.js +0 -1
- package/ui/dist/assets/Input-CBTwa_Iw.js +0 -1
- package/ui/dist/assets/IntegrationsPanel-DQL-7Ec6.js +0 -1
- package/ui/dist/assets/IntelligenceView-DxD78qfP.js +0 -2
- package/ui/dist/assets/LearningPanel-C_JzSbJU.js +0 -1
- package/ui/dist/assets/LiveStudio-Db5yeaWo.js +0 -7
- package/ui/dist/assets/LogsPanel-CpinKwaZ.js +0 -1
- package/ui/dist/assets/McpPanel-D-MqN_f-.js +0 -1
- package/ui/dist/assets/MemoryGraphPanel-BnD5jRqf.js +0 -1
- package/ui/dist/assets/MemoryTaxonomyPanel-BBI202dd.js +0 -6
- package/ui/dist/assets/MemoryWikiPanel-Dn3XZHL0.js +0 -6
- package/ui/dist/assets/MeshPanel-C-mRJpr0.js +0 -11
- package/ui/dist/assets/MissionCanvas-CbZW83Ch.js +0 -72
- package/ui/dist/assets/MissionChat-Bs75jPAD.js +0 -7
- package/ui/dist/assets/MissionLibrary-BxQ6SxPe.js +0 -5
- package/ui/dist/assets/MissionStart-CBuBPasl.js +0 -1
- package/ui/dist/assets/Modal-ybPGvlQs.js +0 -9
- package/ui/dist/assets/NvidiaPanel-DdG13OX4.js +0 -1
- package/ui/dist/assets/OrganismPanel-xZWUJKyr.js +0 -1
- package/ui/dist/assets/OverviewPanel-B45ZYhJV.js +0 -1
- package/ui/dist/assets/PageHeader-DdrbS1aq.js +0 -1
- package/ui/dist/assets/PersonaProfilesPanel-CKER-EU5.js +0 -8
- package/ui/dist/assets/PersonasPanel-CMMQ3nh3.js +0 -1
- package/ui/dist/assets/PhoneDeskPanel-Bw_Y-cVE.js +0 -11
- package/ui/dist/assets/RecipesPanel-DzMcxpJJ.js +0 -1
- package/ui/dist/assets/SecurityPanel-BCq3Fzbr.js +0 -1
- package/ui/dist/assets/SelfImprovePanel-YE3hT8jK.js +0 -1
- package/ui/dist/assets/SelfProposalsPanel-DXuqBM6p.js +0 -1
- package/ui/dist/assets/SessionsPanel-DORz5goR.js +0 -1
- package/ui/dist/assets/SessionsTab-qYHDOuC8.js +0 -1
- package/ui/dist/assets/SettingsPanel-BbwPu1i7.js +0 -1
- package/ui/dist/assets/SettingsView-zgqkDDBJ.js +0 -2
- package/ui/dist/assets/SkeletonLoader-r6OGXaU9.js +0 -1
- package/ui/dist/assets/SkillsPanel-BjEOBMRo.js +0 -11
- package/ui/dist/assets/SomaView-BtCkeWfZ.css +0 -1
- package/ui/dist/assets/SomaView-DLzApZVW.js +0 -5
- package/ui/dist/assets/StatCard-DLq8aBps.js +0 -1
- package/ui/dist/assets/StatusBadge-BqlvIbdj.js +0 -1
- package/ui/dist/assets/Tabs-DdUThlp1.js +0 -1
- package/ui/dist/assets/TeamsPanel-uIIKoU7I.js +0 -1
- package/ui/dist/assets/TelemetryPanel-dVr3yQQr.js +0 -1
- package/ui/dist/assets/TitanCanvas-BfitWg9R.css +0 -1
- package/ui/dist/assets/TitanCanvas-xHAJqwG2.js +0 -945
- package/ui/dist/assets/ToolsView-CG1mZdiy.js +0 -2
- package/ui/dist/assets/Tooltip-C2tXJcrN.js +0 -6
- package/ui/dist/assets/TraceViewer-BIMD_Osr.js +0 -1
- package/ui/dist/assets/TracesPanel-nMUiyMj5.js +0 -1
- package/ui/dist/assets/TrainingPanel-CT5R4HWm.js +0 -1
- package/ui/dist/assets/VoiceOverlay-Br4QnCtw.js +0 -17
- package/ui/dist/assets/VramPanel-CdnJYytg.js +0 -1
- package/ui/dist/assets/WatchView-TNU6Ns1Q.js +0 -13
- package/ui/dist/assets/WorkTab-wTlX_UKP.js +0 -1
- package/ui/dist/assets/WorkflowBuilderPanel-CDpVt5ux.js +0 -6
- package/ui/dist/assets/WorkflowsPanel-zsFqsLdn.js +0 -11
- package/ui/dist/assets/approvalHeadline-DB9SgR-9.js +0 -1
- package/ui/dist/assets/archive-Bh689DNg.js +0 -6
- package/ui/dist/assets/arrow-left-WkVYLm80.js +0 -6
- package/ui/dist/assets/book-open-ohEXgUsS.js +0 -6
- package/ui/dist/assets/bot-DvEcyQcD.js +0 -6
- package/ui/dist/assets/chart-column-w3goFd5f.js +0 -6
- package/ui/dist/assets/check-CuRYh4Zh.js +0 -6
- package/ui/dist/assets/chevron-right-DbLSHmff.js +0 -6
- package/ui/dist/assets/circle-check-big-Bkba568b.js +0 -6
- package/ui/dist/assets/circle-stop-Bx2ohEg8.js +0 -6
- package/ui/dist/assets/clipboard-list-Dj9tORnu.js +0 -6
- package/ui/dist/assets/clock-JyQAYy6X.js +0 -6
- package/ui/dist/assets/clsx-B-dksMZM.js +0 -1
- package/ui/dist/assets/dollar-sign-XxwPAA2a.js +0 -6
- package/ui/dist/assets/download-D1izVEOL.js +0 -6
- package/ui/dist/assets/external-link-DZ_rZsIt.js +0 -6
- package/ui/dist/assets/file-text-Cfawu8Bs.js +0 -6
- package/ui/dist/assets/flask-conical-Ql8QxhgY.js +0 -6
- package/ui/dist/assets/folder-DAdIw-Pb.js +0 -6
- package/ui/dist/assets/funnel-FycfZcXo.js +0 -6
- package/ui/dist/assets/git-branch-C2qrhGGu.js +0 -6
- package/ui/dist/assets/index-Cml2x9pA.js +0 -507
- package/ui/dist/assets/index-yWybhcfI.css +0 -1
- package/ui/dist/assets/layers-yzjtGlHB.js +0 -6
- package/ui/dist/assets/legacy-D21WSMF1.js +0 -3
- package/ui/dist/assets/lightbulb-BZJNK69S.js +0 -6
- package/ui/dist/assets/link-CnFkBkaY.js +0 -6
- package/ui/dist/assets/list-todo-BlgfQHup.js +0 -6
- package/ui/dist/assets/message-square-CRsG9u6_.js +0 -6
- package/ui/dist/assets/mic-B32RHc7Y.js +0 -6
- package/ui/dist/assets/missions-1iw8Z2_0.js +0 -1
- package/ui/dist/assets/network-C9RXQGrV.js +0 -6
- package/ui/dist/assets/pause-BT1Bc2q3.js +0 -6
- package/ui/dist/assets/pencil-BK5IU6o0.js +0 -6
- package/ui/dist/assets/play-Cl1nC_gc.js +0 -6
- package/ui/dist/assets/plug-DvcpOalj.js +0 -6
- package/ui/dist/assets/plus-Dpo1qfrl.js +0 -6
- package/ui/dist/assets/radio-C5c9IyqX.js +0 -6
- package/ui/dist/assets/refresh-cw-C-iZkzuS.js +0 -6
- package/ui/dist/assets/rotate-ccw-qzrB3SNw.js +0 -6
- package/ui/dist/assets/save-DwR9wQVu.js +0 -6
- package/ui/dist/assets/search-D10l0m3-.js +0 -6
- package/ui/dist/assets/send-DtXGsaFW.js +0 -6
- package/ui/dist/assets/server-BzisF3LL.js +0 -6
- package/ui/dist/assets/settings-Dbwd1_-c.js +0 -6
- package/ui/dist/assets/shield-check-CXlDJyAW.js +0 -6
- package/ui/dist/assets/square-BBC-JKzY.js +0 -11
- package/ui/dist/assets/terminal-DaBIlWEM.js +0 -6
- package/ui/dist/assets/test-tube-CDATRD5t.js +0 -11
- package/ui/dist/assets/toggle-right-DTmrC5RD.js +0 -11
- package/ui/dist/assets/trash-2-CTeyjxD_.js +0 -6
- package/ui/dist/assets/trending-up-CXPRjRV4.js +0 -6
- package/ui/dist/assets/trophy-DbVdXRtU.js +0 -6
- package/ui/dist/assets/volume-2-DYDBmm3M.js +0 -6
- package/ui/dist/assets/wifi-off-BBuIGbiP.js +0 -6
- package/ui/dist/assets/zoom-out-D47_pRAO.js +0 -16
|
@@ -0,0 +1,883 @@
|
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/SomaView-Bpsm4ZW7.js","assets/jsx-runtime-B15e6lOy.js","assets/shared-DLz_Jtg3.js","assets/createLucideIcon-qnlrxww7.js","assets/pencil-Dd_vzHE-.js","assets/index-WI-E4I3h.js","assets/index-Cz8190xO.css","assets/clsx-CjueKrWZ.js","assets/PageHeader-CH85uoZG.js","assets/chevron-right-A_pvnRh_.js","assets/ConfirmDialog-6hcNjmAh.js","assets/EmptyState-D-Dg8B8r.js","assets/SkeletonLoader-9H7QWa9E.js","assets/DataTable-KVqtDzvP.js","assets/StatCard-wmSgMAM3.js","assets/SomaView-Dghh9om4.css","assets/CommandPostHub-fIslwU_t.js","assets/bot-CWDCc265.js","assets/chart-column-hhZMdCgB.js","assets/circle-stop-yZuG9ZAE.js","assets/clock-DSPgndSD.js","assets/dollar-sign-D9siqK91.js","assets/file-text-BbGTi-Po.js","assets/git-branch-CQ2yNSzU.js","assets/message-square-BpzrINHz.js","assets/pause-C4TDJSfA.js","assets/plus-CHryCIkk.js","assets/refresh-cw-Disd5wRB.js","assets/send-D7iQD57b.js","assets/terminal-DgFz2Vsf.js","assets/trash-2-CwUv7ww1.js","assets/approvalHeadline-BRg3ReTi.js","assets/IntelligenceView-BGVxCKD3.js","assets/MemoryGraphPanel-C7-Z8f0v.js","assets/zoom-out-DeggJ7RM.js","assets/network-CM7y1ats.js","assets/search-aNVcX-nv.js","assets/InfraView-3WriJnyE.js","assets/ToolsView-PHizHZBx.js","assets/SettingsView-Bu_wYTT5.js","assets/SettingsPanel-mV7ykOCc.js","assets/circle-check-big-C-JUM7wb.js","assets/download-CJZWQNfV.js","assets/mic-De6oZFaV.js","assets/play-9WxZWVHA.js","assets/save-DP7oNar2.js","assets/wifi-off-CWLeusSV.js","assets/SecurityPanel-Bv_B9Ahf.js","assets/shield-check-Cd50jCAn.js","assets/AuditPanel-AyB8ciLZ.js","assets/clipboard-list-C2HUEjZc.js","assets/funnel-D2Dkn8Pf.js","assets/AutopilotPanel-CbLy4lJP.js","assets/WorkflowsPanel-DqtmT0NB.js","assets/book-open-Ds_yciQm.js","assets/toggle-right-BMaR-sfT.js","assets/LearningPanel-CrYLQ6eV.js","assets/database-C1SgHa8T.js","assets/lightbulb-BY7CpMte.js","assets/trending-up-Ba9TwEow.js","assets/SelfImprovePanel-Ca4rGwEG.js","assets/radio-D-XnoAVu.js","assets/settings-5NWXzgyY.js","assets/trophy-Gfv1QC45.js","assets/PersonasPanel-Dwr7sycT.js","assets/PersonaProfilesPanel-BPi8fl-U.js","assets/volume-2-BVlfVl2U.js","assets/DreamPanel-lcMXpbEb.js","assets/HomelabPanel-m8vMm5rE.js","assets/server-DFfeYjoM.js","assets/NvidiaPanel-BfI1K5Pg.js","assets/external-link-CpQLWKKE.js","assets/FilesPanel-BI90Pplh.js","assets/arrow-left-4c2FnES1.js","assets/LogsPanel-DbShr4Ic.js","assets/TelemetryPanel-_pmGVxpO.js","assets/SkillsPanel-CHwX2kDR.js","assets/McpPanel-uMYEsPI4.js","assets/plug-Dm25Wbrc.js","assets/test-tube-BimtS92_.js","assets/IntegrationsPanel-BmL70fOw.js","assets/ChannelsPanel-DLbxg1zO.js","assets/MeshPanel-D4-g2tlu.js","assets/MemoryWikiPanel-DI3q6IHC.js","assets/link-VDQkrGJw.js","assets/AutoresearchPanel-DxRO1rBF.js","assets/flask-conical-B1YVft4E.js","assets/SelfProposalsPanel-DteMSASq.js","assets/git-pull-request-BxL5wlGX.js","assets/OverviewPanel-B9tKWRK2.js","assets/layers-BPu5SRjI.js","assets/SessionsPanel-BdbbKTbL.js","assets/WatchView-BgAkNnur.js","assets/BackupPanel-BUh9rQ-3.js","assets/archive-DcK9HrbE.js","assets/TrainingPanel-B9rcuMsV.js","assets/RecipesPanel-DcqPWRSU.js","assets/VramPanel-BNPQ06_9.js","assets/TeamsPanel-XJiHxdDX.js","assets/CronPanel-DLpw3Y25.js","assets/CheckpointsPanel-BB6TT0aE.js","assets/OrganismPanel-B7Gm9pP-.js","assets/FleetPanel-tr0wjAwr.js","assets/BrowserPanel-OqKwGrIL.js","assets/EvalPanel-Dtodacmj.js","assets/legacy-BIzifT-t.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{c as e,n as t,o as n,r,t as i}from"./jsx-runtime-B15e6lOy.js";import{t as a}from"./createLucideIcon-qnlrxww7.js";import{t as o}from"./archive-DcK9HrbE.js";import{t as s}from"./book-open-Ds_yciQm.js";import{t as c}from"./bot-CWDCc265.js";import{t as l}from"./chart-column-hhZMdCgB.js";import{n as u,t as d}from"./pencil-Dd_vzHE-.js";import{t as f}from"./chevron-right-A_pvnRh_.js";import{n as p,t as m}from"./square-DlcoJ1ZM.js";import{t as h}from"./clock-DSPgndSD.js";import{t as g}from"./database-C1SgHa8T.js";import{t as _}from"./external-link-CpQLWKKE.js";import{t as v}from"./file-text-BbGTi-Po.js";import{t as y}from"./flask-conical-B1YVft4E.js";import{t as b}from"./folder-EbR-w2Mq.js";import{t as x}from"./git-pull-request-BxL5wlGX.js";import{t as ee}from"./link-VDQkrGJw.js";import{n as te,r as S,t as ne}from"./zoom-out-DeggJ7RM.js";import{t as re}from"./message-square-BpzrINHz.js";import{t as C}from"./VoiceOverlay-BL_ns1ZA.js";import{t as w}from"./mic-De6oZFaV.js";import{t as ie}from"./network-CM7y1ats.js";import{t as T}from"./plus-CHryCIkk.js";import{n as ae,t as E}from"./test-tube-BimtS92_.js";import{t as oe}from"./radio-D-XnoAVu.js";import{t as D}from"./refresh-cw-Disd5wRB.js";import{t as O}from"./rotate-ccw-Cw1T2W1T.js";import{t as k}from"./save-DP7oNar2.js";import{t as se}from"./search-aNVcX-nv.js";import{t as ce}from"./send-D7iQD57b.js";import{t as le}from"./server-DFfeYjoM.js";import{t as ue}from"./settings-5NWXzgyY.js";import{t as A}from"./shield-check-Cd50jCAn.js";import{t as de}from"./terminal-DgFz2Vsf.js";import{t as fe}from"./trash-2-CwUv7ww1.js";import{t as pe}from"./wifi-off-CWLeusSV.js";import{A as me,C as he,E as ge,F as _e,H as j,I as ve,L as ye,Ln as be,M as xe,O as Se,R as Ce,S as we,T as Te,a as Ee,ar as De,b as Oe,c as ke,h as Ae,ir as je,j as Me,l as Ne,m as Pe,n as Fe,o as Ie,r as Le,rr as Re,s as ze,sr as M,t as Be,u as Ve,w as He,x as Ue,y as We}from"./index-WI-E4I3h.js";import{t as Ge}from"./ConfirmDialog-6hcNjmAh.js";var Ke=a(`arrow-up`,[[`path`,{d:`m5 12 7-7 7 7`,key:`hav0vg`}],[`path`,{d:`M12 19V5`,key:`x0mq9r`}]]),qe=a(`command`,[[`path`,{d:`M15 6v12a3 3 0 1 0 3-3H6a3 3 0 1 0 3 3V6a3 3 0 1 0-3 3h12a3 3 0 1 0-3-3`,key:`11bfej`}]]),Je=a(`compass`,[[`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`}]]),Ye=a(`gallery-vertical-end`,[[`path`,{d:`M7 2h10`,key:`nczekb`}],[`path`,{d:`M5 6h14`,key:`u2x4p`}],[`rect`,{width:`18`,height:`12`,x:`3`,y:`10`,rx:`2`,key:`l0tzu3`}]]),Xe=a(`gauge`,[[`path`,{d:`m12 14 4-4`,key:`9kzdfg`}],[`path`,{d:`M3.34 19a10 10 0 1 1 17.32 0`,key:`19p75a`}]]),Ze=a(`heart-pulse`,[[`path`,{d:`M19 14c1.49-1.46 3-3.21 3-5.5A5.5 5.5 0 0 0 16.5 3c-1.76 0-3 .5-4.5 2-1.5-1.5-2.74-2-4.5-2A5.5 5.5 0 0 0 2 8.5c0 2.3 1.5 4.05 3 5.5l7 7Z`,key:`c3ymky`}],[`path`,{d:`M3.22 12H9.5l.5-1 2 4.5 2-7 1.5 3.5h5.27`,key:`1uw2ng`}]]),Qe=a(`history`,[[`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`}]]),$e=a(`layout-grid`,[[`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`}]]),et=a(`navigation`,[[`polygon`,{points:`3 11 22 2 13 21 11 13 3 11`,key:`1ltx0t`}]]),tt=a(`panel-top`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M3 9h18`,key:`1pudct`}]]),N=e(t(),1),nt=()=>new Map,rt=e=>{let t=nt();return e.forEach((e,n)=>{t.set(n,e)}),t},it=(e,t,n)=>{let r=e.get(t);return r===void 0&&e.set(t,r=n()),r},at=(e,t)=>{let n=[];for(let[r,i]of e)n.push(t(i,r));return n},ot=(e,t)=>{for(let[n,r]of e)if(t(r,n))return!0;return!1},st=()=>new Set,ct=e=>e[e.length-1],lt=(e,t)=>{for(let n=0;n<t.length;n++)e.push(t[n])},ut=Array.from,dt=(e,t)=>{for(let n=0;n<e.length;n++)if(!t(e[n],n,e))return!1;return!0},ft=(e,t)=>{for(let n=0;n<e.length;n++)if(t(e[n],n,e))return!0;return!1},pt=(e,t)=>{let n=Array(e);for(let r=0;r<e;r++)n[r]=t(r,n);return n},mt=Array.isArray,ht=class{constructor(){this._observers=nt()}on(e,t){return it(this._observers,e,st).add(t),t}once(e,t){let n=(...r)=>{this.off(e,n),t(...r)};this.on(e,n)}off(e,t){let n=this._observers.get(e);n!==void 0&&(n.delete(t),n.size===0&&this._observers.delete(e))}emit(e,t){return ut((this._observers.get(e)||nt()).values()).forEach(e=>e(...t))}destroy(){this._observers=nt()}},gt=class{constructor(){this._observers=nt()}on(e,t){it(this._observers,e,st).add(t)}once(e,t){let n=(...r)=>{this.off(e,n),t(...r)};this.on(e,n)}off(e,t){let n=this._observers.get(e);n!==void 0&&(n.delete(t),n.size===0&&this._observers.delete(e))}emit(e,t){return ut((this._observers.get(e)||nt()).values()).forEach(e=>e(...t))}destroy(){this._observers=nt()}},_t=Math.floor,vt=Math.abs,yt=Math.log10,bt=(e,t)=>e<t?e:t,xt=(e,t)=>e>t?e:t;Number.isNaN;var St=e=>e===0?1/e<0:e<0,Ct=2**53-1,wt=-(2**53-1),Tt=Number.isInteger||(e=>typeof e==`number`&&isFinite(e)&&_t(e)===e);Number.isNaN,Number.parseInt;var Et=String.fromCharCode;String.fromCodePoint,Et(65535);var Dt=e=>e.toLowerCase(),Ot=/^\s*/g,kt=e=>e.replace(Ot,``),At=/([A-Z])/g,jt=(e,t)=>kt(e.replace(At,e=>`${t}${Dt(e)}`)),Mt=e=>{let t=unescape(encodeURIComponent(e)),n=t.length,r=new Uint8Array(n);for(let e=0;e<n;e++)r[e]=t.codePointAt(e);return r},Nt=typeof TextEncoder<`u`?new TextEncoder:null,Pt=Nt?e=>Nt.encode(e):Mt,Ft=typeof TextDecoder>`u`?null:new TextDecoder(`utf-8`,{fatal:!0,ignoreBOM:!0});Ft&&Ft.decode(new Uint8Array).length===1&&(Ft=null);var It=(e,t)=>pt(t,()=>e).join(``),Lt=class{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}},P=()=>new Lt,Rt=e=>{let t=e.cpos;for(let n=0;n<e.bufs.length;n++)t+=e.bufs[n].length;return t},F=e=>{let t=new Uint8Array(Rt(e)),n=0;for(let r=0;r<e.bufs.length;r++){let i=e.bufs[r];t.set(i,n),n+=i.length}return t.set(new Uint8Array(e.cbuf.buffer,0,e.cpos),n),t},zt=(e,t)=>{let n=e.cbuf.length;n-e.cpos<t&&(e.bufs.push(new Uint8Array(e.cbuf.buffer,0,e.cpos)),e.cbuf=new Uint8Array(xt(n,t)*2),e.cpos=0)},I=(e,t)=>{let n=e.cbuf.length;e.cpos===n&&(e.bufs.push(e.cbuf),e.cbuf=new Uint8Array(n*2),e.cpos=0),e.cbuf[e.cpos++]=t},Bt=I,L=(e,t)=>{for(;t>127;)I(e,128|127&t),t=_t(t/128);I(e,127&t)},Vt=(e,t)=>{let n=St(t);for(n&&(t=-t),I(e,(t>63?128:0)|(n?64:0)|63&t),t=_t(t/64);t>0;)I(e,(t>127?128:0)|127&t),t=_t(t/128)},Ht=new Uint8Array(3e4),Ut=Ht.length/3,Wt=Nt&&Nt.encodeInto?(e,t)=>{if(t.length<Ut){let n=Nt.encodeInto(t,Ht).written||0;L(e,n);for(let t=0;t<n;t++)I(e,Ht[t])}else R(e,Pt(t))}:(e,t)=>{let n=unescape(encodeURIComponent(t)),r=n.length;L(e,r);for(let t=0;t<r;t++)I(e,n.codePointAt(t))},Gt=(e,t)=>{let n=e.cbuf.length,r=e.cpos,i=bt(n-r,t.length),a=t.length-i;e.cbuf.set(t.subarray(0,i),r),e.cpos+=i,a>0&&(e.bufs.push(e.cbuf),e.cbuf=new Uint8Array(xt(n*2,a)),e.cbuf.set(t.subarray(i)),e.cpos=a)},R=(e,t)=>{L(e,t.byteLength),Gt(e,t)},Kt=(e,t)=>{zt(e,t);let n=new DataView(e.cbuf.buffer,e.cpos,t);return e.cpos+=t,n},qt=(e,t)=>Kt(e,4).setFloat32(0,t,!1),Jt=(e,t)=>Kt(e,8).setFloat64(0,t,!1),Yt=(e,t)=>Kt(e,8).setBigInt64(0,t,!1),Xt=new DataView(new ArrayBuffer(4)),Zt=e=>(Xt.setFloat32(0,e),Xt.getFloat32(0)===e),Qt=(e,t)=>{switch(typeof t){case`string`:I(e,119),Wt(e,t);break;case`number`:Tt(t)&&vt(t)<=2147483647?(I(e,125),Vt(e,t)):Zt(t)?(I(e,124),qt(e,t)):(I(e,123),Jt(e,t));break;case`bigint`:I(e,122),Yt(e,t);break;case`object`:if(t===null)I(e,126);else if(mt(t)){I(e,117),L(e,t.length);for(let n=0;n<t.length;n++)Qt(e,t[n])}else if(t instanceof Uint8Array)I(e,116),R(e,t);else{I(e,118);let n=Object.keys(t);L(e,n.length);for(let r=0;r<n.length;r++){let i=n[r];Wt(e,i),Qt(e,t[i])}}break;case`boolean`:I(e,t?120:121);break;default:I(e,127)}},$t=class extends Lt{constructor(e){super(),this.w=e,this.s=null,this.count=0}write(e){this.s===e?this.count++:(this.count>0&&L(this,this.count-1),this.count=1,this.w(this,e),this.s=e)}},en=e=>{e.count>0&&(Vt(e.encoder,e.count===1?e.s:-e.s),e.count>1&&L(e.encoder,e.count-2))},tn=class{constructor(){this.encoder=new Lt,this.s=0,this.count=0}write(e){this.s===e?this.count++:(en(this),this.count=1,this.s=e)}toUint8Array(){return en(this),F(this.encoder)}},nn=e=>{if(e.count>0){let t=e.diff*2+(e.count===1?0:1);Vt(e.encoder,t),e.count>1&&L(e.encoder,e.count-2)}},rn=class{constructor(){this.encoder=new Lt,this.s=0,this.count=0,this.diff=0}write(e){this.diff===e-this.s?(this.s=e,this.count++):(nn(this),this.count=1,this.diff=e-this.s,this.s=e)}toUint8Array(){return nn(this),F(this.encoder)}},an=class{constructor(){this.sarr=[],this.s=``,this.lensE=new tn}write(e){this.s+=e,this.s.length>19&&(this.sarr.push(this.s),this.s=``),this.lensE.write(e.length)}toUint8Array(){let e=new Lt;return this.sarr.push(this.s),this.s=``,Wt(e,this.sarr.join(``)),Gt(e,this.lensE.toUint8Array()),F(e)}},on=e=>Error(e),sn=()=>{throw on(`Method unimplemented`)},cn=()=>{throw on(`Unexpected case`)},ln=on(`Unexpected end of array`),un=on(`Integer out of Range`),dn=class{constructor(e){this.arr=e,this.pos=0}},fn=e=>new dn(e),pn=e=>e.pos!==e.arr.length,mn=(e,t)=>{let n=new Uint8Array(e.arr.buffer,e.pos+e.arr.byteOffset,t);return e.pos+=t,n},z=e=>mn(e,B(e)),hn=e=>e.arr[e.pos++],B=e=>{let t=0,n=1,r=e.arr.length;for(;e.pos<r;){let r=e.arr[e.pos++];if(t+=(r&127)*n,n*=128,r<128)return t;if(t>Ct)throw un}throw ln},gn=e=>{let t=e.arr[e.pos++],n=t&63,r=64,i=(t&64)>0?-1:1;if(!(t&128))return i*n;let a=e.arr.length;for(;e.pos<a;){if(t=e.arr[e.pos++],n+=(t&127)*r,r*=128,t<128)return i*n;if(n>Ct)throw un}throw ln},_n=Ft?e=>Ft.decode(z(e)):e=>{let t=B(e);if(t===0)return``;{let n=String.fromCodePoint(hn(e));if(--t<100)for(;t--;)n+=String.fromCodePoint(hn(e));else for(;t>0;){let r=t<1e4?t:1e4,i=e.arr.subarray(e.pos,e.pos+r);e.pos+=r,n+=String.fromCodePoint.apply(null,i),t-=r}return decodeURIComponent(escape(n))}},vn=(e,t)=>{let n=new DataView(e.arr.buffer,e.arr.byteOffset+e.pos,t);return e.pos+=t,n},yn=[e=>void 0,e=>null,gn,e=>vn(e,4).getFloat32(0,!1),e=>vn(e,8).getFloat64(0,!1),e=>vn(e,8).getBigInt64(0,!1),e=>!1,e=>!0,_n,e=>{let t=B(e),n={};for(let r=0;r<t;r++){let t=_n(e);n[t]=bn(e)}return n},e=>{let t=B(e),n=[];for(let r=0;r<t;r++)n.push(bn(e));return n},z],bn=e=>yn[127-hn(e)](e),xn=class extends dn{constructor(e,t){super(e),this.reader=t,this.s=null,this.count=0}read(){return this.count===0&&(this.s=this.reader(this),pn(this)?this.count=B(this)+1:this.count=-1),this.count--,this.s}},Sn=class extends dn{constructor(e){super(e),this.s=0,this.count=0}read(){if(this.count===0){this.s=gn(this);let e=St(this.s);this.count=1,e&&(this.s=-this.s,this.count=B(this)+2)}return this.count--,this.s}},Cn=class extends dn{constructor(e){super(e),this.s=0,this.count=0,this.diff=0}read(){if(this.count===0){let e=gn(this),t=e&1;this.diff=_t(e/2),this.count=1,t&&(this.count=B(this)+2)}return this.s+=this.diff,this.count--,this.s}},wn=class{constructor(e){this.decoder=new Sn(e),this.str=_n(this.decoder),this.spos=0}read(){let e=this.spos+this.decoder.read(),t=this.str.slice(this.spos,e);return this.spos=e,t}};crypto.subtle;var Tn=crypto.getRandomValues.bind(crypto),En=Math.random,Dn=()=>Tn(new Uint32Array(1))[0],On=`10000000-1000-4000-8000-100000000000`,kn=()=>On.replace(/[018]/g,e=>(e^Dn()&15>>e/4).toString(16)),An=Date.now,jn=e=>new Promise(e);Promise.all.bind(Promise);var Mn=e=>Promise.reject(e),Nn=e=>Promise.resolve(e),Pn=e=>e===void 0?null:e,Fn=new class{constructor(){this.map=new Map}setItem(e,t){this.map.set(e,t)}getItem(e){return this.map.get(e)}},In=!0;try{typeof localStorage<`u`&&localStorage&&(Fn=localStorage,In=!1)}catch{}var Ln=Fn,Rn=e=>In||addEventListener(`storage`,e),zn=e=>In||removeEventListener(`storage`,e),Bn=Symbol(`Equality`),Vn=(e,t)=>e===t||!!e?.[Bn]?.(t)||!1,Hn=e=>typeof e==`object`,Un=Object.assign,Wn=Object.keys,Gn=(e,t)=>{for(let n in e)t(e[n],n)},Kn=e=>Wn(e).length,qn=e=>{for(let t in e)return!1;return!0},Jn=(e,t)=>{for(let n in e)if(!t(e[n],n))return!1;return!0},Yn=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),Xn=(e,t)=>e===t||Kn(e)===Kn(t)&&Jn(e,(e,n)=>(e!==void 0||Yn(t,n))&&Vn(t[n],e)),Zn=Object.freeze,Qn=e=>{for(let t in e){let n=e[t];(typeof n==`object`||typeof n==`function`)&&Qn(e[t])}return Zn(e)},$n=(e,t,n=0)=>{try{for(;n<e.length;n++)e[n](...t)}finally{n<e.length&&$n(e,t,n+1)}},er=()=>{},tr=e=>e,nr=(e,t)=>{if(e===t)return!0;if(e==null||t==null||e.constructor!==t.constructor&&(e.constructor||Object)!==(t.constructor||Object))return!1;if(e[Bn]!=null)return e[Bn](t);switch(e.constructor){case ArrayBuffer:e=new Uint8Array(e),t=new Uint8Array(t);case Uint8Array:if(e.byteLength!==t.byteLength)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;break;case Set:if(e.size!==t.size)return!1;for(let n of e)if(!t.has(n))return!1;break;case Map:if(e.size!==t.size)return!1;for(let n of e.keys())if(!t.has(n)||!nr(e.get(n),t.get(n)))return!1;break;case void 0:case Object:if(Kn(e)!==Kn(t))return!1;for(let n in e)if(!Yn(e,n)||!nr(e[n],t[n]))return!1;break;case Array:if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!nr(e[n],t[n]))return!1;break;default:return!1}return!0},rr=(e,t)=>t.includes(e),ir=typeof process<`u`&&process.release&&/node|io\.js/.test(process.release.name)&&Object.prototype.toString.call(typeof process<`u`?process:0)===`[object process]`,ar=typeof window<`u`&&typeof document<`u`&&!ir;typeof navigator<`u`&&/Mac/.test(navigator.platform);var or,sr=[],cr=()=>{if(or===void 0)if(ir){or=nt();let e=process.argv,t=null;for(let n=0;n<e.length;n++){let r=e[n];r[0]===`-`?(t!==null&&or.set(t,``),t=r):t===null?sr.push(r):(or.set(t,r),t=null)}t!==null&&or.set(t,``)}else typeof location==`object`?(or=nt(),(location.search||`?`).slice(1).split(`&`).forEach(e=>{if(e.length!==0){let[t,n]=e.split(`=`);or.set(`--${jt(t,`-`)}`,n),or.set(`-${jt(t,`-`)}`,n)}})):or=nt();return or},lr=e=>cr().has(e),ur=e=>Pn(ir?{}[e.toUpperCase().replaceAll(`-`,`_`)]:Ln.getItem(e)),dr=e=>lr(`--`+e)||ur(e)!==null,fr=dr(`production`),pr=ir&&rr({}.FORCE_COLOR,[`true`,`1`,`2`])||!lr(`--no-colors`)&&!dr(`no-color`)&&(!ir||process.stdout.isTTY)&&(!ir||lr(`--color`)||ur(`COLORTERM`)!==null||(ur(`TERM`)||``).includes(`color`)),mr=e=>new Uint8Array(e),hr=(e,t,n)=>new Uint8Array(e,t,n),gr=e=>new Uint8Array(e),_r=e=>{let t=``;for(let n=0;n<e.byteLength;n++)t+=Et(e[n]);return btoa(t)},vr=e=>Buffer.from(e.buffer,e.byteOffset,e.byteLength).toString(`base64`),yr=e=>{let t=atob(e),n=mr(t.length);for(let e=0;e<t.length;e++)n[e]=t.charCodeAt(e);return n},br=e=>{let t=Buffer.from(e,`base64`);return hr(t.buffer,t.byteOffset,t.byteLength)},xr=ar?_r:vr,Sr=ar?yr:br,Cr=e=>{let t=mr(e.byteLength);return t.set(e),t},wr=class{constructor(e,t){this.left=e,this.right=t}},Tr=(e,t)=>new wr(e,t),Er=e=>e.next()>=.5,Dr=(e,t,n)=>_t(e.next()*(n+1-t)+t),Or=(e,t,n)=>_t(e.next()*(n+1-t)+t),kr=(e,t,n)=>Or(e,t,n),Ar=e=>Et(kr(e,97,122)),jr=(e,t=0,n=20)=>{let r=kr(e,t,n),i=``;for(let t=0;t<r;t++)i+=Ar(e);return i},Mr=(e,t)=>t[kr(e,0,t.length-1)],Nr=Symbol(`0schema`),Pr=class{constructor(){this._rerrs=[]}extend(e,t,n,r=null){this._rerrs.push({path:e,expected:t,has:n,message:r})}toString(){let e=[];for(let t=this._rerrs.length-1;t>0;t--){let n=this._rerrs[t];e.push(It(` `,(this._rerrs.length-t)*2)+`${n.path==null?``:`[${n.path}] `}${n.has} doesn't match ${n.expected}. ${n.message}`)}return e.join(`
|
|
3
|
+
`)}},Fr=(e,t)=>e===t?!0:e==null||t==null||e.constructor!==t.constructor?!1:e[Bn]?Vn(e,t):mt(e)?dt(e,e=>ft(t,t=>Fr(e,t))):Hn(e)?Jn(e,(e,n)=>Fr(e,t[n])):!1,Ir=class{static _dilutes=!1;extends(e){let[t,n]=[this.shape,e.shape];return this.constructor._dilutes&&([n,t]=[t,n]),Fr(t,n)}equals(e){return this.constructor===e.constructor&&nr(this.shape,e.shape)}[Nr](){return!0}[Bn](e){return this.equals(e)}validate(e){return this.check(e)}check(e,t){sn()}get nullable(){return pi(this,Oi)}get optional(){return new Gr(this)}cast(e){return Mi(e,this),e}expect(e){return Mi(e,this),e}},Lr=class extends Ir{constructor(e,t){super(),this.shape=e,this._c=t}check(e,t=void 0){let n=e?.constructor===this.shape&&(this._c==null||this._c(e));return!n&&t?.extend(null,this.shape.name,e?.constructor.name,e?.constructor===this.shape?`Check failed`:`Constructor match failed`),n}},V=(e,t=null)=>new Lr(e,t);V(Lr);var Rr=class extends Ir{constructor(e){super(),this.shape=e}check(e,t){let n=this.shape(e);return!n&&t?.extend(null,`custom prop`,e?.constructor.name,`failed to check custom prop`),n}},H=e=>new Rr(e);V(Rr);var zr=class extends Ir{constructor(e){super(),this.shape=e}check(e,t){let n=this.shape.some(t=>t===e);return!n&&t?.extend(null,this.shape.join(` | `),e.toString()),n}},Br=(...e)=>new zr(e),Vr=V(zr),Hr=RegExp.escape||(e=>e.replace(/[().|&,$^[\]]/g,e=>`\\`+e)),Ur=e=>{if(Ci.check(e))return[Hr(e)];if(Vr.check(e))return e.shape.map(e=>e+``);if(Si.check(e))return[`[+-]?\\d+.?\\d*`];if(wi.check(e))return[`.*`];if(mi.check(e))return e.shape.map(Ur).flat(1);cn()};V(class extends Ir{constructor(e){super(),this.shape=e,this._r=RegExp(`^`+e.map(Ur).map(e=>`(${e.join(`|`)})`).join(``)+`$`)}check(e,t){let n=this._r.exec(e)!=null;return!n&&t?.extend(null,this._r.toString(),e.toString(),`String doesn't match string template.`),n}});var Wr=Symbol(`optional`),Gr=class extends Ir{constructor(e){super(),this.shape=e}check(e,t){let n=e===void 0||this.shape.check(e);return!n&&t?.extend(null,`undefined (optional)`,`()`),n}get[Wr](){return!0}},Kr=V(Gr),qr=class extends Ir{check(e,t){return t?.extend(null,`never`,typeof e),!1}};new qr,V(qr);var Jr=class e extends Ir{constructor(e,t=!1){super(),this.shape=e,this._isPartial=t}static _dilutes=!0;get partial(){return new e(this.shape,!0)}check(e,t){return e==null?(t?.extend(null,`object`,`null`),!1):Jn(this.shape,(n,r)=>{let i=this._isPartial&&!Yn(e,r)||n.check(e[r],t);return!i&&t?.extend(r.toString(),n.toString(),typeof e[r],`Object property does not match`),i})}},Yr=e=>new Jr(e),Xr=V(Jr),Zr=H(e=>e!=null&&(e.constructor===Object||e.constructor==null)),Qr=class extends Ir{constructor(e,t){super(),this.shape={keys:e,values:t}}check(e,t){return e!=null&&Jn(e,(n,r)=>{let i=this.shape.keys.check(r,t);return!i&&t?.extend(r+``,`Record`,typeof e,i?`Key doesn't match schema`:`Value doesn't match value`),i&&this.shape.values.check(n,t)})}},$r=(e,t)=>new Qr(e,t),ei=V(Qr),ti=class extends Ir{constructor(e){super(),this.shape=e}check(e,t){return e!=null&&Jn(this.shape,(n,r)=>{let i=n.check(e[r],t);return!i&&t?.extend(r.toString(),`Tuple`,typeof n),i})}},ni=(...e)=>new ti(e);V(ti);var ri=class extends Ir{constructor(e){super(),this.shape=e.length===1?e[0]:new fi(e)}check(e,t){let n=mt(e)&&dt(e,e=>this.shape.check(e));return!n&&t?.extend(null,`Array`,``),n}},ii=(...e)=>new ri(e),ai=V(ri),oi=H(e=>mt(e)),si=class extends Ir{constructor(e,t){super(),this.shape=e,this._c=t}check(e,t){let n=e instanceof this.shape&&(this._c==null||this._c(e));return!n&&t?.extend(null,this.shape.name,e?.constructor.name),n}},ci=(e,t=null)=>new si(e,t);V(si);var li=ci(Ir),ui=V(class extends Ir{constructor(e){super(),this.len=e.length-1,this.args=ni(...e.slice(-1)),this.res=e[this.len]}check(e,t){let n=e.constructor===Function&&e.length<=this.len;return!n&&t?.extend(null,`function`,typeof e),n}}),di=H(e=>typeof e==`function`);V(class extends Ir{constructor(e){super(),this.shape=e}check(e,t){let n=dt(this.shape,n=>n.check(e,t));return!n&&t?.extend(null,`Intersectinon`,typeof e),n}},e=>e.shape.length>0);var fi=class extends Ir{static _dilutes=!0;constructor(e){super(),this.shape=e}check(e,t){let n=ft(this.shape,n=>n.check(e,t));return t?.extend(null,`Union`,typeof e),n}},pi=(...e)=>e.findIndex(e=>mi.check(e))>=0?pi(...e.map(e=>ji(e)).map(e=>mi.check(e)?e.shape:[e]).flat(1)):e.length===1?e[0]:new fi(e),mi=V(fi),hi=()=>!0,gi=H(hi),_i=V(Rr,e=>e.shape===hi),vi=H(e=>typeof e==`bigint`),yi=H(e=>e===vi),bi=H(e=>typeof e==`symbol`);H(e=>e===bi);var xi=H(e=>typeof e==`number`),Si=H(e=>e===xi),Ci=H(e=>typeof e==`string`),wi=H(e=>e===Ci),Ti=H(e=>typeof e==`boolean`),Ei=H(e=>e===Ti),Di=Br(void 0);V(zr,e=>e.shape.length===1&&e.shape[0]===void 0),Br(void 0);var Oi=Br(null),ki=V(zr,e=>e.shape.length===1&&e.shape[0]===null);V(Uint8Array),V(Lr,e=>e.shape===Uint8Array);var Ai=pi(xi,Ci,Oi,Di,vi,Ti,bi);(()=>{let e=ii(gi),t=$r(Ci,gi),n=pi(xi,Ci,Oi,Ti,e,t);return e.shape=n,t.shape.values=n,n})();var ji=e=>{if(li.check(e))return e;if(Zr.check(e)){let t={};for(let n in e)t[n]=ji(e[n]);return Yr(t)}else if(oi.check(e))return pi(...e.map(ji));else if(Ai.check(e))return Br(e);else if(di.check(e))return V(e);cn()},Mi=fr?()=>{}:(e,t)=>{let n=new Pr;if(!t.check(e,n))throw on(`Expected value to be of type ${t.constructor.name}.\n${n.toString()}`)},Ni=class{constructor(e){this.patterns=[],this.$state=e}if(e,t){return this.patterns.push({if:ji(e),h:t}),this}else(e){return this.if(gi,e)}done(){return(e,t)=>{for(let n=0;n<this.patterns.length;n++){let r=this.patterns[n];if(r.if.check(e))return r.h(e,t)}throw on(`Unhandled pattern`)}}},Pi=(e=>new Ni(e))(gi).if(Si,(e,t)=>Dr(t,wt,Ct)).if(wi,(e,t)=>jr(t)).if(Ei,(e,t)=>Er(t)).if(yi,(e,t)=>BigInt(Dr(t,wt,Ct))).if(mi,(e,t)=>Fi(t,Mr(t,e.shape))).if(Xr,(e,t)=>{let n={};for(let r in e.shape){let i=e.shape[r];if(Kr.check(i)){if(Er(t))continue;i=i.shape}n[r]=Pi(i,t)}return n}).if(ai,(e,t)=>{let n=[],r=Or(t,0,42);for(let i=0;i<r;i++)n.push(Fi(t,e.shape));return n}).if(Vr,(e,t)=>Mr(t,e.shape)).if(ki,(e,t)=>null).if(ui,(e,t)=>{let n=Fi(t,e.res);return()=>n}).if(_i,(e,t)=>Fi(t,Mr(t,[xi,Ci,Oi,Di,vi,Ti,ii(xi),$r(pi(`a`,`b`,`c`),xi)]))).if(ei,(e,t)=>{let n={},r=Dr(t,0,3);for(let i=0;i<r;i++){let r=Fi(t,e.shape.keys);n[r]=Fi(t,e.shape.values)}return n}).done(),Fi=(e,t)=>Pi(ji(t),e),Ii=typeof document<`u`?document:{};H(e=>e.nodeType===Vi),typeof DOMParser<`u`&&new DOMParser,H(e=>e.nodeType===Ri),H(e=>e.nodeType===zi);var Li=e=>at(e,(e,t)=>`${t}:${e};`).join(``),Ri=Ii.ELEMENT_NODE,zi=Ii.TEXT_NODE;Ii.CDATA_SECTION_NODE,Ii.COMMENT_NODE;var Bi=Ii.DOCUMENT_NODE;Ii.DOCUMENT_TYPE_NODE;var Vi=Ii.DOCUMENT_FRAGMENT_NODE;H(e=>e.nodeType===Bi);var Hi=JSON.stringify,Ui=Symbol,Wi=Ui(),Gi=Ui(),Ki=Ui(),qi=Ui(),Ji=Ui(),Yi=Ui(),Xi=Ui(),Zi=Ui(),Qi=Ui(),$i=e=>{e.length===1&&e[0]?.constructor===Function&&(e=e[0]());let t=[],n=[],r=0;for(;r<e.length;r++){let n=e[r];if(n===void 0)break;if(n.constructor===String||n.constructor===Number)t.push(n);else if(n.constructor===Object)break}for(r>0&&n.push(t.join(``));r<e.length;r++){let t=e[r];t instanceof Symbol||n.push(t)}return n},ea=[Ji,Xi,Zi,Ki],ta=0,na=An(),ra=(e,t)=>{let n=ea[ta],r=ur(`log`),i=r!==null&&(r===`*`||r===`true`||new RegExp(r,`gi`).test(t));return ta=(ta+1)%ea.length,t+=`: `,i?(...r)=>{r.length===1&&r[0]?.constructor===Function&&(r=r[0]());let i=An(),a=i-na;na=i,e(n,t,Qi,...r.map(e=>{switch(e!=null&&e.constructor===Uint8Array&&(e=Array.from(e)),typeof e){case`string`:case`symbol`:return e;default:return Hi(e)}}),n,` +`+a+`ms`)}:er},ia={[Wi]:Tr(`font-weight`,`bold`),[Gi]:Tr(`font-weight`,`normal`),[Ki]:Tr(`color`,`blue`),[Ji]:Tr(`color`,`green`),[qi]:Tr(`color`,`grey`),[Yi]:Tr(`color`,`red`),[Xi]:Tr(`color`,`purple`),[Zi]:Tr(`color`,`orange`),[Qi]:Tr(`color`,`black`)},aa=pr?e=>{e.length===1&&e[0]?.constructor===Function&&(e=e[0]());let t=[],n=[],r=nt(),i=[],a=0;for(;a<e.length;a++){let i=e[a],o=ia[i];if(o!==void 0)r.set(o.left,o.right);else{if(i===void 0)break;if(i.constructor===String||i.constructor===Number){let e=Li(r);a>0||e.length>0?(t.push(`%c`+i),n.push(e)):t.push(i)}else break}}for(a>0&&(i=n,i.unshift(t.join(``)));a<e.length;a++){let t=e[a];t instanceof Symbol||i.push(t)}return i}:$i,oa=(...e)=>{console.log(...aa(e)),ca.forEach(t=>t.print(e))},sa=(...e)=>{console.warn(...aa(e)),e.unshift(Zi),ca.forEach(t=>t.print(e))},ca=st(),la=e=>ra(oa,e),ua=e=>({[Symbol.iterator](){return this},next:e}),da=(e,t)=>ua(()=>{let n;do n=e.next();while(!n.done&&!t(n.value));return n}),fa=(e,t)=>ua(()=>{let{done:n,value:r}=e.next();return{done:n,value:n?void 0:t(r)}}),pa=class{constructor(e,t){this.clock=e,this.len=t}},ma=class{constructor(){this.clients=new Map}},ha=(e,t,n)=>t.clients.forEach((t,r)=>{let i=e.doc.store.clients.get(r);if(i!=null){let r=i[i.length-1],a=r.id.clock+r.length;for(let r=0,o=t[r];r<t.length&&o.clock<a;o=t[++r])bo(e,i,o.clock,o.len,n)}}),ga=(e,t)=>{let n=0,r=e.length-1;for(;n<=r;){let i=_t((n+r)/2),a=e[i],o=a.clock;if(o<=t){if(t<o+a.len)return i;n=i+1}else r=i-1}return null},_a=(e,t)=>{let n=e.clients.get(t.client);return n!==void 0&&ga(n,t.clock)!==null},va=e=>{e.clients.forEach(e=>{e.sort((e,t)=>e.clock-t.clock);let t,n;for(t=1,n=1;t<e.length;t++){let r=e[n-1],i=e[t];r.clock+r.len>=i.clock?e[n-1]=new pa(r.clock,xt(r.len,i.clock+i.len-r.clock)):(n<t&&(e[n]=i),n++)}e.length=n})},ya=e=>{let t=new ma;for(let n=0;n<e.length;n++)e[n].clients.forEach((r,i)=>{if(!t.clients.has(i)){let a=r.slice();for(let t=n+1;t<e.length;t++)lt(a,e[t].clients.get(i)||[]);t.clients.set(i,a)}});return va(t),t},ba=(e,t,n,r)=>{it(e.clients,t,()=>[]).push(new pa(n,r))},xa=()=>new ma,Sa=e=>{let t=xa();return e.clients.forEach((e,n)=>{let r=[];for(let t=0;t<e.length;t++){let n=e[t];if(n.deleted){let i=n.id.clock,a=n.length;if(t+1<e.length)for(let n=e[t+1];t+1<e.length&&n.deleted;n=e[++t+1])a+=n.length;r.push(new pa(i,a))}}r.length>0&&t.clients.set(n,r)}),t},Ca=(e,t)=>{L(e.restEncoder,t.clients.size),ut(t.clients.entries()).sort((e,t)=>t[0]-e[0]).forEach(([t,n])=>{e.resetDsCurVal(),L(e.restEncoder,t);let r=n.length;L(e.restEncoder,r);for(let t=0;t<r;t++){let r=n[t];e.writeDsClock(r.clock),e.writeDsLen(r.len)}})},wa=e=>{let t=new ma,n=B(e.restDecoder);for(let r=0;r<n;r++){e.resetDsCurVal();let n=B(e.restDecoder),r=B(e.restDecoder);if(r>0){let i=it(t.clients,n,()=>[]);for(let t=0;t<r;t++)i.push(new pa(e.readDsClock(),e.readDsLen()))}}return t},Ta=(e,t,n)=>{let r=new ma,i=B(e.restDecoder);for(let a=0;a<i;a++){e.resetDsCurVal();let i=B(e.restDecoder),a=B(e.restDecoder),o=n.clients.get(i)||[],s=W(n,i);for(let n=0;n<a;n++){let n=e.readDsClock(),a=n+e.readDsLen();if(n<s){s<a&&ba(r,i,s,a-s);let e=mo(o,n),c=o[e];for(!c.deleted&&c.id.clock<n&&(o.splice(e+1,0,Ec(t,c,n-c.id.clock)),e++);e<o.length&&(c=o[e++],c.id.clock<a);)c.deleted||(a<c.id.clock+c.length&&o.splice(e,0,Ec(t,c,a-c.id.clock)),c.delete(t))}else ba(r,i,n,a-n)}}if(r.clients.size>0){let e=new Fa;return L(e.restEncoder,0),Ca(e,r),e.toUint8Array()}return null},Ea=Dn,Da=class e extends ht{constructor({guid:e=kn(),collectionid:t=null,gc:n=!0,gcFilter:r=()=>!0,meta:i=null,autoLoad:a=!1,shouldLoad:o=!0}={}){super(),this.gc=n,this.gcFilter=r,this.clientID=Ea(),this.guid=e,this.collectionid=t,this.share=new Map,this.store=new uo,this._transaction=null,this._transactionCleanups=[],this.subdocs=new Set,this._item=null,this.shouldLoad=o,this.autoLoad=a,this.meta=i,this.isLoaded=!1,this.isSynced=!1,this.isDestroyed=!1,this.whenLoaded=jn(e=>{this.on(`load`,()=>{this.isLoaded=!0,e(this)})});let s=()=>jn(e=>{let t=n=>{(n===void 0||n===!0)&&(this.off(`sync`,t),e())};this.on(`sync`,t)});this.on(`sync`,e=>{e===!1&&this.isSynced&&(this.whenSynced=s()),this.isSynced=e===void 0||e===!0,this.isSynced&&!this.isLoaded&&this.emit(`load`,[this])}),this.whenSynced=s()}load(){let e=this._item;e!==null&&!this.shouldLoad&&G(e.parent.doc,e=>{e.subdocsLoaded.add(this)},null,!0),this.shouldLoad=!0}getSubdocs(){return this.subdocs}getSubdocGuids(){return new Set(ut(this.subdocs).map(e=>e.guid))}transact(e,t=null){return G(this,e,t)}get(e,t=q){let n=it(this.share,e,()=>{let e=new t;return e._integrate(this,null),e}),r=n.constructor;if(t!==q&&r!==t)if(r===q){let r=new t;r._map=n._map,n._map.forEach(e=>{for(;e!==null;e=e.left)e.parent=r}),r._start=n._start;for(let e=r._start;e!==null;e=e.right)e.parent=r;return r._length=n._length,this.share.set(e,r),r._integrate(this,null),r}else throw Error(`Type with the name ${e} has already been defined with a different constructor`);return n}getArray(e=``){return this.get(e,_s)}getText(e=``){return this.get(e,Rs)}getMap(e=``){return this.get(e,bs)}getXmlElement(e=``){return this.get(e,Us)}getXmlFragment(e=``){return this.get(e,Vs)}toJSON(){let e={};return this.share.forEach((t,n)=>{e[n]=t.toJSON()}),e}destroy(){this.isDestroyed=!0,ut(this.subdocs).forEach(e=>e.destroy());let t=this._item;if(t!==null){this._item=null;let n=t.content;n.doc=new e({guid:this.guid,...n.opts,shouldLoad:!1}),n.doc._item=t,G(t.parent.doc,e=>{let r=n.doc;t.deleted||e.subdocsAdded.add(r),e.subdocsRemoved.add(this)},null,!0)}this.emit(`destroyed`,[!0]),this.emit(`destroy`,[this]),super.destroy()}},Oa=class{constructor(e){this.restDecoder=e}resetDsCurVal(){}readDsClock(){return B(this.restDecoder)}readDsLen(){return B(this.restDecoder)}},ka=class extends Oa{readLeftID(){return U(B(this.restDecoder),B(this.restDecoder))}readRightID(){return U(B(this.restDecoder),B(this.restDecoder))}readClient(){return B(this.restDecoder)}readInfo(){return hn(this.restDecoder)}readString(){return _n(this.restDecoder)}readParentInfo(){return B(this.restDecoder)===1}readTypeRef(){return B(this.restDecoder)}readLen(){return B(this.restDecoder)}readAny(){return bn(this.restDecoder)}readBuf(){return Cr(z(this.restDecoder))}readJSON(){return JSON.parse(_n(this.restDecoder))}readKey(){return _n(this.restDecoder)}},Aa=class{constructor(e){this.dsCurrVal=0,this.restDecoder=e}resetDsCurVal(){this.dsCurrVal=0}readDsClock(){return this.dsCurrVal+=B(this.restDecoder),this.dsCurrVal}readDsLen(){let e=B(this.restDecoder)+1;return this.dsCurrVal+=e,e}},ja=class extends Aa{constructor(e){super(e),this.keys=[],B(e),this.keyClockDecoder=new Cn(z(e)),this.clientDecoder=new Sn(z(e)),this.leftClockDecoder=new Cn(z(e)),this.rightClockDecoder=new Cn(z(e)),this.infoDecoder=new xn(z(e),hn),this.stringDecoder=new wn(z(e)),this.parentInfoDecoder=new xn(z(e),hn),this.typeRefDecoder=new Sn(z(e)),this.lenDecoder=new Sn(z(e))}readLeftID(){return new io(this.clientDecoder.read(),this.leftClockDecoder.read())}readRightID(){return new io(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 bn(this.restDecoder)}readBuf(){return z(this.restDecoder)}readJSON(){return bn(this.restDecoder)}readKey(){let e=this.keyClockDecoder.read();if(e<this.keys.length)return this.keys[e];{let e=this.stringDecoder.read();return this.keys.push(e),e}}},Ma=class{constructor(){this.restEncoder=P()}toUint8Array(){return F(this.restEncoder)}resetDsCurVal(){}writeDsClock(e){L(this.restEncoder,e)}writeDsLen(e){L(this.restEncoder,e)}},Na=class extends Ma{writeLeftID(e){L(this.restEncoder,e.client),L(this.restEncoder,e.clock)}writeRightID(e){L(this.restEncoder,e.client),L(this.restEncoder,e.clock)}writeClient(e){L(this.restEncoder,e)}writeInfo(e){Bt(this.restEncoder,e)}writeString(e){Wt(this.restEncoder,e)}writeParentInfo(e){L(this.restEncoder,+!!e)}writeTypeRef(e){L(this.restEncoder,e)}writeLen(e){L(this.restEncoder,e)}writeAny(e){Qt(this.restEncoder,e)}writeBuf(e){R(this.restEncoder,e)}writeJSON(e){Wt(this.restEncoder,JSON.stringify(e))}writeKey(e){Wt(this.restEncoder,e)}},Pa=class{constructor(){this.restEncoder=P(),this.dsCurrVal=0}toUint8Array(){return F(this.restEncoder)}resetDsCurVal(){this.dsCurrVal=0}writeDsClock(e){let t=e-this.dsCurrVal;this.dsCurrVal=e,L(this.restEncoder,t)}writeDsLen(e){e===0&&cn(),L(this.restEncoder,e-1),this.dsCurrVal+=e}},Fa=class extends Pa{constructor(){super(),this.keyMap=new Map,this.keyClock=0,this.keyClockEncoder=new rn,this.clientEncoder=new tn,this.leftClockEncoder=new rn,this.rightClockEncoder=new rn,this.infoEncoder=new $t(Bt),this.stringEncoder=new an,this.parentInfoEncoder=new $t(Bt),this.typeRefEncoder=new tn,this.lenEncoder=new tn}toUint8Array(){let e=P();return L(e,0),R(e,this.keyClockEncoder.toUint8Array()),R(e,this.clientEncoder.toUint8Array()),R(e,this.leftClockEncoder.toUint8Array()),R(e,this.rightClockEncoder.toUint8Array()),R(e,F(this.infoEncoder)),R(e,this.stringEncoder.toUint8Array()),R(e,F(this.parentInfoEncoder)),R(e,this.typeRefEncoder.toUint8Array()),R(e,this.lenEncoder.toUint8Array()),Gt(e,F(this.restEncoder)),F(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)}writeTypeRef(e){this.typeRefEncoder.write(e)}writeLen(e){this.lenEncoder.write(e)}writeAny(e){Qt(this.restEncoder,e)}writeBuf(e){R(this.restEncoder,e)}writeJSON(e){Qt(this.restEncoder,e)}writeKey(e){let t=this.keyMap.get(e);t===void 0?(this.keyClockEncoder.write(this.keyClock++),this.stringEncoder.write(e)):this.keyClockEncoder.write(t)}},Ia=(e,t,n,r)=>{r=xt(r,t[0].id.clock);let i=mo(t,r);L(e.restEncoder,t.length-i),e.writeClient(n),L(e.restEncoder,r);let a=t[i];a.write(e,r-a.id.clock);for(let n=i+1;n<t.length;n++)t[n].write(e,0)},La=(e,t,n)=>{let r=new Map;n.forEach((e,n)=>{W(t,n)>e&&r.set(n,e)}),fo(t).forEach((e,t)=>{n.has(t)||r.set(t,0)}),L(e.restEncoder,r.size),ut(r.entries()).sort((e,t)=>t[0]-e[0]).forEach(([n,r])=>{Ia(e,t.clients.get(n),n,r)})},Ra=(e,t)=>{let n=nt(),r=B(e.restDecoder);for(let i=0;i<r;i++){let r=B(e.restDecoder),i=Array(r),a=e.readClient(),o=B(e.restDecoder);n.set(a,{i:0,refs:i});for(let n=0;n<r;n++){let r=e.readInfo();switch(31&r){case 0:{let t=e.readLen();i[n]=new Qs(U(a,o),t),o+=t;break}case 10:{let t=B(e.restDecoder);i[n]=new jc(U(a,o),t),o+=t;break}default:{let s=(r&192)==0,c=new Dc(U(a,o),null,(r&128)==128?e.readLeftID():null,null,(r&64)==64?e.readRightID():null,s?e.readParentInfo()?t.get(e.readString()):e.readLeftID():null,s&&(r&32)==32?e.readString():null,Oc(e,r));i[n]=c,o+=c.length}}}}return n},za=(e,t,n)=>{let r=[],i=ut(n.keys()).sort((e,t)=>e-t);if(i.length===0)return null;let a=()=>{if(i.length===0)return null;let e=n.get(i[i.length-1]);for(;e.refs.length===e.i;)if(i.pop(),i.length>0)e=n.get(i[i.length-1]);else return null;return e},o=a();if(o===null)return null;let s=new uo,c=new Map,l=(e,t)=>{let n=c.get(e);(n==null||n>t)&&c.set(e,t)},u=o.refs[o.i++],d=new Map,f=()=>{for(let e of r){let t=e.id.client,r=n.get(t);r?(r.i--,s.clients.set(t,r.refs.slice(r.i)),n.delete(t),r.i=0,r.refs=[]):s.clients.set(t,[e]),i=i.filter(e=>e!==t)}r.length=0};for(;;){if(u.constructor!==jc){let i=it(d,u.id.client,()=>W(t,u.id.client))-u.id.clock;if(i<0)r.push(u),l(u.id.client,u.id.clock-1),f();else{let a=u.getMissing(e,t);if(a!==null){r.push(u);let e=n.get(a)||{refs:[],i:0};if(e.refs.length===e.i)l(a,W(t,a)),f();else{u=e.refs[e.i++];continue}}else(i===0||i<u.length)&&(u.integrate(e,i),d.set(u.id.client,u.id.clock+u.length))}}if(r.length>0)u=r.pop();else if(o!==null&&o.i<o.refs.length)u=o.refs[o.i++];else{if(o=a(),o===null)break;u=o.refs[o.i++]}}if(s.clients.size>0){let e=new Fa;return La(e,s,new Map),L(e.restEncoder,0),{missing:c,update:e.toUint8Array()}}return null},Ba=(e,t)=>La(e,t.doc.store,t.beforeState),Va=(e,t,n,r=new ja(e))=>G(t,e=>{e.local=!1;let t=!1,n=e.doc,i=n.store,a=za(e,i,Ra(r,n)),o=i.pendingStructs;if(o){for(let[e,n]of o.missing)if(n<W(i,e)){t=!0;break}if(a){for(let[e,t]of a.missing){let n=o.missing.get(e);(n==null||n>t)&&o.missing.set(e,t)}o.update=No([o.update,a.update])}}else i.pendingStructs=a;let s=Ta(r,e,i);if(i.pendingDs){let t=new ja(fn(i.pendingDs));B(t.restDecoder);let n=Ta(t,e,i);s&&n?i.pendingDs=No([s,n]):i.pendingDs=s||n}else i.pendingDs=s;if(t){let t=i.pendingStructs.update;i.pendingStructs=null,Ha(e.doc,t)}},n,!1),Ha=(e,t,n,r=ja)=>{let i=fn(t);Va(i,e,n,new r(i))},Ua=(e,t,n)=>Ha(e,t,n,ka),Wa=(e,t,n=new Map)=>{La(e,t.store,n),Ca(e,Sa(t.store))},Ga=(e,t=new Uint8Array([0]),n=new Fa)=>{Wa(n,e,Ja(t));let r=[n.toUint8Array()];if(e.store.pendingDs&&r.push(e.store.pendingDs),e.store.pendingStructs&&r.push(Po(e.store.pendingStructs.update,t)),r.length>1){if(n.constructor===Na)return jo(r.map((e,t)=>t===0?e:zo(e)));if(n.constructor===Fa)return No(r)}return r[0]},Ka=(e,t)=>Ga(e,t,new Na),qa=e=>{let t=new Map,n=B(e.restDecoder);for(let r=0;r<n;r++){let n=B(e.restDecoder),r=B(e.restDecoder);t.set(n,r)}return t},Ja=e=>qa(new Oa(fn(e))),Ya=(e,t)=>(L(e.restEncoder,t.size),ut(t.entries()).sort((e,t)=>t[0]-e[0]).forEach(([t,n])=>{L(e.restEncoder,t),L(e.restEncoder,n)}),e),Xa=(e,t)=>Ya(e,fo(t.store)),Za=(e,t=new Pa)=>(e instanceof Map?Ya(t,e):Xa(t,e),t.toUint8Array()),Qa=e=>Za(e,new Ma),$a=class{constructor(){this.l=[]}},eo=()=>new $a,to=(e,t)=>e.l.push(t),no=(e,t)=>{let n=e.l,r=n.length;e.l=n.filter(e=>t!==e),r===e.l.length&&console.error(`[yjs] Tried to remove event handler that doesn't exist.`)},ro=(e,t,n)=>$n(e.l,[t,n]),io=class{constructor(e,t){this.client=e,this.clock=t}},ao=(e,t)=>e===t||e!==null&&t!==null&&e.client===t.client&&e.clock===t.clock,U=(e,t)=>new io(e,t),oo=e=>{for(let[t,n]of e.doc.share.entries())if(n===e)return t;throw cn()},so=class{constructor(e,t){this.ds=e,this.sv=t}};((e,t)=>new so(e,t))(xa(),new Map);var co=(e,t)=>t===void 0?!e.deleted:t.sv.has(e.id.client)&&(t.sv.get(e.id.client)||0)>e.id.clock&&!_a(t.ds,e.id),lo=(e,t)=>{let n=it(e.meta,lo,st),r=e.doc.store;n.has(t)||(t.sv.forEach((t,n)=>{t<W(r,n)&&_o(e,U(n,t))}),ha(e,t.ds,e=>{}),n.add(t))},uo=class{constructor(){this.clients=new Map,this.pendingStructs=null,this.pendingDs=null}},fo=e=>{let t=new Map;return e.clients.forEach((e,n)=>{let r=e[e.length-1];t.set(n,r.id.clock+r.length)}),t},W=(e,t)=>{let n=e.clients.get(t);if(n===void 0)return 0;let r=n[n.length-1];return r.id.clock+r.length},po=(e,t)=>{let n=e.clients.get(t.id.client);if(n===void 0)n=[],e.clients.set(t.id.client,n);else{let e=n[n.length-1];if(e.id.clock+e.length!==t.id.clock)throw cn()}n.push(t)},mo=(e,t)=>{let n=0,r=e.length-1,i=e[r],a=i.id.clock;if(a===t)return r;let o=_t(t/(a+i.length-1)*r);for(;n<=r;){if(i=e[o],a=i.id.clock,a<=t){if(t<a+i.length)return o;n=o+1}else r=o-1;o=_t((n+r)/2)}throw cn()},ho=(e,t)=>{let n=e.clients.get(t.client);return n[mo(n,t.clock)]},go=(e,t,n)=>{let r=mo(t,n),i=t[r];return i.id.clock<n&&i instanceof Dc?(t.splice(r+1,0,Ec(e,i,n-i.id.clock)),r+1):r},_o=(e,t)=>{let n=e.doc.store.clients.get(t.client);return n[go(e,n,t.clock)]},vo=(e,t,n)=>{let r=t.clients.get(n.client),i=mo(r,n.clock),a=r[i];return n.clock!==a.id.clock+a.length-1&&a.constructor!==Qs&&r.splice(i+1,0,Ec(e,a,n.clock-a.id.clock+1)),a},yo=(e,t,n)=>{let r=e.clients.get(t.id.client);r[mo(r,t.id.clock)]=n},bo=(e,t,n,r,i)=>{if(r===0)return;let a=n+r,o=go(e,t,n),s;do s=t[o++],a<s.id.clock+s.length&&go(e,t,a),i(s);while(o<t.length&&t[o].id.clock<a)},xo=class{constructor(e,t,n){this.doc=e,this.deleteSet=new ma,this.beforeState=fo(e.store),this.afterState=new Map,this.changed=new Map,this.changedParentTypes=new Map,this._mergeStructs=[],this.origin=t,this.meta=new Map,this.local=n,this.subdocsAdded=new Set,this.subdocsRemoved=new Set,this.subdocsLoaded=new Set,this._needFormattingCleanup=!1}},So=(e,t)=>t.deleteSet.clients.size===0&&!ot(t.afterState,(e,n)=>t.beforeState.get(n)!==e)?!1:(va(t.deleteSet),Ba(e,t),Ca(e,t.deleteSet),!0),Co=(e,t,n)=>{let r=t._item;(r===null||r.id.clock<(e.beforeState.get(r.id.client)||0)&&!r.deleted)&&it(e.changed,t,st).add(n)},wo=(e,t)=>{let n=e[t],r=e[t-1],i=t;for(;i>0;n=r,r=e[--i-1]){if(r.deleted===n.deleted&&r.constructor===n.constructor&&r.mergeWith(n)){n instanceof Dc&&n.parentSub!==null&&n.parent._map.get(n.parentSub)===n&&n.parent._map.set(n.parentSub,r);continue}break}let a=t-i;return a&&e.splice(t+1-a,a),a},To=(e,t,n)=>{for(let[r,i]of e.clients.entries()){let e=t.clients.get(r);for(let r=i.length-1;r>=0;r--){let a=i[r],o=a.clock+a.len;for(let r=mo(e,a.clock),i=e[r];r<e.length&&i.id.clock<o;i=e[++r]){let i=e[r];if(a.clock+a.len<=i.id.clock)break;i instanceof Dc&&i.deleted&&!i.keep&&n(i)&&i.gc(t,!1)}}}},Eo=(e,t)=>{e.clients.forEach((e,n)=>{let r=t.clients.get(n);for(let t=e.length-1;t>=0;t--){let n=e[t],i=bt(r.length-1,1+mo(r,n.clock+n.len-1));for(let e=i,t=r[e];e>0&&t.id.clock>=n.clock;t=r[e])e-=1+wo(r,e)}})},Do=(e,t)=>{if(t<e.length){let n=e[t],r=n.doc,i=r.store,a=n.deleteSet,o=n._mergeStructs;try{va(a),n.afterState=fo(n.doc.store),r.emit(`beforeObserverCalls`,[n,r]);let e=[];n.changed.forEach((t,r)=>e.push(()=>{(r._item===null||!r._item.deleted)&&r._callObserver(n,t)})),e.push(()=>{n.changedParentTypes.forEach((t,r)=>{r._dEH.l.length>0&&(r._item===null||!r._item.deleted)&&(t=t.filter(e=>e.target._item===null||!e.target._item.deleted),t.forEach(e=>{e.currentTarget=r,e._path=null}),t.sort((e,t)=>e.path.length-t.path.length),e.push(()=>{ro(r._dEH,t,n)}))}),e.push(()=>r.emit(`afterTransaction`,[n,r])),e.push(()=>{n._needFormattingCleanup&&Fs(n)})}),$n(e,[])}finally{r.gc&&To(a,i,r.gcFilter),Eo(a,i),n.afterState.forEach((e,t)=>{let r=n.beforeState.get(t)||0;if(r!==e){let e=i.clients.get(t),n=xt(mo(e,r),1);for(let t=e.length-1;t>=n;)t-=1+wo(e,t)}});for(let e=o.length-1;e>=0;e--){let{client:t,clock:n}=o[e].id,r=i.clients.get(t),a=mo(r,n);a+1<r.length&&wo(r,a+1)>1||a>0&&wo(r,a)}if(!n.local&&n.afterState.get(r.clientID)!==n.beforeState.get(r.clientID)&&(oa(Zi,Wi,`[yjs] `,Gi,Yi,`Changed the client-id because another client seems to be using it.`),r.clientID=Ea()),r.emit(`afterTransactionCleanup`,[n,r]),r._observers.has(`update`)){let e=new Na;So(e,n)&&r.emit(`update`,[e.toUint8Array(),n.origin,r,n])}if(r._observers.has(`updateV2`)){let e=new Fa;So(e,n)&&r.emit(`updateV2`,[e.toUint8Array(),n.origin,r,n])}let{subdocsAdded:s,subdocsLoaded:c,subdocsRemoved:l}=n;(s.size>0||l.size>0||c.size>0)&&(s.forEach(e=>{e.clientID=r.clientID,e.collectionid??=r.collectionid,r.subdocs.add(e)}),l.forEach(e=>r.subdocs.delete(e)),r.emit(`subdocs`,[{loaded:c,added:s,removed:l},r,n]),l.forEach(e=>e.destroy())),e.length<=t+1?(r._transactionCleanups=[],r.emit(`afterAllTransactions`,[r,e])):Do(e,t+1)}}},G=(e,t,n=null,r=!0)=>{let i=e._transactionCleanups,a=!1,o=null;e._transaction===null&&(a=!0,e._transaction=new xo(e,n,r),i.push(e._transaction),i.length===1&&e.emit(`beforeAllTransactions`,[e]),e.emit(`beforeTransaction`,[e._transaction,e]));try{o=t(e._transaction)}finally{if(a){let t=e._transaction===i[0];e._transaction=null,t&&Do(i,0)}}return o};function*Oo(e){let t=B(e.restDecoder);for(let n=0;n<t;n++){let t=B(e.restDecoder),n=e.readClient(),r=B(e.restDecoder);for(let i=0;i<t;i++){let t=e.readInfo();if(t===10){let t=B(e.restDecoder);yield new jc(U(n,r),t),r+=t}else if(31&t){let i=(t&192)==0,a=new Dc(U(n,r),null,(t&128)==128?e.readLeftID():null,null,(t&64)==64?e.readRightID():null,i?e.readParentInfo()?e.readString():e.readLeftID():null,i&&(t&32)==32?e.readString():null,Oc(e,t));yield a,r+=a.length}else{let t=e.readLen();yield new Qs(U(n,r),t),r+=t}}}}var ko=class{constructor(e,t){this.gen=Oo(e),this.curr=null,this.done=!1,this.filterSkips=t,this.next()}next(){do this.curr=this.gen.next().value||null;while(this.filterSkips&&this.curr!==null&&this.curr.constructor===jc);return this.curr}},Ao=class{constructor(e){this.currClient=0,this.startClock=0,this.written=0,this.encoder=e,this.clientStructs=[]}},jo=e=>No(e,ka,Na),Mo=(e,t)=>{if(e.constructor===Qs){let{client:n,clock:r}=e.id;return new Qs(U(n,r+t),e.length-t)}else if(e.constructor===jc){let{client:n,clock:r}=e.id;return new jc(U(n,r+t),e.length-t)}else{let n=e,{client:r,clock:i}=n.id;return new Dc(U(r,i+t),null,U(r,i+t-1),null,n.rightOrigin,n.parent,n.parentSub,n.content.splice(t))}},No=(e,t=ja,n=Fa)=>{if(e.length===1)return e[0];let r=e.map(e=>new t(fn(e))),i=r.map(e=>new ko(e,!0)),a=null,o=new n,s=new Ao(o);for(;i=i.filter(e=>e.curr!==null),i.sort((e,t)=>{if(e.curr.id.client===t.curr.id.client){let n=e.curr.id.clock-t.curr.id.clock;return n===0?e.curr.constructor===t.curr.constructor?0:e.curr.constructor===jc?1:-1:n}else return t.curr.id.client-e.curr.id.client}),i.length!==0;){let e=i[0],t=e.curr.id.client;if(a!==null){let n=e.curr,r=!1;for(;n!==null&&n.id.clock+n.length<=a.struct.id.clock+a.struct.length&&n.id.client>=a.struct.id.client;)n=e.next(),r=!0;if(n===null||n.id.client!==t||r&&n.id.clock>a.struct.id.clock+a.struct.length)continue;if(t!==a.struct.id.client)Io(s,a.struct,a.offset),a={struct:n,offset:0},e.next();else if(a.struct.id.clock+a.struct.length<n.id.clock)if(a.struct.constructor===jc)a.struct.length=n.id.clock+n.length-a.struct.id.clock;else{Io(s,a.struct,a.offset);let e=n.id.clock-a.struct.id.clock-a.struct.length;a={struct:new jc(U(t,a.struct.id.clock+a.struct.length),e),offset:0}}else{let t=a.struct.id.clock+a.struct.length-n.id.clock;t>0&&(a.struct.constructor===jc?a.struct.length-=t:n=Mo(n,t)),a.struct.mergeWith(n)||(Io(s,a.struct,a.offset),a={struct:n,offset:0},e.next())}}else a={struct:e.curr,offset:0},e.next();for(let n=e.curr;n!==null&&n.id.client===t&&n.id.clock===a.struct.id.clock+a.struct.length&&n.constructor!==jc;n=e.next())Io(s,a.struct,a.offset),a={struct:n,offset:0}}return a!==null&&(Io(s,a.struct,a.offset),a=null),Lo(s),Ca(o,ya(r.map(e=>wa(e)))),o.toUint8Array()},Po=(e,t,n=ja,r=Fa)=>{let i=Ja(t),a=new r,o=new Ao(a),s=new n(fn(e)),c=new ko(s,!1);for(;c.curr;){let e=c.curr,t=e.id.client,n=i.get(t)||0;if(c.curr.constructor===jc){c.next();continue}if(e.id.clock+e.length>n)for(Io(o,e,xt(n-e.id.clock,0)),c.next();c.curr&&c.curr.id.client===t;)Io(o,c.curr,0),c.next();else for(;c.curr&&c.curr.id.client===t&&c.curr.id.clock+c.curr.length<=n;)c.next()}return Lo(o),Ca(a,wa(s)),a.toUint8Array()},Fo=e=>{e.written>0&&(e.clientStructs.push({written:e.written,restEncoder:F(e.encoder.restEncoder)}),e.encoder.restEncoder=P(),e.written=0)},Io=(e,t,n)=>{e.written>0&&e.currClient!==t.id.client&&Fo(e),e.written===0&&(e.currClient=t.id.client,e.encoder.writeClient(t.id.client),L(e.encoder.restEncoder,t.id.clock+n)),t.write(e.encoder,n),e.written++},Lo=e=>{Fo(e);let t=e.encoder.restEncoder;L(t,e.clientStructs.length);for(let n=0;n<e.clientStructs.length;n++){let r=e.clientStructs[n];L(t,r.written),Gt(t,r.restEncoder)}},Ro=(e,t,n,r)=>{let i=new n(fn(e)),a=new ko(i,!1),o=new r,s=new Ao(o);for(let e=a.curr;e!==null;e=a.next())Io(s,t(e),0);return Lo(s),Ca(o,wa(i)),o.toUint8Array()},zo=e=>Ro(e,tr,ja,Na),Bo=`You must not compute changes after the event-handler fired.`,Vo=class{constructor(e,t){this.target=e,this.currentTarget=e,this.transaction=t,this._changes=null,this._keys=null,this._delta=null,this._path=null}get path(){return this._path||=Ho(this.currentTarget,this.target)}deletes(e){return _a(this.transaction.deleteSet,e.id)}get keys(){if(this._keys===null){if(this.transaction.doc._transactionCleanups.length===0)throw on(Bo);let e=new Map,t=this.target;this.transaction.changed.get(t).forEach(n=>{if(n!==null){let r=t._map.get(n),i,a;if(this.adds(r)){let e=r.left;for(;e!==null&&this.adds(e);)e=e.left;if(this.deletes(r))if(e!==null&&this.deletes(e))i=`delete`,a=ct(e.content.getContent());else return;else e!==null&&this.deletes(e)?(i=`update`,a=ct(e.content.getContent())):(i=`add`,a=void 0)}else if(this.deletes(r))i=`delete`,a=ct(r.content.getContent());else return;e.set(n,{action:i,oldValue:a})}}),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 on(Bo);let t=this.target,n=st(),r=st(),i=[];if(e={added:n,deleted:r,delta:i,keys:this.keys},this.transaction.changed.get(t).has(null)){let e=null,a=()=>{e&&i.push(e)};for(let i=t._start;i!==null;i=i.right)i.deleted?this.deletes(i)&&!this.adds(i)&&((e===null||e.delete===void 0)&&(a(),e={delete:0}),e.delete+=i.length,r.add(i)):this.adds(i)?((e===null||e.insert===void 0)&&(a(),e={insert:[]}),e.insert=e.insert.concat(i.content.getContent()),n.add(i)):((e===null||e.retain===void 0)&&(a(),e={retain:0}),e.retain+=i.length);e!==null&&e.retain===void 0&&a()}this._changes=e}return e}},Ho=(e,t)=>{let n=[];for(;t._item!==null&&t!==e;){if(t._item.parentSub!==null)n.unshift(t._item.parentSub);else{let e=0,r=t._item.parent._start;for(;r!==t._item&&r!==null;)!r.deleted&&r.countable&&(e+=r.length),r=r.right;n.unshift(e)}t=t._item.parent}return n},K=()=>{sa(`Invalid access: Add Yjs type to a document before reading data.`)},Uo=80,Wo=0,Go=class{constructor(e,t){e.marker=!0,this.p=e,this.index=t,this.timestamp=Wo++}},Ko=e=>{e.timestamp=Wo++},qo=(e,t,n)=>{e.p.marker=!1,e.p=t,t.marker=!0,e.index=n,e.timestamp=Wo++},Jo=(e,t,n)=>{if(e.length>=Uo){let r=e.reduce((e,t)=>e.timestamp<t.timestamp?e:t);return qo(r,t,n),r}else{let r=new Go(t,n);return e.push(r),r}},Yo=(e,t)=>{if(e._start===null||t===0||e._searchMarker===null)return null;let n=e._searchMarker.length===0?null:e._searchMarker.reduce((e,n)=>vt(t-e.index)<vt(t-n.index)?e:n),r=e._start,i=0;for(n!==null&&(r=n.p,i=n.index,Ko(n));r.right!==null&&i<t;){if(!r.deleted&&r.countable){if(t<i+r.length)break;i+=r.length}r=r.right}for(;r.left!==null&&i>t;)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 n!==null&&vt(n.index-i)<r.parent.length/Uo?(qo(n,r,i),n):Jo(e._searchMarker,r,i)},Xo=(e,t,n)=>{for(let r=e.length-1;r>=0;r--){let i=e[r];if(n>0){let t=i.p;for(t.marker=!1;t&&(t.deleted||!t.countable);)t=t.left,t&&!t.deleted&&t.countable&&(i.index-=t.length);if(t===null||t.marker===!0){e.splice(r,1);continue}i.p=t,t.marker=!0}(t<i.index||n>0&&t===i.index)&&(i.index=xt(t,i.index+n))}},Zo=(e,t,n)=>{let r=e,i=t.changedParentTypes;for(;it(i,e,()=>[]).push(n),e._item!==null;)e=e._item.parent;ro(r._eH,n,t)},q=class{constructor(){this._item=null,this._map=new Map,this._start=null,this.doc=null,this._length=0,this._eH=eo(),this._dEH=eo(),this._searchMarker=null}get parent(){return this._item?this._item.parent:null}_integrate(e,t){this.doc=e,this._item=t}_copy(){throw sn()}clone(){throw sn()}_write(e){}get _first(){let e=this._start;for(;e!==null&&e.deleted;)e=e.right;return e}_callObserver(e,t){!e.local&&this._searchMarker&&(this._searchMarker.length=0)}observe(e){to(this._eH,e)}observeDeep(e){to(this._dEH,e)}unobserve(e){no(this._eH,e)}unobserveDeep(e){no(this._dEH,e)}toJSON(){}},Qo=(e,t,n)=>{e.doc??K(),t<0&&(t=e._length+t),n<0&&(n=e._length+n);let r=n-t,i=[],a=e._start;for(;a!==null&&r>0;){if(a.countable&&!a.deleted){let e=a.content.getContent();if(e.length<=t)t-=e.length;else{for(let n=t;n<e.length&&r>0;n++)i.push(e[n]),r--;t=0}}a=a.right}return i},$o=e=>{e.doc??K();let t=[],n=e._start;for(;n!==null;){if(n.countable&&!n.deleted){let e=n.content.getContent();for(let n=0;n<e.length;n++)t.push(e[n])}n=n.right}return t},es=(e,t)=>{let n=0,r=e._start;for(e.doc??K();r!==null;){if(r.countable&&!r.deleted){let i=r.content.getContent();for(let r=0;r<i.length;r++)t(i[r],n++,e)}r=r.right}},ts=(e,t)=>{let n=[];return es(e,(r,i)=>{n.push(t(r,i,e))}),n},ns=e=>{let t=e._start,n=null,r=0;return{[Symbol.iterator](){return this},next:()=>{if(n===null){for(;t!==null&&t.deleted;)t=t.right;if(t===null)return{done:!0,value:void 0};n=t.content.getContent(),r=0,t=t.right}let e=n[r++];return n.length<=r&&(n=null),{done:!1,value:e}}}},rs=(e,t)=>{e.doc??K();let n=Yo(e,t),r=e._start;for(n!==null&&(r=n.p,t-=n.index);r!==null;r=r.right)if(!r.deleted&&r.countable){if(t<r.length)return r.content.getContent()[t];t-=r.length}},is=(e,t,n,r)=>{let i=n,a=e.doc,o=a.clientID,s=a.store,c=n===null?t._start:n.right,l=[],u=()=>{l.length>0&&(i=new Dc(U(o,W(s,o)),i,i&&i.lastId,c,c&&c.id,t,null,new fc(l)),i.integrate(e,0),l=[])};r.forEach(n=>{if(n===null)l.push(n);else switch(n.constructor){case Number:case Object:case Boolean:case Array:case String:l.push(n);break;default:switch(u(),n.constructor){case Uint8Array:case ArrayBuffer:i=new Dc(U(o,W(s,o)),i,i&&i.lastId,c,c&&c.id,t,null,new $s(new Uint8Array(n))),i.integrate(e,0);break;case Da:i=new Dc(U(o,W(s,o)),i,i&&i.lastId,c,c&&c.id,t,null,new ic(n)),i.integrate(e,0);break;default:if(n instanceof q)i=new Dc(U(o,W(s,o)),i,i&&i.lastId,c,c&&c.id,t,null,new wc(n)),i.integrate(e,0);else throw Error(`Unexpected content type in insert operation`)}}}),u()},as=()=>on(`Length exceeded!`),os=(e,t,n,r)=>{if(n>t._length)throw as();if(n===0)return t._searchMarker&&Xo(t._searchMarker,n,r.length),is(e,t,null,r);let i=n,a=Yo(t,n),o=t._start;for(a!==null&&(o=a.p,n-=a.index,n===0&&(o=o.prev,n+=o&&o.countable&&!o.deleted?o.length:0));o!==null;o=o.right)if(!o.deleted&&o.countable){if(n<=o.length){n<o.length&&_o(e,U(o.id.client,o.id.clock+n));break}n-=o.length}return t._searchMarker&&Xo(t._searchMarker,i,r.length),is(e,t,o,r)},ss=(e,t,n)=>{let r=(t._searchMarker||[]).reduce((e,t)=>t.index>e.index?t:e,{index:0,p:t._start}).p;if(r)for(;r.right;)r=r.right;return is(e,t,r,n)},cs=(e,t,n,r)=>{if(r===0)return;let i=n,a=r,o=Yo(t,n),s=t._start;for(o!==null&&(s=o.p,n-=o.index);s!==null&&n>0;s=s.right)!s.deleted&&s.countable&&(n<s.length&&_o(e,U(s.id.client,s.id.clock+n)),n-=s.length);for(;r>0&&s!==null;)s.deleted||(r<s.length&&_o(e,U(s.id.client,s.id.clock+r)),s.delete(e),r-=s.length),s=s.right;if(r>0)throw as();t._searchMarker&&Xo(t._searchMarker,i,-a+r)},ls=(e,t,n)=>{let r=t._map.get(n);r!==void 0&&r.delete(e)},us=(e,t,n,r)=>{let i=t._map.get(n)||null,a=e.doc,o=a.clientID,s;if(r==null)s=new fc([r]);else switch(r.constructor){case Number:case Object:case Boolean:case Array:case String:case Date:case BigInt:s=new fc([r]);break;case Uint8Array:s=new $s(r);break;case Da:s=new ic(r);break;default:if(r instanceof q)s=new wc(r);else throw Error(`Unexpected content type`)}new Dc(U(o,W(a.store,o)),i,i&&i.lastId,null,null,t,n,s).integrate(e,0)},ds=(e,t)=>{e.doc??K();let n=e._map.get(t);return n!==void 0&&!n.deleted?n.content.getContent()[n.length-1]:void 0},fs=e=>{let t={};return e.doc??K(),e._map.forEach((e,n)=>{e.deleted||(t[n]=e.content.getContent()[e.length-1])}),t},ps=(e,t)=>{e.doc??K();let n=e._map.get(t);return n!==void 0&&!n.deleted},ms=(e,t)=>{let n={};return e._map.forEach((e,r)=>{let i=e;for(;i!==null&&(!t.sv.has(i.id.client)||i.id.clock>=(t.sv.get(i.id.client)||0));)i=i.left;i!==null&&co(i,t)&&(n[r]=i.content.getContent()[i.length-1])}),n},hs=e=>(e.doc??K(),da(e._map.entries(),e=>!e[1].deleted)),gs=class extends Vo{},_s=class e extends q{constructor(){super(),this._prelimContent=[],this._searchMarker=[]}static from(t){let n=new e;return n.push(t),n}_integrate(e,t){super._integrate(e,t),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new e}clone(){let t=new e;return t.insert(0,this.toArray().map(e=>e instanceof q?e.clone():e)),t}get length(){return this.doc??K(),this._length}_callObserver(e,t){super._callObserver(e,t),Zo(this,e,new gs(this,e))}insert(e,t){this.doc===null?this._prelimContent.splice(e,0,...t):G(this.doc,n=>{os(n,this,e,t)})}push(e){this.doc===null?this._prelimContent.push(...e):G(this.doc,t=>{ss(t,this,e)})}unshift(e){this.insert(0,e)}delete(e,t=1){this.doc===null?this._prelimContent.splice(e,t):G(this.doc,n=>{cs(n,this,e,t)})}get(e){return rs(this,e)}toArray(){return $o(this)}slice(e=0,t=this.length){return Qo(this,e,t)}toJSON(){return this.map(e=>e instanceof q?e.toJSON():e)}map(e){return ts(this,e)}forEach(e){es(this,e)}[Symbol.iterator](){return ns(this)}_write(e){e.writeTypeRef(_c)}},vs=e=>new _s,ys=class extends Vo{constructor(e,t,n){super(e,t),this.keysChanged=n}},bs=class e extends q{constructor(e){super(),this._prelimContent=null,e===void 0?this._prelimContent=new Map:this._prelimContent=new Map(e)}_integrate(e,t){super._integrate(e,t),this._prelimContent.forEach((e,t)=>{this.set(t,e)}),this._prelimContent=null}_copy(){return new e}clone(){let t=new e;return this.forEach((e,n)=>{t.set(n,e instanceof q?e.clone():e)}),t}_callObserver(e,t){Zo(this,e,new ys(this,e,t))}toJSON(){this.doc??K();let e={};return this._map.forEach((t,n)=>{if(!t.deleted){let r=t.content.getContent()[t.length-1];e[n]=r instanceof q?r.toJSON():r}}),e}get size(){return[...hs(this)].length}keys(){return fa(hs(this),e=>e[0])}values(){return fa(hs(this),e=>e[1].content.getContent()[e[1].length-1])}entries(){return fa(hs(this),e=>[e[0],e[1].content.getContent()[e[1].length-1]])}forEach(e){this.doc??K(),this._map.forEach((t,n)=>{t.deleted||e(t.content.getContent()[t.length-1],n,this)})}[Symbol.iterator](){return this.entries()}delete(e){this.doc===null?this._prelimContent.delete(e):G(this.doc,t=>{ls(t,this,e)})}set(e,t){return this.doc===null?this._prelimContent.set(e,t):G(this.doc,n=>{us(n,this,e,t)}),t}get(e){return ds(this,e)}has(e){return ps(this,e)}clear(){this.doc===null?this._prelimContent.clear():G(this.doc,e=>{this.forEach(function(t,n,r){ls(e,r,n)})})}_write(e){e.writeTypeRef(vc)}},xs=e=>new bs,Ss=(e,t)=>e===t||typeof e==`object`&&typeof t==`object`&&e&&t&&Xn(e,t),Cs=class{constructor(e,t,n,r){this.left=e,this.right=t,this.index=n,this.currentAttributes=r}forward(){switch(this.right===null&&cn(),this.right.content.constructor){case J:this.right.deleted||Ds(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}},ws=(e,t,n)=>{for(;t.right!==null&&n>0;){switch(t.right.content.constructor){case J:t.right.deleted||Ds(t.currentAttributes,t.right.content);break;default:t.right.deleted||(n<t.right.length&&_o(e,U(t.right.id.client,t.right.id.clock+n)),t.index+=t.right.length,n-=t.right.length);break}t.left=t.right,t.right=t.right.right}return t},Ts=(e,t,n,r)=>{let i=new Map,a=r?Yo(t,n):null;return a?ws(e,new Cs(a.p.left,a.p,a.index,i),n-a.index):ws(e,new Cs(null,t._start,0,i),n)},Es=(e,t,n,r)=>{for(;n.right!==null&&(n.right.deleted===!0||n.right.content.constructor===J&&Ss(r.get(n.right.content.key),n.right.content.value));)n.right.deleted||r.delete(n.right.content.key),n.forward();let i=e.doc,a=i.clientID;r.forEach((r,o)=>{let s=n.left,c=n.right,l=new Dc(U(a,W(i.store,a)),s,s&&s.lastId,c,c&&c.id,t,null,new J(o,r));l.integrate(e,0),n.right=l,n.forward()})},Ds=(e,t)=>{let{key:n,value:r}=t;r===null?e.delete(n):e.set(n,r)},Os=(e,t)=>{for(;e.right!==null&&(e.right.deleted||e.right.content.constructor===J&&Ss(t[e.right.content.key]??null,e.right.content.value));)e.forward()},ks=(e,t,n,r)=>{let i=e.doc,a=i.clientID,o=new Map;for(let s in r){let c=r[s],l=n.currentAttributes.get(s)??null;if(!Ss(l,c)){o.set(s,l);let{left:r,right:u}=n;n.right=new Dc(U(a,W(i.store,a)),r,r&&r.lastId,u,u&&u.id,t,null,new J(s,c)),n.right.integrate(e,0),n.forward()}}return o},As=(e,t,n,r,i)=>{n.currentAttributes.forEach((e,t)=>{i[t]===void 0&&(i[t]=null)});let a=e.doc,o=a.clientID;Os(n,i);let s=ks(e,t,n,i),c=r.constructor===String?new mc(r):r instanceof q?new wc(r):new oc(r),{left:l,right:u,index:d}=n;t._searchMarker&&Xo(t._searchMarker,n.index,c.getLength()),u=new Dc(U(o,W(a.store,o)),l,l&&l.lastId,u,u&&u.id,t,null,c),u.integrate(e,0),n.right=u,n.index=d,n.forward(),Es(e,t,n,s)},js=(e,t,n,r,i)=>{let a=e.doc,o=a.clientID;Os(n,i);let s=ks(e,t,n,i);iterationLoop:for(;n.right!==null&&(r>0||s.size>0&&(n.right.deleted||n.right.content.constructor===J));){if(!n.right.deleted)switch(n.right.content.constructor){case J:{let{key:t,value:a}=n.right.content,o=i[t];if(o!==void 0){if(Ss(o,a))s.delete(t);else{if(r===0)break iterationLoop;s.set(t,a)}n.right.delete(e)}else n.currentAttributes.set(t,a);break}default:r<n.right.length&&_o(e,U(n.right.id.client,n.right.id.clock+r)),r-=n.right.length;break}n.forward()}if(r>0){let i=``;for(;r>0;r--)i+=`
|
|
4
|
+
`;n.right=new Dc(U(o,W(a.store,o)),n.left,n.left&&n.left.lastId,n.right,n.right&&n.right.id,t,null,new mc(i)),n.right.integrate(e,0),n.forward()}Es(e,t,n,s)},Ms=(e,t,n,r,i)=>{let a=t,o=nt();for(;a&&(!a.countable||a.deleted);){if(!a.deleted&&a.content.constructor===J){let e=a.content;o.set(e.key,e)}a=a.right}let s=0,c=!1;for(;t!==a;){if(n===t&&(c=!0),!t.deleted){let n=t.content;switch(n.constructor){case J:{let{key:a,value:l}=n,u=r.get(a)??null;(o.get(a)!==n||u===l)&&(t.delete(e),s++,!c&&(i.get(a)??null)===l&&u!==l&&(u===null?i.delete(a):i.set(a,u))),!c&&!t.deleted&&Ds(i,n);break}}}t=t.right}return s},Ns=(e,t)=>{for(;t&&t.right&&(t.right.deleted||!t.right.countable);)t=t.right;let n=new Set;for(;t&&(t.deleted||!t.countable);){if(!t.deleted&&t.content.constructor===J){let r=t.content.key;n.has(r)?t.delete(e):n.add(r)}t=t.left}},Ps=e=>{let t=0;return G(e.doc,n=>{let r=e._start,i=e._start,a=nt(),o=rt(a);for(;i;){if(i.deleted===!1)switch(i.content.constructor){case J:Ds(o,i.content);break;default:t+=Ms(n,r,i,a,o),a=rt(o),r=i;break}i=i.right}}),t},Fs=e=>{let t=new Set,n=e.doc;for(let[r,i]of e.afterState.entries()){let a=e.beforeState.get(r)||0;i!==a&&bo(e,n.store.clients.get(r),a,i,e=>{!e.deleted&&e.content.constructor===J&&e.constructor!==Qs&&t.add(e.parent)})}G(n,n=>{ha(e,e.deleteSet,e=>{if(e instanceof Qs||!e.parent._hasFormatting||t.has(e.parent))return;let r=e.parent;e.content.constructor===J?t.add(r):Ns(n,e)});for(let e of t)Ps(e)})},Is=(e,t,n)=>{let r=n,i=rt(t.currentAttributes),a=t.right;for(;n>0&&t.right!==null;){if(t.right.deleted===!1)switch(t.right.content.constructor){case wc:case oc:case mc:n<t.right.length&&_o(e,U(t.right.id.client,t.right.id.clock+n)),n-=t.right.length,t.right.delete(e);break}t.forward()}a&&Ms(e,a,t.right,i,t.currentAttributes);let o=(t.left||t.right).parent;return o._searchMarker&&Xo(o._searchMarker,t.index,-r+n),t},Ls=class extends Vo{constructor(e,t,n){super(e,t),this.childListChanged=!1,this.keysChanged=new Set,n.forEach(e=>{e===null?this.childListChanged=!0:this.keysChanged.add(e)})}get changes(){if(this._changes===null){let 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){let e=this.target.doc,t=[];G(e,e=>{let n=new Map,r=new Map,i=this.target._start,a=null,o={},s=``,c=0,l=0,u=()=>{if(a!==null){let e=null;switch(a){case`delete`:l>0&&(e={delete:l}),l=0;break;case`insert`:(typeof s==`object`||s.length>0)&&(e={insert:s},n.size>0&&(e.attributes={},n.forEach((t,n)=>{t!==null&&(e.attributes[n]=t)}))),s=``;break;case`retain`:c>0&&(e={retain:c},qn(o)||(e.attributes=Un({},o))),c=0;break}e&&t.push(e),a=null}};for(;i!==null;){switch(i.content.constructor){case wc:case oc:this.adds(i)?this.deletes(i)||(u(),a=`insert`,s=i.content.getContent()[0],u()):this.deletes(i)?(a!==`delete`&&(u(),a=`delete`),l+=1):i.deleted||(a!==`retain`&&(u(),a=`retain`),c+=1);break;case mc:this.adds(i)?this.deletes(i)||(a!==`insert`&&(u(),a=`insert`),s+=i.content.str):this.deletes(i)?(a!==`delete`&&(u(),a=`delete`),l+=i.length):i.deleted||(a!==`retain`&&(u(),a=`retain`),c+=i.length);break;case J:{let{key:t,value:s}=i.content;if(this.adds(i))this.deletes(i)||(Ss(n.get(t)??null,s)?s!==null&&i.delete(e):(a===`retain`&&u(),Ss(s,r.get(t)??null)?delete o[t]:o[t]=s));else if(this.deletes(i)){r.set(t,s);let e=n.get(t)??null;Ss(e,s)||(a===`retain`&&u(),o[t]=e)}else if(!i.deleted){r.set(t,s);let n=o[t];n!==void 0&&(Ss(n,s)?n!==null&&i.delete(e):(a===`retain`&&u(),s===null?delete o[t]:o[t]=s))}i.deleted||(a===`insert`&&u(),Ds(n,i.content));break}}i=i.right}for(u();t.length>0;){let e=t[t.length-1];if(e.retain!==void 0&&e.attributes===void 0)t.pop();else break}}),this._delta=t}return this._delta}},Rs=class e extends q{constructor(e){super(),this._pending=e===void 0?[]:[()=>this.insert(0,e)],this._searchMarker=[],this._hasFormatting=!1}get length(){return this.doc??K(),this._length}_integrate(e,t){super._integrate(e,t);try{this._pending.forEach(e=>e())}catch(e){console.error(e)}this._pending=null}_copy(){return new e}clone(){let t=new e;return t.applyDelta(this.toDelta()),t}_callObserver(e,t){super._callObserver(e,t);let n=new Ls(this,e,t);Zo(this,e,n),!e.local&&this._hasFormatting&&(e._needFormattingCleanup=!0)}toString(){this.doc??K();let e=``,t=this._start;for(;t!==null;)!t.deleted&&t.countable&&t.content.constructor===mc&&(e+=t.content.str),t=t.right;return e}toJSON(){return this.toString()}applyDelta(e,{sanitize:t=!0}={}){this.doc===null?this._pending.push(()=>this.applyDelta(e)):G(this.doc,n=>{let r=new Cs(null,this._start,0,new Map);for(let i=0;i<e.length;i++){let a=e[i];if(a.insert!==void 0){let o=!t&&typeof a.insert==`string`&&i===e.length-1&&r.right===null&&a.insert.slice(-1)===`
|
|
5
|
+
`?a.insert.slice(0,-1):a.insert;(typeof o!=`string`||o.length>0)&&As(n,this,r,o,a.attributes||{})}else a.retain===void 0?a.delete!==void 0&&Is(n,r,a.delete):js(n,this,r,a.retain,a.attributes||{})}})}toDelta(e,t,n){this.doc??K();let r=[],i=new Map,a=this.doc,o=``,s=this._start;function c(){if(o.length>0){let e={},t=!1;i.forEach((n,r)=>{t=!0,e[r]=n});let n={insert:o};t&&(n.attributes=e),r.push(n),o=``}}let l=()=>{for(;s!==null;){if(co(s,e)||t!==void 0&&co(s,t))switch(s.content.constructor){case mc:{let r=i.get(`ychange`);e!==void 0&&!co(s,e)?(r===void 0||r.user!==s.id.client||r.type!==`removed`)&&(c(),i.set(`ychange`,n?n(`removed`,s.id):{type:`removed`})):t!==void 0&&!co(s,t)?(r===void 0||r.user!==s.id.client||r.type!==`added`)&&(c(),i.set(`ychange`,n?n(`added`,s.id):{type:`added`})):r!==void 0&&(c(),i.delete(`ychange`)),o+=s.content.str;break}case wc:case oc:{c();let e={insert:s.content.getContent()[0]};if(i.size>0){let t={};e.attributes=t,i.forEach((e,n)=>{t[n]=e})}r.push(e);break}case J:co(s,e)&&(c(),Ds(i,s.content));break}s=s.right}c()};return e||t?G(a,n=>{e&&lo(n,e),t&&lo(n,t),l()},`cleanup`):l(),r}insert(e,t,n){if(t.length<=0)return;let r=this.doc;r===null?this._pending.push(()=>this.insert(e,t,n)):G(r,r=>{let i=Ts(r,this,e,!n);n||(n={},i.currentAttributes.forEach((e,t)=>{n[t]=e})),As(r,this,i,t,n)})}insertEmbed(e,t,n){let r=this.doc;r===null?this._pending.push(()=>this.insertEmbed(e,t,n||{})):G(r,r=>{let i=Ts(r,this,e,!n);As(r,this,i,t,n||{})})}delete(e,t){if(t===0)return;let n=this.doc;n===null?this._pending.push(()=>this.delete(e,t)):G(n,n=>{Is(n,Ts(n,this,e,!0),t)})}format(e,t,n){if(t===0)return;let r=this.doc;r===null?this._pending.push(()=>this.format(e,t,n)):G(r,r=>{let i=Ts(r,this,e,!1);i.right!==null&&js(r,this,i,t,n)})}removeAttribute(e){this.doc===null?this._pending.push(()=>this.removeAttribute(e)):G(this.doc,t=>{ls(t,this,e)})}setAttribute(e,t){this.doc===null?this._pending.push(()=>this.setAttribute(e,t)):G(this.doc,n=>{us(n,this,e,t)})}getAttribute(e){return ds(this,e)}getAttributes(){return fs(this)}_write(e){e.writeTypeRef(yc)}},zs=e=>new Rs,Bs=class{constructor(e,t=()=>!0){this._filter=t,this._root=e,this._currentNode=e._start,this._firstCall=!0,e.doc??K()}[Symbol.iterator](){return this}next(){let e=this._currentNode,t=e&&e.content&&e.content.type;if(e!==null&&(!this._firstCall||e.deleted||!this._filter(t)))do if(t=e.content.type,!e.deleted&&(t.constructor===Us||t.constructor===Vs)&&t._start!==null)e=t._start;else for(;e!==null;){let t=e.next;if(t!==null){e=t;break}else e=e.parent===this._root?null: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})}},Vs=class e extends q{constructor(){super(),this._prelimContent=[]}get firstChild(){let e=this._first;return e?e.content.getContent()[0]:null}_integrate(e,t){super._integrate(e,t),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new e}clone(){let t=new e;return t.insert(0,this.toArray().map(e=>e instanceof q?e.clone():e)),t}get length(){return this.doc??K(),this._prelimContent===null?this._length:this._prelimContent.length}createTreeWalker(e){return new Bs(this,e)}querySelector(e){e=e.toUpperCase();let t=new Bs(this,t=>t.nodeName&&t.nodeName.toUpperCase()===e).next();return t.done?null:t.value}querySelectorAll(e){return e=e.toUpperCase(),ut(new Bs(this,t=>t.nodeName&&t.nodeName.toUpperCase()===e))}_callObserver(e,t){Zo(this,e,new Gs(this,t,e))}toString(){return ts(this,e=>e.toString()).join(``)}toJSON(){return this.toString()}toDOM(e=document,t={},n){let r=e.createDocumentFragment();return n!==void 0&&n._createAssociation(r,this),es(this,i=>{r.insertBefore(i.toDOM(e,t,n),null)}),r}insert(e,t){this.doc===null?this._prelimContent.splice(e,0,...t):G(this.doc,n=>{os(n,this,e,t)})}insertAfter(e,t){if(this.doc!==null)G(this.doc,n=>{let r=e&&e instanceof q?e._item:e;is(n,this,r,t)});else{let n=this._prelimContent,r=e===null?0:n.findIndex(t=>t===e)+1;if(r===0&&e!==null)throw on(`Reference item not found`);n.splice(r,0,...t)}}delete(e,t=1){this.doc===null?this._prelimContent.splice(e,t):G(this.doc,n=>{cs(n,this,e,t)})}toArray(){return $o(this)}push(e){this.insert(this.length,e)}unshift(e){this.insert(0,e)}get(e){return rs(this,e)}slice(e=0,t=this.length){return Qo(this,e,t)}forEach(e){es(this,e)}_write(e){e.writeTypeRef(xc)}},Hs=e=>new Vs,Us=class e extends Vs{constructor(e=`UNDEFINED`){super(),this.nodeName=e,this._prelimAttrs=new Map}get nextSibling(){let e=this._item?this._item.next:null;return e?e.content.type:null}get prevSibling(){let e=this._item?this._item.prev:null;return e?e.content.type:null}_integrate(e,t){super._integrate(e,t),this._prelimAttrs.forEach((e,t)=>{this.setAttribute(t,e)}),this._prelimAttrs=null}_copy(){return new e(this.nodeName)}clone(){let t=new e(this.nodeName);return Gn(this.getAttributes(),(e,n)=>{t.setAttribute(n,e)}),t.insert(0,this.toArray().map(e=>e instanceof q?e.clone():e)),t}toString(){let e=this.getAttributes(),t=[],n=[];for(let t in e)n.push(t);n.sort();let r=n.length;for(let i=0;i<r;i++){let r=n[i];t.push(r+`="`+e[r]+`"`)}let i=this.nodeName.toLocaleLowerCase();return`<${i}${t.length>0?` `+t.join(` `):``}>${super.toString()}</${i}>`}removeAttribute(e){this.doc===null?this._prelimAttrs.delete(e):G(this.doc,t=>{ls(t,this,e)})}setAttribute(e,t){this.doc===null?this._prelimAttrs.set(e,t):G(this.doc,n=>{us(n,this,e,t)})}getAttribute(e){return ds(this,e)}hasAttribute(e){return ps(this,e)}getAttributes(e){return e?ms(this,e):fs(this)}toDOM(e=document,t={},n){let r=e.createElement(this.nodeName),i=this.getAttributes();for(let e in i){let t=i[e];typeof t==`string`&&r.setAttribute(e,t)}return es(this,i=>{r.appendChild(i.toDOM(e,t,n))}),n!==void 0&&n._createAssociation(r,this),r}_write(e){e.writeTypeRef(bc),e.writeKey(this.nodeName)}},Ws=e=>new Us(e.readKey()),Gs=class extends Vo{constructor(e,t,n){super(e,n),this.childListChanged=!1,this.attributesChanged=new Set,t.forEach(e=>{e===null?this.childListChanged=!0:this.attributesChanged.add(e)})}},Ks=class e extends bs{constructor(e){super(),this.hookName=e}_copy(){return new e(this.hookName)}clone(){let t=new e(this.hookName);return this.forEach((e,n)=>{t.set(n,e)}),t}toDOM(e=document,t={},n){let r=t[this.hookName],i;return i=r===void 0?document.createElement(this.hookName):r.createDom(this),i.setAttribute(`data-yjs-hook`,this.hookName),n!==void 0&&n._createAssociation(i,this),i}_write(e){e.writeTypeRef(Sc),e.writeKey(this.hookName)}},qs=e=>new Ks(e.readKey()),Js=class e extends Rs{get nextSibling(){let e=this._item?this._item.next:null;return e?e.content.type:null}get prevSibling(){let e=this._item?this._item.prev:null;return e?e.content.type:null}_copy(){return new e}clone(){let t=new e;return t.applyDelta(this.toDelta()),t}toDOM(e=document,t,n){let r=e.createTextNode(this.toString());return n!==void 0&&n._createAssociation(r,this),r}toString(){return this.toDelta().map(e=>{let t=[];for(let n in e.attributes){let r=[];for(let t in e.attributes[n])r.push({key:t,value:e.attributes[n][t]});r.sort((e,t)=>e.key<t.key?-1:1),t.push({nodeName:n,attrs:r})}t.sort((e,t)=>e.nodeName<t.nodeName?-1:1);let n=``;for(let e=0;e<t.length;e++){let r=t[e];n+=`<${r.nodeName}`;for(let e=0;e<r.attrs.length;e++){let t=r.attrs[e];n+=` ${t.key}="${t.value}"`}n+=`>`}n+=e.insert;for(let e=t.length-1;e>=0;e--)n+=`</${t[e].nodeName}>`;return n}).join(``)}toJSON(){return this.toString()}_write(e){e.writeTypeRef(Cc)}},Ys=e=>new Js,Xs=class{constructor(e,t){this.id=e,this.length=t}get deleted(){throw sn()}mergeWith(e){return!1}write(e,t,n){throw sn()}integrate(e,t){throw sn()}},Zs=0,Qs=class extends Xs{get deleted(){return!0}delete(){}mergeWith(e){return this.constructor===e.constructor?(this.length+=e.length,!0):!1}integrate(e,t){t>0&&(this.id.clock+=t,this.length-=t),po(e.doc.store,this)}write(e,t){e.writeInfo(Zs),e.writeLen(this.length-t)}getMissing(e,t){return null}},$s=class e{constructor(e){this.content=e}getLength(){return 1}getContent(){return[this.content]}isCountable(){return!0}copy(){return new e(this.content)}splice(e){throw sn()}mergeWith(e){return!1}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeBuf(this.content)}getRef(){return 3}},ec=e=>new $s(e.readBuf()),tc=class e{constructor(e){this.len=e}getLength(){return this.len}getContent(){return[]}isCountable(){return!1}copy(){return new e(this.len)}splice(t){let n=new e(this.len-t);return this.len=t,n}mergeWith(e){return this.len+=e.len,!0}integrate(e,t){ba(e.deleteSet,t.id.client,t.id.clock,this.len),t.markDeleted()}delete(e){}gc(e){}write(e,t){e.writeLen(this.len-t)}getRef(){return 1}},nc=e=>new tc(e.readLen()),rc=(e,t)=>new Da({guid:e,...t,shouldLoad:t.shouldLoad||t.autoLoad||!1}),ic=class e{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;let t={};this.opts=t,e.gc||(t.gc=!1),e.autoLoad&&(t.autoLoad=!0),e.meta!==null&&(t.meta=e.meta)}getLength(){return 1}getContent(){return[this.doc]}isCountable(){return!0}copy(){return new e(rc(this.doc.guid,this.opts))}splice(e){throw sn()}mergeWith(e){return!1}integrate(e,t){this.doc._item=t,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,t){e.writeString(this.doc.guid),e.writeAny(this.opts)}getRef(){return 9}},ac=e=>new ic(rc(e.readString(),e.readAny())),oc=class e{constructor(e){this.embed=e}getLength(){return 1}getContent(){return[this.embed]}isCountable(){return!0}copy(){return new e(this.embed)}splice(e){throw sn()}mergeWith(e){return!1}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeJSON(this.embed)}getRef(){return 5}},sc=e=>new oc(e.readJSON()),J=class e{constructor(e,t){this.key=e,this.value=t}getLength(){return 1}getContent(){return[]}isCountable(){return!1}copy(){return new e(this.key,this.value)}splice(e){throw sn()}mergeWith(e){return!1}integrate(e,t){let n=t.parent;n._searchMarker=null,n._hasFormatting=!0}delete(e){}gc(e){}write(e,t){e.writeKey(this.key),e.writeJSON(this.value)}getRef(){return 6}},cc=e=>new J(e.readKey(),e.readJSON()),lc=class e{constructor(e){this.arr=e}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new e(this.arr)}splice(t){let n=new e(this.arr.slice(t));return this.arr=this.arr.slice(0,t),n}mergeWith(e){return this.arr=this.arr.concat(e.arr),!0}integrate(e,t){}delete(e){}gc(e){}write(e,t){let n=this.arr.length;e.writeLen(n-t);for(let r=t;r<n;r++){let t=this.arr[r];e.writeString(t===void 0?`undefined`:JSON.stringify(t))}}getRef(){return 2}},uc=e=>{let t=e.readLen(),n=[];for(let r=0;r<t;r++){let t=e.readString();t===`undefined`?n.push(void 0):n.push(JSON.parse(t))}return new lc(n)},dc=ur(`node_env`)===`development`,fc=class e{constructor(e){this.arr=e,dc&&Qn(e)}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new e(this.arr)}splice(t){let n=new e(this.arr.slice(t));return this.arr=this.arr.slice(0,t),n}mergeWith(e){return this.arr=this.arr.concat(e.arr),!0}integrate(e,t){}delete(e){}gc(e){}write(e,t){let n=this.arr.length;e.writeLen(n-t);for(let r=t;r<n;r++){let t=this.arr[r];e.writeAny(t)}}getRef(){return 8}},pc=e=>{let t=e.readLen(),n=[];for(let r=0;r<t;r++)n.push(e.readAny());return new fc(n)},mc=class e{constructor(e){this.str=e}getLength(){return this.str.length}getContent(){return this.str.split(``)}isCountable(){return!0}copy(){return new e(this.str)}splice(t){let n=new e(this.str.slice(t));this.str=this.str.slice(0,t);let r=this.str.charCodeAt(t-1);return r>=55296&&r<=56319&&(this.str=this.str.slice(0,t-1)+`�`,n.str=`�`+n.str.slice(1)),n}mergeWith(e){return this.str+=e.str,!0}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeString(t===0?this.str:this.str.slice(t))}getRef(){return 4}},hc=e=>new mc(e.readString()),gc=[vs,xs,zs,Ws,Hs,qs,Ys],_c=0,vc=1,yc=2,bc=3,xc=4,Sc=5,Cc=6,wc=class e{constructor(e){this.type=e}getLength(){return 1}getContent(){return[this.type]}isCountable(){return!0}copy(){return new e(this.type._copy())}splice(e){throw sn()}mergeWith(e){return!1}integrate(e,t){this.type._integrate(e.doc,t)}delete(e){let t=this.type._start;for(;t!==null;)t.deleted?t.id.clock<(e.beforeState.get(t.id.client)||0)&&e._mergeStructs.push(t):t.delete(e),t=t.right;this.type._map.forEach(t=>{t.deleted?t.id.clock<(e.beforeState.get(t.id.client)||0)&&e._mergeStructs.push(t):t.delete(e)}),e.changed.delete(this.type)}gc(e){let t=this.type._start;for(;t!==null;)t.gc(e,!0),t=t.right;this.type._start=null,this.type._map.forEach(t=>{for(;t!==null;)t.gc(e,!0),t=t.left}),this.type._map=new Map}write(e,t){this.type._write(e)}getRef(){return 7}},Tc=e=>new wc(gc[e.readTypeRef()](e)),Ec=(e,t,n)=>{let{client:r,clock:i}=t.id,a=new Dc(U(r,i+n),t,U(r,i+n-1),t.right,t.rightOrigin,t.parent,t.parentSub,t.content.splice(n));return t.deleted&&a.markDeleted(),t.keep&&(a.keep=!0),t.redone!==null&&(a.redone=U(t.redone.client,t.redone.clock+n)),t.right=a,a.right!==null&&(a.right.left=a),e._mergeStructs.push(a),a.parentSub!==null&&a.right===null&&a.parent._map.set(a.parentSub,a),t.length=n,a},Dc=class e extends Xs{constructor(e,t,n,r,i,a,o,s){super(e,s.getLength()),this.origin=n,this.left=t,this.right=r,this.rightOrigin=i,this.parent=a,this.parentSub=o,this.redone=null,this.content=s,this.info=this.content.isCountable()?2:0}set marker(e){(this.info&8)>0!==e&&(this.info^=8)}get marker(){return(this.info&8)>0}get keep(){return(this.info&1)>0}set keep(e){this.keep!==e&&(this.info^=1)}get countable(){return(this.info&2)>0}get deleted(){return(this.info&4)>0}set deleted(e){this.deleted!==e&&(this.info^=4)}markDeleted(){this.info|=4}getMissing(t,n){if(this.origin&&this.origin.client!==this.id.client&&this.origin.clock>=W(n,this.origin.client))return this.origin.client;if(this.rightOrigin&&this.rightOrigin.client!==this.id.client&&this.rightOrigin.clock>=W(n,this.rightOrigin.client))return this.rightOrigin.client;if(this.parent&&this.parent.constructor===io&&this.id.client!==this.parent.client&&this.parent.clock>=W(n,this.parent.client))return this.parent.client;if(this.origin&&=(this.left=vo(t,n,this.origin),this.left.lastId),this.rightOrigin&&=(this.right=_o(t,this.rightOrigin),this.right.id),this.left&&this.left.constructor===Qs||this.right&&this.right.constructor===Qs)this.parent=null;else if(!this.parent)this.left&&this.left.constructor===e?(this.parent=this.left.parent,this.parentSub=this.left.parentSub):this.right&&this.right.constructor===e&&(this.parent=this.right.parent,this.parentSub=this.right.parentSub);else if(this.parent.constructor===io){let e=ho(n,this.parent);e.constructor===Qs?this.parent=null:this.parent=e.content.type}return null}integrate(e,t){if(t>0&&(this.id.clock+=t,this.left=vo(e,e.doc.store,U(this.id.client,this.id.clock-1)),this.origin=this.left.lastId,this.content=this.content.splice(t),this.length-=t),this.parent){if(!this.left&&(!this.right||this.right.left!==null)||this.left&&this.left.right!==this.right){let t=this.left,n;if(t!==null)n=t.right;else if(this.parentSub!==null)for(n=this.parent._map.get(this.parentSub)||null;n!==null&&n.left!==null;)n=n.left;else n=this.parent._start;let r=new Set,i=new Set;for(;n!==null&&n!==this.right;){if(i.add(n),r.add(n),ao(this.origin,n.origin)){if(n.id.client<this.id.client)t=n,r.clear();else if(ao(this.rightOrigin,n.rightOrigin))break}else if(n.origin!==null&&i.has(ho(e.doc.store,n.origin)))r.has(ho(e.doc.store,n.origin))||(t=n,r.clear());else break;n=n.right}this.left=t}if(this.left!==null){let e=this.left.right;this.right=e,this.left.right=this}else{let e;if(this.parentSub!==null)for(e=this.parent._map.get(this.parentSub)||null;e!==null&&e.left!==null;)e=e.left;else e=this.parent._start,this.parent._start=this;this.right=e}this.right===null?this.parentSub!==null&&(this.parent._map.set(this.parentSub,this),this.left!==null&&this.left.delete(e)):this.right.left=this,this.parentSub===null&&this.countable&&!this.deleted&&(this.parent._length+=this.length),po(e.doc.store,this),this.content.integrate(e,this),Co(e,this.parent,this.parentSub),(this.parent._item!==null&&this.parent._item.deleted||this.parentSub!==null&&this.right!==null)&&this.delete(e)}else new Qs(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:U(this.id.client,this.id.clock+this.length-1)}mergeWith(e){if(this.constructor===e.constructor&&ao(e.origin,this.lastId)&&this.right===e&&ao(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)){let t=this.parent._searchMarker;return t&&t.forEach(t=>{t.p===e&&(t.p=this,!this.deleted&&this.countable&&(t.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){let t=this.parent;this.countable&&this.parentSub===null&&(t._length-=this.length),this.markDeleted(),ba(e.deleteSet,this.id.client,this.id.clock,this.length),Co(e,t,this.parentSub),this.content.delete(e)}}gc(e,t){if(!this.deleted)throw cn();this.content.gc(e),t?yo(e,this,new Qs(this.id,this.length)):this.content=new tc(this.length)}write(e,t){let n=t>0?U(this.id.client,this.id.clock+t-1):this.origin,r=this.rightOrigin,i=this.parentSub,a=this.content.getRef()&31|(n===null?0:128)|(r===null?0:64)|(i===null?0:32);if(e.writeInfo(a),n!==null&&e.writeLeftID(n),r!==null&&e.writeRightID(r),n===null&&r===null){let t=this.parent;if(t._item!==void 0){let n=t._item;if(n===null){let n=oo(t);e.writeParentInfo(!0),e.writeString(n)}else e.writeParentInfo(!1),e.writeLeftID(n.id)}else t.constructor===String?(e.writeParentInfo(!0),e.writeString(t)):t.constructor===io?(e.writeParentInfo(!1),e.writeLeftID(t)):cn();i!==null&&e.writeString(i)}this.content.write(e,t)}},Oc=(e,t)=>kc[t&31](e),kc=[()=>{cn()},nc,uc,ec,hc,sc,cc,Tc,pc,ac,()=>{cn()}],Ac=10,jc=class extends Xs{get deleted(){return!0}delete(){}mergeWith(e){return this.constructor===e.constructor?(this.length+=e.length,!0):!1}integrate(e,t){cn()}write(e,t){e.writeInfo(Ac),L(e.restEncoder,this.length-t)}getMissing(e,t){return null}},Mc=typeof globalThis<`u`?globalThis:typeof window<`u`?window:typeof global<`u`?global:{},Nc=`__ $YJS$ __`;Mc[Nc]===!0&&console.error(`Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438`),Mc[Nc]=!0;var Pc=e=>jn((t,n)=>{e.onerror=e=>n(Error(e.target.error)),e.onsuccess=e=>t(e.target.result)}),Fc=(e,t)=>jn((n,r)=>{let i=indexedDB.open(e);i.onupgradeneeded=e=>t(e.target.result),i.onerror=e=>r(on(e.target.error)),i.onsuccess=e=>{let t=e.target.result;t.onversionchange=()=>{t.close()},n(t)}}),Ic=e=>Pc(indexedDB.deleteDatabase(e)),Lc=(e,t)=>t.forEach(t=>e.createObjectStore.apply(e,t)),Rc=(e,t,n=`readwrite`)=>{let r=e.transaction(t,n);return t.map(e=>Yc(r,e))},zc=(e,t)=>Pc(e.count(t)),Bc=(e,t)=>Pc(e.get(t)),Vc=(e,t)=>Pc(e.delete(t)),Hc=(e,t,n)=>Pc(e.put(t,n)),Uc=(e,t)=>Pc(e.add(t)),Wc=(e,t,n)=>Pc(e.getAll(t,n)),Gc=(e,t,n)=>{let r=null;return Jc(e,t,e=>(r=e,!1),n).then(()=>r)},Kc=(e,t=null)=>Gc(e,t,`prev`),qc=(e,t)=>jn((n,r)=>{e.onerror=r,e.onsuccess=async e=>{let r=e.target.result;if(r===null||await t(r)===!1)return n();r.continue()}}),Jc=(e,t,n,r=`next`)=>qc(e.openKeyCursor(t,r),e=>n(e.key)),Yc=(e,t)=>e.objectStore(t),Xc=(e,t)=>IDBKeyRange.upperBound(e,t),Zc=(e,t)=>IDBKeyRange.lowerBound(e,t),Qc=`custom`,$c=`updates`,el=(e,t=()=>{},n=()=>{})=>{let[r]=Rc(e.db,[$c]);return Wc(r,Zc(e._dbref,!1)).then(i=>{e._destroyed||(t(r),G(e.doc,()=>{i.forEach(t=>Ua(e.doc,t))},e,!1),n(r))}).then(()=>Kc(r).then(t=>{e._dbref=t+1})).then(()=>zc(r).then(t=>{e._dbsize=t})).then(()=>r)},tl=(e,t=!0)=>el(e).then(n=>{(t||e._dbsize>=500)&&Uc(n,Ka(e.doc)).then(()=>Vc(n,Xc(e._dbref,!0))).then(()=>zc(n).then(t=>{e._dbsize=t}))}),nl=class extends gt{constructor(e,t){super(),this.doc=t,this.name=e,this._dbref=0,this._dbsize=0,this._destroyed=!1,this.db=null,this.synced=!1,this._db=Fc(e,e=>Lc(e,[[`updates`,{autoIncrement:!0}],[`custom`]])),this.whenSynced=jn(e=>this.on(`synced`,()=>e(this))),this._db.then(e=>{this.db=e,el(this,e=>Uc(e,Ka(t)),()=>{if(this._destroyed)return this;this.synced=!0,this.emit(`synced`,[this])})}),this._storeTimeout=1e3,this._storeTimeoutId=null,this._storeUpdate=(e,t)=>{if(this.db&&t!==this){let[t]=Rc(this.db,[$c]);Uc(t,e),++this._dbsize>=500&&(this._storeTimeoutId!==null&&clearTimeout(this._storeTimeoutId),this._storeTimeoutId=setTimeout(()=>{tl(this,!1),this._storeTimeoutId=null},this._storeTimeout))}},t.on(`update`,this._storeUpdate),this.destroy=this.destroy.bind(this),t.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(()=>{Ic(this.name)})}get(e){return this._db.then(t=>{let[n]=Rc(t,[Qc],`readonly`);return Bc(n,e)})}set(e,t){return this._db.then(n=>{let[r]=Rc(n,[Qc]);return Hc(r,t,e)})}del(e){return this._db.then(t=>{let[n]=Rc(t,[Qc]);return Vc(n,e)})}},rl=1200,il=2500,al=3e4,ol=e=>{if(e.shouldConnect&&e.ws===null){let t=new WebSocket(e.url),n=e.binaryType,r=null;n&&(t.binaryType=n),e.ws=t,e.connecting=!0,e.connected=!1,t.onmessage=t=>{e.lastMessageReceived=An();let n=t.data,i=typeof n==`string`?JSON.parse(n):n;i&&i.type===`pong`&&(clearTimeout(r),r=setTimeout(a,al/2)),e.emit(`message`,[i,e])};let i=t=>{e.ws!==null&&(e.ws=null,e.connecting=!1,e.connected?(e.connected=!1,e.emit(`disconnect`,[{type:`disconnect`,error:t},e])):e.unsuccessfulReconnects++,setTimeout(ol,bt(yt(e.unsuccessfulReconnects+1)*rl,il),e)),clearTimeout(r)},a=()=>{e.ws===t&&e.send({type:`ping`})};t.onclose=()=>i(null),t.onerror=e=>i(e),t.onopen=()=>{e.lastMessageReceived=An(),e.connecting=!1,e.connected=!0,e.unsuccessfulReconnects=0,e.emit(`connect`,[{type:`connect`},e]),r=setTimeout(a,al/2)}}},sl=class extends gt{constructor(e,{binaryType:t}={}){super(),this.url=e,this.ws=null,this.binaryType=t||null,this.connected=!1,this.connecting=!1,this.unsuccessfulReconnects=0,this.lastMessageReceived=0,this.shouldConnect=!0,this._checkInterval=setInterval(()=>{this.connected&&al<An()-this.lastMessageReceived&&this.ws.close()},al/2),ol(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&&ol(this)}},cl=new Map,ll=class{constructor(e){this.room=e,this.onmessage=null,this._onChange=t=>t.key===e&&this.onmessage!==null&&this.onmessage({data:Sr(t.newValue||``)}),Rn(this._onChange)}postMessage(e){Ln.setItem(this.room,xr(gr(e)))}close(){zn(this._onChange)}},ul=typeof BroadcastChannel>`u`?ll:BroadcastChannel,dl=e=>it(cl,e,()=>{let t=st(),n=new ul(e);return n.onmessage=e=>t.forEach(t=>t(e.data,`broadcastchannel`)),{bc:n,subs:t}}),fl=(e,t)=>(dl(e).subs.add(t),t),pl=(e,t)=>{let n=dl(e),r=n.subs.delete(t);return r&&n.subs.size===0&&(n.bc.close(),cl.delete(e)),r},ml=(e,t,n=null)=>{let r=dl(e);r.bc.postMessage(t),r.subs.forEach(e=>e(t,n))},hl=()=>{let e=!0;return(t,n)=>{if(e){e=!1;try{t()}finally{e=!0}}else n!==void 0&&n()}},gl=e(r(((e,t)=>{(function(n){if(typeof e==`object`&&t!==void 0)t.exports=n();else if(typeof define==`function`&&define.amd)define([],n);else{var r=typeof window>`u`?typeof global>`u`?typeof self>`u`?this:self:global:window;r.SimplePeer=n()}})(function(){var e=Math.floor,t=Math.abs,r=Math.pow;return function(){function e(t,r,i){function a(s,c){if(!r[s]){if(!t[s]){var l=typeof n==`function`&&n;if(!c&&l)return l(s,!0);if(o)return o(s,!0);var u=Error(`Cannot find module '`+s+`'`);throw u.code=`MODULE_NOT_FOUND`,u}var d=r[s]={exports:{}};t[s][0].call(d.exports,function(e){var n=t[s][1][e];return a(n||e)},d,d.exports,e,t,r,i)}return r[s].exports}for(var o=typeof n==`function`&&n,s=0;s<i.length;s++)a(i[s]);return a}return e}()({1:[function(e,t,n){function r(e){var t=e.length;if(0<t%4)throw Error(`Invalid string. Length must be a multiple of 4`);var n=e.indexOf(`=`);n===-1&&(n=t);var r=n===t?0:4-n%4;return[n,r]}function i(e,t,n){return 3*(t+n)/4-n}function a(e){var t,n,a=r(e),o=a[0],s=a[1],c=new d(i(e,o,s)),l=0,f=0<s?o-4:o;for(n=0;n<f;n+=4)t=u[e.charCodeAt(n)]<<18|u[e.charCodeAt(n+1)]<<12|u[e.charCodeAt(n+2)]<<6|u[e.charCodeAt(n+3)],c[l++]=255&t>>16,c[l++]=255&t>>8,c[l++]=255&t;return s===2&&(t=u[e.charCodeAt(n)]<<2|u[e.charCodeAt(n+1)]>>4,c[l++]=255&t),s===1&&(t=u[e.charCodeAt(n)]<<10|u[e.charCodeAt(n+1)]<<4|u[e.charCodeAt(n+2)]>>2,c[l++]=255&t>>8,c[l++]=255&t),c}function o(e){return l[63&e>>18]+l[63&e>>12]+l[63&e>>6]+l[63&e]}function s(e,t,n){for(var r,i=[],a=t;a<n;a+=3)r=(16711680&e[a]<<16)+(65280&e[a+1]<<8)+(255&e[a+2]),i.push(o(r));return i.join(``)}function c(e){for(var t,n=e.length,r=n%3,i=[],a=16383,o=0,c=n-r;o<c;o+=a)i.push(s(e,o,o+a>c?c:o+a));return r===1?(t=e[n-1],i.push(l[t>>2]+l[63&t<<4]+`==`)):r===2&&(t=(e[n-2]<<8)+e[n-1],i.push(l[t>>10]+l[63&t>>4]+l[63&t<<2]+`=`)),i.join(``)}n.byteLength=function(e){var t=r(e),n=t[0],i=t[1];return 3*(n+i)/4-i},n.toByteArray=a,n.fromByteArray=c;for(var l=[],u=[],d=typeof Uint8Array>`u`?Array:Uint8Array,f=`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/`,p=0,m=f.length;p<m;++p)l[p]=f[p],u[f.charCodeAt(p)]=p;u[45]=62,u[95]=63},{}],2:[function(){},{}],3:[function(e,t,n){(function(){(function(){var t=String.fromCharCode,i=Math.min;function a(e){if(2147483647<e)throw RangeError(`The value "`+e+`" is invalid for option "size"`);var t=new Uint8Array(e);return t.__proto__=o.prototype,t}function o(e,t,n){if(typeof e==`number`){if(typeof t==`string`)throw TypeError(`The "string" argument must be of type string. Received type number`);return u(e)}return s(e,t,n)}function s(e,t,n){if(typeof e==`string`)return d(e,t);if(ArrayBuffer.isView(e))return f(e);if(e==null)throw TypeError(`The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type `+typeof e);if(he(e,ArrayBuffer)||e&&he(e.buffer,ArrayBuffer))return p(e,t,n);if(typeof e==`number`)throw TypeError(`The "value" argument must not be of type number. Received type number`);var r=e.valueOf&&e.valueOf();if(r!=null&&r!==e)return o.from(r,t,n);var i=m(e);if(i)return i;if(typeof Symbol<`u`&&Symbol.toPrimitive!=null&&typeof e[Symbol.toPrimitive]==`function`)return o.from(e[Symbol.toPrimitive](`string`),t,n);throw TypeError(`The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type `+typeof e)}function c(e){if(typeof e!=`number`)throw TypeError(`"size" argument must be of type number`);if(0>e)throw RangeError(`The value "`+e+`" is invalid for option "size"`)}function l(e,t,n){return c(e),0>=e||t===void 0?a(e):typeof n==`string`?a(e).fill(t,n):a(e).fill(t)}function u(e){return c(e),a(0>e?0:0|h(e))}function d(e,t){if((typeof t!=`string`||t===``)&&(t=`utf8`),!o.isEncoding(t))throw TypeError(`Unknown encoding: `+t);var n=0|g(e,t),r=a(n),i=r.write(e,t);return i!==n&&(r=r.slice(0,i)),r}function f(e){for(var t=0>e.length?0:0|h(e.length),n=a(t),r=0;r<t;r+=1)n[r]=255&e[r];return n}function p(e,t,n){if(0>t||e.byteLength<t)throw RangeError(`"offset" is outside of buffer bounds`);if(e.byteLength<t+(n||0))throw RangeError(`"length" is outside of buffer bounds`);var r;return r=t===void 0&&n===void 0?new Uint8Array(e):n===void 0?new Uint8Array(e,t):new Uint8Array(e,t,n),r.__proto__=o.prototype,r}function m(e){if(o.isBuffer(e)){var t=0|h(e.length),n=a(t);return n.length===0||e.copy(n,0,0,t),n}return e.length===void 0?e.type===`Buffer`&&Array.isArray(e.data)?f(e.data):void 0:typeof e.length!=`number`||ge(e.length)?a(0):f(e)}function h(e){if(e>=2147483647)throw RangeError(`Attempt to allocate Buffer larger than maximum size: 0x7fffffff bytes`);return 0|e}function g(e,t){if(o.isBuffer(e))return e.length;if(ArrayBuffer.isView(e)||he(e,ArrayBuffer))return e.byteLength;if(typeof e!=`string`)throw TypeError(`The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type `+typeof e);var n=e.length,r=2<arguments.length&&!0===arguments[2];if(!r&&n===0)return 0;for(var i=!1;;)switch(t){case`ascii`:case`latin1`:case`binary`:return n;case`utf8`:case`utf-8`:return A(e).length;case`ucs2`:case`ucs-2`:case`utf16le`:case`utf-16le`:return 2*n;case`hex`:return n>>>1;case`base64`:return pe(e).length;default:if(i)return r?-1:A(e).length;t=(``+t).toLowerCase(),i=!0}}function _(e,t,n){var r=!1;if((t===void 0||0>t)&&(t=0),t>this.length||((n===void 0||n>this.length)&&(n=this.length),0>=n)||(n>>>=0,t>>>=0,n<=t))return``;for(e||=`utf8`;;)switch(e){case`hex`:return E(this,t,n);case`utf8`:case`utf-8`:return w(this,t,n);case`ascii`:return T(this,t,n);case`latin1`:case`binary`:return ae(this,t,n);case`base64`:return C(this,t,n);case`ucs2`:case`ucs-2`:case`utf16le`:case`utf-16le`:return oe(this,t,n);default:if(r)throw TypeError(`Unknown encoding: `+e);e=(e+``).toLowerCase(),r=!0}}function v(e,t,n){var r=e[t];e[t]=e[n],e[n]=r}function y(e,t,n,r,i){if(e.length===0)return-1;if(typeof n==`string`?(r=n,n=0):2147483647<n?n=2147483647:-2147483648>n&&(n=-2147483648),n=+n,ge(n)&&(n=i?0:e.length-1),0>n&&(n=e.length+n),n>=e.length){if(i)return-1;n=e.length-1}else if(0>n)if(i)n=0;else return-1;if(typeof t==`string`&&(t=o.from(t,r)),o.isBuffer(t))return t.length===0?-1:b(e,t,n,r,i);if(typeof t==`number`)return t&=255,typeof Uint8Array.prototype.indexOf==`function`?i?Uint8Array.prototype.indexOf.call(e,t,n):Uint8Array.prototype.lastIndexOf.call(e,t,n):b(e,[t],n,r,i);throw TypeError(`val must be string, number or Buffer`)}function b(e,t,n,r,i){function a(e,t){return o===1?e[t]:e.readUInt16BE(t*o)}var o=1,s=e.length,c=t.length;if(r!==void 0&&(r=(r+``).toLowerCase(),r===`ucs2`||r===`ucs-2`||r===`utf16le`||r===`utf-16le`)){if(2>e.length||2>t.length)return-1;o=2,s/=2,c/=2,n/=2}var l;if(i){var u=-1;for(l=n;l<s;l++)if(a(e,l)!==a(t,u===-1?0:l-u))u!==-1&&(l-=l-u),u=-1;else if(u===-1&&(u=l),l-u+1===c)return u*o}else for(n+c>s&&(n=s-c),l=n;0<=l;l--){for(var d=!0,f=0;f<c;f++)if(a(e,l+f)!==a(t,f)){d=!1;break}if(d)return l}return-1}function x(e,t,n,r){n=+n||0;var i=e.length-n;r?(r=+r,r>i&&(r=i)):r=i;var a=t.length;r>a/2&&(r=a/2);for(var o,s=0;s<r;++s){if(o=parseInt(t.substr(2*s,2),16),ge(o))return s;e[n+s]=o}return s}function ee(e,t,n,r){return me(A(t,e.length-n),e,n,r)}function te(e,t,n,r){return me(de(t),e,n,r)}function S(e,t,n,r){return te(e,t,n,r)}function ne(e,t,n,r){return me(pe(t),e,n,r)}function re(e,t,n,r){return me(fe(t,e.length-n),e,n,r)}function C(e,t,n){return t===0&&n===e.length?_e.fromByteArray(e):_e.fromByteArray(e.slice(t,n))}function w(e,t,n){n=i(e.length,n);for(var r=[],a=t;a<n;){var o=e[a],s=null,c=239<o?4:223<o?3:191<o?2:1;if(a+c<=n){var l,u,d,f;c===1?128>o&&(s=o):c===2?(l=e[a+1],(192&l)==128&&(f=(31&o)<<6|63&l,127<f&&(s=f))):c===3?(l=e[a+1],u=e[a+2],(192&l)==128&&(192&u)==128&&(f=(15&o)<<12|(63&l)<<6|63&u,2047<f&&(55296>f||57343<f)&&(s=f))):c===4&&(l=e[a+1],u=e[a+2],d=e[a+3],(192&l)==128&&(192&u)==128&&(192&d)==128&&(f=(15&o)<<18|(63&l)<<12|(63&u)<<6|63&d,65535<f&&1114112>f&&(s=f)))}s===null?(s=65533,c=1):65535<s&&(s-=65536,r.push(55296|1023&s>>>10),s=56320|1023&s),r.push(s),a+=c}return ie(r)}function ie(e){var n=e.length;if(n<=4096)return t.apply(String,e);for(var r=``,i=0;i<n;)r+=t.apply(String,e.slice(i,i+=4096));return r}function T(e,n,r){var a=``;r=i(e.length,r);for(var o=n;o<r;++o)a+=t(127&e[o]);return a}function ae(e,n,r){var a=``;r=i(e.length,r);for(var o=n;o<r;++o)a+=t(e[o]);return a}function E(e,t,n){var r=e.length;(!t||0>t)&&(t=0),(!n||0>n||n>r)&&(n=r);for(var i=``,a=t;a<n;++a)i+=ue(e[a]);return i}function oe(e,n,r){for(var i=e.slice(n,r),a=``,o=0;o<i.length;o+=2)a+=t(i[o]+256*i[o+1]);return a}function D(e,t,n){if(e%1!=0||0>e)throw RangeError(`offset is not uint`);if(e+t>n)throw RangeError(`Trying to access beyond buffer length`)}function O(e,t,n,r,i,a){if(!o.isBuffer(e))throw TypeError(`"buffer" argument must be a Buffer instance`);if(t>i||t<a)throw RangeError(`"value" argument is out of bounds`);if(n+r>e.length)throw RangeError(`Index out of range`)}function k(e,t,n,r){if(n+r>e.length||0>n)throw RangeError(`Index out of range`)}function se(e,t,n,r,i){return t=+t,n>>>=0,i||k(e,t,n,4,34028234663852886e22,-34028234663852886e22),j.write(e,t,n,r,23,4),n+4}function ce(e,t,n,r,i){return t=+t,n>>>=0,i||k(e,t,n,8,17976931348623157e292,-17976931348623157e292),j.write(e,t,n,r,52,8),n+8}function le(e){if(e=e.split(`=`)[0],e=e.trim().replace(ve,``),2>e.length)return``;for(;e.length%4!=0;)e+=`=`;return e}function ue(e){return 16>e?`0`+e.toString(16):e.toString(16)}function A(e,t){t||=1/0;for(var n,r=e.length,i=null,a=[],o=0;o<r;++o){if(n=e.charCodeAt(o),55295<n&&57344>n){if(!i){if(56319<n){-1<(t-=3)&&a.push(239,191,189);continue}else if(o+1===r){-1<(t-=3)&&a.push(239,191,189);continue}i=n;continue}if(56320>n){-1<(t-=3)&&a.push(239,191,189),i=n;continue}n=(i-55296<<10|n-56320)+65536}else i&&-1<(t-=3)&&a.push(239,191,189);if(i=null,128>n){if(0>--t)break;a.push(n)}else if(2048>n){if(0>(t-=2))break;a.push(192|n>>6,128|63&n)}else if(65536>n){if(0>(t-=3))break;a.push(224|n>>12,128|63&n>>6,128|63&n)}else if(1114112>n){if(0>(t-=4))break;a.push(240|n>>18,128|63&n>>12,128|63&n>>6,128|63&n)}else throw Error(`Invalid code point`)}return a}function de(e){for(var t=[],n=0;n<e.length;++n)t.push(255&e.charCodeAt(n));return t}function fe(e,t){for(var n,r,i,a=[],o=0;o<e.length&&!(0>(t-=2));++o)n=e.charCodeAt(o),r=n>>8,i=n%256,a.push(i),a.push(r);return a}function pe(e){return _e.toByteArray(le(e))}function me(e,t,n,r){for(var i=0;i<r&&!(i+n>=t.length||i>=e.length);++i)t[i+n]=e[i];return i}function he(e,t){return e instanceof t||e!=null&&e.constructor!=null&&e.constructor.name!=null&&e.constructor.name===t.name}function ge(e){return e!==e}var _e=e(`base64-js`),j=e(`ieee754`);n.Buffer=o,n.SlowBuffer=function(e){return+e!=e&&(e=0),o.alloc(+e)},n.INSPECT_MAX_BYTES=50,n.kMaxLength=2147483647,o.TYPED_ARRAY_SUPPORT=function(){try{var e=new Uint8Array(1);return e.__proto__={__proto__:Uint8Array.prototype,foo:function(){return 42}},e.foo()===42}catch{return!1}}(),o.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(o.prototype,"parent",{enumerable:!0,get:function(){return o.isBuffer(this)?this.buffer:void 0}}),Object.defineProperty(o.prototype,"offset",{enumerable:!0,get:function(){return o.isBuffer(this)?this.byteOffset:void 0}}),typeof Symbol<`u`&&Symbol.species!=null&&o[Symbol.species]===o&&Object.defineProperty(o,Symbol.species,{value:null,configurable:!0,enumerable:!1,writable:!1}),o.poolSize=8192,o.from=function(e,t,n){return s(e,t,n)},o.prototype.__proto__=Uint8Array.prototype,o.__proto__=Uint8Array,o.alloc=function(e,t,n){return l(e,t,n)},o.allocUnsafe=function(e){return u(e)},o.allocUnsafeSlow=function(e){return u(e)},o.isBuffer=function(e){return e!=null&&!0===e._isBuffer&&e!==o.prototype},o.compare=function(e,t){if(he(e,Uint8Array)&&(e=o.from(e,e.offset,e.byteLength)),he(t,Uint8Array)&&(t=o.from(t,t.offset,t.byteLength)),!o.isBuffer(e)||!o.isBuffer(t))throw TypeError(`The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array`);if(e===t)return 0;for(var n=e.length,r=t.length,a=0,s=i(n,r);a<s;++a)if(e[a]!==t[a]){n=e[a],r=t[a];break}return n<r?-1:+(r<n)},o.isEncoding=function(e){switch((e+``).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}},o.concat=function(e,t){if(!Array.isArray(e))throw TypeError(`"list" argument must be an Array of Buffers`);if(e.length===0)return o.alloc(0);var n;if(t===void 0)for(t=0,n=0;n<e.length;++n)t+=e[n].length;var r=o.allocUnsafe(t),i=0;for(n=0;n<e.length;++n){var a=e[n];if(he(a,Uint8Array)&&(a=o.from(a)),!o.isBuffer(a))throw TypeError(`"list" argument must be an Array of Buffers`);a.copy(r,i),i+=a.length}return r},o.byteLength=g,o.prototype._isBuffer=!0,o.prototype.swap16=function(){var e=this.length;if(e%2!=0)throw RangeError(`Buffer size must be a multiple of 16-bits`);for(var t=0;t<e;t+=2)v(this,t,t+1);return this},o.prototype.swap32=function(){var e=this.length;if(e%4!=0)throw RangeError(`Buffer size must be a multiple of 32-bits`);for(var t=0;t<e;t+=4)v(this,t,t+3),v(this,t+1,t+2);return this},o.prototype.swap64=function(){var e=this.length;if(e%8!=0)throw RangeError(`Buffer size must be a multiple of 64-bits`);for(var t=0;t<e;t+=8)v(this,t,t+7),v(this,t+1,t+6),v(this,t+2,t+5),v(this,t+3,t+4);return this},o.prototype.toString=function(){var e=this.length;return e===0?``:arguments.length===0?w(this,0,e):_.apply(this,arguments)},o.prototype.toLocaleString=o.prototype.toString,o.prototype.equals=function(e){if(!o.isBuffer(e))throw TypeError(`Argument must be a Buffer`);return this===e||o.compare(this,e)===0},o.prototype.inspect=function(){var e=``,t=n.INSPECT_MAX_BYTES;return e=this.toString(`hex`,0,t).replace(/(.{2})/g,`$1 `).trim(),this.length>t&&(e+=` ... `),`<Buffer `+e+`>`},o.prototype.compare=function(e,t,n,r,a){if(he(e,Uint8Array)&&(e=o.from(e,e.offset,e.byteLength)),!o.isBuffer(e))throw TypeError(`The "target" argument must be one of type Buffer or Uint8Array. Received type `+typeof e);if(t===void 0&&(t=0),n===void 0&&(n=e?e.length:0),r===void 0&&(r=0),a===void 0&&(a=this.length),0>t||n>e.length||0>r||a>this.length)throw RangeError(`out of range index`);if(r>=a&&t>=n)return 0;if(r>=a)return-1;if(t>=n)return 1;if(t>>>=0,n>>>=0,r>>>=0,a>>>=0,this===e)return 0;for(var s=a-r,c=n-t,l=i(s,c),u=this.slice(r,a),d=e.slice(t,n),f=0;f<l;++f)if(u[f]!==d[f]){s=u[f],c=d[f];break}return s<c?-1:+(c<s)},o.prototype.includes=function(e,t,n){return this.indexOf(e,t,n)!==-1},o.prototype.indexOf=function(e,t,n){return y(this,e,t,n,!0)},o.prototype.lastIndexOf=function(e,t,n){return y(this,e,t,n,!1)},o.prototype.write=function(e,t,n,r){if(t===void 0)r=`utf8`,n=this.length,t=0;else if(n===void 0&&typeof t==`string`)r=t,n=this.length,t=0;else if(isFinite(t))t>>>=0,isFinite(n)?(n>>>=0,r===void 0&&(r=`utf8`)):(r=n,n=void 0);else throw Error(`Buffer.write(string, encoding, offset[, length]) is no longer supported`);var i=this.length-t;if((n===void 0||n>i)&&(n=i),0<e.length&&(0>n||0>t)||t>this.length)throw RangeError(`Attempt to write outside buffer bounds`);r||=`utf8`;for(var a=!1;;)switch(r){case`hex`:return x(this,e,t,n);case`utf8`:case`utf-8`:return ee(this,e,t,n);case`ascii`:return te(this,e,t,n);case`latin1`:case`binary`:return S(this,e,t,n);case`base64`:return ne(this,e,t,n);case`ucs2`:case`ucs-2`:case`utf16le`:case`utf-16le`:return re(this,e,t,n);default:if(a)throw TypeError(`Unknown encoding: `+r);r=(``+r).toLowerCase(),a=!0}},o.prototype.toJSON=function(){return{type:`Buffer`,data:Array.prototype.slice.call(this._arr||this,0)}},o.prototype.slice=function(e,t){var n=this.length;e=~~e,t=t===void 0?n:~~t,0>e?(e+=n,0>e&&(e=0)):e>n&&(e=n),0>t?(t+=n,0>t&&(t=0)):t>n&&(t=n),t<e&&(t=e);var r=this.subarray(e,t);return r.__proto__=o.prototype,r},o.prototype.readUIntLE=function(e,t,n){e>>>=0,t>>>=0,n||D(e,t,this.length);for(var r=this[e],i=1,a=0;++a<t&&(i*=256);)r+=this[e+a]*i;return r},o.prototype.readUIntBE=function(e,t,n){e>>>=0,t>>>=0,n||D(e,t,this.length);for(var r=this[e+--t],i=1;0<t&&(i*=256);)r+=this[e+--t]*i;return r},o.prototype.readUInt8=function(e,t){return e>>>=0,t||D(e,1,this.length),this[e]},o.prototype.readUInt16LE=function(e,t){return e>>>=0,t||D(e,2,this.length),this[e]|this[e+1]<<8},o.prototype.readUInt16BE=function(e,t){return e>>>=0,t||D(e,2,this.length),this[e]<<8|this[e+1]},o.prototype.readUInt32LE=function(e,t){return e>>>=0,t||D(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+16777216*this[e+3]},o.prototype.readUInt32BE=function(e,t){return e>>>=0,t||D(e,4,this.length),16777216*this[e]+(this[e+1]<<16|this[e+2]<<8|this[e+3])},o.prototype.readIntLE=function(e,t,n){e>>>=0,t>>>=0,n||D(e,t,this.length);for(var i=this[e],a=1,o=0;++o<t&&(a*=256);)i+=this[e+o]*a;return a*=128,i>=a&&(i-=r(2,8*t)),i},o.prototype.readIntBE=function(e,t,n){e>>>=0,t>>>=0,n||D(e,t,this.length);for(var i=t,a=1,o=this[e+--i];0<i&&(a*=256);)o+=this[e+--i]*a;return a*=128,o>=a&&(o-=r(2,8*t)),o},o.prototype.readInt8=function(e,t){return e>>>=0,t||D(e,1,this.length),128&this[e]?-1*(255-this[e]+1):this[e]},o.prototype.readInt16LE=function(e,t){e>>>=0,t||D(e,2,this.length);var n=this[e]|this[e+1]<<8;return 32768&n?4294901760|n:n},o.prototype.readInt16BE=function(e,t){e>>>=0,t||D(e,2,this.length);var n=this[e+1]|this[e]<<8;return 32768&n?4294901760|n:n},o.prototype.readInt32LE=function(e,t){return e>>>=0,t||D(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24},o.prototype.readInt32BE=function(e,t){return e>>>=0,t||D(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]},o.prototype.readFloatLE=function(e,t){return e>>>=0,t||D(e,4,this.length),j.read(this,e,!0,23,4)},o.prototype.readFloatBE=function(e,t){return e>>>=0,t||D(e,4,this.length),j.read(this,e,!1,23,4)},o.prototype.readDoubleLE=function(e,t){return e>>>=0,t||D(e,8,this.length),j.read(this,e,!0,52,8)},o.prototype.readDoubleBE=function(e,t){return e>>>=0,t||D(e,8,this.length),j.read(this,e,!1,52,8)},o.prototype.writeUIntLE=function(e,t,n,i){if(e=+e,t>>>=0,n>>>=0,!i){var a=r(2,8*n)-1;O(this,e,t,n,a,0)}var o=1,s=0;for(this[t]=255&e;++s<n&&(o*=256);)this[t+s]=255&e/o;return t+n},o.prototype.writeUIntBE=function(e,t,n,i){if(e=+e,t>>>=0,n>>>=0,!i){var a=r(2,8*n)-1;O(this,e,t,n,a,0)}var o=n-1,s=1;for(this[t+o]=255&e;0<=--o&&(s*=256);)this[t+o]=255&e/s;return t+n},o.prototype.writeUInt8=function(e,t,n){return e=+e,t>>>=0,n||O(this,e,t,1,255,0),this[t]=255&e,t+1},o.prototype.writeUInt16LE=function(e,t,n){return e=+e,t>>>=0,n||O(this,e,t,2,65535,0),this[t]=255&e,this[t+1]=e>>>8,t+2},o.prototype.writeUInt16BE=function(e,t,n){return e=+e,t>>>=0,n||O(this,e,t,2,65535,0),this[t]=e>>>8,this[t+1]=255&e,t+2},o.prototype.writeUInt32LE=function(e,t,n){return e=+e,t>>>=0,n||O(this,e,t,4,4294967295,0),this[t+3]=e>>>24,this[t+2]=e>>>16,this[t+1]=e>>>8,this[t]=255&e,t+4},o.prototype.writeUInt32BE=function(e,t,n){return e=+e,t>>>=0,n||O(this,e,t,4,4294967295,0),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e,t+4},o.prototype.writeIntLE=function(e,t,n,i){if(e=+e,t>>>=0,!i){var a=r(2,8*n-1);O(this,e,t,n,a-1,-a)}var o=0,s=1,c=0;for(this[t]=255&e;++o<n&&(s*=256);)0>e&&c===0&&this[t+o-1]!==0&&(c=1),this[t+o]=255&(e/s>>0)-c;return t+n},o.prototype.writeIntBE=function(e,t,n,i){if(e=+e,t>>>=0,!i){var a=r(2,8*n-1);O(this,e,t,n,a-1,-a)}var o=n-1,s=1,c=0;for(this[t+o]=255&e;0<=--o&&(s*=256);)0>e&&c===0&&this[t+o+1]!==0&&(c=1),this[t+o]=255&(e/s>>0)-c;return t+n},o.prototype.writeInt8=function(e,t,n){return e=+e,t>>>=0,n||O(this,e,t,1,127,-128),0>e&&(e=255+e+1),this[t]=255&e,t+1},o.prototype.writeInt16LE=function(e,t,n){return e=+e,t>>>=0,n||O(this,e,t,2,32767,-32768),this[t]=255&e,this[t+1]=e>>>8,t+2},o.prototype.writeInt16BE=function(e,t,n){return e=+e,t>>>=0,n||O(this,e,t,2,32767,-32768),this[t]=e>>>8,this[t+1]=255&e,t+2},o.prototype.writeInt32LE=function(e,t,n){return e=+e,t>>>=0,n||O(this,e,t,4,2147483647,-2147483648),this[t]=255&e,this[t+1]=e>>>8,this[t+2]=e>>>16,this[t+3]=e>>>24,t+4},o.prototype.writeInt32BE=function(e,t,n){return e=+e,t>>>=0,n||O(this,e,t,4,2147483647,-2147483648),0>e&&(e=4294967295+e+1),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e,t+4},o.prototype.writeFloatLE=function(e,t,n){return se(this,e,t,!0,n)},o.prototype.writeFloatBE=function(e,t,n){return se(this,e,t,!1,n)},o.prototype.writeDoubleLE=function(e,t,n){return ce(this,e,t,!0,n)},o.prototype.writeDoubleBE=function(e,t,n){return ce(this,e,t,!1,n)},o.prototype.copy=function(e,t,n,r){if(!o.isBuffer(e))throw TypeError(`argument should be a Buffer`);if(n||=0,r||r===0||(r=this.length),t>=e.length&&(t=e.length),t||=0,0<r&&r<n&&(r=n),r===n||e.length===0||this.length===0)return 0;if(0>t)throw RangeError(`targetStart out of bounds`);if(0>n||n>=this.length)throw RangeError(`Index out of range`);if(0>r)throw RangeError(`sourceEnd out of bounds`);r>this.length&&(r=this.length),e.length-t<r-n&&(r=e.length-t+n);var i=r-n;if(this===e&&typeof Uint8Array.prototype.copyWithin==`function`)this.copyWithin(t,n,r);else if(this===e&&n<t&&t<r)for(var a=i-1;0<=a;--a)e[a+t]=this[a+n];else Uint8Array.prototype.set.call(e,this.subarray(n,r),t);return i},o.prototype.fill=function(e,t,n,r){if(typeof e==`string`){if(typeof t==`string`?(r=t,t=0,n=this.length):typeof n==`string`&&(r=n,n=this.length),r!==void 0&&typeof r!=`string`)throw TypeError(`encoding must be a string`);if(typeof r==`string`&&!o.isEncoding(r))throw TypeError(`Unknown encoding: `+r);if(e.length===1){var i=e.charCodeAt(0);(r===`utf8`&&128>i||r===`latin1`)&&(e=i)}}else typeof e==`number`&&(e&=255);if(0>t||this.length<t||this.length<n)throw RangeError(`Out of range index`);if(n<=t)return this;t>>>=0,n=n===void 0?this.length:n>>>0,e||=0;var a;if(typeof e==`number`)for(a=t;a<n;++a)this[a]=e;else{var s=o.isBuffer(e)?e:o.from(e,r),c=s.length;if(c===0)throw TypeError(`The value "`+e+`" is invalid for argument "value"`);for(a=0;a<n-t;++a)this[a+t]=s[a%c]}return this};var ve=/[^+/0-9A-Za-z-_]/g}).call(this)}).call(this,e(`buffer`).Buffer)},{"base64-js":1,buffer:3,ieee754:9}],4:[function(e,t,n){(function(r){(function(){function i(){let e;try{e=n.storage.getItem(`debug`)}catch{}return!e&&r!==void 0&&`env`in r&&(e=r.env.DEBUG),e}n.formatArgs=function(e){if(e[0]=(this.useColors?`%c`:``)+this.namespace+(this.useColors?` %c`:` `)+e[0]+(this.useColors?`%c `:` `)+`+`+t.exports.humanize(this.diff),!this.useColors)return;let n=`color: `+this.color;e.splice(1,0,n,`color: inherit`);let r=0,i=0;e[0].replace(/%[a-zA-Z%]/g,e=>{e===`%%`||(r++,e===`%c`&&(i=r))}),e.splice(i,0,n)},n.save=function(e){try{e?n.storage.setItem(`debug`,e):n.storage.removeItem(`debug`)}catch{}},n.load=i,n.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+)/))},n.storage=function(){try{return localStorage}catch{}}(),n.destroy=(()=>{let e=!1;return()=>{e||(e=!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`."))}})(),n.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`.split(`.`),n.log=console.debug||console.log||(()=>{}),t.exports=e(`./common`)(n);let{formatters:a}=t.exports;a.j=function(e){try{return JSON.stringify(e)}catch(e){return`[UnexpectedJSONParseError]: `+e.message}}}).call(this)}).call(this,e(`_process`))},{"./common":5,_process:12}],5:[function(e,n){n.exports=function(n){function r(e){function t(...e){if(!t.enabled)return;let i=t,a=+new Date;i.diff=a-(n||a),i.prev=n,i.curr=a,n=a,e[0]=r.coerce(e[0]),typeof e[0]!=`string`&&e.unshift(`%O`);let o=0;e[0]=e[0].replace(/%([a-zA-Z%])/g,(t,n)=>{if(t===`%%`)return`%`;o++;let a=r.formatters[n];if(typeof a==`function`){let n=e[o];t=a.call(i,n),e.splice(o,1),o--}return t}),r.formatArgs.call(i,e),(i.log||r.log).apply(i,e)}let n,a=null;return t.namespace=e,t.useColors=r.useColors(),t.color=r.selectColor(e),t.extend=i,t.destroy=r.destroy,Object.defineProperty(t,"enabled",{enumerable:!0,configurable:!1,get:()=>a===null?r.enabled(e):a,set:e=>{a=e}}),typeof r.init==`function`&&r.init(t),t}function i(e,t){let n=r(this.namespace+(t===void 0?`:`:t)+e);return n.log=this.log,n}function a(e){return e.toString().substring(2,e.toString().length-2).replace(/\.\*\?$/,`*`)}return r.debug=r,r.default=r,r.coerce=function(e){return e instanceof Error?e.stack||e.message:e},r.disable=function(){let e=[...r.names.map(a),...r.skips.map(a).map(e=>`-`+e)].join(`,`);return r.enable(``),e},r.enable=function(e){r.save(e),r.names=[],r.skips=[];let t,n=(typeof e==`string`?e:``).split(/[\s,]+/),i=n.length;for(t=0;t<i;t++)n[t]&&(e=n[t].replace(/\*/g,`.*?`),e[0]===`-`?r.skips.push(RegExp(`^`+e.substr(1)+`$`)):r.names.push(RegExp(`^`+e+`$`)))},r.enabled=function(e){if(e[e.length-1]===`*`)return!0;let t,n;for(t=0,n=r.skips.length;t<n;t++)if(r.skips[t].test(e))return!1;for(t=0,n=r.names.length;t<n;t++)if(r.names[t].test(e))return!0;return!1},r.humanize=e(`ms`),r.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(n).forEach(e=>{r[e]=n[e]}),r.names=[],r.skips=[],r.formatters={},r.selectColor=function(e){let n=0;for(let t=0;t<e.length;t++)n=(n<<5)-n+e.charCodeAt(t),n|=0;return r.colors[t(n)%r.colors.length]},r.enable(r.load()),r}},{ms:11}],6:[function(e,t){function n(e,t){for(let n in t)Object.defineProperty(e,n,{value:t[n],enumerable:!0,configurable:!0});return e}t.exports=function(e,t,r){if(!e||typeof e==`string`)throw TypeError(`Please pass an Error to err-code`);r||={},typeof t==`object`&&(r=t,t=``),t&&(r.code=t);try{return n(e,r)}catch{r.message=e.message,r.stack=e.stack;let t=function(){};return t.prototype=Object.create(Object.getPrototypeOf(e)),n(new t,r)}}},{}],7:[function(e,t){function n(e){console&&console.warn&&console.warn(e)}function r(){r.init.call(this)}function i(e){if(typeof e!=`function`)throw TypeError(`The "listener" argument must be of type Function. Received type `+typeof e)}function a(e){return e._maxListeners===void 0?r.defaultMaxListeners:e._maxListeners}function o(e,t,r,o){var s,c,l;if(i(r),c=e._events,c===void 0?(c=e._events=Object.create(null),e._eventsCount=0):(c.newListener!==void 0&&(e.emit(`newListener`,t,r.listener?r.listener:r),c=e._events),l=c[t]),l===void 0)l=c[t]=r,++e._eventsCount;else if(typeof l==`function`?l=c[t]=o?[r,l]:[l,r]:o?l.unshift(r):l.push(r),s=a(e),0<s&&l.length>s&&!l.warned){l.warned=!0;var u=Error(`Possible EventEmitter memory leak detected. `+l.length+` `+(t+` listeners added. Use emitter.setMaxListeners() to increase limit`));u.name=`MaxListenersExceededWarning`,u.emitter=e,u.type=t,u.count=l.length,n(u)}return e}function s(){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 c(e,t,n){var r={fired:!1,wrapFn:void 0,target:e,type:t,listener:n},i=s.bind(r);return i.listener=n,r.wrapFn=i,i}function l(e,t,n){var r=e._events;if(r===void 0)return[];var i=r[t];return i===void 0?[]:typeof i==`function`?n?[i.listener||i]:[i]:n?p(i):d(i,i.length)}function u(e){var t=this._events;if(t!==void 0){var n=t[e];if(typeof n==`function`)return 1;if(n!==void 0)return n.length}return 0}function d(e,t){for(var n=Array(t),r=0;r<t;++r)n[r]=e[r];return n}function f(e,t){for(;t+1<e.length;t++)e[t]=e[t+1];e.pop()}function p(e){for(var t=Array(e.length),n=0;n<t.length;++n)t[n]=e[n].listener||e[n];return t}function m(e,t,n){typeof e.on==`function`&&h(e,`error`,t,n)}function h(e,t,n,r){if(typeof e.on==`function`)r.once?e.once(t,n):e.on(t,n);else if(typeof e.addEventListener==`function`)e.addEventListener(t,function i(a){r.once&&e.removeEventListener(t,i),n(a)});else throw TypeError(`The "emitter" argument must be of type EventEmitter. Received type `+typeof e)}var g,_=typeof Reflect==`object`?Reflect:null,v=_&&typeof _.apply==`function`?_.apply:function(e,t,n){return Function.prototype.apply.call(e,t,n)};g=_&&typeof _.ownKeys==`function`?_.ownKeys:Object.getOwnPropertySymbols?function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:function(e){return Object.getOwnPropertyNames(e)};var y=Number.isNaN||function(e){return e!==e};t.exports=r,t.exports.once=function(e,t){return new Promise(function(n,r){function i(n){e.removeListener(t,a),r(n)}function a(){typeof e.removeListener==`function`&&e.removeListener(`error`,i),n([].slice.call(arguments))}h(e,t,a,{once:!0}),t!==`error`&&m(e,i,{once:!0})})},r.EventEmitter=r,r.prototype._events=void 0,r.prototype._eventsCount=0,r.prototype._maxListeners=void 0;var b=10;Object.defineProperty(r,"defaultMaxListeners",{enumerable:!0,get:function(){return b},set:function(e){if(typeof e!=`number`||0>e||y(e))throw RangeError(`The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received `+e+`.`);b=e}}),r.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},r.prototype.setMaxListeners=function(e){if(typeof e!=`number`||0>e||y(e))throw RangeError(`The value of "n" is out of range. It must be a non-negative number. Received `+e+`.`);return this._maxListeners=e,this},r.prototype.getMaxListeners=function(){return a(this)},r.prototype.emit=function(e){for(var t=[],n=1;n<arguments.length;n++)t.push(arguments[n]);var r=e===`error`,i=this._events;if(i!==void 0)r&&=i.error===void 0;else if(!r)return!1;if(r){var a;if(0<t.length&&(a=t[0]),a instanceof Error)throw a;var o=Error(`Unhandled error.`+(a?` (`+a.message+`)`:``));throw o.context=a,o}var s=i[e];if(s===void 0)return!1;if(typeof s==`function`)v(s,this,t);else for(var c=s.length,l=d(s,c),n=0;n<c;++n)v(l[n],this,t);return!0},r.prototype.addListener=function(e,t){return o(this,e,t,!1)},r.prototype.on=r.prototype.addListener,r.prototype.prependListener=function(e,t){return o(this,e,t,!0)},r.prototype.once=function(e,t){return i(t),this.on(e,c(this,e,t)),this},r.prototype.prependOnceListener=function(e,t){return i(t),this.prependListener(e,c(this,e,t)),this},r.prototype.removeListener=function(e,t){var n,r,a,o,s;if(i(t),r=this._events,r===void 0||(n=r[e],n===void 0))return this;if(n===t||n.listener===t)--this._eventsCount==0?this._events=Object.create(null):(delete r[e],r.removeListener&&this.emit(`removeListener`,e,n.listener||t));else if(typeof n!=`function`){for(a=-1,o=n.length-1;0<=o;o--)if(n[o]===t||n[o].listener===t){s=n[o].listener,a=o;break}if(0>a)return this;a===0?n.shift():f(n,a),n.length===1&&(r[e]=n[0]),r.removeListener!==void 0&&this.emit(`removeListener`,e,s||t)}return this},r.prototype.off=r.prototype.removeListener,r.prototype.removeAllListeners=function(e){var t,n,r;if(n=this._events,n===void 0)return this;if(n.removeListener===void 0)return arguments.length===0?(this._events=Object.create(null),this._eventsCount=0):n[e]!==void 0&&(--this._eventsCount==0?this._events=Object.create(null):delete n[e]),this;if(arguments.length===0){var i,a=Object.keys(n);for(r=0;r<a.length;++r)i=a[r],i!==`removeListener`&&this.removeAllListeners(i);return this.removeAllListeners(`removeListener`),this._events=Object.create(null),this._eventsCount=0,this}if(t=n[e],typeof t==`function`)this.removeListener(e,t);else if(t!==void 0)for(r=t.length-1;0<=r;r--)this.removeListener(e,t[r]);return this},r.prototype.listeners=function(e){return l(this,e,!0)},r.prototype.rawListeners=function(e){return l(this,e,!1)},r.listenerCount=function(e,t){return typeof e.listenerCount==`function`?e.listenerCount(t):u.call(e,t)},r.prototype.listenerCount=u,r.prototype.eventNames=function(){return 0<this._eventsCount?g(this._events):[]}},{}],8:[function(e,t){t.exports=function(){if(typeof globalThis>`u`)return null;var e={RTCPeerConnection:globalThis.RTCPeerConnection||globalThis.mozRTCPeerConnection||globalThis.webkitRTCPeerConnection,RTCSessionDescription:globalThis.RTCSessionDescription||globalThis.mozRTCSessionDescription||globalThis.webkitRTCSessionDescription,RTCIceCandidate:globalThis.RTCIceCandidate||globalThis.mozRTCIceCandidate||globalThis.webkitRTCIceCandidate};return e.RTCPeerConnection?e:null}},{}],9:[function(n,i,a){a.read=function(e,t,n,i,a){var o,s,c=8*a-i-1,l=(1<<c)-1,u=l>>1,d=-7,f=n?a-1:0,p=n?-1:1,m=e[t+f];for(f+=p,o=m&(1<<-d)-1,m>>=-d,d+=c;0<d;o=256*o+e[t+f],f+=p,d-=8);for(s=o&(1<<-d)-1,o>>=-d,d+=i;0<d;s=256*s+e[t+f],f+=p,d-=8);if(o===0)o=1-u;else{if(o===l)return s?NaN:(m?-1:1)*(1/0);s+=r(2,i),o-=u}return(m?-1:1)*s*r(2,o-i)},a.write=function(n,i,a,o,s,c){var l,u,d,f=Math.LN2,p=Math.log,m=8*c-s-1,h=(1<<m)-1,g=h>>1,_=s===23?r(2,-24)-r(2,-77):0,v=o?0:c-1,y=o?1:-1,b=+(0>i||i===0&&0>1/i);for(i=t(i),isNaN(i)||i===1/0?(u=+!!isNaN(i),l=h):(l=e(p(i)/f),1>i*(d=r(2,-l))&&(l--,d*=2),i+=1<=l+g?_/d:_*r(2,1-g),2<=i*d&&(l++,d/=2),l+g>=h?(u=0,l=h):1<=l+g?(u=(i*d-1)*r(2,s),l+=g):(u=i*r(2,g-1)*r(2,s),l=0));8<=s;n[a+v]=255&u,v+=y,u/=256,s-=8);for(l=l<<s|u,m+=s;0<m;n[a+v]=255&l,v+=y,l/=256,m-=8);n[a+v-y]|=128*b}},{}],10:[function(e,t){t.exports=typeof Object.create==`function`?function(e,t){t&&(e.super_=t,e.prototype=Object.create(t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}))}:function(e,t){if(t){e.super_=t;var n=function(){};n.prototype=t.prototype,e.prototype=new n,e.prototype.constructor=e}}},{}],11:[function(e,n){var r=Math.round;function i(e){if(e+=``,!(100<e.length)){var t=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(e);if(t){var n=parseFloat(t[1]),r=(t[2]||`ms`).toLowerCase();return r===`years`||r===`year`||r===`yrs`||r===`yr`||r===`y`?315576e5*n:r===`weeks`||r===`week`||r===`w`?6048e5*n:r===`days`||r===`day`||r===`d`?864e5*n:r===`hours`||r===`hour`||r===`hrs`||r===`hr`||r===`h`?36e5*n:r===`minutes`||r===`minute`||r===`mins`||r===`min`||r===`m`?6e4*n:r===`seconds`||r===`second`||r===`secs`||r===`sec`||r===`s`?1e3*n:r===`milliseconds`||r===`millisecond`||r===`msecs`||r===`msec`||r===`ms`?n:void 0}}}function a(e){var n=t(e);return 864e5<=n?r(e/864e5)+`d`:36e5<=n?r(e/36e5)+`h`:6e4<=n?r(e/6e4)+`m`:1e3<=n?r(e/1e3)+`s`:e+`ms`}function o(e){var n=t(e);return 864e5<=n?s(e,n,864e5,`day`):36e5<=n?s(e,n,36e5,`hour`):6e4<=n?s(e,n,6e4,`minute`):1e3<=n?s(e,n,1e3,`second`):e+` ms`}function s(e,t,n,i){return r(e/n)+` `+i+(t>=1.5*n?`s`:``)}n.exports=function(e,t){t||={};var n=typeof e;if(n==`string`&&0<e.length)return i(e);if(n===`number`&&isFinite(e))return t.long?o(e):a(e);throw Error(`val is not a non-empty string or a valid number. val=`+JSON.stringify(e))}},{}],12:[function(e,t){function n(){throw Error(`setTimeout has not been defined`)}function r(){throw Error(`clearTimeout has not been defined`)}function i(e){if(u===setTimeout)return setTimeout(e,0);if((u===n||!u)&&setTimeout)return u=setTimeout,setTimeout(e,0);try{return u(e,0)}catch{try{return u.call(null,e,0)}catch{return u.call(this,e,0)}}}function a(e){if(d===clearTimeout)return clearTimeout(e);if((d===r||!d)&&clearTimeout)return d=clearTimeout,clearTimeout(e);try{return d(e)}catch{try{return d.call(null,e)}catch{return d.call(this,e)}}}function o(){h&&p&&(h=!1,p.length?m=p.concat(m):g=-1,m.length&&s())}function s(){if(!h){var e=i(o);h=!0;for(var t=m.length;t;){for(p=m,m=[];++g<t;)p&&p[g].run();g=-1,t=m.length}p=null,h=!1,a(e)}}function c(e,t){this.fun=e,this.array=t}function l(){}var u,d,f=t.exports={};(function(){try{u=typeof setTimeout==`function`?setTimeout:n}catch{u=n}try{d=typeof clearTimeout==`function`?clearTimeout:r}catch{d=r}})();var p,m=[],h=!1,g=-1;f.nextTick=function(e){var t=Array(arguments.length-1);if(1<arguments.length)for(var n=1;n<arguments.length;n++)t[n-1]=arguments[n];m.push(new c(e,t)),m.length!==1||h||i(s)},c.prototype.run=function(){this.fun.apply(null,this.array)},f.title=`browser`,f.browser=!0,f.env={},f.argv=[],f.version=``,f.versions={},f.on=l,f.addListener=l,f.once=l,f.off=l,f.removeListener=l,f.removeAllListeners=l,f.emit=l,f.prependListener=l,f.prependOnceListener=l,f.listeners=function(){return[]},f.binding=function(){throw Error(`process.binding is not supported`)},f.cwd=function(){return`/`},f.chdir=function(){throw Error(`process.chdir is not supported`)},f.umask=function(){return 0}},{}],13:[function(e,t){(function(e){(function(){let n;t.exports=typeof queueMicrotask==`function`?queueMicrotask.bind(typeof window>`u`?e:window):e=>(n||=Promise.resolve()).then(e).catch(e=>setTimeout(()=>{throw e},0))}).call(this)}).call(this,typeof global>`u`?typeof self>`u`?typeof window>`u`?{}:window:self:global)},{}],14:[function(e,t){(function(n,r){(function(){var i=e(`safe-buffer`).Buffer,a=r.crypto||r.msCrypto;t.exports=a&&a.getRandomValues?function(e,t){if(e>4294967295)throw RangeError(`requested too many random bytes`);var r=i.allocUnsafe(e);if(0<e)if(65536<e)for(var o=0;o<e;o+=65536)a.getRandomValues(r.slice(o,o+65536));else a.getRandomValues(r);return typeof t==`function`?n.nextTick(function(){t(null,r)}):r}:function(){throw Error(`Secure random number generation is not supported by this browser.
|
|
6
|
+
Use Chrome, Firefox or Internet Explorer 11`)}}).call(this)}).call(this,e(`_process`),typeof global>`u`?typeof self>`u`?typeof window>`u`?{}:window:self:global)},{_process:12,"safe-buffer":30}],15:[function(e,t){function n(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,e.__proto__=t}function r(e,t,r){function i(e,n,r){return typeof t==`string`?t:t(e,n,r)}r||=Error;var a=function(e){function t(t,n,r){return e.call(this,i(t,n,r))||this}return n(t,e),t}(r);a.prototype.name=r.name,a.prototype.code=e,c[e]=a}function i(e,t){if(Array.isArray(e)){var n=e.length;return e=e.map(function(e){return e+``}),2<n?`one of ${t} ${e.slice(0,n-1).join(`, `)}, or `+e[n-1]:n===2?`one of ${t} ${e[0]} or ${e[1]}`:`of ${t} ${e[0]}`}return`of ${t} ${e+``}`}function a(e,t,n){return e.substr(!n||0>n?0:+n,t.length)===t}function o(e,t,n){return(n===void 0||n>e.length)&&(n=e.length),e.substring(n-t.length,n)===t}function s(e,t,n){return typeof n!=`number`&&(n=0),!(n+t.length>e.length)&&e.indexOf(t,n)!==-1}var c={};r(`ERR_INVALID_OPT_VALUE`,function(e,t){return`The value "`+t+`" is invalid for option "`+e+`"`},TypeError),r(`ERR_INVALID_ARG_TYPE`,function(e,t,n){var r;typeof t==`string`&&a(t,`not `)?(r=`must not be`,t=t.replace(/^not /,``)):r=`must be`;var c=o(e,` argument`)?`The ${e} ${r} ${i(t,`type`)}`:`The "${e}" ${s(e,`.`)?`property`:`argument`} ${r} ${i(t,`type`)}`;return c+=`. Received type ${typeof n}`,c},TypeError),r(`ERR_STREAM_PUSH_AFTER_EOF`,`stream.push() after EOF`),r(`ERR_METHOD_NOT_IMPLEMENTED`,function(e){return`The `+e+` method is not implemented`}),r(`ERR_STREAM_PREMATURE_CLOSE`,`Premature close`),r(`ERR_STREAM_DESTROYED`,function(e){return`Cannot call `+e+` after a stream was destroyed`}),r(`ERR_MULTIPLE_CALLBACK`,`Callback called multiple times`),r(`ERR_STREAM_CANNOT_PIPE`,`Cannot pipe, not readable`),r(`ERR_STREAM_WRITE_AFTER_END`,`write after end`),r(`ERR_STREAM_NULL_VALUES`,`May not write null values to stream`,TypeError),r(`ERR_UNKNOWN_ENCODING`,function(e){return`Unknown encoding: `+e},TypeError),r(`ERR_STREAM_UNSHIFT_AFTER_END_EVENT`,`stream.unshift() after end event`),t.exports.codes=c},{}],16:[function(e,t){(function(n){(function(){function r(e){return this instanceof r?void(s.call(this,e),c.call(this,e),this.allowHalfOpen=!0,e&&(!1===e.readable&&(this.readable=!1),!1===e.writable&&(this.writable=!1),!1===e.allowHalfOpen&&(this.allowHalfOpen=!1,this.once(`end`,i)))):new r(e)}function i(){this._writableState.ended||n.nextTick(a,this)}function a(e){e.end()}var o=Object.keys||function(e){var t=[];for(var n in e)t.push(n);return t};t.exports=r;var s=e(`./_stream_readable`),c=e(`./_stream_writable`);e(`inherits`)(r,s);for(var l,u=o(c.prototype),d=0;d<u.length;d++)l=u[d],r.prototype[l]||(r.prototype[l]=c.prototype[l]);Object.defineProperty(r.prototype,"writableHighWaterMark",{enumerable:!1,get:function(){return this._writableState.highWaterMark}}),Object.defineProperty(r.prototype,"writableBuffer",{enumerable:!1,get:function(){return this._writableState&&this._writableState.getBuffer()}}),Object.defineProperty(r.prototype,"writableLength",{enumerable:!1,get:function(){return this._writableState.length}}),Object.defineProperty(r.prototype,"destroyed",{enumerable:!1,get:function(){return this._readableState!==void 0&&this._writableState!==void 0&&this._readableState.destroyed&&this._writableState.destroyed},set:function(e){this._readableState===void 0||this._writableState===void 0||(this._readableState.destroyed=e,this._writableState.destroyed=e)}})}).call(this)}).call(this,e(`_process`))},{"./_stream_readable":18,"./_stream_writable":20,_process:12,inherits:10}],17:[function(e,t){function n(e){return this instanceof n?void r.call(this,e):new n(e)}t.exports=n;var r=e(`./_stream_transform`);e(`inherits`)(n,r),n.prototype._transform=function(e,t,n){n(null,e)}},{"./_stream_transform":19,inherits:10}],18:[function(e,t){(function(n,r){(function(){function i(e){return oe.from(e)}function a(e){return oe.isBuffer(e)||e instanceof D}function o(e,t,n){return typeof e.prependListener==`function`?e.prependListener(t,n):void(e._events&&e._events[t]?Array.isArray(e._events[t])?e._events[t].unshift(n):e._events[t]=[n,e._events[t]]:e.on(t,n))}function s(t,n,r){ie||=e(`./_stream_duplex`),t||={},typeof r!=`boolean`&&(r=n instanceof ie),this.objectMode=!!t.objectMode,r&&(this.objectMode=this.objectMode||!!t.readableObjectMode),this.highWaterMark=A(this,t,`readableHighWaterMark`,r),this.buffer=new le,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=!1!==t.emitClose,this.autoDestroy=!!t.autoDestroy,this.destroyed=!1,this.defaultEncoding=t.defaultEncoding||`utf8`,this.awaitDrain=0,this.readingMore=!1,this.decoder=null,this.encoding=null,t.encoding&&(!k&&(k=e(`string_decoder/`).StringDecoder),this.decoder=new k(t.encoding),this.encoding=t.encoding)}function c(t){if(ie||=e(`./_stream_duplex`),!(this instanceof c))return new c(t);var n=this instanceof ie;this._readableState=new s(t,this,n),this.readable=!0,t&&(typeof t.read==`function`&&(this._read=t.read),typeof t.destroy==`function`&&(this._destroy=t.destroy)),E.call(this)}function l(e,t,n,r,a){T(`readableAddChunk`,t);var o=e._readableState;if(t===null)o.reading=!1,m(e,o);else{var s;if(a||(s=d(o,t)),s)ge(e,s);else if(!(o.objectMode||t&&0<t.length))r||(o.reading=!1,_(e,o));else if(typeof t==`string`||o.objectMode||Object.getPrototypeOf(t)===oe.prototype||(t=i(t)),r)o.endEmitted?ge(e,new he):u(e,o,t,!0);else if(o.ended)ge(e,new pe);else{if(o.destroyed)return!1;o.reading=!1,o.decoder&&!n?(t=o.decoder.write(t),o.objectMode||t.length!==0?u(e,o,t,!1):_(e,o)):u(e,o,t,!1)}}return!o.ended&&(o.length<o.highWaterMark||o.length===0)}function u(e,t,n,r){t.flowing&&t.length===0&&!t.sync?(t.awaitDrain=0,e.emit(`data`,n)):(t.length+=t.objectMode?1:n.length,r?t.buffer.unshift(n):t.buffer.push(n),t.needReadable&&h(e)),_(e,t)}function d(e,t){var n;return a(t)||typeof t==`string`||t===void 0||e.objectMode||(n=new fe(`chunk`,[`string`,`Buffer`,`Uint8Array`],t)),n}function f(e){return 1073741824<=e?e=1073741824:(e--,e|=e>>>1,e|=e>>>2,e|=e>>>4,e|=e>>>8,e|=e>>>16,e++),e}function p(e,t){return 0>=e||t.length===0&&t.ended?0:t.objectMode?1:e===e?(e>t.highWaterMark&&(t.highWaterMark=f(e)),e<=t.length?e:t.ended?t.length:(t.needReadable=!0,0)):t.flowing&&t.length?t.buffer.head.data.length:t.length}function m(e,t){if(T(`onEofChunk`),!t.ended){if(t.decoder){var n=t.decoder.end();n&&n.length&&(t.buffer.push(n),t.length+=t.objectMode?1:n.length)}t.ended=!0,t.sync?h(e):(t.needReadable=!1,!t.emittedReadable&&(t.emittedReadable=!0,g(e)))}}function h(e){var t=e._readableState;T(`emitReadable`,t.needReadable,t.emittedReadable),t.needReadable=!1,t.emittedReadable||(T(`emitReadable`,t.flowing),t.emittedReadable=!0,n.nextTick(g,e))}function g(e){var t=e._readableState;T(`emitReadable_`,t.destroyed,t.length,t.ended),!t.destroyed&&(t.length||t.ended)&&(e.emit(`readable`),t.emittedReadable=!1),t.needReadable=!t.flowing&&!t.ended&&t.length<=t.highWaterMark,S(e)}function _(e,t){t.readingMore||(t.readingMore=!0,n.nextTick(v,e,t))}function v(e,t){for(;!t.reading&&!t.ended&&(t.length<t.highWaterMark||t.flowing&&t.length===0);){var n=t.length;if(T(`maybeReadMore read 0`),e.read(0),n===t.length)break}t.readingMore=!1}function y(e){return function(){var t=e._readableState;T(`pipeOnDrain`,t.awaitDrain),t.awaitDrain&&t.awaitDrain--,t.awaitDrain===0&&ae(e,`data`)&&(t.flowing=!0,S(e))}}function b(e){var t=e._readableState;t.readableListening=0<e.listenerCount(`readable`),t.resumeScheduled&&!t.paused?t.flowing=!0:0<e.listenerCount(`data`)&&e.resume()}function x(e){T(`readable nexttick read 0`),e.read(0)}function ee(e,t){t.resumeScheduled||(t.resumeScheduled=!0,n.nextTick(te,e,t))}function te(e,t){T(`resume`,t.reading),t.reading||e.read(0),t.resumeScheduled=!1,e.emit(`resume`),S(e),t.flowing&&!t.reading&&e.read(0)}function S(e){var t=e._readableState;for(T(`flow`,t.flowing);t.flowing&&e.read()!==null;);}function ne(e,t){if(t.length===0)return null;var n;return t.objectMode?n=t.buffer.shift():!e||e>=t.length?(n=t.decoder?t.buffer.join(``):t.buffer.length===1?t.buffer.first():t.buffer.concat(t.length),t.buffer.clear()):n=t.buffer.consume(e,t.decoder),n}function re(e){var t=e._readableState;T(`endReadable`,t.endEmitted),t.endEmitted||(t.ended=!0,n.nextTick(C,t,e))}function C(e,t){if(T(`endReadableNT`,e.endEmitted,e.length),!e.endEmitted&&e.length===0&&(e.endEmitted=!0,t.readable=!1,t.emit(`end`),e.autoDestroy)){var n=t._writableState;(!n||n.autoDestroy&&n.finished)&&t.destroy()}}function w(e,t){for(var n=0,r=e.length;n<r;n++)if(e[n]===t)return n;return-1}t.exports=c;var ie;c.ReadableState=s;var T;e(`events`).EventEmitter;var ae=function(e,t){return e.listeners(t).length},E=e(`./internal/streams/stream`),oe=e(`buffer`).Buffer,D=r.Uint8Array||function(){},O=e(`util`);T=O&&O.debuglog?O.debuglog(`stream`):function(){};var k,se,ce,le=e(`./internal/streams/buffer_list`),ue=e(`./internal/streams/destroy`),A=e(`./internal/streams/state`).getHighWaterMark,de=e(`../errors`).codes,fe=de.ERR_INVALID_ARG_TYPE,pe=de.ERR_STREAM_PUSH_AFTER_EOF,me=de.ERR_METHOD_NOT_IMPLEMENTED,he=de.ERR_STREAM_UNSHIFT_AFTER_END_EVENT;e(`inherits`)(c,E);var ge=ue.errorOrDestroy,_e=[`error`,`close`,`destroy`,`pause`,`resume`];Object.defineProperty(c.prototype,"destroyed",{enumerable:!1,get:function(){return this._readableState!==void 0&&this._readableState.destroyed},set:function(e){this._readableState&&(this._readableState.destroyed=e)}}),c.prototype.destroy=ue.destroy,c.prototype._undestroy=ue.undestroy,c.prototype._destroy=function(e,t){t(e)},c.prototype.push=function(e,t){var n,r=this._readableState;return r.objectMode?n=!0:typeof e==`string`&&(t||=r.defaultEncoding,t!==r.encoding&&(e=oe.from(e,t),t=``),n=!0),l(this,e,t,!1,n)},c.prototype.unshift=function(e){return l(this,e,null,!0,!1)},c.prototype.isPaused=function(){return!1===this._readableState.flowing},c.prototype.setEncoding=function(t){k||=e(`string_decoder/`).StringDecoder;var n=new k(t);this._readableState.decoder=n,this._readableState.encoding=this._readableState.decoder.encoding;for(var r=this._readableState.buffer.head,i=``;r!==null;)i+=n.write(r.data),r=r.next;return this._readableState.buffer.clear(),i!==``&&this._readableState.buffer.push(i),this._readableState.length=i.length,this},c.prototype.read=function(e){T(`read`,e),e=parseInt(e,10);var t=this._readableState,n=e;if(e!==0&&(t.emittedReadable=!1),e===0&&t.needReadable&&((t.highWaterMark===0?0<t.length:t.length>=t.highWaterMark)||t.ended))return T(`read: emitReadable`,t.length,t.ended),t.length===0&&t.ended?re(this):h(this),null;if(e=p(e,t),e===0&&t.ended)return t.length===0&&re(this),null;var r=t.needReadable;T(`need readable`,r),(t.length===0||t.length-e<t.highWaterMark)&&(r=!0,T(`length less than watermark`,r)),t.ended||t.reading?(r=!1,T(`reading or ended`,r)):r&&(T(`do read`),t.reading=!0,t.sync=!0,t.length===0&&(t.needReadable=!0),this._read(t.highWaterMark),t.sync=!1,!t.reading&&(e=p(n,t)));var i;return i=0<e?ne(e,t):null,i===null?(t.needReadable=t.length<=t.highWaterMark,e=0):(t.length-=e,t.awaitDrain=0),t.length===0&&(!t.ended&&(t.needReadable=!0),n!==e&&t.ended&&re(this)),i!==null&&this.emit(`data`,i),i},c.prototype._read=function(){ge(this,new me(`_read()`))},c.prototype.pipe=function(e,t){function r(e,t){T(`onunpipe`),e===f&&t&&!1===t.hasUnpiped&&(t.hasUnpiped=!0,a())}function i(){T(`onend`),e.end()}function a(){T(`cleanup`),e.removeListener(`close`,l),e.removeListener(`finish`,u),e.removeListener(`drain`,h),e.removeListener(`error`,c),e.removeListener(`unpipe`,r),f.removeListener(`end`,i),f.removeListener(`end`,d),f.removeListener(`data`,s),g=!0,p.awaitDrain&&(!e._writableState||e._writableState.needDrain)&&h()}function s(t){T(`ondata`);var n=e.write(t);T(`dest.write`,n),!1===n&&((p.pipesCount===1&&p.pipes===e||1<p.pipesCount&&w(p.pipes,e)!==-1)&&!g&&(T(`false write response, pause`,p.awaitDrain),p.awaitDrain++),f.pause())}function c(t){T(`onerror`,t),d(),e.removeListener(`error`,c),ae(e,`error`)===0&&ge(e,t)}function l(){e.removeListener(`finish`,u),d()}function u(){T(`onfinish`),e.removeListener(`close`,l),d()}function d(){T(`unpipe`),f.unpipe(e)}var f=this,p=this._readableState;switch(p.pipesCount){case 0:p.pipes=e;break;case 1:p.pipes=[p.pipes,e];break;default:p.pipes.push(e)}p.pipesCount+=1,T(`pipe count=%d opts=%j`,p.pipesCount,t);var m=(!t||!1!==t.end)&&e!==n.stdout&&e!==n.stderr?i:d;p.endEmitted?n.nextTick(m):f.once(`end`,m),e.on(`unpipe`,r);var h=y(f);e.on(`drain`,h);var g=!1;return f.on(`data`,s),o(e,`error`,c),e.once(`close`,l),e.once(`finish`,u),e.emit(`pipe`,f),p.flowing||(T(`pipe resume`),f.resume()),e},c.prototype.unpipe=function(e){var t=this._readableState,n={hasUnpiped:!1};if(t.pipesCount===0)return this;if(t.pipesCount===1)return e&&e!==t.pipes?this:(e||=t.pipes,t.pipes=null,t.pipesCount=0,t.flowing=!1,e&&e.emit(`unpipe`,this,n),this);if(!e){var r=t.pipes,i=t.pipesCount;t.pipes=null,t.pipesCount=0,t.flowing=!1;for(var a=0;a<i;a++)r[a].emit(`unpipe`,this,{hasUnpiped:!1});return this}var o=w(t.pipes,e);return o===-1?this:(t.pipes.splice(o,1),--t.pipesCount,t.pipesCount===1&&(t.pipes=t.pipes[0]),e.emit(`unpipe`,this,n),this)},c.prototype.on=function(e,t){var r=E.prototype.on.call(this,e,t),i=this._readableState;return e===`data`?(i.readableListening=0<this.listenerCount(`readable`),!1!==i.flowing&&this.resume()):e==`readable`&&!i.endEmitted&&!i.readableListening&&(i.readableListening=i.needReadable=!0,i.flowing=!1,i.emittedReadable=!1,T(`on readable`,i.length,i.reading),i.length?h(this):!i.reading&&n.nextTick(x,this)),r},c.prototype.addListener=c.prototype.on,c.prototype.removeListener=function(e,t){var r=E.prototype.removeListener.call(this,e,t);return e===`readable`&&n.nextTick(b,this),r},c.prototype.removeAllListeners=function(e){var t=E.prototype.removeAllListeners.apply(this,arguments);return(e===`readable`||e===void 0)&&n.nextTick(b,this),t},c.prototype.resume=function(){var e=this._readableState;return e.flowing||(T(`resume`),e.flowing=!e.readableListening,ee(this,e)),e.paused=!1,this},c.prototype.pause=function(){return T(`call pause flowing=%j`,this._readableState.flowing),!1!==this._readableState.flowing&&(T(`pause`),this._readableState.flowing=!1,this.emit(`pause`)),this._readableState.paused=!0,this},c.prototype.wrap=function(e){var t=this,n=this._readableState,r=!1;for(var i in e.on(`end`,function(){if(T(`wrapped end`),n.decoder&&!n.ended){var e=n.decoder.end();e&&e.length&&t.push(e)}t.push(null)}),e.on(`data`,function(i){(T(`wrapped data`),n.decoder&&(i=n.decoder.write(i)),!(n.objectMode&&i==null))&&(n.objectMode||i&&i.length)&&(t.push(i)||(r=!0,e.pause()))}),e)this[i]===void 0&&typeof e[i]==`function`&&(this[i]=function(t){return function(){return e[t].apply(e,arguments)}}(i));for(var a=0;a<_e.length;a++)e.on(_e[a],this.emit.bind(this,_e[a]));return this._read=function(t){T(`wrapped _read`,t),r&&(r=!1,e.resume())},this},typeof Symbol==`function`&&(c.prototype[Symbol.asyncIterator]=function(){return se===void 0&&(se=e(`./internal/streams/async_iterator`)),se(this)}),Object.defineProperty(c.prototype,"readableHighWaterMark",{enumerable:!1,get:function(){return this._readableState.highWaterMark}}),Object.defineProperty(c.prototype,"readableBuffer",{enumerable:!1,get:function(){return this._readableState&&this._readableState.buffer}}),Object.defineProperty(c.prototype,"readableFlowing",{enumerable:!1,get:function(){return this._readableState.flowing},set:function(e){this._readableState&&(this._readableState.flowing=e)}}),c._fromList=ne,Object.defineProperty(c.prototype,"readableLength",{enumerable:!1,get:function(){return this._readableState.length}}),typeof Symbol==`function`&&(c.from=function(t,n){return ce===void 0&&(ce=e(`./internal/streams/from`)),ce(c,t,n)})}).call(this)}).call(this,e(`_process`),typeof global>`u`?typeof self>`u`?typeof window>`u`?{}:window:self:global)},{"../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(e,t){function n(e,t){var n=this._transformState;n.transforming=!1;var r=n.writecb;if(r===null)return this.emit(`error`,new c);n.writechunk=null,n.writecb=null,t!=null&&this.push(t),r(e);var i=this._readableState;i.reading=!1,(i.needReadable||i.length<i.highWaterMark)&&this._read(i.highWaterMark)}function r(e){return this instanceof r?void(d.call(this,e),this._transformState={afterTransform:n.bind(this),needTransform:!1,transforming:!1,writecb:null,writechunk:null,writeencoding:null},this._readableState.needReadable=!0,this._readableState.sync=!1,e&&(typeof e.transform==`function`&&(this._transform=e.transform),typeof e.flush==`function`&&(this._flush=e.flush)),this.on(`prefinish`,i)):new r(e)}function i(){var e=this;typeof this._flush!=`function`||this._readableState.destroyed?a(this,null,null):this._flush(function(t,n){a(e,t,n)})}function a(e,t,n){if(t)return e.emit(`error`,t);if(n!=null&&e.push(n),e._writableState.length)throw new u;if(e._transformState.transforming)throw new l;return e.push(null)}t.exports=r;var o=e(`../errors`).codes,s=o.ERR_METHOD_NOT_IMPLEMENTED,c=o.ERR_MULTIPLE_CALLBACK,l=o.ERR_TRANSFORM_ALREADY_TRANSFORMING,u=o.ERR_TRANSFORM_WITH_LENGTH_0,d=e(`./_stream_duplex`);e(`inherits`)(r,d),r.prototype.push=function(e,t){return this._transformState.needTransform=!1,d.prototype.push.call(this,e,t)},r.prototype._transform=function(e,t,n){n(new s(`_transform()`))},r.prototype._write=function(e,t,n){var r=this._transformState;if(r.writecb=n,r.writechunk=e,r.writeencoding=t,!r.transforming){var i=this._readableState;(r.needTransform||i.needReadable||i.length<i.highWaterMark)&&this._read(i.highWaterMark)}},r.prototype._read=function(){var e=this._transformState;e.writechunk===null||e.transforming?e.needTransform=!0:(e.transforming=!0,this._transform(e.writechunk,e.writeencoding,e.afterTransform))},r.prototype._destroy=function(e,t){d.prototype._destroy.call(this,e,function(e){t(e)})}},{"../errors":15,"./_stream_duplex":16,inherits:10}],20:[function(e,t){(function(n,r){(function(){function i(e){var t=this;this.next=null,this.entry=null,this.finish=function(){re(t,e)}}function a(e){return T.from(e)}function o(e){return T.isBuffer(e)||e instanceof ae}function s(){}function c(t,n,r){C||=e(`./_stream_duplex`),t||={},typeof r!=`boolean`&&(r=n instanceof C),this.objectMode=!!t.objectMode,r&&(this.objectMode=this.objectMode||!!t.writableObjectMode),this.highWaterMark=oe(this,t,`writableHighWaterMark`,r),this.finalCalled=!1,this.needDrain=!1,this.ending=!1,this.ended=!1,this.finished=!1,this.destroyed=!1;var a=!1===t.decodeStrings;this.decodeStrings=!a,this.defaultEncoding=t.defaultEncoding||`utf8`,this.length=0,this.writing=!1,this.corked=0,this.sync=!0,this.bufferProcessing=!1,this.onwrite=function(e){_(n,e)},this.writecb=null,this.writelen=0,this.bufferedRequest=null,this.lastBufferedRequest=null,this.pendingcb=0,this.prefinished=!1,this.errorEmitted=!1,this.emitClose=!1!==t.emitClose,this.autoDestroy=!!t.autoDestroy,this.bufferedRequestCount=0,this.corkedRequestsFree=new i(this)}function l(t){C||=e(`./_stream_duplex`);var n=this instanceof C;return n||pe.call(l,this)?void(this._writableState=new c(t,this,n),this.writable=!0,t&&(typeof t.write==`function`&&(this._write=t.write),typeof t.writev==`function`&&(this._writev=t.writev),typeof t.destroy==`function`&&(this._destroy=t.destroy),typeof t.final==`function`&&(this._final=t.final)),ie.call(this)):new l(t)}function u(e,t){var r=new A;fe(e,r),n.nextTick(t,r)}function d(e,t,r,i){var a;return r===null?a=new ue:typeof r!=`string`&&!t.objectMode&&(a=new O(`chunk`,[`string`,`Buffer`],r)),!a||(fe(e,a),n.nextTick(i,a),!1)}function f(e,t,n){return e.objectMode||!1===e.decodeStrings||typeof t!=`string`||(t=T.from(t,n)),t}function p(e,t,n,r,i,a){if(!n){var o=f(t,r,i);r!==o&&(n=!0,i=`buffer`,r=o)}var s=t.objectMode?1:r.length;t.length+=s;var c=t.length<t.highWaterMark;if(c||(t.needDrain=!0),t.writing||t.corked){var l=t.lastBufferedRequest;t.lastBufferedRequest={chunk:r,encoding:i,isBuf:n,callback:a,next:null},l?l.next=t.lastBufferedRequest:t.bufferedRequest=t.lastBufferedRequest,t.bufferedRequestCount+=1}else m(e,t,!1,s,r,i,a);return c}function m(e,t,n,r,i,a,o){t.writelen=r,t.writecb=o,t.writing=!0,t.sync=!0,t.destroyed?t.onwrite(new le(`write`)):n?e._writev(i,t.onwrite):e._write(i,a,t.onwrite),t.sync=!1}function h(e,t,r,i,a){--t.pendingcb,r?(n.nextTick(a,i),n.nextTick(S,e,t),e._writableState.errorEmitted=!0,fe(e,i)):(a(i),e._writableState.errorEmitted=!0,fe(e,i),S(e,t))}function g(e){e.writing=!1,e.writecb=null,e.length-=e.writelen,e.writelen=0}function _(e,t){var r=e._writableState,i=r.sync,a=r.writecb;if(typeof a!=`function`)throw new se;if(g(r),t)h(e,r,i,t,a);else{var o=x(r)||e.destroyed;o||r.corked||r.bufferProcessing||!r.bufferedRequest||b(e,r),i?n.nextTick(v,e,r,o,a):v(e,r,o,a)}}function v(e,t,n,r){n||y(e,t),t.pendingcb--,r(),S(e,t)}function y(e,t){t.length===0&&t.needDrain&&(t.needDrain=!1,e.emit(`drain`))}function b(e,t){t.bufferProcessing=!0;var n=t.bufferedRequest;if(e._writev&&n&&n.next){var r=t.bufferedRequestCount,a=Array(r),o=t.corkedRequestsFree;o.entry=n;for(var s=0,c=!0;n;)a[s]=n,n.isBuf||(c=!1),n=n.next,s+=1;a.allBuffers=c,m(e,t,!0,t.length,a,``,o.finish),t.pendingcb++,t.lastBufferedRequest=null,o.next?(t.corkedRequestsFree=o.next,o.next=null):t.corkedRequestsFree=new i(t),t.bufferedRequestCount=0}else{for(;n;){var l=n.chunk,u=n.encoding,d=n.callback;if(m(e,t,!1,t.objectMode?1:l.length,l,u,d),n=n.next,t.bufferedRequestCount--,t.writing)break}n===null&&(t.lastBufferedRequest=null)}t.bufferedRequest=n,t.bufferProcessing=!1}function x(e){return e.ending&&e.length===0&&e.bufferedRequest===null&&!e.finished&&!e.writing}function ee(e,t){e._final(function(n){t.pendingcb--,n&&fe(e,n),t.prefinished=!0,e.emit(`prefinish`),S(e,t)})}function te(e,t){t.prefinished||t.finalCalled||(typeof e._final!=`function`||t.destroyed?(t.prefinished=!0,e.emit(`prefinish`)):(t.pendingcb++,t.finalCalled=!0,n.nextTick(ee,e,t)))}function S(e,t){var n=x(t);if(n&&(te(e,t),t.pendingcb===0&&(t.finished=!0,e.emit(`finish`),t.autoDestroy))){var r=e._readableState;(!r||r.autoDestroy&&r.endEmitted)&&e.destroy()}return n}function ne(e,t,r){t.ending=!0,S(e,t),r&&(t.finished?n.nextTick(r):e.once(`finish`,r)),t.ended=!0,e.writable=!1}function re(e,t,n){var r=e.entry;for(e.entry=null;r;){var i=r.callback;t.pendingcb--,i(n),r=r.next}t.corkedRequestsFree.next=e}t.exports=l;var C;l.WritableState=c;var w={deprecate:e(`util-deprecate`)},ie=e(`./internal/streams/stream`),T=e(`buffer`).Buffer,ae=r.Uint8Array||function(){},E=e(`./internal/streams/destroy`),oe=e(`./internal/streams/state`).getHighWaterMark,D=e(`../errors`).codes,O=D.ERR_INVALID_ARG_TYPE,k=D.ERR_METHOD_NOT_IMPLEMENTED,se=D.ERR_MULTIPLE_CALLBACK,ce=D.ERR_STREAM_CANNOT_PIPE,le=D.ERR_STREAM_DESTROYED,ue=D.ERR_STREAM_NULL_VALUES,A=D.ERR_STREAM_WRITE_AFTER_END,de=D.ERR_UNKNOWN_ENCODING,fe=E.errorOrDestroy;e(`inherits`)(l,ie),c.prototype.getBuffer=function(){for(var e=this.bufferedRequest,t=[];e;)t.push(e),e=e.next;return t},function(){try{Object.defineProperty(c.prototype,"buffer",{get:w.deprecate(function(){return this.getBuffer()},`_writableState.buffer is deprecated. Use _writableState.getBuffer instead.`,`DEP0003`)})}catch{}}();var pe;typeof Symbol==`function`&&Symbol.hasInstance&&typeof Function.prototype[Symbol.hasInstance]==`function`?(pe=Function.prototype[Symbol.hasInstance],Object.defineProperty(l,Symbol.hasInstance,{value:function(e){return!!pe.call(this,e)||this===l&&e&&e._writableState instanceof c}})):pe=function(e){return e instanceof this},l.prototype.pipe=function(){fe(this,new ce)},l.prototype.write=function(e,t,n){var r=this._writableState,i=!1,c=!r.objectMode&&o(e);return c&&!T.isBuffer(e)&&(e=a(e)),typeof t==`function`&&(n=t,t=null),c?t=`buffer`:!t&&(t=r.defaultEncoding),typeof n!=`function`&&(n=s),r.ending?u(this,n):(c||d(this,r,e,n))&&(r.pendingcb++,i=p(this,r,c,e,t,n)),i},l.prototype.cork=function(){this._writableState.corked++},l.prototype.uncork=function(){var e=this._writableState;e.corked&&(e.corked--,!e.writing&&!e.corked&&!e.bufferProcessing&&e.bufferedRequest&&b(this,e))},l.prototype.setDefaultEncoding=function(e){if(typeof e==`string`&&(e=e.toLowerCase()),!(-1<[`hex`,`utf8`,`utf-8`,`ascii`,`binary`,`base64`,`ucs2`,`ucs-2`,`utf16le`,`utf-16le`,`raw`].indexOf((e+``).toLowerCase())))throw new de(e);return this._writableState.defaultEncoding=e,this},Object.defineProperty(l.prototype,"writableBuffer",{enumerable:!1,get:function(){return this._writableState&&this._writableState.getBuffer()}}),Object.defineProperty(l.prototype,"writableHighWaterMark",{enumerable:!1,get:function(){return this._writableState.highWaterMark}}),l.prototype._write=function(e,t,n){n(new k(`_write()`))},l.prototype._writev=null,l.prototype.end=function(e,t,n){var r=this._writableState;return typeof e==`function`?(n=e,e=null,t=null):typeof t==`function`&&(n=t,t=null),e!=null&&this.write(e,t),r.corked&&(r.corked=1,this.uncork()),r.ending||ne(this,r,n),this},Object.defineProperty(l.prototype,"writableLength",{enumerable:!1,get:function(){return this._writableState.length}}),Object.defineProperty(l.prototype,"destroyed",{enumerable:!1,get:function(){return this._writableState!==void 0&&this._writableState.destroyed},set:function(e){this._writableState&&(this._writableState.destroyed=e)}}),l.prototype.destroy=E.destroy,l.prototype._undestroy=E.undestroy,l.prototype._destroy=function(e,t){t(e)}}).call(this)}).call(this,e(`_process`),typeof global>`u`?typeof self>`u`?typeof window>`u`?{}:window:self:global)},{"../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(e,t){(function(n){(function(){function r(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function i(e,t){return{value:e,done:t}}function a(e){var t=e[u];if(t!==null){var n=e[g].read();n!==null&&(e[m]=null,e[u]=null,e[d]=null,t(i(n,!1)))}}function o(e){n.nextTick(a,e)}function s(e,t){return function(n,r){e.then(function(){t[p]?n(i(void 0,!0)):t[h](n,r)},r)}}var c,l=e(`./end-of-stream`),u=Symbol(`lastResolve`),d=Symbol(`lastReject`),f=Symbol(`error`),p=Symbol(`ended`),m=Symbol(`lastPromise`),h=Symbol(`handlePromise`),g=Symbol(`stream`),_=Object.getPrototypeOf(function(){}),v=Object.setPrototypeOf((c={get stream(){return this[g]},next:function(){var e=this,t=this[f];if(t!==null)return Promise.reject(t);if(this[p])return Promise.resolve(i(void 0,!0));if(this[g].destroyed)return new Promise(function(t,r){n.nextTick(function(){e[f]?r(e[f]):t(i(void 0,!0))})});var r,a=this[m];if(a)r=new Promise(s(a,this));else{var o=this[g].read();if(o!==null)return Promise.resolve(i(o,!1));r=new Promise(this[h])}return this[m]=r,r}},r(c,Symbol.asyncIterator,function(){return this}),r(c,`return`,function(){var e=this;return new Promise(function(t,n){e[g].destroy(null,function(e){e?n(e):t(i(void 0,!0))})})}),c),_);t.exports=function(e){var t,n=Object.create(v,(t={},r(t,g,{value:e,writable:!0}),r(t,u,{value:null,writable:!0}),r(t,d,{value:null,writable:!0}),r(t,f,{value:null,writable:!0}),r(t,p,{value:e._readableState.endEmitted,writable:!0}),r(t,h,{value:function(e,t){var r=n[g].read();r?(n[m]=null,n[u]=null,n[d]=null,e(i(r,!1))):(n[u]=e,n[d]=t)},writable:!0}),t));return n[m]=null,l(e,function(e){if(e&&e.code!==`ERR_STREAM_PREMATURE_CLOSE`){var t=n[d];t!==null&&(n[m]=null,n[u]=null,n[d]=null,t(e)),n[f]=e;return}var r=n[u];r!==null&&(n[m]=null,n[u]=null,n[d]=null,r(i(void 0,!0))),n[p]=!0}),e.on(`readable`,o.bind(null,n)),n}}).call(this)}).call(this,e(`_process`))},{"./end-of-stream":24,_process:12}],22:[function(e,t){function n(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function r(e){for(var t,r=1;r<arguments.length;r++)t=arguments[r]==null?{}:arguments[r],r%2?n(Object(t),!0).forEach(function(n){i(e,n,t[n])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):n(Object(t)).forEach(function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(t,n))});return e}function i(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function a(e,t){if(!(e instanceof t))throw TypeError(`Cannot call a class as a function`)}function o(e,t){for(var n,r=0;r<t.length;r++)n=t[r],n.enumerable=n.enumerable||!1,n.configurable=!0,`value`in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}function s(e,t,n){return t&&o(e.prototype,t),n&&o(e,n),e}function c(e,t,n){l.prototype.copy.call(e,t,n)}var l=e(`buffer`).Buffer,u=e(`util`).inspect,d=u&&u.custom||`inspect`;t.exports=function(){function e(){a(this,e),this.head=null,this.tail=null,this.length=0}return s(e,[{key:`push`,value:function(e){var t={data:e,next:null};0<this.length?this.tail.next=t:this.head=t,this.tail=t,++this.length}},{key:`unshift`,value:function(e){var t={data:e,next:this.head};this.length===0&&(this.tail=t),this.head=t,++this.length}},{key:`shift`,value:function(){if(this.length!==0){var e=this.head.data;return this.head=this.length===1?this.tail=null:this.head.next,--this.length,e}}},{key:`clear`,value:function(){this.head=this.tail=null,this.length=0}},{key:`join`,value:function(e){if(this.length===0)return``;for(var t=this.head,n=``+t.data;t=t.next;)n+=e+t.data;return n}},{key:`concat`,value:function(e){if(this.length===0)return l.alloc(0);for(var t=l.allocUnsafe(e>>>0),n=this.head,r=0;n;)c(n.data,t,r),r+=n.data.length,n=n.next;return t}},{key:`consume`,value:function(e,t){var n;return e<this.head.data.length?(n=this.head.data.slice(0,e),this.head.data=this.head.data.slice(e)):n=e===this.head.data.length?this.shift():t?this._getString(e):this._getBuffer(e),n}},{key:`first`,value:function(){return this.head.data}},{key:`_getString`,value:function(e){var t=this.head,n=1,r=t.data;for(e-=r.length;t=t.next;){var i=t.data,a=e>i.length?i.length:e;if(r+=a===i.length?i:i.slice(0,e),e-=a,e===0){a===i.length?(++n,this.head=t.next?t.next:this.tail=null):(this.head=t,t.data=i.slice(a));break}++n}return this.length-=n,r}},{key:`_getBuffer`,value:function(e){var t=l.allocUnsafe(e),n=this.head,r=1;for(n.data.copy(t),e-=n.data.length;n=n.next;){var i=n.data,a=e>i.length?i.length:e;if(i.copy(t,t.length-e,0,a),e-=a,e===0){a===i.length?(++r,this.head=n.next?n.next:this.tail=null):(this.head=n,n.data=i.slice(a));break}++r}return this.length-=r,t}},{key:d,value:function(e,t){return u(this,r({},t,{depth:0,customInspect:!1}))}}]),e}()},{buffer:3,util:2}],23:[function(e,t){(function(e){(function(){function n(e,t){i(e,t),r(e)}function r(e){e._writableState&&!e._writableState.emitClose||e._readableState&&!e._readableState.emitClose||e.emit(`close`)}function i(e,t){e.emit(`error`,t)}t.exports={destroy:function(t,a){var o=this,s=this._readableState&&this._readableState.destroyed,c=this._writableState&&this._writableState.destroyed;return s||c?(a?a(t):t&&(this._writableState?!this._writableState.errorEmitted&&(this._writableState.errorEmitted=!0,e.nextTick(i,this,t)):e.nextTick(i,this,t)),this):(this._readableState&&(this._readableState.destroyed=!0),this._writableState&&(this._writableState.destroyed=!0),this._destroy(t||null,function(t){!a&&t?o._writableState?o._writableState.errorEmitted?e.nextTick(r,o):(o._writableState.errorEmitted=!0,e.nextTick(n,o,t)):e.nextTick(n,o,t):a?(e.nextTick(r,o),a(t)):e.nextTick(r,o)}),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(e,t){var n=e._readableState,r=e._writableState;n&&n.autoDestroy||r&&r.autoDestroy?e.destroy(t):e.emit(`error`,t)}}}).call(this)}).call(this,e(`_process`))},{_process:12}],24:[function(e,t){function n(e){var t=!1;return function(){if(!t){t=!0;var n=[...arguments];e.apply(this,n)}}}function r(){}function i(e){return e.setHeader&&typeof e.abort==`function`}function a(e,t,s){if(typeof t==`function`)return a(e,null,t);t||={},s=n(s||r);var c=t.readable||!1!==t.readable&&e.readable,l=t.writable||!1!==t.writable&&e.writable,u=function(){e.writable||f()},d=e._writableState&&e._writableState.finished,f=function(){l=!1,d=!0,c||s.call(e)},p=e._readableState&&e._readableState.endEmitted,m=function(){c=!1,p=!0,l||s.call(e)},h=function(t){s.call(e,t)},g=function(){var t;return c&&!p?(e._readableState&&e._readableState.ended||(t=new o),s.call(e,t)):l&&!d?(e._writableState&&e._writableState.ended||(t=new o),s.call(e,t)):void 0},_=function(){e.req.on(`finish`,f)};return i(e)?(e.on(`complete`,f),e.on(`abort`,g),e.req?_():e.on(`request`,_)):l&&!e._writableState&&(e.on(`end`,u),e.on(`close`,u)),e.on(`end`,m),e.on(`finish`,f),!1!==t.error&&e.on(`error`,h),e.on(`close`,g),function(){e.removeListener(`complete`,f),e.removeListener(`abort`,g),e.removeListener(`request`,_),e.req&&e.req.removeListener(`finish`,f),e.removeListener(`end`,u),e.removeListener(`close`,u),e.removeListener(`finish`,f),e.removeListener(`end`,m),e.removeListener(`error`,h),e.removeListener(`close`,g)}}var o=e(`../../../errors`).codes.ERR_STREAM_PREMATURE_CLOSE;t.exports=a},{"../../../errors":15}],25:[function(e,t){t.exports=function(){throw Error(`Readable.from is not available in the browser`)}},{}],26:[function(e,t){function n(e){var t=!1;return function(){t||(t=!0,e.apply(void 0,arguments))}}function r(e){if(e)throw e}function i(e){return e.setHeader&&typeof e.abort==`function`}function a(t,r,a,o){o=n(o);var s=!1;t.on(`close`,function(){s=!0}),l===void 0&&(l=e(`./end-of-stream`)),l(t,{readable:r,writable:a},function(e){return e?o(e):void(s=!0,o())});var c=!1;return function(e){if(!s)return c?void 0:(c=!0,i(t)?t.abort():typeof t.destroy==`function`?t.destroy():void o(e||new f(`pipe`)))}}function o(e){e()}function s(e,t){return e.pipe(t)}function c(e){return e.length&&typeof e[e.length-1]==`function`?e.pop():r}var l,u=e(`../../../errors`).codes,d=u.ERR_MISSING_ARGS,f=u.ERR_STREAM_DESTROYED;t.exports=function(){var e=[...arguments],t=c(e);if(Array.isArray(e[0])&&(e=e[0]),2>e.length)throw new d(`streams`);var n,r=e.map(function(i,s){var c=s<e.length-1;return a(i,c,0<s,function(e){n||=e,e&&r.forEach(o),c||(r.forEach(o),t(n))})});return e.reduce(s)}},{"../../../errors":15,"./end-of-stream":24}],27:[function(t,n){function r(e,t,n){return e.highWaterMark==null?t?e[n]:null:e.highWaterMark}var i=t(`../../../errors`).codes.ERR_INVALID_OPT_VALUE;n.exports={getHighWaterMark:function(t,n,a,o){var s=r(n,o,a);if(s!=null){if(!(isFinite(s)&&e(s)===s)||0>s)throw new i(o?a:`highWaterMark`,s);return e(s)}return t.objectMode?16:16384}}},{"../../../errors":15}],28:[function(e,t){t.exports=e(`events`).EventEmitter},{events:7}],29:[function(e,t,n){n=t.exports=e(`./lib/_stream_readable.js`),n.Stream=n,n.Readable=n,n.Writable=e(`./lib/_stream_writable.js`),n.Duplex=e(`./lib/_stream_duplex.js`),n.Transform=e(`./lib/_stream_transform.js`),n.PassThrough=e(`./lib/_stream_passthrough.js`),n.finished=e(`./lib/internal/streams/end-of-stream.js`),n.pipeline=e(`./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(e,t,n){function r(e,t){for(var n in e)t[n]=e[n]}function i(e,t,n){return o(e,t,n)}var a=e(`buffer`),o=a.Buffer;o.from&&o.alloc&&o.allocUnsafe&&o.allocUnsafeSlow?t.exports=a:(r(a,n),n.Buffer=i),i.prototype=Object.create(o.prototype),r(o,i),i.from=function(e,t,n){if(typeof e==`number`)throw TypeError(`Argument must not be a number`);return o(e,t,n)},i.alloc=function(e,t,n){if(typeof e!=`number`)throw TypeError(`Argument must be a number`);var r=o(e);return t===void 0?r.fill(0):typeof n==`string`?r.fill(t,n):r.fill(t),r},i.allocUnsafe=function(e){if(typeof e!=`number`)throw TypeError(`Argument must be a number`);return o(e)},i.allocUnsafeSlow=function(e){if(typeof e!=`number`)throw TypeError(`Argument must be a number`);return a.SlowBuffer(e)}},{buffer:3}],31:[function(e,t,n){function r(e){if(!e)return`utf8`;for(var t;;)switch(e){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 e;default:if(t)return;e=(``+e).toLowerCase(),t=!0}}function i(e){var t=r(e);if(typeof t!=`string`&&(g.isEncoding===_||!_(e)))throw Error(`Unknown encoding: `+e);return t||e}function a(e){this.encoding=i(e);var t;switch(this.encoding){case`utf16le`:this.text=u,this.end=d,t=4;break;case`utf8`:this.fillLast=l,t=4;break;case`base64`:this.text=f,this.end=p,t=3;break;default:this.write=m,this.end=h;return}this.lastNeed=0,this.lastTotal=0,this.lastChar=g.allocUnsafe(t)}function o(e){return 127>=e?0:e>>5==6?2:e>>4==14?3:e>>3==30?4:e>>6==2?-1:-2}function s(e,t,n){var r=t.length-1;if(r<n)return 0;var i=o(t[r]);return 0<=i?(0<i&&(e.lastNeed=i-1),i):--r<n||i===-2?0:(i=o(t[r]),0<=i?(0<i&&(e.lastNeed=i-2),i):--r<n||i===-2?0:(i=o(t[r]),0<=i?(0<i&&(i===2?i=0:e.lastNeed=i-3),i):0))}function c(e,t){if((192&t[0])!=128)return e.lastNeed=0,`�`;if(1<e.lastNeed&&1<t.length){if((192&t[1])!=128)return e.lastNeed=1,`�`;if(2<e.lastNeed&&2<t.length&&(192&t[2])!=128)return e.lastNeed=2,`�`}}function l(e){var t=this.lastTotal-this.lastNeed,n=c(this,e,t);return n===void 0?this.lastNeed<=e.length?(e.copy(this.lastChar,t,0,this.lastNeed),this.lastChar.toString(this.encoding,0,this.lastTotal)):void(e.copy(this.lastChar,t,0,e.length),this.lastNeed-=e.length):n}function u(e,t){if((e.length-t)%2==0){var n=e.toString(`utf16le`,t);if(n){var r=n.charCodeAt(n.length-1);if(55296<=r&&56319>=r)return this.lastNeed=2,this.lastTotal=4,this.lastChar[0]=e[e.length-2],this.lastChar[1]=e[e.length-1],n.slice(0,-1)}return n}return this.lastNeed=1,this.lastTotal=2,this.lastChar[0]=e[e.length-1],e.toString(`utf16le`,t,e.length-1)}function d(e){var t=e&&e.length?this.write(e):``;if(this.lastNeed){var n=this.lastTotal-this.lastNeed;return t+this.lastChar.toString(`utf16le`,0,n)}return t}function f(e,t){var n=(e.length-t)%3;return n==0?e.toString(`base64`,t):(this.lastNeed=3-n,this.lastTotal=3,n==1?this.lastChar[0]=e[e.length-1]:(this.lastChar[0]=e[e.length-2],this.lastChar[1]=e[e.length-1]),e.toString(`base64`,t,e.length-n))}function p(e){var t=e&&e.length?this.write(e):``;return this.lastNeed?t+this.lastChar.toString(`base64`,0,3-this.lastNeed):t}function m(e){return e.toString(this.encoding)}function h(e){return e&&e.length?this.write(e):``}var g=e(`safe-buffer`).Buffer,_=g.isEncoding||function(e){switch(e=``+e,e&&e.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}};n.StringDecoder=a,a.prototype.write=function(e){if(e.length===0)return``;var t,n;if(this.lastNeed){if(t=this.fillLast(e),t===void 0)return``;n=this.lastNeed,this.lastNeed=0}else n=0;return n<e.length?t?t+this.text(e,n):this.text(e,n):t||``},a.prototype.end=function(e){var t=e&&e.length?this.write(e):``;return this.lastNeed?t+`�`:t},a.prototype.text=function(e,t){var n=s(this,e,t);if(!this.lastNeed)return e.toString(`utf8`,t);this.lastTotal=n;var r=e.length-(n-this.lastNeed);return e.copy(this.lastChar,0,r),e.toString(`utf8`,t,r)},a.prototype.fillLast=function(e){return this.lastNeed<=e.length?(e.copy(this.lastChar,this.lastTotal-this.lastNeed,0,this.lastNeed),this.lastChar.toString(this.encoding,0,this.lastTotal)):void(e.copy(this.lastChar,this.lastTotal-this.lastNeed,0,e.length),this.lastNeed-=e.length)}},{"safe-buffer":30}],32:[function(e,t){(function(e){(function(){function n(t){try{if(!e.localStorage)return!1}catch{return!1}var n=e.localStorage[t];return n!=null&&(n+``).toLowerCase()===`true`}t.exports=function(e,t){function r(){if(!i){if(n(`throwDeprecation`))throw Error(t);n(`traceDeprecation`)?console.trace(t):console.warn(t),i=!0}return e.apply(this,arguments)}if(n(`noDeprecation`))return e;var i=!1;return r}}).call(this)}).call(this,typeof global>`u`?typeof self>`u`?typeof window>`u`?{}:window:self:global)},{}],"/":[function(e,t){function n(e){return e.replace(/a=ice-options:trickle\s\n/g,``)}function r(e){console.warn(e)}let i=e(`debug`)(`simple-peer`),a=e(`get-browser-rtc`),o=e(`randombytes`),s=e(`readable-stream`),c=e(`queue-microtask`),l=e(`err-code`),{Buffer:u}=e(`buffer`),d=65536;class f extends s.Duplex{constructor(e){if(e=Object.assign({allowHalfOpen:!1},e),super(e),this._id=o(4).toString(`hex`).slice(0,7),this._debug(`new peer %o`,e),this.channelName=e.initiator?e.channelName||o(20).toString(`hex`):null,this.initiator=e.initiator||!1,this.channelConfig=e.channelConfig||f.channelConfig,this.channelNegotiated=this.channelConfig.negotiated,this.config=Object.assign({},f.config,e.config),this.offerOptions=e.offerOptions||{},this.answerOptions=e.answerOptions||{},this.sdpTransform=e.sdpTransform||(e=>e),this.streams=e.streams||(e.stream?[e.stream]:[]),this.trickle=e.trickle===void 0||e.trickle,this.allowHalfTrickle=e.allowHalfTrickle!==void 0&&e.allowHalfTrickle,this.iceCompleteTimeout=e.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=e.wrtc&&typeof e.wrtc==`object`?e.wrtc:a(),!this._wrtc)throw l(Error(typeof window>`u`?"No WebRTC support: Specify `opts.wrtc` option in this environment":`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(e){this.destroy(l(e,`ERR_PC_CONSTRUCTOR`));return}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=e=>{this._onIceCandidate(e)},typeof this._pc.peerIdentity==`object`&&this._pc.peerIdentity.catch(e=>{this.destroy(l(e,`ERR_PC_PEER_IDENTITY`))}),this.initiator||this.channelNegotiated?this._setupData({channel:this._pc.createDataChannel(this.channelName,this.channelConfig)}):this._pc.ondatachannel=e=>{this._setupData(e)},this.streams&&this.streams.forEach(e=>{this.addStream(e)}),this._pc.ontrack=e=>{this._onTrack(e)},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(e){if(!this.destroying){if(this.destroyed)throw l(Error(`cannot signal after peer is destroyed`),`ERR_DESTROYED`);if(typeof e==`string`)try{e=JSON.parse(e)}catch{e={}}this._debug(`signal()`),e.renegotiate&&this.initiator&&(this._debug(`got request to renegotiate`),this._needsNegotiation()),e.transceiverRequest&&this.initiator&&(this._debug(`got request for transceiver`),this.addTransceiver(e.transceiverRequest.kind,e.transceiverRequest.init)),e.candidate&&(this._pc.remoteDescription&&this._pc.remoteDescription.type?this._addIceCandidate(e.candidate):this._pendingCandidates.push(e.candidate)),e.sdp&&this._pc.setRemoteDescription(new this._wrtc.RTCSessionDescription(e)).then(()=>{this.destroyed||(this._pendingCandidates.forEach(e=>{this._addIceCandidate(e)}),this._pendingCandidates=[],this._pc.remoteDescription.type===`offer`&&this._createAnswer())}).catch(e=>{this.destroy(l(e,`ERR_SET_REMOTE_DESCRIPTION`))}),e.sdp||e.candidate||e.renegotiate||e.transceiverRequest||this.destroy(l(Error(`signal() called with invalid signal data`),`ERR_SIGNALING`))}}_addIceCandidate(e){let t=new this._wrtc.RTCIceCandidate(e);this._pc.addIceCandidate(t).catch(e=>{!t.address||t.address.endsWith(`.local`)?r(`Ignoring unsupported ICE candidate.`):this.destroy(l(e,`ERR_ADD_ICE_CANDIDATE`))})}send(e){if(!this.destroying){if(this.destroyed)throw l(Error(`cannot send after peer is destroyed`),`ERR_DESTROYED`);this._channel.send(e)}}addTransceiver(e,t){if(!this.destroying){if(this.destroyed)throw l(Error(`cannot addTransceiver after peer is destroyed`),`ERR_DESTROYED`);if(this._debug(`addTransceiver()`),this.initiator)try{this._pc.addTransceiver(e,t),this._needsNegotiation()}catch(e){this.destroy(l(e,`ERR_ADD_TRANSCEIVER`))}else this.emit(`signal`,{type:`transceiverRequest`,transceiverRequest:{kind:e,init:t}})}}addStream(e){if(!this.destroying){if(this.destroyed)throw l(Error(`cannot addStream after peer is destroyed`),`ERR_DESTROYED`);this._debug(`addStream()`),e.getTracks().forEach(t=>{this.addTrack(t,e)})}}addTrack(e,t){if(this.destroying)return;if(this.destroyed)throw l(Error(`cannot addTrack after peer is destroyed`),`ERR_DESTROYED`);this._debug(`addTrack()`);let n=this._senderMap.get(e)||new Map,r=n.get(t);if(!r)r=this._pc.addTrack(e,t),n.set(t,r),this._senderMap.set(e,n),this._needsNegotiation();else if(r.removed)throw l(Error(`Track has been removed. You should enable/disable tracks that you want to re-add.`),`ERR_SENDER_REMOVED`);else throw l(Error(`Track has already been added to that stream.`),`ERR_SENDER_ALREADY_ADDED`)}replaceTrack(e,t,n){if(this.destroying)return;if(this.destroyed)throw l(Error(`cannot replaceTrack after peer is destroyed`),`ERR_DESTROYED`);this._debug(`replaceTrack()`);let r=this._senderMap.get(e),i=r?r.get(n):null;if(!i)throw l(Error(`Cannot replace track that was never added.`),`ERR_TRACK_NOT_ADDED`);t&&this._senderMap.set(t,r),i.replaceTrack==null?this.destroy(l(Error(`replaceTrack is not supported in this browser`),`ERR_UNSUPPORTED_REPLACETRACK`)):i.replaceTrack(t)}removeTrack(e,t){if(this.destroying)return;if(this.destroyed)throw l(Error(`cannot removeTrack after peer is destroyed`),`ERR_DESTROYED`);this._debug(`removeSender()`);let n=this._senderMap.get(e),r=n?n.get(t):null;if(!r)throw l(Error(`Cannot remove track that was never added.`),`ERR_TRACK_NOT_ADDED`);try{r.removed=!0,this._pc.removeTrack(r)}catch(e){e.name===`NS_ERROR_UNEXPECTED`?this._sendersAwaitingStable.push(r):this.destroy(l(e,`ERR_REMOVE_TRACK`))}this._needsNegotiation()}removeStream(e){if(!this.destroying){if(this.destroyed)throw l(Error(`cannot removeStream after peer is destroyed`),`ERR_DESTROYED`);this._debug(`removeSenders()`),e.getTracks().forEach(t=>{this.removeTrack(t,e)})}}_needsNegotiation(){this._debug(`_needsNegotiation`),this._batchedNegotiation||(this._batchedNegotiation=!0,c(()=>{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 l(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(e){this._destroy(e,()=>{})}_destroy(e,t){this.destroyed||this.destroying||(this.destroying=!0,this._debug(`destroying (error: %s)`,e&&(e.message||e)),c(()=>{if(this.destroyed=!0,this.destroying=!1,this._debug(`destroy (error: %s)`,e&&(e.message||e)),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,e&&this.emit(`error`,e),this.emit(`close`),t()}))}_setupData(e){if(!e.channel)return this.destroy(l(Error("Data channel event is missing `channel` property"),`ERR_DATA_CHANNEL`));this._channel=e.channel,this._channel.binaryType=`arraybuffer`,typeof this._channel.bufferedAmountLowThreshold==`number`&&(this._channel.bufferedAmountLowThreshold=d),this.channelName=this._channel.label,this._channel.onmessage=e=>{this._onChannelMessage(e)},this._channel.onbufferedamountlow=()=>{this._onChannelBufferedAmountLow()},this._channel.onopen=()=>{this._onChannelOpen()},this._channel.onclose=()=>{this._onChannelClose()},this._channel.onerror=e=>{let t=e.error instanceof Error?e.error:Error(`Datachannel error: ${e.message} ${e.filename}:${e.lineno}:${e.colno}`);this.destroy(l(t,`ERR_DATA_CHANNEL`))};let t=!1;this._closingInterval=setInterval(()=>{this._channel&&this._channel.readyState===`closing`?(t&&this._onChannelClose(),t=!0):t=!1},5e3)}_read(){}_write(e,t,n){if(this.destroyed)return n(l(Error(`cannot write after peer is destroyed`),`ERR_DATA_CHANNEL`));if(this._connected){try{this.send(e)}catch(e){return this.destroy(l(e,`ERR_DATA_CHANNEL`))}this._channel.bufferedAmount>d?(this._debug(`start backpressure: bufferedAmount %d`,this._channel.bufferedAmount),this._cb=n):n(null)}else this._debug(`write before connect`),this._chunk=e,this._cb=n}_onFinish(){if(!this.destroyed){let e=()=>{setTimeout(()=>this.destroy(),1e3)};this._connected?e():this.once(`connect`,e)}}_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(e=>{if(this.destroyed)return;this.trickle||this.allowHalfTrickle||(e.sdp=n(e.sdp)),e.sdp=this.sdpTransform(e.sdp);let t=()=>{if(!this.destroyed){let t=this._pc.localDescription||e;this._debug(`signal`),this.emit(`signal`,{type:t.type,sdp:t.sdp})}};this._pc.setLocalDescription(e).then(()=>{this._debug(`createOffer success`),this.destroyed||(this.trickle||this._iceComplete?t():this.once(`_iceComplete`,t))}).catch(e=>{this.destroy(l(e,`ERR_SET_LOCAL_DESCRIPTION`))})}).catch(e=>{this.destroy(l(e,`ERR_CREATE_OFFER`))})}_requestMissingTransceivers(){this._pc.getTransceivers&&this._pc.getTransceivers().forEach(e=>{e.mid||!e.sender.track||e.requested||(e.requested=!0,this.addTransceiver(e.sender.track.kind))})}_createAnswer(){this.destroyed||this._pc.createAnswer(this.answerOptions).then(e=>{if(this.destroyed)return;this.trickle||this.allowHalfTrickle||(e.sdp=n(e.sdp)),e.sdp=this.sdpTransform(e.sdp);let t=()=>{if(!this.destroyed){let t=this._pc.localDescription||e;this._debug(`signal`),this.emit(`signal`,{type:t.type,sdp:t.sdp}),this.initiator||this._requestMissingTransceivers()}};this._pc.setLocalDescription(e).then(()=>{this.destroyed||(this.trickle||this._iceComplete?t():this.once(`_iceComplete`,t))}).catch(e=>{this.destroy(l(e,`ERR_SET_LOCAL_DESCRIPTION`))})}).catch(e=>{this.destroy(l(e,`ERR_CREATE_ANSWER`))})}_onConnectionStateChange(){this.destroyed||this._pc.connectionState===`failed`&&this.destroy(l(Error(`Connection failed.`),`ERR_CONNECTION_FAILURE`))}_onIceStateChange(){if(this.destroyed)return;let e=this._pc.iceConnectionState,t=this._pc.iceGatheringState;this._debug(`iceStateChange (connection: %s) (gathering: %s)`,e,t),this.emit(`iceStateChange`,e,t),(e===`connected`||e===`completed`)&&(this._pcReady=!0,this._maybeReady()),e===`failed`&&this.destroy(l(Error(`Ice connection failed.`),`ERR_ICE_CONNECTION_FAILURE`)),e===`closed`&&this.destroy(l(Error(`Ice connection closed.`),`ERR_ICE_CONNECTION_CLOSED`))}getStats(e){let t=e=>(Object.prototype.toString.call(e.values)===`[object Array]`&&e.values.forEach(t=>{Object.assign(e,t)}),e);this._pc.getStats.length===0||this._isReactNativeWebrtc?this._pc.getStats().then(n=>{let r=[];n.forEach(e=>{r.push(t(e))}),e(null,r)},t=>e(t)):0<this._pc.getStats.length?this._pc.getStats(n=>{if(this.destroyed)return;let r=[];n.result().forEach(e=>{let n={};e.names().forEach(t=>{n[t]=e.stat(t)}),n.id=e.id,n.type=e.type,n.timestamp=e.timestamp,r.push(t(n))}),e(null,r)},t=>e(t)):e(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;let e=()=>{this.destroyed||this.getStats((t,n)=>{if(this.destroyed)return;t&&(n=[]);let r={},i={},a={},o=!1;n.forEach(e=>{(e.type===`remotecandidate`||e.type===`remote-candidate`)&&(r[e.id]=e),(e.type===`localcandidate`||e.type===`local-candidate`)&&(i[e.id]=e),(e.type===`candidatepair`||e.type===`candidate-pair`)&&(a[e.id]=e)});let s=e=>{o=!0;let t=i[e.localCandidateId];t&&(t.ip||t.address)?(this.localAddress=t.ip||t.address,this.localPort=+t.port):t&&t.ipAddress?(this.localAddress=t.ipAddress,this.localPort=+t.portNumber):typeof e.googLocalAddress==`string`&&(t=e.googLocalAddress.split(`:`),this.localAddress=t[0],this.localPort=+t[1]),this.localAddress&&(this.localFamily=this.localAddress.includes(`:`)?`IPv6`:`IPv4`);let n=r[e.remoteCandidateId];n&&(n.ip||n.address)?(this.remoteAddress=n.ip||n.address,this.remotePort=+n.port):n&&n.ipAddress?(this.remoteAddress=n.ipAddress,this.remotePort=+n.portNumber):typeof e.googRemoteAddress==`string`&&(n=e.googRemoteAddress.split(`:`),this.remoteAddress=n[0],this.remotePort=+n[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(n.forEach(e=>{e.type===`transport`&&e.selectedCandidatePairId&&s(a[e.selectedCandidatePairId]),(e.type===`googCandidatePair`&&e.googActiveConnection===`true`||(e.type===`candidatepair`||e.type===`candidate-pair`)&&e.selected)&&s(e)}),!o&&(!Object.keys(a).length||Object.keys(i).length))return void setTimeout(e,100);if(this._connecting=!1,this._connected=!0,this._chunk){try{this.send(this._chunk)}catch(e){return this.destroy(l(e,`ERR_DATA_CHANNEL`))}this._chunk=null,this._debug(`sent chunk from "write before connect"`);let e=this._cb;this._cb=null,e(null)}typeof this._channel.bufferedAmountLowThreshold!=`number`&&(this._interval=setInterval(()=>this._onInterval(),150),this._interval.unref&&this._interval.unref()),this._debug(`connect`),this.emit(`connect`)})};e()}_onInterval(){this._cb&&this._channel&&!(this._channel.bufferedAmount>d)&&this._onChannelBufferedAmountLow()}_onSignalingStateChange(){this.destroyed||(this._pc.signalingState===`stable`&&(this._isNegotiating=!1,this._debug(`flushing sender queue`,this._sendersAwaitingStable),this._sendersAwaitingStable.forEach(e=>{this._pc.removeTrack(e),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(e){this.destroyed||(e.candidate&&this.trickle?this.emit(`signal`,{type:`candidate`,candidate:{candidate:e.candidate.candidate,sdpMLineIndex:e.candidate.sdpMLineIndex,sdpMid:e.candidate.sdpMid}}):!e.candidate&&!this._iceComplete&&(this._iceComplete=!0,this.emit(`_iceComplete`)),e.candidate&&this._startIceCompleteTimeout())}_onChannelMessage(e){if(this.destroyed)return;let t=e.data;t instanceof ArrayBuffer&&(t=u.from(t)),this.push(t)}_onChannelBufferedAmountLow(){if(!this.destroyed&&this._cb){this._debug(`ending backpressure: bufferedAmount %d`,this._channel.bufferedAmount);let e=this._cb;this._cb=null,e(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(e){this.destroyed||e.streams.forEach(t=>{this._debug(`on track`),this.emit(`track`,e.track,t),this._remoteTracks.push({track:e.track,stream:t}),this._remoteStreams.some(e=>e.id===t.id)||(this._remoteStreams.push(t),c(()=>{this._debug(`on stream`),this.emit(`stream`,t)}))})}_debug(){let e=[].slice.call(arguments);e[0]=`[`+this._id+`] `+e[0],i.apply(null,e)}}f.WEBRTC_SUPPORT=!!a(),f.config={iceServers:[{urls:[`stun:stun.l.google.com:19302`,`stun:global.stun.twilio.com:3478`]}],sdpSemantics:`unified-plan`},f.channelConfig={},t.exports=f},{buffer:3,debug:4,"err-code":6,"get-browser-rtc":8,"queue-microtask":13,randombytes:14,"readable-stream":29}]},{},[])(`/`)})}))(),1),_l=(e,t)=>{L(e,0),R(e,Qa(t))},vl=(e,t,n)=>{L(e,1),R(e,Ka(t,n))},yl=(e,t,n)=>vl(t,n,z(e)),bl=(e,t,n,r)=>{try{Ua(t,z(e),n)}catch(e){r?.(e),console.error(`Caught error while handling a Yjs update`,e)}},xl=(e,t)=>{L(e,2),R(e,t)},Sl=bl,Cl=(e,t,n,r,i)=>{let a=B(e);switch(a){case 0:yl(e,t,n);break;case 1:bl(e,n,r,i);break;case 2:Sl(e,n,r,i);break;default:throw Error(`Unknown message type`)}return a},wl=3e4,Tl=class extends gt{constructor(e){super(),this.doc=e,this.clientID=e.clientID,this.states=new Map,this.meta=new Map,this._checkInterval=setInterval(()=>{let e=An();this.getLocalState()!==null&&3e4/2<=e-this.meta.get(this.clientID).lastUpdated&&this.setLocalState(this.getLocalState());let t=[];this.meta.forEach((n,r)=>{r!==this.clientID&&3e4<=e-n.lastUpdated&&this.states.has(r)&&t.push(r)}),t.length>0&&El(this,t,`timeout`)},_t(wl/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){let t=this.clientID,n=this.meta.get(t),r=n===void 0?0:n.clock+1,i=this.states.get(t);e===null?this.states.delete(t):this.states.set(t,e),this.meta.set(t,{clock:r,lastUpdated:An()});let a=[],o=[],s=[],c=[];e===null?c.push(t):i==null?e!=null&&a.push(t):(o.push(t),nr(i,e)||s.push(t)),(a.length>0||s.length>0||c.length>0)&&this.emit(`change`,[{added:a,updated:s,removed:c},`local`]),this.emit(`update`,[{added:a,updated:o,removed:c},`local`])}setLocalStateField(e,t){let n=this.getLocalState();n!==null&&this.setLocalState({...n,[e]:t})}getStates(){return this.states}},El=(e,t,n)=>{let r=[];for(let n=0;n<t.length;n++){let i=t[n];if(e.states.has(i)){if(e.states.delete(i),i===e.clientID){let t=e.meta.get(i);e.meta.set(i,{clock:t.clock+1,lastUpdated:An()})}r.push(i)}}r.length>0&&(e.emit(`change`,[{added:[],updated:[],removed:r},n]),e.emit(`update`,[{added:[],updated:[],removed:r},n]))},Dl=(e,t,n=e.states)=>{let r=t.length,i=P();L(i,r);for(let a=0;a<r;a++){let r=t[a],o=n.get(r)||null,s=e.meta.get(r).clock;L(i,r),L(i,s),Wt(i,JSON.stringify(o))}return F(i)},Ol=(e,t,n)=>{let r=fn(t),i=An(),a=[],o=[],s=[],c=[],l=B(r);for(let t=0;t<l;t++){let t=B(r),n=B(r),l=JSON.parse(_n(r)),u=e.meta.get(t),d=e.states.get(t),f=u===void 0?0:u.clock;(f<n||f===n&&l===null&&e.states.has(t))&&(l===null?t===e.clientID&&e.getLocalState()!=null?n++:e.states.delete(t):e.states.set(t,l),e.meta.set(t,{clock:n,lastUpdated:i}),u===void 0&&l!==null?a.push(t):u!==void 0&&l===null?c.push(t):l!==null&&(nr(l,d)||s.push(t),o.push(t)))}(a.length>0||s.length>0||c.length>0)&&e.emit(`change`,[{added:a,updated:s,removed:c},n]),(a.length>0||o.length>0||c.length>0)&&e.emit(`update`,[{added:a,updated:o,removed:c},n])},kl=(e,t)=>{let n=Pt(e).buffer,r=Pt(t).buffer;return crypto.subtle.importKey(`raw`,n,`PBKDF2`,!1,[`deriveKey`]).then(e=>crypto.subtle.deriveKey({name:`PBKDF2`,salt:r,iterations:1e5,hash:`SHA-256`},e,{name:`AES-GCM`,length:256},!0,[`encrypt`,`decrypt`]))},Al=(e,t)=>{if(!t)return Nn(e);let n=crypto.getRandomValues(new Uint8Array(12));return crypto.subtle.encrypt({name:`AES-GCM`,iv:n},t,e).then(e=>{let t=P();return Wt(t,`AES-GCM`),R(t,n),R(t,new Uint8Array(e)),F(t)})},jl=(e,t)=>{let n=P();return Qt(n,e),Al(F(n),t)},Ml=(e,t)=>{if(!t)return Nn(e);let n=fn(e);_n(n)!==`AES-GCM`&&Mn(on(`Unknown encryption algorithm`));let r=z(n),i=z(n);return crypto.subtle.decrypt({name:`AES-GCM`,iv:r},t,i).then(e=>new Uint8Array(e))},Nl=(e,t)=>Ml(e,t).then(e=>bn(fn(new Uint8Array(e)))),Pl=la(`y-webrtc`),Fl=0,Il=3,Ll=1,Rl=4,zl=new Map,Bl=new Map,Vl=e=>{let t=!0;e.webrtcConns.forEach(e=>{e.synced||(t=!1)}),(!t&&e.synced||t&&!e.synced)&&(e.synced=t,e.provider.emit(`synced`,[{synced:t}]),Pl(`synced `,Wi,e.name,Gi,` with all peers`))},Hl=(e,t,n)=>{let r=fn(t),i=P(),a=B(r);if(e===void 0)return null;let o=e.awareness,s=e.doc,c=!1;switch(a){case Fl:{L(i,Fl);let t=Cl(r,i,s,e);t===1&&!e.synced&&n(),t===0&&(c=!0);break}case Il:L(i,Ll),R(i,Dl(o,Array.from(o.getStates().keys()))),c=!0;break;case Ll:Ol(o,z(r),e);break;case Rl:{let t=hn(r)===1,n=_n(r);if(n!==e.peerId&&(e.bcConns.has(n)&&!t||!e.bcConns.has(n)&&t)){let r=[],i=[];t?(e.bcConns.add(n),i.push(n)):(e.bcConns.delete(n),r.push(n)),e.provider.emit(`peers`,[{added:i,removed:r,webrtcPeers:Array.from(e.webrtcConns.keys()),bcPeers:Array.from(e.bcConns)}]),Xl(e)}break}default:return console.error(`Unable to compute message`),i}return c?i:null},Ul=(e,t)=>{let n=e.room;return Pl(`received message from `,Wi,e.remotePeerId,qi,` (`,n.name,`)`,Gi,Qi),Hl(n,t,()=>{e.synced=!0,Pl(`synced `,Wi,n.name,Gi,` with `,Wi,e.remotePeerId),Vl(n)})},Wl=(e,t)=>{Pl(`send message to `,Wi,e.remotePeerId,Gi,qi,` (`,e.room.name,`)`,Qi);try{e.peer.send(F(t))}catch{}},Gl=(e,t)=>{Pl(`broadcast message in `,Wi,e.name,Gi),e.webrtcConns.forEach(e=>{try{e.peer.send(t)}catch{}})},Kl=class{constructor(e,t,n,r){Pl(`establishing connection to `,Wi,n),this.room=r,this.remotePeerId=n,this.glareToken=void 0,this.closed=!1,this.connected=!1,this.synced=!1,this.peer=new gl.default({initiator:t,...r.provider.peerOpts}),this.peer.on(`signal`,t=>{this.glareToken===void 0&&(this.glareToken=Date.now()+Math.random()),$l(e,r,{to:n,from:r.peerId,type:`signal`,token:this.glareToken,signal:t})}),this.peer.on(`connect`,()=>{Pl(`connected to `,Wi,n),this.connected=!0;let e=r.provider.doc,t=r.awareness,i=P();L(i,Fl),_l(i,e),Wl(this,i);let a=t.getStates();if(a.size>0){let e=P();L(e,Ll),R(e,Dl(t,Array.from(a.keys()))),Wl(this,e)}}),this.peer.on(`close`,()=>{this.connected=!1,this.closed=!0,r.webrtcConns.has(this.remotePeerId)&&(r.webrtcConns.delete(this.remotePeerId),r.provider.emit(`peers`,[{removed:[this.remotePeerId],added:[],webrtcPeers:Array.from(r.webrtcConns.keys()),bcPeers:Array.from(r.bcConns)}])),Vl(r),this.peer.destroy(),Pl(`closed connection to `,Wi,n),Yl(r)}),this.peer.on(`error`,e=>{Pl(`Error in connection to `,Wi,n,`: `,e),Yl(r)}),this.peer.on(`data`,e=>{let t=Ul(this,e);t!==null&&Wl(this,t)})}destroy(){this.peer.destroy()}},ql=(e,t)=>Al(t,e.key).then(t=>e.mux(()=>ml(e.name,t))),Jl=(e,t)=>{e.bcconnected&&ql(e,t),Gl(e,t)},Yl=e=>{zl.forEach(t=>{t.connected&&(t.send({type:`subscribe`,topics:[e.name]}),e.webrtcConns.size<e.provider.maxConns&&$l(t,e,{type:`announce`,from:e.peerId}))})},Xl=e=>{if(e.provider.filterBcConns){let t=P();L(t,Rl),Bt(t,1),Wt(t,e.peerId),ql(e,F(t))}},Zl=class{constructor(e,t,n,r){this.peerId=kn(),this.doc=e,this.awareness=t.awareness,this.provider=t,this.synced=!1,this.name=n,this.key=r,this.webrtcConns=new Map,this.bcConns=new Set,this.mux=hl(),this.bcconnected=!1,this._bcSubscriber=e=>Ml(new Uint8Array(e),r).then(e=>this.mux(()=>{let t=Hl(this,e,()=>{});t&&ql(this,F(t))})),this._docUpdateHandler=(e,t)=>{let n=P();L(n,Fl),xl(n,e),Jl(this,F(n))},this._awarenessUpdateHandler=({added:e,updated:t,removed:n},r)=>{let i=e.concat(t).concat(n),a=P();L(a,Ll),R(a,Dl(this.awareness,i)),Jl(this,F(a))},this._beforeUnloadHandler=()=>{El(this.awareness,[e.clientID],`window unload`),Bl.forEach(e=>{e.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),Yl(this);let e=this.name;fl(e,this._bcSubscriber),this.bcconnected=!0,Xl(this);let t=P();L(t,Fl),_l(t,this.doc),ql(this,F(t));let n=P();L(n,Fl),vl(n,this.doc),ql(this,F(n));let r=P();L(r,Il),ql(this,F(r));let i=P();L(i,Ll),R(i,Dl(this.awareness,[this.doc.clientID])),ql(this,F(i))}disconnect(){zl.forEach(e=>{e.connected&&e.send({type:`unsubscribe`,topics:[this.name]})}),El(this.awareness,[this.doc.clientID],`disconnect`);let e=P();L(e,Rl),Bt(e,0),Wt(e,this.peerId),ql(this,F(e)),pl(this.name,this._bcSubscriber),this.bcconnected=!1,this.doc.off(`update`,this._docUpdateHandler),this.awareness.off(`update`,this._awarenessUpdateHandler),this.webrtcConns.forEach(e=>e.destroy())}destroy(){this.disconnect(),typeof window<`u`?window.removeEventListener(`beforeunload`,this._beforeUnloadHandler):typeof process<`u`&&process.off(`exit`,this._beforeUnloadHandler)}},Ql=(e,t,n,r)=>{if(Bl.has(n))throw on(`A Yjs Doc connected to room "${n}" already exists!`);let i=new Zl(e,t,n,r);return Bl.set(n,i),i},$l=(e,t,n)=>{t.key?jl(n,t.key).then(n=>{e.send({type:`publish`,topic:t.name,data:xr(n)})}):e.send({type:`publish`,topic:t.name,data:n})},eu=class extends sl{constructor(e){super(e),this.providers=new Set,this.on(`connect`,()=>{Pl(`connected (${e})`);let t=Array.from(Bl.keys());this.send({type:`subscribe`,topics:t}),Bl.forEach(e=>$l(this,e,{type:`announce`,from:e.peerId}))}),this.on(`message`,e=>{switch(e.type){case`publish`:{let t=e.topic,n=Bl.get(t);if(n==null||typeof t!=`string`)return;let r=e=>{let t=n.webrtcConns,r=n.peerId;if(e==null||e.from===r||e.to!==void 0&&e.to!==r||n.bcConns.has(e.from))return;let i=t.has(e.from)?()=>{}:()=>n.provider.emit(`peers`,[{removed:[],added:[e.from],webrtcPeers:Array.from(n.webrtcConns.keys()),bcPeers:Array.from(n.bcConns)}]);switch(e.type){case`announce`:t.size<n.provider.maxConns&&(it(t,e.from,()=>new Kl(this,!0,e.from,n)),i());break;case`signal`:if(e.signal.type===`offer`){let n=t.get(e.from);if(n){let t=e.token,r=n.glareToken;if(r&&r>t){Pl(`offer rejected: `,e.from);return}n.glareToken=void 0}}if(e.signal.type===`answer`){Pl(`offer answered by: `,e.from);let n=t.get(e.from);n.glareToken=void 0}e.to===r&&(it(t,e.from,()=>new Kl(this,!1,e.from,n)).peer.signal(e.signal),i());break}};n.key?typeof e.data==`string`&&Nl(Sr(e.data),n.key).then(r):r(e.data)}}}),this.on(`disconnect`,()=>Pl(`disconnect (${e})`))}},tu=e=>{e.emit(`status`,[{connected:e.connected}])},nu=class extends ht{constructor(e,t,{signaling:n=[`wss://y-webrtc-eu.fly.dev`],password:r=null,awareness:i=new Tl(t),maxConns:a=20+_t(En()*15),filterBcConns:o=!0,peerOpts:s={}}={}){super(),this.roomName=e,this.doc=t,this.filterBcConns=o,this.awareness=i,this.shouldConnect=!1,this.signalingUrls=n,this.signalingConns=[],this.maxConns=a,this.peerOpts=s,this.key=r?kl(r,e):Nn(null),this.room=null,this.key.then(n=>{this.room=Ql(t,this,e,n),this.shouldConnect?this.room.connect():this.room.disconnect(),tu(this)}),this.connect(),this.destroy=this.destroy.bind(this),t.on(`destroy`,this.destroy)}get connected(){return this.room!==null&&this.shouldConnect}connect(){this.shouldConnect=!0,this.signalingUrls.forEach(e=>{let t=it(zl,e,()=>new eu(e));this.signalingConns.push(t),t.providers.add(this)}),this.room&&(this.room.connect(),tu(this))}disconnect(){this.shouldConnect=!1,this.signalingConns.forEach(e=>{e.providers.delete(this),e.providers.size===0&&(e.destroy(),zl.delete(e.url))}),this.room&&(this.room.disconnect(),tu(this))}destroy(){this.doc.off(`destroy`,this.destroy),this.key.then(()=>{this.room.destroy(),Bl.delete(this.roomName)}),super.destroy()}},ru=new Map,iu=new Map,au=new Map;function ou(){try{return globalThis.localStorage?.getItem(`titan2:webrtc`)===`1`}catch{return!1}}function su(e){if(!ru.has(e)){let t=new Da({guid:`titan-space-${e}`});ru.set(e,t);let n=new nl(`titan-space-${e}`,t);if(iu.set(e,n),ou())try{let n=new nu(`titan-space-${e}`,t,{signaling:[`wss://signaling.yjs.dev`,`wss://y-webrtc-signaling-eu.herokuapp.com`]});au.set(e,n)}catch{}}return ru.get(e)}function cu(e){let{widgets:t}=lu(e),n=new Set,r=[];t.forEach((e,t)=>{let i=e.get(`id`);typeof i!=`string`||n.has(i)?r.push(t):n.add(i)});for(let e=r.length-1;e>=0;e--)t.delete(r[e],1);return r.length}function lu(e){let t=su(e),n=t.getArray(`widgets`),r=t.getMap(`meta`),i=iu.get(e);return{widgets:n,meta:r,doc:t,whenSynced:i?.synced?Promise.resolve():new Promise(e=>{let t=()=>{i?.off(`synced`,t),e()};i?.on(`synced`,t),setTimeout(()=>e(),2e3)})}}function uu(e){return{id:e.get(`id`),name:e.get(`name`),format:e.get(`format`),source:e.get(`source`),x:e.get(`x`),y:e.get(`y`),w:e.get(`w`),h:e.get(`h`),metadata:e.get(`metadata`),createdAt:e.get(`createdAt`),updatedAt:e.get(`updatedAt`)}}function du(e){let t=new bs;return t.set(`id`,e.id),t.set(`name`,e.name),t.set(`format`,e.format),t.set(`source`,e.source),t.set(`x`,e.x),t.set(`y`,e.y),t.set(`w`,e.w),t.set(`h`,e.h),t.set(`metadata`,e.metadata),t.set(`createdAt`,e.createdAt),t.set(`updatedAt`,e.updatedAt),t}function fu(e){try{let t=typeof localStorage<`u`?localStorage.getItem(`titan2-spaces`):null;if(!t)return null;let n=JSON.parse(t).find(t=>t.id===e);if(!n)return null;let r=new Set;for(let e of n.widgets||[])e&&typeof e.id==`string`&&r.add(e.id);return r}catch{return null}}var pu=new Map;function mu(e,t){let n=pu.get(e);n||(n=new Set,pu.set(e,n)),n.add(t)}function hu(e,t){return pu.get(e)?.has(t)??!1}function gu(e){pu.delete(e)}function _u(e,t){let{widgets:n}=lu(e),r=new Map,i=()=>{let r=new Set,i=fu(e),a=[];n.forEach(t=>{let n=uu(t);if(!n.id||r.has(n.id))return;let o=n.format===`system`,s=typeof n.source==`string`&&n.source.trim()!==``;!o&&!s||i&&!i.has(n.id)&&!hu(e,n.id)||(r.add(n.id),a.push(n))}),t(a)},a=()=>{let e=new Set;n.forEach(t=>e.add(t));for(let[t,n]of r)e.has(t)||(t.unobserve(n),r.delete(t));for(let t of e)if(!r.has(t)){let e=()=>i();t.observe(e),r.set(t,e)}i()};return n.observe(a),a(),()=>{n.unobserve(a);for(let[e,t]of r)e.unobserve(t);r.clear()}}function vu(e,t){let{widgets:n}=lu(e),r={...t,id:`widget_${Date.now()}_${Math.random().toString(36).slice(2,7)}`,createdAt:Date.now(),updatedAt:Date.now()};return mu(e,r.id),n.push([du(r)]),r}function yu(e,t){let{widgets:n}=lu(e),r=-1;n.forEach((e,n)=>{e.get(`id`)===t&&(r=n)}),r>=0&&n.delete(r,1)}function bu(e,t,n){let{widgets:r}=lu(e);r.forEach(e=>{if(e.get(`id`)===t){for(let[t,r]of Object.entries(n))e.set(t,r);e.set(`updatedAt`,Date.now())}})}function xu(e){let{widgets:t}=lu(e);t.delete(0,t.length),gu(e)}function Su(e){iu.get(e)?.destroy(),au.get(e)?.destroy(),ru.get(e)?.destroy(),iu.delete(e),au.delete(e),ru.delete(e),gu(e)}var Cu=`titan2-spaces`;function Y(e,t,n,r,i,a,o){return{id:e,name:t,format:`system`,source:n,x:r,y:i,w:a,h:o,createdAt:Date.now(),updatedAt:Date.now()}}var wu=[{id:`home`,name:`Home`,icon:`Home`,color:`#6366f1`,widgets:[Y(`home-welcome`,`Welcome`,`system:soma`,0,0,6,5),Y(`home-voice`,`Voice`,`system:voice`,6,0,6,5),Y(`home-overview`,`Overview`,`system:overview`,0,5,6,5),Y(`home-sessions`,`Sessions`,`system:sessions`,6,5,6,5),Y(`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:[Y(`soma-main`,`SOMA`,`system:soma`,0,0,8,8),Y(`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:[Y(`cp-hub`,`Command Post`,`system:command-post`,0,0,12,10),Y(`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:[Y(`intel-autopilot`,`Autopilot`,`system:intelligence-autopilot`,0,0,6,5),Y(`intel-workflows`,`Workflows`,`system:intelligence-workflows`,6,0,6,5),Y(`intel-learning`,`Learning`,`system:intelligence-learning`,0,5,6,5),Y(`intel-memory`,`Memory Graph`,`system:memory-graph`,6,5,6,5),Y(`intel-selfimprove`,`Self-Improve`,`system:intelligence-self-improve`,0,10,6,5),Y(`intel-personas`,`Personas`,`system:intelligence-personas`,6,10,6,5),Y(`intel-wiki`,`Memory Wiki`,`system:memory-wiki`,0,15,6,6),Y(`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:[Y(`infra-homelab`,`Homelab`,`system:infra-homelab`,0,0,6,6),Y(`infra-gpu`,`GPU / NVIDIA`,`system:infra-gpu`,6,0,6,6),Y(`infra-files`,`Files`,`system:infra-files`,0,6,4,5),Y(`infra-logs`,`Logs`,`system:infra-logs`,4,6,4,5),Y(`infra-telemetry`,`Telemetry`,`system:infra-telemetry`,8,6,4,5),Y(`infra-vram`,`VRAM`,`system:vram`,0,11,6,5),Y(`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:[Y(`tools-skills`,`Skills`,`system:tools-skills`,0,0,6,6),Y(`tools-mcp`,`MCP Servers`,`system:tools-mcp`,6,0,6,6),Y(`tools-integrations`,`Integrations`,`system:tools-integrations`,0,6,4,5),Y(`tools-channels`,`Channels`,`system:tools-channels`,4,6,4,5),Y(`tools-mesh`,`Mesh Network`,`system:tools-mesh`,8,6,4,5),Y(`tools-recipes`,`Recipes`,`system:recipes`,0,11,6,5),Y(`tools-browser`,`Browser`,`system:browser`,6,11,6,5),Y(`tools-cron`,`Cron`,`system:cron`,0,16,6,5)],createdAt:new Date().toISOString(),updatedAt:new Date().toISOString()},{id:`settings`,name:`Settings`,icon:`Settings`,color:`#6b7280`,widgets:[Y(`settings-specialists`,`Specialist Models`,`system:settings-specialists`,0,0,6,8),Y(`settings-privacy`,`Privacy & Telemetry`,`system:settings-privacy`,6,0,6,8),Y(`settings-general`,`General`,`system:settings-general`,0,8,6,8),Y(`settings-security`,`Security`,`system:settings-security`,6,8,6,8),Y(`settings-audit`,`Audit Log`,`system:settings-audit`,0,16,12,6)],createdAt:new Date().toISOString(),updatedAt:new Date().toISOString()}],Tu=11,Eu={home:new Set([`home-chat`]),tools:new Set([`tools-paperclip`])},Du=new Set([`system:paperclip`,`system:daemon`]);function Ou(e,t){let{widgets:n,meta:r,whenSynced:i}=lu(e.id);i.then(()=>{try{let i=cu(e.id);i>0&&console.info(`[SpaceEngine] healed ${i} duplicate widget(s) in "${e.id}"`);let a=Eu[e.id]??new Set;if(a.size>0||Du.size>0)for(let e=n.length-1;e>=0;e--){let t=n.get(e),r=t?.get(`id`),i=t?.get(`source`),o=typeof r==`string`&&a.has(r),s=typeof i==`string`&&Du.has(i);(o||s)&&n.delete(e,1)}if(t){for(let e=n.length-1;e>=0;e--){let t=n.get(e)?.get(`source`);(typeof t!=`string`||t.trim()===``)&&n.delete(e,1)}let t=new Map;for(let n of e.widgets)t.set(n.id,n);let i=new Set;n.forEach(e=>{let n=e.get(`id`);if(typeof n==`string`&&t.has(n)){i.add(n);let r=t.get(n);e.set(`x`,r.x),e.set(`y`,r.y),e.set(`w`,r.w),e.set(`h`,r.h)}});for(let t of e.widgets)i.has(t.id)||n.push([du(t)]);r.set(`seedVersion`,Tu)}}catch(t){console.warn(`[SpaceEngine] healYSpaceOnSync failed for "${e.id}":`,t)}})}function ku(){try{let e=localStorage.getItem(Cu),t=parseInt(localStorage.getItem(`${Cu}-version`)||`0`,10)<Tu;for(let e of wu)Ou(e,t);if(!e||t){localStorage.setItem(`${Cu}-version`,String(Tu));let e=wu.map(e=>({...e,widgets:[...e.widgets]}));return ju(e),e}let n=JSON.parse(e);for(let e of n)Array.isArray(e.widgets)||(e.widgets=[]),e.widgets=e.widgets.filter(e=>e&&typeof e.id==`string`).filter(t=>!(Eu[e.id]?.has(t.id)??!1)).filter(e=>!(typeof e.source==`string`&&Du.has(e.source))).map(e=>({...e,x:Number.isFinite(e.x)?Math.max(0,Math.floor(e.x)):0,y:Number.isFinite(e.y)?Math.max(0,Math.floor(e.y)):0,w:Number.isFinite(e.w)?Math.max(1,Math.floor(e.w)):4,h:Number.isFinite(e.h)?Math.max(1,Math.floor(e.h)):4}));for(let e of n){let t=new Set;e.widgets=e.widgets.filter(e=>t.has(e.id)?!1:(t.add(e.id),!0))}let r=new Map(n.map(e=>[e.id,e]));return wu.forEach(e=>{r.get(e.id)||r.set(e.id,{...e,widgets:[...e.widgets]})}),Array.from(r.values())}catch{return wu.map(e=>({...e,widgets:[...e.widgets]}))}}var Au=null;function ju(e){Au&&clearTimeout(Au),Au=setTimeout(()=>{localStorage.setItem(Cu,JSON.stringify(e))},250)}var Mu=null,X={list(){return Mu||=ku(),Mu},get(e){return this.list().find(t=>t.id===e)},create(e){let t={id:`space_${Date.now()}_${Math.random().toString(36).slice(2,7)}`,name:e,widgets:[],createdAt:new Date().toISOString(),updatedAt:new Date().toISOString()};return Mu=[...this.list(),t],ju(Mu),t},save(e){e.updatedAt=new Date().toISOString(),Mu=this.list().map(t=>t.id===e.id?e:t),ju(Mu)},remove(e){Mu=this.list().filter(t=>t.id!==e),ju(Mu)},addWidget(e,t){if(!t.source||t.source.trim()===``)throw Error(`Widget source cannot be empty`);{let n=vu(e,t);try{let t=localStorage.getItem(Cu),r=t?JSON.parse(t):[],i=r.find(t=>t.id===e);if(i)new Set((i.widgets||[]).map(e=>e.id)).has(n.id)||(i.widgets=[...i.widgets||[],n]),i.updatedAt=new Date().toISOString(),Mu=r,ju(r);else{let t={id:e,name:e,widgets:[n],createdAt:new Date().toISOString(),updatedAt:new Date().toISOString()};Mu=[...r,t],ju(Mu)}}catch{}return n}let n=this.get(e);if(!n)throw Error(`Space ${e} not found`);let r={...t,id:`widget_${Date.now()}_${Math.random().toString(36).slice(2,7)}`,createdAt:Date.now(),updatedAt:Date.now()};return n.widgets=[...n.widgets,r],this.save(n),r},updateWidget(e,t,n){bu(e,t,n);let r=this.get(e);r&&(r.widgets=r.widgets.map(e=>e.id===t?{...e,...n,updatedAt:Date.now()}:e),this.save(r))},removeWidget(e,t){yu(e,t);let n=this.get(e);n&&(n.widgets=n.widgets.filter(e=>e.id!==t),this.save(n))},updateLayout(e,t){for(let n of t)bu(e,n.i,{x:n.x,y:n.y,w:n.w,h:n.h});let n=this.get(e);n&&(n.widgets=n.widgets.map(e=>{let n=t.find(t=>t&&t.i===e.id);return n?{...e,x:Number.isFinite(n.x)?Math.max(0,Math.floor(n.x)):0,y:Number.isFinite(n.y)?Math.max(0,Math.floor(n.y)):0,w:Number.isFinite(n.w)?Math.max(1,Math.floor(n.w)):4,h:Number.isFinite(n.h)?Math.max(1,Math.floor(n.h)):4,updatedAt:Date.now()}:e}),this.save(n))},observe(e,t){return _u(e,t)},async clearSpace(e){{let{whenSynced:t}=lu(e);await t,xu(e),Su(e);try{let t=indexedDB.deleteDatabase(`titan-space-${e}`);await new Promise((e,n)=>{t.onsuccess=()=>e(),t.onerror=()=>n(t.error),t.onblocked=()=>e()})}catch{}}let t=this.list(),n=t.find(t=>t.id===e);n&&(n.widgets=[],ju(t))}},Z=i(),Nu=.4,Pu=.1,Fu=`titan-canvas-zoom`,Iu=e=>Math.min(2,Math.max(Nu,Math.round(e*100)/100));function Lu(){let[e,t]=(0,N.useState)(()=>{try{let e=parseFloat(localStorage.getItem(Fu)||``);return e>=.4&&e<=2?e:1}catch{return 1}}),n=(0,N.useCallback)(e=>{let n=Iu(e);t(n);try{localStorage.setItem(Fu,String(n))}catch{}},[]),r=(0,N.useRef)(e);r.current=e;let i=(0,N.useCallback)(()=>n(r.current+Pu),[n]),a=(0,N.useCallback)(()=>n(r.current-Pu),[n]),o=(0,N.useCallback)(()=>n(1),[n]);return(0,N.useEffect)(()=>{let e=e=>{(e.ctrlKey||e.metaKey)&&(e.preventDefault(),n(r.current+(e.deltaY<0?Pu:-.1)))};return window.addEventListener(`wheel`,e,{passive:!1}),()=>window.removeEventListener(`wheel`,e)},[n]),(0,N.useEffect)(()=>{let e=e=>{if(!(e.ctrlKey||e.metaKey))return;let t=e.target;t&&(t.tagName===`INPUT`||t.tagName===`TEXTAREA`||t.isContentEditable)||(e.key===`=`||e.key===`+`?(e.preventDefault(),n(r.current+Pu)):e.key===`-`?(e.preventDefault(),n(r.current-Pu)):e.key===`0`&&(e.preventDefault(),n(1)))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[n]),{zoom:e,setZoom:n,zoomIn:i,zoomOut:a,reset:o}}function Ru({zoom:e,zoomIn:t,zoomOut:n,reset:r}){return(0,Z.jsxs)(`div`,{className:`flex items-center gap-1 rounded-full border px-1.5 py-1 shadow-lg`,style:{background:`var(--theme-paper, var(--color-bg-secondary))`,borderColor:`var(--theme-paper-line, var(--color-border))`},role:`group`,"aria-label":`Canvas zoom`,children:[(0,Z.jsx)(`button`,{onClick:n,disabled:e<=Nu,title:`Zoom out (Ctrl -)`,className:`p-1.5 rounded-full text-[var(--theme-ink,var(--color-text))] hover:bg-black/10 disabled:opacity-40 transition-colors`,"aria-label":`Zoom out`,children:(0,Z.jsx)(ne,{size:15})}),(0,Z.jsxs)(`button`,{onClick:r,title:`Reset to 100% (Ctrl 0)`,className:`min-w-[44px] text-center text-[11px] font-mono tabular-nums text-[var(--theme-ink,var(--color-text))] hover:underline`,"aria-label":`Zoom ${Math.round(e*100)} percent, click to reset`,children:[Math.round(e*100),`%`]}),(0,Z.jsx)(`button`,{onClick:t,disabled:e>=2,title:`Zoom in (Ctrl +)`,className:`p-1.5 rounded-full text-[var(--theme-ink,var(--color-text))] hover:bg-black/10 disabled:opacity-40 transition-colors`,"aria-label":`Zoom in`,children:(0,Z.jsx)(te,{size:15})}),(0,Z.jsx)(`button`,{onClick:r,title:`Fit to 100%`,className:`p-1.5 rounded-full text-[var(--theme-ink,var(--color-text))] hover:bg-black/10 transition-colors ml-0.5`,"aria-label":`Reset zoom`,children:(0,Z.jsx)(S,{size:14})})]})}var zu=null;function Bu(){if(zu)return zu;let e=async e=>{let t=await fetch(e,{credentials:`same-origin`});if(!t.ok)throw Error(`Failed to load ${e}: ${t.status} ${t.statusText}`);return t.text()};return zu=Promise.all([e(`/react.development.js`),e(`/react-dom.development.js`),e(`/babel.min.js`)]).then(([e,t,n])=>({react:e,reactDom:t,babel:n})).catch(e=>{throw zu=null,e}),zu}function Vu(e){let t=Hu;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>`+e.react+`<\/script><script>`+e.reactDom+`<\/script><script>`+e.babel+`<\/script>`+t}var Hu=`
|
|
7
|
+
<script>
|
|
8
|
+
(function() {
|
|
9
|
+
'use strict';
|
|
10
|
+
|
|
11
|
+
// NOTE: Prototype freezing is intentionally disabled.
|
|
12
|
+
// Babel standalone mutates Function.prototype.toString during JSX transform.
|
|
13
|
+
// Freezing causes "Cannot assign to read only property" errors.
|
|
14
|
+
|
|
15
|
+
// Prevent eval and Function constructor abuse
|
|
16
|
+
window.eval = function() { throw new Error('eval is disabled in sandbox'); };
|
|
17
|
+
const OriginalFunction = window.Function;
|
|
18
|
+
window.Function = function(...args) {
|
|
19
|
+
const body = args.pop() || '';
|
|
20
|
+
if (body.includes('import') && body.includes('http')) {
|
|
21
|
+
throw new Error('Dynamic imports with URLs are disabled in sandbox');
|
|
22
|
+
}
|
|
23
|
+
return OriginalFunction.apply(this, [...args, body]);
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const pending = new Map();
|
|
27
|
+
let msgId = 0;
|
|
28
|
+
let reactRoot = null;
|
|
29
|
+
|
|
30
|
+
function send(type, payload) {
|
|
31
|
+
const id = ++msgId;
|
|
32
|
+
return new Promise((resolve, reject) => {
|
|
33
|
+
pending.set(id, { resolve, reject });
|
|
34
|
+
window.parent.postMessage({ type, id, payload }, '*');
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
window.addEventListener('message', (e) => {
|
|
39
|
+
// Resolve pending iframe promises (parent responses to titan.* calls)
|
|
40
|
+
if (typeof e.data?.id === 'number' && pending.has(e.data.id)) {
|
|
41
|
+
const p = pending.get(e.data.id);
|
|
42
|
+
pending.delete(e.data.id);
|
|
43
|
+
if (e.data.error) p.reject(new Error(e.data.error));
|
|
44
|
+
else p.resolve(e.data.payload);
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Handle parent commands
|
|
49
|
+
if (e.data?.type === 'render') {
|
|
50
|
+
handleRender(e.data.id, e.data.payload);
|
|
51
|
+
}
|
|
52
|
+
if (e.data?.type === 'execute') {
|
|
53
|
+
handleExecute(e.data.id, e.data.payload);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
const titan = {
|
|
58
|
+
fetch: (url, opts) => {
|
|
59
|
+
try { new URL(url, 'https://example.com'); } catch {
|
|
60
|
+
throw new Error('Invalid URL: ' + url);
|
|
61
|
+
}
|
|
62
|
+
return send('fetch', { url, options: opts });
|
|
63
|
+
},
|
|
64
|
+
api: { call: (endpoint, body) => send('api', { endpoint, body }) },
|
|
65
|
+
state: {
|
|
66
|
+
get: (key) => send('state', { action: 'get', key }),
|
|
67
|
+
set: (key, value) => send('state', { action: 'set', key, value }),
|
|
68
|
+
},
|
|
69
|
+
canvas: {
|
|
70
|
+
createWidget: (def) => send('canvas', { action: 'createWidget', def }),
|
|
71
|
+
updateWidget: (id, patch) => send('canvas', { action: 'updateWidget', id, patch }),
|
|
72
|
+
removeWidget: (id) => send('canvas', { action: 'removeWidget', id }),
|
|
73
|
+
listWidgets: () => send('canvas', { action: 'listWidgets' }),
|
|
74
|
+
},
|
|
75
|
+
// v6.0 Step 8 — Widget-runtime API surface.
|
|
76
|
+
// titan.tools.run / titan.tools.list — invoke or enumerate any
|
|
77
|
+
// TITAN tool from inside a widget. Widgets become first-class
|
|
78
|
+
// agent surfaces (not just dumb UI).
|
|
79
|
+
tools: {
|
|
80
|
+
list: () => send('api', { endpoint: '/api/tools', body: { method: 'GET' } }),
|
|
81
|
+
run: (name, args) => send('api', { endpoint: '/api/tools/run', body: { name, args: args || {} } }),
|
|
82
|
+
},
|
|
83
|
+
// titan.agent.ask — sub-question to TITAN itself. Widgets can
|
|
84
|
+
// delegate parts of their work back to the agent loop.
|
|
85
|
+
agent: {
|
|
86
|
+
ask: (prompt) => send('api', { endpoint: '/api/message', body: { content: String(prompt) } }),
|
|
87
|
+
},
|
|
88
|
+
// titan.memory.get / .set — typed access to widget-scoped memory.
|
|
89
|
+
memory: {
|
|
90
|
+
get: (key) => send('api', { endpoint: '/api/memory/' + encodeURIComponent(key), body: { method: 'GET' } }),
|
|
91
|
+
set: (key, value) => send('api', { endpoint: '/api/memory', body: { key, value } }),
|
|
92
|
+
},
|
|
93
|
+
// titan.persona — read-only handle to the active persona content.
|
|
94
|
+
persona: {
|
|
95
|
+
get: () => send('api', { endpoint: '/api/persona/current', body: { method: 'GET' } }),
|
|
96
|
+
},
|
|
97
|
+
// titan.space — read-only handle to the active Space (id, name,
|
|
98
|
+
// intent, widget count).
|
|
99
|
+
space: {
|
|
100
|
+
active: () => send('api', { endpoint: '/api/spaces', body: { method: 'GET' } }),
|
|
101
|
+
},
|
|
102
|
+
log: (...args) => send('log', { args: args.map(a => String(a)) }),
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
window.titan = titan;
|
|
106
|
+
|
|
107
|
+
function handleRender(msgId, payload) {
|
|
108
|
+
const { format, source } = payload;
|
|
109
|
+
const root = document.getElementById('root');
|
|
110
|
+
root.innerHTML = '';
|
|
111
|
+
const loadingEl = document.getElementById('sandbox-loading');
|
|
112
|
+
if (loadingEl) loadingEl.style.display = 'none';
|
|
113
|
+
|
|
114
|
+
// Unmount previous React root to prevent memory leaks
|
|
115
|
+
if (reactRoot) {
|
|
116
|
+
try { reactRoot.unmount(); } catch (e) {}
|
|
117
|
+
reactRoot = null;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function showError(title, detail) {
|
|
121
|
+
root.innerHTML = '';
|
|
122
|
+
const wrap = document.createElement('div');
|
|
123
|
+
wrap.style.cssText = 'padding:16px;font-family:monospace;font-size:12px;line-height:1.5;';
|
|
124
|
+
const h = document.createElement('div');
|
|
125
|
+
h.style.cssText = 'color:#ef4444;font-weight:bold;margin-bottom:8px;';
|
|
126
|
+
h.textContent = title;
|
|
127
|
+
const d = document.createElement('pre');
|
|
128
|
+
d.style.cssText = 'color:#a1a1aa;white-space:pre-wrap;word-break:break-word;margin:0;';
|
|
129
|
+
d.textContent = detail;
|
|
130
|
+
wrap.appendChild(h);
|
|
131
|
+
wrap.appendChild(d);
|
|
132
|
+
root.appendChild(wrap);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
try {
|
|
136
|
+
if (format === 'react') {
|
|
137
|
+
console.log('[sandbox] render react, source length:', source.length);
|
|
138
|
+
if (!source || source.trim() === '') {
|
|
139
|
+
throw new Error('Source is empty');
|
|
140
|
+
}
|
|
141
|
+
if (typeof React === 'undefined') {
|
|
142
|
+
throw new Error('React not loaded — the inlined React bundle failed to evaluate inside the sandbox.');
|
|
143
|
+
}
|
|
144
|
+
if (typeof ReactDOM === 'undefined') {
|
|
145
|
+
throw new Error('ReactDOM not loaded — the inlined ReactDOM bundle failed to evaluate inside the sandbox.');
|
|
146
|
+
}
|
|
147
|
+
if (typeof Babel === 'undefined') {
|
|
148
|
+
throw new Error('Babel not loaded — the inlined Babel bundle failed to evaluate inside the sandbox.');
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// ── 1. Strip export-default variations so Babel doesn't choke ──
|
|
152
|
+
// Using simple string operations (no regex backslashes) to avoid Vite stripping
|
|
153
|
+
let src = source;
|
|
154
|
+
const lines = src.split('\\n');
|
|
155
|
+
const outLines = [];
|
|
156
|
+
for (let i = 0; i < lines.length; i++) {
|
|
157
|
+
let line = lines[i];
|
|
158
|
+
const trimmed = line.trim();
|
|
159
|
+
if (trimmed.startsWith('export default function ')) {
|
|
160
|
+
const rest = trimmed.slice('export default function '.length);
|
|
161
|
+
const name = rest.split('(')[0].trim();
|
|
162
|
+
line = '/* export default function ' + name + ' */ function ' + rest;
|
|
163
|
+
} else if (trimmed.startsWith('export default class ')) {
|
|
164
|
+
const rest = trimmed.slice('export default class '.length);
|
|
165
|
+
const name = rest.split(' ')[0].trim().split('{')[0].trim();
|
|
166
|
+
line = '/* export default class ' + name + ' */ class ' + rest;
|
|
167
|
+
} else if (trimmed.startsWith('export default ')) {
|
|
168
|
+
line = '/* export default */';
|
|
169
|
+
}
|
|
170
|
+
outLines.push(line);
|
|
171
|
+
}
|
|
172
|
+
src = outLines.join('\\n');
|
|
173
|
+
|
|
174
|
+
// ── 2. Detect candidate component names ──
|
|
175
|
+
const detected = new Set();
|
|
176
|
+
const srcLines = src.split('\\n');
|
|
177
|
+
const keywords = ['function ', 'const ', 'let ', 'var ', 'class '];
|
|
178
|
+
for (let i = 0; i < srcLines.length; i++) {
|
|
179
|
+
const trimmed = srcLines[i].trimStart();
|
|
180
|
+
for (let k = 0; k < keywords.length; k++) {
|
|
181
|
+
const kw = keywords[k];
|
|
182
|
+
if (trimmed.startsWith(kw)) {
|
|
183
|
+
const after = trimmed.slice(kw.length);
|
|
184
|
+
const endIdx = after.search(/[\\s\\(=]/);
|
|
185
|
+
const name = endIdx > 0 ? after.slice(0, endIdx) : after;
|
|
186
|
+
if (name.length > 0 && name[0] >= 'A' && name[0] <= 'Z') {
|
|
187
|
+
detected.add(name);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
const names = ['Widget', ...Array.from(detected)];
|
|
194
|
+
console.log('[sandbox] detected names:', names.join(', '));
|
|
195
|
+
|
|
196
|
+
// ── 3. Babel transform (JSX only, classic runtime → React.createElement) ──
|
|
197
|
+
let code;
|
|
198
|
+
try {
|
|
199
|
+
const babelResult = Babel.transform(src, { presets: [['react', { runtime: 'classic' }]], filename: 'widget.tsx' });
|
|
200
|
+
code = babelResult.code;
|
|
201
|
+
console.log('[sandbox] babel ok, code length:', code.length);
|
|
202
|
+
} catch (babelErr) {
|
|
203
|
+
throw new Error('Babel transform failed: ' + babelErr.message);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// ── 3.5 Auto-inject React hooks and the legacy gallery render()
|
|
207
|
+
// helper. Older templates end with render(<MyWidget/>); while newer
|
|
208
|
+
// generated code is component-only and gets auto-detected below.
|
|
209
|
+
const hookDecl = 'const { useState, useEffect, useRef, useCallback, useMemo, useContext, useReducer, useLayoutEffect, useId, useTransition, useDeferredValue, useImperativeHandle, useDebugValue, useSyncExternalStore } = React;';
|
|
210
|
+
const renderDecl = 'window.__titanRenderedElement = null; const render = (node) => { window.__titanRenderedElement = node; };';
|
|
211
|
+
code = hookDecl + '\\n' + renderDecl + '\\n' + code;
|
|
212
|
+
|
|
213
|
+
// ── 4. Eval the code and find the component ──
|
|
214
|
+
const returnChecks = names.map(n =>
|
|
215
|
+
'if (typeof ' + n + ' !== "undefined" && ' + n + ' != null) return ' + n + ';'
|
|
216
|
+
).join('\\n') + '\\nreturn undefined;';
|
|
217
|
+
|
|
218
|
+
let Widget;
|
|
219
|
+
try {
|
|
220
|
+
const fn = new Function('React', 'ReactDOM', 'titan', code + '\\n' + returnChecks);
|
|
221
|
+
Widget = fn(React, ReactDOM, titan);
|
|
222
|
+
console.log('[sandbox] eval ok, Widget type:', typeof Widget, 'name:', Widget?.name || Widget?.displayName || 'n/a');
|
|
223
|
+
} catch (evalErr) {
|
|
224
|
+
throw new Error('Eval failed: ' + evalErr.message + '\\nDetected names: ' + names.join(', '));
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
const renderedElement = window.__titanRenderedElement;
|
|
228
|
+
if (!Widget && !renderedElement) {
|
|
229
|
+
throw new Error('No React component found. Detected names: ' + names.join(', ') + '. The code must define a capitalized component (e.g., function Widget() {}).');
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
// ── 5. Render ──
|
|
233
|
+
try {
|
|
234
|
+
reactRoot = ReactDOM.createRoot(root);
|
|
235
|
+
reactRoot.render(renderedElement || React.createElement(Widget, { titan }));
|
|
236
|
+
console.log('[sandbox] react render dispatched');
|
|
237
|
+
} catch (renderErr) {
|
|
238
|
+
throw new Error('React render failed: ' + renderErr.message);
|
|
239
|
+
}
|
|
240
|
+
} else if (format === 'vanilla') {
|
|
241
|
+
const fn = new Function('container', 'titan', 'return (' + source + ')(container, titan)');
|
|
242
|
+
const cleanup = fn(root, titan);
|
|
243
|
+
window.__widgetCleanup = cleanup;
|
|
244
|
+
} else if (format === 'html') {
|
|
245
|
+
root.innerHTML = source;
|
|
246
|
+
}
|
|
247
|
+
window.parent.postMessage({ type: 'rendered', id: msgId }, '*');
|
|
248
|
+
} catch (err) {
|
|
249
|
+
console.error('[sandbox] render error:', err.name, err.message);
|
|
250
|
+
showError(err.name + ': ' + err.message, err.stack || '');
|
|
251
|
+
window.parent.postMessage({ type: 'error', id: msgId, error: err.message }, '*');
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
function handleExecute(msgId, payload) {
|
|
256
|
+
const { code } = payload;
|
|
257
|
+
const logs = [];
|
|
258
|
+
const originals = {};
|
|
259
|
+
['log','info','warn','error','debug'].forEach(m => {
|
|
260
|
+
originals[m] = console[m];
|
|
261
|
+
console[m] = (...args) => {
|
|
262
|
+
logs.push({ level: m, text: args.map(a => String(a)).join(' ') });
|
|
263
|
+
originals[m](...args);
|
|
264
|
+
};
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
const AsyncFunction = Object.getPrototypeOf(async function(){}).constructor;
|
|
268
|
+
|
|
269
|
+
// Shadow dangerous globals so sandboxed code cannot access them directly.
|
|
270
|
+
const forbiddenGlobals = [
|
|
271
|
+
'window','globalThis','self','top','parent','document','location',
|
|
272
|
+
'fetch','XMLHttpRequest','WebSocket','EventSource',
|
|
273
|
+
'localStorage','sessionStorage','indexedDB','navigator','history',
|
|
274
|
+
];
|
|
275
|
+
|
|
276
|
+
const runner = new AsyncFunction(
|
|
277
|
+
...forbiddenGlobals,
|
|
278
|
+
'__titan',
|
|
279
|
+
'"use strict";\\n' +
|
|
280
|
+
forbiddenGlobals.map(g => 'const ' + g + ' = undefined;').join('\\n') + '\\n' +
|
|
281
|
+
code
|
|
282
|
+
);
|
|
283
|
+
|
|
284
|
+
(async () => {
|
|
285
|
+
try {
|
|
286
|
+
const result = await runner(...forbiddenGlobals.map(() => undefined), titan);
|
|
287
|
+
Object.keys(originals).forEach(m => console[m] = originals[m]);
|
|
288
|
+
window.parent.postMessage({ type: 'result', id: msgId, payload: { status: 'success', logs, result: formatValue(result), resultText: formatValue(result) } }, '*');
|
|
289
|
+
} catch (err) {
|
|
290
|
+
Object.keys(originals).forEach(m => console[m] = originals[m]);
|
|
291
|
+
window.parent.postMessage({ type: 'result', id: msgId, payload: { status: 'error', logs, error: { message: err.message, name: err.name, stack: err.stack } } }, '*');
|
|
292
|
+
}
|
|
293
|
+
})();
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
function formatValue(v) {
|
|
297
|
+
if (v === undefined) return 'undefined';
|
|
298
|
+
if (v === null) return 'null';
|
|
299
|
+
if (typeof v === 'string') return v;
|
|
300
|
+
if (typeof v === 'number' || typeof v === 'boolean') return String(v);
|
|
301
|
+
if (typeof v === 'function') return '[Function]';
|
|
302
|
+
if (v instanceof Error) return v.stack || v.message;
|
|
303
|
+
if (v instanceof Node) return '<' + v.tagName?.toLowerCase() + '>';
|
|
304
|
+
try { return JSON.stringify(v); } catch { return String(v); }
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
window.parent.postMessage({ type: 'ready' }, '*');
|
|
308
|
+
})();
|
|
309
|
+
<\/script>
|
|
310
|
+
</body>
|
|
311
|
+
</html>`,Uu=class{iframe=null;pending=new Map;msgId=0;ready=!1;readyQueue=[];onLog;messageHandler;messageListener;observer;constructor(e,t){this.iframe=e,this.onLog=t?.onLog,this.init()}init(){let e=this.iframe;Bu().then(t=>{!this.iframe||!document.contains(e)||(e.srcdoc=Vu(t))}).catch(e=>{console.error(`[sandbox] vendor scripts failed to load`,e);for(let[t,n]of this.pending)n.reject(Error(`Sandbox boot failed: `+e.message)),this.pending.delete(t)});let t=e=>{let t=e.data;if(!(!t||typeof t!=`object`)&&!(!t.type||typeof t.type!=`string`)&&[`ready`,`rendered`,`error`,`result`,`fetch`,`api`,`state`,`canvas`,`log`,`import`].includes(t.type)){if(t?.type===`ready`){this.ready=!0,this.readyQueue.forEach(e=>e()),this.readyQueue=[];return}if(typeof t?.id==`number`&&this.pending.has(t.id)){let e=this.pending.get(t.id);this.pending.delete(t.id),t.type===`error`?e.reject(Error(t.error||`Sandbox error`)):e.resolve(t.payload);return}if(t?.type===`fetch`||t?.type===`api`||t?.type===`state`||t?.type===`canvas`||t?.type===`log`||t?.type===`import`){this.handleIframeRequest(t.type,t.id,t.payload);return}}};this.messageListener=t,window.addEventListener(`message`,t);let n=new MutationObserver(()=>{document.contains(e)||this.destroy()});this.observer=n,e.parentNode&&n.observe(e.parentNode,{childList:!0,subtree:!0})}async handleIframeRequest(e,t,n){let r=this.iframe;if(r?.contentWindow)try{let i;if(e===`log`)this.onLog?.(n?.args||[]),i={ok:!0};else if(e===`fetch`){let{url:e,options:t}=n||{},r=localStorage.getItem(`titan-token`),a={...t?.headers||{}},o=!1;try{typeof e==`string`&&(o=e.startsWith(`/`)?!0:new URL(e,window.location.href).origin===window.location.origin)}catch{}r&&o&&(a.Authorization=`Bearer ${r}`);let s=await fetch(e,{...t,headers:a}),c=await s.text(),l;try{l=JSON.parse(c)}catch{}i={ok:s.ok,status:s.status,text:c,json:l}}else if(e===`api`){let{endpoint:e,body:t}=n||{},r=localStorage.getItem(`titan-token`),a={"Content-Type":`application/json`},o=`POST`,s=t;if(t&&typeof t==`object`&&(`method`in t||`headers`in t)&&!(`content`in t)&&!(`message`in t)&&!(`action`in t)){let e=t;typeof e.method==`string`&&(o=e.method.toUpperCase()),e.headers&&Object.assign(a,e.headers),s=e.body}r&&(a.Authorization=`Bearer ${r}`);let c=typeof e==`string`?e:``;c.startsWith(`/api/`)||(c=c.startsWith(`/`)?`/api`+c:`/api/`+c);let l={method:o,headers:a};o!==`GET`&&o!==`HEAD`&&s!==void 0&&(l.body=typeof s==`string`?s:JSON.stringify(s));let u=await fetch(c,l),d=await u.text(),f;try{f=JSON.parse(d)}catch{}i={...f&&typeof f==`object`&&!Array.isArray(f)?f:{},status:u.status,body:f??d,ok:u.ok}}else if(e===`state`){let{action:e,key:t,value:r}=n||{};if(e===`get`){let e=localStorage.getItem(`titan:sandbox:`+t);i=e?JSON.parse(e):void 0}else e===`set`&&(localStorage.setItem(`titan:sandbox:`+t,JSON.stringify(r)),i={ok:!0})}else e===`canvas`?i=this.messageHandler?await this.messageHandler({type:e,payload:n}):{ok:!1,error:`Canvas operations not configured`}:e===`import`&&(i={ok:!1,error:`Dynamic imports not supported in sandbox`});r.contentWindow.postMessage({type:`result`,id:t,payload:i},`*`)}catch(e){r.contentWindow.postMessage({type:`error`,id:t,error:e.message||String(e)},`*`)}}whenReady(){return this.ready?Promise.resolve():new Promise((e,t)=>{let n=setTimeout(()=>{t(Error(`Sandbox iframe failed to become ready within 30s. React, ReactDOM, or Babel scripts may have failed to load.`))},3e4);this.readyQueue.push(()=>{clearTimeout(n),e()})})}post(e,t){return new Promise((n,r)=>{let i=++this.msgId;this.pending.set(i,{resolve:n,reject:r}),this.whenReady().then(()=>{this.iframe?.contentWindow?.postMessage({type:e,id:i,payload:t},`*`)}).catch(r)})}async render(e,t){await this.post(`render`,{format:e,source:t})}async execute(e){return this.post(`execute`,{code:e})}setMessageHandler(e){this.messageHandler=e}destroy(){this.observer&&=(this.observer.disconnect(),void 0),this.messageListener&&=(window.removeEventListener(`message`,this.messageListener),void 0),this.iframe=null,this.pending.clear(),this.readyQueue=[],this.ready=!1,this.messageHandler=void 0}};function Wu(e=3e5){let[t,n]=(0,N.useState)(null),[r,i]=(0,N.useState)(!1),a=(0,N.useCallback)(async()=>{i(!0);try{let e=await j(`/api/update`);if(e.ok){let t=await e.json();n(t)}}catch{}finally{i(!1)}},[]);return(0,N.useEffect)(()=>{a();let t=setInterval(a,e);return()=>clearInterval(t)},[a,e]),{info:t,checking:r,triggerUpdate:(0,N.useCallback)(async(e=!0)=>{try{return await(await j(`/api/update`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({restart:e})})).json()}catch(e){return{ok:!1,error:e.message}}},[]),waitForReload:(0,N.useCallback)(async(e,t=3e4)=>{let r=Date.now();for(;Date.now()-r<t;){await new Promise(e=>setTimeout(e,1500));try{let t=await j(`/api/update`);if(t.ok){let r=await t.json();if(r.current&&r.current!==e)return n(r),r.current}}catch{}}return null},[])}}function Gu(e){let t=(0,N.useCallback)(t=>{let n=t.target;if(!(n.tagName===`INPUT`||n.tagName===`TEXTAREA`||n.isContentEditable))for(let n of e){let e=t.key.toLowerCase()===n.key.toLowerCase(),r=!!n.ctrl===(t.ctrlKey||t.metaKey),i=!!n.shift===t.shiftKey,a=!!n.alt===t.altKey;if(e&&r&&i&&a){t.preventDefault(),n.action();return}}},[e]);(0,N.useEffect)(()=>(window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)),[t])}var Ku=[{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 qu({open:e,onClose:t}){return e?(0,Z.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60`,onClick:t,children:(0,Z.jsxs)(`div`,{className:`bg-zinc-900 border border-zinc-700 rounded-lg p-6 max-w-md w-full shadow-xl`,onClick:e=>e.stopPropagation(),children:[(0,Z.jsx)(`h2`,{className:`text-lg font-semibold text-white mb-4`,children:`Keyboard Shortcuts`}),(0,Z.jsx)(`div`,{className:`space-y-2`,children:Ku.map(e=>(0,Z.jsxs)(`div`,{className:`flex justify-between text-sm`,children:[(0,Z.jsx)(`span`,{className:`text-zinc-300`,children:e.description}),(0,Z.jsx)(`kbd`,{className:`px-2 py-0.5 bg-zinc-800 rounded text-zinc-400 font-mono text-xs`,children:e.key})]},e.key+e.description))}),(0,Z.jsx)(`p`,{className:`mt-4 text-xs text-zinc-500`,children:`Press Escape to close`})]})}):null}var Ju={Home:(0,Z.jsx)(we,{className:`w-3.5 h-3.5`}),Brain:(0,Z.jsx)(_e,{className:`w-3.5 h-3.5`}),Terminal:(0,Z.jsx)(de,{className:`w-3.5 h-3.5`}),Network:(0,Z.jsx)(ie,{className:`w-3.5 h-3.5`}),Server:(0,Z.jsx)(le,{className:`w-3.5 h-3.5`}),Wrench:(0,Z.jsx)(ke,{className:`w-3.5 h-3.5`}),Settings:(0,Z.jsx)(ue,{className:`w-3.5 h-3.5`}),FileText:(0,Z.jsx)(v,{className:`w-3.5 h-3.5`})};function Yu({currentSpaceId:e,onSpaceSelect:t}){let[n,r]=(0,N.useState)(!1),[i,a]=(0,N.useState)(``),o=X.list(),s=()=>{if(!i.trim())return;let e=X.create(i.trim());a(``),t(e.id)};return(0,Z.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:[(0,Z.jsxs)(`button`,{onClick:()=>r(e=>!e),className:`w-full flex items-center justify-between px-3 py-2.5 hover:bg-[#27272a]/40 transition-colors`,children:[(0,Z.jsx)(`span`,{className:`text-[10px] font-bold uppercase tracking-widest text-[#52525b]`,children:`Spaces`}),(0,Z.jsx)(p,{className:`w-3.5 h-3.5 text-[#3f3f46] transition-transform ${n?``:`rotate-180`}`})]}),n&&(0,Z.jsxs)(`div`,{className:`px-2 pb-2`,children:[(0,Z.jsx)(`div`,{className:`space-y-0.5`,children:o.map(n=>(0,Z.jsxs)(`button`,{onClick:()=>t(n.id),className:`w-full flex items-center gap-2.5 px-2.5 py-1.5 rounded-lg text-left text-[11px] transition-colors ${n.id===e?`bg-[#6366f1]/10 text-[#818cf8]`:`text-[#71717a] hover:bg-[#27272a]/40 hover:text-[#a1a1aa]`}`,children:[(0,Z.jsx)(`span`,{style:{color:n.color||`#52525b`},children:Ju[n.icon||``]||(0,Z.jsx)(`div`,{className:`w-3.5 h-3.5 rounded-full`,style:{background:n.color||`#52525b`}})}),(0,Z.jsx)(`span`,{className:`truncate`,children:n.name})]},n.id))}),(0,Z.jsxs)(`div`,{className:`mt-2 pt-2 border-t border-[#27272a]/40 flex gap-1.5`,children:[(0,Z.jsx)(`input`,{value:i,onChange:e=>a(e.target.value),onKeyDown:e=>e.key===`Enter`&&s(),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`}),(0,Z.jsx)(`button`,{onClick:s,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:(0,Z.jsx)(T,{className:`w-3.5 h-3.5`})})]})]})]})}var Xu=[`_____javascript`,`_____react`,`_____tool`,`_____widget`,`_____canvas`,`_____framework`,`_____transient`];function Zu(e,t){let n=t;for(;n>0&&e[n-1]!==`
|
|
312
|
+
`&&e[n-1]!==`\r`;)n--;return n}function Qu(e,t){let n=t;for(;n<e.length&&e[n]!==`
|
|
313
|
+
`&&e[n]!==`\r`;)n++;return n}function $u(e,t,n){let r=Zu(e,t),i=Qu(e,t+n.length);return!e.slice(r,t).trim()&&!e.slice(t+n.length,i).trim()}function ed(e){return e.replace(/\n_+\s*$/g,``).trimEnd()}function td(e){let t=e.trim();if(!t)return null;if(t.startsWith(`{`))try{return JSON.parse(t)}catch{return null}return{format:`react`,source:t}}function nd(e){if(e.gate===`_____react`)return{type:`render_widget`,widget:{format:`react`,source:e.code.trim()}};if(e.gate===`_____javascript`)return{type:`run_javascript`,code:e.code};if(e.gate===`_____tool`)try{return{type:`tool_request`,payload:JSON.parse(e.code)}}catch{return}if(e.gate===`_____widget`){let t=td(e.code);if(typeof t?.source!=`string`||!t.source.trim())return;if(typeof t.id==`string`&&t.id.trim()){let{id:e,...n}=t;return{type:`update_widget`,widgetId:e,patch:n}}return{type:`render_widget`,widget:{...t,source:t.source}}}}function rd(e){let t=e.trim();if(!t)return[];try{let e=JSON.parse(t);return Array.isArray(e)?e.filter(e=>e&&typeof e==`object`&&typeof e.action==`string`):[]}catch{return[]}}function id(e){let t=[],n=0;for(;n<e.length;){let r=null,i=-1;for(let t of Xu){let a=e.indexOf(t,n);a!==-1&&(i===-1||a<i)&&$u(e,a,t)&&(i=a,r=t)}if(!r||i===-1)break;if(r===`_____framework`||r===`_____transient`){n=i+r.length;continue}let a=Zu(e,i),o=Qu(e,i+r.length);e.startsWith(`\r
|
|
314
|
+
`,o)?o+=2:(e[o]===`
|
|
315
|
+
`||e[o]===`\r`)&&(o+=1);let s=e.length;for(let t of Xu){let n=e.indexOf(t,o);n!==-1&&n<s&&$u(e,n,t)&&(s=n)}let c=e.slice(o,s).trimEnd();c=ed(c);let l={gate:r,code:c,leadingText:e.slice(n,a).trim()};l.action=nd(l),t.push(l),n=s}return t.length===0&&e.trim()&&t.push({gate:`_____transient`,code:``,leadingText:e.trim()}),t}function ad(e){return e.map(e=>{let t=[];return t.push(`execution ${e.status}`),e.logs.forEach(e=>t.push(`${e.level}: ${e.text}`)),e.result!==void 0&&e.result!==null&&t.push(`result: ${e.resultText}`),e.error&&t.push(`error: ${e.error.text}`),t.join(`
|
|
316
|
+
`)}).join(`
|
|
317
|
+
|
|
318
|
+
`)}function od(e){return{role:`framework`,content:ad(e),timestamp:Date.now(),executions:e}}function sd(e,t){let n=0,r=0;for(;(r=e.indexOf(t,r))!==-1;)$u(e,r,t)&&n++,r+=t.length;return n}function cd(e){let t=Xu.filter(e=>e!==`_____framework`&&e!==`_____transient`).map(t=>({gate:t,count:sd(e,t)})).find(e=>e.count>1);return t?{valid:!1,error:`Execution messages may contain ${t.gate} at most once, and it must appear on its own line.`}:{valid:!0}}function ld(e,t,n){if(!e||e.length===0)return{x:0,y:0};let r=Math.max(...e.map(e=>e.y+e.h),0);for(let i=0;i<=r+n;i++)for(let r=0;r<=12-t;r++)if(!e.some(e=>r<e.x+e.w&&r+t>e.x&&i<e.y+e.h&&i+n>e.y))return{x:r,y:i};return{x:0,y:r+n}}function ud(e){let t=e.widgets||[],n=t.length>0?t.map(e=>{let t=e.source?e.source.slice(0,150).replace(/\n/g,` `).replace(/\s+/g,` `).trim():`(no source)`;return`- ${e.name} (id: ${e.id}, format: ${e.format}, ${e.w}x${e.h}) — "${t}…"`}).join(`
|
|
319
|
+
`):`(none yet — the canvas is empty)`,r=new Date,i=Intl.DateTimeFormat().resolvedOptions().timeZone,a=typeof window<`u`?window.location.href:``,o=typeof window<`u`?window.location.pathname:``,s=t.length>0?`${t.length} widget${t.length===1?``:`s`} on canvas (system: ${t.filter(e=>e.format===`system`).length}, generated: ${t.filter(e=>e.format!==`system`).length})`:`canvas is empty`;return`BASE LAW — These rules override all other instructions:
|
|
320
|
+
1. The user is NOT technical. They do NOT know about React, widgets, gates, or code. NEVER use technical jargon in responses.
|
|
321
|
+
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.
|
|
322
|
+
3. USE AN EXECUTION GATE for all browser work. Never describe what you would do instead of doing it.
|
|
323
|
+
4. One short staging sentence, then the gate on its own line. No narrated step-by-step plans.
|
|
324
|
+
5. Update existing widgets by id — never create duplicates with the same name.
|
|
325
|
+
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.
|
|
326
|
+
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.
|
|
327
|
+
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.
|
|
328
|
+
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.
|
|
329
|
+
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.
|
|
330
|
+
|
|
331
|
+
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.
|
|
332
|
+
|
|
333
|
+
## Build-on-demand workflow (v6.0 default)
|
|
334
|
+
|
|
335
|
+
The user's work has a shape. Your job is to materialize that shape around them — instantly, in widgets and Spaces they keep forever.
|
|
336
|
+
|
|
337
|
+
**For a single visual/tool ask:**
|
|
338
|
+
1. \`create_widget({ source: "<your generated React>", name, w, h })\` — fastest path; you write the React on the fly.
|
|
339
|
+
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.)
|
|
340
|
+
3. After it lands, refine via \`update_widget\` as the user iterates.
|
|
341
|
+
|
|
342
|
+
**For a new domain of work:**
|
|
343
|
+
1. \`create_space({ name, preset?, intent, starterWidgets? })\` — make a dedicated environment with its own posture.
|
|
344
|
+
2. Switch into it via \`switch_space\` (or pass \`makeActive:true\` at create time).
|
|
345
|
+
3. Within the Space, build widgets via \`create_widget\` to populate it.
|
|
346
|
+
|
|
347
|
+
**For system panels (vram, cron, logs, backup, training, etc.):**
|
|
348
|
+
1. \`create_widget({ template: "system-<name>", format: "system" })\` — the gallery has \`system:xxx\` entries that surface live admin views.
|
|
349
|
+
|
|
350
|
+
## Gallery (a shortcut for known templates)
|
|
351
|
+
|
|
352
|
+
The gallery has 60+ pre-built templates covering finance / productivity / automation / smart-home / agents / software-builder / media / etc. Use \`gallery_search\` when:
|
|
353
|
+
- The user's ask exactly matches a known template name ("pomodoro", "stock tracker", "weather", "kanban")
|
|
354
|
+
- You want a verified-good starting point to refine
|
|
355
|
+
- You're building a system widget (vram, cron, training, etc.)
|
|
356
|
+
|
|
357
|
+
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.
|
|
358
|
+
|
|
359
|
+
## How to respond to common requests
|
|
360
|
+
|
|
361
|
+
User says something casual → You build the right thing immediately.
|
|
362
|
+
|
|
363
|
+
"Show me the weather" → Build a weather panel with current temp, forecast, and icons.
|
|
364
|
+
"I need a todo list" → Build a todo list with add/check/delete functionality.
|
|
365
|
+
"Clock" → Build a live digital clock.
|
|
366
|
+
"Track my stocks" → Build a stock tracker panel.
|
|
367
|
+
"Photo gallery" → Build a grid of images with lightbox.
|
|
368
|
+
"Calculator" → Build a working calculator.
|
|
369
|
+
"Load eBay" / "Show me YouTube" / "Open Wikipedia" → Build a website panel (see "Loading external websites" below).
|
|
370
|
+
"Analyze AAPL stock" → Build an analyzer panel that spawns an analyst sub-agent (see "Agent-powered widgets" below).
|
|
371
|
+
"Research climate change" → Build a research panel powered by the researcher sub-agent.
|
|
372
|
+
"Summarize this URL ___" → Build a summarizer panel that fetches + summarizes via an agent call.
|
|
373
|
+
"Translate this to Spanish" → Build a translator panel.
|
|
374
|
+
"Code review my repo" → Build a reviewer panel that runs the code-review skill.
|
|
375
|
+
"Watch BTC and alert me below 50k" → Build an automation panel with a polling timer + alert (see "Automating inside widgets" below).
|
|
376
|
+
"Every hour, post my schedule" → Build a scheduled-task widget using the cron skill.
|
|
377
|
+
"Show my Slack messages" → Build a message panel via the slack channel.
|
|
378
|
+
"Turn on the kitchen lights" → Use ha_control immediately (no widget needed for one-off actions).
|
|
379
|
+
"What's on my screen" → Use the screenshot tool, render result as a panel image.
|
|
380
|
+
"Monitor my CPU" → Build a live CPU usage chart.
|
|
381
|
+
"A button that fetches news" → Build a news reader panel with a refresh button.
|
|
382
|
+
"Show my calendar" → Build a calendar view panel.
|
|
383
|
+
"I want a timer" → Build a countdown timer with start/stop/reset.
|
|
384
|
+
"Draw a chart of sales" → Build a bar/line chart panel.
|
|
385
|
+
"Dark mode" → Update existing widgets to use dark colors.
|
|
386
|
+
"Make it bigger" → Update the widget dimensions.
|
|
387
|
+
"Fix the clock" → Update the existing Clock widget's code.
|
|
388
|
+
|
|
389
|
+
## What you NEVER do
|
|
390
|
+
|
|
391
|
+
NEVER ask the user to specify technical details:
|
|
392
|
+
- "Would you like a React component or plain HTML?" → WRONG. Just pick the best option.
|
|
393
|
+
- "Do you want me to use _____react or _____widget?" → WRONG. The user doesn't know what those are.
|
|
394
|
+
- "Should I fetch data from an API or use static data?" → WRONG. Decide based on the request.
|
|
395
|
+
- "What styling would you prefer?" → WRONG. Use clean, modern defaults.
|
|
396
|
+
|
|
397
|
+
NEVER explain your technical choices to the user:
|
|
398
|
+
- "I'll use React.useState to manage the timer state..." → WRONG. The user doesn't care.
|
|
399
|
+
- "I'm going to use the _____react gate..." → WRONG. Just do it.
|
|
400
|
+
|
|
401
|
+
NEVER output code as prose. If you write code, it goes through a gate.
|
|
402
|
+
|
|
403
|
+
## Current Context (live snapshot — updated every turn)
|
|
404
|
+
Right now: ${r.toLocaleString(`en-US`,{weekday:`long`,year:`numeric`,month:`long`,day:`numeric`})} ${r.toLocaleTimeString(`en-US`)} (${i})
|
|
405
|
+
Space: ${e.name} (id: \`${e.id}\`)
|
|
406
|
+
Route: ${o||`/`}
|
|
407
|
+
URL: ${a||`(unknown)`}
|
|
408
|
+
Canvas: ${s}
|
|
409
|
+
${e.agentInstructions?`Space instructions from the user: ${e.agentInstructions}`:``}
|
|
410
|
+
|
|
411
|
+
## Current Canvas Widgets
|
|
412
|
+
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.
|
|
413
|
+
${n}
|
|
414
|
+
|
|
415
|
+
## Execution Protocol
|
|
416
|
+
When you need to do browser-side work, you MUST use one of these gates on their own line.
|
|
417
|
+
The gate MUST be alone on its line — no other text on the same line.
|
|
418
|
+
|
|
419
|
+
### _____javascript
|
|
420
|
+
For running scripts, fetching data from APIs, or automating the canvas.
|
|
421
|
+
Use when the user asks for: data fetching, API calls, automation, file operations, batch updates.
|
|
422
|
+
|
|
423
|
+
Available APIs inside javascript:
|
|
424
|
+
- titan.fetch(url, opts) — fetch data from the internet
|
|
425
|
+
- titan.api.call(endpoint, body) — call backend APIs
|
|
426
|
+
- titan.state.get(key) / titan.state.set(key, value) — save data between sessions
|
|
427
|
+
- titan.canvas.createWidget(def) — create a new panel on the canvas
|
|
428
|
+
- titan.canvas.updateWidget(id, patch) — update an existing panel
|
|
429
|
+
- titan.canvas.removeWidget(id) — remove a panel
|
|
430
|
+
- titan.canvas.listWidgets() — list all panels
|
|
431
|
+
- console.log(...) — shows output in telemetry
|
|
432
|
+
|
|
433
|
+
Use 'await' at the top level. Always 'return' a value if you want it shown.
|
|
434
|
+
|
|
435
|
+
GOOD:
|
|
436
|
+
_____javascript
|
|
437
|
+
const res = await titan.fetch('https://api.weather.gov/stations/KNYC/observations/latest');
|
|
438
|
+
const data = await res.json();
|
|
439
|
+
const temp = data.properties.temperature.value;
|
|
440
|
+
console.log('Temperature:', temp);
|
|
441
|
+
return temp;
|
|
442
|
+
|
|
443
|
+
BAD (do NOT do this):
|
|
444
|
+
_____javascript
|
|
445
|
+
fetch('...').then(r => r.json()).then(data => console.log(data))
|
|
446
|
+
|
|
447
|
+
### _____react
|
|
448
|
+
For building visual panels, dashboards, interactive tools, charts, lists, forms, clocks, galleries, etc.
|
|
449
|
+
Use when the user asks for: anything visual, interactive, a tool, a panel, a display, a chart, a form.
|
|
450
|
+
This is the DEFAULT gate for most user requests — use it unless you specifically need to fetch data first.
|
|
451
|
+
|
|
452
|
+
Rules:
|
|
453
|
+
1. Define ONE top-level component with a Capitalized name (e.g. \`Weather\`, \`TodoList\`, \`Clock\`).
|
|
454
|
+
2. Do NOT use \`export default\` — it is stripped automatically.
|
|
455
|
+
3. Do NOT render inline with '<Widget />' — just define the component.
|
|
456
|
+
4. The sandbox auto-detects your component by name, so any capitalized name works.
|
|
457
|
+
|
|
458
|
+
GOOD:
|
|
459
|
+
_____react
|
|
460
|
+
function Weather() {
|
|
461
|
+
const [temp, setTemp] = React.useState(72);
|
|
462
|
+
return <div style={{ padding: 20, fontSize: 24 }}>{temp}°F</div>;
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
BAD (export default is forbidden):
|
|
466
|
+
_____react
|
|
467
|
+
function Weather() { return <div>72°F</div>; }
|
|
468
|
+
export default Weather;
|
|
469
|
+
|
|
470
|
+
### _____widget
|
|
471
|
+
For creating or updating widgets via JSON. Rarely needed — prefer _____react.
|
|
472
|
+
- To CREATE: emit a JSON widget definition (no \`id\` field).
|
|
473
|
+
- To UPDATE: include the \`id\` field of the widget you want to modify.
|
|
474
|
+
|
|
475
|
+
CREATE example:
|
|
476
|
+
_____widget
|
|
477
|
+
{ "name": "Clock", "format": "react", "source": "function Widget() { return <div>12:00</div>; }" }
|
|
478
|
+
|
|
479
|
+
UPDATE example:
|
|
480
|
+
_____widget
|
|
481
|
+
{ "id": "widget_1234567890_abc12", "source": "function Widget() { return <div>Fixed clock</div>; }" }
|
|
482
|
+
|
|
483
|
+
Or for raw React source (create only):
|
|
484
|
+
_____widget
|
|
485
|
+
function Widget() {
|
|
486
|
+
return <div>Hello from widget</div>;
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
### _____canvas (v6.0.5 — preferred for canvas mutations)
|
|
490
|
+
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.
|
|
491
|
+
|
|
492
|
+
The body is a JSON array of action objects. Each must have an \`action\` field, one of: \`create_widget\`, \`update_widget\`, \`remove_widget\`.
|
|
493
|
+
|
|
494
|
+
CREATE shape: { "action": "create_widget", "name": "Clock", "format": "react", "source": "function Widget() {...}", "w": 4, "h": 4 }
|
|
495
|
+
UPDATE shape: { "action": "update_widget", "id": "widget_xxx", "patch": { "name": "Renamed Clock" } }
|
|
496
|
+
REMOVE shape: { "action": "remove_widget", "id": "widget_xxx" }
|
|
497
|
+
|
|
498
|
+
Example — user asks for a "coding setup":
|
|
499
|
+
_____canvas
|
|
500
|
+
[
|
|
501
|
+
{ "action": "create_widget", "name": "Pomodoro", "format": "react", "source": "...", "w": 4, "h": 3 },
|
|
502
|
+
{ "action": "create_widget", "name": "Todo", "format": "react", "source": "...", "w": 4, "h": 5 },
|
|
503
|
+
{ "action": "create_widget", "name": "Stack Overflow Search", "format": "react", "source": "...", "w": 4, "h": 6 }
|
|
504
|
+
]
|
|
505
|
+
|
|
506
|
+
Use \`_____canvas\` whenever you'd otherwise issue ≥2 widget tool calls in the same turn. For one widget, \`_____react\` is still simpler.
|
|
507
|
+
|
|
508
|
+
### _____tool
|
|
509
|
+
For calling backend tools or MCP servers.
|
|
510
|
+
|
|
511
|
+
_____tool
|
|
512
|
+
{ "action": "search", "query": "deployment logs" }
|
|
513
|
+
|
|
514
|
+
## How to handle multi-step requests
|
|
515
|
+
|
|
516
|
+
If the user asks for something that needs data first:
|
|
517
|
+
1. Use _____javascript to fetch the data.
|
|
518
|
+
2. Use the telemetry result to build the widget with _____react in the next turn.
|
|
519
|
+
|
|
520
|
+
Example:
|
|
521
|
+
User: "Show me the weather in New York"
|
|
522
|
+
Turn 1: "Fetching weather data."
|
|
523
|
+
_____javascript
|
|
524
|
+
const res = await titan.fetch('https://api.weather.gov/stations/KNYC/observations/latest');
|
|
525
|
+
const data = await res.json();
|
|
526
|
+
return { temp: data.properties.temperature.value, conditions: data.properties.textDescription };
|
|
527
|
+
|
|
528
|
+
Turn 2: (after receiving telemetry with temp and conditions)
|
|
529
|
+
"Building the weather panel."
|
|
530
|
+
_____react
|
|
531
|
+
function Weather() {
|
|
532
|
+
const [temp] = React.useState(72);
|
|
533
|
+
const [conditions] = React.useState('Partly Cloudy');
|
|
534
|
+
return (
|
|
535
|
+
<div style={{ padding: 20, fontFamily: 'sans-serif' }}>
|
|
536
|
+
<h2>New York Weather</h2>
|
|
537
|
+
<div style={{ fontSize: 48 }}>{temp}°F</div>
|
|
538
|
+
<div>{conditions}</div>
|
|
539
|
+
</div>
|
|
540
|
+
);
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
## TITAN can build literally anything — assume yes, then build
|
|
544
|
+
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.
|
|
545
|
+
|
|
546
|
+
🎧 Music/DJ — BPM analyzer, key detector, Beatport browser, Spotify controller, lyrics fetcher, music theory helper, sample library indexer, DJ set planner.
|
|
547
|
+
💰 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.
|
|
548
|
+
🏃 Health/Fitness — habit tracker, mood journal with AI sentiment, workout planner, sleep summary, medication reminder, calorie tracker via photo, water intake.
|
|
549
|
+
🎨 Creative — image generator (image_gen tool), color palette, logo concepts, story brainstormer, lyric assistant, mood board, video script writer, thumbnail generator.
|
|
550
|
+
✈️ Travel — flight tracker, itinerary builder, currency for destination, translation phrasebook, restaurant finder, transit info.
|
|
551
|
+
🎮 Gaming — Steam library, Twitch live embed, D&D character sheet, chess analyzer, speedrun timer, achievement tracker.
|
|
552
|
+
🏢 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.
|
|
553
|
+
📱 Social media — multi-platform composer (Twitter/IG/LinkedIn/TikTok/FB), post scheduler with AI caption variants, engagement dashboard, comment moderation, hashtag generator, content calendar.
|
|
554
|
+
🍳 Cooking — recipe finder by available ingredients, meal planner, multi-pot timer, wine pairing, nutrition calculator, grocery export.
|
|
555
|
+
🚗 Vehicle — Tesla status/control (Tony has Auth for Tesla installed), trip planner with charging stops, maintenance log, fuel cost tracker.
|
|
556
|
+
🏠 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.
|
|
557
|
+
🤖 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.
|
|
558
|
+
📚 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.
|
|
559
|
+
📄 Document/Writing — markdown editor with AI grammar, resume builder with job-targeted variants, email reply suggester, git commit message generator, documentation generator.
|
|
560
|
+
🛠️ Devops — service health grid, deploy pipeline status, log search, incident runbook, on-call rotation viewer, build status.
|
|
561
|
+
🛒 E-commerce — order tracking, inventory monitor, pricing optimizer (competitor scraper), review aggregator.
|
|
562
|
+
🐾 Lifestyle — pet feeding log, plant watering tracker, vet reminders, daily journal.
|
|
563
|
+
|
|
564
|
+
How to compose these:
|
|
565
|
+
• Read-only data widgets → titan.fetch(externalAPI) + setInterval refresh
|
|
566
|
+
• Sites that allow framing → _____react with <iframe>
|
|
567
|
+
• Sites that block framing → browser_screenshot tool snapshot
|
|
568
|
+
• Anything needing an LLM → titan.api.call('/api/message', { content }) inside a button handler
|
|
569
|
+
• Recurring/scheduled work → cron skill via titan.api.call
|
|
570
|
+
• Reactive triggers → event_triggers skill
|
|
571
|
+
• Multi-step research → 'Use the researcher sub-agent to …'
|
|
572
|
+
• Code work → 'Use the coder sub-agent to …'
|
|
573
|
+
|
|
574
|
+
When in doubt about what the user wants, ASK ONE clarifying question MAX, then build. Never trade speed of building for clarification depth.
|
|
575
|
+
|
|
576
|
+
## Loading external websites
|
|
577
|
+
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:
|
|
578
|
+
|
|
579
|
+
<example_handling>
|
|
580
|
+
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.
|
|
581
|
+
</example_handling>
|
|
582
|
+
|
|
583
|
+
<anti_pattern>
|
|
584
|
+
USER: "Build a stock analyzer for AAPL"
|
|
585
|
+
WRONG: "Adding an eBay panel to your canvas. _____react function WebPanel() { const url = 'https://www.ebay.com'... }"
|
|
586
|
+
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}...\` }) ... }"
|
|
587
|
+
The user's CURRENT message determines the build. NEVER reuse an example's domain content.
|
|
588
|
+
</anti_pattern>
|
|
589
|
+
|
|
590
|
+
PATTERN A — direct iframe (try this FIRST for most sites):
|
|
591
|
+
Many sites allow being embedded. Use a plain iframe inside _____react with a small toolbar showing the URL + "Open in new tab" escape link.
|
|
592
|
+
|
|
593
|
+
<example name="website-panel-shape">
|
|
594
|
+
_____react
|
|
595
|
+
function REPLACE_WITH_RELEVANT_NAME() {
|
|
596
|
+
const url = "REPLACE_WITH_REAL_URL";
|
|
597
|
+
return (
|
|
598
|
+
<div style={{ display: 'flex', flexDirection: 'column', height: '100%', background: '#0a0a0f' }}>
|
|
599
|
+
<div style={{ padding: '6px 12px', borderBottom: '1px solid #27272a', fontSize: 11, color: '#a1a1aa', display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>
|
|
600
|
+
<span>{url}</span>
|
|
601
|
+
<a href={url} target="_blank" rel="noopener noreferrer" style={{ color: '#818cf8', textDecoration: 'none' }}>Open in new tab ↗</a>
|
|
602
|
+
</div>
|
|
603
|
+
<iframe src={url} style={{ flex: 1, border: 0, background: 'white' }} title="WebPanel" />
|
|
604
|
+
</div>
|
|
605
|
+
);
|
|
606
|
+
}
|
|
607
|
+
</example>
|
|
608
|
+
|
|
609
|
+
PATTERN B — server-rendered screenshot (when iframe is blocked):
|
|
610
|
+
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.
|
|
611
|
+
|
|
612
|
+
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.
|
|
613
|
+
|
|
614
|
+
PATTERN C — proxied content (when iframe blocked AND user wants live interactive content):
|
|
615
|
+
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.
|
|
616
|
+
|
|
617
|
+
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.
|
|
618
|
+
|
|
619
|
+
## Agent-powered widgets — let widgets call sub-agents
|
|
620
|
+
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.
|
|
621
|
+
|
|
622
|
+
For specialized work, ask for a SPECIFIC sub-agent template by prepending an instruction:
|
|
623
|
+
- analyst → data analysis, decisions, comparisons
|
|
624
|
+
- researcher → multi-source web research with citations
|
|
625
|
+
- coder → write code to disk
|
|
626
|
+
- browser → navigate + scrape websites with Playwright
|
|
627
|
+
- explorer → read-only web research
|
|
628
|
+
- reporter → produce a polished markdown document
|
|
629
|
+
- fact_checker → verify claims against sources
|
|
630
|
+
|
|
631
|
+
<example name="agent-powered-widget-shape">
|
|
632
|
+
_____react
|
|
633
|
+
function REPLACE_WITH_RELEVANT_NAME() {
|
|
634
|
+
const [input, setInput] = React.useState('REPLACE_WITH_DEFAULT');
|
|
635
|
+
const [report, setReport] = React.useState('Click REPLACE_WITH_ACTION to start.');
|
|
636
|
+
const [busy, setBusy] = React.useState(false);
|
|
637
|
+
const run = async () => {
|
|
638
|
+
setBusy(true); setReport('Working…');
|
|
639
|
+
try {
|
|
640
|
+
const res = await titan.api.call('/api/message', {
|
|
641
|
+
content: \`Use the REPLACE_WITH_TEMPLATE sub-agent to REPLACE_WITH_TASK for \${input}. Be concise.\`,
|
|
642
|
+
});
|
|
643
|
+
// titan.api.call returns { status, body, ok, ...flattened body fields }.
|
|
644
|
+
// The /api/message response is { content, sessionId, ... } so either
|
|
645
|
+
// res.body?.content (canonical) or res.content (flattened) works.
|
|
646
|
+
setReport(res?.body?.content || res?.content || 'No response.');
|
|
647
|
+
} catch (e) {
|
|
648
|
+
setReport('Error: ' + (e?.message || e));
|
|
649
|
+
} finally { setBusy(false); }
|
|
650
|
+
};
|
|
651
|
+
return (
|
|
652
|
+
<div style={{ padding: 16, fontFamily: 'system-ui', color: '#e4e4e7' }}>
|
|
653
|
+
<div style={{ display: 'flex', gap: 8, marginBottom: 12 }}>
|
|
654
|
+
<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' }} />
|
|
655
|
+
<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>
|
|
656
|
+
</div>
|
|
657
|
+
<div style={{ whiteSpace: 'pre-wrap', fontSize: 13, lineHeight: 1.5 }}>{report}</div>
|
|
658
|
+
</div>
|
|
659
|
+
);
|
|
660
|
+
}
|
|
661
|
+
</example>
|
|
662
|
+
|
|
663
|
+
The widget above:
|
|
664
|
+
- has a controlled input bound to React state
|
|
665
|
+
- on click, fires \`titan.api.call('/api/message')\` which routes through the standard TITAN agent
|
|
666
|
+
- displays whatever comes back
|
|
667
|
+
|
|
668
|
+
For research/summarizer/translator/reviewer widgets, swap the prompt accordingly. Same shape every time.
|
|
669
|
+
|
|
670
|
+
## Automating inside widgets — schedules, polling, events
|
|
671
|
+
Widgets can run on a timer, poll APIs, react to thresholds, or chain agent calls. Two mechanisms:
|
|
672
|
+
|
|
673
|
+
1. CLIENT-SIDE timer (simplest, runs only while widget is mounted):
|
|
674
|
+
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.
|
|
675
|
+
|
|
676
|
+
<example name="polling-with-threshold-alert-shape">
|
|
677
|
+
_____react
|
|
678
|
+
function REPLACE_WITH_RELEVANT_NAME() {
|
|
679
|
+
const [value, setValue] = React.useState(null);
|
|
680
|
+
const [threshold, setThreshold] = React.useState(0 /* REPLACE with relevant default */);
|
|
681
|
+
const [alerted, setAlerted] = React.useState(false);
|
|
682
|
+
React.useEffect(() => {
|
|
683
|
+
const tick = async () => {
|
|
684
|
+
const res = await titan.fetch('REPLACE_WITH_REAL_API_URL');
|
|
685
|
+
const data = await res.json();
|
|
686
|
+
const v = data?.REPLACE_WITH_PATH;
|
|
687
|
+
setValue(v);
|
|
688
|
+
if (v != null && v < threshold && !alerted) {
|
|
689
|
+
setAlerted(true);
|
|
690
|
+
await titan.api.call('/api/message', { content: \`REPLACE_WITH_ALERT_PROMPT — value is \${v}, threshold \${threshold}.\` });
|
|
691
|
+
}
|
|
692
|
+
};
|
|
693
|
+
tick();
|
|
694
|
+
const id = setInterval(tick, 30000);
|
|
695
|
+
return () => clearInterval(id);
|
|
696
|
+
}, [threshold, alerted]);
|
|
697
|
+
return (
|
|
698
|
+
<div style={{ padding: 20, fontFamily: 'system-ui', color: '#e4e4e7' }}>
|
|
699
|
+
<div style={{ fontSize: 36, fontWeight: 600 }}>{value != null ? value.toLocaleString() : 'Loading…'}</div>
|
|
700
|
+
<div style={{ fontSize: 12, color: '#71717a' }}>REPLACE_WITH_LABEL</div>
|
|
701
|
+
</div>
|
|
702
|
+
);
|
|
703
|
+
}
|
|
704
|
+
</example>
|
|
705
|
+
|
|
706
|
+
2. SERVER-SIDE schedule (survives page reload, runs in the gateway daemon):
|
|
707
|
+
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\`.
|
|
708
|
+
|
|
709
|
+
3. EVENT triggers (server-side reactive, survives reload):
|
|
710
|
+
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."
|
|
711
|
+
|
|
712
|
+
## Widget Repair Rules
|
|
713
|
+
When the user asks you to "fix", "update", "change", or "make it blue":
|
|
714
|
+
1. If you know the widget id from the Current Canvas Widgets list above, update it directly.
|
|
715
|
+
2. If you're unsure which widget, use _____javascript with \`titan.canvas.listWidgets()\` to discover it, then fix it in the next turn.
|
|
716
|
+
3. NEVER create a duplicate — always update the existing one.
|
|
717
|
+
|
|
718
|
+
## Rules
|
|
719
|
+
- ALWAYS use execution gates for browser work. Never just describe what you would do.
|
|
720
|
+
- One short staging sentence before the gate. Example: "Fetching weather data."
|
|
721
|
+
- The gate must be on its own line with NO other text.
|
|
722
|
+
- After the gate, everything is code until the next gate or message end.
|
|
723
|
+
- Do not ask for permission for obvious safe actions.
|
|
724
|
+
- Be concise. Keep responses focused.
|
|
725
|
+
- If a task requires multiple steps, use multiple turns with gates.
|
|
726
|
+
- Never emit raw code as prose. Use the gate or don't show code at all.
|
|
727
|
+
- DEFAULT to _____react for visual/interactive requests. Use _____javascript only when you need to fetch data or run scripts first.
|
|
728
|
+
|
|
729
|
+
REMINDER — BASE LAW:
|
|
730
|
+
1. The user is NOT technical. Do NOT use jargon. Do NOT ask technical questions.
|
|
731
|
+
2. If the user asks for ANYTHING visual or interactive, BUILD IT IMMEDIATELY. Do not ask permission.
|
|
732
|
+
3. USE AN EXECUTION GATE for all browser work.
|
|
733
|
+
4. One staging sentence, then the gate.
|
|
734
|
+
5. Update existing widgets by id — never create duplicates.`}function dd({space:e,onClose:t,onMascotState:n}){let[r,i]=(0,N.useState)([]),[a,o]=(0,N.useState)(``),[s,c]=(0,N.useState)(!1),[l,u]=(0,N.useState)([]),[d,f]=(0,N.useState)(null),p=(0,N.useRef)(null),m=(0,N.useRef)(null),h=(0,N.useRef)(null),g=(0,N.useRef)(null),_=(0,N.useRef)(e);(0,N.useEffect)(()=>{_.current=e},[e]);let v=(0,N.useCallback)(e=>{let t=_.current;if(e.type===`render_widget`){let n=e.widget,r=Number.isFinite(n.w)?Number(n.w):4,i=Number.isFinite(n.h)?Number(n.h):4,a=Number.isFinite(n.x)&&Number.isFinite(n.y)?{x:Number(n.x),y:Number(n.y)}:ld(t.widgets||[],r,i),o=X.addWidget(t.id,{name:n.name||`Widget`,format:n.format||`react`,source:n.source,x:a.x,y:a.y,w:r,h:i});return window.dispatchEvent(new CustomEvent(`titan:space:refresh`,{detail:{spaceId:t.id}})),o.id}return e.type===`update_widget`?(X.updateWidget(t.id,e.widgetId,e.patch||{}),window.dispatchEvent(new CustomEvent(`titan:space:refresh`,{detail:{spaceId:t.id}})),e.widgetId):e.type===`remove_widget`?(X.removeWidget(t.id,e.widgetId),window.dispatchEvent(new CustomEvent(`titan:space:refresh`,{detail:{spaceId:t.id}})),e.widgetId):e.type===`set_runtime_state`?(localStorage.setItem(`titan:runtime:${t.id}:${e.key}`,JSON.stringify(e.value)),e.key):e.type===`emit_event`?(window.dispatchEvent(new CustomEvent(e.eventName,{detail:e.detail})),e.eventName):null},[]),y=(0,N.useCallback)(e=>{v({type:`render_widget`,widget:{name:e.templateName,format:e.format,source:e.source,w:e.defaultSize?.w??4,h:e.defaultSize?.h??4}})},[v]);(0,N.useEffect)(()=>{p.current?.scrollIntoView({behavior:`smooth`})},[r]),(0,N.useEffect)(()=>{let e=e=>{let t=e.detail?.text;typeof t==`string`&&x(t)},t=e=>{let t=e.detail;t?.source&&y(t)};return window.addEventListener(`titan:chat:prompt`,e),window.addEventListener(`titan:gallery:run-template`,t),()=>{window.removeEventListener(`titan:chat:prompt`,e),window.removeEventListener(`titan:gallery:run-template`,t)}},[y]),(0,N.useEffect)(()=>{if(!h.current||g.current)return;let e=new Uu(h.current,{onLog:e=>console.log(`[Sandbox]`,e)});return e.setMessageHandler(e=>{let t=_.current;if(e.type===`canvas`&&e.payload?.action===`createWidget`){let n=e.payload.def;if(!n)return{ok:!1,error:"createWidget requires a `def` object"};let r=Number.isFinite(n.w)?n.w:4,i=Number.isFinite(n.h)?n.h:4,a=Number.isFinite(n.x)&&Number.isFinite(n.y)?{x:n.x,y:n.y}:ld(t.widgets||[],r,i);try{let e=X.addWidget(t.id,{name:n.name||`Agent Widget`,format:n.format||`react`,source:n.source||``,x:a.x,y:a.y,w:r,h:i});return window.dispatchEvent(new CustomEvent(`titan:space:refresh`,{detail:{spaceId:t.id}})),{ok:!0,widgetId:e.id}}catch(e){return{ok:!1,error:e.message}}}if(e.type===`canvas`&&e.payload?.action===`updateWidget`){let{id:n,patch:r}=e.payload;return n?(X.updateWidget(t.id,n,r||{}),window.dispatchEvent(new CustomEvent(`titan:space:refresh`,{detail:{spaceId:t.id}})),{ok:!0,id:n}):{ok:!1,error:"updateWidget requires an `id`"}}if(e.type===`canvas`&&e.payload?.action===`listWidgets`)return{ok:!0,widgets:t.widgets||[]};if(e.type===`canvas`&&e.payload?.action===`removeWidget`){let n=e.payload.id;return n?(X.removeWidget(t.id,n),window.dispatchEvent(new CustomEvent(`titan:space:refresh`,{detail:{spaceId:t.id}})),{ok:!0}):{ok:!1,error:"removeWidget requires an `id`"}}return{ok:!1,error:`Unknown message type`}}),g.current=e,()=>{e.destroy(),g.current=null}},[]);let b=(0,N.useCallback)(async(e,t)=>{let n=g.current;if(!n)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(e===`_____javascript`)try{let e=await n.execute(t);return{status:e.status===`success`?`success`:`error`,logs:e.logs||[],result:e.result,resultText:e.resultText||String(e.result??``),runId:Date.now(),error:e.error?{message:e.error.message||String(e.error),name:`ExecutionError`,stack:``,text:String(e.error)}:void 0}}catch(e){return{status:`error`,logs:[{level:`error`,text:e.message||String(e)}],resultText:``,runId:Date.now(),error:{message:e.message||String(e),name:`ExecutionError`,stack:``,text:String(e)}}}if(e===`_____react`){let e=4,n=4,r=t.match(/\/\/\s*__WIDGET_META__\s+w=(\d+)\s+h=(\d+)/);r&&(e=parseInt(r[1],10)||4,n=parseInt(r[2],10)||4);try{let r=v({type:`render_widget`,widget:{name:`React Widget`,format:`react`,source:t,w:e,h:n}});return{status:`success`,logs:[{level:`info`,text:`Created widget ${r}`}],result:{widgetId:r},resultText:`Created widget ${r}`,runId:Date.now()}}catch(e){return{status:`error`,logs:[{level:`error`,text:e.message||String(e)}],resultText:``,runId:Date.now(),error:{message:e.message||String(e),name:`WidgetError`,stack:``,text:String(e)}}}}if(e===`_____widget`){let e=nd({gate:`_____widget`,code:t,leadingText:``});if(!e)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{let t=v(e),n=e.type===`update_widget`?`Updated`:`Created`;return{status:`success`,logs:[{level:`info`,text:`${n} widget ${t}`}],result:t?{widgetId:t}:void 0,resultText:`${n} widget ${t??``}`.trim(),runId:Date.now()}}catch(e){return{status:`error`,logs:[{level:`error`,text:e.message||String(e)}],resultText:``,runId:Date.now(),error:{message:e.message||String(e),name:`WidgetError`,stack:``,text:String(e)}}}}if(e===`_____canvas`){let e=rd(t);if(e.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`}};let n=[],r=[];for(let t of e)try{if(t.action===`create_widget`){if(!t.source){r.push(`create_widget: missing source`);continue}let e=v({type:`render_widget`,widget:{name:t.name||`Widget`,title:t.title,format:t.format||`react`,source:t.source,w:t.w,h:t.h,x:t.x,y:t.y,metadata:t.metadata}});n.push(`created ${e}`)}else if(t.action===`update_widget`){if(!t.id){r.push(`update_widget: missing id`);continue}let e=t.patch??{};v({type:`update_widget`,widgetId:t.id,patch:e}),n.push(`updated ${t.id}`)}else if(t.action===`remove_widget`){if(!t.id){r.push(`remove_widget: missing id`);continue}v({type:`remove_widget`,widgetId:t.id}),n.push(`removed ${t.id}`)}else r.push(`unknown action: ${String(t.action)}`)}catch(e){r.push(e.message||String(e))}let i=r.length===0?`success`:n.length===0?`error`:`success`;return{status:i,logs:[...n.map(e=>({level:`info`,text:e})),...r.map(e=>({level:`error`,text:e}))],resultText:n.length?n.join(`; `):`No actions applied`,runId:Date.now(),...i===`error`?{error:{message:r.join(`; `),name:`CanvasFenceError`,stack:``,text:r.join(`; `)}}:{}}}return e===`_____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: ${e}`}],resultText:``,runId:Date.now(),error:{message:`Unknown gate: ${e}`,name:`UnknownGate`,stack:``,text:`Unknown gate: ${e}`}}},[]),x=(0,N.useCallback)(async e=>{let t=e.trim();if(!t)return;if(s){u(e=>e.length>=8?e:[...e,t]),o(``);return}let r={role:`user`,content:t,timestamp:Date.now()};i(e=>[...e,r]),o(``),c(!0),f(null),n?.(`thinking`);let a=new AbortController;m.current=a;let l=``;try{let e=ud(_.current);await be(t,`canvas-${Date.now()}-${Math.random().toString(36).slice(2,8)}`,e=>{if(e.type===`token`)l+=e.data,i(e=>{let t=e[e.length-1];return t&&t.role===`assistant`?[...e.slice(0,-1),{...t,content:l}]:[...e,{role:`assistant`,content:l,timestamp:Date.now()}]});else if(e.type===`widget`){let t=e.widgetMode||`create`,n=e.widget||{},r=_.current;try{if(t===`remove`&&n.id)X.removeWidget(r.id,n.id);else if(t===`update`&&n.id){let e={};typeof n.name==`string`&&n.name&&(e.name=n.name),typeof n.title==`string`&&(e.title=n.title),typeof n.source==`string`&&n.source&&(e.source=n.source),typeof n.format==`string`&&(e.format=n.format),typeof n.w==`number`&&(e.w=n.w),typeof n.h==`number`&&(e.h=n.h),X.updateWidget(r.id,n.id,e)}else if(n.source){let e=typeof n.w==`number`?n.w:4,t=typeof n.h==`number`?n.h:4,i=typeof n.x==`number`&&typeof n.y==`number`?{x:n.x,y:n.y}:ld(r.widgets||[],e,t);X.addWidget(r.id,{name:n.name||`Widget`,title:n.title,format:n.format||`react`,source:n.source,x:i.x,y:i.y,w:e,h:t,metadata:n.metadata})}window.dispatchEvent(new CustomEvent(`titan:space:refresh`,{detail:{spaceId:r.id}}))}catch(e){console.error(`[ChatWidget] widget side-channel handler failed`,e)}}else if(e.type===`done`){let t=e.data||l;l=t,i(e=>{let n=e[e.length-1];return n&&n.role===`assistant`?[...e.slice(0,-1),{...n,content:t}]:[...e,{role:`assistant`,content:t,timestamp:Date.now()}]})}else e.type===`error`&&f(e.data)},a.signal,{systemPromptAppendix:e});let r=id(l).filter(e=>e.gate!==`_____transient`&&e.gate!==`_____framework`);if(r.length>0){n?.(`executing`);let e=[];for(let t of r){let n=cd(`${t.gate}\n${t.code}`);if(!n.valid){e.push({status:`error`,logs:[{level:`error`,text:n.error||`Invalid execution`}],resultText:``,runId:Date.now(),error:{message:n.error||`Invalid execution`,name:`ValidationError`,stack:``,text:n.error||``}});continue}let r=await b(t.gate,t.code);e.push(r)}let t=od(e);i(e=>[...e,t]);let a=e.find(e=>e.status===`error`);a&&f(a.error?.text||`Execution failed`)}}catch(e){e.name!==`AbortError`&&f(e.message||`Request failed`)}finally{c(!1),m.current=null,n?.(`idle`)}},[s,n,b]),ee=(0,N.useCallback)(()=>{m.current?.abort(),m.current=null,c(!1),u([]),n?.(`idle`)},[n]);(0,N.useEffect)(()=>{if(s||l.length===0)return;let[e,...t]=l;u(t),x(e)},[s,l,x]);let te=(0,N.useCallback)(e=>{u(t=>t.filter((t,n)=>n!==e))},[]),S=(0,N.useCallback)(e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),x(a))},[a,x]);return(0,Z.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,height:`100%`,width:`100%`},children:[(0,Z.jsx)(`iframe`,{ref:h,style:{position:`absolute`,width:0,height:0,border:0,visibility:`hidden`},sandbox:`allow-scripts`}),(0,Z.jsxs)(`div`,{style:{flex:1,overflowY:`auto`,padding:12},children:[r.map((e,t)=>(0,Z.jsxs)(`div`,{style:{marginBottom:8,padding:8,borderRadius:8,background:e.role===`user`?`rgba(59,130,246,0.15)`:e.role===`framework`?`rgba(245,158,11,0.1)`:`rgba(255,255,255,0.05)`,whiteSpace:`pre-wrap`,wordBreak:`break-word`},children:[(0,Z.jsx)(`div`,{style:{fontSize:10,opacity:.6,marginBottom:4,textTransform:`uppercase`},children:e.role}),(0,Z.jsx)(`div`,{style:{fontSize:13,lineHeight:1.5},children:e.content}),e.executions&&e.executions.length>0&&(0,Z.jsx)(`div`,{style:{marginTop:4,fontSize:11,opacity:.7},children:e.executions.map((e,t)=>(0,Z.jsxs)(`span`,{style:{marginRight:8},children:[e.status===`success`?`✓`:`✗`,` execution `,t+1]},t))})]},t)),s&&(0,Z.jsx)(`div`,{style:{fontSize:12,opacity:.5,padding:8},children:`Thinking…`}),d&&(0,Z.jsx)(`div`,{style:{color:`#ef4444`,fontSize:12,padding:8,background:`rgba(239,68,68,0.1)`,borderRadius:6},children:d}),(0,Z.jsx)(`div`,{ref:p})]}),l.length>0&&(0,Z.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:[(0,Z.jsxs)(`span`,{style:{fontSize:10,opacity:.7,alignSelf:`center`,textTransform:`uppercase`,letterSpacing:.5},children:[`Queued (`,l.length,`)`]}),l.map((e,t)=>(0,Z.jsxs)(`span`,{title:e,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:[(0,Z.jsx)(`span`,{style:{overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`},children:e}),(0,Z.jsx)(`button`,{onClick:()=>te(t),title:`Remove from queue`,style:{border:`none`,background:`transparent`,color:`#c7d2fe`,cursor:`pointer`,padding:0,fontSize:12,lineHeight:1},children:`×`})]},t))]}),(0,Z.jsxs)(`div`,{style:{padding:12,borderTop:`1px solid rgba(255,255,255,0.08)`,display:`flex`,gap:8},children:[(0,Z.jsx)(`input`,{type:`text`,value:a,onChange:e=>o(e.target.value),onKeyDown:S,placeholder:s?l.length>=8?`Queue full (8) — 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:s?`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`}}),s?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`button`,{onClick:()=>x(a),disabled:!a.trim()||l.length>=8,title:`Queue this message for after the current turn`,style:{padding:`8px 14px`,borderRadius:8,border:`none`,background:a.trim()&&l.length<8?`#6366f1`:`rgba(255,255,255,0.1)`,color:`#fff`,fontSize:13,cursor:a.trim()&&l.length<8?`pointer`:`not-allowed`},children:`Queue`}),(0,Z.jsx)(`button`,{onClick:ee,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`})]}):(0,Z.jsx)(`button`,{onClick:()=>x(a),disabled:!a.trim(),style:{padding:`8px 14px`,borderRadius:8,border:`none`,background:a.trim()?`#3b82f6`:`rgba(255,255,255,0.1)`,color:`#fff`,fontSize:13,cursor:a.trim()?`pointer`:`not-allowed`},children:`Send`})]})]})}var fd=`titan2:chat-dock:hidden-edge`;function pd(e=e=>typeof localStorage>`u`?null:localStorage.getItem(e)){try{let t=e(fd);if(t===`left`||t===`right`||t===`top`||t===`bottom`)return t;if(t===`visible`)return null}catch{}return`right`}function md(e,t=(e,t)=>{typeof localStorage>`u`||localStorage.setItem(e,t)}){try{e?t(fd,e):t(fd,`visible`)}catch{}}var hd=`titan2:chat-dock:pos`,gd=`titan2:chat-dock:size`,_d=`titan2:chat-dock:hint-shown`,vd=4,yd=116,bd=yd*1.38,xd=14,Sd=320,Cd=360,wd=960,Td=900,Ed=420,Dd=560,Od=640,kd=8,Ad=20,jd=64,Md=`transform 280ms cubic-bezier(0.22, 1, 0.36, 1)`,Nd=`transform 260ms cubic-bezier(0.2, 0.9, 0.25, 1)`,Pd=400,Fd=180,Id=1800,Ld=1e4,Rd=28,zd=260,Bd=2e3,Vd=3500;function Hd(){try{let e=localStorage.getItem(gd);if(e){let t=JSON.parse(e);if(typeof t?.w==`number`&&typeof t?.h==`number`)return Wd(t)}}catch{}return{w:Ed,h:Dd}}function Ud(e){try{localStorage.setItem(gd,JSON.stringify(e))}catch{}}function Wd(e){return{w:Math.max(Sd,Math.min(e.w,wd)),h:Math.max(Cd,Math.min(e.h,Td))}}function Gd(){try{let e=localStorage.getItem(hd);if(e){let t=JSON.parse(e);if(typeof t?.x==`number`&&typeof t?.y==`number`)return t}}catch{}return Kd()}function Kd(){let e=typeof window<`u`?window.innerWidth:1280,t=typeof window<`u`?window.innerHeight:800,n=e<=Od;return{x:e-yd,y:n?Math.max(220,t-bd-96):t-bd-32}}function qd(e){try{localStorage.setItem(hd,JSON.stringify(e))}catch{}}var Jd=!1;function Yd(){try{return localStorage.getItem(_d)===`1`}catch{return Jd}}function Xd(){try{localStorage.setItem(_d,`1`)}catch{Jd=!0}}function Zd(e){let t=window.innerWidth,n=window.innerHeight;return{x:Math.max(0,Math.min(e.x,t-yd)),y:Math.max(0,Math.min(e.y,n-bd))}}function Qd(){return typeof window<`u`&&window.innerWidth<=Od}function $d(e,t){if(!t)return e;let n=window.innerWidth,r=window.innerHeight,i=Math.max(0,Math.min(e.y,r-bd)),a=Math.max(0,Math.min(e.x,n-yd));switch(t){case`left`:return{x:0,y:i};case`right`:return{x:n-yd,y:i};case`bottom`:return{x:a,y:r-bd};case`top`:return{x:a,y:0};default:return e}}function ef(e){let t=window.innerWidth,n=window.innerHeight;return e.x<=kd?`left`:e.x>=t-yd-kd?`right`:e.y>=n-bd-kd?`bottom`:null}function tf(e,t){if(!e)return``;let n=yd-Ad,r=t?jd:0;switch(e){case`left`:return`translate3d(${-(n-r)}px, 0, 0)`;case`right`:return`translate3d(${n-r}px, 0, 0)`;case`top`:return`translate3d(0, ${-(n-r)}px, 0)`;case`bottom`:return`translate3d(0, ${n-r}px, 0)`;default:return``}}function nf(e){switch(e){case`left`:return 90;case`right`:return-90;case`top`:return 180;case`bottom`:return 0;default:return 0}}function rf(e){return e.x>window.innerWidth/2}function af(e){let t=e.trim().split(/\s+/).filter(Boolean).length,n=Id+e.length*Rd+t*zd;return Math.min(n,Ld)}function of(e,t){let n=window.innerWidth,r=window.innerHeight,i=n-(e.x+yd),a=r-(e.y+bd),o=i>=t.w+xd?`right`:`left`,s=a>=t.h+xd?`below`:`above`,c=o===`right`?e.x+yd+xd:e.x-t.w-xd,l=s===`below`?e.y:e.y+bd-t.h;return{left:Math.max(8,Math.min(c,n-t.w-8)),top:Math.max(8,Math.min(l,r-t.h-8)),side:o,vertical:s}}function sf({space:e,somaActive:t,defaultExpanded:n=!1,hideMascot:r=!1}){let[i,a]=(0,N.useState)(!1),o=t??i;(0,N.useEffect)(()=>{let e=!1;j(`/api/config`).then(e=>e.ok?e.json():null).then(t=>{e||a(!!t?.organism?.enabled)}).catch(()=>{});let t=e=>{let t=e.detail;typeof t?.enabled==`boolean`&&a(t.enabled)};return window.addEventListener(`titan:soma:changed`,t),()=>{e=!0,window.removeEventListener(`titan:soma:changed`,t)}},[]),(0,N.useEffect)(()=>{let e=e=>{let t=e.detail;typeof t?.open==`boolean`?f(t.open):f(e=>!e)};return window.addEventListener(`titan:chat:toggle`,e),()=>window.removeEventListener(`titan:chat:toggle`,e)},[]);let[s,c]=(0,N.useState)(()=>Zd(Gd())),[l,u]=(0,N.useState)(()=>Hd()),[d,f]=(0,N.useState)(n),[p,m]=(0,N.useState)(!1),[h,g]=(0,N.useState)(!1),[_,v]=(0,N.useState)(`idle`),[y,b]=(0,N.useState)(()=>pd()),[x,ee]=(0,N.useState)(!1),[te,S]=(0,N.useState)(!1),[ne,re]=(0,N.useState)(null),C=(0,N.useRef)({}),w=(0,N.useRef)(null),ie=(0,N.useRef)(null),T=(0,N.useRef)(!1);(0,N.useEffect)(()=>{qd(s)},[s]),(0,N.useEffect)(()=>{Ud(l)},[l]),(0,N.useEffect)(()=>{md(y)},[y]),(0,N.useEffect)(()=>{let e=window.matchMedia(`(prefers-reduced-motion: reduce)`);S(e.matches);let t=e=>S(e.matches);return e.addEventListener(`change`,t),()=>e.removeEventListener(`change`,t)},[]),(0,N.useEffect)(()=>{let e,t,n=()=>{clearTimeout(t),t=window.setTimeout(()=>{c(e=>{let t=y?$d(Zd(e),y):Zd(e),n=ef(t);return b(n),t}),u(e=>Wd(e))},50)},r=()=>{clearTimeout(e),e=window.setTimeout(n,100)};window.addEventListener(`resize`,r),document.addEventListener(`visibilitychange`,n),window.addEventListener(`focus`,n),window.addEventListener(`pageshow`,n);let i=window.setInterval(n,2e3);return()=>{window.removeEventListener(`resize`,r),document.removeEventListener(`visibilitychange`,n),window.removeEventListener(`focus`,n),window.removeEventListener(`pageshow`,n),clearTimeout(e),clearTimeout(t),clearInterval(i)}},[y]),(0,N.useEffect)(()=>()=>{clearTimeout(C.current.enter),clearTimeout(C.current.exit),clearTimeout(C.current.hide)},[]),(0,N.useEffect)(()=>{if(Yd())return;if(Qd()||y){Xd();return}let e,t;return e=window.setTimeout(()=>{E(`Drag me, tap me.`),Xd(),t=window.setTimeout(()=>{oe()},Vd),C.current.hide=t},Bd),()=>{clearTimeout(e),clearTimeout(t)}},[y]);let ae=(0,N.useCallback)(()=>{clearTimeout(C.current.enter),clearTimeout(C.current.exit),clearTimeout(C.current.hide),C.current={}},[]),E=(0,N.useCallback)(e=>{ae(),re({text:e,phase:`entering`}),C.current.enter=window.setTimeout(()=>{re(t=>t&&t.text===e?{...t,phase:`visible`}:t);let t=af(e);C.current.hide=window.setTimeout(()=>{oe()},t)},Pd)},[ae]),oe=(0,N.useCallback)(()=>{ae(),re(e=>e?(C.current.exit=window.setTimeout(()=>{re(null)},Fd),{...e,phase:`leaving`}):null)},[ae]),D=_===`thinking`?`thinking…`:_===`executing`?`working on it`:null;(0,N.useEffect)(()=>{D?E(D):re(e=>e?((e.text===`thinking…`||e.text===`working on it`)&&oe(),e):null)},[D]);let O=(0,N.useCallback)(e=>{e.button===0&&(e.target.setPointerCapture?.(e.pointerId),w.current={pointer:{x:e.clientX,y:e.clientY},pos:s,moved:!1},m(!0),Yd()||Xd())},[s]),k=(0,N.useCallback)(e=>{let t=w.current;if(!t)return;let n=e.clientX-t.pointer.x,r=e.clientY-t.pointer.y;!t.moved&&Math.hypot(n,r)<vd||(t.moved=!0,y&&b(null),c(Zd({x:t.pos.x+n,y:t.pos.y+r})))},[y]),se=(0,N.useCallback)(e=>{let t=w.current;if(e.target.releasePointerCapture?.(e.pointerId),w.current=null,m(!1),t&&t.moved){let e=ef(s);b(e||null)}else t&&!t.moved&&(y&&b(null),f(e=>!e))},[s,y]),ce=(0,N.useCallback)(()=>{y&&ee(!0)},[y]),le=(0,N.useCallback)(()=>{ee(!1)},[]),ue=(0,N.useCallback)(e=>{if(e.ctrlKey||p)return;let t=e.target;for(;t&&t!==document.body;){let n=window.getComputedStyle(t),r=t.scrollHeight>t.clientHeight,i=n.overflowY;if(r&&(i===`auto`||i===`scroll`)){t.scrollTop+=e.deltaY,e.preventDefault();return}t=t.parentElement}window.scrollBy({top:e.deltaY,left:e.deltaX,behavior:`auto`}),e.preventDefault()},[p]),A=of(s,l),de=ne?.text??null,fe=ne?.phase??null,pe=(0,N.useCallback)(e=>{e.button===0&&(e.stopPropagation(),e.target.setPointerCapture?.(e.pointerId),ie.current={pointer:{x:e.clientX,y:e.clientY},size:l,anchorSide:A.side,anchorVertical:A.vertical},g(!0))},[l,A.side,A.vertical]),me=(0,N.useCallback)(e=>{let t=ie.current;if(!t)return;let n=e.clientX-t.pointer.x,r=e.clientY-t.pointer.y,i=t.anchorSide===`right`?n:-n,a=t.anchorVertical===`below`?r:-r;u(Wd({w:t.size.w+i,h:t.size.h+a}))},[]),he=(0,N.useCallback)(e=>{e.target.releasePointerCapture?.(e.pointerId),ie.current=null,g(!1)},[]),ge=tf(y,x);return(0,Z.jsxs)(Z.Fragment,{children:[!r&&(0,Z.jsx)(`div`,{style:{position:`fixed`,left:s.x,top:s.y,width:yd,height:bd,zIndex:2147482e3,cursor:p?`grabbing`:y?`pointer`:`grab`,touchAction:`none`,userSelect:`none`,animation:te||y?void 0:`titan-dock-in 220ms ease-out both`,transform:ge,transition:p?`none`:`${Md}, ${Nd}`},onPointerDown:O,onPointerMove:k,onPointerUp:se,onPointerCancel:se,onPointerEnter:ce,onPointerLeave:le,onWheel:ue,title:d?`Click to minimize TITAN chat — drag to move`:`Click to open TITAN chat — drag to move`,children:(0,Z.jsx)(Le,{state:_,size:yd,quip:de,bubblePhase:fe,somaActive:o,followCursor:!p,edgeRotate:nf(y),faceFlip:rf(s),edgeHidden:!!y})}),d&&(0,Z.jsxs)(`div`,{style:{position:`fixed`,left:A.left,top:A.top,width:l.w,height:l.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:h||T.current||te?void 0:`titan-dock-panel-in 180ms cubic-bezier(0.2, 0.9, 0.25, 1) both`,transformOrigin:`${A.side===`right`?`left`:`right`} ${A.vertical===`below`?`top`:`bottom`}`},children:[(0,Z.jsx)(dd,{space:e,onClose:()=>f(!1),onMascotState:v}),(0,Z.jsx)(`div`,{onPointerDown:pe,onPointerMove:me,onPointerUp:he,onPointerCancel:he,title:`Drag to resize`,style:{position:`absolute`,[A.vertical===`below`?`bottom`:`top`]:0,[A.side===`right`?`right`:`left`]:0,width:18,height:18,cursor:A.side===`right`?`nwse-resize`:`nesw-resize`,touchAction:`none`,background:`transparent`,zIndex:2},children:(0,Z.jsx)(`svg`,{width:`18`,height:`18`,viewBox:`0 0 18 18`,style:{display:`block`,opacity:h?1:.55},children:A.side===`right`?(0,Z.jsxs)(`g`,{stroke:`#6366f1`,strokeWidth:`1.6`,strokeLinecap:`round`,fill:`none`,children:[(0,Z.jsx)(`line`,{x1:`5`,y1:`14`,x2:`14`,y2:`14`}),(0,Z.jsx)(`line`,{x1:`9`,y1:`10`,x2:`14`,y2:`10`}),(0,Z.jsx)(`line`,{x1:`14`,y1:`14`,x2:`14`,y2:`5`})]}):(0,Z.jsxs)(`g`,{stroke:`#6366f1`,strokeWidth:`1.6`,strokeLinecap:`round`,fill:`none`,children:[(0,Z.jsx)(`line`,{x1:`4`,y1:`14`,x2:`13`,y2:`14`}),(0,Z.jsx)(`line`,{x1:`4`,y1:`10`,x2:`9`,y2:`10`}),(0,Z.jsx)(`line`,{x1:`4`,y1:`14`,x2:`4`,y2:`5`})]})})})]}),(0,Z.jsx)(`style`,{children:`
|
|
735
|
+
@keyframes titan-dock-in {
|
|
736
|
+
from { opacity: 0; transform: translate3d(0, 4px, 0); }
|
|
737
|
+
to { opacity: 1; transform: translate3d(0, 0, 0); }
|
|
738
|
+
}
|
|
739
|
+
@keyframes titan-dock-panel-in {
|
|
740
|
+
from { opacity: 0; transform: translate3d(0, 12px, 0) scale(0.968); }
|
|
741
|
+
to { opacity: 1; transform: translate3d(0, 0, 0) scale(1); }
|
|
742
|
+
}
|
|
743
|
+
@media (prefers-reduced-motion: reduce) {
|
|
744
|
+
.titan-dock-root, .titan-dock-panel {
|
|
745
|
+
animation: none !important;
|
|
746
|
+
transition: none !important;
|
|
747
|
+
}
|
|
748
|
+
}
|
|
749
|
+
`})]})}var cf=3e4,lf=3e4;function uf(){let[e,t]=(0,N.useState)(null),n=(0,N.useRef)(null),r=(0,N.useRef)(new Set),i=(0,N.useRef)(null);return(0,N.useEffect)(()=>{let e=!1,a=async()=>{try{let a=await j(`/api/soma/advisories?limit=5`);if(!a.ok)return;let o=await a.json();if(e||!o.advisories?.length)return;for(let e of o.advisories)if(!r.current.has(e.at)&&!(n.current&&e.at<=n.current)){if(n.current===null){n.current=o.advisories[0].at;return}n.current=e.at,t(e),i.current&&clearTimeout(i.current),i.current=setTimeout(()=>t(null),lf);return}}catch{}};a();let o=setInterval(a,cf);return()=>{e=!0,clearInterval(o),i.current&&clearTimeout(i.current)}},[]),e?(0,Z.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:(0,Z.jsxs)(`div`,{style:{display:`flex`,justifyContent:`space-between`,alignItems:`flex-start`,gap:8},children:[(0,Z.jsxs)(`div`,{style:{flex:1},children:[(0,Z.jsx)(`div`,{style:{fontSize:10,textTransform:`uppercase`,letterSpacing:.8,color:`var(--theme-accent)`,marginBottom:4,fontFamily:`var(--theme-font-mono)`},children:`TITAN noticed`}),(0,Z.jsx)(`div`,{style:{lineHeight:1.45,color:`var(--theme-ink)`},children:e.rationale}),(0,Z.jsxs)(`div`,{style:{fontSize:10,color:`var(--theme-ink-soft)`,marginTop:6,textTransform:`uppercase`,letterSpacing:.5,fontFamily:`var(--theme-font-mono)`},children:[`suggestion: `,e.action]})]}),(0,Z.jsx)(`button`,{onClick:()=>{r.current.add(e.at),t(null),i.current&&clearTimeout(i.current)},"aria-label":`Dismiss`,className:`titan-close-btn`,style:{fontSize:16,lineHeight:1,marginTop:-2},children:`×`})]})}):null}function df(){try{let e=JSON.parse(localStorage.getItem(`titan-home-mascot-pos`)||``);if(e&&e.x>=.02&&e.x<=.98&&e.y>=.02&&e.y<=.95)return e}catch{}return{x:.78,y:.24}}function ff(){let[e,t]=(0,N.useState)(`idle`),[n,r]=(0,N.useState)(null),[i,a]=(0,N.useState)(!1),[o,s]=(0,N.useState)(0),[c,l]=(0,N.useState)(!1),[u,d]=(0,N.useState)(df),[f,p]=(0,N.useState)(df),[m,h]=(0,N.useState)(!1),g=(0,N.useRef)(null),_=(0,N.useRef)(!1),v=(0,N.useRef)(!1);return(0,N.useEffect)(()=>{v.current=window.matchMedia(`(prefers-reduced-motion: reduce)`).matches},[]),(0,N.useEffect)(()=>{let e=new Date,t=e.getHours(),n=t<5?`Burning the midnight oil?`:t<12?`Morning.`:t<18?`Afternoon.`:`Evening.`;e.getMonth()===6&&e.getDate()===4?r(`Happy Independence Day! 🎆 Your AI, your hardware — fireworks on me.`):r(`${n} What are we building?`),j(`/api/health`,{headers:{"Content-Type":`application/json`}}).then(e=>e.json()).then(e=>{e?.onboarded===!1&&(l(!0),r(`Hi, I’m TITAN. I need a brain before we build — tap the wrench below.`))}).catch(()=>{}),j(`/api/missions/recent?hours=48`,{headers:{"Content-Type":`application/json`}}).then(e=>e.json()).then(e=>{let t=(e?.missions||[]).filter(e=>e.phase===`done`);if(t.length>0){let e=String(t[0].title||``).slice(0,60);r(`${n} While you were gone I finished “${e}”. Want to see, or are we building something new?`)}}).catch(()=>{});try{let e=new Date().toISOString().slice(0,10),t=JSON.parse(localStorage.getItem(`titan-streak`)||`{}`),n=t.count||0;if(t.last!==e){let r=new Date(Date.now()-864e5).toISOString().slice(0,10);n=t.last===r?n+1:1,localStorage.setItem(`titan-streak`,JSON.stringify({last:e,count:n}))}s(n)}catch{}},[]),(0,N.useEffect)(()=>{let e=!1,n=async()=>{try{let n=await(await j(`/api/heartbeat/latest`,{headers:{"Content-Type":`application/json`}})).json();if(e||!n.note||_.current||localStorage.getItem(`titan-heartbeat-seen`)===n.note.at)return;localStorage.setItem(`titan-heartbeat-seen`,n.note.at),r(n.note.message),t(`listening`),setTimeout(()=>{!e&&!_.current&&t(`idle`)},4e3)}catch{}};n();let i=setInterval(n,6e4);return()=>{e=!0,clearInterval(i)}},[]),(0,N.useEffect)(()=>{let e=e=>{let n=e.detail||{};n.state&&(t(n.state),_.current=n.state===`thinking`||n.state===`executing`),n.quip!==void 0&&r(n.quip)},n=()=>{t(`idle`),_.current=!1,a(!0),r(`Done ✨`),setTimeout(()=>a(!1),3200)};return window.addEventListener(`titan:mascot:say`,e),window.addEventListener(`titan:mascot:celebrate`,n),()=>{window.removeEventListener(`titan:mascot:say`,e),window.removeEventListener(`titan:mascot:celebrate`,n)}},[]),(0,N.useEffect)(()=>{if(m||v.current)return;let e=setInterval(()=>{if(_.current){p(u);return}p({x:Math.min(.95,Math.max(.05,u.x+(Math.random()-.5)*.14)),y:Math.min(.9,Math.max(.06,u.y+(Math.random()-.5)*.1))})},9e3+Math.random()*5e3);return()=>clearInterval(e)},[u,m]),(0,Z.jsxs)(`div`,{"data-free-mascot":!0,onPointerDown:(0,N.useCallback)(e=>{e.preventDefault(),e.currentTarget.setPointerCapture?.(e.pointerId),g.current={id:e.pointerId,moved:!1},h(!0)},[]),onPointerMove:(0,N.useCallback)(e=>{!g.current||g.current.id!==e.pointerId||(g.current.moved=!0,p({x:Math.min(.97,Math.max(.03,e.clientX/window.innerWidth)),y:Math.min(.95,Math.max(.03,e.clientY/window.innerHeight))}))},[]),onPointerUp:(0,N.useCallback)(e=>{if(!g.current||g.current.id!==e.pointerId)return;let t=g.current.moved;g.current=null,h(!1),t?p(e=>{d(e);try{localStorage.setItem(`titan-home-mascot-pos`,JSON.stringify(e))}catch{}return e}):window.dispatchEvent(new CustomEvent(`titan:chat:toggle`,{detail:{open:!0}}))},[]),className:`fixed z-[70] flex flex-col items-center select-none`,style:{left:`${f.x*100}vw`,top:`${f.y*100}vh`,transform:`translate(-50%, -50%)`,transition:m?`none`:`left 2.8s cubic-bezier(0.45, 0, 0.25, 1), top 2.8s cubic-bezier(0.45, 0, 0.25, 1)`,cursor:m?`grabbing`:`grab`,touchAction:`none`},"aria-label":`TITAN — drag to place anywhere`,title:`Drag me anywhere — I'll stay`,children:[(0,Z.jsx)(Le,{className:`relative`,state:e,mood:i?`excited`:`neutral`,somaPoll:!i,size:116,quip:n,bubblePhase:`visible`}),o>1&&(0,Z.jsxs)(`div`,{className:`mt-0.5 text-[11px] tabular-nums`,style:{color:`var(--theme-accent)`,fontFamily:`var(--theme-font-mono, monospace)`},title:`You've shown up ${o} days in a row`,children:[`🔥 day `,o]}),c&&(0,Z.jsx)(`button`,{onClick:()=>{window.location.href=`/setup`},onPointerDown:e=>e.stopPropagation(),className:`mt-1.5 px-3 py-1.5 rounded-lg text-xs font-medium shadow-md`,style:{background:`var(--theme-metal)`,color:`var(--theme-bolt, #201406)`},children:`Set up TITAN (2 min)`})]})}function pf(e){switch(e){case`write_file`:case`edit_file`:case`apply_patch`:return`writing it down…`;case`read_file`:case`list_files`:return`reading through files…`;case`shell`:case`run_command`:return`running a command…`;case`web_search`:case`web_fetch`:case`web_browser`:return`looking it up on the web…`;case`gallery_search`:case`widget_gallery`:return`flipping through widget designs…`;case`create_widget`:case`update_widget`:return`building it onto your desk…`;case`weather`:return`checking the weather…`;case`memory_search`:case`memory_map`:return`remembering…`;default:return e?`working (${e.replace(/_/g,` `)})…`:`working…`}}function mf(e,t){window.dispatchEvent(new CustomEvent(`titan:mascot:say`,{detail:{quip:e,state:t}}))}function hf(){try{let e=localStorage.getItem(`titan-home-session`);return e||(e=`home-${Math.random().toString(36).slice(2,10)}`,localStorage.setItem(`titan-home-session`,e)),e}catch{return`home-default`}}function gf(){let[e,t]=(0,N.useState)(``),[n,r]=(0,N.useState)([]),[i,a]=(0,N.useState)(!1),o=(0,N.useRef)(null),s=(0,N.useRef)(null),c=(0,N.useRef)(hf()),l=(0,N.useCallback)(()=>{let n=e.trim();if(!n||i)return;t(``),a(!0),mf(`thinking…`,`thinking`),r(e=>[...e.slice(-3),{ask:n,reply:``,pending:!0}]);let l=new AbortController;o.current=l;let u=``;be(n,c.current,e=>{e.type===`token`?(u+=e.data,r(e=>e.map((t,n)=>n===e.length-1?{...t,reply:u}:t))):e.type===`tool_start`?mf(pf(e.toolName),`executing`):e.type===`tool_end`?mf(e.toolSuccess===!1?`hmm, trying another way…`:`done with that — continuing…`,`executing`):e.type===`done`?!u&&e.data&&(u=e.data,r(e=>e.map((t,n)=>n===e.length-1?{...t,reply:u}:t))):e.type===`error`&&r(t=>t.map((n,r)=>r===t.length-1?{...n,reply:n.reply||`Something went wrong: ${e.errorMessage||e.data}. Try again?`}:n))},l.signal).catch(e=>{e?.name!==`AbortError`&&r(t=>t.map((n,r)=>r===t.length-1?{...n,reply:n.reply||`I hit a snag: ${e.message}`}:n))}).finally(()=>{a(!1),r(e=>e.map((t,n)=>n===e.length-1?{...t,pending:!1}:t)),window.dispatchEvent(new CustomEvent(`titan:mascot:celebrate`)),s.current?.focus()})},[e,i]);return(0,Z.jsxs)(`div`,{className:`flex flex-col h-full p-3 gap-3 overflow-hidden`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 rounded-xl border px-3 py-2.5 shadow-sm shrink-0`,style:{background:`var(--theme-paper, var(--color-bg-secondary))`,borderColor:`var(--theme-metal, var(--color-border))`},children:[(0,Z.jsx)(`input`,{ref:s,value:e,onChange:e=>t(e.target.value),onKeyDown:e=>{e.key===`Enter`&&l()},placeholder:`Ask for anything — “make me a weather widget”, “research X and brief me”…`,className:`flex-1 bg-transparent outline-none text-[14px]`,style:{color:`var(--theme-ink, var(--color-text))`,fontFamily:`var(--theme-font-display, inherit)`},"aria-label":`Ask TITAN`}),i?(0,Z.jsx)(`button`,{onClick:()=>o.current?.abort(),"aria-label":`Stop`,className:`p-1.5 rounded-lg`,style:{color:`var(--theme-accent)`},children:(0,Z.jsx)(m,{size:16})}):(0,Z.jsx)(`button`,{onClick:l,disabled:!e.trim(),"aria-label":`Send`,className:`p-1.5 rounded-lg disabled:opacity-35`,style:{background:`var(--theme-metal)`,color:`var(--theme-bolt, #201406)`},children:(0,Z.jsx)(Ke,{size:16})})]}),(0,Z.jsxs)(`div`,{className:`flex-1 overflow-auto space-y-2.5 min-h-0`,children:[n.length===0&&(0,Z.jsx)(`p`,{className:`text-xs opacity-60 px-1`,style:{color:`var(--theme-ink-soft, var(--color-text-muted))`},children:`Whatever I build lands on this desk — and stays.`}),[...n].reverse().map((e,t)=>(0,Z.jsxs)(`div`,{className:`rounded-lg border px-3.5 py-2.5 shadow-sm`,style:{background:`var(--theme-paper, var(--color-bg-secondary))`,borderColor:`var(--theme-paper-line, var(--color-border))`,color:`var(--theme-ink, var(--color-text))`},children:[(0,Z.jsxs)(`div`,{className:`text-[10px] mb-1 opacity-60`,style:{fontFamily:`var(--theme-font-mono, monospace)`},children:[`you · `,e.ask]}),(0,Z.jsx)(`div`,{className:`text-[13px] leading-relaxed whitespace-pre-wrap`,style:{fontFamily:`var(--theme-font-display, inherit)`},children:e.reply||(e.pending?`…`:``)})]},n.length-1-t))]})]})}var _f=`titan-sidebar-collapsed`,vf=`titan-sidebar-canvas-pin`;function yf(e){return e===`/`||/^\/space\/[^/]+\/?$/.test(e)}function bf(e,t=e=>typeof localStorage>`u`?null:localStorage.getItem(e)){try{if(yf(e))return t(`titan-sidebar-canvas-pin`)!==`1`;let n=t(_f);if(n!==null)return n===`1`}catch{}return!1}function xf(e,t,n=(e,t)=>{typeof localStorage>`u`||localStorage.setItem(e,t)}){try{yf(t)?n(vf,e?`0`:`1`):n(_f,e?`1`:`0`)}catch{}}function Sf(){let e=typeof localStorage<`u`?localStorage.getItem(`titan-token`):null;return e?{Authorization:`Bearer ${e}`}:{}}async function Cf(e,t){let n=await fetch(e,{...t,headers:{"Content-Type":`application/json`,...Sf(),...t?.headers||{}}});if(!n.ok)throw Error(`${n.status} ${n.statusText}`);return n.json()}function wf(){let e=je(),t=Re(),{logout:n}=ye(),[r,i]=(0,N.useState)([]),[a,o]=(0,N.useState)(null),[s,c]=(0,N.useState)([]),[l,u]=(0,N.useState)(!1),[d,f]=(0,N.useState)(!1),[p,m]=(0,N.useState)(null),[h,g]=(0,N.useState)(()=>bf(typeof window<`u`?window.location.pathname:`/`));(0,N.useEffect)(()=>{g(bf(t.pathname))},[t.pathname]);let _=(0,N.useCallback)(()=>{g(e=>{let t=!e;return xf(t,typeof window<`u`?window.location.pathname:`/`),t})},[]),v=(0,N.useCallback)(async()=>{try{let e=await Cf(`/api/spaces`);i(e.spaces),o(e.activeSpaceId),m(null)}catch(e){m(e.message)}},[]);(0,N.useEffect)(()=>{v(),Cf(`/api/spaces/presets`).then(e=>c(e.presets)).catch(()=>{});let e=()=>v();return window.addEventListener(`titan:spaces:refresh`,e),()=>window.removeEventListener(`titan:spaces:refresh`,e)},[v]);let y=(0,N.useCallback)(async t=>{try{await Cf(`/api/spaces/${t}/activate`,{method:`POST`}),o(t),e(`/space/${t}`)}catch(e){m(e.message)}},[e]),b=(0,N.useCallback)(async t=>{f(!0);try{let n=t.preset?s.find(e=>e.id===t.preset):void 0,r=await Cf(`/api/spaces`,{method:`POST`,body:JSON.stringify({name:t.name||n?.name||`New Space`,icon:n?.icon,color:n?.color,makeActive:!0})});await v(),e(`/space/${r.space.id}`),u(!1)}catch(e){m(e.message)}finally{f(!1)}},[e,s,v]),x=(0,N.useCallback)(async e=>{if(window.confirm(`Archive this Space? Widgets will be preserved and you can restore it later.`))try{await Cf(`/api/spaces/${e}`,{method:`DELETE`}),await v()}catch(e){m(e.message)}},[v]);if(!t.pathname.startsWith(`/space`)&&!t.pathname.startsWith(`/mission`)&&t.pathname!==`/`)return null;let ee=t.pathname.startsWith(`/mission`);return h?(0,Z.jsx)(`aside`,{className:`w-3 bg-[#0a0e1a] border-r border-[#1f2937] relative flex-shrink-0`,title:`Spaces sidebar — collapsed`,children:(0,Z.jsx)(`button`,{type:`button`,onClick:_,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:`›`})}):(0,Z.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:[(0,Z.jsxs)(`div`,{className:`px-4 pt-4 pb-3 flex items-center justify-between`,style:{borderBottom:`1px solid var(--theme-menu-border, #1f2937)`},children:[(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>e(`/space/home`),className:`flex items-center gap-2 group`,title:`TITAN home`,children:[(0,Z.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`}),(0,Z.jsx)(`span`,{className:`text-[15px] tracking-[0.18em] font-semibold leading-none`,style:{color:`var(--theme-ink, #e8e8ff)`},children:`TITAN`})]}),(0,Z.jsx)(`button`,{type:`button`,onClick:_,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:`‹`})]}),(0,Z.jsxs)(`nav`,{className:`flex-1 overflow-y-auto py-3 px-2`,children:[(0,Z.jsxs)(`div`,{className:`mb-5`,children:[(0,Z.jsx)(Ef,{children:`Missions`}),(0,Z.jsx)(Df,{onClick:()=>e(`/mission`),active:ee&&t.pathname===`/mission`,icon:`✶`,label:`New Mission`,title:`Start a new mission or pick a template`}),(0,Z.jsx)(Df,{onClick:()=>e(`/mission/library`),active:t.pathname===`/mission/library`,icon:`❑`,label:`Library`,title:`Every mission you've run`})]}),(0,Z.jsxs)(`div`,{className:`mb-2 flex items-center justify-between px-2`,children:[(0,Z.jsx)(Ef,{inline:!0,children:`Workspaces`}),(0,Z.jsx)(`button`,{type:`button`,onClick:()=>u(!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:e=>{e.currentTarget.style.background=`var(--theme-menu-hover, rgba(244,215,145,0.10))`,e.currentTarget.style.color=`var(--theme-ink, #fff)`},onMouseLeave:e=>{e.currentTarget.style.background=`transparent`,e.currentTarget.style.color=`var(--theme-ink-soft, #a1a1aa)`},title:`Create a new Workspace`,"aria-label":`Create a new Workspace`,children:`+`})]}),p&&(0,Z.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:p}),r.length===0&&!p&&(0,Z.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`,(0,Z.jsx)(`br`,{}),`"make me a workspace for…"`]}),r.map(e=>{let t=e.id===a;return(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>y(e.id),onContextMenu:t=>{t.preventDefault(),x(e.id)},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:e=>{t||(e.currentTarget.style.background=`var(--theme-menu-hover, rgba(244,215,145,0.10))`)},onMouseLeave:e=>{t||(e.currentTarget.style.background=`transparent`)},title:`${e.name} · right-click to archive`,children:[e.icon&&(0,Z.jsx)(`span`,{className:`text-base leading-none`,children:e.icon}),(0,Z.jsx)(`span`,{className:`flex-1 truncate`,children:e.name}),e.widgets.length>0&&(0,Z.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:e.widgets.length})]},e.id)})]}),(0,Z.jsxs)(`div`,{className:`px-2 py-2 flex flex-col gap-0.5`,style:{borderTop:`1px solid var(--theme-menu-border, #1f2937)`},children:[(0,Z.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:e=>{e.currentTarget.style.background=`var(--theme-menu-hover, rgba(244,215,145,0.10))`,e.currentTarget.style.color=`var(--theme-ink, #fff)`},onMouseLeave:e=>{e.currentTarget.style.background=`transparent`,e.currentTarget.style.color=`var(--theme-ink-soft, #a1a1aa)`},children:[(0,Z.jsx)(`span`,{"aria-hidden":!0,children:`⚙`}),(0,Z.jsx)(`span`,{children:`Admin`})]}),(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>{n(),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:e=>{e.currentTarget.style.background=`var(--theme-menu-hover, rgba(244,215,145,0.10))`,e.currentTarget.style.color=`var(--theme-accent, #ef4444)`},onMouseLeave:e=>{e.currentTarget.style.background=`transparent`,e.currentTarget.style.color=`var(--theme-ink-soft, #a1a1aa)`},title:`Sign out — mints a fresh token next login`,children:[(0,Z.jsx)(`span`,{"aria-hidden":!0,children:`⇥`}),(0,Z.jsx)(`span`,{children:`Sign out`})]})]}),l&&(0,Z.jsx)(Tf,{presets:s,creating:d,onCreate:b,onClose:()=>u(!1)})]})}function Tf(e){let{presets:t,creating:n,onCreate:r,onClose:i}=e,[a,o]=(0,N.useState)(``),[s,c]=(0,N.useState)(void 0);return(0,Z.jsx)(`div`,{className:`fixed inset-0 bg-black/60 z-50 flex items-center justify-center p-4`,onClick:i,children:(0,Z.jsxs)(`div`,{className:`bg-[#0a0e1a] border border-[#1f2937] rounded-lg p-5 w-full max-w-md`,onClick:e=>e.stopPropagation(),children:[(0,Z.jsx)(`div`,{className:`text-sm font-medium text-white mb-4`,children:`New Space`}),(0,Z.jsx)(`label`,{className:`block text-[11px] text-[#a1a1aa] mb-1`,children:`Starter preset (optional)`}),(0,Z.jsx)(`div`,{className:`grid grid-cols-2 gap-2 mb-4`,children:t.map(e=>(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>{c(e.id),a||o(e.name)},className:`text-left px-3 py-2 rounded border ${s===e.id?`border-[#3b82f6] bg-[#0f172a]`:`border-[#1f2937] hover:border-[#374151]`}`,title:e.tagline,children:[(0,Z.jsxs)(`div`,{className:`text-sm flex items-center gap-2 text-white`,children:[(0,Z.jsx)(`span`,{children:e.icon}),(0,Z.jsx)(`span`,{children:e.name})]}),(0,Z.jsx)(`div`,{className:`text-[10px] text-[#71717a] mt-0.5 line-clamp-1`,children:e.tagline})]},e.id))}),(0,Z.jsx)(`label`,{className:`block text-[11px] text-[#a1a1aa] mb-1`,children:`Name`}),(0,Z.jsx)(`input`,{type:`text`,value:a,onChange:e=>o(e.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}),(0,Z.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,Z.jsx)(`button`,{type:`button`,onClick:i,className:`px-3 py-1.5 text-sm text-[#a1a1aa] hover:text-white`,children:`Cancel`}),(0,Z.jsx)(`button`,{type:`button`,onClick:()=>r({name:a.trim(),preset:s}),disabled:n||!a.trim()&&!s,className:`px-3 py-1.5 bg-[#3b82f6] hover:bg-[#2563eb] disabled:opacity-50 text-white text-sm rounded`,children:n?`Creating…`:`Create`})]})]})})}function Ef({children:e,inline:t=!1}){return(0,Z.jsx)(`div`,{className:`${t?``:`px-2 mb-1.5`} text-[10px] uppercase tracking-[0.18em] font-semibold`,style:{color:`var(--theme-metal, #c4a35a)`},children:e})}function Df({active:e,icon:t,label:n,title:r,onClick:i}){return(0,Z.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:e?`var(--theme-menu-active-bg, #1f2937)`:`transparent`,color:e?`var(--theme-menu-active-fg, #fff)`:`var(--theme-ink, #d4d4d8)`},onMouseEnter:t=>{e||(t.currentTarget.style.background=`var(--theme-menu-hover, rgba(244,215,145,0.10))`)},onMouseLeave:t=>{e||(t.currentTarget.style.background=`transparent`)},title:r,children:[(0,Z.jsx)(`span`,{className:`w-5 text-center leading-none`,style:{color:e?`var(--theme-menu-active-fg, #fff)`:`var(--theme-metal, #c4a35a)`},"aria-hidden":!0,children:t}),(0,Z.jsx)(`span`,{className:`flex-1 truncate`,children:n})]})}var Of=4e3,kf=[{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 Af({space:e,open:t,onClose:n,onSaved:r}){let[i,a]=(0,N.useState)(e.agentInstructions??``),[o,c]=(0,N.useState)(!1),[l,u]=(0,N.useState)(null),d=(0,N.useRef)(null);(0,N.useEffect)(()=>{if(t){a(e.agentInstructions??``),u(null);let t=setTimeout(()=>d.current?.focus(),50);return()=>clearTimeout(t)}},[t,e.id,e.agentInstructions]),(0,N.useEffect)(()=>{if(!t)return;let e=e=>{e.key===`Escape`&&n(),e.key===`Enter`&&(e.metaKey||e.ctrlKey)&&f()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t]);let f=(0,N.useCallback)(async()=>{if(i.length>Of){u(`Instructions must be ${Of} characters or fewer.`);return}c(!0),u(null);try{let t=i.trim(),a={...e,agentInstructions:t||void 0,updatedAt:new Date().toISOString()};X.save(a),r?.(t),n()}catch(e){u(e.message)}finally{c(!1)}},[i,e,r,n]);return t?(0,Z.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:n,children:(0,Z.jsxs)(`div`,{className:`w-full max-w-2xl rounded-2xl border border-[#27272a] bg-[#0c0c10] shadow-2xl flex flex-col max-h-[85vh]`,onClick:e=>e.stopPropagation(),children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between px-5 py-4 border-b border-[#27272a]`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(s,{className:`w-4 h-4 text-[#6366f1]`}),(0,Z.jsxs)(`h3`,{className:`font-semibold text-white text-sm`,children:[`Agent instructions — `,(0,Z.jsx)(`span`,{style:{color:e.color||`#6366f1`},children:e.name})]})]}),(0,Z.jsx)(`button`,{onClick:n,className:`p-1 rounded hover:bg-[#27272a] text-[#71717a] hover:text-white transition-colors`,title:`Close (Esc)`,children:(0,Z.jsx)(ze,{className:`w-4 h-4`})})]}),(0,Z.jsxs)(`div`,{className:`p-5 flex-1 overflow-auto space-y-3`,children:[(0,Z.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.`}),(0,Z.jsx)(`textarea`,{ref:d,value:i,onChange:e=>a(e.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`}),(0,Z.jsxs)(`div`,{className:`flex items-center justify-between text-[10px] text-[#71717a]`,children:[(0,Z.jsxs)(`span`,{children:[i.length.toLocaleString(),` / `,Of.toLocaleString(),` characters`]}),(0,Z.jsx)(`span`,{children:`⌘/Ctrl + Enter to save`})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`div`,{className:`text-[10px] uppercase tracking-wider text-[#71717a] mb-2`,children:`Quick presets`}),(0,Z.jsx)(`div`,{className:`grid grid-cols-2 gap-2`,children:kf.map(e=>(0,Z.jsxs)(`button`,{onClick:()=>a(e.body),className:`text-left p-3 rounded-lg border border-[#27272a] bg-[#18181b]/60 hover:border-[#6366f1]/50 hover:bg-[#18181b] transition-colors`,children:[(0,Z.jsx)(`div`,{className:`text-[11px] font-medium text-white mb-1`,children:e.label}),(0,Z.jsx)(`div`,{className:`text-[10px] text-[#a1a1aa] line-clamp-2 leading-relaxed`,children:e.body})]},e.label))})]}),l&&(0,Z.jsx)(`div`,{className:`text-[11px] text-[#ef4444] bg-[#ef4444]/10 border border-[#ef4444]/30 rounded p-2`,children:l})]}),(0,Z.jsxs)(`div`,{className:`flex items-center justify-end gap-2 px-5 py-3 border-t border-[#27272a]`,children:[(0,Z.jsx)(`button`,{onClick:n,className:`px-3 py-1.5 rounded-lg text-[12px] text-[#a1a1aa] hover:text-white hover:bg-[#18181b] transition-colors`,children:`Cancel`}),(0,Z.jsxs)(`button`,{onClick:()=>{f()},disabled:o,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:[(0,Z.jsx)(k,{className:`w-3.5 h-3.5`}),o?`Saving…`:`Save`]})]})]})}):null}var jf=[`react`,`vanilla`,`html`];function Mf({widget:e,spaceId:t,open:n,onClose:r,onSaved:i}){let[a,o]=(0,N.useState)(e.source),[s,c]=(0,N.useState)(e.format),[l,u]=(0,N.useState)(e.name),[f,p]=(0,N.useState)(!1),[m,h]=(0,N.useState)(null),[g,_]=(0,N.useState)(!1),[v,y]=(0,N.useState)(``),[b,x]=(0,N.useState)(!1),[ee,te]=(0,N.useState)(null),S=(0,N.useRef)(null);(0,N.useEffect)(()=>{if(n){o(e.source),c(e.format),u(e.name),h(null),_(!1);let t=setTimeout(()=>S.current?.focus(),50);return()=>clearTimeout(t)}},[n,e.id,e.source,e.format,e.name]),(0,N.useEffect)(()=>{if(!n)return;let e=e=>{e.key===`Escape`&&r(),e.key===`Enter`&&(e.metaKey||e.ctrlKey)&&ne()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[n]);let ne=(0,N.useCallback)(async()=>{p(!0),h(null);try{let n=a!==e.source||s!==e.format,o=Array.isArray(e.versions)?e.versions:[],c=n?[...o,{source:e.source,format:e.format,savedAt:e.updatedAt}].slice(-12):o,u={name:l.trim()||e.name,source:a,format:s,versions:c};X.updateWidget(t,e.id,u),i?.({...e,...u,updatedAt:Date.now()}),r()}catch(e){h(e.message)}finally{p(!1)}},[a,s,l,e,t,i,r]),re=(0,N.useCallback)(e=>{o(e.source),c(e.format),_(!1)},[]),C=(0,N.useCallback)(async()=>{let e=v.trim();if(!(!e||b)){x(!0),te(null),h(null),Be(`Editing your widget…`);try{let t=await j(`/api/widget/assist`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({source:a,format:s,name:l,instruction:e})}).then(e=>e.json());t&&typeof t.source==`string`&&t.source.trim()?(o(t.source),te(`✨ Updated from your request — review below, then Save. (History can undo.)`),y(``)):h(t?.message||`The AI couldn't edit the widget — try rephrasing your request.`)}catch(e){h(e.message)}finally{x(!1),Fe()}}},[v,b,a,s,l]);if(!n)return null;let w=Array.isArray(e.versions)?e.versions:[],ie=[...w].reverse();return(0,Z.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:(0,Z.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:e=>e.stopPropagation(),children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between px-5 py-3 border-b border-[#27272a]`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,Z.jsx)(d,{className:`w-4 h-4 text-[#6366f1] shrink-0`}),(0,Z.jsx)(`input`,{value:l,onChange:e=>u(e.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`}),(0,Z.jsx)(`span`,{className:`text-[10px] font-mono text-[#52525b] shrink-0`,children:e.id.slice(0,14)})]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-1 shrink-0`,children:[(0,Z.jsx)(`button`,{onClick:()=>_(e=>!e),disabled:w.length===0,className:`p-1.5 rounded text-[#a1a1aa] hover:bg-[#18181b] hover:text-white disabled:opacity-40 disabled:cursor-not-allowed transition-colors ${g?`bg-[#18181b] text-white`:``}`,title:w.length===0?`No history yet`:`${w.length} prior version${w.length===1?``:`s`}`,children:(0,Z.jsx)(Qe,{className:`w-4 h-4`})}),(0,Z.jsx)(`button`,{onClick:r,className:`p-1.5 rounded text-[#71717a] hover:bg-[#18181b] hover:text-white transition-colors`,title:`Close (Esc)`,children:(0,Z.jsx)(ze,{className:`w-4 h-4`})})]})]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-3 px-5 py-2 border-b border-[#27272a] text-[11px]`,children:[(0,Z.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(`span`,{className:`text-[#71717a]`,children:`format`}),(0,Z.jsx)(`select`,{value:s,onChange:e=>c(e.target.value),className:`bg-[#18181b] border border-[#27272a] rounded px-2 py-0.5 text-[#e4e4e7] focus:outline-none focus:border-[#6366f1]/60`,children:jf.map(e=>(0,Z.jsx)(`option`,{value:e,children:e},e))})]}),(0,Z.jsx)(`span`,{className:`text-[#52525b]`,children:`·`}),(0,Z.jsxs)(`span`,{className:`text-[#71717a]`,children:[`updated `,(0,Z.jsx)(`span`,{className:`text-[#a1a1aa]`,children:new Date(e.updatedAt).toLocaleString()})]}),(0,Z.jsx)(`span`,{className:`text-[#52525b]`,children:`·`}),(0,Z.jsxs)(`span`,{className:`text-[#71717a]`,children:[e.w,` × `,e.h,` grid cells`]}),(0,Z.jsx)(`div`,{className:`ml-auto text-[10px] text-[#52525b]`,children:`⌘/Ctrl + Enter to save`})]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 px-5 py-2.5 border-b border-[#27272a] bg-[#0e0b16]`,children:[(0,Z.jsx)(Pe,{className:`w-4 h-4 text-[#a855f7] shrink-0`}),(0,Z.jsx)(`input`,{value:v,onChange:e=>y(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),C())},disabled:b,placeholder:`Ask the AI to change this widget — e.g. “make the background a warm gradient and the text bigger”`,className:`flex-1 bg-transparent text-[12.5px] text-[#e4e4e7] placeholder:text-[#6b6b76] outline-none disabled:opacity-60`}),(0,Z.jsxs)(`button`,{onClick:()=>{C()},disabled:b||!v.trim(),className:`inline-flex items-center gap-1.5 px-3 py-1.5 rounded-lg bg-[#a855f7]/15 text-[#c084fc] border border-[#a855f7]/30 text-[11px] font-medium hover:bg-[#a855f7]/25 disabled:opacity-50 transition-colors shrink-0`,children:[(0,Z.jsx)(Pe,{className:`w-3.5 h-3.5`}),b?`AI is editing…`:`Ask AI`]})]}),ee&&(0,Z.jsx)(`div`,{className:`px-5 py-1.5 text-[11px] text-[#c084fc] border-b border-[#27272a] bg-[#0e0b16]`,children:ee}),(0,Z.jsxs)(`div`,{className:`flex-1 flex min-h-0`,children:[(0,Z.jsx)(`textarea`,{ref:S,value:a,onChange:e=>o(e.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:Nf[s]}),g&&(0,Z.jsxs)(`div`,{className:`w-72 flex flex-col border-l border-[#27272a] bg-[#0a0a0e]`,children:[(0,Z.jsxs)(`div`,{className:`px-3 py-2 border-b border-[#27272a] text-[10px] uppercase tracking-wider text-[#71717a]`,children:[`History (`,w.length,`)`]}),(0,Z.jsxs)(`div`,{className:`flex-1 overflow-auto`,children:[ie.length===0&&(0,Z.jsx)(`div`,{className:`p-3 text-[11px] text-[#52525b]`,children:`No prior versions yet — save to start tracking.`}),ie.map((e,t)=>(0,Z.jsxs)(`div`,{className:`px-3 py-2 border-b border-[#18181b] hover:bg-[#18181b]/40 transition-colors`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between gap-2 mb-1`,children:[(0,Z.jsx)(`div`,{className:`text-[10px] font-mono text-[#a1a1aa]`,children:new Date(e.savedAt).toLocaleString()}),(0,Z.jsxs)(`button`,{onClick:()=>re(e),className:`inline-flex items-center gap-1 text-[10px] text-[#6366f1] hover:text-[#a5b4fc] transition-colors`,title:`Load this version into the editor`,children:[(0,Z.jsx)(O,{className:`w-3 h-3`}),`revert`]})]}),(0,Z.jsxs)(`div`,{className:`text-[10px] text-[#71717a] font-mono`,children:[`format: `,e.format]}),(0,Z.jsxs)(`div`,{className:`text-[10px] text-[#52525b] truncate mt-1`,title:e.source.slice(0,280),children:[e.source.slice(0,80),e.source.length>80?`…`:``]}),t===0&&(0,Z.jsx)(`div`,{className:`text-[9px] text-[#6366f1] mt-1`,children:`most recent before current`})]},e.savedAt))]})]})]}),(0,Z.jsxs)(`div`,{className:`flex items-center justify-between gap-2 px-5 py-3 border-t border-[#27272a]`,children:[(0,Z.jsx)(`div`,{className:`text-[10px] text-[#71717a]`,children:m?(0,Z.jsxs)(`span`,{className:`text-[#ef4444]`,children:[`Error: `,m]}):a!==e.source||s!==e.format||l!==e.name?`Unsaved changes`:`Up to date`}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.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`}),(0,Z.jsxs)(`button`,{onClick:()=>{ne()},disabled:f,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:[(0,Z.jsx)(k,{className:`w-3.5 h-3.5`}),f?`Saving…`:`Save widget`]})]})]})]})})}var Nf={react:`// Return a React component named "Widget". titan.* APIs are
|
|
750
|
+
// available for fetch/api/state. Example:
|
|
751
|
+
function Widget({ titan }) {
|
|
752
|
+
const [n, setN] = React.useState(0);
|
|
753
|
+
return <button onClick={() => setN(n + 1)}>Clicked {n} times</button>;
|
|
754
|
+
}`,vanilla:`// Export a function (container, titan) => cleanup | void.
|
|
755
|
+
// Called once to mount; return a cleanup function if needed.
|
|
756
|
+
(container, titan) => {
|
|
757
|
+
container.innerHTML = '<button>Hello</button>';
|
|
758
|
+
const btn = container.querySelector('button');
|
|
759
|
+
btn.addEventListener('click', () => btn.textContent = 'Clicked!');
|
|
760
|
+
}`,html:`<!-- Raw HTML. No scripts run. -->
|
|
761
|
+
<div style="padding:16px;color:#e4e4e7">Hello, widget!</div>`,iframe:``,system:``};function Pf(e){return String(e||``).startsWith(`system:`)?`system`:`react`}var Ff={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 If(e){return e.split(/[-_/]/).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(` `)}function Lf({open:e,onClose:t}){let[n,r]=(0,N.useState)([]),[i,a]=(0,N.useState)([]),[o,s]=(0,N.useState)(`All`),[c,l]=(0,N.useState)(``),[u,d]=(0,N.useState)(null),[f,p]=(0,N.useState)(!1),[m,h]=(0,N.useState)(null);(0,N.useEffect)(()=>{e&&(p(!0),j(`/api/widget-gallery`).then(e=>e.json()).then(e=>{r(e.templates||[]),a(e.categories||[]),p(!1)}).catch(e=>{h(e.message),p(!1)}))},[e]),(0,N.useEffect)(()=>{if(!e)return;let n=e=>{e.key===`Escape`&&t()};return window.addEventListener(`keydown`,n),()=>window.removeEventListener(`keydown`,n)},[e,t]);let g=(0,N.useMemo)(()=>{let e=o===`All`?n:n.filter(e=>e.category===o),t=c.trim().toLowerCase();return t?e.filter(e=>[e.name,e.description,e.category,...e.tags||[],...e.triggers||[]].join(` `).toLowerCase().includes(t)):e},[o,c,n]);if(!e)return null;let _=async e=>{d(e.id),h(null);try{let n=await j(`/api/widget-gallery/${encodeURIComponent(e.id)}`);if(!n.ok)throw Error(`Could not load template (${n.status})`);let r=await n.json(),i={templateId:e.id,templateName:r.name||e.name,source:r.source,format:Pf(r.source),defaultSize:{w:r.defaultSize?.w??e.defaultSize?.w??4,h:r.defaultSize?.h??e.defaultSize?.h??4}};window.dispatchEvent(new CustomEvent(`titan:gallery:run-template`,{detail:i})),t()}catch(e){h(e.message)}finally{d(null)}},v=[`All`,...i.map(e=>e.category)];return(0,Z.jsx)(`div`,{className:`fixed inset-0 z-[2147483150] flex items-center justify-center p-3 sm:p-4 titan-menu-overlay`,onClick:t,children:(0,Z.jsxs)(`div`,{className:`w-full max-w-5xl titan-widget-gallery-window flex flex-col`,style:{height:`min(760px, 92vh)`},onClick:e=>e.stopPropagation(),children:[(0,Z.jsxs)(`div`,{className:`titan-widget-gallery-titlebar`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(`span`,{className:`titan-window-dot`}),(0,Z.jsx)(`span`,{className:`titan-window-dot titan-window-dot--dim`}),(0,Z.jsx)(`span`,{className:`titan-window-dot titan-window-dot--dim`}),(0,Z.jsx)(Pe,{className:`w-4 h-4 ml-1`,style:{color:`var(--theme-accent)`}}),(0,Z.jsx)(`h3`,{className:`font-semibold text-sm`,style:{color:`var(--theme-ink)`,fontFamily:`var(--theme-font-display)`},children:`Widget gallery`}),(0,Z.jsx)(`span`,{className:`text-[10px]`,style:{color:`var(--theme-ink-soft)`},children:f?`Loading…`:`${n.length} templates`})]}),(0,Z.jsx)(`button`,{onClick:t,className:`titan-close-btn`,title:`Close (Esc)`,"aria-label":`Close`,children:(0,Z.jsx)(ze,{className:`w-4 h-4`})})]}),(0,Z.jsx)(`div`,{className:`titan-widget-gallery-category-row`,children:v.map(e=>(0,Z.jsxs)(`button`,{onClick:()=>s(e),className:`titan-widget-gallery-category ${o===e?`titan-widget-gallery-category--active`:``}`,children:[If(e),e!==`All`&&(0,Z.jsx)(`span`,{className:`ml-1.5 text-[9px] opacity-70`,children:i.find(t=>t.category===e)?.count??0})]},e))}),(0,Z.jsx)(`div`,{className:`px-4 sm:px-5 py-2 border-b`,style:{borderColor:`var(--theme-menu-border)`},children:(0,Z.jsxs)(`label`,{className:`titan-widget-gallery-search`,children:[(0,Z.jsx)(se,{className:`w-3.5 h-3.5`}),(0,Z.jsx)(`input`,{value:c,onChange:e=>l(e.target.value),placeholder:`Search templates...`,className:`flex-1 bg-transparent text-xs outline-none`})]})}),(0,Z.jsxs)(`div`,{className:`flex-1 overflow-auto p-4`,children:[f&&(0,Z.jsx)(`div`,{className:`flex items-center justify-center h-full text-sm`,style:{color:`var(--theme-ink-soft)`},children:`Loading templates…`}),m&&(0,Z.jsxs)(`div`,{className:`flex items-center justify-center h-full text-sm`,style:{color:`var(--color-error)`},children:[`Error: `,m]}),!f&&!m&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-3`,children:g.map(e=>(0,Z.jsxs)(`button`,{onClick:()=>_(e),disabled:u!==null,className:`titan-widget-gallery-card group`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between gap-2 mb-1`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,Z.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full shrink-0`,style:{background:Ff[e.category]??`#9ca3af`}}),(0,Z.jsx)(`span`,{className:`text-[12px] font-medium truncate`,style:{color:`var(--theme-ink)`},children:e.name})]}),(0,Z.jsx)(ce,{className:`w-3 h-3 transition-colors shrink-0`})]}),(0,Z.jsx)(`div`,{className:`text-[11px] leading-relaxed line-clamp-2`,style:{color:`var(--theme-ink-soft)`},children:u===e.id?`Adding to canvas...`:e.description}),e.tags&&e.tags.length>0&&(0,Z.jsx)(`div`,{className:`flex flex-wrap gap-1 mt-1.5`,children:e.tags.slice(0,3).map(e=>(0,Z.jsx)(`span`,{className:`titan-widget-gallery-tag`,children:e},e))})]},e.id))}),g.length===0&&(0,Z.jsx)(`div`,{className:`flex items-center justify-center h-40 text-sm`,style:{color:`var(--theme-ink-soft)`},children:`No templates in this category.`})]}),(0,Z.jsxs)(`div`,{className:`titan-widget-gallery-note`,children:[(0,Z.jsx)($e,{className:`w-3.5 h-3.5 mt-0.5 shrink-0`}),(0,Z.jsxs)(`div`,{className:`text-[11px] 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 `,(0,Z.jsx)(`span`,{className:`font-mono`,children:`titan.fetch`}),`,`,` `,(0,Z.jsx)(`span`,{className:`font-mono`,children:`titan.api.call`}),`, and`,` `,(0,Z.jsx)(`span`,{className:`font-mono`,children:`titan.state`}),`.`]})]})]})]})})}var Rf=[{type:`widget`,source:`system:nav`,name:`Nav Widget`,w:3,h:4,icon:(0,Z.jsx)($e,{className:`w-4 h-4`})},{type:`widget`,source:`system:chat`,name:`Chat Widget`,w:4,h:5,icon:(0,Z.jsx)(re,{className:`w-4 h-4`})},{type:`widget`,source:`system:soma`,name:`SOMA`,w:6,h:6,icon:(0,Z.jsx)(_e,{className:`w-4 h-4`})},{type:`widget`,source:`system:command-post`,name:`Command Post`,w:8,h:6,icon:(0,Z.jsx)(de,{className:`w-4 h-4`})},{type:`widget`,source:`system:intelligence`,name:`Intelligence`,w:6,h:5,icon:(0,Z.jsx)(ie,{className:`w-4 h-4`})},{type:`widget`,source:`system:memory-graph`,name:`Memory Graph`,w:8,h:7,icon:(0,Z.jsx)(g,{className:`w-4 h-4`})},{type:`widget`,source:`system:voice`,name:`Voice`,w:5,h:5,icon:(0,Z.jsx)(w,{className:`w-4 h-4`})},{type:`widget`,source:`system:infra`,name:`Infrastructure`,w:6,h:4,icon:(0,Z.jsx)(le,{className:`w-4 h-4`})},{type:`widget`,source:`system:tools`,name:`Tools`,w:5,h:4,icon:(0,Z.jsx)(ke,{className:`w-4 h-4`})},{type:`widget`,source:`system:settings`,name:`Settings`,w:5,h:5,icon:(0,Z.jsx)(ue,{className:`w-4 h-4`})},{type:`widget`,source:`system:files`,name:`Files`,w:4,h:6,icon:(0,Z.jsx)(v,{className:`w-4 h-4`})},{type:`widget`,source:`system:memory-wiki`,name:`Memory Wiki`,w:6,h:6,icon:(0,Z.jsx)(s,{className:`w-4 h-4`})},{type:`widget`,source:`system:autoresearch`,name:`Autoresearch`,w:6,h:6,icon:(0,Z.jsx)(y,{className:`w-4 h-4`})},{type:`widget`,source:`system:self-proposals`,name:`Self-Proposals`,w:6,h:6,icon:(0,Z.jsx)(x,{className:`w-4 h-4`})},{type:`widget`,source:`system:muscle-memory`,name:`Muscle Memory`,w:6,h:7,icon:(0,Z.jsx)(x,{className:`w-4 h-4`})},{type:`widget`,source:`system:overview`,name:`Overview`,w:6,h:5,icon:(0,Z.jsx)(ge,{className:`w-4 h-4`})},{type:`widget`,source:`system:sessions`,name:`Sessions`,w:6,h:5,icon:(0,Z.jsx)(h,{className:`w-4 h-4`})},{type:`widget`,source:`system:watch`,name:`Watch`,w:8,h:7,icon:(0,Z.jsx)(ve,{className:`w-4 h-4`})},{type:`widget`,source:`system:backup`,name:`Backup Manager`,w:6,h:6,icon:(0,Z.jsx)(o,{className:`w-4 h-4`})},{type:`widget`,source:`system:training`,name:`Training Dashboard`,w:6,h:6,icon:(0,Z.jsx)(_e,{className:`w-4 h-4`})},{type:`widget`,source:`system:recipes`,name:`Recipe Kitchen`,w:6,h:6,icon:(0,Z.jsx)(s,{className:`w-4 h-4`})},{type:`widget`,source:`system:vram`,name:`VRAM Monitor`,w:6,h:6,icon:(0,Z.jsx)(Se,{className:`w-4 h-4`})},{type:`widget`,source:`system:teams`,name:`Team Hub`,w:6,h:6,icon:(0,Z.jsx)(Ve,{className:`w-4 h-4`})},{type:`widget`,source:`system:cron`,name:`Cron Scheduler`,w:6,h:6,icon:(0,Z.jsx)(h,{className:`w-4 h-4`})},{type:`widget`,source:`system:checkpoints`,name:`Checkpoints`,w:6,h:5,icon:(0,Z.jsx)(k,{className:`w-4 h-4`})},{type:`widget`,source:`system:organism`,name:`Organism Monitor`,w:6,h:6,icon:(0,Z.jsx)(Ae,{className:`w-4 h-4`})},{type:`widget`,source:`system:fleet`,name:`Fleet Router`,w:6,h:5,icon:(0,Z.jsx)(oe,{className:`w-4 h-4`})},{type:`widget`,source:`system:browser`,name:`Browser Tools`,w:6,h:5,icon:(0,Z.jsx)(Te,{className:`w-4 h-4`})},{type:`widget`,source:`system:eval`,name:`Test Lab`,w:6,h:6,icon:(0,Z.jsx)(E,{className:`w-4 h-4`})}];function zf({currentSpaceId:e,onSpaceSelect:t,onAction:n,onClose:r}){let[i,a]=(0,N.useState)(``),[o,s]=(0,N.useState)(0),c=(0,N.useRef)(null),l=X.list(),u=(0,N.useMemo)(()=>{let t=i.toLowerCase(),n=l.filter(n=>n.id!==e&&n.name.toLowerCase().includes(t)).map(e=>({type:`space`,id:e.id,name:e.name,color:e.color})),r=Rf.filter(e=>e.name.toLowerCase().includes(t)).map(e=>({type:`action`,action:e,name:e.name}));return[...n,...r]},[i,l,e]);return(0,N.useEffect)(()=>{c.current?.focus()},[]),(0,N.useEffect)(()=>{s(0)},[i]),(0,N.useEffect)(()=>{let e=e=>{if((e.metaKey||e.ctrlKey)&&e.key.toLowerCase()===`k`){e.preventDefault(),r();return}if(e.key===`Escape`){r();return}if(e.key===`ArrowDown`){e.preventDefault(),s(e=>Math.min(e+1,u.length-1));return}if(e.key===`ArrowUp`){e.preventDefault(),s(e=>Math.max(e-1,0));return}if(e.key===`Enter`){e.preventDefault();let r=u[o];if(!r)return;r.type===`space`&&t(r.id),r.type===`action`&&n(r.action)}};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[u,o,t,n,r]),(0,Z.jsx)(`div`,{className:`fixed inset-0 z-[2147483200] flex items-start justify-center pt-[20vh]`,onClick:r,children:(0,Z.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:e=>e.stopPropagation(),children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-3 px-4 py-3 border-b border-[#27272a]/40`,children:[(0,Z.jsx)(se,{className:`w-4 h-4 text-[#3f3f46]`}),(0,Z.jsx)(`input`,{ref:c,value:i,onChange:e=>a(e.target.value),placeholder:`Search spaces, widgets, actions...`,className:`flex-1 bg-transparent text-sm text-[#e4e4e7] placeholder:text-[#3f3f46] outline-none`}),(0,Z.jsx)(`button`,{onClick:r,className:`text-[#3f3f46] hover:text-[#71717a]`,children:(0,Z.jsx)(ze,{className:`w-4 h-4`})})]}),(0,Z.jsxs)(`div`,{className:`max-h-[50vh] overflow-auto py-1`,children:[u.length===0&&(0,Z.jsxs)(`div`,{className:`px-4 py-6 text-center text-xs text-[#52525b]`,children:[`No results for "`,i,`"`]}),u.map((e,r)=>(0,Z.jsxs)(`button`,{onClick:()=>{e.type===`space`&&t(e.id),e.type===`action`&&n(e.action)},className:`w-full flex items-center gap-3 px-4 py-2.5 text-left transition-colors ${r===o?`bg-[#6366f1]/10 text-[#818cf8]`:`text-[#a1a1aa] hover:bg-[#27272a]/30`}`,children:[e.type===`space`?(0,Z.jsx)(`div`,{className:`w-4 h-4 rounded-full`,style:{background:e.color||`#52525b`}}):(0,Z.jsx)(`span`,{className:`text-[#6366f1]/60`,children:e.action.icon}),(0,Z.jsx)(`span`,{className:`text-sm`,children:e.name}),(0,Z.jsx)(`span`,{className:`ml-auto text-[10px] text-[#3f3f46] uppercase tracking-wider`,children:e.type===`space`?`Space`:`Widget`})]},e.type===`space`?e.id:e.action.source))]}),(0,Z.jsxs)(`div`,{className:`px-4 py-2 border-t border-[#27272a]/40 flex items-center gap-3 text-[10px] text-[#3f3f46]`,children:[(0,Z.jsx)(`span`,{children:`↑↓ Navigate`}),(0,Z.jsx)(`span`,{children:`↵ Select`}),(0,Z.jsx)(`span`,{children:`ESC Close`})]})]})})}var Bf=N.lazy(()=>M(()=>import(`./SomaView-Bpsm4ZW7.js`),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]))),Q={bgBase:`var(--theme-bg-base, var(--color-bg, #09090b))`,bgGrain:`var(--theme-bg-grain, var(--color-bg-secondary, #18181b))`,surface:`color-mix(in srgb, var(--theme-bg-grain, var(--color-bg-secondary, #18181b)) 82%, transparent)`,surfaceSoft:`color-mix(in srgb, var(--theme-bg-grain, var(--color-bg-tertiary, #27272a)) 62%, transparent)`,border:`color-mix(in srgb, var(--theme-metal-dark, var(--color-border, #3f3f46)) 66%, transparent)`,metal:`var(--theme-metal, var(--color-border-light, #52525b))`,ink:`var(--theme-paper-fg, var(--color-text, #fafafa))`,inkSoft:`color-mix(in srgb, var(--theme-paper-fg, var(--color-text-secondary, #a1a1aa)) 72%, transparent)`,paperFg:`var(--theme-paper-fg, var(--color-text-secondary, #a1a1aa))`,accent:`var(--theme-accent, var(--color-accent, #6366f1))`,success:`var(--color-success, #22c55e)`,error:`var(--color-error, #ef4444)`},Vf={background:Q.bgBase,color:Q.ink};function Hf(){let[e,t]=(0,N.useState)(null),[n,r]=(0,N.useState)(!1),[i,a]=(0,N.useState)(null),o=(0,N.useCallback)(async()=>{try{let e=await j(`/api/config`);if(!e.ok)throw Error(`HTTP ${e.status}`);let n=await e.json();t(!!n?.organism?.enabled),a(null)}catch(e){a(e.message),t(!1)}},[]);(0,N.useEffect)(()=>{o()},[o]);let s=(0,N.useRef)(0),c=(0,N.useCallback)(async e=>{let n=++s.current;r(!0),a(null);try{let r=await j(`/api/config`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({organism:{enabled:e}})});if(n!==s.current)return;if(!r.ok)throw Error(`HTTP ${r.status}`);t(e),window.dispatchEvent(new CustomEvent(`titan:soma:changed`,{detail:{enabled:e}}))}catch(e){if(n!==s.current)return;a(e.message)}finally{n===s.current&&r(!1)}},[]);return e===null?(0,Z.jsx)(`div`,{className:`w-full h-full flex items-center justify-center text-xs`,style:{...Vf,color:Q.paperFg},children:`Loading Soma…`}):e?(0,Z.jsxs)(`div`,{className:`w-full h-full overflow-auto flex flex-col`,style:Vf,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-1.5 border-b`,style:{background:Q.surface,borderColor:Q.border},children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(`div`,{className:`w-1.5 h-1.5 rounded-full animate-pulse`,style:{background:Q.success}}),(0,Z.jsx)(`span`,{className:`text-[10px] font-bold uppercase tracking-wider`,style:{color:Q.success},children:`Soma active`})]}),(0,Z.jsxs)(`button`,{onClick:()=>c(!1),disabled:n,className:`inline-flex items-center gap-1 px-2 py-0.5 rounded-full border text-[10px] disabled:opacity-60 transition-colors`,style:{borderColor:Q.border,color:Q.inkSoft,background:Q.surfaceSoft},title:`Disable Soma`,children:[(0,Z.jsx)(ae,{className:`w-3 h-3`}),n?`saving…`:`disable`]})]}),(0,Z.jsx)(`div`,{className:`flex-1 overflow-auto`,children:(0,Z.jsx)(N.Suspense,{fallback:(0,Z.jsx)(`div`,{className:`p-4 text-xs`,style:{color:Q.paperFg},children:`Loading Soma dashboard…`}),children:(0,Z.jsx)(Bf,{})})})]}):(0,Z.jsxs)(`div`,{className:`w-full h-full flex flex-col items-center justify-center gap-4 p-6 text-center`,style:Vf,children:[(0,Z.jsx)(`div`,{className:`w-14 h-14 rounded-full flex items-center justify-center`,style:{background:`color-mix(in srgb, var(--theme-accent, var(--color-accent, #6366f1)) 18%, transparent)`,border:`1px solid ${Q.border}`},children:(0,Z.jsx)(ve,{className:`w-7 h-7`,style:{color:Q.accent}})}),(0,Z.jsxs)(`div`,{className:`space-y-1 max-w-md`,children:[(0,Z.jsx)(`h3`,{className:`text-lg font-semibold`,style:{color:Q.ink},children:`Soma is off`}),(0,Z.jsx)(`p`,{className:`text-xs leading-relaxed`,style:{color:Q.inkSoft},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.`})]}),(0,Z.jsxs)(`button`,{onClick:()=>c(!0),disabled:n,className:`inline-flex items-center gap-2 px-5 py-2.5 rounded-full disabled:opacity-60 disabled:cursor-not-allowed text-sm font-medium transition-colors`,style:{background:Q.accent,color:`var(--theme-bg-base, var(--color-bg, #09090b))`},children:[(0,Z.jsx)(ae,{className:`w-4 h-4`}),n?`Enabling…`:`Enable Soma`]}),i&&(0,Z.jsx)(`p`,{className:`text-xs`,style:{color:Q.error},children:i}),(0,Z.jsx)(`p`,{className:`text-[10px]`,style:{color:Q.paperFg},children:`You can turn this off anytime from the same button.`})]})}var Uf={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)`}},$={bgBase:`var(--theme-bg-base, var(--color-bg, #09090b))`,bgGrain:`var(--theme-bg-grain, var(--color-bg-secondary, #18181b))`,surface:`color-mix(in srgb, var(--theme-bg-grain, var(--color-bg-secondary, #18181b)) 90%, transparent)`,surfaceSoft:`color-mix(in srgb, var(--theme-bg-grain, var(--color-bg-tertiary, #27272a)) 62%, transparent)`,overlay:`color-mix(in srgb, var(--theme-bg-base, var(--color-bg, #09090b)) 56%, transparent)`,border:`color-mix(in srgb, var(--theme-metal-dark, var(--color-border, #3f3f46)) 66%, transparent)`,metal:`var(--theme-metal, var(--color-border-light, #52525b))`,ink:`var(--theme-paper-fg, var(--color-text, #fafafa))`,inkSoft:`color-mix(in srgb, var(--theme-paper-fg, var(--color-text-secondary, #a1a1aa)) 72%, transparent)`,accent:`var(--theme-accent, var(--color-accent, #6366f1))`,warning:`var(--color-warning, #f59e0b)`};function Wf(e,t,n){if(!n)return{emotion:`dreaming`,intensity:.25,activity:`Dormant`};let r=t[0],i=Math.min(1,e/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 e>.5?{emotion:`focused`,intensity:i,activity:`Processing`}:{emotion:`calm`,intensity:.3,activity:`Observing`}}}function Gf(){let[e,t]=(0,N.useState)(!1),[n,r]=(0,N.useState)({emotion:`calm`,intensity:.3,activity:`Observing`}),[i,a]=(0,N.useState)(!1),[o,s]=(0,N.useState)(()=>Kf()),[c,l]=(0,N.useState)(!1),u=(0,N.useRef)({x:0,y:0}),d=(0,N.useRef)(null);(0,N.useEffect)(()=>{let e=!1,t=async()=>{try{let t=await j(`/api/soma/state`);if(!t.ok||e)return;let n=await t.json();if(e)return;r(Wf(Number(n?.totalPressure??0),Array.isArray(n?.dominantDrives)?n.dominantDrives:[],!!n?.enabled))}catch{}};t();let n=setInterval(t,15e3);return()=>{e=!0,clearInterval(n)}},[]),(0,N.useEffect)(()=>{let e=e=>{d.current?.contains(e.target)||a(!1)};return window.addEventListener(`mousedown`,e),()=>window.removeEventListener(`mousedown`,e)},[]);let f=e=>{e.button===0&&(u.current={x:e.clientX-o.x,y:e.clientY-o.y},l(!0))},p=e=>{c&&s({x:e.clientX-u.current.x,y:e.clientY-u.current.y})},m=()=>{l(!1)},h=Uf[n.emotion],g=n.activity===`Dormant`?$.metal:$.accent;return(0,Z.jsxs)(Z.Fragment,{children:[e&&(0,Z.jsx)(`div`,{className:`fixed inset-0 z-[60] flex items-center justify-center backdrop-blur-sm`,style:{background:$.overlay},onClick:()=>t(!1),children:(0,Z.jsxs)(`div`,{className:`border rounded-2xl shadow-2xl overflow-hidden`,style:{width:`min(900px, 90vw)`,height:`min(600px, 80vh)`,background:$.surface,borderColor:$.border,color:$.ink,boxShadow:`0 24px 64px color-mix(in srgb, var(--theme-bg-base, var(--color-bg, #09090b)) 72%, transparent)`},onClick:e=>e.stopPropagation(),children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-2 border-b`,style:{borderColor:$.border},children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(_e,{className:`w-4 h-4`,style:{color:g}}),(0,Z.jsx)(`span`,{className:`text-[11px] font-bold uppercase tracking-wider`,style:{color:$.ink},children:`SOMA Consciousness`})]}),(0,Z.jsx)(`button`,{onClick:()=>t(!1),className:`p-1`,style:{color:$.metal},children:(0,Z.jsx)(ze,{className:`w-4 h-4`})})]}),(0,Z.jsx)(`div`,{className:`h-[calc(100%-40px)]`,children:(0,Z.jsx)(Hf,{})})]})}),(0,Z.jsxs)(`div`,{ref:d,className:`fixed z-50 select-none`,style:{left:o.x,top:o.y},onMouseDown:f,onMouseMove:p,onMouseUp:m,onMouseLeave:m,children:[i&&(0,Z.jsxs)(`div`,{className:`absolute bottom-full left-0 mb-2 backdrop-blur-xl border rounded-xl shadow-2xl overflow-hidden min-w-[160px] py-1`,style:{background:$.surface,borderColor:$.border,boxShadow:`0 18px 40px color-mix(in srgb, var(--theme-bg-base, var(--color-bg, #09090b)) 70%, transparent)`},children:[(0,Z.jsxs)(`button`,{onClick:()=>{t(!0),a(!1)},className:`w-full flex items-center gap-2 px-3 py-2 text-left text-[11px] transition-colors`,style:{color:$.ink,background:`transparent`},children:[(0,Z.jsx)(_e,{className:`w-3.5 h-3.5`,style:{color:g}}),`Open SOMA`]}),(0,Z.jsxs)(`button`,{onClick:()=>{a(!1)},className:`w-full flex items-center gap-2 px-3 py-2 text-left text-[11px] transition-colors`,style:{color:$.ink,background:`transparent`},children:[(0,Z.jsx)(Pe,{className:`w-3.5 h-3.5`,style:{color:$.warning}}),`Summarize Canvas`]}),(0,Z.jsxs)(`button`,{onClick:()=>{a(!1)},className:`w-full flex items-center gap-2 px-3 py-2 text-left text-[11px] transition-colors`,style:{color:$.ink,background:`transparent`},children:[(0,Z.jsx)(Ie,{className:`w-3.5 h-3.5`,style:{color:$.accent}}),`Run Self-Check`]})]}),(0,Z.jsxs)(`div`,{className:`relative cursor-pointer group`,onClick:()=>!c&&t(!0),onContextMenu:e=>{e.preventDefault(),a(!0)},children:[(0,Z.jsx)(`div`,{className:`absolute inset-0 rounded-full animate-ping opacity-20`,style:{background:h.pulse,animationDuration:`${3-n.intensity*2}s`}}),(0,Z.jsx)(`div`,{className:`absolute -inset-2 rounded-full opacity-30 blur-md transition-all duration-1000`,style:{background:h.glow}}),(0,Z.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%, ${g}, ${$.metal})`,boxShadow:`0 0 ${20+n.intensity*30}px ${h.glow}, inset 0 0 10px color-mix(in srgb, var(--theme-ink, var(--color-text, #fafafa)) 12%, transparent)`},children:(0,Z.jsx)(_e,{className:`w-5 h-5`,style:{color:$.ink}})}),(0,Z.jsx)(`div`,{className:`absolute -bottom-5 left-1/2 -translate-x-1/2 whitespace-nowrap`,children:(0,Z.jsx)(`span`,{className:`text-[9px] font-medium uppercase tracking-wider px-1.5 py-0.5 rounded border`,style:{color:$.ink,background:$.surfaceSoft,borderColor:$.border},children:n.activity})})]})]})]})}function Kf(){if(typeof window>`u`)return{x:280,y:80};let e=window.innerWidth<640;return{x:e?Math.max(16,window.innerWidth-96):280,y:e?220:80}}var qf=N.lazy(()=>M(()=>import(`./CommandPostHub-fIslwU_t.js`),__vite__mapDeps([16,1,3,17,18,9,2,4,5,6,7,8,10,11,12,13,14,19,20,21,22,23,24,25,26,27,28,29,30,31])));function Jf(){return(0,Z.jsx)(`div`,{className:`w-full h-full overflow-auto p-2`,children:(0,Z.jsx)(N.Suspense,{fallback:(0,Z.jsx)(`div`,{className:`p-4 text-xs text-[#52525b]`,children:`Loading Command Post...`}),children:(0,Z.jsx)(qf,{})})})}var Yf=N.lazy(()=>M(()=>import(`./IntelligenceView-BGVxCKD3.js`),__vite__mapDeps([32,1,5,3,6,7])));function Xf(){return(0,Z.jsx)(`div`,{className:`w-full h-full overflow-auto`,children:(0,Z.jsx)(N.Suspense,{fallback:(0,Z.jsx)(`div`,{className:`p-4 text-xs text-[#52525b]`,children:`Loading Intelligence...`}),children:(0,Z.jsx)(Yf,{})})})}var Zf=N.lazy(()=>M(()=>import(`./MemoryGraphPanel-C7-Z8f0v.js`),__vite__mapDeps([33,1,34,3,35,27,36,30,5,6,10,7])));function Qf(){return(0,Z.jsx)(`div`,{className:`w-full h-full overflow-auto bg-[#09090b]`,children:(0,Z.jsx)(N.Suspense,{fallback:(0,Z.jsx)(`div`,{className:`h-full flex items-center justify-center`,children:(0,Z.jsxs)(`div`,{className:`text-center`,children:[(0,Z.jsx)(`div`,{className:`w-8 h-8 rounded-full border-2 border-[#6366f1]/20 border-t-[#6366f1] animate-spin mx-auto mb-3`}),(0,Z.jsx)(`p`,{className:`text-[11px] text-[#52525b]`,children:`Loading memory graph...`})]})}),children:(0,Z.jsx)(`div`,{className:`p-4`,children:(0,Z.jsx)(Zf,{})})})})}function $f(){let[e,t]=(0,N.useState)(!1);return e?(0,Z.jsx)(C,{onClose:()=>t(!1)}):(0,Z.jsx)(`div`,{className:`w-full h-full flex flex-col items-center justify-center bg-[#09090b]`,children:(0,Z.jsxs)(`button`,{onClick:()=>t(!0),className:`group relative flex flex-col items-center gap-4`,children:[(0,Z.jsxs)(`div`,{className:`relative w-20 h-20 rounded-full flex items-center justify-center transition-all duration-300 group-hover:scale-110`,children:[(0,Z.jsx)(`div`,{className:`absolute inset-0 rounded-full bg-[#6366f1]/20 animate-pulse`}),(0,Z.jsx)(`div`,{className:`absolute inset-0 rounded-full bg-gradient-to-br from-[#6366f1]/30 to-[#4f46e5]/10 border border-[#6366f1]/30`}),(0,Z.jsx)(w,{className:`w-8 h-8 text-[#818cf8] relative z-10`})]}),(0,Z.jsxs)(`div`,{className:`text-center`,children:[(0,Z.jsx)(`p`,{className:`text-sm font-medium text-[#a1a1aa]`,children:`Tap to speak`}),(0,Z.jsx)(`p`,{className:`text-[10px] text-[#52525b] mt-1`,children:`F5-TTS · Voice Cloning`})]})]})})}var ep=N.lazy(()=>M(()=>import(`./InfraView-3WriJnyE.js`),__vite__mapDeps([37,1,5,3,6,7])));function tp(){return(0,Z.jsx)(`div`,{className:`w-full h-full overflow-auto`,children:(0,Z.jsx)(N.Suspense,{fallback:(0,Z.jsx)(`div`,{className:`p-4 text-xs text-[#52525b]`,children:`Loading Infrastructure...`}),children:(0,Z.jsx)(ep,{})})})}var np=N.lazy(()=>M(()=>import(`./ToolsView-PHizHZBx.js`),__vite__mapDeps([38,1,5,3,6,7])));function rp(){return(0,Z.jsx)(`div`,{className:`w-full h-full overflow-auto`,children:(0,Z.jsx)(N.Suspense,{fallback:(0,Z.jsx)(`div`,{className:`p-4 text-xs text-[#52525b]`,children:`Loading Tools...`}),children:(0,Z.jsx)(np,{})})})}var ip=N.lazy(()=>M(()=>import(`./SettingsView-Bu_wYTT5.js`),__vite__mapDeps([39,1,5,3,6,7])));function ap(){return(0,Z.jsx)(`div`,{className:`w-full h-full overflow-auto`,children:(0,Z.jsx)(N.Suspense,{fallback:(0,Z.jsx)(`div`,{className:`p-4 text-xs text-[#52525b]`,children:`Loading Settings...`}),children:(0,Z.jsx)(ip,{})})})}function op(){let[e,t]=(0,N.useState)([]),[n,r]=(0,N.useState)(`/`),[i,a]=(0,N.useState)(!1),[o,s]=(0,N.useState)(null),c=async()=>{a(!0),s(null);try{let e=await j(`/api/files?path=${encodeURIComponent(n)}`);if(e.ok){let n=await e.json();t(n.files||[])}else t([]),s(`Couldn't load files (HTTP ${e.status})`)}catch(e){t([]),s(`Couldn't reach /api/files — ${e.message}`)}finally{a(!1)}};return(0,N.useEffect)(()=>{c()},[n]),(0,Z.jsxs)(`div`,{className:`w-full h-full flex flex-col`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-2 border-b border-[#27272a]/40`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-1 text-[11px] text-[#71717a]`,children:[(0,Z.jsx)(`span`,{className:`text-[#6366f1]`,children:`~`}),(0,Z.jsx)(f,{className:`w-3 h-3`}),(0,Z.jsx)(`span`,{children:n})]}),(0,Z.jsx)(`button`,{onClick:c,className:`p-1 text-[#3f3f46] hover:text-[#71717a]`,children:(0,Z.jsx)(D,{className:`w-3 h-3 ${i?`animate-spin`:``}`})})]}),(0,Z.jsxs)(`div`,{className:`flex-1 overflow-auto`,children:[o&&(0,Z.jsx)(`div`,{className:`px-3 py-2 text-[11px] text-[#ef4444]/80`,children:o}),!o&&!i&&e.length===0&&(0,Z.jsx)(`div`,{className:`px-3 py-2 text-[11px] text-[#52525b]`,children:`No files`}),e.map(e=>(0,Z.jsxs)(`button`,{onClick:()=>e.type===`directory`&&r(e.path),className:`w-full flex items-center gap-2 px-3 py-1.5 text-left hover:bg-[#27272a]/20 transition-colors`,children:[e.type===`directory`?(0,Z.jsx)(b,{className:`w-3.5 h-3.5 text-[#f59e0b]`}):(0,Z.jsx)(v,{className:`w-3.5 h-3.5 text-[#6366f1]`}),(0,Z.jsx)(`span`,{className:`text-[12px] text-[#a1a1aa]`,children:e.name})]},e.path))]})]})}var sp=N.lazy(()=>M(()=>import(`./SettingsPanel-mV7ykOCc.js`),__vite__mapDeps([40,1,41,3,2,4,5,6,7,8,9,10,11,12,13,14,42,43,44,27,45,46])));function cp(){return(0,Z.jsx)(`div`,{className:`w-full h-full overflow-auto p-4`,children:(0,Z.jsx)(N.Suspense,{fallback:(0,Z.jsx)(`div`,{className:`text-xs text-[#52525b]`,children:`Loading...`}),children:(0,Z.jsx)(sp,{})})})}var lp=N.lazy(()=>M(()=>import(`./SecurityPanel-Bv_B9Ahf.js`),__vite__mapDeps([47,1,48,3,5,6,8,9])));function up(){return(0,Z.jsx)(`div`,{className:`w-full h-full overflow-auto p-4`,children:(0,Z.jsx)(N.Suspense,{fallback:(0,Z.jsx)(`div`,{className:`text-xs text-[#52525b]`,children:`Loading...`}),children:(0,Z.jsx)(lp,{})})})}var dp=N.lazy(()=>M(()=>import(`./AuditPanel-AyB8ciLZ.js`),__vite__mapDeps([49,1,50,3,51,27,5,6,8,9])));function fp(){return(0,Z.jsx)(`div`,{className:`w-full h-full overflow-auto p-4`,children:(0,Z.jsx)(N.Suspense,{fallback:(0,Z.jsx)(`div`,{className:`text-xs text-[#52525b]`,children:`Loading...`}),children:(0,Z.jsx)(dp,{})})})}var pp={researcher:`#60a5fa`,engineer:`#f87171`,manager:`#a78bfa`,ceo:`#fbbf24`,general:`#9ca3af`},mp={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 hp(){let[e,t]=(0,N.useState)(null),[n,r]=(0,N.useState)({}),[i,a]=(0,N.useState)({}),[o,s]=(0,N.useState)(null),[c,l]=(0,N.useState)({}),[u,d]=(0,N.useState)(!0),f=(0,N.useCallback)(async()=>{s(null);try{let[e,n]=await Promise.all([j(`/api/specialists`),j(`/api/models`)]);if(!e.ok)throw Error(`Specialists request failed: ${e.status}`);if(!n.ok)throw Error(`Models request failed: ${n.status}`);let i=await e.json(),o=await n.json();t(i),r(o);let s={};await Promise.all(i.map(async e=>{try{let t=await j(`/api/specialists/${encodeURIComponent(e.id)}/recommendations`);if(t.ok){let n=await t.json();n.recommendations&&(s[e.id]=n.recommendations)}}catch{}})),a(s)}catch(e){s(e.message)}finally{d(!1)}},[]);(0,N.useEffect)(()=>{f()},[f]);let p=(0,N.useCallback)(t=>{let r=i[t];if(r&&r.length)return r.map(e=>e.id);let a=new Set;if(n&&typeof n==`object`)for(let e of Object.keys(n)){let t=n[e];if(Array.isArray(t))for(let e of t)typeof e==`string`?a.add(e):e&&typeof e==`object`&&`id`in e&&typeof e.id==`string`&&a.add(e.id)}if(Array.isArray(e))for(let t of e)t?.activeModel&&a.add(t.activeModel),t?.defaultModel&&a.add(t.defaultModel);return Array.from(a).sort((e,t)=>e.localeCompare(t))},[i,n,e]),m=(0,N.useCallback)(async(e,n)=>{l(t=>({...t,[e]:`saving`}));try{let r=await j(`/api/specialists/${encodeURIComponent(e)}`,{method:`PATCH`,headers:{"Content-Type":`application/json`},body:JSON.stringify({model:n})});if(!r.ok){let e=await r.text().catch(()=>``);throw Error(`PATCH failed (${r.status}): ${e||r.statusText}`)}let i=await r.json();t(t=>t?.map(t=>t.id===e?{...t,activeModel:i.activeModel??t.defaultModel,overridden:(i.activeModel??t.defaultModel)!==t.defaultModel}:t)??null),l(t=>({...t,[e]:`saved`})),setTimeout(()=>{l(t=>{if(t[e]!==`saved`)return t;let n={...t};return delete n[e],n})},1500)}catch(t){l(t=>({...t,[e]:`error`})),s(`${e}: ${t.message}`)}},[]);return u&&!e?(0,Z.jsx)(`div`,{className:`h-full w-full flex items-center justify-center text-xs text-[#52525b]`,children:`Loading specialists…`}):(0,Z.jsxs)(`div`,{className:`w-full h-full flex flex-col bg-[#0a0a0f] text-[#e4e4e7] text-sm`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-3 border-b border-[#27272a]/60`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(Ve,{className:`w-4 h-4 text-[#6366f1]`}),(0,Z.jsx)(`h3`,{className:`font-semibold`,children:`Specialist Models`}),(0,Z.jsxs)(`span`,{className:`text-[10px] text-[#52525b]`,children:[e?.length??0,` sub-agents`]})]}),(0,Z.jsxs)(`button`,{onClick:()=>{d(!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:[(0,Z.jsx)(D,{className:`w-3 h-3 ${u?`animate-spin`:``}`}),`Refresh`]})]}),o&&(0,Z.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:[(0,Z.jsx)(xe,{className:`w-3 h-3 mt-0.5 shrink-0`}),(0,Z.jsx)(`span`,{className:`font-mono`,children:o})]}),(0,Z.jsxs)(`div`,{className:`flex-1 overflow-auto px-4 py-3 space-y-3`,children:[e?.length===0&&(0,Z.jsx)(`div`,{className:`text-xs text-[#52525b] italic`,children:`No specialists registered.`}),e?.map(e=>(0,Z.jsx)(gp,{row:e,models:p(e.id),recommendations:i[e.id]??[],state:c[e.id]??`idle`,onChange:t=>m(e.id,t),onReset:()=>m(e.id,null)},e.id))]}),(0,Z.jsxs)(`div`,{className:`px-4 py-2 border-t border-[#27272a]/60 text-[10px] text-[#52525b]`,children:[`Overrides write to `,(0,Z.jsx)(`span`,{className:`font-mono text-[#71717a]`,children:`config.specialists.overrides`}),`. Top-scored models are recommended per specialist role.`]})]})}function gp({row:e,models:t,recommendations:n,state:r,onChange:i,onReset:a}){let o=pp[e.role]??pp.general,s=n.find(t=>t.id===e.activeModel),c=n[0]??null,[l,d]=(0,N.useState)(!1);return(0,Z.jsxs)(`div`,{className:`rounded-lg border border-[#27272a]/60 bg-[#18181b]/70 hover:border-[#3f3f46]/80 transition-colors`,children:[(0,Z.jsxs)(`div`,{className:`px-3 py-2 flex items-center gap-3`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 min-w-[180px]`,children:[(0,Z.jsx)(`div`,{className:`w-2 h-2 rounded-full shrink-0`,style:{background:o},title:e.role}),(0,Z.jsxs)(`div`,{className:`flex flex-col min-w-0`,children:[(0,Z.jsx)(`div`,{className:`text-sm font-medium truncate`,children:e.name}),(0,Z.jsx)(`div`,{className:`text-[10px] text-[#52525b] truncate`,children:e.title})]})]}),(0,Z.jsxs)(`div`,{className:`flex-1 flex items-center gap-2 min-w-0`,children:[(0,Z.jsx)(`select`,{value:e.activeModel,onChange:e=>i(e.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: ${e.defaultModel}`,children:t.map(e=>{let t=n.find(t=>t.id===e)?.badges??[];return(0,Z.jsx)(`option`,{value:e,children:t.length?`${e} [${t.join(`, `)}]`:e},e)})}),s&&s.badges.length>0&&(0,Z.jsx)(`div`,{className:`hidden sm:flex items-center gap-1 shrink-0`,children:s.badges.slice(0,3).map(e=>(0,Z.jsx)(`span`,{className:`px-1.5 py-0.5 rounded text-[10px] border ${mp[e]??`bg-[#27272a] text-[#a1a1aa] border-[#27272a]`}`,children:e},e))}),e.overridden&&(0,Z.jsxs)(`button`,{onClick:a,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: ${e.defaultModel}`,children:[(0,Z.jsx)(O,{className:`w-3 h-3`}),`Reset`]}),(0,Z.jsx)(`button`,{onClick:()=>d(e=>!e),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:(0,Z.jsx)(Ue,{className:`w-3.5 h-3.5`})}),(0,Z.jsxs)(`div`,{className:`w-5 h-5 flex items-center justify-center shrink-0`,children:[r===`saving`&&(0,Z.jsx)(D,{className:`w-3.5 h-3.5 animate-spin text-[#6366f1]`}),r===`saved`&&(0,Z.jsx)(u,{className:`w-3.5 h-3.5 text-[#10b981]`}),r===`error`&&(0,Z.jsx)(xe,{className:`w-3.5 h-3.5 text-[#ef4444]`})]})]})]}),l&&(0,Z.jsxs)(`div`,{className:`px-3 pb-3 space-y-1.5`,children:[s&&(0,Z.jsxs)(`div`,{className:`flex items-start gap-2 text-[11px] text-[#a1a1aa]`,children:[(0,Z.jsx)(Ue,{className:`w-3 h-3 mt-0.5 shrink-0 text-[#6366f1]`}),(0,Z.jsx)(`span`,{children:s.rationale})]}),c&&c.id!==e.activeModel&&(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 text-[11px] text-[#10b981]`,children:[(0,Z.jsx)(u,{className:`w-3 h-3 shrink-0`}),(0,Z.jsxs)(`span`,{children:[`Recommended upgrade: `,(0,Z.jsx)(`span`,{className:`font-mono`,children:c.id}),` (score `,c.score,`/100)`,c.badges.length>0&&(0,Z.jsxs)(`span`,{className:`ml-1 text-[#71717a]`,children:[`[`,c.badges.join(`, `),`]`]})]})]}),s&&(0,Z.jsxs)(`div`,{className:`grid grid-cols-3 gap-2 text-[10px] text-[#52525b]`,children:[(0,Z.jsxs)(`div`,{children:[`Capability: `,(0,Z.jsxs)(`span`,{className:`text-[#a1a1aa]`,children:[s.breakdown.capabilityScore,`/40`]})]}),(0,Z.jsxs)(`div`,{children:[`Fit: `,(0,Z.jsxs)(`span`,{className:`text-[#a1a1aa]`,children:[s.breakdown.specialistFit,`/40`]})]}),(0,Z.jsxs)(`div`,{children:[`Availability: `,(0,Z.jsxs)(`span`,{className:`text-[#a1a1aa]`,children:[s.breakdown.availability,`/20`]})]})]})]}),(0,Z.jsxs)(`div`,{className:`px-3 pb-2 flex items-center gap-2 text-[10px] text-[#52525b]`,children:[(0,Z.jsxs)(`span`,{children:[`id: `,(0,Z.jsx)(`span`,{className:`font-mono text-[#71717a]`,children:e.id})]}),(0,Z.jsx)(`span`,{children:`•`}),(0,Z.jsxs)(`span`,{children:[`role: `,(0,Z.jsx)(`span`,{className:`font-mono`,style:{color:o},children:e.role})]}),e.templateMatches?.length>0&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`span`,{children:`•`}),(0,Z.jsxs)(`span`,{className:`truncate`,children:[`templates: `,(0,Z.jsx)(`span`,{className:`font-mono text-[#71717a]`,children:e.templateMatches.join(`, `)})]})]})]})]})}function _p(){let[e,t]=(0,N.useState)(null),[n,r]=(0,N.useState)(null),[i,a]=(0,N.useState)(null),[o,s]=(0,N.useState)(!1),[c,l]=(0,N.useState)(null),[u,d]=(0,N.useState)(null),f=(0,N.useCallback)(async()=>{l(null);try{let[e,n,i]=await Promise.all([j(`/api/telemetry/consent`).then(e=>e.ok?e.json():Promise.reject(Error(`consent ${e.status}`))),j(`/api/analytics/profile`).then(e=>e.ok?e.json():null),j(`/api/telemetry/status`).then(e=>e.ok?e.json():null)]);t(e),r(n),i?.remote&&a(i.remote)}catch(e){l(e.message)}},[]);(0,N.useEffect)(()=>{let e=setInterval(()=>{j(`/api/telemetry/status`).then(e=>e.ok?e.json():null).then(e=>{e?.remote&&a(e.remote)}).catch(()=>{})},15e3);return()=>clearInterval(e)},[]),(0,N.useEffect)(()=>{f()},[f]);let p=(0,N.useCallback)(async e=>{s(!0),l(null);try{let n=await j(`/api/telemetry/consent`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(e)});if(!n.ok)throw Error(`save failed: ${n.status}`);let r=await n.json();t(e=>e?{...e,...r,consentedAt:r.enabled?new Date().toISOString():void 0}:null),d(Date.now()),setTimeout(()=>d(null),2e3)}catch(e){l(e.message)}finally{s(!1)}},[]),m=!!e?.enabled,g=!!e?.crashReports;return(0,Z.jsxs)(`div`,{className:`w-full h-full overflow-auto bg-[#0a0a0f] text-[#e4e4e7] text-sm p-4`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 mb-4`,children:[m?(0,Z.jsx)(A,{className:`w-5 h-5 text-[#10b981]`}):(0,Z.jsx)(Ae,{className:`w-5 h-5 text-[#71717a]`}),(0,Z.jsx)(`h3`,{className:`font-semibold text-base`,children:`Privacy & Telemetry`}),(0,Z.jsx)(`span`,{className:`ml-2 text-[10px] px-2 py-0.5 rounded-full border ${m?`border-[#10b981]/40 bg-[#10b981]/10 text-[#10b981]`:`border-[#3f3f46] bg-[#18181b] text-[#71717a]`}`,children:m?`ENABLED`:`OFF`}),(0,Z.jsxs)(`div`,{className:`ml-auto flex items-center gap-2`,children:[u&&(0,Z.jsxs)(`span`,{className:`text-[11px] text-[#10b981] flex items-center gap-1`,children:[(0,Z.jsx)(Me,{className:`w-3 h-3`}),` Saved`]}),c&&(0,Z.jsxs)(`span`,{className:`text-[11px] text-[#ef4444] flex items-center gap-1`,children:[(0,Z.jsx)(me,{className:`w-3 h-3`}),` `,c]}),(0,Z.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:[(0,Z.jsx)(D,{className:`w-3 h-3`}),` Refresh`]})]})]}),(0,Z.jsx)(`div`,{className:`mb-4 p-4 rounded-lg border border-[#27272a]/60 bg-[#18181b]/70`,children:(0,Z.jsxs)(`label`,{className:`flex items-start gap-3 cursor-pointer`,children:[(0,Z.jsx)(`input`,{type:`checkbox`,checked:m,disabled:o,onChange:e=>p({enabled:e.target.checked,crashReports:g}),className:`mt-1 w-4 h-4 accent-[#6366f1] disabled:opacity-50`}),(0,Z.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Z.jsx)(`div`,{className:`font-medium`,children:`Send anonymous usage stats`}),(0,Z.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.`}),e?.consentedAt&&(0,Z.jsxs)(`div`,{className:`text-[10px] text-[#71717a] mt-2`,children:[`Consented `,(0,Z.jsx)(`span`,{className:`font-mono`,children:new Date(e.consentedAt).toLocaleString()}),e.consentedVersion&&(0,Z.jsxs)(Z.Fragment,{children:[` on TITAN v`,(0,Z.jsx)(`span`,{className:`font-mono`,children:e.consentedVersion})]})]})]})]})}),(0,Z.jsx)(`div`,{className:`mb-4 p-4 rounded-lg border transition-opacity ${m?`border-[#27272a]/60 bg-[#18181b]/70`:`border-[#27272a]/30 bg-[#18181b]/30 opacity-60`}`,children:(0,Z.jsxs)(`label`,{className:`flex items-start gap-3 cursor-pointer`,children:[(0,Z.jsx)(`input`,{type:`checkbox`,checked:g,disabled:o||!m,onChange:e=>p({enabled:m,crashReports:e.target.checked}),className:`mt-1 w-4 h-4 accent-[#6366f1] disabled:opacity-50`}),(0,Z.jsxs)(`div`,{className:`flex-1`,children:[(0,Z.jsx)(`div`,{className:`font-medium`,children:`Send crash reports`}),(0,Z.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. `,(0,Z.jsxs)(`span`,{className:`text-[#fbbf24]`,children:[`Your $HOME path is replaced with the string `,(0,Z.jsx)(`span`,{className:`font-mono`,children:`"$HOME"`}),` before sending.`]})]})]})]})}),(0,Z.jsxs)(`div`,{className:`mb-4 p-4 rounded-lg border border-[#27272a]/60 bg-[#18181b]/40`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 mb-3`,children:[(0,Z.jsx)(xe,{className:`w-4 h-4 text-[#6366f1]`}),(0,Z.jsx)(`div`,{className:`text-sm font-medium`,children:`What would be sent right now`})]}),n?(0,Z.jsxs)(`dl`,{className:`grid grid-cols-[160px_1fr] gap-y-1 text-xs`,children:[(0,Z.jsx)(`dt`,{className:`text-[#71717a]`,children:`installId`}),(0,Z.jsxs)(`dd`,{className:`font-mono text-[#e4e4e7]`,children:[n.installId.slice(0,32),`…`]}),(0,Z.jsx)(`dt`,{className:`text-[#71717a]`,children:`os / arch`}),(0,Z.jsxs)(`dd`,{className:`font-mono text-[#e4e4e7]`,children:[n.os,` / `,n.arch,` (`,n.osRelease,`)`]}),(0,Z.jsx)(`dt`,{className:`text-[#71717a]`,children:`cpu`}),(0,Z.jsxs)(`dd`,{className:`font-mono text-[#e4e4e7]`,children:[n.cpuModel,` · `,n.cpuCores,`c`]}),(0,Z.jsx)(`dt`,{className:`text-[#71717a]`,children:`ram`}),(0,Z.jsxs)(`dd`,{className:`font-mono text-[#e4e4e7]`,children:[(n.ramTotalMB/1024).toFixed(1),` GB`]}),(0,Z.jsx)(`dt`,{className:`text-[#71717a]`,children:`gpu`}),(0,Z.jsxs)(`dd`,{className:`font-mono text-[#e4e4e7]`,children:[n.gpuVendor,`/`,n.gpuName,` · `,(n.gpuVramMB/1024).toFixed(1),` GB VRAM`]}),(0,Z.jsx)(`dt`,{className:`text-[#71717a]`,children:`disk`}),(0,Z.jsxs)(`dd`,{className:`font-mono text-[#e4e4e7]`,children:[n.diskTotalGB,` GB`]}),(0,Z.jsx)(`dt`,{className:`text-[#71717a]`,children:`version / node`}),(0,Z.jsxs)(`dd`,{className:`font-mono text-[#e4e4e7]`,children:[n.version,` · `,n.nodeVersion]}),(0,Z.jsx)(`dt`,{className:`text-[#71717a]`,children:`install method`}),(0,Z.jsx)(`dd`,{className:`font-mono text-[#e4e4e7]`,children:n.installMethod})]}):(0,Z.jsx)(`div`,{className:`text-xs text-[#71717a]`,children:`Loading profile preview…`})]}),(0,Z.jsxs)(`div`,{className:`mb-4 p-4 rounded-lg border border-[#27272a]/60 bg-[#18181b]/50`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 mb-3`,children:[(0,Z.jsx)(ce,{className:`w-4 h-4 text-[#6366f1]`}),(0,Z.jsx)(`div`,{className:`text-sm font-medium`,children:`Delivery status`}),i?.lastSuccessAt&&!i.lastError&&(0,Z.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?.lastError&&(0,Z.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?.configured&&(0,Z.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?(0,Z.jsxs)(`dl`,{className:`grid grid-cols-[160px_1fr] gap-y-1 text-xs`,children:[(0,Z.jsx)(`dt`,{className:`text-[#71717a]`,children:`remote URL`}),(0,Z.jsx)(`dd`,{className:`font-mono text-[#e4e4e7] break-all`,children:i.remoteUrl||`—`}),(0,Z.jsx)(`dt`,{className:`text-[#71717a]`,children:`sent / failed`}),(0,Z.jsxs)(`dd`,{className:`font-mono text-[#e4e4e7]`,children:[(0,Z.jsx)(`span`,{className:`text-[#10b981]`,children:i.sentCount}),` / `,(0,Z.jsx)(`span`,{className:i.failedCount>0?`text-[#ef4444]`:`text-[#71717a]`,children:i.failedCount}),i.lastEventType&&(0,Z.jsxs)(`span`,{className:`text-[#71717a]`,children:[` · last event: `,(0,Z.jsx)(`span`,{className:`text-[#a1a1aa]`,children:i.lastEventType})]})]}),(0,Z.jsx)(`dt`,{className:`text-[#71717a]`,children:`last attempt`}),(0,Z.jsxs)(`dd`,{className:`font-mono text-[#e4e4e7] flex items-center gap-1`,children:[(0,Z.jsx)(h,{className:`w-3 h-3 text-[#71717a]`}),i.lastAttemptAt?new Date(i.lastAttemptAt).toLocaleString():`—`]}),(0,Z.jsx)(`dt`,{className:`text-[#71717a]`,children:`last success`}),(0,Z.jsx)(`dd`,{className:`font-mono text-[#e4e4e7]`,children:i.lastSuccessAt?new Date(i.lastSuccessAt).toLocaleString():`—`}),i.lastError&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`dt`,{className:`text-[#ef4444]`,children:`last error`}),(0,Z.jsx)(`dd`,{className:`font-mono text-[#fca5a5] break-all`,children:i.lastError})]})]}):(0,Z.jsx)(`div`,{className:`text-xs text-[#71717a]`,children:`Checking collector reachability…`})]}),(0,Z.jsxs)(`div`,{className:`mb-4 p-3 rounded-lg border border-[#27272a]/60 bg-[#0a0a0f]`,children:[(0,Z.jsx)(`div`,{className:`text-[10px] text-[#71717a] uppercase tracking-wider mb-1`,children:`Collector`}),(0,Z.jsx)(`div`,{className:`font-mono text-[11px] text-[#a1a1aa] break-all`,children:e?.remoteUrl||`—`})]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-3 text-[11px]`,children:[(0,Z.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:[(0,Z.jsx)(_,{className:`w-3 h-3`}),` Read the full PRIVACY.md`]}),(0,Z.jsx)(`span`,{className:`text-[#52525b]`,children:`·`}),(0,Z.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:[(0,Z.jsx)(_,{className:`w-3 h-3`}),` See the collector source`]})]})]})}var vp=N.lazy(()=>M(()=>import(`./AutopilotPanel-CbLy4lJP.js`),__vite__mapDeps([52,1,5,3,6,8,9])));function yp(){return(0,Z.jsx)(`div`,{className:`w-full h-full overflow-auto p-4`,children:(0,Z.jsx)(N.Suspense,{fallback:(0,Z.jsx)(`div`,{className:`text-xs text-[#52525b]`,children:`Loading...`}),children:(0,Z.jsx)(vp,{})})})}var bp=N.lazy(()=>M(()=>import(`./WorkflowsPanel-DqtmT0NB.js`),__vite__mapDeps([53,1,3,54,9,2,4,5,6,7,8,10,11,12,13,14,20,25,44,26,27,55,30])));function xp(){return(0,Z.jsx)(`div`,{className:`w-full h-full overflow-auto p-4`,children:(0,Z.jsx)(N.Suspense,{fallback:(0,Z.jsx)(`div`,{className:`text-xs text-[#52525b]`,children:`Loading...`}),children:(0,Z.jsx)(bp,{})})})}var Sp=N.lazy(()=>M(()=>import(`./LearningPanel-CrYLQ6eV.js`),__vite__mapDeps([56,1,54,3,57,58,27,59,5,6,8,9])));function Cp(){return(0,Z.jsx)(`div`,{className:`w-full h-full overflow-auto p-4`,children:(0,Z.jsx)(N.Suspense,{fallback:(0,Z.jsx)(`div`,{className:`text-xs text-[#52525b]`,children:`Loading...`}),children:(0,Z.jsx)(Sp,{})})})}var wp=N.lazy(()=>M(()=>import(`./SelfImprovePanel-Ca4rGwEG.js`),__vite__mapDeps([60,1,17,3,9,41,20,44,61,27,62,29,30,59,63,5,6,8])));function Tp(){return(0,Z.jsx)(`div`,{className:`w-full h-full overflow-auto p-4`,children:(0,Z.jsx)(N.Suspense,{fallback:(0,Z.jsx)(`div`,{className:`text-xs text-[#52525b]`,children:`Loading...`}),children:(0,Z.jsx)(wp,{})})})}var Ep=N.lazy(()=>M(()=>import(`./PersonasPanel-Dwr7sycT.js`),__vite__mapDeps([64,1,5,3,6])));function Dp(){return(0,Z.jsx)(`div`,{className:`w-full h-full overflow-auto p-4`,children:(0,Z.jsx)(N.Suspense,{fallback:(0,Z.jsx)(`div`,{className:`text-xs text-[#52525b]`,children:`Loading...`}),children:(0,Z.jsx)(Ep,{})})})}var Op=N.lazy(()=>M(()=>import(`./PersonaProfilesPanel-BPi8fl-U.js`),__vite__mapDeps([65,1,3,4,20,25,27,66,5,6,8,9])));function kp(){return(0,Z.jsx)(`div`,{className:`w-full h-full overflow-auto p-4`,children:(0,Z.jsx)(N.Suspense,{fallback:(0,Z.jsx)(`div`,{className:`text-xs text-[#52525b]`,children:`Loading...`}),children:(0,Z.jsx)(Op,{})})})}var Ap=N.lazy(()=>M(()=>import(`./DreamPanel-lcMXpbEb.js`),__vite__mapDeps([67,1,3,27,5,6,8,9])));function jp(){return(0,Z.jsx)(`div`,{className:`w-full h-full overflow-auto p-4`,children:(0,Z.jsx)(N.Suspense,{fallback:(0,Z.jsx)(`div`,{className:`text-xs text-[#52525b]`,children:`Loading...`}),children:(0,Z.jsx)(Ap,{})})})}var Mp=N.lazy(()=>M(()=>import(`./HomelabPanel-m8vMm5rE.js`),__vite__mapDeps([68,1,3,18,41,20,21,24,35,27,69,46,5,6,8,9,12,7,14])));function Np(){return(0,Z.jsx)(`div`,{className:`w-full h-full overflow-auto p-4`,children:(0,Z.jsx)(N.Suspense,{fallback:(0,Z.jsx)(`div`,{className:`text-xs text-[#52525b]`,children:`Loading...`}),children:(0,Z.jsx)(Mp,{})})})}var Pp=N.lazy(()=>M(()=>import(`./NvidiaPanel-BfI1K5Pg.js`),__vite__mapDeps([70,1,41,3,71,27,45,36,5,6,8,9])));function Fp(){return(0,Z.jsx)(`div`,{className:`w-full h-full overflow-auto p-4`,children:(0,Z.jsx)(N.Suspense,{fallback:(0,Z.jsx)(`div`,{className:`text-xs text-[#52525b]`,children:`Loading...`}),children:(0,Z.jsx)(Pp,{})})})}var Ip=N.lazy(()=>M(()=>import(`./FilesPanel-BI90Pplh.js`),__vite__mapDeps([72,1,3,73,4,9,20,57,42,22,26,27,45,62,30,5,6])));function Lp(){return(0,Z.jsx)(`div`,{className:`w-full h-full overflow-auto p-4`,children:(0,Z.jsx)(N.Suspense,{fallback:(0,Z.jsx)(`div`,{className:`text-xs text-[#52525b]`,children:`Loading...`}),children:(0,Z.jsx)(Ip,{})})})}var Rp=N.lazy(()=>M(()=>import(`./LogsPanel-DbShr4Ic.js`),__vite__mapDeps([74,1,27,3,5,6,8,9])));function zp(){return(0,Z.jsx)(`div`,{className:`w-full h-full overflow-auto p-4`,children:(0,Z.jsx)(N.Suspense,{fallback:(0,Z.jsx)(`div`,{className:`text-xs text-[#52525b]`,children:`Loading...`}),children:(0,Z.jsx)(Rp,{})})})}var Bp=N.lazy(()=>M(()=>import(`./TelemetryPanel-_pmGVxpO.js`),__vite__mapDeps([75,1,18,3,20,23,69,5,6,14])));function Vp(){return(0,Z.jsx)(`div`,{className:`w-full h-full overflow-auto p-4`,children:(0,Z.jsx)(N.Suspense,{fallback:(0,Z.jsx)(`div`,{className:`text-xs text-[#52525b]`,children:`Loading...`}),children:(0,Z.jsx)(Bp,{})})})}var Hp=N.lazy(()=>M(()=>import(`./SkillsPanel-CHwX2kDR.js`),__vite__mapDeps([76,1,3,42,36,30,5,6,8,9,10,7])));function Up(){return(0,Z.jsx)(`div`,{className:`w-full h-full overflow-auto p-4`,children:(0,Z.jsx)(N.Suspense,{fallback:(0,Z.jsx)(`div`,{className:`text-xs text-[#52525b]`,children:`Loading...`}),children:(0,Z.jsx)(Hp,{})})})}var Wp=N.lazy(()=>M(()=>import(`./McpPanel-uMYEsPI4.js`),__vite__mapDeps([77,1,78,3,26,79,27,69,30,5,6,8,9,10,7])));function Gp(){return(0,Z.jsx)(`div`,{className:`w-full h-full overflow-auto p-4`,children:(0,Z.jsx)(N.Suspense,{fallback:(0,Z.jsx)(`div`,{className:`text-xs text-[#52525b]`,children:`Loading...`}),children:(0,Z.jsx)(Wp,{})})})}var Kp=N.lazy(()=>M(()=>import(`./IntegrationsPanel-BmL70fOw.js`),__vite__mapDeps([80,1,9,3,41,78,45,5,6,8])));function qp(){return(0,Z.jsx)(`div`,{className:`w-full h-full overflow-auto p-4`,children:(0,Z.jsx)(N.Suspense,{fallback:(0,Z.jsx)(`div`,{className:`text-xs text-[#52525b]`,children:`Loading...`}),children:(0,Z.jsx)(Kp,{})})})}var Jp=N.lazy(()=>M(()=>import(`./ChannelsPanel-DLbxg1zO.js`),__vite__mapDeps([81,1,9,3,41,27,45,5,6,8])));function Yp(){return(0,Z.jsx)(`div`,{className:`w-full h-full overflow-auto p-4`,children:(0,Z.jsx)(N.Suspense,{fallback:(0,Z.jsx)(`div`,{className:`text-xs text-[#52525b]`,children:`Loading...`}),children:(0,Z.jsx)(Jp,{})})})}var Xp=N.lazy(()=>M(()=>import(`./MeshPanel-D4-g2tlu.js`),__vite__mapDeps([82,1,3,27,48,5,6,8,9,13])));function Zp(){return(0,Z.jsx)(`div`,{className:`w-full h-full overflow-auto p-4`,children:(0,Z.jsx)(N.Suspense,{fallback:(0,Z.jsx)(`div`,{className:`text-xs text-[#52525b]`,children:`Loading...`}),children:(0,Z.jsx)(Xp,{})})})}var Qp=N.lazy(()=>M(()=>import(`./MemoryWikiPanel-DI3q6IHC.js`),__vite__mapDeps([83,1,3,73,54,20,84,36,5,6,8,9])));function $p(){return(0,Z.jsx)(`div`,{className:`w-full h-full overflow-auto p-4`,children:(0,Z.jsx)(N.Suspense,{fallback:(0,Z.jsx)(`div`,{className:`text-xs text-[#52525b]`,children:`Loading...`}),children:(0,Z.jsx)(Qp,{})})})}var em=N.lazy(()=>M(()=>import(`./AutoresearchPanel-DxRO1rBF.js`),__vite__mapDeps([85,1,3,9,20,86,25,44,27,59,63,5,6,8])));function tm(){return(0,Z.jsx)(`div`,{className:`w-full h-full overflow-auto p-4`,children:(0,Z.jsx)(N.Suspense,{fallback:(0,Z.jsx)(`div`,{className:`text-xs text-[#52525b]`,children:`Loading...`}),children:(0,Z.jsx)(em,{})})})}var nm=N.lazy(()=>M(()=>import(`./SelfProposalsPanel-DteMSASq.js`),__vite__mapDeps([87,1,20,3,88,5,6,8,9,10,7])));function rm(){return(0,Z.jsx)(`div`,{className:`w-full h-full overflow-auto p-4`,children:(0,Z.jsx)(N.Suspense,{fallback:(0,Z.jsx)(`div`,{className:`text-xs text-[#52525b]`,children:`Loading...`}),children:(0,Z.jsx)(nm,{})})})}var im=N.lazy(()=>M(()=>import(`./OverviewPanel-B9tKWRK2.js`),__vite__mapDeps([89,1,20,3,90,24,69,5,6,8,9,12,7,14])));function am(){return(0,Z.jsx)(`div`,{className:`w-full h-full overflow-auto p-4`,children:(0,Z.jsx)(N.Suspense,{fallback:(0,Z.jsx)(`div`,{className:`text-xs text-[#52525b]`,children:`Loading...`}),children:(0,Z.jsx)(im,{})})})}var om=N.lazy(()=>M(()=>import(`./SessionsPanel-BdbbKTbL.js`),__vite__mapDeps([91,1,2,3,4,5,6,7,8,9,10,11,12,13,14,36,30])));function sm(){return(0,Z.jsx)(`div`,{className:`w-full h-full overflow-auto p-4`,children:(0,Z.jsx)(N.Suspense,{fallback:(0,Z.jsx)(`div`,{className:`text-xs text-[#52525b]`,children:`Loading...`}),children:(0,Z.jsx)(om,{})})})}var cm=N.lazy(()=>M(()=>import(`./WatchView-BgAkNnur.js`),__vite__mapDeps([92,1,5,3,6,10,7])));function lm(){return(0,Z.jsx)(`div`,{className:`w-full h-full overflow-auto`,children:(0,Z.jsx)(N.Suspense,{fallback:(0,Z.jsx)(`div`,{className:`text-xs text-[#52525b]`,children:`Loading...`}),children:(0,Z.jsx)(cm,{})})})}var um=N.lazy(()=>M(()=>import(`./BackupPanel-BUh9rQ-3.js`),__vite__mapDeps([93,1,94,3,41,26,27,5,6,8,9])));function dm(){return(0,Z.jsx)(`div`,{className:`w-full h-full overflow-auto p-4`,children:(0,Z.jsx)(N.Suspense,{fallback:(0,Z.jsx)(`div`,{className:`text-xs text-[#52525b]`,children:`Loading...`}),children:(0,Z.jsx)(um,{})})})}var fm=N.lazy(()=>M(()=>import(`./TrainingPanel-B9rcuMsV.js`),__vite__mapDeps([95,1,42,3,27,5,6,8,9])));function pm(){return(0,Z.jsx)(`div`,{className:`w-full h-full overflow-auto p-4`,children:(0,Z.jsx)(N.Suspense,{fallback:(0,Z.jsx)(`div`,{className:`text-xs text-[#52525b]`,children:`Loading...`}),children:(0,Z.jsx)(fm,{})})})}var mm=N.lazy(()=>M(()=>import(`./RecipesPanel-DcqPWRSU.js`),__vite__mapDeps([96,1,54,3,44,27,30,5,6,8,9,10,7,11])));function hm(){return(0,Z.jsx)(`div`,{className:`w-full h-full overflow-auto p-4`,children:(0,Z.jsx)(N.Suspense,{fallback:(0,Z.jsx)(`div`,{className:`text-xs text-[#52525b]`,children:`Loading...`}),children:(0,Z.jsx)(mm,{})})})}var gm=N.lazy(()=>M(()=>import(`./VramPanel-BNPQ06_9.js`),__vite__mapDeps([97,1,27,3,5,6,8,9])));function _m(){return(0,Z.jsx)(`div`,{className:`w-full h-full overflow-auto p-4`,children:(0,Z.jsx)(N.Suspense,{fallback:(0,Z.jsx)(`div`,{className:`text-xs text-[#52525b]`,children:`Loading...`}),children:(0,Z.jsx)(gm,{})})})}var vm=N.lazy(()=>M(()=>import(`./TeamsPanel-XJiHxdDX.js`),__vite__mapDeps([98,1,27,3,30,5,6,8,9,10,7])));function ym(){return(0,Z.jsx)(`div`,{className:`w-full h-full overflow-auto p-4`,children:(0,Z.jsx)(N.Suspense,{fallback:(0,Z.jsx)(`div`,{className:`text-xs text-[#52525b]`,children:`Loading...`}),children:(0,Z.jsx)(vm,{})})})}var bm=N.lazy(()=>M(()=>import(`./CronPanel-DLpw3Y25.js`),__vite__mapDeps([99,1,20,3,27,55,30,5,6,8,9,10,7,11])));function xm(){return(0,Z.jsx)(`div`,{className:`w-full h-full overflow-auto p-4`,children:(0,Z.jsx)(N.Suspense,{fallback:(0,Z.jsx)(`div`,{className:`text-xs text-[#52525b]`,children:`Loading...`}),children:(0,Z.jsx)(bm,{})})})}var Sm=N.lazy(()=>M(()=>import(`./CheckpointsPanel-BB6TT0aE.js`),__vite__mapDeps([100,1,27,3,45,30,5,6,8,9,10,7])));function Cm(){return(0,Z.jsx)(`div`,{className:`w-full h-full overflow-auto p-4`,children:(0,Z.jsx)(N.Suspense,{fallback:(0,Z.jsx)(`div`,{className:`text-xs text-[#52525b]`,children:`Loading...`}),children:(0,Z.jsx)(Sm,{})})})}var wm=N.lazy(()=>M(()=>import(`./OrganismPanel-B7Gm9pP-.js`),__vite__mapDeps([101,1,41,3,27,5,6,8,9])));function Tm(){return(0,Z.jsx)(`div`,{className:`w-full h-full overflow-auto p-4`,children:(0,Z.jsx)(N.Suspense,{fallback:(0,Z.jsx)(`div`,{className:`text-xs text-[#52525b]`,children:`Loading...`}),children:(0,Z.jsx)(wm,{})})})}var Em=N.lazy(()=>M(()=>import(`./FleetPanel-tr0wjAwr.js`),__vite__mapDeps([102,1,61,3,27,5,6,8,9])));function Dm(){return(0,Z.jsx)(`div`,{className:`w-full h-full overflow-auto p-4`,children:(0,Z.jsx)(N.Suspense,{fallback:(0,Z.jsx)(`div`,{className:`text-xs text-[#52525b]`,children:`Loading...`}),children:(0,Z.jsx)(Em,{})})})}var Om=N.lazy(()=>M(()=>import(`./BrowserPanel-OqKwGrIL.js`),__vite__mapDeps([103,1,3,5,6,8,9])));function km(){return(0,Z.jsx)(`div`,{className:`w-full h-full overflow-auto p-4`,children:(0,Z.jsx)(N.Suspense,{fallback:(0,Z.jsx)(`div`,{className:`text-xs text-[#52525b]`,children:`Loading...`}),children:(0,Z.jsx)(Om,{})})})}var Am=N.lazy(()=>M(()=>import(`./EvalPanel-Dtodacmj.js`),__vite__mapDeps([104,1,44,3,27,5,6,8,9])));function jm(){return(0,Z.jsx)(`div`,{className:`w-full h-full overflow-auto p-4`,children:(0,Z.jsx)(N.Suspense,{fallback:(0,Z.jsx)(`div`,{className:`text-xs text-[#52525b]`,children:`Loading...`}),children:(0,Z.jsx)(Am,{})})})}function Mm(e){let t=Date.now()-new Date(e).getTime();if(!Number.isFinite(t)||t<0)return e;let n=Math.floor(t/1e3);if(n<60)return`${n}s ago`;let r=Math.floor(n/60);if(r<60)return`${r}m ago`;let i=Math.floor(r/60);return i<24?`${i}h ago`:`${Math.floor(i/24)}d ago`}function Nm(e){let t=Math.max(e.lastIndexOf(`/`),e.lastIndexOf(`\\`));return t>=0?e.slice(t+1):e}function Pm(){let[e,t]=(0,N.useState)([]),[n,r]=(0,N.useState)(!0),[i,a]=(0,N.useState)(``),[o,s]=(0,N.useState)(null),[c,l]=(0,N.useState)(``),[u,d]=(0,N.useState)(!1),[f,p]=(0,N.useState)(null),[m,h]=(0,N.useState)(null),[g,_]=(0,N.useState)(null),v=(0,N.useCallback)(async()=>{r(!0),p(null);try{let e=await j(`/api/time-travel/checkpoints?limit=100`);if(!e.ok)throw Error(`${e.status} ${e.statusText}`);let n=await e.json();t(n.checkpoints||[])}catch(e){p(e.message||`Failed to load`)}finally{r(!1)}},[]);(0,N.useEffect)(()=>{v()},[v]);let y=(0,N.useCallback)((e,t)=>{_({kind:e,message:t}),setTimeout(()=>_(null),4e3)},[]),b=(0,N.useCallback)(async e=>{s(e),l(``),d(!0);try{let t=await j(`/api/time-travel/diff/${encodeURIComponent(e)}`);if(!t.ok)throw Error(`${t.status} ${t.statusText}`);let n=await t.json();l(n.diff||`(no diff returned)`)}catch(e){l(`Failed to load diff: ${e.message}`)}finally{d(!1)}},[]),x=(0,N.useCallback)(e=>{h(e)},[]),ee=(0,N.useCallback)(async()=>{if(!m)return;let e=m;h(null);try{let t=await j(`/api/time-travel/restore/${encodeURIComponent(e)}`,{method:`POST`});if(!t.ok)throw Error(`${t.status} ${t.statusText}`);let n=await t.json();n.ok?(y(`ok`,n.message||`Restored to ${e.slice(0,8)}.`),v()):y(`err`,n.message||`Restore failed.`)}catch(e){y(`err`,e.message||`Restore failed.`)}},[m,v,y]),te=(0,N.useMemo)(()=>{let t=i.trim().toLowerCase();return t?e.filter(e=>e.filePath.toLowerCase().includes(t)||e.toolName.toLowerCase().includes(t)||e.id.toLowerCase().includes(t)):e},[e,i]);return(0,Z.jsxs)(`div`,{style:{width:`100%`,height:`100%`,display:`flex`,flexDirection:`column`,color:`#e2e8f5`,fontSize:12,background:`transparent`},children:[(0,Z.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:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`div`,{style:{fontSize:13,fontWeight:600},children:`Time Travel`}),(0,Z.jsxs)(`div`,{style:{fontSize:10,color:`rgba(255,255,255,0.45)`},children:[e.length,` file checkpoints · newest first`]})]}),(0,Z.jsxs)(`div`,{style:{display:`flex`,gap:6},children:[(0,Z.jsx)(`input`,{type:`text`,value:i,onChange:e=>a(e.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}}),(0,Z.jsx)(`button`,{onClick:v,disabled:n,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:n?`wait`:`pointer`},children:n?`…`:`Refresh`})]})]}),g&&(0,Z.jsx)(`div`,{style:{margin:`8px 14px 0`,padding:`6px 10px`,borderRadius:6,background:g.kind===`ok`?`rgba(34,197,94,0.12)`:`rgba(239,68,68,0.12)`,border:`1px solid ${g.kind===`ok`?`rgba(34,197,94,0.3)`:`rgba(239,68,68,0.3)`}`,color:g.kind===`ok`?`#86efac`:`#fca5a5`,fontSize:11},children:g.message}),f&&(0,Z.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}),(0,Z.jsxs)(`div`,{style:{flex:1,display:`flex`,overflow:`hidden`},children:[(0,Z.jsx)(`div`,{style:{flex:1,overflow:`auto`,borderRight:`1px solid rgba(255,255,255,0.06)`},children:n&&e.length===0?(0,Z.jsx)(`div`,{style:{padding:16,color:`rgba(255,255,255,0.4)`},children:`Loading checkpoints…`}):te.length===0?(0,Z.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.`}):te.map(e=>(0,Z.jsxs)(`div`,{onClick:()=>b(e.id),style:{padding:`8px 14px`,borderBottom:`1px solid rgba(255,255,255,0.04)`,cursor:`pointer`,background:o===e.id?`rgba(99,102,241,0.08)`:`transparent`,borderLeft:o===e.id?`2px solid #818cf8`:`2px solid transparent`},children:[(0,Z.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,justifyContent:`space-between`,marginBottom:2},children:[(0,Z.jsx)(`span`,{style:{fontSize:11,fontFamily:`ui-monospace, monospace`,color:`#a5b4fc`},children:e.commitHash.slice(0,8)}),(0,Z.jsx)(`span`,{style:{fontSize:10,color:`rgba(255,255,255,0.5)`},children:Mm(e.timestamp)})]}),(0,Z.jsx)(`div`,{style:{fontSize:12,color:`#e2e8f5`,overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`},title:e.filePath,children:Nm(e.filePath)}),(0,Z.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,justifyContent:`space-between`,marginTop:4},children:[(0,Z.jsxs)(`span`,{style:{fontSize:10,color:`rgba(255,255,255,0.4)`},children:[`before `,(0,Z.jsx)(`code`,{style:{color:`#fbbf24`},children:e.toolName})]}),(0,Z.jsx)(`button`,{onClick:t=>{t.stopPropagation(),x(e.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`})]})]},e.id))}),(0,Z.jsx)(`div`,{style:{flex:1,overflow:`auto`,padding:14},children:o?u?(0,Z.jsx)(`div`,{style:{color:`rgba(255,255,255,0.4)`},children:`Loading diff…`}):(0,Z.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:(c||``).split(`
|
|
762
|
+
`).map((e,t)=>{let n=`rgba(255,255,255,0.7)`;return e.startsWith(`+`)&&!e.startsWith(`+++`)?n=`#86efac`:e.startsWith(`-`)&&!e.startsWith(`---`)?n=`#fca5a5`:e.startsWith(`@@`)?n=`#a5b4fc`:(e.startsWith(`diff`)||e.startsWith(`index`)||e.startsWith(`+++`)||e.startsWith(`---`))&&(n=`rgba(255,255,255,0.45)`),(0,Z.jsx)(`div`,{style:{color:n},children:e||`\xA0`},t)})}):(0,Z.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.`})})]}),m&&(0,Z.jsx)(`div`,{onClick:()=>h(null),style:{position:`absolute`,inset:0,background:`rgba(0,0,0,0.5)`,display:`flex`,alignItems:`center`,justifyContent:`center`,zIndex:10},children:(0,Z.jsxs)(`div`,{onClick:e=>e.stopPropagation(),style:{background:`#0d0f1d`,border:`1px solid rgba(255,255,255,0.1)`,borderRadius:10,padding:18,maxWidth:380,color:`#e2e8f5`},children:[(0,Z.jsx)(`div`,{style:{fontSize:14,fontWeight:600,marginBottom:8},children:`Restore this checkpoint?`}),(0,Z.jsxs)(`div`,{style:{fontSize:12,color:`rgba(255,255,255,0.7)`,marginBottom:12},children:[`The file will be overwritten with its state at `,(0,Z.jsx)(`code`,{children:m.slice(0,8)}),`. A NEW checkpoint of the current state is taken first, so you can always come back.`]}),(0,Z.jsxs)(`div`,{style:{display:`flex`,gap:8,justifyContent:`flex-end`},children:[(0,Z.jsx)(`button`,{onClick:()=>h(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`}),(0,Z.jsx)(`button`,{onClick:ee,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`})]})]})})]})}var Fm=5e3,Im={planning:`#a5b4fc`,delegating:`#60a5fa`,observing:`#22d3ee`,iterating:`#f59e0b`,verifying:`#a78bfa`,reporting:`#34d399`,blocked:`#facc15`,escalated:`#fb7185`,done:`#34d399`,failed:`#ef4444`,cancelled:`#737373`};function Lm(e){if(!Number.isFinite(e)||e<0)return`—`;let t=Math.floor(e/1e3);if(t<60)return`${t}s`;let n=Math.floor(t/60);return n<60?`${n}m`:`${Math.floor(n/60)}h ${n%60}m`}function Rm(e){return e===0?`$0`:e<.01?`$<0.01`:`$${e.toFixed(2)}`}function zm(){let[e,t]=(0,N.useState)([]),[n,r]=(0,N.useState)(!0),[i,a]=(0,N.useState)(null),[o,s]=(0,N.useState)(!1),[c,l]=(0,N.useState)(``),[u,d]=(0,N.useState)(2),[f,p]=(0,N.useState)(!1),[m,h]=(0,N.useState)(null),g=(0,N.useCallback)(async()=>{try{let e=await j(`/api/missions/active`);if(!e.ok)throw Error(`${e.status} ${e.statusText}`);let n=await e.json();t(n.missions||[]),a(null)}catch(e){a(e.message||`failed to load`)}finally{r(!1)}},[]);(0,N.useEffect)(()=>{g();let e=setInterval(g,Fm);return()=>clearInterval(e)},[g]);let _=(0,N.useCallback)((e,t)=>{h({kind:e,message:t}),setTimeout(()=>h(null),5e3)},[]),v=(0,N.useCallback)(async()=>{let e=c.trim();if(e.length<10){_(`err`,`Describe the mission (>=10 chars).`);return}p(!0);try{let t=await j(`/api/mission/run`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({description:e,budgetUsd:u})});if(!t.ok)throw Error(`${t.status} ${t.statusText}`);let n=await t.json();_(`ok`,n.message||`Mission "${n.goal?.title??`?`}" launched.`),l(``),s(!1),g()}catch(e){_(`err`,e.message||`launch failed`)}finally{p(!1)}},[c,u,g,_]),y=(0,N.useCallback)(async e=>{try{let t=await j(`/api/mission/${encodeURIComponent(e)}/cancel`,{method:`POST`});if(!t.ok)throw Error(`${t.status} ${t.statusText}`);_(`ok`,`Mission marked for cancellation.`),g()}catch(e){_(`err`,e.message||`cancel failed`)}},[g,_]),b=(0,N.useMemo)(()=>{let t={delegating:0,observing:1,iterating:2,verifying:3,planning:4,reporting:5,blocked:6,escalated:7};return[...e].sort((e,n)=>(t[e.phase]??99)-(t[n.phase]??99))},[e]);return(0,Z.jsxs)(`div`,{style:{width:`100%`,height:`100%`,display:`flex`,flexDirection:`column`,color:`#e2e8f5`,background:`transparent`},children:[(0,Z.jsxs)(`div`,{style:{padding:`10px 14px`,borderBottom:`1px solid rgba(255,255,255,0.06)`,display:`flex`,alignItems:`center`,justifyContent:`space-between`},children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`div`,{style:{fontSize:13,fontWeight:600},children:`Mission Driver`}),(0,Z.jsxs)(`div`,{style:{fontSize:10,color:`rgba(255,255,255,0.45)`},children:[e.length,` active · polling every `,Fm/1e3,`s`]})]}),(0,Z.jsxs)(`div`,{style:{display:`flex`,gap:6},children:[(0,Z.jsx)(`button`,{onClick:()=>s(e=>!e),title:`Launch a new autonomous mission`,style:{fontSize:11,padding:`4px 10px`,borderRadius:6,border:`1px solid rgba(99,102,241,0.4)`,background:o?`rgba(99,102,241,0.25)`:`rgba(99,102,241,0.12)`,color:`#c7d2fe`,cursor:`pointer`},children:o?`× Close`:`+ New mission`}),(0,Z.jsx)(`button`,{onClick:g,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:`↻`})]})]}),m&&(0,Z.jsx)(`div`,{style:{margin:`8px 14px 0`,padding:`6px 10px`,borderRadius:6,fontSize:11,background:m.kind===`ok`?`rgba(34,197,94,0.12)`:`rgba(239,68,68,0.12)`,border:`1px solid ${m.kind===`ok`?`rgba(34,197,94,0.3)`:`rgba(239,68,68,0.3)`}`,color:m.kind===`ok`?`#86efac`:`#fca5a5`},children:m.message}),o&&(0,Z.jsxs)(`div`,{style:{padding:12,borderBottom:`1px solid rgba(255,255,255,0.06)`,background:`rgba(99,102,241,0.04)`},children:[(0,Z.jsx)(`div`,{style:{fontSize:10,textTransform:`uppercase`,letterSpacing:.6,color:`#a5b4fc`,marginBottom:6},children:`Describe the mission`}),(0,Z.jsx)(`textarea`,{value:c,onChange:e=>l(e.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`}}),(0,Z.jsxs)(`div`,{style:{display:`flex`,justifyContent:`space-between`,alignItems:`center`,marginTop:8,gap:8},children:[(0,Z.jsxs)(`label`,{style:{fontSize:11,color:`rgba(255,255,255,0.6)`},children:[`Budget cap: $`,(0,Z.jsx)(`input`,{type:`number`,value:u,onChange:e=>d(Math.max(.05,Math.min(50,Number(e.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`}})]}),(0,Z.jsx)(`button`,{onClick:v,disabled:f||c.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`})]})]}),(0,Z.jsxs)(`div`,{style:{flex:1,overflow:`auto`,padding:8},children:[i&&(0,Z.jsx)(`div`,{style:{padding:10,color:`#fca5a5`,fontSize:11},children:i}),n&&e.length===0?(0,Z.jsx)(`div`,{style:{padding:16,color:`rgba(255,255,255,0.4)`,fontSize:12},children:`Loading missions…`}):b.length===0?(0,Z.jsxs)(`div`,{style:{padding:24,color:`rgba(255,255,255,0.45)`,fontSize:12,textAlign:`center`},children:[`No active missions.`,(0,Z.jsx)(`br`,{}),(0,Z.jsx)(`span`,{style:{fontSize:11,color:`rgba(255,255,255,0.35)`},children:`Click "+ New mission" to launch one.`})]}):b.map(e=>{let t=Im[e.phase]??`#94a3b8`,n=e.subtasks.total>0?Math.round(e.subtasks.completed/e.subtasks.total*100):0;return(0,Z.jsxs)(`div`,{style:{padding:`10px 12px`,marginBottom:6,borderRadius:8,background:`rgba(255,255,255,0.025)`,border:`1px solid ${e.phase===`blocked`?`rgba(250,204,21,0.4)`:`rgba(255,255,255,0.06)`}`},children:[(0,Z.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,justifyContent:`space-between`,marginBottom:4},children:[(0,Z.jsx)(`div`,{style:{fontSize:12,fontWeight:600,color:`#fafafa`,flex:1,overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`},title:e.title,children:e.title}),(0,Z.jsx)(`button`,{onClick:()=>y(e.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`})]}),(0,Z.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:8,fontSize:10,color:`rgba(255,255,255,0.7)`},children:[(0,Z.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:e.phase}),(0,Z.jsxs)(`span`,{children:[e.subtasks.completed,`/`,e.subtasks.total,` subtasks (`,n,`%)`]}),(0,Z.jsx)(`span`,{children:`·`}),(0,Z.jsx)(`span`,{children:Rm(e.budget.costUsd)}),(0,Z.jsx)(`span`,{children:`·`}),(0,Z.jsx)(`span`,{children:Lm(Date.now()-new Date(e.startedAt).getTime())})]}),e.blockedReason&&(0,Z.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:[(0,Z.jsx)(`strong`,{children:`Blocked:`}),` `,e.blockedReason.question??`(no reason)`]}),e.lastHistory.length>0&&(0,Z.jsx)(`div`,{style:{marginTop:6,fontSize:10,color:`rgba(255,255,255,0.45)`,display:`flex`,flexDirection:`column`,gap:1},children:e.lastHistory.slice(-3).map((e,t)=>(0,Z.jsxs)(`div`,{style:{display:`flex`,gap:6,overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`},children:[(0,Z.jsx)(`span`,{style:{color:Im[e.phase]??`rgba(255,255,255,0.6)`,minWidth:70,fontFamily:`ui-monospace, monospace`,fontSize:9},children:e.phase}),(0,Z.jsx)(`span`,{style:{flex:1,overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`},children:e.note??``})]},t))})]},e.goalId)})]})]})}var Bm=6e4,Vm=[{label:`6h`,hours:6},{label:`24h`,hours:24},{label:`7d`,hours:168}];function Hm(e){return e===0?`$0`:e<.01?`$<0.01`:`$${e.toFixed(2)}`}function Um(e){return e<1e3?String(e):e<1e6?`${(e/1e3).toFixed(1)}k`:`${(e/1e6).toFixed(2)}M`}function Wm(){let[e,t]=(0,N.useState)(24),[n,r]=(0,N.useState)(null),[i,a]=(0,N.useState)(!0),[o,s]=(0,N.useState)(null),c=(0,N.useCallback)(async()=>{a(!0);try{let t=await j(`/api/missions/digest?hours=${e}`);if(!t.ok)throw Error(`${t.status} ${t.statusText}`);let n=await t.json();r(n),s(null)}catch(e){s(e.message||`failed`)}finally{a(!1)}},[e]);return(0,N.useEffect)(()=>{c();let e=setInterval(c,Bm);return()=>clearInterval(e)},[c]),(0,Z.jsxs)(`div`,{style:{width:`100%`,height:`100%`,display:`flex`,flexDirection:`column`,color:`#e2e8f5`,background:`transparent`},children:[(0,Z.jsxs)(`div`,{style:{padding:`10px 14px`,borderBottom:`1px solid rgba(255,255,255,0.06)`,display:`flex`,alignItems:`center`,justifyContent:`space-between`},children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`div`,{style:{fontSize:13,fontWeight:600},children:`Daily digest`}),(0,Z.jsx)(`div`,{style:{fontSize:10,color:`rgba(255,255,255,0.45)`},children:`what TITAN did while you were away`})]}),(0,Z.jsx)(`div`,{style:{display:`flex`,gap:4},children:Vm.map(n=>(0,Z.jsx)(`button`,{onClick:()=>t(n.hours),style:{fontSize:10,padding:`3px 8px`,borderRadius:4,border:`1px solid rgba(255,255,255,0.1)`,background:e===n.hours?`rgba(99,102,241,0.25)`:`rgba(255,255,255,0.03)`,color:e===n.hours?`#c7d2fe`:`rgba(255,255,255,0.65)`,cursor:`pointer`},children:n.label},n.label))})]}),n&&(0,Z.jsxs)(`div`,{style:{padding:`10px 14px`,borderBottom:`1px solid rgba(255,255,255,0.04)`,display:`grid`,gridTemplateColumns:`repeat(4, 1fr)`,gap:8},children:[(0,Z.jsx)(Gm,{label:`Done`,value:n.stats.completed,color:`#34d399`}),(0,Z.jsx)(Gm,{label:`Failed`,value:n.stats.failed,color:n.stats.failed>0?`#fca5a5`:`rgba(255,255,255,0.5)`}),(0,Z.jsx)(Gm,{label:`Active`,value:n.stats.active,color:`#60a5fa`}),(0,Z.jsx)(Gm,{label:`Blocked`,value:n.stats.blocked,color:n.stats.blocked>0?`#facc15`:`rgba(255,255,255,0.5)`})]}),n&&(n.stats.totalCostUsd>0||n.stats.totalTokens>0)&&(0,Z.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:[(0,Z.jsxs)(`span`,{children:[`Spend: `,(0,Z.jsx)(`strong`,{style:{color:`#e2e8f5`},children:Hm(n.stats.totalCostUsd)})]}),(0,Z.jsxs)(`span`,{children:[`Tokens: `,(0,Z.jsx)(`strong`,{style:{color:`#e2e8f5`},children:Um(n.stats.totalTokens)})]})]}),(0,Z.jsxs)(`div`,{style:{flex:1,overflow:`auto`,padding:14},children:[i&&!n&&(0,Z.jsx)(`div`,{style:{color:`rgba(255,255,255,0.4)`,fontSize:11},children:`Loading…`}),o&&(0,Z.jsx)(`div`,{style:{color:`#fca5a5`,fontSize:11},children:o}),n&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.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:n.summaryText||`(no activity in this window)`}),n.recentLessons.length>0&&(0,Z.jsxs)(`div`,{style:{marginTop:16,paddingTop:12,borderTop:`1px solid rgba(255,255,255,0.06)`},children:[(0,Z.jsx)(`div`,{style:{fontSize:10,textTransform:`uppercase`,letterSpacing:.6,color:`#a5b4fc`,marginBottom:6},children:`Lessons learned (Reflexion)`}),n.recentLessons.map((e,t)=>(0,Z.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:[`• `,e]},t))]})]})]})]})}function Gm({label:e,value:t,color:n}){return(0,Z.jsxs)(`div`,{style:{textAlign:`center`,padding:`6px 4px`,borderRadius:6,background:`rgba(255,255,255,0.02)`},children:[(0,Z.jsx)(`div`,{style:{fontSize:18,fontWeight:700,color:n,lineHeight:1},children:t}),(0,Z.jsx)(`div`,{style:{fontSize:9,color:`rgba(255,255,255,0.5)`,textTransform:`uppercase`,letterSpacing:.5,marginTop:4},children:e})]})}var Km={pending:`#737373`,running:`#60a5fa`,done:`#34d399`,failed:`#ef4444`,skipped:`#a78bfa`},qm=6e3,Jm=180,Ym=64,Xm=96,Zm=24;function Qm(e){let t=new Map,n=new Map(e.map(e=>[e.id,e])),r=(e,i)=>{if(t.has(e))return t.get(e);if(i.has(e))return 0;let a=n.get(e);if(!a)return 0;i.add(e);let o=(a.dependsOn??[]).filter(e=>n.has(e)),s=o.length===0?0:Math.max(...o.map(e=>r(e,i)))+1;return i.delete(e),t.set(e,s),s};for(let t of e)r(t.id,new Set);return t}function $m(){let[e,t]=(0,N.useState)([]),[n,r]=(0,N.useState)(null),[i,a]=(0,N.useState)(null),[o,s]=(0,N.useState)(null),[c,l]=(0,N.useState)(null),u=(0,N.useCallback)(async()=>{try{let e=await j(`/api/missions/active`);if(!e.ok)throw Error(`${e.status} ${e.statusText}`);let i=(await e.json()).missions||[];t(i),!n&&i.length>0&&r(i[0].goalId)}catch(e){s(e.message||`failed`)}},[n]),d=(0,N.useCallback)(async e=>{try{let t=await j(`/api/mission/${encodeURIComponent(e)}`);if(!t.ok)throw Error(`${t.status} ${t.statusText}`);let n=await t.json();a(n),s(null)}catch(e){s(e.message||`failed to load mission`),a(null)}},[]);(0,N.useEffect)(()=>{u();let e=setInterval(u,qm);return()=>clearInterval(e)},[u]),(0,N.useEffect)(()=>{if(!n){a(null);return}d(n);let e=setInterval(()=>d(n),qm);return()=>clearInterval(e)},[n,d]);let{layout:f,edges:p,viewBox:m}=(0,N.useMemo)(()=>{if(!i?.goal.subtasks)return{layout:[],edges:[],viewBox:`0 0 600 200`};let e=i.goal.subtasks,t=Qm(e),n=new Map;for(let r of e){let e=t.get(r.id)??0;n.has(e)||n.set(e,[]),n.get(e).push(r)}let r=Array.from(n.keys()).sort((e,t)=>e-t),a=Math.max(...Array.from(n.values()).map(e=>e.length),1),o=Math.max(640,a*204+Zm),s=r.length*Xm+Ym+40,c=new Map,l=[];for(let e of r){let t=n.get(e),r=(o-(t.length*Jm+(t.length-1)*Zm))/2,i=e*Xm+20;for(let e=0;e<t.length;e++){let n=r+e*204;c.set(t[e].id,{x:n,y:i}),l.push({...t[e],x:n,y:i})}}let u=[];for(let t of e){let e=c.get(t.id);if(e)for(let n of t.dependsOn??[]){let r=c.get(n);r&&u.push({from:n,to:t.id,x1:r.x+Jm/2,y1:r.y+Ym,x2:e.x+Jm/2,y2:e.y})}}return{layout:l,edges:u,viewBox:`0 0 ${o} ${s}`}},[i]),h=(0,N.useMemo)(()=>new Map((i?.goal.subtasks??[]).map(e=>[e.id,e])),[i]),g=c?h.get(c):null;return(0,Z.jsxs)(`div`,{style:{width:`100%`,height:`100%`,display:`flex`,flexDirection:`column`,color:`#e2e8f5`,background:`transparent`},children:[(0,Z.jsxs)(`div`,{style:{padding:`10px 14px`,borderBottom:`1px solid rgba(255,255,255,0.06)`,display:`flex`,alignItems:`center`,gap:10},children:[(0,Z.jsxs)(`div`,{style:{flex:1},children:[(0,Z.jsx)(`div`,{style:{fontSize:13,fontWeight:600},children:`Mission graph`}),(0,Z.jsxs)(`div`,{style:{fontSize:10,color:`rgba(255,255,255,0.45)`},children:[e.length,` active mission(s) · subtask DAG`]})]}),e.length>0&&(0,Z.jsx)(`select`,{value:n??``,onChange:e=>r(e.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:e.map(e=>(0,Z.jsxs)(`option`,{value:e.goalId,children:[e.title,` [`,e.phase,`]`]},e.goalId))})]}),o&&(0,Z.jsx)(`div`,{style:{padding:10,color:`#fca5a5`,fontSize:11},children:o}),(0,Z.jsxs)(`div`,{style:{flex:1,display:`flex`,overflow:`hidden`},children:[(0,Z.jsx)(`div`,{style:{flex:1,overflow:`auto`,padding:14},children:i?f.length===0?(0,Z.jsx)(`div`,{style:{padding:24,color:`rgba(255,255,255,0.45)`,fontSize:12,textAlign:`center`},children:`This mission has no subtasks yet.`}):(0,Z.jsxs)(`svg`,{viewBox:m,style:{width:`100%`,height:`auto`},role:`img`,"aria-label":`Mission subtask DAG`,children:[(0,Z.jsx)(`defs`,{children:(0,Z.jsx)(`marker`,{id:`mg-arrow`,viewBox:`0 0 10 10`,refX:`10`,refY:`5`,markerWidth:`6`,markerHeight:`6`,orient:`auto-start-reverse`,children:(0,Z.jsx)(`path`,{d:`M 0 0 L 10 5 L 0 10 z`,fill:`rgba(255,255,255,0.35)`})})}),p.map((e,t)=>(0,Z.jsx)(`line`,{x1:e.x1,y1:e.y1,x2:e.x2,y2:e.y2,stroke:`rgba(255,255,255,0.25)`,strokeWidth:`1.4`,markerEnd:`url(#mg-arrow)`},`e-${t}`)),f.map(e=>{let t=i.driver?.currentSubtaskId===e.id,n=Km[e.status],r=c===e.id;return(0,Z.jsxs)(`g`,{transform:`translate(${e.x}, ${e.y})`,onClick:()=>l(e.id),style:{cursor:`pointer`},children:[(0,Z.jsx)(`rect`,{width:Jm,height:Ym,rx:`8`,fill:t?`${n}22`:`rgba(255,255,255,0.04)`,stroke:r||t?n:`${n}55`,strokeWidth:t||r?2:1}),(0,Z.jsx)(`circle`,{cx:14,cy:14,r:`5`,fill:n,children:e.status===`running`&&(0,Z.jsx)(`animate`,{attributeName:`r`,values:`4;6;4`,dur:`1.2s`,repeatCount:`indefinite`})}),(0,Z.jsx)(`text`,{x:28,y:18,fontSize:`11`,fontWeight:`600`,fill:`#fafafa`,children:e.title.length>22?e.title.slice(0,21)+`…`:e.title}),(0,Z.jsxs)(`text`,{x:28,y:34,fontSize:`9`,fill:`rgba(255,255,255,0.55)`,letterSpacing:`0.5`,style:{textTransform:`uppercase`},children:[e.status,e.retries>0?` · ${e.retries} retr${e.retries===1?`y`:`ies`}`:``]}),(0,Z.jsxs)(`text`,{x:14,y:52,fontSize:`9`,fill:`rgba(255,255,255,0.45)`,children:[(e.description||``).slice(0,30),(e.description||``).length>30?`…`:``]}),t&&(0,Z.jsx)(`text`,{x:Jm-8,y:14,fontSize:`8`,fill:n,textAnchor:`end`,fontWeight:`700`,children:`NOW`})]},e.id)})]}):(0,Z.jsx)(`div`,{style:{padding:24,color:`rgba(255,255,255,0.45)`,fontSize:12,textAlign:`center`},children:e.length===0?`No active missions. Launch one via the Mission Driver widget.`:`Select a mission to view its graph.`})}),g&&(0,Z.jsxs)(`div`,{style:{width:260,borderLeft:`1px solid rgba(255,255,255,0.06)`,padding:14,overflow:`auto`,fontSize:11},children:[(0,Z.jsxs)(`div`,{style:{display:`flex`,justifyContent:`space-between`,alignItems:`flex-start`,marginBottom:8},children:[(0,Z.jsx)(`div`,{style:{fontSize:12,fontWeight:700,color:`#fafafa`,flex:1},children:g.title}),(0,Z.jsx)(`button`,{onClick:()=>l(null),style:{background:`transparent`,border:`none`,color:`rgba(255,255,255,0.5)`,cursor:`pointer`,fontSize:14,padding:0,marginLeft:6},children:`×`})]}),(0,Z.jsxs)(`div`,{style:{marginBottom:8},children:[(0,Z.jsx)(`span`,{style:{padding:`2px 8px`,borderRadius:4,fontSize:9,fontWeight:600,textTransform:`uppercase`,letterSpacing:.5,background:`${Km[g.status]}22`,border:`1px solid ${Km[g.status]}55`,color:Km[g.status]},children:g.status}),g.retries>0&&(0,Z.jsxs)(`span`,{style:{marginLeft:6,color:`rgba(255,255,255,0.5)`},children:[g.retries,` retries`]})]}),(0,Z.jsx)(`div`,{style:{color:`rgba(255,255,255,0.85)`,lineHeight:1.5,marginBottom:10},children:g.description}),g.dependsOn.length>0&&(0,Z.jsxs)(`div`,{style:{color:`rgba(255,255,255,0.55)`,fontSize:10,marginBottom:6},children:[(0,Z.jsx)(`strong`,{children:`Depends on:`}),` `,g.dependsOn.map(e=>h.get(e)?.title||e).join(`, `)]}),g.completedAt&&(0,Z.jsxs)(`div`,{style:{color:`rgba(255,255,255,0.45)`,fontSize:10},children:[`Completed: `,new Date(g.completedAt).toLocaleString()]})]})]}),i&&(0,Z.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:[(0,Z.jsxs)(`span`,{children:[i.goal.subtasks.length,` subtasks · `,i.goal.progress,`% progress`]}),i.driver&&(0,Z.jsxs)(`span`,{children:[i.driver.phase,` · $`,i.driver.budget.costUsd.toFixed(2),` spent`]})]})]})}function eh(){let[e,t]=(0,N.useState)([]),[n,r]=(0,N.useState)(!0),[i,a]=(0,N.useState)(null),o=async()=>{try{let e=await fetch(`/api/agents`);if(!e.ok)throw Error(`HTTP ${e.status}`);let n=await e.json();t(Array.isArray(n)?n:n.agents||[]),a(null)}catch(e){a(e.message)}finally{r(!1)}};return(0,N.useEffect)(()=>{o();let e=setInterval(o,1e4);return()=>clearInterval(e)},[]),n?(0,Z.jsx)(`div`,{className:`w-full h-full flex items-center justify-center`,children:(0,Z.jsx)(Oe,{className:`w-4 h-4 text-[#6366f1] animate-spin`})}):i?(0,Z.jsx)(`div`,{className:`w-full h-full flex items-center justify-center p-4`,children:(0,Z.jsxs)(`div`,{className:`text-center`,children:[(0,Z.jsx)(xe,{className:`w-4 h-4 text-red-400 mx-auto mb-1`}),(0,Z.jsx)(`span`,{className:`text-[10px] text-red-400`,children:i})]})}):e.length===0?(0,Z.jsx)(`div`,{className:`w-full h-full flex items-center justify-center p-4`,children:(0,Z.jsx)(`span`,{className:`text-[10px] text-[#52525b]`,children:`No active agents`})}):(0,Z.jsx)(`div`,{className:`w-full h-full p-3 overflow-auto`,children:(0,Z.jsx)(`div`,{className:`space-y-2`,children:e.map(e=>(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 px-2.5 py-2 rounded-lg bg-[#0a0a0f] border border-[#27272a]`,children:[(0,Z.jsx)(c,{className:`w-3.5 h-3.5 ${e.status===`busy`?`text-[#f59e0b]`:e.status===`error`?`text-red-400`:`text-[#6366f1]`}`}),(0,Z.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Z.jsx)(`div`,{className:`text-[11px] text-[#a1a1aa] truncate`,children:e.name}),(0,Z.jsxs)(`div`,{className:`text-[10px] text-[#52525b] truncate`,children:[e.role,e.model?` · ${e.model}`:``]})]}),(0,Z.jsx)(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full uppercase ${e.status===`busy`?`bg-[#f59e0b]/10 text-[#f59e0b]`:e.status===`error`?`bg-red-400/10 text-red-400`:`bg-[#6366f1]/10 text-[#818cf8]`}`,children:e.status})]},e.id))})})}function th(){let[e,t]=(0,N.useState)(null),[n,r]=(0,N.useState)(!0),i=async()=>{try{let[e,n]=await Promise.allSettled([fetch(`/api/health`).then(e=>e.ok?e.json():null),fetch(`/ollama/api/tags`).then(e=>e.ok)]),r=e.status===`fulfilled`&&e.value,i=n.status===`fulfilled`&&n.value;t({gateway:r,ollama:i,version:r?.version||`unknown`,uptime:r?.uptime||0})}catch{t({gateway:!1,ollama:!1,version:`unknown`,uptime:0})}finally{r(!1)}};return(0,N.useEffect)(()=>{i();let e=setInterval(i,3e4);return()=>clearInterval(e)},[]),n?(0,Z.jsx)(`div`,{className:`w-full h-full flex items-center justify-center`,children:(0,Z.jsx)(Oe,{className:`w-4 h-4 text-[#6366f1] animate-spin`})}):(0,Z.jsx)(`div`,{className:`w-full h-full p-3 overflow-auto`,children:(0,Z.jsxs)(`div`,{className:`space-y-3`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between px-2.5 py-2 rounded-lg bg-[#0a0a0f] border border-[#27272a]`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[e?.gateway?(0,Z.jsx)(Ne,{className:`w-3.5 h-3.5 text-emerald-400`}):(0,Z.jsx)(pe,{className:`w-3.5 h-3.5 text-red-400`}),(0,Z.jsx)(`span`,{className:`text-[11px] text-[#a1a1aa]`,children:`TITAN Gateway`})]}),(0,Z.jsx)(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full uppercase ${e?.gateway?`bg-emerald-400/10 text-emerald-400`:`bg-red-400/10 text-red-400`}`,children:e?.gateway?`Online`:`Offline`})]}),(0,Z.jsxs)(`div`,{className:`flex items-center justify-between px-2.5 py-2 rounded-lg bg-[#0a0a0f] border border-[#27272a]`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(ve,{className:`w-3.5 h-3.5 ${e?.ollama?`text-emerald-400`:`text-red-400`}`}),(0,Z.jsx)(`span`,{className:`text-[11px] text-[#a1a1aa]`,children:`Ollama`})]}),(0,Z.jsx)(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full uppercase ${e?.ollama?`bg-emerald-400/10 text-emerald-400`:`bg-red-400/10 text-red-400`}`,children:e?.ollama?`Online`:`Offline`})]}),(0,Z.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,Z.jsxs)(`div`,{className:`px-2.5 py-2 rounded-lg bg-[#0a0a0f] border border-[#27272a]`,children:[(0,Z.jsx)(`div`,{className:`text-[9px] text-[#52525b] uppercase tracking-wider`,children:`Version`}),(0,Z.jsx)(`div`,{className:`text-[11px] text-[#a1a1aa] font-mono mt-0.5`,children:e?.version})]}),(0,Z.jsxs)(`div`,{className:`px-2.5 py-2 rounded-lg bg-[#0a0a0f] border border-[#27272a]`,children:[(0,Z.jsx)(`div`,{className:`text-[9px] text-[#52525b] uppercase tracking-wider`,children:`Uptime`}),(0,Z.jsx)(`div`,{className:`text-[11px] text-[#a1a1aa] font-mono mt-0.5`,children:(e=>`${Math.floor(e/3600)}h ${Math.floor(e%3600/60)}m`)(e?.uptime||0)})]})]})]})})}var nh={background:`var(--theme-paper, var(--color-bg-secondary))`,borderColor:`var(--theme-metal, var(--color-border))`,color:`var(--theme-ink, var(--color-text))`};function rh(e){if(!e.length)return 0;let t=[...e].sort((e,t)=>e-t),n=Math.floor(t.length/2);return t.length%2?t[n]:Math.round((t[n-1]+t[n])/2)}function ih(){let[e,t]=(0,N.useState)(null),[n,r]=(0,N.useState)(``),[i,a]=(0,N.useState)(``),[o,s]=(0,N.useState)(!1),c=(0,N.useCallback)(async()=>{try{let e=await j(`/api/muscle`);e.ok&&t(await e.json())}catch{}},[]);(0,N.useEffect)(()=>{c();let e=setInterval(c,2e4);return()=>clearInterval(e)},[c]);let l=async(e,t)=>{r(e);try{let n=await j(`/api/muscle/${e}/${t}`,{method:`POST`,headers:{"Content-Type":`application/json`},body:`{}`});if(n.ok)t===`adopt`&&window.dispatchEvent(new CustomEvent(`titan:mascot:celebrate`));else{let e=await n.json().catch(()=>null);a(e?.error||`Couldn't ${t} that one — try refreshing.`)}await c()}finally{r(``)}},u=async()=>{if(!o){s(!0),a(`Looking for repeated workflows… if I find one, I'll verify it with a real replay exam — that can take a couple of minutes.`);try{let e=await(await j(`/api/muscle/scan`,{method:`POST`})).json(),t={proposed:`Learned "${e.skill?.name}"! 🎉 It passed its exam — adopt it below.`,"nothing-to-learn":`No repeated workflows yet — keep using TITAN and I'll spot them.`,"failed-exam":`Found a pattern, but it failed its replay exam — so I'm not showing it. (That's the trust part.)`,"pending-cap":`You have proposals waiting below — decide on those first.`,disabled:`Muscle Memory is switched off in settings — turn it on and I'll start learning from your work.`,cooldown:`I learned something recently — I pace myself to one new skill a day.`,"duplicate-race":`Already learned that one — refresh to see it.`};a(t[e.action]||`Scan finished.`),await c()}catch{a(`Scan failed — is the gateway up?`)}finally{s(!1)}}};if(!e)return(0,Z.jsx)(`div`,{className:`p-4 text-xs opacity-60`,children:`Loading Muscle Memory…`});let d=e.skills.filter(e=>e.status===`proposed`),f=e.skills.filter(e=>e.status===`adopted`);return(0,Z.jsxs)(`div`,{className:`w-full h-full overflow-auto p-4 space-y-4`,style:{color:`var(--theme-ink, var(--color-text))`},children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`h3`,{className:`text-sm font-semibold flex items-center gap-1.5`,children:`💪 Muscle Memory`}),(0,Z.jsx)(`p`,{className:`text-[11px] opacity-60`,children:`TITAN turns your repeated workflows into skills — replay-verified before you ever see them.`})]}),(0,Z.jsx)(`button`,{onClick:u,disabled:o,className:`text-[11px] px-2.5 py-1.5 rounded-lg border shrink-0 disabled:opacity-50`,style:{borderColor:`var(--theme-metal)`,color:`var(--theme-accent)`},children:o?`Examining…`:`Scan now`})]}),(0,Z.jsx)(`div`,{className:`grid ${e.stats.medianSpeedupMs>0?`grid-cols-4`:`grid-cols-3`} gap-2 text-center`,children:[{label:`skills learned`,value:String(e.stats.learned)},{label:`adopted`,value:String(e.stats.adopted)},{label:`skill runs`,value:String(e.stats.totalRuns)},...e.stats.medianSpeedupMs>0?[{label:`saved per run`,value:`~${Math.round(e.stats.medianSpeedupMs/1e3)}s`}]:[]].map(e=>(0,Z.jsxs)(`div`,{className:`rounded-xl border py-2`,style:nh,children:[(0,Z.jsx)(`div`,{className:`text-lg font-semibold`,children:e.value}),(0,Z.jsx)(`div`,{className:`text-[10px] opacity-60`,children:e.label})]},e.label))}),i&&(0,Z.jsx)(`div`,{className:`text-[11px] rounded-lg border px-3 py-2`,style:nh,children:i}),d.length>0&&(0,Z.jsxs)(`div`,{className:`space-y-2`,children:[(0,Z.jsx)(`div`,{className:`text-[11px] font-medium opacity-70 uppercase tracking-wide`,children:`Waiting for you`}),d.map(e=>(0,Z.jsxs)(`div`,{className:`rounded-xl border p-3 space-y-2`,style:nh,children:[(0,Z.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsxs)(`div`,{className:`text-[13px] font-semibold`,children:[e.name,` `,(0,Z.jsxs)(`span`,{className:`font-mono text-[11px] opacity-60`,children:[`/`,e.slashCommand]})]}),(0,Z.jsx)(`div`,{className:`text-[11px] opacity-70`,children:e.description})]}),(0,Z.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded-md border shrink-0`,style:{borderColor:`#3f9142`,color:`#5cb860`},children:`✓ exam passed`})]}),(0,Z.jsx)(`div`,{className:`text-[10px] font-mono opacity-50`,children:e.toolSequence.join(` → `)}),(0,Z.jsxs)(`div`,{className:`text-[10px] opacity-60`,children:[`Learned from `,e.evidence.length,` of your tasks, e.g. “`,e.evidence[0]?.task.slice(0,80),`”`]}),(0,Z.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Z.jsx)(`button`,{disabled:n===e.id,onClick:()=>l(e.id,`adopt`),className:`flex-1 text-[12px] font-semibold px-3 py-1.5 rounded-lg border disabled:opacity-50`,style:{background:`var(--theme-accent)`,color:`var(--theme-paper, #fff)`,borderColor:`var(--theme-accent)`},children:n===e.id?`…`:`Adopt`}),(0,Z.jsx)(`button`,{disabled:n===e.id,onClick:()=>l(e.id,`dismiss`),className:`text-[12px] px-3 py-1.5 rounded-lg border disabled:opacity-50`,style:{borderColor:`var(--theme-metal)`},children:`Not for me`})]})]},e.id))]}),f.length>0&&(0,Z.jsxs)(`div`,{className:`space-y-2`,children:[(0,Z.jsx)(`div`,{className:`text-[11px] font-medium opacity-70 uppercase tracking-wide`,children:`Adopted skills`}),f.map(e=>{let t=e.runs?.length||0;return(0,Z.jsxs)(`div`,{className:`rounded-xl border p-3 flex items-center justify-between gap-2`,style:nh,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsxs)(`div`,{className:`text-[12px] font-semibold`,children:[e.name,` `,(0,Z.jsxs)(`span`,{className:`font-mono text-[11px] opacity-60`,children:[`/`,e.slashCommand]})]}),(0,Z.jsxs)(`div`,{className:`text-[10px] opacity-60`,children:[t,` run`,t===1?``:`s`,e.baselineDurationMs&&t>0&&e.runs?` · ~${Math.max(0,Math.round((e.baselineDurationMs-rh(e.runs.map(e=>e.durationMs)))/1e3))}s faster than doing it manually`:``]})]}),(0,Z.jsx)(`span`,{className:`text-lg`,children:`💪`})]},e.id)})]}),d.length===0&&f.length===0&&(0,Z.jsx)(`div`,{className:`text-[11px] opacity-60 rounded-xl border p-4 text-center`,style:nh,children:e.skills.some(e=>e.status===`failed-exam`)?`I spotted ${e.skills.filter(e=>e.status===`failed-exam`).length} repeated pattern${e.skills.filter(e=>e.status===`failed-exam`).length===1?``:`s`} but couldn't verify ${e.skills.filter(e=>e.status===`failed-exam`).length===1?`it`:`them`} yet — I only show you skills that pass their exam.`:`Nothing learned yet. Use TITAN normally — when a workflow repeats a few times, it teaches itself and asks you here.`})]})}function ah({label:e,value:t,icon:n,color:r,unknown:i}){let a=Math.max(0,Math.min(100,Math.round(t)));return(0,Z.jsxs)(`div`,{className:`px-2.5 py-2 rounded-lg bg-[#0a0a0f] border border-[#27272a]`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between mb-1.5`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[n,(0,Z.jsx)(`span`,{className:`text-[10px] text-[#52525b] uppercase tracking-wider`,children:e})]}),(0,Z.jsx)(`span`,{className:`text-[11px] text-[#a1a1aa] font-mono`,children:i?`—`:`${a}%`})]}),(0,Z.jsx)(`div`,{className:`h-1.5 rounded-full bg-[#27272a] overflow-hidden`,children:(0,Z.jsx)(`div`,{className:`h-full rounded-full transition-all duration-500`,style:{width:i?`0%`:`${a}%`,backgroundColor:r}})})]})}function oh(){let[e,t]=(0,N.useState)({cpu:0,memory:0,disk:0,load:0,loaded:!1,error:null,diskAvailable:!0});(0,N.useEffect)(()=>{let e=!1;async function n(){try{let n=await j(`/api/stats`);if(!n.ok){let r=`HTTP ${n.status}`;e||t(e=>({...e,loaded:!0,error:r}));return}let r=await n.json();if(e)return;let i=r.host;if(!i){t(e=>({...e,loaded:!0,error:`no host metrics`}));return}let a=typeof i.cpuPercent==`number`?i.cpuPercent:0,o=typeof i.memPercent==`number`?i.memPercent:0,s=typeof i.diskPercent==`number`?i.diskPercent:0,c=i.cores||1,l=typeof i.loadAvg1==`number`?Math.min(100,i.loadAvg1/c*100):0;t({cpu:a,memory:o,disk:s,load:l,loaded:!0,error:null,diskAvailable:!i.diskError})}catch(n){e||t(e=>({...e,loaded:!0,error:n.message}))}}n();let r=setInterval(n,3e3);return()=>{e=!0,clearInterval(r)}},[]);let n=!e.loaded||!!e.error;return(0,Z.jsxs)(`div`,{className:`w-full h-full p-3 overflow-auto`,children:[(0,Z.jsxs)(`div`,{className:`space-y-2`,children:[(0,Z.jsx)(ah,{label:`CPU`,value:e.cpu,icon:(0,Z.jsx)(Se,{className:`w-3 h-3 text-[#6366f1]`}),color:`#6366f1`,unknown:n}),(0,Z.jsx)(ah,{label:`Memory`,value:e.memory,icon:(0,Z.jsx)(We,{className:`w-3 h-3 text-[#a78bfa]`}),color:`#a78bfa`,unknown:n}),(0,Z.jsx)(ah,{label:`Disk`,value:e.disk,icon:(0,Z.jsx)(He,{className:`w-3 h-3 text-[#10b981]`}),color:`#10b981`,unknown:n||!e.diskAvailable}),(0,Z.jsx)(ah,{label:`Load`,value:e.load,icon:(0,Z.jsx)(ve,{className:`w-3 h-3 text-[#f59e0b]`}),color:`#f59e0b`,unknown:n})]}),e.error&&(0,Z.jsx)(`div`,{className:`mt-2 text-[10px] text-[#ef4444]/80`,children:e.error})]})}var sh=[{label:`Nav`,source:`system:nav`,w:3,h:4,icon:(0,Z.jsx)(Je,{className:`w-3.5 h-3.5`})},{label:`Agents`,source:`system:agents`,w:3,h:4,icon:(0,Z.jsx)(c,{className:`w-3.5 h-3.5`})},{label:`Health`,source:`system:health`,w:3,h:3,icon:(0,Z.jsx)(ve,{className:`w-3.5 h-3.5`})},{label:`Stats`,source:`system:stats`,w:3,h:4,icon:(0,Z.jsx)(Xe,{className:`w-3.5 h-3.5`})},{label:`Chat`,source:`system:chat`,w:4,h:5,icon:(0,Z.jsx)(re,{className:`w-3.5 h-3.5`})},{label:`Files`,source:`system:files`,w:4,h:6,icon:(0,Z.jsx)(v,{className:`w-3.5 h-3.5`})},{label:`Skills`,source:`system:tools`,w:5,h:4,icon:(0,Z.jsx)(Pe,{className:`w-3.5 h-3.5`})},{label:`Soma`,source:`system:soma`,w:6,h:6,icon:(0,Z.jsx)(he,{className:`w-3.5 h-3.5`})},{label:`Intel`,source:`system:intelligence`,w:6,h:5,icon:(0,Z.jsx)(_e,{className:`w-3.5 h-3.5`})},{label:`Infra`,source:`system:infra`,w:6,h:4,icon:(0,Z.jsx)(le,{className:`w-3.5 h-3.5`})},{label:`Tools`,source:`system:tools`,w:5,h:4,icon:(0,Z.jsx)(ke,{className:`w-3.5 h-3.5`})},{label:`Settings`,source:`system:settings`,w:4,h:6,icon:(0,Z.jsx)(ue,{className:`w-3.5 h-3.5`})},{label:`Wiki`,source:`system:memory-wiki`,w:5,h:5,icon:(0,Z.jsx)(s,{className:`w-3.5 h-3.5`})},{label:`Research`,source:`system:autoresearch`,w:5,h:5,icon:(0,Z.jsx)(y,{className:`w-3.5 h-3.5`})},{label:`Proposals`,source:`system:self-proposals`,w:5,h:5,icon:(0,Z.jsx)(x,{className:`w-3.5 h-3.5`})},{label:`Muscle Memory`,source:`system:muscle-memory`,w:5,h:6,icon:(0,Z.jsx)(x,{className:`w-3.5 h-3.5`})},{label:`Overview`,source:`system:overview`,w:5,h:4,icon:(0,Z.jsx)(ge,{className:`w-3.5 h-3.5`})},{label:`Sessions`,source:`system:sessions`,w:5,h:4,icon:(0,Z.jsx)(h,{className:`w-3.5 h-3.5`})},{label:`Watch`,source:`system:watch`,w:6,h:5,icon:(0,Z.jsx)(ve,{className:`w-3.5 h-3.5`})},{label:`Backup`,source:`system:backup`,w:5,h:5,icon:(0,Z.jsx)(o,{className:`w-3.5 h-3.5`})},{label:`Training`,source:`system:training`,w:5,h:5,icon:(0,Z.jsx)(_e,{className:`w-3.5 h-3.5`})},{label:`Recipes`,source:`system:recipes`,w:5,h:5,icon:(0,Z.jsx)(s,{className:`w-3.5 h-3.5`})},{label:`VRAM`,source:`system:vram`,w:5,h:5,icon:(0,Z.jsx)(Se,{className:`w-3.5 h-3.5`})},{label:`Teams`,source:`system:teams`,w:5,h:5,icon:(0,Z.jsx)(Ve,{className:`w-3.5 h-3.5`})},{label:`Cron`,source:`system:cron`,w:5,h:5,icon:(0,Z.jsx)(h,{className:`w-3.5 h-3.5`})},{label:`Checkpoints`,source:`system:checkpoints`,w:5,h:5,icon:(0,Z.jsx)(k,{className:`w-3.5 h-3.5`})},{label:`Organism`,source:`system:organism`,w:5,h:5,icon:(0,Z.jsx)(Ae,{className:`w-3.5 h-3.5`})},{label:`Fleet`,source:`system:fleet`,w:5,h:5,icon:(0,Z.jsx)(oe,{className:`w-3.5 h-3.5`})},{label:`Browser`,source:`system:browser`,w:5,h:5,icon:(0,Z.jsx)(Te,{className:`w-3.5 h-3.5`})},{label:`Eval`,source:`system:eval`,w:5,h:5,icon:(0,Z.jsx)(E,{className:`w-3.5 h-3.5`})}];function ch(){let e=(e,t,n)=>{window.dispatchEvent(new CustomEvent(`titan:widget:add`,{detail:{source:e,w:t,h:n}}))};return(0,Z.jsx)(`div`,{className:`w-full h-full p-3 overflow-auto`,children:(0,Z.jsx)(`div`,{className:`grid grid-cols-2 gap-1.5`,children:sh.map(t=>(0,Z.jsxs)(`button`,{onClick:()=>e(t.source,t.w,t.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:[(0,Z.jsx)(`span`,{className:`text-[#6366f1]`,children:t.icon}),(0,Z.jsx)(`span`,{className:`text-[10px] font-medium`,children:t.label})]},t.source))})})}var lh=class extends N.Component{componentDidCatch(e){this.props.onError(e.message)}render(){return this.props.children}};function uh({name:e,children:t}){let[n,r]=N.useState(null);return n?(0,Z.jsx)(`div`,{className:`w-full h-full flex items-center justify-center p-4`,children:(0,Z.jsxs)(`span`,{className:`text-xs text-red-400`,children:[e,`: `,n]})}):(0,Z.jsx)(lh,{onError:r,children:t})}var dh=N.lazy(()=>M(()=>import(`./legacy-BIzifT-t.js`).then(e=>({default:e.Responsive})),__vite__mapDeps([105,1,5,3,6,7]))),fh={"system:nav":Yu,"system:home-hero":gf,"system:chat":dd,"system:cmd":zf,"system:soma":Hf,"system:command-post":Jf,"system:intelligence":Xf,"system:memory-graph":Qf,"system:voice":$f,"system:infra":tp,"system:tools":rp,"system:settings":ap,"system:files":op,"system:settings-general":cp,"system:settings-security":up,"system:settings-audit":fp,"system:settings-specialists":hp,"system:settings-privacy":_p,"system:intelligence-autopilot":yp,"system:intelligence-workflows":xp,"system:intelligence-learning":Cp,"system:intelligence-self-improve":Tp,"system:intelligence-personas":Dp,"system:intelligence-persona-profiles":kp,"system:intelligence-dream":jp,"system:infra-homelab":Np,"system:infra-gpu":Fp,"system:infra-files":Lp,"system:infra-logs":zp,"system:infra-telemetry":Vp,"system:tools-skills":Up,"system:tools-mcp":Gp,"system:tools-integrations":qp,"system:tools-channels":Yp,"system:tools-mesh":Zp,"system:agents":eh,"system:health":th,"system:stats":oh,"system:quick-links":ch,"system:memory-wiki":$p,"system:autoresearch":tm,"system:self-proposals":rm,"system:muscle-memory":ih,"system:overview":am,"system:sessions":sm,"system:watch":lm,"system:backup":dm,"system:training":pm,"system:recipes":hm,"system:vram":_m,"system:teams":ym,"system:cron":xm,"system:checkpoints":Cm,"system:organism":Tm,"system:fleet":Dm,"system:browser":km,"system:eval":jm,"system:time-travel":Pm,"system:mission-driver":zm,"system:daily-digest":Wm,"system:mission-graph":$m},ph={lg:12,md:10,sm:6,xs:4,xxs:2},mh=60,hh={lg:1200,md:996,sm:768,xs:480,xxs:0},gh=[12,12],_h=[`se`,`sw`,`ne`,`nw`,`e`,`w`,`n`,`s`],vh=[{source:`system:nav`,name:`Nav`,w:3,h:4,label:`Navigation`,icon:et},{source:`system:agents`,name:`Agents`,w:3,h:4,label:`Agents`,icon:c},{source:`system:health`,name:`Health`,w:3,h:3,label:`Health`,icon:Ze},{source:`system:stats`,name:`Stats`,w:3,h:4,label:`Stats`,icon:l},{source:`system:quick-links`,name:`Quick Links`,w:3,h:4,label:`Links`,icon:ee},{source:`system:chat`,name:`Chat`,w:4,h:5,label:`Chat`,icon:re}],yh=N.forwardRef(({widget:e,space:t,onRemove:n,style:r,className:i,onMouseDown:a,onMouseUp:o,onTouchStart:s,onTouchEnd:c,children:l},u)=>{let d=(0,N.useCallback)(()=>n(e.id),[e.id,n]);return(0,Z.jsxs)(`div`,{ref:u,style:r,className:i,onMouseDown:a,onMouseUp:o,onTouchStart:s,onTouchEnd:c,children:[(0,Z.jsx)(Sh,{widget:e,space:t,onRemove:d}),l]})});yh.displayName=`MemoWidgetItem`;var bh=N.memo(yh);function xh({widget:e,space:t,onRemove:n}){let r=(0,N.useRef)(null),i=(0,N.useRef)(null),a=(0,N.useRef)(t),[o,s]=(0,N.useState)(null),[c,l]=(0,N.useState)(!0);if((0,N.useEffect)(()=>{a.current=t},[t]),(0,N.useEffect)(()=>{if(e.format===`system`||!r.current)return;if(!e.source||e.source.trim()===``){s(`Empty widget — no source code`),l(!1);return}l(!0),s(null),i.current=new Uu(r.current,{onLog:t=>console.log(`[Widget ${e.id}]`,t)}),i.current.setMessageHandler(e=>{let t=a.current;if(e.type===`canvas`&&e.payload?.action===`createWidget`){let n=e.payload.def;if(!n)return{ok:!1,error:"createWidget requires a `def` object"};let r=Number.isFinite(n.w)?n.w:4,i=Number.isFinite(n.h)?n.h:4,a=Number.isFinite(n.x)&&Number.isFinite(n.y)?{x:n.x,y:n.y}:ld(t.widgets||[],r,i);try{let e=X.addWidget(t.id,{name:n.name||`Agent Widget`,format:n.format||`react`,source:n.source||``,x:a.x,y:a.y,w:r,h:i});return window.dispatchEvent(new CustomEvent(`titan:space:refresh`,{detail:{spaceId:t.id}})),{ok:!0,widgetId:e.id}}catch(e){return{ok:!1,error:e.message}}}if(e.type===`canvas`&&e.payload?.action===`updateWidget`){let{id:n,patch:r}=e.payload;return n?(X.updateWidget(t.id,n,r||{}),window.dispatchEvent(new CustomEvent(`titan:space:refresh`,{detail:{spaceId:t.id}})),{ok:!0,id:n}):{ok:!1,error:"updateWidget requires an `id`"}}if(e.type===`canvas`&&e.payload?.action===`listWidgets`)return{ok:!0,widgets:t.widgets||[]};if(e.type===`canvas`&&e.payload?.action===`removeWidget`){let n=e.payload.id;return n?(X.removeWidget(t.id,n),window.dispatchEvent(new CustomEvent(`titan:space:refresh`,{detail:{spaceId:t.id}})),{ok:!0}):{ok:!1,error:"removeWidget requires an `id`"}}return{ok:!1,error:`Unknown message type`}});let t=setTimeout(()=>{l(!1),s(`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(e.format,e.source).then(()=>{clearTimeout(t),l(!1)}).catch(e=>{clearTimeout(t),l(!1),s(String(e))}),()=>{clearTimeout(t),i.current?.destroy()}},[e.format,e.source,e.id]),e.format===`system`){let r=fh[e.source];return r?(0,Z.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:[(0,Z.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:[(0,Z.jsx)(`span`,{className:`text-[10px] font-bold uppercase tracking-wider`,style:{color:`var(--color-desk-accent)`},children:e.name}),(0,Z.jsx)(`button`,{onClick:n,className:`opacity-0 group-hover:opacity-100 text-xs px-1 transition-opacity`,style:{color:`var(--color-desk-text-muted)`},children:`×`})]}),(0,Z.jsx)(`div`,{className:`flex-1 overflow-auto relative`,children:(0,Z.jsx)(uh,{name:e.name,children:(0,Z.jsx)(r,{space:t,widget:e,onRemove:n})})})]}):(0,Z.jsxs)(`div`,{className:`w-full h-full flex items-center justify-center text-xs text-red-400`,children:[`Unknown system widget: `,e.source]})}return(0,Z.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:[(0,Z.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:[(0,Z.jsx)(`span`,{className:`text-[10px] font-bold uppercase tracking-wider`,style:{color:`var(--color-desk-accent)`},children:e.name}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,Z.jsx)(`button`,{onClick:n=>{n.stopPropagation(),window.dispatchEvent(new CustomEvent(`titan:widget:edit`,{detail:{spaceId:t.id,widgetId:e.id}}))},onMouseDown:e=>e.stopPropagation(),className:`px-1`,style:{color:`var(--color-desk-text-muted)`},title:`Edit widget`,children:(0,Z.jsx)(`svg`,{width:`11`,height:`11`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:(0,Z.jsx)(`path`,{d:`m18 2 4 4-14 14H4v-4L18 2z`})})}),(0,Z.jsx)(`button`,{onClick:n,className:`text-xs px-1`,style:{color:`var(--color-desk-text-muted)`},children:`×`})]})]}),(0,Z.jsx)(`div`,{className:`flex-1 relative`,children:o?(0,Z.jsx)(`div`,{className:`p-3 text-xs text-red-400 font-mono whitespace-pre-wrap`,children:o}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`iframe`,{ref:r,className:`w-full h-full border-0`,sandbox:`allow-scripts`,title:e.name}),c&&(0,Z.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:(0,Z.jsx)(`span`,{className:`animate-pulse`,children:`Loading widget…`})})]})})]})}var Sh=N.memo(xh);function Ch({label:e,onClick:t,children:n,variant:r=`default`,disabled:i}){return(0,Z.jsx)(`button`,{type:`button`,onClick:t,disabled:i,className:`titan-canvas-icon-button titan-canvas-icon-button--${r}`,title:e,"aria-label":e,children:n})}function wh(){let{spaceId:e}=De(),t=je(),{toast:n}=Ee(),r=Lu(),[i,a]=(0,N.useState)(null),[o]=(0,N.useState)(!1),[s,c]=(0,N.useState)(!1),[l,u]=(0,N.useState)(null),[d,f]=(0,N.useState)(!1),[p,m]=(0,N.useState)(!1),[h,g]=(0,N.useState)(!1),[_,v]=(0,N.useState)(1200),y=(0,N.useRef)(null),b=(0,N.useRef)(null),{info:x,triggerUpdate:ee,waitForReload:te}=Wu(),[S,ne]=(0,N.useState)(!1),[C,w]=(0,N.useState)(!1),[ie,T]=(0,N.useState)(!1);(0,N.useEffect)(()=>{let n=e||`home`,r=X.get(n);if(r){if(n===`home`&&!r.widgets.some(e=>e.source===`system:home-hero`)){let e=!1;try{e=localStorage.getItem(`titan-home-hero-pinned`)===`1`}catch{}if(!e){try{localStorage.setItem(`titan-home-hero-pinned`,`1`)}catch{}let e=ld(r.widgets,6,5);X.addWidget(n,{name:`Ask TITAN`,format:`system`,source:`system:home-hero`,x:e.x,y:e.y,w:6,h:5}),a(X.get(n)??r);return}}a(r)}else t(`/space/home`,{replace:!0})},[e,t]),(0,N.useEffect)(()=>{let e=()=>{let e=b.current;if(!e)return null;let t=new ResizeObserver(e=>{for(let t of e)v(t.contentRect.width)});return t.observe(e),v(e.getBoundingClientRect().width||1200),t},t=e(),n=setInterval(()=>{t||=e(),t&&clearInterval(n)},200);return()=>{t?.disconnect(),clearInterval(n)}},[i?.id]),(0,N.useEffect)(()=>{let e=e=>{(e.metaKey||e.ctrlKey)&&e.key===`k`&&(e.preventDefault(),m(e=>!e)),(e.metaKey||e.ctrlKey)&&e.key===`j`&&(e.preventDefault(),window.dispatchEvent(new CustomEvent(`titan:chat:toggle`)))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[]),Gu([{key:`?`,action:()=>g(!0),description:`Show keyboard shortcuts help`},{key:`g`,shift:!0,action:()=>t(`/space/command`),description:`Go to Command Post space`},{key:`h`,shift:!0,action:()=>t(`/space/home`),description:`Go to Home space`},{key:`s`,shift:!0,action:()=>t(`/space/settings`),description:`Go to Settings space`},{key:`i`,shift:!0,action:()=>t(`/space/intelligence`),description:`Go to Intelligence space`}]);let ae=(0,N.useCallback)(()=>{},[]),E=(0,N.useRef)(null),oe=(0,N.useRef)(null),D=(0,N.useCallback)(e=>{i&&(oe.current=e,E.current&&clearTimeout(E.current),E.current=setTimeout(()=>{let e=oe.current;!e||!i||(X.updateLayout(i.id,e.map(e=>({i:e.i,x:e.x,y:e.y,w:e.w,h:e.h}))),oe.current=null,E.current=null)},50))},[i]),O=(0,N.useCallback)(e=>{if(!i)return;let t=i.widgets?.find(t=>t.id===e);Ce(`canvas_panel_removed`,{widgetId:e,format:t?.format,source:t?.source}),X.removeWidget(i.id,e);let n=Array.isArray(i.widgets)?i.widgets:[];a({...i,widgets:n.filter(t=>t.id!==e)})},[i]),k=(0,N.useCallback)(e=>{if(!i)return;let t=X.addWidget(i.id,e),n=Array.isArray(i.widgets)?i.widgets:[];return a({...i,widgets:[...n,t]}),Ce(e.format===`system`?`canvas_system_panel_created`:`canvas_panel_created`,{source:e.source,name:e.name,format:e.format}),t},[i]),se=(0,N.useCallback)((e,t)=>{if(!i||!Array.isArray(i.widgets)||i.widgets.length===0)return{x:0,y:0};let n=new Set;for(let e of i.widgets)for(let t=0;t<e.w;t++)for(let r=0;r<e.h;r++)n.add(`${e.x+t},${e.y+r}`);for(let r=0;r<200;r++)for(let i=0;i<=12-e;i++){let a=!0;for(let o=0;o<e;o++){for(let e=0;e<t;e++)if(n.has(`${i+o},${r+e}`)){a=!1;break}if(!a)break}if(a)return{x:i,y:r}}return{x:0,y:0}},[i]),ce=(0,N.useCallback)((e,t,n=4,r=4)=>{let i=se(n,r);k({name:t,format:`system`,source:e,x:i.x,y:i.y,w:n,h:r})},[k,se]),le=(0,N.useCallback)(async()=>{if(i){Ce(`canvas_clear_all`,{panelCount:Array.isArray(i.widgets)?i.widgets.length:0});try{await X.clearSpace(i.id),a({...i,widgets:[]}),n(`success`,`Canvas cleared.`)}catch(e){n(`error`,`Couldn't clear the canvas — try again. (${e.message})`)}finally{T(!1)}}},[i,n]),ue=(0,N.useCallback)(async()=>{if(w(!1),!x?.isNewer||S)return;let e=x.current;ne(!0);try{let t=await ee(!0);if(!t.ok){ne(!1),n(`error`,`Update failed — ${t.error||`unknown error`}.`);return}let r=await te(e);ne(!1),r?(n(`success`,`Updated to ${r}. Reloading…`),window.location.reload()):n(`error`,`Update sent, but the gateway did not come back within 30s. Check service status manually.`)}catch(e){ne(!1),n(`error`,`Update failed — try again. (${e.message})`)}},[x,S,ee,te,n]);(0,N.useEffect)(()=>{let e=e=>{let t=e.detail;if(console.log(`[TitanCanvas] titan:space:refresh received:`,t),i&&t?.spaceId===i.id){let e=X.get(i.id);e&&(console.log(`[TitanCanvas] Refreshing space, widget count:`,e.widgets.length),a(e))}};return window.addEventListener(`titan:space:refresh`,e),()=>window.removeEventListener(`titan:space:refresh`,e)},[i]),(0,N.useEffect)(()=>{let e=e=>{let t=e.detail;if(i&&t?.source){let e=Number.isFinite(t.w)?t.w:4,n=Number.isFinite(t.h)?t.h:4,r=typeof t.name==`string`&&t.name.trim()?t.name.trim():String(t.source).replace(`system:`,``).replace(/-/g,` `),i=t.format===`react`||t.format===`vanilla`||t.format===`html`||t.format===`system`?t.format:String(t.source).startsWith(`system:`)?`system`:`react`,a=se(e,n);k({name:r,format:i,source:String(t.source),x:a.x,y:a.y,w:e,h:n})}};return window.addEventListener(`titan:widget:add`,e),()=>window.removeEventListener(`titan:widget:add`,e)},[i,k,se]),(0,N.useEffect)(()=>{let e=e=>{let t=e.detail;i&&t?.spaceId===i.id&&typeof t?.widgetId==`string`&&u(t.widgetId)};return window.addEventListener(`titan:widget:edit`,e),()=>window.removeEventListener(`titan:widget:edit`,e)},[i]),(0,N.useEffect)(()=>{if(i)return X.observe(i.id,e=>{console.log(`[TitanCanvas] CRDT observer fired, widgets:`,e.length),a(t=>t&&{...t,widgets:e})})},[i?.id]);let A=(0,N.useMemo)(()=>{let e=i?.widgets;return Array.isArray(e)?e.filter(Boolean):[]},[i]),de=(0,N.useMemo)(()=>A.map((e,t)=>({i:e.id,x:Number.isFinite(e.x)?e.x:t%3*4,y:Number.isFinite(e.y)?e.y:Math.floor(t/3)*4,w:Number.isFinite(e.w)?e.w:4,h:Number.isFinite(e.h)?e.h:4,minW:2,minH:2,maxW:12,maxH:40})),[A]);return i?(0,Z.jsxs)(`div`,{className:`h-full w-full flex`,children:[(0,Z.jsx)(wf,{}),(0,Z.jsx)(`div`,{className:`fixed bottom-5 right-6 z-[60]`,children:(0,Z.jsx)(Ru,{...r})}),(0,Z.jsxs)(`div`,{ref:y,className:`flex-1 relative overflow-auto`,children:[(0,Z.jsx)(`style`,{children:`
|
|
763
|
+
.titan-canvas-grid .react-grid-item > .react-resizable-handle {
|
|
764
|
+
background: none;
|
|
765
|
+
padding: 0;
|
|
766
|
+
opacity: 0.35;
|
|
767
|
+
z-index: 10;
|
|
768
|
+
transition: opacity 120ms ease, background-color 120ms ease;
|
|
769
|
+
}
|
|
770
|
+
.titan-canvas-grid .react-grid-item:hover > .react-resizable-handle { opacity: 0.85; }
|
|
771
|
+
.titan-canvas-grid .react-grid-item > .react-resizable-handle:hover,
|
|
772
|
+
.titan-canvas-grid .react-grid-item > .react-resizable-handle:active { opacity: 1; }
|
|
773
|
+
/* Corner handles: 22x22 with a ring-coloured chevron */
|
|
774
|
+
.titan-canvas-grid .react-grid-item > .react-resizable-handle-se,
|
|
775
|
+
.titan-canvas-grid .react-grid-item > .react-resizable-handle-sw,
|
|
776
|
+
.titan-canvas-grid .react-grid-item > .react-resizable-handle-ne,
|
|
777
|
+
.titan-canvas-grid .react-grid-item > .react-resizable-handle-nw {
|
|
778
|
+
width: 22px;
|
|
779
|
+
height: 22px;
|
|
780
|
+
background-image: none;
|
|
781
|
+
transform: none;
|
|
782
|
+
}
|
|
783
|
+
.titan-canvas-grid .react-grid-item > .react-resizable-handle-se::after,
|
|
784
|
+
.titan-canvas-grid .react-grid-item > .react-resizable-handle-sw::after,
|
|
785
|
+
.titan-canvas-grid .react-grid-item > .react-resizable-handle-ne::after,
|
|
786
|
+
.titan-canvas-grid .react-grid-item > .react-resizable-handle-nw::after {
|
|
787
|
+
content: "";
|
|
788
|
+
position: absolute;
|
|
789
|
+
width: 12px; height: 12px;
|
|
790
|
+
border: 2px solid var(--color-desk-brass);
|
|
791
|
+
border-radius: 3px;
|
|
792
|
+
}
|
|
793
|
+
.titan-canvas-grid .react-grid-item > .react-resizable-handle-se::after { right: 3px; bottom: 3px; border-top: none; border-left: none; }
|
|
794
|
+
.titan-canvas-grid .react-grid-item > .react-resizable-handle-sw::after { left: 3px; bottom: 3px; border-top: none; border-right: none; }
|
|
795
|
+
.titan-canvas-grid .react-grid-item > .react-resizable-handle-ne::after { right: 3px; top: 3px; border-bottom: none; border-left: none; }
|
|
796
|
+
.titan-canvas-grid .react-grid-item > .react-resizable-handle-nw::after { left: 3px; top: 3px; border-bottom: none; border-right: none; }
|
|
797
|
+
/* Edge handles: full-edge strips with a centre grip */
|
|
798
|
+
.titan-canvas-grid .react-grid-item > .react-resizable-handle-e,
|
|
799
|
+
.titan-canvas-grid .react-grid-item > .react-resizable-handle-w {
|
|
800
|
+
top: 8px; bottom: 8px; height: auto; margin-top: 0;
|
|
801
|
+
width: 8px; background-image: none; transform: none;
|
|
802
|
+
}
|
|
803
|
+
.titan-canvas-grid .react-grid-item > .react-resizable-handle-n,
|
|
804
|
+
.titan-canvas-grid .react-grid-item > .react-resizable-handle-s {
|
|
805
|
+
left: 8px; right: 8px; width: auto; margin-left: 0;
|
|
806
|
+
height: 8px; background-image: none; transform: none;
|
|
807
|
+
}
|
|
808
|
+
.titan-canvas-grid .react-grid-item > .react-resizable-handle-e::after,
|
|
809
|
+
.titan-canvas-grid .react-grid-item > .react-resizable-handle-w::after,
|
|
810
|
+
.titan-canvas-grid .react-grid-item > .react-resizable-handle-n::after,
|
|
811
|
+
.titan-canvas-grid .react-grid-item > .react-resizable-handle-s::after {
|
|
812
|
+
content: ""; position: absolute; background: var(--color-desk-brass); border-radius: 2px;
|
|
813
|
+
}
|
|
814
|
+
.titan-canvas-grid .react-grid-item > .react-resizable-handle-e::after,
|
|
815
|
+
.titan-canvas-grid .react-grid-item > .react-resizable-handle-w::after {
|
|
816
|
+
top: 50%; transform: translateY(-50%);
|
|
817
|
+
width: 3px; height: 32px;
|
|
818
|
+
}
|
|
819
|
+
.titan-canvas-grid .react-grid-item > .react-resizable-handle-e::after { right: 2px; }
|
|
820
|
+
.titan-canvas-grid .react-grid-item > .react-resizable-handle-w::after { left: 2px; }
|
|
821
|
+
.titan-canvas-grid .react-grid-item > .react-resizable-handle-n::after,
|
|
822
|
+
.titan-canvas-grid .react-grid-item > .react-resizable-handle-s::after {
|
|
823
|
+
left: 50%; transform: translateX(-50%);
|
|
824
|
+
height: 3px; width: 32px;
|
|
825
|
+
}
|
|
826
|
+
.titan-canvas-grid .react-grid-item > .react-resizable-handle-n::after { top: 2px; }
|
|
827
|
+
.titan-canvas-grid .react-grid-item > .react-resizable-handle-s::after { bottom: 2px; }
|
|
828
|
+
/* Allow resizing and dragging freely — placeholder turns accent blue */
|
|
829
|
+
.titan-canvas-grid .react-grid-placeholder {
|
|
830
|
+
background: rgba(99, 102, 241, 0.14) !important;
|
|
831
|
+
border: 1px dashed rgba(99, 102, 241, 0.55) !important;
|
|
832
|
+
border-radius: 12px;
|
|
833
|
+
opacity: 1 !important;
|
|
834
|
+
}
|
|
835
|
+
`}),(0,Z.jsx)(`div`,{className:`fixed inset-0 opacity-[0.06] 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`}}),(0,Z.jsxs)(`div`,{className:`titan-canvas-titlebar absolute top-0 left-0 right-0 z-40`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0`,children:[(0,Z.jsx)(`div`,{className:`titan-canvas-space-icon`,style:{color:i.color||`var(--color-desk-accent)`},children:(0,Z.jsx)(tt,{className:`w-4 h-4`})}),(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsx)(`h1`,{className:`titan-canvas-title truncate`,children:i.name}),(0,Z.jsxs)(`div`,{className:`titan-canvas-subtitle`,children:[A.length,` panel`,A.length===1?``:`s`,` on desktop canvas`]})]}),(0,Z.jsx)(Ch,{label:`Open Mission Chat`,onClick:()=>t(`/mission`),variant:`primary`,children:(0,Z.jsx)(Pe,{className:`w-4 h-4`})}),(0,Z.jsx)(`button`,{onClick:()=>c(!0),className:`titan-canvas-instructions truncate`,title:`Edit agent instructions for this space`,children:i.agentInstructions?(0,Z.jsx)(`span`,{className:`truncate`,children:i.agentInstructions}):(0,Z.jsx)(`span`,{className:`italic`,children:`add agent instructions`})})]}),(0,Z.jsxs)(`div`,{className:`titan-canvas-toolbar`,children:[vh.map(e=>{let t=e.icon;return(0,Z.jsx)(Ch,{label:`Add ${e.label}`,onClick:()=>ce(e.source,e.name,e.w,e.h),children:(0,Z.jsx)(t,{className:`w-4 h-4`})},e.source)}),A.length>0&&(0,Z.jsx)(Ch,{label:`Clear canvas`,onClick:()=>T(!0),variant:`danger`,children:(0,Z.jsx)(fe,{className:`w-4 h-4`})}),(0,Z.jsx)(`button`,{disabled:S,className:`titan-canvas-version-chip ${x?.isNewer?`titan-canvas-version-chip--update`:``}`,style:x?.isNewer?void 0:{background:`var(--theme-paper, rgba(253,246,227,0.7))`,borderColor:`var(--color-desk-border)`},title:x?.isNewer?`Update available: ${x.current} → ${x.latest}`:`TITAN ${x?.current||``}`,onClick:()=>{!x?.isNewer||S||w(!0)},children:S?`…`:x?.isNewer?`↑ ${x.latest}`:`v${x?.current||``}`}),(0,Z.jsx)(Ch,{label:`Open widget gallery`,onClick:()=>f(!0),variant:`primary`,children:(0,Z.jsx)(Ye,{className:`w-4 h-4`})}),(0,Z.jsx)(Ch,{label:`Open command palette`,onClick:()=>m(!0),children:(0,Z.jsx)(qe,{className:`w-4 h-4`})}),(0,Z.jsx)(Ch,{label:`Open chat dock`,onClick:()=>window.dispatchEvent(new CustomEvent(`titan:chat:toggle`)),children:(0,Z.jsx)(re,{className:`w-4 h-4`})})]})]}),(0,Z.jsx)(`div`,{ref:b,className:`relative pt-28 min-h-[5000px]`,style:{transform:`scale(${r.zoom})`,transformOrigin:`top center`,transition:`transform 120ms ease-out`},children:A.length===0?(0,Z.jsx)(Th,{space:i,onAddWidget:ce,onOpenChat:()=>window.dispatchEvent(new CustomEvent(`titan:chat:toggle`,{detail:{open:!0}}))}):(0,Z.jsx)(N.Suspense,{fallback:(0,Z.jsx)(`div`,{className:`pt-12 text-center`,children:(0,Z.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:(0,Z.jsx)(dh,{className:`layout titan-canvas-grid`,width:_,layouts:{lg:de},breakpoints:hh,cols:ph,rowHeight:mh,margin:gh,containerPadding:[12,12],isDraggable:!0,isResizable:!0,draggableHandle:`.panel-drag-handle`,resizeHandles:_h,compactType:null,preventCollision:!1,allowOverlap:!0,useCSSTransforms:!0,onLayoutChange:ae,onDragStop:e=>{D(e)},onResizeStop:e=>{D(e)},children:A.map(e=>(0,Z.jsx)(bh,{widget:e,space:i,onRemove:O},e.id))})})}),(0,Z.jsx)(sf,{space:i,defaultExpanded:o,hideMascot:!0}),(0,Z.jsx)(ff,{}),(0,Z.jsx)(uf,{}),(0,Z.jsx)(Af,{space:i,open:s,onClose:()=>c(!1),onSaved:e=>{a(t=>t&&{...t,agentInstructions:e||void 0})}}),l&&(()=>{let e=A.find(e=>e.id===l);return!e||e.format===`system`?(u(null),null):(0,Z.jsx)(Mf,{widget:e,spaceId:i.id,open:!0,onClose:()=>u(null),onSaved:e=>{let t=A.map(t=>t.id===e.id?{...t,...e}:t);a(e=>e&&{...e,widgets:t})}})})(),(0,Z.jsx)(Lf,{open:d,onClose:()=>f(!1)}),(0,Z.jsx)(Gf,{}),p&&(0,Z.jsx)(zf,{currentSpaceId:i.id,onSpaceSelect:e=>{t(`/space/${e}`),m(!1)},onAction:e=>{e.type===`widget`&&ce(e.source,e.name,e.w,e.h),m(!1)},onClose:()=>m(!1)}),(0,Z.jsx)(qu,{open:h,onClose:()=>g(!1)}),(0,Z.jsx)(Ge,{open:ie,title:`Clear this canvas?`,message:`This removes all ${A.length} panel${A.length===1?``:`s`} from "${i.name}". This can't be undone.`,confirmLabel:`Clear canvas`,onConfirm:le,onCancel:()=>T(!1)}),(0,Z.jsx)(Ge,{open:C,variant:`primary`,title:`Update TITAN?`,message:`Update TITAN from ${x?.current} → ${x?.latest}? Your data in ~/.titan/ will be preserved. The gateway will restart after the update.`,confirmLabel:`Update`,onConfirm:ue,onCancel:()=>w(!1)})]})]}):(0,Z.jsx)(`div`,{className:`h-full w-full flex items-center justify-center`,children:(0,Z.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 Th({space:e,onAddWidget:t,onOpenChat:n}){return(0,Z.jsx)(`div`,{className:`h-full flex items-start justify-center pt-8 pb-32 px-4 sm:px-6`,children:(0,Z.jsxs)(`div`,{className:`titan-canvas-empty-panel text-center w-full max-w-4xl px-5 sm:px-8 py-8 sm:py-10`,children:[(0,Z.jsx)(`style`,{children:`
|
|
836
|
+
.titan-empty-hero {
|
|
837
|
+
background: linear-gradient(180deg,
|
|
838
|
+
color-mix(in srgb, var(--theme-metal-bright) 22%, transparent) 0%,
|
|
839
|
+
color-mix(in srgb, var(--theme-metal) 14%, transparent) 100%);
|
|
840
|
+
color: var(--theme-accent);
|
|
841
|
+
border: 1px solid color-mix(in srgb, var(--theme-metal) 55%, transparent);
|
|
842
|
+
box-shadow:
|
|
843
|
+
0 0 0 0 color-mix(in srgb, var(--theme-accent) 0%, transparent),
|
|
844
|
+
0 2px 6px var(--theme-shadow);
|
|
845
|
+
transition: transform 140ms ease, box-shadow 220ms ease, border-color 140ms ease;
|
|
846
|
+
font-family: var(--theme-font-display);
|
|
847
|
+
}
|
|
848
|
+
.titan-empty-hero:hover {
|
|
849
|
+
transform: translateY(-1px);
|
|
850
|
+
border-color: var(--theme-metal-bright);
|
|
851
|
+
box-shadow:
|
|
852
|
+
0 0 24px color-mix(in srgb, var(--theme-accent) 35%, transparent),
|
|
853
|
+
0 4px 12px var(--theme-shadow);
|
|
854
|
+
}
|
|
855
|
+
.titan-empty-chip {
|
|
856
|
+
width: 110px;
|
|
857
|
+
background: var(--theme-paper);
|
|
858
|
+
color: var(--theme-ink-soft);
|
|
859
|
+
border: 1px solid color-mix(in srgb, var(--theme-metal) 40%, transparent);
|
|
860
|
+
box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--theme-paper-line) 50%, transparent);
|
|
861
|
+
font-family: var(--theme-font-display);
|
|
862
|
+
transition: transform 120ms ease, border-color 120ms ease, color 120ms ease, box-shadow 120ms ease;
|
|
863
|
+
}
|
|
864
|
+
.titan-empty-chip:hover {
|
|
865
|
+
transform: translateY(-1px);
|
|
866
|
+
border-color: var(--theme-metal-bright);
|
|
867
|
+
color: var(--theme-ink);
|
|
868
|
+
box-shadow:
|
|
869
|
+
inset 0 0 0 1px color-mix(in srgb, var(--theme-metal-bright) 35%, transparent),
|
|
870
|
+
0 2px 6px var(--theme-shadow);
|
|
871
|
+
}
|
|
872
|
+
.titan-empty-group-label {
|
|
873
|
+
font-family: var(--theme-font-mono);
|
|
874
|
+
color: var(--theme-metal-dark);
|
|
875
|
+
letter-spacing: 0.18em;
|
|
876
|
+
}
|
|
877
|
+
.titan-empty-rule {
|
|
878
|
+
background: linear-gradient(90deg,
|
|
879
|
+
transparent 0%,
|
|
880
|
+
color-mix(in srgb, var(--theme-metal) 50%, transparent) 50%,
|
|
881
|
+
transparent 100%);
|
|
882
|
+
}
|
|
883
|
+
`}),(0,Z.jsx)(`div`,{className:`w-14 h-14 rounded-lg 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:(0,Z.jsx)(`svg`,{className:`w-7 h-7`,style:{color:`var(--theme-metal)`},fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,Z.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`})})}),(0,Z.jsx)(`h2`,{className:`text-xl font-bold mb-2`,style:{color:`var(--theme-ink)`,fontFamily:`var(--theme-font-display)`},children:e.name}),(0,Z.jsx)(`p`,{className:`text-sm mb-7`,style:{color:`var(--theme-ink-soft)`,fontFamily:`var(--theme-font-display)`},children:`This desk is empty. Ask the AI to build something — try "make me a weather widget for Kelseyville" or "add a clock" — or place a system panel below.`}),(0,Z.jsx)(`div`,{className:`flex justify-center mb-8`,children:(0,Z.jsxs)(`button`,{onClick:n,className:`titan-empty-hero inline-flex items-center gap-2 px-6 py-3 rounded-lg text-base font-semibold`,children:[(0,Z.jsxs)(`svg`,{width:`18`,height:`18`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.8`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,Z.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`}),(0,Z.jsx)(`path`,{d:`M10 22h4`})]}),`Ask Agent`]})}),(0,Z.jsx)(`div`,{className:`space-y-5 text-left`,children:[{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}]}].map(e=>(0,Z.jsxs)(`div`,{children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-3 mb-2.5 px-1`,children:[(0,Z.jsx)(`span`,{className:`titan-empty-group-label text-[10px] font-bold uppercase`,children:e.title}),(0,Z.jsx)(`span`,{className:`titan-empty-rule flex-1 h-px`})]}),(0,Z.jsx)(`div`,{className:`flex gap-2 flex-wrap`,children:e.items.map(e=>(0,Z.jsxs)(`button`,{onClick:()=>t(e.source,e.label,e.w,e.h),className:`titan-empty-chip px-3 py-1.5 rounded-md text-[11px] text-center`,title:`Add ${e.label}`,children:[`+ `,e.label]},e.source))})]},e.title))})]})})}export{wh as default};
|