shadow-claw 1.59.6 → 1.59.7
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/.well-known/mcp/server-card.json +12 -4
- package/.well-known/mcp.json +12 -4
- package/dist/cli/build/build.js +1 -1
- package/dist/cli/{chunk-DM4xsTry.js → chunk-3vNYrs_L.js} +1 -1
- package/dist/cli/{chunk-Ctg5L55n.js → chunk-66BvqAV0.js} +1 -1
- package/dist/cli/{chunk-Bq38OubR.js → chunk-B0qusANw.js} +1 -1
- package/dist/cli/{chunk-yiVdvGCJ.js → chunk-B3TrWbca.js} +7 -7
- package/dist/cli/{chunk-C8DBACtx.js → chunk-B88Z8T_9.js} +1 -1
- package/dist/cli/chunk-BCjL0JXf.js +1 -0
- package/dist/cli/chunk-BNcu1oiT.js +1 -0
- package/dist/cli/{chunk-gvNsvav0.js → chunk-C5ypckWC.js} +7 -7
- package/dist/cli/{chunk-Dw8GndPD.js → chunk-CAAeGOdy.js} +1 -1
- package/dist/cli/chunk-CFxww5Yz.js +1 -0
- package/dist/cli/chunk-CGIgtL6R.js +1 -0
- package/dist/cli/{chunk-DJqHK-qS.js → chunk-CQaCgswD.js} +7 -7
- package/dist/cli/chunk-CZdCRqNe.js +7 -0
- package/dist/cli/chunk-CafdvLx-.js +1 -0
- package/dist/cli/{chunk-Bc_weULz.js → chunk-CncW6_WL.js} +1 -1
- package/dist/cli/chunk-DDvuLVfW.js +1 -0
- package/dist/cli/{chunk-Cq_kQohv.js → chunk-DMs7kREC.js} +1 -1
- package/dist/cli/{chunk-CX2itile.js → chunk-D_te8ufL.js} +1 -1
- package/dist/cli/{chunk-3wTukVof.js → chunk-DhOU6GYX.js} +1 -1
- package/dist/cli/chunk-Dhap1VwA.js +1 -0
- package/dist/cli/chunk-DwvavohW.js +1 -0
- package/dist/cli/{chunk-DLde6nuO.js → chunk-SRBRVorc.js} +1 -1
- package/dist/cli/{chunk-D3y7h9Xe.js → chunk-SxK79JmB.js} +1 -1
- package/dist/cli/chunk-_a0CkUNS.js +139 -0
- package/dist/cli/{chunk-C9o6lXP3.js → chunk-hVf839t7.js} +1 -1
- package/dist/cli/chunk-iB8OoMmW.js +7 -0
- package/dist/cli/cli.js +1 -1
- package/dist/headless-agent.js +1 -1
- package/dist/lib/{app-routes-DJdIjp2V.js → app-routes-BXiRvlNl.js} +7 -25
- package/dist/lib/{app-routes-DJdIjp2V.js.map → app-routes-BXiRvlNl.js.map} +1 -1
- package/dist/lib/{attachment-capabilities-Dbb-4ZP5.js → attachment-capabilities-BjkEPip8.js} +2 -2
- package/dist/lib/{attachment-capabilities-Dbb-4ZP5.js.map → attachment-capabilities-BjkEPip8.js.map} +1 -1
- package/dist/lib/{channel-Dlru5ofR.js → channel-mmdGzPkT.js} +3 -3
- package/dist/lib/{channel-Dlru5ofR.js.map → channel-mmdGzPkT.js.map} +1 -1
- package/dist/lib/{chat-template-BuuLY8l7.js → chat-template-DPEKGJhB.js} +2 -2
- package/dist/lib/{chat-template-BuuLY8l7.js.map → chat-template-DPEKGJhB.js.map} +1 -1
- package/dist/lib/{compact-context-BtR55YPU.js → compact-context-CY9BBlUQ.js} +19 -19
- package/dist/lib/{compact-context-BtR55YPU.js.map → compact-context-CY9BBlUQ.js.map} +1 -1
- package/dist/lib/components/common/shadow-claw-provider-model-picker.js +1 -1
- package/dist/lib/components/index.js +27 -27
- package/dist/lib/components/settings/shadow-claw-accounts.js +1 -1
- package/dist/lib/components/settings/shadow-claw-channel-config.js +1 -1
- package/dist/lib/components/settings/shadow-claw-control-plane.js +1 -1
- package/dist/lib/components/settings/shadow-claw-git.js +1 -1
- package/dist/lib/components/settings/shadow-claw-integrations.js +1 -1
- package/dist/lib/components/settings/shadow-claw-llm.js +1 -1
- package/dist/lib/components/settings/shadow-claw-mcp-remote.js +1 -1
- package/dist/lib/components/settings/shadow-claw-networking.js +1 -1
- package/dist/lib/components/settings/shadow-claw-notifications.js +1 -1
- package/dist/lib/components/settings/shadow-claw-peerjs.js +1 -1
- package/dist/lib/components/settings/shadow-claw-storage.js +1 -1
- package/dist/lib/components/settings/shadow-claw-task-server.js +1 -1
- package/dist/lib/components/settings/shadow-claw-webvm.js +1 -1
- package/dist/lib/components/shadow-claw-a2ui.js +1 -1
- package/dist/lib/components/shadow-claw-accounts.js +1 -1
- package/dist/lib/components/shadow-claw-channel-config.js +1 -1
- package/dist/lib/components/shadow-claw-channels.js +1 -1
- package/dist/lib/components/shadow-claw-chat.js +1 -1
- package/dist/lib/components/shadow-claw-control-plane.js +1 -1
- package/dist/lib/components/shadow-claw-conversations.js +1 -1
- package/dist/lib/components/shadow-claw-file-viewer.js +1 -1
- package/dist/lib/components/shadow-claw-files.js +1 -1
- package/dist/lib/components/shadow-claw-git.js +1 -1
- package/dist/lib/components/shadow-claw-integrations.js +1 -1
- package/dist/lib/components/shadow-claw-llm.js +1 -1
- package/dist/lib/components/shadow-claw-mcp-remote.js +1 -1
- package/dist/lib/components/shadow-claw-networking.js +1 -1
- package/dist/lib/components/shadow-claw-notifications.js +1 -1
- package/dist/lib/components/shadow-claw-page-header.js +1 -1
- package/dist/lib/components/shadow-claw-pages.js +1 -1
- package/dist/lib/components/shadow-claw-peerjs.js +1 -1
- package/dist/lib/components/shadow-claw-provider-model-picker.js +1 -1
- package/dist/lib/components/shadow-claw-settings.js +1 -1
- package/dist/lib/components/shadow-claw-storage.js +1 -1
- package/dist/lib/components/shadow-claw-task-server.js +1 -1
- package/dist/lib/components/shadow-claw-tasks.js +1 -1
- package/dist/lib/components/shadow-claw-terminal.js +1 -1
- package/dist/lib/components/shadow-claw-tools.js +1 -1
- package/dist/lib/components/shadow-claw-webvm.js +1 -1
- package/dist/lib/components/shadow-claw.js +1 -1
- package/dist/lib/{config-DxNI3TlW.js → config-BrHR97zt.js} +2 -2
- package/dist/lib/{config-DxNI3TlW.js.map → config-BrHR97zt.js.map} +1 -1
- package/dist/lib/{configure-peer-js-ChDhOZU4.js → configure-peer-js-ccNvax2N.js} +3 -3
- package/dist/lib/{configure-peer-js-ChDhOZU4.js.map → configure-peer-js-ccNvax2N.js.map} +1 -1
- package/dist/lib/{connections-DC4NZkJE.js → connections-C1FWsBsE.js} +2 -2
- package/dist/lib/{connections-DC4NZkJE.js.map → connections-C1FWsBsE.js.map} +1 -1
- package/dist/lib/{credentials-5vpz0XPk.js → credentials-CZbngHXW.js} +2 -2
- package/dist/lib/{credentials-5vpz0XPk.js.map → credentials-CZbngHXW.js.map} +1 -1
- package/dist/lib/{discover-skills-CD0sKvAI.js → discover-skills-OwlQ2sXA.js} +13 -13
- package/dist/lib/{discover-skills-CD0sKvAI.js.map → discover-skills-OwlQ2sXA.js.map} +1 -1
- package/dist/lib/{download-group-file-Dk3qaxhJ.js → download-group-file-D0wgg10Q.js} +2 -2
- package/dist/lib/{download-group-file-Dk3qaxhJ.js.map → download-group-file-D0wgg10Q.js.map} +1 -1
- package/dist/lib/{file-viewer-B4pRW-_G.js → file-viewer-DOfvX6yy.js} +5 -5
- package/dist/lib/{file-viewer-B4pRW-_G.js.map → file-viewer-DOfvX6yy.js.map} +1 -1
- package/dist/lib/{get-or-create-subscriber-id-HCcgDEPz.js → get-or-create-subscriber-id-wyzaML7Z.js} +2 -2
- package/dist/lib/{get-or-create-subscriber-id-HCcgDEPz.js.map → get-or-create-subscriber-id-wyzaML7Z.js.map} +1 -1
- package/dist/lib/{git-B3Q1euc5.js → git-D2J_j9X9.js} +5 -5
- package/dist/lib/{git-B3Q1euc5.js.map → git-D2J_j9X9.js.map} +1 -1
- package/dist/lib/{iframe-bridge-scripts-D8iuFhUk.js → iframe-bridge-scripts-Dx825LLG.js} +2 -2
- package/dist/lib/{iframe-bridge-scripts-D8iuFhUk.js.map → iframe-bridge-scripts-Dx825LLG.js.map} +1 -1
- package/dist/lib/index.js +28 -28
- package/dist/lib/{init-chat-split-resize-B0ODULx9.js → init-chat-split-resize-Cc0bd2z9.js} +2 -2
- package/dist/lib/{init-chat-split-resize-B0ODULx9.js.map → init-chat-split-resize-Cc0bd2z9.js.map} +1 -1
- package/dist/lib/{init-control-plane-C1FRRmjC.js → init-control-plane-B7blDVIE.js} +15 -15
- package/dist/lib/{init-control-plane-C1FRRmjC.js.map → init-control-plane-B7blDVIE.js.map} +1 -1
- package/dist/lib/{invoke-agent-CzN7sVh-.js → invoke-agent-SxvudiDT.js} +11 -11
- package/dist/lib/{invoke-agent-CzN7sVh-.js.map → invoke-agent-SxvudiDT.js.map} +1 -1
- package/dist/lib/{markdown-mbNo7cV3.js → markdown--6vTAPEH.js} +2 -2
- package/dist/lib/{markdown-mbNo7cV3.js.map → markdown--6vTAPEH.js.map} +1 -1
- package/dist/lib/{mcp-reconnect-3T7yWGEY.js → mcp-reconnect-BeqQvNWO.js} +3 -3
- package/dist/lib/{mcp-reconnect-3T7yWGEY.js.map → mcp-reconnect-BeqQvNWO.js.map} +1 -1
- package/dist/lib/{model-ranking-DGNSWYwN.js → model-ranking-BhsJV7vb.js} +2 -2
- package/dist/lib/{model-ranking-DGNSWYwN.js.map → model-ranking-BhsJV7vb.js.map} +1 -1
- package/dist/lib/{move-group-entry-NMTJ59M9.js → move-group-entry-DDpjxa10.js} +5 -5
- package/dist/lib/{move-group-entry-NMTJ59M9.js.map → move-group-entry-DDpjxa10.js.map} +1 -1
- package/dist/lib/{orchestrator-B8FV1V7x.js → orchestrator-C7fkh7T7.js} +24 -24
- package/dist/lib/{orchestrator-B8FV1V7x.js.map → orchestrator-C7fkh7T7.js.map} +1 -1
- package/dist/lib/{orchestrator-i_QJ-o22.js → orchestrator-CCARkxQC.js} +11 -11
- package/dist/lib/orchestrator-CCARkxQC.js.map +1 -0
- package/dist/lib/{parse-path-DPCn-HwI.js → parse-path-BOHQP_IQ.js} +3 -3
- package/dist/lib/{parse-path-DPCn-HwI.js.map → parse-path-BOHQP_IQ.js.map} +1 -1
- package/dist/lib/{peerjs-z5zeioPV.js → peerjs-Bfw_FWLB.js} +8 -8
- package/dist/lib/{peerjs-z5zeioPV.js.map → peerjs-Bfw_FWLB.js.map} +1 -1
- package/dist/lib/{process-peer-query-param-CJp7w7AU.js → process-peer-query-param-BxYiZNdf.js} +5 -5
- package/dist/lib/{process-peer-query-param-CJp7w7AU.js.map → process-peer-query-param-BxYiZNdf.js.map} +1 -1
- package/dist/lib/{process-pending-shared-payloads-B6_TlBFA.js → process-pending-shared-payloads-DPIbwRb3.js} +4 -4
- package/dist/lib/{process-pending-shared-payloads-B6_TlBFA.js.map → process-pending-shared-payloads-DPIbwRb3.js.map} +1 -1
- package/dist/lib/{process-room-query-param-C3FFGGn6.js → process-room-query-param-B2_d50nE.js} +4 -4
- package/dist/lib/{process-room-query-param-C3FFGGn6.js.map → process-room-query-param-B2_d50nE.js.map} +1 -1
- package/dist/lib/{provider-DcQZypu5.js → provider-BC9KPI14.js} +3 -3
- package/dist/lib/{provider-DcQZypu5.js.map → provider-BC9KPI14.js.map} +1 -1
- package/dist/lib/{push-client-Cx5rMs6J.js → push-client-rrjTdc-U.js} +5 -5
- package/dist/lib/{push-client-Cx5rMs6J.js.map → push-client-rrjTdc-U.js.map} +1 -1
- package/dist/lib/{read-group-file-bytes-CXOG_YyM.js → read-group-file-bytes-UQIk1eJG.js} +2 -2
- package/dist/lib/{read-group-file-bytes-CXOG_YyM.js.map → read-group-file-bytes-UQIk1eJG.js.map} +1 -1
- package/dist/lib/{rooms-CwlkYLDU.js → rooms-bwGoYb1q.js} +2 -2
- package/dist/lib/{rooms-CwlkYLDU.js.map → rooms-bwGoYb1q.js.map} +1 -1
- package/dist/lib/{shadow-claw-DoQ7fgl5.js → shadow-claw-CypGVlVO.js} +17 -20
- package/dist/lib/shadow-claw-CypGVlVO.js.map +1 -0
- package/dist/lib/{shadow-claw-a2ui-Br6qJMs1.js → shadow-claw-a2ui-lG0vQbW8.js} +2 -2
- package/dist/lib/{shadow-claw-a2ui-Br6qJMs1.js.map → shadow-claw-a2ui-lG0vQbW8.js.map} +1 -1
- package/dist/lib/{shadow-claw-accounts-BTDILfWw.js → shadow-claw-accounts-CkqyCxwp.js} +3 -3
- package/dist/lib/{shadow-claw-accounts-BTDILfWw.js.map → shadow-claw-accounts-CkqyCxwp.js.map} +1 -1
- package/dist/lib/{shadow-claw-channel-config-IKiL34tI.js → shadow-claw-channel-config-DJpDovkF.js} +4 -4
- package/dist/lib/{shadow-claw-channel-config-IKiL34tI.js.map → shadow-claw-channel-config-DJpDovkF.js.map} +1 -1
- package/dist/lib/{shadow-claw-channels-JgEzuHWK.js → shadow-claw-channels-DJLwRovH.js} +3 -3
- package/dist/lib/{shadow-claw-channels-JgEzuHWK.js.map → shadow-claw-channels-DJLwRovH.js.map} +1 -1
- package/dist/lib/{shadow-claw-chat-SGUDT31r.js → shadow-claw-chat-B92cPaft.js} +15 -15
- package/dist/lib/{shadow-claw-chat-SGUDT31r.js.map → shadow-claw-chat-B92cPaft.js.map} +1 -1
- package/dist/lib/{shadow-claw-control-plane-CRWFZ3vD.js → shadow-claw-control-plane-fvn-qyHj.js} +7 -7
- package/dist/lib/{shadow-claw-control-plane-CRWFZ3vD.js.map → shadow-claw-control-plane-fvn-qyHj.js.map} +1 -1
- package/dist/lib/{shadow-claw-conversations-D23GJ7qo.js → shadow-claw-conversations-CsVyDOny.js} +7 -7
- package/dist/lib/{shadow-claw-conversations-D23GJ7qo.js.map → shadow-claw-conversations-CsVyDOny.js.map} +1 -1
- package/dist/lib/{shadow-claw-file-viewer-C1V8WTiU.js → shadow-claw-file-viewer-DFfyP7s5.js} +10 -10
- package/dist/lib/{shadow-claw-file-viewer-C1V8WTiU.js.map → shadow-claw-file-viewer-DFfyP7s5.js.map} +1 -1
- package/dist/lib/{shadow-claw-files-DN7irmE1.js → shadow-claw-files-cT6HL7ye.js} +11 -11
- package/dist/lib/{shadow-claw-files-DN7irmE1.js.map → shadow-claw-files-cT6HL7ye.js.map} +1 -1
- package/dist/lib/{shadow-claw-git-D-1oIh65.js → shadow-claw-git-Cv9mQgTx.js} +6 -6
- package/dist/lib/{shadow-claw-git-D-1oIh65.js.map → shadow-claw-git-Cv9mQgTx.js.map} +1 -1
- package/dist/lib/{shadow-claw-integrations-CZjnm7cM.js → shadow-claw-integrations-RZZ-m-Id.js} +4 -4
- package/dist/lib/{shadow-claw-integrations-CZjnm7cM.js.map → shadow-claw-integrations-RZZ-m-Id.js.map} +1 -1
- package/dist/lib/{shadow-claw-llm-4Gefh5FN.js → shadow-claw-llm-CKOYzPDp.js} +9 -9
- package/dist/lib/{shadow-claw-llm-4Gefh5FN.js.map → shadow-claw-llm-CKOYzPDp.js.map} +1 -1
- package/dist/lib/{shadow-claw-mcp-remote-B9ssb3YV.js → shadow-claw-mcp-remote-BKFROurv.js} +4 -4
- package/dist/lib/{shadow-claw-mcp-remote-B9ssb3YV.js.map → shadow-claw-mcp-remote-BKFROurv.js.map} +1 -1
- package/dist/lib/{shadow-claw-networking-BN5BB4hb.js → shadow-claw-networking-DYfiUQaH.js} +2 -2
- package/dist/lib/{shadow-claw-networking-BN5BB4hb.js.map → shadow-claw-networking-DYfiUQaH.js.map} +1 -1
- package/dist/lib/{shadow-claw-notifications-71KARtkY.js → shadow-claw-notifications-JJlzriuX.js} +3 -3
- package/dist/lib/{shadow-claw-notifications-71KARtkY.js.map → shadow-claw-notifications-JJlzriuX.js.map} +1 -1
- package/dist/lib/{shadow-claw-page-header-DMGO-TSe.js → shadow-claw-page-header-C_Qr3xZM.js} +2 -2
- package/dist/lib/{shadow-claw-page-header-DMGO-TSe.js.map → shadow-claw-page-header-C_Qr3xZM.js.map} +1 -1
- package/dist/lib/{shadow-claw-pages-BiRM6qiA.js → shadow-claw-pages-BCo3ihZI.js} +11 -11
- package/dist/lib/{shadow-claw-pages-BiRM6qiA.js.map → shadow-claw-pages-BCo3ihZI.js.map} +1 -1
- package/dist/lib/{shadow-claw-peerjs-BZu7jNSe.js → shadow-claw-peerjs-CFNjfrY5.js} +6 -6
- package/dist/lib/{shadow-claw-peerjs-BZu7jNSe.js.map → shadow-claw-peerjs-CFNjfrY5.js.map} +1 -1
- package/dist/lib/{shadow-claw-provider-model-picker-BXYXEobD.js → shadow-claw-provider-model-picker-B-Ct4yW-.js} +2 -2
- package/dist/lib/{shadow-claw-provider-model-picker-BXYXEobD.js.map → shadow-claw-provider-model-picker-B-Ct4yW-.js.map} +1 -1
- package/dist/lib/{shadow-claw-settings-CcT5EK08.js → shadow-claw-settings-BMwne0bh.js} +7 -7
- package/dist/lib/{shadow-claw-settings-CcT5EK08.js.map → shadow-claw-settings-BMwne0bh.js.map} +1 -1
- package/dist/lib/{shadow-claw-storage-eTOpbvpi.js → shadow-claw-storage-DUY8B9m-.js} +5 -5
- package/dist/lib/{shadow-claw-storage-eTOpbvpi.js.map → shadow-claw-storage-DUY8B9m-.js.map} +1 -1
- package/dist/lib/{shadow-claw-task-server-DFImTUbw.js → shadow-claw-task-server-yWeoA3eL.js} +2 -2
- package/dist/lib/{shadow-claw-task-server-DFImTUbw.js.map → shadow-claw-task-server-yWeoA3eL.js.map} +1 -1
- package/dist/lib/{shadow-claw-tasks-BjaxsmUx.js → shadow-claw-tasks-Bg0uM15I.js} +9 -9
- package/dist/lib/{shadow-claw-tasks-BjaxsmUx.js.map → shadow-claw-tasks-Bg0uM15I.js.map} +1 -1
- package/dist/lib/{shadow-claw-terminal-C-4wreFe.js → shadow-claw-terminal-fyJPppY_.js} +2 -2
- package/dist/lib/{shadow-claw-terminal-C-4wreFe.js.map → shadow-claw-terminal-fyJPppY_.js.map} +1 -1
- package/dist/lib/{shadow-claw-tools-COdrGZJk.js → shadow-claw-tools-D0T8m3go.js} +7 -7
- package/dist/lib/{shadow-claw-tools-COdrGZJk.js.map → shadow-claw-tools-D0T8m3go.js.map} +1 -1
- package/dist/lib/{shadow-claw-webvm-sxqVjO0L.js → shadow-claw-webvm-CQvzJwKI.js} +3 -3
- package/dist/lib/{shadow-claw-webvm-sxqVjO0L.js.map → shadow-claw-webvm-CQvzJwKI.js.map} +1 -1
- package/dist/lib/{sync-web-mcp-registration-D4hdUwtv.js → sync-web-mcp-registration-BFtG_4kx.js} +6 -6
- package/dist/lib/{sync-web-mcp-registration-D4hdUwtv.js.map → sync-web-mcp-registration-BFtG_4kx.js.map} +1 -1
- package/dist/lib/{system-prompt-DT_KeYaL.js → system-prompt-bhGRLoL2.js} +7 -7
- package/dist/lib/{system-prompt-DT_KeYaL.js.map → system-prompt-bhGRLoL2.js.map} +1 -1
- package/dist/lib/{tools-Beuyh8y1.js → tools-B8OJ4sMF.js} +4 -4
- package/dist/lib/{tools-Beuyh8y1.js.map → tools-B8OJ4sMF.js.map} +1 -1
- package/dist/lib/{transformers-DydnReu4.js → transformers-BMURofG6.js} +2 -2
- package/dist/lib/{transformers-DydnReu4.js.map → transformers-BMURofG6.js.map} +1 -1
- package/dist/lib/{trusted-types-CfwZl_rr.js → trusted-types-HwsGS5Nj.js} +19 -17
- package/dist/lib/{trusted-types-CfwZl_rr.js.map → trusted-types-HwsGS5Nj.js.map} +1 -1
- package/dist/lib/{upload-group-file-BbBzjTcN.js → upload-group-file-CJpoNjEb.js} +3 -3
- package/dist/lib/{upload-group-file-BbBzjTcN.js.map → upload-group-file-CJpoNjEb.js.map} +1 -1
- package/dist/lib/utils/index.js +1 -1
- package/dist/lib/utils/namespaced-storage.js +1 -1
- package/dist/lib/utils/runtime-assets.js +1 -1
- package/dist/lib/utils/utils.js +1 -1
- package/dist/lib/{webmcp-DCfAFiIO.js → webmcp-BoMTvgmX.js} +3 -3
- package/dist/lib/{webmcp-DCfAFiIO.js.map → webmcp-BoMTvgmX.js.map} +1 -1
- package/dist/lib/{write-group-file-bytes-Ccn-VFUU.js → write-group-file-bytes-CNT7DqOZ.js} +3 -3
- package/dist/lib/{write-group-file-bytes-Ccn-VFUU.js.map → write-group-file-bytes-CNT7DqOZ.js.map} +1 -1
- package/dist/public/.well-known/mcp/server-card.json +12 -4
- package/dist/public/.well-known/mcp.json +12 -4
- package/dist/public/agent.worker.js +1 -1
- package/dist/public/attachment-capabilities-AdwXt3--.js +1 -0
- package/dist/public/{channel-BylT3rJC.js → channel-Dk7wl-Av.js} +1 -1
- package/dist/public/{chat-template-DPHJy7tr.js → chat-template-BwAnTFKf.js} +1 -1
- package/dist/public/{compact-context-BINQh64w.js → compact-context-fOTqwKF6.js} +2 -2
- package/dist/public/config-C16fFWtP.js +1 -0
- package/dist/public/{configure-peer-js-DChhcOfe.js → configure-peer-js-BOV0tR6G.js} +1 -1
- package/dist/public/{connections-CHaw0VqP.js → connections-Dxwj8yK_.js} +1 -1
- package/dist/public/{create-model-cache-fetch-DQebkoPL.js → create-model-cache-fetch-DSAFjOwc.js} +1 -1
- package/dist/public/{credentials-CgVqS119.js → credentials-CJUQ5Ep2.js} +1 -1
- package/dist/public/{custom-element-security-kiDhPfb8.js → custom-element-security-B2daIE5r.js} +2 -2
- package/dist/public/{discover-skills-Cvmx5I9V.js → discover-skills-D1sNTy2r.js} +6 -6
- package/dist/public/docs/example/article/index.html +28 -29
- package/dist/public/docs/example/article.html +28 -29
- package/dist/public/docs/publishing/index.html +28 -29
- package/dist/public/docs/publishing.html +28 -29
- package/dist/public/docs/skill-creator/index.html +28 -29
- package/dist/public/docs/skill-creator.html +28 -29
- package/dist/public/{download-group-file-BapoRgfU.js → download-group-file-BkMH-JKi.js} +1 -1
- package/dist/public/{e2e-bridge-C0g8vZKr.js → e2e-bridge-Cz95DLlb.js} +1 -1
- package/dist/public/get-group-dir-D--BiEyk.js +1 -0
- package/dist/public/{get-or-create-subscriber-id-GvRZYXwA.js → get-or-create-subscriber-id-jVHnQfbr.js} +1 -1
- package/dist/public/{git-CaAAZfVd.js → git-BmMlwIMP.js} +2 -2
- package/dist/public/{iframe-bridge-scripts-BnqtKhE4.js → iframe-bridge-scripts-Cibg0m6A.js} +1 -1
- package/dist/public/index.html +28 -29
- package/dist/public/index.js +1 -1
- package/dist/public/{init-chat-split-resize-Btonoy8u.js → init-chat-split-resize-C8AqCCiK.js} +1 -1
- package/dist/public/init-control-plane-Cb31yLTY.js +1 -0
- package/dist/public/{invoke-agent-B3Osw6K7.js → invoke-agent-CN7mSV0Z.js} +1 -1
- package/dist/public/main/index.html +28 -29
- package/dist/public/main/memory/index.html +28 -29
- package/dist/public/main/memory.html +28 -29
- package/dist/public/main.html +28 -29
- package/dist/public/{markdown-CPbU4r1U.js → markdown-CDSb5Hrl.js} +1 -1
- package/dist/public/{mcp-reconnect-CzROVsXG.js → mcp-reconnect-iPZPihwX.js} +1 -1
- package/dist/public/{memory-storage-BkoMlxOr.js → memory-storage-2m7KZ-aP.js} +1 -1
- package/dist/public/{model-ranking-CK0iBo3Z.js → model-ranking-BgOSaNIy.js} +1 -1
- package/dist/public/{move-group-entry-CTxoq7lw.js → move-group-entry-CXneuNVa.js} +1 -1
- package/dist/public/orchestrator-DBO4NZqd.js +63 -0
- package/dist/public/{orchestrator-BrDjQbGf.js → orchestrator-Dyylc8IU.js} +2 -2
- package/dist/public/{peerjs-CgF4Iz5W.js → peerjs-l0jiBoh6.js} +1 -1
- package/dist/public/{process-peer-query-param-BL2k0Hu-.js → process-peer-query-param-s-aSP1Rq.js} +1 -1
- package/dist/public/{process-pending-shared-payloads-C1AgGvn8.js → process-pending-shared-payloads-BN3GigPT.js} +1 -1
- package/dist/public/{process-room-query-param-DM0QCq3_.js → process-room-query-param-B2Qe0F0M.js} +1 -1
- package/dist/public/provider-YPZmsuHR.js +1 -0
- package/dist/public/{push-client-DJEOz7bi.js → push-client-B2LC8Qp9.js} +1 -1
- package/dist/public/{rooms-C6LXIJl4.js → rooms-ChCEOvkw.js} +1 -1
- package/dist/public/service-worker.js +1 -1
- package/dist/public/shadow-claw-Br8mWDUx.js +1176 -0
- package/dist/public/{shadow-claw-accounts--4hd_oCz.js → shadow-claw-accounts-Dm6G7KMP.js} +1 -1
- package/dist/public/{shadow-claw-card-IbNlZAdK.js → shadow-claw-card-CggS8uSa.js} +1 -1
- package/dist/public/{shadow-claw-channels-Vq_pPGa2.js → shadow-claw-channels-088vhuWO.js} +1 -1
- package/dist/public/{shadow-claw-chat-D7_GS25e.js → shadow-claw-chat-BRwRlq-n.js} +3 -3
- package/dist/public/{shadow-claw-control-plane-WTMEV8_p.js → shadow-claw-control-plane-rhKACK85.js} +2 -2
- package/dist/public/{shadow-claw-conversations-CLQgU1IT.js → shadow-claw-conversations-CF_yUfKl.js} +1 -1
- package/dist/public/{shadow-claw-empty-state-D4CrFGsN.js → shadow-claw-empty-state-CkpOSXCS.js} +1 -1
- package/dist/public/{shadow-claw-file-viewer-BhqiqLWQ.js → shadow-claw-file-viewer-DWCejuY3.js} +4 -4
- package/dist/public/{shadow-claw-files-senDiG9l.js → shadow-claw-files-L6_ioyzh.js} +2 -2
- package/dist/public/{shadow-claw-git-DOOCqY23.js → shadow-claw-git-DsdkwLqQ.js} +2 -2
- package/dist/public/{shadow-claw-integrations-Bsvc3Agq.js → shadow-claw-integrations-CSbRTOm3.js} +1 -1
- package/dist/public/{shadow-claw-llm-actYICAk.js → shadow-claw-llm-BitaeAVc.js} +2 -2
- package/dist/public/{shadow-claw-mcp-remote-BYUgrK3v.js → shadow-claw-mcp-remote-gSbV5riy.js} +1 -1
- package/dist/public/{shadow-claw-networking-Dk3p5Ny_.js → shadow-claw-networking-Dn_y6Cl9.js} +1 -1
- package/dist/public/{shadow-claw-notifications-CzPAlay8.js → shadow-claw-notifications-Cj4Lqx8U.js} +1 -1
- package/dist/public/{shadow-claw-page-header-CjJpVkyL.js → shadow-claw-page-header-DR4OZFt2.js} +1 -1
- package/dist/public/{shadow-claw-page-header-action-button-2DH5O1TD.js → shadow-claw-page-header-action-button-BnCV_2Kb.js} +1 -1
- package/dist/public/{shadow-claw-pages-3r5I-wI8.js → shadow-claw-pages-mpDOtNYj.js} +6 -6
- package/dist/public/{shadow-claw-pdf-viewer-BiCEwsoY.js → shadow-claw-pdf-viewer-DZ_84qJH.js} +1 -1
- package/dist/public/{shadow-claw-settings-DgB9RSZN.js → shadow-claw-settings-CfFTYTEy.js} +2 -2
- package/dist/public/{shadow-claw-storage-JB_43nd8.js → shadow-claw-storage-DLmiT4bG.js} +1 -1
- package/dist/public/{shadow-claw-task-server-oi5UIxdA.js → shadow-claw-task-server-BoMBCsiS.js} +1 -1
- package/dist/public/{shadow-claw-tasks-CnyiOt81.js → shadow-claw-tasks-ChEp1j7x.js} +3 -3
- package/dist/public/{shadow-claw-terminal-BC3RynHt.js → shadow-claw-terminal-BaoVbOda.js} +1 -1
- package/dist/public/{shadow-claw-toast-YjG--2Za.js → shadow-claw-toast-e8oz7z6Z.js} +1 -1
- package/dist/public/{shadow-claw-tools-Bbwk4vlT.js → shadow-claw-tools-BYjUBiJz.js} +1 -1
- package/dist/public/{shadow-claw-webvm-HZqzl2H5.js → shadow-claw-webvm-xGb13TME.js} +1 -1
- package/dist/public/{sync-web-mcp-registration-BaH2nAP0.js → sync-web-mcp-registration-CQluj-Kz.js} +1 -1
- package/dist/public/{system-prompt-Dck3N8T0.js → system-prompt-CTJn0tK-.js} +1 -1
- package/dist/public/{tools-DHA1dK2I.js → tools-D-52Zmfc.js} +1 -1
- package/dist/public/{transformers-C-DuTM2K.js → transformers-CQ9ss9rD.js} +1 -1
- package/dist/public/{upload-group-file-Cejr3zo1.js → upload-group-file-A8kB7lvO.js} +1 -1
- package/dist/public/{webmcp-CMRtu57-.js → webmcp-DIUZjVF5.js} +1 -1
- package/dist/public/{write-group-file-CmJuVQNO.js → write-group-file-R67DjJ-q.js} +1 -1
- package/dist/public/{write-group-file-bytes-Cejr3zo1.js → write-group-file-bytes-A8kB7lvO.js} +1 -1
- package/dist/public/{zip-reader-CuQ13eLe.js → zip-reader-DN7FB-Q0.js} +1 -1
- package/dist/server.js +1 -1
- package/package.json +1 -1
- package/dist/cli/chunk-BFziiMKt.js +0 -7
- package/dist/cli/chunk-BM3llsxb.js +0 -1
- package/dist/cli/chunk-Bj5qFsDi.js +0 -7
- package/dist/cli/chunk-Bj95zm-y.js +0 -1
- package/dist/cli/chunk-BpyP-esT.js +0 -1
- package/dist/cli/chunk-CX696s3_.js +0 -1
- package/dist/cli/chunk-DRxCrCAA.js +0 -139
- package/dist/cli/chunk-DjbCHa0h.js +0 -1
- package/dist/cli/chunk-DsQhAF31.js +0 -1
- package/dist/cli/chunk-VM-dECyG.js +0 -1
- package/dist/cli/chunk-heu2xRw1.js +0 -1
- package/dist/lib/orchestrator-i_QJ-o22.js.map +0 -1
- package/dist/lib/shadow-claw-DoQ7fgl5.js.map +0 -1
- package/dist/public/app-routes-V_-URXc5.js +0 -1
- package/dist/public/attachment-capabilities-B6ibLwQB.js +0 -1
- package/dist/public/config-C-YdSFZB.js +0 -1
- package/dist/public/get-group-dir-DL44kvqW.js +0 -1
- package/dist/public/init-control-plane-BoJijVtf.js +0 -1
- package/dist/public/orchestrator-CaUpEVkQ.js +0 -63
- package/dist/public/provider-DNIL4-Hw.js +0 -1
- package/dist/public/shadow-claw-DdgeYPg5.js +0 -1176
package/dist/server.js
CHANGED
|
@@ -3690,7 +3690,7 @@ x8e=Object.defineProperty,S8e=(e,t,n)=>t in e?x8e(e,t,{enumerable:!0,configurabl
|
|
|
3690
3690
|
(id, groupId, enabled, schedule, prompt, tools, lastRun, createdAt, type, freshContext, subagent, name, task_order, pushNotifications)
|
|
3691
3691
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`);for(let e of i)a.run(Hf(),n,+!!e.enabled,e.schedule??null,e.prompt??``,e.tools??null,e.lastRun??null,e.createdAt,e.type??null,e.freshContext?1:null,e.subagent?1:null,e.name??null,e.task_order??null,e.pushNotifications?1:null);return Promise.resolve(i.length)}return new Promise((r,i)=>{let a=e?.transaction(`tasks`,`readwrite`);if(!a)throw Error(`failed to get transaction, cannot clone tasks.`);let o=a.objectStore(`tasks`),s=o.index(`by-group`).openCursor(t),c=0;s.onsuccess=()=>{let e=s.result;if(e){let t={...e.value,id:Hf(),groupId:n};o.put(t),c++,e.continue()}else r(c)},s.onerror=()=>i(s.error)})}var G8e=R((()=>{qf(),ma()}));function K8e(e,t){return _a(e,`messages`,`readwrite`,e=>e.delete(t)).then(()=>void 0)}var q8e=R((()=>{va()}));function J8e(e,t){return t?_a(e,`tasks`,`readwrite`,e=>e.delete(t)).then(()=>void 0):Promise.reject(/* @__PURE__ */ Error(`Task ID is required for deletion.`))}var Y8e=R((()=>{va()}));function pO(e){return _a(e,`tasks`,`readonly`,e=>e.getAll()).then(e=>e.map(e=>({...e,enabled:!!e.enabled})))}var mO=R((()=>{va()}));function X8e(){return typeof crypto<`u`&&typeof crypto.randomUUID==`function`?crypto.randomUUID():`sub-${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`}async function hO(e){if(!e)return X8e();let t=await ba(e,V.SUBSCRIBER_ID);if(typeof t==`string`&&t.trim().length>0)return t;let n=X8e();return await BD(e,V.SUBSCRIBER_ID,n),n}var Z8e=R((()=>{Mn(),xa(),VD()}));function Q8e(e,t,n){let r=null,i,a;return typeof e==`string`?(i=e,a=t):(r=e,i=t,a=n??50),r&&fa(r)?Promise.resolve().then(()=>(r.db.prepare(`SELECT * FROM messages WHERE groupId = ? ORDER BY timestamp DESC LIMIT ?`).all(i,a)??[]).reverse().map($8e)):new Promise(async(e,t)=>{try{let n=r??await aa();if(!n)return t(/* @__PURE__ */ Error(`failed to get transaction, cannot get recent messages.`));let o=n.transaction(`messages`,`readonly`);if(!o)return t(/* @__PURE__ */ Error(`failed to get transaction`));let s=o.objectStore(`messages`).index(`by-group-time`),c=IDBKeyRange.bound([i,0],[i,1/0]),l=s.openCursor(c,`prev`),u=[];l.onsuccess=()=>{let t=l.result;t&&u.length<a?(u.push(t.value),t.continue()):e(u.reverse())},l.onerror=()=>t(l.error)}catch(e){t(e)}})}function $8e(e){return{...e,isFromMe:!!e.isFromMe,isTrigger:!!e.isTrigger,attachments:e.attachments?JSON.parse(e.attachments):void 0,a2uiAction:e.a2uiAction?JSON.parse(e.a2uiAction):void 0,a2uiEnvelopes:e.a2uiEnvelopes?JSON.parse(e.a2uiEnvelopes):void 0}}var e5e=R((()=>{da(),ma()}));async function gO(e){let t=await ba(e,u5e);if(!t)return[];try{return JSON.parse(t)}catch{return[]}}async function _O(e,t){await BD(e,u5e,JSON.stringify(t))}async function t5e(e,t,n=`br:`,r){let i=await gO(e),a={groupId:`${n}${r??Hf()}`,name:t,createdAt:Date.now()};return i.push(a),await _O(e,i),a}async function n5e(e,t,n){let r=await gO(e),i=r.find(e=>e.groupId===t);i&&(i.name=n),await _O(e,r)}async function r5e(e,t,n){let r=await gO(e),i=r.find(e=>e.groupId===t);i&&(n&&n.length>0?i.toolTags=n:delete i.toolTags),await _O(e,r)}async function i5e(e,t){await _O(e,(await gO(e)).filter(e=>e.groupId!==t))}async function vO(e){let t=await gO(e);if(t.length===0){let t={groupId:fn,name:`Main`,createdAt:0};return await _O(e,[t]),[t]}return t}async function a5e(e,t){let n=await gO(e),r=new Map(n.map(e=>[e.groupId,e])),i=[];for(let e of t){let t=r.get(e);t&&(i.push(t),r.delete(e))}for(let e of n)r.has(e.groupId)&&i.push(e);await _O(e,i)}async function o5e(e,t){let n=await gO(e),r=n.find(e=>e.groupId===t);if(!r)return null;let i=t.indexOf(`:`),a={groupId:`${i>=0?t.slice(0,i+1):`br:`}${Hf()}`,name:`${r.name} (copy)`,createdAt:Date.now(),pinnedMaxTokens:r.pinnedMaxTokens,providerRuntimeOverrides:r.providerRuntimeOverrides?JSON.parse(JSON.stringify(r.providerRuntimeOverrides)):void 0,subagentModelSelectionMode:r.subagentModelSelectionMode,subagentMaxTokens:r.subagentMaxTokens,subagentPinnedProvider:r.subagentPinnedProvider,subagentPinnedModel:r.subagentPinnedModel,subagentFastProvider:r.subagentFastProvider,subagentFastModel:r.subagentFastModel,subagentSmartProvider:r.subagentSmartProvider,subagentSmartModel:r.subagentSmartModel,subagentPowerfulProvider:r.subagentPowerfulProvider,subagentPowerfulModel:r.subagentPowerfulModel,toolTags:r.toolTags?[...r.toolTags]:void 0};return n.push(a),await _O(e,n),a}async function s5e(e,t,n,r,i){let a=await gO(e),o=a.find(e=>e.groupId===t);o&&(n?o.pinnedProvider=n:delete o.pinnedProvider,r?o.pinnedModel=r:delete o.pinnedModel,typeof i==`number`&&Number.isFinite(i)&&i>0?o.pinnedMaxTokens=Math.floor(i):delete o.pinnedMaxTokens),await _O(e,a)}async function c5e(e,t,n,r,i,a){let o=await gO(e),s=o.find(e=>e.groupId===t);s&&(s.subagentModelSelectionMode=n,n===`manual`?(r?s.subagentPinnedProvider=r:delete s.subagentPinnedProvider,i?s.subagentPinnedModel=i:delete s.subagentPinnedModel):(delete s.subagentPinnedProvider,delete s.subagentPinnedModel),typeof a==`number`&&Number.isFinite(a)&&a>0?s.subagentMaxTokens=Math.floor(a):delete s.subagentMaxTokens),await _O(e,o)}async function l5e(e,t,n){let r=await gO(e),i=r.find(e=>e.groupId===t);i&&(n&&Object.keys(n).length>0?i.providerRuntimeOverrides=JSON.parse(JSON.stringify(n)):delete i.providerRuntimeOverrides),await _O(e,r)}var u5e,d5e=R((()=>{Mn(),xa(),VD(),qf(),u5e=`group_metadata`}));function yO(e,t){return _a(e,`messages`,`readwrite`,e=>e.put(t)).then(()=>void 0)}var f5e=R((()=>{va()}));function bO(e,t){let n={...t,enabled:+!!t.enabled};return _a(e,`tasks`,`readwrite`,e=>e.put(n)).then(()=>void 0)}var p5e=R((()=>{va()}));function m5e(e,t,n){let r=null,i,a;return typeof e==`string`?(i=e,a=t):(r=e,i=t,a=n),r&&fa(r)?Promise.resolve().then(()=>{r.db.prepare(`UPDATE tasks SET lastRun = ? WHERE id = ?`).run(a,i)}):new Promise(async(e,t)=>{try{let n=r??await aa();if(!n)return t(/* @__PURE__ */ Error(`failed to get transaction, cannot update task last run.`));let o=n.transaction(`tasks`,`readwrite`);if(!o)return t(/* @__PURE__ */ Error(`failed to get transaction`));let s=o.objectStore(`tasks`),c=s.get(i);c.onsuccess=()=>{let n=c.result;if(!n){e();return}n.lastRun=a;let r=s.put(n);r.onsuccess=()=>e(),r.onerror=()=>t(r.error)},c.onerror=()=>t(c.error)}catch(e){t(e)}})}var h5e=R((()=>{da(),ma()}));async function g5e(e,t,n){let r=(await pO(e)).filter(e=>e.groupId===t),i=new Map(r.map(e=>[e.id,e])),a=[],o=0;for(let t of n){let n=i.get(t);n&&(n.order=o++,await bO(e,n),a.push(n),i.delete(t))}let s=Array.from(i.values()).sort((e,t)=>{let n=e.order??0,r=t.order??0;return n===r?e.createdAt-t.createdAt:n-r});for(let t of s)t.order=o++,await bO(e,t),a.push(t);return a}var _5e=R((()=>{mO(),p5e()}));async function v5e(e,t,n,r){let i=await Lp(e,t),a=await Lp(e,n),o=r.replace(/\\/g,`/`).replace(/^\/+/,``).split(`/`).filter(Boolean),s=i,c=a;for(let e of o)s=await s.getDirectoryHandle(e),c=await c.getDirectoryHandle(e,{create:!0});let l=n.replace(/:/g,`-`),u=[yp(),`groups`,l,...o];try{await y5e(e,n,s,c,u)}catch(e){throw o.length>0&&await a.removeEntry(o[0],{recursive:!0}).catch(()=>void 0),e}}async function y5e(e,t,n,r,i){for await(let[a,o]of n.entries()){if(o.kind===`directory`){await y5e(e,t,o,await r.getDirectoryHandle(a,{create:!0}),[...i,a]);continue}let n=await o.getFile(),s=await r.getFileHandle(a,{create:!0});try{await FD(s,n)}catch(t){if(!((t instanceof Error?t.message:String(t)).includes(`Writable file streams are not supported`)&&(await wp(e)).type===`opfs`))throw t;await ID([...i,a],n)}}}var b5e=R((()=>{Rp(),Ep(),LD()}));async function xO(e,t,n=`.`){for(let r=0;r<2;r++)try{let r=await Lp(e,t);if(n&&n!==`.`){let e=n.replace(/\\/g,`/`).replace(/^\/home\/user\//,`/`).replace(/^\/+/,``).split(`/`).filter(Boolean);for(let t of e){let e=await r.getDirectoryHandle(t);if(typeof r.isSameEntry==`function`&&await r.isSameEntry(e))throw Error(`Directory navigation stuck at "${r.name}" for segment "${t}" — the stored directory handle may be stale.`);r=e}}let i=[];for await(let[e,t]of r.entries())i.push(t.kind===`directory`?`${e}/`:e);return i.sort()}catch(e){if(r===0&&Cp(e)){Sp();continue}throw e}return[]}var SO=R((()=>{Rp(),Ep()}));function x5e(e){if(!e||typeof e!=`object`)return!1;let t=globalThis.FileSystemDirectoryHandle;return t!==void 0&&e instanceof t||typeof e.getDirectoryHandle==`function`&&typeof e.getFileHandle==`function`&&typeof e.requestPermission==`function`}async function S5e(e){let t=await ba(e,V.STORAGE_HANDLE);return!x5e(t)||await t.requestPermission({mode:`readwrite`})===`granted`}var C5e=R((()=>{Mn(),xa()}));function w5e(e){let t=Lt();return t?`shadowclaw:${t}:${e}`:e}function T5e(e){if(typeof localStorage>`u`)return null;let t=w5e(e);try{let n=localStorage.getItem(t);if(n!==null)return n;if(t===e)return null;let r=localStorage.getItem(e);if(r!==null)return localStorage.setItem(t,r),r}catch(e){console.warn(`Unable to read from localStorage:`,e)}return null}function E5e(e,t){if(typeof localStorage>`u`)return;let n=w5e(e);try{localStorage.setItem(n,t)}catch(e){console.warn(`Unable to write to localStorage:`,e)}}var D5e=R((()=>{Gt()}));async function O5e(e,t){let n=await Lp(e,t);for await(let[e]of n.entries())await n.removeEntry(e,{recursive:!0})}var k5e=R((()=>{Rp()}));async function CO(e,t,n){let r=await Lp(e,t),{dirs:i,filename:a}=zp(n.replace(/\/$/,``)),o=r;for(let e of i)o=await o.getDirectoryHandle(e);await o.removeEntry(a,{recursive:!0})}var A5e=R((()=>{Rp(),Bp()}));function wO(e,t){return`${e}:${t}`}async function j5e(e){let t=await ba(e,V.SUPPRESSED_PAGES_LIST);if(!t||typeof t!=`string`)return[];try{let e=JSON.parse(t);if(Array.isArray(e))return e}catch{}return[]}async function M5e(e,t,n){let r=await j5e(e),i=wO(t,n);return r.some(e=>wO(e.groupId,e.path)===i)}async function N5e(e,t,n){let r=await j5e(e),i=wO(t,n);if(!r.some(e=>wO(e.groupId,e.path)===i)){let i=[...r,{groupId:t,path:n}];await BD(e,V.SUPPRESSED_PAGES_LIST,JSON.stringify(i))}}async function P5e(e,t,n){let r=await j5e(e),i=wO(t,n),a=r.filter(e=>wO(e.groupId,e.path)!==i);a.length!==r.length&&await BD(e,V.SUPPRESSED_PAGES_LIST,JSON.stringify(a))}var F5e=R((()=>{Mn(),xa(),VD()}));function TO(e){return Array.from(new Set(e.map(e=>e.trim()).filter(Boolean)))}var EO=R((()=>{}));function I5e(e){let t=e.trim().replace(/\\/g,`/`);return t===`/`||/^\/+$/.test(t)?`/`:t.replace(/^\/+/,``).replace(/\/+$/,``)}function DO(e){return e===`/`?`/`:e.replace(U5e,``)}function L5e(e){let t=e.trim().replace(/\\/g,`/`);return t===`/`||/^\/+$/.test(t)?`/`:t.replace(/^\/+/,``).replace(/\/+$/,``)}function R5e(e){return e?e.replace(/^br:/i,``).replace(/^br-/i,``).trim():`main`}function OO(e,t){let n=L5e(t);if(!n)return;e.add(n);let r=DO(n);r&&r!==n&&e.add(r)}function z5e(e,t,n){let r=/* @__PURE__ */ new Set;if(!e)return r;let i=R5e(t);if(e===`/`){if(r.add(`/`),OO(r,`index.html`),n){let e=I5e(n);e&&e!==`/`&&OO(r,`${e}/index.html`)}return OO(r,`pages/index.html`),OO(r,`pages/${i}/index.html`),OO(r,`${i}/index.html`),r}if(OO(r,e),n){let t=I5e(n);t&&t!==`/`&&OO(r,`${t}/${e}`)}if(e.startsWith(`pages/`)){let t=e.slice(6);OO(r,t),t.startsWith(`${i}/`)?OO(r,t.slice(`${i}/`.length)):OO(r,t.replace(/^[^/]+\//,``))}else OO(r,`pages/${e}`),OO(r,`pages/${i}/${e}`),OO(r,`${i}/${e}`);for(let e of Array.from(r)){let t=DO(e);if(e===`index.html`||t===`index`){r.add(`/`);break}}return r}function B5e(e,t){let n=t.toLowerCase(),r=DO(t).toLowerCase(),i=n===r?[n]:[n,r];for(let t of e){let e=t.toLowerCase(),n=DO(e);for(let t of i)if(t&&(e===t||n===t||t!==`/`&&(e.startsWith(`${t}/`)||n.startsWith(`${t}/`)||e.endsWith(`/${t}`)||n.endsWith(`/${t}`)||e.includes(`/${t}/`)||n.includes(`/${t}/`))))return!0}return!1}function V5e(e,t){for(let n of t){let t=I5e(n);if(t&&B5e(e,t))return!0}return!1}function H5e(e,t,n,r){if(!e||typeof e!=`string`)return!1;let i=L5e(e);if(!i)return!1;let a=[],o=[],s,c;if(t&&typeof t==`object`&&!Array.isArray(t)){let e=t,n=e.allowList??e.allowlist??[],r=e.denyList??e.denylist??[];a=TO(Array.from(n||[])),o=TO(Array.from(r||[])),s=e.groupId,c=e.basePathPrefix}else a=TO(Array.from(t||[])),o=TO(Array.from(n||[])),s=r?.groupId,c=r?.basePathPrefix;let l=z5e(i,s,c);return o.length>0&&V5e(l,o)?!1:a.length>0?V5e(l,a):!0}var U5e,W5e=R((()=>{EO(),U5e=/\.(md|markdown|html|xhtml|txt)$/i}));function G5e(e){if(!e)return``;let t=e.match(/^\r?\n([ \t]+)/);if(t){let n=t[1],r=RegExp(`^[ \\t]{1,${n.length}}`,`gm`);return e.replace(/^\r?\n/,``).replace(r,``).replace(/\r?\n[ \t]*$/,`
|
|
3692
3692
|
`)}if(/^(?:\r?\n)+[ \t]*---/.test(e))return e.replace(/^(?:\r?\n)+/,``);if(/^[ \t]+---/.test(e)){let t=e.match(/^[ \t]+/);if(t){let n=t[0],r=RegExp(`^[ \\t]{1,${n.length}}`,`gm`);return e.replace(r,``)}}return e}var K5e=R((()=>{}));function q5e(e=fn){return e===`br:main`?V.STATIC_MAIN_SITE_SEEDED:`${V.STATIC_MAIN_SITE_SEEDED}:${e}`}async function J5e(e,t=fn){let n=await ba(e,q5e(t));return n===!0||n===`true`}async function Y5e(e,t=fn,n=!0){await BD(e,q5e(t),n)}function X5e(){let e=zt(`/${f7e}`);if(typeof window<`u`&&window.location?.origin)try{return new URL(e,window.location.origin).toString()}catch{return e}return e}function Z5e(e){let t=e.replace(/^\/+/,``),n=p7e;if(typeof document<`u`)try{let e=document.getElementById(`shadow-claw-site-config`);if(e?.textContent){let t=JSON.parse(e.textContent);typeof t?.pages?.baseUrl==`string`&&(n=t.pages.baseUrl.replace(/^\/+/,``).replace(/\/+$/,``))}}catch{}let r=zt(n?`/${n}/${t}`:`/${t}`);if(typeof window<`u`&&window.location?.origin)try{return new URL(r,window.location.origin).toString()}catch{return r}return r}async function Q5e(){if(typeof fetch!=`function`)return null;try{let e=X5e(),t=await fetch(e);if(t.ok){if((t.headers?.get?.(`content-type`)||``).includes(`text/html`))return null;let e=await t.json();if(e&&Array.isArray(e.pages))return e}}catch{}return null}async function $5e(e){if(typeof fetch!=`function`)return null;try{let t=Z5e(e),n=await fetch(t);if(n.ok){let t=n.headers?.get?.(`content-type`)||``;if((e.endsWith(`.md`)||e.endsWith(`.markdown`)||e.endsWith(`.json`))&&t.includes(`text/html`))return null;let r=await n.text();return r.includes(`<shadow-claw`)||r.includes(`data-shadow-claw-dsd`)?null:r}}catch{}return null}function e7e(e){if(typeof document>`u`)return null;let t=t=>{if(!t||!(t instanceof HTMLElement))return!1;if(!e)return!0;let n=t.getAttribute(`data-initial-path`)?.trim();return!n||n===e},n=document.querySelector(e?`[data-pages-rendered][data-initial-path="${e}"]`:`[data-pages-rendered]`);if(t(n))return n;let r=document.querySelector(`shadow-claw`)?.shadowRoot,i=(r?.querySelector(`shadow-claw-pages`)?.shadowRoot)?.querySelector(e?`[data-pages-rendered][data-initial-path="${e}"]`:`[data-pages-rendered]`)||r?.querySelector(e?`[data-pages-rendered][data-initial-path="${e}"]`:`[data-pages-rendered]`);if(t(i))return i;let a=document.querySelectorAll(`template`);for(let n of Array.from(a)){let r=n.content?.querySelector(e?`[data-pages-rendered][data-initial-path="${e}"]`:`[data-pages-rendered]`);if(t(r))return r;let i=n.content?.querySelectorAll(`template`);if(i)for(let n of Array.from(i)){let r=n.content?.querySelector(e?`[data-pages-rendered][data-initial-path="${e}"]`:`[data-pages-rendered]`);if(t(r))return r}}return null}function kO(e=`index.html`){let t=e7e(e);if(!t)return null;let n=t.getAttribute(`data-initial-path`)?.trim();if(n&&n!==e)return null;let r=t.querySelector(`[data-markdown-frontmatter]`),i=null;if(r){let e=r.getAttribute(`data-frontmatter`);if(e)try{i=JSON.parse(e)}catch{}}let a=t.cloneNode(!0),o=a.querySelector(`[data-markdown-frontmatter]`);o&&o.remove();let s=a.innerHTML.trim();if(!s&&!i)return null;if(i&&Object.keys(i).length>0){let e=[`---`];for(let[t,n]of Object.entries(i))typeof n==`string`?e.push(`${t}: ${JSON.stringify(n)}`):typeof n==`number`||typeof n==`boolean`?e.push(`${t}: ${n}`):e.push(`${t}: ${JSON.stringify(n)}`);return e.push(`---`,``),`${e.join(`
|
|
3693
|
-
`)}\n${s}`}return s}async function t7e(e={}){let t=()=>{let e=null;if(typeof document<`u`){let t=document.getElementById(`shadow-claw-static-manifest`);if(t&&t.textContent)try{let n=JSON.parse(t.textContent);n&&Array.isArray(n.pages)&&(e={...n,pages:[...n.pages]})}catch(e){console.warn(`Failed to parse embedded static main manifest:`,e)}let n=document.querySelectorAll(`script[type="text/markdown"][data-shadow-claw-page]`);if(n.length>0){e||={pages:[]};for(let t of Array.from(n)){let n=t.getAttribute(`data-shadow-claw-page`)?.trim();if(n){let r=t.textContent||``;r=G5e(r),!r.trim()&&/^memory\.(md|markdown)$/iu.test(n)&&(r=HD),!r.trim()&&(n===`index.html`||/^index\.(html?|xhtml)$/iu.test(n))&&(r=kO(n)??YD);let i=e.pages.findIndex(e=>e.displayPath===n);i>=0?e.pages[i].content=r:e.pages.push({displayPath:n,content:r})}}}let r=document.getElementById(`shadow-claw-site-config`);if(r?.textContent)try{let t=JSON.parse(r.textContent);if(Array.isArray(t?.pages?.files)){e||={pages:[]};for(let n of t.pages.files)if(typeof n==`string`&&n.trim()){let t=n.trim(),r=``;/^memory\.(md|markdown)$/iu.test(t)?r=HD:(t===`index.html`||/^index\.(html?|xhtml)$/iu.test(t))&&(r=kO(t)??YD),e.pages.some(e=>e.displayPath===t)||e.pages.push({displayPath:t,content:r})}}}catch{}let i=e7e();if(i){e||={pages:[]};let t=i.getAttribute(`data-initial-path`)?.trim()||`index.html`;if(!e.pages.some(e=>e.displayPath===t)){let n=kO(t)??YD;e.pages.push({displayPath:t,content:n})}e.pages.some(e=>/^memory\.(md|markdown)$/iu.test(e.displayPath))||e.pages.push({displayPath:`MEMORY.md`,content:HD})}}return e};if(e.preferEmbedded!==!1){let e=t();if(e)return e}if(e.fetchFallback!==!1){let e=await Q5e();if(e)return e}if(e.preferEmbedded===!1){let e=t();if(e)return e}return{pages:[{displayPath:`index.html`,content:YD},{displayPath:`MEMORY.md`,content:HD}]}}async function n7e(e,t,n=[]){for(let[r,i]of Object.entries(t))if(r===`purgePreRenderedStaticPages`&&i===!0){if(n.length>0){let t=n[0],r=n.slice(1).join(`/`);try{r?await CO(e,t,r):await O5e(e,t)}catch(e){console.warn(`Failed to purge pre-rendered static pages for ${t}/${r}:`,e)}}}else typeof i==`object`&&i&&await n7e(e,i,[...n,r])}function r7e(){if(typeof document<`u`)try{let e=document.getElementById(`shadow-claw-site-config`);if(e?.textContent){let t=JSON.parse(e.textContent);if(t?.pages?.sortOrder===`desc`)return`desc`;if(t?.pages?.sortOrder===`asc`)return`asc`}}catch{}return`desc`}function i7e(){if(typeof document<`u`)try{let e=document.getElementById(`shadow-claw-site-config`);if(e?.textContent){let t=JSON.parse(e.textContent)?.pages?.defaultPinnedPage;if(typeof t==`string`&&t.trim().length>0)return t.trim()}}catch{}return null}function a7e(){if(typeof document<`u`)try{let e=document.getElementById(`shadow-claw-site-config`);if(e?.textContent){let t=JSON.parse(e.textContent);return{allowList:TO(t?.pages?.allowList??t?.pages?.allowlist??t?.allowList??t?.allowlist??[]),denyList:TO(t?.pages?.denyList??t?.pages?.denylist??t?.denyList??t?.denylist??[])}}}catch{}return{allowList:[],denyList:[]}}function o7e(e,t){let n=t??r7e();return[...e].sort((e,t)=>{let r=e.path,i=t.path,a=r.split(`/`).pop()||``,o=i.split(`/`).pop()||``,s=/^index\.(html?|xhtml)$/iu.test(a),c=/^index\.(html?|xhtml)$/iu.test(o);if(s&&!c)return-1;if(!s&&c)return 1;let l=/^memory\.(md|markdown)$/iu.test(a),u=/^memory\.(md|markdown)$/iu.test(o);return l&&!u?1:!l&&u?-1:n===`asc`?r.localeCompare(i,void 0,{numeric:!0,sensitivity:`base`}):i.localeCompare(r,void 0,{numeric:!0,sensitivity:`base`})})}async function s7e(e,t,n=l7e,r=u7e){let i=t??d7e;try{if(T5e(n)===i)return!0}catch{}try{if(await ba(e,r)===i){try{E5e(n,i)}catch{}return!0}await BD(e,r,i);try{E5e(n,i)}catch{}}catch{try{E5e(n,i)}catch{}}return!1}async function c7e(e,t=fn,n=[],r={}){await X6e(e,t);let i=await t7e(r),a=!1;i.preRenderedStaticPages&&(await s7e(e,i.purgeId)||(a=!0,await n7e(e,i.preRenderedStaticPages)));let o=!1;if(t===`br:main`&&i.skillsPurgeId!==void 0&&!await s7e(e,i.skillsPurgeId,`sc:skills-purge-id`,`static_main_skills_purge_id`)){o=!0;try{await CO(e,t,`.agents/skills/main`)}catch(e){if(!(e&&typeof e==`object`&&`name`in e&&e.name===`NotFoundError`))throw e}try{await CO(e,t,`.agents/tools/main`)}catch(e){if(!(e&&typeof e==`object`&&`name`in e&&e.name===`NotFoundError`))throw e}}for(let n of i.pages)if(n.content?.includes(`slug: "shadow-claw--purge-pages"`)){!a&&!await s7e(e,i.purgeId)&&(a=!0,await O5e(e,t));break}let s=t===`br:main`&&await GD(e),c=new Set(i.pages.map(e=>wO(t,e.displayPath))),l=a?n.filter(e=>e.groupId!==t||c.has(wO(e.groupId,e.path))):[...n],{allowList:u,denyList:d}=a7e(),f=0;for(let n of i.pages)if(f++,f%5==0&&await new Promise(e=>setTimeout(e,0)),!n.content?.includes(`slug: "shadow-claw--purge-pages"`)&&H5e(n.displayPath,{allowList:u,denyList:d,groupId:t})){if(/^memory\.(md|markdown)$/iu.test(n.displayPath)){if(s)continue;let r=typeof n.content==`string`&&n.content.trim().length>0&&n.content!==HD?n.content:void 0;if(r===void 0?await qD(e,t):await qD(e,t,r)){let e=wO(t,n.displayPath);l.some(t=>wO(t.groupId,t.path)===e)||l.push({groupId:t,path:n.displayPath})}}else if(!await M5e(e,t,n.displayPath))try{if(!await UD(e,t,n.displayPath)){let r=n.content;(typeof r!=`string`||!r.trim())&&(r=n.displayPath===`index.html`?kO(`index.html`)??YD:await $5e(n.displayPath)??``),await RD(e,t,n.displayPath,r)}let r=wO(t,n.displayPath);l.some(e=>wO(e.groupId,e.path)===r)||l.push({groupId:t,path:n.displayPath})}catch(e){console.warn(`Failed to seed static page file ${n.displayPath}:`,e)}}if(t===`br:main`){for(let n of i.skills||[]){let r=`.agents/skills/main/${n.displayPath}`;try{await UD(e,t,r)||await RD(e,t,r,n.content)}catch(e){console.warn(`Failed to seed skill file ${r}:`,e)}}for(let n of i.tools||[]){let r=`.agents/tools/main/${n.displayPath}`;try{(o||!await UD(e,t,r))&&await RD(e,t,r,n.content)}catch(e){console.warn(`Failed to seed tool file ${r}:`,e)}}}let p=typeof document<`u`&&(document.getElementById(`shadow-claw-static-manifest`)!==null||document.querySelector(`script[type="text/markdown"][data-shadow-claw-page]`)!==null||e7e()!==null);r.preferEmbedded!==!1&&p||await Y5e(e,t,!0);let m=l.filter(e=>H5e(e.path,{allowList:u,denyList:d,groupId:e.groupId}));return Object.defineProperty(m,"didPurge",{value:a,enumerable:!1,writable:!0,configurable:!0}),Object.defineProperty(m,"didPurgeSkills",{value:o,enumerable:!1,writable:!0,configurable:!0}),o7e(m)}var l7e,u7e,d7e,f7e,p7e,m7e=R((()=>{Mn(),D5e(),K6e(),H6e(),Gt(),xa(),VD(),k5e(),A5e(),Q6e(),G6e(),WD(),F5e(),zD(),W5e(),EO(),K5e(),l7e=`sc:purge-id`,u7e=`static_main_site_purge_id`,d7e=`__legacy_purge_pages__`,f7e=`static-main-manifest.json`,p7e=`static-main`})),h7e,g7e=R((()=>{qf(),h7e=class{_events;_handlers=[];_runs=/* @__PURE__ */ new Map;constructor(e){this._events=e}start(){this._listen(`streaming-start`,this._onStreamingStart),this._listen(`streaming-chunk`,this._onStreamingChunk),this._listen(`streaming-end`,this._onStreamingEnd),this._listen(`streaming-done`,this._onStreamingDone),this._listen(`streaming-error`,this._onStreamingError),this._listen(`tool-activity`,this._onToolActivity)}stop(){for(let{event:e,handler:t}of this._handlers)this._events.off(e,t);this._handlers=[],this._runs.clear()}_emit(e,t){window.dispatchEvent(new CustomEvent(`shadow-claw-agui-event`,{detail:{groupId:e,event:t}}))}_listen(e,t){this._events.on(e,t),this._handlers.push({event:e,handler:t})}_onStreamingChunk=({groupId:e,text:t})=>{let n=this._runs.get(e);n&&n.messageId&&this._emit(e,{type:`TEXT_MESSAGE_CONTENT`,messageId:n.messageId,delta:t,timestamp:Date.now()})};_onStreamingDone=({groupId:e})=>{let t=this._runs.get(e);t&&(t.messageId&&this._emit(e,{type:`TEXT_MESSAGE_END`,messageId:t.messageId,timestamp:Date.now()}),this._emit(e,{type:`RUN_FINISHED`,threadId:t.threadId,runId:t.runId,timestamp:Date.now()}),this._runs.delete(e))};_onStreamingEnd=({groupId:e})=>{let t=this._runs.get(e);t&&t.messageId&&(this._emit(e,{type:`TEXT_MESSAGE_END`,messageId:t.messageId,timestamp:Date.now()}),t.messageId=null)};_onStreamingError=({groupId:e,error:t})=>{let n=this._runs.get(e);n&&(n.messageId&&this._emit(e,{type:`TEXT_MESSAGE_END`,messageId:n.messageId,timestamp:Date.now()}),this._emit(e,{type:`RUN_ERROR`,message:t||`Unknown streaming error`,timestamp:Date.now()}),this._runs.delete(e))};_onStreamingStart=({groupId:e})=>{let t=Hf(),n=e,r=Hf();this._runs.set(e,{runId:t,threadId:n,messageId:r,activeToolCallIds:/* @__PURE__ */ new Set}),this._emit(e,{type:`RUN_STARTED`,threadId:n,runId:t,timestamp:Date.now()}),this._emit(e,{type:`TEXT_MESSAGE_START`,messageId:r,role:`assistant`,timestamp:Date.now()})};_onToolActivity=({groupId:e,tool:t,status:n})=>{let r=this._runs.get(e);if(r){if(n===`running`){let n=Hf();r.activeToolCallIds.add(n),this._emit(e,{type:`TOOL_CALL_START`,toolCallId:n,toolCallName:t,timestamp:Date.now()}),r._lastToolCallId=n}else if(n===`done`||n===`error`){let t=r._lastToolCallId;t&&(r.activeToolCallIds.delete(t),this._emit(e,{type:`TOOL_CALL_END`,toolCallId:t,timestamp:Date.now()}))}}}}})),_7e,v7e,AO,y7e=R((()=>{O8e(),_7e=5,v7e=class{#e=new fO.State(0);#t=/* @__PURE__ */ new Map;#n=new fO.State([]);clear(){this.#t.forEach((e,t)=>this.clearTimer(t)),this.#t.clear(),this.#n.set([])}clearTimer(e){let t=this.#t.get(e);t?.timeoutId&&clearTimeout(t.timeoutId),this.#t.delete(e)}dismiss(e){this.clearTimer(e),this.#n.set(this.#n.get().filter(t=>t.id!==e))}pause(e){let t=this.#t.get(e);t&&t.timeoutId&&(clearTimeout(t.timeoutId),t.timeoutId=void 0,t.remaining=Math.max(0,t.remaining-(Date.now()-t.startedAt)),this.#t.set(e,t))}resolveAction(e){if(e&&typeof e.label==`string`&&typeof e.onClick==`function`)return e}resolveDuration(e){return typeof e!=`number`||Number.isNaN(e)||e<0?4e3:e}resolveType(e){return e&&[`success`,`warning`,`error`,`info`].includes(e)?e:`info`}resume(e){let t=this.#t.get(e);!t||t.timeoutId||t.remaining<=0||this.scheduleDismiss(e,t.remaining)}scheduleDismiss(e,t){this.clearTimer(e);let n=globalThis.setTimeout(()=>{this.dismiss(e)},t);this.#t.set(e,{timeoutId:n,remaining:t,startedAt:Date.now()})}show(e,t={}){let n=this.#e.get()+1;this.#e.set(n);let r={id:n,message:e,type:this.resolveType(t.type),duration:this.resolveDuration(t.duration),action:this.resolveAction(t.action),createdAt:Date.now()},i=[...this.#n.get(),r];if(i.length>_7e){let e=i[0];this.clearTimer(e.id),this.#n.set(i.slice(1))}else this.#n.set(i);return r.duration>0&&this.scheduleDismiss(r.id,r.duration),r.id}get toasts(){return this.#n.get()}async runAction(e){let t=this.#n.get().find(t=>t.id===e);t?.action&&await t.action.onClick()}},AO=new v7e}));function jO(e,t={}){return AO.show(e,t)}function b7e(e,t=4e3){return AO.show(e,{type:`success`,duration:t})}function MO(e,t=5e3){return AO.show(e,{type:`error`,duration:t})}var x7e=R((()=>{y7e()}));function S7e(e,t){if(!e||typeof e!=`object`)return e;let n=JSON.parse(JSON.stringify(e));for(let e of t)C7e(n,e);return n}function C7e(e,t){let{op:n,path:r,value:i}=t;if(!r||!r.startsWith(`/`))return;let a=r.split(`/`).slice(1).map(e=>e.replace(/~1/g,`/`).replace(/~0/g,`~`)),o=a.pop();if(o===void 0)return;let s=e;for(let e of a){if(typeof s!=`object`||!s)return;s=s[e]}typeof s==`object`&&s&&(Array.isArray(s)?w7e(s,o,n,i):T7e(s,o,n,i))}function w7e(e,t,n,r){if(n===`add`){if(t===`-`)e.push(r);else{let n=parseInt(t,10);!isNaN(n)&&n>=0&&n<=e.length&&e.splice(n,0,r)}}else if(n===`replace`){let n=parseInt(t,10);!isNaN(n)&&n>=0&&n<e.length&&(e[n]=r)}else if(n===`remove`){let n=parseInt(t,10);!isNaN(n)&&n>=0&&n<e.length&&e.splice(n,1)}}function T7e(e,t,n,r){n===`add`||n===`replace`?e[t]=r:n===`remove`&&delete e[t]}var E7e=R((()=>{}));function D7e(e){if(e==null)return null;let t=String(e).trim().toLowerCase();return[`1`,`true`,`yes`,`on`].includes(t)?!0:![`0`,`false`,`no`,`off`].includes(t)&&null}function O7e(e,t=!1){if(e==null)return t;if(typeof e==`boolean`)return e;if(typeof e==`number`)return e===1;if(typeof e==`string`){let t=e.trim().toLowerCase();return t===`true`||t===`1`}return!1}var k7e=R((()=>{}));function A7e(e){if(!e)return[];try{let t=JSON.parse(e);if(Array.isArray(t))return TO(t.map(e=>String(e)))}catch{}return TO(e.split(`,`))}var j7e=R((()=>{EO()}));function M7e(e){if(typeof document>`u`)return null;let t=`shadow-claw-site-config`;if(e){let n=e.getAttribute(`config`)?.trim();n&&(t=n.replace(/^#/,``))}let n=document.getElementById(t);if(!n?.textContent)return NO.delete(t),null;let r=NO.get(t);if(r&&r.rawText===n.textContent)return r.config;try{let e=JSON.parse(n.textContent);if(!e||typeof e!=`object`)return NO.delete(t),null;let r={...e};return NO.set(t,{rawText:n.textContent,config:r}),r}catch(e){return console.warn(`[ShadowClaw] Failed to parse site configuration from #${t}:`,e),null}}var NO,N7e=R((()=>{NO=/* @__PURE__ */ new Map})),P7e,F7e=R((()=>{P7e={name:`bash`,description:`Execute a shell command. When WebVM is available, runs in a full Alpine Linux VM (x86) with all standard Linux commands. When WebVM is disabled or unavailable, falls back to a lightweight JavaScript shell emulator with 83 commands: alias, awk, base64, basename, bash, cat, cd, chmod, clear, column, comm, command, cp, curl, cut, date, diff, dirname, du, echo, egrep, env, expand, export, expr, false, fgrep, file, find, fold, grep, gunzip, gzip, head, help, html-to-markdown, join, jq, ln, ls, md5sum, mkdir, mv, nl, od, paste, printenv, printf, pwd, readlink, realpath, rev, rg, rm, rmdir, sed, seq, sh, sha1sum, sha256sum, sha384sum, sha512sum, sleep, sort, split, stat, strings, tac, tail, tar, tee, test, timeout, touch, tr, tree, true, unalias, uniq, wc, which, xargs, yes, zcat. Commands NOT available in fallback mode: node, npm, npx, git, apk, python, wget.Supports pipes (|), redirects (> >>), operators (&& || ;), newlines, and # comments. Prefer read_file/write_file for file inspection and edits — they are faster and more reliable than shell commands for that purpose.`,input_schema:{type:`object`,properties:{command:{type:`string`,description:`The bash command to execute`},stdin:{type:`string`,description:`Optional standard input (stdin) to pass to the command`},timeout:{type:`number`,description:`Timeout in seconds (default from Settings, initially 120; max: 1800)`}},required:[`command`]}}})),I7e,L7e,R7e=R((()=>{I7e={name:`clear_chat`,description:`Clear the current chat history and start a new session. Useful for scheduled tasks to prevent context from growing indefinitely.`,input_schema:{type:`object`,properties:{}}},L7e={name:`ask_user`,description:`Pause execution to ask the user a question or request confirmation. This halts the agent's work until the user provides an answer. Use this for human-in-the-loop checkpoints before taking destructive actions or when you need clarification to proceed.`,input_schema:{type:`object`,properties:{question:{type:`string`,description:`The question or confirmation message to present to the user.`},options:{type:`array`,items:{type:`string`},description:`Optional list of predefined choices for the user to select from.`}},required:[`question`]}}})),z7e,B7e,V7e,H7e=R((()=>{z7e={name:`manage_email`,description:`Manage email connection settings for IMAP/SMTP workflows. Supports status, connect/configure, enable/disable, delete, read_messages, send_message, mark_as_read, mark_as_unread, delete_messages, download_attachments, list available connection types, and lightweight test actions.`,input_schema:{type:`object`,properties:{action:{type:`string`,enum:[`status`,`list_plugins`,`list_connections`,`connect`,`configure`,`enable`,`disable`,`delete`,`test`,`read_messages`,`send_message`,`mark_as_read`,`mark_as_unread`,`delete_messages`,`download_attachments`],description:`Email management action to perform.`},plugin_id:{type:`string`,description:`Optional connection type ID for connect operations (default: imap).`},connection_id:{type:`string`,description:`Connection ID or label for configure, enable, disable, delete, and test actions. For read_messages/send_message, it may be omitted when there is exactly one enabled IMAP connection.`},label:{type:`string`,description:`Human-readable connection label for new connections.`},enabled:{type:`boolean`,description:`Optional enabled flag used during connect/configure actions.`},config:{type:`object`,properties:{},description:`Email config object (host, port, secure, mailboxPath, smtpHost, smtpPort, smtpSecure, etc.).`},mailbox_path:{type:`string`,description:`Optional mailbox path override for read_messages (default: INBOX).`},limit:{type:`number`,description:`Optional max messages to fetch for read_messages (default 10, range 1-50).`},unread_only:{type:`boolean`,description:`If true, read_messages returns only unread messages.`},message_uids:{type:`array`,items:{type:`number`},description:`Message UIDs for mark_as_read, mark_as_unread, and delete_messages actions.`},message_uid:{type:`number`,description:`Single message UID used by download_attachments action.`},attachment_parts:{type:`array`,items:{type:`string`},description:`Optional IMAP MIME part IDs to download (for example: 2, 3.1). If omitted, all attachments in the message are downloaded.`},save_directory:{type:`string`,description:`Optional workspace directory for downloaded attachments (default: downloads/email).`},attachments:{type:`array`,items:{anyOf:[{type:`string`},{type:`object`,properties:{path:{type:`string`},filename:{type:`string`},content_type:{type:`string`}},required:[`path`]}]},description:`Optional workspace file attachments for send_message. Provide paths or objects with path/filename/content_type.`},to:{type:`array`,items:{type:`string`},description:`Recipient email addresses for send_message.`},cc:{type:`array`,items:{type:`string`},description:`Optional CC recipient addresses for send_message.`},bcc:{type:`array`,items:{type:`string`},description:`Optional BCC recipient addresses for send_message.`},subject:{type:`string`,description:`Message subject for send_message.`},body:{type:`string`,description:`Plaintext message body for send_message.`},html:{type:`string`,description:`Optional HTML body for send_message.`},from:{type:`string`,description:`Optional from address override for send_message.`},reply_to:{type:`string`,description:`Optional reply-to address for send_message.`},username:{type:`string`,description:`Optional username override for connect/configure/read_messages/send_message.`},password:{type:`string`,description:`Optional password override for connect/configure/read_messages/send_message.`}},required:[`action`]}},B7e={name:`email_read_messages`,description:`Read recent messages from a configured email connection (IMAP). Use this to check inbox mail from an agent workflow. Results include attachment metadata when available.`,input_schema:{type:`object`,properties:{connection_id:{type:`string`,description:`Email connection ID or label.`},mailbox_path:{type:`string`,description:`Optional mailbox path override (default: INBOX).`},limit:{type:`number`,description:`Optional max messages to fetch (default 10, range 1-50).`},unread_only:{type:`boolean`,description:`If true, only unread messages are returned.`}},required:[`connection_id`]}},V7e={name:`email_send_message`,description:`Send an email message through a configured email connection (SMTP).`,input_schema:{type:`object`,properties:{connection_id:{type:`string`,description:`Email connection ID or label.`},to:{type:`array`,items:{type:`string`},description:`Recipient email addresses.`},cc:{type:`array`,items:{type:`string`},description:`Optional CC recipient addresses.`},bcc:{type:`array`,items:{type:`string`},description:`Optional BCC recipient addresses.`},subject:{type:`string`,description:`Message subject.`},body:{type:`string`,description:`Plaintext message body.`},html:{type:`string`,description:`Optional HTML message body.`},from:{type:`string`,description:`Optional from address override.`},reply_to:{type:`string`,description:`Optional reply-to address.`}},required:[`connection_id`,`to`,`subject`]}}})),U7e,W7e,G7e,K7e=R((()=>{U7e={name:`fetch_url`,description:`Fetch a URL via HTTP and return the response body. Subject to browser CORS restrictions — works with most public APIs. Response is truncated to 100KB. Set use_git_auth to true to automatically inject the saved Git PAT as an Authorization header (supports GitHub, Azure DevOps, GitLab, and other providers — auth format is auto-detected from the URL's host). If include_headers is true, the response will include both request and response headers.`,input_schema:{type:`object`,properties:{url:{type:`string`,description:`The URL to fetch`},method:{type:`string`,description:`HTTP method (default: GET)`},headers:{type:`object`,properties:{},description:`Request headers as key-value pairs`},body:{type:`string`,description:`Request body (for POST/PUT/PATCH)`},use_git_auth:{type:`boolean`,description:`If true, inject the saved Git credentials as an Authorization header. Auth format is auto-detected from the URL host: GitHub (token), Azure DevOps (Basic), GitLab (Bearer), or generic Bearer.`},git_account_id:{type:`string`,description:`Optional explicit Git account ID to use when use_git_auth is true. If omitted, account resolution uses hostPattern/default matching.`},use_account_auth:{type:`boolean`,description:`If true, inject a saved service account PAT as a Bearer Authorization header. The account is matched by hostPattern against the URL (longest match wins), then falls back to the default service account. Use this for non-Git services like Figma, Notion, or any other service whose PAT is stored under Settings → Accounts.`},account_id:{type:`string`,description:`Optional explicit service account ID to use when use_account_auth is true. If omitted, account resolution uses hostPattern/default matching.`},auth_mode:{type:`string`,enum:[`pat`,`oauth`],description:`Optional preferred credential mode when multiple accounts match. Valid values: pat or oauth.`},include_headers:{type:`boolean`,description:`If true, include request and response headers in the output.`}},required:[`url`]}},W7e={name:`fetch_file`,description:`Fetch a URL and save the response body directly to the workspace in one step. Equivalent to fetch_url + write_file but atomic. Text responses are saved as UTF-8; binary responses (images, PDFs, audio, video, zip, application/octet-stream) are saved as raw bytes. The destination path within the workspace is required. Supports the same authentication options as fetch_url (use_git_auth, use_account_auth, etc.). Returns the workspace path the file was saved to and the number of bytes written.`,input_schema:{type:`object`,properties:{url:{type:`string`,description:`The URL to fetch`},path:{type:`string`,description:`Destination path within the workspace (e.g. 'data/response.json'). Parent directories are created automatically. Must not contain '..' segments.`},method:{type:`string`,description:`HTTP method (default: GET)`},headers:{type:`object`,properties:{},description:`Request headers as key-value pairs`},body:{type:`string`,description:`Request body (for POST/PUT/PATCH)`},use_git_auth:{type:`boolean`,description:`If true, inject the saved Git credentials as an Authorization header. Auth format is auto-detected from the URL host: GitHub (token), Azure DevOps (Basic), GitLab (Bearer), or generic Bearer.`},git_account_id:{type:`string`,description:`Optional explicit Git account ID to use when use_git_auth is true. If omitted, account resolution uses hostPattern/default matching.`},use_account_auth:{type:`boolean`,description:`If true, inject a saved service account PAT as a Bearer Authorization header. The account is matched by hostPattern against the URL (longest match wins), then falls back to the default service account.`},account_id:{type:`string`,description:`Optional explicit service account ID to use when use_account_auth is true. If omitted, account resolution uses hostPattern/default matching.`},auth_mode:{type:`string`,enum:[`pat`,`oauth`],description:`Optional preferred credential mode when multiple accounts match. Valid values: pat or oauth.`}},required:[`url`,`path`]}},G7e={name:`web_search`,description:`Perform a web search using a search engine to discover information. Returns a plain-text summary of the top search results including titles, URLs, and snippets. Use this when you need to find information but don't know the exact URL to fetch.`,input_schema:{type:`object`,properties:{query:{type:`string`,description:`The search query to look up.`}},required:[`query`]}}})),q7e,J7e=R((()=>{q7e={name:`javascript`,description:`Execute JavaScript code in a sandboxed Worker and return the result. Lighter than bash — no VM boot required. Use for calculations, data transformations, JSON processing, string analysis, etc. Runs in strict mode. No access to DOM, eval(), Function(), self, postMessage, importScripts, navigator, or indexedDB — these are all undefined. fetch availability is controlled by Tool Configuration -> Internet Access (shared with bash). setTimeout is available but setInterval is blocked. IMPORTANT: You CANNOT call other agent tools (like read_file, write_file, or bash) from inside this sandbox. If you need to process file contents or tool outputs, you must fetch them in a previous turn and pass the data into this tool via the $PIPE_DATA variable. Write plain JavaScript expressions and statements — the return value of the last expression is captured as the result.`,input_schema:{type:`object`,properties:{code:{type:`string`,description:`JavaScript code to execute. The return value of the last expression is captured.`},data:{type:`string`,description:"Optional input data string. Accessible inside the code sandbox via the global constant `$PIPE_DATA`."}},required:[`code`]}}})),Y7e,X7e,Z7e=R((()=>{Y7e={name:`remote_mcp_list_tools`,description:`List available tools from a configured Remote MCP connection by connection ID or label.`,input_schema:{type:`object`,properties:{connection_id:{type:`string`,description:`Remote MCP connection ID or label`}},required:[`connection_id`]}},X7e={name:`remote_mcp_call_tool`,description:`Call a tool exposed by a configured Remote MCP connection.`,input_schema:{type:`object`,properties:{connection_id:{type:`string`,description:`Remote MCP connection ID or label`},tool_name:{type:`string`,description:`Remote MCP tool name`},arguments:{type:`object`,properties:{},description:`Arguments object passed to the remote MCP tool`}},required:[`connection_id`,`tool_name`]}}})),Q7e,$7e,e9e=R((()=>{Q7e={name:`manage_tools`,description:`Enable or disable specific tools, or activate a predefined tool profile. Use list_tool_profiles to see available profiles before activating one. This helps optimize the context window and focus capabilities. Changes take effect on the NEXT turn, not immediately within the current tool-use loop.`,input_schema:{type:`object`,properties:{action:{type:`string`,enum:[`enable`,`disable`,`activate_profile`],description:`The management action to perform.`},tool_names:{type:`array`,items:{type:`string`},description:`List of tool names to enable or disable. Required for 'enable' and 'disable' actions.`},profile_id:{type:`string`,description:`The unique ID of the tool profile to activate. Required for 'activate_profile' action.`}},required:[`action`]}},$7e={name:`list_tool_profiles`,description:`List all available tool profiles that can be activated using manage_tools. Returns a list of profiles with their IDs, names, and the tools they contain.`,input_schema:{type:`object`,properties:{}}}})),t9e,n9e=R((()=>{t9e={name:`update_memory`,description:`Update the MEMORY.md memory file for this group. Use this to persist important context, user preferences, project state, and anything the agent should remember across conversations. This file is loaded as system context on every invocation.`,input_schema:{type:`object`,properties:{content:{type:`string`,description:`New content for the MEMORY.md memory file`}},required:[`content`]}}})),r9e,i9e,a9e=R((()=>{r9e={name:`show_toast`,description:`Show a toast notification to the user. Toasts are non-blocking, auto-dismissing notifications that appear in the bottom-right corner. Use for: operation status (success/failure), warnings, informational messages, progress updates. Avoid for: critical errors requiring acknowledgment (use clear error messages instead), lengthy content (keep messages concise).`,input_schema:{type:`object`,properties:{message:{type:`string`,description:`The message to display in the toast (keep concise)`},type:{type:`string`,description:`Type of toast: 'success', 'error', 'warning', or 'info' (default: 'info')`,enum:[`success`,`error`,`warning`,`info`]},duration:{type:`number`,description:`Auto-dismiss duration in milliseconds (default: 5000 for info/success, 8000 for warning/error). Set to 0 to disable auto-dismiss.`}},required:[`message`]}},i9e={name:`send_notification`,description:`Send an OS-level push notification to the user via Web Push. Unlike toasts (in-app only), push notifications appear even when the app is not focused or the tab is in the background. Use for: important alerts, long-running task completion, time-sensitive information. Requires the user to have enabled push notifications in Settings.`,input_schema:{type:`object`,properties:{title:{type:`string`,description:`Notification title (default: 'ShadowClaw')`},body:{type:`string`,description:`The notification body text`}},required:[`body`]}}})),o9e,s9e,c9e=R((()=>{o9e=`https://a2ui.org/specification/v1_0/catalogs/basic/catalog.json`,s9e=`A2UI Basic Catalog — Component & Function Reference
|
|
3693
|
+
`)}\n${s}`}return s}async function t7e(e={}){let t=()=>{let e=null;if(typeof document<`u`){let t=document.getElementById(`shadow-claw-static-manifest`);if(t&&t.textContent)try{let n=JSON.parse(t.textContent);n&&Array.isArray(n.pages)&&(e={...n,pages:[...n.pages]})}catch(e){console.warn(`Failed to parse embedded static main manifest:`,e)}let n=document.querySelectorAll(`script[type="text/markdown"][data-shadow-claw-page]`);if(n.length>0){e||={pages:[]};for(let t of Array.from(n)){let n=t.getAttribute(`data-shadow-claw-page`)?.trim();if(n){let r=t.textContent||``;r=G5e(r),!r.trim()&&/^memory\.(md|markdown)$/iu.test(n)&&(r=HD),!r.trim()&&(n===`index.html`||/^index\.(html?|xhtml)$/iu.test(n))&&(r=kO(n)??YD);let i=e.pages.findIndex(e=>e.displayPath===n);i>=0?e.pages[i].content=r:e.pages.push({displayPath:n,content:r})}}}let r=document.getElementById(`shadow-claw-site-config`);if(r?.textContent)try{let t=JSON.parse(r.textContent);if(Array.isArray(t?.pages?.files)){e||={pages:[]};for(let n of t.pages.files)if(typeof n==`string`&&n.trim()){let t=n.trim(),r=``;/^memory\.(md|markdown)$/iu.test(t)?r=HD:(t===`index.html`||/^index\.(html?|xhtml)$/iu.test(t))&&(r=kO(t)??YD),e.pages.some(e=>e.displayPath===t)||e.pages.push({displayPath:t,content:r})}}}catch{}let i=e7e();if(i){e||={pages:[]};let t=i.getAttribute(`data-initial-path`)?.trim()||`index.html`;if(!e.pages.some(e=>e.displayPath===t)){let n=kO(t)??YD;e.pages.push({displayPath:t,content:n})}e.pages.some(e=>/^memory\.(md|markdown)$/iu.test(e.displayPath))||e.pages.push({displayPath:`MEMORY.md`,content:HD})}}return e};if(e.preferEmbedded!==!1){let e=t();if(e&&e.pages.length>0)return e}if(e.fetchFallback!==!1){let e=await Q5e();if(e&&e.pages.length>0)return e}if(e.preferEmbedded===!1){let e=t();if(e&&e.pages.length>0)return e}return{pages:[{displayPath:`index.html`,content:YD},{displayPath:`MEMORY.md`,content:HD}]}}async function n7e(e,t,n=[]){for(let[r,i]of Object.entries(t))if(r===`purgePreRenderedStaticPages`&&i===!0){if(n.length>0){let t=n[0],r=n.slice(1).join(`/`);try{r?await CO(e,t,r):await O5e(e,t)}catch(e){console.warn(`Failed to purge pre-rendered static pages for ${t}/${r}:`,e)}}}else typeof i==`object`&&i&&await n7e(e,i,[...n,r])}function r7e(){if(typeof document<`u`)try{let e=document.getElementById(`shadow-claw-site-config`);if(e?.textContent){let t=JSON.parse(e.textContent);if(t?.pages?.sortOrder===`desc`)return`desc`;if(t?.pages?.sortOrder===`asc`)return`asc`}}catch{}return`desc`}function i7e(){if(typeof document<`u`)try{let e=document.getElementById(`shadow-claw-site-config`);if(e?.textContent){let t=JSON.parse(e.textContent)?.pages?.defaultPinnedPage;if(typeof t==`string`&&t.trim().length>0)return t.trim()}}catch{}return null}function a7e(){if(typeof document<`u`)try{let e=document.getElementById(`shadow-claw-site-config`);if(e?.textContent){let t=JSON.parse(e.textContent);return{allowList:TO(t?.pages?.allowList??t?.pages?.allowlist??t?.allowList??t?.allowlist??[]),denyList:TO(t?.pages?.denyList??t?.pages?.denylist??t?.denyList??t?.denylist??[])}}}catch{}return{allowList:[],denyList:[]}}function o7e(e,t){let n=t??r7e();return[...e].sort((e,t)=>{let r=e.path,i=t.path,a=r.split(`/`).pop()||``,o=i.split(`/`).pop()||``,s=/^index\.(html?|xhtml)$/iu.test(a),c=/^index\.(html?|xhtml)$/iu.test(o);if(s&&!c)return-1;if(!s&&c)return 1;let l=/^memory\.(md|markdown)$/iu.test(a),u=/^memory\.(md|markdown)$/iu.test(o);return l&&!u?1:!l&&u?-1:n===`asc`?r.localeCompare(i,void 0,{numeric:!0,sensitivity:`base`}):i.localeCompare(r,void 0,{numeric:!0,sensitivity:`base`})})}async function s7e(e,t,n=l7e,r=u7e){let i=t??d7e;try{if(T5e(n)===i)return!0}catch{}try{if(await ba(e,r)===i){try{E5e(n,i)}catch{}return!0}await BD(e,r,i);try{E5e(n,i)}catch{}}catch{try{E5e(n,i)}catch{}}return!1}async function c7e(e,t=fn,n=[],r={}){await X6e(e,t);let i=await t7e(r),a=!1;i.preRenderedStaticPages&&(await s7e(e,i.purgeId)||(a=!0,await n7e(e,i.preRenderedStaticPages)));let o=!1;if(t===`br:main`&&i.skillsPurgeId!==void 0&&!await s7e(e,i.skillsPurgeId,`sc:skills-purge-id`,`static_main_skills_purge_id`)){o=!0;try{await CO(e,t,`.agents/skills/main`)}catch(e){if(!(e&&typeof e==`object`&&`name`in e&&e.name===`NotFoundError`))throw e}try{await CO(e,t,`.agents/tools/main`)}catch(e){if(!(e&&typeof e==`object`&&`name`in e&&e.name===`NotFoundError`))throw e}}for(let n of i.pages)if(n.content?.includes(`slug: "shadow-claw--purge-pages"`)){!a&&!await s7e(e,i.purgeId)&&(a=!0,await O5e(e,t));break}let s=t===`br:main`&&await GD(e),c=new Set(i.pages.map(e=>wO(t,e.displayPath))),l=a?n.filter(e=>e.groupId!==t||c.has(wO(e.groupId,e.path))):[...n],{allowList:u,denyList:d}=a7e(),f=0;for(let n of i.pages)if(f++,f%5==0&&await new Promise(e=>setTimeout(e,0)),!n.content?.includes(`slug: "shadow-claw--purge-pages"`)&&H5e(n.displayPath,{allowList:u,denyList:d,groupId:t})){if(/^memory\.(md|markdown)$/iu.test(n.displayPath)){if(s)continue;let r=typeof n.content==`string`&&n.content.trim().length>0&&n.content!==HD?n.content:void 0;if(r===void 0?await qD(e,t):await qD(e,t,r)){let e=wO(t,n.displayPath);l.some(t=>wO(t.groupId,t.path)===e)||l.push({groupId:t,path:n.displayPath})}}else if(!await M5e(e,t,n.displayPath))try{if(!await UD(e,t,n.displayPath)){let r=n.content;(typeof r!=`string`||!r.trim())&&(r=n.displayPath===`index.html`?kO(`index.html`)??YD:await $5e(n.displayPath)??``),await RD(e,t,n.displayPath,r)}let r=wO(t,n.displayPath);l.some(e=>wO(e.groupId,e.path)===r)||l.push({groupId:t,path:n.displayPath})}catch(e){console.warn(`Failed to seed static page file ${n.displayPath}:`,e)}}if(t===`br:main`){for(let n of i.skills||[]){let r=`.agents/skills/main/${n.displayPath}`;try{await UD(e,t,r)||await RD(e,t,r,n.content)}catch(e){console.warn(`Failed to seed skill file ${r}:`,e)}}for(let n of i.tools||[]){let r=`.agents/tools/main/${n.displayPath}`;try{(o||!await UD(e,t,r))&&await RD(e,t,r,n.content)}catch(e){console.warn(`Failed to seed tool file ${r}:`,e)}}}let p=typeof document<`u`&&(document.getElementById(`shadow-claw-static-manifest`)!==null||document.querySelector(`script[type="text/markdown"][data-shadow-claw-page]`)!==null||e7e()!==null);r.preferEmbedded!==!1&&p||await Y5e(e,t,!0);let m=l.filter(e=>H5e(e.path,{allowList:u,denyList:d,groupId:e.groupId}));return Object.defineProperty(m,"didPurge",{value:a,enumerable:!1,writable:!0,configurable:!0}),Object.defineProperty(m,"didPurgeSkills",{value:o,enumerable:!1,writable:!0,configurable:!0}),o7e(m)}var l7e,u7e,d7e,f7e,p7e,m7e=R((()=>{Mn(),D5e(),K6e(),H6e(),Gt(),xa(),VD(),k5e(),A5e(),Q6e(),G6e(),WD(),F5e(),zD(),W5e(),EO(),K5e(),l7e=`sc:purge-id`,u7e=`static_main_site_purge_id`,d7e=`__legacy_purge_pages__`,f7e=`static-main-manifest.json`,p7e=`static-main`})),h7e,g7e=R((()=>{qf(),h7e=class{_events;_handlers=[];_runs=/* @__PURE__ */ new Map;constructor(e){this._events=e}start(){this._listen(`streaming-start`,this._onStreamingStart),this._listen(`streaming-chunk`,this._onStreamingChunk),this._listen(`streaming-end`,this._onStreamingEnd),this._listen(`streaming-done`,this._onStreamingDone),this._listen(`streaming-error`,this._onStreamingError),this._listen(`tool-activity`,this._onToolActivity)}stop(){for(let{event:e,handler:t}of this._handlers)this._events.off(e,t);this._handlers=[],this._runs.clear()}_emit(e,t){window.dispatchEvent(new CustomEvent(`shadow-claw-agui-event`,{detail:{groupId:e,event:t}}))}_listen(e,t){this._events.on(e,t),this._handlers.push({event:e,handler:t})}_onStreamingChunk=({groupId:e,text:t})=>{let n=this._runs.get(e);n&&n.messageId&&this._emit(e,{type:`TEXT_MESSAGE_CONTENT`,messageId:n.messageId,delta:t,timestamp:Date.now()})};_onStreamingDone=({groupId:e})=>{let t=this._runs.get(e);t&&(t.messageId&&this._emit(e,{type:`TEXT_MESSAGE_END`,messageId:t.messageId,timestamp:Date.now()}),this._emit(e,{type:`RUN_FINISHED`,threadId:t.threadId,runId:t.runId,timestamp:Date.now()}),this._runs.delete(e))};_onStreamingEnd=({groupId:e})=>{let t=this._runs.get(e);t&&t.messageId&&(this._emit(e,{type:`TEXT_MESSAGE_END`,messageId:t.messageId,timestamp:Date.now()}),t.messageId=null)};_onStreamingError=({groupId:e,error:t})=>{let n=this._runs.get(e);n&&(n.messageId&&this._emit(e,{type:`TEXT_MESSAGE_END`,messageId:n.messageId,timestamp:Date.now()}),this._emit(e,{type:`RUN_ERROR`,message:t||`Unknown streaming error`,timestamp:Date.now()}),this._runs.delete(e))};_onStreamingStart=({groupId:e})=>{let t=Hf(),n=e,r=Hf();this._runs.set(e,{runId:t,threadId:n,messageId:r,activeToolCallIds:/* @__PURE__ */ new Set}),this._emit(e,{type:`RUN_STARTED`,threadId:n,runId:t,timestamp:Date.now()}),this._emit(e,{type:`TEXT_MESSAGE_START`,messageId:r,role:`assistant`,timestamp:Date.now()})};_onToolActivity=({groupId:e,tool:t,status:n})=>{let r=this._runs.get(e);if(r){if(n===`running`){let n=Hf();r.activeToolCallIds.add(n),this._emit(e,{type:`TOOL_CALL_START`,toolCallId:n,toolCallName:t,timestamp:Date.now()}),r._lastToolCallId=n}else if(n===`done`||n===`error`){let t=r._lastToolCallId;t&&(r.activeToolCallIds.delete(t),this._emit(e,{type:`TOOL_CALL_END`,toolCallId:t,timestamp:Date.now()}))}}}}})),_7e,v7e,AO,y7e=R((()=>{O8e(),_7e=5,v7e=class{#e=new fO.State(0);#t=/* @__PURE__ */ new Map;#n=new fO.State([]);clear(){this.#t.forEach((e,t)=>this.clearTimer(t)),this.#t.clear(),this.#n.set([])}clearTimer(e){let t=this.#t.get(e);t?.timeoutId&&clearTimeout(t.timeoutId),this.#t.delete(e)}dismiss(e){this.clearTimer(e),this.#n.set(this.#n.get().filter(t=>t.id!==e))}pause(e){let t=this.#t.get(e);t&&t.timeoutId&&(clearTimeout(t.timeoutId),t.timeoutId=void 0,t.remaining=Math.max(0,t.remaining-(Date.now()-t.startedAt)),this.#t.set(e,t))}resolveAction(e){if(e&&typeof e.label==`string`&&typeof e.onClick==`function`)return e}resolveDuration(e){return typeof e!=`number`||Number.isNaN(e)||e<0?4e3:e}resolveType(e){return e&&[`success`,`warning`,`error`,`info`].includes(e)?e:`info`}resume(e){let t=this.#t.get(e);!t||t.timeoutId||t.remaining<=0||this.scheduleDismiss(e,t.remaining)}scheduleDismiss(e,t){this.clearTimer(e);let n=globalThis.setTimeout(()=>{this.dismiss(e)},t);this.#t.set(e,{timeoutId:n,remaining:t,startedAt:Date.now()})}show(e,t={}){let n=this.#e.get()+1;this.#e.set(n);let r={id:n,message:e,type:this.resolveType(t.type),duration:this.resolveDuration(t.duration),action:this.resolveAction(t.action),createdAt:Date.now()},i=[...this.#n.get(),r];if(i.length>_7e){let e=i[0];this.clearTimer(e.id),this.#n.set(i.slice(1))}else this.#n.set(i);return r.duration>0&&this.scheduleDismiss(r.id,r.duration),r.id}get toasts(){return this.#n.get()}async runAction(e){let t=this.#n.get().find(t=>t.id===e);t?.action&&await t.action.onClick()}},AO=new v7e}));function jO(e,t={}){return AO.show(e,t)}function b7e(e,t=4e3){return AO.show(e,{type:`success`,duration:t})}function MO(e,t=5e3){return AO.show(e,{type:`error`,duration:t})}var x7e=R((()=>{y7e()}));function S7e(e,t){if(!e||typeof e!=`object`)return e;let n=JSON.parse(JSON.stringify(e));for(let e of t)C7e(n,e);return n}function C7e(e,t){let{op:n,path:r,value:i}=t;if(!r||!r.startsWith(`/`))return;let a=r.split(`/`).slice(1).map(e=>e.replace(/~1/g,`/`).replace(/~0/g,`~`)),o=a.pop();if(o===void 0)return;let s=e;for(let e of a){if(typeof s!=`object`||!s)return;s=s[e]}typeof s==`object`&&s&&(Array.isArray(s)?w7e(s,o,n,i):T7e(s,o,n,i))}function w7e(e,t,n,r){if(n===`add`){if(t===`-`)e.push(r);else{let n=parseInt(t,10);!isNaN(n)&&n>=0&&n<=e.length&&e.splice(n,0,r)}}else if(n===`replace`){let n=parseInt(t,10);!isNaN(n)&&n>=0&&n<e.length&&(e[n]=r)}else if(n===`remove`){let n=parseInt(t,10);!isNaN(n)&&n>=0&&n<e.length&&e.splice(n,1)}}function T7e(e,t,n,r){n===`add`||n===`replace`?e[t]=r:n===`remove`&&delete e[t]}var E7e=R((()=>{}));function D7e(e){if(e==null)return null;let t=String(e).trim().toLowerCase();return[`1`,`true`,`yes`,`on`].includes(t)?!0:![`0`,`false`,`no`,`off`].includes(t)&&null}function O7e(e,t=!1){if(e==null)return t;if(typeof e==`boolean`)return e;if(typeof e==`number`)return e===1;if(typeof e==`string`){let t=e.trim().toLowerCase();return t===`true`||t===`1`}return!1}var k7e=R((()=>{}));function A7e(e){if(!e)return[];try{let t=JSON.parse(e);if(Array.isArray(t))return TO(t.map(e=>String(e)))}catch{}return TO(e.split(`,`))}var j7e=R((()=>{EO()}));function M7e(e){if(typeof document>`u`)return null;let t=`shadow-claw-site-config`;if(e){let n=e.getAttribute(`config`)?.trim();n&&(t=n.replace(/^#/,``))}let n=document.getElementById(t);if(!n?.textContent)return NO.delete(t),null;let r=NO.get(t);if(r&&r.rawText===n.textContent)return r.config;try{let e=JSON.parse(n.textContent);if(!e||typeof e!=`object`)return NO.delete(t),null;let r={...e};return NO.set(t,{rawText:n.textContent,config:r}),r}catch(e){return console.warn(`[ShadowClaw] Failed to parse site configuration from #${t}:`,e),null}}var NO,N7e=R((()=>{NO=/* @__PURE__ */ new Map})),P7e,F7e=R((()=>{P7e={name:`bash`,description:`Execute a shell command. When WebVM is available, runs in a full Alpine Linux VM (x86) with all standard Linux commands. When WebVM is disabled or unavailable, falls back to a lightweight JavaScript shell emulator with 83 commands: alias, awk, base64, basename, bash, cat, cd, chmod, clear, column, comm, command, cp, curl, cut, date, diff, dirname, du, echo, egrep, env, expand, export, expr, false, fgrep, file, find, fold, grep, gunzip, gzip, head, help, html-to-markdown, join, jq, ln, ls, md5sum, mkdir, mv, nl, od, paste, printenv, printf, pwd, readlink, realpath, rev, rg, rm, rmdir, sed, seq, sh, sha1sum, sha256sum, sha384sum, sha512sum, sleep, sort, split, stat, strings, tac, tail, tar, tee, test, timeout, touch, tr, tree, true, unalias, uniq, wc, which, xargs, yes, zcat. Commands NOT available in fallback mode: node, npm, npx, git, apk, python, wget.Supports pipes (|), redirects (> >>), operators (&& || ;), newlines, and # comments. Prefer read_file/write_file for file inspection and edits — they are faster and more reliable than shell commands for that purpose.`,input_schema:{type:`object`,properties:{command:{type:`string`,description:`The bash command to execute`},stdin:{type:`string`,description:`Optional standard input (stdin) to pass to the command`},timeout:{type:`number`,description:`Timeout in seconds (default from Settings, initially 120; max: 1800)`}},required:[`command`]}}})),I7e,L7e,R7e=R((()=>{I7e={name:`clear_chat`,description:`Clear the current chat history and start a new session. Useful for scheduled tasks to prevent context from growing indefinitely.`,input_schema:{type:`object`,properties:{}}},L7e={name:`ask_user`,description:`Pause execution to ask the user a question or request confirmation. This halts the agent's work until the user provides an answer. Use this for human-in-the-loop checkpoints before taking destructive actions or when you need clarification to proceed.`,input_schema:{type:`object`,properties:{question:{type:`string`,description:`The question or confirmation message to present to the user.`},options:{type:`array`,items:{type:`string`},description:`Optional list of predefined choices for the user to select from.`}},required:[`question`]}}})),z7e,B7e,V7e,H7e=R((()=>{z7e={name:`manage_email`,description:`Manage email connection settings for IMAP/SMTP workflows. Supports status, connect/configure, enable/disable, delete, read_messages, send_message, mark_as_read, mark_as_unread, delete_messages, download_attachments, list available connection types, and lightweight test actions.`,input_schema:{type:`object`,properties:{action:{type:`string`,enum:[`status`,`list_plugins`,`list_connections`,`connect`,`configure`,`enable`,`disable`,`delete`,`test`,`read_messages`,`send_message`,`mark_as_read`,`mark_as_unread`,`delete_messages`,`download_attachments`],description:`Email management action to perform.`},plugin_id:{type:`string`,description:`Optional connection type ID for connect operations (default: imap).`},connection_id:{type:`string`,description:`Connection ID or label for configure, enable, disable, delete, and test actions. For read_messages/send_message, it may be omitted when there is exactly one enabled IMAP connection.`},label:{type:`string`,description:`Human-readable connection label for new connections.`},enabled:{type:`boolean`,description:`Optional enabled flag used during connect/configure actions.`},config:{type:`object`,properties:{},description:`Email config object (host, port, secure, mailboxPath, smtpHost, smtpPort, smtpSecure, etc.).`},mailbox_path:{type:`string`,description:`Optional mailbox path override for read_messages (default: INBOX).`},limit:{type:`number`,description:`Optional max messages to fetch for read_messages (default 10, range 1-50).`},unread_only:{type:`boolean`,description:`If true, read_messages returns only unread messages.`},message_uids:{type:`array`,items:{type:`number`},description:`Message UIDs for mark_as_read, mark_as_unread, and delete_messages actions.`},message_uid:{type:`number`,description:`Single message UID used by download_attachments action.`},attachment_parts:{type:`array`,items:{type:`string`},description:`Optional IMAP MIME part IDs to download (for example: 2, 3.1). If omitted, all attachments in the message are downloaded.`},save_directory:{type:`string`,description:`Optional workspace directory for downloaded attachments (default: downloads/email).`},attachments:{type:`array`,items:{anyOf:[{type:`string`},{type:`object`,properties:{path:{type:`string`},filename:{type:`string`},content_type:{type:`string`}},required:[`path`]}]},description:`Optional workspace file attachments for send_message. Provide paths or objects with path/filename/content_type.`},to:{type:`array`,items:{type:`string`},description:`Recipient email addresses for send_message.`},cc:{type:`array`,items:{type:`string`},description:`Optional CC recipient addresses for send_message.`},bcc:{type:`array`,items:{type:`string`},description:`Optional BCC recipient addresses for send_message.`},subject:{type:`string`,description:`Message subject for send_message.`},body:{type:`string`,description:`Plaintext message body for send_message.`},html:{type:`string`,description:`Optional HTML body for send_message.`},from:{type:`string`,description:`Optional from address override for send_message.`},reply_to:{type:`string`,description:`Optional reply-to address for send_message.`},username:{type:`string`,description:`Optional username override for connect/configure/read_messages/send_message.`},password:{type:`string`,description:`Optional password override for connect/configure/read_messages/send_message.`}},required:[`action`]}},B7e={name:`email_read_messages`,description:`Read recent messages from a configured email connection (IMAP). Use this to check inbox mail from an agent workflow. Results include attachment metadata when available.`,input_schema:{type:`object`,properties:{connection_id:{type:`string`,description:`Email connection ID or label.`},mailbox_path:{type:`string`,description:`Optional mailbox path override (default: INBOX).`},limit:{type:`number`,description:`Optional max messages to fetch (default 10, range 1-50).`},unread_only:{type:`boolean`,description:`If true, only unread messages are returned.`}},required:[`connection_id`]}},V7e={name:`email_send_message`,description:`Send an email message through a configured email connection (SMTP).`,input_schema:{type:`object`,properties:{connection_id:{type:`string`,description:`Email connection ID or label.`},to:{type:`array`,items:{type:`string`},description:`Recipient email addresses.`},cc:{type:`array`,items:{type:`string`},description:`Optional CC recipient addresses.`},bcc:{type:`array`,items:{type:`string`},description:`Optional BCC recipient addresses.`},subject:{type:`string`,description:`Message subject.`},body:{type:`string`,description:`Plaintext message body.`},html:{type:`string`,description:`Optional HTML message body.`},from:{type:`string`,description:`Optional from address override.`},reply_to:{type:`string`,description:`Optional reply-to address.`}},required:[`connection_id`,`to`,`subject`]}}})),U7e,W7e,G7e,K7e=R((()=>{U7e={name:`fetch_url`,description:`Fetch a URL via HTTP and return the response body. Subject to browser CORS restrictions — works with most public APIs. Response is truncated to 100KB. Set use_git_auth to true to automatically inject the saved Git PAT as an Authorization header (supports GitHub, Azure DevOps, GitLab, and other providers — auth format is auto-detected from the URL's host). If include_headers is true, the response will include both request and response headers.`,input_schema:{type:`object`,properties:{url:{type:`string`,description:`The URL to fetch`},method:{type:`string`,description:`HTTP method (default: GET)`},headers:{type:`object`,properties:{},description:`Request headers as key-value pairs`},body:{type:`string`,description:`Request body (for POST/PUT/PATCH)`},use_git_auth:{type:`boolean`,description:`If true, inject the saved Git credentials as an Authorization header. Auth format is auto-detected from the URL host: GitHub (token), Azure DevOps (Basic), GitLab (Bearer), or generic Bearer.`},git_account_id:{type:`string`,description:`Optional explicit Git account ID to use when use_git_auth is true. If omitted, account resolution uses hostPattern/default matching.`},use_account_auth:{type:`boolean`,description:`If true, inject a saved service account PAT as a Bearer Authorization header. The account is matched by hostPattern against the URL (longest match wins), then falls back to the default service account. Use this for non-Git services like Figma, Notion, or any other service whose PAT is stored under Settings → Accounts.`},account_id:{type:`string`,description:`Optional explicit service account ID to use when use_account_auth is true. If omitted, account resolution uses hostPattern/default matching.`},auth_mode:{type:`string`,enum:[`pat`,`oauth`],description:`Optional preferred credential mode when multiple accounts match. Valid values: pat or oauth.`},include_headers:{type:`boolean`,description:`If true, include request and response headers in the output.`}},required:[`url`]}},W7e={name:`fetch_file`,description:`Fetch a URL and save the response body directly to the workspace in one step. Equivalent to fetch_url + write_file but atomic. Text responses are saved as UTF-8; binary responses (images, PDFs, audio, video, zip, application/octet-stream) are saved as raw bytes. The destination path within the workspace is required. Supports the same authentication options as fetch_url (use_git_auth, use_account_auth, etc.). Returns the workspace path the file was saved to and the number of bytes written.`,input_schema:{type:`object`,properties:{url:{type:`string`,description:`The URL to fetch`},path:{type:`string`,description:`Destination path within the workspace (e.g. 'data/response.json'). Parent directories are created automatically. Must not contain '..' segments.`},method:{type:`string`,description:`HTTP method (default: GET)`},headers:{type:`object`,properties:{},description:`Request headers as key-value pairs`},body:{type:`string`,description:`Request body (for POST/PUT/PATCH)`},use_git_auth:{type:`boolean`,description:`If true, inject the saved Git credentials as an Authorization header. Auth format is auto-detected from the URL host: GitHub (token), Azure DevOps (Basic), GitLab (Bearer), or generic Bearer.`},git_account_id:{type:`string`,description:`Optional explicit Git account ID to use when use_git_auth is true. If omitted, account resolution uses hostPattern/default matching.`},use_account_auth:{type:`boolean`,description:`If true, inject a saved service account PAT as a Bearer Authorization header. The account is matched by hostPattern against the URL (longest match wins), then falls back to the default service account.`},account_id:{type:`string`,description:`Optional explicit service account ID to use when use_account_auth is true. If omitted, account resolution uses hostPattern/default matching.`},auth_mode:{type:`string`,enum:[`pat`,`oauth`],description:`Optional preferred credential mode when multiple accounts match. Valid values: pat or oauth.`}},required:[`url`,`path`]}},G7e={name:`web_search`,description:`Perform a web search using a search engine to discover information. Returns a plain-text summary of the top search results including titles, URLs, and snippets. Use this when you need to find information but don't know the exact URL to fetch.`,input_schema:{type:`object`,properties:{query:{type:`string`,description:`The search query to look up.`}},required:[`query`]}}})),q7e,J7e=R((()=>{q7e={name:`javascript`,description:`Execute JavaScript code in a sandboxed Worker and return the result. Lighter than bash — no VM boot required. Use for calculations, data transformations, JSON processing, string analysis, etc. Runs in strict mode. No access to DOM, eval(), Function(), self, postMessage, importScripts, navigator, or indexedDB — these are all undefined. fetch availability is controlled by Tool Configuration -> Internet Access (shared with bash). setTimeout is available but setInterval is blocked. IMPORTANT: You CANNOT call other agent tools (like read_file, write_file, or bash) from inside this sandbox. If you need to process file contents or tool outputs, you must fetch them in a previous turn and pass the data into this tool via the $PIPE_DATA variable. Write plain JavaScript expressions and statements — the return value of the last expression is captured as the result.`,input_schema:{type:`object`,properties:{code:{type:`string`,description:`JavaScript code to execute. The return value of the last expression is captured.`},data:{type:`string`,description:"Optional input data string. Accessible inside the code sandbox via the global constant `$PIPE_DATA`."}},required:[`code`]}}})),Y7e,X7e,Z7e=R((()=>{Y7e={name:`remote_mcp_list_tools`,description:`List available tools from a configured Remote MCP connection by connection ID or label.`,input_schema:{type:`object`,properties:{connection_id:{type:`string`,description:`Remote MCP connection ID or label`}},required:[`connection_id`]}},X7e={name:`remote_mcp_call_tool`,description:`Call a tool exposed by a configured Remote MCP connection.`,input_schema:{type:`object`,properties:{connection_id:{type:`string`,description:`Remote MCP connection ID or label`},tool_name:{type:`string`,description:`Remote MCP tool name`},arguments:{type:`object`,properties:{},description:`Arguments object passed to the remote MCP tool`}},required:[`connection_id`,`tool_name`]}}})),Q7e,$7e,e9e=R((()=>{Q7e={name:`manage_tools`,description:`Enable or disable specific tools, or activate a predefined tool profile. Use list_tool_profiles to see available profiles before activating one. This helps optimize the context window and focus capabilities. Changes take effect on the NEXT turn, not immediately within the current tool-use loop.`,input_schema:{type:`object`,properties:{action:{type:`string`,enum:[`enable`,`disable`,`activate_profile`],description:`The management action to perform.`},tool_names:{type:`array`,items:{type:`string`},description:`List of tool names to enable or disable. Required for 'enable' and 'disable' actions.`},profile_id:{type:`string`,description:`The unique ID of the tool profile to activate. Required for 'activate_profile' action.`}},required:[`action`]}},$7e={name:`list_tool_profiles`,description:`List all available tool profiles that can be activated using manage_tools. Returns a list of profiles with their IDs, names, and the tools they contain.`,input_schema:{type:`object`,properties:{}}}})),t9e,n9e=R((()=>{t9e={name:`update_memory`,description:`Update the MEMORY.md memory file for this group. Use this to persist important context, user preferences, project state, and anything the agent should remember across conversations. This file is loaded as system context on every invocation.`,input_schema:{type:`object`,properties:{content:{type:`string`,description:`New content for the MEMORY.md memory file`}},required:[`content`]}}})),r9e,i9e,a9e=R((()=>{r9e={name:`show_toast`,description:`Show a toast notification to the user. Toasts are non-blocking, auto-dismissing notifications that appear in the bottom-right corner. Use for: operation status (success/failure), warnings, informational messages, progress updates. Avoid for: critical errors requiring acknowledgment (use clear error messages instead), lengthy content (keep messages concise).`,input_schema:{type:`object`,properties:{message:{type:`string`,description:`The message to display in the toast (keep concise)`},type:{type:`string`,description:`Type of toast: 'success', 'error', 'warning', or 'info' (default: 'info')`,enum:[`success`,`error`,`warning`,`info`]},duration:{type:`number`,description:`Auto-dismiss duration in milliseconds (default: 5000 for info/success, 8000 for warning/error). Set to 0 to disable auto-dismiss.`}},required:[`message`]}},i9e={name:`send_notification`,description:`Send an OS-level push notification to the user via Web Push. Unlike toasts (in-app only), push notifications appear even when the app is not focused or the tab is in the background. Use for: important alerts, long-running task completion, time-sensitive information. Requires the user to have enabled push notifications in Settings.`,input_schema:{type:`object`,properties:{title:{type:`string`,description:`Notification title (default: 'ShadowClaw')`},body:{type:`string`,description:`The notification body text`}},required:[`body`]}}})),o9e,s9e,c9e=R((()=>{o9e=`https://a2ui.org/specification/v1_0/catalogs/basic/catalog.json`,s9e=`A2UI Basic Catalog — Component & Function Reference
|
|
3694
3694
|
=====================================================
|
|
3695
3695
|
|
|
3696
3696
|
Catalog ID: ${o9e}
|
package/package.json
CHANGED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import{i as e,n as t,r as n,t as r}from"./chunk-4-QO2z6r.js";import{i,n as a,r as o,t as s}from"./chunk-DnR17T-6.js";import{t as c}from"./chunk-BChOKoxf.js";import{c as l,f as u,i as d,l as f,m as p,n as m,o as h,p as g,r as _,s as ee,t as v,u as te}from"./chunk-CeGycQxn.js";import{o as y,r as b}from"./chunk-BcxWvEHa.js";import{t as x}from"./chunk-Dl4zTOqg.js";import{t as S}from"./chunk-DjKQO7aV.js";import{n as C,t as w}from"./chunk-IVWoxOkm.js";import{c as T,l as E,s as D,u as O}from"./chunk-D0Xq-Muz.js";import{i as k,r as A,t as j}from"./chunk-CMEzBK2J.js";import{t as ne}from"./chunk-BhCmCUGL.js";function M(e){if(!e)return``;let t=e.match(/^\r?\n([ \t]+)/);if(t){let n=t[1],r=RegExp(`^[ \\t]{1,${n.length}}`,`gm`);return e.replace(/^\r?\n/,``).replace(r,``).replace(/\r?\n[ \t]*$/,`
|
|
2
|
-
`)}if(/^(?:\r?\n)+[ \t]*---/.test(e))return e.replace(/^(?:\r?\n)+/,``);if(/^[ \t]+---/.test(e)){let t=e.match(/^[ \t]+/);if(t){let n=t[0],r=RegExp(`^[ \\t]{1,${n.length}}`,`gm`);return e.replace(r,``)}}return e}let N=/* @__PURE__ */ new Map;function re(e){if(typeof document>`u`)return null;let t=`shadow-claw-site-config`;if(e){let n=e.getAttribute(`config`)?.trim();n&&(t=n.replace(/^#/,``))}let n=document.getElementById(t);if(!n?.textContent)return N.delete(t),null;let r=N.get(t);if(r&&r.rawText===n.textContent)return r.config;try{let e=JSON.parse(n.textContent);if(!e||typeof e!=`object`)return N.delete(t),null;let r={...e};return N.set(t,{rawText:n.textContent,config:r}),r}catch(e){return console.warn(`[ShadowClaw] Failed to parse site configuration from #${t}:`,e),null}}function ie(e,t,n){let r=null,i,a;return typeof e==`string`?(i=e,a=t):(r=e,i=t,a=n??50),r&&S(r)?Promise.resolve().then(()=>(r.db.prepare(`SELECT * FROM messages WHERE groupId = ? ORDER BY timestamp DESC LIMIT ?`).all(i,a)??[]).reverse().map(ae)):new Promise(async(e,t)=>{try{let n=r??await x();if(!n)return t(/* @__PURE__ */ Error(`failed to get transaction, cannot get recent messages.`));let o=n.transaction(`messages`,`readonly`);if(!o)return t(/* @__PURE__ */ Error(`failed to get transaction`));let s=o.objectStore(`messages`).index(`by-group-time`),c=IDBKeyRange.bound([i,0],[i,1/0]),l=s.openCursor(c,`prev`),u=[];l.onsuccess=()=>{let t=l.result;t&&u.length<a?(u.push(t.value),t.continue()):e(u.reverse())},l.onerror=()=>t(l.error)}catch(e){t(e)}})}function ae(e){return{...e,isFromMe:!!e.isFromMe,isTrigger:!!e.isTrigger,attachments:e.attachments?JSON.parse(e.attachments):void 0,a2uiAction:e.a2uiAction?JSON.parse(e.a2uiAction):void 0,a2uiEnvelopes:e.a2uiEnvelopes?JSON.parse(e.a2uiEnvelopes):void 0}}const oe=`group_metadata`;async function P(e){let t=await w(e,oe);if(!t)return[];try{return JSON.parse(t)}catch{return[]}}async function F(e,t){await O(e,oe,JSON.stringify(t))}async function se(e,t,n=`br:`,r){let i=await P(e),a={groupId:`${n}${r??c()}`,name:t,createdAt:Date.now()};return i.push(a),await F(e,i),a}async function ce(e,t,n){let r=await P(e),i=r.find(e=>e.groupId===t);i&&(i.name=n),await F(e,r)}async function le(e,t,n){let r=await P(e),i=r.find(e=>e.groupId===t);i&&(n&&n.length>0?i.toolTags=n:delete i.toolTags),await F(e,r)}async function ue(e,t){await F(e,(await P(e)).filter(e=>e.groupId!==t))}async function I(e){let t=await P(e);if(t.length===0){let t={groupId:y,name:`Main`,createdAt:0};return await F(e,[t]),[t]}return t}async function de(e,t){let n=await P(e),r=new Map(n.map(e=>[e.groupId,e])),i=[];for(let e of t){let t=r.get(e);t&&(i.push(t),r.delete(e))}for(let e of n)r.has(e.groupId)&&i.push(e);await F(e,i)}async function fe(e,t){let n=await P(e),r=n.find(e=>e.groupId===t);if(!r)return null;let i=t.indexOf(`:`),a={groupId:`${i>=0?t.slice(0,i+1):`br:`}${c()}`,name:`${r.name} (copy)`,createdAt:Date.now(),pinnedMaxTokens:r.pinnedMaxTokens,providerRuntimeOverrides:r.providerRuntimeOverrides?JSON.parse(JSON.stringify(r.providerRuntimeOverrides)):void 0,subagentModelSelectionMode:r.subagentModelSelectionMode,subagentMaxTokens:r.subagentMaxTokens,subagentPinnedProvider:r.subagentPinnedProvider,subagentPinnedModel:r.subagentPinnedModel,subagentFastProvider:r.subagentFastProvider,subagentFastModel:r.subagentFastModel,subagentSmartProvider:r.subagentSmartProvider,subagentSmartModel:r.subagentSmartModel,subagentPowerfulProvider:r.subagentPowerfulProvider,subagentPowerfulModel:r.subagentPowerfulModel,toolTags:r.toolTags?[...r.toolTags]:void 0};return n.push(a),await F(e,n),a}async function pe(e,t,n,r,i){let a=await P(e),o=a.find(e=>e.groupId===t);o&&(n?o.pinnedProvider=n:delete o.pinnedProvider,r?o.pinnedModel=r:delete o.pinnedModel,typeof i==`number`&&Number.isFinite(i)&&i>0?o.pinnedMaxTokens=Math.floor(i):delete o.pinnedMaxTokens),await F(e,a)}async function me(e,t,n,r,i,a){let o=await P(e),s=o.find(e=>e.groupId===t);s&&(s.subagentModelSelectionMode=n,n===`manual`?(r?s.subagentPinnedProvider=r:delete s.subagentPinnedProvider,i?s.subagentPinnedModel=i:delete s.subagentPinnedModel):(delete s.subagentPinnedProvider,delete s.subagentPinnedModel),typeof a==`number`&&Number.isFinite(a)&&a>0?s.subagentMaxTokens=Math.floor(a):delete s.subagentMaxTokens),await F(e,o)}async function he(e,t,n){let r=await P(e),i=r.find(e=>e.groupId===t);i&&(n&&Object.keys(n).length>0?i.providerRuntimeOverrides=JSON.parse(JSON.stringify(n)):delete i.providerRuntimeOverrides),await F(e,r)}function ge(e,t,n,r){let i=t*2**e,a=Math.min(i,n),o=a*r*Math.random();return Math.max(0,a-o)}function _e(e,t){return new Promise((n,r)=>{if(t?.aborted){r(t.reason??new DOMException(`Aborted`,`AbortError`));return}let i=setTimeout(n,e);if(t){let e=()=>{clearTimeout(i),r(t.reason??new DOMException(`Aborted`,`AbortError`))};t.addEventListener(`abort`,e,{once:!0});let a=n;n=(n=>{t.removeEventListener(`abort`,e),a(n)})}})}async function L(){let e=typeof globalThis<`u`?globalThis:void 0;e?.scheduler&&typeof e.scheduler.yield==`function`?await e.scheduler.yield():await new Promise(e=>setTimeout(e,0))}function ve(e,t=y){e.agentWorker?.postMessage({payload:{groupId:t},type:`vm-workspace-sync`})}function ye(e,t=y){e.agentWorker?.postMessage({payload:{groupId:t},type:`vm-workspace-flush`})}function be(e){`serviceWorker`in navigator&&navigator.serviceWorker?.controller&&navigator.serviceWorker.controller.postMessage({type:`set-proxy-config`,payload:{useProxy:e.useProxy,proxyUrl:e.proxyUrl}})}async function xe(e,t,n,r=O){e.gitProxyUrl=n||`/git-proxy`,await r(t,b.GIT_PROXY_URL,e.gitProxyUrl)}async function Se(e,t,n,r=O){e.proxyUrl=n||`/proxy`,await r(t,b.PROXY_URL,e.proxyUrl),be(e)}async function Ce(e,t,n,r=O){e.useProxy=!!n,await r(t,b.USE_PROXY,e.useProxy?`true`:`false`),be(e)}async function we(e,t,n,r=O){e.vmBashFullInternetAccess=!!n,await r(t,b.VM_BASH_FULL_INTERNET_ACCESS,e.vmBashFullInternetAccess?`true`:`false`)}function Te(e,t,n){if(e&&S(e)){let r=e.db,i=r.prepare(`SELECT * FROM messages WHERE groupId = ?`).all(t),a=r.prepare(`INSERT INTO messages
|
|
3
|
-
(id, groupId, timestamp, content, sender, channel, isFromMe, isTrigger, attachments, a2uiAction, a2uiEnvelopes, freshContext, subagent)
|
|
4
|
-
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`);for(let e of i)a.run(c(),n,e.timestamp,e.content,e.sender,e.channel??`chat`,e.isFromMe,e.isTrigger,e.attachments,e.a2uiAction,e.a2uiEnvelopes,e.freshContext,e.subagent);return Promise.resolve(i.length)}return new Promise((r,i)=>{let a=e?.transaction(`messages`,`readwrite`);if(!a)throw Error(`failed to get transaction, cannot clone messages.`);let o=a.objectStore(`messages`),s=o.index(`by-group`).openCursor(t),l=0;s.onsuccess=()=>{let e=s.result;if(e){let t={...e.value,id:c(),groupId:n};o.put(t),l++,e.continue()}else r(l)},s.onerror=()=>i(s.error)})}function Ee(e,t,n){if(e&&S(e)){let r=e.db,i=r.prepare(`SELECT * FROM tasks WHERE groupId = ?`).all(t),a=r.prepare(`INSERT INTO tasks
|
|
5
|
-
(id, groupId, enabled, schedule, prompt, tools, lastRun, createdAt, type, freshContext, subagent, name, task_order, pushNotifications)
|
|
6
|
-
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`);for(let e of i)a.run(c(),n,+!!e.enabled,e.schedule??null,e.prompt??``,e.tools??null,e.lastRun??null,e.createdAt,e.type??null,e.freshContext?1:null,e.subagent?1:null,e.name??null,e.task_order??null,e.pushNotifications?1:null);return Promise.resolve(i.length)}return new Promise((r,i)=>{let a=e?.transaction(`tasks`,`readwrite`);if(!a)throw Error(`failed to get transaction, cannot clone tasks.`);let o=a.objectStore(`tasks`),s=o.index(`by-group`).openCursor(t),l=0;s.onsuccess=()=>{let e=s.result;if(e){let t={...e.value,id:c(),groupId:n};o.put(t),l++,e.continue()}else r(l)},s.onerror=()=>i(s.error)})}function De(e,t){return C(e,`messages`,`readwrite`,e=>e.delete(t)).then(()=>void 0)}function R(e,t){return t?C(e,`tasks`,`readwrite`,e=>e.delete(t)).then(()=>void 0):Promise.reject(/* @__PURE__ */ Error(`Task ID is required for deletion.`))}function Oe(){return typeof crypto<`u`&&typeof crypto.randomUUID==`function`?crypto.randomUUID():`sub-${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`}async function ke(e){if(!e)return Oe();let t=await w(e,b.SUBSCRIBER_ID);if(typeof t==`string`&&t.trim().length>0)return t;let n=Oe();return await O(e,b.SUBSCRIBER_ID,n),n}function z(e,t){return C(e,`messages`,`readwrite`,e=>e.put(t)).then(()=>void 0)}function B(e,t){let n={...t,enabled:+!!t.enabled};return C(e,`tasks`,`readwrite`,e=>e.put(n)).then(()=>void 0)}function Ae(e,t,n){let r=null,i,a;return typeof e==`string`?(i=e,a=t):(r=e,i=t,a=n),r&&S(r)?Promise.resolve().then(()=>{r.db.prepare(`UPDATE tasks SET lastRun = ? WHERE id = ?`).run(a,i)}):new Promise(async(e,t)=>{try{let n=r??await x();if(!n)return t(/* @__PURE__ */ Error(`failed to get transaction, cannot update task last run.`));let o=n.transaction(`tasks`,`readwrite`);if(!o)return t(/* @__PURE__ */ Error(`failed to get transaction`));let s=o.objectStore(`tasks`),c=s.get(i);c.onsuccess=()=>{let n=c.result;if(!n){e();return}n.lastRun=a;let r=s.put(n);r.onsuccess=()=>e(),r.onerror=()=>t(r.error)},c.onerror=()=>t(c.error)}catch(e){t(e)}})}async function je(e,t,n){let r=(await A(e)).filter(e=>e.groupId===t),i=new Map(r.map(e=>[e.id,e])),a=[],o=0;for(let t of n){let n=i.get(t);n&&(n.order=o++,await B(e,n),a.push(n),i.delete(t))}let s=Array.from(i.values()).sort((e,t)=>{let n=e.order??0,r=t.order??0;return n===r?e.createdAt-t.createdAt:n-r});for(let t of s)t.order=o++,await B(e,t),a.push(t);return a}async function Me(e,t,n,r){let i=await f(e,t),a=await f(e,n),o=r.replace(/\\/g,`/`).replace(/^\/+/,``).split(`/`).filter(Boolean),s=i,c=a;for(let e of o)s=await s.getDirectoryHandle(e),c=await c.getDirectoryHandle(e,{create:!0});let l=n.replace(/:/g,`-`),u=[te(),`groups`,l,...o];try{await Ne(e,n,s,c,u)}catch(e){throw o.length>0&&await a.removeEntry(o[0],{recursive:!0}).catch(()=>void 0),e}}async function Ne(e,t,n,r,i){for await(let[a,o]of n.entries()){if(o.kind===`directory`){await Ne(e,t,o,await r.getDirectoryHandle(a,{create:!0}),[...i,a]);continue}let n=await o.getFile(),s=await r.getFileHandle(a,{create:!0});try{await v(s,n)}catch(t){if(!((t instanceof Error?t.message:String(t)).includes(`Writable file streams are not supported`)&&(await u(e)).type===`opfs`))throw t;await m([...i,a],n)}}}function Pe(){let e=s(`/static-main/index.html`);if(typeof window<`u`&&window.location?.origin)try{return new URL(e,window.location.origin).toString()}catch{return e}return e}async function Fe(e){let t=await w(e,b.MAIN_GROUP_INDEX_SUPPRESSED);return t===!0||t===`true`}async function Ie(e,t){await O(e,b.MAIN_GROUP_INDEX_SUPPRESSED,t)}async function Le(t,n=y,r){try{if(await T(t,n,`index.html`)){if(n===`br:main`)try{let i=await E(t,n,`index.html`);typeof i==`string`&&(i.includes(`<shadow-claw`)||i.includes(`data-shadow-claw-dsd`))&&await D(t,n,`index.html`,r??e)}catch{}return!0}if(n===`br:main`&&await Fe(t))return!1;let i=r;if(i===void 0&&typeof fetch==`function`)try{let e=await fetch(Pe());if(e.ok){let t=await e.text();!t.includes(`<shadow-claw`)&&!t.includes(`data-shadow-claw-dsd`)&&(i=t)}}catch{}return i??=e,await D(t,n,`index.html`,i),!0}catch(e){return console.warn(`Failed to ensure main workspace Memory:`,e),!1}}const V=`MEMORY.md`;function Re(){let e=s(`/static-main/MEMORY.md`);if(typeof window<`u`&&window.location?.origin)try{return new URL(e,window.location.origin).toString()}catch{return e}return e}async function H(e){let t=await w(e,b.MAIN_GROUP_README_SUPPRESSED);return t===!0||t===`true`}async function U(e,t){await O(e,b.MAIN_GROUP_README_SUPPRESSED,t)}async function W(e,t=y,r){try{if(await T(e,t,`MEMORY.md`)){if(t===`br:main`)try{let i=await E(e,t,V);typeof i==`string`&&(i.includes(`<shadow-claw`)||i.includes(`data-shadow-claw-dsd`))&&await D(e,t,V,r??n)}catch{}return!0}if(t===`br:main`&&await H(e))return!1;let i=r;if(i===void 0&&typeof fetch==`function`)try{let e=await fetch(Re());if(e.ok){let t=await e.text();!t.includes(`<shadow-claw`)&&!t.includes(`data-shadow-claw-dsd`)&&(i=t)}}catch{}return i??=n,await D(e,t,V,i),!0}catch(e){return console.warn(`Failed to ensure main workspace Memory:`,e),!1}}async function G(e,t,n=`.`){for(let r=0;r<2;r++)try{let r=await f(e,t);if(n&&n!==`.`){let e=n.replace(/\\/g,`/`).replace(/^\/home\/user\//,`/`).replace(/^\/+/,``).split(`/`).filter(Boolean);for(let t of e){let e=await r.getDirectoryHandle(t);if(typeof r.isSameEntry==`function`&&await r.isSameEntry(e))throw Error(`Directory navigation stuck at "${r.name}" for segment "${t}" — the stored directory handle may be stale.`);r=e}}let i=[];for await(let[e,t]of r.entries())i.push(t.kind===`directory`?`${e}/`:e);return i.sort()}catch(e){if(r===0&&p(e)){g();continue}throw e}return[]}function ze(e){if(!e||typeof e!=`object`)return!1;let t=globalThis.FileSystemDirectoryHandle;return t!==void 0&&e instanceof t||typeof e.getDirectoryHandle==`function`&&typeof e.getFileHandle==`function`&&typeof e.requestPermission==`function`}async function Be(e){let t=await w(e,b.STORAGE_HANDLE);return!ze(t)||await t.requestPermission({mode:`readwrite`})===`granted`}function Ve(e){let t=o();return t?`shadowclaw:${t}:${e}`:e}function He(e){if(typeof localStorage>`u`)return null;let t=Ve(e);try{let n=localStorage.getItem(t);if(n!==null)return n;if(t===e)return null;let r=localStorage.getItem(e);if(r!==null)return localStorage.setItem(t,r),r}catch(e){console.warn(`Unable to read from localStorage:`,e)}return null}function K(e,t){if(typeof localStorage>`u`)return;let n=Ve(e);try{localStorage.setItem(n,t)}catch(e){console.warn(`Unable to write to localStorage:`,e)}}async function Ue(e,t){let n=await f(e,t);for await(let[e]of n.entries())await n.removeEntry(e,{recursive:!0})}async function q(e,t,n){let r=await f(e,t),{dirs:i,filename:a}=l(n.replace(/\/$/,``)),o=r;for(let e of i)o=await o.getDirectoryHandle(e);await o.removeEntry(a,{recursive:!0})}function J(e,t){return`${e}:${t}`}async function We(e){let t=await w(e,b.SUPPRESSED_PAGES_LIST);if(!t||typeof t!=`string`)return[];try{let e=JSON.parse(t);if(Array.isArray(e))return e}catch{}return[]}async function Ge(e,t,n){let r=await We(e),i=J(t,n);return r.some(e=>J(e.groupId,e.path)===i)}async function Ke(e,t,n){let r=await We(e),i=J(t,n);if(!r.some(e=>J(e.groupId,e.path)===i)){let i=[...r,{groupId:t,path:n}];await O(e,b.SUPPRESSED_PAGES_LIST,JSON.stringify(i))}}async function qe(e,t,n){let r=await We(e),i=J(t,n),a=r.filter(e=>J(e.groupId,e.path)!==i);a.length!==r.length&&await O(e,b.SUPPRESSED_PAGES_LIST,JSON.stringify(a))}function Je(e=y){return e===`br:main`?b.STATIC_MAIN_SITE_SEEDED:`${b.STATIC_MAIN_SITE_SEEDED}:${e}`}async function Ye(e,t=y){let n=Je(t),r=await w(e,n);return r===!0||r===`true`}async function Xe(e,t=y,n=!0){let r=Je(t);await O(e,r,n)}function Ze(){let e=s(`/static-main-manifest.json`);if(typeof window<`u`&&window.location?.origin)try{return new URL(e,window.location.origin).toString()}catch{return e}return e}function Qe(e){let t=e.replace(/^\/+/,``),n=`static-main`;if(typeof document<`u`)try{let e=document.getElementById(`shadow-claw-site-config`);if(e?.textContent){let t=JSON.parse(e.textContent);typeof t?.pages?.baseUrl==`string`&&(n=t.pages.baseUrl.replace(/^\/+/,``).replace(/\/+$/,``))}}catch{}let r=s(n?`/${n}/${t}`:`/${t}`);if(typeof window<`u`&&window.location?.origin)try{return new URL(r,window.location.origin).toString()}catch{return r}return r}async function $e(){if(typeof fetch!=`function`)return null;try{let e=Ze(),t=await fetch(e);if(t.ok){if((t.headers?.get?.(`content-type`)||``).includes(`text/html`))return null;let e=await t.json();if(e&&Array.isArray(e.pages))return e}}catch{}return null}async function et(e){if(typeof fetch!=`function`)return null;try{let t=Qe(e),n=await fetch(t);if(n.ok){let t=n.headers?.get?.(`content-type`)||``;if((e.endsWith(`.md`)||e.endsWith(`.markdown`)||e.endsWith(`.json`))&&t.includes(`text/html`))return null;let r=await n.text();return r.includes(`<shadow-claw`)||r.includes(`data-shadow-claw-dsd`)?null:r}}catch{}return null}function tt(e){if(typeof document>`u`)return null;let t=t=>{if(!t||!(t instanceof HTMLElement))return!1;if(!e)return!0;let n=t.getAttribute(`data-initial-path`)?.trim();return!n||n===e},n=document.querySelector(e?`[data-pages-rendered][data-initial-path="${e}"]`:`[data-pages-rendered]`);if(t(n))return n;let r=document.querySelector(`shadow-claw`)?.shadowRoot,i=(r?.querySelector(`shadow-claw-pages`)?.shadowRoot)?.querySelector(e?`[data-pages-rendered][data-initial-path="${e}"]`:`[data-pages-rendered]`)||r?.querySelector(e?`[data-pages-rendered][data-initial-path="${e}"]`:`[data-pages-rendered]`);if(t(i))return i;let a=document.querySelectorAll(`template`);for(let n of Array.from(a)){let r=n.content?.querySelector(e?`[data-pages-rendered][data-initial-path="${e}"]`:`[data-pages-rendered]`);if(t(r))return r;let i=n.content?.querySelectorAll(`template`);if(i)for(let n of Array.from(i)){let r=n.content?.querySelector(e?`[data-pages-rendered][data-initial-path="${e}"]`:`[data-pages-rendered]`);if(t(r))return r}}return null}function Y(e=`index.html`){let t=tt(e);if(!t)return null;let n=t.getAttribute(`data-initial-path`)?.trim();if(n&&n!==e)return null;let r=t.querySelector(`[data-markdown-frontmatter]`),i=null;if(r){let e=r.getAttribute(`data-frontmatter`);if(e)try{i=JSON.parse(e)}catch{}}let a=t.cloneNode(!0),o=a.querySelector(`[data-markdown-frontmatter]`);o&&o.remove();let s=a.innerHTML.trim();if(!s&&!i)return null;if(i&&Object.keys(i).length>0){let e=[`---`];for(let[t,n]of Object.entries(i))typeof n==`string`?e.push(`${t}: ${JSON.stringify(n)}`):typeof n==`number`||typeof n==`boolean`?e.push(`${t}: ${n}`):e.push(`${t}: ${JSON.stringify(n)}`);return e.push(`---`,``),`${e.join(`
|
|
7
|
-
`)}\n${s}`}return s}async function nt(t={}){let r=()=>{let t=null;if(typeof document<`u`){let r=document.getElementById(`shadow-claw-static-manifest`);if(r&&r.textContent)try{let e=JSON.parse(r.textContent);e&&Array.isArray(e.pages)&&(t={...e,pages:[...e.pages]})}catch(e){console.warn(`Failed to parse embedded static main manifest:`,e)}let i=document.querySelectorAll(`script[type="text/markdown"][data-shadow-claw-page]`);if(i.length>0){t||={pages:[]};for(let r of Array.from(i)){let i=r.getAttribute(`data-shadow-claw-page`)?.trim();if(i){let a=r.textContent||``;a=M(a),!a.trim()&&/^memory\.(md|markdown)$/iu.test(i)&&(a=n),!a.trim()&&(i===`index.html`||/^index\.(html?|xhtml)$/iu.test(i))&&(a=Y(i)??e);let o=t.pages.findIndex(e=>e.displayPath===i);o>=0?t.pages[o].content=a:t.pages.push({displayPath:i,content:a})}}}let a=document.getElementById(`shadow-claw-site-config`);if(a?.textContent)try{let r=JSON.parse(a.textContent);if(Array.isArray(r?.pages?.files)){t||={pages:[]};for(let i of r.pages.files)if(typeof i==`string`&&i.trim()){let r=i.trim(),a=``;/^memory\.(md|markdown)$/iu.test(r)?a=n:(r===`index.html`||/^index\.(html?|xhtml)$/iu.test(r))&&(a=Y(r)??e),t.pages.some(e=>e.displayPath===r)||t.pages.push({displayPath:r,content:a})}}}catch{}let o=tt();if(o){t||={pages:[]};let r=o.getAttribute(`data-initial-path`)?.trim()||`index.html`;if(!t.pages.some(e=>e.displayPath===r)){let n=Y(r)??e;t.pages.push({displayPath:r,content:n})}t.pages.some(e=>/^memory\.(md|markdown)$/iu.test(e.displayPath))||t.pages.push({displayPath:`MEMORY.md`,content:n})}}return t};if(t.preferEmbedded!==!1){let e=r();if(e)return e}if(t.fetchFallback!==!1){let e=await $e();if(e)return e}if(t.preferEmbedded===!1){let e=r();if(e)return e}return{pages:[{displayPath:`index.html`,content:e},{displayPath:`MEMORY.md`,content:n}]}}async function rt(e,t,n=[]){for(let[r,i]of Object.entries(t))if(r===`purgePreRenderedStaticPages`&&i===!0){if(n.length>0){let t=n[0],r=n.slice(1).join(`/`);try{r?await q(e,t,r):await Ue(e,t)}catch(e){console.warn(`Failed to purge pre-rendered static pages for ${t}/${r}:`,e)}}}else typeof i==`object`&&i&&await rt(e,i,[...n,r])}function it(){if(typeof document<`u`)try{let e=document.getElementById(`shadow-claw-site-config`);if(e?.textContent){let t=JSON.parse(e.textContent);if(t?.pages?.sortOrder===`desc`)return`desc`;if(t?.pages?.sortOrder===`asc`)return`asc`}}catch{}return`desc`}function at(){if(typeof document<`u`)try{let e=document.getElementById(`shadow-claw-site-config`);if(e?.textContent){let t=JSON.parse(e.textContent)?.pages?.defaultPinnedPage;if(typeof t==`string`&&t.trim().length>0)return t.trim()}}catch{}return null}function ot(){if(typeof document<`u`)try{let e=document.getElementById(`shadow-claw-site-config`);if(e?.textContent){let n=JSON.parse(e.textContent);return{allowList:t(n?.pages?.allowList??n?.pages?.allowlist??n?.allowList??n?.allowlist??[]),denyList:t(n?.pages?.denyList??n?.pages?.denylist??n?.denyList??n?.denylist??[])}}}catch{}return{allowList:[],denyList:[]}}function st(e,t){let n=t??it();return[...e].sort((e,t)=>{let r=e.path,i=t.path,a=r.split(`/`).pop()||``,o=i.split(`/`).pop()||``,s=/^index\.(html?|xhtml)$/iu.test(a),c=/^index\.(html?|xhtml)$/iu.test(o);if(s&&!c)return-1;if(!s&&c)return 1;let l=/^memory\.(md|markdown)$/iu.test(a),u=/^memory\.(md|markdown)$/iu.test(o);return l&&!u?1:!l&&u?-1:n===`asc`?r.localeCompare(i,void 0,{numeric:!0,sensitivity:`base`}):i.localeCompare(r,void 0,{numeric:!0,sensitivity:`base`})})}async function X(e,t,n=`sc:purge-id`,r=`static_main_site_purge_id`){let i=t??`__legacy_purge_pages__`;try{if(He(n)===i)return!0}catch{}try{if(await w(e,r)===i){try{K(n,i)}catch{}return!0}await O(e,r,i);try{K(n,i)}catch{}}catch{try{K(n,i)}catch{}}return!1}async function ct(t,i=y,a=[],o={}){await Le(t,i);let s=await nt(o),c=!1;s.preRenderedStaticPages&&(await X(t,s.purgeId)||(c=!0,await rt(t,s.preRenderedStaticPages)));let l=!1;if(i===`br:main`&&s.skillsPurgeId!==void 0&&!await X(t,s.skillsPurgeId,`sc:skills-purge-id`,`static_main_skills_purge_id`)){l=!0;try{await q(t,i,`.agents/skills/main`)}catch(e){if(!(e&&typeof e==`object`&&`name`in e&&e.name===`NotFoundError`))throw e}try{await q(t,i,`.agents/tools/main`)}catch(e){if(!(e&&typeof e==`object`&&`name`in e&&e.name===`NotFoundError`))throw e}}for(let e of s.pages)if(e.content?.includes(`slug: "shadow-claw--purge-pages"`)){!c&&!await X(t,s.purgeId)&&(c=!0,await Ue(t,i));break}let u=i===`br:main`&&await H(t),d=new Set(s.pages.map(e=>J(i,e.displayPath))),f=c?a.filter(e=>e.groupId!==i||d.has(J(e.groupId,e.path))):[...a],{allowList:p,denyList:m}=ot(),h=0;for(let a of s.pages)if(h++,h%5==0&&await new Promise(e=>setTimeout(e,0)),!a.content?.includes(`slug: "shadow-claw--purge-pages"`)&&r(a.displayPath,{allowList:p,denyList:m,groupId:i})){if(/^memory\.(md|markdown)$/iu.test(a.displayPath)){if(u)continue;let e=typeof a.content==`string`&&a.content.trim().length>0&&a.content!==n?a.content:void 0;if(e===void 0?await W(t,i):await W(t,i,e)){let e=J(i,a.displayPath);f.some(t=>J(t.groupId,t.path)===e)||f.push({groupId:i,path:a.displayPath})}}else if(!await Ge(t,i,a.displayPath))try{if(!await T(t,i,a.displayPath)){let n=a.content;(typeof n!=`string`||!n.trim())&&(n=a.displayPath===`index.html`?Y(`index.html`)??e:await et(a.displayPath)??``),await D(t,i,a.displayPath,n)}let n=J(i,a.displayPath);f.some(e=>J(e.groupId,e.path)===n)||f.push({groupId:i,path:a.displayPath})}catch(e){console.warn(`Failed to seed static page file ${a.displayPath}:`,e)}}if(i===`br:main`){for(let e of s.skills||[]){let n=`.agents/skills/main/${e.displayPath}`;try{await T(t,i,n)||await D(t,i,n,e.content)}catch(e){console.warn(`Failed to seed skill file ${n}:`,e)}}for(let e of s.tools||[]){let n=`.agents/tools/main/${e.displayPath}`;try{(l||!await T(t,i,n))&&await D(t,i,n,e.content)}catch(e){console.warn(`Failed to seed tool file ${n}:`,e)}}}let g=typeof document<`u`&&(document.getElementById(`shadow-claw-static-manifest`)!==null||document.querySelector(`script[type="text/markdown"][data-shadow-claw-page]`)!==null||tt()!==null);o.preferEmbedded!==!1&&g||await Xe(t,i,!0);let _=f.filter(e=>r(e.path,{allowList:p,denyList:m,groupId:e.groupId}));return Object.defineProperty(_,"didPurge",{value:c,enumerable:!1,writable:!0,configurable:!0}),Object.defineProperty(_,"didPurgeSkills",{value:l,enumerable:!1,writable:!0,configurable:!0}),st(_)}var lt=class{_events;_handlers=[];_runs=/* @__PURE__ */ new Map;constructor(e){this._events=e}start(){this._listen(`streaming-start`,this._onStreamingStart),this._listen(`streaming-chunk`,this._onStreamingChunk),this._listen(`streaming-end`,this._onStreamingEnd),this._listen(`streaming-done`,this._onStreamingDone),this._listen(`streaming-error`,this._onStreamingError),this._listen(`tool-activity`,this._onToolActivity)}stop(){for(let{event:e,handler:t}of this._handlers)this._events.off(e,t);this._handlers=[],this._runs.clear()}_emit(e,t){window.dispatchEvent(new CustomEvent(`shadow-claw-agui-event`,{detail:{groupId:e,event:t}}))}_listen(e,t){this._events.on(e,t),this._handlers.push({event:e,handler:t})}_onStreamingChunk=({groupId:e,text:t})=>{let n=this._runs.get(e);n&&n.messageId&&this._emit(e,{type:`TEXT_MESSAGE_CONTENT`,messageId:n.messageId,delta:t,timestamp:Date.now()})};_onStreamingDone=({groupId:e})=>{let t=this._runs.get(e);t&&(t.messageId&&this._emit(e,{type:`TEXT_MESSAGE_END`,messageId:t.messageId,timestamp:Date.now()}),this._emit(e,{type:`RUN_FINISHED`,threadId:t.threadId,runId:t.runId,timestamp:Date.now()}),this._runs.delete(e))};_onStreamingEnd=({groupId:e})=>{let t=this._runs.get(e);t&&t.messageId&&(this._emit(e,{type:`TEXT_MESSAGE_END`,messageId:t.messageId,timestamp:Date.now()}),t.messageId=null)};_onStreamingError=({groupId:e,error:t})=>{let n=this._runs.get(e);n&&(n.messageId&&this._emit(e,{type:`TEXT_MESSAGE_END`,messageId:n.messageId,timestamp:Date.now()}),this._emit(e,{type:`RUN_ERROR`,message:t||`Unknown streaming error`,timestamp:Date.now()}),this._runs.delete(e))};_onStreamingStart=({groupId:e})=>{let t=c(),n=e,r=c();this._runs.set(e,{runId:t,threadId:n,messageId:r,activeToolCallIds:/* @__PURE__ */ new Set}),this._emit(e,{type:`RUN_STARTED`,threadId:n,runId:t,timestamp:Date.now()}),this._emit(e,{type:`TEXT_MESSAGE_START`,messageId:r,role:`assistant`,timestamp:Date.now()})};_onToolActivity=({groupId:e,tool:t,status:n})=>{let r=this._runs.get(e);if(r){if(n===`running`){let n=c();r.activeToolCallIds.add(n),this._emit(e,{type:`TOOL_CALL_START`,toolCallId:n,toolCallName:t,timestamp:Date.now()}),r._lastToolCallId=n}else if(n===`done`||n===`error`){let t=r._lastToolCallId;t&&(r.activeToolCallIds.delete(t),this._emit(e,{type:`TOOL_CALL_END`,toolCallId:t,timestamp:Date.now()}))}}}};const ut=new class{#e=new k.State(0);#t=/* @__PURE__ */ new Map;#n=new k.State([]);clear(){this.#t.forEach((e,t)=>this.clearTimer(t)),this.#t.clear(),this.#n.set([])}clearTimer(e){let t=this.#t.get(e);t?.timeoutId&&clearTimeout(t.timeoutId),this.#t.delete(e)}dismiss(e){this.clearTimer(e),this.#n.set(this.#n.get().filter(t=>t.id!==e))}pause(e){let t=this.#t.get(e);t&&t.timeoutId&&(clearTimeout(t.timeoutId),t.timeoutId=void 0,t.remaining=Math.max(0,t.remaining-(Date.now()-t.startedAt)),this.#t.set(e,t))}resolveAction(e){if(e&&typeof e.label==`string`&&typeof e.onClick==`function`)return e}resolveDuration(e){return typeof e!=`number`||Number.isNaN(e)||e<0?4e3:e}resolveType(e){return e&&[`success`,`warning`,`error`,`info`].includes(e)?e:`info`}resume(e){let t=this.#t.get(e);!t||t.timeoutId||t.remaining<=0||this.scheduleDismiss(e,t.remaining)}scheduleDismiss(e,t){this.clearTimer(e);let n=globalThis.setTimeout(()=>{this.dismiss(e)},t);this.#t.set(e,{timeoutId:n,remaining:t,startedAt:Date.now()})}show(e,t={}){let n=this.#e.get()+1;this.#e.set(n);let r={id:n,message:e,type:this.resolveType(t.type),duration:this.resolveDuration(t.duration),action:this.resolveAction(t.action),createdAt:Date.now()},i=[...this.#n.get(),r];if(i.length>5){let e=i[0];this.clearTimer(e.id),this.#n.set(i.slice(1))}else this.#n.set(i);return r.duration>0&&this.scheduleDismiss(r.id,r.duration),r.id}get toasts(){return this.#n.get()}async runAction(e){let t=this.#n.get().find(t=>t.id===e);t?.action&&await t.action.onClick()}};function dt(e,t={}){return ut.show(e,t)}function ft(e,t=4e3){return ut.show(e,{type:`success`,duration:t})}function Z(e,t=5e3){return ut.show(e,{type:`error`,duration:t})}function pt(e,t){if(!e||typeof e!=`object`)return e;let n=JSON.parse(JSON.stringify(e));for(let e of t)mt(n,e);return n}function mt(e,t){let{op:n,path:r,value:i}=t;if(!r||!r.startsWith(`/`))return;let a=r.split(`/`).slice(1).map(e=>e.replace(/~1/g,`/`).replace(/~0/g,`~`)),o=a.pop();if(o===void 0)return;let s=e;for(let e of a){if(typeof s!=`object`||!s)return;s=s[e]}typeof s==`object`&&s&&(Array.isArray(s)?ht(s,o,n,i):gt(s,o,n,i))}function ht(e,t,n,r){if(n===`add`){if(t===`-`)e.push(r);else{let n=parseInt(t,10);!isNaN(n)&&n>=0&&n<=e.length&&e.splice(n,0,r)}}else if(n===`replace`){let n=parseInt(t,10);!isNaN(n)&&n>=0&&n<e.length&&(e[n]=r)}else if(n===`remove`){let n=parseInt(t,10);!isNaN(n)&&n>=0&&n<e.length&&e.splice(n,1)}}function gt(e,t,n,r){n===`add`||n===`replace`?e[t]=r:n===`remove`&&delete e[t]}function _t(e){if(e==null)return null;let t=String(e).trim().toLowerCase();return[`1`,`true`,`yes`,`on`].includes(t)?!0:![`0`,`false`,`no`,`off`].includes(t)&&null}function vt(e,t=!1){if(e==null)return t;if(typeof e==`boolean`)return e;if(typeof e==`number`)return e===1;if(typeof e==`string`){let t=e.trim().toLowerCase();return t===`true`||t===`1`}return!1}function yt(e){if(!e)return[];try{let n=JSON.parse(e);if(Array.isArray(n))return t(n.map(e=>String(e)))}catch{}return t(e.split(`,`))}function bt(e){if(e){if(Array.isArray(e))return e;if(typeof e==`string`)try{let t=JSON.parse(e);return Array.isArray(t)?t:void 0}catch{return}}}function xt(e){if(typeof e==`boolean`)return e;if(typeof e==`string`){let t=e.trim().toLowerCase();return t===`true`||t===`1`}return typeof e==`number`&&e===1}function St(e){return!!e}async function Q(e,t,n,r){if(!St(r))return!0;if(!e.schedule)return await $(e.id,t,n,r)!==`failed`;try{let r=t.replace(/\/$/,``);return(await fetch(`${r}/tasks`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({...e,subscriberId:n})})).ok}catch{return!1}}async function $(e,t,n,r){if(!St(r))return`missing`;try{let r=t.replace(/\/$/,``),i=`subscriberId=${encodeURIComponent(n)}`,a=await fetch(`${r}/tasks/${encodeURIComponent(e)}?${i}`,{method:`DELETE`});return a.ok?`deleted`:a.status===404||a.status===405?`missing`:`failed`}catch{return`failed`}}async function Ct(e,t,n,r){if(!St(r))return null;try{let r=t.replace(/\/$/,``),i=await fetch(`${r}/tasks?groupId=${encodeURIComponent(e)}&subscriberId=${encodeURIComponent(n)}`,{method:`GET`});if(!i.ok||typeof i.json!=`function`)return null;let a=await i.json();return Array.isArray(a)?a.filter(e=>!!e&&typeof e==`object`&&typeof e.id==`string`&&typeof e.schedule==`string`&&typeof e.prompt==`string`).map(t=>({id:t.id,groupId:t.group_id||t.groupId||e,schedule:t.schedule,type:t.type,prompt:t.prompt,tools:bt(t.tools),channel:typeof t.channel==`string`?t.channel:void 0,enabled:t.enabled===!0||t.enabled===1,lastRun:typeof t.lastRun==`number`?t.lastRun:typeof t.last_run==`number`?t.last_run:null,createdAt:typeof t.createdAt==`number`?t.createdAt:typeof t.created_at==`number`?t.created_at:Date.now(),name:typeof t.name==`string`?t.name:void 0,order:typeof t.order==`number`?t.order:typeof t.task_order==`number`?t.task_order:void 0})):null}catch{return null}}function wt(e,t){let n=(e?.inputTokens??0)+(t.inputTokens??0),r=(e?.outputTokens??0)+(t.outputTokens??0),i=(e?.cacheReadTokens??0)+(t.cacheReadTokens??0),a=(e?.cacheCreationTokens??0)+(t.cacheCreationTokens??0);return{groupId:t.groupId||e?.groupId||``,inputTokens:n,outputTokens:r,cacheReadTokens:i,cacheCreationTokens:a,totalTokens:n+r+i+a,contextLimit:t.contextLimit||e?.contextLimit||0}}var Tt=class e{static DEFAULT_PAGE_PATH=`MEMORY.md`;orchestrator;_activeGroupId;_activePage;_activePinnedPage;_defaultPinnedPage;_activityLog;_activityLogSessionStartedAtByGroup;_aguiAdapter;_aguiEvent;_contextUsage;_currentPath;_db;_error;_files;_gitProxyUrl;_groups;_hadPersistedActivePage;_initResolve;_isTyping;_lastOrchestratorDisplayState=`idle`;_messages;_modelDownloadProgress;_onlineReplayHandler;_pages;_pagesAllowList;_pagesDenyList;_peerStateByGroup;_proxyUrl;_ready;_remoteAgentStatusByGroup;_remoteAgentTypingByGroup;_replayingTaskSyncOutbox;_subscriberId;_sidebarDefaultPage;_state;_storageStatus;_streamingText;_tasks;_taskSyncOutbox;_tokenUsage;_tokenUsageAccumulator=null;_toolActivity;_unreadGroupIds;_useProxy;_vmBashFullInternetAccess;_whenInitialized;_whenReady;_readyResolve;constructor(){this._messages=new k.State([]),this._isTyping=new k.State(!1),this._storageStatus=new k.State(null),this._toolActivity=new k.State(null),this._modelDownloadProgress=new k.State(null),this._activityLog=new k.State([]),this._state=new k.State(`idle`),this._tokenUsage=new k.State(null),this._error=new k.State(null),this._activeGroupId=new k.State(y),this._ready=new k.State(!1),this._tasks=new k.State([]),this._files=new k.State([]),this._currentPath=new k.State(`.`),this._groups=new k.State([]),this._unreadGroupIds=new k.State(/* @__PURE__ */ new Set),this._streamingText=new k.State(null),this._aguiEvent=new k.State(null),this._contextUsage=new k.State(null),this._useProxy=new k.State(!1),this._proxyUrl=new k.State(`/proxy`),this._gitProxyUrl=new k.State(`/git-proxy`),this._vmBashFullInternetAccess=new k.State(!1),this._activePage=new k.State(`pages`);let e=re()?.sidebar?.defaultPage,t=e===`pages`||e===`chat`||e===`tasks`||e===`files`?e:`chat`;this._sidebarDefaultPage=new k.State(t),this._pages=new k.State([]),this._pagesAllowList=new k.State([]),this._pagesDenyList=new k.State([]),this._activePinnedPage=new k.State(null),this._defaultPinnedPage=new k.State(null),this._remoteAgentStatusByGroup=new k.State(/* @__PURE__ */ new Map),this._remoteAgentTypingByGroup=new k.State(/* @__PURE__ */ new Map),this._peerStateByGroup=new k.State(/* @__PURE__ */ new Map),this._hadPersistedActivePage=!1,this._initResolve=null,this._whenInitialized=new Promise(e=>{this._initResolve=e}),this._readyResolve=null,this._whenReady=new Promise(e=>{this._readyResolve=e}),this.orchestrator=null,this._db=null,this._activityLogSessionStartedAtByGroup=/* @__PURE__ */ new Map,this._taskSyncOutbox=[],this._replayingTaskSyncOutbox=!1,this._subscriberId=null,this._onlineReplayHandler=null,this._aguiAdapter=null}get activeGroupId(){return this._activeGroupId.get()}get activePage(){return this._activePage.get()}get activePinnedPage(){return this._activePinnedPage.get()}get defaultPinnedPage(){return this._defaultPinnedPage.get()}get pagesAllowList(){return this._pagesAllowList.get()}get pagesDenyList(){return this._pagesDenyList.get()}isPageAllowed(e,t){return r(e,{allowList:this._pagesAllowList.get(),denyList:this._pagesDenyList.get(),groupId:t??this._activeGroupId.get()})}get effectiveDefaultPage(){let e=this._defaultPinnedPage.get();return e&&this.isPageAllowed(e.path,e.groupId)?e:this._pages.get()[0]||null}get activityLog(){return this._activityLog.get()}get taskServerEnabled(){return this.orchestrator?.taskServerEnabled??!1}get aguiEvent(){return this._aguiEvent.get()}clearError(){this._error.set(null),this._state.get()===`error`&&this._state.set(`idle`)}get contextUsage(){return this._contextUsage.get()}get tokenUsageAccumulator(){return this._tokenUsageAccumulator}get currentPath(){return this._currentPath.get()}get error(){return this._error.get()}get files(){return this._files.get()}getPeerState(e){return this._peerStateByGroup.get().get(e)||null}getRemoteAgentStatus(e){return this._remoteAgentStatusByGroup.get().get(e)||`idle`}getState(){return{messages:this.messages,isTyping:this.isTyping,toolActivity:this.toolActivity,activityLog:this.activityLog,state:this.state,tokenUsage:this.tokenUsage,modelDownloadProgress:this.modelDownloadProgress,error:this.error,activeGroupId:this.activeGroupId,pages:this.pages,ready:this.ready,files:this.files,currentPath:this.currentPath,streamingText:this.streamingText,contextUsage:this.contextUsage}}getTasksForBackup(){return this._tasks.get()}get gitProxyUrl(){return this._gitProxyUrl.get()}get groups(){return this._groups.get()}get hadPersistedActivePage(){return this._hadPersistedActivePage}isRemoteAgentTyping(e){return this._remoteAgentTypingByGroup.get().get(e)||!1}get isTyping(){return this._isTyping.get()}get messages(){return this._messages.get()}get modelDownloadProgress(){return this._modelDownloadProgress.get()}get pages(){return this._pages.get()}get proxyUrl(){return this._proxyUrl.get()}get ready(){return this._ready.get()}sendMessage(e,t=[],n){n===void 0?this.orchestrator?.browserChat?.submit(e,this._activeGroupId.get(),t):this.orchestrator?.browserChat?.submit(e,this._activeGroupId.get(),t,n)}async sendFileToPeer(e,t=this._activeGroupId.get(),n){let r=t.startsWith(`peer:`),i=t.startsWith(`room:`);if(!r&&!i){let e=`Can only send files to peers in a peer or room conversation.`;throw Z(e,4500),Error(e)}let a=this.orchestrator?.router;if(!a){let e=`Network router is not initialized.`;throw Z(e,4500),Error(e)}let o=n?.fileName||e.split(`/`).pop()||e,s=n?.mimeType||`application/octet-stream`,l=n?.size||0;a.setTyping(t,!0);try{let n={path:e,fileName:o,mimeType:s,size:l};if(await a.send(t,``,[n]),this._db){let e={id:c(),groupId:t,sender:`You`,content:``,timestamp:Date.now(),channel:i?`room`:`peerjs`,attachments:[n],isFromMe:!1,isTrigger:!1};await z(this._db,e),this.orchestrator?.events.emit(`message`,e)}ft(`Sent ${o} to ${i?`room peers`:`peer`}`,2500)}catch(e){let t=e instanceof Error?e.message:String(e);throw console.error(`sendFileToPeer error:`,e),Z(`Failed to send file: ${t}`,6e3),e}finally{a.setTyping(t,!1)}}setActiveGroup(e,t,n=this._activePage.get()===`chat`){if(this._activeGroupId.set(t),this._messages.set([]),this._activityLog.set([]),this._error.set(null),this._isTyping.set(!1),this._toolActivity.set(null),this._modelDownloadProgress.set(null),this._streamingText.set(null),this._currentPath.set(`.`),n){let e=new Set(this._unreadGroupIds.get());e.delete(t)&&this._unreadGroupIds.set(e)}this.loadHistory(),this.loadTasks(e),this.loadFiles(e)}setReady(e=!0){this._ready.set(e),e&&this._readyResolve&&this._readyResolve()}setRemoteAgentStatus(e,t){let n=this._remoteAgentStatusByGroup.get(),r=new Map(n);r.set(e,t),this._remoteAgentStatusByGroup.set(r)}setRemoteAgentTyping(e,t){let n=this._remoteAgentTypingByGroup.get(),r=new Map(n);t?r.set(e,!0):r.delete(e),this._remoteAgentTypingByGroup.set(r)}get sidebarDefaultPage(){return this._sidebarDefaultPage.get()}get state(){return this._state.get()}stopCurrentRequest(){this.orchestrator?.stopCurrentRequest?.(this._activeGroupId.get())}get storageStatus(){return this._storageStatus.get()}get streamingText(){return this._streamingText.get()}syncHostWorkspaceToVM(){ve(this.orchestrator,this._activeGroupId.get())}syncVMWorkspaceToHost(){ye(this.orchestrator,this._activeGroupId.get())}get tasks(){return this._tasks.get()}get tokenUsage(){return this._tokenUsage.get()}get toolActivity(){return this._toolActivity.get()}get unreadGroupIds(){return this._unreadGroupIds.get()}get useProxy(){return this._useProxy.get()}get vmBashFullInternetAccess(){return this._vmBashFullInternetAccess.get()}get whenInitialized(){return this._whenInitialized}async resetSiteConfigSeed(e){await O(e,b.SITE_CONFIG_SEEDED,!1)}get whenReady(){return this._whenReady}async addPage(e,t,n=this._activeGroupId.get()){let r=n===`br:main`?this.normalizePagePath(t):t.trim();if(!r||!this.isPageAllowed(r,n))return;let i=this._pages.get();i.some(e=>e.path===r&&e.groupId===n)||(this.setPages([...i,{groupId:n,path:r}]),await qe(e,n,r),n===`br:main`&&r===`MEMORY.md`&&await U(e,!1),await this.persistPages(e))}async clearAllTasks(e){let t=await A(e),n=this._activeGroupId.get(),r=t.filter(e=>e.groupId===n),i=await this.getSubscriberId(e);for(let t of r)await $(t.id,this.getTaskServerBaseUrl(),i,this.orchestrator?.taskServerEnabled??!1)===`failed`?(console.warn(`Failed to delete task "${t.id}" from server — queued for replay.`),await this.queueTaskSyncOutboxOperation(e,{type:`delete`,id:t.id,queuedAt:Date.now()})):await R(e,t.id);await this.loadTasks(e)}async cloneConversation(e,t){let n=await fe(e,t);if(!n)return null;await Te(e,t,n.groupId),await Ee(e,t,n.groupId);try{let r=await E(e,t,`MEMORY.md`);r&&await D(e,n.groupId,`MEMORY.md`,r)}catch{}try{await Me(e,t,n.groupId,`attachments`)}catch{}return this.setActiveGroup(e,n.groupId),await this.loadGroups(e),n}async compactContext(e){if(!this.orchestrator)return;let{compactContext:t}=await import(`./chunk-Bq38OubR.js`);return t(this.orchestrator,e,this._activeGroupId.get())}async createConversation(e,t){let n=await se(e,t);return this.setActiveGroup(e,n.groupId),await this.loadGroups(e),n}async deleteConversation(e,t){if(!(this._groups.get().length<=1)&&(await ue(e,t),await ne(e,t),await this.loadGroups(e),this._activeGroupId.get()===t)){let t=this._groups.get()[0]?.groupId||`br:main`;this.setActiveGroup(e,t)}}async deleteMessage(e,t){await De(e,t),await this.loadHistory(),this.orchestrator?.refreshContextUsage&&await this.orchestrator.refreshContextUsage(e,this._activeGroupId.get())}async deleteTask(e,t){let n=await this.getSubscriberId(e);if(await $(t,this.getTaskServerBaseUrl(),n,this.orchestrator?.taskServerEnabled??!1)===`failed`)throw console.warn(`Failed to delete task from server — queued for replay.`),await this.queueTaskSyncOutboxOperation(e,{type:`delete`,id:t,queuedAt:Date.now()}),Error(`Failed to delete scheduled task on server; task kept locally.`);await R(e,t),await this.loadTasks(e)}async ensurePeerConversation(e,t){let n=`peer:${t}`,r=await I(e);if(!r.find(e=>e.groupId===n)){let i=[...r],a=``;if(this.orchestrator?.peerjsPeerAliases){for(let[e,n]of Object.entries(this.orchestrator.peerjsPeerAliases))if(n===t){a=e;break}}i.push({groupId:n,name:`Peer: ${a||t.substring(0,8)}`,createdAt:Date.now()}),await F(e,i),await this.loadGroups(e)}return n}async grantStorageAccess(e){try{await Be(e),await this.loadFiles(e)}catch(e){console.error(`Failed to grant storage access:`,e)}}async init(e,t){this._db=e,this.orchestrator=t,this._taskSyncOutbox=this.parseTaskSyncOutbox(await w(e,b.TASK_SYNC_OUTBOX)),await this.replayTaskSyncOutbox(e),typeof window<`u`&&!this._onlineReplayHandler&&(this._onlineReplayHandler=()=>{this._db&&this.replayTaskSyncOutbox(this._db)},window.addEventListener(`online`,this._onlineReplayHandler)),t.events.on(`a2ui-surface`,async({groupId:t,envelope:n})=>{t&&this.ensureGroupExists(e,t);let r=this._messages.get(),i=r.findIndex(e=>e.a2uiEnvelopes?.some(e=>e.surfaceId===n.surfaceId));if(i!==-1){let t=r[i],a=[...t.a2uiEnvelopes||[],n],o={...t,a2uiEnvelopes:a},s=[...r];s[i]=o,this._messages.set(s),await z(e,o)}else{let i=!t.startsWith(`peer:`),a={id:c(),groupId:t,sender:i?`agent`:t.replace(/^peer:/,``),content:``,timestamp:Date.now(),channel:t.startsWith(`peer:`)?`peerjs`:`browser`,isFromMe:i,isTrigger:!1,a2uiEnvelopes:[n]};t===this._activeGroupId.get()&&this._messages.set([...r,a]),await z(e,a)}}),t.events.on(`message`,t=>{if(t.groupId&&this.ensureGroupExists(e,t.groupId,t.timestamp),t.groupId&&t.groupId!==this._activeGroupId.get()){let e=new Set(this._unreadGroupIds.get());e.add(t.groupId),this._unreadGroupIds.set(e)}else t.isFromMe&&this._streamingText.get()!==null&&this._streamingText.set(null),this._messages.set([...this._messages.get(),t])}),t.events.on(`typing`,({groupId:e,typing:t})=>{e&&e!==this._activeGroupId.get()||this._isTyping.set(t)}),t.events.on(`tool-activity`,({groupId:e,tool:t,status:n})=>{e&&e!==this._activeGroupId.get()||this._toolActivity.set(n===`running`?{tool:t,status:n}:null)}),t.events.on(`model-download-progress`,e=>{this._modelDownloadProgress.set(e.status===`done`?null:e)}),t.events.on(`thinking-log`,e=>{e.groupId&&e.groupId!==this._activeGroupId.get()||(e.level===`info`&&e.label===`Starting`?this._activityLog.set([e]):this._activityLog.set([...this._activityLog.get(),e]),this.forwardActivityLogEntryToServer(e))}),t.events.on(`state-change`,e=>{let t=typeof e==`string`?e:e.state,n=typeof e==`string`?void 0:e.groupId;if(n&&n!==this._activeGroupId.get())return;let r=this._lastOrchestratorDisplayState;this._lastOrchestratorDisplayState=t,this._state.set(t),t===`idle`&&(this._toolActivity.set(null),this._modelDownloadProgress.set(null),this._streamingText.set(null)),t===`thinking`&&r!==`thinking`&&r!==`responding`&&(this._tokenUsageAccumulator=null)}),t.events.on(`error`,({error:e})=>{console.error(`[Orchestrator Error Event]`,e),this._error.set(e),this._state.set(`error`)}),t.events.on(`session-reset`,()=>{this._messages.set([]),this._activityLog.set([]),this._tokenUsageAccumulator=null,this._tokenUsage.set(null),this._contextUsage.set(null),this._toolActivity.set(null),this._modelDownloadProgress.set(null),this._streamingText.set(null),this._isTyping.set(!1),this._state.set(`idle`)}),t.events.on(`context-compacted`,e=>{e?.groupId&&e.groupId!==this._activeGroupId.get()||(this._tokenUsage.set(null),this.loadHistory())}),t.events.on(`token-usage`,e=>{if(!e||e.groupId&&e.groupId!==this._activeGroupId.get())return;let t=wt(this._tokenUsageAccumulator,e);this._tokenUsageAccumulator=t,this._tokenUsage.set(t),this.orchestrator?.refreshContextUsage&&this._db&&this.orchestrator.refreshContextUsage(this._db,this._activeGroupId.get())}),t.events.on(`context-usage`,e=>{this._contextUsage.set(e)}),t.events.on(`ready`,()=>{this._ready.set(!0)}),t.events.on(`task-change`,()=>{this.loadTasks(e)}),t.events.on(`file-change`,()=>{this.loadFiles(e)}),t.events.on(`streaming-start`,({groupId:e})=>{e===this._activeGroupId.get()&&this._streamingText.set(``)}),t.events.on(`streaming-chunk`,({groupId:e,text:t})=>{if(e!==this._activeGroupId.get())return;let n=this._streamingText.get();this._streamingText.set((n||``)+t)}),t.events.on(`streaming-end`,({groupId:e})=>{e===this._activeGroupId.get()&&this._streamingText.set(null)}),t.events.on(`streaming-done`,({groupId:e})=>{this._activeGroupId.get()}),t.events.on(`streaming-error`,({groupId:e})=>{this._activeGroupId.get()}),this._aguiAdapter=new lt(t.events),this._aguiAdapter.start(),typeof window<`u`&&window.addEventListener(`shadow-claw-agui-event`,(e=>{e.detail.groupId===this._activeGroupId.get()&&this._aguiEvent.set(e.detail);let t=e.detail.event;if(t){if(t.type===`STATE_SNAPSHOT`){let n=new Map(this._peerStateByGroup.get());n.set(e.detail.groupId,t.snapshot||{}),this._peerStateByGroup.set(n)}else if(t.type===`STATE_DELTA`){let n=new Map(this._peerStateByGroup.get()),r=pt(n.get(e.detail.groupId)||{},t.delta||[]);n.set(e.detail.groupId,r),this._peerStateByGroup.set(n)}}})),await d(e),ee(),h(),await L();let n=await w(e,b.PAGES_ALLOW_LIST),r=await w(e,b.PAGES_DENY_LIST);n&&this._pagesAllowList.set(yt(String(n))),r&&this._pagesDenyList.set(yt(String(r))),await L();let o=typeof document<`u`&&document.getElementById(`shadow-claw-static-routing`)!==null,s=await w(e,b.PAGES_LIST),l=s==null?[]:this.parsePagesList(s),u=await ct(e,y,l);u.length>0?(this.setPages(u),await this.persistPages(e)):await this.ensureDefaultPage(e),await L(),await this.applySiteConfigDefaults(e),await L(),await this.loadGroups(e);let f=await w(e,b.LAST_ACTIVE_GROUP);f&&f!==this._activeGroupId.get()&&this._activeGroupId.set(f),await L();let p=await w(e,b.LAST_ACTIVE_PAGE);p&&(this._activePage.set(p),this._hadPersistedActivePage=!0);let m=await w(e,b.SIDEBAR_DEFAULT_PAGE);this._sidebarDefaultPage.set(this.normalizeSidebarDefaultPage(m));let g=at(),_=null;if(g&&(_=i(g)),!_){let t=await w(e,b.DEFAULT_PINNED_PAGE);t&&(_=i(t))}_&&this.isPageAllowed(_.path,_.groupId)&&this._defaultPinnedPage.set(_),await L();let v=typeof window<`u`&&window.history?window.history.state:null,te=!!(v?.inFeedScroll||v?.scrollSpy||v?.suppressRouter)||typeof window<`u`&&window.location&&(()=>{let e=window.location.pathname||`/`,t=a();t!==`/`&&e.startsWith(t)&&(e=`/`+e.slice(t.length));let n=e.split(`/`).filter(Boolean);return n.length===0||n.length===1&&n[0]===`index.html`})(),x=!1;if(te&&_&&this.isPageAllowed(_.path,_.groupId)&&(this._activePinnedPage.set(_),x=!0),!x){let t=await w(e,b.LAST_SELECTED_PINNED_PAGE);if(t)try{let e=JSON.parse(t);e&&typeof e.path==`string`&&typeof e.groupId==`string`&&this.isPageAllowed(e.path,e.groupId)&&(this._activePinnedPage.set(e),x=!0)}catch{}}!x&&te&&this.effectiveDefaultPage&&this.isPageAllowed(this.effectiveDefaultPage.path,this.effectiveDefaultPage.groupId)&&(this._activePinnedPage.set(this.effectiveDefaultPage),x=!0),this.orchestrator&&(this._useProxy.set(this.orchestrator.useProxy),this._proxyUrl.set(this.orchestrator.proxyUrl),this._gitProxyUrl.set(this.orchestrator.gitProxyUrl),this._vmBashFullInternetAccess.set(this.orchestrator.vmBashFullInternetAccess));let[S,C,T]=await Promise.all([w(e,b.SIDEBAR_CHAT_HIDDEN),w(e,b.SIDEBAR_TASKS_HIDDEN),w(e,b.SIDEBAR_FILES_HIDDEN)]),E=re(),D=E?.sidebar?.chatHidden,O=E?.sidebar?.tasksHidden,k=E?.sidebar?.filesHidden,A=S==null?!!D:vt(S),j=C==null?!!O:vt(C),ne=T==null?!!k:vt(T),M=()=>{let t=[];(!A||this.activePage===`chat`)&&t.push(this.loadHistory()),(!j||this.activePage===`tasks`)&&t.push(this.loadTasks(e)),(!ne||this.activePage===`files`)&&t.push(this.loadFiles(e)),Promise.all(t).catch(e=>{console.warn(`Secondary background store loads failed:`,e)})};if(o)typeof window.requestIdleCallback==`function`?window.requestIdleCallback(M,{timeout:2e3}):setTimeout(M,100);else{let t=[];(!A||this.activePage===`chat`)&&t.push(this.loadHistory()),(!j||this.activePage===`tasks`)&&t.push(this.loadTasks(e)),(!ne||this.activePage===`files`)&&t.push(this.loadFiles(e)),await Promise.all(t)}await L(),this._initResolve?.(),this.scheduleBackgroundStaticMainSiteSeeding(e)}async loadFiles(e){let t=this._activeGroupId.get(),n=this._currentPath.get();try{this._storageStatus.set(await u(e));let r=await G(e,t,n);this._files.set(r)}catch(e){console.error(`Failed to load files in store:`,e)}}async loadGroups(e){let t=await I(e);this._groups.set(t)}async loadHistory(){let e=this._activeGroupId.get(),t=await ie(e,200);this._activeGroupId.get()===e&&this._messages.set(t)}async loadTasks(e){let t=this._activeGroupId.get(),n=await A(e),r=n.filter(e=>e.groupId===t);r.sort((e,t)=>{let n=e.order??0,r=t.order??0;return n===r?e.createdAt-t.createdAt:n-r}),this._tasks.set(r);let i=await this.getSubscriberId(e),a=await Ct(t,this.getTaskServerBaseUrl(),i,this.orchestrator?.taskServerEnabled??!1);if(!a)return;let o=new Set(n.map(e=>e.id)),s=a.filter(e=>!o.has(e.id));if(s.length===0)return;for(let t of s)await B(e,t);let c=[...r,...s];c.sort((e,t)=>{let n=e.order??0,r=t.order??0;return n===r?e.createdAt-t.createdAt:n-r}),this._tasks.set(c)}async navigateBackFolder(e){let t=this._currentPath.get();if(t===`.`)return;let n=t.split(`/`).filter(Boolean);n.pop();let r=n.length===0?`.`:n.join(`/`);await this.setCurrentPath(e,r)}async navigateIntoFolder(e,t){let n=this._currentPath.get(),r=n===`.`?t.replace(/\/$/,``):`${n}/${t.replace(/\/$/,``)}`;try{await this.setCurrentPath(e,r)}catch(t){console.error(`Failed to navigate into folder in store:`,t),Z(`Folder not found: ${r}`,4500),await this.loadFiles(e)}}async newSession(e){await this.orchestrator?.newSession?.(e,this._activeGroupId.get()),await this.loadHistory()}async removePage(t,n,r=this._activeGroupId.get()){let i=this.normalizePagePath(n);if(!i)return;let a=this._pages.get();if(!a.some(e=>e.path===i&&e.groupId===r))return;let o=a.filter(e=>e.path!==i||e.groupId!==r);await Ke(t,r,i);let s=r===`br:main`&&i===`MEMORY.md`;s&&await U(t,!0);let c=s||await H(t);if(o.length===0&&!c){if(await W(t,`br:main`))o.push({groupId:y,path:e.DEFAULT_PAGE_PATH});else return}this.setPages(o);let l=this._defaultPinnedPage.get();l&&l.path===i&&l.groupId===r&&await this.setDefaultPinnedPage(t,null),await this.persistPages(t)}async removeAllPages(e){let t=[...this._pages.get()];for(let n of t)await Ke(e,n.groupId,n.path),n.groupId===`br:main`&&n.path===`MEMORY.md`&&await U(e,!0);this.setPages([]),await this.setDefaultPinnedPage(e,null),await this.setActivePinnedPage(e,null),await this.persistPages(e)}async renameConversation(e,t,n){await ce(e,t,n),await this.loadGroups(e)}async reorderConversations(e,t){await de(e,t),await this.loadGroups(e)}async reorderTasks(e,t,n){let r=await je(e,t,n);await this.loadTasks(e);let i=await this.getSubscriberId(e);for(let t of r)await Q(t,this.getTaskServerBaseUrl(),i,this.orchestrator?.taskServerEnabled??!1)||(console.warn(`Failed to sync reordered task "${t.id}" to server — queued for replay.`),await this.queueTaskSyncOutboxOperation(e,{type:`upsert`,id:t.id,task:t,queuedAt:Date.now()}))}async replayTaskSyncOutbox(e){if(!(this._replayingTaskSyncOutbox||this._taskSyncOutbox.length===0)){this._replayingTaskSyncOutbox=!0;try{let t=await this.getSubscriberId(e),n=[];for(let e of this._taskSyncOutbox){let r=this.getTaskServerBaseUrl();(e.type===`upsert`?await Q(e.task,r,t,this.orchestrator?.taskServerEnabled??!1):await $(e.id,r,t,this.orchestrator?.taskServerEnabled??!1))||n.push(e)}this._taskSyncOutbox=this.compactTaskSyncOutbox(n),await this.persistTaskSyncOutbox(e)}finally{this._replayingTaskSyncOutbox=!1}}}async resetToRootFolder(e){await this.setCurrentPath(e,`.`)}async restartCurrentRequest(){return this.orchestrator?.restartCurrentRequest?this.orchestrator.restartCurrentRequest(this._activeGroupId.get()):!1}async restoreTasksFromBackup(e,t){await this.clearAllTasks(e);let n=this._activeGroupId.get();for(let r of t){let t={...r,groupId:n,id:crypto.randomUUID?crypto.randomUUID():`task-${Date.now()}-${Math.random()}`};await this.upsertTask(e,t,{reloadTasks:!1})}await this.loadTasks(e)}async runTask(e,t=!1){let n=this._db;if(t&&n&&(await Ae(e.id,Date.now()),await this.loadTasks(n)),e.type===`tools`&&Array.isArray(e.tools)&&e.tools.length>0){if(this.orchestrator?.agentWorker){let n=e.subagent?`subagent:${c()}`:e.groupId;this.orchestrator.agentWorker.postMessage({type:`execute-task-tools`,payload:{groupId:n,tools:e.tools,isManual:t}})}else console.error(`Agent worker not available to execute tool task.`)}else{if(!e.groupId){console.error(`Task ${e.id} has no groupId - refusing to execute in active conversation to prevent context pollution.`);return}this.orchestrator?.browserChat?.submit(e.prompt,e.groupId,[],void 0,e.freshContext,e.subagent)}}async setActivePage(e,t){this._activePage.set(t),await O(e,b.LAST_ACTIVE_PAGE,t);let n=this.resolveSidebarDefaultPageForActivePage(t);n!==this._sidebarDefaultPage.get()&&(this._sidebarDefaultPage.set(n),await O(e,b.SIDEBAR_DEFAULT_PAGE,n))}async setActivePinnedPage(e,t){t&&!this.isPageAllowed(t.path,t.groupId)&&(t=this.effectiveDefaultPage),this._activePinnedPage.set(t),t?await O(e,b.LAST_SELECTED_PINNED_PAGE,JSON.stringify(t)):await O(e,b.LAST_SELECTED_PINNED_PAGE,null)}async setDefaultPinnedPage(e,t){if(t&&!this.isPageAllowed(t.path,t.groupId))return;let n=this._defaultPinnedPage.get(),r=n&&t&&n.path===t.path&&n.groupId===t.groupId?null:t;this._defaultPinnedPage.set(r),r?await O(e,b.DEFAULT_PINNED_PAGE,JSON.stringify(r)):await O(e,b.DEFAULT_PINNED_PAGE,null)}async reorderPages(e,t){this.setPages(t),await this.persistPages(e)}async setCurrentPath(e,t){let n=t.replace(/^\/+|\/+$/g,``)||`.`,r=this._activeGroupId.get();this._storageStatus.set(await u(e));let i=await G(e,r,n);this._currentPath.set(n),this._files.set(i)}async setGitProxyUrl(e,t){this.orchestrator&&(await xe(this.orchestrator,e,t),this._gitProxyUrl.set(this.orchestrator.gitProxyUrl))}async setProxyUrl(e,t){this.orchestrator&&(await Se(this.orchestrator,e,t),this._proxyUrl.set(this.orchestrator.proxyUrl))}async setUseProxy(e,t){this.orchestrator&&(await Ce(this.orchestrator,e,t),this._useProxy.set(this.orchestrator.useProxy))}async setVMBashFullInternetAccess(e,t){this.orchestrator&&(await we(this.orchestrator,e,t),this._vmBashFullInternetAccess.set(this.orchestrator.vmBashFullInternetAccess))}async switchConversation(e,t,n){this.setActiveGroup(e,t,n??this._activePage.get()===`chat`),await O(e,b.LAST_ACTIVE_GROUP,t)}async toggleTask(e,t,n){let r={...t,enabled:n};await B(e,r),await this.loadTasks(e),await Q(r,this.getTaskServerBaseUrl(),await this.getSubscriberId(e),this.orchestrator?.taskServerEnabled??!1)||(console.warn(`Failed to update task on server — queued for replay.`),await this.queueTaskSyncOutboxOperation(e,{type:`upsert`,id:r.id,task:r,queuedAt:Date.now()}))}async updateConversationPinnedProvider(e,t,n,r,i){await pe(e,t,n,r,i),await this.loadGroups(e)}async updateConversationProviderRuntimeOverrides(e,t,n){await he(e,t,n),await this.loadGroups(e)}async updateConversationSubagentSettings(e,t,n,r,i,a){await me(e,t,n,r,i,a),await this.loadGroups(e)}async updateConversationToolTags(e,t,n){await le(e,t,n),await this.loadGroups(e)}async upsertTask(e,t,n){let r=n?.reloadTasks!==!1;await B(e,t),r&&await this.loadTasks(e);let i=await this.getSubscriberId(e);await Q(t,this.getTaskServerBaseUrl(),i,this.orchestrator?.taskServerEnabled??!1)||(console.warn(`Failed to sync task to server — queued for replay.`),await this.queueTaskSyncOutboxOperation(e,{type:`upsert`,id:t.id,task:t,queuedAt:Date.now()}))}compactTaskSyncOutbox(e){let t=/* @__PURE__ */ new Map;return e.forEach((e,n)=>{t.set(e.id,n)}),e.filter((e,n)=>t.get(e.id)===n)}deriveGroupName(e){return e.startsWith(`tg:`)?`Telegram ${e.slice(3)}`:e.startsWith(`im:`)?`iMessage ${e.slice(3)}`:e.startsWith(`br:`)?e===`br:main`?`Main`:`Browser Conversation`:`Conversation`}getActivityLogSessionStartedAt(e){let t=this._activityLogSessionStartedAtByGroup.get(e);if(t)return t;let n=(/* @__PURE__ */ new Date()).toISOString();return this._activityLogSessionStartedAtByGroup.set(e,n),n}getTaskServerBaseUrl(){return this.orchestrator?.taskServerUrl??`/schedule`}async getSubscriberId(e){if(this._subscriberId)return this._subscriberId;let t=await ke(e);return this._subscriberId=t,t}normalizePagePath(t){let n=t.trim().replace(/^\/+/,``).replace(/\/+/g,`/`);return n===`main/memory.md`?e.DEFAULT_PAGE_PATH:n}normalizeSidebarDefaultPage(e){return e===`pages`||e===`chat`||e===`tasks`||e===`files`?e:`chat`}parsePagesList(e){if(!e)return[];try{let t=JSON.parse(e);return Array.isArray(t)?t.map(e=>{if(typeof e==`string`)return{groupId:y,path:this.normalizePagePath(e)};if(!e||typeof e!=`object`)return null;let t=e;if(typeof t.path!=`string`)return null;let n=typeof t.groupId==`string`&&t.groupId.trim().length>0?t.groupId:y,r=n===`br:main`?this.normalizePagePath(t.path):t.path.trim();return r?{groupId:n,path:r}:null}).filter(e=>!!e).filter((e,t,n)=>{let r=`${e.groupId}\u0000${e.path}`;return t===n.findIndex(e=>`${e.groupId}\u0000${e.path}`===r)}):[]}catch{return[]}}parseTaskSyncOutbox(e){if(!e)return[];try{let t=JSON.parse(e);if(!Array.isArray(t))return[];let n=t.filter(e=>!!e&&typeof e==`object`).filter(e=>e.type===`upsert`||e.type===`delete`).filter(e=>typeof e.id==`string`&&e.id.length>0).map(e=>({...e,queuedAt:typeof e.queuedAt==`number`?e.queuedAt:Date.now()}));return this.compactTaskSyncOutbox(n)}catch{return[]}}resolveSidebarDefaultPageForActivePage(e){return e===`pages`||e===`chat`||e===`tasks`||e===`files`?e:this._sidebarDefaultPage.get()}setPages(e){let t=e.filter(e=>this.isPageAllowed(e.path,e.groupId)),n=t.filter(e=>e.path.toLowerCase()===`memory.md`),r=t.filter(e=>e.path.toLowerCase()!==`memory.md`);this._pages.set([...r,...n])}async ensureDefaultPage(t){if(await H(t))return;let n=await W(t,y);await Le(t,y),!(!n||this._pages.get().length>0)&&(this.setPages([{groupId:y,path:e.DEFAULT_PAGE_PATH}]),await this.persistPages(t))}async ensureGroupExists(e,t,n){let r=this._groups.get();if(r.some(e=>e.groupId===t))return;let i=[...r,{groupId:t,name:this.deriveGroupName(t),createdAt:n||Date.now()}];this._groups.set(i);try{await F(e,i)}catch(e){console.error(`Failed to persist new conversation metadata:`,e)}}async forwardActivityLogEntryToServer(e){if(!this._db||!xt(await w(this._db,b.ACTIVITY_LOG_DISK_LOGGING_ENABLED)))return;let t=typeof e.groupId==`string`&&e.groupId?e.groupId:this._activeGroupId.get();if(!t)return;let n=typeof e.message==`string`?e.message.trim():``;if(!n)return;e.level===`info`&&e.label===`Starting`&&this._activityLogSessionStartedAtByGroup.set(t,(/* @__PURE__ */ new Date()).toISOString());let r=this.getActivityLogSessionStartedAt(t);try{await fetch(`/activity-log`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({groupId:t,level:e.level,label:e.label,message:n,timestamp:(/* @__PURE__ */ new Date()).toISOString(),sessionStartedAt:r})})}catch(e){console.warn(`Failed to persist activity log entry to server:`,e)}}scheduleBackgroundStaticMainSiteSeeding(e){if(typeof window>`u`)return;let t=async()=>{try{if(await Ye(e,`br:main`))return;let t=await w(e,b.PAGES_LIST),n=t==null?[]:this.parsePagesList(t),r=await ct(e,y,n,{preferEmbedded:!1});r&&r.length>0&&(this.setPages(r),await this.persistPages(e))}catch(e){console.warn(`Background static main site seeding failed:`,e)}};typeof window.requestIdleCallback==`function`?window.requestIdleCallback(()=>void t(),{timeout:3e3}):setTimeout(()=>void t(),100)}async persistPages(e){await O(e,b.PAGES_LIST,JSON.stringify(this._pages.get()))}async persistTaskSyncOutbox(e){await O(e,b.TASK_SYNC_OUTBOX,JSON.stringify(this._taskSyncOutbox))}async queueTaskSyncOutboxOperation(e,t){this._taskSyncOutbox=this.compactTaskSyncOutbox([...this._taskSyncOutbox,t]),await this.persistTaskSyncOutbox(e)}async applySiteConfigDefaults(e){if(typeof document<`u`)try{let n=re();if(!n||typeof n!=`object`)return;_(n),ee(),h();let r=n.customElements;if((await I(e)).find(e=>e.groupId===`br:main`)?.toolTags&&await le(e,y,void 0),(n.settings?.internetAccess??n.settings?.vm_bash_full_internet_access??n.settings?.fullInternetAccess??n.internetAccess)===!0&&await w(e,b.VM_BASH_FULL_INTERNET_ACCESS)!==`true`&&(await O(e,b.VM_BASH_FULL_INTERNET_ACCESS,`true`),this.orchestrator&&(this.orchestrator.vmBashFullInternetAccess=!0),this._vmBashFullInternetAccess.set(!0)),n.pages&&typeof n.pages==`object`){let{defaultPinnedPage:t}=n.pages;if(t&&typeof t==`string`){let n=i(t);n&&this.isPageAllowed(n.path,n.groupId)&&(this._defaultPinnedPage.set(n),await O(e,b.DEFAULT_PINNED_PAGE,JSON.stringify(n)))}}let a=n.allowedCustomElements||(typeof r==`object`&&!Array.isArray(r)?r.allowedElements:void 0);a!==void 0&&(await w(e,b.ALLOWED_CUSTOM_ELEMENTS)??await O(e,b.ALLOWED_CUSTOM_ELEMENTS,JSON.stringify(a)));let o=n.allowedCustomElementDomains||(typeof r==`object`&&!Array.isArray(r)?r.allowedDomains:void 0);if(o!==void 0&&(await w(e,b.ALLOWED_CUSTOM_ELEMENT_HOST_PATTERNS)??await O(e,b.ALLOWED_CUSTOM_ELEMENT_HOST_PATTERNS,JSON.stringify(o))),n.sidebar&&typeof n.sidebar==`object`){let{pagesHidden:t,chatHidden:r,tasksHidden:i,filesHidden:a,defaultPage:o}=n.sidebar;if(t!==void 0&&(await w(e,b.SIDEBAR_PAGES_HIDDEN)??await O(e,b.SIDEBAR_PAGES_HIDDEN,String(!!t))),r!==void 0&&(await w(e,b.SIDEBAR_CHAT_HIDDEN)??await O(e,b.SIDEBAR_CHAT_HIDDEN,String(!!r))),i!==void 0&&(await w(e,b.SIDEBAR_TASKS_HIDDEN)??await O(e,b.SIDEBAR_TASKS_HIDDEN,String(!!i))),a!==void 0&&(await w(e,b.SIDEBAR_FILES_HIDDEN)??await O(e,b.SIDEBAR_FILES_HIDDEN,String(!!a))),o&&typeof o==`string`){let t=this.normalizeSidebarDefaultPage(o);this._sidebarDefaultPage.set(t),await w(e,b.SIDEBAR_DEFAULT_PAGE)||await O(e,b.SIDEBAR_DEFAULT_PAGE,o)}}if(n.settings&&typeof n.settings==`object`){let{assistantName:t,defaultProvider:r,provider:i,defaultModel:a,model:o}=n.settings;t&&typeof t==`string`&&(await w(e,b.ASSISTANT_NAME)||await O(e,b.ASSISTANT_NAME,t));let s=r??i;if(typeof s==`string`&&s.trim().length>0&&!await w(e,b.PROVIDER)){let t=s.trim();await O(e,b.PROVIDER,t),this.orchestrator&&(this.orchestrator.provider=t)}let c=a??o;if(typeof c==`string`&&c.trim().length>0&&!await w(e,b.MODEL)){let t=c.trim();await O(e,b.MODEL,t),this.orchestrator&&(this.orchestrator.model=t)}let l=n.settings.internetAccess??n.settings.vm_bash_full_internet_access??n.settings.fullInternetAccess??n.internetAccess;typeof l==`boolean`&&(await w(e,b.VM_BASH_FULL_INTERNET_ACCESS)??(await O(e,b.VM_BASH_FULL_INTERNET_ACCESS,String(l)),this.orchestrator&&(this.orchestrator.vmBashFullInternetAccess=l),this._vmBashFullInternetAccess.set(l)))}let s=(n.settings&&typeof n.settings==`object`?n.settings.defaultToolsProfile:void 0)??n.defaultToolsProfile;if(typeof s==`string`&&s.trim().length>0&&!await w(e,b.ACTIVE_TOOL_PROFILE)){let t=s.trim();if(t.toLowerCase()===`none`)await j.deactivateProfile(e);else{let n=j.profiles.find(e=>e.id.toLowerCase()===t.toLowerCase()||e.name.toLowerCase()===t.toLowerCase());n?await j.activateProfile(e,n.id):console.warn(`Default tools profile "${t}" specified in site-config was not found.`)}}if(n.pages&&typeof n.pages==`object`){let{defaultPinnedPage:t}=n.pages;t&&typeof t==`string`&&(await w(e,b.DEFAULT_PINNED_PAGE)||await O(e,b.DEFAULT_PINNED_PAGE,t))}let c=n.pages?.allowList??n.pages?.allowlist??n.allowList??n.allowlist,l=n.pages?.denyList??n.pages?.denylist??n.denyList??n.denylist;if(Array.isArray(c)&&await w(e,b.PAGES_ALLOW_LIST)==null){let n=t(c.map(String));this._pagesAllowList.set(n),await O(e,b.PAGES_ALLOW_LIST,JSON.stringify(n))}if(Array.isArray(l)&&await w(e,b.PAGES_DENY_LIST)==null){let n=t(l.map(String));this._pagesDenyList.set(n),await O(e,b.PAGES_DENY_LIST,JSON.stringify(n))}await O(e,b.SITE_CONFIG_SEEDED,`true`);let u=this._pages.get(),d=u.filter(e=>this.isPageAllowed(e.path,e.groupId));d.length!==u.length&&(this.setPages(d),await this.persistPages(e));let f=this._activePinnedPage.get();f&&!this.isPageAllowed(f.path,f.groupId)&&await this.setActivePinnedPage(e,this.effectiveDefaultPage);let p=this._defaultPinnedPage.get();if(p&&!this.isPageAllowed(p.path,p.groupId)&&await this.setDefaultPinnedPage(e,null),Array.isArray(n.enabledTools)){let t=n.enabledTools.filter(e=>typeof e==`string`&&e.trim().length>0);await j.setAllEnabled(e,t),await j.setAllDeclarativeEnabled(e,t)}await O(e,b.SITE_CONFIG_SEEDED,`true`)}catch(e){console.warn(`Failed to apply site-config defaults:`,e)}}};const Et=new Tt;export{I as _,dt as a,G as c,B as d,z as f,_e as g,ge as h,_t as i,U as l,R as m,wt as n,Ke as o,ke as p,Et as r,q as s,Tt as t,Ie as u,ie as v};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export{t as getAgentCore}from"./chunk-Bc_weULz.js";
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import{i as e,n as t,r as n,t as r}from"./chunk-4-QO2z6r.js";import{i,n as a,r as o,t as s}from"./chunk-DnR17T-6.js";import{t as c}from"./chunk-BChOKoxf.js";import{c as l,f as u,i as d,l as f,m as p,n as m,o as h,p as g,r as _,s as ee,t as v,u as te}from"./chunk-DKAtC-O0.js";import{o as y,r as b}from"./chunk-DZyBXNgc.js";import{t as x}from"./chunk-Dl4zTOqg.js";import{t as S}from"./chunk-DjKQO7aV.js";import{n as C,t as w}from"./chunk-IVWoxOkm.js";import{c as T,l as E,s as D,u as O}from"./chunk-CsZlU6GT.js";import{i as k,r as A,t as j}from"./chunk-ByA6Dh5i.js";import{t as ne}from"./chunk-BhCmCUGL.js";function M(e){if(!e)return``;let t=e.match(/^\r?\n([ \t]+)/);if(t){let n=t[1],r=RegExp(`^[ \\t]{1,${n.length}}`,`gm`);return e.replace(/^\r?\n/,``).replace(r,``).replace(/\r?\n[ \t]*$/,`
|
|
2
|
-
`)}if(/^(?:\r?\n)+[ \t]*---/.test(e))return e.replace(/^(?:\r?\n)+/,``);if(/^[ \t]+---/.test(e)){let t=e.match(/^[ \t]+/);if(t){let n=t[0],r=RegExp(`^[ \\t]{1,${n.length}}`,`gm`);return e.replace(r,``)}}return e}let N=/* @__PURE__ */ new Map;function re(e){if(typeof document>`u`)return null;let t=`shadow-claw-site-config`;if(e){let n=e.getAttribute(`config`)?.trim();n&&(t=n.replace(/^#/,``))}let n=document.getElementById(t);if(!n?.textContent)return N.delete(t),null;let r=N.get(t);if(r&&r.rawText===n.textContent)return r.config;try{let e=JSON.parse(n.textContent);if(!e||typeof e!=`object`)return N.delete(t),null;let r={...e};return N.set(t,{rawText:n.textContent,config:r}),r}catch(e){return console.warn(`[ShadowClaw] Failed to parse site configuration from #${t}:`,e),null}}function ie(e,t,n){let r=null,i,a;return typeof e==`string`?(i=e,a=t):(r=e,i=t,a=n??50),r&&S(r)?Promise.resolve().then(()=>(r.db.prepare(`SELECT * FROM messages WHERE groupId = ? ORDER BY timestamp DESC LIMIT ?`).all(i,a)??[]).reverse().map(ae)):new Promise(async(e,t)=>{try{let n=r??await x();if(!n)return t(/* @__PURE__ */ Error(`failed to get transaction, cannot get recent messages.`));let o=n.transaction(`messages`,`readonly`);if(!o)return t(/* @__PURE__ */ Error(`failed to get transaction`));let s=o.objectStore(`messages`).index(`by-group-time`),c=IDBKeyRange.bound([i,0],[i,1/0]),l=s.openCursor(c,`prev`),u=[];l.onsuccess=()=>{let t=l.result;t&&u.length<a?(u.push(t.value),t.continue()):e(u.reverse())},l.onerror=()=>t(l.error)}catch(e){t(e)}})}function ae(e){return{...e,isFromMe:!!e.isFromMe,isTrigger:!!e.isTrigger,attachments:e.attachments?JSON.parse(e.attachments):void 0,a2uiAction:e.a2uiAction?JSON.parse(e.a2uiAction):void 0,a2uiEnvelopes:e.a2uiEnvelopes?JSON.parse(e.a2uiEnvelopes):void 0}}const oe=`group_metadata`;async function P(e){let t=await w(e,oe);if(!t)return[];try{return JSON.parse(t)}catch{return[]}}async function F(e,t){await O(e,oe,JSON.stringify(t))}async function se(e,t,n=`br:`,r){let i=await P(e),a={groupId:`${n}${r??c()}`,name:t,createdAt:Date.now()};return i.push(a),await F(e,i),a}async function ce(e,t,n){let r=await P(e),i=r.find(e=>e.groupId===t);i&&(i.name=n),await F(e,r)}async function le(e,t,n){let r=await P(e),i=r.find(e=>e.groupId===t);i&&(n&&n.length>0?i.toolTags=n:delete i.toolTags),await F(e,r)}async function ue(e,t){await F(e,(await P(e)).filter(e=>e.groupId!==t))}async function I(e){let t=await P(e);if(t.length===0){let t={groupId:y,name:`Main`,createdAt:0};return await F(e,[t]),[t]}return t}async function de(e,t){let n=await P(e),r=new Map(n.map(e=>[e.groupId,e])),i=[];for(let e of t){let t=r.get(e);t&&(i.push(t),r.delete(e))}for(let e of n)r.has(e.groupId)&&i.push(e);await F(e,i)}async function fe(e,t){let n=await P(e),r=n.find(e=>e.groupId===t);if(!r)return null;let i=t.indexOf(`:`),a={groupId:`${i>=0?t.slice(0,i+1):`br:`}${c()}`,name:`${r.name} (copy)`,createdAt:Date.now(),pinnedMaxTokens:r.pinnedMaxTokens,providerRuntimeOverrides:r.providerRuntimeOverrides?JSON.parse(JSON.stringify(r.providerRuntimeOverrides)):void 0,subagentModelSelectionMode:r.subagentModelSelectionMode,subagentMaxTokens:r.subagentMaxTokens,subagentPinnedProvider:r.subagentPinnedProvider,subagentPinnedModel:r.subagentPinnedModel,subagentFastProvider:r.subagentFastProvider,subagentFastModel:r.subagentFastModel,subagentSmartProvider:r.subagentSmartProvider,subagentSmartModel:r.subagentSmartModel,subagentPowerfulProvider:r.subagentPowerfulProvider,subagentPowerfulModel:r.subagentPowerfulModel,toolTags:r.toolTags?[...r.toolTags]:void 0};return n.push(a),await F(e,n),a}async function pe(e,t,n,r,i){let a=await P(e),o=a.find(e=>e.groupId===t);o&&(n?o.pinnedProvider=n:delete o.pinnedProvider,r?o.pinnedModel=r:delete o.pinnedModel,typeof i==`number`&&Number.isFinite(i)&&i>0?o.pinnedMaxTokens=Math.floor(i):delete o.pinnedMaxTokens),await F(e,a)}async function me(e,t,n,r,i,a){let o=await P(e),s=o.find(e=>e.groupId===t);s&&(s.subagentModelSelectionMode=n,n===`manual`?(r?s.subagentPinnedProvider=r:delete s.subagentPinnedProvider,i?s.subagentPinnedModel=i:delete s.subagentPinnedModel):(delete s.subagentPinnedProvider,delete s.subagentPinnedModel),typeof a==`number`&&Number.isFinite(a)&&a>0?s.subagentMaxTokens=Math.floor(a):delete s.subagentMaxTokens),await F(e,o)}async function he(e,t,n){let r=await P(e),i=r.find(e=>e.groupId===t);i&&(n&&Object.keys(n).length>0?i.providerRuntimeOverrides=JSON.parse(JSON.stringify(n)):delete i.providerRuntimeOverrides),await F(e,r)}function ge(e,t,n,r){let i=t*2**e,a=Math.min(i,n),o=a*r*Math.random();return Math.max(0,a-o)}function _e(e,t){return new Promise((n,r)=>{if(t?.aborted){r(t.reason??new DOMException(`Aborted`,`AbortError`));return}let i=setTimeout(n,e);if(t){let e=()=>{clearTimeout(i),r(t.reason??new DOMException(`Aborted`,`AbortError`))};t.addEventListener(`abort`,e,{once:!0});let a=n;n=(n=>{t.removeEventListener(`abort`,e),a(n)})}})}async function L(){let e=typeof globalThis<`u`?globalThis:void 0;e?.scheduler&&typeof e.scheduler.yield==`function`?await e.scheduler.yield():await new Promise(e=>setTimeout(e,0))}function ve(e,t=y){e.agentWorker?.postMessage({payload:{groupId:t},type:`vm-workspace-sync`})}function ye(e,t=y){e.agentWorker?.postMessage({payload:{groupId:t},type:`vm-workspace-flush`})}function be(e){`serviceWorker`in navigator&&navigator.serviceWorker?.controller&&navigator.serviceWorker.controller.postMessage({type:`set-proxy-config`,payload:{useProxy:e.useProxy,proxyUrl:e.proxyUrl}})}async function xe(e,t,n,r=O){e.gitProxyUrl=n||`/git-proxy`,await r(t,b.GIT_PROXY_URL,e.gitProxyUrl)}async function Se(e,t,n,r=O){e.proxyUrl=n||`/proxy`,await r(t,b.PROXY_URL,e.proxyUrl),be(e)}async function Ce(e,t,n,r=O){e.useProxy=!!n,await r(t,b.USE_PROXY,e.useProxy?`true`:`false`),be(e)}async function we(e,t,n,r=O){e.vmBashFullInternetAccess=!!n,await r(t,b.VM_BASH_FULL_INTERNET_ACCESS,e.vmBashFullInternetAccess?`true`:`false`)}function Te(e,t,n){if(e&&S(e)){let r=e.db,i=r.prepare(`SELECT * FROM messages WHERE groupId = ?`).all(t),a=r.prepare(`INSERT INTO messages
|
|
3
|
-
(id, groupId, timestamp, content, sender, channel, isFromMe, isTrigger, attachments, a2uiAction, a2uiEnvelopes, freshContext, subagent)
|
|
4
|
-
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`);for(let e of i)a.run(c(),n,e.timestamp,e.content,e.sender,e.channel??`chat`,e.isFromMe,e.isTrigger,e.attachments,e.a2uiAction,e.a2uiEnvelopes,e.freshContext,e.subagent);return Promise.resolve(i.length)}return new Promise((r,i)=>{let a=e?.transaction(`messages`,`readwrite`);if(!a)throw Error(`failed to get transaction, cannot clone messages.`);let o=a.objectStore(`messages`),s=o.index(`by-group`).openCursor(t),l=0;s.onsuccess=()=>{let e=s.result;if(e){let t={...e.value,id:c(),groupId:n};o.put(t),l++,e.continue()}else r(l)},s.onerror=()=>i(s.error)})}function Ee(e,t,n){if(e&&S(e)){let r=e.db,i=r.prepare(`SELECT * FROM tasks WHERE groupId = ?`).all(t),a=r.prepare(`INSERT INTO tasks
|
|
5
|
-
(id, groupId, enabled, schedule, prompt, tools, lastRun, createdAt, type, freshContext, subagent, name, task_order, pushNotifications)
|
|
6
|
-
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`);for(let e of i)a.run(c(),n,+!!e.enabled,e.schedule??null,e.prompt??``,e.tools??null,e.lastRun??null,e.createdAt,e.type??null,e.freshContext?1:null,e.subagent?1:null,e.name??null,e.task_order??null,e.pushNotifications?1:null);return Promise.resolve(i.length)}return new Promise((r,i)=>{let a=e?.transaction(`tasks`,`readwrite`);if(!a)throw Error(`failed to get transaction, cannot clone tasks.`);let o=a.objectStore(`tasks`),s=o.index(`by-group`).openCursor(t),l=0;s.onsuccess=()=>{let e=s.result;if(e){let t={...e.value,id:c(),groupId:n};o.put(t),l++,e.continue()}else r(l)},s.onerror=()=>i(s.error)})}function De(e,t){return C(e,`messages`,`readwrite`,e=>e.delete(t)).then(()=>void 0)}function R(e,t){return t?C(e,`tasks`,`readwrite`,e=>e.delete(t)).then(()=>void 0):Promise.reject(/* @__PURE__ */ Error(`Task ID is required for deletion.`))}function Oe(){return typeof crypto<`u`&&typeof crypto.randomUUID==`function`?crypto.randomUUID():`sub-${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`}async function ke(e){if(!e)return Oe();let t=await w(e,b.SUBSCRIBER_ID);if(typeof t==`string`&&t.trim().length>0)return t;let n=Oe();return await O(e,b.SUBSCRIBER_ID,n),n}function z(e,t){return C(e,`messages`,`readwrite`,e=>e.put(t)).then(()=>void 0)}function B(e,t){let n={...t,enabled:+!!t.enabled};return C(e,`tasks`,`readwrite`,e=>e.put(n)).then(()=>void 0)}function Ae(e,t,n){let r=null,i,a;return typeof e==`string`?(i=e,a=t):(r=e,i=t,a=n),r&&S(r)?Promise.resolve().then(()=>{r.db.prepare(`UPDATE tasks SET lastRun = ? WHERE id = ?`).run(a,i)}):new Promise(async(e,t)=>{try{let n=r??await x();if(!n)return t(/* @__PURE__ */ Error(`failed to get transaction, cannot update task last run.`));let o=n.transaction(`tasks`,`readwrite`);if(!o)return t(/* @__PURE__ */ Error(`failed to get transaction`));let s=o.objectStore(`tasks`),c=s.get(i);c.onsuccess=()=>{let n=c.result;if(!n){e();return}n.lastRun=a;let r=s.put(n);r.onsuccess=()=>e(),r.onerror=()=>t(r.error)},c.onerror=()=>t(c.error)}catch(e){t(e)}})}async function je(e,t,n){let r=(await A(e)).filter(e=>e.groupId===t),i=new Map(r.map(e=>[e.id,e])),a=[],o=0;for(let t of n){let n=i.get(t);n&&(n.order=o++,await B(e,n),a.push(n),i.delete(t))}let s=Array.from(i.values()).sort((e,t)=>{let n=e.order??0,r=t.order??0;return n===r?e.createdAt-t.createdAt:n-r});for(let t of s)t.order=o++,await B(e,t),a.push(t);return a}async function Me(e,t,n,r){let i=await f(e,t),a=await f(e,n),o=r.replace(/\\/g,`/`).replace(/^\/+/,``).split(`/`).filter(Boolean),s=i,c=a;for(let e of o)s=await s.getDirectoryHandle(e),c=await c.getDirectoryHandle(e,{create:!0});let l=n.replace(/:/g,`-`),u=[te(),`groups`,l,...o];try{await Ne(e,n,s,c,u)}catch(e){throw o.length>0&&await a.removeEntry(o[0],{recursive:!0}).catch(()=>void 0),e}}async function Ne(e,t,n,r,i){for await(let[a,o]of n.entries()){if(o.kind===`directory`){await Ne(e,t,o,await r.getDirectoryHandle(a,{create:!0}),[...i,a]);continue}let n=await o.getFile(),s=await r.getFileHandle(a,{create:!0});try{await v(s,n)}catch(t){if(!((t instanceof Error?t.message:String(t)).includes(`Writable file streams are not supported`)&&(await u(e)).type===`opfs`))throw t;await m([...i,a],n)}}}function Pe(){let e=s(`/static-main/index.html`);if(typeof window<`u`&&window.location?.origin)try{return new URL(e,window.location.origin).toString()}catch{return e}return e}async function Fe(e){let t=await w(e,b.MAIN_GROUP_INDEX_SUPPRESSED);return t===!0||t===`true`}async function Ie(e,t){await O(e,b.MAIN_GROUP_INDEX_SUPPRESSED,t)}async function Le(t,n=y,r){try{if(await T(t,n,`index.html`)){if(n===`br:main`)try{let i=await E(t,n,`index.html`);typeof i==`string`&&(i.includes(`<shadow-claw`)||i.includes(`data-shadow-claw-dsd`))&&await D(t,n,`index.html`,r??e)}catch{}return!0}if(n===`br:main`&&await Fe(t))return!1;let i=r;if(i===void 0&&typeof fetch==`function`)try{let e=await fetch(Pe());if(e.ok){let t=await e.text();!t.includes(`<shadow-claw`)&&!t.includes(`data-shadow-claw-dsd`)&&(i=t)}}catch{}return i??=e,await D(t,n,`index.html`,i),!0}catch(e){return console.warn(`Failed to ensure main workspace Memory:`,e),!1}}const V=`MEMORY.md`;function Re(){let e=s(`/static-main/MEMORY.md`);if(typeof window<`u`&&window.location?.origin)try{return new URL(e,window.location.origin).toString()}catch{return e}return e}async function H(e){let t=await w(e,b.MAIN_GROUP_README_SUPPRESSED);return t===!0||t===`true`}async function U(e,t){await O(e,b.MAIN_GROUP_README_SUPPRESSED,t)}async function W(e,t=y,r){try{if(await T(e,t,`MEMORY.md`)){if(t===`br:main`)try{let i=await E(e,t,V);typeof i==`string`&&(i.includes(`<shadow-claw`)||i.includes(`data-shadow-claw-dsd`))&&await D(e,t,V,r??n)}catch{}return!0}if(t===`br:main`&&await H(e))return!1;let i=r;if(i===void 0&&typeof fetch==`function`)try{let e=await fetch(Re());if(e.ok){let t=await e.text();!t.includes(`<shadow-claw`)&&!t.includes(`data-shadow-claw-dsd`)&&(i=t)}}catch{}return i??=n,await D(e,t,V,i),!0}catch(e){return console.warn(`Failed to ensure main workspace Memory:`,e),!1}}async function G(e,t,n=`.`){for(let r=0;r<2;r++)try{let r=await f(e,t);if(n&&n!==`.`){let e=n.replace(/\\/g,`/`).replace(/^\/home\/user\//,`/`).replace(/^\/+/,``).split(`/`).filter(Boolean);for(let t of e){let e=await r.getDirectoryHandle(t);if(typeof r.isSameEntry==`function`&&await r.isSameEntry(e))throw Error(`Directory navigation stuck at "${r.name}" for segment "${t}" — the stored directory handle may be stale.`);r=e}}let i=[];for await(let[e,t]of r.entries())i.push(t.kind===`directory`?`${e}/`:e);return i.sort()}catch(e){if(r===0&&p(e)){g();continue}throw e}return[]}function ze(e){if(!e||typeof e!=`object`)return!1;let t=globalThis.FileSystemDirectoryHandle;return t!==void 0&&e instanceof t||typeof e.getDirectoryHandle==`function`&&typeof e.getFileHandle==`function`&&typeof e.requestPermission==`function`}async function Be(e){let t=await w(e,b.STORAGE_HANDLE);return!ze(t)||await t.requestPermission({mode:`readwrite`})===`granted`}function Ve(e){let t=o();return t?`shadowclaw:${t}:${e}`:e}function He(e){if(typeof localStorage>`u`)return null;let t=Ve(e);try{let n=localStorage.getItem(t);if(n!==null)return n;if(t===e)return null;let r=localStorage.getItem(e);if(r!==null)return localStorage.setItem(t,r),r}catch(e){console.warn(`Unable to read from localStorage:`,e)}return null}function K(e,t){if(typeof localStorage>`u`)return;let n=Ve(e);try{localStorage.setItem(n,t)}catch(e){console.warn(`Unable to write to localStorage:`,e)}}async function Ue(e,t){let n=await f(e,t);for await(let[e]of n.entries())await n.removeEntry(e,{recursive:!0})}async function q(e,t,n){let r=await f(e,t),{dirs:i,filename:a}=l(n.replace(/\/$/,``)),o=r;for(let e of i)o=await o.getDirectoryHandle(e);await o.removeEntry(a,{recursive:!0})}function J(e,t){return`${e}:${t}`}async function We(e){let t=await w(e,b.SUPPRESSED_PAGES_LIST);if(!t||typeof t!=`string`)return[];try{let e=JSON.parse(t);if(Array.isArray(e))return e}catch{}return[]}async function Ge(e,t,n){let r=await We(e),i=J(t,n);return r.some(e=>J(e.groupId,e.path)===i)}async function Ke(e,t,n){let r=await We(e),i=J(t,n);if(!r.some(e=>J(e.groupId,e.path)===i)){let i=[...r,{groupId:t,path:n}];await O(e,b.SUPPRESSED_PAGES_LIST,JSON.stringify(i))}}async function qe(e,t,n){let r=await We(e),i=J(t,n),a=r.filter(e=>J(e.groupId,e.path)!==i);a.length!==r.length&&await O(e,b.SUPPRESSED_PAGES_LIST,JSON.stringify(a))}function Je(e=y){return e===`br:main`?b.STATIC_MAIN_SITE_SEEDED:`${b.STATIC_MAIN_SITE_SEEDED}:${e}`}async function Ye(e,t=y){let n=Je(t),r=await w(e,n);return r===!0||r===`true`}async function Xe(e,t=y,n=!0){let r=Je(t);await O(e,r,n)}function Ze(){let e=s(`/static-main-manifest.json`);if(typeof window<`u`&&window.location?.origin)try{return new URL(e,window.location.origin).toString()}catch{return e}return e}function Qe(e){let t=e.replace(/^\/+/,``),n=`static-main`;if(typeof document<`u`)try{let e=document.getElementById(`shadow-claw-site-config`);if(e?.textContent){let t=JSON.parse(e.textContent);typeof t?.pages?.baseUrl==`string`&&(n=t.pages.baseUrl.replace(/^\/+/,``).replace(/\/+$/,``))}}catch{}let r=s(n?`/${n}/${t}`:`/${t}`);if(typeof window<`u`&&window.location?.origin)try{return new URL(r,window.location.origin).toString()}catch{return r}return r}async function $e(){if(typeof fetch!=`function`)return null;try{let e=Ze(),t=await fetch(e);if(t.ok){if((t.headers?.get?.(`content-type`)||``).includes(`text/html`))return null;let e=await t.json();if(e&&Array.isArray(e.pages))return e}}catch{}return null}async function et(e){if(typeof fetch!=`function`)return null;try{let t=Qe(e),n=await fetch(t);if(n.ok){let t=n.headers?.get?.(`content-type`)||``;if((e.endsWith(`.md`)||e.endsWith(`.markdown`)||e.endsWith(`.json`))&&t.includes(`text/html`))return null;let r=await n.text();return r.includes(`<shadow-claw`)||r.includes(`data-shadow-claw-dsd`)?null:r}}catch{}return null}function tt(e){if(typeof document>`u`)return null;let t=t=>{if(!t||!(t instanceof HTMLElement))return!1;if(!e)return!0;let n=t.getAttribute(`data-initial-path`)?.trim();return!n||n===e},n=document.querySelector(e?`[data-pages-rendered][data-initial-path="${e}"]`:`[data-pages-rendered]`);if(t(n))return n;let r=document.querySelector(`shadow-claw`)?.shadowRoot,i=(r?.querySelector(`shadow-claw-pages`)?.shadowRoot)?.querySelector(e?`[data-pages-rendered][data-initial-path="${e}"]`:`[data-pages-rendered]`)||r?.querySelector(e?`[data-pages-rendered][data-initial-path="${e}"]`:`[data-pages-rendered]`);if(t(i))return i;let a=document.querySelectorAll(`template`);for(let n of Array.from(a)){let r=n.content?.querySelector(e?`[data-pages-rendered][data-initial-path="${e}"]`:`[data-pages-rendered]`);if(t(r))return r;let i=n.content?.querySelectorAll(`template`);if(i)for(let n of Array.from(i)){let r=n.content?.querySelector(e?`[data-pages-rendered][data-initial-path="${e}"]`:`[data-pages-rendered]`);if(t(r))return r}}return null}function Y(e=`index.html`){let t=tt(e);if(!t)return null;let n=t.getAttribute(`data-initial-path`)?.trim();if(n&&n!==e)return null;let r=t.querySelector(`[data-markdown-frontmatter]`),i=null;if(r){let e=r.getAttribute(`data-frontmatter`);if(e)try{i=JSON.parse(e)}catch{}}let a=t.cloneNode(!0),o=a.querySelector(`[data-markdown-frontmatter]`);o&&o.remove();let s=a.innerHTML.trim();if(!s&&!i)return null;if(i&&Object.keys(i).length>0){let e=[`---`];for(let[t,n]of Object.entries(i))typeof n==`string`?e.push(`${t}: ${JSON.stringify(n)}`):typeof n==`number`||typeof n==`boolean`?e.push(`${t}: ${n}`):e.push(`${t}: ${JSON.stringify(n)}`);return e.push(`---`,``),`${e.join(`
|
|
7
|
-
`)}\n${s}`}return s}async function nt(t={}){let r=()=>{let t=null;if(typeof document<`u`){let r=document.getElementById(`shadow-claw-static-manifest`);if(r&&r.textContent)try{let e=JSON.parse(r.textContent);e&&Array.isArray(e.pages)&&(t={...e,pages:[...e.pages]})}catch(e){console.warn(`Failed to parse embedded static main manifest:`,e)}let i=document.querySelectorAll(`script[type="text/markdown"][data-shadow-claw-page]`);if(i.length>0){t||={pages:[]};for(let r of Array.from(i)){let i=r.getAttribute(`data-shadow-claw-page`)?.trim();if(i){let a=r.textContent||``;a=M(a),!a.trim()&&/^memory\.(md|markdown)$/iu.test(i)&&(a=n),!a.trim()&&(i===`index.html`||/^index\.(html?|xhtml)$/iu.test(i))&&(a=Y(i)??e);let o=t.pages.findIndex(e=>e.displayPath===i);o>=0?t.pages[o].content=a:t.pages.push({displayPath:i,content:a})}}}let a=document.getElementById(`shadow-claw-site-config`);if(a?.textContent)try{let r=JSON.parse(a.textContent);if(Array.isArray(r?.pages?.files)){t||={pages:[]};for(let i of r.pages.files)if(typeof i==`string`&&i.trim()){let r=i.trim(),a=``;/^memory\.(md|markdown)$/iu.test(r)?a=n:(r===`index.html`||/^index\.(html?|xhtml)$/iu.test(r))&&(a=Y(r)??e),t.pages.some(e=>e.displayPath===r)||t.pages.push({displayPath:r,content:a})}}}catch{}let o=tt();if(o){t||={pages:[]};let r=o.getAttribute(`data-initial-path`)?.trim()||`index.html`;if(!t.pages.some(e=>e.displayPath===r)){let n=Y(r)??e;t.pages.push({displayPath:r,content:n})}t.pages.some(e=>/^memory\.(md|markdown)$/iu.test(e.displayPath))||t.pages.push({displayPath:`MEMORY.md`,content:n})}}return t};if(t.preferEmbedded!==!1){let e=r();if(e)return e}if(t.fetchFallback!==!1){let e=await $e();if(e)return e}if(t.preferEmbedded===!1){let e=r();if(e)return e}return{pages:[{displayPath:`index.html`,content:e},{displayPath:`MEMORY.md`,content:n}]}}async function rt(e,t,n=[]){for(let[r,i]of Object.entries(t))if(r===`purgePreRenderedStaticPages`&&i===!0){if(n.length>0){let t=n[0],r=n.slice(1).join(`/`);try{r?await q(e,t,r):await Ue(e,t)}catch(e){console.warn(`Failed to purge pre-rendered static pages for ${t}/${r}:`,e)}}}else typeof i==`object`&&i&&await rt(e,i,[...n,r])}function it(){if(typeof document<`u`)try{let e=document.getElementById(`shadow-claw-site-config`);if(e?.textContent){let t=JSON.parse(e.textContent);if(t?.pages?.sortOrder===`desc`)return`desc`;if(t?.pages?.sortOrder===`asc`)return`asc`}}catch{}return`desc`}function at(){if(typeof document<`u`)try{let e=document.getElementById(`shadow-claw-site-config`);if(e?.textContent){let t=JSON.parse(e.textContent)?.pages?.defaultPinnedPage;if(typeof t==`string`&&t.trim().length>0)return t.trim()}}catch{}return null}function ot(){if(typeof document<`u`)try{let e=document.getElementById(`shadow-claw-site-config`);if(e?.textContent){let n=JSON.parse(e.textContent);return{allowList:t(n?.pages?.allowList??n?.pages?.allowlist??n?.allowList??n?.allowlist??[]),denyList:t(n?.pages?.denyList??n?.pages?.denylist??n?.denyList??n?.denylist??[])}}}catch{}return{allowList:[],denyList:[]}}function st(e,t){let n=t??it();return[...e].sort((e,t)=>{let r=e.path,i=t.path,a=r.split(`/`).pop()||``,o=i.split(`/`).pop()||``,s=/^index\.(html?|xhtml)$/iu.test(a),c=/^index\.(html?|xhtml)$/iu.test(o);if(s&&!c)return-1;if(!s&&c)return 1;let l=/^memory\.(md|markdown)$/iu.test(a),u=/^memory\.(md|markdown)$/iu.test(o);return l&&!u?1:!l&&u?-1:n===`asc`?r.localeCompare(i,void 0,{numeric:!0,sensitivity:`base`}):i.localeCompare(r,void 0,{numeric:!0,sensitivity:`base`})})}async function X(e,t,n=`sc:purge-id`,r=`static_main_site_purge_id`){let i=t??`__legacy_purge_pages__`;try{if(He(n)===i)return!0}catch{}try{if(await w(e,r)===i){try{K(n,i)}catch{}return!0}await O(e,r,i);try{K(n,i)}catch{}}catch{try{K(n,i)}catch{}}return!1}async function ct(t,i=y,a=[],o={}){await Le(t,i);let s=await nt(o),c=!1;s.preRenderedStaticPages&&(await X(t,s.purgeId)||(c=!0,await rt(t,s.preRenderedStaticPages)));let l=!1;if(i===`br:main`&&s.skillsPurgeId!==void 0&&!await X(t,s.skillsPurgeId,`sc:skills-purge-id`,`static_main_skills_purge_id`)){l=!0;try{await q(t,i,`.agents/skills/main`)}catch(e){if(!(e&&typeof e==`object`&&`name`in e&&e.name===`NotFoundError`))throw e}try{await q(t,i,`.agents/tools/main`)}catch(e){if(!(e&&typeof e==`object`&&`name`in e&&e.name===`NotFoundError`))throw e}}for(let e of s.pages)if(e.content?.includes(`slug: "shadow-claw--purge-pages"`)){!c&&!await X(t,s.purgeId)&&(c=!0,await Ue(t,i));break}let u=i===`br:main`&&await H(t),d=new Set(s.pages.map(e=>J(i,e.displayPath))),f=c?a.filter(e=>e.groupId!==i||d.has(J(e.groupId,e.path))):[...a],{allowList:p,denyList:m}=ot(),h=0;for(let a of s.pages)if(h++,h%5==0&&await new Promise(e=>setTimeout(e,0)),!a.content?.includes(`slug: "shadow-claw--purge-pages"`)&&r(a.displayPath,{allowList:p,denyList:m,groupId:i})){if(/^memory\.(md|markdown)$/iu.test(a.displayPath)){if(u)continue;let e=typeof a.content==`string`&&a.content.trim().length>0&&a.content!==n?a.content:void 0;if(e===void 0?await W(t,i):await W(t,i,e)){let e=J(i,a.displayPath);f.some(t=>J(t.groupId,t.path)===e)||f.push({groupId:i,path:a.displayPath})}}else if(!await Ge(t,i,a.displayPath))try{if(!await T(t,i,a.displayPath)){let n=a.content;(typeof n!=`string`||!n.trim())&&(n=a.displayPath===`index.html`?Y(`index.html`)??e:await et(a.displayPath)??``),await D(t,i,a.displayPath,n)}let n=J(i,a.displayPath);f.some(e=>J(e.groupId,e.path)===n)||f.push({groupId:i,path:a.displayPath})}catch(e){console.warn(`Failed to seed static page file ${a.displayPath}:`,e)}}if(i===`br:main`){for(let e of s.skills||[]){let n=`.agents/skills/main/${e.displayPath}`;try{await T(t,i,n)||await D(t,i,n,e.content)}catch(e){console.warn(`Failed to seed skill file ${n}:`,e)}}for(let e of s.tools||[]){let n=`.agents/tools/main/${e.displayPath}`;try{(l||!await T(t,i,n))&&await D(t,i,n,e.content)}catch(e){console.warn(`Failed to seed tool file ${n}:`,e)}}}let g=typeof document<`u`&&(document.getElementById(`shadow-claw-static-manifest`)!==null||document.querySelector(`script[type="text/markdown"][data-shadow-claw-page]`)!==null||tt()!==null);o.preferEmbedded!==!1&&g||await Xe(t,i,!0);let _=f.filter(e=>r(e.path,{allowList:p,denyList:m,groupId:e.groupId}));return Object.defineProperty(_,"didPurge",{value:c,enumerable:!1,writable:!0,configurable:!0}),Object.defineProperty(_,"didPurgeSkills",{value:l,enumerable:!1,writable:!0,configurable:!0}),st(_)}var lt=class{_events;_handlers=[];_runs=/* @__PURE__ */ new Map;constructor(e){this._events=e}start(){this._listen(`streaming-start`,this._onStreamingStart),this._listen(`streaming-chunk`,this._onStreamingChunk),this._listen(`streaming-end`,this._onStreamingEnd),this._listen(`streaming-done`,this._onStreamingDone),this._listen(`streaming-error`,this._onStreamingError),this._listen(`tool-activity`,this._onToolActivity)}stop(){for(let{event:e,handler:t}of this._handlers)this._events.off(e,t);this._handlers=[],this._runs.clear()}_emit(e,t){window.dispatchEvent(new CustomEvent(`shadow-claw-agui-event`,{detail:{groupId:e,event:t}}))}_listen(e,t){this._events.on(e,t),this._handlers.push({event:e,handler:t})}_onStreamingChunk=({groupId:e,text:t})=>{let n=this._runs.get(e);n&&n.messageId&&this._emit(e,{type:`TEXT_MESSAGE_CONTENT`,messageId:n.messageId,delta:t,timestamp:Date.now()})};_onStreamingDone=({groupId:e})=>{let t=this._runs.get(e);t&&(t.messageId&&this._emit(e,{type:`TEXT_MESSAGE_END`,messageId:t.messageId,timestamp:Date.now()}),this._emit(e,{type:`RUN_FINISHED`,threadId:t.threadId,runId:t.runId,timestamp:Date.now()}),this._runs.delete(e))};_onStreamingEnd=({groupId:e})=>{let t=this._runs.get(e);t&&t.messageId&&(this._emit(e,{type:`TEXT_MESSAGE_END`,messageId:t.messageId,timestamp:Date.now()}),t.messageId=null)};_onStreamingError=({groupId:e,error:t})=>{let n=this._runs.get(e);n&&(n.messageId&&this._emit(e,{type:`TEXT_MESSAGE_END`,messageId:n.messageId,timestamp:Date.now()}),this._emit(e,{type:`RUN_ERROR`,message:t||`Unknown streaming error`,timestamp:Date.now()}),this._runs.delete(e))};_onStreamingStart=({groupId:e})=>{let t=c(),n=e,r=c();this._runs.set(e,{runId:t,threadId:n,messageId:r,activeToolCallIds:/* @__PURE__ */ new Set}),this._emit(e,{type:`RUN_STARTED`,threadId:n,runId:t,timestamp:Date.now()}),this._emit(e,{type:`TEXT_MESSAGE_START`,messageId:r,role:`assistant`,timestamp:Date.now()})};_onToolActivity=({groupId:e,tool:t,status:n})=>{let r=this._runs.get(e);if(r){if(n===`running`){let n=c();r.activeToolCallIds.add(n),this._emit(e,{type:`TOOL_CALL_START`,toolCallId:n,toolCallName:t,timestamp:Date.now()}),r._lastToolCallId=n}else if(n===`done`||n===`error`){let t=r._lastToolCallId;t&&(r.activeToolCallIds.delete(t),this._emit(e,{type:`TOOL_CALL_END`,toolCallId:t,timestamp:Date.now()}))}}}};const ut=new class{#e=new k.State(0);#t=/* @__PURE__ */ new Map;#n=new k.State([]);clear(){this.#t.forEach((e,t)=>this.clearTimer(t)),this.#t.clear(),this.#n.set([])}clearTimer(e){let t=this.#t.get(e);t?.timeoutId&&clearTimeout(t.timeoutId),this.#t.delete(e)}dismiss(e){this.clearTimer(e),this.#n.set(this.#n.get().filter(t=>t.id!==e))}pause(e){let t=this.#t.get(e);t&&t.timeoutId&&(clearTimeout(t.timeoutId),t.timeoutId=void 0,t.remaining=Math.max(0,t.remaining-(Date.now()-t.startedAt)),this.#t.set(e,t))}resolveAction(e){if(e&&typeof e.label==`string`&&typeof e.onClick==`function`)return e}resolveDuration(e){return typeof e!=`number`||Number.isNaN(e)||e<0?4e3:e}resolveType(e){return e&&[`success`,`warning`,`error`,`info`].includes(e)?e:`info`}resume(e){let t=this.#t.get(e);!t||t.timeoutId||t.remaining<=0||this.scheduleDismiss(e,t.remaining)}scheduleDismiss(e,t){this.clearTimer(e);let n=globalThis.setTimeout(()=>{this.dismiss(e)},t);this.#t.set(e,{timeoutId:n,remaining:t,startedAt:Date.now()})}show(e,t={}){let n=this.#e.get()+1;this.#e.set(n);let r={id:n,message:e,type:this.resolveType(t.type),duration:this.resolveDuration(t.duration),action:this.resolveAction(t.action),createdAt:Date.now()},i=[...this.#n.get(),r];if(i.length>5){let e=i[0];this.clearTimer(e.id),this.#n.set(i.slice(1))}else this.#n.set(i);return r.duration>0&&this.scheduleDismiss(r.id,r.duration),r.id}get toasts(){return this.#n.get()}async runAction(e){let t=this.#n.get().find(t=>t.id===e);t?.action&&await t.action.onClick()}};function dt(e,t={}){return ut.show(e,t)}function ft(e,t=4e3){return ut.show(e,{type:`success`,duration:t})}function Z(e,t=5e3){return ut.show(e,{type:`error`,duration:t})}function pt(e,t){if(!e||typeof e!=`object`)return e;let n=JSON.parse(JSON.stringify(e));for(let e of t)mt(n,e);return n}function mt(e,t){let{op:n,path:r,value:i}=t;if(!r||!r.startsWith(`/`))return;let a=r.split(`/`).slice(1).map(e=>e.replace(/~1/g,`/`).replace(/~0/g,`~`)),o=a.pop();if(o===void 0)return;let s=e;for(let e of a){if(typeof s!=`object`||!s)return;s=s[e]}typeof s==`object`&&s&&(Array.isArray(s)?ht(s,o,n,i):gt(s,o,n,i))}function ht(e,t,n,r){if(n===`add`){if(t===`-`)e.push(r);else{let n=parseInt(t,10);!isNaN(n)&&n>=0&&n<=e.length&&e.splice(n,0,r)}}else if(n===`replace`){let n=parseInt(t,10);!isNaN(n)&&n>=0&&n<e.length&&(e[n]=r)}else if(n===`remove`){let n=parseInt(t,10);!isNaN(n)&&n>=0&&n<e.length&&e.splice(n,1)}}function gt(e,t,n,r){n===`add`||n===`replace`?e[t]=r:n===`remove`&&delete e[t]}function _t(e){if(e==null)return null;let t=String(e).trim().toLowerCase();return[`1`,`true`,`yes`,`on`].includes(t)?!0:![`0`,`false`,`no`,`off`].includes(t)&&null}function vt(e,t=!1){if(e==null)return t;if(typeof e==`boolean`)return e;if(typeof e==`number`)return e===1;if(typeof e==`string`){let t=e.trim().toLowerCase();return t===`true`||t===`1`}return!1}function yt(e){if(!e)return[];try{let n=JSON.parse(e);if(Array.isArray(n))return t(n.map(e=>String(e)))}catch{}return t(e.split(`,`))}function bt(e){if(e){if(Array.isArray(e))return e;if(typeof e==`string`)try{let t=JSON.parse(e);return Array.isArray(t)?t:void 0}catch{return}}}function xt(e){if(typeof e==`boolean`)return e;if(typeof e==`string`){let t=e.trim().toLowerCase();return t===`true`||t===`1`}return typeof e==`number`&&e===1}function St(e){return!!e}async function Q(e,t,n,r){if(!St(r))return!0;if(!e.schedule)return await $(e.id,t,n,r)!==`failed`;try{let r=t.replace(/\/$/,``);return(await fetch(`${r}/tasks`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({...e,subscriberId:n})})).ok}catch{return!1}}async function $(e,t,n,r){if(!St(r))return`missing`;try{let r=t.replace(/\/$/,``),i=`subscriberId=${encodeURIComponent(n)}`,a=await fetch(`${r}/tasks/${encodeURIComponent(e)}?${i}`,{method:`DELETE`});return a.ok?`deleted`:a.status===404||a.status===405?`missing`:`failed`}catch{return`failed`}}async function Ct(e,t,n,r){if(!St(r))return null;try{let r=t.replace(/\/$/,``),i=await fetch(`${r}/tasks?groupId=${encodeURIComponent(e)}&subscriberId=${encodeURIComponent(n)}`,{method:`GET`});if(!i.ok||typeof i.json!=`function`)return null;let a=await i.json();return Array.isArray(a)?a.filter(e=>!!e&&typeof e==`object`&&typeof e.id==`string`&&typeof e.schedule==`string`&&typeof e.prompt==`string`).map(t=>({id:t.id,groupId:t.group_id||t.groupId||e,schedule:t.schedule,type:t.type,prompt:t.prompt,tools:bt(t.tools),channel:typeof t.channel==`string`?t.channel:void 0,enabled:t.enabled===!0||t.enabled===1,lastRun:typeof t.lastRun==`number`?t.lastRun:typeof t.last_run==`number`?t.last_run:null,createdAt:typeof t.createdAt==`number`?t.createdAt:typeof t.created_at==`number`?t.created_at:Date.now(),name:typeof t.name==`string`?t.name:void 0,order:typeof t.order==`number`?t.order:typeof t.task_order==`number`?t.task_order:void 0})):null}catch{return null}}function wt(e,t){let n=(e?.inputTokens??0)+(t.inputTokens??0),r=(e?.outputTokens??0)+(t.outputTokens??0),i=(e?.cacheReadTokens??0)+(t.cacheReadTokens??0),a=(e?.cacheCreationTokens??0)+(t.cacheCreationTokens??0);return{groupId:t.groupId||e?.groupId||``,inputTokens:n,outputTokens:r,cacheReadTokens:i,cacheCreationTokens:a,totalTokens:n+r+i+a,contextLimit:t.contextLimit||e?.contextLimit||0}}var Tt=class e{static DEFAULT_PAGE_PATH=`MEMORY.md`;orchestrator;_activeGroupId;_activePage;_activePinnedPage;_defaultPinnedPage;_activityLog;_activityLogSessionStartedAtByGroup;_aguiAdapter;_aguiEvent;_contextUsage;_currentPath;_db;_error;_files;_gitProxyUrl;_groups;_hadPersistedActivePage;_initResolve;_isTyping;_lastOrchestratorDisplayState=`idle`;_messages;_modelDownloadProgress;_onlineReplayHandler;_pages;_pagesAllowList;_pagesDenyList;_peerStateByGroup;_proxyUrl;_ready;_remoteAgentStatusByGroup;_remoteAgentTypingByGroup;_replayingTaskSyncOutbox;_subscriberId;_sidebarDefaultPage;_state;_storageStatus;_streamingText;_tasks;_taskSyncOutbox;_tokenUsage;_tokenUsageAccumulator=null;_toolActivity;_unreadGroupIds;_useProxy;_vmBashFullInternetAccess;_whenInitialized;_whenReady;_readyResolve;constructor(){this._messages=new k.State([]),this._isTyping=new k.State(!1),this._storageStatus=new k.State(null),this._toolActivity=new k.State(null),this._modelDownloadProgress=new k.State(null),this._activityLog=new k.State([]),this._state=new k.State(`idle`),this._tokenUsage=new k.State(null),this._error=new k.State(null),this._activeGroupId=new k.State(y),this._ready=new k.State(!1),this._tasks=new k.State([]),this._files=new k.State([]),this._currentPath=new k.State(`.`),this._groups=new k.State([]),this._unreadGroupIds=new k.State(/* @__PURE__ */ new Set),this._streamingText=new k.State(null),this._aguiEvent=new k.State(null),this._contextUsage=new k.State(null),this._useProxy=new k.State(!1),this._proxyUrl=new k.State(`/proxy`),this._gitProxyUrl=new k.State(`/git-proxy`),this._vmBashFullInternetAccess=new k.State(!1),this._activePage=new k.State(`pages`);let e=re()?.sidebar?.defaultPage,t=e===`pages`||e===`chat`||e===`tasks`||e===`files`?e:`chat`;this._sidebarDefaultPage=new k.State(t),this._pages=new k.State([]),this._pagesAllowList=new k.State([]),this._pagesDenyList=new k.State([]),this._activePinnedPage=new k.State(null),this._defaultPinnedPage=new k.State(null),this._remoteAgentStatusByGroup=new k.State(/* @__PURE__ */ new Map),this._remoteAgentTypingByGroup=new k.State(/* @__PURE__ */ new Map),this._peerStateByGroup=new k.State(/* @__PURE__ */ new Map),this._hadPersistedActivePage=!1,this._initResolve=null,this._whenInitialized=new Promise(e=>{this._initResolve=e}),this._readyResolve=null,this._whenReady=new Promise(e=>{this._readyResolve=e}),this.orchestrator=null,this._db=null,this._activityLogSessionStartedAtByGroup=/* @__PURE__ */ new Map,this._taskSyncOutbox=[],this._replayingTaskSyncOutbox=!1,this._subscriberId=null,this._onlineReplayHandler=null,this._aguiAdapter=null}get activeGroupId(){return this._activeGroupId.get()}get activePage(){return this._activePage.get()}get activePinnedPage(){return this._activePinnedPage.get()}get defaultPinnedPage(){return this._defaultPinnedPage.get()}get pagesAllowList(){return this._pagesAllowList.get()}get pagesDenyList(){return this._pagesDenyList.get()}isPageAllowed(e,t){return r(e,{allowList:this._pagesAllowList.get(),denyList:this._pagesDenyList.get(),groupId:t??this._activeGroupId.get()})}get effectiveDefaultPage(){let e=this._defaultPinnedPage.get();return e&&this.isPageAllowed(e.path,e.groupId)?e:this._pages.get()[0]||null}get activityLog(){return this._activityLog.get()}get taskServerEnabled(){return this.orchestrator?.taskServerEnabled??!1}get aguiEvent(){return this._aguiEvent.get()}clearError(){this._error.set(null),this._state.get()===`error`&&this._state.set(`idle`)}get contextUsage(){return this._contextUsage.get()}get tokenUsageAccumulator(){return this._tokenUsageAccumulator}get currentPath(){return this._currentPath.get()}get error(){return this._error.get()}get files(){return this._files.get()}getPeerState(e){return this._peerStateByGroup.get().get(e)||null}getRemoteAgentStatus(e){return this._remoteAgentStatusByGroup.get().get(e)||`idle`}getState(){return{messages:this.messages,isTyping:this.isTyping,toolActivity:this.toolActivity,activityLog:this.activityLog,state:this.state,tokenUsage:this.tokenUsage,modelDownloadProgress:this.modelDownloadProgress,error:this.error,activeGroupId:this.activeGroupId,pages:this.pages,ready:this.ready,files:this.files,currentPath:this.currentPath,streamingText:this.streamingText,contextUsage:this.contextUsage}}getTasksForBackup(){return this._tasks.get()}get gitProxyUrl(){return this._gitProxyUrl.get()}get groups(){return this._groups.get()}get hadPersistedActivePage(){return this._hadPersistedActivePage}isRemoteAgentTyping(e){return this._remoteAgentTypingByGroup.get().get(e)||!1}get isTyping(){return this._isTyping.get()}get messages(){return this._messages.get()}get modelDownloadProgress(){return this._modelDownloadProgress.get()}get pages(){return this._pages.get()}get proxyUrl(){return this._proxyUrl.get()}get ready(){return this._ready.get()}sendMessage(e,t=[],n){n===void 0?this.orchestrator?.browserChat?.submit(e,this._activeGroupId.get(),t):this.orchestrator?.browserChat?.submit(e,this._activeGroupId.get(),t,n)}async sendFileToPeer(e,t=this._activeGroupId.get(),n){let r=t.startsWith(`peer:`),i=t.startsWith(`room:`);if(!r&&!i){let e=`Can only send files to peers in a peer or room conversation.`;throw Z(e,4500),Error(e)}let a=this.orchestrator?.router;if(!a){let e=`Network router is not initialized.`;throw Z(e,4500),Error(e)}let o=n?.fileName||e.split(`/`).pop()||e,s=n?.mimeType||`application/octet-stream`,l=n?.size||0;a.setTyping(t,!0);try{let n={path:e,fileName:o,mimeType:s,size:l};if(await a.send(t,``,[n]),this._db){let e={id:c(),groupId:t,sender:`You`,content:``,timestamp:Date.now(),channel:i?`room`:`peerjs`,attachments:[n],isFromMe:!1,isTrigger:!1};await z(this._db,e),this.orchestrator?.events.emit(`message`,e)}ft(`Sent ${o} to ${i?`room peers`:`peer`}`,2500)}catch(e){let t=e instanceof Error?e.message:String(e);throw console.error(`sendFileToPeer error:`,e),Z(`Failed to send file: ${t}`,6e3),e}finally{a.setTyping(t,!1)}}setActiveGroup(e,t,n=this._activePage.get()===`chat`){if(this._activeGroupId.set(t),this._messages.set([]),this._activityLog.set([]),this._error.set(null),this._isTyping.set(!1),this._toolActivity.set(null),this._modelDownloadProgress.set(null),this._streamingText.set(null),this._currentPath.set(`.`),n){let e=new Set(this._unreadGroupIds.get());e.delete(t)&&this._unreadGroupIds.set(e)}this.loadHistory(),this.loadTasks(e),this.loadFiles(e)}setReady(e=!0){this._ready.set(e),e&&this._readyResolve&&this._readyResolve()}setRemoteAgentStatus(e,t){let n=this._remoteAgentStatusByGroup.get(),r=new Map(n);r.set(e,t),this._remoteAgentStatusByGroup.set(r)}setRemoteAgentTyping(e,t){let n=this._remoteAgentTypingByGroup.get(),r=new Map(n);t?r.set(e,!0):r.delete(e),this._remoteAgentTypingByGroup.set(r)}get sidebarDefaultPage(){return this._sidebarDefaultPage.get()}get state(){return this._state.get()}stopCurrentRequest(){this.orchestrator?.stopCurrentRequest?.(this._activeGroupId.get())}get storageStatus(){return this._storageStatus.get()}get streamingText(){return this._streamingText.get()}syncHostWorkspaceToVM(){ve(this.orchestrator,this._activeGroupId.get())}syncVMWorkspaceToHost(){ye(this.orchestrator,this._activeGroupId.get())}get tasks(){return this._tasks.get()}get tokenUsage(){return this._tokenUsage.get()}get toolActivity(){return this._toolActivity.get()}get unreadGroupIds(){return this._unreadGroupIds.get()}get useProxy(){return this._useProxy.get()}get vmBashFullInternetAccess(){return this._vmBashFullInternetAccess.get()}get whenInitialized(){return this._whenInitialized}async resetSiteConfigSeed(e){await O(e,b.SITE_CONFIG_SEEDED,!1)}get whenReady(){return this._whenReady}async addPage(e,t,n=this._activeGroupId.get()){let r=n===`br:main`?this.normalizePagePath(t):t.trim();if(!r||!this.isPageAllowed(r,n))return;let i=this._pages.get();i.some(e=>e.path===r&&e.groupId===n)||(this.setPages([...i,{groupId:n,path:r}]),await qe(e,n,r),n===`br:main`&&r===`MEMORY.md`&&await U(e,!1),await this.persistPages(e))}async clearAllTasks(e){let t=await A(e),n=this._activeGroupId.get(),r=t.filter(e=>e.groupId===n),i=await this.getSubscriberId(e);for(let t of r)await $(t.id,this.getTaskServerBaseUrl(),i,this.orchestrator?.taskServerEnabled??!1)===`failed`?(console.warn(`Failed to delete task "${t.id}" from server — queued for replay.`),await this.queueTaskSyncOutboxOperation(e,{type:`delete`,id:t.id,queuedAt:Date.now()})):await R(e,t.id);await this.loadTasks(e)}async cloneConversation(e,t){let n=await fe(e,t);if(!n)return null;await Te(e,t,n.groupId),await Ee(e,t,n.groupId);try{let r=await E(e,t,`MEMORY.md`);r&&await D(e,n.groupId,`MEMORY.md`,r)}catch{}try{await Me(e,t,n.groupId,`attachments`)}catch{}return this.setActiveGroup(e,n.groupId),await this.loadGroups(e),n}async compactContext(e){if(!this.orchestrator)return;let{compactContext:t}=await import(`./chunk-Cq_kQohv.js`);return t(this.orchestrator,e,this._activeGroupId.get())}async createConversation(e,t){let n=await se(e,t);return this.setActiveGroup(e,n.groupId),await this.loadGroups(e),n}async deleteConversation(e,t){if(!(this._groups.get().length<=1)&&(await ue(e,t),await ne(e,t),await this.loadGroups(e),this._activeGroupId.get()===t)){let t=this._groups.get()[0]?.groupId||`br:main`;this.setActiveGroup(e,t)}}async deleteMessage(e,t){await De(e,t),await this.loadHistory(),this.orchestrator?.refreshContextUsage&&await this.orchestrator.refreshContextUsage(e,this._activeGroupId.get())}async deleteTask(e,t){let n=await this.getSubscriberId(e);if(await $(t,this.getTaskServerBaseUrl(),n,this.orchestrator?.taskServerEnabled??!1)===`failed`)throw console.warn(`Failed to delete task from server — queued for replay.`),await this.queueTaskSyncOutboxOperation(e,{type:`delete`,id:t,queuedAt:Date.now()}),Error(`Failed to delete scheduled task on server; task kept locally.`);await R(e,t),await this.loadTasks(e)}async ensurePeerConversation(e,t){let n=`peer:${t}`,r=await I(e);if(!r.find(e=>e.groupId===n)){let i=[...r],a=``;if(this.orchestrator?.peerjsPeerAliases){for(let[e,n]of Object.entries(this.orchestrator.peerjsPeerAliases))if(n===t){a=e;break}}i.push({groupId:n,name:`Peer: ${a||t.substring(0,8)}`,createdAt:Date.now()}),await F(e,i),await this.loadGroups(e)}return n}async grantStorageAccess(e){try{await Be(e),await this.loadFiles(e)}catch(e){console.error(`Failed to grant storage access:`,e)}}async init(e,t){this._db=e,this.orchestrator=t,this._taskSyncOutbox=this.parseTaskSyncOutbox(await w(e,b.TASK_SYNC_OUTBOX)),await this.replayTaskSyncOutbox(e),typeof window<`u`&&!this._onlineReplayHandler&&(this._onlineReplayHandler=()=>{this._db&&this.replayTaskSyncOutbox(this._db)},window.addEventListener(`online`,this._onlineReplayHandler)),t.events.on(`a2ui-surface`,async({groupId:t,envelope:n})=>{t&&this.ensureGroupExists(e,t);let r=this._messages.get(),i=r.findIndex(e=>e.a2uiEnvelopes?.some(e=>e.surfaceId===n.surfaceId));if(i!==-1){let t=r[i],a=[...t.a2uiEnvelopes||[],n],o={...t,a2uiEnvelopes:a},s=[...r];s[i]=o,this._messages.set(s),await z(e,o)}else{let i=!t.startsWith(`peer:`),a={id:c(),groupId:t,sender:i?`agent`:t.replace(/^peer:/,``),content:``,timestamp:Date.now(),channel:t.startsWith(`peer:`)?`peerjs`:`browser`,isFromMe:i,isTrigger:!1,a2uiEnvelopes:[n]};t===this._activeGroupId.get()&&this._messages.set([...r,a]),await z(e,a)}}),t.events.on(`message`,t=>{if(t.groupId&&this.ensureGroupExists(e,t.groupId,t.timestamp),t.groupId&&t.groupId!==this._activeGroupId.get()){let e=new Set(this._unreadGroupIds.get());e.add(t.groupId),this._unreadGroupIds.set(e)}else t.isFromMe&&this._streamingText.get()!==null&&this._streamingText.set(null),this._messages.set([...this._messages.get(),t])}),t.events.on(`typing`,({groupId:e,typing:t})=>{e&&e!==this._activeGroupId.get()||this._isTyping.set(t)}),t.events.on(`tool-activity`,({groupId:e,tool:t,status:n})=>{e&&e!==this._activeGroupId.get()||this._toolActivity.set(n===`running`?{tool:t,status:n}:null)}),t.events.on(`model-download-progress`,e=>{this._modelDownloadProgress.set(e.status===`done`?null:e)}),t.events.on(`thinking-log`,e=>{e.groupId&&e.groupId!==this._activeGroupId.get()||(e.level===`info`&&e.label===`Starting`?this._activityLog.set([e]):this._activityLog.set([...this._activityLog.get(),e]),this.forwardActivityLogEntryToServer(e))}),t.events.on(`state-change`,e=>{let t=typeof e==`string`?e:e.state,n=typeof e==`string`?void 0:e.groupId;if(n&&n!==this._activeGroupId.get())return;let r=this._lastOrchestratorDisplayState;this._lastOrchestratorDisplayState=t,this._state.set(t),t===`idle`&&(this._toolActivity.set(null),this._modelDownloadProgress.set(null),this._streamingText.set(null)),t===`thinking`&&r!==`thinking`&&r!==`responding`&&(this._tokenUsageAccumulator=null)}),t.events.on(`error`,({error:e})=>{console.error(`[Orchestrator Error Event]`,e),this._error.set(e),this._state.set(`error`)}),t.events.on(`session-reset`,()=>{this._messages.set([]),this._activityLog.set([]),this._tokenUsageAccumulator=null,this._tokenUsage.set(null),this._contextUsage.set(null),this._toolActivity.set(null),this._modelDownloadProgress.set(null),this._streamingText.set(null),this._isTyping.set(!1),this._state.set(`idle`)}),t.events.on(`context-compacted`,e=>{e?.groupId&&e.groupId!==this._activeGroupId.get()||(this._tokenUsage.set(null),this.loadHistory())}),t.events.on(`token-usage`,e=>{if(!e||e.groupId&&e.groupId!==this._activeGroupId.get())return;let t=wt(this._tokenUsageAccumulator,e);this._tokenUsageAccumulator=t,this._tokenUsage.set(t),this.orchestrator?.refreshContextUsage&&this._db&&this.orchestrator.refreshContextUsage(this._db,this._activeGroupId.get())}),t.events.on(`context-usage`,e=>{this._contextUsage.set(e)}),t.events.on(`ready`,()=>{this._ready.set(!0)}),t.events.on(`task-change`,()=>{this.loadTasks(e)}),t.events.on(`file-change`,()=>{this.loadFiles(e)}),t.events.on(`streaming-start`,({groupId:e})=>{e===this._activeGroupId.get()&&this._streamingText.set(``)}),t.events.on(`streaming-chunk`,({groupId:e,text:t})=>{if(e!==this._activeGroupId.get())return;let n=this._streamingText.get();this._streamingText.set((n||``)+t)}),t.events.on(`streaming-end`,({groupId:e})=>{e===this._activeGroupId.get()&&this._streamingText.set(null)}),t.events.on(`streaming-done`,({groupId:e})=>{this._activeGroupId.get()}),t.events.on(`streaming-error`,({groupId:e})=>{this._activeGroupId.get()}),this._aguiAdapter=new lt(t.events),this._aguiAdapter.start(),typeof window<`u`&&window.addEventListener(`shadow-claw-agui-event`,(e=>{e.detail.groupId===this._activeGroupId.get()&&this._aguiEvent.set(e.detail);let t=e.detail.event;if(t){if(t.type===`STATE_SNAPSHOT`){let n=new Map(this._peerStateByGroup.get());n.set(e.detail.groupId,t.snapshot||{}),this._peerStateByGroup.set(n)}else if(t.type===`STATE_DELTA`){let n=new Map(this._peerStateByGroup.get()),r=pt(n.get(e.detail.groupId)||{},t.delta||[]);n.set(e.detail.groupId,r),this._peerStateByGroup.set(n)}}})),await d(e),ee(),h(),await L();let n=await w(e,b.PAGES_ALLOW_LIST),r=await w(e,b.PAGES_DENY_LIST);n&&this._pagesAllowList.set(yt(String(n))),r&&this._pagesDenyList.set(yt(String(r))),await L();let o=typeof document<`u`&&document.getElementById(`shadow-claw-static-routing`)!==null,s=await w(e,b.PAGES_LIST),l=s==null?[]:this.parsePagesList(s),u=await ct(e,y,l);u.length>0?(this.setPages(u),await this.persistPages(e)):await this.ensureDefaultPage(e),await L(),await this.applySiteConfigDefaults(e),await L(),await this.loadGroups(e);let f=await w(e,b.LAST_ACTIVE_GROUP);f&&f!==this._activeGroupId.get()&&this._activeGroupId.set(f),await L();let p=await w(e,b.LAST_ACTIVE_PAGE);p&&(this._activePage.set(p),this._hadPersistedActivePage=!0);let m=await w(e,b.SIDEBAR_DEFAULT_PAGE);this._sidebarDefaultPage.set(this.normalizeSidebarDefaultPage(m));let g=at(),_=null;if(g&&(_=i(g)),!_){let t=await w(e,b.DEFAULT_PINNED_PAGE);t&&(_=i(t))}_&&this.isPageAllowed(_.path,_.groupId)&&this._defaultPinnedPage.set(_),await L();let v=typeof window<`u`&&window.history?window.history.state:null,te=!!(v?.inFeedScroll||v?.scrollSpy||v?.suppressRouter)||typeof window<`u`&&window.location&&(()=>{let e=window.location.pathname||`/`,t=a();t!==`/`&&e.startsWith(t)&&(e=`/`+e.slice(t.length));let n=e.split(`/`).filter(Boolean);return n.length===0||n.length===1&&n[0]===`index.html`})(),x=!1;if(te&&_&&this.isPageAllowed(_.path,_.groupId)&&(this._activePinnedPage.set(_),x=!0),!x){let t=await w(e,b.LAST_SELECTED_PINNED_PAGE);if(t)try{let e=JSON.parse(t);e&&typeof e.path==`string`&&typeof e.groupId==`string`&&this.isPageAllowed(e.path,e.groupId)&&(this._activePinnedPage.set(e),x=!0)}catch{}}!x&&te&&this.effectiveDefaultPage&&this.isPageAllowed(this.effectiveDefaultPage.path,this.effectiveDefaultPage.groupId)&&(this._activePinnedPage.set(this.effectiveDefaultPage),x=!0),this.orchestrator&&(this._useProxy.set(this.orchestrator.useProxy),this._proxyUrl.set(this.orchestrator.proxyUrl),this._gitProxyUrl.set(this.orchestrator.gitProxyUrl),this._vmBashFullInternetAccess.set(this.orchestrator.vmBashFullInternetAccess));let[S,C,T]=await Promise.all([w(e,b.SIDEBAR_CHAT_HIDDEN),w(e,b.SIDEBAR_TASKS_HIDDEN),w(e,b.SIDEBAR_FILES_HIDDEN)]),E=re(),D=E?.sidebar?.chatHidden,O=E?.sidebar?.tasksHidden,k=E?.sidebar?.filesHidden,A=S==null?!!D:vt(S),j=C==null?!!O:vt(C),ne=T==null?!!k:vt(T),M=()=>{let t=[];(!A||this.activePage===`chat`)&&t.push(this.loadHistory()),(!j||this.activePage===`tasks`)&&t.push(this.loadTasks(e)),(!ne||this.activePage===`files`)&&t.push(this.loadFiles(e)),Promise.all(t).catch(e=>{console.warn(`Secondary background store loads failed:`,e)})};if(o)typeof window.requestIdleCallback==`function`?window.requestIdleCallback(M,{timeout:2e3}):setTimeout(M,100);else{let t=[];(!A||this.activePage===`chat`)&&t.push(this.loadHistory()),(!j||this.activePage===`tasks`)&&t.push(this.loadTasks(e)),(!ne||this.activePage===`files`)&&t.push(this.loadFiles(e)),await Promise.all(t)}await L(),this._initResolve?.(),this.scheduleBackgroundStaticMainSiteSeeding(e)}async loadFiles(e){let t=this._activeGroupId.get(),n=this._currentPath.get();try{this._storageStatus.set(await u(e));let r=await G(e,t,n);this._files.set(r)}catch(e){console.error(`Failed to load files in store:`,e)}}async loadGroups(e){let t=await I(e);this._groups.set(t)}async loadHistory(){let e=this._activeGroupId.get(),t=await ie(e,200);this._activeGroupId.get()===e&&this._messages.set(t)}async loadTasks(e){let t=this._activeGroupId.get(),n=await A(e),r=n.filter(e=>e.groupId===t);r.sort((e,t)=>{let n=e.order??0,r=t.order??0;return n===r?e.createdAt-t.createdAt:n-r}),this._tasks.set(r);let i=await this.getSubscriberId(e),a=await Ct(t,this.getTaskServerBaseUrl(),i,this.orchestrator?.taskServerEnabled??!1);if(!a)return;let o=new Set(n.map(e=>e.id)),s=a.filter(e=>!o.has(e.id));if(s.length===0)return;for(let t of s)await B(e,t);let c=[...r,...s];c.sort((e,t)=>{let n=e.order??0,r=t.order??0;return n===r?e.createdAt-t.createdAt:n-r}),this._tasks.set(c)}async navigateBackFolder(e){let t=this._currentPath.get();if(t===`.`)return;let n=t.split(`/`).filter(Boolean);n.pop();let r=n.length===0?`.`:n.join(`/`);await this.setCurrentPath(e,r)}async navigateIntoFolder(e,t){let n=this._currentPath.get(),r=n===`.`?t.replace(/\/$/,``):`${n}/${t.replace(/\/$/,``)}`;try{await this.setCurrentPath(e,r)}catch(t){console.error(`Failed to navigate into folder in store:`,t),Z(`Folder not found: ${r}`,4500),await this.loadFiles(e)}}async newSession(e){await this.orchestrator?.newSession?.(e,this._activeGroupId.get()),await this.loadHistory()}async removePage(t,n,r=this._activeGroupId.get()){let i=this.normalizePagePath(n);if(!i)return;let a=this._pages.get();if(!a.some(e=>e.path===i&&e.groupId===r))return;let o=a.filter(e=>e.path!==i||e.groupId!==r);await Ke(t,r,i);let s=r===`br:main`&&i===`MEMORY.md`;s&&await U(t,!0);let c=s||await H(t);if(o.length===0&&!c){if(await W(t,`br:main`))o.push({groupId:y,path:e.DEFAULT_PAGE_PATH});else return}this.setPages(o);let l=this._defaultPinnedPage.get();l&&l.path===i&&l.groupId===r&&await this.setDefaultPinnedPage(t,null),await this.persistPages(t)}async removeAllPages(e){let t=[...this._pages.get()];for(let n of t)await Ke(e,n.groupId,n.path),n.groupId===`br:main`&&n.path===`MEMORY.md`&&await U(e,!0);this.setPages([]),await this.setDefaultPinnedPage(e,null),await this.setActivePinnedPage(e,null),await this.persistPages(e)}async renameConversation(e,t,n){await ce(e,t,n),await this.loadGroups(e)}async reorderConversations(e,t){await de(e,t),await this.loadGroups(e)}async reorderTasks(e,t,n){let r=await je(e,t,n);await this.loadTasks(e);let i=await this.getSubscriberId(e);for(let t of r)await Q(t,this.getTaskServerBaseUrl(),i,this.orchestrator?.taskServerEnabled??!1)||(console.warn(`Failed to sync reordered task "${t.id}" to server — queued for replay.`),await this.queueTaskSyncOutboxOperation(e,{type:`upsert`,id:t.id,task:t,queuedAt:Date.now()}))}async replayTaskSyncOutbox(e){if(!(this._replayingTaskSyncOutbox||this._taskSyncOutbox.length===0)){this._replayingTaskSyncOutbox=!0;try{let t=await this.getSubscriberId(e),n=[];for(let e of this._taskSyncOutbox){let r=this.getTaskServerBaseUrl();(e.type===`upsert`?await Q(e.task,r,t,this.orchestrator?.taskServerEnabled??!1):await $(e.id,r,t,this.orchestrator?.taskServerEnabled??!1))||n.push(e)}this._taskSyncOutbox=this.compactTaskSyncOutbox(n),await this.persistTaskSyncOutbox(e)}finally{this._replayingTaskSyncOutbox=!1}}}async resetToRootFolder(e){await this.setCurrentPath(e,`.`)}async restartCurrentRequest(){return this.orchestrator?.restartCurrentRequest?this.orchestrator.restartCurrentRequest(this._activeGroupId.get()):!1}async restoreTasksFromBackup(e,t){await this.clearAllTasks(e);let n=this._activeGroupId.get();for(let r of t){let t={...r,groupId:n,id:crypto.randomUUID?crypto.randomUUID():`task-${Date.now()}-${Math.random()}`};await this.upsertTask(e,t,{reloadTasks:!1})}await this.loadTasks(e)}async runTask(e,t=!1){let n=this._db;if(t&&n&&(await Ae(e.id,Date.now()),await this.loadTasks(n)),e.type===`tools`&&Array.isArray(e.tools)&&e.tools.length>0){if(this.orchestrator?.agentWorker){let n=e.subagent?`subagent:${c()}`:e.groupId;this.orchestrator.agentWorker.postMessage({type:`execute-task-tools`,payload:{groupId:n,tools:e.tools,isManual:t}})}else console.error(`Agent worker not available to execute tool task.`)}else{if(!e.groupId){console.error(`Task ${e.id} has no groupId - refusing to execute in active conversation to prevent context pollution.`);return}this.orchestrator?.browserChat?.submit(e.prompt,e.groupId,[],void 0,e.freshContext,e.subagent)}}async setActivePage(e,t){this._activePage.set(t),await O(e,b.LAST_ACTIVE_PAGE,t);let n=this.resolveSidebarDefaultPageForActivePage(t);n!==this._sidebarDefaultPage.get()&&(this._sidebarDefaultPage.set(n),await O(e,b.SIDEBAR_DEFAULT_PAGE,n))}async setActivePinnedPage(e,t){t&&!this.isPageAllowed(t.path,t.groupId)&&(t=this.effectiveDefaultPage),this._activePinnedPage.set(t),t?await O(e,b.LAST_SELECTED_PINNED_PAGE,JSON.stringify(t)):await O(e,b.LAST_SELECTED_PINNED_PAGE,null)}async setDefaultPinnedPage(e,t){if(t&&!this.isPageAllowed(t.path,t.groupId))return;let n=this._defaultPinnedPage.get(),r=n&&t&&n.path===t.path&&n.groupId===t.groupId?null:t;this._defaultPinnedPage.set(r),r?await O(e,b.DEFAULT_PINNED_PAGE,JSON.stringify(r)):await O(e,b.DEFAULT_PINNED_PAGE,null)}async reorderPages(e,t){this.setPages(t),await this.persistPages(e)}async setCurrentPath(e,t){let n=t.replace(/^\/+|\/+$/g,``)||`.`,r=this._activeGroupId.get();this._storageStatus.set(await u(e));let i=await G(e,r,n);this._currentPath.set(n),this._files.set(i)}async setGitProxyUrl(e,t){this.orchestrator&&(await xe(this.orchestrator,e,t),this._gitProxyUrl.set(this.orchestrator.gitProxyUrl))}async setProxyUrl(e,t){this.orchestrator&&(await Se(this.orchestrator,e,t),this._proxyUrl.set(this.orchestrator.proxyUrl))}async setUseProxy(e,t){this.orchestrator&&(await Ce(this.orchestrator,e,t),this._useProxy.set(this.orchestrator.useProxy))}async setVMBashFullInternetAccess(e,t){this.orchestrator&&(await we(this.orchestrator,e,t),this._vmBashFullInternetAccess.set(this.orchestrator.vmBashFullInternetAccess))}async switchConversation(e,t,n){this.setActiveGroup(e,t,n??this._activePage.get()===`chat`),await O(e,b.LAST_ACTIVE_GROUP,t)}async toggleTask(e,t,n){let r={...t,enabled:n};await B(e,r),await this.loadTasks(e),await Q(r,this.getTaskServerBaseUrl(),await this.getSubscriberId(e),this.orchestrator?.taskServerEnabled??!1)||(console.warn(`Failed to update task on server — queued for replay.`),await this.queueTaskSyncOutboxOperation(e,{type:`upsert`,id:r.id,task:r,queuedAt:Date.now()}))}async updateConversationPinnedProvider(e,t,n,r,i){await pe(e,t,n,r,i),await this.loadGroups(e)}async updateConversationProviderRuntimeOverrides(e,t,n){await he(e,t,n),await this.loadGroups(e)}async updateConversationSubagentSettings(e,t,n,r,i,a){await me(e,t,n,r,i,a),await this.loadGroups(e)}async updateConversationToolTags(e,t,n){await le(e,t,n),await this.loadGroups(e)}async upsertTask(e,t,n){let r=n?.reloadTasks!==!1;await B(e,t),r&&await this.loadTasks(e);let i=await this.getSubscriberId(e);await Q(t,this.getTaskServerBaseUrl(),i,this.orchestrator?.taskServerEnabled??!1)||(console.warn(`Failed to sync task to server — queued for replay.`),await this.queueTaskSyncOutboxOperation(e,{type:`upsert`,id:t.id,task:t,queuedAt:Date.now()}))}compactTaskSyncOutbox(e){let t=/* @__PURE__ */ new Map;return e.forEach((e,n)=>{t.set(e.id,n)}),e.filter((e,n)=>t.get(e.id)===n)}deriveGroupName(e){return e.startsWith(`tg:`)?`Telegram ${e.slice(3)}`:e.startsWith(`im:`)?`iMessage ${e.slice(3)}`:e.startsWith(`br:`)?e===`br:main`?`Main`:`Browser Conversation`:`Conversation`}getActivityLogSessionStartedAt(e){let t=this._activityLogSessionStartedAtByGroup.get(e);if(t)return t;let n=(/* @__PURE__ */ new Date()).toISOString();return this._activityLogSessionStartedAtByGroup.set(e,n),n}getTaskServerBaseUrl(){return this.orchestrator?.taskServerUrl??`/schedule`}async getSubscriberId(e){if(this._subscriberId)return this._subscriberId;let t=await ke(e);return this._subscriberId=t,t}normalizePagePath(t){let n=t.trim().replace(/^\/+/,``).replace(/\/+/g,`/`);return n===`main/memory.md`?e.DEFAULT_PAGE_PATH:n}normalizeSidebarDefaultPage(e){return e===`pages`||e===`chat`||e===`tasks`||e===`files`?e:`chat`}parsePagesList(e){if(!e)return[];try{let t=JSON.parse(e);return Array.isArray(t)?t.map(e=>{if(typeof e==`string`)return{groupId:y,path:this.normalizePagePath(e)};if(!e||typeof e!=`object`)return null;let t=e;if(typeof t.path!=`string`)return null;let n=typeof t.groupId==`string`&&t.groupId.trim().length>0?t.groupId:y,r=n===`br:main`?this.normalizePagePath(t.path):t.path.trim();return r?{groupId:n,path:r}:null}).filter(e=>!!e).filter((e,t,n)=>{let r=`${e.groupId}\u0000${e.path}`;return t===n.findIndex(e=>`${e.groupId}\u0000${e.path}`===r)}):[]}catch{return[]}}parseTaskSyncOutbox(e){if(!e)return[];try{let t=JSON.parse(e);if(!Array.isArray(t))return[];let n=t.filter(e=>!!e&&typeof e==`object`).filter(e=>e.type===`upsert`||e.type===`delete`).filter(e=>typeof e.id==`string`&&e.id.length>0).map(e=>({...e,queuedAt:typeof e.queuedAt==`number`?e.queuedAt:Date.now()}));return this.compactTaskSyncOutbox(n)}catch{return[]}}resolveSidebarDefaultPageForActivePage(e){return e===`pages`||e===`chat`||e===`tasks`||e===`files`?e:this._sidebarDefaultPage.get()}setPages(e){let t=e.filter(e=>this.isPageAllowed(e.path,e.groupId)),n=t.filter(e=>e.path.toLowerCase()===`memory.md`),r=t.filter(e=>e.path.toLowerCase()!==`memory.md`);this._pages.set([...r,...n])}async ensureDefaultPage(t){if(await H(t))return;let n=await W(t,y);await Le(t,y),!(!n||this._pages.get().length>0)&&(this.setPages([{groupId:y,path:e.DEFAULT_PAGE_PATH}]),await this.persistPages(t))}async ensureGroupExists(e,t,n){let r=this._groups.get();if(r.some(e=>e.groupId===t))return;let i=[...r,{groupId:t,name:this.deriveGroupName(t),createdAt:n||Date.now()}];this._groups.set(i);try{await F(e,i)}catch(e){console.error(`Failed to persist new conversation metadata:`,e)}}async forwardActivityLogEntryToServer(e){if(!this._db||!xt(await w(this._db,b.ACTIVITY_LOG_DISK_LOGGING_ENABLED)))return;let t=typeof e.groupId==`string`&&e.groupId?e.groupId:this._activeGroupId.get();if(!t)return;let n=typeof e.message==`string`?e.message.trim():``;if(!n)return;e.level===`info`&&e.label===`Starting`&&this._activityLogSessionStartedAtByGroup.set(t,(/* @__PURE__ */ new Date()).toISOString());let r=this.getActivityLogSessionStartedAt(t);try{await fetch(`/activity-log`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({groupId:t,level:e.level,label:e.label,message:n,timestamp:(/* @__PURE__ */ new Date()).toISOString(),sessionStartedAt:r})})}catch(e){console.warn(`Failed to persist activity log entry to server:`,e)}}scheduleBackgroundStaticMainSiteSeeding(e){if(typeof window>`u`)return;let t=async()=>{try{if(await Ye(e,`br:main`))return;let t=await w(e,b.PAGES_LIST),n=t==null?[]:this.parsePagesList(t),r=await ct(e,y,n,{preferEmbedded:!1});r&&r.length>0&&(this.setPages(r),await this.persistPages(e))}catch(e){console.warn(`Background static main site seeding failed:`,e)}};typeof window.requestIdleCallback==`function`?window.requestIdleCallback(()=>void t(),{timeout:3e3}):setTimeout(()=>void t(),100)}async persistPages(e){await O(e,b.PAGES_LIST,JSON.stringify(this._pages.get()))}async persistTaskSyncOutbox(e){await O(e,b.TASK_SYNC_OUTBOX,JSON.stringify(this._taskSyncOutbox))}async queueTaskSyncOutboxOperation(e,t){this._taskSyncOutbox=this.compactTaskSyncOutbox([...this._taskSyncOutbox,t]),await this.persistTaskSyncOutbox(e)}async applySiteConfigDefaults(e){if(typeof document<`u`)try{let n=re();if(!n||typeof n!=`object`)return;_(n),ee(),h();let r=n.customElements;if((await I(e)).find(e=>e.groupId===`br:main`)?.toolTags&&await le(e,y,void 0),(n.settings?.internetAccess??n.settings?.vm_bash_full_internet_access??n.settings?.fullInternetAccess??n.internetAccess)===!0&&await w(e,b.VM_BASH_FULL_INTERNET_ACCESS)!==`true`&&(await O(e,b.VM_BASH_FULL_INTERNET_ACCESS,`true`),this.orchestrator&&(this.orchestrator.vmBashFullInternetAccess=!0),this._vmBashFullInternetAccess.set(!0)),n.pages&&typeof n.pages==`object`){let{defaultPinnedPage:t}=n.pages;if(t&&typeof t==`string`){let n=i(t);n&&this.isPageAllowed(n.path,n.groupId)&&(this._defaultPinnedPage.set(n),await O(e,b.DEFAULT_PINNED_PAGE,JSON.stringify(n)))}}let a=n.allowedCustomElements||(typeof r==`object`&&!Array.isArray(r)?r.allowedElements:void 0);a!==void 0&&(await w(e,b.ALLOWED_CUSTOM_ELEMENTS)??await O(e,b.ALLOWED_CUSTOM_ELEMENTS,JSON.stringify(a)));let o=n.allowedCustomElementDomains||(typeof r==`object`&&!Array.isArray(r)?r.allowedDomains:void 0);if(o!==void 0&&(await w(e,b.ALLOWED_CUSTOM_ELEMENT_HOST_PATTERNS)??await O(e,b.ALLOWED_CUSTOM_ELEMENT_HOST_PATTERNS,JSON.stringify(o))),n.sidebar&&typeof n.sidebar==`object`){let{pagesHidden:t,chatHidden:r,tasksHidden:i,filesHidden:a,defaultPage:o}=n.sidebar;if(t!==void 0&&(await w(e,b.SIDEBAR_PAGES_HIDDEN)??await O(e,b.SIDEBAR_PAGES_HIDDEN,String(!!t))),r!==void 0&&(await w(e,b.SIDEBAR_CHAT_HIDDEN)??await O(e,b.SIDEBAR_CHAT_HIDDEN,String(!!r))),i!==void 0&&(await w(e,b.SIDEBAR_TASKS_HIDDEN)??await O(e,b.SIDEBAR_TASKS_HIDDEN,String(!!i))),a!==void 0&&(await w(e,b.SIDEBAR_FILES_HIDDEN)??await O(e,b.SIDEBAR_FILES_HIDDEN,String(!!a))),o&&typeof o==`string`){let t=this.normalizeSidebarDefaultPage(o);this._sidebarDefaultPage.set(t),await w(e,b.SIDEBAR_DEFAULT_PAGE)||await O(e,b.SIDEBAR_DEFAULT_PAGE,o)}}if(n.settings&&typeof n.settings==`object`){let{assistantName:t,defaultProvider:r,provider:i,defaultModel:a,model:o}=n.settings;t&&typeof t==`string`&&(await w(e,b.ASSISTANT_NAME)||await O(e,b.ASSISTANT_NAME,t));let s=r??i;if(typeof s==`string`&&s.trim().length>0&&!await w(e,b.PROVIDER)){let t=s.trim();await O(e,b.PROVIDER,t),this.orchestrator&&(this.orchestrator.provider=t)}let c=a??o;if(typeof c==`string`&&c.trim().length>0&&!await w(e,b.MODEL)){let t=c.trim();await O(e,b.MODEL,t),this.orchestrator&&(this.orchestrator.model=t)}let l=n.settings.internetAccess??n.settings.vm_bash_full_internet_access??n.settings.fullInternetAccess??n.internetAccess;typeof l==`boolean`&&(await w(e,b.VM_BASH_FULL_INTERNET_ACCESS)??(await O(e,b.VM_BASH_FULL_INTERNET_ACCESS,String(l)),this.orchestrator&&(this.orchestrator.vmBashFullInternetAccess=l),this._vmBashFullInternetAccess.set(l)))}let s=(n.settings&&typeof n.settings==`object`?n.settings.defaultToolsProfile:void 0)??n.defaultToolsProfile;if(typeof s==`string`&&s.trim().length>0&&!await w(e,b.ACTIVE_TOOL_PROFILE)){let t=s.trim();if(t.toLowerCase()===`none`)await j.deactivateProfile(e);else{let n=j.profiles.find(e=>e.id.toLowerCase()===t.toLowerCase()||e.name.toLowerCase()===t.toLowerCase());n?await j.activateProfile(e,n.id):console.warn(`Default tools profile "${t}" specified in site-config was not found.`)}}if(n.pages&&typeof n.pages==`object`){let{defaultPinnedPage:t}=n.pages;t&&typeof t==`string`&&(await w(e,b.DEFAULT_PINNED_PAGE)||await O(e,b.DEFAULT_PINNED_PAGE,t))}let c=n.pages?.allowList??n.pages?.allowlist??n.allowList??n.allowlist,l=n.pages?.denyList??n.pages?.denylist??n.denyList??n.denylist;if(Array.isArray(c)&&await w(e,b.PAGES_ALLOW_LIST)==null){let n=t(c.map(String));this._pagesAllowList.set(n),await O(e,b.PAGES_ALLOW_LIST,JSON.stringify(n))}if(Array.isArray(l)&&await w(e,b.PAGES_DENY_LIST)==null){let n=t(l.map(String));this._pagesDenyList.set(n),await O(e,b.PAGES_DENY_LIST,JSON.stringify(n))}await O(e,b.SITE_CONFIG_SEEDED,`true`);let u=this._pages.get(),d=u.filter(e=>this.isPageAllowed(e.path,e.groupId));d.length!==u.length&&(this.setPages(d),await this.persistPages(e));let f=this._activePinnedPage.get();f&&!this.isPageAllowed(f.path,f.groupId)&&await this.setActivePinnedPage(e,this.effectiveDefaultPage);let p=this._defaultPinnedPage.get();if(p&&!this.isPageAllowed(p.path,p.groupId)&&await this.setDefaultPinnedPage(e,null),Array.isArray(n.enabledTools)){let t=n.enabledTools.filter(e=>typeof e==`string`&&e.trim().length>0);await j.setAllEnabled(e,t),await j.setAllDeclarativeEnabled(e,t)}await O(e,b.SITE_CONFIG_SEEDED,`true`)}catch(e){console.warn(`Failed to apply site-config defaults:`,e)}}};const Et=new Tt;export{I as _,dt as a,G as c,B as d,z as f,_e as g,ge as h,_t as i,U as l,R as m,wt as n,Ke as o,ke as p,Et as r,q as s,Tt as t,Ie as u,ie as v};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export{n as runWebRtcListenCommand}from"./chunk-Dw8GndPD.js";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export{r as orchestratorStore}from"./chunk-Bj5qFsDi.js";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export{t as getAgentCore}from"./chunk-C8DBACtx.js";
|