@inkeep/open-knowledge 0.31.0-beta.6 → 0.31.0-beta.8
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/dist/assets/skills/discovery/SKILL.md +1 -1
- package/dist/assets/skills/project/SKILL.md +1 -1
- package/dist/cli.mjs +11 -11
- package/dist/constants-B2EvNGWZ.mjs +2 -0
- package/dist/{dist-Pe1Q8dMj.mjs → dist-CynAX6cy.mjs} +4 -4
- package/dist/{dist-BYM_jxPa.mjs → dist-DiaxTJ69.mjs} +1 -1
- package/dist/{gh-detect-C6QZctcU.mjs → gh-detect-Uu4VAWnW.mjs} +2 -2
- package/dist/index.d.mts +9 -3
- package/dist/index.mjs +1 -1
- package/dist/init-1G9fj8cH.mjs +639 -0
- package/dist/init-MrbSP11w.mjs +1 -0
- package/dist/launch-json-removal-D3x1PYMJ.mjs +2 -0
- package/dist/loader-BvbWpeUk.mjs +1 -0
- package/dist/{loader-B7V7uIES.mjs → loader-DIcwzOTi.mjs} +2 -2
- package/dist/{open-browser-CPSoIF8R.mjs → open-browser-Lk0l8JF5.mjs} +2 -2
- package/dist/{preview-BBQwe-gv.mjs → preview-C9JeIyOB.mjs} +2 -2
- package/dist/preview-CZN7WKk2.mjs +1 -0
- package/dist/public/assets/ActivityModeContent-BbFXNuKx.js +2 -0
- package/dist/public/assets/CodeMirrorPropInput-CHf8Iz40.js +3 -0
- package/dist/public/assets/{ConsentDialogBody-DUEo7dzd.js → ConsentDialogBody-TGvdiCLr.js} +1 -1
- package/dist/public/assets/CopyButton-DoEsGDa4.js +1 -0
- package/dist/public/assets/DocumentContext-DG5n9u7B.js +36 -0
- package/dist/public/assets/{EnableSyncConfirmDialog-BRji_vuj.js → EnableSyncConfirmDialog-CJzmvuen.js} +1 -1
- package/dist/public/assets/{GraphPanel-cScfZ2Kh.js → GraphPanel-m-nt5HQn.js} +1 -1
- package/dist/public/assets/{ManagedArtifactProperties-_bcR56Re.js → ManagedArtifactProperties-BePO6ANU.js} +1 -1
- package/dist/public/assets/{McpConsentDialogBody-pimma18E.js → McpConsentDialogBody-arNbqqes.js} +1 -1
- package/dist/public/assets/{MermaidDocEditor-Bm909VrA.js → MermaidDocEditor-DoV9dGJN.js} +1 -1
- package/dist/public/assets/PropertyPanel-DUZsqzTw.js +2 -0
- package/dist/public/assets/ReportBugDialogBody-CJkfjKa2.js +2 -0
- package/dist/public/assets/SettingsDialogBody-BPlL1Yed.js +7 -0
- package/dist/public/assets/{ShareBranchSwitchDialog-nDcQbyjK.js → ShareBranchSwitchDialog-DSKoiVrF.js} +1 -1
- package/dist/public/assets/{ShareReceiveDialog-Bi91UHeB.js → ShareReceiveDialog-Bvh3tHuH.js} +1 -1
- package/dist/public/assets/{ShareReceiveMissDialog-Cr-lyfq3.js → ShareReceiveMissDialog-Bdk7y3ML.js} +1 -1
- package/dist/public/assets/{SkillEditorActions-COoshjEA.js → SkillEditorActions-oiOuAa4I.js} +1 -1
- package/dist/public/assets/{SourceEditor-CmecCLss.js → SourceEditor-Df_8kdW5.js} +1 -1
- package/dist/public/assets/{TerminalPanel-C8Yoxppo.js → TerminalPanel-Bd8Dtt_n.js} +1 -1
- package/dist/public/assets/{_baseFor-VECk3xZB.js → _baseFor-0d9AvFx1.js} +1 -1
- package/dist/public/assets/agent-presence-Dl0E_LN8.js +1 -0
- package/dist/public/assets/{arc-CxehPN-O.js → arc-BWLwkJ2r.js} +1 -1
- package/dist/public/assets/architecture-YZFGNWBL-9BNhGkdz.js +1 -0
- package/dist/public/assets/{architectureDiagram-Q4EWVU46-BP3qpyaD.js → architectureDiagram-Q4EWVU46-KXeh9itt.js} +1 -1
- package/dist/public/assets/{auth-state-cache-DewLLWl7.js → auth-state-cache-BSJEl4LS.js} +5 -5
- package/dist/public/assets/{blockDiagram-DXYQGD6D-B5TD8A38.js → blockDiagram-DXYQGD6D-DtrdFoMb.js} +1 -1
- package/dist/public/assets/{c4Diagram-AHTNJAMY-DXobwygF.js → c4Diagram-AHTNJAMY-fq1Z49Kc.js} +1 -1
- package/dist/public/assets/{calendar-DvL8Q5iT.js → calendar-B2qs7swV.js} +1 -1
- package/dist/public/assets/channel-CuMNseph.js +1 -0
- package/dist/public/assets/{checkbox-09LNjybZ.js → checkbox-CgcvT5md.js} +1 -1
- package/dist/public/assets/{chunk-2KRD3SAO-DDUdr-iX.js → chunk-2KRD3SAO-Bk_Wilkm.js} +1 -1
- package/dist/public/assets/{chunk-336JU56O-B_KFr_Bs.js → chunk-336JU56O-CL9kwjEg.js} +2 -2
- package/dist/public/assets/chunk-426QAEUC-pZbdhoaS.js +1 -0
- package/dist/public/assets/{chunk-4BX2VUAB-DRfG-ueY.js → chunk-4BX2VUAB-D96BT_Bg.js} +1 -1
- package/dist/public/assets/{chunk-4TB4RGXK-B0Gnlc8Z.js → chunk-4TB4RGXK-1ZoApeth.js} +1 -1
- package/dist/public/assets/chunk-55IACEB6-HEGApgMn.js +1 -0
- package/dist/public/assets/{chunk-5FUZZQ4R-CVl_7PAT.js → chunk-5FUZZQ4R-DPbA0GBM.js} +1 -1
- package/dist/public/assets/{chunk-5PVQY5BW-Cfkq4RiL.js → chunk-5PVQY5BW-CQS0U6F7.js} +1 -1
- package/dist/public/assets/{chunk-67CJDMHE-G9bUyIhz.js → chunk-67CJDMHE-okMxnkQT.js} +1 -1
- package/dist/public/assets/{chunk-7N4EOEYR-URuUKEXP.js → chunk-7N4EOEYR-Drske5an.js} +1 -1
- package/dist/public/assets/{chunk-AA7GKIK3-DRCEQeZY.js → chunk-AA7GKIK3-BlHxQeSp.js} +1 -1
- package/dist/public/assets/{chunk-BSJP7CBP-DGKfJILj.js → chunk-BSJP7CBP-BpNyv8Y4.js} +1 -1
- package/dist/public/assets/{chunk-CIAEETIT-C-4SSDk6.js → chunk-CIAEETIT-8deU_mkj.js} +1 -1
- package/dist/public/assets/{chunk-EDXVE4YY-B7GwVaSD.js → chunk-EDXVE4YY-VzPvg9KF.js} +1 -1
- package/dist/public/assets/{chunk-ENJZ2VHE-BaPHkOPd.js → chunk-ENJZ2VHE-BjhT8OeZ.js} +1 -1
- package/dist/public/assets/{chunk-FMBD7UC4-Sg4QfR2X.js → chunk-FMBD7UC4-CGtQ8v2r.js} +1 -1
- package/dist/public/assets/{chunk-FOC6F5B3-D76iMJUf.js → chunk-FOC6F5B3--YnpQUAX.js} +1 -1
- package/dist/public/assets/{chunk-ICPOFSXX-DlM8yc3o.js → chunk-ICPOFSXX-By9Q-6fm.js} +2 -2
- package/dist/public/assets/{chunk-K5T4RW27-o4pGUO6-.js → chunk-K5T4RW27-C_6VcMXC.js} +1 -1
- package/dist/public/assets/{chunk-KGLVRYIC-DlaCM317.js → chunk-KGLVRYIC-C3De9ry6.js} +1 -1
- package/dist/public/assets/{chunk-LIHQZDEY-wt2Qc-rg.js → chunk-LIHQZDEY-D4-GsYgm.js} +1 -1
- package/dist/public/assets/{chunk-ORNJ4GCN-BHgDQV41.js → chunk-ORNJ4GCN-qQUTfvQr.js} +1 -1
- package/dist/public/assets/{chunk-OYMX7WX6-BHQCcMht.js → chunk-OYMX7WX6-DAJTRr-n.js} +1 -1
- package/dist/public/assets/chunk-QZHKN3VN-DI8KBGbP.js +1 -0
- package/dist/public/assets/{chunk-U2HBQHQK-D4H3Zear.js → chunk-U2HBQHQK-Cp-6rjnO.js} +1 -1
- package/dist/public/assets/{chunk-X2U36JSP-ByMMuCmz.js → chunk-X2U36JSP-BFqfQNWU.js} +1 -1
- package/dist/public/assets/{chunk-XPW4576I-DGAGb6jI.js → chunk-XPW4576I-DI0-cfrS.js} +1 -1
- package/dist/public/assets/{chunk-YZCP3GAM-CLKcOka4.js → chunk-YZCP3GAM-sn7T8ho2.js} +1 -1
- package/dist/public/assets/{chunk-ZZ45TVLE-nqD2epOe.js → chunk-ZZ45TVLE-CxH2fGjk.js} +1 -1
- package/dist/public/assets/classDiagram-6PBFFD2Q-D98rNdcz.js +1 -0
- package/dist/public/assets/classDiagram-v2-HSJHXN6E-Cz77sXrt.js +1 -0
- package/dist/public/assets/clone-DXiEg0sZ.js +1 -0
- package/dist/public/assets/{config-provider-CPU__wB0.js → config-provider-CFiLGdZF.js} +1 -1
- package/dist/public/assets/copy-D8YVE0Jc.js +1 -0
- package/dist/public/assets/{cose-bilkent-S5V4N54A-B2yzzZk8.js → cose-bilkent-S5V4N54A-CXBsVXq9.js} +1 -1
- package/dist/public/assets/{cursor-CouJSC9c.js → cursor-BsJMggkz.js} +1 -1
- package/dist/public/assets/{dagre-BIgQuqiZ.js → dagre-C2Qb6hf2.js} +1 -1
- package/dist/public/assets/{dagre-KV5264BT-D7ZMiRem.js → dagre-KV5264BT-BQUJovtG.js} +1 -1
- package/dist/public/assets/{diagram-5BDNPKRD-BYEpe_ZJ.js → diagram-5BDNPKRD-C6tTTvBq.js} +1 -1
- package/dist/public/assets/{diagram-G4DWMVQ6-DxQlpGFr.js → diagram-G4DWMVQ6-Cq1-s9xc.js} +1 -1
- package/dist/public/assets/{diagram-MMDJMWI5-RJKi5ZMs.js → diagram-MMDJMWI5-BE-MhKN8.js} +1 -1
- package/dist/public/assets/{diagram-TYMM5635-Cbv6Q-Tj.js → diagram-TYMM5635-G0QPzMX4.js} +1 -1
- package/dist/public/assets/{dialog-CZK_GJbX.js → dialog-BvTRDNMV.js} +1 -1
- package/dist/public/assets/{dist-5OMiBr1O.js → dist-B0sSo1rx.js} +1 -1
- package/dist/public/assets/{dist-CK-u_yUG.js → dist-BI2wTleN.js} +1 -1
- package/dist/public/assets/{dist-DwvfOBE4.js → dist-BVRsG3b2.js} +3 -3
- package/dist/public/assets/{dist-C1stM53P.js → dist-C9Q20TxL.js} +1 -1
- package/dist/public/assets/{dist-Ctotkt8m.js → dist-CFvMrf5i.js} +1 -1
- package/dist/public/assets/{dist-DJzR_Ier.js → dist-CN2Ak373.js} +1 -1
- package/dist/public/assets/{dist-yzeYbK6D.js → dist-CPK5NxVp.js} +1 -1
- package/dist/public/assets/{dist-DJkVfTTW.js → dist-C_9BPzNE.js} +1 -1
- package/dist/public/assets/{dist-DwYhX11V.js → dist-CqC3taBS.js} +1 -1
- package/dist/public/assets/{dist-BJTNIx2m.js → dist-DSzqChbc.js} +1 -1
- package/dist/public/assets/{dist-CD524qWG.js → dist-DfkfQshV.js} +1 -1
- package/dist/public/assets/{dist-V49XHj-a.js → dist-LqTeaHS1.js} +1 -1
- package/dist/public/assets/dist-jyqE5kfZ.js +1 -0
- package/dist/public/assets/{dist-DIOoTUYz.js → dist-p4lElMBx.js} +1 -1
- package/dist/public/assets/{doc-hash-BtUMDwMU.js → doc-hash-CmkGIiUd.js} +1 -1
- package/dist/public/assets/{documents-events-DrrEYmNa.js → documents-events-CBqhEmHl.js} +1 -1
- package/dist/public/assets/{erDiagram-SMLLAGMA-BmMOegIt.js → erDiagram-SMLLAGMA-N7gNLe9o.js} +1 -1
- package/dist/public/assets/{file-tree-adapter-BiXhoQNr.js → file-tree-adapter-BRoSU5bE.js} +1 -1
- package/dist/public/assets/{flatten-CCmz8_dj.js → flatten-dENnAN6s.js} +1 -1
- package/dist/public/assets/{flowDiagram-DWJPFMVM-0LqPtkiA.js → flowDiagram-DWJPFMVM-DgclgNSr.js} +1 -1
- package/dist/public/assets/{ganttDiagram-T4ZO3ILL-DRsSWVHe.js → ganttDiagram-T4ZO3ILL-CAydivVh.js} +1 -1
- package/dist/public/assets/gitGraph-7Q5UKJZL-DuuJiYvS.js +1 -0
- package/dist/public/assets/{gitGraphDiagram-UUTBAWPF-BdADm4E0.js → gitGraphDiagram-UUTBAWPF-Qfom5ijS.js} +1 -1
- package/dist/public/assets/{graphlib-Dg3M3E4b.js → graphlib-BZWt_BGf.js} +1 -1
- package/dist/public/assets/index-C3IDVWhb.css +1 -0
- package/dist/public/assets/index-FeSh48__.js +2003 -0
- package/dist/public/assets/info-OMHHGYJF-DmgDPzke.js +1 -0
- package/dist/public/assets/{infoDiagram-42DDH7IO-qvYhaJaR.js → infoDiagram-42DDH7IO-BLFTlht0.js} +1 -1
- package/dist/public/assets/{isEmpty-C5m2-RSe.js → isEmpty-Dg6Et8UD.js} +1 -1
- package/dist/public/assets/isSymbol-BhYgyzzO.js +1 -0
- package/dist/public/assets/{ishikawaDiagram-UXIWVN3A-CcivmKPd.js → ishikawaDiagram-UXIWVN3A-C8gBLX8v.js} +1 -1
- package/dist/public/assets/{journeyDiagram-VCZTEJTY-ouWVthki.js → journeyDiagram-VCZTEJTY-DVV127Ia.js} +1 -1
- package/dist/public/assets/{kanban-definition-6JOO6SKY-ZhUMH8F2.js → kanban-definition-6JOO6SKY-Bi_LNUlw.js} +1 -1
- package/dist/public/assets/{keyboard-shortcuts-CH4qhzpw.js → keyboard-shortcuts-Dw2cvMMp.js} +1 -1
- package/dist/public/assets/{line-So0Nf7v2.js → line-CuRBOqmw.js} +1 -1
- package/dist/public/assets/{linear-7dqmcJYs.js → linear-BnfMN22g.js} +1 -1
- package/dist/public/assets/{mermaid-parser.core-gjoLdFzV.js → mermaid-parser.core-noqTIfNm.js} +2 -2
- package/dist/public/assets/{mermaid.core-DIaQcKcu.js → mermaid.core-DMKNygs1.js} +3 -3
- package/dist/public/assets/{mindmap-definition-QFDTVHPH-BpktrSi5.js → mindmap-definition-QFDTVHPH-DLIIn_h8.js} +1 -1
- package/dist/public/assets/{navigation-targets-C8x96muf.js → navigation-targets-G6yEVp6c.js} +1 -1
- package/dist/public/assets/{now-Dslec7Y8.js → now-esIbxJzw.js} +1 -1
- package/dist/public/assets/{open-managed-artifact-tab-C7sLBkCv.js → open-managed-artifact-tab-acLO8au6.js} +1 -1
- package/dist/public/assets/{ordinal-GH4e7Z1z.js → ordinal-DYUgOuL7.js} +1 -1
- package/dist/public/assets/packet-4T2RLAQJ-CVcq-ivT.js +1 -0
- package/dist/public/assets/{pending-receive-nav-store-D83rXcWH.js → pending-receive-nav-store-omPUhaeY.js} +1 -1
- package/dist/public/assets/pie-ZZUOXDRM-DSvYqp8t.js +1 -0
- package/dist/public/assets/{pieDiagram-DEJITSTG-BPZLf8gB.js → pieDiagram-DEJITSTG-C-vgeRar.js} +1 -1
- package/dist/public/assets/{project-paths-Bg2cu_Xr.js → project-paths-CqH22Xq0.js} +1 -1
- package/dist/public/assets/{prop-types-589M92VT.js → prop-types-6gA_YVnm.js} +1 -1
- package/dist/public/assets/{propagation-api-C0PBUfbG.js → propagation-api-M_AcuP6N.js} +1 -1
- package/dist/public/assets/{quadrantDiagram-34T5L4WZ-pdw_MogG.js → quadrantDiagram-34T5L4WZ-BmQcA7GQ.js} +1 -1
- package/dist/public/assets/radar-PYXPWWZC-BrGdIzLo.js +1 -0
- package/dist/public/assets/{radio-group-CkH5F_ZT.js → radio-group-DyHNJs2C.js} +1 -1
- package/dist/public/assets/{receive-store-DUmQ9Q7m.js → receive-store-CrJ3w3k0.js} +1 -1
- package/dist/public/assets/{reduce-CmXLDnl6.js → reduce-BKUJZ1TP.js} +1 -1
- package/dist/public/assets/{requirementDiagram-MS252O5E-BPFpj55s.js → requirementDiagram-MS252O5E-DPE-Czmf.js} +1 -1
- package/dist/public/assets/{sankeyDiagram-XADWPNL6-BlIkXMJT.js → sankeyDiagram-XADWPNL6-C6mEVWX1.js} +1 -1
- package/dist/public/assets/{selection-context-D_zj8y90.js → selection-context-8HFgCBJz.js} +1 -1
- package/dist/public/assets/{sequenceDiagram-FGHM5R23-DiHLgJYc.js → sequenceDiagram-FGHM5R23-rp9LrkhC.js} +1 -1
- package/dist/public/assets/skill-actions-D2r7iq9h.js +1 -0
- package/dist/public/assets/{skills-api-DULTMJrv.js → skills-api-DvU5qnRa.js} +1 -1
- package/dist/public/assets/{src-DReJgyBg.js → src-DldiksFQ.js} +1 -1
- package/dist/public/assets/{src-CqaRgyJX.js → src-sATQ-1TS.js} +1 -1
- package/dist/public/assets/{stateDiagram-FHFEXIEX-BvvfLH6H.js → stateDiagram-FHFEXIEX-4q5ruYzC.js} +1 -1
- package/dist/public/assets/stateDiagram-v2-QKLJ7IA2-9Y5TkQAw.js +1 -0
- package/dist/public/assets/{target-navigation-intent-BrbTHf_2.js → target-navigation-intent-DIz1qTBm.js} +1 -1
- package/dist/public/assets/{telemetry-impl-DkfWYdsZ.js → telemetry-impl-Cs0UMIR2.js} +2 -2
- package/dist/public/assets/telemetry-startup-BO7q-IdH.js +1 -0
- package/dist/public/assets/{timeline-definition-GMOUNBTQ-Cm-_wwCn.js → timeline-definition-GMOUNBTQ-CRtE2coR.js} +1 -1
- package/dist/public/assets/{toggle-group-B_aSxEq-.js → toggle-group-Hn7Etr9N.js} +1 -1
- package/dist/public/assets/{tooltip-DZYAkZo5.js → tooltip-tSMIHkKA.js} +1 -1
- package/dist/public/assets/treeView-SZITEDCU-C_aWaIS6.js +1 -0
- package/dist/public/assets/treemap-W4RFUUIX-CcQyutfG.js +1 -0
- package/dist/public/assets/{typing-burst-detector-BCt9a4xO.js → typing-burst-detector-DP8u_tQC.js} +1 -1
- package/dist/public/assets/{vennDiagram-DHZGUBPP-rndTcHCv.js → vennDiagram-DHZGUBPP-B5-arv9-.js} +1 -1
- package/dist/public/assets/wardley-RL74JXVD-B57ZwOFM.js +1 -0
- package/dist/public/assets/{wardleyDiagram-NUSXRM2D-D0g460BL.js → wardleyDiagram-NUSXRM2D-NXmNnKuY.js} +1 -1
- package/dist/public/assets/workspace-paths-Dj3MgOE7.js +1 -0
- package/dist/public/assets/{xychartDiagram-5P7HB3ND-DzjJ5eMr.js → xychartDiagram-5P7HB3ND-B_cLbDrg.js} +1 -1
- package/dist/public/index.html +79 -80
- package/dist/{repair-launch-json-Du0EU3Si.mjs → repair-launch-json-DzczMayl.mjs} +2 -2
- package/dist/repair-mcp-configs-Cp5VRehu.mjs +2 -0
- package/dist/repair-skills-B-9mVcmb.mjs +1 -0
- package/dist/{repair-skills-DuNm-kMp.mjs → repair-skills-XQg-rb3q.mjs} +2 -2
- package/dist/server-lock-GuuouVft-C6kYMpa7.mjs +1 -0
- package/dist/{server-lock-iLcBw_q0-nWzkxbfg.mjs → server-lock-iLcBw_q0-DddnIrHS.mjs} +2 -2
- package/dist/{src-B9TNCBdI.mjs → src-CZcBOOJs.mjs} +4 -4
- package/dist/start-DcvuVtnN.mjs +1 -0
- package/dist/{start-Dld0QqQ2.mjs → start-Ig8o-wfe.mjs} +2 -2
- package/dist/write-project-skill-DV1PSHkd.mjs +50 -0
- package/package.json +1 -1
- package/dist/constants-Ba7kuv_h.mjs +0 -2
- package/dist/init-CM8vkkIB.mjs +0 -1
- package/dist/init-CWVdQeQP.mjs +0 -653
- package/dist/launch-json-removal-TcMw8bt1.mjs +0 -2
- package/dist/loader-BktwkYhG.mjs +0 -1
- package/dist/preview-C317XX3v.mjs +0 -1
- package/dist/public/assets/ActivityModeContent-tdDE-61j.js +0 -2
- package/dist/public/assets/CodeMirrorPropInput-DNVWCpb0.js +0 -3
- package/dist/public/assets/DocumentContext-Dc9Bp6oO.js +0 -36
- package/dist/public/assets/PropertyPanel-CvVf4BX_.js +0 -2
- package/dist/public/assets/ReportBugDialogBody-C_Q3PS3L.js +0 -2
- package/dist/public/assets/SettingsDialogBody-DUbN9FMx.js +0 -7
- package/dist/public/assets/agent-presence-BgZw7jcH.js +0 -1
- package/dist/public/assets/architecture-YZFGNWBL-DsxJN6Kz.js +0 -1
- package/dist/public/assets/channel-DVu0OxhH.js +0 -1
- package/dist/public/assets/chunk-426QAEUC-RFGaT71Y.js +0 -1
- package/dist/public/assets/chunk-55IACEB6-DAOIsDKo.js +0 -1
- package/dist/public/assets/chunk-QZHKN3VN-BcpoMdLu.js +0 -1
- package/dist/public/assets/circle-alert-sOrK-E2e.js +0 -1
- package/dist/public/assets/classDiagram-6PBFFD2Q-MnKF6SyF.js +0 -1
- package/dist/public/assets/classDiagram-v2-HSJHXN6E-zCakvYeI.js +0 -1
- package/dist/public/assets/clone-C-i8X3vQ.js +0 -1
- package/dist/public/assets/dist-CCW5cnWo.js +0 -1
- package/dist/public/assets/dist-D-nYc0c5.js +0 -1
- package/dist/public/assets/file-text-et24uQST.js +0 -1
- package/dist/public/assets/gitGraph-7Q5UKJZL-D_-MQMqR.js +0 -1
- package/dist/public/assets/index-BDOi3sKE.js +0 -2003
- package/dist/public/assets/index-Bai-YKSb.css +0 -1
- package/dist/public/assets/info-OMHHGYJF-BszLPAsY.js +0 -1
- package/dist/public/assets/isSymbol-bbBleIZC.js +0 -1
- package/dist/public/assets/packet-4T2RLAQJ-Bv1Aae8C.js +0 -1
- package/dist/public/assets/pie-ZZUOXDRM-CWm6tOdZ.js +0 -1
- package/dist/public/assets/radar-PYXPWWZC-BnuozSTl.js +0 -1
- package/dist/public/assets/skill-actions-DbGgyPDT.js +0 -1
- package/dist/public/assets/stateDiagram-v2-QKLJ7IA2-Ddr1j6xz.js +0 -1
- package/dist/public/assets/telemetry-startup-B2tAiMsF.js +0 -1
- package/dist/public/assets/treeView-SZITEDCU-DKwVPz-3.js +0 -1
- package/dist/public/assets/treemap-W4RFUUIX-D4LXGVs_.js +0 -1
- package/dist/public/assets/wardley-RL74JXVD-BivuXjN1.js +0 -1
- package/dist/public/assets/workspace-paths-AsbfFKxa.js +0 -1
- package/dist/repair-mcp-configs-DCP-rfpP.mjs +0 -2
- package/dist/repair-skills-BDe9l22O.mjs +0 -1
- package/dist/server-lock-GuuouVft-CO_sPVNi.mjs +0 -1
- package/dist/start-rypz41-s.mjs +0 -1
- package/dist/write-project-skill-DyoxYjJB.mjs +0 -36
- /package/dist/public/assets/{ActivityPanelDiffView-BUS_IClA.js → ActivityPanelDiffView-B2UyxRqh.js} +0 -0
- /package/dist/public/assets/{__vite-browser-external-nMYNicjc.js → __vite-browser-external-DWP-nnLG.js} +0 -0
- /package/dist/public/assets/{array-DA62ss4d.js → array-DCThpSXQ.js} +0 -0
- /package/dist/public/assets/{arrow-up-right-Vg7lRNno.js → arrow-up-right-Bj9cWgcz.js} +0 -0
- /package/dist/public/assets/{check-CBLIjSIa.js → check-nyYgwOgK.js} +0 -0
- /package/dist/public/assets/{chevron-down-D2qF2W9D.js → chevron-down-B4gqqe-h.js} +0 -0
- /package/dist/public/assets/{chevron-left-SSPDkqEW.js → chevron-left-aRnXScdx.js} +0 -0
- /package/dist/public/assets/{chevron-right-C6588edp.js → chevron-right-DjreZbLo.js} +0 -0
- /package/dist/public/assets/{clike-f5rGWX5o.js → clike-DBPhSRc7.js} +0 -0
- /package/dist/public/assets/{clipboard-adapter-BscVzpz1.js → clipboard-adapter-BYqGVFAr.js} +0 -0
- /package/dist/public/assets/{colors-BtJnRWTu.js → colors-BWTxgr-H.js} +0 -0
- /package/dist/public/assets/{config-context-GBTLA0Td.js → config-context-B9tR3DuQ.js} +0 -0
- /package/dist/public/assets/{cytoscape.esm-DAexRXdS.js → cytoscape.esm-DI3FlJaw.js} +0 -0
- /package/dist/public/assets/{defaultLocale-DjcXuYt0.js → defaultLocale-CRhqsANo.js} +0 -0
- /package/dist/public/assets/{desktop-bridge-types-DUvVV0tT.js → desktop-bridge-types-BTzWYfK3.js} +0 -0
- /package/dist/public/assets/{diff-C6rPA7NX.js → diff-Drz_kYcR.js} +0 -0
- /package/dist/public/assets/{dist-K3kyyBcW.js → dist-B0Ibo2lT.js} +0 -0
- /package/dist/public/assets/{dist-DlBs2Z86.js → dist-BR1KZiCX.js} +0 -0
- /package/dist/public/assets/{dist-Bvqpz5aH.js → dist-BRGTi0a4.js} +0 -0
- /package/dist/public/assets/{dist-QYTl87xy.js → dist-URshSBRl.js} +0 -0
- /package/dist/public/assets/{documents-fetch-D9Azkuau.js → documents-fetch-B7M_d64D.js} +0 -0
- /package/dist/public/assets/{external-link-PPmVWR7S.js → external-link-Ds9yTh4D.js} +0 -0
- /package/dist/public/assets/{file-tree-rename-validation-DEJ31Vcw.js → file-tree-rename-validation-DcXYaYEd.js} +0 -0
- /package/dist/public/assets/{folder-open-BO3O3WRb.js → folder-open-DVXRBalt.js} +0 -0
- /package/dist/public/assets/{format-ReH7V0UD.js → format-Dfi8-r7-.js} +0 -0
- /package/dist/public/assets/{git-branch-Bb5seqP3.js → git-branch-BfSSsaKF.js} +0 -0
- /package/dist/public/assets/{go-BDL-nvej.js → go-BpmSPnTF.js} +0 -0
- /package/dist/public/assets/{info-p7xnknfW.js → info-DsmJgZ0m.js} +0 -0
- /package/dist/public/assets/{init-BcRdj30F.js → init-Do59aTWs.js} +0 -0
- /package/dist/public/assets/{input-DBQZgTXT.js → input-tBscWWrn.js} +0 -0
- /package/dist/public/assets/{isObjectLike-p4oxO3k2.js → isObjectLike-DBZB8Di0.js} +0 -0
- /package/dist/public/assets/{katex-lkho_UhZ.js → katex-C_q0VtM5.js} +0 -0
- /package/dist/public/assets/{label-BpH34DoN.js → label-DmfuSB7r.js} +0 -0
- /package/dist/public/assets/{loader-circle-Cu01Ckhe.js → loader-circle-IFoG3v_v.js} +0 -0
- /package/dist/public/assets/{lua-DazQKUZ0.js → lua-C_zL8YdL.js} +0 -0
- /package/dist/public/assets/{mcp-consent-store-3q0L29vA.js → mcp-consent-store-Q4I4TJ6C.js} +0 -0
- /package/dist/public/assets/{min-BBkt5AXx.js → min-CHYmOP54.js} +0 -0
- /package/dist/public/assets/{miss-dialog-store-DxVemLe3.js → miss-dialog-store-E61ZbtU3.js} +0 -0
- /package/dist/public/assets/{panzoom.es-CuUBMiI5.js → panzoom.es-IG_ffrHS.js} +0 -0
- /package/dist/public/assets/{parse-api-error-D_SUnYAN.js → parse-api-error-CKwNHPHP.js} +0 -0
- /package/dist/public/assets/{path-DO8zQ-Ae.js → path-BumxrnWh.js} +0 -0
- /package/dist/public/assets/{pdf-CbXPrrUD.js → pdf-Dfrvv9Dp.js} +0 -0
- /package/dist/public/assets/{pdf.worker-XGhSae8l.js → pdf.worker-BW4O2Ok7.js} +0 -0
- /package/dist/public/assets/{perl-BaZItvTQ.js → perl-CBgKNlH2.js} +0 -0
- /package/dist/public/assets/{properties-CuaVqlKt.js → properties-CYWLEd9P.js} +0 -0
- /package/dist/public/assets/{r-IUsFwQdS.js → r-C7V19TwF.js} +0 -0
- /package/dist/public/assets/{refresh-cw-C9i-ShKk.js → refresh-cw-C6wj273J.js} +0 -0
- /package/dist/public/assets/{rough.esm-DWDlLNAi.js → rough.esm-DGd9yuC8.js} +0 -0
- /package/dist/public/assets/{ruby-BWibniew.js → ruby-XhXUlf0J.js} +0 -0
- /package/dist/public/assets/{share-metadata-rows-VY-5eTfA.js → share-metadata-rows-C9T0cDSG.js} +0 -0
- /package/dist/public/assets/{shell-DUveK2Hb.js → shell-CGj6v8kb.js} +0 -0
- /package/dist/public/assets/{sql-C6MOB-cH.js → sql-CLlqBctF.js} +0 -0
- /package/dist/public/assets/{src-C1bTuxCq.js → src-DHCu-mNI.js} +0 -0
- /package/dist/public/assets/{startup-marks-DdXX18dm.js → startup-marks-DkfPsa68.js} +0 -0
- /package/dist/public/assets/{stex-C0Jw9RbH.js → stex-Bt71ugp5.js} +0 -0
- /package/dist/public/assets/{swift-BD9rjiqY.js → swift-C_3ADj_i.js} +0 -0
- /package/dist/public/assets/{textarea-BBYgAifm.js → textarea-IugbKaIV.js} +0 -0
- /package/dist/public/assets/{toml-25JKpH7B.js → toml-DohB9k6t.js} +0 -0
- /package/dist/public/assets/{trace-api-DN18ByDo.js → trace-api-BIWqyPc9.js} +0 -0
- /package/dist/public/assets/{trash-2-410fw8eF.js → trash-2-DuQrfywu.js} +0 -0
- /package/dist/public/assets/{triangle-alert-Bo8gNh02.js → triangle-alert-CX4BgEzP.js} +0 -0
- /package/dist/public/assets/{w3c-keyname-VSld09PZ.js → w3c-keyname-CRPBoZED.js} +0 -0
- /package/dist/public/assets/{worktree-store-CLuGV1SL.js → worktree-store-DfQ15jw3.js} +0 -0
- /package/dist/public/assets/{x-BIoRq4ww.js → x-Bcc1k6VU.js} +0 -0
|
@@ -301,7 +301,7 @@ Read more at https://docs.orama.com/docs/orama-js/plugins/plugin-secure-proxy#pl
|
|
|
301
301
|
`,PLUGIN_SECURE_PROXY_MISSING_CHAT_MODEL:`Could not find a chat model defined in the secure proxy plugin configuration.
|
|
302
302
|
Please provide a chat model before proceeding with creating an answer session.
|
|
303
303
|
Read more at https://docs.orama.com/docs/orama-js/plugins/plugin-secure-proxy#plugin-secure-proxy
|
|
304
|
-
`,ANSWER_SESSION_LAST_MESSAGE_IS_NOT_ASSISTANT:`The last message in the session is not an assistant message. Cannot regenerate non-assistant messages.`,PLUGIN_COMPONENT_CONFLICT:`The component "%s" is already defined. The plugin "%s" is trying to redefine it.`};function mH(e,...t){let n=Error(GV(pH[e]??`Unsupported Orama Error code: ${e}`,...t));return n.code=e,`captureStackTrace`in Error.prototype&&Error.captureStackTrace(n),n}function hH(e){return{raw:Number(e),formatted:YV(e)}}function gH(e){if(e.id){if(typeof e.id!=`string`)throw mH(`DOCUMENT_ID_MUST_BE_STRING`,typeof e.id);return e.id}return ZV()}function _H(e,t){for(let[n,r]of Object.entries(t)){let t=e[n];if(t!==void 0&&!(r===`geopoint`&&typeof t==`object`&&typeof t.lon==`number`&&typeof t.lat==`number`)&&!(r===`enum`&&(typeof t==`string`||typeof t==`number`))){if(r===`enum[]`&&Array.isArray(t)){let e=t.length;for(let r=0;r<e;r++)if(typeof t[r]!=`string`&&typeof t[r]!=`number`)return n+`.`+r;continue}if(xH(r)){let e=wH(r);if(!Array.isArray(t)||t.length!==e)throw mH(`INVALID_INPUT_VECTOR`,n,e,t.length);continue}if(SH(r)){if(!Array.isArray(t))return n;let e=CH(r),i=t.length;for(let r=0;r<i;r++)if(typeof t[r]!==e)return n+`.`+r;continue}if(typeof r==`object`){if(!t||typeof t!=`object`)return n;let e=_H(t,r);if(e)return n+`.`+e;continue}if(typeof t!==r)return n}}}const vH={string:!1,number:!1,boolean:!1,enum:!1,geopoint:!1,"string[]":!0,"number[]":!0,"boolean[]":!0,"enum[]":!0},yH={"string[]":`string`,"number[]":`number`,"boolean[]":`boolean`,"enum[]":`enum`};function bH(e){return e===`geopoint`}function xH(e){return typeof e==`string`&&/^vector\[\d+\]$/.test(e)}function SH(e){return typeof e==`string`&&vH[e]}function CH(e){return yH[e]}function wH(e){let t=Number(e.slice(7,-1));switch(!0){case isNaN(t):throw mH(`INVALID_VECTOR_VALUE`,e);case t<=0:throw mH(`INVALID_VECTOR_SIZE`,e);default:return t}}function TH(){return{idToInternalId:new Map,internalIdToId:[],save:EH,load:DH}}function EH(e){return{internalIdToId:e.internalIdToId}}function DH(e,t){let{internalIdToId:n}=t;e.internalDocumentIDStore.idToInternalId.clear(),e.internalDocumentIDStore.internalIdToId=[];let r=n.length;for(let t=0;t<r;t++){let r=n[t];e.internalDocumentIDStore.idToInternalId.set(r,t+1),e.internalDocumentIDStore.internalIdToId.push(r)}}function OH(e,t){if(typeof t==`string`){let n=e.idToInternalId.get(t);if(n)return n;let r=e.idToInternalId.size+1;return e.idToInternalId.set(t,r),e.internalIdToId.push(t),r}return t>e.internalIdToId.length?OH(e,t.toString()):t}function kH(e,t){if(e.internalIdToId.length<t)throw Error(`Invalid internalId ${t}`);return e.internalIdToId[t-1]}function AH(e,t){return{sharedInternalDocumentStore:t,docs:{},count:0}}function jH(e,t){let n=OH(e.sharedInternalDocumentStore,t);return e.docs[n]}function MH(e,t){let n=t.length,r=Array.from({length:n});for(let i=0;i<n;i++){let n=OH(e.sharedInternalDocumentStore,t[i]);r[i]=e.docs[n]}return r}function NH(e){return e.docs}function PH(e,t,n,r){return e.docs[n]===void 0?(e.docs[n]=r,e.count++,!0):!1}function FH(e,t){let n=OH(e.sharedInternalDocumentStore,t);return e.docs[n]===void 0?!1:(delete e.docs[n],e.count--,!0)}function IH(e){return e.count}function LH(e,t){let n=t;return{docs:n.docs,count:n.count,sharedInternalDocumentStore:e}}function RH(e){return{docs:e.docs,count:e.count}}function zH(){return{create:AH,get:jH,getMultiple:MH,getAll:NH,store:PH,remove:FH,count:IH,load:LH,save:RH}}const BH=[`beforeInsert`,`afterInsert`,`beforeRemove`,`afterRemove`,`beforeUpdate`,`afterUpdate`,`beforeUpsert`,`afterUpsert`,`beforeSearch`,`afterSearch`,`beforeInsertMultiple`,`afterInsertMultiple`,`beforeRemoveMultiple`,`afterRemoveMultiple`,`beforeUpdateMultiple`,`afterUpdateMultiple`,`beforeUpsertMultiple`,`afterUpsertMultiple`,`beforeLoad`,`afterLoad`,`afterCreate`];function VH(e,t){let n=[],r=e.plugins?.length;if(!r)return n;for(let i=0;i<r;i++)try{let r=e.plugins[i];typeof r[t]==`function`&&n.push(r[t])}catch(e){throw console.error(`Caught error in getAllPluginsByHook:`,e),mH(`PLUGIN_CRASHED`)}return n}const HH=[`tokenizer`,`index`,`documentsStore`,`sorter`,`pinning`],UH=[`validateSchema`,`getDocumentIndexId`,`getDocumentProperties`,`formatElapsedTime`];function WH(e,t,n,r){if(e.some(oH))return(async()=>{for(let i of e)await i(t,n,r)})();for(let i of e)i(t,n,r)}function GH(e,t,n){if(e.some(oH))return(async()=>{for(let r of e)await r(t,n)})();for(let r of e)r(t,n)}function KH(e,t,n,r,i){if(e.some(oH))return(async()=>{for(let a of e)await a(t,n,r,i)})();for(let a of e)a(t,n,r,i)}function qH(e,t,n,r){if(e.some(oH))return(async()=>{for(let i of e)await i(t,n,r)})();for(let i of e)i(t,n,r)}function JH(e,t){if(e.some(oH))return(async()=>{for(let n of e)await n(t)})();for(let n of e)n(t)}var YH=class e{k;v;l=null;r=null;h=1;constructor(e,t){this.k=e,this.v=new Set(t)}updateHeight(){this.h=Math.max(e.getHeight(this.l),e.getHeight(this.r))+1}static getHeight(e){return e?e.h:0}getBalanceFactor(){return e.getHeight(this.l)-e.getHeight(this.r)}rotateLeft(){let e=this.r;return this.r=e.l,e.l=this,this.updateHeight(),e.updateHeight(),e}rotateRight(){let e=this.l;return this.l=e.r,e.r=this,this.updateHeight(),e.updateHeight(),e}toJSON(){return{k:this.k,v:Array.from(this.v),l:this.l?this.l.toJSON():null,r:this.r?this.r.toJSON():null,h:this.h}}static fromJSON(t){let n=new e(t.k,t.v);return n.l=t.l?e.fromJSON(t.l):null,n.r=t.r?e.fromJSON(t.r):null,n.h=t.h,n}},XH=class e{root=null;insertCount=0;constructor(e,t){e!==void 0&&t!==void 0&&(this.root=new YH(e,t))}insert(e,t,n=1e3){this.root=this.insertNode(this.root,e,t,n)}insertMultiple(e,t,n=1e3){for(let r of t)this.insert(e,r,n)}rebalance(){this.root&&=this.rebalanceNode(this.root)}toJSON(){return{root:this.root?this.root.toJSON():null,insertCount:this.insertCount}}static fromJSON(t){let n=new e;return n.root=t.root?YH.fromJSON(t.root):null,n.insertCount=t.insertCount||0,n}insertNode(e,t,n,r){if(e===null)return new YH(t,[n]);let i=[],a=e,o=null;for(;a!==null;)if(i.push({parent:o,node:a}),t<a.k)if(a.l===null){a.l=new YH(t,[n]),i.push({parent:a,node:a.l});break}else o=a,a=a.l;else if(t>a.k)if(a.r===null){a.r=new YH(t,[n]),i.push({parent:a,node:a.r});break}else o=a,a=a.r;else return a.v.add(n),e;let s=!1;this.insertCount++%r===0&&(s=!0);for(let t=i.length-1;t>=0;t--){let{parent:n,node:r}=i[t];if(r.updateHeight(),s){let t=this.rebalanceNode(r);n?n.l===r?n.l=t:n.r===r&&(n.r=t):e=t}}return e}rebalanceNode(e){let t=e.getBalanceFactor();if(t>1){if(e.l&&e.l.getBalanceFactor()>=0)return e.rotateRight();if(e.l)return e.l=e.l.rotateLeft(),e.rotateRight()}if(t<-1){if(e.r&&e.r.getBalanceFactor()<=0)return e.rotateLeft();if(e.r)return e.r=e.r.rotateRight(),e.rotateLeft()}return e}find(e){let t=this.findNodeByKey(e);return t?t.v:null}contains(e){return this.find(e)!==null}getSize(){let e=0,t=[],n=this.root;for(;n||t.length>0;){for(;n;)t.push(n),n=n.l;n=t.pop(),e++,n=n.r}return e}isBalanced(){if(!this.root)return!0;let e=[this.root];for(;e.length>0;){let t=e.pop(),n=t.getBalanceFactor();if(Math.abs(n)>1)return!1;t.l&&e.push(t.l),t.r&&e.push(t.r)}return!0}remove(e){this.root=this.removeNode(this.root,e)}removeDocument(e,t){let n=this.findNodeByKey(e);n&&(n.v.size===1?this.root=this.removeNode(this.root,e):n.v=new Set([...n.v.values()].filter(e=>e!==t)))}findNodeByKey(e){let t=this.root;for(;t;)if(e<t.k)t=t.l;else if(e>t.k)t=t.r;else return t;return null}removeNode(e,t){if(e===null)return null;let n=[],r=e;for(;r!==null&&r.k!==t;)n.push(r),r=t<r.k?r.l:r.r;if(r===null)return e;if(r.l===null||r.r===null){let t=r.l?r.l:r.r;if(n.length===0)e=t;else{let e=n[n.length-1];e.l===r?e.l=t:e.r=t}}else{let e=r,t=r.r;for(;t.l!==null;)e=t,t=t.l;r.k=t.k,r.v=t.v,e.l===t?e.l=t.r:e.r=t.r,r=e}n.push(r);for(let t=n.length-1;t>=0;t--){let r=n[t];r.updateHeight();let i=this.rebalanceNode(r);if(t>0){let e=n[t-1];e.l===r?e.l=i:e.r===r&&(e.r=i)}else e=i}return e}rangeSearch(e,t){let n=new Set,r=[],i=this.root;for(;i||r.length>0;){for(;i;)r.push(i),i=i.l;if(i=r.pop(),i.k>=e&&i.k<=t)for(let e of i.v)n.add(e);if(i.k>t)break;i=i.r}return n}greaterThan(e,t=!1){let n=new Set,r=[],i=this.root;for(;i||r.length>0;){for(;i;)r.push(i),i=i.r;if(i=r.pop(),t&&i.k>=e||!t&&i.k>e)for(let e of i.v)n.add(e);else if(i.k<=e)break;i=i.l}return n}lessThan(e,t=!1){let n=new Set,r=[],i=this.root;for(;i||r.length>0;){for(;i;)r.push(i),i=i.l;if(i=r.pop(),t&&i.k<=e||!t&&i.k<e)for(let e of i.v)n.add(e);else if(i.k>e)break;i=i.r}return n}},ZH=class e{numberToDocumentId;constructor(){this.numberToDocumentId=new Map}insert(e,t){this.numberToDocumentId.has(e)?this.numberToDocumentId.get(e).add(t):this.numberToDocumentId.set(e,new Set([t]))}find(e){let t=this.numberToDocumentId.get(e);return t?Array.from(t):null}remove(e){this.numberToDocumentId.delete(e)}removeDocument(e,t){let n=this.numberToDocumentId.get(t);n&&(n.delete(e),n.size===0&&this.numberToDocumentId.delete(t))}contains(e){return this.numberToDocumentId.has(e)}getSize(){let e=0;for(let t of this.numberToDocumentId.values())e+=t.size;return e}filter(e){let t=Object.keys(e);if(t.length!==1)throw Error(`Invalid operation`);let n=t[0];switch(n){case`eq`:{let t=e[n],r=this.numberToDocumentId.get(t);return r?Array.from(r):[]}case`in`:{let t=e[n],r=new Set;for(let e of t){let t=this.numberToDocumentId.get(e);if(t)for(let e of t)r.add(e)}return Array.from(r)}case`nin`:{let t=new Set(e[n]),r=new Set;for(let[e,n]of this.numberToDocumentId.entries())if(!t.has(e))for(let e of n)r.add(e);return Array.from(r)}default:throw Error(`Invalid operation`)}}filterArr(e){let t=Object.keys(e);if(t.length!==1)throw Error(`Invalid operation`);let n=t[0];switch(n){case`containsAll`:{let t=e[n].map(e=>this.numberToDocumentId.get(e)??new Set);if(t.length===0)return[];let r=t.reduce((e,t)=>new Set([...e].filter(e=>t.has(e))));return Array.from(r)}case`containsAny`:{let t=e[n].map(e=>this.numberToDocumentId.get(e)??new Set);if(t.length===0)return[];let r=t.reduce((e,t)=>new Set([...e,...t]));return Array.from(r)}default:throw Error(`Invalid operation`)}}static fromJSON(t){if(!t.numberToDocumentId)throw Error(`Invalid Flat Tree JSON`);let n=new e;for(let[e,r]of t.numberToDocumentId)n.numberToDocumentId.set(e,new Set(r));return n}toJSON(){return{numberToDocumentId:Array.from(this.numberToDocumentId.entries()).map(([e,t])=>[e,Array.from(t)])}}};function QH(e,t,n){if(n<0)return-1;if(e===t)return 0;let r=e.length,i=t.length;if(r===0)return i<=n?i:-1;if(i===0)return r<=n?r:-1;let a=Math.abs(r-i);if(e.startsWith(t))return a<=n?a:-1;if(t.startsWith(e))return 0;if(a>n)return-1;let o=[];for(let e=0;e<=r;e++){o[e]=[e];for(let t=1;t<=i;t++)o[e][t]=e===0?t:0}for(let a=1;a<=r;a++){let r=1/0;for(let n=1;n<=i;n++)e[a-1]===t[n-1]?o[a][n]=o[a-1][n-1]:o[a][n]=Math.min(o[a-1][n]+1,o[a][n-1]+1,o[a-1][n-1]+1),r=Math.min(r,o[a][n]);if(r>n)return-1}return o[r][i]<=n?o[r][i]:-1}function $H(e,t,n){let r=QH(e,t,n);return{distance:r,isBounded:r>=0}}var eU=class e{k;s;c=new Map;d=new Set;e;w=``;constructor(e,t,n){this.k=e,this.s=t,this.e=n}updateParent(e){this.w=e.w+this.s}addDocument(e){this.d.add(e)}removeDocument(e){return this.d.delete(e)}findAllWords(e,t,n,r){let i=[this];for(;i.length>0;){let a=i.pop();if(a.e){let{w:i,d:o}=a;if(n&&i!==t)continue;if(QV(e,i)!==null)if(r)if(Math.abs(t.length-i.length)<=r&&$H(t,i,r).isBounded)e[i]=[];else continue;else e[i]=[];if(QV(e,i)!=null&&o.size>0){let t=e[i];for(let e of o)t.includes(e)||t.push(e)}}a.c.size>0&&i.push(...a.c.values())}return e}insert(t,n){let r=this,i=0,a=t.length;for(;i<a;){let o=t[i],s=r.c.get(o);if(s){let o=s.s,c=o.length,l=0;for(;l<c&&i+l<a&&o[l]===t[i+l];)l++;if(l===c){if(r=s,i+=l,i===a){s.e||=!0,s.addDocument(n);return}continue}let u=o.slice(0,l),d=o.slice(l),f=t.slice(i+l),p=new e(u[0],u,!1);if(r.c.set(u[0],p),p.updateParent(r),s.s=d,s.k=d[0],p.c.set(d[0],s),s.updateParent(p),f){let t=new e(f[0],f,!0);t.addDocument(n),p.c.set(f[0],t),t.updateParent(p)}else p.e=!0,p.addDocument(n);return}else{let a=new e(o,t.slice(i),!0);a.addDocument(n),r.c.set(o,a),a.updateParent(r);return}}r.e||=!0,r.addDocument(n)}_findLevenshtein(e,t,n,r,i){let a=[{node:this,index:t,tolerance:n}];for(;a.length>0;){let{node:t,index:n,tolerance:o}=a.pop();if(t.w.startsWith(e)){t.findAllWords(i,e,!1,0);continue}if(o<0)continue;if(t.e){let{w:n,d:a}=t;if(n&&($H(e,n,r).isBounded&&(i[n]=[]),QV(i,n)!==void 0&&a.size>0)){let e=new Set(i[n]);for(let t of a)e.add(t);i[n]=Array.from(e)}}if(n>=e.length)continue;let s=e[n];if(t.c.has(s)){let e=t.c.get(s);a.push({node:e,index:n+1,tolerance:o})}a.push({node:t,index:n+1,tolerance:o-1});for(let[e,r]of t.c)a.push({node:r,index:n,tolerance:o-1}),e!==s&&a.push({node:r,index:n+1,tolerance:o-1})}}find(e){let{term:t,exact:n,tolerance:r}=e;if(r&&!n){let e={};return this._findLevenshtein(t,0,r,r,e),e}else{let e=this,i=0,a=t.length;for(;i<a;){let o=t[i],s=e.c.get(o);if(s){let o=s.s,c=o.length,l=0;for(;l<c&&i+l<a&&o[l]===t[i+l];)l++;if(l===c)e=s,i+=l;else if(i+l===a)if(l===a-i){if(n)return{};{let e={};return s.findAllWords(e,t,n,r),e}}else return{};else return{}}else return{}}let o={};return e.findAllWords(o,t,n,r),o}}contains(e){let t=this,n=0,r=e.length;for(;n<r;){let i=e[n],a=t.c.get(i);if(a){let i=a.s,o=i.length,s=0;for(;s<o&&n+s<r&&i[s]===e[n+s];)s++;if(s<o)return!1;n+=o,t=a}else return!1}return!0}removeWord(e){if(!e)return!1;let t=this,n=e.length,r=[];for(let i=0;i<n;i++){let n=e[i];if(t.c.has(n)){let e=t.c.get(n);r.push({parent:t,character:n}),i+=e.s.length-1,t=e}else return!1}for(t.d.clear(),t.e=!1;r.length>0&&t.c.size===0&&!t.e&&t.d.size===0;){let{parent:e,character:n}=r.pop();e.c.delete(n),t=e}return!0}removeDocumentByWord(e,t,n=!0){if(!e)return!0;let r=this,i=e.length;for(let a=0;a<i;a++){let i=e[a];if(r.c.has(i)){let o=r.c.get(i);a+=o.s.length-1,r=o,n&&r.w!==e||r.removeDocument(t)}else return!1}return!0}static getCommonPrefix(e,t){let n=Math.min(e.length,t.length),r=0;for(;r<n&&e.charCodeAt(r)===t.charCodeAt(r);)r++;return e.slice(0,r)}toJSON(){return{w:this.w,s:this.s,e:this.e,k:this.k,d:Array.from(this.d),c:Array.from(this.c?.entries())?.map(([e,t])=>[e,t.toJSON()])}}static fromJSON(t){let n=new e(t.k,t.s,t.e);return n.w=t.w,n.d=new Set(t.d),n.c=new Map(t?.c?.map(([t,n])=>[t,e.fromJSON(n)])||[]),n}},tU=class e extends eU{constructor(){super(``,``,!1)}static fromJSON(t){let n=new e;return n.w=t.w,n.s=t.s,n.e=t.e,n.k=t.k,n.d=new Set(t.d),n.c=new Map(t?.c?.map(([e,t])=>[e,eU.fromJSON(t)])||[]),n}toJSON(){return super.toJSON()}},nU=class e{point;docIDs;left;right;parent;constructor(e,t){this.point=e,this.docIDs=new Set(t),this.left=null,this.right=null,this.parent=null}toJSON(){return{point:this.point,docIDs:Array.from(this.docIDs),left:this.left?this.left.toJSON():null,right:this.right?this.right.toJSON():null}}static fromJSON(t,n=null){let r=new e(t.point,t.docIDs);return r.parent=n,t.left&&(r.left=e.fromJSON(t.left,r)),t.right&&(r.right=e.fromJSON(t.right,r)),r}},rU=class e{root;nodeMap;constructor(){this.root=null,this.nodeMap=new Map}getPointKey(e){return`${e.lon},${e.lat}`}insert(e,t){let n=this.getPointKey(e),r=this.nodeMap.get(n);if(r){t.forEach(e=>r.docIDs.add(e));return}let i=new nU(e,t);if(this.nodeMap.set(n,i),this.root==null){this.root=i;return}let a=this.root,o=0;for(;;){if(o%2==0)if(e.lon<a.point.lon){if(a.left==null){a.left=i,i.parent=a;return}a=a.left}else{if(a.right==null){a.right=i,i.parent=a;return}a=a.right}else if(e.lat<a.point.lat){if(a.left==null){a.left=i,i.parent=a;return}a=a.left}else{if(a.right==null){a.right=i,i.parent=a;return}a=a.right}o++}}contains(e){let t=this.getPointKey(e);return this.nodeMap.has(t)}getDocIDsByCoordinates(e){let t=this.getPointKey(e),n=this.nodeMap.get(t);return n?Array.from(n.docIDs):null}removeDocByID(e,t){let n=this.getPointKey(e),r=this.nodeMap.get(n);r&&(r.docIDs.delete(t),r.docIDs.size===0&&(this.nodeMap.delete(n),this.deleteNode(r)))}deleteNode(e){let t=e.parent,n=e.left?e.left:e.right;n&&(n.parent=t),t?t.left===e?t.left=n:t.right===e&&(t.right=n):(this.root=n,this.root&&(this.root.parent=null))}searchByRadius(t,n,r=!0,i=`asc`,a=!1){let o=a?e.vincentyDistance:e.haversineDistance,s=[{node:this.root,depth:0}],c=[];for(;s.length>0;){let{node:e,depth:i}=s.pop();if(e==null)continue;let a=o(t,e.point);(r?a<=n:a>n)&&c.push({point:e.point,docIDs:Array.from(e.docIDs)}),e.left!=null&&s.push({node:e.left,depth:i+1}),e.right!=null&&s.push({node:e.right,depth:i+1})}return i&&c.sort((e,n)=>{let r=o(t,e.point),a=o(t,n.point);return i.toLowerCase()===`asc`?r-a:a-r}),c}searchByPolygon(t,n=!0,r=null,i=!1){let a=[{node:this.root,depth:0}],o=[];for(;a.length>0;){let{node:r,depth:i}=a.pop();if(r==null)continue;r.left!=null&&a.push({node:r.left,depth:i+1}),r.right!=null&&a.push({node:r.right,depth:i+1});let s=e.isPointInPolygon(t,r.point);(s&&n||!s&&!n)&&o.push({point:r.point,docIDs:Array.from(r.docIDs)})}let s=e.calculatePolygonCentroid(t);if(r){let t=i?e.vincentyDistance:e.haversineDistance;o.sort((e,n)=>{let i=t(s,e.point),a=t(s,n.point);return r.toLowerCase()===`asc`?i-a:a-i})}return o}toJSON(){return{root:this.root?this.root.toJSON():null}}static fromJSON(t){let n=new e;return t.root&&(n.root=nU.fromJSON(t.root),n.buildNodeMap(n.root)),n}buildNodeMap(e){if(e==null)return;let t=this.getPointKey(e.point);this.nodeMap.set(t,e),e.left&&this.buildNodeMap(e.left),e.right&&this.buildNodeMap(e.right)}static calculatePolygonCentroid(e){let t=0,n=0,r=0,i=e.length;for(let a=0,o=i-1;a<i;o=a++){let i=e[a].lon,s=e[a].lat,c=e[o].lon,l=e[o].lat,u=i*l-c*s;t+=u,n+=(i+c)*u,r+=(s+l)*u}t/=2;let a=6*t;return n/=a,r/=a,{lon:n,lat:r}}static isPointInPolygon(e,t){let n=!1,r=t.lon,i=t.lat,a=e.length;for(let t=0,o=a-1;t<a;o=t++){let a=e[t].lon,s=e[t].lat,c=e[o].lon,l=e[o].lat;s>i!=l>i&&r<(c-a)*(i-s)/(l-s)+a&&(n=!n)}return n}static haversineDistance(e,t){let n=Math.PI/180,r=e.lat*n,i=t.lat*n,a=(t.lat-e.lat)*n,o=(t.lon-e.lon)*n,s=Math.sin(a/2)*Math.sin(a/2)+Math.cos(r)*Math.cos(i)*Math.sin(o/2)*Math.sin(o/2);return 6371e3*(2*Math.atan2(Math.sqrt(s),Math.sqrt(1-s)))}static vincentyDistance(e,t){let n=6378137,r=1/298.257223563,i=(1-r)*n,a=Math.PI/180,o=e.lat*a,s=t.lat*a,c=(t.lon-e.lon)*a,l=Math.atan((1-r)*Math.tan(o)),u=Math.atan((1-r)*Math.tan(s)),d=Math.sin(l),f=Math.cos(l),p=Math.sin(u),m=Math.cos(u),h=c,g,_=1e3,v,y,b,x,S,C;do{let e=Math.sin(h),t=Math.cos(h);if(v=Math.sqrt(m*e*(m*e)+(f*p-d*m*t)*(f*p-d*m*t)),v===0)return 0;y=d*p+f*m*t,b=Math.atan2(v,y),x=f*m*e/v,S=1-x*x,C=y-2*d*p/S,isNaN(C)&&(C=0);let n=r/16*S*(4+r*(4-3*S));g=h,h=c+(1-n)*r*x*(b+n*v*(C+n*y*(-1+2*C*C)))}while(Math.abs(h-g)>1e-12&&--_>0);if(_===0)return NaN;let w=S*(n*n-i*i)/(i*i),T=1+w/16384*(4096+w*(-768+w*(320-175*w))),E=w/1024*(256+w*(-128+w*(74-47*w))),ee=E*v*(C+E/4*(y*(-1+2*C*C)-E/6*C*(-3+4*v*v)*(-3+4*C*C)));return i*T*(b-ee)}},iU=class e{true;false;constructor(){this.true=new Set,this.false=new Set}insert(e,t){t?this.true.add(e):this.false.add(e)}delete(e,t){t?this.true.delete(e):this.false.delete(e)}getSize(){return this.true.size+this.false.size}toJSON(){return{true:Array.from(this.true),false:Array.from(this.false)}}static fromJSON(t){let n=new e;return n.true=new Set(t.true),n.false=new Set(t.false),n}};function aU(e,t,n,r,i,{k:a,b:o,d:s}){return Math.log(1+(n-t+.5)/(t+.5))*(s+e*(a+1))/(e+a*(1-o+o*r/i))}var oU=class e{size;vectors=new Map;constructor(e){this.size=e}add(e,t){t instanceof Float32Array||(t=new Float32Array(t));let n=sU(t,this.size);this.vectors.set(e,[n,t])}remove(e){this.vectors.delete(e)}find(e,t,n){return e instanceof Float32Array||(e=new Float32Array(e)),cU(e,n,this.vectors,this.size,t)}toJSON(){let e=[];for(let[t,[n,r]]of this.vectors)e.push([t,[n,Array.from(r)]]);return{size:this.size,vectors:e}}static fromJSON(t){let n=t,r=new e(n.size);for(let[e,[t,i]]of n.vectors)r.vectors.set(e,[t,new Float32Array(i)]);return r}};function sU(e,t){let n=0;for(let r=0;r<t;r++)n+=e[r]*e[r];return Math.sqrt(n)}function cU(e,t,n,r,i){let a=sU(e,r),o=[],s=t||n.keys();for(let t of s){let s=n.get(t);if(!s)continue;let c=s[0],l=s[1],u=0;for(let t=0;t<r;t++)u+=e[t]*l[t];let d=u/(a*c);d>=i&&o.push([t,d])}return o}function lU(e,t,n,r,i){let a=OH(e.sharedInternalDocumentStore,n);e.avgFieldLength[t]=((e.avgFieldLength[t]??0)*(i-1)+r.length)/i,e.fieldLengths[t][a]=r.length,e.frequencies[t][a]={}}function uU(e,t,n,r,i){let a=0;for(let e of r)e===i&&a++;let o=OH(e.sharedInternalDocumentStore,n),s=a/r.length;e.frequencies[t][o][i]=s,i in e.tokenOccurrences[t]||(e.tokenOccurrences[t][i]=0),e.tokenOccurrences[t][i]=(e.tokenOccurrences[t][i]??0)+1}function dU(e,t,n,r){let i=OH(e.sharedInternalDocumentStore,n);r>1?e.avgFieldLength[t]=(e.avgFieldLength[t]*r-e.fieldLengths[t][i])/(r-1):e.avgFieldLength[t]=void 0,e.fieldLengths[t][i]=void 0,e.frequencies[t][i]=void 0}function fU(e,t,n){e.tokenOccurrences[t][n]--}function pU(e,t,n,r,i=``){r||={sharedInternalDocumentStore:t,indexes:{},vectorIndexes:{},searchableProperties:[],searchablePropertiesWithTypes:{},frequencies:{},tokenOccurrences:{},avgFieldLength:{},fieldLengths:{}};for(let[a,o]of Object.entries(n)){let n=`${i}${i?`.`:``}${a}`;if(typeof o==`object`&&!Array.isArray(o)){pU(e,t,o,r,n);continue}if(xH(o))r.searchableProperties.push(n),r.searchablePropertiesWithTypes[n]=o,r.vectorIndexes[n]={type:`Vector`,node:new oU(wH(o)),isArray:!1};else{let e=/\[/.test(o);switch(o){case`boolean`:case`boolean[]`:r.indexes[n]={type:`Bool`,node:new iU,isArray:e};break;case`number`:case`number[]`:r.indexes[n]={type:`AVL`,node:new XH(0,[]),isArray:e};break;case`string`:case`string[]`:r.indexes[n]={type:`Radix`,node:new tU,isArray:e},r.avgFieldLength[n]=0,r.frequencies[n]={},r.tokenOccurrences[n]={},r.fieldLengths[n]={};break;case`enum`:case`enum[]`:r.indexes[n]={type:`Flat`,node:new ZH,isArray:e};break;case`geopoint`:r.indexes[n]={type:`BKD`,node:new rU,isArray:e};break;default:throw mH(`INVALID_SCHEMA_TYPE`,Array.isArray(o)?`array`:o,n)}r.searchableProperties.push(n),r.searchablePropertiesWithTypes[n]=o}}return r}function mU(e,t,n,r,i,a,o,s){return c=>{let{type:l,node:u}=t.indexes[n];switch(l){case`Bool`:u[c?`true`:`false`].add(r);break;case`AVL`:{let e=s?.avlRebalanceThreshold??1;u.insert(c,r,e);break}case`Radix`:{let s=a.tokenize(c,i,n,!1);e.insertDocumentScoreParameters(t,n,r,s,o);for(let i of s)e.insertTokenScoreParameters(t,n,r,s,i),u.insert(i,r);break}case`Flat`:u.insert(c,r);break;case`BKD`:u.insert(c,[r]);break}}}function hU(e,t,n,r,i,a,o,s,c,l,u){if(xH(o))return gU(t,n,a,r,i);let d=mU(e,t,n,i,s,c,l,u);if(!SH(o))return d(a);let f=a,p=f.length;for(let e=0;e<p;e++)d(f[e])}function gU(e,t,n,r,i){e.vectorIndexes[t].node.add(i,n)}function _U(e,t,n,r,i,a,o,s,c,l){if(xH(o))return t.vectorIndexes[n].node.remove(i),!0;let{type:u,node:d}=t.indexes[n];switch(u){case`AVL`:return d.removeDocument(a,i),!0;case`Bool`:return d[a?`true`:`false`].delete(i),!0;case`Radix`:{let o=c.tokenize(a,s,n);e.removeDocumentScoreParameters(t,n,r,l);for(let r of o)e.removeTokenScoreParameters(t,n,r),d.removeDocumentByWord(r,i);return!0}case`Flat`:return d.removeDocument(i,a),!0;case`BKD`:return d.removeDocByID(a,i),!1}}function vU(e,t,n,r,i,a,o,s,c,l){if(!SH(o))return _U(e,t,n,r,i,a,o,s,c,l);let u=CH(o),d=a,f=d.length;for(let a=0;a<f;a++)_U(e,t,n,r,i,d[a],u,s,c,l);return!0}function yU(e,t,n,r,i,a,o,s,c,l){let u=Array.from(r),d=e.avgFieldLength[t],f=e.fieldLengths[t],p=e.tokenOccurrences[t],m=e.frequencies[t],h=typeof p[n]==`number`?p[n]??0:0,g=u.length;for(let e=0;e<g;e++){let r=u[e];if(c&&!c.has(r))continue;l.has(r)||l.set(r,new Map);let p=l.get(r);p.set(t,(p.get(t)||0)+1);let g=aU(m?.[r]?.[n]??0,h,i,f[r],d,a);o.has(r)?o.set(r,o.get(r)+g*s):o.set(r,g*s)}}function bU(e,t,n,r,i,a,o,s,c,l,u,d=0){let f=n.tokenize(t,r),p=f.length||1,m=new Map,h=new Map,g=new Map;for(let n of i){if(!(n in e.indexes))continue;let r=e.indexes[n],{type:i}=r;if(i!==`Radix`)throw mH(`WRONG_SEARCH_PROPERTY_TYPE`,n);let d=s[n]??1;if(d<=0)throw mH(`INVALID_BOOST_VALUE`,d);f.length===0&&!t&&f.push(``);let p=f.length;for(let t=0;t<p;t++){let i=f[t],s=r.node.find({term:i,exact:a,tolerance:o}),p=Object.keys(s);p.length>0&&h.set(i,!0);let _=p.length;for(let t=0;t<_;t++){let r=p[t],i=s[r];yU(e,n,r,i,l,c,g,d,u,m)}}}let _=Array.from(g.entries()).map(([e,t])=>[e,t]).sort((e,t)=>t[1]-e[1]);if(_.length===0)return[];if(d===1)return _;if(d===0){if(p===1)return _;for(let e of f)if(!h.get(e))return[];return _.filter(([e])=>{let t=m.get(e);return t?Array.from(t.values()).some(e=>e===p):!1})}let v=_.filter(([e])=>{let t=m.get(e);return t?Array.from(t.values()).some(e=>e===p):!1});if(v.length>0){let e=_.filter(([e])=>!v.some(([t])=>t===e)),t=Math.ceil(e.length*d);return[...v,...e.slice(0,t)]}return _}function xU(e,t,n,r){if(`and`in n&&n.and&&Array.isArray(n.and)){let i=n.and;return i.length===0?new Set:cH(...i.map(n=>xU(e,t,n,r)))}if(`or`in n&&n.or&&Array.isArray(n.or)){let i=n.or;return i.length===0?new Set:i.map(n=>xU(e,t,n,r)).reduce((e,t)=>uH(e,t),new Set)}if(`not`in n&&n.not){let i=n.not,a=new Set,o=e.sharedInternalDocumentStore;for(let e=1;e<=o.internalIdToId.length;e++)a.add(e);return dH(a,xU(e,t,i,r))}let i=Object.keys(n),a=i.reduce((e,t)=>({[t]:new Set,...e}),{});for(let o of i){let i=n[o];if(e.indexes[o]===void 0)throw mH(`UNKNOWN_FILTER_PROPERTY`,o);let{node:s,type:c,isArray:l}=e.indexes[o];if(c===`Bool`){let e=s,t=i?e.true:e.false;a[o]=uH(a[o],t);continue}if(c===`BKD`){let e;if(`radius`in i)e=`radius`;else if(`polygon`in i)e=`polygon`;else throw Error(`Invalid operation ${i}`);if(e===`radius`){let{value:t,coordinates:n,unit:r=`m`,inside:c=!0,highPrecision:l=!1}=i[e],u=iH(t,r),d=s.searchByRadius(n,u,c,void 0,l);a[o]=DU(a[o],d)}else{let{coordinates:t,inside:n=!0,highPrecision:r=!1}=i[e],c=s.searchByPolygon(t,n,void 0,r);a[o]=DU(a[o],c)}continue}if(c===`Radix`&&(typeof i==`string`||Array.isArray(i))){for(let e of[i].flat()){let n=t.tokenize(e,r,o);for(let e of n){let t=s.find({term:e,exact:!0});a[o]=jU(a[o],t)}}continue}let u=Object.keys(i);if(u.length>1)throw mH(`INVALID_FILTER_OPERATION`,u.length);if(c===`Flat`){let e=new Set(l?s.filterArr(i):s.filter(i));a[o]=uH(a[o],e);continue}if(c===`AVL`){let e=u[0],t=i[e],n;switch(e){case`gt`:n=s.greaterThan(t,!1);break;case`gte`:n=s.greaterThan(t,!0);break;case`lt`:n=s.lessThan(t,!1);break;case`lte`:n=s.lessThan(t,!0);break;case`eq`:n=s.find(t)??new Set;break;case`between`:{let[e,r]=t;n=s.rangeSearch(e,r);break}default:throw mH(`INVALID_FILTER_OPERATION`,e)}a[o]=uH(a[o],n)}}return cH(...Object.values(a))}function SU(e){return e.searchableProperties}function CU(e){return e.searchablePropertiesWithTypes}function wU(e,t){let{indexes:n,vectorIndexes:r,searchableProperties:i,searchablePropertiesWithTypes:a,frequencies:o,tokenOccurrences:s,avgFieldLength:c,fieldLengths:l}=t,u={},d={};for(let e of Object.keys(n)){let{node:t,type:r,isArray:i}=n[e];switch(r){case`Radix`:u[e]={type:`Radix`,node:tU.fromJSON(t),isArray:i};break;case`Flat`:u[e]={type:`Flat`,node:ZH.fromJSON(t),isArray:i};break;case`AVL`:u[e]={type:`AVL`,node:XH.fromJSON(t),isArray:i};break;case`BKD`:u[e]={type:`BKD`,node:rU.fromJSON(t),isArray:i};break;case`Bool`:u[e]={type:`Bool`,node:iU.fromJSON(t),isArray:i};break;default:u[e]=n[e]}}for(let e of Object.keys(r))d[e]={type:`Vector`,isArray:!1,node:oU.fromJSON(r[e])};return{sharedInternalDocumentStore:e,indexes:u,vectorIndexes:d,searchableProperties:i,searchablePropertiesWithTypes:a,frequencies:o,tokenOccurrences:s,avgFieldLength:c,fieldLengths:l}}function TU(e){let{indexes:t,vectorIndexes:n,searchableProperties:r,searchablePropertiesWithTypes:i,frequencies:a,tokenOccurrences:o,avgFieldLength:s,fieldLengths:c}=e,l={};for(let e of Object.keys(n))l[e]=n[e].node.toJSON();let u={};for(let e of Object.keys(t)){let{type:n,node:r,isArray:i}=t[e];n===`Flat`||n===`Radix`||n===`AVL`||n===`BKD`||n===`Bool`?u[e]={type:n,node:r.toJSON(),isArray:i}:(u[e]=t[e],u[e].node=u[e].node.toJSON())}return{indexes:u,vectorIndexes:l,searchableProperties:r,searchablePropertiesWithTypes:i,frequencies:a,tokenOccurrences:o,avgFieldLength:s,fieldLengths:c}}function EU(){return{create:pU,insert:hU,remove:vU,insertDocumentScoreParameters:lU,insertTokenScoreParameters:uU,removeDocumentScoreParameters:dU,removeTokenScoreParameters:fU,calculateResultScores:yU,search:bU,searchByWhereClause:xU,getSearchableProperties:SU,getSearchablePropertiesWithTypes:CU,load:wU,save:TU}}function DU(e,t){e||=new Set;let n=t.length;for(let r=0;r<n;r++){let n=t[r].docIDs,i=n.length;for(let t=0;t<i;t++)e.add(n[t])}return e}function OU(e,t,n=!1){let r=n?rU.vincentyDistance:rU.haversineDistance,i=[],a=[];for(let{point:n}of e)a.push(r(t,n));let o=Math.max(...a),s=0;for(let{docIDs:t}of e){let e=o-a[s]+1;for(let n of t)i.push([n,e]);s++}return i.sort((e,t)=>t[1]-e[1]),i}function kU(e,t){let n=Object.keys(e);if(n.length!==1)return{isGeoOnly:!1};let r=n[0],i=e[r];if(t.indexes[r]===void 0)return{isGeoOnly:!1};let{type:a}=t.indexes[r];return a===`BKD`&&i&&(`radius`in i||`polygon`in i)?{isGeoOnly:!0,geoProperty:r,geoOperation:i}:{isGeoOnly:!1}}function AU(e,t){let n=e,r=kU(t,n);if(!r.isGeoOnly||!r.geoProperty||!r.geoOperation)return null;let{node:i}=n.indexes[r.geoProperty],a=r.geoOperation,o=i,s;if(`radius`in a){let{value:e,coordinates:t,unit:n=`m`,inside:r=!0,highPrecision:i=!1}=a.radius,c=t,l=iH(e,n);return s=o.searchByRadius(c,l,r,`asc`,i),OU(s,c,i)}else if(`polygon`in a){let{coordinates:e,inside:t=!0,highPrecision:n=!1}=a.polygon;s=o.searchByPolygon(e,t,`asc`,n);let r=rU.calculatePolygonCentroid(e);return OU(s,r,n)}return null}function jU(e,t){e||=new Set;let n=Object.keys(t),r=n.length;for(let i=0;i<r;i++){let r=t[n[i]],a=r.length;for(let t=0;t<a;t++)e.add(r[t])}return e}function MU(e,t,n,r,i){let a={language:e.tokenizer.language,sharedInternalDocumentStore:t,enabled:!0,isSorted:!0,sortableProperties:[],sortablePropertiesWithTypes:{},sorts:{}};for(let[o,s]of Object.entries(n)){let n=`${i}${i?`.`:``}${o}`;if(!r.includes(n)){if(typeof s==`object`&&!Array.isArray(s)){let i=MU(e,t,s,r,n);WV(a.sortableProperties,i.sortableProperties),a.sorts={...a.sorts,...i.sorts},a.sortablePropertiesWithTypes={...a.sortablePropertiesWithTypes,...i.sortablePropertiesWithTypes};continue}if(!xH(s))switch(s){case`boolean`:case`number`:case`string`:a.sortableProperties.push(n),a.sortablePropertiesWithTypes[n]=s,a.sorts[n]={docs:new Map,orderedDocsToRemove:new Map,orderedDocs:[],type:s};break;case`geopoint`:case`enum`:continue;case`enum[]`:case`boolean[]`:case`number[]`:case`string[]`:continue;default:throw mH(`INVALID_SORT_SCHEMA_TYPE`,Array.isArray(s)?`array`:s,n)}}}return a}function NU(e,t,n,r){return r?.enabled===!1?{disabled:!0}:MU(e,t,n,(r||{}).unsortableProperties||[],``)}function PU(e,t,n,r){if(!e.enabled)return;e.isSorted=!1;let i=OH(e.sharedInternalDocumentStore,n),a=e.sorts[t];a.orderedDocsToRemove.has(i)&&VU(e,t),a.docs.set(i,a.orderedDocs.length),a.orderedDocs.push([i,r])}function FU(e){if(e.isSorted||!e.enabled)return;let t=Object.keys(e.sorts);for(let n of t)zU(e,n);e.isSorted=!0}function IU(e,t,n){return t[1].localeCompare(n[1],LV(e))}function LU(e,t){return e[1]-t[1]}function RU(e,t){return t[1]?-1:1}function zU(e,t){let n=e.sorts[t],r;switch(n.type){case`string`:r=IU.bind(null,e.language);break;case`number`:r=LU.bind(null);break;case`boolean`:r=RU.bind(null);break}n.orderedDocs.sort(r);let i=n.orderedDocs.length;for(let e=0;e<i;e++){let t=n.orderedDocs[e][0];n.docs.set(t,e)}}function BU(e){let t=Object.keys(e.sorts);for(let n of t)VU(e,n)}function VU(e,t){let n=e.sorts[t];n.orderedDocsToRemove.size&&(n.orderedDocs=n.orderedDocs.filter(e=>!n.orderedDocsToRemove.has(e[0])),n.orderedDocsToRemove.clear())}function HU(e,t,n){if(!e.enabled)return;let r=e.sorts[t],i=OH(e.sharedInternalDocumentStore,n);r.docs.get(i)&&(r.docs.delete(i),r.orderedDocsToRemove.set(i,!0))}function UU(e,t,n){if(!e.enabled)throw mH(`SORT_DISABLED`);let r=n.property,i=n.order===`DESC`,a=e.sorts[r];if(!a)throw mH(`UNABLE_TO_SORT_ON_UNKNOWN_FIELD`,r,e.sortableProperties.join(`, `));return VU(e,r),FU(e),t.sort((t,n)=>{let r=a.docs.get(OH(e.sharedInternalDocumentStore,t[0])),o=a.docs.get(OH(e.sharedInternalDocumentStore,n[0])),s=r!==void 0,c=o!==void 0;return!s&&!c?0:s?c?i?o-r:r-o:-1:1}),t}function WU(e){return e.enabled?e.sortableProperties:[]}function GU(e){return e.enabled?e.sortablePropertiesWithTypes:{}}function KU(e,t){let n=t;if(!n.enabled)return{enabled:!1};let r=Object.keys(n.sorts).reduce((e,t)=>{let{docs:r,orderedDocs:i,type:a}=n.sorts[t];return e[t]={docs:new Map(Object.entries(r).map(([e,t])=>[+e,t])),orderedDocsToRemove:new Map,orderedDocs:i,type:a},e},{});return{sharedInternalDocumentStore:e,language:n.language,sortableProperties:n.sortableProperties,sortablePropertiesWithTypes:n.sortablePropertiesWithTypes,sorts:r,enabled:!0,isSorted:n.isSorted}}function qU(e){if(!e.enabled)return{enabled:!1};BU(e),FU(e);let t=Object.keys(e.sorts).reduce((t,n)=>{let{docs:r,orderedDocs:i,type:a}=e.sorts[n];return t[n]={docs:Object.fromEntries(r.entries()),orderedDocs:i,type:a},t},{});return{language:e.language,sortableProperties:e.sortableProperties,sortablePropertiesWithTypes:e.sortablePropertiesWithTypes,sorts:t,enabled:e.enabled,isSorted:e.isSorted}}function JU(){return{create:NU,insert:PU,remove:HU,save:qU,load:KU,sortBy:UU,getSortableProperties:WU,getSortablePropertiesWithTypes:GU}}const YU=[65,65,65,65,65,65,65,67,69,69,69,69,73,73,73,73,69,78,79,79,79,79,79,null,79,85,85,85,85,89,80,115,97,97,97,97,97,97,97,99,101,101,101,101,105,105,105,105,101,110,111,111,111,111,111,null,111,117,117,117,117,121,112,121,65,97,65,97,65,97,67,99,67,99,67,99,67,99,68,100,68,100,69,101,69,101,69,101,69,101,69,101,71,103,71,103,71,103,71,103,72,104,72,104,73,105,73,105,73,105,73,105,73,105,73,105,74,106,75,107,107,76,108,76,108,76,108,76,108,76,108,78,110,78,110,78,110,110,78,110,79,111,79,111,79,111,79,111,82,114,82,114,82,114,83,115,83,115,83,115,83,115,84,116,84,116,84,116,85,117,85,117,85,117,85,117,85,117,85,117,87,119,89,121,89,90,122,90,122,90,122,115];function XU(e){return e<192||e>383?e:YU[e-192]||e}function ZU(e){let t=[];for(let n=0;n<e.length;n++)t[n]=XU(e.charCodeAt(n));return String.fromCharCode(...t)}const QU={ational:`ate`,tional:`tion`,enci:`ence`,anci:`ance`,izer:`ize`,bli:`ble`,alli:`al`,entli:`ent`,eli:`e`,ousli:`ous`,ization:`ize`,ation:`ate`,ator:`ate`,alism:`al`,iveness:`ive`,fulness:`ful`,ousness:`ous`,aliti:`al`,iviti:`ive`,biliti:`ble`,logi:`log`},$U={icate:`ic`,ative:``,alize:`al`,iciti:`ic`,ical:`ic`,ful:``,ness:``},eW=`[aeiouy]`,tW=`[^aeiou][^aeiouy]*`;eW+``;const nW=`^(`+tW+`)?[aeiouy][aeiou]*[^aeiou][^aeiouy]*`;``+tW;const rW=`^(`+tW+`)?[aeiouy][aeiou]*[^aeiou][^aeiouy]*[aeiouy][aeiou]*[^aeiou][^aeiouy]*`,iW=`^(`+tW+`)?[aeiouy]`;function aW(e){let t,n,r,i,a,o;if(e.length<3)return e;let s=e.substring(0,1);if(s==`y`&&(e=s.toUpperCase()+e.substring(1)),r=/^(.+?)(ss|i)es$/,i=/^(.+?)([^s])s$/,r.test(e)?e=e.replace(r,`$1$2`):i.test(e)&&(e=e.replace(i,`$1$2`)),r=/^(.+?)eed$/,i=/^(.+?)(ed|ing)$/,r.test(e)){let t=r.exec(e);r=new RegExp(nW),r.test(t[1])&&(r=/.$/,e=e.replace(r,``))}else i.test(e)&&(t=i.exec(e)[1],i=new RegExp(iW),i.test(t)&&(e=t,i=/(at|bl|iz)$/,a=RegExp(`([^aeiouylsz])\\1$`),o=RegExp(`^`+tW+eW+`[^aeiouwxy]$`),i.test(e)?e+=`e`:a.test(e)?(r=/.$/,e=e.replace(r,``)):o.test(e)&&(e+=`e`)));if(r=/^(.+?)y$/,r.test(e)&&(t=r.exec(e)?.[1],r=new RegExp(iW),t&&r.test(t)&&(e=t+`i`)),r=/^(.+?)(ational|tional|enci|anci|izer|bli|alli|entli|eli|ousli|ization|ation|ator|alism|iveness|fulness|ousness|aliti|iviti|biliti|logi)$/,r.test(e)){let i=r.exec(e);t=i?.[1],n=i?.[2],r=new RegExp(nW),t&&r.test(t)&&(e=t+QU[n])}if(r=/^(.+?)(icate|ative|alize|iciti|ical|ful|ness)$/,r.test(e)){let i=r.exec(e);t=i?.[1],n=i?.[2],r=new RegExp(nW),t&&r.test(t)&&(e=t+$U[n])}if(r=/^(.+?)(al|ance|ence|er|ic|able|ible|ant|ement|ment|ent|ou|ism|ate|iti|ous|ive|ize)$/,i=/^(.+?)(s|t)(ion)$/,r.test(e))t=r.exec(e)?.[1],r=new RegExp(rW),t&&r.test(t)&&(e=t);else if(i.test(e)){let n=i.exec(e);t=n?.[1]??``+n?.[2]??``,i=new RegExp(rW),i.test(t)&&(e=t)}return r=/^(.+?)e$/,r.test(e)&&(t=r.exec(e)?.[1],r=new RegExp(rW),i=RegExp(`^([^aeiou][^aeiouy]*)?[aeiouy][aeiou]*[^aeiou][^aeiouy]*([aeiouy][aeiou]*)?$`),a=RegExp(`^`+tW+eW+`[^aeiouwxy]$`),t&&(r.test(t)||i.test(t)&&!a.test(t))&&(e=t)),r=/ll$/,i=new RegExp(rW),r.test(e)&&i.test(e)&&(r=/.$/,e=e.replace(r,``)),s==`y`&&(e=s.toLowerCase()+e.substring(1)),e}function oW(e,t,n=!0){let r=`${this.language}:${e}:${t}`;return n&&this.normalizationCache.has(r)?this.normalizationCache.get(r):this.stopWords?.includes(t)?(n&&this.normalizationCache.set(r,``),``):(this.stemmer&&!this.stemmerSkipProperties.has(e)&&(t=this.stemmer(t)),t=ZU(t),n&&this.normalizationCache.set(r,t),t)}function sW(e){for(;e[e.length-1]===``;)e.pop();for(;e[0]===``;)e.shift();return e}function cW(e,t,n,r=!0){if(t&&t!==this.language)throw mH(`LANGUAGE_NOT_SUPPORTED`,t);if(typeof e!=`string`)return[e];let i=this.normalizeToken.bind(this,n??``),a;if(n&&this.tokenizeSkipProperties.has(n))a=[i(e,r)];else{let t=FV[this.language];a=e.toLowerCase().split(t).map(e=>i(e,r)).filter(Boolean)}let o=sW(a);return this.allowDuplicates?o:Array.from(new Set(o))}function lW(e={}){if(!e.language)e.language=`english`;else if(!IV.includes(e.language))throw mH(`LANGUAGE_NOT_SUPPORTED`,e.language);let t;if(e.stemming||e.stemmer&&!(`stemming`in e))if(e.stemmer){if(typeof e.stemmer!=`function`)throw mH(`INVALID_STEMMER_FUNCTION_TYPE`);t=e.stemmer}else if(e.language===`english`)t=aW;else throw mH(`MISSING_STEMMER`,e.language);let n;if(e.stopWords!==!1){if(n=[],Array.isArray(e.stopWords))n=e.stopWords;else if(typeof e.stopWords==`function`)n=e.stopWords(n);else if(e.stopWords)throw mH(`CUSTOM_STOP_WORDS_MUST_BE_FUNCTION_OR_ARRAY`);if(!Array.isArray(n))throw mH(`CUSTOM_STOP_WORDS_MUST_BE_FUNCTION_OR_ARRAY`);for(let e of n)if(typeof e!=`string`)throw mH(`CUSTOM_STOP_WORDS_MUST_BE_FUNCTION_OR_ARRAY`)}let r={tokenize:cW,language:e.language,stemmer:t,stemmerSkipProperties:new Set(e.stemmerSkipProperties?[e.stemmerSkipProperties].flat():[]),tokenizeSkipProperties:new Set(e.tokenizeSkipProperties?[e.tokenizeSkipProperties].flat():[]),stopWords:n,allowDuplicates:!!e.allowDuplicates,normalizeToken:oW,normalizationCache:new Map};return r.tokenize=cW.bind(r),r.normalizeToken=oW,r}function uW(e){return{sharedInternalDocumentStore:e,rules:new Map}}function dW(e,t){if(e.rules.has(t.id))throw Error(`PINNING_RULE_ALREADY_EXISTS: A pinning rule with id "${t.id}" already exists. Use updateRule to modify it.`);e.rules.set(t.id,t)}function fW(e,t){if(!e.rules.has(t.id))throw Error(`PINNING_RULE_NOT_FOUND: Cannot update pinning rule with id "${t.id}" because it does not exist. Use addRule to create it.`);e.rules.set(t.id,t)}function pW(e,t){return e.rules.delete(t)}function mW(e,t){return e.rules.get(t)}function hW(e){return Array.from(e.rules.values())}function gW(e,t){let n=e.toLowerCase().trim(),r=t.pattern.toLowerCase().trim();switch(t.anchoring){case`is`:return n===r;case`starts_with`:return n.startsWith(r);case`contains`:return n.includes(r);default:return!1}}function _W(e,t){return e?t.conditions.every(t=>gW(e,t)):!1}function vW(e,t){if(!t)return[];let n=[];for(let r of e.rules.values())_W(t,r)&&n.push(r);return n}function yW(e,t){return{sharedInternalDocumentStore:e,rules:new Map(t?.rules??[])}}function bW(e){return{rules:Array.from(e.rules.entries())}}function xW(){return{create:uW,addRule:dW,updateRule:fW,removeRule:pW,getRule:mW,getAllRules:hW,getMatchingRules:vW,load:yW,save:bW}}function SW(e){let t={formatElapsedTime:hH,getDocumentIndexId:gH,getDocumentProperties:tH,validateSchema:_H};for(let n of UH){let r=n;if(e[r]){if(typeof e[r]!=`function`)throw mH(`COMPONENT_MUST_BE_FUNCTION`,r)}else e[r]=t[r]}for(let t of Object.keys(e))if(!HH.includes(t)&&!UH.includes(t))throw mH(`UNSUPPORTED_COMPONENT`,t)}function CW({schema:e,sort:t,language:n,components:r,id:i,plugins:a}){r||={};for(let t of a??[]){if(!(`getComponents`in t)||typeof t.getComponents!=`function`)continue;let n=t.getComponents(e),i=Object.keys(n);for(let e of i)if(r[e])throw mH(`PLUGIN_COMPONENT_CONFLICT`,e,t.name);r={...r,...n}}i||=ZV();let o=r.tokenizer,s=r.index,c=r.documentsStore,l=r.sorter,u=r.pinning;if(o=o?o.tokenize?o:lW(o):lW({language:n??`english`}),r.tokenizer&&n)throw mH(`NO_LANGUAGE_WITH_CUSTOM_TOKENIZER`);let d=TH();s||=EU(),l||=JU(),c||=zH(),u||=xW(),SW(r);let{getDocumentProperties:f,getDocumentIndexId:p,validateSchema:m,formatElapsedTime:h}=r,g={data:{},caches:{},schema:e,tokenizer:o,index:s,sorter:l,documentsStore:c,pinning:u,internalDocumentIDStore:d,getDocumentProperties:f,getDocumentIndexId:p,validateSchema:m,beforeInsert:[],afterInsert:[],beforeRemove:[],afterRemove:[],beforeUpdate:[],afterUpdate:[],beforeUpsert:[],afterUpsert:[],beforeSearch:[],afterSearch:[],beforeInsertMultiple:[],afterInsertMultiple:[],beforeRemoveMultiple:[],afterRemoveMultiple:[],beforeUpdateMultiple:[],afterUpdateMultiple:[],beforeUpsertMultiple:[],afterUpsertMultiple:[],afterCreate:[],formatElapsedTime:h,id:i,plugins:a,version:wW()};g.data={index:g.index.create(g,d,e),docs:g.documentsStore.create(g,d),sorting:g.sorter.create(g,d,e,t),pinning:g.pinning.create(d)};for(let e of BH)g[e]=(g[e]??[]).concat(VH(g,e));let _=g.afterCreate;return _&&JH(_,g),g}function wW(){return`{{VERSION}}`}function TW(e){return e.documentsStore.count(e.data.docs)}function EW(e,t,n,r,i){let a=e.validateSchema(t,e.schema);if(a)throw mH(`SCHEMA_VALIDATION_FAILURE`,a);return oH(e.beforeInsert)||oH(e.afterInsert)||oH(e.index.beforeInsert)||oH(e.index.insert)||oH(e.index.afterInsert)?kW(e,t,n,r,i):AW(e,t,n,r,i)}const DW=new Set([`enum`,`enum[]`]),OW=new Set([`string`,`number`]);async function kW(e,t,n,r,i){let{index:a,docs:o}=e.data,s=e.getDocumentIndexId(t);if(typeof s!=`string`)throw mH(`DOCUMENT_ID_MUST_BE_STRING`,typeof s);let c=OH(e.internalDocumentIDStore,s);if(r||await WH(e.beforeInsert,e,s,t),!e.documentsStore.store(o,s,c,t))throw mH(`DOCUMENT_ALREADY_EXISTS`,s);let l=e.documentsStore.count(o),u=e.index.getSearchableProperties(a),d=e.index.getSearchablePropertiesWithTypes(a),f=e.getDocumentProperties(t,u);for(let[e,t]of Object.entries(f)){if(t===void 0)continue;let n=typeof t,r=d[e];jW(n,r,e,t)}return await MW(e,s,u,f,l,n,t,i),r||await WH(e.afterInsert,e,s,t),s}function AW(e,t,n,r,i){let{index:a,docs:o}=e.data,s=e.getDocumentIndexId(t);if(typeof s!=`string`)throw mH(`DOCUMENT_ID_MUST_BE_STRING`,typeof s);let c=OH(e.internalDocumentIDStore,s);if(r||WH(e.beforeInsert,e,s,t),!e.documentsStore.store(o,s,c,t))throw mH(`DOCUMENT_ALREADY_EXISTS`,s);let l=e.documentsStore.count(o),u=e.index.getSearchableProperties(a),d=e.index.getSearchablePropertiesWithTypes(a),f=e.getDocumentProperties(t,u);for(let[e,t]of Object.entries(f)){if(t===void 0)continue;let n=typeof t,r=d[e];jW(n,r,e,t)}return NW(e,s,u,f,l,n,t,i),r||WH(e.afterInsert,e,s,t),s}function jW(e,t,n,r){if(!(bH(t)&&typeof r==`object`&&typeof r.lon==`number`&&typeof r.lat==`number`)&&!(xH(t)&&Array.isArray(r))&&!(SH(t)&&Array.isArray(r))&&!(DW.has(t)&&OW.has(e))&&e!==t)throw mH(`INVALID_DOCUMENT_PROPERTY`,n,t,e)}async function MW(e,t,n,r,i,a,o,s){for(let o of n){let n=r[o];if(n===void 0)continue;let c=e.index.getSearchablePropertiesWithTypes(e.data.index)[o];await e.index.beforeInsert?.(e.data.index,o,t,n,c,a,e.tokenizer,i);let l=e.internalDocumentIDStore.idToInternalId.get(t);await e.index.insert(e.index,e.data.index,o,t,l,n,c,a,e.tokenizer,i,s),await e.index.afterInsert?.(e.data.index,o,t,n,c,a,e.tokenizer,i)}let c=e.sorter.getSortableProperties(e.data.sorting),l=e.getDocumentProperties(o,c);for(let n of c){let r=l[n];if(r===void 0)continue;let i=e.sorter.getSortablePropertiesWithTypes(e.data.sorting)[n];e.sorter.insert(e.data.sorting,n,t,r,i,a)}}function NW(e,t,n,r,i,a,o,s){for(let o of n){let n=r[o];if(n===void 0)continue;let c=e.index.getSearchablePropertiesWithTypes(e.data.index)[o],l=OH(e.internalDocumentIDStore,t);e.index.beforeInsert?.(e.data.index,o,t,n,c,a,e.tokenizer,i),e.index.insert(e.index,e.data.index,o,t,l,n,c,a,e.tokenizer,i,s),e.index.afterInsert?.(e.data.index,o,t,n,c,a,e.tokenizer,i)}let c=e.sorter.getSortableProperties(e.data.sorting),l=e.getDocumentProperties(o,c);for(let n of c){let r=l[n];if(r===void 0)continue;let i=e.sorter.getSortablePropertiesWithTypes(e.data.sorting)[n];e.sorter.insert(e.data.sorting,n,t,r,i,a)}}function PW(e,t,n,r,i,a){return oH(e.afterInsertMultiple)||oH(e.beforeInsertMultiple)||oH(e.index.beforeInsert)||oH(e.index.insert)||oH(e.index.afterInsert)?FW(e,t,n,r,i,a):IW(e,t,n,r,i,a)}async function FW(e,t,n=1e3,r,i,a=0){let o=[],s=async a=>{let s=Math.min(a+n,t.length),c=t.slice(a,s);for(let t of c){let n=await EW(e,t,r,i,{avlRebalanceThreshold:c.length});o.push(n)}return s};return await(async()=>{let e=0;for(;e<t.length;){let t=Date.now();if(e=await s(e),a>0){let e=a-(Date.now()-t);e>0&&fH(e)}}})(),i||await GH(e.afterInsertMultiple,e,t),o}function IW(e,t,n=1e3,r,i,a=0){let o=[],s=0;function c(){let a=t.slice(s*n,(s+1)*n);if(a.length===0)return!1;for(let t of a){let n=EW(e,t,r,i,{avlRebalanceThreshold:a.length});o.push(n)}return s++,!0}function l(){let e=Date.now();for(;c();)if(a>0){let t=Date.now()-e;if(t>=a){let e=a-t%a;e>0&&fH(e)}}}return l(),i||GH(e.afterInsertMultiple,e,t),o}function LW(e,t){return e[1]-t[1]}function RW(e,t){return t[1]-e[1]}function zW(e=`desc`){return e.toLowerCase()===`asc`?LW:RW}function BW(e,t,n){let r={},i=t.map(([e])=>e),a=e.documentsStore.getMultiple(e.data.docs,i),o=Object.keys(n),s=e.index.getSearchablePropertiesWithTypes(e.data.index);for(let e of o){let t;if(s[e]===`number`){let{ranges:r}=n[e],i=r.length,a=Array.from({length:i});for(let e=0;e<i;e++){let t=r[e];a[e]=[`${t.from}-${t.to}`,0]}t=Object.fromEntries(a)}r[e]={count:0,values:t??{}}}let c=a.length;for(let e=0;e<c;e++){let t=a[e];for(let e of o){let i=e.includes(`.`)?nH(t,e):t[e],a=s[e],o=r[e].values;switch(a){case`number`:{let t=n[e].ranges;VW(t,o)(i);break}case`number[]`:{let t=new Set,r=n[e].ranges,a=VW(r,o,t);for(let e of i)a(e);break}case`boolean`:case`enum`:case`string`:HW(o,a)(i);break;case`boolean[]`:case`enum[]`:case`string[]`:{let e=HW(o,a===`boolean[]`?`boolean`:`string`,new Set);for(let t of i)e(t);break}default:throw mH(`FACET_NOT_SUPPORTED`,a)}}}for(let e of o){let t=r[e];if(t.count=Object.keys(t.values).length,s[e]===`string`){let r=n[e],i=zW(r.sort);t.values=Object.fromEntries(Object.entries(t.values).sort(i).slice(r.offset??0,r.limit??10))}}return r}function VW(e,t,n){return r=>{for(let i of e){let e=`${i.from}-${i.to}`;n?.has(e)||r>=i.from&&r<=i.to&&(t[e]===void 0?t[e]=1:(t[e]++,n?.add(e)))}}}function HW(e,t,n){let r=t===`boolean`?`false`:``;return t=>{let i=t?.toString()??r;n?.has(i)||(e[i]=(e[i]??0)+1,n?.add(i))}}const UW={reducer:(e,t,n,r)=>(t[r]=n,t),getInitialValue:e=>Array.from({length:e})},WW=[`string`,`number`,`boolean`];function GW(e,t,n){let r=n.properties,i=r.length,a=e.index.getSearchablePropertiesWithTypes(e.data.index);for(let e=0;e<i;e++){let t=r[e];if(a[t]===void 0)throw mH(`UNKNOWN_GROUP_BY_PROPERTY`,t);if(!WW.includes(a[t]))throw mH(`INVALID_GROUP_BY_PROPERTY`,t,WW.join(`, `),a[t])}let o=t.map(([t])=>kH(e.internalDocumentIDStore,t)),s=e.documentsStore.getMultiple(e.data.docs,o),c=s.length,l=n.maxResult||2**53-1,u=[],d={};for(let e=0;e<i;e++){let t=r[e],n={property:t,perValue:{}},i=new Set;for(let e=0;e<c;e++){let r=s[e],a=nH(r,t);if(a===void 0)continue;let o=typeof a==`boolean`?``+a:a,c=n.perValue[o]??{indexes:[],count:0};c.count>=l||(c.indexes.push(e),c.count++,n.perValue[o]=c,i.add(a))}u.push(Array.from(i)),d[t]=n}let f=KW(u),p=f.length,m=[];for(let e=0;e<p;e++){let t=f[e],n=t.length,i={values:[],indexes:[]},a=[];for(let e=0;e<n;e++){let n=t[e],o=r[e];a.push(d[o].perValue[typeof n==`boolean`?``+n:n].indexes),i.values.push(n)}i.indexes=eH(a).sort((e,t)=>e-t),i.indexes.length!==0&&m.push(i)}let h=m.length,g=Array.from({length:h});for(let e=0;e<h;e++){let r=m[e],i=n.reduce||UW,a=r.indexes.map(e=>({id:o[e],score:t[e][1],document:s[e]})),c=i.reducer.bind(null,r.values),l=i.getInitialValue(r.indexes.length),u=a.reduce(c,l);g[e]={values:r.values,result:u}}return g}function KW(e,t=0){if(t+1===e.length)return e[t].map(e=>[e]);let n=e[t],r=KW(e,t+1),i=[];for(let e of n)for(let t of r){let n=[e];WV(n,t),i.push(n)}return i}function qW(e,t,n,r){let i=vW(t,r);if(i.length===0)return n;let a=i.flatMap(e=>e.consequence.promote);a.sort((e,t)=>e.position-t.position);let o=new Set,s=new Map,c=new Set;for(let t of a){let n=OH(e.internalDocumentIDStore,t.doc_id);if(n!==void 0){if(s.has(n)){let e=s.get(n);t.position<e&&s.set(n,t.position);continue}c.has(t.position)||(o.add(n),s.set(n,t.position),c.add(t.position))}}if(s.size===0)return n;let l=n.filter(([e])=>!o.has(e)),u=[];for(let[t,r]of s.entries())n.find(([e])=>e===t)?u.push([t,1e6-r]):e.documentsStore.get(e.data.docs,t)&&u.push([t,0]);u.sort((e,t)=>(s.get(e[0])??1/0)-(s.get(t[0])??1/0));let d=[],f=new Map;for(let e of u){let t=s.get(e[0]);f.set(t,e)}let p=0,m=0;for(;m<l.length+u.length;)if(f.has(m))d.push(f.get(m)),m++;else if(p<l.length)d.push(l[p]),p++,m++;else break;for(let[e,t]of f.entries())e>=d.length&&d.push(t);return d}function JW(e,t,n){let{term:r,properties:i}=t,a=e.data.index,o=e.caches.propertiesToSearch;if(!o){let t=e.index.getSearchablePropertiesWithTypes(a);o=e.index.getSearchableProperties(a),o=o.filter(e=>t[e].startsWith(`string`)),e.caches.propertiesToSearch=o}if(i&&i!==`*`){for(let e of i)if(!o.includes(e))throw mH(`UNKNOWN_INDEX`,e,o.join(`, `));o=o.filter(e=>i.includes(e))}let s=Object.keys(t.where??{}).length>0,c;s&&(c=e.index.searchByWhereClause(a,e.tokenizer,t.where,n));let l,u=t.threshold!==void 0&&t.threshold!==null?t.threshold:1;if(r||i){let i=TW(e);if(l=e.index.search(a,r||``,e.tokenizer,n,o,t.exact||!1,t.tolerance||0,t.boost||{},$W(t.relevance),i,c,u),t.exact&&r){let t=r.trim().split(/\s+/);l=l.filter(([n])=>{let r=e.documentsStore.get(e.data.docs,n);if(!r)return!1;for(let e of o){let n=XW(r,e);if(typeof n==`string`&&t.every(e=>RegExp(`\\b${YW(e)}\\b`).test(n)))return!0}return!1})}}else l=s?AU(a,t.where)||(c?Array.from(c):[]).map(e=>[+e,0]):Object.keys(e.documentsStore.getAll(e.data.docs)).map(e=>[+e,0]);return l}function YW(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function XW(e,t){let n=t.split(`.`),r=e;for(let e of n)if(r&&typeof r==`object`&&e in r)r=r[e];else return;return r}function ZW(e,t,n){let r=XV();function i(){let i=Object.keys(e.data.index.vectorIndexes),a=t.facets&&Object.keys(t.facets).length>0,{limit:o=10,offset:s=0,distinctOn:c,includeVectors:l=!1}=t,u=t.preflight===!0,d=JW(e,t,n);if(t.sortBy)if(typeof t.sortBy==`function`){let n=d.map(([e])=>e),r=e.documentsStore.getMultiple(e.data.docs,n).map((e,t)=>[d[t][0],d[t][1],e]);r.sort(t.sortBy),d=r.map(([e,t])=>[e,t])}else d=e.sorter.sortBy(e.data.sorting,d,t.sortBy).map(([t,n])=>[OH(e.internalDocumentIDStore,t),n]);else d=d.sort($V);d=qW(e,e.data.pinning,d,t.term);let f;u||(f=c?dG(e,d,s,o,c):fG(e,d,s,o));let p={elapsed:{formatted:``,raw:0},hits:[],count:d.length};return f!==void 0&&(p.hits=f.filter(Boolean),l||aH(p,i)),a&&(p.facets=BW(e,d,t.facets)),t.groupBy&&(p.groups=GW(e,d,t.groupBy)),p.elapsed=e.formatElapsedTime(XV()-r),p}async function a(){e.beforeSearch&&await qH(e.beforeSearch,e,t,n);let r=i();return e.afterSearch&&await KH(e.afterSearch,e,t,n,r),r}return e.beforeSearch?.length||e.afterSearch?.length?a():i()}const QW={k:1.2,b:.75,d:.5};function $W(e){let t=e??{};return t.k=t.k??QW.k,t.b=t.b??QW.b,t.d=t.d??QW.d,t}function eG(e,t,n){let r=t.vector;if(r&&(!(`value`in r)||!(`property`in r)))throw mH(`INVALID_VECTOR_INPUT`,Object.keys(r).join(`, `));let i=e.data.index.vectorIndexes[r.property];if(!i)throw mH(`UNKNOWN_VECTOR_PROPERTY`,r.property);let a=i.node.size;if(r?.value.length!==a)throw r?.property===void 0||r?.value.length===void 0?mH(`INVALID_INPUT_VECTOR`,`undefined`,a,`undefined`):mH(`INVALID_INPUT_VECTOR`,r.property,a,r.value.length);let o=e.data.index,s;return Object.keys(t.where??{}).length>0&&(s=e.index.searchByWhereClause(o,e.tokenizer,t.where,n)),i.node.find(r.value,t.similarity??.8,s)}function tG(e,t,n=`english`){let r=XV();function i(){let i=eG(e,t,n).sort($V);i=qW(e,e.data.pinning,i,void 0);let a=[];t.facets&&Object.keys(t.facets).length>0&&(a=BW(e,i,t.facets));let o=t.vector.property,s=t.includeVectors??!1,c=t.limit??10,l=t.offset??0,u=Array.from({length:c});for(let t=0;t<c;t++){let n=i[t+l];if(!n)break;let r=e.data.docs.docs[n[0]];r&&(s||(r[o]=null),u[t]={id:kH(e.internalDocumentIDStore,n[0]),score:n[1],document:r})}let d=[];t.groupBy&&(d=GW(e,i,t.groupBy));let f=XV()-r;return{count:i.length,hits:u.filter(Boolean),elapsed:{raw:Number(f),formatted:YV(f)},...a?{facets:a}:{},...d?{groups:d}:{}}}async function a(){e.beforeSearch&&await qH(e.beforeSearch,e,t,n);let r=i();return e.afterSearch&&await KH(e.afterSearch,e,t,n,r),r}return e.beforeSearch?.length||e.afterSearch?.length?a():i()}function nG(e,t,n){let r=aG(JW(e,t,n)),i=eG(e,t,n),a=t.hybridWeights;return cG(r,i,t.term??``,a)}function rG(e,t,n){let r=XV();function i(){let i=nG(e,t,n);i=qW(e,e.data.pinning,i,t.term);let a;t.facets&&Object.keys(t.facets).length>0&&(a=BW(e,i,t.facets));let o;t.groupBy&&(o=GW(e,i,t.groupBy));let s=t.offset??0,c=t.limit??10,l=fG(e,i,s,c).filter(Boolean),u=XV(),d={count:i.length,elapsed:{raw:Number(u-r),formatted:YV(u-r)},hits:l,...a?{facets:a}:{},...o?{groups:o}:{}};return(t.includeVectors??!1)||aH(d,Object.keys(e.data.index.vectorIndexes)),d}async function a(){e.beforeSearch&&await qH(e.beforeSearch,e,t,n);let r=i();return e.afterSearch&&await KH(e.afterSearch,e,t,n,r),r}return e.beforeSearch?.length||e.afterSearch?.length?a():i()}function iG(e){return e[1]}function aG(e){let t=Math.max.apply(Math,e.map(iG));return e.map(([e,n])=>[e,n/t])}function oG(e,t){return e/t}function sG(e,t){return(n,r)=>n*e+r*t}function cG(e,t,n,r){let i=Math.max.apply(Math,e.map(iG)),a=Math.max.apply(Math,t.map(iG)),{text:o,vector:s}=r&&r.text&&r.vector?r:lG(n),c=new Map,l=e.length,u=sG(o,s);for(let t=0;t<l;t++){let[n,r]=e[t],a=u(oG(r,i),0);c.set(n,a)}let d=t.length;for(let e=0;e<d;e++){let[n,r]=t[e],i=oG(r,a),o=c.get(n)??0;c.set(n,o+u(0,i))}return[...c].sort((e,t)=>t[1]-e[1])}function lG(e){return{text:.5,vector:.5}}function uG(e,t,n){let r=t.mode??`fulltext`;if(r===`fulltext`)return ZW(e,t,n);if(r===`vector`)return tG(e,t);if(r===`hybrid`)return rG(e,t);throw mH(`INVALID_SEARCH_MODE`,r)}function dG(e,t,n,r,i){let a=e.data.docs,o=new Map,s=[],c=new Set,l=t.length,u=0;for(let d=0;d<l;d++){let l=t[d];if(l===void 0)continue;let[f,p]=l;if(c.has(f))continue;let m=e.documentsStore.get(a,f),h=nH(m,i);if(!(h===void 0||o.has(h))&&(o.set(h,!0),u++,!(u<=n)&&(s.push({id:kH(e.internalDocumentIDStore,f),score:p,document:m}),c.add(f),u>=n+r)))break}return s}function fG(e,t,n,r){let i=e.data.docs,a=Array.from({length:r}),o=new Set;for(let s=n;s<r+n;s++){let n=t[s];if(n===void 0)break;let[r,c]=n;if(!o.has(r)){let t=e.documentsStore.get(i,r);a[s]={id:kH(e.internalDocumentIDStore,r),score:c,document:t},o.add(r)}}return a}var pG=n(kV(),1);const mG=1,hG={protocol:`x-ok-client-protocol`,runtime:`x-ok-client-runtime`,kind:`x-ok-client-kind`};function gG({kind:e,runtimeVersion:t}){return{[hG.protocol]:`1`,[hG.runtime]:t,[hG.kind]:e}}const _G=`__system__`,vG=1,yG=`__config__/project`,bG=`__user__/config.yml`,xG=`__local__/project`,SG=`__config__/okignore`,CG=Object.freeze([yG,xG,bG,SG]),wG=`__skill__/`,TG=`__template__/`,EG=[`project`,`global`];function DG(e){return e.startsWith(`__skill__/`)||e.startsWith(`__template__/`)}const OG=`.ok/skills`;function kG(e){return`${OG}/${e}/SKILL`}const AG=[`references`,`scripts`];function jG(e,t){let n=/^(\.ok\/skills\/[^/]+)\/SKILL$/.exec(t);if(!n)return null;let r=n[1],i=e.trim().replace(/\.mdx?$/i,``).split(`/`).filter(e=>e!==``&&e!==`.`),[a]=i;return!a||!AG.includes(a)||i.includes(`..`)||i.length<2?null:`${r}/${i.join(`/`)}`}const MG=/^\.ok\/skills\/([^/]+)\/(SKILL|references\/.+)$/;function NG(e){let t=MG.exec(e);if(!t)return null;let n=t[1],r=t[2];return r===`SKILL`?{name:n,kind:`skill`,rel:null}:{name:n,kind:`reference`,rel:r.slice(11)}}const PG=/^__skill__\/global\/([^/]+)(?:\/(references\/.+))?$/;function FG(e){let t=PG.exec(e);if(!t)return null;let n=t[1],r=t[2];return r===void 0?{name:n,kind:`skill`,rel:null}:{name:n,kind:`reference`,rel:r.slice(11)}}function IG(e,t){return e===`project`?kG(t):`${wG}${e}/${t}`}function LG(e){if(e===``)return``;try{return e.split(`/`).map(e=>decodeURIComponent(e)).join(`/`)}catch{return e}}function RG(e){if(e.startsWith(`__skill__/`)){let t=e.slice(10),n=t.indexOf(`/`);if(n<0)return null;let r=t.slice(0,n);if(r!==`global`&&r!==`project`)return null;let i=t.slice(n+1);return i?{kind:`skill`,scope:r,name:LG(i)}:null}if(e.startsWith(`__template__/`)){let t=e.slice(13);if(!t)return null;let n=t.lastIndexOf(`/`),r=n<0?t:t.slice(n+1);return r?{kind:`template`,folder:LG(n<0?``:t.slice(0,n)),name:LG(r)}:null}return null}const zG=/^(?:(.+)\/)?\.ok\/templates\/([^/]+?)(?:\.mdx?)?$/;function BG(e){let t=zG.exec(e);if(t){let e=(t[1]??``).replace(/^\/+|\/+$/g,``);return`${TG}${e?`${e}/`:``}${t[2]}`}return null}const VG=[`.mdx`,`.md`],HG=`epoch`,UG=512*1024,WG=[`claude`,`claude-desktop`,`cursor`,`codex`,`opencode`,`openclaw`,`pi`,`antigravity`,`lm-studio`,`hermes`],GG={claude:`Claude`,"claude-desktop":`Claude Desktop`,cursor:`Cursor`,codex:`Codex`,opencode:`OpenCode`,openclaw:`OpenClaw`,pi:`Pi`,antigravity:`Antigravity`,"lm-studio":`LM Studio`,hermes:`Hermes`},KG={claude:`.claude/skills`,"claude-desktop":null,cursor:`.cursor/skills`,codex:`.codex/skills`,opencode:`.opencode/skills`,openclaw:null,pi:`.pi/skills`,antigravity:null,"lm-studio":null,hermes:null},qG=WG.filter(e=>KG[e]!==null),JG=qG.filter(e=>e!==`pi`).map(e=>({hostDir:(KG[e]??``).split(`/`)[0],editorId:e})),YG={claude:`.mcp.json`,"claude-desktop":null,cursor:`.cursor/mcp.json`,codex:`.codex/config.toml`,opencode:`opencode.json`,openclaw:null,pi:`.pi/extensions/open-knowledge.ts`,antigravity:null,"lm-studio":null,hermes:null},XG={cursor:/\bCursor(?:\([^)]+\))?\/\d/,codex:/\bCodex(?:\([^)]+\))?\/\d/,"claude-desktop":/\bClaude(?:\([^)]+\))?\/\d/},ZG=`Ov23liqlSd0V1MwR6rhI`,QG=new Set([`gitlab.com`,`bitbucket.org`,`codeberg.org`,`gitea.com`,`sr.ht`,`sourcehut.org`]),$G=[`incoming`,`outgoing`,`both`];function eK(e){return $G.includes(e)}const tK=`open-knowledge`,nK=[{id:`chart`,title:`Chart`,description:`A bar chart whose series colors track the OK chart palette.`,html:`<div style="font-family:system-ui,sans-serif;padding:20px;color:var(--foreground)">
|
|
304
|
+
`,ANSWER_SESSION_LAST_MESSAGE_IS_NOT_ASSISTANT:`The last message in the session is not an assistant message. Cannot regenerate non-assistant messages.`,PLUGIN_COMPONENT_CONFLICT:`The component "%s" is already defined. The plugin "%s" is trying to redefine it.`};function mH(e,...t){let n=Error(GV(pH[e]??`Unsupported Orama Error code: ${e}`,...t));return n.code=e,`captureStackTrace`in Error.prototype&&Error.captureStackTrace(n),n}function hH(e){return{raw:Number(e),formatted:YV(e)}}function gH(e){if(e.id){if(typeof e.id!=`string`)throw mH(`DOCUMENT_ID_MUST_BE_STRING`,typeof e.id);return e.id}return ZV()}function _H(e,t){for(let[n,r]of Object.entries(t)){let t=e[n];if(t!==void 0&&!(r===`geopoint`&&typeof t==`object`&&typeof t.lon==`number`&&typeof t.lat==`number`)&&!(r===`enum`&&(typeof t==`string`||typeof t==`number`))){if(r===`enum[]`&&Array.isArray(t)){let e=t.length;for(let r=0;r<e;r++)if(typeof t[r]!=`string`&&typeof t[r]!=`number`)return n+`.`+r;continue}if(xH(r)){let e=wH(r);if(!Array.isArray(t)||t.length!==e)throw mH(`INVALID_INPUT_VECTOR`,n,e,t.length);continue}if(SH(r)){if(!Array.isArray(t))return n;let e=CH(r),i=t.length;for(let r=0;r<i;r++)if(typeof t[r]!==e)return n+`.`+r;continue}if(typeof r==`object`){if(!t||typeof t!=`object`)return n;let e=_H(t,r);if(e)return n+`.`+e;continue}if(typeof t!==r)return n}}}const vH={string:!1,number:!1,boolean:!1,enum:!1,geopoint:!1,"string[]":!0,"number[]":!0,"boolean[]":!0,"enum[]":!0},yH={"string[]":`string`,"number[]":`number`,"boolean[]":`boolean`,"enum[]":`enum`};function bH(e){return e===`geopoint`}function xH(e){return typeof e==`string`&&/^vector\[\d+\]$/.test(e)}function SH(e){return typeof e==`string`&&vH[e]}function CH(e){return yH[e]}function wH(e){let t=Number(e.slice(7,-1));switch(!0){case isNaN(t):throw mH(`INVALID_VECTOR_VALUE`,e);case t<=0:throw mH(`INVALID_VECTOR_SIZE`,e);default:return t}}function TH(){return{idToInternalId:new Map,internalIdToId:[],save:EH,load:DH}}function EH(e){return{internalIdToId:e.internalIdToId}}function DH(e,t){let{internalIdToId:n}=t;e.internalDocumentIDStore.idToInternalId.clear(),e.internalDocumentIDStore.internalIdToId=[];let r=n.length;for(let t=0;t<r;t++){let r=n[t];e.internalDocumentIDStore.idToInternalId.set(r,t+1),e.internalDocumentIDStore.internalIdToId.push(r)}}function OH(e,t){if(typeof t==`string`){let n=e.idToInternalId.get(t);if(n)return n;let r=e.idToInternalId.size+1;return e.idToInternalId.set(t,r),e.internalIdToId.push(t),r}return t>e.internalIdToId.length?OH(e,t.toString()):t}function kH(e,t){if(e.internalIdToId.length<t)throw Error(`Invalid internalId ${t}`);return e.internalIdToId[t-1]}function AH(e,t){return{sharedInternalDocumentStore:t,docs:{},count:0}}function jH(e,t){let n=OH(e.sharedInternalDocumentStore,t);return e.docs[n]}function MH(e,t){let n=t.length,r=Array.from({length:n});for(let i=0;i<n;i++){let n=OH(e.sharedInternalDocumentStore,t[i]);r[i]=e.docs[n]}return r}function NH(e){return e.docs}function PH(e,t,n,r){return e.docs[n]===void 0?(e.docs[n]=r,e.count++,!0):!1}function FH(e,t){let n=OH(e.sharedInternalDocumentStore,t);return e.docs[n]===void 0?!1:(delete e.docs[n],e.count--,!0)}function IH(e){return e.count}function LH(e,t){let n=t;return{docs:n.docs,count:n.count,sharedInternalDocumentStore:e}}function RH(e){return{docs:e.docs,count:e.count}}function zH(){return{create:AH,get:jH,getMultiple:MH,getAll:NH,store:PH,remove:FH,count:IH,load:LH,save:RH}}const BH=[`beforeInsert`,`afterInsert`,`beforeRemove`,`afterRemove`,`beforeUpdate`,`afterUpdate`,`beforeUpsert`,`afterUpsert`,`beforeSearch`,`afterSearch`,`beforeInsertMultiple`,`afterInsertMultiple`,`beforeRemoveMultiple`,`afterRemoveMultiple`,`beforeUpdateMultiple`,`afterUpdateMultiple`,`beforeUpsertMultiple`,`afterUpsertMultiple`,`beforeLoad`,`afterLoad`,`afterCreate`];function VH(e,t){let n=[],r=e.plugins?.length;if(!r)return n;for(let i=0;i<r;i++)try{let r=e.plugins[i];typeof r[t]==`function`&&n.push(r[t])}catch(e){throw console.error(`Caught error in getAllPluginsByHook:`,e),mH(`PLUGIN_CRASHED`)}return n}const HH=[`tokenizer`,`index`,`documentsStore`,`sorter`,`pinning`],UH=[`validateSchema`,`getDocumentIndexId`,`getDocumentProperties`,`formatElapsedTime`];function WH(e,t,n,r){if(e.some(oH))return(async()=>{for(let i of e)await i(t,n,r)})();for(let i of e)i(t,n,r)}function GH(e,t,n){if(e.some(oH))return(async()=>{for(let r of e)await r(t,n)})();for(let r of e)r(t,n)}function KH(e,t,n,r,i){if(e.some(oH))return(async()=>{for(let a of e)await a(t,n,r,i)})();for(let a of e)a(t,n,r,i)}function qH(e,t,n,r){if(e.some(oH))return(async()=>{for(let i of e)await i(t,n,r)})();for(let i of e)i(t,n,r)}function JH(e,t){if(e.some(oH))return(async()=>{for(let n of e)await n(t)})();for(let n of e)n(t)}var YH=class e{k;v;l=null;r=null;h=1;constructor(e,t){this.k=e,this.v=new Set(t)}updateHeight(){this.h=Math.max(e.getHeight(this.l),e.getHeight(this.r))+1}static getHeight(e){return e?e.h:0}getBalanceFactor(){return e.getHeight(this.l)-e.getHeight(this.r)}rotateLeft(){let e=this.r;return this.r=e.l,e.l=this,this.updateHeight(),e.updateHeight(),e}rotateRight(){let e=this.l;return this.l=e.r,e.r=this,this.updateHeight(),e.updateHeight(),e}toJSON(){return{k:this.k,v:Array.from(this.v),l:this.l?this.l.toJSON():null,r:this.r?this.r.toJSON():null,h:this.h}}static fromJSON(t){let n=new e(t.k,t.v);return n.l=t.l?e.fromJSON(t.l):null,n.r=t.r?e.fromJSON(t.r):null,n.h=t.h,n}},XH=class e{root=null;insertCount=0;constructor(e,t){e!==void 0&&t!==void 0&&(this.root=new YH(e,t))}insert(e,t,n=1e3){this.root=this.insertNode(this.root,e,t,n)}insertMultiple(e,t,n=1e3){for(let r of t)this.insert(e,r,n)}rebalance(){this.root&&=this.rebalanceNode(this.root)}toJSON(){return{root:this.root?this.root.toJSON():null,insertCount:this.insertCount}}static fromJSON(t){let n=new e;return n.root=t.root?YH.fromJSON(t.root):null,n.insertCount=t.insertCount||0,n}insertNode(e,t,n,r){if(e===null)return new YH(t,[n]);let i=[],a=e,o=null;for(;a!==null;)if(i.push({parent:o,node:a}),t<a.k)if(a.l===null){a.l=new YH(t,[n]),i.push({parent:a,node:a.l});break}else o=a,a=a.l;else if(t>a.k)if(a.r===null){a.r=new YH(t,[n]),i.push({parent:a,node:a.r});break}else o=a,a=a.r;else return a.v.add(n),e;let s=!1;this.insertCount++%r===0&&(s=!0);for(let t=i.length-1;t>=0;t--){let{parent:n,node:r}=i[t];if(r.updateHeight(),s){let t=this.rebalanceNode(r);n?n.l===r?n.l=t:n.r===r&&(n.r=t):e=t}}return e}rebalanceNode(e){let t=e.getBalanceFactor();if(t>1){if(e.l&&e.l.getBalanceFactor()>=0)return e.rotateRight();if(e.l)return e.l=e.l.rotateLeft(),e.rotateRight()}if(t<-1){if(e.r&&e.r.getBalanceFactor()<=0)return e.rotateLeft();if(e.r)return e.r=e.r.rotateRight(),e.rotateLeft()}return e}find(e){let t=this.findNodeByKey(e);return t?t.v:null}contains(e){return this.find(e)!==null}getSize(){let e=0,t=[],n=this.root;for(;n||t.length>0;){for(;n;)t.push(n),n=n.l;n=t.pop(),e++,n=n.r}return e}isBalanced(){if(!this.root)return!0;let e=[this.root];for(;e.length>0;){let t=e.pop(),n=t.getBalanceFactor();if(Math.abs(n)>1)return!1;t.l&&e.push(t.l),t.r&&e.push(t.r)}return!0}remove(e){this.root=this.removeNode(this.root,e)}removeDocument(e,t){let n=this.findNodeByKey(e);n&&(n.v.size===1?this.root=this.removeNode(this.root,e):n.v=new Set([...n.v.values()].filter(e=>e!==t)))}findNodeByKey(e){let t=this.root;for(;t;)if(e<t.k)t=t.l;else if(e>t.k)t=t.r;else return t;return null}removeNode(e,t){if(e===null)return null;let n=[],r=e;for(;r!==null&&r.k!==t;)n.push(r),r=t<r.k?r.l:r.r;if(r===null)return e;if(r.l===null||r.r===null){let t=r.l?r.l:r.r;if(n.length===0)e=t;else{let e=n[n.length-1];e.l===r?e.l=t:e.r=t}}else{let e=r,t=r.r;for(;t.l!==null;)e=t,t=t.l;r.k=t.k,r.v=t.v,e.l===t?e.l=t.r:e.r=t.r,r=e}n.push(r);for(let t=n.length-1;t>=0;t--){let r=n[t];r.updateHeight();let i=this.rebalanceNode(r);if(t>0){let e=n[t-1];e.l===r?e.l=i:e.r===r&&(e.r=i)}else e=i}return e}rangeSearch(e,t){let n=new Set,r=[],i=this.root;for(;i||r.length>0;){for(;i;)r.push(i),i=i.l;if(i=r.pop(),i.k>=e&&i.k<=t)for(let e of i.v)n.add(e);if(i.k>t)break;i=i.r}return n}greaterThan(e,t=!1){let n=new Set,r=[],i=this.root;for(;i||r.length>0;){for(;i;)r.push(i),i=i.r;if(i=r.pop(),t&&i.k>=e||!t&&i.k>e)for(let e of i.v)n.add(e);else if(i.k<=e)break;i=i.l}return n}lessThan(e,t=!1){let n=new Set,r=[],i=this.root;for(;i||r.length>0;){for(;i;)r.push(i),i=i.l;if(i=r.pop(),t&&i.k<=e||!t&&i.k<e)for(let e of i.v)n.add(e);else if(i.k>e)break;i=i.r}return n}},ZH=class e{numberToDocumentId;constructor(){this.numberToDocumentId=new Map}insert(e,t){this.numberToDocumentId.has(e)?this.numberToDocumentId.get(e).add(t):this.numberToDocumentId.set(e,new Set([t]))}find(e){let t=this.numberToDocumentId.get(e);return t?Array.from(t):null}remove(e){this.numberToDocumentId.delete(e)}removeDocument(e,t){let n=this.numberToDocumentId.get(t);n&&(n.delete(e),n.size===0&&this.numberToDocumentId.delete(t))}contains(e){return this.numberToDocumentId.has(e)}getSize(){let e=0;for(let t of this.numberToDocumentId.values())e+=t.size;return e}filter(e){let t=Object.keys(e);if(t.length!==1)throw Error(`Invalid operation`);let n=t[0];switch(n){case`eq`:{let t=e[n],r=this.numberToDocumentId.get(t);return r?Array.from(r):[]}case`in`:{let t=e[n],r=new Set;for(let e of t){let t=this.numberToDocumentId.get(e);if(t)for(let e of t)r.add(e)}return Array.from(r)}case`nin`:{let t=new Set(e[n]),r=new Set;for(let[e,n]of this.numberToDocumentId.entries())if(!t.has(e))for(let e of n)r.add(e);return Array.from(r)}default:throw Error(`Invalid operation`)}}filterArr(e){let t=Object.keys(e);if(t.length!==1)throw Error(`Invalid operation`);let n=t[0];switch(n){case`containsAll`:{let t=e[n].map(e=>this.numberToDocumentId.get(e)??new Set);if(t.length===0)return[];let r=t.reduce((e,t)=>new Set([...e].filter(e=>t.has(e))));return Array.from(r)}case`containsAny`:{let t=e[n].map(e=>this.numberToDocumentId.get(e)??new Set);if(t.length===0)return[];let r=t.reduce((e,t)=>new Set([...e,...t]));return Array.from(r)}default:throw Error(`Invalid operation`)}}static fromJSON(t){if(!t.numberToDocumentId)throw Error(`Invalid Flat Tree JSON`);let n=new e;for(let[e,r]of t.numberToDocumentId)n.numberToDocumentId.set(e,new Set(r));return n}toJSON(){return{numberToDocumentId:Array.from(this.numberToDocumentId.entries()).map(([e,t])=>[e,Array.from(t)])}}};function QH(e,t,n){if(n<0)return-1;if(e===t)return 0;let r=e.length,i=t.length;if(r===0)return i<=n?i:-1;if(i===0)return r<=n?r:-1;let a=Math.abs(r-i);if(e.startsWith(t))return a<=n?a:-1;if(t.startsWith(e))return 0;if(a>n)return-1;let o=[];for(let e=0;e<=r;e++){o[e]=[e];for(let t=1;t<=i;t++)o[e][t]=e===0?t:0}for(let a=1;a<=r;a++){let r=1/0;for(let n=1;n<=i;n++)e[a-1]===t[n-1]?o[a][n]=o[a-1][n-1]:o[a][n]=Math.min(o[a-1][n]+1,o[a][n-1]+1,o[a-1][n-1]+1),r=Math.min(r,o[a][n]);if(r>n)return-1}return o[r][i]<=n?o[r][i]:-1}function $H(e,t,n){let r=QH(e,t,n);return{distance:r,isBounded:r>=0}}var eU=class e{k;s;c=new Map;d=new Set;e;w=``;constructor(e,t,n){this.k=e,this.s=t,this.e=n}updateParent(e){this.w=e.w+this.s}addDocument(e){this.d.add(e)}removeDocument(e){return this.d.delete(e)}findAllWords(e,t,n,r){let i=[this];for(;i.length>0;){let a=i.pop();if(a.e){let{w:i,d:o}=a;if(n&&i!==t)continue;if(QV(e,i)!==null)if(r)if(Math.abs(t.length-i.length)<=r&&$H(t,i,r).isBounded)e[i]=[];else continue;else e[i]=[];if(QV(e,i)!=null&&o.size>0){let t=e[i];for(let e of o)t.includes(e)||t.push(e)}}a.c.size>0&&i.push(...a.c.values())}return e}insert(t,n){let r=this,i=0,a=t.length;for(;i<a;){let o=t[i],s=r.c.get(o);if(s){let o=s.s,c=o.length,l=0;for(;l<c&&i+l<a&&o[l]===t[i+l];)l++;if(l===c){if(r=s,i+=l,i===a){s.e||=!0,s.addDocument(n);return}continue}let u=o.slice(0,l),d=o.slice(l),f=t.slice(i+l),p=new e(u[0],u,!1);if(r.c.set(u[0],p),p.updateParent(r),s.s=d,s.k=d[0],p.c.set(d[0],s),s.updateParent(p),f){let t=new e(f[0],f,!0);t.addDocument(n),p.c.set(f[0],t),t.updateParent(p)}else p.e=!0,p.addDocument(n);return}else{let a=new e(o,t.slice(i),!0);a.addDocument(n),r.c.set(o,a),a.updateParent(r);return}}r.e||=!0,r.addDocument(n)}_findLevenshtein(e,t,n,r,i){let a=[{node:this,index:t,tolerance:n}];for(;a.length>0;){let{node:t,index:n,tolerance:o}=a.pop();if(t.w.startsWith(e)){t.findAllWords(i,e,!1,0);continue}if(o<0)continue;if(t.e){let{w:n,d:a}=t;if(n&&($H(e,n,r).isBounded&&(i[n]=[]),QV(i,n)!==void 0&&a.size>0)){let e=new Set(i[n]);for(let t of a)e.add(t);i[n]=Array.from(e)}}if(n>=e.length)continue;let s=e[n];if(t.c.has(s)){let e=t.c.get(s);a.push({node:e,index:n+1,tolerance:o})}a.push({node:t,index:n+1,tolerance:o-1});for(let[e,r]of t.c)a.push({node:r,index:n,tolerance:o-1}),e!==s&&a.push({node:r,index:n+1,tolerance:o-1})}}find(e){let{term:t,exact:n,tolerance:r}=e;if(r&&!n){let e={};return this._findLevenshtein(t,0,r,r,e),e}else{let e=this,i=0,a=t.length;for(;i<a;){let o=t[i],s=e.c.get(o);if(s){let o=s.s,c=o.length,l=0;for(;l<c&&i+l<a&&o[l]===t[i+l];)l++;if(l===c)e=s,i+=l;else if(i+l===a)if(l===a-i){if(n)return{};{let e={};return s.findAllWords(e,t,n,r),e}}else return{};else return{}}else return{}}let o={};return e.findAllWords(o,t,n,r),o}}contains(e){let t=this,n=0,r=e.length;for(;n<r;){let i=e[n],a=t.c.get(i);if(a){let i=a.s,o=i.length,s=0;for(;s<o&&n+s<r&&i[s]===e[n+s];)s++;if(s<o)return!1;n+=o,t=a}else return!1}return!0}removeWord(e){if(!e)return!1;let t=this,n=e.length,r=[];for(let i=0;i<n;i++){let n=e[i];if(t.c.has(n)){let e=t.c.get(n);r.push({parent:t,character:n}),i+=e.s.length-1,t=e}else return!1}for(t.d.clear(),t.e=!1;r.length>0&&t.c.size===0&&!t.e&&t.d.size===0;){let{parent:e,character:n}=r.pop();e.c.delete(n),t=e}return!0}removeDocumentByWord(e,t,n=!0){if(!e)return!0;let r=this,i=e.length;for(let a=0;a<i;a++){let i=e[a];if(r.c.has(i)){let o=r.c.get(i);a+=o.s.length-1,r=o,n&&r.w!==e||r.removeDocument(t)}else return!1}return!0}static getCommonPrefix(e,t){let n=Math.min(e.length,t.length),r=0;for(;r<n&&e.charCodeAt(r)===t.charCodeAt(r);)r++;return e.slice(0,r)}toJSON(){return{w:this.w,s:this.s,e:this.e,k:this.k,d:Array.from(this.d),c:Array.from(this.c?.entries())?.map(([e,t])=>[e,t.toJSON()])}}static fromJSON(t){let n=new e(t.k,t.s,t.e);return n.w=t.w,n.d=new Set(t.d),n.c=new Map(t?.c?.map(([t,n])=>[t,e.fromJSON(n)])||[]),n}},tU=class e extends eU{constructor(){super(``,``,!1)}static fromJSON(t){let n=new e;return n.w=t.w,n.s=t.s,n.e=t.e,n.k=t.k,n.d=new Set(t.d),n.c=new Map(t?.c?.map(([e,t])=>[e,eU.fromJSON(t)])||[]),n}toJSON(){return super.toJSON()}},nU=class e{point;docIDs;left;right;parent;constructor(e,t){this.point=e,this.docIDs=new Set(t),this.left=null,this.right=null,this.parent=null}toJSON(){return{point:this.point,docIDs:Array.from(this.docIDs),left:this.left?this.left.toJSON():null,right:this.right?this.right.toJSON():null}}static fromJSON(t,n=null){let r=new e(t.point,t.docIDs);return r.parent=n,t.left&&(r.left=e.fromJSON(t.left,r)),t.right&&(r.right=e.fromJSON(t.right,r)),r}},rU=class e{root;nodeMap;constructor(){this.root=null,this.nodeMap=new Map}getPointKey(e){return`${e.lon},${e.lat}`}insert(e,t){let n=this.getPointKey(e),r=this.nodeMap.get(n);if(r){t.forEach(e=>r.docIDs.add(e));return}let i=new nU(e,t);if(this.nodeMap.set(n,i),this.root==null){this.root=i;return}let a=this.root,o=0;for(;;){if(o%2==0)if(e.lon<a.point.lon){if(a.left==null){a.left=i,i.parent=a;return}a=a.left}else{if(a.right==null){a.right=i,i.parent=a;return}a=a.right}else if(e.lat<a.point.lat){if(a.left==null){a.left=i,i.parent=a;return}a=a.left}else{if(a.right==null){a.right=i,i.parent=a;return}a=a.right}o++}}contains(e){let t=this.getPointKey(e);return this.nodeMap.has(t)}getDocIDsByCoordinates(e){let t=this.getPointKey(e),n=this.nodeMap.get(t);return n?Array.from(n.docIDs):null}removeDocByID(e,t){let n=this.getPointKey(e),r=this.nodeMap.get(n);r&&(r.docIDs.delete(t),r.docIDs.size===0&&(this.nodeMap.delete(n),this.deleteNode(r)))}deleteNode(e){let t=e.parent,n=e.left?e.left:e.right;n&&(n.parent=t),t?t.left===e?t.left=n:t.right===e&&(t.right=n):(this.root=n,this.root&&(this.root.parent=null))}searchByRadius(t,n,r=!0,i=`asc`,a=!1){let o=a?e.vincentyDistance:e.haversineDistance,s=[{node:this.root,depth:0}],c=[];for(;s.length>0;){let{node:e,depth:i}=s.pop();if(e==null)continue;let a=o(t,e.point);(r?a<=n:a>n)&&c.push({point:e.point,docIDs:Array.from(e.docIDs)}),e.left!=null&&s.push({node:e.left,depth:i+1}),e.right!=null&&s.push({node:e.right,depth:i+1})}return i&&c.sort((e,n)=>{let r=o(t,e.point),a=o(t,n.point);return i.toLowerCase()===`asc`?r-a:a-r}),c}searchByPolygon(t,n=!0,r=null,i=!1){let a=[{node:this.root,depth:0}],o=[];for(;a.length>0;){let{node:r,depth:i}=a.pop();if(r==null)continue;r.left!=null&&a.push({node:r.left,depth:i+1}),r.right!=null&&a.push({node:r.right,depth:i+1});let s=e.isPointInPolygon(t,r.point);(s&&n||!s&&!n)&&o.push({point:r.point,docIDs:Array.from(r.docIDs)})}let s=e.calculatePolygonCentroid(t);if(r){let t=i?e.vincentyDistance:e.haversineDistance;o.sort((e,n)=>{let i=t(s,e.point),a=t(s,n.point);return r.toLowerCase()===`asc`?i-a:a-i})}return o}toJSON(){return{root:this.root?this.root.toJSON():null}}static fromJSON(t){let n=new e;return t.root&&(n.root=nU.fromJSON(t.root),n.buildNodeMap(n.root)),n}buildNodeMap(e){if(e==null)return;let t=this.getPointKey(e.point);this.nodeMap.set(t,e),e.left&&this.buildNodeMap(e.left),e.right&&this.buildNodeMap(e.right)}static calculatePolygonCentroid(e){let t=0,n=0,r=0,i=e.length;for(let a=0,o=i-1;a<i;o=a++){let i=e[a].lon,s=e[a].lat,c=e[o].lon,l=e[o].lat,u=i*l-c*s;t+=u,n+=(i+c)*u,r+=(s+l)*u}t/=2;let a=6*t;return n/=a,r/=a,{lon:n,lat:r}}static isPointInPolygon(e,t){let n=!1,r=t.lon,i=t.lat,a=e.length;for(let t=0,o=a-1;t<a;o=t++){let a=e[t].lon,s=e[t].lat,c=e[o].lon,l=e[o].lat;s>i!=l>i&&r<(c-a)*(i-s)/(l-s)+a&&(n=!n)}return n}static haversineDistance(e,t){let n=Math.PI/180,r=e.lat*n,i=t.lat*n,a=(t.lat-e.lat)*n,o=(t.lon-e.lon)*n,s=Math.sin(a/2)*Math.sin(a/2)+Math.cos(r)*Math.cos(i)*Math.sin(o/2)*Math.sin(o/2);return 6371e3*(2*Math.atan2(Math.sqrt(s),Math.sqrt(1-s)))}static vincentyDistance(e,t){let n=6378137,r=1/298.257223563,i=(1-r)*n,a=Math.PI/180,o=e.lat*a,s=t.lat*a,c=(t.lon-e.lon)*a,l=Math.atan((1-r)*Math.tan(o)),u=Math.atan((1-r)*Math.tan(s)),d=Math.sin(l),f=Math.cos(l),p=Math.sin(u),m=Math.cos(u),h=c,g,_=1e3,v,y,b,x,S,C;do{let e=Math.sin(h),t=Math.cos(h);if(v=Math.sqrt(m*e*(m*e)+(f*p-d*m*t)*(f*p-d*m*t)),v===0)return 0;y=d*p+f*m*t,b=Math.atan2(v,y),x=f*m*e/v,S=1-x*x,C=y-2*d*p/S,isNaN(C)&&(C=0);let n=r/16*S*(4+r*(4-3*S));g=h,h=c+(1-n)*r*x*(b+n*v*(C+n*y*(-1+2*C*C)))}while(Math.abs(h-g)>1e-12&&--_>0);if(_===0)return NaN;let w=S*(n*n-i*i)/(i*i),T=1+w/16384*(4096+w*(-768+w*(320-175*w))),E=w/1024*(256+w*(-128+w*(74-47*w))),ee=E*v*(C+E/4*(y*(-1+2*C*C)-E/6*C*(-3+4*v*v)*(-3+4*C*C)));return i*T*(b-ee)}},iU=class e{true;false;constructor(){this.true=new Set,this.false=new Set}insert(e,t){t?this.true.add(e):this.false.add(e)}delete(e,t){t?this.true.delete(e):this.false.delete(e)}getSize(){return this.true.size+this.false.size}toJSON(){return{true:Array.from(this.true),false:Array.from(this.false)}}static fromJSON(t){let n=new e;return n.true=new Set(t.true),n.false=new Set(t.false),n}};function aU(e,t,n,r,i,{k:a,b:o,d:s}){return Math.log(1+(n-t+.5)/(t+.5))*(s+e*(a+1))/(e+a*(1-o+o*r/i))}var oU=class e{size;vectors=new Map;constructor(e){this.size=e}add(e,t){t instanceof Float32Array||(t=new Float32Array(t));let n=sU(t,this.size);this.vectors.set(e,[n,t])}remove(e){this.vectors.delete(e)}find(e,t,n){return e instanceof Float32Array||(e=new Float32Array(e)),cU(e,n,this.vectors,this.size,t)}toJSON(){let e=[];for(let[t,[n,r]]of this.vectors)e.push([t,[n,Array.from(r)]]);return{size:this.size,vectors:e}}static fromJSON(t){let n=t,r=new e(n.size);for(let[e,[t,i]]of n.vectors)r.vectors.set(e,[t,new Float32Array(i)]);return r}};function sU(e,t){let n=0;for(let r=0;r<t;r++)n+=e[r]*e[r];return Math.sqrt(n)}function cU(e,t,n,r,i){let a=sU(e,r),o=[],s=t||n.keys();for(let t of s){let s=n.get(t);if(!s)continue;let c=s[0],l=s[1],u=0;for(let t=0;t<r;t++)u+=e[t]*l[t];let d=u/(a*c);d>=i&&o.push([t,d])}return o}function lU(e,t,n,r,i){let a=OH(e.sharedInternalDocumentStore,n);e.avgFieldLength[t]=((e.avgFieldLength[t]??0)*(i-1)+r.length)/i,e.fieldLengths[t][a]=r.length,e.frequencies[t][a]={}}function uU(e,t,n,r,i){let a=0;for(let e of r)e===i&&a++;let o=OH(e.sharedInternalDocumentStore,n),s=a/r.length;e.frequencies[t][o][i]=s,i in e.tokenOccurrences[t]||(e.tokenOccurrences[t][i]=0),e.tokenOccurrences[t][i]=(e.tokenOccurrences[t][i]??0)+1}function dU(e,t,n,r){let i=OH(e.sharedInternalDocumentStore,n);r>1?e.avgFieldLength[t]=(e.avgFieldLength[t]*r-e.fieldLengths[t][i])/(r-1):e.avgFieldLength[t]=void 0,e.fieldLengths[t][i]=void 0,e.frequencies[t][i]=void 0}function fU(e,t,n){e.tokenOccurrences[t][n]--}function pU(e,t,n,r,i=``){r||={sharedInternalDocumentStore:t,indexes:{},vectorIndexes:{},searchableProperties:[],searchablePropertiesWithTypes:{},frequencies:{},tokenOccurrences:{},avgFieldLength:{},fieldLengths:{}};for(let[a,o]of Object.entries(n)){let n=`${i}${i?`.`:``}${a}`;if(typeof o==`object`&&!Array.isArray(o)){pU(e,t,o,r,n);continue}if(xH(o))r.searchableProperties.push(n),r.searchablePropertiesWithTypes[n]=o,r.vectorIndexes[n]={type:`Vector`,node:new oU(wH(o)),isArray:!1};else{let e=/\[/.test(o);switch(o){case`boolean`:case`boolean[]`:r.indexes[n]={type:`Bool`,node:new iU,isArray:e};break;case`number`:case`number[]`:r.indexes[n]={type:`AVL`,node:new XH(0,[]),isArray:e};break;case`string`:case`string[]`:r.indexes[n]={type:`Radix`,node:new tU,isArray:e},r.avgFieldLength[n]=0,r.frequencies[n]={},r.tokenOccurrences[n]={},r.fieldLengths[n]={};break;case`enum`:case`enum[]`:r.indexes[n]={type:`Flat`,node:new ZH,isArray:e};break;case`geopoint`:r.indexes[n]={type:`BKD`,node:new rU,isArray:e};break;default:throw mH(`INVALID_SCHEMA_TYPE`,Array.isArray(o)?`array`:o,n)}r.searchableProperties.push(n),r.searchablePropertiesWithTypes[n]=o}}return r}function mU(e,t,n,r,i,a,o,s){return c=>{let{type:l,node:u}=t.indexes[n];switch(l){case`Bool`:u[c?`true`:`false`].add(r);break;case`AVL`:{let e=s?.avlRebalanceThreshold??1;u.insert(c,r,e);break}case`Radix`:{let s=a.tokenize(c,i,n,!1);e.insertDocumentScoreParameters(t,n,r,s,o);for(let i of s)e.insertTokenScoreParameters(t,n,r,s,i),u.insert(i,r);break}case`Flat`:u.insert(c,r);break;case`BKD`:u.insert(c,[r]);break}}}function hU(e,t,n,r,i,a,o,s,c,l,u){if(xH(o))return gU(t,n,a,r,i);let d=mU(e,t,n,i,s,c,l,u);if(!SH(o))return d(a);let f=a,p=f.length;for(let e=0;e<p;e++)d(f[e])}function gU(e,t,n,r,i){e.vectorIndexes[t].node.add(i,n)}function _U(e,t,n,r,i,a,o,s,c,l){if(xH(o))return t.vectorIndexes[n].node.remove(i),!0;let{type:u,node:d}=t.indexes[n];switch(u){case`AVL`:return d.removeDocument(a,i),!0;case`Bool`:return d[a?`true`:`false`].delete(i),!0;case`Radix`:{let o=c.tokenize(a,s,n);e.removeDocumentScoreParameters(t,n,r,l);for(let r of o)e.removeTokenScoreParameters(t,n,r),d.removeDocumentByWord(r,i);return!0}case`Flat`:return d.removeDocument(i,a),!0;case`BKD`:return d.removeDocByID(a,i),!1}}function vU(e,t,n,r,i,a,o,s,c,l){if(!SH(o))return _U(e,t,n,r,i,a,o,s,c,l);let u=CH(o),d=a,f=d.length;for(let a=0;a<f;a++)_U(e,t,n,r,i,d[a],u,s,c,l);return!0}function yU(e,t,n,r,i,a,o,s,c,l){let u=Array.from(r),d=e.avgFieldLength[t],f=e.fieldLengths[t],p=e.tokenOccurrences[t],m=e.frequencies[t],h=typeof p[n]==`number`?p[n]??0:0,g=u.length;for(let e=0;e<g;e++){let r=u[e];if(c&&!c.has(r))continue;l.has(r)||l.set(r,new Map);let p=l.get(r);p.set(t,(p.get(t)||0)+1);let g=aU(m?.[r]?.[n]??0,h,i,f[r],d,a);o.has(r)?o.set(r,o.get(r)+g*s):o.set(r,g*s)}}function bU(e,t,n,r,i,a,o,s,c,l,u,d=0){let f=n.tokenize(t,r),p=f.length||1,m=new Map,h=new Map,g=new Map;for(let n of i){if(!(n in e.indexes))continue;let r=e.indexes[n],{type:i}=r;if(i!==`Radix`)throw mH(`WRONG_SEARCH_PROPERTY_TYPE`,n);let d=s[n]??1;if(d<=0)throw mH(`INVALID_BOOST_VALUE`,d);f.length===0&&!t&&f.push(``);let p=f.length;for(let t=0;t<p;t++){let i=f[t],s=r.node.find({term:i,exact:a,tolerance:o}),p=Object.keys(s);p.length>0&&h.set(i,!0);let _=p.length;for(let t=0;t<_;t++){let r=p[t],i=s[r];yU(e,n,r,i,l,c,g,d,u,m)}}}let _=Array.from(g.entries()).map(([e,t])=>[e,t]).sort((e,t)=>t[1]-e[1]);if(_.length===0)return[];if(d===1)return _;if(d===0){if(p===1)return _;for(let e of f)if(!h.get(e))return[];return _.filter(([e])=>{let t=m.get(e);return t?Array.from(t.values()).some(e=>e===p):!1})}let v=_.filter(([e])=>{let t=m.get(e);return t?Array.from(t.values()).some(e=>e===p):!1});if(v.length>0){let e=_.filter(([e])=>!v.some(([t])=>t===e)),t=Math.ceil(e.length*d);return[...v,...e.slice(0,t)]}return _}function xU(e,t,n,r){if(`and`in n&&n.and&&Array.isArray(n.and)){let i=n.and;return i.length===0?new Set:cH(...i.map(n=>xU(e,t,n,r)))}if(`or`in n&&n.or&&Array.isArray(n.or)){let i=n.or;return i.length===0?new Set:i.map(n=>xU(e,t,n,r)).reduce((e,t)=>uH(e,t),new Set)}if(`not`in n&&n.not){let i=n.not,a=new Set,o=e.sharedInternalDocumentStore;for(let e=1;e<=o.internalIdToId.length;e++)a.add(e);return dH(a,xU(e,t,i,r))}let i=Object.keys(n),a=i.reduce((e,t)=>({[t]:new Set,...e}),{});for(let o of i){let i=n[o];if(e.indexes[o]===void 0)throw mH(`UNKNOWN_FILTER_PROPERTY`,o);let{node:s,type:c,isArray:l}=e.indexes[o];if(c===`Bool`){let e=s,t=i?e.true:e.false;a[o]=uH(a[o],t);continue}if(c===`BKD`){let e;if(`radius`in i)e=`radius`;else if(`polygon`in i)e=`polygon`;else throw Error(`Invalid operation ${i}`);if(e===`radius`){let{value:t,coordinates:n,unit:r=`m`,inside:c=!0,highPrecision:l=!1}=i[e],u=iH(t,r),d=s.searchByRadius(n,u,c,void 0,l);a[o]=DU(a[o],d)}else{let{coordinates:t,inside:n=!0,highPrecision:r=!1}=i[e],c=s.searchByPolygon(t,n,void 0,r);a[o]=DU(a[o],c)}continue}if(c===`Radix`&&(typeof i==`string`||Array.isArray(i))){for(let e of[i].flat()){let n=t.tokenize(e,r,o);for(let e of n){let t=s.find({term:e,exact:!0});a[o]=jU(a[o],t)}}continue}let u=Object.keys(i);if(u.length>1)throw mH(`INVALID_FILTER_OPERATION`,u.length);if(c===`Flat`){let e=new Set(l?s.filterArr(i):s.filter(i));a[o]=uH(a[o],e);continue}if(c===`AVL`){let e=u[0],t=i[e],n;switch(e){case`gt`:n=s.greaterThan(t,!1);break;case`gte`:n=s.greaterThan(t,!0);break;case`lt`:n=s.lessThan(t,!1);break;case`lte`:n=s.lessThan(t,!0);break;case`eq`:n=s.find(t)??new Set;break;case`between`:{let[e,r]=t;n=s.rangeSearch(e,r);break}default:throw mH(`INVALID_FILTER_OPERATION`,e)}a[o]=uH(a[o],n)}}return cH(...Object.values(a))}function SU(e){return e.searchableProperties}function CU(e){return e.searchablePropertiesWithTypes}function wU(e,t){let{indexes:n,vectorIndexes:r,searchableProperties:i,searchablePropertiesWithTypes:a,frequencies:o,tokenOccurrences:s,avgFieldLength:c,fieldLengths:l}=t,u={},d={};for(let e of Object.keys(n)){let{node:t,type:r,isArray:i}=n[e];switch(r){case`Radix`:u[e]={type:`Radix`,node:tU.fromJSON(t),isArray:i};break;case`Flat`:u[e]={type:`Flat`,node:ZH.fromJSON(t),isArray:i};break;case`AVL`:u[e]={type:`AVL`,node:XH.fromJSON(t),isArray:i};break;case`BKD`:u[e]={type:`BKD`,node:rU.fromJSON(t),isArray:i};break;case`Bool`:u[e]={type:`Bool`,node:iU.fromJSON(t),isArray:i};break;default:u[e]=n[e]}}for(let e of Object.keys(r))d[e]={type:`Vector`,isArray:!1,node:oU.fromJSON(r[e])};return{sharedInternalDocumentStore:e,indexes:u,vectorIndexes:d,searchableProperties:i,searchablePropertiesWithTypes:a,frequencies:o,tokenOccurrences:s,avgFieldLength:c,fieldLengths:l}}function TU(e){let{indexes:t,vectorIndexes:n,searchableProperties:r,searchablePropertiesWithTypes:i,frequencies:a,tokenOccurrences:o,avgFieldLength:s,fieldLengths:c}=e,l={};for(let e of Object.keys(n))l[e]=n[e].node.toJSON();let u={};for(let e of Object.keys(t)){let{type:n,node:r,isArray:i}=t[e];n===`Flat`||n===`Radix`||n===`AVL`||n===`BKD`||n===`Bool`?u[e]={type:n,node:r.toJSON(),isArray:i}:(u[e]=t[e],u[e].node=u[e].node.toJSON())}return{indexes:u,vectorIndexes:l,searchableProperties:r,searchablePropertiesWithTypes:i,frequencies:a,tokenOccurrences:o,avgFieldLength:s,fieldLengths:c}}function EU(){return{create:pU,insert:hU,remove:vU,insertDocumentScoreParameters:lU,insertTokenScoreParameters:uU,removeDocumentScoreParameters:dU,removeTokenScoreParameters:fU,calculateResultScores:yU,search:bU,searchByWhereClause:xU,getSearchableProperties:SU,getSearchablePropertiesWithTypes:CU,load:wU,save:TU}}function DU(e,t){e||=new Set;let n=t.length;for(let r=0;r<n;r++){let n=t[r].docIDs,i=n.length;for(let t=0;t<i;t++)e.add(n[t])}return e}function OU(e,t,n=!1){let r=n?rU.vincentyDistance:rU.haversineDistance,i=[],a=[];for(let{point:n}of e)a.push(r(t,n));let o=Math.max(...a),s=0;for(let{docIDs:t}of e){let e=o-a[s]+1;for(let n of t)i.push([n,e]);s++}return i.sort((e,t)=>t[1]-e[1]),i}function kU(e,t){let n=Object.keys(e);if(n.length!==1)return{isGeoOnly:!1};let r=n[0],i=e[r];if(t.indexes[r]===void 0)return{isGeoOnly:!1};let{type:a}=t.indexes[r];return a===`BKD`&&i&&(`radius`in i||`polygon`in i)?{isGeoOnly:!0,geoProperty:r,geoOperation:i}:{isGeoOnly:!1}}function AU(e,t){let n=e,r=kU(t,n);if(!r.isGeoOnly||!r.geoProperty||!r.geoOperation)return null;let{node:i}=n.indexes[r.geoProperty],a=r.geoOperation,o=i,s;if(`radius`in a){let{value:e,coordinates:t,unit:n=`m`,inside:r=!0,highPrecision:i=!1}=a.radius,c=t,l=iH(e,n);return s=o.searchByRadius(c,l,r,`asc`,i),OU(s,c,i)}else if(`polygon`in a){let{coordinates:e,inside:t=!0,highPrecision:n=!1}=a.polygon;s=o.searchByPolygon(e,t,`asc`,n);let r=rU.calculatePolygonCentroid(e);return OU(s,r,n)}return null}function jU(e,t){e||=new Set;let n=Object.keys(t),r=n.length;for(let i=0;i<r;i++){let r=t[n[i]],a=r.length;for(let t=0;t<a;t++)e.add(r[t])}return e}function MU(e,t,n,r,i){let a={language:e.tokenizer.language,sharedInternalDocumentStore:t,enabled:!0,isSorted:!0,sortableProperties:[],sortablePropertiesWithTypes:{},sorts:{}};for(let[o,s]of Object.entries(n)){let n=`${i}${i?`.`:``}${o}`;if(!r.includes(n)){if(typeof s==`object`&&!Array.isArray(s)){let i=MU(e,t,s,r,n);WV(a.sortableProperties,i.sortableProperties),a.sorts={...a.sorts,...i.sorts},a.sortablePropertiesWithTypes={...a.sortablePropertiesWithTypes,...i.sortablePropertiesWithTypes};continue}if(!xH(s))switch(s){case`boolean`:case`number`:case`string`:a.sortableProperties.push(n),a.sortablePropertiesWithTypes[n]=s,a.sorts[n]={docs:new Map,orderedDocsToRemove:new Map,orderedDocs:[],type:s};break;case`geopoint`:case`enum`:continue;case`enum[]`:case`boolean[]`:case`number[]`:case`string[]`:continue;default:throw mH(`INVALID_SORT_SCHEMA_TYPE`,Array.isArray(s)?`array`:s,n)}}}return a}function NU(e,t,n,r){return r?.enabled===!1?{disabled:!0}:MU(e,t,n,(r||{}).unsortableProperties||[],``)}function PU(e,t,n,r){if(!e.enabled)return;e.isSorted=!1;let i=OH(e.sharedInternalDocumentStore,n),a=e.sorts[t];a.orderedDocsToRemove.has(i)&&VU(e,t),a.docs.set(i,a.orderedDocs.length),a.orderedDocs.push([i,r])}function FU(e){if(e.isSorted||!e.enabled)return;let t=Object.keys(e.sorts);for(let n of t)zU(e,n);e.isSorted=!0}function IU(e,t,n){return t[1].localeCompare(n[1],LV(e))}function LU(e,t){return e[1]-t[1]}function RU(e,t){return t[1]?-1:1}function zU(e,t){let n=e.sorts[t],r;switch(n.type){case`string`:r=IU.bind(null,e.language);break;case`number`:r=LU.bind(null);break;case`boolean`:r=RU.bind(null);break}n.orderedDocs.sort(r);let i=n.orderedDocs.length;for(let e=0;e<i;e++){let t=n.orderedDocs[e][0];n.docs.set(t,e)}}function BU(e){let t=Object.keys(e.sorts);for(let n of t)VU(e,n)}function VU(e,t){let n=e.sorts[t];n.orderedDocsToRemove.size&&(n.orderedDocs=n.orderedDocs.filter(e=>!n.orderedDocsToRemove.has(e[0])),n.orderedDocsToRemove.clear())}function HU(e,t,n){if(!e.enabled)return;let r=e.sorts[t],i=OH(e.sharedInternalDocumentStore,n);r.docs.get(i)&&(r.docs.delete(i),r.orderedDocsToRemove.set(i,!0))}function UU(e,t,n){if(!e.enabled)throw mH(`SORT_DISABLED`);let r=n.property,i=n.order===`DESC`,a=e.sorts[r];if(!a)throw mH(`UNABLE_TO_SORT_ON_UNKNOWN_FIELD`,r,e.sortableProperties.join(`, `));return VU(e,r),FU(e),t.sort((t,n)=>{let r=a.docs.get(OH(e.sharedInternalDocumentStore,t[0])),o=a.docs.get(OH(e.sharedInternalDocumentStore,n[0])),s=r!==void 0,c=o!==void 0;return!s&&!c?0:s?c?i?o-r:r-o:-1:1}),t}function WU(e){return e.enabled?e.sortableProperties:[]}function GU(e){return e.enabled?e.sortablePropertiesWithTypes:{}}function KU(e,t){let n=t;if(!n.enabled)return{enabled:!1};let r=Object.keys(n.sorts).reduce((e,t)=>{let{docs:r,orderedDocs:i,type:a}=n.sorts[t];return e[t]={docs:new Map(Object.entries(r).map(([e,t])=>[+e,t])),orderedDocsToRemove:new Map,orderedDocs:i,type:a},e},{});return{sharedInternalDocumentStore:e,language:n.language,sortableProperties:n.sortableProperties,sortablePropertiesWithTypes:n.sortablePropertiesWithTypes,sorts:r,enabled:!0,isSorted:n.isSorted}}function qU(e){if(!e.enabled)return{enabled:!1};BU(e),FU(e);let t=Object.keys(e.sorts).reduce((t,n)=>{let{docs:r,orderedDocs:i,type:a}=e.sorts[n];return t[n]={docs:Object.fromEntries(r.entries()),orderedDocs:i,type:a},t},{});return{language:e.language,sortableProperties:e.sortableProperties,sortablePropertiesWithTypes:e.sortablePropertiesWithTypes,sorts:t,enabled:e.enabled,isSorted:e.isSorted}}function JU(){return{create:NU,insert:PU,remove:HU,save:qU,load:KU,sortBy:UU,getSortableProperties:WU,getSortablePropertiesWithTypes:GU}}const YU=[65,65,65,65,65,65,65,67,69,69,69,69,73,73,73,73,69,78,79,79,79,79,79,null,79,85,85,85,85,89,80,115,97,97,97,97,97,97,97,99,101,101,101,101,105,105,105,105,101,110,111,111,111,111,111,null,111,117,117,117,117,121,112,121,65,97,65,97,65,97,67,99,67,99,67,99,67,99,68,100,68,100,69,101,69,101,69,101,69,101,69,101,71,103,71,103,71,103,71,103,72,104,72,104,73,105,73,105,73,105,73,105,73,105,73,105,74,106,75,107,107,76,108,76,108,76,108,76,108,76,108,78,110,78,110,78,110,110,78,110,79,111,79,111,79,111,79,111,82,114,82,114,82,114,83,115,83,115,83,115,83,115,84,116,84,116,84,116,85,117,85,117,85,117,85,117,85,117,85,117,87,119,89,121,89,90,122,90,122,90,122,115];function XU(e){return e<192||e>383?e:YU[e-192]||e}function ZU(e){let t=[];for(let n=0;n<e.length;n++)t[n]=XU(e.charCodeAt(n));return String.fromCharCode(...t)}const QU={ational:`ate`,tional:`tion`,enci:`ence`,anci:`ance`,izer:`ize`,bli:`ble`,alli:`al`,entli:`ent`,eli:`e`,ousli:`ous`,ization:`ize`,ation:`ate`,ator:`ate`,alism:`al`,iveness:`ive`,fulness:`ful`,ousness:`ous`,aliti:`al`,iviti:`ive`,biliti:`ble`,logi:`log`},$U={icate:`ic`,ative:``,alize:`al`,iciti:`ic`,ical:`ic`,ful:``,ness:``},eW=`[aeiouy]`,tW=`[^aeiou][^aeiouy]*`;eW+``;const nW=`^(`+tW+`)?[aeiouy][aeiou]*[^aeiou][^aeiouy]*`;``+tW;const rW=`^(`+tW+`)?[aeiouy][aeiou]*[^aeiou][^aeiouy]*[aeiouy][aeiou]*[^aeiou][^aeiouy]*`,iW=`^(`+tW+`)?[aeiouy]`;function aW(e){let t,n,r,i,a,o;if(e.length<3)return e;let s=e.substring(0,1);if(s==`y`&&(e=s.toUpperCase()+e.substring(1)),r=/^(.+?)(ss|i)es$/,i=/^(.+?)([^s])s$/,r.test(e)?e=e.replace(r,`$1$2`):i.test(e)&&(e=e.replace(i,`$1$2`)),r=/^(.+?)eed$/,i=/^(.+?)(ed|ing)$/,r.test(e)){let t=r.exec(e);r=new RegExp(nW),r.test(t[1])&&(r=/.$/,e=e.replace(r,``))}else i.test(e)&&(t=i.exec(e)[1],i=new RegExp(iW),i.test(t)&&(e=t,i=/(at|bl|iz)$/,a=RegExp(`([^aeiouylsz])\\1$`),o=RegExp(`^`+tW+eW+`[^aeiouwxy]$`),i.test(e)?e+=`e`:a.test(e)?(r=/.$/,e=e.replace(r,``)):o.test(e)&&(e+=`e`)));if(r=/^(.+?)y$/,r.test(e)&&(t=r.exec(e)?.[1],r=new RegExp(iW),t&&r.test(t)&&(e=t+`i`)),r=/^(.+?)(ational|tional|enci|anci|izer|bli|alli|entli|eli|ousli|ization|ation|ator|alism|iveness|fulness|ousness|aliti|iviti|biliti|logi)$/,r.test(e)){let i=r.exec(e);t=i?.[1],n=i?.[2],r=new RegExp(nW),t&&r.test(t)&&(e=t+QU[n])}if(r=/^(.+?)(icate|ative|alize|iciti|ical|ful|ness)$/,r.test(e)){let i=r.exec(e);t=i?.[1],n=i?.[2],r=new RegExp(nW),t&&r.test(t)&&(e=t+$U[n])}if(r=/^(.+?)(al|ance|ence|er|ic|able|ible|ant|ement|ment|ent|ou|ism|ate|iti|ous|ive|ize)$/,i=/^(.+?)(s|t)(ion)$/,r.test(e))t=r.exec(e)?.[1],r=new RegExp(rW),t&&r.test(t)&&(e=t);else if(i.test(e)){let n=i.exec(e);t=n?.[1]??``+n?.[2]??``,i=new RegExp(rW),i.test(t)&&(e=t)}return r=/^(.+?)e$/,r.test(e)&&(t=r.exec(e)?.[1],r=new RegExp(rW),i=RegExp(`^([^aeiou][^aeiouy]*)?[aeiouy][aeiou]*[^aeiou][^aeiouy]*([aeiouy][aeiou]*)?$`),a=RegExp(`^`+tW+eW+`[^aeiouwxy]$`),t&&(r.test(t)||i.test(t)&&!a.test(t))&&(e=t)),r=/ll$/,i=new RegExp(rW),r.test(e)&&i.test(e)&&(r=/.$/,e=e.replace(r,``)),s==`y`&&(e=s.toLowerCase()+e.substring(1)),e}function oW(e,t,n=!0){let r=`${this.language}:${e}:${t}`;return n&&this.normalizationCache.has(r)?this.normalizationCache.get(r):this.stopWords?.includes(t)?(n&&this.normalizationCache.set(r,``),``):(this.stemmer&&!this.stemmerSkipProperties.has(e)&&(t=this.stemmer(t)),t=ZU(t),n&&this.normalizationCache.set(r,t),t)}function sW(e){for(;e[e.length-1]===``;)e.pop();for(;e[0]===``;)e.shift();return e}function cW(e,t,n,r=!0){if(t&&t!==this.language)throw mH(`LANGUAGE_NOT_SUPPORTED`,t);if(typeof e!=`string`)return[e];let i=this.normalizeToken.bind(this,n??``),a;if(n&&this.tokenizeSkipProperties.has(n))a=[i(e,r)];else{let t=FV[this.language];a=e.toLowerCase().split(t).map(e=>i(e,r)).filter(Boolean)}let o=sW(a);return this.allowDuplicates?o:Array.from(new Set(o))}function lW(e={}){if(!e.language)e.language=`english`;else if(!IV.includes(e.language))throw mH(`LANGUAGE_NOT_SUPPORTED`,e.language);let t;if(e.stemming||e.stemmer&&!(`stemming`in e))if(e.stemmer){if(typeof e.stemmer!=`function`)throw mH(`INVALID_STEMMER_FUNCTION_TYPE`);t=e.stemmer}else if(e.language===`english`)t=aW;else throw mH(`MISSING_STEMMER`,e.language);let n;if(e.stopWords!==!1){if(n=[],Array.isArray(e.stopWords))n=e.stopWords;else if(typeof e.stopWords==`function`)n=e.stopWords(n);else if(e.stopWords)throw mH(`CUSTOM_STOP_WORDS_MUST_BE_FUNCTION_OR_ARRAY`);if(!Array.isArray(n))throw mH(`CUSTOM_STOP_WORDS_MUST_BE_FUNCTION_OR_ARRAY`);for(let e of n)if(typeof e!=`string`)throw mH(`CUSTOM_STOP_WORDS_MUST_BE_FUNCTION_OR_ARRAY`)}let r={tokenize:cW,language:e.language,stemmer:t,stemmerSkipProperties:new Set(e.stemmerSkipProperties?[e.stemmerSkipProperties].flat():[]),tokenizeSkipProperties:new Set(e.tokenizeSkipProperties?[e.tokenizeSkipProperties].flat():[]),stopWords:n,allowDuplicates:!!e.allowDuplicates,normalizeToken:oW,normalizationCache:new Map};return r.tokenize=cW.bind(r),r.normalizeToken=oW,r}function uW(e){return{sharedInternalDocumentStore:e,rules:new Map}}function dW(e,t){if(e.rules.has(t.id))throw Error(`PINNING_RULE_ALREADY_EXISTS: A pinning rule with id "${t.id}" already exists. Use updateRule to modify it.`);e.rules.set(t.id,t)}function fW(e,t){if(!e.rules.has(t.id))throw Error(`PINNING_RULE_NOT_FOUND: Cannot update pinning rule with id "${t.id}" because it does not exist. Use addRule to create it.`);e.rules.set(t.id,t)}function pW(e,t){return e.rules.delete(t)}function mW(e,t){return e.rules.get(t)}function hW(e){return Array.from(e.rules.values())}function gW(e,t){let n=e.toLowerCase().trim(),r=t.pattern.toLowerCase().trim();switch(t.anchoring){case`is`:return n===r;case`starts_with`:return n.startsWith(r);case`contains`:return n.includes(r);default:return!1}}function _W(e,t){return e?t.conditions.every(t=>gW(e,t)):!1}function vW(e,t){if(!t)return[];let n=[];for(let r of e.rules.values())_W(t,r)&&n.push(r);return n}function yW(e,t){return{sharedInternalDocumentStore:e,rules:new Map(t?.rules??[])}}function bW(e){return{rules:Array.from(e.rules.entries())}}function xW(){return{create:uW,addRule:dW,updateRule:fW,removeRule:pW,getRule:mW,getAllRules:hW,getMatchingRules:vW,load:yW,save:bW}}function SW(e){let t={formatElapsedTime:hH,getDocumentIndexId:gH,getDocumentProperties:tH,validateSchema:_H};for(let n of UH){let r=n;if(e[r]){if(typeof e[r]!=`function`)throw mH(`COMPONENT_MUST_BE_FUNCTION`,r)}else e[r]=t[r]}for(let t of Object.keys(e))if(!HH.includes(t)&&!UH.includes(t))throw mH(`UNSUPPORTED_COMPONENT`,t)}function CW({schema:e,sort:t,language:n,components:r,id:i,plugins:a}){r||={};for(let t of a??[]){if(!(`getComponents`in t)||typeof t.getComponents!=`function`)continue;let n=t.getComponents(e),i=Object.keys(n);for(let e of i)if(r[e])throw mH(`PLUGIN_COMPONENT_CONFLICT`,e,t.name);r={...r,...n}}i||=ZV();let o=r.tokenizer,s=r.index,c=r.documentsStore,l=r.sorter,u=r.pinning;if(o=o?o.tokenize?o:lW(o):lW({language:n??`english`}),r.tokenizer&&n)throw mH(`NO_LANGUAGE_WITH_CUSTOM_TOKENIZER`);let d=TH();s||=EU(),l||=JU(),c||=zH(),u||=xW(),SW(r);let{getDocumentProperties:f,getDocumentIndexId:p,validateSchema:m,formatElapsedTime:h}=r,g={data:{},caches:{},schema:e,tokenizer:o,index:s,sorter:l,documentsStore:c,pinning:u,internalDocumentIDStore:d,getDocumentProperties:f,getDocumentIndexId:p,validateSchema:m,beforeInsert:[],afterInsert:[],beforeRemove:[],afterRemove:[],beforeUpdate:[],afterUpdate:[],beforeUpsert:[],afterUpsert:[],beforeSearch:[],afterSearch:[],beforeInsertMultiple:[],afterInsertMultiple:[],beforeRemoveMultiple:[],afterRemoveMultiple:[],beforeUpdateMultiple:[],afterUpdateMultiple:[],beforeUpsertMultiple:[],afterUpsertMultiple:[],afterCreate:[],formatElapsedTime:h,id:i,plugins:a,version:wW()};g.data={index:g.index.create(g,d,e),docs:g.documentsStore.create(g,d),sorting:g.sorter.create(g,d,e,t),pinning:g.pinning.create(d)};for(let e of BH)g[e]=(g[e]??[]).concat(VH(g,e));let _=g.afterCreate;return _&&JH(_,g),g}function wW(){return`{{VERSION}}`}function TW(e){return e.documentsStore.count(e.data.docs)}function EW(e,t,n,r,i){let a=e.validateSchema(t,e.schema);if(a)throw mH(`SCHEMA_VALIDATION_FAILURE`,a);return oH(e.beforeInsert)||oH(e.afterInsert)||oH(e.index.beforeInsert)||oH(e.index.insert)||oH(e.index.afterInsert)?kW(e,t,n,r,i):AW(e,t,n,r,i)}const DW=new Set([`enum`,`enum[]`]),OW=new Set([`string`,`number`]);async function kW(e,t,n,r,i){let{index:a,docs:o}=e.data,s=e.getDocumentIndexId(t);if(typeof s!=`string`)throw mH(`DOCUMENT_ID_MUST_BE_STRING`,typeof s);let c=OH(e.internalDocumentIDStore,s);if(r||await WH(e.beforeInsert,e,s,t),!e.documentsStore.store(o,s,c,t))throw mH(`DOCUMENT_ALREADY_EXISTS`,s);let l=e.documentsStore.count(o),u=e.index.getSearchableProperties(a),d=e.index.getSearchablePropertiesWithTypes(a),f=e.getDocumentProperties(t,u);for(let[e,t]of Object.entries(f)){if(t===void 0)continue;let n=typeof t,r=d[e];jW(n,r,e,t)}return await MW(e,s,u,f,l,n,t,i),r||await WH(e.afterInsert,e,s,t),s}function AW(e,t,n,r,i){let{index:a,docs:o}=e.data,s=e.getDocumentIndexId(t);if(typeof s!=`string`)throw mH(`DOCUMENT_ID_MUST_BE_STRING`,typeof s);let c=OH(e.internalDocumentIDStore,s);if(r||WH(e.beforeInsert,e,s,t),!e.documentsStore.store(o,s,c,t))throw mH(`DOCUMENT_ALREADY_EXISTS`,s);let l=e.documentsStore.count(o),u=e.index.getSearchableProperties(a),d=e.index.getSearchablePropertiesWithTypes(a),f=e.getDocumentProperties(t,u);for(let[e,t]of Object.entries(f)){if(t===void 0)continue;let n=typeof t,r=d[e];jW(n,r,e,t)}return NW(e,s,u,f,l,n,t,i),r||WH(e.afterInsert,e,s,t),s}function jW(e,t,n,r){if(!(bH(t)&&typeof r==`object`&&typeof r.lon==`number`&&typeof r.lat==`number`)&&!(xH(t)&&Array.isArray(r))&&!(SH(t)&&Array.isArray(r))&&!(DW.has(t)&&OW.has(e))&&e!==t)throw mH(`INVALID_DOCUMENT_PROPERTY`,n,t,e)}async function MW(e,t,n,r,i,a,o,s){for(let o of n){let n=r[o];if(n===void 0)continue;let c=e.index.getSearchablePropertiesWithTypes(e.data.index)[o];await e.index.beforeInsert?.(e.data.index,o,t,n,c,a,e.tokenizer,i);let l=e.internalDocumentIDStore.idToInternalId.get(t);await e.index.insert(e.index,e.data.index,o,t,l,n,c,a,e.tokenizer,i,s),await e.index.afterInsert?.(e.data.index,o,t,n,c,a,e.tokenizer,i)}let c=e.sorter.getSortableProperties(e.data.sorting),l=e.getDocumentProperties(o,c);for(let n of c){let r=l[n];if(r===void 0)continue;let i=e.sorter.getSortablePropertiesWithTypes(e.data.sorting)[n];e.sorter.insert(e.data.sorting,n,t,r,i,a)}}function NW(e,t,n,r,i,a,o,s){for(let o of n){let n=r[o];if(n===void 0)continue;let c=e.index.getSearchablePropertiesWithTypes(e.data.index)[o],l=OH(e.internalDocumentIDStore,t);e.index.beforeInsert?.(e.data.index,o,t,n,c,a,e.tokenizer,i),e.index.insert(e.index,e.data.index,o,t,l,n,c,a,e.tokenizer,i,s),e.index.afterInsert?.(e.data.index,o,t,n,c,a,e.tokenizer,i)}let c=e.sorter.getSortableProperties(e.data.sorting),l=e.getDocumentProperties(o,c);for(let n of c){let r=l[n];if(r===void 0)continue;let i=e.sorter.getSortablePropertiesWithTypes(e.data.sorting)[n];e.sorter.insert(e.data.sorting,n,t,r,i,a)}}function PW(e,t,n,r,i,a){return oH(e.afterInsertMultiple)||oH(e.beforeInsertMultiple)||oH(e.index.beforeInsert)||oH(e.index.insert)||oH(e.index.afterInsert)?FW(e,t,n,r,i,a):IW(e,t,n,r,i,a)}async function FW(e,t,n=1e3,r,i,a=0){let o=[],s=async a=>{let s=Math.min(a+n,t.length),c=t.slice(a,s);for(let t of c){let n=await EW(e,t,r,i,{avlRebalanceThreshold:c.length});o.push(n)}return s};return await(async()=>{let e=0;for(;e<t.length;){let t=Date.now();if(e=await s(e),a>0){let e=a-(Date.now()-t);e>0&&fH(e)}}})(),i||await GH(e.afterInsertMultiple,e,t),o}function IW(e,t,n=1e3,r,i,a=0){let o=[],s=0;function c(){let a=t.slice(s*n,(s+1)*n);if(a.length===0)return!1;for(let t of a){let n=EW(e,t,r,i,{avlRebalanceThreshold:a.length});o.push(n)}return s++,!0}function l(){let e=Date.now();for(;c();)if(a>0){let t=Date.now()-e;if(t>=a){let e=a-t%a;e>0&&fH(e)}}}return l(),i||GH(e.afterInsertMultiple,e,t),o}function LW(e,t){return e[1]-t[1]}function RW(e,t){return t[1]-e[1]}function zW(e=`desc`){return e.toLowerCase()===`asc`?LW:RW}function BW(e,t,n){let r={},i=t.map(([e])=>e),a=e.documentsStore.getMultiple(e.data.docs,i),o=Object.keys(n),s=e.index.getSearchablePropertiesWithTypes(e.data.index);for(let e of o){let t;if(s[e]===`number`){let{ranges:r}=n[e],i=r.length,a=Array.from({length:i});for(let e=0;e<i;e++){let t=r[e];a[e]=[`${t.from}-${t.to}`,0]}t=Object.fromEntries(a)}r[e]={count:0,values:t??{}}}let c=a.length;for(let e=0;e<c;e++){let t=a[e];for(let e of o){let i=e.includes(`.`)?nH(t,e):t[e],a=s[e],o=r[e].values;switch(a){case`number`:{let t=n[e].ranges;VW(t,o)(i);break}case`number[]`:{let t=new Set,r=n[e].ranges,a=VW(r,o,t);for(let e of i)a(e);break}case`boolean`:case`enum`:case`string`:HW(o,a)(i);break;case`boolean[]`:case`enum[]`:case`string[]`:{let e=HW(o,a===`boolean[]`?`boolean`:`string`,new Set);for(let t of i)e(t);break}default:throw mH(`FACET_NOT_SUPPORTED`,a)}}}for(let e of o){let t=r[e];if(t.count=Object.keys(t.values).length,s[e]===`string`){let r=n[e],i=zW(r.sort);t.values=Object.fromEntries(Object.entries(t.values).sort(i).slice(r.offset??0,r.limit??10))}}return r}function VW(e,t,n){return r=>{for(let i of e){let e=`${i.from}-${i.to}`;n?.has(e)||r>=i.from&&r<=i.to&&(t[e]===void 0?t[e]=1:(t[e]++,n?.add(e)))}}}function HW(e,t,n){let r=t===`boolean`?`false`:``;return t=>{let i=t?.toString()??r;n?.has(i)||(e[i]=(e[i]??0)+1,n?.add(i))}}const UW={reducer:(e,t,n,r)=>(t[r]=n,t),getInitialValue:e=>Array.from({length:e})},WW=[`string`,`number`,`boolean`];function GW(e,t,n){let r=n.properties,i=r.length,a=e.index.getSearchablePropertiesWithTypes(e.data.index);for(let e=0;e<i;e++){let t=r[e];if(a[t]===void 0)throw mH(`UNKNOWN_GROUP_BY_PROPERTY`,t);if(!WW.includes(a[t]))throw mH(`INVALID_GROUP_BY_PROPERTY`,t,WW.join(`, `),a[t])}let o=t.map(([t])=>kH(e.internalDocumentIDStore,t)),s=e.documentsStore.getMultiple(e.data.docs,o),c=s.length,l=n.maxResult||2**53-1,u=[],d={};for(let e=0;e<i;e++){let t=r[e],n={property:t,perValue:{}},i=new Set;for(let e=0;e<c;e++){let r=s[e],a=nH(r,t);if(a===void 0)continue;let o=typeof a==`boolean`?``+a:a,c=n.perValue[o]??{indexes:[],count:0};c.count>=l||(c.indexes.push(e),c.count++,n.perValue[o]=c,i.add(a))}u.push(Array.from(i)),d[t]=n}let f=KW(u),p=f.length,m=[];for(let e=0;e<p;e++){let t=f[e],n=t.length,i={values:[],indexes:[]},a=[];for(let e=0;e<n;e++){let n=t[e],o=r[e];a.push(d[o].perValue[typeof n==`boolean`?``+n:n].indexes),i.values.push(n)}i.indexes=eH(a).sort((e,t)=>e-t),i.indexes.length!==0&&m.push(i)}let h=m.length,g=Array.from({length:h});for(let e=0;e<h;e++){let r=m[e],i=n.reduce||UW,a=r.indexes.map(e=>({id:o[e],score:t[e][1],document:s[e]})),c=i.reducer.bind(null,r.values),l=i.getInitialValue(r.indexes.length),u=a.reduce(c,l);g[e]={values:r.values,result:u}}return g}function KW(e,t=0){if(t+1===e.length)return e[t].map(e=>[e]);let n=e[t],r=KW(e,t+1),i=[];for(let e of n)for(let t of r){let n=[e];WV(n,t),i.push(n)}return i}function qW(e,t,n,r){let i=vW(t,r);if(i.length===0)return n;let a=i.flatMap(e=>e.consequence.promote);a.sort((e,t)=>e.position-t.position);let o=new Set,s=new Map,c=new Set;for(let t of a){let n=OH(e.internalDocumentIDStore,t.doc_id);if(n!==void 0){if(s.has(n)){let e=s.get(n);t.position<e&&s.set(n,t.position);continue}c.has(t.position)||(o.add(n),s.set(n,t.position),c.add(t.position))}}if(s.size===0)return n;let l=n.filter(([e])=>!o.has(e)),u=[];for(let[t,r]of s.entries())n.find(([e])=>e===t)?u.push([t,1e6-r]):e.documentsStore.get(e.data.docs,t)&&u.push([t,0]);u.sort((e,t)=>(s.get(e[0])??1/0)-(s.get(t[0])??1/0));let d=[],f=new Map;for(let e of u){let t=s.get(e[0]);f.set(t,e)}let p=0,m=0;for(;m<l.length+u.length;)if(f.has(m))d.push(f.get(m)),m++;else if(p<l.length)d.push(l[p]),p++,m++;else break;for(let[e,t]of f.entries())e>=d.length&&d.push(t);return d}function JW(e,t,n){let{term:r,properties:i}=t,a=e.data.index,o=e.caches.propertiesToSearch;if(!o){let t=e.index.getSearchablePropertiesWithTypes(a);o=e.index.getSearchableProperties(a),o=o.filter(e=>t[e].startsWith(`string`)),e.caches.propertiesToSearch=o}if(i&&i!==`*`){for(let e of i)if(!o.includes(e))throw mH(`UNKNOWN_INDEX`,e,o.join(`, `));o=o.filter(e=>i.includes(e))}let s=Object.keys(t.where??{}).length>0,c;s&&(c=e.index.searchByWhereClause(a,e.tokenizer,t.where,n));let l,u=t.threshold!==void 0&&t.threshold!==null?t.threshold:1;if(r||i){let i=TW(e);if(l=e.index.search(a,r||``,e.tokenizer,n,o,t.exact||!1,t.tolerance||0,t.boost||{},$W(t.relevance),i,c,u),t.exact&&r){let t=r.trim().split(/\s+/);l=l.filter(([n])=>{let r=e.documentsStore.get(e.data.docs,n);if(!r)return!1;for(let e of o){let n=XW(r,e);if(typeof n==`string`&&t.every(e=>RegExp(`\\b${YW(e)}\\b`).test(n)))return!0}return!1})}}else l=s?AU(a,t.where)||(c?Array.from(c):[]).map(e=>[+e,0]):Object.keys(e.documentsStore.getAll(e.data.docs)).map(e=>[+e,0]);return l}function YW(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function XW(e,t){let n=t.split(`.`),r=e;for(let e of n)if(r&&typeof r==`object`&&e in r)r=r[e];else return;return r}function ZW(e,t,n){let r=XV();function i(){let i=Object.keys(e.data.index.vectorIndexes),a=t.facets&&Object.keys(t.facets).length>0,{limit:o=10,offset:s=0,distinctOn:c,includeVectors:l=!1}=t,u=t.preflight===!0,d=JW(e,t,n);if(t.sortBy)if(typeof t.sortBy==`function`){let n=d.map(([e])=>e),r=e.documentsStore.getMultiple(e.data.docs,n).map((e,t)=>[d[t][0],d[t][1],e]);r.sort(t.sortBy),d=r.map(([e,t])=>[e,t])}else d=e.sorter.sortBy(e.data.sorting,d,t.sortBy).map(([t,n])=>[OH(e.internalDocumentIDStore,t),n]);else d=d.sort($V);d=qW(e,e.data.pinning,d,t.term);let f;u||(f=c?dG(e,d,s,o,c):fG(e,d,s,o));let p={elapsed:{formatted:``,raw:0},hits:[],count:d.length};return f!==void 0&&(p.hits=f.filter(Boolean),l||aH(p,i)),a&&(p.facets=BW(e,d,t.facets)),t.groupBy&&(p.groups=GW(e,d,t.groupBy)),p.elapsed=e.formatElapsedTime(XV()-r),p}async function a(){e.beforeSearch&&await qH(e.beforeSearch,e,t,n);let r=i();return e.afterSearch&&await KH(e.afterSearch,e,t,n,r),r}return e.beforeSearch?.length||e.afterSearch?.length?a():i()}const QW={k:1.2,b:.75,d:.5};function $W(e){let t=e??{};return t.k=t.k??QW.k,t.b=t.b??QW.b,t.d=t.d??QW.d,t}function eG(e,t,n){let r=t.vector;if(r&&(!(`value`in r)||!(`property`in r)))throw mH(`INVALID_VECTOR_INPUT`,Object.keys(r).join(`, `));let i=e.data.index.vectorIndexes[r.property];if(!i)throw mH(`UNKNOWN_VECTOR_PROPERTY`,r.property);let a=i.node.size;if(r?.value.length!==a)throw r?.property===void 0||r?.value.length===void 0?mH(`INVALID_INPUT_VECTOR`,`undefined`,a,`undefined`):mH(`INVALID_INPUT_VECTOR`,r.property,a,r.value.length);let o=e.data.index,s;return Object.keys(t.where??{}).length>0&&(s=e.index.searchByWhereClause(o,e.tokenizer,t.where,n)),i.node.find(r.value,t.similarity??.8,s)}function tG(e,t,n=`english`){let r=XV();function i(){let i=eG(e,t,n).sort($V);i=qW(e,e.data.pinning,i,void 0);let a=[];t.facets&&Object.keys(t.facets).length>0&&(a=BW(e,i,t.facets));let o=t.vector.property,s=t.includeVectors??!1,c=t.limit??10,l=t.offset??0,u=Array.from({length:c});for(let t=0;t<c;t++){let n=i[t+l];if(!n)break;let r=e.data.docs.docs[n[0]];r&&(s||(r[o]=null),u[t]={id:kH(e.internalDocumentIDStore,n[0]),score:n[1],document:r})}let d=[];t.groupBy&&(d=GW(e,i,t.groupBy));let f=XV()-r;return{count:i.length,hits:u.filter(Boolean),elapsed:{raw:Number(f),formatted:YV(f)},...a?{facets:a}:{},...d?{groups:d}:{}}}async function a(){e.beforeSearch&&await qH(e.beforeSearch,e,t,n);let r=i();return e.afterSearch&&await KH(e.afterSearch,e,t,n,r),r}return e.beforeSearch?.length||e.afterSearch?.length?a():i()}function nG(e,t,n){let r=aG(JW(e,t,n)),i=eG(e,t,n),a=t.hybridWeights;return cG(r,i,t.term??``,a)}function rG(e,t,n){let r=XV();function i(){let i=nG(e,t,n);i=qW(e,e.data.pinning,i,t.term);let a;t.facets&&Object.keys(t.facets).length>0&&(a=BW(e,i,t.facets));let o;t.groupBy&&(o=GW(e,i,t.groupBy));let s=t.offset??0,c=t.limit??10,l=fG(e,i,s,c).filter(Boolean),u=XV(),d={count:i.length,elapsed:{raw:Number(u-r),formatted:YV(u-r)},hits:l,...a?{facets:a}:{},...o?{groups:o}:{}};return(t.includeVectors??!1)||aH(d,Object.keys(e.data.index.vectorIndexes)),d}async function a(){e.beforeSearch&&await qH(e.beforeSearch,e,t,n);let r=i();return e.afterSearch&&await KH(e.afterSearch,e,t,n,r),r}return e.beforeSearch?.length||e.afterSearch?.length?a():i()}function iG(e){return e[1]}function aG(e){let t=Math.max.apply(Math,e.map(iG));return e.map(([e,n])=>[e,n/t])}function oG(e,t){return e/t}function sG(e,t){return(n,r)=>n*e+r*t}function cG(e,t,n,r){let i=Math.max.apply(Math,e.map(iG)),a=Math.max.apply(Math,t.map(iG)),{text:o,vector:s}=r&&r.text&&r.vector?r:lG(n),c=new Map,l=e.length,u=sG(o,s);for(let t=0;t<l;t++){let[n,r]=e[t],a=u(oG(r,i),0);c.set(n,a)}let d=t.length;for(let e=0;e<d;e++){let[n,r]=t[e],i=oG(r,a),o=c.get(n)??0;c.set(n,o+u(0,i))}return[...c].sort((e,t)=>t[1]-e[1])}function lG(e){return{text:.5,vector:.5}}function uG(e,t,n){let r=t.mode??`fulltext`;if(r===`fulltext`)return ZW(e,t,n);if(r===`vector`)return tG(e,t);if(r===`hybrid`)return rG(e,t);throw mH(`INVALID_SEARCH_MODE`,r)}function dG(e,t,n,r,i){let a=e.data.docs,o=new Map,s=[],c=new Set,l=t.length,u=0;for(let d=0;d<l;d++){let l=t[d];if(l===void 0)continue;let[f,p]=l;if(c.has(f))continue;let m=e.documentsStore.get(a,f),h=nH(m,i);if(!(h===void 0||o.has(h))&&(o.set(h,!0),u++,!(u<=n)&&(s.push({id:kH(e.internalDocumentIDStore,f),score:p,document:m}),c.add(f),u>=n+r)))break}return s}function fG(e,t,n,r){let i=e.data.docs,a=Array.from({length:r}),o=new Set;for(let s=n;s<r+n;s++){let n=t[s];if(n===void 0)break;let[r,c]=n;if(!o.has(r)){let t=e.documentsStore.get(i,r);a[s]={id:kH(e.internalDocumentIDStore,r),score:c,document:t},o.add(r)}}return a}var pG=n(kV(),1);const mG=1,hG={protocol:`x-ok-client-protocol`,runtime:`x-ok-client-runtime`,kind:`x-ok-client-kind`};function gG({kind:e,runtimeVersion:t}){return{[hG.protocol]:`1`,[hG.runtime]:t,[hG.kind]:e}}const _G=`__system__`,vG=1,yG=`__config__/project`,bG=`__user__/config.yml`,xG=`__local__/project`,SG=`__config__/okignore`,CG=Object.freeze([yG,xG,bG,SG]),wG=`__skill__/`,TG=`__template__/`,EG=[`project`,`global`];function DG(e){return e.startsWith(`__skill__/`)||e.startsWith(`__template__/`)}const OG=`.ok/skills`;function kG(e){return`${OG}/${e}/SKILL`}const AG=[`references`,`scripts`];function jG(e,t){let n=/^(\.ok\/skills\/[^/]+)\/SKILL$/.exec(t);if(!n)return null;let r=n[1],i=e.trim().replace(/\.mdx?$/i,``).split(`/`).filter(e=>e!==``&&e!==`.`),[a]=i;return!a||!AG.includes(a)||i.includes(`..`)||i.length<2?null:`${r}/${i.join(`/`)}`}const MG=/^\.ok\/skills\/([^/]+)\/(SKILL|references\/.+)$/;function NG(e){let t=MG.exec(e);if(!t)return null;let n=t[1],r=t[2];return r===`SKILL`?{name:n,kind:`skill`,rel:null}:{name:n,kind:`reference`,rel:r.slice(11)}}const PG=/^__skill__\/global\/([^/]+)(?:\/(references\/.+))?$/;function FG(e){let t=PG.exec(e);if(!t)return null;let n=t[1],r=t[2];return r===void 0?{name:n,kind:`skill`,rel:null}:{name:n,kind:`reference`,rel:r.slice(11)}}function IG(e,t){return e===`project`?kG(t):`${wG}${e}/${t}`}function LG(e){if(e===``)return``;try{return e.split(`/`).map(e=>decodeURIComponent(e)).join(`/`)}catch{return e}}function RG(e){if(e.startsWith(`__skill__/`)){let t=e.slice(10),n=t.indexOf(`/`);if(n<0)return null;let r=t.slice(0,n);if(r!==`global`&&r!==`project`)return null;let i=t.slice(n+1);return i?{kind:`skill`,scope:r,name:LG(i)}:null}if(e.startsWith(`__template__/`)){let t=e.slice(13);if(!t)return null;let n=t.lastIndexOf(`/`),r=n<0?t:t.slice(n+1);return r?{kind:`template`,folder:LG(n<0?``:t.slice(0,n)),name:LG(r)}:null}return null}const zG=/^(?:(.+)\/)?\.ok\/templates\/([^/]+?)(?:\.mdx?)?$/;function BG(e){let t=zG.exec(e);if(t){let e=(t[1]??``).replace(/^\/+|\/+$/g,``);return`${TG}${e?`${e}/`:``}${t[2]}`}return null}const VG=[`.mdx`,`.md`],HG=`epoch`,UG=512*1024,WG=[`claude`,`claude-desktop`,`cursor`,`codex`,`copilot`,`opencode`,`openclaw`,`pi`,`antigravity`,`lm-studio`,`hermes`],GG={claude:`Claude`,"claude-desktop":`Claude Desktop`,cursor:`Cursor`,codex:`Codex`,copilot:`GitHub Copilot`,opencode:`OpenCode`,openclaw:`OpenClaw`,pi:`Pi`,antigravity:`Antigravity`,"lm-studio":`LM Studio`,hermes:`Hermes`},KG={claude:`.claude/skills`,"claude-desktop":null,cursor:`.cursor/skills`,codex:`.codex/skills`,copilot:`.github/skills`,opencode:`.opencode/skills`,openclaw:null,pi:`.pi/skills`,antigravity:null,"lm-studio":null,hermes:null},qG=WG.filter(e=>KG[e]!==null),JG=qG.filter(e=>e!==`pi`&&e!==`copilot`).map(e=>({hostDir:(KG[e]??``).split(`/`)[0],editorId:e})),YG={claude:`.mcp.json`,"claude-desktop":null,cursor:`.cursor/mcp.json`,codex:`.codex/config.toml`,copilot:null,opencode:`opencode.json`,openclaw:null,pi:`.pi/extensions/open-knowledge.ts`,antigravity:null,"lm-studio":null,hermes:null},XG={cursor:/\bCursor(?:\([^)]+\))?\/\d/,codex:/\bCodex(?:\([^)]+\))?\/\d/,"claude-desktop":/\bClaude(?:\([^)]+\))?\/\d/},ZG=`Ov23liqlSd0V1MwR6rhI`,QG=new Set([`gitlab.com`,`bitbucket.org`,`codeberg.org`,`gitea.com`,`sr.ht`,`sourcehut.org`]),$G=[`incoming`,`outgoing`,`both`];function eK(e){return $G.includes(e)}const tK=`open-knowledge`,nK=[{id:`chart`,title:`Chart`,description:`A bar chart whose series colors track the OK chart palette.`,html:`<div style="font-family:system-ui,sans-serif;padding:20px;color:var(--foreground)">
|
|
305
305
|
<h3 style="margin:0 0 14px;font-size:15px;font-weight:600">Revenue by region</h3>
|
|
306
306
|
<div id="bars" style="display:flex;align-items:flex-end;gap:14px;height:170px"></div>
|
|
307
307
|
<script>
|
|
@@ -457,4 +457,4 @@ $2`).split(`
|
|
|
457
457
|
`);if(!(t[0]??``).startsWith(`template:`))return null;let n=[t[0]??``],r=1;for(;r<t.length;){let e=t[r]??``;if(/^[ \t]/.test(e)){n.push(e),r++;continue}if(e.trim()===``){let i=r+1;for(;i<t.length&&(t[i]??``).trim()===``;)i++;if(i<t.length&&/^[ \t]/.test(t[i]??``)){n.push(e),r++;continue}}break}let i=n8(n.join(`
|
|
458
458
|
`))[t8];return{identity:typeof i==`object`&&i&&!Array.isArray(i)?i:{},docFrontmatterText:t.slice(r).join(`
|
|
459
459
|
`).replace(/\n+$/,``)}}function o8(e){let t=e.charCodeAt(0)===65279?e.slice(1):e,{frontmatter:n,body:r}=pK(t);if(n===``)return{identity:{},starterContent:t};let i=hK(n),a=a8(i);if(a)return{identity:a.identity,starterContent:r8(a.docFrontmatterText,r)};let{frontmatter:o}=pK(r);if(o!==``)return{identity:n8(i),starterContent:r};let s=n8(i);return typeof s.title==`string`?{identity:s,starterContent:r}:{identity:{},starterContent:r8(i,r)}}function s8(e,t){let{docFrontmatterText:n,markdown:r}=i8(t),i={};for(let[t,n]of Object.entries(e))n!==void 0&&(i[t]=n);let a=(0,Fc.stringify)({[t8]:i});return`---\n${n.trim()===``?a:`${a}${n}\n`}---\n${r}`}function c8(e){return o8(e).starterContent}function l8(){let e=!1,t=``,n=0;return r=>{let i=u8(r);return e?(i&&i.char===t&&i.len>=n&&!i.hasInfo&&(e=!1,t=``,n=0),!0):i?(e=!0,t=i.char,n=i.len,!0):!1}}function u8(e){let t=(e.endsWith(`\r`)?e.slice(0,-1):e).match(/^ {0,3}([`~])(\1{2,})(.*)$/);return t?{char:t[1],len:1+t[2].length,hasInfo:t[3].trim()!==``}:null}const d8=[`#D97757`,`#1B1912`,`#F9F3E9`,`#7A9DFF`,`#8534F3`,`#9663F0`,`#727CF3`],f8={claude:`#D97757`,cursor:`#1B1912`,windsurf:`#0B100F`,openai:`#7A9DFF`,github:`#8534F3`,cline:`#9663F0`,bot:`#727CF3`};function p8(e,t=d8){let n=0;for(let t of e)n=(n<<5)-n+t.charCodeAt(0)|0;return t[Math.abs(n)%t.length]}const m8={"claude-code":`claude`,"claude-ai":`claude`,cursor:`cursor`,"cursor-vscode":`cursor`,cascade:`windsurf`,codex:`openai`,"codex-mcp-client":`openai`,copilot:`github`,cline:`cline`};function h8(e){return e?m8[e]||(e.startsWith(`local-agent-mode-`)?`claude`:`bot`):`bot`}const g8={claude:`Claude`,cursor:`Cursor`,windsurf:`Windsurf`,openai:`Codex`,github:`Copilot`,cline:`Cline`};function _8(e){let t=e?.trim();return t?g8[h8(t)]??t:`Agent`}function v8(e,t){let n=e.trim();if(!n||/^[a-zA-Z][a-zA-Z\d+\-.]*:/.test(n)||n.startsWith(`//`)||n.startsWith(`#`))return null;let r=n.indexOf(`#`),i=r>=0?n.slice(0,r):n,a=r>=0?n.slice(r+1):null,o=(i.split(`?`)[0]??``).trim();if(!o)return null;let s=(o.split(`/`).pop()??``).match(/\.([a-z0-9]+)$/i);if(s){let e=(s[1]??``).toLowerCase();if(e!==`md`&&e!==`mdx`)return null}let c=o.toLowerCase(),l=c.endsWith(`.mdx`)?o.slice(0,-4):c.endsWith(`.md`)?o.slice(0,-3):o,u=l.startsWith(`/`),d=u?l.slice(1):l,f=u?[]:t.includes(`/`)?t.split(`/`).slice(0,-1):[];for(let e of d.split(`/`))if(e===`..`){if(f.length===0)return null;f.pop()}else e!==`.`&&e!==``&&f.push(e);return f.length===0?null:{docName:f.join(`/`),anchor:a||null}}const y8=/^[a-zA-Z][a-zA-Z\d+\-.]*:/;function b8(e){let t=(e.split(/[?#]/)[0]??e).match(/\.([a-z0-9]+)$/i);return t?(t[1]??``).toLowerCase():null}function x8(e){let t=e.trim();return y8.test(t)||t.startsWith(`//`)}function S8(e,t){let n=e.trim();if(!n)return null;if(n.startsWith(`#`)){let e=n.slice(1).trim();return e?{kind:`anchor`,anchor:e}:null}if(x8(n))return{kind:`external`,url:n};let r=v8(n,t);if(r)return{kind:`doc`,docName:r.docName,anchor:r.anchor};let i=b8(n);return i&&i!==`md`&&i!==`mdx`?{kind:`asset`,url:n,ext:i}:null}function C8(e,t){let n=e.trim();if(!n)return null;if(x8(n))return{kind:`external`,url:t?`${n}#${t}`:n};let r=b8(n);return r&&r!==`md`&&r!==`mdx`?{kind:`asset`,url:n,ext:r}:{kind:`doc`,docName:n,anchor:t?.trim()||null}}function w8(e,t){let n=e.trim();if(!n||y8.test(n)||n.startsWith(`//`)||n.startsWith(`#`))return null;let r=n.indexOf(`#`),i=((r>=0?n.slice(0,r):n).split(`?`)[0]??``).trim();if(!i)return null;let a=i.startsWith(`/`),o=a?i.slice(1):i,s=a?[]:t.includes(`/`)?t.split(`/`).slice(0,-1):[];for(let e of o.split(`/`))if(e===`..`){if(s.length===0)return null;s.pop()}else e!==`.`&&e!==``&&s.push(e);return s.length===0?null:s.join(`/`)}function T8(e){let t=e;return t.startsWith(`./`)&&(t=t.slice(2)),t.startsWith(`/`)&&(t=t.slice(1)),t}function E8(e){let t=e.lastIndexOf(`/`);return t===-1?e:e.slice(t+1)}function D8(e){let t=e.lastIndexOf(`/`);return t===-1?``:e.slice(0,t)}function O8(e){return e.split(`/`).filter(e=>e!==``)}function k8(e,t){let n=D8(t);return e===``||n===e?!0:n.startsWith(`${e}/`)}function A8(e,t){let n=D8(t);if(e===n)return 0;let r=e===``?n:n.slice(e.length+1);return r===``?0:O8(r).length}function j8(e,t){let n=O8(e),r=O8(t),i=0;for(;i<n.length&&i<r.length&&n[i]===r[i];)i++;return n.length-i+(r.length-i)}function M8(){let e=new Map;function t(t){let n=T8(t);if(n===``)return;let r=E8(n);if(r===``)return;let i=r.toLowerCase(),a=e.get(i);if(!a){e.set(i,[n]);return}a.includes(n)||a.push(n)}function n(t){let n=T8(t),r=E8(n).toLowerCase(),i=e.get(r);if(!i)return;let a=i.indexOf(n);a!==-1&&(i.splice(a,1),i.length===0&&e.delete(r))}function r(e,r){n(e),t(r)}function i(t,n){let r=t.toLowerCase(),i=e.get(r);if(!i||i.length===0)return null;if(i.length===1)return i[0];let a=D8(T8(n)),o=[],s=[];for(let e of i)k8(a,e)?o.push(e):s.push(e);return o.length>0?(e=>{let t=e[0],n=A8(a,t);for(let r=1;r<e.length;r++){let i=e[r],o=A8(a,i);(o<n||o===n&&i<t)&&(t=i,n=o)}return t})(o):(e=>{let t=e[0],n=j8(a,D8(t));for(let r=1;r<e.length;r++){let i=e[r],o=j8(a,D8(i));(o<n||o===n&&i<t)&&(t=i,n=o)}return t})(s)}function a(){let t=new Map;for(let[n,r]of e)t.set(n,[...r]);return t}function o(){e.clear()}return{add:t,remove:n,rename:r,resolveEmbed:i,clear:o,snapshot:a,size:()=>e.size}}function N8(e){if(!e)return[];let t=e.split(`/`),n=[],r=``;for(let e of t)r=r?`${r}/${e}`:e,n.push(r);return n}function P8(e,t){if(e.size===0)return new Set;if(t===``)return new Set(e);let n=new Set,r=`${t}/`;for(let i of e)(i===t||i.startsWith(r))&&n.add(i);return n}function F8(e){try{return process.kill(e,0),!0}catch(e){return!!(e&&typeof e==`object`&&`code`in e&&e.code===`EPERM`)}}function I8(e){return!(typeof e!=`number`||!Number.isInteger(e)||e<2||e>2147483647)}const L8=/^[A-Za-z0-9-]{8,64}$/;let R8=null;function z8(e){return l(e??m(),`.ok`,`machine-id`)}function B8(e){if(e===void 0&&R8!==null)return R8;let t=z8(e),n=null;try{let e=b(t,`utf-8`).trim();L8.test(e)&&(n=e)}catch{}if(n===null){n=w();try{v(c(t),{recursive:!0}),S(t,`${n}\n`,{encoding:`utf-8`,mode:384})}catch(e){console.warn(`[machine-id] Failed to persist ${t} — using an ephemeral per-process id; lock ownership checks will fail closed (collision) instead of recognizing this machine: ${e instanceof Error?e.message:String(e)}`)}}return e===void 0&&(R8=n),n}function V8(){try{let e=u(c(f(import.meta.url)),`..`,`package.json`),t=JSON.parse(b(e,`utf-8`));if(typeof t.version==`string`&&t.version.length>0)return t.version}catch{}return`0.0.0-unknown`}const H8=V8(),U8=1;var W8=class extends Error{existing;lockPath;lockName;constructor(e,t,n){super(`OpenKnowledge ${n} already running on port ${e.port} (pid ${e.pid}, started ${e.startedAt}). Stop it first or use a different directory. Lock: ${t}`),this.name=`ProcessLockCollisionError`,this.existing=e,this.lockPath=t,this.lockName=n}};function G8(e,t){return u(e,`${t}.lock`)}const K8=new Map;function q8(e){K8.set(e,(K8.get(e)??0)+1)}function J8(e){let t=K8.get(e);return t===void 0||t<=1?(K8.delete(e),!0):(K8.set(e,t-1),!1)}function Y8(e){return typeof e.machineId==`string`?e.machineId===B8():e.hostname===h()}const X8=new Set;let Z8=!1;function Q8(e){X8.add(e),!Z8&&(Z8=!0,process.on(`exit`,()=>{for(let e of X8)try{let t=JSON.parse(b(e,`utf-8`));if(t?.pid!==process.pid||typeof t.machineId==`string`&&t.machineId!==B8()||t.machineId===void 0&&typeof t.hostname==`string`&&t.hostname!==h())continue;x(e)}catch{}}))}function $8(e,t){try{let n=JSON.parse(b(e,`utf-8`));return n&&typeof n==`object`&&I8(n.pid)?n:(console.warn(`${t} Corrupt lock file at ${e} — replacing`),null)}catch{return console.warn(`${t} Corrupt lock file at ${e} — replacing`),null}}function e5(e){let{lockName:t,lockDir:n,metadata:r}=e,i=`[${t}-lock]`;v(n,{recursive:!0});let a=G8(n,t),o={pid:process.pid,hostname:h(),port:r.port,startedAt:new Date().toISOString(),worktreeRoot:r.worktreeRoot,machineId:B8(),...r.kind!==void 0&&{kind:r.kind},...r.parentPid!==void 0&&{parentPid:r.parentPid},...r.capabilities!==void 0&&{capabilities:r.capabilities},protocolVersion:r.protocolVersion??1,runtimeVersion:r.runtimeVersion??H8},s=JSON.stringify(o,null,2);for(let e=0;e<3;e++){if(!_(a))try{let e=y(a,`wx`,384);try{C(e,s)}finally{g(e)}return q8(a),Q8(a),t5({lockName:t,lockDir:n,lockPath:a})}catch(e){if(e.code!==`EEXIST`)throw e}let e=$8(a,i);if(e){if(Y8(e)&&e.pid===process.pid)return S(a,s,{encoding:`utf-8`,mode:384}),q8(a),Q8(a),t5({lockName:t,lockDir:n,lockPath:a});if(F8(e.pid))throw new W8(e,a,t);console.warn(`${i} Stale lock detected (pid=${e.pid}, host=${e.hostname}) — replacing`)}try{x(a)}catch{}}throw Error(`${i} Failed to acquire ${a} after 3 attempts (concurrent acquire contention).`)}function t5(e){let{lockName:t,lockDir:n,lockPath:r}=e;return{lockPath:r,release:()=>s5({lockName:t,lockDir:n}),updatePort:e=>n5({lockName:t,lockDir:n,port:e})}}function n5(e){let{lockName:t,lockDir:n,port:r}=e,i=`[${t}-lock]`,a=G8(n,t);if(!_(a)){console.warn(`${i} Lock file missing at ${a} during port update — skipping`);return}let o;try{let e=JSON.parse(b(a,`utf-8`));if(!e||typeof e!=`object`||!I8(e.pid)){console.warn(`${i} Corrupt lock at ${a} during port update — skipping`);return}o=e}catch{console.warn(`${i} Unreadable lock at ${a} during port update — skipping`);return}if(o.pid===process.pid&&Y8(o)){o.port=r;try{S(a,JSON.stringify(o,null,2),{encoding:`utf-8`,mode:384})}catch(e){console.warn(`${i} Failed to update port in ${a}: ${e instanceof Error?e.message:String(e)}`)}}}function r5(e){let{lockName:t,lockDir:n}=e,r=`[${t}-lock]`,i=G8(n,t);if((K8.get(i)??0)>1)return;let a;try{let e=JSON.parse(b(i,`utf-8`));if(!e||typeof e!=`object`||!I8(e.pid)){console.warn(`${r} Corrupt lock at ${i} during draining mark — skipping`);return}a=e}catch(e){e.code!==`ENOENT`&&console.warn(`${r} Unreadable lock at ${i} during draining mark — skipping: ${e instanceof Error?e.message:String(e)}`);return}if(a.pid===process.pid&&Y8(a)&&a.draining!==!0){a.draining=!0;try{S(i,JSON.stringify(a,null,2),{encoding:`utf-8`,mode:384})}catch(e){console.warn(`${r} Failed to mark ${i} draining: ${e instanceof Error?e.message:String(e)}`)}}}function i5(e){let{lockName:t,lockDir:n}=e,r=G8(n,t);if(!_(r))return null;let i;try{let e=JSON.parse(b(r,`utf-8`));if(!e||typeof e!=`object`||!I8(e.pid))return null;i=e}catch{return null}if(!Y8(i))return null;if(!F8(i.pid)){try{x(r)}catch{}return null}return i}function a5(e){let{lockName:t,lockDir:n}=e,r=G8(n,t);if(!_(r))return{status:`absent`};let i;try{i=JSON.parse(b(r,`utf-8`))}catch{return{status:`incompatible`,reason:`corrupt`,raw:void 0}}if(!i||typeof i!=`object`)return{status:`incompatible`,reason:`corrupt`,raw:i};let a=i;if(!I8(a.pid)||typeof a.hostname!=`string`||typeof a.port!=`number`||typeof a.startedAt!=`string`||typeof a.worktreeRoot!=`string`)return{status:`incompatible`,reason:`corrupt`,raw:i};let o={pid:a.pid,hostname:a.hostname,port:a.port,startedAt:a.startedAt,worktreeRoot:a.worktreeRoot,machineId:typeof a.machineId==`string`?a.machineId:void 0,draining:a.draining===!0?!0:void 0,protocolVersion:typeof a.protocolVersion==`number`?a.protocolVersion:void 0,runtimeVersion:typeof a.runtimeVersion==`string`?a.runtimeVersion:void 0};if(!Y8(o))return{status:`stale`,lock:o};if(!F8(o.pid)){try{x(r)}catch{}return{status:`stale`,lock:o}}return o.protocolVersion===void 0||o.runtimeVersion===void 0?{status:`incompatible`,reason:`missing-fields`,raw:i}:{status:`live`,lock:o}}async function o5(e){let{lockName:t,lockDir:n}=e,r=e.timeoutMs??1e4,i=e.pollIntervalMs??100,a=e.readLock??(()=>i5({lockName:t,lockDir:n})),o=e.sleep??(e=>new Promise(t=>setTimeout(t,e))),s=a();if(s===null||s.draining!==!0)return`no-drain`;let c=Date.now()+r;for(;Date.now()<c;){await o(i);let e=a();if(e===null)return`released`;if(e.draining!==!0)return`no-drain`}return`timeout`}function s5(e){let{lockName:t,lockDir:n,deferUnlinkToExit:r=!1}=e,i=`[${t}-lock]`,a=G8(n,t);if(J8(a)){if(r){r5({lockName:t,lockDir:n});return}if(_(a))try{let e=JSON.parse(b(a,`utf-8`));if(!e||typeof e!=`object`||typeof e.pid!=`number`||e.pid!==process.pid||!Y8(e))return;x(a),X8.delete(a)}catch(e){console.warn(`${i} Failed to release ${a}: ${e instanceof Error?e.message:String(e)}`)}}}var c5=class extends W8{constructor(e,t){super(e,t,`server`),this.name=`ServerLockCollisionError`}};function l5(e,t){try{return e5({lockName:`server`,lockDir:e,metadata:t}).lockPath}catch(e){throw e instanceof W8&&e.lockName===`server`?new c5(e.existing,e.lockPath):e}}function u5(e,t){n5({lockName:`server`,lockDir:e,port:t})}function d5(e){return i5({lockName:`server`,lockDir:e})}function f5(e,t){s5({lockName:`server`,lockDir:e,...t})}function p5(e){r5({lockName:`server`,lockDir:e})}function m5(e,t){return o5({lockName:`server`,lockDir:e,...t})}export{hG as $,Ml as $a,U4 as $i,Hq as $n,D0 as $r,_0 as $t,h1 as A,wq as Aa,e8 as Ai,OG as An,ac as Ao,P0 as Ar,A2 as At,E1 as B,Cl as Ba,c8 as Bi,Z1 as Bn,si as Bo,t8 as Br,i6 as Bt,w1 as C,IG as Ca,_6 as Ci,uJ as Cn,rc as Co,f4 as Cr,U0 as Ct,A1 as D,r3 as Da,_8 as Di,n0 as Dn,P as Do,X2 as Dr,Y1 as Dt,g1 as E,P8 as Ea,J4 as Ei,Y0 as En,j as Eo,l4 as Er,KG as Et,V1 as F,uu as Fa,X$ as Fi,S2 as Fn,Go as Fo,u2 as Fr,u1 as Ft,j4 as G,Kc as Ga,DG as Gi,v2 as Gn,gn as Go,N2 as Gr,QG as Gt,N4 as H,Sl as Ha,p1 as Hi,y4 as Hn,un as Ho,O2 as Hr,x2 as Ht,B1 as I,qc as Ia,W$ as Ii,$3 as In,Uo as Io,d2 as Ir,JG as It,E4 as J,lu as Ja,Gq as Ji,lJ as Jn,Dt as Jo,F2 as Jr,r0 as Jt,O4 as K,Xc as Ka,eK as Ki,p2 as Kn,cn as Ko,R2 as Kr,HG as Kt,nJ as L,su as La,GY as Li,VG as Ln,ma as Lo,o2 as Lr,$1 as Lt,m1 as M,_b as Ma,N8 as Mi,K6 as Mn,$s as Mo,u0 as Mr,U1 as Mt,O1 as N,sp as Na,r6 as Ni,q6 as Nn,Ks as No,f2 as Nr,M1 as Nt,_1 as O,H$ as Oa,Z3 as Oi,e2 as On,dc as Oo,Z2 as Or,L0 as Ot,dJ as P,L as Pa,E$ as Pi,Y6 as Pn,xs as Po,l2 as Pr,N1 as Pt,vG as Q,Jc as Qa,d3 as Qi,zq as Qn,mt as Qo,E0 as Qr,m0 as Qt,i3 as R,Ol as Ra,_q as Ri,_G as Rn,Ka as Ro,s2 as Rr,e0 as Rt,WG as S,Cq as Sa,y6 as Si,W0 as Sn,tc as So,d4 as Sr,H0 as St,w0 as T,pK as Ta,L3 as Ti,J0 as Tn,Zs as To,c4 as Tr,YG as Tt,M4 as U,xl as Ua,Eq as Ui,m2 as Un,fn as Uo,E2 as Ur,N0 as Ut,k4 as V,wl as Va,qq as Vi,h4 as Vn,br as Vo,W2 as Vr,y2 as Vt,A4 as W,bl as Wa,eJ as Wi,h2 as Wn,mn as Wo,L2 as Wr,s6 as Wt,w4 as X,ru as Xa,p3 as Xi,Fq as Xn,O as Xo,P2 as Xr,a0 as Xt,T4 as Y,cu as Ya,BG as Yi,Mq as Yn,k as Yo,I2 as Yr,i0 as Yt,S4 as Z,Yc as Za,I3 as Zi,Bq as Zn,ht as Zo,O0 as Zr,y0 as Zt,f5 as _,jG as _a,s8 as _i,nK as _n,Hs as _o,m4 as _r,l0 as _t,e5 as a,o8 as aa,hJ as ai,p0 as an,fl as ao,i4 as ar,rJ as at,m5 as b,X3 as ba,l8 as bi,mG as bn,M as bo,C2 as br,R1 as bt,F8 as c,a1 as ca,R4 as ci,EG as cn,ml as co,K2 as cr,F1 as ct,r5 as d,Z4 as da,$q as di,M0 as dn,Ll as do,s4 as dr,R0 as dt,FG as ea,T0 as ei,v0 as en,zl as eo,Wq as er,CG as et,p5 as f,s3 as fa,S8 as fi,A0 as fn,Al as fo,$2 as fr,z0 as ft,s5 as g,v8 as ga,RJ as gi,R3 as gn,F as go,p4 as gr,UG as gt,d5 as h,$6 as ha,p8 as hi,o0 as hn,uc as ho,Y2 as hr,Q3 as ht,c5 as i,T2 as ia,gJ as ii,d0 as in,Jl as io,a4 as ir,bG as it,k1 as j,q4 as ja,V6 as ji,V2 as jn,A as jo,vJ as jr,j2 as jt,j1 as k,hK as ka,c6 as ki,t2 as kn,Pc as ko,q2 as kr,k2 as kt,I8 as l,c3 as la,n3 as li,tK as ln,El as lo,o4 as lr,B0 as lt,a5 as m,w8 as ma,gG as mi,$G as mn,Ls as mo,J2 as mr,aK as mt,H8 as n,RG as na,$0 as ni,g0 as nn,ou as no,sJ as nr,yG as nt,l5 as o,mK as oa,t0 as oi,wG as on,Dl as oo,n4 as or,aJ as ot,i5 as p,o1 as pa,C8 as pi,k0 as pn,jl as po,e4 as pr,ZG as pt,C4 as q,pl as qa,W3 as qi,v4 as qn,zt as qo,z2 as qr,K1 as qt,U8 as r,NG as ra,XG as ri,h0 as rn,Zl as ro,Q2 as rr,xG as rt,B8 as s,rK as sa,z4 as si,TG as sn,tu as so,r4 as sr,P1 as st,W8 as t,l6 as ta,Q0 as ti,_J as tn,Tl as to,oJ as tr,SG as tt,G8 as u,kG as ua,pJ as ui,D$ as un,Bl as uo,x4 as ur,V0 as ut,n5 as v,R6 as va,U2 as vi,iK as vn,Ws as vo,B2 as vr,X0 as vt,C0 as w,o3 as wa,G3 as wi,mJ as wn,I as wo,w2 as wr,GG as wt,f8 as x,xq as xa,$Z as xi,K0 as xn,jc as xo,u4 as xr,L1 as xt,u5 as y,W4 as ya,M8 as yi,qG as yn,N as yo,Q6 as yr,Z0 as yt,g3 as z,Zc as za,h8 as zi,X1 as zn,qa as zo,c2 as zr,s0 as zt};
|
|
460
|
-
//# sourceMappingURL=server-lock-iLcBw_q0-
|
|
460
|
+
//# sourceMappingURL=server-lock-iLcBw_q0-DddnIrHS.mjs.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{s as e}from"./chunk-C94x7I9S.mjs";import{Qo as t,c as n,l as r,s as i,u as a}from"./server-lock-iLcBw_q0-
|
|
1
|
+
import{s as e}from"./chunk-C94x7I9S.mjs";import{Qo as t,c as n,l as r,s as i,u as a}from"./server-lock-iLcBw_q0-DddnIrHS.mjs";import{Ar as o,Qi as s,Sn as c,ha as l,jr as u,pa as d,ti as f,un as p,vn as m}from"./dist-CynAX6cy.mjs";import{t as h}from"./yazl-DgCFuIuD.mjs";import{t as g}from"./esm-CsQUg9js.mjs";import"./gh-detect-Uu4VAWnW.mjs";import{E as _,S as v,T as y,_ as ee,b as te,o as b,v as x,w as S}from"./init-1G9fj8cH.mjs";import{n as C}from"./constants-B2EvNGWZ.mjs";import{t as w}from"./is-object-Cie0xXKD.mjs";import{S as ne,h as re,i as ie,x as T}from"./write-project-skill-DV1PSHkd.mjs";import"./loader-DIcwzOTi.mjs";import{c as ae}from"./colors-8SzMRIVy.mjs";import"./preview-C9JeIyOB.mjs";import{execSync as oe,spawnSync as E}from"node:child_process";import{basename as D,dirname as O,isAbsolute as k,join as A,relative as se,resolve as j,sep as ce}from"node:path";import{arch as le,freemem as ue,homedir as de,hostname as fe,platform as pe,release as me,tmpdir as he,totalmem as ge,type as _e,uptime as ve}from"node:os";import{cpSync as ye,createWriteStream as be,existsSync as M,lstatSync as xe,mkdirSync as N,mkdtempSync as Se,readFileSync as P,readdirSync as F,readlinkSync as Ce,rmSync as I,statSync as we,writeFileSync as L}from"node:fs";import{createHash as R}from"node:crypto";import{readFile as z,realpath as B}from"node:fs/promises";const Te=[{name:`macos-home-path`,regex:/\/Users\/[^/]+\//g,replacement:`~/`},{name:`linux-home-path`,regex:/\/home\/[^/]+\//g,replacement:`~/`},{name:`github-pat`,regex:/\b(ghp_|gho_|ghu_|ghs_|ghr_)[A-Za-z0-9]{36,}\b/g,replacement:`[REDACTED-GH-PAT]`},{name:`aws-access-key`,regex:/\b(AKIA|ASIA|ABIA)[A-Z2-7]{16}\b/g,replacement:`[REDACTED-AWS-KEY]`},{name:`anthropic-key`,regex:/\bsk-ant-api03-[A-Za-z0-9_-]{20,}\b/g,replacement:`[REDACTED-ANTHROPIC]`},{name:`openai-key`,regex:/\bsk-[A-Za-z0-9]{20,}\b/g,replacement:`[REDACTED-OPENAI]`},{name:`bearer-token`,regex:/([Aa]uthorization:\s*[Bb]earer\s+)\S+/g,replacement:`$1[REDACTED]`},{name:`jwt`,regex:/eyJ[A-Za-z0-9_-]{8,}\.eyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}/g,replacement:`[REDACTED-JWT]`},{name:`url-credentials`,regex:/:\/\/[^/\s:@]+:[^/\s:@]+@/g,replacement:`://[REDACTED]@`}],Ee=Te.map(e=>e.name);function V(e){let t=new Set,n=0;return{redacted:e.split(`
|
|
2
2
|
`).map(e=>{let r=e;for(let{name:e,regex:i,replacement:a}of Te)i.lastIndex=0,i.test(r)&&(t.add(e),n++,i.lastIndex=0,r=r.replace(i,a));return r}).join(`
|
|
3
3
|
`),patterns:[...t],lineCount:n}}function De(){return A(de(),`.ok`,`bug-reports`)}function Oe(e=new Date){let t=e.toISOString().replace(/[:.]/g,`-`);return A(De(),`${t}-bugreport.zip`)}function ke(e,t){let n=A(e,`.ok`,`config.yml`);if(M(n))try{let e=P(n,`utf8`).match(/^\s*name:\s*['"]?(.+?)['"]?\s*$/m);if(e?.[1])return e[1]}catch(e){t?.warn({configPath:n,err:e instanceof Error?e.message:String(e)},`bug-report: failed to read .ok/config.yml for project slug; using path-hash fallback`)}return M(A(e,`.ok`))?R(`sha256`).update(j(e)).digest(`hex`).slice(0,12):null}function Ae(){let e={timestamp:new Date().toISOString(),platform:pe(),osType:_e(),osRelease:me(),hostname:`[redacted]`,uptime:ve(),freeMem:ue(),totalMem:ge(),nodeVersion:process.version,bunVersion:process.versions.bun??null,v8Version:process.versions.v8??null,pid:process.pid};try{e.macosVersion=oe(`sw_vers -productVersion 2>/dev/null`,s({encoding:`utf8`})).trim()}catch{}try{let t=A(__dirname,`..`,`..`,`package.json`);M(t)&&(e.okVersion=JSON.parse(P(t,`utf8`)).version)}catch{}return e}function je(e,t){if(!M(t))return{files:[]};let n=F(t).filter(e=>e.endsWith(`.log`)||/\.log\.\d+$/.test(e)).map(e=>A(t,e));if(e&&n.length>0){let t=n.filter(t=>{try{return P(t,`utf8`).includes(`"project":"${e}"`)}catch{return!0}});t.length>0&&(n=t)}return{files:n}}function Me(e){let t=A(e,`.ok`,`local`);return M(t)?{files:[`server.lock`,`last-spawn-error.log`].map(e=>A(t,e)).filter(e=>M(e))}:{files:[]}}function Ne(e){let t=A(e,`.ok`,`local`,`logs`);return M(t)?{files:[`server-current.jsonl`,`server-prev.jsonl`].map(e=>A(t,e)).filter(e=>M(e))}:{files:[]}}function Pe(e){if(e.redact){let{redacted:t,patterns:n,lineCount:r}=V(e.content);e.zipfile.addBuffer(Buffer.from(t,`utf8`),e.name),e.bundleFiles.push(e.name),n.length>0&&e.redactions.push({file:e.name,lineCount:r,patterns:n})}else e.zipfile.addBuffer(Buffer.from(e.content,`utf8`),e.name),e.bundleFiles.push(e.name)}function H(e){for(let t of e.files)try{Pe({zipfile:e.zipfile,name:`${e.prefix}/${D(t)}`,content:P(t,`utf8`),redact:e.redact,bundleFiles:e.bundleFiles,redactions:e.redactions})}catch(n){e.logger?.warn({file:t,prefix:e.prefix,err:n instanceof Error?n.message:String(n)},`bug-report: skipped unreadable file`)}}async function Fe(t){let{redact:n,outputPath:r,logger:i}=t,a=t.userLogsDir??A(de(),`.ok`,`logs`),o=t.projectDir?ke(t.projectDir,i):null;N(O(r),{recursive:!0}),i?.info({projectSlug:o},`gathering diagnostic data`);let s=Ae();s.desktop=t.desktop??null;let{files:c}=je(o,a),{files:l}=t.projectDir?Me(t.projectDir):{files:[]},{files:u}=t.projectDir?Ne(t.projectDir):{files:[]};i?.info({logFileCount:c.length,lockFileCount:l.length,localSinkFileCount:u.length},`files collected`);let d=[],f=[],{ZipFile:p}=await import(`./yazl-Clfc09F-.mjs`).then(t=>e(t.default,1)),m=new p;H({zipfile:m,files:c,prefix:`logs`,redact:n,bundleFiles:f,redactions:d,logger:i}),H({zipfile:m,files:l,prefix:`lockdir`,redact:n,bundleFiles:f,redactions:d,logger:i}),H({zipfile:m,files:u,prefix:`local-logs`,redact:n,bundleFiles:f,redactions:d,logger:i});for(let e of t.extraFiles??[])try{let t=P(e.sourcePath),n=`extra/${e.zipName??D(e.sourcePath)}`;m.addBuffer(t,n),f.push(n)}catch(t){i?.warn({sourcePath:e.sourcePath,err:t},`extra file unreadable; omitted from bundle`)}t.note&&Pe({zipfile:m,name:`note.txt`,content:t.note,redact:n,bundleFiles:f,redactions:d});let h=JSON.stringify(s,null,2);m.addBuffer(Buffer.from(h,`utf8`),`sysinfo.json`),f.push(`sysinfo.json`);let g={generatedAt:new Date().toISOString(),disciplineVersion:`1.0.0`,projectSlug:o,files:f,redactions:d,sysinfo:s};m.addBuffer(Buffer.from(JSON.stringify(g,null,2),`utf8`),`MANIFEST.json`);let _=d.reduce((e,t)=>e+t.lineCount,0),v=[`# Bug Report Bundle`,``,`Generated: ${g.generatedAt}`,`Project: ${o??`(unscoped)`}`,`Discipline version: ${g.disciplineVersion}`,``,`## Contents`,``,...f.map(e=>`- ${e}`),``,`## Privacy`,``,...n?[`This bundle was auto-redacted before packaging.`,`Patterns checked: ${Ee.join(`, `)}`,_>0?`${_} line(s) were scrubbed across ${d.length} file(s).`:`No redactions were needed.`,`See MANIFEST.json for the full redaction audit report.`,``,`This bundle is safe to attach to a GitHub issue.`]:[`Redaction was disabled for this bundle; file contents are unmodified.`]].join(`
|
|
4
4
|
`);m.addBuffer(Buffer.from(v,`utf8`),`README.md`),m.end();let y=be(r);return m.outputStream.pipe(y),await new Promise((e,t)=>{y.on(`close`,e),y.on(`error`,t)}),i?.info({bundlePath:r,fileCount:f.length,redactionCount:_},`bundle written`),{zipPath:r,summary:{projectSlug:o,files:f,redactions:d,redactedLineCount:_,generatedAt:g.generatedAt}}}const Ie=new Set([`doc.name`]);function Le(e){return`doc:${R(`blake2b512`,{outputLength:32}).update(e).digest(`hex`).slice(0,8)}`}function Re(e,t,n){let r=e.docNameMap[n];if(r===void 0){e.docNameMap[n]=t;return}if(r===t)return;let i=e.docNameCollisions[n];i?i.includes(t)||i.push(t):e.docNameCollisions[n]=[t]}function ze(e,t){let n=t.originalToHashed.get(e);if(n!==void 0)return n;let r=Le(e);return t.originalToHashed.set(e,r),Re(t,e,r),r}function U(e,t){return t.length===0||!e.includes(t)?e:e.split(t).join(`<CONTENT_DIR>`)}function W(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function G(e,t){if(typeof e==`string`)return U(e,t.contentDir);if(Array.isArray(e))return e.map(e=>G(e,t));if(!W(e))return e;let n=typeof e.key==`string`&&Ie.has(e.key)&&W(e.value)&&typeof e.value.stringValue==`string`?e.value.stringValue:null,r={};for(let[i,a]of Object.entries(e))if(n!==null&&i===`value`&&W(a)){let e=ze(n,t);r[i]={...a,stringValue:e}}else Ie.has(i)&&typeof a==`string`?r[i]=ze(a,t):r[i]=G(a,t);return r}function Be(e,t){if(t.originalToHashed.size===0)return e;let n=Array.from(t.originalToHashed.entries()).sort(([e],[t])=>t.length-e.length),r=e;for(let[e,t]of n)e.length!==0&&r.includes(e)&&(r=r.split(e).join(t));return r}function Ve(e,t){let n=P(e,`utf-8`);if(n.length===0)return;let r=n.endsWith(`
|
|
@@ -8,7 +8,7 @@ import{s as e}from"./chunk-C94x7I9S.mjs";import{Qo as t,c as n,l as r,s as i,u a
|
|
|
8
8
|
`))}function He(e,t){let n=P(e,`utf-8`);if(n.trim().length!==0)try{let r=G(JSON.parse(n),t),i=n.endsWith(`
|
|
9
9
|
`)?`
|
|
10
10
|
`:``;L(e,`${JSON.stringify(r,null,2)}${i}`)}catch{let r=Be(U(n,t.contentDir),t);r!==n&&L(e,r)}}function Ue(e,t){let n=P(e,`utf-8`),r=U(n,t.contentDir);r!==n&&L(e,r)}function We(e){try{return F(e,{withFileTypes:!0}).filter(e=>e.isFile()).map(t=>A(e,t.name))}catch{return[]}}const Ge=new Set([`agent-presence.json`,`runtime.json`]);function Ke(e){let t={contentDir:e.contentDir,docNameMap:{},originalToHashed:new Map,docNameCollisions:{}};for(let n of[`telemetry`,`logs`,`process`])for(let r of We(A(e.stagingDir,n)))r.endsWith(`.jsonl`)?Ve(r,t):r.endsWith(`.json`)?He(r,t):Ue(r,t);for(let n of We(A(e.stagingDir,`state`))){let e=D(n);Ge.has(e)?He(n,t):Ue(n,t)}return{docNameMap:t.docNameMap,docNameCollisions:t.docNameCollisions}}var K=t(),qe=e(h(),1);const Je=[`.ok`,`local`,`telemetry`],Ye=[`.ok`,`local`,`logs`],Xe=`spans-current.jsonl`,Ze=`spans-prev.jsonl`,Qe=`server-current.jsonl`,$e=`server-prev.jsonl`;function et(e){return A(e,...Je,Xe)}function tt(e){return A(e,...Je,Ze)}function nt(e){return A(e,...Ye,Qe)}function rt(e){return A(e,...Ye,$e)}async function it(e){try{let t=await fetch(`http://127.0.0.1:${e}/api/metrics/agent-presence`,{signal:AbortSignal.timeout(1e3)});return t.ok?await t.text():null}catch{return null}}function at(e){let t=A(e,`.git`,`ok`);if(!M(t))return null;let n=E(`git`,[`-C`,t,`log`,`--oneline`,`-50`],s({encoding:`utf-8`,timeout:2e3}));return n.error||n.status!==0?null:n.stdout??``}function ot(){let e=process.env.OK_DESKTOP_VERSION,t=process.env.OK_DESKTOP_PACKAGED,n=process.env.OK_DESKTOP_CHANNEL;return e===void 0||t===void 0||n===void 0?null:{electronVersion:e,packaged:t===`1`||t.toLowerCase()===`true`,channel:n}}function st(){return{nodeVersion:process.version,platform:pe(),arch:le()}}function ct(){return process.env.OTEL_SDK_DISABLED===`false`}function q(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function lt(e){if(!M(e))return{};let t;try{t=(0,K.parse)(P(e,`utf-8`))}catch(t){return console.warn(`[ok diagnose bundle] failed to parse ${e} for manifest config; manifest will report schema defaults. Reason: ${t instanceof Error?t.message:String(t)}`),{}}if(!q(t))return{};let n=t.telemetry;if(!q(n))return{};let r=n.localSink;return q(r)?r:{}}function ut(e){return typeof e==`boolean`?e:void 0}function dt(e){return typeof e==`number`&&Number.isFinite(e)&&e>0?e:void 0}function J(e){if(q(e))return dt(e.maxBytes)}function ft(e){let t=lt(l(`project`,e)),n=lt(l(`project-local`,e));return{enabled:ut(n.enabled)??ut(t.enabled)??!0,spansMaxBytes:J(n.spans)??J(t.spans)??52428800,logsMaxBytes:J(n.logs)??J(t.logs)??26214400}}function pt(e){return R(`sha256`).update(e).digest(`hex`)}function mt(e){let t=P(e),n=0;for(let e=0;e<t.length;e++)t[e]===10&&n++;return n}function ht(e){let t=P(e,`utf-8`),n=`"doc.name"`,r=0,i=t.indexOf(n);for(;i!==-1;)r++,i=t.indexOf(n,i+10);return r}function Y(e,t){return M(e)?(N(O(t),{recursive:!0}),ye(e,t),!0):!1}function gt(e){let t=[],n=e=>{let r=F(e,{withFileTypes:!0});for(let i of r){let r=A(e,i.name);i.isDirectory()?n(r):i.isFile()&&t.push(r)}};return n(e),t.sort()}const _t=new Set([`.jsonl`]);function vt(e){let t=e.lastIndexOf(`.`);return t===-1?!1:_t.has(e.slice(t))}const yt=new Set([`.jsonl`,`.json`,`.txt`,`.log`,`.lock`]);function bt(e){let t=e.lastIndexOf(`.`);return t===-1?!1:yt.has(e.slice(t))}function xt(e){let t=[];for(let n of gt(e)){let r=St(e,n);if(!bt(r))continue;let{redacted:i,patterns:a,lineCount:o}=V(P(n,`utf-8`));a.length!==0&&(L(n,i),t.push({file:r,lineCount:o,patterns:a}))}return{redactions:t,redactedLineCount:t.reduce((e,t)=>e+t.lineCount,0)}}function St(e,t){return se(e,t).split(ce).join(`/`)}async function Ct(e){let t=j(e.contentDir),n=j(e.projectDir??e.contentDir),r=e.deps??{},i=r.fetchAgentPresence??it,a=r.readShadowHead??at,o=r.now??(()=>new Date),s=r.okVersion??(()=>C),c=r.readDesktopEnv??ot,l=r.readRuntime??st,u=r.isOtlpPushEnabled??ct,d=Se(A(he(),`ok-bundle-`));try{N(A(d,`telemetry`),{recursive:!0}),N(A(d,`logs`),{recursive:!0}),N(A(d,`state`),{recursive:!0}),Y(et(n),A(d,`telemetry`,Xe)),Y(tt(n),A(d,`telemetry`,Ze)),Y(nt(n),A(d,`logs`,Qe)),Y(rt(n),A(d,`logs`,$e));let f=A(n,`.ok`,`local`),p=A(f,`server.lock`),m=`not-running`,h=`no server.lock`,g=null;if(M(p)){Y(p,A(d,`state`,`server.lock`));try{let e=P(p,`utf-8`),t=JSON.parse(e);typeof t.port==`number`?g=t.port:h=`lock present but no port`}catch{h=`lock present but unparseable`}}if(g!==null){let e=await i(g);e===null?h=`agent-presence endpoint at :${g} unreachable`:(L(A(d,`state`,`agent-presence.json`),e),m=`running`,h=``)}let _=a(t);_!==null&&L(A(d,`state`,`shadow-head.txt`),_),Y(A(f,`last-spawn-error.log`),A(d,`state`,`last-spawn-error.log`));let v=l(),y=c(),ee={ok:{version:s(),nodeVersion:v.nodeVersion,platform:v.platform,arch:v.arch},host:{desktop:y}};L(A(d,`state`,`runtime.json`),`${JSON.stringify(ee,null,2)}\n`);let te=m===`running`?`running
|
|
11
|
-
`:`not-running (${h})\n`;if(L(A(d,`state`,`server-status.txt`),te),e.processDir&&M(e.processDir)){let t=A(d,`process`);N(t,{recursive:!0}),ye(e.processDir,t,{recursive:!0})}let b=null;e.redact===!0&&(b=Ke({stagingDir:d,contentDir:t})),e.note&&L(A(d,`note.txt`),e.note);let x=null;e.scrubSecrets===!0&&(x=xt(d));for(let t of e.extraFiles??[])Y(t.sourcePath,A(d,`extra`,t.zipName??D(t.sourcePath)))||r.logger?.warn({sourcePath:t.sourcePath},`extra file missing; omitted from bundle`);let S=ft(n),C=gt(d),w=[],ne=0,re=0;for(let e of C){let t=St(d,e),n=we(e).size,r=vt(t)?mt(e):0;w.push({path:t,bytes:n,lines:r}),ne+=n,t.startsWith(`telemetry/`)&&vt(t)&&(re+=ht(e))}let ie=b===null?{applied:!1,docNameMapSidecar:null}:Object.keys(b.docNameCollisions).length>0?{applied:!0,docNameMapSidecar:null,docNameCollisions:b.docNameCollisions}:{applied:!0,docNameMapSidecar:null};x!==null&&(ie.secretScrub=x);let T={schemaVersion:1,createdAt:o().toISOString(),ok:{version:s(),nodeVersion:v.nodeVersion,platform:v.platform,arch:v.arch},host:{desktop:y},contentDir:{pathSha256:pt(t),absolutePath:b===null?t:`<CONTENT_DIR>`},telemetry:{localSink:S,otlpPushEnabled:u()},redaction:ie,serverStatus:m,files:w};L(A(d,`manifest.json`),`${JSON.stringify(T,null,2)}\n`);let ae=C.some(e=>{try{return P(e,`utf-8`).includes(t)}catch{return!1}}),oe={totalBytes:ne,fileCount:w.length,docNameCount:re,contentDirVisible:ae,redacted:b!==null},E=!1;return{stagingDir:d,manifest:T,summary:oe,redactionMapPayload:b===null?null:{docNameMap:b.docNameMap,docNameCollisions:b.docNameCollisions},cleanup:()=>{E||(E=!0,I(d,{recursive:!0,force:!0}))}}}catch(e){throw I(d,{recursive:!0,force:!0}),e}}async function wt(e){let{collected:t,outputPath:n}=e,r=O(n);if(!M(r))throw Error(`ok diagnose bundle: parent directory does not exist: ${r}. Create it or pass --out with an existing parent.`);if(t.redactionMapPayload!==null){let e=`${D(n,`.zip`)}.docnames.json`,r={...t.manifest,redaction:{...t.manifest.redaction,applied:!0,docNameMapSidecar:e}};L(A(t.stagingDir,`manifest.json`),`${JSON.stringify(r,null,2)}\n`)}let i=new qe.ZipFile,a=gt(t.stagingDir);for(let e of a){let n=St(t.stagingDir,e);i.addFile(e,n)}i.end(),t.redactionMapPayload!==null&&L(A(r,`${D(n,`.zip`)}.docnames.json`),`${JSON.stringify({docNameMap:t.redactionMapPayload.docNameMap,docNameCollisions:t.redactionMapPayload.docNameCollisions},null,2)}\n`,{mode:384});let o=be(n);return i.outputStream.pipe(o),await new Promise((e,t)=>{o.on(`close`,e),o.on(`error`,t),i.outputStream.on(`error`,t)}),n}function Tt(e,t){let n=A(e,`.ok`,`config.yml`);if(M(n))try{let t=(0,K.parse)(P(n,`utf-8`)),r=w(t)?t.content:void 0,i=w(r)?r.dir:void 0;if(typeof i==`string`&&i.length>0)return j(e,i)}catch(e){t?.warn({configPath:n,err:e instanceof Error?e.message:String(e)},`bug-report: failed to read .ok/config.yml; falling back to project root as content dir`)}return j(e)}async function Et(e,t,n){let r=await Ct({contentDir:Tt(t,e.logger),projectDir:t,redact:e.redact,scrubSecrets:e.redact,note:e.note,extraFiles:e.extraFiles,deps:{readDesktopEnv:n,logger:e.logger}});try{N(O(e.outputPath),{recursive:!0}),await wt({collected:r,outputPath:e.outputPath});let n=r.manifest.redaction.secretScrub;return{zipPath:e.outputPath,summary:{level:`full`,systemWide:!1,projectSlug:ke(t,e.logger),files:r.manifest.files.map(e=>e.path),redactions:n?.redactions??[],redactedLineCount:n?.redactedLineCount??0,generatedAt:r.manifest.createdAt}}}finally{r.cleanup()}}async function Dt(e){let{projectDir:t}=e,n=e.readDesktopEnv??ot;if(e.level===`full`&&t!==void 0)return Et(e,t,n);let{zipPath:r,summary:i}=await Fe({projectDir:t,redact:e.redact,outputPath:e.outputPath,userLogsDir:e.userLogsDir,logger:e.logger,note:e.note,extraFiles:e.extraFiles,desktop:n()});return{zipPath:r,summary:{level:e.level,systemWide:t===void 0,projectSlug:i.projectSlug,files:i.files,redactions:i.redactions,redactedLineCount:i.redactedLineCount,generatedAt:i.generatedAt}}}function X(e,t,o={}){let s=a(e,t);if(!M(s))return{status:`missing`,lockPath:s};let c;try{c=JSON.parse(P(s,`utf-8`))}catch{return{status:`corrupt`,lockPath:s}}if(!c||typeof c!=`object`||!r(c.pid))return{status:`corrupt`,lockPath:s};let l=c;if(!(o.isAlive??n)(l.pid))return{status:`dead-pid`,lockPath:s,lock:l};if(typeof l.machineId==`string`)return l.machineId===(o.machineId??i())?{status:`alive`,lockPath:s,lock:l}:{status:`foreign-host`,lockPath:s,lock:l};let u=o.host??fe();return l.hostname===u?{status:`alive`,lockPath:s,lock:l}:{status:`foreign-host`,lockPath:s,lock:l}}function Ot(e){return e.replace(/:\d+$/,``)}function kt(e){let t=e.trim();if(!t)return null;{let e=/^https?:\/\/([^/?#]+)\/([\w.\-~%]+)\/([\w.\-~%]+?)(?:\.git)?\/?$/.exec(t);if(e)return{protocol:`https`,hostname:Ot(e[1]),owner:e[2],name:e[3]}}{let e=/^ssh:\/\/(?:[\w.-]+@)?([^/?#]+)\/([\w.\-~%]+)\/([\w.\-~%]+?)(?:\.git)?\/?$/.exec(t);if(e)return{protocol:`ssh`,hostname:Ot(e[1]),owner:e[2],name:e[3]}}{let e=/^git:\/\/([^/?#]+)\/([\w.\-~%]+)\/([\w.\-~%]+?)(?:\.git)?\/?$/.exec(t);if(e)return{protocol:`git`,hostname:Ot(e[1]),owner:e[2],name:e[3]}}{let e=/^(?:[\w.-]+@)?([\w.-]+):([\w.\-~%]+)\/([\w.\-~%]+?)(?:\.git)?$/.exec(t);if(e?.[1].includes(`.`)||e&&t.startsWith(`git@`))return{protocol:`ssh`,hostname:e[1],owner:e[2],name:e[3]}}{let e=/^git:([\w.-]+)\/([\w.\-~%]+)\/([\w.\-~%]+?)(?:\.git)?\/?$/.exec(t);if(e)return{protocol:`git`,hostname:e[1],owner:e[2],name:e[3]}}if(!t.includes(`://`)&&!t.includes(`@`)&&!t.startsWith(`/`)){let e=/^([\w.-]+)\/([\w.\-~%]+?)(?:\.git)?$/.exec(t);if(e)return{protocol:`https`,hostname:`github.com`,owner:e[1],name:e[2]}}return null}function At(e){let t;try{t=new URL(e)}catch{return null}if(t.hostname!==`github.com`&&t.hostname!==`www.github.com`)return null;let n=t.pathname.split(`/`).filter(e=>e.length>0);if(n.length<5||n[2]!==`blob`)return null;let r,i,a,o;try{r=decodeURIComponent(n[0]),i=decodeURIComponent(n[1]),a=decodeURIComponent(n[3]),o=n.slice(4).map(e=>decodeURIComponent(e))}catch{return null}return!r||!i||!a||o.length===0||o.some(e=>e.length===0)?null:{owner:r,repo:i,branch:a,path:o.join(`/`)}}function jt(e){let t;try{t=new URL(e)}catch{return null}if(t.hostname!==`github.com`&&t.hostname!==`www.github.com`)return null;let n=t.pathname.split(`/`);if(n.length<5||n[0]!==``||n[3]!==`tree`)return null;let r=n.slice(5);r.length===1&&r[0]===``&&r.pop();let i,a,o,s;try{i=decodeURIComponent(n[1]),a=decodeURIComponent(n[2]),o=decodeURIComponent(n[4]),s=r.map(e=>decodeURIComponent(e))}catch{return null}return!i||!a||!o||s.some(e=>e.length===0)?null:{owner:i,repo:a,branch:o,path:s.join(`/`)}}function Mt(e){let t=At(e);if(t)return{kind:`doc`,...t};let n=jt(e);return n?{kind:`folder`,...n}:null}const Nt=`# >>> open-knowledge cli >>>`,Pt=`# <<< open-knowledge cli <<<`,Ft=/^# >>> open-knowledge cli >>>\n[\s\S]*?^# <<< open-knowledge cli <<<\n?/m;function It(e){return A(e,`Library`,`Application Support`,`OpenKnowledge`,`path-install.json`)}const Lt={existsSync:e=>M(e),readFileSync:(e,t)=>P(e,t),lstatSync:e=>xe(e),readlinkSync:e=>Ce(e)};function Rt(e,t=Lt){let n=It(e);if(!t.existsSync(n))return null;try{let e=JSON.parse(t.readFileSync(n,`utf8`));return e?.version===1?e:null}catch{return null}}function zt(e){let t=e.replace(Ft,``);return{text:t,changed:t!==e,emptyAfter:t.trim()===``}}function Bt(e,t,n=Lt){try{return n.lstatSync(e).isSymbolicLink()?n.readlinkSync(e)===t:!1}catch{return!1}}function Vt(e){return
|
|
11
|
+
`:`not-running (${h})\n`;if(L(A(d,`state`,`server-status.txt`),te),e.processDir&&M(e.processDir)){let t=A(d,`process`);N(t,{recursive:!0}),ye(e.processDir,t,{recursive:!0})}let b=null;e.redact===!0&&(b=Ke({stagingDir:d,contentDir:t})),e.note&&L(A(d,`note.txt`),e.note);let x=null;e.scrubSecrets===!0&&(x=xt(d));for(let t of e.extraFiles??[])Y(t.sourcePath,A(d,`extra`,t.zipName??D(t.sourcePath)))||r.logger?.warn({sourcePath:t.sourcePath},`extra file missing; omitted from bundle`);let S=ft(n),C=gt(d),w=[],ne=0,re=0;for(let e of C){let t=St(d,e),n=we(e).size,r=vt(t)?mt(e):0;w.push({path:t,bytes:n,lines:r}),ne+=n,t.startsWith(`telemetry/`)&&vt(t)&&(re+=ht(e))}let ie=b===null?{applied:!1,docNameMapSidecar:null}:Object.keys(b.docNameCollisions).length>0?{applied:!0,docNameMapSidecar:null,docNameCollisions:b.docNameCollisions}:{applied:!0,docNameMapSidecar:null};x!==null&&(ie.secretScrub=x);let T={schemaVersion:1,createdAt:o().toISOString(),ok:{version:s(),nodeVersion:v.nodeVersion,platform:v.platform,arch:v.arch},host:{desktop:y},contentDir:{pathSha256:pt(t),absolutePath:b===null?t:`<CONTENT_DIR>`},telemetry:{localSink:S,otlpPushEnabled:u()},redaction:ie,serverStatus:m,files:w};L(A(d,`manifest.json`),`${JSON.stringify(T,null,2)}\n`);let ae=C.some(e=>{try{return P(e,`utf-8`).includes(t)}catch{return!1}}),oe={totalBytes:ne,fileCount:w.length,docNameCount:re,contentDirVisible:ae,redacted:b!==null},E=!1;return{stagingDir:d,manifest:T,summary:oe,redactionMapPayload:b===null?null:{docNameMap:b.docNameMap,docNameCollisions:b.docNameCollisions},cleanup:()=>{E||(E=!0,I(d,{recursive:!0,force:!0}))}}}catch(e){throw I(d,{recursive:!0,force:!0}),e}}async function wt(e){let{collected:t,outputPath:n}=e,r=O(n);if(!M(r))throw Error(`ok diagnose bundle: parent directory does not exist: ${r}. Create it or pass --out with an existing parent.`);if(t.redactionMapPayload!==null){let e=`${D(n,`.zip`)}.docnames.json`,r={...t.manifest,redaction:{...t.manifest.redaction,applied:!0,docNameMapSidecar:e}};L(A(t.stagingDir,`manifest.json`),`${JSON.stringify(r,null,2)}\n`)}let i=new qe.ZipFile,a=gt(t.stagingDir);for(let e of a){let n=St(t.stagingDir,e);i.addFile(e,n)}i.end(),t.redactionMapPayload!==null&&L(A(r,`${D(n,`.zip`)}.docnames.json`),`${JSON.stringify({docNameMap:t.redactionMapPayload.docNameMap,docNameCollisions:t.redactionMapPayload.docNameCollisions},null,2)}\n`,{mode:384});let o=be(n);return i.outputStream.pipe(o),await new Promise((e,t)=>{o.on(`close`,e),o.on(`error`,t),i.outputStream.on(`error`,t)}),n}function Tt(e,t){let n=A(e,`.ok`,`config.yml`);if(M(n))try{let t=(0,K.parse)(P(n,`utf-8`)),r=w(t)?t.content:void 0,i=w(r)?r.dir:void 0;if(typeof i==`string`&&i.length>0)return j(e,i)}catch(e){t?.warn({configPath:n,err:e instanceof Error?e.message:String(e)},`bug-report: failed to read .ok/config.yml; falling back to project root as content dir`)}return j(e)}async function Et(e,t,n){let r=await Ct({contentDir:Tt(t,e.logger),projectDir:t,redact:e.redact,scrubSecrets:e.redact,note:e.note,extraFiles:e.extraFiles,deps:{readDesktopEnv:n,logger:e.logger}});try{N(O(e.outputPath),{recursive:!0}),await wt({collected:r,outputPath:e.outputPath});let n=r.manifest.redaction.secretScrub;return{zipPath:e.outputPath,summary:{level:`full`,systemWide:!1,projectSlug:ke(t,e.logger),files:r.manifest.files.map(e=>e.path),redactions:n?.redactions??[],redactedLineCount:n?.redactedLineCount??0,generatedAt:r.manifest.createdAt}}}finally{r.cleanup()}}async function Dt(e){let{projectDir:t}=e,n=e.readDesktopEnv??ot;if(e.level===`full`&&t!==void 0)return Et(e,t,n);let{zipPath:r,summary:i}=await Fe({projectDir:t,redact:e.redact,outputPath:e.outputPath,userLogsDir:e.userLogsDir,logger:e.logger,note:e.note,extraFiles:e.extraFiles,desktop:n()});return{zipPath:r,summary:{level:e.level,systemWide:t===void 0,projectSlug:i.projectSlug,files:i.files,redactions:i.redactions,redactedLineCount:i.redactedLineCount,generatedAt:i.generatedAt}}}function X(e,t,o={}){let s=a(e,t);if(!M(s))return{status:`missing`,lockPath:s};let c;try{c=JSON.parse(P(s,`utf-8`))}catch{return{status:`corrupt`,lockPath:s}}if(!c||typeof c!=`object`||!r(c.pid))return{status:`corrupt`,lockPath:s};let l=c;if(!(o.isAlive??n)(l.pid))return{status:`dead-pid`,lockPath:s,lock:l};if(typeof l.machineId==`string`)return l.machineId===(o.machineId??i())?{status:`alive`,lockPath:s,lock:l}:{status:`foreign-host`,lockPath:s,lock:l};let u=o.host??fe();return l.hostname===u?{status:`alive`,lockPath:s,lock:l}:{status:`foreign-host`,lockPath:s,lock:l}}function Ot(e){return e.replace(/:\d+$/,``)}function kt(e){let t=e.trim();if(!t)return null;{let e=/^https?:\/\/([^/?#]+)\/([\w.\-~%]+)\/([\w.\-~%]+?)(?:\.git)?\/?$/.exec(t);if(e)return{protocol:`https`,hostname:Ot(e[1]),owner:e[2],name:e[3]}}{let e=/^ssh:\/\/(?:[\w.-]+@)?([^/?#]+)\/([\w.\-~%]+)\/([\w.\-~%]+?)(?:\.git)?\/?$/.exec(t);if(e)return{protocol:`ssh`,hostname:Ot(e[1]),owner:e[2],name:e[3]}}{let e=/^git:\/\/([^/?#]+)\/([\w.\-~%]+)\/([\w.\-~%]+?)(?:\.git)?\/?$/.exec(t);if(e)return{protocol:`git`,hostname:Ot(e[1]),owner:e[2],name:e[3]}}{let e=/^(?:[\w.-]+@)?([\w.-]+):([\w.\-~%]+)\/([\w.\-~%]+?)(?:\.git)?$/.exec(t);if(e?.[1].includes(`.`)||e&&t.startsWith(`git@`))return{protocol:`ssh`,hostname:e[1],owner:e[2],name:e[3]}}{let e=/^git:([\w.-]+)\/([\w.\-~%]+)\/([\w.\-~%]+?)(?:\.git)?\/?$/.exec(t);if(e)return{protocol:`git`,hostname:e[1],owner:e[2],name:e[3]}}if(!t.includes(`://`)&&!t.includes(`@`)&&!t.startsWith(`/`)){let e=/^([\w.-]+)\/([\w.\-~%]+?)(?:\.git)?$/.exec(t);if(e)return{protocol:`https`,hostname:`github.com`,owner:e[1],name:e[2]}}return null}function At(e){let t;try{t=new URL(e)}catch{return null}if(t.hostname!==`github.com`&&t.hostname!==`www.github.com`)return null;let n=t.pathname.split(`/`).filter(e=>e.length>0);if(n.length<5||n[2]!==`blob`)return null;let r,i,a,o;try{r=decodeURIComponent(n[0]),i=decodeURIComponent(n[1]),a=decodeURIComponent(n[3]),o=n.slice(4).map(e=>decodeURIComponent(e))}catch{return null}return!r||!i||!a||o.length===0||o.some(e=>e.length===0)?null:{owner:r,repo:i,branch:a,path:o.join(`/`)}}function jt(e){let t;try{t=new URL(e)}catch{return null}if(t.hostname!==`github.com`&&t.hostname!==`www.github.com`)return null;let n=t.pathname.split(`/`);if(n.length<5||n[0]!==``||n[3]!==`tree`)return null;let r=n.slice(5);r.length===1&&r[0]===``&&r.pop();let i,a,o,s;try{i=decodeURIComponent(n[1]),a=decodeURIComponent(n[2]),o=decodeURIComponent(n[4]),s=r.map(e=>decodeURIComponent(e))}catch{return null}return!i||!a||!o||s.some(e=>e.length===0)?null:{owner:i,repo:a,branch:o,path:s.join(`/`)}}function Mt(e){let t=At(e);if(t)return{kind:`doc`,...t};let n=jt(e);return n?{kind:`folder`,...n}:null}const Nt=`# >>> open-knowledge cli >>>`,Pt=`# <<< open-knowledge cli <<<`,Ft=/^# >>> open-knowledge cli >>>\n[\s\S]*?^# <<< open-knowledge cli <<<\n?/m;function It(e){return A(e,`Library`,`Application Support`,`OpenKnowledge`,`path-install.json`)}const Lt={existsSync:e=>M(e),readFileSync:(e,t)=>P(e,t),lstatSync:e=>xe(e),readlinkSync:e=>Ce(e)};function Rt(e,t=Lt){let n=It(e);if(!t.existsSync(n))return null;try{let e=JSON.parse(t.readFileSync(n,`utf8`));return e?.version===1?e:null}catch{return null}}function zt(e){let t=e.replace(Ft,``);return{text:t,changed:t!==e,emptyAfter:t.trim()===``}}function Bt(e,t,n=Lt){try{return n.lstatSync(e).isSymbolicLink()?n.readlinkSync(e)===t:!1}catch{return!1}}function Vt(e){return T(e)||ne(e)||v(e)}const Ht=10*1024*1024;function Ut(e,t,n,r){let i=b(e,t,n,r);if(i.kind===`absent`||i.kind===`no-entry`)return{kind:`not-present`};if(i.kind===`decline`)return{kind:`declined`,reason:i.reason};if(!Vt(i.entry))return{kind:`left-foreign`};let a;try{a=r??e.configPath(t,n)}catch{return{kind:`not-present`}}let o=e.serverName(t);return e.format===`file`?(I(a,{force:!0}),{kind:`removed`}):e.format===`toml`?Kt(a,o):e.format===`yaml`?Gt(a,e.topLevelKey,o):Wt(a,e.topLevelKey,e.serverMapSubKey,o)}function Wt(e,t,n,r){let i;try{i=P(e,`utf-8`)}catch{return{kind:`declined`,reason:`unparseable`}}if(Buffer.byteLength(i,`utf-8`)>Ht)return{kind:`declined`,reason:`oversize`};let{text:a,changed:o}=_(i,ee(t,n,r));return o?(d(e,a,{mode:S(e)}),{kind:`removed`}):{kind:`not-present`}}function Gt(e,t,n){let r;try{r=P(e,`utf-8`)}catch{return{kind:`declined`,reason:`unparseable`}}if(Buffer.byteLength(r,`utf-8`)>Ht)return{kind:`declined`,reason:`oversize`};let i=r.charCodeAt(0)===65279,a=i?r.slice(1):r,o=(0,K.parseDocument)(a);if(o.errors.length>0)return{kind:`declined`,reason:`unparseable`};let s=[t,n];if(!o.hasIn(s))return{kind:`not-present`};o.deleteIn(s);let c=o.toString(),l=y(a);a.trim()===``||a.endsWith(`
|
|
12
12
|
`)?c.endsWith(`
|
|
13
13
|
`)||(c=`${c}\n`):c=c.replace(/\n+$/,``),l&&(c=c.replace(/\r\n/g,`
|
|
14
14
|
`).replace(/\n/g,`\r
|
|
@@ -17,5 +17,5 @@ import{s as e}from"./chunk-C94x7I9S.mjs";import{Qo as t,c as n,l as r,s as i,u a
|
|
|
17
17
|
`)||(l=`${l}\n`):l=l.replace(/\n+$/,``),o&&(l=l.replace(/\r\n/g,`
|
|
18
18
|
`).replace(/\n/g,`\r
|
|
19
19
|
`));let u=`${i?``:``}${l}`;return u!==r&&d(e,u,{mode:S(e)}),{kind:`removed`}}const qt=new Set([`start`,`stop`,`status`,`clean`,`ui`,`mcp`,`preview`,`deinit`,`auth`]);function Jt(e,t,n=c){if(e!==void 0&&!qt.has(e))return null;let r=n(t);return r===null||r.distance===0?null:r.rootPath}let Yt=null;function Xt(e){Yt=e}function Zt(){return Yt??process.cwd()}var Z=e(ae(),1);function Qt(e){return e==null?!1:e.includes(`--type=utility`)&&e.includes(`--utility-sub-type=node.mojom.NodeService`)}function $t(e,t=Date.now()){let n=new Date(e).getTime();if(Number.isNaN(n))return`—`;let r=t-n,i=Math.floor(r/1e3);if(i<60)return`${i}s`;let a=Math.floor(i/60);if(a<60)return`${a}m ago`;let o=Math.floor(a/60);return o<24?`${o}h ago`:`${Math.floor(o/24)}d ago`}function en(e,t,n,r,i,a){if(t.status===`missing`||t.status===`corrupt`)return null;let o=t.lock,s=null;if(n.status!==`missing`&&n.status!==`corrupt`){let e=n.lock;s={port:e.port,status:n.status,pid:e.pid,startedAt:e.startedAt,usage:a}}return{directory:o.worktreeRoot,server:{port:o.port,status:t.status,pid:o.pid,startedAt:o.startedAt,usage:i},ui:s,hostname:o.hostname,lockPath:t.lockPath,binary:r==null?null:m(r),command:r,isDesktop:Qt(r)}}function tn(e){return e.ui==null?!1:e.ui.status===`alive`||e.ui.status===`foreign-host`}function Q(e){let t=e.server.status;return t===`alive`||t===`foreign-host`?e.isDesktop?`desktop`:t===`alive`?`running`:`foreign`:t===`dead-pid`&&tn(e)?`ui-orphan`:`stale`}const nn=new Set([`running`,`desktop`,`foreign`,`ui-orphan`]);function rn(e){switch(e){case`running`:return Z.default.green(e);case`desktop`:return Z.default.blue(e);case`foreign`:return Z.default.cyan(e);case`ui-orphan`:return Z.default.magenta(e);case`stale`:return Z.default.yellow(e)}}function an(e){return e==null?`—`:`${e.cpuPercent.toFixed(1)}% / ${e.memPercent.toFixed(1)}%`}function on(e){return`${an(e.server.usage)} | ${an(e.ui?.usage??null)}`}function sn(e){return`${e.server.port===0?`(starting)`:String(e.server.port)} / ${e.ui==null||e.ui.status===`dead-pid`?`—`:String(e.ui.port)}`}function cn(e){if(e.length===0)return`No open-knowledge servers found.`;let t=[`DIRECTORY`,`PORTS (API/UI)`,`CPU/MEM (API | UI)`,`STATUS`,`PID`,`STARTED`,`BINARY`],n=e.map(e=>{let t=Q(e),n=t===`ui-orphan`&&e.ui!=null?e.ui.pid:e.server.pid;return[e.directory,sn(e),on(e),t,String(n),$t(e.server.startedAt),e.binary??`—`]}),r=t.length,i=t.map(e=>e.length);for(let e of n)for(let t=0;t<r;t++)i[t]=Math.max(i[t]??0,(e[t]??``).length);let a=t.map((e,t)=>e.padEnd(i[t]??0)).join(` `).trimEnd(),o=e.map((e,t)=>{let a=n[t]??[],o=[];for(let t=0;t<r;t++){let n=(a[t]??``).padEnd(i[t]??0);if(t===3){let r=a[t]??``;n=rn(Q(e))+` `.repeat(Math.max(0,(i[t]??0)-r.length))}o.push(n)}return o.join(` `).trimEnd()}),s=Z.default.dim(`To stop a server: ok stop <port|pid|directory|all>`);return[a,...o,``,s].join(`
|
|
20
|
-
`)}async function ln(e={}){let t=e.discover??p,n=e.inspect??X,r=e.log??(e=>console.log(e)),i=e.resolveCommand??o,a=e.resolveUsage??u,s=await t(),c=[];for(let e of s){let t=n(e,`server`),r=n(e,`ui`),o=en(e,t,r,t.status===`missing`||t.status===`corrupt`?null:i(t.lock.pid),t.status===`missing`||t.status===`corrupt`?null:a(t.lock.pid),r.status===`missing`||r.status===`corrupt`?null:a(r.lock.pid));o!=null&&c.push(o)}if(e.json){let e=c.map(e=>({...e,displayStatus:Q(e)}));r(JSON.stringify(e,null,2));return}r(cn(e.all?c:c.filter(e=>nn.has(Q(e)))))}function un(){return new g(`ps`).description(`List all running open-knowledge servers`).argument(`[modifier]`,`"all" to include stale (dead-pid) entries`).option(`--all`,`Include stale (dead-pid) entries (foreign-host shows by default)`).option(`--json`,`Emit structured JSON (always includes all statuses)`).action(async(e,t)=>{await ln({all:t.all===!0||e===`all`,json:t.json===!0})})}function dn(e,t,r={}){let i=r.isAlive??n,a=[];for(let[n,r]of[[`server`,e],[`ui`,t]])(r.status===`alive`||r.status===`foreign-host`&&i(r.lock.pid))&&a.push({name:n,pid:r.lock.pid,port:r.lock.port});return{targets:a}}function fn(e){let t=e.inspect??(t=>X(e.lockDir,t)),n=e.kill??((e,t)=>process.kill(e,t)),r=e.log??(e=>console.log(e)),i=e.error??(e=>console.error(e)),a=dn(t(`server`),t(`ui`),{isAlive:e.isAlive});if(a.targets.length===0)return r(`No running open-knowledge processes.`),{stopped:[],failed:[],hadTargets:!1};let o=[],s=[];for(let e of a.targets)try{n(e.pid,`SIGTERM`),o.push(e)}catch(t){s.push({target:e,error:t instanceof Error?t.message:String(t)})}return o.length>0&&r(`Stopped: ${o.map(e=>`${e.name} (pid=${e.pid}, port=${e.port})`).join(`, `)}`),s.length>0&&i(`Failed to stop: ${s.map(({target:e,error:t})=>`${e.name} (pid=${e.pid}): ${t}`).join(`; `)}`),{stopped:o,failed:s,hadTargets:!0}}function $(e,t){return e.status===`alive`?!0:e.status===`foreign-host`?t(e.lock.pid):!1}async function pn(e,t=n){let r=await p(),i=null;for(let n of r){let r=X(n,`server`),a=X(n,`ui`);if($(r,t)&&r.lock.port===e||$(a,t)&&a.lock.port===e)return n;i===null&&($(r,t)&&r.lock.pid===e||$(a,t)&&a.lock.pid===e)&&(i=n)}return i}function mn(e){let t=fn({lockDir:e});return t.failed.length>0&&(process.exitCode=1),t}function hn(e){return new g(`stop`).description(`Stop open-knowledge server(s). With no argument: stops the server for the current directory. Pass a port number, a directory path, or "all" to target globally.`).argument(`[target...]`,`port number, directory path (spaces OK), or "all"`).action(async t=>{let r=t.length===0?void 0:t.join(` `);if(r===void 0){e();let t=fn({lockDir:f(process.cwd()),log:()=>{}});if(t.hadTargets){if(t.stopped.length>0){let e=t.stopped.map(e=>`${e.name} (pid=${e.pid}, port=${e.port})`).join(`, `);console.log(`Stopped: ${e}`)}t.failed.length>0&&(process.exitCode=1)}else await ln({});return}if(r===`all`){let e=await p();if(e.length===0){console.log(`No running open-knowledge servers found.`);return}let t=0;for(let r of e){let e=X(r,`server`),i=X(r,`ui`);!$(e,n)&&!$(i,n)||(mn(r),t++)}t===0&&console.log(`No running open-knowledge servers found.`);return}if(/^\d+$/.test(r)){let e=Number.parseInt(r,10),t=await pn(e);if(t===null){console.log(`No running open-knowledge server found with port or PID ${e}.`);return}mn(t);return}mn(f(j(Zt(),r)))})}function gn(e){return{event:`mcp-config-decline`,scope:e.scope,surface:e.surface,editorId:e.editorId,reason:e.reason}}async function _n(e,t){let n,r;try{n=await B(j(e)),r=await B(j(O(e)))}catch{return{kind:`not-git`}}if(!yn(n,r))return{kind:`symlink-escape`};let i=A(n,`.git`),a;try{a=we(i)}catch{return{kind:`not-git`}}let o;if(a.isDirectory()){let e;try{e=await B(i)}catch{return{kind:`not-git`}}if(!yn(e,n))return{kind:`symlink-escape`};o=e}else if(a.isFile()){let e;try{e=await z(i,`utf-8`)}catch{return{kind:`not-git`}}let t=/^gitdir:\s*(.+)$/m.exec(e.trim());if(!t)return{kind:`not-git`};let r=t[1].trim(),a=k(r)?r:j(n,r);try{o=await B(a)}catch{return{kind:`not-git`}}}else return{kind:`not-git`};let s=A(await vn(o),`config`),c;try{c=await z(s,`utf-8`)}catch{return{kind:`not-git`}}let l=xn(c);if(l===null)return{kind:`no-origin`};let u=kt(l);if(u===null||u.hostname!==`github.com`)return{kind:`non-github`};let d=u.owner.toLowerCase()===t.owner.toLowerCase(),f=u.name.toLowerCase()===t.repo.toLowerCase();return!d||!f?{kind:`wrong-repo`,actualOwner:u.owner,actualRepo:u.name}:{kind:`ok`,gitRemoteUrl:`https://github.com/${u.owner}/${u.name}.git`}}async function vn(e){let t;try{t=(await z(A(e,`commondir`),`utf-8`)).trim()}catch{return e}if(t.length===0)return e;let n=k(t)?t:j(e,t);try{return await B(n)}catch{return n}}function yn(e,t){if(e===t)return!0;let n=se(t,e);return n.length>0&&!n.startsWith(`..`)&&!k(n)}function bn(e){let t=e.indexOf(`#`),n=e.indexOf(`;`),r=-1;return t>=0&&n>=0?r=Math.min(t,n):t>=0?r=t:n>=0&&(r=n),(r===-1?e:e.slice(0,r)).trim()}function xn(e){let t=!1;for(let n of e.split(/\r?\n/)){let e=bn(n);if(e.length===0)continue;if(e.startsWith(`[`)){t=/^\[\s*remote\s+["']origin["']\s*\]$/.test(e);continue}if(!t)continue;let r=/^url\s*=\s*(.+)$/.exec(e);if(r)return Sn(r[1])}return null}function Sn(e){let t=e.trim();return t.startsWith(`"`)&&t.endsWith(`"`)||t.startsWith(`'`)&&t.endsWith(`'`)?t.slice(1,-1):t}const Cn=[{id:`mcp-config`,write(e,t,n){let r=e.projectConfigPath?.(t);if(!r)return{integration:`mcp-config`,editorId:e.id,action:`skipped-unsupported`};try{let i=x(e,t,n,void 0,r);return i.action===`written`||i.action===`overwritten`?{integration:`mcp-config`,editorId:e.id,action:i.action,path:i.configPath}:i.action===`failed`?{integration:`mcp-config`,editorId:e.id,action:`failed`,path:i.configPath,error:i.error??`unknown failure`}:i.action===`declined`?{integration:`mcp-config`,editorId:e.id,action:`declined`,path:i.configPath,...i.declineReason===void 0?{}:{reason:i.declineReason}}:{integration:`mcp-config`,editorId:e.id,action:`failed`,path:i.configPath,error:`unexpected project-scope action: ${i.action}`}}catch(t){return{integration:`mcp-config`,editorId:e.id,action:`failed`,path:r,error:t instanceof Error?t.message:String(t)}}}},{id:`project-skill`,write(e,t,n){try{let
|
|
21
|
-
//# sourceMappingURL=src-
|
|
20
|
+
`)}async function ln(e={}){let t=e.discover??p,n=e.inspect??X,r=e.log??(e=>console.log(e)),i=e.resolveCommand??o,a=e.resolveUsage??u,s=await t(),c=[];for(let e of s){let t=n(e,`server`),r=n(e,`ui`),o=en(e,t,r,t.status===`missing`||t.status===`corrupt`?null:i(t.lock.pid),t.status===`missing`||t.status===`corrupt`?null:a(t.lock.pid),r.status===`missing`||r.status===`corrupt`?null:a(r.lock.pid));o!=null&&c.push(o)}if(e.json){let e=c.map(e=>({...e,displayStatus:Q(e)}));r(JSON.stringify(e,null,2));return}r(cn(e.all?c:c.filter(e=>nn.has(Q(e)))))}function un(){return new g(`ps`).description(`List all running open-knowledge servers`).argument(`[modifier]`,`"all" to include stale (dead-pid) entries`).option(`--all`,`Include stale (dead-pid) entries (foreign-host shows by default)`).option(`--json`,`Emit structured JSON (always includes all statuses)`).action(async(e,t)=>{await ln({all:t.all===!0||e===`all`,json:t.json===!0})})}function dn(e,t,r={}){let i=r.isAlive??n,a=[];for(let[n,r]of[[`server`,e],[`ui`,t]])(r.status===`alive`||r.status===`foreign-host`&&i(r.lock.pid))&&a.push({name:n,pid:r.lock.pid,port:r.lock.port});return{targets:a}}function fn(e){let t=e.inspect??(t=>X(e.lockDir,t)),n=e.kill??((e,t)=>process.kill(e,t)),r=e.log??(e=>console.log(e)),i=e.error??(e=>console.error(e)),a=dn(t(`server`),t(`ui`),{isAlive:e.isAlive});if(a.targets.length===0)return r(`No running open-knowledge processes.`),{stopped:[],failed:[],hadTargets:!1};let o=[],s=[];for(let e of a.targets)try{n(e.pid,`SIGTERM`),o.push(e)}catch(t){s.push({target:e,error:t instanceof Error?t.message:String(t)})}return o.length>0&&r(`Stopped: ${o.map(e=>`${e.name} (pid=${e.pid}, port=${e.port})`).join(`, `)}`),s.length>0&&i(`Failed to stop: ${s.map(({target:e,error:t})=>`${e.name} (pid=${e.pid}): ${t}`).join(`; `)}`),{stopped:o,failed:s,hadTargets:!0}}function $(e,t){return e.status===`alive`?!0:e.status===`foreign-host`?t(e.lock.pid):!1}async function pn(e,t=n){let r=await p(),i=null;for(let n of r){let r=X(n,`server`),a=X(n,`ui`);if($(r,t)&&r.lock.port===e||$(a,t)&&a.lock.port===e)return n;i===null&&($(r,t)&&r.lock.pid===e||$(a,t)&&a.lock.pid===e)&&(i=n)}return i}function mn(e){let t=fn({lockDir:e});return t.failed.length>0&&(process.exitCode=1),t}function hn(e){return new g(`stop`).description(`Stop open-knowledge server(s). With no argument: stops the server for the current directory. Pass a port number, a directory path, or "all" to target globally.`).argument(`[target...]`,`port number, directory path (spaces OK), or "all"`).action(async t=>{let r=t.length===0?void 0:t.join(` `);if(r===void 0){e();let t=fn({lockDir:f(process.cwd()),log:()=>{}});if(t.hadTargets){if(t.stopped.length>0){let e=t.stopped.map(e=>`${e.name} (pid=${e.pid}, port=${e.port})`).join(`, `);console.log(`Stopped: ${e}`)}t.failed.length>0&&(process.exitCode=1)}else await ln({});return}if(r===`all`){let e=await p();if(e.length===0){console.log(`No running open-knowledge servers found.`);return}let t=0;for(let r of e){let e=X(r,`server`),i=X(r,`ui`);!$(e,n)&&!$(i,n)||(mn(r),t++)}t===0&&console.log(`No running open-knowledge servers found.`);return}if(/^\d+$/.test(r)){let e=Number.parseInt(r,10),t=await pn(e);if(t===null){console.log(`No running open-knowledge server found with port or PID ${e}.`);return}mn(t);return}mn(f(j(Zt(),r)))})}function gn(e){return{event:`mcp-config-decline`,scope:e.scope,surface:e.surface,editorId:e.editorId,reason:e.reason}}async function _n(e,t){let n,r;try{n=await B(j(e)),r=await B(j(O(e)))}catch{return{kind:`not-git`}}if(!yn(n,r))return{kind:`symlink-escape`};let i=A(n,`.git`),a;try{a=we(i)}catch{return{kind:`not-git`}}let o;if(a.isDirectory()){let e;try{e=await B(i)}catch{return{kind:`not-git`}}if(!yn(e,n))return{kind:`symlink-escape`};o=e}else if(a.isFile()){let e;try{e=await z(i,`utf-8`)}catch{return{kind:`not-git`}}let t=/^gitdir:\s*(.+)$/m.exec(e.trim());if(!t)return{kind:`not-git`};let r=t[1].trim(),a=k(r)?r:j(n,r);try{o=await B(a)}catch{return{kind:`not-git`}}}else return{kind:`not-git`};let s=A(await vn(o),`config`),c;try{c=await z(s,`utf-8`)}catch{return{kind:`not-git`}}let l=xn(c);if(l===null)return{kind:`no-origin`};let u=kt(l);if(u===null||u.hostname!==`github.com`)return{kind:`non-github`};let d=u.owner.toLowerCase()===t.owner.toLowerCase(),f=u.name.toLowerCase()===t.repo.toLowerCase();return!d||!f?{kind:`wrong-repo`,actualOwner:u.owner,actualRepo:u.name}:{kind:`ok`,gitRemoteUrl:`https://github.com/${u.owner}/${u.name}.git`}}async function vn(e){let t;try{t=(await z(A(e,`commondir`),`utf-8`)).trim()}catch{return e}if(t.length===0)return e;let n=k(t)?t:j(e,t);try{return await B(n)}catch{return n}}function yn(e,t){if(e===t)return!0;let n=se(t,e);return n.length>0&&!n.startsWith(`..`)&&!k(n)}function bn(e){let t=e.indexOf(`#`),n=e.indexOf(`;`),r=-1;return t>=0&&n>=0?r=Math.min(t,n):t>=0?r=t:n>=0&&(r=n),(r===-1?e:e.slice(0,r)).trim()}function xn(e){let t=!1;for(let n of e.split(/\r?\n/)){let e=bn(n);if(e.length===0)continue;if(e.startsWith(`[`)){t=/^\[\s*remote\s+["']origin["']\s*\]$/.test(e);continue}if(!t)continue;let r=/^url\s*=\s*(.+)$/.exec(e);if(r)return Sn(r[1])}return null}function Sn(e){let t=e.trim();return t.startsWith(`"`)&&t.endsWith(`"`)||t.startsWith(`'`)&&t.endsWith(`'`)?t.slice(1,-1):t}const Cn=[{id:`mcp-config`,write(e,t,n){let r=e.projectConfigPath?.(t);if(!r)return{integration:`mcp-config`,editorId:e.id,action:`skipped-unsupported`};try{let i=x(e,t,n,void 0,r);return i.action===`written`||i.action===`overwritten`?{integration:`mcp-config`,editorId:e.id,action:i.action,path:i.configPath}:i.action===`failed`?{integration:`mcp-config`,editorId:e.id,action:`failed`,path:i.configPath,error:i.error??`unknown failure`}:i.action===`declined`?{integration:`mcp-config`,editorId:e.id,action:`declined`,path:i.configPath,...i.declineReason===void 0?{}:{reason:i.declineReason}}:{integration:`mcp-config`,editorId:e.id,action:`failed`,path:i.configPath,error:`unexpected project-scope action: ${i.action}`}}catch(t){return{integration:`mcp-config`,editorId:e.id,action:`failed`,path:r,error:t instanceof Error?t.message:String(t)}}}},{id:`project-skill`,write(e,t,n){try{let r=ie(e,t,{home:n.home});return{integration:`project-skill`,editorId:e.id,action:r.action,...r.path?{path:r.path}:{},...r.error?{error:r.error}:{}}}catch(t){return{integration:`project-skill`,editorId:e.id,action:`failed`,error:t instanceof Error?t.message:String(t)}}}}];function wn(e,t,n={},r=Cn){let i=[];for(let a of t){let t=re[a];for(let a of r)i.push(a.write(t,e,n))}return i}function Tn(e,t,n={}){return{integrations:wn(e,t,n)}}export{Ct as C,V as E,Dt as S,Oe as T,At as _,hn as a,kt as b,Jt as c,Ft as d,Pt as f,zt as g,Rt as h,fn as i,Ut as l,It as m,_n as n,un as o,Bt as p,gn as r,Xt as s,Tn as t,Nt as u,Mt as v,wt as w,X as x,jt as y};
|
|
21
|
+
//# sourceMappingURL=src-CZcBOOJs.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{_ as e,f as t,r as n}from"./start-Ig8o-wfe.mjs";export{n as bootStartServer,t as resolveHost,e as startCommand};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{In as e,ht as t}from"./server-lock-iLcBw_q0-nWzkxbfg.mjs";import{ar as n,kr as r,vr as i}from"./dist-Pe1Q8dMj.mjs";import{n as a,t as o}from"./esm-CsQUg9js.mjs";import{i as s,t as c}from"./gh-detect-C6QZctcU.mjs";import{n as l}from"./constants-Ba7kuv_h.mjs";import{spawn as u}from"node:child_process";import{basename as d,dirname as f,join as p}from"node:path";import{homedir as m}from"node:os";import{closeSync as h,existsSync as g,mkdirSync as _,openSync as v,statSync as y}from"node:fs";import{rm as b}from"node:fs/promises";import{setTimeout as x}from"node:timers/promises";const S=`OpenKnowledge.app`,C=`/Applications/${S}`;function w(){return{platform:process.platform,env:process.env,execPath:process.execPath,isTTY:process.stdout.isTTY,statSync:e=>{try{return y(e,{throwIfNoEntry:!1})??null}catch{return null}}}}function T(e){if(e.env.ELECTRON_RUN_AS_NODE===`1`){let t=/(.+?\.app)\/Contents\/MacOS\//.exec(e.execPath);if(t?.[1])return t[1]}if(E(e,C))return C;let t=p(e.homeDir??m(),`Applications`,S);return E(e,t)?t:null}function E(e,t){try{let n=p(t,`Contents`,`MacOS`,`OpenKnowledge`),r=e.statSync(n);return r&&typeof r.isFile==`function`?r.isFile():!1}catch{return!1}}function D(e){if(e.env.OK_FORCE_BROWSER===`1`)return{available:!1,reason:`force-browser`};if(e.platform!==`darwin`)return{available:!1,reason:`darwin-only`};let t;try{t=T(e)}catch{return{available:!1,reason:`stat-error`}}return t?e.env.OK_FORCE_DESKTOP===`1`?{available:!0,reason:`available`,bundlePath:t}:e.isTTY!==!0||e.env.SSH_CONNECTION||e.env.SSH_TTY?{available:!1,reason:`headless`,bundlePath:t}:{available:!0,reason:`available`,bundlePath:t}:{available:!1,reason:`no-bundle`}}function O(e){(e.log??(e=>console.error(e)))("Launching OpenKnowledge desktop (use `ok start` for the browser server, or `OK_FORCE_BROWSER=1` to always skip)");let t={...process.env};delete t.ELECTRON_RUN_AS_NODE,e.spawn(`open`,[`-b`,`com.inkeep.open-knowledge`],{detached:!0,stdio:`ignore`,env:t}).unref()}function k(e=`no-bundle`){switch(e){case`no-bundle`:return`Desktop app not found at ${C}. Install via DMG, or omit --mode for browser mode.`;case`darwin-only`:return`Desktop app is macOS-only on this release. Use --mode=browser, or omit --mode for the server fallback.`;case`headless`:return`Desktop launch is gated in headless contexts (CI, SSH, non-TTY stdout). Set OK_FORCE_DESKTOP=1 to override, or use --mode=browser.`;case`force-browser`:return`OK_FORCE_BROWSER=1 is set — desktop dispatch is disabled. Unset it to use --mode=app.`;case`stat-error`:return`Failed to inspect desktop bundle at ${C} (filesystem error). Check permissions or use --mode=browser.`;case`available`:return`Desktop app appears available at ${C} but launch dispatch did not fire (caller bug).`}}function A(e){return p(f(e),`..`,`Frameworks`,`OpenKnowledge Server.app`,`Contents`,`MacOS`,`OpenKnowledge Helper`)}const j=/\/[^/]+\.app\/Contents\/MacOS\/[^/]+$/;function M(e){if(e.platform!==`darwin`||!j.test(e.execPath))return null;let t=A(e.execPath);return e.exists(t)?t:null}function N(e={}){let t=e.execPath??process.execPath,n=e.platform??process.platform,r=e.argv??process.argv,i=e.exists??g,a=r[1];return a?{command:M({execPath:t,platform:n,exists:i})??t,prefixArgs:[a]}:(console.warn(`[self-spawn] process.argv[1] is empty — falling back to \`npx -y @inkeep/open-knowledge@latest\`. This re-introduces the registry-fetch surface that re-exec was fixing. Observed argv: ${JSON.stringify(r)}`),{command:`npx`,prefixArgs:[`-y`,`@inkeep/open-knowledge@latest`]})}function P(e,t){return e.host??t.HOST??`127.0.0.1`}function F(e){let t=d(e).replace(/[^\x20-\x7E]/g,``).trim().slice(0,64);return`open-knowledge-server ${t.length>0?t:`unknown`}`}var I=class extends Error{cwd;constructor(e){super("This directory isn't set up yet. Run `ok init` first, then `ok start` again."),this.name=`OkDirMissingError`,this.cwd=e}};function L(e){return e.uiLock?e.isAlive(e.uiLock.pid)?{action:`skip`,reason:`alive`,pid:e.uiLock.pid,port:e.uiLock.port}:{action:`spawn`,reason:`stale`,stalePid:e.uiLock.pid}:{action:`spawn`,reason:`absent`}}function R(t){g(t.lockDir)||_(t.lockDir,{recursive:!0});let n=v(p(t.lockDir,e),`w`),r=t.spawn??u,{PORT:i,...a}=process.env,o=N();try{let e=r(o.command,[...o.prefixArgs,...t.args??[`ui`]],{detached:!0,stdio:[`ignore`,`ignore`,n],windowsHide:!0,cwd:t.cwd,env:{...a,ELECTRON_RUN_AS_NODE:`1`}});return e.unref(),e}finally{try{h(n)}catch{}}}function z(e,t,n){return e??(n===void 0?t:void 0)}function B(e,t){return e!==void 0&&t!==null&&t.port>0&&t.draining!==!0}function V(e,t,n){return e??(t!=null&&!n?1:0)}async function H(e){let t=e.spawn??u,n=N(),{PORT:r,...i}=process.env,a=t(n.command,[...n.prefixArgs,`ui`,`--port`,String(e.uiPort)],{cwd:e.cwd,stdio:`inherit`,windowsHide:!0,env:{...i,ELECTRON_RUN_AS_NODE:`1`}}),o=!1,s=e=>{o=!0;try{a.kill(e)}catch{}},c=()=>s(`SIGINT`),l=()=>s(`SIGTERM`);process.once(`SIGINT`,c),process.once(`SIGTERM`,l),await new Promise(e=>{a.on(`exit`,(t,n)=>{process.exitCode=V(t,n,o),e()}),a.on(`error`,t=>{console.error(`[start] connect fallback: failed to spawn ok ui — ${t instanceof Error?t.message:String(t)}`),process.exitCode=1,e()})}),process.removeListener(`SIGINT`,c),process.removeListener(`SIGTERM`,l)}async function U(e){let t=e.now()+e.timeoutMs;for(;e.now()<t;){let t=e.readUiLock();if(t&&t.port>0)return t.port;await e.sleep(e.pollIntervalMs)}let n=e.readUiLock();return n&&n.port>0?n.port:null}const W=t;function G(e,t,n=e=>b(e,{recursive:!0,force:!0})){return async()=>{try{await e()}finally{try{await n(t)}catch(e){process.stderr.write(`[start] ephemeral temp dir reap failed for ${t}: ${e instanceof Error?e.message:String(e)}\n`)}}}}function K(e,t={}){let n=t.exit??(e=>process.exit(e)),r=t.getActiveHandles??(()=>{let e=process._getActiveHandles;return e?e.call(process):null});return async()=>{let i=!1;try{await e()}catch(e){i=!0,t.log?.error({err:e},`idle-shutdown: destroy failed — exiting anyway`)}finally{let e=null;try{let t=r();if(t!==null){e={};for(let n of t){let t=n?.constructor?.name??`unknown`;e[t]=(e[t]??0)+1}}}catch{e=null}t.log?.info({event:`idle-shutdown-exit`,exitCode:i?1:0,openHandles:e??{},handlesAvailable:e!==null},`idle-shutdown: teardown finished — exiting process`),n(i?1:0)}}}function q(e){let t=e.sigtermGraceMs??W,n=e.sigtermPollIntervalMs??200,r=e.sleep??(e=>x(e));return async()=>{try{let i=e.readUiLock();if(i&&e.isAlive(i.pid))try{e.killPid(i.pid,`SIGTERM`),e.log?.info({pid:i.pid,port:i.port},`idle-shutdown: SIGTERM UI sibling`);let a=Date.now()+t;for(;Date.now()<a&&e.isAlive(i.pid);)await r(n);if(e.isAlive(i.pid))try{e.killPid(i.pid,`SIGKILL`),e.log?.warn({pid:i.pid,graceMs:t},`idle-shutdown: SIGTERM grace expired — escalated to SIGKILL`)}catch(t){e.log?.error({pid:i.pid,err:t instanceof Error?t.message:String(t)},`idle-shutdown: SIGKILL failed`)}}catch(t){e.log?.warn({pid:i.pid,err:t instanceof Error?t.message:String(t)},`idle-shutdown: failed to SIGTERM UI sibling`)}}catch(t){e.log?.warn({err:t instanceof Error?t.message:String(t)},`idle-shutdown: UI lookup failed; proceeding with destroy`)}await e.destroy()}}async function J(e){let{config:t,cwd:a,host:o}=e,l=e.skipAutoInit??!1,u=e.skipUiAutoSpawn??!1,d=e.idleThresholdMs??18e5,{existsSync:f,mkdirSync:p}=await import(`node:fs`),{basename:m,dirname:h}=await import(`node:path`),{bootServer:g,getLogger:_,isProcessAlive:v,readUiLock:y,resolveContentDir:b,resolveLockDir:S,waitForServerLockDrain:C}=await import(`./dist-BYM_jxPa.mjs`),w=e.log??_(`start`),T=e.singleFile!==void 0,E=e.projectDir??a,D=T?r(e.singleFile).canonicalFilePath:void 0,O=D?h(D):void 0,k=D?m(D):void 0;if(!T){if(!l&&!n(a))throw new I(a);let t=process.env.OK_RECLAIM_DISABLE??null,r=e=>{let t=typeof e.event==`string`?e.event:``;(t.endsWith(`-failed`)||t.endsWith(`-error`)||t.endsWith(`-missing`))&&w.warn({event:e},`[start] reclaim sweep reported a problem`)};try{(e.repairMcpConfigsFn??(await import(`./repair-mcp-configs-DCP-rfpP.mjs`)).repairMcpConfigs)({projectDir:a,reclaimDisableEnv:t,logger:r})}catch(e){w.warn({err:e},`[start] mcp-config repair sweep failed; continuing`)}try{(e.repairLaunchJsonFn??(await import(`./repair-launch-json-Du0EU3Si.mjs`)).repairLaunchJson)({projectDir:a,reclaimDisableEnv:t,logger:r})}catch(e){w.warn({err:e},`[start] launch.json repair sweep failed; continuing`)}try{await(e.repairSkillsFn??(await import(`./repair-skills-BDe9l22O.mjs`)).repairSkills)({projectDir:a,reclaimDisableEnv:t,logger:r})}catch(e){w.warn({err:e},`[start] skill repair sweep failed; continuing`)}}let A=O??b(t,a);!T&&!f(A)&&(p(A,{recursive:!0}),w.info({contentDir:A},`Created content directory`));let j=null,M=async({lockDir:t})=>{if(j=L({uiLock:y(t),isAlive:v}),j.action===`spawn`&&!u)try{let n=e.uiPort===void 0?void 0:[`ui`,`--port`,String(e.uiPort)];R({lockDir:t,cwd:a,spawn:e.spawn,args:n}),w.info({reason:j.reason,uiPort:e.uiPort},`[start] auto-spawned ok ui sibling`)}catch(e){console.warn(`[start] failed to auto-spawn ok ui: ${e instanceof Error?e.message:String(e)}`)}else j.action===`skip`&&w.info({port:j.port,pid:j.pid},`UI already running at port ${j.port}`)},N=e.reactShellDistDir===void 0,P=s(),F=i();{let e=S(T?E:a),t=Date.now(),n=await C(e);n!==`no-drain`&&w.info({event:`start-waited-for-draining-predecessor`,outcome:n,waitedMs:Date.now()-t,drainLockDir:e},n===`released`?`[start] predecessor server finished draining — proceeding`:`[start] predecessor server still draining after wait — proceeding to collide`)}let z=await g({config:t,contentDir:A,projectDir:T?E:a,contentRoot:T?void 0:t.content.dir,port:e.port,host:o,quiet:!1,detectGh:c,tokenStore:P,embeddingsKeyStore:F,...T?{ephemeral:!0,singleDocRelPath:k,gitEnabled:!1,gitPreflight:()=>({ok:!0,version:`0.0.0`,resolvedPath:`git`,source:`PATH`})}:{},localOpCliArgs:[process.execPath,process.argv[1]],attachUiSibling:N,idleShutdownMs:d,skipAutoInit:!0,...N?{spawnUiSiblingFn:M}:{},idleShutdownHandler:t=>{let n=q({readUiLock:()=>y(z.lockDir),isAlive:v,killPid:(e,t)=>{process.kill(e,t)},destroy:t,log:w});return K(T?G(n,E):n,{log:w,exit:e.idleExit})},log:w,...e.serveContentAssets===void 0?{}:{serveContentAssets:e.serveContentAssets},...e.reactShellDistDir?{reactShellDistDir:e.reactShellDistDir}:{}});j||={action:`skip`,reason:`alive`,pid:0,port:0};let B=j,V=null;if(B.action===`skip`)V=B.port>0?B.port:null;else if(!u){let t=e.uiBindTimeoutMs??3e3;V=await U({readUiLock:()=>y(z.lockDir),now:Date.now,sleep:e=>x(e),timeoutMs:t,pollIntervalMs:50}),V===null&&w.warn({timeoutMs:t},`[start] ok ui did not bind within timeout — banner falls back to API URL`)}return{httpServer:z.httpServer,destroy:z.destroy,lockDir:z.lockDir,contentDir:A,port:z.port,ready:z.ready,degraded:z.degraded,uiSpawnDecision:j,resolvedUiPort:V}}function ee(e){if(e===`browser`||e===`app`)return e;throw new a(`--mode must be 'browser' or 'app'`)}function te(e){let t=Number.parseInt(e,10);if(Number.isNaN(t)||t<1||t>65535)throw new a(`--ui-port must be a port number between 1 and 65535`);return t}function Y(e){return e.OK_CONSOLE_LEVEL!==void 0||e.LOG_LEVEL!==void 0?null:`warn`}function X(e){let t=[`Stopping OpenKnowledge…`,`Saving pending changes and releasing the server lock — this can take a few seconds.`];return e===`SIGINT`&&t.push(`Press Ctrl+C again to force quit.`),t}async function Z(e,t){let n=Y(process.env);n!==null&&(process.env.OK_CONSOLE_LEVEL=n);let{renderBanner:r}=await import(`./banner-BLebOalA.mjs`),{accent:i,dim:a,error:o,warning:s}=await import(`./colors-CmkIIbww.mjs`),c=process.cwd(),u=e;process.title=F(c);let d=P(t,process.env),f=t.port===void 0?void 0:Number(t.port),p=process.env.PORT?Number(process.env.PORT):void 0,m=t.uiPort===void 0?void 0:Number(t.uiPort),h=z(f,p,m);if(m!==void 0){let{readServerLock:e,resolveLockDir:t}=await import(`./dist-BYM_jxPa.mjs`);if(B(m,e(t(c)))){await H({cwd:c,uiPort:m});return}}let g;try{g=await J({config:u,cwd:c,host:d,port:h,...m===void 0?{}:{uiPort:m},...t.serveContentAssets===void 0?{}:{serveContentAssets:t.serveContentAssets},...t.reactShellDistDir?{reactShellDistDir:t.reactShellDistDir}:{},...t.singleFile?{singleFile:t.singleFile}:{},...t.projectDir?{projectDir:t.projectDir}:{}})}catch(e){e instanceof I&&(console.error(o(e.message)),process.exit(1));let t=await import(`./dist-BYM_jxPa.mjs`);if((e instanceof t.GitNotAvailableError||e instanceof t.GitTooOldError)&&process.exit(78),(e instanceof t.SingleFileNotFoundError||e instanceof t.SingleFileNotAFileError||e instanceof t.SingleFileNotMarkdownError)&&(console.error(o(e.message)),process.exit(1)),m!==void 0&&Q(e,t)){await H({cwd:c,uiPort:m});return}let n=$(e,c,t);n!==null&&(console.error(o(n)),process.exit(1)),console.error(`${o(`Failed to start:`)} ${e instanceof Error?e.stack??e.message:String(e)}`),process.exit(1)}let _=!1,v=async e=>{if(_)return;_=!0;let[t,...n]=X(e);console.log(i(`\n${t}`));for(let e of n)console.log(a(` ${e}`));try{await g.destroy()}catch(e){console.error(`${o(`destroy() failed:`)} ${e instanceof Error?e.stack??e.message:String(e)}`),process.exitCode=1}process.exit(process.exitCode??0)};process.once(`SIGINT`,()=>{v(`SIGINT`)}),process.once(`SIGTERM`,()=>{v(`SIGTERM`)});let y=`http://${d}:${g.port}`,b=d===`0.0.0.0`||d===`::`?`http://0.0.0.0:${g.port}`:void 0,x=g.resolvedUiPort,S=x!==null&&x>0?`http://${d}:${x}`:y;console.log(r({name:`open-knowledge`,version:l,localUrl:S,apiUrl:S===y?void 0:y,networkUrl:b,nextSteps:[`Open the Editor URL in your browser to start editing.`]}));let C={"shadow-repo":`Version history and branch-switch safety unavailable`,"file-watcher":`External file changes will not sync to the editor`,"head-watcher":`Git branch switches may cause document inconsistency`};g.ready.then(async()=>{if(g.degraded.length>0){console.log();for(let e of g.degraded){let t=C[e]??`${e} (check server logs for details)`;console.warn(` ${s(`⚠`)} ${s(e)}: ${a(t)}`)}console.log()}if(t.open){let{openBrowser:e}=await import(`./open-browser-CPSoIF8R.mjs`);e(S)}}).catch(e=>{console.error(` ${o(`Server initialization failed:`)} ${e instanceof Error?e.message:String(e)}`)})}function Q(e,t){let n=t.ServerLockCollisionError;return n!==void 0&&e instanceof n}function $(e,t,n){let r=n.ServerLockCollisionError;if(r===void 0||!(e instanceof r))return null;try{let e=p(t,`.ok`),r=n.readServerLock(e);return r?r.kind===`interactive`?`OpenKnowledge desktop is currently running on this project. Quit it or use --cwd to point elsewhere.`:r.kind===`mcp-spawned`?"An MCP-spawned server holds this lock; it should release on idle-shutdown (~30 min). Or run `ok stop`.":"OpenKnowledge server is already running on this project — check `ok status` or `ok stop`.":"OpenKnowledge server is already running on this project — check `ok status` or `ok stop`."}catch{return null}}function ne(e){return new o(`start`).description(`Start the knowledge base collab server`).option(`-p, --port <port>`,`Server port`,void 0).option(`--ui-port <port>`,`Pin the ok ui sibling to <port> and connect (not exit) if a server already runs here — the worktree-preview recipe path`,te).option(`-H, --host <host>`,`Server host`,void 0).option(`--open`,`Open browser after start`).option(`--mode <mode>`,`Force dispatch mode: 'browser' or 'app'`,ee).option(`--serve-content-assets`,`Serve content assets from this server (now the default; kept for compatibility)`).option(`--react-shell-dist-dir <path>`,`Serve React shell from <path> (suppresses ok ui sibling)`).option(`--single-file <path>`,`No-project ephemeral single-file mode: scope the server to one markdown file (git + MCP off)`).option(`--project-dir <dir>`,`Throwaway project root for --single-file (where ephemeral .ok/ state lives)`).action(async t=>{let n=e();if(t.mode===`app`){t.open&&(process.stderr.write(`error: option '--mode=app' cannot be combined with '--open' (--open opens a browser tab against the local server, which app mode does not boot)
|
|
1
|
+
import{In as e,ht as t}from"./server-lock-iLcBw_q0-DddnIrHS.mjs";import{ar as n,kr as r,vr as i}from"./dist-CynAX6cy.mjs";import{n as a,t as o}from"./esm-CsQUg9js.mjs";import{i as s,t as c}from"./gh-detect-Uu4VAWnW.mjs";import{n as l}from"./constants-B2EvNGWZ.mjs";import{spawn as u}from"node:child_process";import{basename as d,dirname as f,join as p}from"node:path";import{homedir as m}from"node:os";import{closeSync as h,existsSync as g,mkdirSync as _,openSync as v,statSync as y}from"node:fs";import{rm as b}from"node:fs/promises";import{setTimeout as x}from"node:timers/promises";const S=`OpenKnowledge.app`,C=`/Applications/${S}`;function w(){return{platform:process.platform,env:process.env,execPath:process.execPath,isTTY:process.stdout.isTTY,statSync:e=>{try{return y(e,{throwIfNoEntry:!1})??null}catch{return null}}}}function T(e){if(e.env.ELECTRON_RUN_AS_NODE===`1`){let t=/(.+?\.app)\/Contents\/MacOS\//.exec(e.execPath);if(t?.[1])return t[1]}if(E(e,C))return C;let t=p(e.homeDir??m(),`Applications`,S);return E(e,t)?t:null}function E(e,t){try{let n=p(t,`Contents`,`MacOS`,`OpenKnowledge`),r=e.statSync(n);return r&&typeof r.isFile==`function`?r.isFile():!1}catch{return!1}}function D(e){if(e.env.OK_FORCE_BROWSER===`1`)return{available:!1,reason:`force-browser`};if(e.platform!==`darwin`)return{available:!1,reason:`darwin-only`};let t;try{t=T(e)}catch{return{available:!1,reason:`stat-error`}}return t?e.env.OK_FORCE_DESKTOP===`1`?{available:!0,reason:`available`,bundlePath:t}:e.isTTY!==!0||e.env.SSH_CONNECTION||e.env.SSH_TTY?{available:!1,reason:`headless`,bundlePath:t}:{available:!0,reason:`available`,bundlePath:t}:{available:!1,reason:`no-bundle`}}function O(e){(e.log??(e=>console.error(e)))("Launching OpenKnowledge desktop (use `ok start` for the browser server, or `OK_FORCE_BROWSER=1` to always skip)");let t={...process.env};delete t.ELECTRON_RUN_AS_NODE,e.spawn(`open`,[`-b`,`com.inkeep.open-knowledge`],{detached:!0,stdio:`ignore`,env:t}).unref()}function k(e=`no-bundle`){switch(e){case`no-bundle`:return`Desktop app not found at ${C}. Install via DMG, or omit --mode for browser mode.`;case`darwin-only`:return`Desktop app is macOS-only on this release. Use --mode=browser, or omit --mode for the server fallback.`;case`headless`:return`Desktop launch is gated in headless contexts (CI, SSH, non-TTY stdout). Set OK_FORCE_DESKTOP=1 to override, or use --mode=browser.`;case`force-browser`:return`OK_FORCE_BROWSER=1 is set — desktop dispatch is disabled. Unset it to use --mode=app.`;case`stat-error`:return`Failed to inspect desktop bundle at ${C} (filesystem error). Check permissions or use --mode=browser.`;case`available`:return`Desktop app appears available at ${C} but launch dispatch did not fire (caller bug).`}}function A(e){return p(f(e),`..`,`Frameworks`,`OpenKnowledge Server.app`,`Contents`,`MacOS`,`OpenKnowledge Helper`)}const j=/\/[^/]+\.app\/Contents\/MacOS\/[^/]+$/;function M(e){if(e.platform!==`darwin`||!j.test(e.execPath))return null;let t=A(e.execPath);return e.exists(t)?t:null}function N(e={}){let t=e.execPath??process.execPath,n=e.platform??process.platform,r=e.argv??process.argv,i=e.exists??g,a=r[1];return a?{command:M({execPath:t,platform:n,exists:i})??t,prefixArgs:[a]}:(console.warn(`[self-spawn] process.argv[1] is empty — falling back to \`npx -y @inkeep/open-knowledge@latest\`. This re-introduces the registry-fetch surface that re-exec was fixing. Observed argv: ${JSON.stringify(r)}`),{command:`npx`,prefixArgs:[`-y`,`@inkeep/open-knowledge@latest`]})}function P(e,t){return e.host??t.HOST??`127.0.0.1`}function F(e){let t=d(e).replace(/[^\x20-\x7E]/g,``).trim().slice(0,64);return`open-knowledge-server ${t.length>0?t:`unknown`}`}var I=class extends Error{cwd;constructor(e){super("This directory isn't set up yet. Run `ok init` first, then `ok start` again."),this.name=`OkDirMissingError`,this.cwd=e}};function L(e){return e.uiLock?e.isAlive(e.uiLock.pid)?{action:`skip`,reason:`alive`,pid:e.uiLock.pid,port:e.uiLock.port}:{action:`spawn`,reason:`stale`,stalePid:e.uiLock.pid}:{action:`spawn`,reason:`absent`}}function R(t){g(t.lockDir)||_(t.lockDir,{recursive:!0});let n=v(p(t.lockDir,e),`w`),r=t.spawn??u,{PORT:i,...a}=process.env,o=N();try{let e=r(o.command,[...o.prefixArgs,...t.args??[`ui`]],{detached:!0,stdio:[`ignore`,`ignore`,n],windowsHide:!0,cwd:t.cwd,env:{...a,ELECTRON_RUN_AS_NODE:`1`}});return e.unref(),e}finally{try{h(n)}catch{}}}function z(e,t,n){return e??(n===void 0?t:void 0)}function B(e,t){return e!==void 0&&t!==null&&t.port>0&&t.draining!==!0}function V(e,t,n){return e??(t!=null&&!n?1:0)}async function H(e){let t=e.spawn??u,n=N(),{PORT:r,...i}=process.env,a=t(n.command,[...n.prefixArgs,`ui`,`--port`,String(e.uiPort)],{cwd:e.cwd,stdio:`inherit`,windowsHide:!0,env:{...i,ELECTRON_RUN_AS_NODE:`1`}}),o=!1,s=e=>{o=!0;try{a.kill(e)}catch{}},c=()=>s(`SIGINT`),l=()=>s(`SIGTERM`);process.once(`SIGINT`,c),process.once(`SIGTERM`,l),await new Promise(e=>{a.on(`exit`,(t,n)=>{process.exitCode=V(t,n,o),e()}),a.on(`error`,t=>{console.error(`[start] connect fallback: failed to spawn ok ui — ${t instanceof Error?t.message:String(t)}`),process.exitCode=1,e()})}),process.removeListener(`SIGINT`,c),process.removeListener(`SIGTERM`,l)}async function U(e){let t=e.now()+e.timeoutMs;for(;e.now()<t;){let t=e.readUiLock();if(t&&t.port>0)return t.port;await e.sleep(e.pollIntervalMs)}let n=e.readUiLock();return n&&n.port>0?n.port:null}const W=t;function G(e,t,n=e=>b(e,{recursive:!0,force:!0})){return async()=>{try{await e()}finally{try{await n(t)}catch(e){process.stderr.write(`[start] ephemeral temp dir reap failed for ${t}: ${e instanceof Error?e.message:String(e)}\n`)}}}}function K(e,t={}){let n=t.exit??(e=>process.exit(e)),r=t.getActiveHandles??(()=>{let e=process._getActiveHandles;return e?e.call(process):null});return async()=>{let i=!1;try{await e()}catch(e){i=!0,t.log?.error({err:e},`idle-shutdown: destroy failed — exiting anyway`)}finally{let e=null;try{let t=r();if(t!==null){e={};for(let n of t){let t=n?.constructor?.name??`unknown`;e[t]=(e[t]??0)+1}}}catch{e=null}t.log?.info({event:`idle-shutdown-exit`,exitCode:i?1:0,openHandles:e??{},handlesAvailable:e!==null},`idle-shutdown: teardown finished — exiting process`),n(i?1:0)}}}function q(e){let t=e.sigtermGraceMs??W,n=e.sigtermPollIntervalMs??200,r=e.sleep??(e=>x(e));return async()=>{try{let i=e.readUiLock();if(i&&e.isAlive(i.pid))try{e.killPid(i.pid,`SIGTERM`),e.log?.info({pid:i.pid,port:i.port},`idle-shutdown: SIGTERM UI sibling`);let a=Date.now()+t;for(;Date.now()<a&&e.isAlive(i.pid);)await r(n);if(e.isAlive(i.pid))try{e.killPid(i.pid,`SIGKILL`),e.log?.warn({pid:i.pid,graceMs:t},`idle-shutdown: SIGTERM grace expired — escalated to SIGKILL`)}catch(t){e.log?.error({pid:i.pid,err:t instanceof Error?t.message:String(t)},`idle-shutdown: SIGKILL failed`)}}catch(t){e.log?.warn({pid:i.pid,err:t instanceof Error?t.message:String(t)},`idle-shutdown: failed to SIGTERM UI sibling`)}}catch(t){e.log?.warn({err:t instanceof Error?t.message:String(t)},`idle-shutdown: UI lookup failed; proceeding with destroy`)}await e.destroy()}}async function J(e){let{config:t,cwd:a,host:o}=e,l=e.skipAutoInit??!1,u=e.skipUiAutoSpawn??!1,d=e.idleThresholdMs??18e5,{existsSync:f,mkdirSync:p}=await import(`node:fs`),{basename:m,dirname:h}=await import(`node:path`),{bootServer:g,getLogger:_,isProcessAlive:v,readUiLock:y,resolveContentDir:b,resolveLockDir:S,waitForServerLockDrain:C}=await import(`./dist-DiaxTJ69.mjs`),w=e.log??_(`start`),T=e.singleFile!==void 0,E=e.projectDir??a,D=T?r(e.singleFile).canonicalFilePath:void 0,O=D?h(D):void 0,k=D?m(D):void 0;if(!T){if(!l&&!n(a))throw new I(a);let t=process.env.OK_RECLAIM_DISABLE??null,r=e=>{let t=typeof e.event==`string`?e.event:``;(t.endsWith(`-failed`)||t.endsWith(`-error`)||t.endsWith(`-missing`))&&w.warn({event:e},`[start] reclaim sweep reported a problem`)};try{(e.repairMcpConfigsFn??(await import(`./repair-mcp-configs-Cp5VRehu.mjs`)).repairMcpConfigs)({projectDir:a,reclaimDisableEnv:t,logger:r})}catch(e){w.warn({err:e},`[start] mcp-config repair sweep failed; continuing`)}try{(e.repairLaunchJsonFn??(await import(`./repair-launch-json-DzczMayl.mjs`)).repairLaunchJson)({projectDir:a,reclaimDisableEnv:t,logger:r})}catch(e){w.warn({err:e},`[start] launch.json repair sweep failed; continuing`)}try{await(e.repairSkillsFn??(await import(`./repair-skills-B-9mVcmb.mjs`)).repairSkills)({projectDir:a,reclaimDisableEnv:t,logger:r})}catch(e){w.warn({err:e},`[start] skill repair sweep failed; continuing`)}}let A=O??b(t,a);!T&&!f(A)&&(p(A,{recursive:!0}),w.info({contentDir:A},`Created content directory`));let j=null,M=async({lockDir:t})=>{if(j=L({uiLock:y(t),isAlive:v}),j.action===`spawn`&&!u)try{let n=e.uiPort===void 0?void 0:[`ui`,`--port`,String(e.uiPort)];R({lockDir:t,cwd:a,spawn:e.spawn,args:n}),w.info({reason:j.reason,uiPort:e.uiPort},`[start] auto-spawned ok ui sibling`)}catch(e){console.warn(`[start] failed to auto-spawn ok ui: ${e instanceof Error?e.message:String(e)}`)}else j.action===`skip`&&w.info({port:j.port,pid:j.pid},`UI already running at port ${j.port}`)},N=e.reactShellDistDir===void 0,P=s(),F=i();{let e=S(T?E:a),t=Date.now(),n=await C(e);n!==`no-drain`&&w.info({event:`start-waited-for-draining-predecessor`,outcome:n,waitedMs:Date.now()-t,drainLockDir:e},n===`released`?`[start] predecessor server finished draining — proceeding`:`[start] predecessor server still draining after wait — proceeding to collide`)}let z=await g({config:t,contentDir:A,projectDir:T?E:a,contentRoot:T?void 0:t.content.dir,port:e.port,host:o,quiet:!1,detectGh:c,tokenStore:P,embeddingsKeyStore:F,...T?{ephemeral:!0,singleDocRelPath:k,gitEnabled:!1,gitPreflight:()=>({ok:!0,version:`0.0.0`,resolvedPath:`git`,source:`PATH`})}:{},localOpCliArgs:[process.execPath,process.argv[1]],attachUiSibling:N,idleShutdownMs:d,skipAutoInit:!0,...N?{spawnUiSiblingFn:M}:{},idleShutdownHandler:t=>{let n=q({readUiLock:()=>y(z.lockDir),isAlive:v,killPid:(e,t)=>{process.kill(e,t)},destroy:t,log:w});return K(T?G(n,E):n,{log:w,exit:e.idleExit})},log:w,...e.serveContentAssets===void 0?{}:{serveContentAssets:e.serveContentAssets},...e.reactShellDistDir?{reactShellDistDir:e.reactShellDistDir}:{}});j||={action:`skip`,reason:`alive`,pid:0,port:0};let B=j,V=null;if(B.action===`skip`)V=B.port>0?B.port:null;else if(!u){let t=e.uiBindTimeoutMs??3e3;V=await U({readUiLock:()=>y(z.lockDir),now:Date.now,sleep:e=>x(e),timeoutMs:t,pollIntervalMs:50}),V===null&&w.warn({timeoutMs:t},`[start] ok ui did not bind within timeout — banner falls back to API URL`)}return{httpServer:z.httpServer,destroy:z.destroy,lockDir:z.lockDir,contentDir:A,port:z.port,ready:z.ready,degraded:z.degraded,uiSpawnDecision:j,resolvedUiPort:V}}function ee(e){if(e===`browser`||e===`app`)return e;throw new a(`--mode must be 'browser' or 'app'`)}function te(e){let t=Number.parseInt(e,10);if(Number.isNaN(t)||t<1||t>65535)throw new a(`--ui-port must be a port number between 1 and 65535`);return t}function Y(e){return e.OK_CONSOLE_LEVEL!==void 0||e.LOG_LEVEL!==void 0?null:`warn`}function X(e){let t=[`Stopping OpenKnowledge…`,`Saving pending changes and releasing the server lock — this can take a few seconds.`];return e===`SIGINT`&&t.push(`Press Ctrl+C again to force quit.`),t}async function Z(e,t){let n=Y(process.env);n!==null&&(process.env.OK_CONSOLE_LEVEL=n);let{renderBanner:r}=await import(`./banner-BLebOalA.mjs`),{accent:i,dim:a,error:o,warning:s}=await import(`./colors-CmkIIbww.mjs`),c=process.cwd(),u=e;process.title=F(c);let d=P(t,process.env),f=t.port===void 0?void 0:Number(t.port),p=process.env.PORT?Number(process.env.PORT):void 0,m=t.uiPort===void 0?void 0:Number(t.uiPort),h=z(f,p,m);if(m!==void 0){let{readServerLock:e,resolveLockDir:t}=await import(`./dist-DiaxTJ69.mjs`);if(B(m,e(t(c)))){await H({cwd:c,uiPort:m});return}}let g;try{g=await J({config:u,cwd:c,host:d,port:h,...m===void 0?{}:{uiPort:m},...t.serveContentAssets===void 0?{}:{serveContentAssets:t.serveContentAssets},...t.reactShellDistDir?{reactShellDistDir:t.reactShellDistDir}:{},...t.singleFile?{singleFile:t.singleFile}:{},...t.projectDir?{projectDir:t.projectDir}:{}})}catch(e){e instanceof I&&(console.error(o(e.message)),process.exit(1));let t=await import(`./dist-DiaxTJ69.mjs`);if((e instanceof t.GitNotAvailableError||e instanceof t.GitTooOldError)&&process.exit(78),(e instanceof t.SingleFileNotFoundError||e instanceof t.SingleFileNotAFileError||e instanceof t.SingleFileNotMarkdownError)&&(console.error(o(e.message)),process.exit(1)),m!==void 0&&Q(e,t)){await H({cwd:c,uiPort:m});return}let n=$(e,c,t);n!==null&&(console.error(o(n)),process.exit(1)),console.error(`${o(`Failed to start:`)} ${e instanceof Error?e.stack??e.message:String(e)}`),process.exit(1)}let _=!1,v=async e=>{if(_)return;_=!0;let[t,...n]=X(e);console.log(i(`\n${t}`));for(let e of n)console.log(a(` ${e}`));try{await g.destroy()}catch(e){console.error(`${o(`destroy() failed:`)} ${e instanceof Error?e.stack??e.message:String(e)}`),process.exitCode=1}process.exit(process.exitCode??0)};process.once(`SIGINT`,()=>{v(`SIGINT`)}),process.once(`SIGTERM`,()=>{v(`SIGTERM`)});let y=`http://${d}:${g.port}`,b=d===`0.0.0.0`||d===`::`?`http://0.0.0.0:${g.port}`:void 0,x=g.resolvedUiPort,S=x!==null&&x>0?`http://${d}:${x}`:y;console.log(r({name:`open-knowledge`,version:l,localUrl:S,apiUrl:S===y?void 0:y,networkUrl:b,nextSteps:[`Open the Editor URL in your browser to start editing.`]}));let C={"shadow-repo":`Version history and branch-switch safety unavailable`,"file-watcher":`External file changes will not sync to the editor`,"head-watcher":`Git branch switches may cause document inconsistency`};g.ready.then(async()=>{if(g.degraded.length>0){console.log();for(let e of g.degraded){let t=C[e]??`${e} (check server logs for details)`;console.warn(` ${s(`⚠`)} ${s(e)}: ${a(t)}`)}console.log()}if(t.open){let{openBrowser:e}=await import(`./open-browser-Lk0l8JF5.mjs`);e(S)}}).catch(e=>{console.error(` ${o(`Server initialization failed:`)} ${e instanceof Error?e.message:String(e)}`)})}function Q(e,t){let n=t.ServerLockCollisionError;return n!==void 0&&e instanceof n}function $(e,t,n){let r=n.ServerLockCollisionError;if(r===void 0||!(e instanceof r))return null;try{let e=p(t,`.ok`),r=n.readServerLock(e);return r?r.kind===`interactive`?`OpenKnowledge desktop is currently running on this project. Quit it or use --cwd to point elsewhere.`:r.kind===`mcp-spawned`?"An MCP-spawned server holds this lock; it should release on idle-shutdown (~30 min). Or run `ok stop`.":"OpenKnowledge server is already running on this project — check `ok status` or `ok stop`.":"OpenKnowledge server is already running on this project — check `ok status` or `ok stop`."}catch{return null}}function ne(e){return new o(`start`).description(`Start the knowledge base collab server`).option(`-p, --port <port>`,`Server port`,void 0).option(`--ui-port <port>`,`Pin the ok ui sibling to <port> and connect (not exit) if a server already runs here — the worktree-preview recipe path`,te).option(`-H, --host <host>`,`Server host`,void 0).option(`--open`,`Open browser after start`).option(`--mode <mode>`,`Force dispatch mode: 'browser' or 'app'`,ee).option(`--serve-content-assets`,`Serve content assets from this server (now the default; kept for compatibility)`).option(`--react-shell-dist-dir <path>`,`Serve React shell from <path> (suppresses ok ui sibling)`).option(`--single-file <path>`,`No-project ephemeral single-file mode: scope the server to one markdown file (git + MCP off)`).option(`--project-dir <dir>`,`Throwaway project root for --single-file (where ephemeral .ok/ state lives)`).action(async t=>{let n=e();if(t.mode===`app`){t.open&&(process.stderr.write(`error: option '--mode=app' cannot be combined with '--open' (--open opens a browser tab against the local server, which app mode does not boot)
|
|
2
2
|
`),process.exit(2));let e=[];if(t.port!==void 0&&e.push(`--port`),t.uiPort!==void 0&&e.push(`--ui-port`),t.host!==void 0&&e.push(`--host`),e.length>0){let t=process.env.OK_LOG_LEVEL??`info`;(t===`debug`||t===`trace`)&&console.error(`--mode=app: ignoring ${e.join(`, `)}`)}let n=D(w());if(n.available){O({spawn:u});return}console.error(k(n.reason)),process.exit(1)}await Z(n,t)})}export{D as C,w as S,ne as _,V as a,K as b,F as c,z as d,P as f,R as g,B as h,q as i,X as l,Z as m,U as n,H as o,Y as p,J as r,L as s,I as t,Q as u,$ as v,O as w,N as x,G as y};
|
|
3
|
-
//# sourceMappingURL=start-
|
|
3
|
+
//# sourceMappingURL=start-Ig8o-wfe.mjs.map
|