shadow-claw 1.59.7 → 1.60.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.well-known/mcp/server-card.json +4 -12
- package/.well-known/mcp.json +4 -12
- package/README.md +6 -2
- package/dist/cli/build/build.js +1 -1
- package/dist/cli/{chunk-DDvuLVfW.js → chunk-3C5izdQW.js} +1 -1
- package/dist/cli/chunk-B-75h9gX.js +1 -0
- package/dist/cli/{chunk-hVf839t7.js → chunk-B7Kn-otm.js} +1 -1
- package/dist/cli/{chunk-YX32FcN7.js → chunk-BBczgswQ.js} +1 -1
- package/dist/cli/{chunk-DcNxjqH6.js → chunk-BE-lYWcn.js} +1 -1
- package/dist/cli/{chunk-CQaCgswD.js → chunk-BECr0WxI.js} +11 -11
- package/dist/cli/chunk-BEz1PD1_.js +1 -0
- package/dist/cli/chunk-BLzI1Fp2.js +1 -0
- package/dist/cli/{chunk-B3TrWbca.js → chunk-BVSC1MNQ.js} +11 -11
- package/dist/cli/{chunk-D_te8ufL.js → chunk-BdWcep6o.js} +1 -1
- package/dist/cli/{chunk-SRBRVorc.js → chunk-BfTpnSS4.js} +1 -1
- package/dist/cli/{chunk-D2_eAO83.js → chunk-BgvqTf7w.js} +1 -1
- package/dist/cli/chunk-BwsJfUT3.js +1 -0
- package/dist/cli/{chunk--PFY91kE.js → chunk-C9b4b7c_.js} +1 -1
- package/dist/cli/{chunk-SxK79JmB.js → chunk-CAw9XYFe.js} +1 -1
- package/dist/cli/chunk-CFCcbFs2.js +396 -0
- package/dist/cli/{chunk-Cnjb8Usu.js → chunk-CTarF4FC.js} +1 -1
- package/dist/cli/{chunk-3vNYrs_L.js → chunk-Cbq5hpjb.js} +4 -4
- package/dist/cli/chunk-CjTjKy_v.js +310 -0
- package/dist/cli/chunk-Cjyu4cr_.js +36 -0
- package/dist/cli/{chunk-DUGZPka_.js → chunk-ClMKygjZ.js} +1 -1
- package/dist/cli/chunk-Cppnq1KF.js +1 -0
- package/dist/cli/{chunk-DvemF16v.js → chunk-D9QCNFMO.js} +1 -1
- package/dist/cli/{chunk-iB8OoMmW.js → chunk-DB21BMqt.js} +1 -1
- package/dist/cli/{chunk-_Vo-o_e3.js → chunk-DHoIWvCc.js} +1 -1
- package/dist/cli/chunk-DZEN9T5y.js +1 -0
- package/dist/cli/{chunk-5rLO4DWS.js → chunk-Dl14OyYO.js} +9 -9
- package/dist/cli/chunk-Dl_vv0dI.js +1 -0
- package/dist/cli/chunk-Dpmfhlyl.js +1 -0
- package/dist/cli/{chunk-BrR1DOBS.js → chunk-Du7Xtucq.js} +1 -1
- package/dist/cli/{chunk-B88Z8T_9.js → chunk-DxcDFUi_.js} +1 -1
- package/dist/cli/{chunk-Dt7-hzJU.js → chunk-DyyEWbV7.js} +1 -1
- package/dist/cli/chunk-N0x3mXU0.js +1 -0
- package/dist/cli/{chunk-CGoE4llV.js → chunk-V-w0Bata.js} +1 -1
- package/dist/cli/{chunk-CncW6_WL.js → chunk-ZxDxSSn-.js} +1 -1
- package/dist/cli/{chunk-CZdCRqNe.js → chunk-lPvFUkd5.js} +1 -1
- package/dist/cli/{chunk-66BvqAV0.js → chunk-n5s-sCdU.js} +1 -1
- package/dist/cli/{chunk-CAAeGOdy.js → chunk-nD9VPVMq.js} +1 -1
- package/dist/cli/{chunk-DMs7kREC.js → chunk-rFuy8aS_.js} +1 -1
- package/dist/cli/{chunk-B0qusANw.js → chunk-wjM6JXWa.js} +1 -1
- package/dist/cli/{chunk-DhOU6GYX.js → chunk-zcES9rut.js} +1 -1
- package/dist/cli/cli.js +3 -3
- package/dist/headless-agent.js +1 -1
- package/dist/lib/{channel-mmdGzPkT.js → channel-DB77spML.js} +2 -2
- package/dist/lib/{channel-mmdGzPkT.js.map → channel-DB77spML.js.map} +1 -1
- package/dist/lib/{compact-context-CY9BBlUQ.js → compact-context-Q9t9aL1e.js} +7 -7
- package/dist/lib/{compact-context-CY9BBlUQ.js.map → compact-context-Q9t9aL1e.js.map} +1 -1
- package/dist/lib/components/index.js +21 -21
- 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-llm.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-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-llm.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-pages.js +1 -1
- package/dist/lib/components/shadow-claw-peerjs.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/{configure-peer-js-ccNvax2N.js → configure-peer-js-CgFiwoxY.js} +2 -2
- package/dist/lib/{configure-peer-js-ccNvax2N.js.map → configure-peer-js-CgFiwoxY.js.map} +1 -1
- package/dist/lib/content/build-attachment-content-blocks.d.ts +2 -0
- package/dist/lib/{discover-skills-OwlQ2sXA.js → discover-skills-CXyaWHKi.js} +5 -5
- package/dist/lib/{discover-skills-OwlQ2sXA.js.map → discover-skills-CXyaWHKi.js.map} +1 -1
- package/dist/lib/{git-D2J_j9X9.js → git-CogDRlEz.js} +2 -2
- package/dist/lib/{git-D2J_j9X9.js.map → git-CogDRlEz.js.map} +1 -1
- package/dist/lib/index.js +21 -21
- package/dist/lib/{init-control-plane-B7blDVIE.js → init-control-plane-CEGdzgWX.js} +7 -7
- package/dist/lib/{init-control-plane-B7blDVIE.js.map → init-control-plane-CEGdzgWX.js.map} +1 -1
- package/dist/lib/{invoke-agent-SxvudiDT.js → invoke-agent-cac3gCsj.js} +6 -6
- package/dist/lib/{invoke-agent-SxvudiDT.js.map → invoke-agent-cac3gCsj.js.map} +1 -1
- package/dist/lib/{move-group-entry-DDpjxa10.js → move-group-entry-D8dptMg0.js} +2 -2
- package/dist/lib/{move-group-entry-DDpjxa10.js.map → move-group-entry-D8dptMg0.js.map} +1 -1
- package/dist/lib/{orchestrator-C7fkh7T7.js → orchestrator-BBAwy9Nm.js} +12 -12
- package/dist/lib/{orchestrator-C7fkh7T7.js.map → orchestrator-BBAwy9Nm.js.map} +1 -1
- package/dist/lib/{orchestrator-CCARkxQC.js → orchestrator-cRBe3lhq.js} +2 -2
- package/dist/lib/{orchestrator-CCARkxQC.js.map → orchestrator-cRBe3lhq.js.map} +1 -1
- package/dist/lib/{peerjs-Bfw_FWLB.js → peerjs-BLg8aGUj.js} +3 -3
- package/dist/lib/{peerjs-Bfw_FWLB.js.map → peerjs-BLg8aGUj.js.map} +1 -1
- package/dist/lib/{process-peer-query-param-BxYiZNdf.js → process-peer-query-param-BnsVnxzH.js} +5 -5
- package/dist/lib/{process-peer-query-param-BxYiZNdf.js.map → process-peer-query-param-BnsVnxzH.js.map} +1 -1
- package/dist/lib/{process-pending-shared-payloads-DPIbwRb3.js → process-pending-shared-payloads-DBZfZOOa.js} +2 -2
- package/dist/lib/{process-pending-shared-payloads-DPIbwRb3.js.map → process-pending-shared-payloads-DBZfZOOa.js.map} +1 -1
- package/dist/lib/{process-room-query-param-B2_d50nE.js → process-room-query-param-B8EYg_-r.js} +4 -4
- package/dist/lib/{process-room-query-param-B2_d50nE.js.map → process-room-query-param-B8EYg_-r.js.map} +1 -1
- package/dist/lib/{push-client-rrjTdc-U.js → push-client-CAm6UMvE.js} +3 -3
- package/dist/lib/{push-client-rrjTdc-U.js.map → push-client-CAm6UMvE.js.map} +1 -1
- package/dist/lib/{rooms-bwGoYb1q.js → rooms-Dzphx3rK.js} +2 -2
- package/dist/lib/{rooms-bwGoYb1q.js.map → rooms-Dzphx3rK.js.map} +1 -1
- package/dist/lib/{shadow-claw-CypGVlVO.js → shadow-claw-CGl8tXtG.js} +6 -6
- package/dist/lib/{shadow-claw-CypGVlVO.js.map → shadow-claw-CGl8tXtG.js.map} +1 -1
- package/dist/lib/{shadow-claw-channel-config-DJpDovkF.js → shadow-claw-channel-config-BNIWCdsL.js} +4 -4
- package/dist/lib/{shadow-claw-channel-config-DJpDovkF.js.map → shadow-claw-channel-config-BNIWCdsL.js.map} +1 -1
- package/dist/lib/{shadow-claw-channels-DJLwRovH.js → shadow-claw-channels-C2QSn4Ew.js} +2 -2
- package/dist/lib/{shadow-claw-channels-DJLwRovH.js.map → shadow-claw-channels-C2QSn4Ew.js.map} +1 -1
- package/dist/lib/{shadow-claw-chat-B92cPaft.js → shadow-claw-chat-Wx3y9y6c.js} +3 -3
- package/dist/lib/{shadow-claw-chat-B92cPaft.js.map → shadow-claw-chat-Wx3y9y6c.js.map} +1 -1
- package/dist/lib/{shadow-claw-control-plane-fvn-qyHj.js → shadow-claw-control-plane-D5E4cFGu.js} +6 -6
- package/dist/lib/{shadow-claw-control-plane-fvn-qyHj.js.map → shadow-claw-control-plane-D5E4cFGu.js.map} +1 -1
- package/dist/lib/{shadow-claw-conversations-CsVyDOny.js → shadow-claw-conversations-BtDv7GRW.js} +2 -2
- package/dist/lib/{shadow-claw-conversations-CsVyDOny.js.map → shadow-claw-conversations-BtDv7GRW.js.map} +1 -1
- package/dist/lib/{shadow-claw-file-viewer-DFfyP7s5.js → shadow-claw-file-viewer-CG40kwWV.js} +2 -2
- package/dist/lib/{shadow-claw-file-viewer-DFfyP7s5.js.map → shadow-claw-file-viewer-CG40kwWV.js.map} +1 -1
- package/dist/lib/{shadow-claw-files-cT6HL7ye.js → shadow-claw-files-BOUULrlX.js} +3 -3
- package/dist/lib/{shadow-claw-files-cT6HL7ye.js.map → shadow-claw-files-BOUULrlX.js.map} +1 -1
- package/dist/lib/{shadow-claw-git-Cv9mQgTx.js → shadow-claw-git-BeHV73_9.js} +3 -3
- package/dist/lib/{shadow-claw-git-Cv9mQgTx.js.map → shadow-claw-git-BeHV73_9.js.map} +1 -1
- package/dist/lib/{shadow-claw-llm-CKOYzPDp.js → shadow-claw-llm-KONyWKZM.js} +2 -2
- package/dist/lib/{shadow-claw-llm-CKOYzPDp.js.map → shadow-claw-llm-KONyWKZM.js.map} +1 -1
- package/dist/lib/{shadow-claw-networking-DYfiUQaH.js → shadow-claw-networking-Diy3JJkc.js} +2 -2
- package/dist/lib/{shadow-claw-networking-DYfiUQaH.js.map → shadow-claw-networking-Diy3JJkc.js.map} +1 -1
- package/dist/lib/{shadow-claw-notifications-JJlzriuX.js → shadow-claw-notifications-C-upPa-4.js} +2 -2
- package/dist/lib/{shadow-claw-notifications-JJlzriuX.js.map → shadow-claw-notifications-C-upPa-4.js.map} +1 -1
- package/dist/lib/{shadow-claw-pages-BCo3ihZI.js → shadow-claw-pages-CfAjUKgd.js} +2 -2
- package/dist/lib/{shadow-claw-pages-BCo3ihZI.js.map → shadow-claw-pages-CfAjUKgd.js.map} +1 -1
- package/dist/lib/{shadow-claw-peerjs-CFNjfrY5.js → shadow-claw-peerjs-t4YibS9s.js} +5 -5
- package/dist/lib/{shadow-claw-peerjs-CFNjfrY5.js.map → shadow-claw-peerjs-t4YibS9s.js.map} +1 -1
- package/dist/lib/{shadow-claw-settings-BMwne0bh.js → shadow-claw-settings-Cg5V0e9g.js} +2 -2
- package/dist/lib/{shadow-claw-settings-BMwne0bh.js.map → shadow-claw-settings-Cg5V0e9g.js.map} +1 -1
- package/dist/lib/{shadow-claw-storage-DUY8B9m-.js → shadow-claw-storage-C7tCnsSG.js} +2 -2
- package/dist/lib/{shadow-claw-storage-DUY8B9m-.js.map → shadow-claw-storage-C7tCnsSG.js.map} +1 -1
- package/dist/lib/{shadow-claw-task-server-yWeoA3eL.js → shadow-claw-task-server-BObsRdf8.js} +2 -2
- package/dist/lib/{shadow-claw-task-server-yWeoA3eL.js.map → shadow-claw-task-server-BObsRdf8.js.map} +1 -1
- package/dist/lib/{shadow-claw-tasks-Bg0uM15I.js → shadow-claw-tasks-B2EEqrcY.js} +3 -3
- package/dist/lib/{shadow-claw-tasks-Bg0uM15I.js.map → shadow-claw-tasks-B2EEqrcY.js.map} +1 -1
- package/dist/lib/{shadow-claw-terminal-fyJPppY_.js → shadow-claw-terminal-DSHfO2b9.js} +2 -2
- package/dist/lib/{shadow-claw-terminal-fyJPppY_.js.map → shadow-claw-terminal-DSHfO2b9.js.map} +1 -1
- package/dist/lib/{shadow-claw-tools-D0T8m3go.js → shadow-claw-tools-DwPBADua.js} +3 -3
- package/dist/lib/{shadow-claw-tools-D0T8m3go.js.map → shadow-claw-tools-DwPBADua.js.map} +1 -1
- package/dist/lib/{shadow-claw-webvm-CQvzJwKI.js → shadow-claw-webvm-CY4qGaMB.js} +2 -2
- package/dist/lib/{shadow-claw-webvm-CQvzJwKI.js.map → shadow-claw-webvm-CY4qGaMB.js.map} +1 -1
- package/dist/lib/{sync-web-mcp-registration-BFtG_4kx.js → sync-web-mcp-registration-BiOZvW-R.js} +3 -3
- package/dist/lib/{sync-web-mcp-registration-BFtG_4kx.js.map → sync-web-mcp-registration-BiOZvW-R.js.map} +1 -1
- package/dist/lib/{system-prompt-bhGRLoL2.js → system-prompt-CxJ3Nx4c.js} +4 -3
- package/dist/lib/system-prompt-CxJ3Nx4c.js.map +1 -0
- package/dist/public/.well-known/mcp/server-card.json +4 -12
- package/dist/public/.well-known/mcp.json +4 -12
- package/dist/public/AGENTS.md +3 -1
- package/dist/public/README.md +6 -2
- package/dist/public/agent.worker.js +1 -1
- package/dist/public/{channel-Dk7wl-Av.js → channel-DIpDQekL.js} +1 -1
- package/dist/public/{chat-template-BwAnTFKf.js → chat-template-CXKs8lFR.js} +1 -1
- package/dist/public/compact-context-BQ2ZXoAc.js +5 -0
- package/dist/public/{compact-context-fOTqwKF6.js → compact-context-dHitmPsV.js} +2 -2
- package/dist/public/{configure-peer-js-BOV0tR6G.js → configure-peer-js-DV1rqvFX.js} +1 -1
- package/dist/public/{create-model-cache-fetch-DSAFjOwc.js → create-model-cache-fetch-B0mSCEk6.js} +1 -1
- package/dist/public/{discover-skills-D1sNTy2r.js → discover-skills-BWJB8HUA.js} +1 -1
- package/dist/public/docs/architecture/overview.md +1 -1
- package/dist/public/docs/example/article/index.html +21 -21
- package/dist/public/docs/example/article.html +21 -21
- package/dist/public/docs/publishing/index.html +21 -21
- package/dist/public/docs/publishing.html +21 -21
- package/dist/public/docs/skill-creator/index.html +21 -21
- package/dist/public/docs/skill-creator.html +21 -21
- package/dist/public/docs/subsystems/attachment-capabilities.md +14 -1
- package/dist/public/docs/subsystems/cli.md +95 -51
- package/dist/public/docs/subsystems/pages.md +5 -0
- package/dist/public/e2e/README.md +1 -1
- package/dist/public/{e2e-bridge-Cz95DLlb.js → e2e-bridge-lP2qqiv3.js} +1 -1
- package/dist/public/{git-BmMlwIMP.js → git-DjmQ16rm.js} +1 -1
- package/dist/public/{iframe-bridge-scripts-Cibg0m6A.js → iframe-bridge-scripts-CO0izGjW.js} +1 -1
- package/dist/public/index.html +21 -21
- package/dist/public/index.js +1 -1
- package/dist/public/{init-control-plane-Cb31yLTY.js → init-control-plane-Ctz7FI8M.js} +1 -1
- package/dist/public/{invoke-agent-CN7mSV0Z.js → invoke-agent-C_geruwq.js} +1 -1
- package/dist/public/llms.txt +1 -1
- package/dist/public/main/index.html +21 -21
- package/dist/public/main/memory/index.html +21 -21
- package/dist/public/main/memory.html +21 -21
- package/dist/public/main.html +21 -21
- package/dist/public/{move-group-entry-CXneuNVa.js → move-group-entry-QQ9Hkk54.js} +1 -1
- package/dist/public/{orchestrator-Dyylc8IU.js → orchestrator-C1kaTltu.js} +2 -2
- package/dist/public/{orchestrator-DBO4NZqd.js → orchestrator-Li1UAsv7.js} +1 -1
- package/dist/public/{peerjs-l0jiBoh6.js → peerjs-DbBryE-9.js} +1 -1
- package/dist/public/{process-peer-query-param-s-aSP1Rq.js → process-peer-query-param-DQIgr3KL.js} +1 -1
- package/dist/public/{process-pending-shared-payloads-BN3GigPT.js → process-pending-shared-payloads-Ctb-TFqB.js} +1 -1
- package/dist/public/{process-room-query-param-B2Qe0F0M.js → process-room-query-param-F-XnIVoZ.js} +1 -1
- package/dist/public/{push-client-B2LC8Qp9.js → push-client-DRx9Eggz.js} +1 -1
- package/dist/public/{rooms-ChCEOvkw.js → rooms-BurBI7is.js} +1 -1
- package/dist/public/service-worker/init.js +1 -1
- package/dist/public/service-worker.js +1 -1
- package/dist/public/{shadow-claw-Br8mWDUx.js → shadow-claw-Bg9AQ5x_.js} +2 -2
- package/dist/public/{shadow-claw-accounts-Dm6G7KMP.js → shadow-claw-accounts-B3mjYI0M.js} +1 -1
- package/dist/public/{shadow-claw-card-CggS8uSa.js → shadow-claw-card-tcXRS1GF.js} +1 -1
- package/dist/public/{shadow-claw-channels-088vhuWO.js → shadow-claw-channels-BiSfLvWv.js} +1 -1
- package/dist/public/{shadow-claw-chat-BRwRlq-n.js → shadow-claw-chat-N5jMsXZZ.js} +1 -1
- package/dist/public/{shadow-claw-control-plane-rhKACK85.js → shadow-claw-control-plane-DFVe_Xdq.js} +2 -2
- package/dist/public/{shadow-claw-conversations-CF_yUfKl.js → shadow-claw-conversations-wAR06_ya.js} +1 -1
- package/dist/public/{shadow-claw-empty-state-CkpOSXCS.js → shadow-claw-empty-state-CnPm3NVM.js} +1 -1
- package/dist/public/{shadow-claw-file-viewer-DWCejuY3.js → shadow-claw-file-viewer-sZN_FCDW.js} +2 -2
- package/dist/public/{shadow-claw-files-L6_ioyzh.js → shadow-claw-files-CnvkCbd4.js} +2 -2
- package/dist/public/{shadow-claw-git-DsdkwLqQ.js → shadow-claw-git-BBHfClGk.js} +2 -2
- package/dist/public/{shadow-claw-integrations-CSbRTOm3.js → shadow-claw-integrations-DvdBqzRJ.js} +1 -1
- package/dist/public/{shadow-claw-llm-BitaeAVc.js → shadow-claw-llm-YfohG519.js} +1 -1
- package/dist/public/{shadow-claw-mcp-remote-gSbV5riy.js → shadow-claw-mcp-remote-BAVbf5pi.js} +1 -1
- package/dist/public/{shadow-claw-networking-Dn_y6Cl9.js → shadow-claw-networking-CZ4LWPW7.js} +1 -1
- package/dist/public/{shadow-claw-notifications-Cj4Lqx8U.js → shadow-claw-notifications-BHwyREkG.js} +1 -1
- package/dist/public/{shadow-claw-page-header-DR4OZFt2.js → shadow-claw-page-header-De6Qf6eY.js} +1 -1
- package/dist/public/{shadow-claw-page-header-action-button-BnCV_2Kb.js → shadow-claw-page-header-action-button-FSOhTc9z.js} +1 -1
- package/dist/public/{shadow-claw-pages-mpDOtNYj.js → shadow-claw-pages-D_oPyDca.js} +1 -1
- package/dist/public/{shadow-claw-pdf-viewer-DZ_84qJH.js → shadow-claw-pdf-viewer-CrU4wqRq.js} +1 -1
- package/dist/public/{shadow-claw-settings-CfFTYTEy.js → shadow-claw-settings-DkUhvxVr.js} +2 -2
- package/dist/public/{shadow-claw-storage-DLmiT4bG.js → shadow-claw-storage-D0o56Tjw.js} +1 -1
- package/dist/public/{shadow-claw-task-server-BoMBCsiS.js → shadow-claw-task-server-4rkroO9K.js} +1 -1
- package/dist/public/{shadow-claw-tasks-ChEp1j7x.js → shadow-claw-tasks-BdP7lmvu.js} +1 -1
- package/dist/public/{shadow-claw-terminal-BaoVbOda.js → shadow-claw-terminal-DVHX7Fsu.js} +1 -1
- package/dist/public/{shadow-claw-toast-e8oz7z6Z.js → shadow-claw-toast-B9Y9tSkW.js} +1 -1
- package/dist/public/{shadow-claw-tools-BYjUBiJz.js → shadow-claw-tools-BwwY53Lr.js} +1 -1
- package/dist/public/{shadow-claw-webvm-xGb13TME.js → shadow-claw-webvm-CXGdkCNM.js} +1 -1
- package/dist/public/{sync-web-mcp-registration-CQluj-Kz.js → sync-web-mcp-registration-DVK_IhXZ.js} +1 -1
- package/dist/public/{system-prompt-CTJn0tK-.js → system-prompt-BmswoQwF.js} +2 -2
- package/dist/public/{workbox-92eae37e.js → workbox-e4022e15.js} +1 -1
- package/dist/public/{zip-reader-DN7FB-Q0.js → zip-reader-JHoTbATw.js} +1 -1
- package/dist/server.js +5 -5
- package/package.json +1 -1
- package/dist/cli/chunk-2gZFafgY.js +0 -1
- package/dist/cli/chunk-BCjL0JXf.js +0 -1
- package/dist/cli/chunk-BNcu1oiT.js +0 -1
- package/dist/cli/chunk-BUNoeMKY.js +0 -36
- package/dist/cli/chunk-C5ypckWC.js +0 -225
- package/dist/cli/chunk-CFxww5Yz.js +0 -1
- package/dist/cli/chunk-CGIgtL6R.js +0 -1
- package/dist/cli/chunk-CafdvLx-.js +0 -1
- package/dist/cli/chunk-Dhap1VwA.js +0 -1
- package/dist/cli/chunk-Ds5-K-9o.js +0 -1
- package/dist/cli/chunk-DwvavohW.js +0 -1
- package/dist/cli/chunk-_a0CkUNS.js +0 -139
- package/dist/lib/system-prompt-bhGRLoL2.js.map +0 -1
- package/dist/public/compact-context-CX4H8V57.js +0 -5
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import{i as e,o as t,t as n}from"./chunk-B--rR4-3.js";import{r,t as i}from"./chunk-BuzahJu2.js";import{t as a}from"./chunk-BU-vs0np.js";import{n as o}from"./chunk-DPoeMCv9.js";import{n as s,t as c}from"./chunk-DVKHLRUO.js";import{n as l,t as u}from"./chunk-1VdYkt-J.js";import{existsSync as d}from"node:fs";import{dirname as f,join as p,sep as m}from"node:path";import{fileURLToPath as h}from"node:url";import g from"process";import{randomBytes as _}from"node:crypto";import{Buffer as ee}from"buffer";import{Worker as v}from"node:worker_threads";var y=/* @__PURE__ */ t((/* @__PURE__ */ n(((t,n)=>{var r=void 0,i=function(t){return r||(r=new Promise(function(r,i){var a=t===void 0?{}:t,o=a.onAbort;a.onAbort=function(e){i(Error(e)),o&&o(e)},a.postRun=a.postRun||[],a.postRun.push(function(){r(a)}),n=void 0;var s;s||=a===void 0?{}:a;var c=!!globalThis.window,l=!!globalThis.WorkerGlobalScope,u=globalThis.process?.versions?.node&&globalThis.process?.type!=`renderer`;s.onRuntimeInitialized=function(){function e(e,t){switch(typeof t){case`boolean`:A(e,+!!t);break;case`number`:de(e,t);break;case`string`:pe(e,t,-1,-1);break;case`object`:if(t===null)fe(e);else if(t.length!=null){var n=It(t.length);C.set(t,n),me(e,n,t.length,-1),Lt(n)}else j(e,`Wrong API use : tried to return a value of an unknown type (`+t+`).`,-1);break;default:fe(e)}}function t(e,t){for(var n=[],r=0;r<e;r+=1){var i=M(t+4*r,`i32`),a=oe(i);if(a===1||a===2)i=ue(i);else if(a===3)i=ce(i);else if(a===4){a=i,i=se(a),a=le(a);for(var o=new Uint8Array(i),s=0;s<i;s+=1)o[s]=C[a+s];i=o}else i=null;n.push(i)}return n}function n(e,t){this.Qa=e,this.db=t,this.Oa=1,this.mb=[]}function r(e,t){if(this.db=t,this.fb=At(e),this.fb===null)throw Error(`Unable to allocate memory for the SQL string`);this.lb=this.fb,this.$a=this.sb=null}function i(e){if(this.filename=`dbfile_`+(4294967295*Math.random()>>>0),e!=null){var t=this.filename,n=`/`,r=t;if(n&&(n=typeof n==`string`?n:Be(n),r=t?ve(n+`/`+t):n),t=je(!0,!0),r=nt(r,t),e){if(typeof e==`string`){n=Array(e.length);for(var i=0,o=e.length;i<o;++i)n[i]=e.charCodeAt(i);e=n}lt(r,t|146),n=dt(r,577),ht(n,e,0,e.length,0),ft(n),lt(r,t)}}this.handleError(c(this.filename,a)),this.db=M(a,`i32`),he(this.db),this.gb={},this.Sa={}}var a=Q(4),o=s.cwrap,c=o(`sqlite3_open`,`number`,[`string`,`number`]),l=o(`sqlite3_close_v2`,`number`,[`number`]),u=o(`sqlite3_exec`,`number`,[`number`,`string`,`number`,`number`,`number`]),d=o(`sqlite3_changes`,`number`,[`number`]),f=o(`sqlite3_prepare_v2`,`number`,[`number`,`string`,`number`,`number`,`number`]),p=o(`sqlite3_sql`,`string`,[`number`]),m=o(`sqlite3_normalized_sql`,`string`,[`number`]),h=o(`sqlite3_prepare_v2`,`number`,[`number`,`number`,`number`,`number`,`number`]),g=o(`sqlite3_bind_text`,`number`,[`number`,`number`,`number`,`number`,`number`]),_=o(`sqlite3_bind_blob`,`number`,[`number`,`number`,`number`,`number`,`number`]),ee=o(`sqlite3_bind_double`,`number`,[`number`,`number`,`number`]),v=o(`sqlite3_bind_int`,`number`,[`number`,`number`,`number`]),y=o(`sqlite3_bind_parameter_index`,`number`,[`number`,`string`]),b=o(`sqlite3_step`,`number`,[`number`]),x=o(`sqlite3_errmsg`,`string`,[`number`]),te=o(`sqlite3_column_count`,`number`,[`number`]),ne=o(`sqlite3_data_count`,`number`,[`number`]),S=o(`sqlite3_column_double`,`number`,[`number`,`number`]),w=o(`sqlite3_column_text`,`string`,[`number`,`number`]),T=o(`sqlite3_column_blob`,`number`,[`number`,`number`]),E=o(`sqlite3_column_bytes`,`number`,[`number`,`number`]),D=o(`sqlite3_column_type`,`number`,[`number`,`number`]),re=o(`sqlite3_column_name`,`string`,[`number`,`number`]),ie=o(`sqlite3_reset`,`number`,[`number`]),O=o(`sqlite3_clear_bindings`,`number`,[`number`]),ae=o(`sqlite3_finalize`,`number`,[`number`]),k=o(`sqlite3_create_function_v2`,`number`,`number string number number number number number number number`.split(` `)),oe=o(`sqlite3_value_type`,`number`,[`number`]),se=o(`sqlite3_value_bytes`,`number`,[`number`]),ce=o(`sqlite3_value_text`,`string`,[`number`]),le=o(`sqlite3_value_blob`,`number`,[`number`]),ue=o(`sqlite3_value_double`,`number`,[`number`]),de=o(`sqlite3_result_double`,``,[`number`,`number`]),fe=o(`sqlite3_result_null`,``,[`number`]),pe=o(`sqlite3_result_text`,``,[`number`,`string`,`number`,`number`]),me=o(`sqlite3_result_blob`,``,[`number`,`number`,`number`,`number`]),A=o(`sqlite3_result_int`,``,[`number`,`number`]),j=o(`sqlite3_result_error`,``,[`number`,`string`,`number`]),N=o(`sqlite3_aggregate_context`,`number`,[`number`,`number`]),he=o(`RegisterExtensionFunctions`,`number`,[`number`]),ge=o(`sqlite3_update_hook`,`number`,[`number`,`number`,`number`]);n.prototype.bind=function(e){if(!this.Qa)throw`Statement closed`;return this.reset(),Array.isArray(e)?this.Gb(e):typeof e==`object`&&e?this.Hb(e):!0},n.prototype.step=function(){if(!this.Qa)throw`Statement closed`;this.Oa=1;var e=b(this.Qa);switch(e){case 100:return!0;case 101:return!1;default:throw this.db.handleError(e)}},n.prototype.Ab=function(e){return e??(e=this.Oa,this.Oa+=1),S(this.Qa,e)},n.prototype.Ob=function(e){if(e??(e=this.Oa,this.Oa+=1),e=w(this.Qa,e),typeof BigInt!=`function`)throw Error(`BigInt is not supported`);return BigInt(e)},n.prototype.Tb=function(e){return e??(e=this.Oa,this.Oa+=1),w(this.Qa,e)},n.prototype.getBlob=function(e){e??(e=this.Oa,this.Oa+=1);var t=E(this.Qa,e);e=T(this.Qa,e);for(var n=new Uint8Array(t),r=0;r<t;r+=1)n[r]=C[e+r];return n},n.prototype.get=function(e,t){t||={},e!=null&&this.bind(e)&&this.step(),e=[];for(var n=ne(this.Qa),r=0;r<n;r+=1)switch(D(this.Qa,r)){case 1:var i=t.useBigInt?this.Ob(r):this.Ab(r);e.push(i);break;case 2:e.push(this.Ab(r));break;case 3:e.push(this.Tb(r));break;case 4:e.push(this.getBlob(r));break;default:e.push(null)}return e},n.prototype.qb=function(){for(var e=[],t=te(this.Qa),n=0;n<t;n+=1)e.push(re(this.Qa,n));return e},n.prototype.zb=function(e,t){e=this.get(e,t),t=this.qb();for(var n={},r=0;r<t.length;r+=1)n[t[r]]=e[r];return n},n.prototype.Sb=function(){return p(this.Qa)},n.prototype.Pb=function(){return m(this.Qa)},n.prototype.run=function(e){return e!=null&&this.bind(e),this.step(),this.reset()},n.prototype.wb=function(e,t){t??(t=this.Oa,this.Oa+=1),e=At(e),this.mb.push(e),this.db.handleError(g(this.Qa,t,e,-1,0))},n.prototype.Fb=function(e,t){t??(t=this.Oa,this.Oa+=1);var n=It(e.length);C.set(e,n),this.mb.push(n),this.db.handleError(_(this.Qa,t,n,e.length,0))},n.prototype.vb=function(e,t){t??(t=this.Oa,this.Oa+=1),this.db.handleError((e===(e|0)?v:ee)(this.Qa,t,e))},n.prototype.Ib=function(e){e??(e=this.Oa,this.Oa+=1),_(this.Qa,e,0,0,0)},n.prototype.xb=function(e,t){switch(t??(t=this.Oa,this.Oa+=1),typeof e){case`string`:this.wb(e,t);return;case`number`:this.vb(e,t);return;case`bigint`:this.wb(e.toString(),t);return;case`boolean`:this.vb(e+0,t);return;case`object`:if(e===null){this.Ib(t);return}if(e.length!=null){this.Fb(e,t);return}}throw`Wrong API use : tried to bind a value of an unknown type (`+e+`).`},n.prototype.Hb=function(e){var t=this;return Object.keys(e).forEach(function(n){var r=y(t.Qa,n);r!==0&&t.xb(e[n],r)}),!0},n.prototype.Gb=function(e){for(var t=0;t<e.length;t+=1)this.xb(e[t],t+1);return!0},n.prototype.reset=function(){return this.freemem(),O(this.Qa)===0&&ie(this.Qa)===0},n.prototype.freemem=function(){for(var e;(e=this.mb.pop())!==void 0;)Lt(e)},n.prototype.Ya=function(){this.freemem();var e=ae(this.Qa)===0;return delete this.db.gb[this.Qa],this.Qa=0,e},r.prototype.next=function(){if(this.fb===null)return{done:!0};if(this.$a!==null&&(this.$a.Ya(),this.$a=null),!this.db.db)throw this.ob(),Error(`Database closed`);var e=Vt(),t=Q(4);P(a),P(t);try{this.db.handleError(h(this.db.db,this.lb,-1,a,t)),this.lb=M(t,`i32`);var r=M(a,`i32`);return r===0?(this.ob(),{done:!0}):(this.$a=new n(r,this.db),this.db.gb[r]=this.$a,{value:this.$a,done:!1})}catch(e){throw this.sb=F(this.lb),this.ob(),e}finally{Bt(e)}},r.prototype.ob=function(){Lt(this.fb),this.fb=null},r.prototype.Qb=function(){return this.sb===null?F(this.lb):this.sb},typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`&&(r.prototype[Symbol.iterator]=function(){return this}),i.prototype.run=function(e,t){if(!this.db)throw`Database closed`;if(t){e=this.tb(e,t);try{e.step()}finally{e.Ya()}}else this.handleError(u(this.db,e,0,0,a));return this},i.prototype.exec=function(e,t,r){if(!this.db)throw`Database closed`;var i=Vt(),o=null,s=null,c=null;try{c=s=At(e);var l=Q(4);for(e=[];M(c,`i8`)!==0;){P(a),P(l),this.handleError(h(this.db,c,-1,a,l));var u=M(a,`i32`);if(c=M(l,`i32`),u!==0){var d=null;for(o=new n(u,this),t!=null&&o.bind(t);o.step();)d===null&&(d={columns:o.qb(),values:[]},e.push(d)),d.values.push(o.get(null,r));o.Ya()}}return e}catch(e){throw o&&o.Ya(),e}finally{s&&Lt(s),Bt(i)}},i.prototype.Mb=function(e,t,n,r,i){typeof t==`function`&&(r=n,n=t,t=void 0),e=this.tb(e,t);try{for(;e.step();)n(e.zb(null,i))}finally{e.Ya()}if(typeof r==`function`)return r()},i.prototype.tb=function(e,t){if(P(a),this.handleError(f(this.db,e,-1,a,0)),e=M(a,`i32`),e===0)throw`Nothing to prepare`;var r=new n(e,this);return t!=null&&r.bind(t),this.gb[e]=r},i.prototype.Ub=function(e){return new r(e,this)},i.prototype.Nb=function(){Object.values(this.gb).forEach(function(e){e.Ya()}),Object.values(this.Sa).forEach(Z),this.Sa={},this.handleError(l(this.db));var e=gt(this.filename);return this.handleError(c(this.filename,a)),this.db=M(a,`i32`),he(this.db),e},i.prototype.close=function(){this.db!==null&&(Object.values(this.gb).forEach(function(e){e.Ya()}),Object.values(this.Sa).forEach(Z),this.Sa={},this.Za&&=(Z(this.Za),void 0),this.handleError(l(this.db)),ot(`/`+this.filename),this.db=null)},i.prototype.handleError=function(e){if(e===0)return null;throw e=x(this.db),Error(e)},i.prototype.Rb=function(){return d(this.db)},i.prototype.Kb=function(n,r){Object.prototype.hasOwnProperty.call(this.Sa,n)&&(Z(this.Sa[n]),delete this.Sa[n]);var i=Ft(function(n,i,a){i=t(i,a);try{var o=r.apply(null,i)}catch(e){j(n,e,-1);return}e(n,o)},`viii`);return this.Sa[n]=i,this.handleError(k(this.db,n,r.length,1,0,i,0,0,0)),this},i.prototype.Jb=function(n,r){var i=r.init||function(){return null},a=r.finalize||function(e){return e},o=r.step;if(!o)throw`An aggregate function must have a step function in `+n;var s={};Object.hasOwnProperty.call(this.Sa,n)&&(Z(this.Sa[n]),delete this.Sa[n]),r=n+`__finalize`,Object.hasOwnProperty.call(this.Sa,r)&&(Z(this.Sa[r]),delete this.Sa[r]);var c=Ft(function(e,n,r){var a=N(e,1);Object.hasOwnProperty.call(s,a)||(s[a]=i()),n=t(n,r),n=[s[a]].concat(n);try{s[a]=o.apply(null,n)}catch(t){delete s[a],j(e,t,-1)}},`viii`),l=Ft(function(t){var n=N(t,1);try{var r=a(s[n])}catch(e){delete s[n],j(t,e,-1);return}e(t,r),delete s[n]},`vi`);return this.Sa[n]=c,this.Sa[r]=l,this.handleError(k(this.db,n,o.length-1,1,0,0,c,l,0)),this},i.prototype.Zb=function(e){return this.Za&&=(ge(this.db,0,0),Z(this.Za),void 0),e&&(this.Za=Ft(function(t,n,r,i,a){switch(n){case 18:t=`insert`;break;case 23:t=`update`;break;case 9:t=`delete`;break;default:throw`unknown operationCode in updateHook callback: `+n}if(r=F(r),i=F(i),a>2**53-1)throw`rowId too big to fit inside a Number`;e(t,r,i,Number(a))},`viiiij`),ge(this.db,this.Za,0)),this},n.prototype.bind=n.prototype.bind,n.prototype.step=n.prototype.step,n.prototype.get=n.prototype.get,n.prototype.getColumnNames=n.prototype.qb,n.prototype.getAsObject=n.prototype.zb,n.prototype.getSQL=n.prototype.Sb,n.prototype.getNormalizedSQL=n.prototype.Pb,n.prototype.run=n.prototype.run,n.prototype.reset=n.prototype.reset,n.prototype.freemem=n.prototype.freemem,n.prototype.free=n.prototype.Ya,r.prototype.next=r.prototype.next,r.prototype.getRemainingSQL=r.prototype.Qb,i.prototype.run=i.prototype.run,i.prototype.exec=i.prototype.exec,i.prototype.each=i.prototype.Mb,i.prototype.prepare=i.prototype.tb,i.prototype.iterateStatements=i.prototype.Ub,i.prototype.export=i.prototype.Nb,i.prototype.close=i.prototype.close,i.prototype.handleError=i.prototype.handleError,i.prototype.getRowsModified=i.prototype.Rb,i.prototype.create_function=i.prototype.Kb,i.prototype.create_aggregate=i.prototype.Jb,i.prototype.updateHook=i.prototype.Zb,s.Database=i};var d=`./this.program`,f=(e,t)=>{throw t},p=globalThis.document?.currentScript?.src;typeof __filename<`u`?p=__filename:l&&(p=self.location.href);var m=``,h,_;if(u){var v=e(`node:fs`);m=__dirname+`/`,_=e=>(e=S(e)?new URL(e):e,v.readFileSync(e)),h=async e=>(e=S(e)?new URL(e):e,v.readFileSync(e,void 0)),1<g.argv.length&&(d=g.argv[1].replace(/\\/g,`/`)),g.argv.slice(2),n!==void 0&&(n.exports=s),f=(e,t)=>{throw g.exitCode=e,t}}else if(c||l){try{m=new URL(`.`,p).href}catch{}l&&(_=e=>{var t=new XMLHttpRequest;return t.open(`GET`,e,!1),t.responseType=`arraybuffer`,t.send(null),new Uint8Array(t.response)}),h=async e=>{if(S(e))return new Promise((t,n)=>{var r=new XMLHttpRequest;r.open(`GET`,e,!0),r.responseType=`arraybuffer`,r.onload=()=>{r.status==200||r.status==0&&r.response?t(r.response):n(r.status)},r.onerror=n,r.send(null)});var t=await fetch(e,{credentials:`same-origin`});if(t.ok)return t.arrayBuffer();throw Error(t.status+` : `+t.url)}}var y=console.log.bind(console),b=console.error.bind(console),x,te=!1,ne,S=e=>e.startsWith(`file://`),C,w,T,E,D,re,ie,O;function ae(){var e=Ht.buffer;C=new Int8Array(e),T=new Int16Array(e),w=new Uint8Array(e),new Uint16Array(e),E=new Int32Array(e),D=new Uint32Array(e),re=new Float32Array(e),ie=new Float64Array(e),O=new BigInt64Array(e),new BigUint64Array(e)}function k(e){throw s.onAbort?.(e),e=`Aborted(`+e+`)`,b(e),te=!0,new WebAssembly.RuntimeError(e+`. Build with -sASSERTIONS for more info.`)}var oe;async function se(e){if(!x)try{var t=await h(e);return new Uint8Array(t)}catch{}if(e==oe&&x)e=new Uint8Array(x);else if(_)e=_(e);else throw`both async and sync fetching of the wasm failed`;return e}async function ce(e,t){try{var n=await se(e);return await WebAssembly.instantiate(n,t)}catch(e){b(`failed to asynchronously prepare wasm: ${e}`),k(e)}}async function le(e){var t=oe;if(!x&&!S(t)&&!u)try{var n=fetch(t,{credentials:`same-origin`});return await WebAssembly.instantiateStreaming(n,e)}catch(e){b(`wasm streaming compile failed: ${e}`),b(`falling back to ArrayBuffer instantiation`)}return ce(t,e)}class ue{name=`ExitStatus`;constructor(e){this.message=`Program terminated with exit(${e})`,this.status=e}}var de=e=>{for(;0<e.length;)e.shift()(s)},fe=[],pe=[],me=()=>{var e=s.preRun.shift();pe.push(e)},A=0,j=null;function M(e,t=`i8`){switch(t.endsWith(`*`)&&(t=`*`),t){case`i1`:return C[e];case`i8`:return C[e];case`i16`:return T[e>>1];case`i32`:return E[e>>2];case`i64`:return O[e>>3];case`float`:return re[e>>2];case`double`:return ie[e>>3];case`*`:return D[e>>2];default:k(`invalid type for getValue: ${t}`)}}var N=!0;function P(e){var t=`i32`;switch(t.endsWith(`*`)&&(t=`*`),t){case`i1`:C[e]=0;break;case`i8`:C[e]=0;break;case`i16`:T[e>>1]=0;break;case`i32`:E[e>>2]=0;break;case`i64`:O[e>>3]=BigInt(0);break;case`float`:re[e>>2]=0;break;case`double`:ie[e>>3]=0;break;case`*`:D[e>>2]=0;break;default:k(`invalid type for setValue: ${t}`)}}var he=new TextDecoder,ge=(e,t,n,r)=>{if(n=t+n,r)return n;for(;e[t]&&!(t>=n);)++t;return t},F=(e,t,n)=>e?he.decode(w.subarray(e,ge(w,e,t,n))):``,_e=(e,t)=>{for(var n=0,r=e.length-1;0<=r;r--){var i=e[r];i===`.`?e.splice(r,1):i===`..`?(e.splice(r,1),n++):n&&(e.splice(r,1),n--)}if(t)for(;n;n--)e.unshift(`..`);return e},ve=e=>{var t=e.charAt(0)===`/`,n=e.slice(-1)===`/`;return(e=_e(e.split(`/`).filter(e=>!!e),!t).join(`/`))||t||(e=`.`),e&&n&&(e+=`/`),(t?`/`:``)+e},ye=e=>{var t=/^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/.exec(e).slice(1);return e=t[0],t=t[1],!e&&!t?`.`:(t&&=t.slice(0,-1),e+t)},be=e=>e&&e.match(/([^\/]+|\/)\/*$/)[1],xe=()=>{if(u){var t=e(`node:crypto`);return e=>t.randomFillSync(e)}return e=>crypto.getRandomValues(e)},Se=e=>{(Se=xe())(e)},Ce=(...e)=>{for(var t=``,n=!1,r=e.length-1;-1<=r&&!n;r--){if(n=0<=r?e[r]:`/`,typeof n!=`string`)throw TypeError(`Arguments to path.resolve must be strings`);if(!n)return``;t=n+`/`+t,n=n.charAt(0)===`/`}return t=_e(t.split(`/`).filter(e=>!!e),!n).join(`/`),(n?`/`:``)+t||`.`},we=e=>{var t=ge(e,0);return he.decode(e.buffer?e.subarray(0,t):new Uint8Array(e.slice(0,t)))},Te=[],I=e=>{for(var t=0,n=0;n<e.length;++n){var r=e.charCodeAt(n);127>=r?t++:2047>=r?t+=2:55296<=r&&57343>=r?(t+=4,++n):t+=3}return t},L=(e,t,n,r)=>{if(!(0<r))return 0;var i=n;r=n+r-1;for(var a=0;a<e.length;++a){var o=e.codePointAt(a);if(127>=o){if(n>=r)break;t[n++]=o}else if(2047>=o){if(n+1>=r)break;t[n++]=192|o>>6,t[n++]=128|o&63}else if(65535>=o){if(n+2>=r)break;t[n++]=224|o>>12,t[n++]=128|o>>6&63,t[n++]=128|o&63}else{if(n+3>=r)break;t[n++]=240|o>>18,t[n++]=128|o>>12&63,t[n++]=128|o>>6&63,t[n++]=128|o&63,a++}}return t[n]=0,n-i},Ee=[];function De(e,t){Ee[e]={input:[],output:[],eb:t},$e(e,Oe)}var Oe={open(e){var t=Ee[e.node.rdev];if(!t)throw new V(43);e.tty=t,e.seekable=!1},close(e){e.tty.eb.fsync(e.tty)},fsync(e){e.tty.eb.fsync(e.tty)},read(e,t,n,r){if(!e.tty||!e.tty.eb.Bb)throw new V(60);for(var i=0,a=0;a<r;a++){try{var o=e.tty.eb.Bb(e.tty)}catch{throw new V(29)}if(o===void 0&&i===0)throw new V(6);if(o==null)break;i++,t[n+a]=o}return i&&(e.node.atime=Date.now()),i},write(e,t,n,r){if(!e.tty||!e.tty.eb.ub)throw new V(60);try{for(var i=0;i<r;i++)e.tty.eb.ub(e.tty,t[n+i])}catch{throw new V(29)}return r&&(e.node.mtime=e.node.ctime=Date.now()),i}},ke={Bb(){a:{if(!Te.length){var e=null;if(u){var t=ee.alloc(256),n=0,r=g.stdin.fd;try{n=v.readSync(r,t,0,256)}catch(e){if(e.toString().includes(`EOF`))n=0;else throw e}0<n&&(e=t.slice(0,n).toString(`utf-8`))}else globalThis.window?.prompt&&(e=window.prompt(`Input: `),e!==null&&(e+=`
|
|
2
|
+
`));if(!e){e=null;break a}t=Array(I(e)+1),e=L(e,t,0,t.length),t.length=e,Te=t}e=Te.shift()}return e},ub(e,t){t===null||t===10?(y(we(e.output)),e.output=[]):t!=0&&e.output.push(t)},fsync(e){0<e.output?.length&&(y(we(e.output)),e.output=[])},hc(){return{bc:25856,dc:5,ac:191,cc:35387,$b:[3,28,127,21,4,0,1,0,17,19,26,0,18,15,23,22,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}},ic(){return 0},jc(){return[24,80]}},Ae={ub(e,t){t===null||t===10?(b(we(e.output)),e.output=[]):t!=0&&e.output.push(t)},fsync(e){0<e.output?.length&&(b(we(e.output)),e.output=[])}},R={Wa:null,Xa(){return R.createNode(null,`/`,16895,0)},createNode(e,t,n,r){if((n&61440)==24576||(n&61440)==4096)throw new V(63);return R.Wa||={dir:{node:{Ta:R.La.Ta,Ua:R.La.Ua,lookup:R.La.lookup,ib:R.La.ib,rename:R.La.rename,unlink:R.La.unlink,rmdir:R.La.rmdir,readdir:R.La.readdir,symlink:R.La.symlink},stream:{Va:R.Ma.Va}},file:{node:{Ta:R.La.Ta,Ua:R.La.Ua},stream:{Va:R.Ma.Va,read:R.Ma.read,write:R.Ma.write,jb:R.Ma.jb,kb:R.Ma.kb}},link:{node:{Ta:R.La.Ta,Ua:R.La.Ua,readlink:R.La.readlink},stream:{}},yb:{node:{Ta:R.La.Ta,Ua:R.La.Ua},stream:Qe}},n=Ue(e,t,n,r),W(n.mode)?(n.La=R.Wa.dir.node,n.Ma=R.Wa.dir.stream,n.Na={}):(n.mode&61440)==32768?(n.La=R.Wa.file.node,n.Ma=R.Wa.file.stream,n.Ra=0,n.Na=null):(n.mode&61440)==40960?(n.La=R.Wa.link.node,n.Ma=R.Wa.link.stream):(n.mode&61440)==8192&&(n.La=R.Wa.yb.node,n.Ma=R.Wa.yb.stream),n.atime=n.mtime=n.ctime=Date.now(),e&&(e.Na[t]=n,e.atime=e.mtime=e.ctime=n.atime),n},fc(e){return e.Na?e.Na.subarray?e.Na.subarray(0,e.Ra):new Uint8Array(e.Na):/* @__PURE__ */ new Uint8Array},La:{Ta(e){var t={};return t.dev=(e.mode&61440)==8192?e.id:1,t.ino=e.id,t.mode=e.mode,t.nlink=1,t.uid=0,t.gid=0,t.rdev=e.rdev,t.size=W(e.mode)?4096:(e.mode&61440)==32768?e.Ra:(e.mode&61440)==40960?e.link.length:0,t.atime=new Date(e.atime),t.mtime=new Date(e.mtime),t.ctime=new Date(e.ctime),t.blksize=4096,t.blocks=Math.ceil(t.size/t.blksize),t},Ua(e,t){for(var n of[`mode`,`atime`,`mtime`,`ctime`])t[n]!=null&&(e[n]=t[n]);t.size!==void 0&&(t=t.size,e.Ra!=t&&(t==0?(e.Na=null,e.Ra=0):(n=e.Na,e.Na=new Uint8Array(t),n&&e.Na.set(n.subarray(0,Math.min(t,e.Ra))),e.Ra=t)))},lookup(){throw R.nb||(R.nb=new V(44),R.nb.stack=`<generic error, no stack>`),R.nb},ib(e,t,n,r){return R.createNode(e,t,n,r)},rename(e,t,n){try{var r=U(t,n)}catch{}if(r){if(W(e.mode))for(var i in r.Na)throw new V(55);He(r)}delete e.parent.Na[e.name],t.Na[n]=e,e.name=n,t.ctime=t.mtime=e.parent.ctime=e.parent.mtime=Date.now()},unlink(e,t){delete e.Na[t],e.ctime=e.mtime=Date.now()},rmdir(e,t){var n=U(e,t),r;for(r in n.Na)throw new V(55);delete e.Na[t],e.ctime=e.mtime=Date.now()},readdir(e){return[`.`,`..`,...Object.keys(e.Na)]},symlink(e,t,n){return e=R.createNode(e,t,41471,0),e.link=n,e},readlink(e){if((e.mode&61440)!=40960)throw new V(28);return e.link}},Ma:{read(e,t,n,r,i){var a=e.node.Na;if(i>=e.node.Ra)return 0;if(e=Math.min(e.node.Ra-i,r),8<e&&a.subarray)t.set(a.subarray(i,i+e),n);else for(r=0;r<e;r++)t[n+r]=a[i+r];return e},write(e,t,n,r,i,a){if(t.buffer===C.buffer&&(a=!1),!r)return 0;if(e=e.node,e.mtime=e.ctime=Date.now(),t.subarray&&(!e.Na||e.Na.subarray)){if(a)return e.Na=t.subarray(n,n+r),e.Ra=r;if(e.Ra===0&&i===0)return e.Na=t.slice(n,n+r),e.Ra=r;if(i+r<=e.Ra)return e.Na.set(t.subarray(n,n+r),i),r}a=i+r;var o=e.Na?e.Na.length:0;if(o>=a||(a=Math.max(a,o*(1048576>o?2:1.125)>>>0),o!=0&&(a=Math.max(a,256)),o=e.Na,e.Na=new Uint8Array(a),0<e.Ra&&e.Na.set(o.subarray(0,e.Ra),0)),e.Na.subarray&&t.subarray)e.Na.set(t.subarray(n,n+r),i);else for(a=0;a<r;a++)e.Na[i+a]=t[n+a];return e.Ra=Math.max(e.Ra,i+r),r},Va(e,t,n){if(n===1?t+=e.position:n===2&&(e.node.mode&61440)==32768&&(t+=e.node.Ra),0>t)throw new V(28);return t},jb(e,t,n,r,i){if((e.node.mode&61440)!=32768)throw new V(43);if(e=e.node.Na,i&2||!e||e.buffer!==C.buffer){i=!0,r=65536*Math.ceil(t/65536);var a=Rt(65536,r);if(a&&w.fill(0,a,a+r),r=a,!r)throw new V(48);e&&((0<n||n+t<e.length)&&(e=e.subarray?e.subarray(n,n+t):Array.prototype.slice.call(e,n,n+t)),C.set(e,r))}else i=!1,r=e.byteOffset;return{Xb:r,Eb:i}},kb(e,t,n,r){return R.Ma.write(e,t,0,r,n,!1),0}}},je=(e,t)=>{var n=0;return e&&(n|=365),t&&(n|=146),n},Me=null,Ne={},z=[],Pe=1,B=null,Fe=!1,Ie=!0,Le={},V=class{name=`ErrnoError`;constructor(e){this.Pa=e}},Re=class{hb={};node=null;get flags(){return this.hb.flags}set flags(e){this.hb.flags=e}get position(){return this.hb.position}set position(e){this.hb.position=e}},ze=class{La={};Ma={};bb=null;constructor(e,t,n,r){e||=this,this.parent=e,this.Xa=e.Xa,this.id=Pe++,this.name=t,this.mode=n,this.rdev=r,this.atime=this.mtime=this.ctime=Date.now()}get read(){return(this.mode&365)==365}set read(e){e?this.mode|=365:this.mode&=-366}get write(){return(this.mode&146)==146}set write(e){e?this.mode|=146:this.mode&=-147}};function H(e,t={}){if(!e)throw new V(44);t.pb??=!0,e.charAt(0)===`/`||(e=`//`+e);var n=0;a:for(;40>n;n++){e=e.split(`/`).filter(e=>!!e);for(var r=Me,i=`/`,a=0;a<e.length;a++){var o=a===e.length-1;if(o&&t.parent)break;if(e[a]!==`.`){if(e[a]===`..`){if(i=ye(i),r===r.parent){e=i+`/`+e.slice(a+1).join(`/`),n--;continue a}r=r.parent}else{i=ve(i+`/`+e[a]);try{r=U(r,e[a])}catch(e){if(e?.Pa===44&&o&&t.Wb)return{path:i};throw e}if(!r.bb||o&&!t.pb||(r=r.bb.root),(r.mode&61440)==40960&&(!o||t.ab)){if(!r.La.readlink)throw new V(52);r=r.La.readlink(r),r.charAt(0)===`/`||(r=ye(i)+`/`+r),e=r+`/`+e.slice(a+1).join(`/`);continue a}}}}return{path:i,node:r}}throw new V(32)}function Be(e){for(var t;;){if(e===e.parent)return e=e.Xa.Db,t?e[e.length-1]===`/`?e+t:`${e}/${t}`:e;t=t?`${e.name}/${t}`:e.name,e=e.parent}}function Ve(e,t){for(var n=0,r=0;r<t.length;r++)n=(n<<5)-n+t.charCodeAt(r)|0;return(e+n>>>0)%B.length}function He(e){var t=Ve(e.parent.id,e.name);if(B[t]===e)B[t]=e.cb;else for(t=B[t];t;){if(t.cb===e){t.cb=e.cb;break}t=t.cb}}function U(e,t){var n=W(e.mode)?(n=Ge(e,`x`))?n:e.La.lookup?0:2:54;if(n)throw new V(n);for(n=B[Ve(e.id,t)];n;n=n.cb){var r=n.name;if(n.parent.id===e.id&&r===t)return n}return e.La.lookup(e,t)}function Ue(e,t,n,r){return e=new ze(e,t,n,r),t=Ve(e.parent.id,e.name),e.cb=B[t],B[t]=e}function W(e){return(e&61440)==16384}function We(e){var t=[`r`,`w`,`rw`][e&3];return e&512&&(t+=`w`),t}function Ge(e,t){if(Ie)return 0;if(!t.includes(`r`)||e.mode&292){if(t.includes(`w`)&&!(e.mode&146)||t.includes(`x`)&&!(e.mode&73))return 2}else return 2;return 0}function Ke(e,t){if(!W(e.mode))return 54;try{return U(e,t),20}catch{}return Ge(e,`wx`)}function qe(e,t,n){try{var r=U(e,t)}catch(e){return e.Pa}if(e=Ge(e,`wx`))return e;if(n){if(!W(r.mode))return 54;if(r===r.parent||Be(r)===`/`)return 10}else if(W(r.mode))return 31;return 0}function Je(e){if(!e)throw new V(63);return e}function G(e){if(e=z[e],!e)throw new V(8);return e}function Ye(e,t=-1){if(e=Object.assign(new Re,e),t==-1)a:{for(t=0;4096>=t;t++)if(!z[t])break a;throw new V(33)}return e.fd=t,z[t]=e}function Xe(e,t=-1){return e=Ye(e,t),e.Ma?.ec?.(e),e}function Ze(e,t,n){var r=e?.Ma.Ua;e=r?e:t,r??=t.La.Ua,Je(r),r(e,n)}var Qe={open(e){e.Ma=Ne[e.node.rdev].Ma,e.Ma.open?.(e)},Va(){throw new V(70)}};function $e(e,t){Ne[e]={Ma:t}}function et(e,t){var n=t===`/`;if(n&&Me)throw new V(10);if(!n&&t){var r=H(t,{pb:!1});if(t=r.path,r=r.node,r.bb)throw new V(10);if(!W(r.mode))throw new V(54)}t={type:e,kc:{},Db:t,Vb:[]},e=e.Xa(t),e.Xa=t,t.root=e,n?Me=e:r&&(r.bb=t,r.Xa&&r.Xa.Vb.push(t))}function tt(e,t,n){var r=H(e,{parent:!0}).node;if(e=be(e),!e)throw new V(28);if(e===`.`||e===`..`)throw new V(20);var i=Ke(r,e);if(i)throw new V(i);if(!r.La.ib)throw new V(63);return r.La.ib(r,e,t,n)}function nt(e,t=438){return tt(e,t&4095|32768,0)}function K(e,t=511){return tt(e,t&1023|16384,0)}function rt(e,t,n){n===void 0&&(n=t,t=438),tt(e,t|8192,n)}function it(e,t){if(!Ce(e))throw new V(44);var n=H(t,{parent:!0}).node;if(!n)throw new V(44);t=be(t);var r=Ke(n,t);if(r)throw new V(r);if(!n.La.symlink)throw new V(63);n.La.symlink(n,t,e)}function at(e){var t=H(e,{parent:!0}).node;e=be(e);var n=U(t,e),r=qe(t,e,!0);if(r)throw new V(r);if(!t.La.rmdir)throw new V(63);if(n.bb)throw new V(10);t.La.rmdir(t,e),He(n)}function ot(e){var t=H(e,{parent:!0}).node;if(!t)throw new V(44);e=be(e);var n=U(t,e),r=qe(t,e,!1);if(r)throw new V(r);if(!t.La.unlink)throw new V(63);if(n.bb)throw new V(10);t.La.unlink(t,e),He(n)}function st(e,t){return e=H(e,{ab:!t}).node,Je(e.La.Ta)(e)}function ct(e,t,n,r){Ze(e,t,{mode:n&4095|t.mode&-4096,ctime:Date.now(),Lb:r})}function lt(e,t){e=typeof e==`string`?H(e,{ab:!0}).node:e,ct(null,e,t)}function ut(e,t,n){if(W(t.mode))throw new V(31);if((t.mode&61440)!=32768)throw new V(28);var r=Ge(t,`w`);if(r)throw new V(r);Ze(e,t,{size:n,timestamp:Date.now()})}function dt(e,t,n=438){if(e===``)throw new V(44);if(typeof t==`string`){var r={r:0,"r+":2,w:577,"w+":578,a:1089,"a+":1090}[t];if(r===void 0)throw Error(`Unknown file open mode: ${t}`);t=r}if(n=t&64?n&4095|32768:0,typeof e==`object`)r=e;else{var i=e.endsWith(`/`);e=H(e,{ab:!(t&131072),Wb:!0}),r=e.node,e=e.path}var a=!1;if(t&64){if(r){if(t&128)throw new V(20)}else{if(i)throw new V(31);r=tt(e,n|511,0),a=!0}}if(!r)throw new V(44);if((r.mode&61440)==8192&&(t&=-513),t&65536&&!W(r.mode))throw new V(54);if(!a&&(i=r?(r.mode&61440)==40960?32:W(r.mode)&&(We(t)!==`r`||t&576)?31:Ge(r,We(t)):44))throw new V(i);return t&512&&!a&&(i=r,i=typeof i==`string`?H(i,{ab:!0}).node:i,ut(null,i,0)),t&=-131713,i=Ye({node:r,path:Be(r),flags:t,seekable:!0,position:0,Ma:r.Ma,Yb:[],error:!1}),i.Ma.open&&i.Ma.open(i),a&<(r,n&511),!s.logReadFiles||t&1||e in Le||(Le[e]=1),i}function ft(e){if(e.fd===null)throw new V(8);e.rb&&=null;try{e.Ma.close&&e.Ma.close(e)}catch(e){throw e}finally{z[e.fd]=null}e.fd=null}function pt(e,t,n){if(e.fd===null)throw new V(8);if(!e.seekable||!e.Ma.Va)throw new V(70);if(n!=0&&n!=1&&n!=2)throw new V(28);e.position=e.Ma.Va(e,t,n),e.Yb=[]}function mt(e,t,n,r,i){if(0>r||0>i)throw new V(28);if(e.fd===null||(e.flags&2097155)==1)throw new V(8);if(W(e.node.mode))throw new V(31);if(!e.Ma.read)throw new V(28);var a=i!==void 0;if(!a)i=e.position;else if(!e.seekable)throw new V(70);return t=e.Ma.read(e,t,n,r,i),a||(e.position+=t),t}function ht(e,t,n,r,i){if(0>r||0>i)throw new V(28);if(e.fd===null||!(e.flags&2097155))throw new V(8);if(W(e.node.mode))throw new V(31);if(!e.Ma.write)throw new V(28);e.seekable&&e.flags&1024&&pt(e,0,2);var a=i!==void 0;if(!a)i=e.position;else if(!e.seekable)throw new V(70);return t=e.Ma.write(e,t,n,r,i,void 0),a||(e.position+=t),t}function gt(e){var t=t||0,n=`binary`;n!==`utf8`&&n!==`binary`&&k(`Invalid encoding type "${n}"`),t=dt(e,t),e=st(e).size;var r=new Uint8Array(e);return mt(t,r,0,e,0),n===`utf8`&&(r=we(r)),ft(t),r}function q(e,t,n){e=ve(`/dev/`+e);var r=je(!!t,!!n);q.Cb??=64;var i=q.Cb++<<8;$e(i,{open(e){e.seekable=!1},close(){n?.buffer?.length&&n(10)},read(e,n,r,i){for(var a=0,o=0;o<i;o++){try{var s=t()}catch{throw new V(29)}if(s===void 0&&a===0)throw new V(6);if(s==null)break;a++,n[r+o]=s}return a&&(e.node.atime=Date.now()),a},write(e,t,r,i){for(var a=0;a<i;a++)try{n(t[r+a])}catch{throw new V(29)}return i&&(e.node.mtime=e.node.ctime=Date.now()),a}}),rt(e,r,i)}var J={};function Y(e,t,n){if(t.charAt(0)===`/`)return t;if(e=e===-100?`/`:G(e).path,t.length==0){if(!n)throw new V(44);return e}return e+`/`+t}function _t(e,t){D[e>>2]=t.dev,D[e+4>>2]=t.mode,D[e+8>>2]=t.nlink,D[e+12>>2]=t.uid,D[e+16>>2]=t.gid,D[e+20>>2]=t.rdev,O[e+24>>3]=BigInt(t.size),E[e+32>>2]=4096,E[e+36>>2]=t.blocks;var n=t.atime.getTime(),r=t.mtime.getTime(),i=t.ctime.getTime();return O[e+40>>3]=BigInt(Math.floor(n/1e3)),D[e+48>>2]=n%1e3*1e6,O[e+56>>3]=BigInt(Math.floor(r/1e3)),D[e+64>>2]=r%1e3*1e6,O[e+72>>3]=BigInt(Math.floor(i/1e3)),D[e+80>>2]=i%1e3*1e6,O[e+88>>3]=BigInt(t.ino),0}var vt=void 0,yt=()=>{var e=E[vt>>2];return vt+=4,e},bt=0,xt=[0,31,60,91,121,152,182,213,244,274,305,335],St=[0,31,59,90,120,151,181,212,243,273,304,334],Ct={},wt=e=>{ne=e,N||0<bt||(s.onExit?.(e),te=!0),f(e,new ue(e))},Tt=e=>{if(!te)try{e()}catch(e){e instanceof ue||e==`unwind`||f(1,e)}finally{if(!(N||0<bt))try{ne=e=ne,wt(e)}catch(e){e instanceof ue||e==`unwind`||f(1,e)}}},Et={},Dt=()=>{if(!Ot){var e={USER:`web_user`,LOGNAME:`web_user`,PATH:`/`,PWD:`/`,HOME:`/home/web_user`,LANG:(globalThis.navigator?.language??`C`).replace(`-`,`_`)+`.UTF-8`,_:d||`./this.program`},t;for(t in Et)Et[t]===void 0?delete e[t]:e[t]=Et[t];var n=[];for(t in e)n.push(`${t}=${e[t]}`);Ot=n}return Ot},Ot,kt=(e,t,n,r)=>{var i={string:e=>{var t=0;if(e!=null&&e!==0){t=I(e)+1;var n=Q(t);L(e,w,n,t),t=n}return t},array:e=>{var t=Q(e.length);return C.set(e,t),t}};e=s[`_`+e];var a=[],o=0;if(r)for(var c=0;c<r.length;c++){var l=i[n[c]];l?(o===0&&(o=Vt()),a[c]=l(r[c])):a[c]=r[c]}return n=e(...a),n=function(e){return o!==0&&Bt(o),t===`string`?F(e):t===`boolean`?!!e:e}(n)},At=e=>{var t=I(e)+1,n=It(t);return n&&L(e,w,n,t),n},X,jt=[],Z=e=>{X.delete($.get(e)),$.set(e,null),jt.push(e)},Mt=e=>{let t=e.length;return[t%128|128,t>>7,...e]},Nt={i:127,p:127,j:126,f:125,d:124,e:111},Pt=e=>Mt(Array.from(e,e=>Nt[e])),Ft=(e,t)=>{if(!X){X=/* @__PURE__ */ new WeakMap;var n=$.length;if(X)for(var r=0;r<0+n;r++){var i=$.get(r);i&&X.set(i,r)}}if(n=X.get(e)||0)return n;n=jt.length?jt.pop():$.grow(1);try{$.set(n,e)}catch(r){if(!(r instanceof TypeError))throw r;t=Uint8Array.of(0,97,115,109,1,0,0,0,1,...Mt([1,96,...Pt(t.slice(1)),...Pt(t[0]===`v`?``:t[0])]),2,7,1,1,101,1,102,0,0,7,5,1,1,102,0,0),t=new WebAssembly.Module(t),t=new WebAssembly.Instance(t,{e:{f:e}}).exports.f,$.set(n,t)}return X.set(e,n),n};if(B=Array(4096),et(R,`/`),K(`/tmp`),K(`/home`),K(`/home/web_user`),(function(){K(`/dev`),$e(259,{read:()=>0,write:(e,t,n,r)=>r,Va:()=>0}),rt(`/dev/null`,259),De(1280,ke),De(1536,Ae),rt(`/dev/tty`,1280),rt(`/dev/tty1`,1536);var e=/* @__PURE__ */ new Uint8Array(1024),t=0,n=()=>(t===0&&(Se(e),t=e.byteLength),e[--t]);q(`random`,n),q(`urandom`,n),K(`/dev/shm`),K(`/dev/shm/tmp`)})(),(function(){K(`/proc`);var e=K(`/proc/self`);K(`/proc/self/fd`),et({Xa(){var t=Ue(e,`fd`,16895,73);return t.Ma={Va:R.Ma.Va},t.La={lookup(e,t){e=+t;var n=G(e);return e={parent:null,Xa:{Db:`fake`},La:{readlink:()=>n.path},id:e+1},e.parent=e},readdir(){return Array.from(z.entries()).filter(([,e])=>e).map(([e])=>e.toString())}},t}},`/proc/self/fd`)})(),s.noExitRuntime&&(N=s.noExitRuntime),s.print&&(y=s.print),s.printErr&&(b=s.printErr),s.wasmBinary&&(x=s.wasmBinary),s.thisProgram&&(d=s.thisProgram),s.preInit)for(typeof s.preInit==`function`&&(s.preInit=[s.preInit]);0<s.preInit.length;)s.preInit.shift()();s.stackSave=()=>Vt(),s.stackRestore=e=>Bt(e),s.stackAlloc=e=>Q(e),s.cwrap=(e,t,n,r)=>{var i=!n||n.every(e=>e===`number`||e===`boolean`);return t!==`string`&&i&&!r?s[`_`+e]:(...r)=>kt(e,t,n,r)},s.addFunction=Ft,s.removeFunction=Z,s.UTF8ToString=F,s.stringToNewUTF8=At,s.writeArrayToMemory=(e,t)=>{C.set(e,t)};var It,Lt,Rt,zt,Bt,Q,Vt,Ht,$,Ut={a:(e,t,n,r)=>k(`Assertion failed: ${F(e)}, at: `+[t?F(t):`unknown filename`,n,r?F(r):`unknown function`]),i:function(e,t){try{return e=F(e),lt(e,t),0}catch(e){if(J===void 0||e.name!==`ErrnoError`)throw e;return-e.Pa}},L:function(e,t,n){try{if(t=F(t),t=Y(e,t),n&-8)return-28;var r=H(t,{ab:!0}).node;return r?(e=``,n&4&&(e+=`r`),n&2&&(e+=`w`),n&1&&(e+=`x`),e&&Ge(r,e)?-2:0):-44}catch(e){if(J===void 0||e.name!==`ErrnoError`)throw e;return-e.Pa}},j:function(e,t){try{var n=G(e);return ct(n,n.node,t,!1),0}catch(e){if(J===void 0||e.name!==`ErrnoError`)throw e;return-e.Pa}},h:function(e){try{var t=G(e);return Ze(t,t.node,{timestamp:Date.now(),Lb:!1}),0}catch(e){if(J===void 0||e.name!==`ErrnoError`)throw e;return-e.Pa}},b:function(e,t,n){vt=n;try{var r=G(e);switch(t){case 0:var i=yt();if(0>i)break;for(;z[i];)i++;return Xe(r,i).fd;case 1:case 2:return 0;case 3:return r.flags;case 4:return i=yt(),r.flags|=i,0;case 12:return i=yt(),T[i+0>>1]=2,0;case 13:case 14:return 0}return-28}catch(e){if(J===void 0||e.name!==`ErrnoError`)throw e;return-e.Pa}},g:function(e,t){try{var n=G(e),r=n.node,i=n.Ma.Ta;return e=i?n:r,i??=r.La.Ta,Je(i),_t(t,i(e))}catch(e){if(J===void 0||e.name!==`ErrnoError`)throw e;return-e.Pa}},H:function(e,t){t=-9007199254740992>t||9007199254740992<t?NaN:Number(t);try{if(isNaN(t))return-61;var n=G(e);if(0>t||!(n.flags&2097155))throw new V(28);return ut(n,n.node,t),0}catch(e){if(J===void 0||e.name!==`ErrnoError`)throw e;return-e.Pa}},G:function(e,t){try{if(t===0)return-28;var n=I(`/`)+1;return t<n?-68:(L(`/`,w,e,t),n)}catch(e){if(J===void 0||e.name!==`ErrnoError`)throw e;return-e.Pa}},K:function(e,t){try{return e=F(e),_t(t,st(e,!0))}catch(e){if(J===void 0||e.name!==`ErrnoError`)throw e;return-e.Pa}},C:function(e,t,n){try{return t=F(t),t=Y(e,t),K(t,n),0}catch(e){if(J===void 0||e.name!==`ErrnoError`)throw e;return-e.Pa}},J:function(e,t,n,r){try{t=F(t);var i=r&256;return t=Y(e,t,r&4096),_t(n,i?st(t,!0):st(t))}catch(e){if(J===void 0||e.name!==`ErrnoError`)throw e;return-e.Pa}},x:function(e,t,n,r){vt=r;try{t=F(t),t=Y(e,t);var i=r?yt():0;return dt(t,n,i).fd}catch(e){if(J===void 0||e.name!==`ErrnoError`)throw e;return-e.Pa}},v:function(e,t,n,r){try{if(t=F(t),t=Y(e,t),0>=r)return-28;var i=H(t).node;if(!i)throw new V(44);if(!i.La.readlink)throw new V(28);var a=i.La.readlink(i),o=Math.min(r,I(a)),s=C[n+o];return L(a,w,n,r+1),C[n+o]=s,o}catch(e){if(J===void 0||e.name!==`ErrnoError`)throw e;return-e.Pa}},u:function(e){try{return e=F(e),at(e),0}catch(e){if(J===void 0||e.name!==`ErrnoError`)throw e;return-e.Pa}},f:function(e,t){try{return e=F(e),_t(t,st(e))}catch(e){if(J===void 0||e.name!==`ErrnoError`)throw e;return-e.Pa}},r:function(e,t,n){try{if(t=F(t),t=Y(e,t),n){if(n===512)at(t);else return-28}else ot(t);return 0}catch(e){if(J===void 0||e.name!==`ErrnoError`)throw e;return-e.Pa}},q:function(e,t,n){try{t=F(t),t=Y(e,t,!0);var r=Date.now(),i,a;if(n){var o=D[n>>2]+4294967296*E[n+4>>2],s=E[n+8>>2];i=s==1073741823?r:s==1073741822?null:1e3*o+s/1e6,n+=16,o=D[n>>2]+4294967296*E[n+4>>2],s=E[n+8>>2],a=s==1073741823?r:s==1073741822?null:1e3*o+s/1e6}else a=i=r;if((a??i)!==null){e=i;var c=H(t,{ab:!0}).node;Je(c.La.Ua)(c,{atime:e,mtime:a})}return 0}catch(e){if(J===void 0||e.name!==`ErrnoError`)throw e;return-e.Pa}},m:()=>k(``),l:()=>{N=!1,bt=0},A:function(e,t){e=-9007199254740992>e||9007199254740992<e?NaN:Number(e),e=/* @__PURE__ */ new Date(1e3*e),E[t>>2]=e.getSeconds(),E[t+4>>2]=e.getMinutes(),E[t+8>>2]=e.getHours(),E[t+12>>2]=e.getDate(),E[t+16>>2]=e.getMonth(),E[t+20>>2]=e.getFullYear()-1900,E[t+24>>2]=e.getDay();var n=e.getFullYear();E[t+28>>2]=(n%4!=0||n%100==0&&n%400!=0?St:xt)[e.getMonth()]+e.getDate()-1|0,E[t+36>>2]=-(60*e.getTimezoneOffset()),n=new Date(e.getFullYear(),6,1).getTimezoneOffset();var r=new Date(e.getFullYear(),0,1).getTimezoneOffset();E[t+32>>2]=(n!=r&&e.getTimezoneOffset()==Math.min(r,n))|0},y:function(e,t,n,r,i,a,o){i=-9007199254740992>i||9007199254740992<i?NaN:Number(i);try{var s=G(r);if(t&2&&!(n&2)&&(s.flags&2097155)!=2||(s.flags&2097155)==1)throw new V(2);if(!s.Ma.jb)throw new V(43);if(!e)throw new V(28);var c=s.Ma.jb(s,e,i,t,n),l=c.Xb;return E[a>>2]=c.Eb,D[o>>2]=l,0}catch(e){if(J===void 0||e.name!==`ErrnoError`)throw e;return-e.Pa}},z:function(e,t,n,r,i,a){a=-9007199254740992>a||9007199254740992<a?NaN:Number(a);try{var o=G(i);if(n&2){if(n=a,(o.node.mode&61440)!=32768)throw new V(43);if(!(r&2)){var s=w.slice(e,e+t);o.Ma.kb&&o.Ma.kb(o,s,n,t,r)}}}catch(e){if(J===void 0||e.name!==`ErrnoError`)throw e;return-e.Pa}},n:(e,t)=>(Ct[e]&&(clearTimeout(Ct[e].id),delete Ct[e]),t&&(Ct[e]={id:setTimeout(()=>{delete Ct[e],Tt(()=>zt(e,performance.now()))},t),lc:t}),0),B:(e,t,n,r)=>{var i=(/* @__PURE__ */ new Date()).getFullYear(),a=new Date(i,0,1).getTimezoneOffset();i=new Date(i,6,1).getTimezoneOffset(),D[e>>2]=60*Math.max(a,i),E[t>>2]=Number(a!=i),t=e=>{var t=Math.abs(e);return`UTC${0<=e?`-`:`+`}${String(Math.floor(t/60)).padStart(2,`0`)}${String(t%60).padStart(2,`0`)}`},e=t(a),t=t(i),i<a?(L(e,w,n,17),L(t,w,r,17)):(L(e,w,r,17),L(t,w,n,17))},d:()=>Date.now(),s:()=>2147483648,c:()=>performance.now(),o:e=>{var t=w.length;if(e>>>=0,2147483648<e)return!1;for(var n=1;4>=n;n*=2){var r=t*(1+.2/n);r=Math.min(r,e+100663296);a:{r=(Math.min(2147483648,65536*Math.ceil(Math.max(e,r)/65536))-Ht.buffer.byteLength+65535)/65536|0;try{Ht.grow(r),ae();var i=1;break a}catch{}i=void 0}if(i)return!0}return!1},E:(e,t)=>{var n=0,r=0,i;for(i of Dt()){var a=t+n;D[e+r>>2]=a,n+=L(i,w,a,1/0)+1,r+=4}return 0},F:(e,t)=>{var n=Dt();D[e>>2]=n.length,e=0;for(var r of n)e+=I(r)+1;return D[t>>2]=e,0},e:function(e){try{return ft(G(e)),0}catch(e){if(J===void 0||e.name!==`ErrnoError`)throw e;return e.Pa}},p:function(e,t){try{var n=G(e);return C[t]=n.tty?2:W(n.mode)?3:(n.mode&61440)==40960?7:4,T[t+2>>1]=0,O[t+8>>3]=BigInt(0),O[t+16>>3]=BigInt(0),0}catch(e){if(J===void 0||e.name!==`ErrnoError`)throw e;return e.Pa}},w:function(e,t,n,r){try{a:{var i=G(e);e=t;for(var a,o=t=0;o<n;o++){var s=D[e>>2],c=D[e+4>>2];e+=8;var l=mt(i,C,s,c,a);if(0>l){var u=-1;break a}if(t+=l,l<c)break;a!==void 0&&(a+=l)}u=t}return D[r>>2]=u,0}catch(e){if(J===void 0||e.name!==`ErrnoError`)throw e;return e.Pa}},D:function(e,t,n,r){t=-9007199254740992>t||9007199254740992<t?NaN:Number(t);try{if(isNaN(t))return 61;var i=G(e);return pt(i,t,n),O[r>>3]=BigInt(i.position),i.rb&&t===0&&n===0&&(i.rb=null),0}catch(e){if(J===void 0||e.name!==`ErrnoError`)throw e;return e.Pa}},I:function(e){try{var t=G(e);return t.Ma?.fsync?.(t)}catch(e){if(J===void 0||e.name!==`ErrnoError`)throw e;return e.Pa}},t:function(e,t,n,r){try{a:{var i=G(e);e=t;for(var a,o=t=0;o<n;o++){var s=D[e>>2],c=D[e+4>>2];e+=8;var l=ht(i,C,s,c,a);if(0>l){var u=-1;break a}if(t+=l,l<c)break;a!==void 0&&(a+=l)}u=t}return D[r>>2]=u,0}catch(e){if(J===void 0||e.name!==`ErrnoError`)throw e;return e.Pa}},k:wt};function Wt(){function e(){if(s.calledRun=!0,!te){if(!s.noFSInit&&!Fe){var e,t;Fe=!0,e??=s.stdin,t??=s.stdout,n??=s.stderr,e?q(`stdin`,e):it(`/dev/tty`,`/dev/stdin`),t?q(`stdout`,null,t):it(`/dev/tty`,`/dev/stdout`),n?q(`stderr`,null,n):it(`/dev/tty1`,`/dev/stderr`),dt(`/dev/stdin`,0),dt(`/dev/stdout`,1),dt(`/dev/stderr`,1)}if(Gt.N(),Ie=!1,s.onRuntimeInitialized?.(),s.postRun)for(typeof s.postRun==`function`&&(s.postRun=[s.postRun]);s.postRun.length;){var n=s.postRun.shift();fe.push(n)}de(fe)}}if(0<A)j=Wt;else{if(s.preRun)for(typeof s.preRun==`function`&&(s.preRun=[s.preRun]);s.preRun.length;)me();de(pe),0<A?j=Wt:s.setStatus?(s.setStatus(`Running...`),setTimeout(()=>{setTimeout(()=>s.setStatus(``),1),e()},1)):e()}}var Gt;return(async function(){function e(e){return e=Gt=e.exports,s._sqlite3_free=e.P,s._sqlite3_value_text=e.Q,s._sqlite3_prepare_v2=e.R,s._sqlite3_step=e.S,s._sqlite3_reset=e.T,s._sqlite3_exec=e.U,s._sqlite3_finalize=e.V,s._sqlite3_column_name=e.W,s._sqlite3_column_text=e.X,s._sqlite3_column_type=e.Y,s._sqlite3_errmsg=e.Z,s._sqlite3_clear_bindings=e._,s._sqlite3_value_blob=e.$,s._sqlite3_value_bytes=e.aa,s._sqlite3_value_double=e.ba,s._sqlite3_value_int=e.ca,s._sqlite3_value_type=e.da,s._sqlite3_result_blob=e.ea,s._sqlite3_result_double=e.fa,s._sqlite3_result_error=e.ga,s._sqlite3_result_int=e.ha,s._sqlite3_result_int64=e.ia,s._sqlite3_result_null=e.ja,s._sqlite3_result_text=e.ka,s._sqlite3_aggregate_context=e.la,s._sqlite3_column_count=e.ma,s._sqlite3_data_count=e.na,s._sqlite3_column_blob=e.oa,s._sqlite3_column_bytes=e.pa,s._sqlite3_column_double=e.qa,s._sqlite3_bind_blob=e.ra,s._sqlite3_bind_double=e.sa,s._sqlite3_bind_int=e.ta,s._sqlite3_bind_text=e.ua,s._sqlite3_bind_parameter_index=e.va,s._sqlite3_sql=e.wa,s._sqlite3_normalized_sql=e.xa,s._sqlite3_changes=e.ya,s._sqlite3_close_v2=e.za,s._sqlite3_create_function_v2=e.Aa,s._sqlite3_update_hook=e.Ba,s._sqlite3_open=e.Ca,It=s._malloc=e.Da,Lt=s._free=e.Ea,s._RegisterExtensionFunctions=e.Fa,Rt=e.Ga,zt=e.Ha,Bt=e.Ia,Q=e.Ja,Vt=e.Ka,Ht=e.M,$=e.O,ae(),A--,s.monitorRunDependencies?.(A),A==0&&j&&(e=j,j=null,e()),Gt}A++,s.monitorRunDependencies?.(A);var t={a:Ut};return s.instantiateWasm?new Promise(n=>{s.instantiateWasm(t,(t,r)=>{n(e(t,r))})}):(oe??=s.locateFile?s.locateFile(`sql-wasm.wasm`,m):m+`sql-wasm.wasm`,e((await le(t)).instance))})(),Wt(),a}),r)};typeof t==`object`&&typeof n==`object`?(n.exports=i,n.exports.default=i):typeof define==`function`&&define.amd?define([],function(){return i}):typeof t==`object`&&(t.Module=i)})))(),1);function b(e,t,n){switch(n.mode){case`list`:return te(e,t,n);case`csv`:return ne(e,t,n);case`json`:return T(e,t);case`line`:return E(e,t,n);case`column`:return D(e,t,n);case`table`:return re(e,t,n);case`markdown`:return ie(e,t,n);case`tabs`:return O(e,t,n);case`box`:return ae(e,t,n);case`quote`:return k(e,t,n);case`html`:return oe(e,t,n);case`ascii`:return ce(e,t,n)}}function x(e,t){return e==null?t:e instanceof Uint8Array||ee.isBuffer(e)?ee.from(e).toString(`utf8`):typeof e==`number`&&!Number.isInteger(e)?e.toPrecision(17).replace(/\.?0+$/,``):String(e)}function te(e,t,n){let r=[];n.header&&e.length>0&&r.push(e.join(n.separator));for(let e of t)r.push(e.map(e=>x(e,n.nullValue)).join(n.separator));return r.length>0?`${r.join(n.newline)}${n.newline}`:``}function ne(e,t,n){let r=[];n.header&&e.length>0&&r.push(e.map(S).join(`,`));for(let e of t)r.push(e.map(e=>S(x(e,n.nullValue))).join(`,`));return r.length>0?`${r.join(`
|
|
3
|
+
`)}
|
|
4
|
+
`:``}function S(e){return e.includes(`,`)||e.includes(`"`)||e.includes(`'`)||e.includes(`
|
|
5
|
+
`)?`"${e.replace(/"/g,`""`)}"`:e}function C(e){return e.toPrecision(17).replace(/\.?0+$/,``)}function w(e){return e===null?`null`:typeof e==`number`?Number.isInteger(e)?String(e):C(e):JSON.stringify(e)}function T(e,t){return t.length===0?``:`[${t.map(t=>`{${e.map((e,n)=>`${JSON.stringify(e)}:${w(t[n])}`).join(`,`)}}`).join(`,
|
|
6
|
+
`)}]
|
|
7
|
+
`}function E(e,t,n){if(e.length===0||t.length===0)return``;let r=Math.max(5,...e.map(e=>e.length)),i=[];for(let a of t)for(let t=0;t<e.length;t++){let o=e[t].padStart(r);i.push(`${o} = ${x(a[t],n.nullValue)}`)}return`${i.join(`
|
|
8
|
+
`)}
|
|
9
|
+
`}function D(e,t,n){if(e.length===0)return``;let r=e.map(e=>e.length);for(let e of t)for(let t=0;t<e.length;t++){let i=x(e[t],n.nullValue).length;i>r[t]&&(r[t]=i)}let i=[];n.header&&(i.push(e.map((e,t)=>e.padEnd(r[t])).join(` `)),i.push(r.map(e=>`-`.repeat(e)).join(` `)));for(let e of t)i.push(e.map((e,t)=>x(e,n.nullValue).padEnd(r[t])).join(` `));return i.length>0?`${i.join(`
|
|
10
|
+
`)}
|
|
11
|
+
`:``}function re(e,t,n){if(e.length===0)return``;let r=e.map(e=>e.length);for(let e of t)for(let t=0;t<e.length;t++){let i=x(e[t],n.nullValue).length;i>r[t]&&(r[t]=i)}let i=[],a=`+${r.map(e=>`-`.repeat(e+2)).join(`+`)}+`;i.push(a),n.header&&(i.push(`| ${e.map((e,t)=>e.padEnd(r[t])).join(` | `)} |`),i.push(a));for(let e of t)i.push(`| ${e.map((e,t)=>x(e,n.nullValue).padEnd(r[t])).join(` | `)} |`);return i.push(a),`${i.join(`
|
|
12
|
+
`)}
|
|
13
|
+
`}function ie(e,t,n){if(e.length===0)return``;let r=[];n.header&&(r.push(`| ${e.join(` | `)} |`),r.push(`|${e.map(()=>`---`).join(`|`)}|`));for(let e of t)r.push(`| ${e.map(e=>x(e,n.nullValue)).join(` | `)} |`);return r.length>0?`${r.join(`
|
|
14
|
+
`)}
|
|
15
|
+
`:``}function O(e,t,n){let r=[];n.header&&e.length>0&&r.push(e.join(` `));for(let e of t)r.push(e.map(e=>x(e,n.nullValue)).join(` `));return r.length>0?`${r.join(n.newline)}${n.newline}`:``}function ae(e,t,n){if(e.length===0)return``;let r=e.map(e=>e.length);for(let e of t)for(let t=0;t<e.length;t++){let i=x(e[t],n.nullValue).length;i>r[t]&&(r[t]=i)}let i=[];i.push(`\u250C${r.map(e=>`─`.repeat(e+2)).join(`┬`)}\u2510`),i.push(`\u2502 ${e.map((e,t)=>e.padEnd(r[t])).join(` │ `)} \u2502`),i.push(`\u251C${r.map(e=>`─`.repeat(e+2)).join(`┼`)}\u2524`);for(let e of t)i.push(`\u2502 ${e.map((e,t)=>x(e,n.nullValue).padEnd(r[t])).join(` │ `)} \u2502`);return i.push(`\u2514${r.map(e=>`─`.repeat(e+2)).join(`┴`)}\u2518`),`${i.join(`
|
|
16
|
+
`)}
|
|
17
|
+
`}function k(e,t,n){let r=[];n.header&&e.length>0&&r.push(e.map(e=>`'${e}'`).join(`,`));for(let e of t)r.push(e.map(e=>e==null?`NULL`:typeof e==`number`?Number.isInteger(e)?String(e):C(e):`'${String(e)}'`).join(`,`));return r.length>0?`${r.join(n.newline)}${n.newline}`:``}function oe(e,t,n){let r=[];n.header&&e.length>0&&(r.push(`<TR>${e.map(e=>`<TH>${se(e)}</TH>`).join(``)}`),r.push(`</TR>`));for(let e of t)r.push(`<TR>${e.map(e=>`<TD>${se(x(e,n.nullValue))}</TD>`).join(``)}`),r.push(`</TR>`);return r.length>0?`${r.join(`
|
|
18
|
+
`)}
|
|
19
|
+
`:``}function se(e){return e.replace(/&/g,`&`).replace(/</g,`<`).replace(/>/g,`>`).replace(/"/g,`"`)}function ce(e,t,n){let r=[];n.header&&e.length>0&&r.push(e.join(``));for(let e of t)r.push(e.map(e=>x(e,n.nullValue)).join(``));return r.length>0?r.join(``)+``:``}var le=5e3,ue={name:`sqlite3`,summary:`SQLite database CLI`,usage:`sqlite3 [OPTIONS] DATABASE [SQL]`,options:[`-list output in list mode (default)`,`-csv output in CSV mode`,`-json output in JSON mode`,`-line output in line mode`,`-column output in column mode`,`-table output as ASCII table`,`-markdown output as markdown table`,`-tabs output in tab-separated mode`,`-box output in Unicode box mode`,`-quote output in SQL quote mode`,`-html output as HTML table`,`-ascii output in ASCII mode (control chars)`,`-header show column headers`,`-noheader hide column headers`,`-separator SEP field separator for list mode (default: |)`,`-newline SEP row separator (default: \\n)`,`-nullvalue TEXT text for NULL values (default: empty)`,`-readonly open database read-only (no writeback)`,`-bail stop on first error`,`-echo print SQL before execution`,`-cmd COMMAND run SQL command before main SQL`,`-version show SQLite version`,`-- end of options`,`--help show this help`],examples:[`sqlite3 :memory: "CREATE TABLE t(x); INSERT INTO t VALUES(1); SELECT * FROM t"`,`sqlite3 -json data.db "SELECT * FROM users"`,`sqlite3 -csv -header data.db "SELECT id, name FROM products"`,`sqlite3 -box data.db "SELECT * FROM users"`]};function de(e){let t={mode:`list`,header:!1,separator:`|`,newline:`
|
|
20
|
+
`,nullValue:``,readonly:!1,bail:!1,echo:!1,cmd:null},n=null,r=null,i=!1,a=!1;for(let o=0;o<e.length;o++){let s=e[o];if(a)n===null?n=s:r===null&&(r=s);else if(s===`--`)a=!0;else if(s===`-version`)i=!0;else if(s===`-list`)t.mode=`list`;else if(s===`-csv`)t.mode=`csv`;else if(s===`-json`)t.mode=`json`;else if(s===`-line`)t.mode=`line`;else if(s===`-column`)t.mode=`column`;else if(s===`-table`)t.mode=`table`;else if(s===`-markdown`)t.mode=`markdown`;else if(s===`-tabs`)t.mode=`tabs`;else if(s===`-box`)t.mode=`box`;else if(s===`-quote`)t.mode=`quote`;else if(s===`-html`)t.mode=`html`;else if(s===`-ascii`)t.mode=`ascii`;else if(s===`-header`)t.header=!0;else if(s===`-noheader`)t.header=!1;else if(s===`-readonly`)t.readonly=!0;else if(s===`-bail`)t.bail=!0;else if(s===`-echo`)t.echo=!0;else if(s===`-separator`){if(o+1>=e.length)return{stdout:``,stderr:`sqlite3: Error: missing argument to -separator
|
|
21
|
+
`,exitCode:1};t.separator=e[++o]}else if(s===`-newline`){if(o+1>=e.length)return{stdout:``,stderr:`sqlite3: Error: missing argument to -newline
|
|
22
|
+
`,exitCode:1};t.newline=e[++o]}else if(s===`-nullvalue`){if(o+1>=e.length)return{stdout:``,stderr:`sqlite3: Error: missing argument to -nullvalue
|
|
23
|
+
`,exitCode:1};t.nullValue=e[++o]}else if(s===`-cmd`){if(o+1>=e.length)return{stdout:``,stderr:`sqlite3: Error: missing argument to -cmd
|
|
24
|
+
`,exitCode:1};t.cmd=e[++o]}else{if(s.startsWith(`-`))return{stdout:``,stderr:`sqlite3: Error: unknown option: ${s.startsWith(`--`)?s.slice(1):s}
|
|
25
|
+
Use -help for a list of options.
|
|
26
|
+
`,exitCode:1};n===null?n=s:r===null&&(r=s)}}return{options:t,database:n,sql:r,showVersion:i}}async function fe(){let e=new(await(a.runTrustedAsync(()=>(0,y.default)()))).Database;try{let t=e.exec(`SELECT sqlite_version()`);return t.length>0&&t[0].values.length>0?String(t[0].values[0][0]):`unknown`}finally{e.close()}}function pe(e=f(h(import.meta.url))){let t=[p(e,`sqlite3-worker.js`),p(e,`../../commands/sqlite3/worker.js`)];(e.endsWith(`${m}commands${m}sqlite3`)||e.endsWith(`/commands/sqlite3`))&&t.push(p(e,`worker.js`)),t.push(p(e,`../../../dist/commands/sqlite3/worker.js`));for(let e of t)if(d(e))return e;throw Error(`sqlite3 worker not found. Run 'pnpm build' to compile the worker.`)}var me={createWorker(e,t){return new v(e,{workerData:t})},findWorkerPath:pe};function A(){return _(16).toString(`hex`)}function j(e,t){if(!e||typeof e!=`object`)return{success:!1,error:`Malformed worker response`};let n=e;return typeof n.protocolToken!=`string`||n.protocolToken!==t?{success:!1,error:`Malformed worker response: invalid protocol token`}:n.type===`security-violation`?{success:!1,error:`Security violation: ${typeof n.violation?.type==`string`?n.violation.type:`unknown`}`}:typeof n.success==`boolean`?n.success?Array.isArray(n.results)?typeof n.hasModifications==`boolean`?n.dbBuffer!==null&&n.dbBuffer!==void 0&&!(n.dbBuffer instanceof Uint8Array)?{success:!1,error:`Malformed worker response: invalid dbBuffer`}:{success:!0,results:n.results,hasModifications:n.hasModifications,dbBuffer:n.dbBuffer===void 0?null:n.dbBuffer,defenseStats:n.defenseStats}:{success:!1,error:`Malformed worker response: missing hasModifications flag`}:{success:!1,error:`Malformed worker response: missing results array`}:{success:!1,error:typeof n.error==`string`&&n.error.length>0?n.error:`Worker execution failed`}:{success:!1,error:`Malformed worker response: missing success flag`}}async function M(e,t,n){try{let r=pe();return await new Promise((i,s)=>{let d=a.runTrusted(()=>me.createWorker(r,e)),f=o(n,`sqlite3`,`worker timeout callback`,()=>{d.terminate(),i({success:!1,error:`Query timeout: execution exceeded ${t}ms limit`})}),p=u(()=>{try{f()}catch(e){let t=e instanceof Error?e.message:String(e);i({success:!1,error:c(t)})}},t),m=o(n,`sqlite3`,`worker message callback`,t=>{l(p),i(j(t,e.protocolToken))}),h=o(n,`sqlite3`,`worker error callback`,e=>{l(p),s(e)}),g=o(n,`sqlite3`,`worker exit callback`,e=>{l(p),e!==0&&i({success:!1,error:`Worker exited with code ${e}`})});d.on(`message`,e=>{try{m(e)}catch(e){l(p);let t=e instanceof Error?e.message:String(e);i({success:!1,error:c(t)})}}),d.on(`error`,e=>{try{h(e)}catch(e){l(p);let t=e instanceof Error?e.message:String(e);s(Error(c(t)))}}),d.on(`exit`,e=>{try{g(e)}catch(e){l(p);let t=e instanceof Error?e.message:String(e);i({success:!1,error:c(t)})}})})}catch(e){let t=c(e.message);throw Error(`sqlite3 worker failed to load: ${t}`)}}var N={name:`sqlite3`,async execute(e,t){if(i(e)||e.includes(`-help`))return r(ue);let n=de(e);if(`exitCode`in n)return n;let{options:a,database:o,sql:l,showVersion:u}=n;if(u)return{stdout:`${await fe()}
|
|
27
|
+
`,stderr:``,exitCode:0};if(!o)return{stdout:``,stderr:`sqlite3: missing database argument
|
|
28
|
+
`,exitCode:1};let d=l||t.stdin.trim();if(a.cmd&&(d=a.cmd+(d?`; ${d}`:``)),!d)return{stdout:``,stderr:`sqlite3: no SQL provided
|
|
29
|
+
`,exitCode:1};let f=o===`:memory:`,p=``,m=null;try{f||(p=t.fs.resolvePath(t.cwd,o),await t.fs.exists(p)&&(m=await t.fs.readFileBuffer(p)))}catch(e){return{stdout:``,stderr:`sqlite3: unable to open database "${o}": ${s(e.message)}
|
|
30
|
+
`,exitCode:1}}let h=t.limits?.maxSqliteTimeoutMs??le,g={protocolToken:A(),dbBuffer:m,sql:d,options:{bail:a.bail,echo:a.echo}},_;try{_=await M(g,h,t.requireDefenseContext)}catch(e){return{stdout:``,stderr:`sqlite3: worker error: ${c(e.message)}
|
|
31
|
+
`,exitCode:1}}if(!_.success)return{stdout:``,stderr:`sqlite3: ${c(_.error)}
|
|
32
|
+
`,exitCode:1};let ee={mode:a.mode,header:a.header,separator:a.separator,newline:a.newline,nullValue:a.nullValue},v=``;a.echo&&(v+=`${d}
|
|
33
|
+
`);let y=!1;for(let e of _.results)if(e.type===`error`){if(a.bail)return{stdout:v,stderr:`Error: ${e.error}
|
|
34
|
+
`,exitCode:1};v+=`Error: ${e.error}
|
|
35
|
+
`,y=!0}else e.columns&&e.rows&&(e.rows.length>0||a.header)&&(v+=b(e.columns,e.rows,ee));if(_.hasModifications&&!a.readonly&&!f&&p&&_.dbBuffer)try{await t.fs.writeFile(p,_.dbBuffer)}catch(e){let t=s(e.message);return{stdout:v,stderr:`sqlite3: failed to write database: ${t}
|
|
36
|
+
`,exitCode:1}}return{stdout:v,stderr:``,exitCode:y&&a.bail?1:0}}},P={name:`sqlite3`,flags:[],needsArgs:!0};export{me as n,P as r,N as t};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{t as e}from"./chunk-
|
|
1
|
+
import{t as e}from"./chunk-CTarF4FC.js";import{t}from"./chunk-DorZAfZa.js";var n={"as-is|as-is|as-is":`You are a **Distinguished Senior Editor and Linguistic Specialist**. Your objective is to rewrite the user's 'TEXT' into a version that represents the pinnacle of clarity, flow, and stylistic appropriateness in the target language. You must strictly adhere to the following constraints.
|
|
2
2
|
|
|
3
3
|
# UNIVERSAL LAWS (NON-NEGOTIABLE)
|
|
4
4
|
1. **SEMANTIC & FACTUAL FIDELITY**: You must preserve the core meaning, facts, numbers, and logic of the original text.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as e,n as t}from"./chunk-vVEl6p-f.js";async function n(n=[],r,i={}){let a=i.maxInlineTextBytes??102400,o=i.maxImageBytes??3145728,s=[];for(let i of n){let n=i.mimeType||`application/octet-stream`,c=t(n,i.fileName),l=c===`text`?`file`:c===`document`?`document`:c,u=null;try{u=await r(i)}catch{u=null}let d=u?.length??(typeof i.size==`number`?i.size:0);if(c===`text`&&u&&d<=a)try{let e=new TextDecoder(`utf-8`).decode(u),t=e.includes("```")?`~~~~`:"```";s.push({type:`text`,text:`Attachment: ${i.fileName}\n${t}\n${e}\n${t}`});continue}catch{}let f={type:`attachment`,mediaType:l,fileName:i.fileName,mimeType:n,size:i.size,path:i.path};u&&(l===`image`&&d<=o||l===`audio`&&d<=5242880||l===`document`&&d<=20971520)&&(f.data=e(u)),s.push(f)}return s}export{n as t};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{t as e}from"./chunk-uAI_Zi6n.js";import t from"node:path";import n from"node:process";import{cp as r,mkdir as i,readFile as a,readdir as o,realpath as s,stat as c,writeFile as l}from"node:fs/promises";import u from"
|
|
1
|
+
import{t as e}from"./chunk-uAI_Zi6n.js";import t from"node:path";import n from"node:process";import{cp as r,mkdir as i,readFile as a,readdir as o,realpath as s,stat as c,writeFile as l}from"node:fs/promises";import u from"node:crypto";import d from"gray-matter";function f(e){return`sha256:${u.createHash(`sha256`).update(e).digest(`hex`).toLowerCase()}`}async function p(e){try{return await c(e),!0}catch{return!1}}function m(e,t){return!!(/\.(test|spec)(\.[^.]+)?$/i.test(e)||e===`__tests__`||e===`test`||e===`tests`||t&&t.split(/[/\\]/).some(e=>e===`__tests__`||e===`test`||e===`tests`||/\.(test|spec)(\.[^.]+)?$/i.test(e)))}async function h(e,n){let r=[];if(!await p(e))return r;let i=/* @__PURE__ */ new Set;async function a(e){try{let t=await s(e);if(i.has(t))return;i.add(t)}catch{return}let l=await o(e,{withFileTypes:!0});for(let i of l){let o=t.join(e,i.name),s=i.isDirectory(),l=i.isFile();if(i.isSymbolicLink())try{let e=await c(o);s=e.isDirectory(),l=e.isFile()}catch{continue}s?m(i.name,o)||await a(o):l&&!m(i.name,o)&&(!n||n(i.name,o))&&r.push(o)}}return await a(e),r.sort()}async function g(o=n.cwd(),s={}){let c=t.resolve(o),u=s.outDir||`.well-known/agent-skills`,m=s.metadataRoot?t.resolve(s.metadataRoot):c,g=s.siteName,_=s.siteDescription,v=t.dirname(m),y=t.dirname(v),b=[s.configPath,t.join(m,`shadow-claw.config.json`),t.join(m,`shadow-claw-config.json`),t.join(m,`site-config.json`),t.join(v,`shadow-claw.config.json`),t.join(v,`shadow-claw-config.json`),t.join(v,`site-config.json`),t.join(y,`shadow-claw.config.json`),t.join(y,`shadow-claw-config.json`),t.join(y,`site-config.json`)].filter(e=>!!e),x=null;for(let e of b)if(await p(e))try{let t=await a(e,`utf8`);x=JSON.parse(t);break}catch{}if(x&&(!g&&x.site?.title&&(g=x.site.title),!_&&x.site?.description&&(_=x.site.description)),!g||!_){let e=[t.join(m,`package.json`),t.join(v,`package.json`),t.join(y,`package.json`)];for(let t of e)if(await p(t))try{let e=JSON.parse(await a(t,`utf8`));!g&&e.name&&(g=e.name),!_&&e.description&&(_=e.description);break}catch{}}g||(g=t.basename(m),(g===`public`||g===`dist`)&&(g=t.basename(v),(g===`public`||g===`dist`)&&t.basename(y)&&(g=t.basename(y)))),_||=`Agent skills and tools collection, powered by ShadowClaw.`;try{let{migrateLegacyWorkspaceLayout:e}=await import(`./chunk-CeuR-KKG.js`);await e(c)}catch{}let S=await h(t.join(c,`.agents`,`tools`),e=>e.endsWith(`.json`)),C=[];for(let e of S){let n=t.relative(c,e),r=t.posix.normalize(t.posix.relative(u,n.split(t.sep).join(t.posix.sep))),i=await a(e),o=f(i),s=t.basename(e,`.json`),l=``;try{let e=JSON.parse(i.toString(`utf8`));e.name&&(s=e.name),e.description&&(l=e.description)}catch{}C.push({name:s,description:l,url:r,digest:o,relFromRoot:n})}let w=await h(t.join(c,`.agents`,`scripts`),e=>e.endsWith(`.js`)||e.endsWith(`.mjs`)),T=[];for(let e of w){let n=t.relative(c,e),r=t.posix.normalize(t.posix.relative(u,n.split(t.sep).join(t.posix.sep))),i=f(await a(e)),o=t.basename(e,t.extname(e));T.push({name:o,description:`Portable ESM engine logic and tool execution handler for ${o}.`,url:r,digest:i,relFromRoot:n})}let E=t.join(c,`.agents`,`skills`),D=(await h(E,e=>e===`SKILL.md`)).sort((e,n)=>{let r=t.relative(E,e).split(t.sep).join(`/`),i=t.relative(E,n).split(t.sep).join(`/`),a=!r.startsWith(`main/`);return a===!i.startsWith(`main/`)?r.localeCompare(i):a?-1:1}),O=[],k=/* @__PURE__ */ new Set;for(let e of D){let n=t.relative(c,e),r=t.posix.normalize(t.posix.relative(u,n.split(t.sep).join(t.posix.sep))),i=await a(e),o=f(i),s={};try{s=d(i.toString(`utf8`)).data||{}}catch{}let l=t.dirname(e),p=t.basename(l),m=s.name||p,g=s.description||``;if(k.has(m))continue;k.add(m);let _=(await h(l)).map(e=>t.relative(l,e).split(t.sep).join(t.posix.sep)).filter(e=>e!==`SKILL.md`&&!e.endsWith(`/SKILL.md`)).sort(),v=/* @__PURE__ */ new Set,y=!1;if(Array.isArray(s.metadata?.execution?.tools))for(let e of s.metadata.execution.tools)e?.name&&(v.add(e.name),y=!0);let b=s.metadata?.[`allowed-tools`]||s.metadata?.allowedTools||s[`allowed-tools`];if(typeof b==`string`&&b.split(/[,\s]+/).filter(Boolean).forEach(e=>{v.add(e),y=!0}),!y)for(let e of C)e.name.replace(/[-_]/g,``)===m.replace(/[-_]/g,``)&&v.add(e.name);let x=C.filter(e=>v.has(e.name)).map(({name:e,url:t,digest:n})=>({name:e,url:t,digest:n})),S=T.filter(e=>{let t=e.name.toLowerCase().replace(/[-_]/g,``),n=m.toLowerCase().replace(/[-_]/g,``);return n.startsWith(t)||t.startsWith(n)||v.has(e.name)}).map(({name:e,url:t,digest:n})=>({name:e,url:t,digest:n}));O.push({name:m,type:`skill-md`,description:g,url:r,digest:o,..._.length>0?{files:[`SKILL.md`,..._]}:{},...x.length?{tools:x}:{},...S.length?{scripts:S}:{}})}let A=e(import.meta.url),j=s.bundledSkillsDir?t.resolve(s.bundledSkillsDir):s.toolchainRoot?t.join(t.resolve(s.toolchainRoot),`.agents`,`skills`):s.includeBundled?t.join(A,`.agents`,`skills`):null;if(j&&await p(j)&&j!==E){let e=await h(j,e=>e===`SKILL.md`);for(let n of e){let e=t.relative(j,n),o=t.join(`.agents`,`skills`,e),l=t.posix.normalize(t.posix.relative(u,o.split(t.sep).join(t.posix.sep))),m=await a(n),h=f(m),g={};try{g=d(m.toString(`utf8`)).data||{}}catch{}let _=t.basename(t.dirname(n)),v=g.name||_,y=g.description||``;if(!O.some(e=>e.name===v)){if(s.write!==!1){let e=t.join(c,o);if(!await p(e)){let a=t.dirname(n),o=t.dirname(e);await i(o,{recursive:!0}),await r(a,o,{recursive:!0})}}O.push({name:v,type:`skill-md`,description:y,url:l,digest:h})}}}let M={$schema:`https://schemas.agentskills.io/discovery/0.2.0/schema.json`,name:g,description:_,skills:O,...C.length?{tools:C.map(({name:e,description:t,url:n,digest:r})=>({name:e,...t?{description:t}:{},url:n,digest:r}))}:{},...T.length?{scripts:T.map(({name:e,description:t,url:n,digest:r})=>({name:e,...t?{description:t}:{},url:n,digest:r}))}:{},...C.length||T.length?{dependencies:{...C.length?{tools:C.map(e=>e.url)}:{},...T.length?{scripts:T.map(e=>e.url)}:{}}}:{}};if(s.stdout&&console.log(JSON.stringify(M,null,2)),s.write!==!1){let e=s.outFile?t.resolve(s.outFile):t.join(c,u,`index.json`);await i(t.dirname(e),{recursive:!0}),await l(e,JSON.stringify(M,null,2)+`
|
|
2
2
|
`,`utf8`)}return M}async function _(e,r={}){let i=e?t.resolve(e):n.cwd();console.log(`Generating Agent Skills Discovery index for ${i}...`);let a=await g(i,{includeBundled:!!r.bundled,...r,configPath:r.config||r.configPath}),o=a.skills?a.skills.length:0;return console.log(`Indexed ${o} skill(s) into .well-known/agent-skills/index.json`),a}export{_ as i,g as n,m as r,f as t};
|
|
@@ -4,4 +4,4 @@ import{i as e,n as t,r as n,t as r}from"./chunk-4-QO2z6r.js";import{i,n as a,r a
|
|
|
4
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
5
|
(id, groupId, enabled, schedule, prompt, tools, lastRun, createdAt, type, freshContext, subagent, name, task_order, pushNotifications)
|
|
6
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&&e.pages.length>0)return e}if(t.fetchFallback!==!1){let e=await $e();if(e&&e.pages.length>0)return e}if(t.preferEmbedded===!1){let e=r();if(e&&e.pages.length>0)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-DMs7kREC.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};
|
|
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&&e.pages.length>0)return e}if(t.fetchFallback!==!1){let e=await $e();if(e&&e.pages.length>0)return e}if(t.preferEmbedded===!1){let e=r();if(e&&e.pages.length>0)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-rFuy8aS_.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 +1 @@
|
|
|
1
|
-
import{i as e,n as t}from"./chunk-CVHGsDhh.js";import"./chunk-mjuZTMQB.js";import"./chunk-BU-vs0np.js";import"./chunk-DPoeMCv9.js";import"./chunk-CgadgaEw.js";import{t as n}from"./chunk-BJhVJGhq.js";import{n as r}from"./chunk-Bja3_77j.js";import{n as i}from"./chunk-MDQTOz2m.js";import{n as ee,r as te}from"./chunk-BjecIi0O.js";import{n as a}from"./chunk-DB419J_B.js";import{n as o}from"./chunk-TE7E49kt.js";import{t as s}from"./chunk-ChG0widi.js";import{n as c}from"./chunk-BKHzPMm6.js";import{n as l}from"./chunk-DAr_GB-2.js";import{n as u}from"./chunk-CPyCZE25.js";import"./chunk-BbpS-dVt.js";import{t as d}from"./chunk-B2-tIuBm.js";import{t as f}from"./chunk-B5wp0a82.js";import{n as p}from"./chunk-Ci19kHX3.js";import{t as m}from"./chunk-DCBrS-UR.js";import{n as h}from"./chunk-ymKVHPxa.js";import{n as g}from"./chunk-DHLYAKo9.js";import{n as _,r as v}from"./chunk-C62bH_wS.js";import{n as y}from"./chunk-DF6S-rlx.js";import{t as b}from"./chunk-CR93gvhe.js";import{t as x}from"./chunk-BTd_kfdL.js";import"./chunk-lqGQ0baE.js";import{t as S}from"./chunk-e89yHxjz.js";import{t as C}from"./chunk-CqXzqQd3.js";import"./chunk-CM826QS4.js";import"./chunk-CSq06NPr.js";import"./chunk-cP_b0a0C.js";import{n as w}from"./chunk-DUAvVma5.js";import"./chunk-tfu3xcYn.js";import{n as T}from"./chunk-BZf43U5Z.js";import"./chunk-1VdYkt-J.js";import{r as E}from"./chunk-
|
|
1
|
+
import{i as e,n as t}from"./chunk-CVHGsDhh.js";import"./chunk-mjuZTMQB.js";import"./chunk-BU-vs0np.js";import"./chunk-DPoeMCv9.js";import"./chunk-CgadgaEw.js";import{t as n}from"./chunk-BJhVJGhq.js";import{n as r}from"./chunk-Bja3_77j.js";import{n as i}from"./chunk-MDQTOz2m.js";import{n as ee,r as te}from"./chunk-BjecIi0O.js";import{n as a}from"./chunk-DB419J_B.js";import{n as o}from"./chunk-TE7E49kt.js";import{t as s}from"./chunk-ChG0widi.js";import{n as c}from"./chunk-BKHzPMm6.js";import{n as l}from"./chunk-DAr_GB-2.js";import{n as u}from"./chunk-CPyCZE25.js";import"./chunk-BbpS-dVt.js";import{t as d}from"./chunk-B2-tIuBm.js";import{t as f}from"./chunk-B5wp0a82.js";import{n as p}from"./chunk-Ci19kHX3.js";import{t as m}from"./chunk-DCBrS-UR.js";import{n as h}from"./chunk-ymKVHPxa.js";import{n as g}from"./chunk-DHLYAKo9.js";import{n as _,r as v}from"./chunk-C62bH_wS.js";import{n as y}from"./chunk-DF6S-rlx.js";import{t as b}from"./chunk-CR93gvhe.js";import{t as x}from"./chunk-BTd_kfdL.js";import"./chunk-lqGQ0baE.js";import{t as S}from"./chunk-e89yHxjz.js";import{t as C}from"./chunk-CqXzqQd3.js";import"./chunk-CM826QS4.js";import"./chunk-CSq06NPr.js";import"./chunk-cP_b0a0C.js";import{n as w}from"./chunk-DUAvVma5.js";import"./chunk-tfu3xcYn.js";import{n as T}from"./chunk-BZf43U5Z.js";import"./chunk-1VdYkt-J.js";import{r as E}from"./chunk-Cjyu4cr_.js";import{n as D}from"./chunk-Cu-nPZE3.js";import{n as O}from"./chunk-CBL_W1GV.js";import{n as k}from"./chunk-TAKAXSu-.js";import{t as A}from"./chunk-Bx1COF_D.js";import{n as j}from"./chunk-5_W2yDzN.js";import{n as M}from"./chunk-DfCRRExB.js";import{n as N}from"./chunk-CE4DzJ7f.js";import{i as P,n as F,o as I}from"./chunk-UDQWmQag.js";import{t as L}from"./chunk-Ca8p8CEj.js";import{t as R}from"./chunk-C-sHDgH0.js";import{n as z}from"./chunk-BBsHG29b.js";import{t as B}from"./chunk-CbXTbBNu.js";import{n as V}from"./chunk--y2S65sw.js";import{n as H}from"./chunk-Cbi2ybnt.js";import{n as U,r as W}from"./chunk-Dv5oFrVy.js";import{t as G}from"./chunk-CXq0x3PG.js";import{t as K}from"./chunk-D2sk50F5.js";import{t as q}from"./chunk-DdHFlX1E.js";import{n as J}from"./chunk-Da7zB8jT.js";import{t as ne}from"./chunk-BM9aHOXe.js";import{t as Y}from"./chunk-BDjSG__v.js";import{t as X}from"./chunk-7zrKWr2J.js";import{t as Z}from"./chunk-DGW-Fq2k.js";import{t as re}from"./chunk-DqI6nry8.js";import{t as ie}from"./chunk-CfUVzP_L.js";import{n as ae}from"./chunk-CVCxOe_a.js";import{n as oe}from"./chunk-DDGFCyj6.js";import{t as se}from"./chunk-DoJxYG6u.js";import{t as ce}from"./chunk-Ct9RaMXj.js";import{t as le}from"./chunk-DQx16vcX.js";import{n as ue}from"./chunk-CWmk-5Co.js";import{t as de}from"./chunk-DehSxhPD.js";import{n as fe}from"./chunk-B9spSy1R.js";import{n as pe}from"./chunk-CfB9fvvy.js";import"./chunk-BhHal_aU.js";import{a as me,i as he,n as ge}from"./chunk-CWXUlng2.js";import{n as _e}from"./chunk-FXPpDMl6.js";import{n as ve}from"./chunk-BPEFs1gz.js";import{t as ye}from"./chunk-BcJG-0og.js";import{t as be}from"./chunk-G-QUfaZM.js";import{n as xe}from"./chunk-DTZoO_ww.js";import{t as Q}from"./chunk-DjBauUOc.js";import{t as Se}from"./chunk-CvqvtO-h.js";import{t as Ce}from"./chunk-T9GSZTZR.js";import{t as we}from"./chunk-e15kgXAj.js";import{n as Te}from"./chunk-Blj5tAZ2.js";import{n as Ee}from"./chunk-C-aGE0nx.js";import{n as De}from"./chunk-CCuim9UZ.js";import{t as Oe}from"./chunk-CpJV0sgc.js";import{n as ke}from"./chunk-Cp3kxgzD.js";var Ae=[g,a,Te,Ee,De,Oe,ke,be,u,xe,Q,o,Se,Ce,we,de,fe,pe,ge,me,he,_e,ve,n,ye,ae,l,d,oe,se,ce,le,ue,y,Y,X,Z,c,re,ie,S,i,m,q,h,_,v,e,t,J,ne,W,U,s,te,ee,G,r,p,f,K,L,R,z,b,B,V,H,x,D,O,k,A,j,M,N,P,F,I,C,w,T,E];function je(){return Ae}var $=/* @__PURE__ */ new Map;for(let e of je())$.set(e.name,new Set(e.flags.map(e=>e.flag)));function Me(e,t,n){let r=$.get(t);if(r&&r.size!==0)for(let i of n)r.has(i)&&e.hit(`cmd:flag:${t}:${i}`)}export{Me as emitFlagCoverage};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{t as getAgentCore}from"./chunk-DxcDFUi_.js";
|