@captain-app/openclaw 2026.2.4
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/CHANGELOG.md +1528 -0
- package/LICENSE +21 -0
- package/README-header.png +0 -0
- package/README.md +539 -0
- package/assets/avatar-placeholder.svg +19 -0
- package/assets/chrome-extension/README.md +22 -0
- package/assets/chrome-extension/background.js +438 -0
- package/assets/chrome-extension/icons/icon128.png +0 -0
- package/assets/chrome-extension/icons/icon16.png +0 -0
- package/assets/chrome-extension/icons/icon32.png +0 -0
- package/assets/chrome-extension/icons/icon48.png +0 -0
- package/assets/chrome-extension/manifest.json +25 -0
- package/assets/chrome-extension/options.html +196 -0
- package/assets/chrome-extension/options.js +59 -0
- package/assets/dmg-background-small.png +0 -0
- package/assets/dmg-background.png +0 -0
- package/dist/accounts-ClnuDahN.js +250 -0
- package/dist/accounts-DzBgAM3C.js +251 -0
- package/dist/acp-cli-BEDDkzXH.js +926 -0
- package/dist/acp-cli-CwV4mdnW.js +923 -0
- package/dist/agent-CArjbSeE.js +695 -0
- package/dist/agent-CB7x5HLT.js +695 -0
- package/dist/agent-scope-BbT4OG2N.js +545 -0
- package/dist/agent-scope-C_O6Vpl0.js +545 -0
- package/dist/agent-scope-Csu2B6AM.js +606 -0
- package/dist/archive-CWrnG1CH.js +85 -0
- package/dist/archive-ccN9aDgq.js +85 -0
- package/dist/audit-DXPkQ275.js +1686 -0
- package/dist/audit-eH7nwgsM.js +1686 -0
- package/dist/auth-health-Bj7Gjbv0.js +149 -0
- package/dist/auth-health-CjjJhHey.js +149 -0
- package/dist/auth-nnRYiqpH.js +192 -0
- package/dist/auth-profiles-DVLfuixr.js +2954 -0
- package/dist/auth-y1BLPUhX.js +192 -0
- package/dist/boolean-Wzu0-e0P.js +30 -0
- package/dist/brew-Cqi8b49_.js +46 -0
- package/dist/brew-DyBGNK8A.js +46 -0
- package/dist/build-info.json +5 -0
- package/dist/call-B7EveN4V.js +252 -0
- package/dist/call-vuUQIjOj.js +252 -0
- package/dist/canvas-host/a2ui/.bundle.hash +1 -0
- package/dist/canvas-host/a2ui/a2ui.bundle.js +17780 -0
- package/dist/canvas-host/a2ui/index.html +307 -0
- package/dist/channel-options-CJfmOkol.js +32 -0
- package/dist/channel-options-lFguMTz1.js +62 -0
- package/dist/channel-selection-BmND9mWj.js +51 -0
- package/dist/channel-selection-cGhL9G0c.js +51 -0
- package/dist/channel-summary-B4G513Eb.js +1154 -0
- package/dist/channel-summary-MCwBCa5y.js +1154 -0
- package/dist/channels-cli-C2Of1mZG.js +1411 -0
- package/dist/channels-cli-DFynrP1H.js +1413 -0
- package/dist/channels-status-issues-YohTjZ-I.js +18 -0
- package/dist/channels-status-issues-ZcR1U-m5.js +18 -0
- package/dist/chrome-B3IuUad-.js +1953 -0
- package/dist/chrome-BZ9K48w9.js +1973 -0
- package/dist/clack-prompter-B9yLhyOm.js +92 -0
- package/dist/clack-prompter-BybM9xdL.js +92 -0
- package/dist/cli/daemon-cli.js +2 -0
- package/dist/cli-BJZdJwug.js +89 -0
- package/dist/cli-BQSoKu3d.js +86 -0
- package/dist/cli-utils-CO4jEMn0.js +43 -0
- package/dist/cli-utils-gtE-0a0D.js +43 -0
- package/dist/client-DPqNOpK3.js +1609 -0
- package/dist/client-DySXIFCA.js +1609 -0
- package/dist/command-format-CFzL448l.js +52 -0
- package/dist/command-format-DELazozB.js +52 -0
- package/dist/command-format-ayFsmwwz.js +38 -0
- package/dist/command-options-CsjxK4cZ.js +33 -0
- package/dist/commands-BRe9VTyU.js +229 -0
- package/dist/completion-cli-DlkjK0iC.js +390 -0
- package/dist/completion-cli-E6Pt41AL.js +387 -0
- package/dist/config-BtSTwPcH.js +4882 -0
- package/dist/config-DfMIMT-f.js +4881 -0
- package/dist/config-_d7_WcRv.js +5623 -0
- package/dist/config-guard-wSnm-U8a.js +5628 -0
- package/dist/configure-CPHAFKlg.js +895 -0
- package/dist/configure-DK1XgXYx.js +894 -0
- package/dist/constants-CNTiY-ZN.js +65 -0
- package/dist/constants-hpmbslG7.js +65 -0
- package/dist/control-service-CqX5g_ko.js +61 -0
- package/dist/control-service-o6xe3hEb.js +61 -0
- package/dist/control-ui/apple-touch-icon.png +0 -0
- package/dist/control-ui/assets/index-RwcW4Xl0.css +1 -0
- package/dist/control-ui/assets/index-ryaCcbyp.js +4584 -0
- package/dist/control-ui/assets/index-ryaCcbyp.js.map +1 -0
- package/dist/control-ui/favicon-32.png +0 -0
- package/dist/control-ui/favicon.ico +0 -0
- package/dist/control-ui/favicon.svg +22 -0
- package/dist/control-ui/index.html +17 -0
- package/dist/cron-cli-BoSaDgvH.js +453 -0
- package/dist/cron-cli-qVandvsD.js +456 -0
- package/dist/daemon-cli-C4gGWa15.js +760 -0
- package/dist/daemon-cli-DV_X0Krf.js +761 -0
- package/dist/daemon-runtime-D5hbSrdO.js +460 -0
- package/dist/daemon-runtime-DXUfrXBC.js +460 -0
- package/dist/deliver-BxK5nI2P.js +2587 -0
- package/dist/deliver-Dwzg9LUd.js +2557 -0
- package/dist/deliver-qpYZp20m.js +2587 -0
- package/dist/deps-CUXtMV9d.js +27 -0
- package/dist/deps-WBvZpFV_.js +27 -0
- package/dist/devices-cli-B2s18Qrh.js +207 -0
- package/dist/devices-cli-D1UEtMUJ.js +204 -0
- package/dist/directory-cli-BXQbrkfM.js +247 -0
- package/dist/directory-cli-CqA7tRbq.js +244 -0
- package/dist/dispatcher-Dyv7T-1r.js +160 -0
- package/dist/dns-cli-CWxKD22D.js +198 -0
- package/dist/dns-cli-CzKr_Fxj.js +201 -0
- package/dist/docs-cli-BNyxUbWr.js +159 -0
- package/dist/docs-cli-DYpTbo3i.js +161 -0
- package/dist/doctor-C8fDYZLq.js +2583 -0
- package/dist/doctor-hYcqp7c0.js +2585 -0
- package/dist/entry.js +1326 -0
- package/dist/env-l7QVNj6j.js +32 -0
- package/dist/errors-CMCg46fK.js +1952 -0
- package/dist/exec-B8JKbXKW.js +246 -0
- package/dist/exec-BMnoMcZW.js +1099 -0
- package/dist/exec-HEWTMJ7j.js +246 -0
- package/dist/exec-approvals-DtrnHx6M.js +1026 -0
- package/dist/exec-approvals-Y42bE8ud.js +1026 -0
- package/dist/exec-approvals-cli-CIedYxP3.js +385 -0
- package/dist/exec-approvals-cli-xpbxnj4O.js +388 -0
- package/dist/extensionAPI.js +66572 -0
- package/dist/format-Dzy9uRLE.js +34 -0
- package/dist/format-sj0fELBK.js +34 -0
- package/dist/gateway-cli-5A-KNLEC.js +16635 -0
- package/dist/gateway-cli-B8kS4chb.js +16637 -0
- package/dist/gateway-rpc-15n38Ize.js +28 -0
- package/dist/gateway-rpc-TMVRgGfj.js +28 -0
- package/dist/github-copilot-auth-DVZj4Zgh.js +1104 -0
- package/dist/github-copilot-auth-DeGYyLY9.js +1104 -0
- package/dist/github-copilot-token-B3SA95yo.js +103 -0
- package/dist/github-copilot-token-C8XFYz0i.js +103 -0
- package/dist/github-copilot-token-CnxakiSC.js +103 -0
- package/dist/gmail-setup-utils-CWPC386a.js +428 -0
- package/dist/gmail-setup-utils-eJVB5Ewp.js +428 -0
- package/dist/health-format-B0tMTk3C.js +1189 -0
- package/dist/health-format-DaURVaUn.js +1188 -0
- package/dist/help-format-CEsRHU2f.js +17 -0
- package/dist/help-format-GuCWws6r.js +17 -0
- package/dist/helpers-BEJ-phFf.js +25 -0
- package/dist/helpers-BtbBZVKZ.js +10 -0
- package/dist/helpers-C12w9zxf.js +10 -0
- package/dist/helpers-CzjGJZmJ.js +25 -0
- package/dist/hooks/bundled/boot-md/HOOK.md +19 -0
- package/dist/hooks/bundled/command-logger/HOOK.md +122 -0
- package/dist/hooks/bundled/session-memory/HOOK.md +109 -0
- package/dist/hooks/bundled/soul-evil/HOOK.md +71 -0
- package/dist/hooks-cli-BZCMAnW2.js +1058 -0
- package/dist/hooks-cli-D0CEFg3P.js +1061 -0
- package/dist/hooks-status-Bn7_O8PM.js +443 -0
- package/dist/hooks-status-BrWVfIn0.js +443 -0
- package/dist/image-BS022pvv.js +1421 -0
- package/dist/image-BzJtY34J.js +629 -0
- package/dist/image-CBqmIbQQ.js +629 -0
- package/dist/index.js +5809 -0
- package/dist/installs-BP4K5L33.js +388 -0
- package/dist/installs-DOpTt7VZ.js +388 -0
- package/dist/is-main-B4o72sqg.js +25 -0
- package/dist/is-main-PYGa3tDA.js +25 -0
- package/dist/links-B4nk2iDf.js +15 -0
- package/dist/links-DwjRqxgR.js +15 -0
- package/dist/loader-Cn4EV_pf.js +63690 -0
- package/dist/logging-CS3tbYDj.js +15 -0
- package/dist/logging-CY-Q5cwf.js +1 -0
- package/dist/logging-DhiLkhLw.js +15 -0
- package/dist/logging-pqyrk15z.js +1 -0
- package/dist/login-qr-CD164Aw1.js +478 -0
- package/dist/login-qr-D7Zdgji2.js +478 -0
- package/dist/login-qr-YgILJ4VC.js +475 -0
- package/dist/logs-cli-BdS0Uv0I.js +227 -0
- package/dist/logs-cli-CqSN1GzB.js +230 -0
- package/dist/manager-CfGY5zND.js +2870 -0
- package/dist/manager-CjuBqFRL.js +2870 -0
- package/dist/manager-CoBEAQKm.js +2872 -0
- package/dist/manifest-registry-Bwjq9Iev.js +668 -0
- package/dist/manifest-registry-D2Yntqcb.js +668 -0
- package/dist/message-channel-Cjsiqxok.js +105 -0
- package/dist/message-channel-D6v_oPAg.js +105 -0
- package/dist/model-selection-Cv5Ox_tY.js +2956 -0
- package/dist/model-selection-Dr-5U5-l.js +2708 -0
- package/dist/models-cli-B39ckynD.js +2541 -0
- package/dist/models-cli-DoiYsBYw.js +2544 -0
- package/dist/net-CFCxaipF.js +137 -0
- package/dist/net-DKJPqXuW.js +137 -0
- package/dist/node-cli-C_FYF-RA.js +1456 -0
- package/dist/node-cli-DWPoNsQS.js +1459 -0
- package/dist/node-service-DcJREOww.js +67 -0
- package/dist/node-service-DuZ9Us9h.js +67 -0
- package/dist/nodes-cli-Elo6tlen.js +1210 -0
- package/dist/nodes-cli-zqryRUWB.js +1207 -0
- package/dist/nodes-screen-C4aCrxie.js +157 -0
- package/dist/nodes-screen-D4PSynkR.js +157 -0
- package/dist/note-CQhSvgQv.js +73 -0
- package/dist/note-_C44YfAQ.js +73 -0
- package/dist/onboard-channels-CHBDi-ZA.js +670 -0
- package/dist/onboard-channels-DOEKyxaL.js +670 -0
- package/dist/onboard-skills-BUTXREDZ.js +3327 -0
- package/dist/onboard-skills-CSLYZmZA.js +3327 -0
- package/dist/onboarding-CgKb8b39.js +3232 -0
- package/dist/openclaw-root-9ILYSmJ9.js +84 -0
- package/dist/openclaw-root-Cvotktkd.js +84 -0
- package/dist/pairing-cli-B4UGR2at.js +114 -0
- package/dist/pairing-cli-BWDDl8cf.js +117 -0
- package/dist/pairing-labels-ClZ-fTWT.js +9 -0
- package/dist/pairing-labels-Ds7BPOkj.js +9 -0
- package/dist/pairing-store-DDLNuzmx.js +391 -0
- package/dist/pairing-store-DRn08lZD.js +391 -0
- package/dist/parse-87ybtYW1.js +23 -0
- package/dist/parse-OCFfznr3.js +23 -0
- package/dist/parse-log-line-C9aL5PUL.js +44 -0
- package/dist/parse-log-line-DxRaGzQb.js +44 -0
- package/dist/parse-timeout-CFqNj7No.js +16 -0
- package/dist/parse-timeout-DV8NQQWk.js +16 -0
- package/dist/path-env-C7kiJUgG.js +77 -0
- package/dist/path-env-DEj4CiFN.js +77 -0
- package/dist/paths-B-q1nXdY.js +43 -0
- package/dist/paths-B1kfl4h5.js +164 -0
- package/dist/paths-B4kigINg.js +40 -0
- package/dist/paths-CHGbP1-A.js +43 -0
- package/dist/paths-scjhy7N2.js +180 -0
- package/dist/pi-embedded-helpers-C19wUpMB.js +8451 -0
- package/dist/pi-embedded-helpers-CT5VuLCb.js +1293 -0
- package/dist/pi-embedded-helpers-Dl8e5Rf8.js +1293 -0
- package/dist/pi-model-discovery-B6CsmK6Y.js +20 -0
- package/dist/pi-model-discovery-DsRqYJLy.js +20 -0
- package/dist/pi-model-discovery-EhM2JAQo.js +20 -0
- package/dist/pi-tools.policy-BvkSDFDN.js +229 -0
- package/dist/plugin-auto-enable-Bd_StZzz.js +461 -0
- package/dist/plugin-auto-enable-DBhXb_0x.js +461 -0
- package/dist/plugin-sdk/agent-scope-DdwUKIOe.js +606 -0
- package/dist/plugin-sdk/chrome-G8apFa5p.js +1953 -0
- package/dist/plugin-sdk/command-format-qUVxzqYm.js +52 -0
- package/dist/plugin-sdk/config-Cm1M7tgH.js +5623 -0
- package/dist/plugin-sdk/deliver-Cl8uowiO.js +2557 -0
- package/dist/plugin-sdk/exec-Cm9b2r9Q.js +1107 -0
- package/dist/plugin-sdk/github-copilot-token-BHNcM4_B.js +103 -0
- package/dist/plugin-sdk/image-7PgoS2VD.js +1421 -0
- package/dist/plugin-sdk/index.d.ts +8908 -0
- package/dist/plugin-sdk/index.js +70888 -0
- package/dist/plugin-sdk/login-qr-qTALvWi2.js +475 -0
- package/dist/plugin-sdk/manager-Cs3EQZCb.js +2870 -0
- package/dist/plugin-sdk/model-selection-BgC1E1a7.js +2708 -0
- package/dist/plugin-sdk/paths-BYpoyRv5.js +164 -0
- package/dist/plugin-sdk/paths-DNQE-bvr.js +40 -0
- package/dist/plugin-sdk/pi-embedded-helpers-5jNqW_dE.js +8755 -0
- package/dist/plugin-sdk/pi-model-discovery-BUGEht9A.js +20 -0
- package/dist/plugin-sdk/pw-ai-COTtei4a.js +1649 -0
- package/dist/plugin-sdk/qmd-manager-ClSwiAJl.js +615 -0
- package/dist/plugin-sdk/redact-2AzjOfk2.js +94 -0
- package/dist/plugin-sdk/rolldown-runtime-Cbj13DAv.js +20 -0
- package/dist/plugin-sdk/sqlite-gCW7MlLs.js +215 -0
- package/dist/plugin-sdk/transcript-events-DGF257vD.js +17 -0
- package/dist/plugins-C3Bm-HQV.js +494 -0
- package/dist/plugins-QJjTXliB.js +495 -0
- package/dist/plugins-cli-DTci0JQb.js +443 -0
- package/dist/plugins-cli-wJsN1HHK.js +440 -0
- package/dist/ports-CiW9dmMq.js +96 -0
- package/dist/program-BWpTHh1I.js +188 -0
- package/dist/progress-Bcjniu7m.js +133 -0
- package/dist/progress-CvaSPjS9.js +133 -0
- package/dist/prompt-style-CFsleyxV.js +9 -0
- package/dist/prompt-style-DYJdrXyV.js +9 -0
- package/dist/prompts-Bt9fwsg2.js +10 -0
- package/dist/prompts-CudpZgTI.js +10 -0
- package/dist/pw-ai-08F3GD-3.js +1649 -0
- package/dist/pw-ai-ZmHxHQnx.js +1651 -0
- package/dist/pw-ai-tNPuRNn3.js +1649 -0
- package/dist/qmd-manager-2r-4n3sP.js +617 -0
- package/dist/qmd-manager-CF52nuBg.js +615 -0
- package/dist/qmd-manager-HEm5H2mk.js +616 -0
- package/dist/redact-BICFkpn7.js +97 -0
- package/dist/redact-BIMJ3ntQ.js +94 -0
- package/dist/redact-KzWHRS5J.js +97 -0
- package/dist/register.subclis-D2K25c84.js +348 -0
- package/dist/register.subclis-Dd8LbOLi.js +342 -0
- package/dist/reply-5UNWRwMn.js +63693 -0
- package/dist/restart-sentinel-Cr0vUxB8.js +65 -0
- package/dist/restart-sentinel-DUemCjgU.js +65 -0
- package/dist/rolldown-runtime-Cbj13DAv.js +20 -0
- package/dist/routes-C6UpTPas.js +2410 -0
- package/dist/routes-ClNyEvlm.js +2410 -0
- package/dist/rpc-D0mf7DIw.js +95 -0
- package/dist/rpc-DYdOrgd9.js +95 -0
- package/dist/run-main-CojI7gWx.js +194 -0
- package/dist/runtime-guard-68M_evhb.js +60 -0
- package/dist/runtime-guard-DkjmhnBD.js +60 -0
- package/dist/sandbox-Ca81z3Tw.js +2924 -0
- package/dist/sandbox-cli-D75GApgp.js +459 -0
- package/dist/sandbox-cli-E4SJsC1C.js +462 -0
- package/dist/sandbox-knontqD9.js +2925 -0
- package/dist/security-cli-BLihvXO-.js +503 -0
- package/dist/security-cli-IGQCsK4g.js +506 -0
- package/dist/server-context-B9GX5GOI.js +740 -0
- package/dist/server-context-BFH7HB_M.js +740 -0
- package/dist/server-node-events-CTdHBiEA.js +218 -0
- package/dist/server-node-events-DAV14qPr.js +215 -0
- package/dist/service-BZNBq9hq.js +680 -0
- package/dist/service-C-BLXx9U.js +680 -0
- package/dist/service-audit-BfJv4NqZ.js +542 -0
- package/dist/service-audit-Bw3M2OEI.js +542 -0
- package/dist/shared-5SH-45AX.js +74 -0
- package/dist/shared-BxRm5uLU.js +74 -0
- package/dist/shared-C80Rmxsd.js +150 -0
- package/dist/shared-fGK6_D2v.js +150 -0
- package/dist/skills-Bhp0l6UK.js +693 -0
- package/dist/skills-Tky2kCMO.js +694 -0
- package/dist/skills-cli-6rCClAE4.js +287 -0
- package/dist/skills-cli-C4nLCrLw.js +290 -0
- package/dist/skills-status-CENcKr3I.js +187 -0
- package/dist/skills-status-DX1eUYvk.js +187 -0
- package/dist/sqlite-CmdZSZRx.js +197 -0
- package/dist/sqlite-Dnmf3LS7.js +215 -0
- package/dist/sqlite-QDf0yuU0.js +215 -0
- package/dist/status-BSfGAp2D.js +27 -0
- package/dist/status-Bp_2NMjt.js +27 -0
- package/dist/status-C0ANDr0T.js +3140 -0
- package/dist/status-CCHBIZnm.js +21 -0
- package/dist/status-Vuqbw2Bb.js +21 -0
- package/dist/status.update-BZW5r8Su.js +79 -0
- package/dist/status.update-BnD93_O8.js +79 -0
- package/dist/subsystem-CAq3uyo7.js +834 -0
- package/dist/system-cli-Bb9zmCO1.js +83 -0
- package/dist/system-cli-TIIQ04ls.js +80 -0
- package/dist/systemd-0Qa_nGqe.js +438 -0
- package/dist/systemd-Czb0Xsm7.js +438 -0
- package/dist/systemd-hints-CWoEOQRb.js +19 -0
- package/dist/systemd-hints-Cv3RN_mZ.js +19 -0
- package/dist/systemd-linger-CsdvcIoS.js +75 -0
- package/dist/systemd-linger-DKUFHcLn.js +75 -0
- package/dist/table-DNPESyNj.js +279 -0
- package/dist/table-DS4-gmkV.js +279 -0
- package/dist/tailnet-Bg_vE5qi.js +42 -0
- package/dist/tailnet-CrNWlQRJ.js +42 -0
- package/dist/tailscale-CBv58toW.js +252 -0
- package/dist/tailscale-DCnMs7_q.js +225 -0
- package/dist/tool-display-BEACy9rK.js +795 -0
- package/dist/tool-display-NYQnSpdo.js +795 -0
- package/dist/transcript-events-CsB1Saa6.js +17 -0
- package/dist/transcript-events-DDYvbmRV.js +17 -0
- package/dist/transcript-events-JLH5W4He.js +17 -0
- package/dist/tui--NY0rnjr.js +2542 -0
- package/dist/tui-DqJfGtvM.js +2543 -0
- package/dist/tui-cli-BuHNY6wF.js +54 -0
- package/dist/tui-cli-LMFV982e.js +57 -0
- package/dist/update-CRpHtCgz.js +317 -0
- package/dist/update-D3qruxhj.js +317 -0
- package/dist/update-cli-CFF-pslM.js +948 -0
- package/dist/update-cli-cn9pEMX7.js +951 -0
- package/dist/update-runner-CxGU142L.js +1221 -0
- package/dist/update-runner-DNobz_ft.js +1221 -0
- package/dist/utils-CKSrBNwq.js +192 -0
- package/dist/utils-DX85MiPR.js +188 -0
- package/dist/webhooks-cli-BGtt2HAR.js +312 -0
- package/dist/webhooks-cli-DHLZrEO_.js +309 -0
- package/dist/widearea-dns-BpG7ATO8.js +127 -0
- package/dist/widearea-dns-D4wkCJly.js +127 -0
- package/dist/ws-3zr8WUwL.js +13 -0
- package/dist/ws-log-BXcT2xQk.js +267 -0
- package/dist/ws-log-DbDIUsgz.js +267 -0
- package/dist/ws-lzrgabja.js +13 -0
- package/dist/wsl-D2O2qOrl.js +160 -0
- package/docs/.i18n/README.md +31 -0
- package/docs/.i18n/glossary.zh-CN.json +190 -0
- package/docs/.i18n/zh-CN.tm.jsonl +1329 -0
- package/docs/CNAME +1 -0
- package/docs/_config.yml +53 -0
- package/docs/_layouts/default.html +145 -0
- package/docs/assets/markdown.css +179 -0
- package/docs/assets/openclaw-logo-text-dark.png +0 -0
- package/docs/assets/openclaw-logo-text.png +0 -0
- package/docs/assets/pixel-lobster.svg +60 -0
- package/docs/assets/showcase/agents-ui.jpg +0 -0
- package/docs/assets/showcase/bambu-cli.png +0 -0
- package/docs/assets/showcase/codexmonitor.png +0 -0
- package/docs/assets/showcase/gohome-grafana.png +0 -0
- package/docs/assets/showcase/ios-testflight.jpg +0 -0
- package/docs/assets/showcase/oura-health.png +0 -0
- package/docs/assets/showcase/padel-cli.svg +11 -0
- package/docs/assets/showcase/padel-screenshot.jpg +0 -0
- package/docs/assets/showcase/papla-tts.jpg +0 -0
- package/docs/assets/showcase/pr-review-telegram.jpg +0 -0
- package/docs/assets/showcase/roborock-screenshot.jpg +0 -0
- package/docs/assets/showcase/roborock-status.svg +13 -0
- package/docs/assets/showcase/roof-camera-sky.jpg +0 -0
- package/docs/assets/showcase/snag.png +0 -0
- package/docs/assets/showcase/tesco-shop.jpg +0 -0
- package/docs/assets/showcase/wienerlinien.png +0 -0
- package/docs/assets/showcase/wine-cellar-skill.jpg +0 -0
- package/docs/assets/showcase/winix-air-purifier.jpg +0 -0
- package/docs/assets/showcase/xuezh-pronunciation.jpeg +0 -0
- package/docs/assets/terminal.css +473 -0
- package/docs/assets/theme.js +55 -0
- package/docs/automation/auth-monitoring.md +44 -0
- package/docs/automation/cron-jobs.md +468 -0
- package/docs/automation/cron-vs-heartbeat.md +282 -0
- package/docs/automation/gmail-pubsub.md +256 -0
- package/docs/automation/poll.md +69 -0
- package/docs/automation/webhook.md +163 -0
- package/docs/bedrock.md +176 -0
- package/docs/brave-search.md +41 -0
- package/docs/broadcast-groups.md +442 -0
- package/docs/channels/bluebubbles.md +338 -0
- package/docs/channels/discord.md +475 -0
- package/docs/channels/feishu.md +507 -0
- package/docs/channels/googlechat.md +250 -0
- package/docs/channels/grammy.md +31 -0
- package/docs/channels/imessage.md +299 -0
- package/docs/channels/index.md +46 -0
- package/docs/channels/line.md +186 -0
- package/docs/channels/location.md +56 -0
- package/docs/channels/matrix.md +233 -0
- package/docs/channels/mattermost.md +138 -0
- package/docs/channels/msteams.md +768 -0
- package/docs/channels/nextcloud-talk.md +136 -0
- package/docs/channels/nostr.md +233 -0
- package/docs/channels/signal.md +202 -0
- package/docs/channels/slack.md +548 -0
- package/docs/channels/telegram.md +750 -0
- package/docs/channels/tlon.md +132 -0
- package/docs/channels/troubleshooting.md +29 -0
- package/docs/channels/twitch.md +379 -0
- package/docs/channels/whatsapp.md +404 -0
- package/docs/channels/zalo.md +189 -0
- package/docs/channels/zalouser.md +140 -0
- package/docs/cli/acp.md +170 -0
- package/docs/cli/agent.md +24 -0
- package/docs/cli/agents.md +75 -0
- package/docs/cli/approvals.md +50 -0
- package/docs/cli/browser.md +107 -0
- package/docs/cli/channels.md +79 -0
- package/docs/cli/config.md +50 -0
- package/docs/cli/configure.md +33 -0
- package/docs/cli/cron.md +42 -0
- package/docs/cli/dashboard.md +16 -0
- package/docs/cli/devices.md +67 -0
- package/docs/cli/directory.md +63 -0
- package/docs/cli/dns.md +23 -0
- package/docs/cli/docs.md +15 -0
- package/docs/cli/doctor.md +41 -0
- package/docs/cli/gateway.md +199 -0
- package/docs/cli/health.md +21 -0
- package/docs/cli/hooks.md +304 -0
- package/docs/cli/index.md +1029 -0
- package/docs/cli/logs.md +24 -0
- package/docs/cli/memory.md +45 -0
- package/docs/cli/message.md +239 -0
- package/docs/cli/models.md +79 -0
- package/docs/cli/node.md +112 -0
- package/docs/cli/nodes.md +73 -0
- package/docs/cli/onboard.md +29 -0
- package/docs/cli/pairing.md +21 -0
- package/docs/cli/plugins.md +62 -0
- package/docs/cli/reset.md +17 -0
- package/docs/cli/sandbox.md +152 -0
- package/docs/cli/security.md +26 -0
- package/docs/cli/sessions.md +16 -0
- package/docs/cli/setup.md +29 -0
- package/docs/cli/skills.md +26 -0
- package/docs/cli/status.md +26 -0
- package/docs/cli/system.md +60 -0
- package/docs/cli/tui.md +23 -0
- package/docs/cli/uninstall.md +17 -0
- package/docs/cli/update.md +98 -0
- package/docs/cli/voicecall.md +34 -0
- package/docs/cli/webhooks.md +25 -0
- package/docs/concepts/agent-loop.md +146 -0
- package/docs/concepts/agent-workspace.md +233 -0
- package/docs/concepts/agent.md +123 -0
- package/docs/concepts/architecture.md +129 -0
- package/docs/concepts/channel-routing.md +114 -0
- package/docs/concepts/compaction.md +61 -0
- package/docs/concepts/context.md +161 -0
- package/docs/concepts/group-messages.md +84 -0
- package/docs/concepts/groups.md +373 -0
- package/docs/concepts/markdown-formatting.md +130 -0
- package/docs/concepts/memory.md +546 -0
- package/docs/concepts/messages.md +154 -0
- package/docs/concepts/model-failover.md +149 -0
- package/docs/concepts/model-providers.md +316 -0
- package/docs/concepts/models.md +208 -0
- package/docs/concepts/multi-agent.md +376 -0
- package/docs/concepts/oauth.md +145 -0
- package/docs/concepts/presence.md +102 -0
- package/docs/concepts/queue.md +89 -0
- package/docs/concepts/retry.md +69 -0
- package/docs/concepts/session-pruning.md +122 -0
- package/docs/concepts/session-tool.md +193 -0
- package/docs/concepts/session.md +188 -0
- package/docs/concepts/sessions.md +10 -0
- package/docs/concepts/streaming.md +135 -0
- package/docs/concepts/system-prompt.md +115 -0
- package/docs/concepts/timezone.md +91 -0
- package/docs/concepts/typebox.md +289 -0
- package/docs/concepts/typing-indicators.md +68 -0
- package/docs/concepts/usage-tracking.md +35 -0
- package/docs/date-time.md +128 -0
- package/docs/debug/node-issue.md +83 -0
- package/docs/debugging.md +162 -0
- package/docs/diagnostics/flags.md +91 -0
- package/docs/docs.json +1587 -0
- package/docs/environment.md +81 -0
- package/docs/experiments/onboarding-config-protocol.md +40 -0
- package/docs/experiments/plans/cron-add-hardening.md +63 -0
- package/docs/experiments/plans/group-policy-hardening.md +40 -0
- package/docs/experiments/plans/openresponses-gateway.md +123 -0
- package/docs/experiments/proposals/model-config.md +36 -0
- package/docs/experiments/research/memory.md +228 -0
- package/docs/gateway/authentication.md +145 -0
- package/docs/gateway/background-process.md +93 -0
- package/docs/gateway/bonjour.md +167 -0
- package/docs/gateway/bridge-protocol.md +89 -0
- package/docs/gateway/cli-backends.md +223 -0
- package/docs/gateway/configuration-examples.md +606 -0
- package/docs/gateway/configuration.md +3393 -0
- package/docs/gateway/discovery.md +116 -0
- package/docs/gateway/doctor.md +282 -0
- package/docs/gateway/gateway-lock.md +34 -0
- package/docs/gateway/health.md +35 -0
- package/docs/gateway/heartbeat.md +302 -0
- package/docs/gateway/index.md +328 -0
- package/docs/gateway/local-models.md +150 -0
- package/docs/gateway/logging.md +113 -0
- package/docs/gateway/multiple-gateways.md +112 -0
- package/docs/gateway/openai-http-api.md +118 -0
- package/docs/gateway/openresponses-http-api.md +317 -0
- package/docs/gateway/pairing.md +99 -0
- package/docs/gateway/protocol.md +221 -0
- package/docs/gateway/remote-gateway-readme.md +157 -0
- package/docs/gateway/remote.md +127 -0
- package/docs/gateway/sandbox-vs-tool-policy-vs-elevated.md +128 -0
- package/docs/gateway/sandboxing.md +193 -0
- package/docs/gateway/security/formal-verification.md +164 -0
- package/docs/gateway/security/index.md +825 -0
- package/docs/gateway/tailscale.md +127 -0
- package/docs/gateway/tools-invoke-http-api.md +85 -0
- package/docs/gateway/troubleshooting.md +767 -0
- package/docs/help/faq.md +2830 -0
- package/docs/help/index.md +21 -0
- package/docs/help/troubleshooting.md +98 -0
- package/docs/hooks/soul-evil.md +69 -0
- package/docs/hooks.md +913 -0
- package/docs/images/feishu-step2-create-app.png +0 -0
- package/docs/images/feishu-step3-credentials.png +0 -0
- package/docs/images/feishu-step4-permissions.png +0 -0
- package/docs/images/feishu-step5-bot-capability.png +0 -0
- package/docs/images/feishu-step6-event-subscription.png +0 -0
- package/docs/images/groups-flow.svg +52 -0
- package/docs/images/mobile-ui-screenshot.png +0 -0
- package/docs/index.md +258 -0
- package/docs/install/ansible.md +208 -0
- package/docs/install/bun.md +59 -0
- package/docs/install/development-channels.md +75 -0
- package/docs/install/docker.md +567 -0
- package/docs/install/index.md +185 -0
- package/docs/install/installer.md +123 -0
- package/docs/install/migrating.md +192 -0
- package/docs/install/nix.md +96 -0
- package/docs/install/node.md +78 -0
- package/docs/install/uninstall.md +128 -0
- package/docs/install/updating.md +228 -0
- package/docs/logging.md +350 -0
- package/docs/multi-agent-sandbox-tools.md +395 -0
- package/docs/network.md +54 -0
- package/docs/nodes/audio.md +114 -0
- package/docs/nodes/camera.md +156 -0
- package/docs/nodes/images.md +72 -0
- package/docs/nodes/index.md +341 -0
- package/docs/nodes/location-command.md +113 -0
- package/docs/nodes/media-understanding.md +379 -0
- package/docs/nodes/talk.md +90 -0
- package/docs/nodes/voicewake.md +65 -0
- package/docs/northflank.mdx +53 -0
- package/docs/perplexity.md +80 -0
- package/docs/pi-dev.md +70 -0
- package/docs/pi.md +612 -0
- package/docs/platforms/android.md +148 -0
- package/docs/platforms/digitalocean.md +262 -0
- package/docs/platforms/exe-dev.md +125 -0
- package/docs/platforms/fly.md +486 -0
- package/docs/platforms/gcp.md +503 -0
- package/docs/platforms/hetzner.md +330 -0
- package/docs/platforms/index.md +53 -0
- package/docs/platforms/ios.md +107 -0
- package/docs/platforms/linux.md +94 -0
- package/docs/platforms/mac/bundled-gateway.md +73 -0
- package/docs/platforms/mac/canvas.md +125 -0
- package/docs/platforms/mac/child-process.md +69 -0
- package/docs/platforms/mac/dev-setup.md +102 -0
- package/docs/platforms/mac/health.md +34 -0
- package/docs/platforms/mac/icon.md +31 -0
- package/docs/platforms/mac/logging.md +57 -0
- package/docs/platforms/mac/menu-bar.md +81 -0
- package/docs/platforms/mac/peekaboo.md +65 -0
- package/docs/platforms/mac/permissions.md +44 -0
- package/docs/platforms/mac/release.md +85 -0
- package/docs/platforms/mac/remote.md +83 -0
- package/docs/platforms/mac/signing.md +47 -0
- package/docs/platforms/mac/skills.md +33 -0
- package/docs/platforms/mac/voice-overlay.md +60 -0
- package/docs/platforms/mac/voicewake.md +67 -0
- package/docs/platforms/mac/webchat.md +41 -0
- package/docs/platforms/mac/xpc.md +61 -0
- package/docs/platforms/macos-vm.md +281 -0
- package/docs/platforms/macos.md +203 -0
- package/docs/platforms/oracle.md +303 -0
- package/docs/platforms/raspberry-pi.md +358 -0
- package/docs/platforms/windows.md +159 -0
- package/docs/plugin.md +664 -0
- package/docs/plugins/agent-tools.md +99 -0
- package/docs/plugins/manifest.md +71 -0
- package/docs/plugins/voice-call.md +284 -0
- package/docs/plugins/zalouser.md +81 -0
- package/docs/prose.md +134 -0
- package/docs/providers/anthropic.md +152 -0
- package/docs/providers/claude-max-api-proxy.md +148 -0
- package/docs/providers/cloudflare-ai-gateway.md +71 -0
- package/docs/providers/deepgram.md +93 -0
- package/docs/providers/github-copilot.md +72 -0
- package/docs/providers/glm.md +33 -0
- package/docs/providers/index.md +63 -0
- package/docs/providers/minimax.md +208 -0
- package/docs/providers/models.md +51 -0
- package/docs/providers/moonshot.md +142 -0
- package/docs/providers/ollama.md +223 -0
- package/docs/providers/openai.md +62 -0
- package/docs/providers/opencode.md +36 -0
- package/docs/providers/openrouter.md +37 -0
- package/docs/providers/qwen.md +53 -0
- package/docs/providers/synthetic.md +99 -0
- package/docs/providers/venice.md +267 -0
- package/docs/providers/vercel-ai-gateway.md +50 -0
- package/docs/providers/xiaomi.md +64 -0
- package/docs/providers/zai.md +36 -0
- package/docs/railway.mdx +99 -0
- package/docs/refactor/clawnet.md +417 -0
- package/docs/refactor/exec-host.md +316 -0
- package/docs/refactor/outbound-session-mirroring.md +85 -0
- package/docs/refactor/plugin-sdk.md +214 -0
- package/docs/refactor/strict-config.md +93 -0
- package/docs/reference/AGENTS.default.md +124 -0
- package/docs/reference/RELEASING.md +120 -0
- package/docs/reference/api-usage-costs.md +137 -0
- package/docs/reference/device-models.md +47 -0
- package/docs/reference/rpc.md +43 -0
- package/docs/reference/session-management-compaction.md +285 -0
- package/docs/reference/templates/AGENTS.dev.md +83 -0
- package/docs/reference/templates/AGENTS.md +218 -0
- package/docs/reference/templates/BOOT.md +10 -0
- package/docs/reference/templates/BOOTSTRAP.md +61 -0
- package/docs/reference/templates/HEARTBEAT.md +11 -0
- package/docs/reference/templates/IDENTITY.dev.md +47 -0
- package/docs/reference/templates/IDENTITY.md +27 -0
- package/docs/reference/templates/SOUL.dev.md +76 -0
- package/docs/reference/templates/SOUL.md +42 -0
- package/docs/reference/templates/TOOLS.dev.md +24 -0
- package/docs/reference/templates/TOOLS.md +46 -0
- package/docs/reference/templates/USER.dev.md +18 -0
- package/docs/reference/templates/USER.md +22 -0
- package/docs/reference/test.md +50 -0
- package/docs/reference/transcript-hygiene.md +129 -0
- package/docs/render.mdx +165 -0
- package/docs/scripts.md +28 -0
- package/docs/security/formal-verification.md +164 -0
- package/docs/start/getting-started.md +208 -0
- package/docs/start/hubs.md +185 -0
- package/docs/start/lore.md +219 -0
- package/docs/start/onboarding.md +110 -0
- package/docs/start/openclaw.md +241 -0
- package/docs/start/pairing.md +86 -0
- package/docs/start/setup.md +149 -0
- package/docs/start/showcase.md +416 -0
- package/docs/start/wizard.md +349 -0
- package/docs/testing.md +368 -0
- package/docs/token-use.md +112 -0
- package/docs/tools/agent-send.md +53 -0
- package/docs/tools/apply-patch.md +50 -0
- package/docs/tools/browser-linux-troubleshooting.md +139 -0
- package/docs/tools/browser-login.md +68 -0
- package/docs/tools/browser.md +576 -0
- package/docs/tools/chrome-extension.md +178 -0
- package/docs/tools/clawhub.md +257 -0
- package/docs/tools/creating-skills.md +54 -0
- package/docs/tools/elevated.md +57 -0
- package/docs/tools/exec-approvals.md +246 -0
- package/docs/tools/exec.md +179 -0
- package/docs/tools/firecrawl.md +61 -0
- package/docs/tools/index.md +509 -0
- package/docs/tools/llm-task.md +115 -0
- package/docs/tools/lobster.md +342 -0
- package/docs/tools/reactions.md +22 -0
- package/docs/tools/skills-config.md +76 -0
- package/docs/tools/skills.md +300 -0
- package/docs/tools/slash-commands.md +198 -0
- package/docs/tools/subagents.md +151 -0
- package/docs/tools/thinking.md +73 -0
- package/docs/tools/web.md +261 -0
- package/docs/tts.md +396 -0
- package/docs/tui.md +159 -0
- package/docs/vps.md +43 -0
- package/docs/web/control-ui.md +221 -0
- package/docs/web/dashboard.md +46 -0
- package/docs/web/index.md +116 -0
- package/docs/web/webchat.md +49 -0
- package/docs/whatsapp-openclaw-ai-zh.jpg +0 -0
- package/docs/whatsapp-openclaw.jpg +0 -0
- package/docs/zh-CN/AGENTS.md +59 -0
- package/docs/zh-CN/automation/auth-monitoring.md +47 -0
- package/docs/zh-CN/automation/cron-jobs.md +424 -0
- package/docs/zh-CN/automation/cron-vs-heartbeat.md +286 -0
- package/docs/zh-CN/automation/gmail-pubsub.md +249 -0
- package/docs/zh-CN/automation/poll.md +76 -0
- package/docs/zh-CN/automation/webhook.md +163 -0
- package/docs/zh-CN/bedrock.md +170 -0
- package/docs/zh-CN/brave-search.md +48 -0
- package/docs/zh-CN/broadcast-groups.md +449 -0
- package/docs/zh-CN/channels/bluebubbles.md +271 -0
- package/docs/zh-CN/channels/discord.md +468 -0
- package/docs/zh-CN/channels/feishu.md +513 -0
- package/docs/zh-CN/channels/googlechat.md +257 -0
- package/docs/zh-CN/channels/grammy.md +38 -0
- package/docs/zh-CN/channels/imessage.md +302 -0
- package/docs/zh-CN/channels/index.md +53 -0
- package/docs/zh-CN/channels/line.md +180 -0
- package/docs/zh-CN/channels/location.md +63 -0
- package/docs/zh-CN/channels/matrix.md +221 -0
- package/docs/zh-CN/channels/mattermost.md +144 -0
- package/docs/zh-CN/channels/msteams.md +775 -0
- package/docs/zh-CN/channels/nextcloud-talk.md +142 -0
- package/docs/zh-CN/channels/nostr.md +240 -0
- package/docs/zh-CN/channels/signal.md +209 -0
- package/docs/zh-CN/channels/slack.md +531 -0
- package/docs/zh-CN/channels/telegram.md +751 -0
- package/docs/zh-CN/channels/tlon.md +136 -0
- package/docs/zh-CN/channels/troubleshooting.md +36 -0
- package/docs/zh-CN/channels/twitch.md +385 -0
- package/docs/zh-CN/channels/whatsapp.md +411 -0
- package/docs/zh-CN/channels/zalo.md +196 -0
- package/docs/zh-CN/channels/zalouser.md +147 -0
- package/docs/zh-CN/cli/acp.md +173 -0
- package/docs/zh-CN/cli/agent.md +30 -0
- package/docs/zh-CN/cli/agents.md +82 -0
- package/docs/zh-CN/cli/approvals.md +57 -0
- package/docs/zh-CN/cli/browser.md +114 -0
- package/docs/zh-CN/cli/channels.md +86 -0
- package/docs/zh-CN/cli/config.md +57 -0
- package/docs/zh-CN/cli/configure.md +38 -0
- package/docs/zh-CN/cli/cron.md +43 -0
- package/docs/zh-CN/cli/dashboard.md +23 -0
- package/docs/zh-CN/cli/devices.md +74 -0
- package/docs/zh-CN/cli/directory.md +70 -0
- package/docs/zh-CN/cli/dns.md +30 -0
- package/docs/zh-CN/cli/docs.md +22 -0
- package/docs/zh-CN/cli/doctor.md +48 -0
- package/docs/zh-CN/cli/gateway.md +206 -0
- package/docs/zh-CN/cli/health.md +28 -0
- package/docs/zh-CN/cli/hooks.md +311 -0
- package/docs/zh-CN/cli/index.md +1032 -0
- package/docs/zh-CN/cli/logs.md +31 -0
- package/docs/zh-CN/cli/memory.md +52 -0
- package/docs/zh-CN/cli/message.md +246 -0
- package/docs/zh-CN/cli/models.md +85 -0
- package/docs/zh-CN/cli/node.md +115 -0
- package/docs/zh-CN/cli/nodes.md +80 -0
- package/docs/zh-CN/cli/onboard.md +36 -0
- package/docs/zh-CN/cli/pairing.md +28 -0
- package/docs/zh-CN/cli/plugins.md +66 -0
- package/docs/zh-CN/cli/reset.md +24 -0
- package/docs/zh-CN/cli/sandbox.md +158 -0
- package/docs/zh-CN/cli/security.md +33 -0
- package/docs/zh-CN/cli/sessions.md +23 -0
- package/docs/zh-CN/cli/setup.md +36 -0
- package/docs/zh-CN/cli/skills.md +33 -0
- package/docs/zh-CN/cli/status.md +33 -0
- package/docs/zh-CN/cli/system.md +63 -0
- package/docs/zh-CN/cli/tui.md +30 -0
- package/docs/zh-CN/cli/uninstall.md +24 -0
- package/docs/zh-CN/cli/update.md +101 -0
- package/docs/zh-CN/cli/voicecall.md +41 -0
- package/docs/zh-CN/cli/webhooks.md +32 -0
- package/docs/zh-CN/concepts/agent-loop.md +146 -0
- package/docs/zh-CN/concepts/agent-workspace.md +219 -0
- package/docs/zh-CN/concepts/agent.md +115 -0
- package/docs/zh-CN/concepts/architecture.md +123 -0
- package/docs/zh-CN/concepts/channel-routing.md +117 -0
- package/docs/zh-CN/concepts/compaction.md +67 -0
- package/docs/zh-CN/concepts/context.md +168 -0
- package/docs/zh-CN/concepts/group-messages.md +91 -0
- package/docs/zh-CN/concepts/groups.md +379 -0
- package/docs/zh-CN/concepts/markdown-formatting.md +117 -0
- package/docs/zh-CN/concepts/memory.md +412 -0
- package/docs/zh-CN/concepts/messages.md +141 -0
- package/docs/zh-CN/concepts/model-failover.md +145 -0
- package/docs/zh-CN/concepts/model-providers.md +320 -0
- package/docs/zh-CN/concepts/models.md +196 -0
- package/docs/zh-CN/concepts/multi-agent.md +372 -0
- package/docs/zh-CN/concepts/oauth.md +151 -0
- package/docs/zh-CN/concepts/presence.md +99 -0
- package/docs/zh-CN/concepts/queue.md +94 -0
- package/docs/zh-CN/concepts/retry.md +76 -0
- package/docs/zh-CN/concepts/session-pruning.md +129 -0
- package/docs/zh-CN/concepts/session-tool.md +200 -0
- package/docs/zh-CN/concepts/session.md +166 -0
- package/docs/zh-CN/concepts/sessions.md +17 -0
- package/docs/zh-CN/concepts/streaming.md +133 -0
- package/docs/zh-CN/concepts/system-prompt.md +101 -0
- package/docs/zh-CN/concepts/timezone.md +96 -0
- package/docs/zh-CN/concepts/typebox.md +284 -0
- package/docs/zh-CN/concepts/typing-indicators.md +74 -0
- package/docs/zh-CN/concepts/usage-tracking.md +42 -0
- package/docs/zh-CN/date-time.md +129 -0
- package/docs/zh-CN/debug/node-issue.md +90 -0
- package/docs/zh-CN/debugging.md +160 -0
- package/docs/zh-CN/diagnostics/flags.md +98 -0
- package/docs/zh-CN/environment.md +88 -0
- package/docs/zh-CN/experiments/onboarding-config-protocol.md +47 -0
- package/docs/zh-CN/experiments/plans/cron-add-hardening.md +70 -0
- package/docs/zh-CN/experiments/plans/group-policy-hardening.md +45 -0
- package/docs/zh-CN/experiments/plans/openresponses-gateway.md +121 -0
- package/docs/zh-CN/experiments/proposals/model-config.md +42 -0
- package/docs/zh-CN/experiments/research/memory.md +235 -0
- package/docs/zh-CN/gateway/authentication.md +142 -0
- package/docs/zh-CN/gateway/background-process.md +100 -0
- package/docs/zh-CN/gateway/bonjour.md +174 -0
- package/docs/zh-CN/gateway/bridge-protocol.md +86 -0
- package/docs/zh-CN/gateway/cli-backends.md +213 -0
- package/docs/zh-CN/gateway/configuration-examples.md +587 -0
- package/docs/zh-CN/gateway/configuration.md +3332 -0
- package/docs/zh-CN/gateway/discovery.md +123 -0
- package/docs/zh-CN/gateway/doctor.md +238 -0
- package/docs/zh-CN/gateway/gateway-lock.md +41 -0
- package/docs/zh-CN/gateway/health.md +42 -0
- package/docs/zh-CN/gateway/heartbeat.md +274 -0
- package/docs/zh-CN/gateway/index.md +335 -0
- package/docs/zh-CN/gateway/local-models.md +157 -0
- package/docs/zh-CN/gateway/logging.md +114 -0
- package/docs/zh-CN/gateway/multiple-gateways.md +119 -0
- package/docs/zh-CN/gateway/openai-http-api.md +125 -0
- package/docs/zh-CN/gateway/openresponses-http-api.md +317 -0
- package/docs/zh-CN/gateway/pairing.md +99 -0
- package/docs/zh-CN/gateway/protocol.md +220 -0
- package/docs/zh-CN/gateway/remote-gateway-readme.md +164 -0
- package/docs/zh-CN/gateway/remote.md +133 -0
- package/docs/zh-CN/gateway/sandbox-vs-tool-policy-vs-elevated.md +135 -0
- package/docs/zh-CN/gateway/sandboxing.md +188 -0
- package/docs/zh-CN/gateway/security/formal-verification.md +169 -0
- package/docs/zh-CN/gateway/security/index.md +777 -0
- package/docs/zh-CN/gateway/tailscale.md +124 -0
- package/docs/zh-CN/gateway/tools-invoke-http-api.md +92 -0
- package/docs/zh-CN/gateway/troubleshooting.md +771 -0
- package/docs/zh-CN/help/faq.md +2628 -0
- package/docs/zh-CN/help/index.md +28 -0
- package/docs/zh-CN/help/troubleshooting.md +104 -0
- package/docs/zh-CN/hooks/soul-evil.md +72 -0
- package/docs/zh-CN/hooks.md +919 -0
- package/docs/zh-CN/index.md +264 -0
- package/docs/zh-CN/install/ansible.md +215 -0
- package/docs/zh-CN/install/bun.md +65 -0
- package/docs/zh-CN/install/development-channels.md +81 -0
- package/docs/zh-CN/install/docker.md +532 -0
- package/docs/zh-CN/install/index.md +193 -0
- package/docs/zh-CN/install/installer.md +128 -0
- package/docs/zh-CN/install/migrating.md +199 -0
- package/docs/zh-CN/install/nix.md +99 -0
- package/docs/zh-CN/install/node.md +85 -0
- package/docs/zh-CN/install/uninstall.md +135 -0
- package/docs/zh-CN/install/updating.md +233 -0
- package/docs/zh-CN/logging.md +329 -0
- package/docs/zh-CN/multi-agent-sandbox-tools.md +401 -0
- package/docs/zh-CN/network.md +59 -0
- package/docs/zh-CN/nodes/audio.md +120 -0
- package/docs/zh-CN/nodes/camera.md +162 -0
- package/docs/zh-CN/nodes/images.md +79 -0
- package/docs/zh-CN/nodes/index.md +348 -0
- package/docs/zh-CN/nodes/location-command.md +120 -0
- package/docs/zh-CN/nodes/media-understanding.md +380 -0
- package/docs/zh-CN/nodes/talk.md +97 -0
- package/docs/zh-CN/nodes/voicewake.md +72 -0
- package/docs/zh-CN/northflank.mdx +60 -0
- package/docs/zh-CN/perplexity.md +84 -0
- package/docs/zh-CN/pi-dev.md +77 -0
- package/docs/zh-CN/pi.md +619 -0
- package/docs/zh-CN/platforms/android.md +155 -0
- package/docs/zh-CN/platforms/digitalocean.md +269 -0
- package/docs/zh-CN/platforms/exe-dev.md +127 -0
- package/docs/zh-CN/platforms/fly.md +490 -0
- package/docs/zh-CN/platforms/gcp.md +510 -0
- package/docs/zh-CN/platforms/hetzner.md +337 -0
- package/docs/zh-CN/platforms/index.md +60 -0
- package/docs/zh-CN/platforms/ios.md +114 -0
- package/docs/zh-CN/platforms/linux.md +101 -0
- package/docs/zh-CN/platforms/mac/bundled-gateway.md +75 -0
- package/docs/zh-CN/platforms/mac/canvas.md +128 -0
- package/docs/zh-CN/platforms/mac/child-process.md +73 -0
- package/docs/zh-CN/platforms/mac/dev-setup.md +109 -0
- package/docs/zh-CN/platforms/mac/health.md +41 -0
- package/docs/zh-CN/platforms/mac/icon.md +38 -0
- package/docs/zh-CN/platforms/mac/logging.md +64 -0
- package/docs/zh-CN/platforms/mac/menu-bar.md +88 -0
- package/docs/zh-CN/platforms/mac/peekaboo.md +62 -0
- package/docs/zh-CN/platforms/mac/permissions.md +46 -0
- package/docs/zh-CN/platforms/mac/release.md +92 -0
- package/docs/zh-CN/platforms/mac/remote.md +90 -0
- package/docs/zh-CN/platforms/mac/signing.md +54 -0
- package/docs/zh-CN/platforms/mac/skills.md +40 -0
- package/docs/zh-CN/platforms/mac/voice-overlay.md +67 -0
- package/docs/zh-CN/platforms/mac/voicewake.md +74 -0
- package/docs/zh-CN/platforms/mac/webchat.md +43 -0
- package/docs/zh-CN/platforms/mac/xpc.md +68 -0
- package/docs/zh-CN/platforms/macos-vm.md +288 -0
- package/docs/zh-CN/platforms/macos.md +193 -0
- package/docs/zh-CN/platforms/oracle.md +310 -0
- package/docs/zh-CN/platforms/raspberry-pi.md +365 -0
- package/docs/zh-CN/platforms/windows.md +156 -0
- package/docs/zh-CN/plugin.md +639 -0
- package/docs/zh-CN/plugins/agent-tools.md +99 -0
- package/docs/zh-CN/plugins/manifest.md +68 -0
- package/docs/zh-CN/plugins/voice-call.md +250 -0
- package/docs/zh-CN/plugins/zalouser.md +88 -0
- package/docs/zh-CN/prose.md +141 -0
- package/docs/zh-CN/providers/anthropic.md +159 -0
- package/docs/zh-CN/providers/claude-max-api-proxy.md +155 -0
- package/docs/zh-CN/providers/deepgram.md +97 -0
- package/docs/zh-CN/providers/github-copilot.md +67 -0
- package/docs/zh-CN/providers/glm.md +39 -0
- package/docs/zh-CN/providers/index.md +68 -0
- package/docs/zh-CN/providers/minimax.md +206 -0
- package/docs/zh-CN/providers/models.md +55 -0
- package/docs/zh-CN/providers/moonshot.md +145 -0
- package/docs/zh-CN/providers/ollama.md +230 -0
- package/docs/zh-CN/providers/openai.md +68 -0
- package/docs/zh-CN/providers/opencode.md +41 -0
- package/docs/zh-CN/providers/openrouter.md +43 -0
- package/docs/zh-CN/providers/qwen.md +55 -0
- package/docs/zh-CN/providers/synthetic.md +102 -0
- package/docs/zh-CN/providers/venice.md +274 -0
- package/docs/zh-CN/providers/vercel-ai-gateway.md +57 -0
- package/docs/zh-CN/providers/xiaomi.md +68 -0
- package/docs/zh-CN/providers/zai.md +41 -0
- package/docs/zh-CN/railway.mdx +106 -0
- package/docs/zh-CN/refactor/clawnet.md +424 -0
- package/docs/zh-CN/refactor/exec-host.md +323 -0
- package/docs/zh-CN/refactor/outbound-session-mirroring.md +92 -0
- package/docs/zh-CN/refactor/plugin-sdk.md +221 -0
- package/docs/zh-CN/refactor/strict-config.md +100 -0
- package/docs/zh-CN/reference/AGENTS.default.md +131 -0
- package/docs/zh-CN/reference/RELEASING.md +123 -0
- package/docs/zh-CN/reference/api-usage-costs.md +136 -0
- package/docs/zh-CN/reference/device-models.md +54 -0
- package/docs/zh-CN/reference/rpc.md +48 -0
- package/docs/zh-CN/reference/session-management-compaction.md +287 -0
- package/docs/zh-CN/reference/templates/AGENTS.dev.md +89 -0
- package/docs/zh-CN/reference/templates/AGENTS.md +225 -0
- package/docs/zh-CN/reference/templates/BOOT.md +17 -0
- package/docs/zh-CN/reference/templates/BOOTSTRAP.md +68 -0
- package/docs/zh-CN/reference/templates/HEARTBEAT.md +18 -0
- package/docs/zh-CN/reference/templates/IDENTITY.dev.md +54 -0
- package/docs/zh-CN/reference/templates/IDENTITY.md +35 -0
- package/docs/zh-CN/reference/templates/SOUL.dev.md +83 -0
- package/docs/zh-CN/reference/templates/SOUL.md +49 -0
- package/docs/zh-CN/reference/templates/TOOLS.dev.md +31 -0
- package/docs/zh-CN/reference/templates/TOOLS.md +53 -0
- package/docs/zh-CN/reference/templates/USER.dev.md +25 -0
- package/docs/zh-CN/reference/templates/USER.md +30 -0
- package/docs/zh-CN/reference/test.md +57 -0
- package/docs/zh-CN/reference/transcript-hygiene.md +109 -0
- package/docs/zh-CN/render.mdx +169 -0
- package/docs/zh-CN/scripts.md +35 -0
- package/docs/zh-CN/security/formal-verification.md +171 -0
- package/docs/zh-CN/start/getting-started.md +206 -0
- package/docs/zh-CN/start/hubs.md +191 -0
- package/docs/zh-CN/start/lore.md +226 -0
- package/docs/zh-CN/start/onboarding.md +105 -0
- package/docs/zh-CN/start/openclaw.md +248 -0
- package/docs/zh-CN/start/pairing.md +89 -0
- package/docs/zh-CN/start/setup.md +153 -0
- package/docs/zh-CN/start/showcase.md +423 -0
- package/docs/zh-CN/start/wizard.md +331 -0
- package/docs/zh-CN/testing.md +375 -0
- package/docs/zh-CN/token-use.md +119 -0
- package/docs/zh-CN/tools/agent-send.md +59 -0
- package/docs/zh-CN/tools/apply-patch.md +57 -0
- package/docs/zh-CN/tools/browser-linux-troubleshooting.md +144 -0
- package/docs/zh-CN/tools/browser-login.md +75 -0
- package/docs/zh-CN/tools/browser.md +553 -0
- package/docs/zh-CN/tools/chrome-extension.md +183 -0
- package/docs/zh-CN/tools/clawhub.md +209 -0
- package/docs/zh-CN/tools/creating-skills.md +61 -0
- package/docs/zh-CN/tools/elevated.md +64 -0
- package/docs/zh-CN/tools/exec-approvals.md +234 -0
- package/docs/zh-CN/tools/exec.md +169 -0
- package/docs/zh-CN/tools/firecrawl.md +68 -0
- package/docs/zh-CN/tools/index.md +515 -0
- package/docs/zh-CN/tools/llm-task.md +117 -0
- package/docs/zh-CN/tools/lobster.md +349 -0
- package/docs/zh-CN/tools/reactions.md +29 -0
- package/docs/zh-CN/tools/skills-config.md +78 -0
- package/docs/zh-CN/tools/skills.md +279 -0
- package/docs/zh-CN/tools/slash-commands.md +205 -0
- package/docs/zh-CN/tools/subagents.md +156 -0
- package/docs/zh-CN/tools/thinking.md +80 -0
- package/docs/zh-CN/tools/web.md +257 -0
- package/docs/zh-CN/tts.md +375 -0
- package/docs/zh-CN/tui.md +166 -0
- package/docs/zh-CN/vps.md +47 -0
- package/docs/zh-CN/web/control-ui.md +191 -0
- package/docs/zh-CN/web/dashboard.md +53 -0
- package/docs/zh-CN/web/index.md +118 -0
- package/docs/zh-CN/web/webchat.md +56 -0
- package/extensions/bluebubbles/README.md +45 -0
- package/extensions/bluebubbles/index.ts +19 -0
- package/extensions/bluebubbles/node_modules/.bin/openclaw +21 -0
- package/extensions/bluebubbles/openclaw.plugin.json +9 -0
- package/extensions/bluebubbles/package.json +36 -0
- package/extensions/bluebubbles/src/accounts.ts +88 -0
- package/extensions/bluebubbles/src/actions.test.ts +650 -0
- package/extensions/bluebubbles/src/actions.ts +438 -0
- package/extensions/bluebubbles/src/attachments.test.ts +345 -0
- package/extensions/bluebubbles/src/attachments.ts +300 -0
- package/extensions/bluebubbles/src/channel.ts +414 -0
- package/extensions/bluebubbles/src/chat.test.ts +461 -0
- package/extensions/bluebubbles/src/chat.ts +378 -0
- package/extensions/bluebubbles/src/config-schema.ts +51 -0
- package/extensions/bluebubbles/src/media-send.ts +174 -0
- package/extensions/bluebubbles/src/monitor.test.ts +2342 -0
- package/extensions/bluebubbles/src/monitor.ts +2490 -0
- package/extensions/bluebubbles/src/onboarding.ts +352 -0
- package/extensions/bluebubbles/src/probe.ts +135 -0
- package/extensions/bluebubbles/src/reactions.test.ts +392 -0
- package/extensions/bluebubbles/src/reactions.ts +188 -0
- package/extensions/bluebubbles/src/runtime.ts +14 -0
- package/extensions/bluebubbles/src/send.test.ts +808 -0
- package/extensions/bluebubbles/src/send.ts +467 -0
- package/extensions/bluebubbles/src/targets.test.ts +183 -0
- package/extensions/bluebubbles/src/targets.ts +422 -0
- package/extensions/bluebubbles/src/types.ts +127 -0
- package/extensions/copilot-proxy/README.md +24 -0
- package/extensions/copilot-proxy/index.ts +148 -0
- package/extensions/copilot-proxy/node_modules/.bin/openclaw +21 -0
- package/extensions/copilot-proxy/openclaw.plugin.json +9 -0
- package/extensions/copilot-proxy/package.json +14 -0
- package/extensions/diagnostics-otel/index.ts +15 -0
- package/extensions/diagnostics-otel/node_modules/.bin/openclaw +21 -0
- package/extensions/diagnostics-otel/openclaw.plugin.json +8 -0
- package/extensions/diagnostics-otel/package.json +27 -0
- package/extensions/diagnostics-otel/src/service.test.ts +226 -0
- package/extensions/diagnostics-otel/src/service.ts +635 -0
- package/extensions/discord/index.ts +17 -0
- package/extensions/discord/node_modules/.bin/openclaw +21 -0
- package/extensions/discord/openclaw.plugin.json +9 -0
- package/extensions/discord/package.json +14 -0
- package/extensions/discord/src/channel.ts +422 -0
- package/extensions/discord/src/runtime.ts +14 -0
- package/extensions/feishu/README.md +47 -0
- package/extensions/feishu/index.ts +15 -0
- package/extensions/feishu/node_modules/.bin/openclaw +21 -0
- package/extensions/feishu/openclaw.plugin.json +9 -0
- package/extensions/feishu/package.json +33 -0
- package/extensions/feishu/src/channel.ts +276 -0
- package/extensions/feishu/src/config-schema.ts +46 -0
- package/extensions/feishu/src/onboarding.ts +278 -0
- package/extensions/google-antigravity-auth/README.md +24 -0
- package/extensions/google-antigravity-auth/index.ts +461 -0
- package/extensions/google-antigravity-auth/node_modules/.bin/openclaw +21 -0
- package/extensions/google-antigravity-auth/openclaw.plugin.json +9 -0
- package/extensions/google-antigravity-auth/package.json +14 -0
- package/extensions/google-gemini-cli-auth/README.md +35 -0
- package/extensions/google-gemini-cli-auth/index.ts +88 -0
- package/extensions/google-gemini-cli-auth/node_modules/.bin/openclaw +21 -0
- package/extensions/google-gemini-cli-auth/oauth.test.ts +240 -0
- package/extensions/google-gemini-cli-auth/oauth.ts +662 -0
- package/extensions/google-gemini-cli-auth/openclaw.plugin.json +9 -0
- package/extensions/google-gemini-cli-auth/package.json +14 -0
- package/extensions/googlechat/index.ts +19 -0
- package/extensions/googlechat/node_modules/.bin/openclaw +21 -0
- package/extensions/googlechat/openclaw.plugin.json +9 -0
- package/extensions/googlechat/package.json +39 -0
- package/extensions/googlechat/src/accounts.ts +147 -0
- package/extensions/googlechat/src/actions.ts +181 -0
- package/extensions/googlechat/src/api.test.ts +61 -0
- package/extensions/googlechat/src/api.ts +282 -0
- package/extensions/googlechat/src/auth.ts +123 -0
- package/extensions/googlechat/src/channel.ts +583 -0
- package/extensions/googlechat/src/monitor.test.ts +22 -0
- package/extensions/googlechat/src/monitor.ts +949 -0
- package/extensions/googlechat/src/onboarding.ts +269 -0
- package/extensions/googlechat/src/runtime.ts +14 -0
- package/extensions/googlechat/src/targets.test.ts +32 -0
- package/extensions/googlechat/src/targets.ts +65 -0
- package/extensions/googlechat/src/types.config.ts +3 -0
- package/extensions/googlechat/src/types.ts +73 -0
- package/extensions/imessage/index.ts +17 -0
- package/extensions/imessage/node_modules/.bin/openclaw +21 -0
- package/extensions/imessage/openclaw.plugin.json +9 -0
- package/extensions/imessage/package.json +14 -0
- package/extensions/imessage/src/channel.ts +294 -0
- package/extensions/imessage/src/runtime.ts +14 -0
- package/extensions/line/index.ts +19 -0
- package/extensions/line/node_modules/.bin/openclaw +21 -0
- package/extensions/line/openclaw.plugin.json +9 -0
- package/extensions/line/package.json +29 -0
- package/extensions/line/src/card-command.ts +344 -0
- package/extensions/line/src/channel.logout.test.ts +99 -0
- package/extensions/line/src/channel.sendPayload.test.ts +306 -0
- package/extensions/line/src/channel.ts +780 -0
- package/extensions/line/src/runtime.ts +14 -0
- package/extensions/llm-task/README.md +97 -0
- package/extensions/llm-task/index.ts +6 -0
- package/extensions/llm-task/node_modules/.bin/openclaw +21 -0
- package/extensions/llm-task/openclaw.plugin.json +21 -0
- package/extensions/llm-task/package.json +14 -0
- package/extensions/llm-task/src/llm-task-tool.test.ts +138 -0
- package/extensions/llm-task/src/llm-task-tool.ts +245 -0
- package/extensions/lobster/README.md +75 -0
- package/extensions/lobster/SKILL.md +97 -0
- package/extensions/lobster/index.ts +14 -0
- package/extensions/lobster/node_modules/.bin/openclaw +21 -0
- package/extensions/lobster/openclaw.plugin.json +10 -0
- package/extensions/lobster/package.json +14 -0
- package/extensions/lobster/src/lobster-tool.test.ts +247 -0
- package/extensions/lobster/src/lobster-tool.ts +328 -0
- package/extensions/matrix/CHANGELOG.md +87 -0
- package/extensions/matrix/index.ts +17 -0
- package/extensions/matrix/node_modules/.bin/markdown-it +21 -0
- package/extensions/matrix/node_modules/.bin/openclaw +21 -0
- package/extensions/matrix/openclaw.plugin.json +9 -0
- package/extensions/matrix/package.json +36 -0
- package/extensions/matrix/src/actions.ts +195 -0
- package/extensions/matrix/src/channel.directory.test.ts +64 -0
- package/extensions/matrix/src/channel.ts +439 -0
- package/extensions/matrix/src/config-schema.ts +62 -0
- package/extensions/matrix/src/directory-live.ts +188 -0
- package/extensions/matrix/src/group-mentions.ts +66 -0
- package/extensions/matrix/src/matrix/accounts.test.ts +82 -0
- package/extensions/matrix/src/matrix/accounts.ts +65 -0
- package/extensions/matrix/src/matrix/actions/client.ts +57 -0
- package/extensions/matrix/src/matrix/actions/messages.ts +128 -0
- package/extensions/matrix/src/matrix/actions/pins.ts +76 -0
- package/extensions/matrix/src/matrix/actions/reactions.ts +96 -0
- package/extensions/matrix/src/matrix/actions/room.ts +85 -0
- package/extensions/matrix/src/matrix/actions/summary.ts +75 -0
- package/extensions/matrix/src/matrix/actions/types.ts +84 -0
- package/extensions/matrix/src/matrix/actions.ts +15 -0
- package/extensions/matrix/src/matrix/active-client.ts +11 -0
- package/extensions/matrix/src/matrix/client/config.ts +160 -0
- package/extensions/matrix/src/matrix/client/create-client.ts +123 -0
- package/extensions/matrix/src/matrix/client/logging.ts +36 -0
- package/extensions/matrix/src/matrix/client/runtime.ts +4 -0
- package/extensions/matrix/src/matrix/client/shared.ts +170 -0
- package/extensions/matrix/src/matrix/client/storage.ts +131 -0
- package/extensions/matrix/src/matrix/client/types.ts +34 -0
- package/extensions/matrix/src/matrix/client.test.ts +56 -0
- package/extensions/matrix/src/matrix/client.ts +5 -0
- package/extensions/matrix/src/matrix/credentials.ts +105 -0
- package/extensions/matrix/src/matrix/deps.ts +60 -0
- package/extensions/matrix/src/matrix/format.test.ts +33 -0
- package/extensions/matrix/src/matrix/format.ts +22 -0
- package/extensions/matrix/src/matrix/index.ts +11 -0
- package/extensions/matrix/src/matrix/monitor/allowlist.test.ts +45 -0
- package/extensions/matrix/src/matrix/monitor/allowlist.ts +103 -0
- package/extensions/matrix/src/matrix/monitor/auto-join.ts +71 -0
- package/extensions/matrix/src/matrix/monitor/direct.ts +104 -0
- package/extensions/matrix/src/matrix/monitor/events.ts +101 -0
- package/extensions/matrix/src/matrix/monitor/handler.ts +661 -0
- package/extensions/matrix/src/matrix/monitor/index.ts +338 -0
- package/extensions/matrix/src/matrix/monitor/location.ts +100 -0
- package/extensions/matrix/src/matrix/monitor/media.test.ts +102 -0
- package/extensions/matrix/src/matrix/monitor/media.ts +113 -0
- package/extensions/matrix/src/matrix/monitor/mentions.ts +31 -0
- package/extensions/matrix/src/matrix/monitor/replies.ts +97 -0
- package/extensions/matrix/src/matrix/monitor/room-info.ts +55 -0
- package/extensions/matrix/src/matrix/monitor/rooms.test.ts +39 -0
- package/extensions/matrix/src/matrix/monitor/rooms.ts +47 -0
- package/extensions/matrix/src/matrix/monitor/threads.ts +68 -0
- package/extensions/matrix/src/matrix/monitor/types.ts +39 -0
- package/extensions/matrix/src/matrix/poll-types.test.ts +21 -0
- package/extensions/matrix/src/matrix/poll-types.ts +166 -0
- package/extensions/matrix/src/matrix/probe.ts +70 -0
- package/extensions/matrix/src/matrix/send/client.ts +66 -0
- package/extensions/matrix/src/matrix/send/formatting.ts +89 -0
- package/extensions/matrix/src/matrix/send/media.ts +229 -0
- package/extensions/matrix/src/matrix/send/targets.test.ts +98 -0
- package/extensions/matrix/src/matrix/send/targets.ts +136 -0
- package/extensions/matrix/src/matrix/send/types.ts +109 -0
- package/extensions/matrix/src/matrix/send.test.ts +171 -0
- package/extensions/matrix/src/matrix/send.ts +260 -0
- package/extensions/matrix/src/onboarding.ts +449 -0
- package/extensions/matrix/src/outbound.ts +52 -0
- package/extensions/matrix/src/resolve-targets.test.ts +48 -0
- package/extensions/matrix/src/resolve-targets.ts +135 -0
- package/extensions/matrix/src/runtime.ts +14 -0
- package/extensions/matrix/src/tool-actions.ts +164 -0
- package/extensions/matrix/src/types.ts +95 -0
- package/extensions/mattermost/index.ts +17 -0
- package/extensions/mattermost/node_modules/.bin/openclaw +21 -0
- package/extensions/mattermost/openclaw.plugin.json +9 -0
- package/extensions/mattermost/package.json +28 -0
- package/extensions/mattermost/src/channel.test.ts +48 -0
- package/extensions/mattermost/src/channel.ts +337 -0
- package/extensions/mattermost/src/config-schema.ts +55 -0
- package/extensions/mattermost/src/group-mentions.ts +15 -0
- package/extensions/mattermost/src/mattermost/accounts.ts +128 -0
- package/extensions/mattermost/src/mattermost/client.ts +220 -0
- package/extensions/mattermost/src/mattermost/index.ts +9 -0
- package/extensions/mattermost/src/mattermost/monitor-helpers.ts +166 -0
- package/extensions/mattermost/src/mattermost/monitor.ts +987 -0
- package/extensions/mattermost/src/mattermost/probe.ts +74 -0
- package/extensions/mattermost/src/mattermost/send.ts +231 -0
- package/extensions/mattermost/src/normalize.ts +46 -0
- package/extensions/mattermost/src/onboarding-helpers.ts +44 -0
- package/extensions/mattermost/src/onboarding.ts +186 -0
- package/extensions/mattermost/src/runtime.ts +14 -0
- package/extensions/mattermost/src/types.ts +50 -0
- package/extensions/memory-core/index.ts +38 -0
- package/extensions/memory-core/node_modules/.bin/openclaw +21 -0
- package/extensions/memory-core/openclaw.plugin.json +9 -0
- package/extensions/memory-core/package.json +17 -0
- package/extensions/memory-lancedb/config.ts +139 -0
- package/extensions/memory-lancedb/index.test.ts +295 -0
- package/extensions/memory-lancedb/index.ts +608 -0
- package/extensions/memory-lancedb/node_modules/.bin/openai +21 -0
- package/extensions/memory-lancedb/node_modules/.bin/openclaw +21 -0
- package/extensions/memory-lancedb/openclaw.plugin.json +60 -0
- package/extensions/memory-lancedb/package.json +19 -0
- package/extensions/minimax-portal-auth/README.md +33 -0
- package/extensions/minimax-portal-auth/index.ts +155 -0
- package/extensions/minimax-portal-auth/node_modules/.bin/openclaw +21 -0
- package/extensions/minimax-portal-auth/oauth.ts +247 -0
- package/extensions/minimax-portal-auth/openclaw.plugin.json +9 -0
- package/extensions/minimax-portal-auth/package.json +14 -0
- package/extensions/msteams/CHANGELOG.md +83 -0
- package/extensions/msteams/index.ts +17 -0
- package/extensions/msteams/node_modules/.bin/openclaw +21 -0
- package/extensions/msteams/openclaw.plugin.json +9 -0
- package/extensions/msteams/package.json +39 -0
- package/extensions/msteams/src/attachments/download.ts +283 -0
- package/extensions/msteams/src/attachments/graph.ts +353 -0
- package/extensions/msteams/src/attachments/html.ts +90 -0
- package/extensions/msteams/src/attachments/payload.ts +22 -0
- package/extensions/msteams/src/attachments/shared.ts +291 -0
- package/extensions/msteams/src/attachments/types.ts +37 -0
- package/extensions/msteams/src/attachments.test.ts +459 -0
- package/extensions/msteams/src/attachments.ts +18 -0
- package/extensions/msteams/src/channel.directory.test.ts +48 -0
- package/extensions/msteams/src/channel.ts +459 -0
- package/extensions/msteams/src/conversation-store-fs.test.ts +88 -0
- package/extensions/msteams/src/conversation-store-fs.ts +165 -0
- package/extensions/msteams/src/conversation-store-memory.ts +47 -0
- package/extensions/msteams/src/conversation-store.ts +41 -0
- package/extensions/msteams/src/directory-live.ts +205 -0
- package/extensions/msteams/src/errors.test.ts +45 -0
- package/extensions/msteams/src/errors.ts +190 -0
- package/extensions/msteams/src/file-consent-helpers.test.ts +243 -0
- package/extensions/msteams/src/file-consent-helpers.ts +73 -0
- package/extensions/msteams/src/file-consent.ts +126 -0
- package/extensions/msteams/src/graph-chat.ts +53 -0
- package/extensions/msteams/src/graph-upload.ts +453 -0
- package/extensions/msteams/src/inbound.test.ts +66 -0
- package/extensions/msteams/src/inbound.ts +48 -0
- package/extensions/msteams/src/index.ts +4 -0
- package/extensions/msteams/src/media-helpers.test.ts +189 -0
- package/extensions/msteams/src/media-helpers.ts +86 -0
- package/extensions/msteams/src/messenger.test.ts +248 -0
- package/extensions/msteams/src/messenger.ts +495 -0
- package/extensions/msteams/src/monitor-handler/inbound-media.ts +128 -0
- package/extensions/msteams/src/monitor-handler/message-handler.ts +640 -0
- package/extensions/msteams/src/monitor-handler.ts +162 -0
- package/extensions/msteams/src/monitor-types.ts +5 -0
- package/extensions/msteams/src/monitor.ts +295 -0
- package/extensions/msteams/src/onboarding.ts +431 -0
- package/extensions/msteams/src/outbound.ts +46 -0
- package/extensions/msteams/src/pending-uploads.ts +89 -0
- package/extensions/msteams/src/policy.test.ts +209 -0
- package/extensions/msteams/src/policy.ts +273 -0
- package/extensions/msteams/src/polls-store-memory.ts +32 -0
- package/extensions/msteams/src/polls-store.test.ts +38 -0
- package/extensions/msteams/src/polls.test.ts +72 -0
- package/extensions/msteams/src/polls.ts +315 -0
- package/extensions/msteams/src/probe.test.ts +58 -0
- package/extensions/msteams/src/probe.ts +107 -0
- package/extensions/msteams/src/reply-dispatcher.ts +130 -0
- package/extensions/msteams/src/resolve-allowlist.ts +297 -0
- package/extensions/msteams/src/runtime.ts +14 -0
- package/extensions/msteams/src/sdk-types.ts +19 -0
- package/extensions/msteams/src/sdk.ts +33 -0
- package/extensions/msteams/src/send-context.ts +164 -0
- package/extensions/msteams/src/send.ts +519 -0
- package/extensions/msteams/src/sent-message-cache.test.ts +15 -0
- package/extensions/msteams/src/sent-message-cache.ts +47 -0
- package/extensions/msteams/src/storage.ts +25 -0
- package/extensions/msteams/src/store-fs.ts +83 -0
- package/extensions/msteams/src/token.ts +19 -0
- package/extensions/nextcloud-talk/index.ts +17 -0
- package/extensions/nextcloud-talk/node_modules/.bin/openclaw +21 -0
- package/extensions/nextcloud-talk/openclaw.plugin.json +9 -0
- package/extensions/nextcloud-talk/package.json +33 -0
- package/extensions/nextcloud-talk/src/accounts.ts +174 -0
- package/extensions/nextcloud-talk/src/channel.ts +409 -0
- package/extensions/nextcloud-talk/src/config-schema.ts +78 -0
- package/extensions/nextcloud-talk/src/format.ts +79 -0
- package/extensions/nextcloud-talk/src/inbound.ts +317 -0
- package/extensions/nextcloud-talk/src/monitor.ts +246 -0
- package/extensions/nextcloud-talk/src/normalize.ts +39 -0
- package/extensions/nextcloud-talk/src/onboarding.ts +343 -0
- package/extensions/nextcloud-talk/src/policy.test.ts +33 -0
- package/extensions/nextcloud-talk/src/policy.ts +180 -0
- package/extensions/nextcloud-talk/src/room-info.ts +125 -0
- package/extensions/nextcloud-talk/src/runtime.ts +14 -0
- package/extensions/nextcloud-talk/src/send.ts +210 -0
- package/extensions/nextcloud-talk/src/signature.ts +72 -0
- package/extensions/nextcloud-talk/src/types.ts +179 -0
- package/extensions/nostr/CHANGELOG.md +74 -0
- package/extensions/nostr/README.md +136 -0
- package/extensions/nostr/index.ts +68 -0
- package/extensions/nostr/node_modules/.bin/openclaw +21 -0
- package/extensions/nostr/openclaw.plugin.json +9 -0
- package/extensions/nostr/package.json +34 -0
- package/extensions/nostr/src/channel.test.ts +151 -0
- package/extensions/nostr/src/channel.ts +353 -0
- package/extensions/nostr/src/config-schema.ts +90 -0
- package/extensions/nostr/src/metrics.ts +478 -0
- package/extensions/nostr/src/nostr-bus.fuzz.test.ts +533 -0
- package/extensions/nostr/src/nostr-bus.integration.test.ts +448 -0
- package/extensions/nostr/src/nostr-bus.test.ts +199 -0
- package/extensions/nostr/src/nostr-bus.ts +715 -0
- package/extensions/nostr/src/nostr-profile-http.test.ts +378 -0
- package/extensions/nostr/src/nostr-profile-http.ts +519 -0
- package/extensions/nostr/src/nostr-profile-import.test.ts +119 -0
- package/extensions/nostr/src/nostr-profile-import.ts +262 -0
- package/extensions/nostr/src/nostr-profile.fuzz.test.ts +477 -0
- package/extensions/nostr/src/nostr-profile.test.ts +410 -0
- package/extensions/nostr/src/nostr-profile.ts +277 -0
- package/extensions/nostr/src/nostr-state-store.test.ts +131 -0
- package/extensions/nostr/src/nostr-state-store.ts +226 -0
- package/extensions/nostr/src/runtime.ts +14 -0
- package/extensions/nostr/src/seen-tracker.ts +303 -0
- package/extensions/nostr/src/types.test.ts +157 -0
- package/extensions/nostr/src/types.ts +101 -0
- package/extensions/nostr/test/setup.ts +5 -0
- package/extensions/open-prose/README.md +25 -0
- package/extensions/open-prose/index.ts +5 -0
- package/extensions/open-prose/node_modules/.bin/openclaw +21 -0
- package/extensions/open-prose/openclaw.plugin.json +11 -0
- package/extensions/open-prose/package.json +14 -0
- package/extensions/open-prose/skills/prose/LICENSE +21 -0
- package/extensions/open-prose/skills/prose/SKILL.md +323 -0
- package/extensions/open-prose/skills/prose/alt-borges.md +141 -0
- package/extensions/open-prose/skills/prose/alts/arabian-nights.md +358 -0
- package/extensions/open-prose/skills/prose/alts/borges.md +360 -0
- package/extensions/open-prose/skills/prose/alts/folk.md +322 -0
- package/extensions/open-prose/skills/prose/alts/homer.md +346 -0
- package/extensions/open-prose/skills/prose/alts/kafka.md +373 -0
- package/extensions/open-prose/skills/prose/compiler.md +2971 -0
- package/extensions/open-prose/skills/prose/examples/01-hello-world.prose +4 -0
- package/extensions/open-prose/skills/prose/examples/02-research-and-summarize.prose +6 -0
- package/extensions/open-prose/skills/prose/examples/03-code-review.prose +17 -0
- package/extensions/open-prose/skills/prose/examples/04-write-and-refine.prose +14 -0
- package/extensions/open-prose/skills/prose/examples/05-debug-issue.prose +20 -0
- package/extensions/open-prose/skills/prose/examples/06-explain-codebase.prose +17 -0
- package/extensions/open-prose/skills/prose/examples/07-refactor.prose +20 -0
- package/extensions/open-prose/skills/prose/examples/08-blog-post.prose +20 -0
- package/extensions/open-prose/skills/prose/examples/09-research-with-agents.prose +25 -0
- package/extensions/open-prose/skills/prose/examples/10-code-review-agents.prose +32 -0
- package/extensions/open-prose/skills/prose/examples/11-skills-and-imports.prose +27 -0
- package/extensions/open-prose/skills/prose/examples/12-secure-agent-permissions.prose +43 -0
- package/extensions/open-prose/skills/prose/examples/13-variables-and-context.prose +51 -0
- package/extensions/open-prose/skills/prose/examples/14-composition-blocks.prose +48 -0
- package/extensions/open-prose/skills/prose/examples/15-inline-sequences.prose +23 -0
- package/extensions/open-prose/skills/prose/examples/16-parallel-reviews.prose +19 -0
- package/extensions/open-prose/skills/prose/examples/17-parallel-research.prose +19 -0
- package/extensions/open-prose/skills/prose/examples/18-mixed-parallel-sequential.prose +36 -0
- package/extensions/open-prose/skills/prose/examples/19-advanced-parallel.prose +71 -0
- package/extensions/open-prose/skills/prose/examples/20-fixed-loops.prose +20 -0
- package/extensions/open-prose/skills/prose/examples/21-pipeline-operations.prose +35 -0
- package/extensions/open-prose/skills/prose/examples/22-error-handling.prose +51 -0
- package/extensions/open-prose/skills/prose/examples/23-retry-with-backoff.prose +63 -0
- package/extensions/open-prose/skills/prose/examples/24-choice-blocks.prose +86 -0
- package/extensions/open-prose/skills/prose/examples/25-conditionals.prose +114 -0
- package/extensions/open-prose/skills/prose/examples/26-parameterized-blocks.prose +100 -0
- package/extensions/open-prose/skills/prose/examples/27-string-interpolation.prose +105 -0
- package/extensions/open-prose/skills/prose/examples/28-automated-pr-review.prose +37 -0
- package/extensions/open-prose/skills/prose/examples/28-gas-town.prose +1572 -0
- package/extensions/open-prose/skills/prose/examples/29-captains-chair.prose +218 -0
- package/extensions/open-prose/skills/prose/examples/30-captains-chair-simple.prose +42 -0
- package/extensions/open-prose/skills/prose/examples/31-captains-chair-with-memory.prose +145 -0
- package/extensions/open-prose/skills/prose/examples/33-pr-review-autofix.prose +168 -0
- package/extensions/open-prose/skills/prose/examples/34-content-pipeline.prose +204 -0
- package/extensions/open-prose/skills/prose/examples/35-feature-factory.prose +296 -0
- package/extensions/open-prose/skills/prose/examples/36-bug-hunter.prose +237 -0
- package/extensions/open-prose/skills/prose/examples/37-the-forge.prose +1474 -0
- package/extensions/open-prose/skills/prose/examples/38-skill-scan.prose +455 -0
- package/extensions/open-prose/skills/prose/examples/39-architect-by-simulation.prose +277 -0
- package/extensions/open-prose/skills/prose/examples/40-rlm-self-refine.prose +32 -0
- package/extensions/open-prose/skills/prose/examples/41-rlm-divide-conquer.prose +38 -0
- package/extensions/open-prose/skills/prose/examples/42-rlm-filter-recurse.prose +46 -0
- package/extensions/open-prose/skills/prose/examples/43-rlm-pairwise.prose +50 -0
- package/extensions/open-prose/skills/prose/examples/44-run-endpoint-ux-test.prose +261 -0
- package/extensions/open-prose/skills/prose/examples/45-plugin-release.prose +159 -0
- package/extensions/open-prose/skills/prose/examples/45-run-endpoint-ux-test-with-remediation.prose +637 -0
- package/extensions/open-prose/skills/prose/examples/46-run-endpoint-ux-test-fast.prose +148 -0
- package/extensions/open-prose/skills/prose/examples/46-workflow-crystallizer.prose +225 -0
- package/extensions/open-prose/skills/prose/examples/47-language-self-improvement.prose +356 -0
- package/extensions/open-prose/skills/prose/examples/48-habit-miner.prose +445 -0
- package/extensions/open-prose/skills/prose/examples/49-prose-run-retrospective.prose +210 -0
- package/extensions/open-prose/skills/prose/examples/README.md +391 -0
- package/extensions/open-prose/skills/prose/examples/roadmap/README.md +22 -0
- package/extensions/open-prose/skills/prose/examples/roadmap/iterative-refinement.prose +20 -0
- package/extensions/open-prose/skills/prose/examples/roadmap/parallel-review.prose +18 -0
- package/extensions/open-prose/skills/prose/examples/roadmap/simple-pipeline.prose +17 -0
- package/extensions/open-prose/skills/prose/examples/roadmap/syntax/open-prose-syntax.prose +223 -0
- package/extensions/open-prose/skills/prose/guidance/antipatterns.md +951 -0
- package/extensions/open-prose/skills/prose/guidance/patterns.md +700 -0
- package/extensions/open-prose/skills/prose/guidance/system-prompt.md +180 -0
- package/extensions/open-prose/skills/prose/help.md +144 -0
- package/extensions/open-prose/skills/prose/lib/README.md +108 -0
- package/extensions/open-prose/skills/prose/lib/calibrator.prose +215 -0
- package/extensions/open-prose/skills/prose/lib/cost-analyzer.prose +174 -0
- package/extensions/open-prose/skills/prose/lib/error-forensics.prose +250 -0
- package/extensions/open-prose/skills/prose/lib/inspector.prose +196 -0
- package/extensions/open-prose/skills/prose/lib/profiler.prose +460 -0
- package/extensions/open-prose/skills/prose/lib/program-improver.prose +275 -0
- package/extensions/open-prose/skills/prose/lib/project-memory.prose +118 -0
- package/extensions/open-prose/skills/prose/lib/user-memory.prose +93 -0
- package/extensions/open-prose/skills/prose/lib/vm-improver.prose +243 -0
- package/extensions/open-prose/skills/prose/primitives/session.md +593 -0
- package/extensions/open-prose/skills/prose/prose.md +1237 -0
- package/extensions/open-prose/skills/prose/state/filesystem.md +498 -0
- package/extensions/open-prose/skills/prose/state/in-context.md +384 -0
- package/extensions/open-prose/skills/prose/state/postgres.md +880 -0
- package/extensions/open-prose/skills/prose/state/sqlite.md +574 -0
- package/extensions/qwen-portal-auth/README.md +24 -0
- package/extensions/qwen-portal-auth/index.ts +130 -0
- package/extensions/qwen-portal-auth/oauth.ts +190 -0
- package/extensions/qwen-portal-auth/openclaw.plugin.json +9 -0
- package/extensions/signal/index.ts +17 -0
- package/extensions/signal/node_modules/.bin/openclaw +21 -0
- package/extensions/signal/openclaw.plugin.json +9 -0
- package/extensions/signal/package.json +14 -0
- package/extensions/signal/src/channel.ts +315 -0
- package/extensions/signal/src/runtime.ts +14 -0
- package/extensions/slack/index.ts +17 -0
- package/extensions/slack/node_modules/.bin/openclaw +21 -0
- package/extensions/slack/openclaw.plugin.json +9 -0
- package/extensions/slack/package.json +14 -0
- package/extensions/slack/src/channel.ts +604 -0
- package/extensions/slack/src/runtime.ts +14 -0
- package/extensions/telegram/index.ts +17 -0
- package/extensions/telegram/node_modules/.bin/openclaw +21 -0
- package/extensions/telegram/openclaw.plugin.json +9 -0
- package/extensions/telegram/package.json +14 -0
- package/extensions/telegram/src/channel.ts +482 -0
- package/extensions/telegram/src/runtime.ts +14 -0
- package/extensions/tlon/README.md +5 -0
- package/extensions/tlon/index.ts +17 -0
- package/extensions/tlon/node_modules/.bin/openclaw +21 -0
- package/extensions/tlon/openclaw.plugin.json +9 -0
- package/extensions/tlon/package.json +33 -0
- package/extensions/tlon/src/channel.ts +392 -0
- package/extensions/tlon/src/config-schema.test.ts +31 -0
- package/extensions/tlon/src/config-schema.ts +43 -0
- package/extensions/tlon/src/monitor/discovery.ts +76 -0
- package/extensions/tlon/src/monitor/history.ts +90 -0
- package/extensions/tlon/src/monitor/index.ts +553 -0
- package/extensions/tlon/src/monitor/processed-messages.test.ts +23 -0
- package/extensions/tlon/src/monitor/processed-messages.ts +46 -0
- package/extensions/tlon/src/monitor/utils.ts +105 -0
- package/extensions/tlon/src/onboarding.ts +214 -0
- package/extensions/tlon/src/runtime.ts +14 -0
- package/extensions/tlon/src/targets.ts +89 -0
- package/extensions/tlon/src/types.ts +92 -0
- package/extensions/tlon/src/urbit/auth.ts +18 -0
- package/extensions/tlon/src/urbit/http-api.ts +38 -0
- package/extensions/tlon/src/urbit/send.test.ts +38 -0
- package/extensions/tlon/src/urbit/send.ts +131 -0
- package/extensions/tlon/src/urbit/sse-client.test.ts +40 -0
- package/extensions/tlon/src/urbit/sse-client.ts +395 -0
- package/extensions/twitch/CHANGELOG.md +45 -0
- package/extensions/twitch/README.md +89 -0
- package/extensions/twitch/index.ts +20 -0
- package/extensions/twitch/node_modules/.bin/openclaw +21 -0
- package/extensions/twitch/openclaw.plugin.json +9 -0
- package/extensions/twitch/package.json +20 -0
- package/extensions/twitch/src/access-control.test.ts +489 -0
- package/extensions/twitch/src/access-control.ts +166 -0
- package/extensions/twitch/src/actions.ts +173 -0
- package/extensions/twitch/src/client-manager-registry.ts +115 -0
- package/extensions/twitch/src/config-schema.ts +82 -0
- package/extensions/twitch/src/config.test.ts +87 -0
- package/extensions/twitch/src/config.ts +116 -0
- package/extensions/twitch/src/monitor.ts +261 -0
- package/extensions/twitch/src/onboarding.test.ts +311 -0
- package/extensions/twitch/src/onboarding.ts +417 -0
- package/extensions/twitch/src/outbound.test.ts +373 -0
- package/extensions/twitch/src/outbound.ts +184 -0
- package/extensions/twitch/src/plugin.test.ts +39 -0
- package/extensions/twitch/src/plugin.ts +274 -0
- package/extensions/twitch/src/probe.test.ts +195 -0
- package/extensions/twitch/src/probe.ts +120 -0
- package/extensions/twitch/src/resolver.ts +137 -0
- package/extensions/twitch/src/runtime.ts +14 -0
- package/extensions/twitch/src/send.test.ts +289 -0
- package/extensions/twitch/src/send.ts +136 -0
- package/extensions/twitch/src/status.test.ts +270 -0
- package/extensions/twitch/src/status.ts +178 -0
- package/extensions/twitch/src/token.test.ts +171 -0
- package/extensions/twitch/src/token.ts +91 -0
- package/extensions/twitch/src/twitch-client.test.ts +589 -0
- package/extensions/twitch/src/twitch-client.ts +277 -0
- package/extensions/twitch/src/types.ts +141 -0
- package/extensions/twitch/src/utils/markdown.ts +98 -0
- package/extensions/twitch/src/utils/twitch.ts +78 -0
- package/extensions/twitch/test/setup.ts +7 -0
- package/extensions/voice-call/CHANGELOG.md +109 -0
- package/extensions/voice-call/README.md +139 -0
- package/extensions/voice-call/index.ts +493 -0
- package/extensions/voice-call/node_modules/.bin/openclaw +21 -0
- package/extensions/voice-call/openclaw.plugin.json +559 -0
- package/extensions/voice-call/package.json +19 -0
- package/extensions/voice-call/src/allowlist.ts +19 -0
- package/extensions/voice-call/src/cli.ts +279 -0
- package/extensions/voice-call/src/config.test.ts +234 -0
- package/extensions/voice-call/src/config.ts +523 -0
- package/extensions/voice-call/src/core-bridge.ts +159 -0
- package/extensions/voice-call/src/manager/context.ts +21 -0
- package/extensions/voice-call/src/manager/events.ts +188 -0
- package/extensions/voice-call/src/manager/lookup.ts +35 -0
- package/extensions/voice-call/src/manager/outbound.ts +275 -0
- package/extensions/voice-call/src/manager/state.ts +48 -0
- package/extensions/voice-call/src/manager/store.ts +91 -0
- package/extensions/voice-call/src/manager/timers.ts +89 -0
- package/extensions/voice-call/src/manager/twiml.ts +9 -0
- package/extensions/voice-call/src/manager.test.ts +194 -0
- package/extensions/voice-call/src/manager.ts +887 -0
- package/extensions/voice-call/src/media-stream.test.ts +96 -0
- package/extensions/voice-call/src/media-stream.ts +411 -0
- package/extensions/voice-call/src/providers/base.ts +67 -0
- package/extensions/voice-call/src/providers/index.ts +10 -0
- package/extensions/voice-call/src/providers/mock.ts +165 -0
- package/extensions/voice-call/src/providers/plivo.test.ts +27 -0
- package/extensions/voice-call/src/providers/plivo.ts +515 -0
- package/extensions/voice-call/src/providers/stt-openai-realtime.ts +311 -0
- package/extensions/voice-call/src/providers/telnyx.ts +371 -0
- package/extensions/voice-call/src/providers/tts-openai.ts +259 -0
- package/extensions/voice-call/src/providers/twilio/api.ts +42 -0
- package/extensions/voice-call/src/providers/twilio/webhook.ts +32 -0
- package/extensions/voice-call/src/providers/twilio.test.ts +60 -0
- package/extensions/voice-call/src/providers/twilio.ts +626 -0
- package/extensions/voice-call/src/response-generator.ts +158 -0
- package/extensions/voice-call/src/runtime.ts +212 -0
- package/extensions/voice-call/src/telephony-audio.ts +90 -0
- package/extensions/voice-call/src/telephony-tts.ts +104 -0
- package/extensions/voice-call/src/tunnel.ts +314 -0
- package/extensions/voice-call/src/types.ts +272 -0
- package/extensions/voice-call/src/utils.ts +14 -0
- package/extensions/voice-call/src/voice-mapping.ts +67 -0
- package/extensions/voice-call/src/webhook-security.test.ts +377 -0
- package/extensions/voice-call/src/webhook-security.ts +689 -0
- package/extensions/voice-call/src/webhook.ts +491 -0
- package/extensions/whatsapp/index.ts +17 -0
- package/extensions/whatsapp/node_modules/.bin/openclaw +21 -0
- package/extensions/whatsapp/openclaw.plugin.json +9 -0
- package/extensions/whatsapp/package.json +14 -0
- package/extensions/whatsapp/src/channel.ts +508 -0
- package/extensions/whatsapp/src/runtime.ts +14 -0
- package/extensions/zalo/CHANGELOG.md +89 -0
- package/extensions/zalo/README.md +50 -0
- package/extensions/zalo/index.ts +19 -0
- package/extensions/zalo/node_modules/.bin/openclaw +21 -0
- package/extensions/zalo/openclaw.plugin.json +9 -0
- package/extensions/zalo/package.json +36 -0
- package/extensions/zalo/src/accounts.ts +80 -0
- package/extensions/zalo/src/actions.ts +67 -0
- package/extensions/zalo/src/api.ts +208 -0
- package/extensions/zalo/src/channel.directory.test.ts +43 -0
- package/extensions/zalo/src/channel.ts +414 -0
- package/extensions/zalo/src/config-schema.ts +24 -0
- package/extensions/zalo/src/monitor.ts +753 -0
- package/extensions/zalo/src/monitor.webhook.test.ts +73 -0
- package/extensions/zalo/src/onboarding.ts +401 -0
- package/extensions/zalo/src/probe.ts +46 -0
- package/extensions/zalo/src/proxy.ts +21 -0
- package/extensions/zalo/src/runtime.ts +14 -0
- package/extensions/zalo/src/send.ts +124 -0
- package/extensions/zalo/src/status-issues.ts +53 -0
- package/extensions/zalo/src/token.ts +63 -0
- package/extensions/zalo/src/types.ts +42 -0
- package/extensions/zalouser/CHANGELOG.md +61 -0
- package/extensions/zalouser/README.md +225 -0
- package/extensions/zalouser/index.ts +31 -0
- package/extensions/zalouser/node_modules/.bin/openclaw +21 -0
- package/extensions/zalouser/openclaw.plugin.json +9 -0
- package/extensions/zalouser/package.json +36 -0
- package/extensions/zalouser/src/accounts.ts +135 -0
- package/extensions/zalouser/src/channel.test.ts +18 -0
- package/extensions/zalouser/src/channel.ts +686 -0
- package/extensions/zalouser/src/config-schema.ts +27 -0
- package/extensions/zalouser/src/monitor.ts +590 -0
- package/extensions/zalouser/src/onboarding.ts +504 -0
- package/extensions/zalouser/src/probe.ts +28 -0
- package/extensions/zalouser/src/runtime.ts +14 -0
- package/extensions/zalouser/src/send.ts +160 -0
- package/extensions/zalouser/src/status-issues.test.ts +57 -0
- package/extensions/zalouser/src/status-issues.ts +89 -0
- package/extensions/zalouser/src/tool.ts +164 -0
- package/extensions/zalouser/src/types.ts +108 -0
- package/extensions/zalouser/src/zca.ts +202 -0
- package/openclaw.mjs +14 -0
- package/package.json +245 -0
- package/skills/1password/SKILL.md +70 -0
- package/skills/1password/references/cli-examples.md +29 -0
- package/skills/1password/references/get-started.md +17 -0
- package/skills/apple-notes/SKILL.md +77 -0
- package/skills/apple-reminders/SKILL.md +96 -0
- package/skills/bear-notes/SKILL.md +107 -0
- package/skills/bird/SKILL.md +224 -0
- package/skills/blogwatcher/SKILL.md +69 -0
- package/skills/blucli/SKILL.md +47 -0
- package/skills/bluebubbles/SKILL.md +131 -0
- package/skills/camsnap/SKILL.md +45 -0
- package/skills/canvas/SKILL.md +198 -0
- package/skills/clawhub/SKILL.md +77 -0
- package/skills/coding-agent/SKILL.md +284 -0
- package/skills/discord/SKILL.md +578 -0
- package/skills/eightctl/SKILL.md +50 -0
- package/skills/food-order/SKILL.md +48 -0
- package/skills/gemini/SKILL.md +43 -0
- package/skills/ghostly-projects/SKILL.md +160 -0
- package/skills/gifgrep/SKILL.md +79 -0
- package/skills/github/SKILL.md +77 -0
- package/skills/gog/SKILL.md +116 -0
- package/skills/goplaces/SKILL.md +52 -0
- package/skills/healthcheck/SKILL.md +245 -0
- package/skills/himalaya/SKILL.md +257 -0
- package/skills/himalaya/references/configuration.md +184 -0
- package/skills/himalaya/references/message-composition.md +199 -0
- package/skills/imsg/SKILL.md +74 -0
- package/skills/linear/SKILL.md +111 -0
- package/skills/linear/linear.sh +204 -0
- package/skills/local-places/SERVER_README.md +101 -0
- package/skills/local-places/SKILL.md +102 -0
- package/skills/local-places/pyproject.toml +21 -0
- package/skills/local-places/src/local_places/__init__.py +2 -0
- package/skills/local-places/src/local_places/google_places.py +314 -0
- package/skills/local-places/src/local_places/main.py +65 -0
- package/skills/local-places/src/local_places/schemas.py +107 -0
- package/skills/mcporter/SKILL.md +61 -0
- package/skills/model-usage/SKILL.md +69 -0
- package/skills/model-usage/references/codexbar-cli.md +33 -0
- package/skills/model-usage/scripts/model_usage.py +310 -0
- package/skills/nano-banana-pro/SKILL.md +58 -0
- package/skills/nano-banana-pro/scripts/generate_image.py +184 -0
- package/skills/nano-pdf/SKILL.md +38 -0
- package/skills/notion/SKILL.md +172 -0
- package/skills/obsidian/SKILL.md +81 -0
- package/skills/openai-image-gen/SKILL.md +89 -0
- package/skills/openai-image-gen/scripts/gen.py +240 -0
- package/skills/openai-whisper/SKILL.md +38 -0
- package/skills/openai-whisper-api/SKILL.md +52 -0
- package/skills/openai-whisper-api/scripts/transcribe.sh +85 -0
- package/skills/openhue/SKILL.md +51 -0
- package/skills/oracle/SKILL.md +125 -0
- package/skills/ordercli/SKILL.md +78 -0
- package/skills/peekaboo/SKILL.md +190 -0
- package/skills/sag/SKILL.md +87 -0
- package/skills/session-logs/SKILL.md +115 -0
- package/skills/sherpa-onnx-tts/SKILL.md +103 -0
- package/skills/sherpa-onnx-tts/bin/sherpa-onnx-tts +178 -0
- package/skills/skill-creator/SKILL.md +370 -0
- package/skills/skill-creator/license.txt +202 -0
- package/skills/skill-creator/scripts/init_skill.py +378 -0
- package/skills/skill-creator/scripts/package_skill.py +111 -0
- package/skills/skill-creator/scripts/quick_validate.py +101 -0
- package/skills/slack/SKILL.md +144 -0
- package/skills/songsee/SKILL.md +49 -0
- package/skills/sonoscli/SKILL.md +46 -0
- package/skills/spotify-player/SKILL.md +64 -0
- package/skills/summarize/SKILL.md +87 -0
- package/skills/things-mac/SKILL.md +86 -0
- package/skills/tmux/SKILL.md +135 -0
- package/skills/tmux/scripts/find-sessions.sh +112 -0
- package/skills/tmux/scripts/wait-for-text.sh +83 -0
- package/skills/trello/SKILL.md +95 -0
- package/skills/video-frames/SKILL.md +46 -0
- package/skills/video-frames/scripts/frame.sh +81 -0
- package/skills/voice-call/SKILL.md +45 -0
- package/skills/wacli/SKILL.md +72 -0
- package/skills/weather/SKILL.md +54 -0
|
@@ -0,0 +1,2872 @@
|
|
|
1
|
+
import { t as __exportAll } from "./rolldown-runtime-Cbj13DAv.js";
|
|
2
|
+
import { g as resolveStateDir } from "./paths-scjhy7N2.js";
|
|
3
|
+
import { n as resolveAgentConfig, r as resolveAgentDir, s as resolveAgentWorkspaceDir } from "./agent-scope-BbT4OG2N.js";
|
|
4
|
+
import { t as createSubsystemLogger } from "./subsystem-CAq3uyo7.js";
|
|
5
|
+
import { h as resolveUserPath, i as clampNumber$1, r as clampInt, v as sleep, x as truncateUtf16Safe } from "./utils-CKSrBNwq.js";
|
|
6
|
+
import { M as resolveApiKeyForProvider, j as requireApiKey } from "./model-selection-Cv5Ox_tY.js";
|
|
7
|
+
import { t as isTruthyEnvValue } from "./env-l7QVNj6j.js";
|
|
8
|
+
import { a as resolveSessionTranscriptsDirForAgent } from "./paths-B-q1nXdY.js";
|
|
9
|
+
import { n as onSessionTranscriptUpdate } from "./transcript-events-CsB1Saa6.js";
|
|
10
|
+
import { a as ensureDir, c as listMemoryFiles, i as cosineSimilarity, l as normalizeExtraMemoryPaths, n as buildFileEntry, o as hashText, r as chunkMarkdown, s as isMemoryPath, t as requireNodeSqlite, u as parseEmbedding } from "./sqlite-QDf0yuU0.js";
|
|
11
|
+
import os from "node:os";
|
|
12
|
+
import path from "node:path";
|
|
13
|
+
import fs from "node:fs";
|
|
14
|
+
import fs$1 from "node:fs/promises";
|
|
15
|
+
import { randomUUID } from "node:crypto";
|
|
16
|
+
import chokidar from "chokidar";
|
|
17
|
+
|
|
18
|
+
//#region src/agents/memory-search.ts
|
|
19
|
+
const DEFAULT_OPENAI_MODEL = "text-embedding-3-small";
|
|
20
|
+
const DEFAULT_GEMINI_MODEL = "gemini-embedding-001";
|
|
21
|
+
const DEFAULT_CHUNK_TOKENS = 400;
|
|
22
|
+
const DEFAULT_CHUNK_OVERLAP = 80;
|
|
23
|
+
const DEFAULT_WATCH_DEBOUNCE_MS = 1500;
|
|
24
|
+
const DEFAULT_SESSION_DELTA_BYTES = 1e5;
|
|
25
|
+
const DEFAULT_SESSION_DELTA_MESSAGES = 50;
|
|
26
|
+
const DEFAULT_MAX_RESULTS = 6;
|
|
27
|
+
const DEFAULT_MIN_SCORE = .35;
|
|
28
|
+
const DEFAULT_HYBRID_ENABLED = true;
|
|
29
|
+
const DEFAULT_HYBRID_VECTOR_WEIGHT = .7;
|
|
30
|
+
const DEFAULT_HYBRID_TEXT_WEIGHT = .3;
|
|
31
|
+
const DEFAULT_HYBRID_CANDIDATE_MULTIPLIER = 4;
|
|
32
|
+
const DEFAULT_CACHE_ENABLED = true;
|
|
33
|
+
const DEFAULT_SOURCES = ["memory"];
|
|
34
|
+
function normalizeSources(sources, sessionMemoryEnabled) {
|
|
35
|
+
const normalized = /* @__PURE__ */ new Set();
|
|
36
|
+
const input = sources?.length ? sources : DEFAULT_SOURCES;
|
|
37
|
+
for (const source of input) {
|
|
38
|
+
if (source === "memory") normalized.add("memory");
|
|
39
|
+
if (source === "sessions" && sessionMemoryEnabled) normalized.add("sessions");
|
|
40
|
+
}
|
|
41
|
+
if (normalized.size === 0) normalized.add("memory");
|
|
42
|
+
return Array.from(normalized);
|
|
43
|
+
}
|
|
44
|
+
function resolveStorePath(agentId, raw) {
|
|
45
|
+
const stateDir = resolveStateDir(process.env, os.homedir);
|
|
46
|
+
const fallback = path.join(stateDir, "memory", `${agentId}.sqlite`);
|
|
47
|
+
if (!raw) return fallback;
|
|
48
|
+
return resolveUserPath(raw.includes("{agentId}") ? raw.replaceAll("{agentId}", agentId) : raw);
|
|
49
|
+
}
|
|
50
|
+
function mergeConfig(defaults, overrides, agentId) {
|
|
51
|
+
const enabled = overrides?.enabled ?? defaults?.enabled ?? true;
|
|
52
|
+
const sessionMemory = overrides?.experimental?.sessionMemory ?? defaults?.experimental?.sessionMemory ?? false;
|
|
53
|
+
const provider = overrides?.provider ?? defaults?.provider ?? "auto";
|
|
54
|
+
const defaultRemote = defaults?.remote;
|
|
55
|
+
const overrideRemote = overrides?.remote;
|
|
56
|
+
const includeRemote = Boolean(overrideRemote?.baseUrl || overrideRemote?.apiKey || overrideRemote?.headers || defaultRemote?.baseUrl || defaultRemote?.apiKey || defaultRemote?.headers) || provider === "openai" || provider === "gemini" || provider === "auto";
|
|
57
|
+
const batch = {
|
|
58
|
+
enabled: overrideRemote?.batch?.enabled ?? defaultRemote?.batch?.enabled ?? true,
|
|
59
|
+
wait: overrideRemote?.batch?.wait ?? defaultRemote?.batch?.wait ?? true,
|
|
60
|
+
concurrency: Math.max(1, overrideRemote?.batch?.concurrency ?? defaultRemote?.batch?.concurrency ?? 2),
|
|
61
|
+
pollIntervalMs: overrideRemote?.batch?.pollIntervalMs ?? defaultRemote?.batch?.pollIntervalMs ?? 2e3,
|
|
62
|
+
timeoutMinutes: overrideRemote?.batch?.timeoutMinutes ?? defaultRemote?.batch?.timeoutMinutes ?? 60
|
|
63
|
+
};
|
|
64
|
+
const remote = includeRemote ? {
|
|
65
|
+
baseUrl: overrideRemote?.baseUrl ?? defaultRemote?.baseUrl,
|
|
66
|
+
apiKey: overrideRemote?.apiKey ?? defaultRemote?.apiKey,
|
|
67
|
+
headers: overrideRemote?.headers ?? defaultRemote?.headers,
|
|
68
|
+
batch
|
|
69
|
+
} : void 0;
|
|
70
|
+
const fallback = overrides?.fallback ?? defaults?.fallback ?? "none";
|
|
71
|
+
const modelDefault = provider === "gemini" ? DEFAULT_GEMINI_MODEL : provider === "openai" ? DEFAULT_OPENAI_MODEL : void 0;
|
|
72
|
+
const model = overrides?.model ?? defaults?.model ?? modelDefault ?? "";
|
|
73
|
+
const local = {
|
|
74
|
+
modelPath: overrides?.local?.modelPath ?? defaults?.local?.modelPath,
|
|
75
|
+
modelCacheDir: overrides?.local?.modelCacheDir ?? defaults?.local?.modelCacheDir
|
|
76
|
+
};
|
|
77
|
+
const sources = normalizeSources(overrides?.sources ?? defaults?.sources, sessionMemory);
|
|
78
|
+
const rawPaths = [...defaults?.extraPaths ?? [], ...overrides?.extraPaths ?? []].map((value) => value.trim()).filter(Boolean);
|
|
79
|
+
const extraPaths = Array.from(new Set(rawPaths));
|
|
80
|
+
const vector = {
|
|
81
|
+
enabled: overrides?.store?.vector?.enabled ?? defaults?.store?.vector?.enabled ?? true,
|
|
82
|
+
extensionPath: overrides?.store?.vector?.extensionPath ?? defaults?.store?.vector?.extensionPath
|
|
83
|
+
};
|
|
84
|
+
const store = {
|
|
85
|
+
driver: overrides?.store?.driver ?? defaults?.store?.driver ?? "sqlite",
|
|
86
|
+
path: resolveStorePath(agentId, overrides?.store?.path ?? defaults?.store?.path),
|
|
87
|
+
vector
|
|
88
|
+
};
|
|
89
|
+
const chunking = {
|
|
90
|
+
tokens: overrides?.chunking?.tokens ?? defaults?.chunking?.tokens ?? DEFAULT_CHUNK_TOKENS,
|
|
91
|
+
overlap: overrides?.chunking?.overlap ?? defaults?.chunking?.overlap ?? DEFAULT_CHUNK_OVERLAP
|
|
92
|
+
};
|
|
93
|
+
const sync = {
|
|
94
|
+
onSessionStart: overrides?.sync?.onSessionStart ?? defaults?.sync?.onSessionStart ?? true,
|
|
95
|
+
onSearch: overrides?.sync?.onSearch ?? defaults?.sync?.onSearch ?? true,
|
|
96
|
+
watch: overrides?.sync?.watch ?? defaults?.sync?.watch ?? true,
|
|
97
|
+
watchDebounceMs: overrides?.sync?.watchDebounceMs ?? defaults?.sync?.watchDebounceMs ?? DEFAULT_WATCH_DEBOUNCE_MS,
|
|
98
|
+
intervalMinutes: overrides?.sync?.intervalMinutes ?? defaults?.sync?.intervalMinutes ?? 0,
|
|
99
|
+
sessions: {
|
|
100
|
+
deltaBytes: overrides?.sync?.sessions?.deltaBytes ?? defaults?.sync?.sessions?.deltaBytes ?? DEFAULT_SESSION_DELTA_BYTES,
|
|
101
|
+
deltaMessages: overrides?.sync?.sessions?.deltaMessages ?? defaults?.sync?.sessions?.deltaMessages ?? DEFAULT_SESSION_DELTA_MESSAGES
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
const query = {
|
|
105
|
+
maxResults: overrides?.query?.maxResults ?? defaults?.query?.maxResults ?? DEFAULT_MAX_RESULTS,
|
|
106
|
+
minScore: overrides?.query?.minScore ?? defaults?.query?.minScore ?? DEFAULT_MIN_SCORE
|
|
107
|
+
};
|
|
108
|
+
const hybrid = {
|
|
109
|
+
enabled: overrides?.query?.hybrid?.enabled ?? defaults?.query?.hybrid?.enabled ?? DEFAULT_HYBRID_ENABLED,
|
|
110
|
+
vectorWeight: overrides?.query?.hybrid?.vectorWeight ?? defaults?.query?.hybrid?.vectorWeight ?? DEFAULT_HYBRID_VECTOR_WEIGHT,
|
|
111
|
+
textWeight: overrides?.query?.hybrid?.textWeight ?? defaults?.query?.hybrid?.textWeight ?? DEFAULT_HYBRID_TEXT_WEIGHT,
|
|
112
|
+
candidateMultiplier: overrides?.query?.hybrid?.candidateMultiplier ?? defaults?.query?.hybrid?.candidateMultiplier ?? DEFAULT_HYBRID_CANDIDATE_MULTIPLIER
|
|
113
|
+
};
|
|
114
|
+
const cache = {
|
|
115
|
+
enabled: overrides?.cache?.enabled ?? defaults?.cache?.enabled ?? DEFAULT_CACHE_ENABLED,
|
|
116
|
+
maxEntries: overrides?.cache?.maxEntries ?? defaults?.cache?.maxEntries
|
|
117
|
+
};
|
|
118
|
+
const overlap = clampNumber$1(chunking.overlap, 0, Math.max(0, chunking.tokens - 1));
|
|
119
|
+
const minScore = clampNumber$1(query.minScore, 0, 1);
|
|
120
|
+
const vectorWeight = clampNumber$1(hybrid.vectorWeight, 0, 1);
|
|
121
|
+
const textWeight = clampNumber$1(hybrid.textWeight, 0, 1);
|
|
122
|
+
const sum = vectorWeight + textWeight;
|
|
123
|
+
const normalizedVectorWeight = sum > 0 ? vectorWeight / sum : DEFAULT_HYBRID_VECTOR_WEIGHT;
|
|
124
|
+
const normalizedTextWeight = sum > 0 ? textWeight / sum : DEFAULT_HYBRID_TEXT_WEIGHT;
|
|
125
|
+
const candidateMultiplier = clampInt(hybrid.candidateMultiplier, 1, 20);
|
|
126
|
+
const deltaBytes = clampInt(sync.sessions.deltaBytes, 0, Number.MAX_SAFE_INTEGER);
|
|
127
|
+
const deltaMessages = clampInt(sync.sessions.deltaMessages, 0, Number.MAX_SAFE_INTEGER);
|
|
128
|
+
return {
|
|
129
|
+
enabled,
|
|
130
|
+
sources,
|
|
131
|
+
extraPaths,
|
|
132
|
+
provider,
|
|
133
|
+
remote,
|
|
134
|
+
experimental: { sessionMemory },
|
|
135
|
+
fallback,
|
|
136
|
+
model,
|
|
137
|
+
local,
|
|
138
|
+
store,
|
|
139
|
+
chunking: {
|
|
140
|
+
tokens: Math.max(1, chunking.tokens),
|
|
141
|
+
overlap
|
|
142
|
+
},
|
|
143
|
+
sync: {
|
|
144
|
+
...sync,
|
|
145
|
+
sessions: {
|
|
146
|
+
deltaBytes,
|
|
147
|
+
deltaMessages
|
|
148
|
+
}
|
|
149
|
+
},
|
|
150
|
+
query: {
|
|
151
|
+
...query,
|
|
152
|
+
minScore,
|
|
153
|
+
hybrid: {
|
|
154
|
+
enabled: Boolean(hybrid.enabled),
|
|
155
|
+
vectorWeight: normalizedVectorWeight,
|
|
156
|
+
textWeight: normalizedTextWeight,
|
|
157
|
+
candidateMultiplier
|
|
158
|
+
}
|
|
159
|
+
},
|
|
160
|
+
cache: {
|
|
161
|
+
enabled: Boolean(cache.enabled),
|
|
162
|
+
maxEntries: typeof cache.maxEntries === "number" && Number.isFinite(cache.maxEntries) ? Math.max(1, Math.floor(cache.maxEntries)) : void 0
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
function resolveMemorySearchConfig(cfg, agentId) {
|
|
167
|
+
const defaults = cfg.agents?.defaults?.memorySearch;
|
|
168
|
+
const overrides = resolveAgentConfig(cfg, agentId)?.memorySearch;
|
|
169
|
+
const resolved = mergeConfig(defaults, overrides, agentId);
|
|
170
|
+
if (!resolved.enabled) return null;
|
|
171
|
+
return resolved;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
//#endregion
|
|
175
|
+
//#region src/memory/batch-gemini.ts
|
|
176
|
+
const GEMINI_BATCH_MAX_REQUESTS = 5e4;
|
|
177
|
+
const debugEmbeddings$1 = isTruthyEnvValue(process.env.OPENCLAW_DEBUG_MEMORY_EMBEDDINGS);
|
|
178
|
+
const log$2 = createSubsystemLogger("memory/embeddings");
|
|
179
|
+
const debugLog$1 = (message, meta) => {
|
|
180
|
+
if (!debugEmbeddings$1) return;
|
|
181
|
+
const suffix = meta ? ` ${JSON.stringify(meta)}` : "";
|
|
182
|
+
log$2.raw(`${message}${suffix}`);
|
|
183
|
+
};
|
|
184
|
+
function getGeminiBaseUrl(gemini) {
|
|
185
|
+
return gemini.baseUrl?.replace(/\/$/, "") ?? "";
|
|
186
|
+
}
|
|
187
|
+
function getGeminiHeaders(gemini, params) {
|
|
188
|
+
const headers = gemini.headers ? { ...gemini.headers } : {};
|
|
189
|
+
if (params.json) {
|
|
190
|
+
if (!headers["Content-Type"] && !headers["content-type"]) headers["Content-Type"] = "application/json";
|
|
191
|
+
} else {
|
|
192
|
+
delete headers["Content-Type"];
|
|
193
|
+
delete headers["content-type"];
|
|
194
|
+
}
|
|
195
|
+
return headers;
|
|
196
|
+
}
|
|
197
|
+
function getGeminiUploadUrl(baseUrl) {
|
|
198
|
+
if (baseUrl.includes("/v1beta")) return baseUrl.replace(/\/v1beta\/?$/, "/upload/v1beta");
|
|
199
|
+
return `${baseUrl.replace(/\/$/, "")}/upload`;
|
|
200
|
+
}
|
|
201
|
+
function splitGeminiBatchRequests(requests) {
|
|
202
|
+
if (requests.length <= GEMINI_BATCH_MAX_REQUESTS) return [requests];
|
|
203
|
+
const groups = [];
|
|
204
|
+
for (let i = 0; i < requests.length; i += GEMINI_BATCH_MAX_REQUESTS) groups.push(requests.slice(i, i + GEMINI_BATCH_MAX_REQUESTS));
|
|
205
|
+
return groups;
|
|
206
|
+
}
|
|
207
|
+
function buildGeminiUploadBody(params) {
|
|
208
|
+
const boundary = `openclaw-${hashText(params.displayName)}`;
|
|
209
|
+
const jsonPart = JSON.stringify({ file: {
|
|
210
|
+
displayName: params.displayName,
|
|
211
|
+
mimeType: "application/jsonl"
|
|
212
|
+
} });
|
|
213
|
+
const delimiter = `--${boundary}\r\n`;
|
|
214
|
+
const closeDelimiter = `--${boundary}--\r\n`;
|
|
215
|
+
const parts = [
|
|
216
|
+
`${delimiter}Content-Type: application/json; charset=UTF-8\r\n\r\n${jsonPart}\r\n`,
|
|
217
|
+
`${delimiter}Content-Type: application/jsonl; charset=UTF-8\r\n\r\n${params.jsonl}\r\n`,
|
|
218
|
+
closeDelimiter
|
|
219
|
+
];
|
|
220
|
+
return {
|
|
221
|
+
body: new Blob([parts.join("")], { type: "multipart/related" }),
|
|
222
|
+
contentType: `multipart/related; boundary=${boundary}`
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
async function submitGeminiBatch(params) {
|
|
226
|
+
const baseUrl = getGeminiBaseUrl(params.gemini);
|
|
227
|
+
const uploadPayload = buildGeminiUploadBody({
|
|
228
|
+
jsonl: params.requests.map((request) => JSON.stringify({
|
|
229
|
+
key: request.custom_id,
|
|
230
|
+
request: {
|
|
231
|
+
content: request.content,
|
|
232
|
+
task_type: request.taskType
|
|
233
|
+
}
|
|
234
|
+
})).join("\n"),
|
|
235
|
+
displayName: `memory-embeddings-${hashText(String(Date.now()))}`
|
|
236
|
+
});
|
|
237
|
+
const uploadUrl = `${getGeminiUploadUrl(baseUrl)}/files?uploadType=multipart`;
|
|
238
|
+
debugLog$1("memory embeddings: gemini batch upload", {
|
|
239
|
+
uploadUrl,
|
|
240
|
+
baseUrl,
|
|
241
|
+
requests: params.requests.length
|
|
242
|
+
});
|
|
243
|
+
const fileRes = await fetch(uploadUrl, {
|
|
244
|
+
method: "POST",
|
|
245
|
+
headers: {
|
|
246
|
+
...getGeminiHeaders(params.gemini, { json: false }),
|
|
247
|
+
"Content-Type": uploadPayload.contentType
|
|
248
|
+
},
|
|
249
|
+
body: uploadPayload.body
|
|
250
|
+
});
|
|
251
|
+
if (!fileRes.ok) {
|
|
252
|
+
const text = await fileRes.text();
|
|
253
|
+
throw new Error(`gemini batch file upload failed: ${fileRes.status} ${text}`);
|
|
254
|
+
}
|
|
255
|
+
const filePayload = await fileRes.json();
|
|
256
|
+
const fileId = filePayload.name ?? filePayload.file?.name;
|
|
257
|
+
if (!fileId) throw new Error("gemini batch file upload failed: missing file id");
|
|
258
|
+
const batchBody = { batch: {
|
|
259
|
+
displayName: `memory-embeddings-${params.agentId}`,
|
|
260
|
+
inputConfig: { file_name: fileId }
|
|
261
|
+
} };
|
|
262
|
+
const batchEndpoint = `${baseUrl}/${params.gemini.modelPath}:asyncBatchEmbedContent`;
|
|
263
|
+
debugLog$1("memory embeddings: gemini batch create", {
|
|
264
|
+
batchEndpoint,
|
|
265
|
+
fileId
|
|
266
|
+
});
|
|
267
|
+
const batchRes = await fetch(batchEndpoint, {
|
|
268
|
+
method: "POST",
|
|
269
|
+
headers: getGeminiHeaders(params.gemini, { json: true }),
|
|
270
|
+
body: JSON.stringify(batchBody)
|
|
271
|
+
});
|
|
272
|
+
if (batchRes.ok) return await batchRes.json();
|
|
273
|
+
const text = await batchRes.text();
|
|
274
|
+
if (batchRes.status === 404) throw new Error("gemini batch create failed: 404 (asyncBatchEmbedContent not available for this model/baseUrl). Disable remote.batch.enabled or switch providers.");
|
|
275
|
+
throw new Error(`gemini batch create failed: ${batchRes.status} ${text}`);
|
|
276
|
+
}
|
|
277
|
+
async function fetchGeminiBatchStatus(params) {
|
|
278
|
+
const statusUrl = `${getGeminiBaseUrl(params.gemini)}/${params.batchName.startsWith("batches/") ? params.batchName : `batches/${params.batchName}`}`;
|
|
279
|
+
debugLog$1("memory embeddings: gemini batch status", { statusUrl });
|
|
280
|
+
const res = await fetch(statusUrl, { headers: getGeminiHeaders(params.gemini, { json: true }) });
|
|
281
|
+
if (!res.ok) {
|
|
282
|
+
const text = await res.text();
|
|
283
|
+
throw new Error(`gemini batch status failed: ${res.status} ${text}`);
|
|
284
|
+
}
|
|
285
|
+
return await res.json();
|
|
286
|
+
}
|
|
287
|
+
async function fetchGeminiFileContent(params) {
|
|
288
|
+
const downloadUrl = `${getGeminiBaseUrl(params.gemini)}/${params.fileId.startsWith("files/") ? params.fileId : `files/${params.fileId}`}:download`;
|
|
289
|
+
debugLog$1("memory embeddings: gemini batch download", { downloadUrl });
|
|
290
|
+
const res = await fetch(downloadUrl, { headers: getGeminiHeaders(params.gemini, { json: true }) });
|
|
291
|
+
if (!res.ok) {
|
|
292
|
+
const text = await res.text();
|
|
293
|
+
throw new Error(`gemini batch file content failed: ${res.status} ${text}`);
|
|
294
|
+
}
|
|
295
|
+
return await res.text();
|
|
296
|
+
}
|
|
297
|
+
function parseGeminiBatchOutput(text) {
|
|
298
|
+
if (!text.trim()) return [];
|
|
299
|
+
return text.split("\n").map((line) => line.trim()).filter(Boolean).map((line) => JSON.parse(line));
|
|
300
|
+
}
|
|
301
|
+
async function waitForGeminiBatch(params) {
|
|
302
|
+
const start = Date.now();
|
|
303
|
+
let current = params.initial;
|
|
304
|
+
while (true) {
|
|
305
|
+
const status = current ?? await fetchGeminiBatchStatus({
|
|
306
|
+
gemini: params.gemini,
|
|
307
|
+
batchName: params.batchName
|
|
308
|
+
});
|
|
309
|
+
const state = status.state ?? "UNKNOWN";
|
|
310
|
+
if ([
|
|
311
|
+
"SUCCEEDED",
|
|
312
|
+
"COMPLETED",
|
|
313
|
+
"DONE"
|
|
314
|
+
].includes(state)) {
|
|
315
|
+
const outputFileId = status.outputConfig?.file ?? status.outputConfig?.fileId ?? status.metadata?.output?.responsesFile;
|
|
316
|
+
if (!outputFileId) throw new Error(`gemini batch ${params.batchName} completed without output file`);
|
|
317
|
+
return { outputFileId };
|
|
318
|
+
}
|
|
319
|
+
if ([
|
|
320
|
+
"FAILED",
|
|
321
|
+
"CANCELLED",
|
|
322
|
+
"CANCELED",
|
|
323
|
+
"EXPIRED"
|
|
324
|
+
].includes(state)) {
|
|
325
|
+
const message = status.error?.message ?? "unknown error";
|
|
326
|
+
throw new Error(`gemini batch ${params.batchName} ${state}: ${message}`);
|
|
327
|
+
}
|
|
328
|
+
if (!params.wait) throw new Error(`gemini batch ${params.batchName} still ${state}; wait disabled`);
|
|
329
|
+
if (Date.now() - start > params.timeoutMs) throw new Error(`gemini batch ${params.batchName} timed out after ${params.timeoutMs}ms`);
|
|
330
|
+
params.debug?.(`gemini batch ${params.batchName} ${state}; waiting ${params.pollIntervalMs}ms`);
|
|
331
|
+
await new Promise((resolve) => setTimeout(resolve, params.pollIntervalMs));
|
|
332
|
+
current = void 0;
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
async function runWithConcurrency$1(tasks, limit) {
|
|
336
|
+
if (tasks.length === 0) return [];
|
|
337
|
+
const resolvedLimit = Math.max(1, Math.min(limit, tasks.length));
|
|
338
|
+
const results = Array.from({ length: tasks.length });
|
|
339
|
+
let next = 0;
|
|
340
|
+
let firstError = null;
|
|
341
|
+
const workers = Array.from({ length: resolvedLimit }, async () => {
|
|
342
|
+
while (true) {
|
|
343
|
+
if (firstError) return;
|
|
344
|
+
const index = next;
|
|
345
|
+
next += 1;
|
|
346
|
+
if (index >= tasks.length) return;
|
|
347
|
+
try {
|
|
348
|
+
results[index] = await tasks[index]();
|
|
349
|
+
} catch (err) {
|
|
350
|
+
firstError = err;
|
|
351
|
+
return;
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
});
|
|
355
|
+
await Promise.allSettled(workers);
|
|
356
|
+
if (firstError) throw firstError;
|
|
357
|
+
return results;
|
|
358
|
+
}
|
|
359
|
+
async function runGeminiEmbeddingBatches(params) {
|
|
360
|
+
if (params.requests.length === 0) return /* @__PURE__ */ new Map();
|
|
361
|
+
const groups = splitGeminiBatchRequests(params.requests);
|
|
362
|
+
const byCustomId = /* @__PURE__ */ new Map();
|
|
363
|
+
const tasks = groups.map((group, groupIndex) => async () => {
|
|
364
|
+
const batchInfo = await submitGeminiBatch({
|
|
365
|
+
gemini: params.gemini,
|
|
366
|
+
requests: group,
|
|
367
|
+
agentId: params.agentId
|
|
368
|
+
});
|
|
369
|
+
const batchName = batchInfo.name ?? "";
|
|
370
|
+
if (!batchName) throw new Error("gemini batch create failed: missing batch name");
|
|
371
|
+
params.debug?.("memory embeddings: gemini batch created", {
|
|
372
|
+
batchName,
|
|
373
|
+
state: batchInfo.state,
|
|
374
|
+
group: groupIndex + 1,
|
|
375
|
+
groups: groups.length,
|
|
376
|
+
requests: group.length
|
|
377
|
+
});
|
|
378
|
+
if (!params.wait && batchInfo.state && ![
|
|
379
|
+
"SUCCEEDED",
|
|
380
|
+
"COMPLETED",
|
|
381
|
+
"DONE"
|
|
382
|
+
].includes(batchInfo.state)) throw new Error(`gemini batch ${batchName} submitted; enable remote.batch.wait to await completion`);
|
|
383
|
+
const completed = batchInfo.state && [
|
|
384
|
+
"SUCCEEDED",
|
|
385
|
+
"COMPLETED",
|
|
386
|
+
"DONE"
|
|
387
|
+
].includes(batchInfo.state) ? { outputFileId: batchInfo.outputConfig?.file ?? batchInfo.outputConfig?.fileId ?? batchInfo.metadata?.output?.responsesFile ?? "" } : await waitForGeminiBatch({
|
|
388
|
+
gemini: params.gemini,
|
|
389
|
+
batchName,
|
|
390
|
+
wait: params.wait,
|
|
391
|
+
pollIntervalMs: params.pollIntervalMs,
|
|
392
|
+
timeoutMs: params.timeoutMs,
|
|
393
|
+
debug: params.debug,
|
|
394
|
+
initial: batchInfo
|
|
395
|
+
});
|
|
396
|
+
if (!completed.outputFileId) throw new Error(`gemini batch ${batchName} completed without output file`);
|
|
397
|
+
const outputLines = parseGeminiBatchOutput(await fetchGeminiFileContent({
|
|
398
|
+
gemini: params.gemini,
|
|
399
|
+
fileId: completed.outputFileId
|
|
400
|
+
}));
|
|
401
|
+
const errors = [];
|
|
402
|
+
const remaining = new Set(group.map((request) => request.custom_id));
|
|
403
|
+
for (const line of outputLines) {
|
|
404
|
+
const customId = line.key ?? line.custom_id ?? line.request_id;
|
|
405
|
+
if (!customId) continue;
|
|
406
|
+
remaining.delete(customId);
|
|
407
|
+
if (line.error?.message) {
|
|
408
|
+
errors.push(`${customId}: ${line.error.message}`);
|
|
409
|
+
continue;
|
|
410
|
+
}
|
|
411
|
+
if (line.response?.error?.message) {
|
|
412
|
+
errors.push(`${customId}: ${line.response.error.message}`);
|
|
413
|
+
continue;
|
|
414
|
+
}
|
|
415
|
+
const embedding = line.embedding?.values ?? line.response?.embedding?.values ?? [];
|
|
416
|
+
if (embedding.length === 0) {
|
|
417
|
+
errors.push(`${customId}: empty embedding`);
|
|
418
|
+
continue;
|
|
419
|
+
}
|
|
420
|
+
byCustomId.set(customId, embedding);
|
|
421
|
+
}
|
|
422
|
+
if (errors.length > 0) throw new Error(`gemini batch ${batchName} failed: ${errors.join("; ")}`);
|
|
423
|
+
if (remaining.size > 0) throw new Error(`gemini batch ${batchName} missing ${remaining.size} embedding responses`);
|
|
424
|
+
});
|
|
425
|
+
params.debug?.("memory embeddings: gemini batch submit", {
|
|
426
|
+
requests: params.requests.length,
|
|
427
|
+
groups: groups.length,
|
|
428
|
+
wait: params.wait,
|
|
429
|
+
concurrency: params.concurrency,
|
|
430
|
+
pollIntervalMs: params.pollIntervalMs,
|
|
431
|
+
timeoutMs: params.timeoutMs
|
|
432
|
+
});
|
|
433
|
+
await runWithConcurrency$1(tasks, params.concurrency);
|
|
434
|
+
return byCustomId;
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
//#endregion
|
|
438
|
+
//#region src/infra/retry.ts
|
|
439
|
+
const DEFAULT_RETRY_CONFIG = {
|
|
440
|
+
attempts: 3,
|
|
441
|
+
minDelayMs: 300,
|
|
442
|
+
maxDelayMs: 3e4,
|
|
443
|
+
jitter: 0
|
|
444
|
+
};
|
|
445
|
+
const asFiniteNumber = (value) => typeof value === "number" && Number.isFinite(value) ? value : void 0;
|
|
446
|
+
const clampNumber = (value, fallback, min, max) => {
|
|
447
|
+
const next = asFiniteNumber(value);
|
|
448
|
+
if (next === void 0) return fallback;
|
|
449
|
+
const floor = typeof min === "number" ? min : Number.NEGATIVE_INFINITY;
|
|
450
|
+
const ceiling = typeof max === "number" ? max : Number.POSITIVE_INFINITY;
|
|
451
|
+
return Math.min(Math.max(next, floor), ceiling);
|
|
452
|
+
};
|
|
453
|
+
function resolveRetryConfig(defaults = DEFAULT_RETRY_CONFIG, overrides) {
|
|
454
|
+
const attempts = Math.max(1, Math.round(clampNumber(overrides?.attempts, defaults.attempts, 1)));
|
|
455
|
+
const minDelayMs = Math.max(0, Math.round(clampNumber(overrides?.minDelayMs, defaults.minDelayMs, 0)));
|
|
456
|
+
return {
|
|
457
|
+
attempts,
|
|
458
|
+
minDelayMs,
|
|
459
|
+
maxDelayMs: Math.max(minDelayMs, Math.round(clampNumber(overrides?.maxDelayMs, defaults.maxDelayMs, 0))),
|
|
460
|
+
jitter: clampNumber(overrides?.jitter, defaults.jitter, 0, 1)
|
|
461
|
+
};
|
|
462
|
+
}
|
|
463
|
+
function applyJitter(delayMs, jitter) {
|
|
464
|
+
if (jitter <= 0) return delayMs;
|
|
465
|
+
const offset = (Math.random() * 2 - 1) * jitter;
|
|
466
|
+
return Math.max(0, Math.round(delayMs * (1 + offset)));
|
|
467
|
+
}
|
|
468
|
+
async function retryAsync(fn, attemptsOrOptions = 3, initialDelayMs = 300) {
|
|
469
|
+
if (typeof attemptsOrOptions === "number") {
|
|
470
|
+
const attempts = Math.max(1, Math.round(attemptsOrOptions));
|
|
471
|
+
let lastErr;
|
|
472
|
+
for (let i = 0; i < attempts; i += 1) try {
|
|
473
|
+
return await fn();
|
|
474
|
+
} catch (err) {
|
|
475
|
+
lastErr = err;
|
|
476
|
+
if (i === attempts - 1) break;
|
|
477
|
+
await sleep(initialDelayMs * 2 ** i);
|
|
478
|
+
}
|
|
479
|
+
throw lastErr ?? /* @__PURE__ */ new Error("Retry failed");
|
|
480
|
+
}
|
|
481
|
+
const options = attemptsOrOptions;
|
|
482
|
+
const resolved = resolveRetryConfig(DEFAULT_RETRY_CONFIG, options);
|
|
483
|
+
const maxAttempts = resolved.attempts;
|
|
484
|
+
const minDelayMs = resolved.minDelayMs;
|
|
485
|
+
const maxDelayMs = Number.isFinite(resolved.maxDelayMs) && resolved.maxDelayMs > 0 ? resolved.maxDelayMs : Number.POSITIVE_INFINITY;
|
|
486
|
+
const jitter = resolved.jitter;
|
|
487
|
+
const shouldRetry = options.shouldRetry ?? (() => true);
|
|
488
|
+
let lastErr;
|
|
489
|
+
for (let attempt = 1; attempt <= maxAttempts; attempt += 1) try {
|
|
490
|
+
return await fn();
|
|
491
|
+
} catch (err) {
|
|
492
|
+
lastErr = err;
|
|
493
|
+
if (attempt >= maxAttempts || !shouldRetry(err, attempt)) break;
|
|
494
|
+
const retryAfterMs = options.retryAfterMs?.(err);
|
|
495
|
+
const baseDelay = typeof retryAfterMs === "number" && Number.isFinite(retryAfterMs) ? Math.max(retryAfterMs, minDelayMs) : minDelayMs * 2 ** (attempt - 1);
|
|
496
|
+
let delay = Math.min(baseDelay, maxDelayMs);
|
|
497
|
+
delay = applyJitter(delay, jitter);
|
|
498
|
+
delay = Math.min(Math.max(delay, minDelayMs), maxDelayMs);
|
|
499
|
+
options.onRetry?.({
|
|
500
|
+
attempt,
|
|
501
|
+
maxAttempts,
|
|
502
|
+
delayMs: delay,
|
|
503
|
+
err,
|
|
504
|
+
label: options.label
|
|
505
|
+
});
|
|
506
|
+
await sleep(delay);
|
|
507
|
+
}
|
|
508
|
+
throw lastErr ?? /* @__PURE__ */ new Error("Retry failed");
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
//#endregion
|
|
512
|
+
//#region src/memory/batch-openai.ts
|
|
513
|
+
const OPENAI_BATCH_ENDPOINT = "/v1/embeddings";
|
|
514
|
+
const OPENAI_BATCH_COMPLETION_WINDOW = "24h";
|
|
515
|
+
const OPENAI_BATCH_MAX_REQUESTS = 5e4;
|
|
516
|
+
function getOpenAiBaseUrl(openAi) {
|
|
517
|
+
return openAi.baseUrl?.replace(/\/$/, "") ?? "";
|
|
518
|
+
}
|
|
519
|
+
function getOpenAiHeaders(openAi, params) {
|
|
520
|
+
const headers = openAi.headers ? { ...openAi.headers } : {};
|
|
521
|
+
if (params.json) {
|
|
522
|
+
if (!headers["Content-Type"] && !headers["content-type"]) headers["Content-Type"] = "application/json";
|
|
523
|
+
} else {
|
|
524
|
+
delete headers["Content-Type"];
|
|
525
|
+
delete headers["content-type"];
|
|
526
|
+
}
|
|
527
|
+
return headers;
|
|
528
|
+
}
|
|
529
|
+
function splitOpenAiBatchRequests(requests) {
|
|
530
|
+
if (requests.length <= OPENAI_BATCH_MAX_REQUESTS) return [requests];
|
|
531
|
+
const groups = [];
|
|
532
|
+
for (let i = 0; i < requests.length; i += OPENAI_BATCH_MAX_REQUESTS) groups.push(requests.slice(i, i + OPENAI_BATCH_MAX_REQUESTS));
|
|
533
|
+
return groups;
|
|
534
|
+
}
|
|
535
|
+
async function submitOpenAiBatch(params) {
|
|
536
|
+
const baseUrl = getOpenAiBaseUrl(params.openAi);
|
|
537
|
+
const jsonl = params.requests.map((request) => JSON.stringify(request)).join("\n");
|
|
538
|
+
const form = new FormData();
|
|
539
|
+
form.append("purpose", "batch");
|
|
540
|
+
form.append("file", new Blob([jsonl], { type: "application/jsonl" }), `memory-embeddings.${hashText(String(Date.now()))}.jsonl`);
|
|
541
|
+
const fileRes = await fetch(`${baseUrl}/files`, {
|
|
542
|
+
method: "POST",
|
|
543
|
+
headers: getOpenAiHeaders(params.openAi, { json: false }),
|
|
544
|
+
body: form
|
|
545
|
+
});
|
|
546
|
+
if (!fileRes.ok) {
|
|
547
|
+
const text = await fileRes.text();
|
|
548
|
+
throw new Error(`openai batch file upload failed: ${fileRes.status} ${text}`);
|
|
549
|
+
}
|
|
550
|
+
const filePayload = await fileRes.json();
|
|
551
|
+
if (!filePayload.id) throw new Error("openai batch file upload failed: missing file id");
|
|
552
|
+
return await (await retryAsync(async () => {
|
|
553
|
+
const res = await fetch(`${baseUrl}/batches`, {
|
|
554
|
+
method: "POST",
|
|
555
|
+
headers: getOpenAiHeaders(params.openAi, { json: true }),
|
|
556
|
+
body: JSON.stringify({
|
|
557
|
+
input_file_id: filePayload.id,
|
|
558
|
+
endpoint: OPENAI_BATCH_ENDPOINT,
|
|
559
|
+
completion_window: OPENAI_BATCH_COMPLETION_WINDOW,
|
|
560
|
+
metadata: {
|
|
561
|
+
source: "openclaw-memory",
|
|
562
|
+
agent: params.agentId
|
|
563
|
+
}
|
|
564
|
+
})
|
|
565
|
+
});
|
|
566
|
+
if (!res.ok) {
|
|
567
|
+
const text = await res.text();
|
|
568
|
+
const err = /* @__PURE__ */ new Error(`openai batch create failed: ${res.status} ${text}`);
|
|
569
|
+
err.status = res.status;
|
|
570
|
+
throw err;
|
|
571
|
+
}
|
|
572
|
+
return res;
|
|
573
|
+
}, {
|
|
574
|
+
attempts: 3,
|
|
575
|
+
minDelayMs: 300,
|
|
576
|
+
maxDelayMs: 2e3,
|
|
577
|
+
jitter: .2,
|
|
578
|
+
shouldRetry: (err) => {
|
|
579
|
+
const status = err.status;
|
|
580
|
+
return status === 429 || typeof status === "number" && status >= 500;
|
|
581
|
+
}
|
|
582
|
+
})).json();
|
|
583
|
+
}
|
|
584
|
+
async function fetchOpenAiBatchStatus(params) {
|
|
585
|
+
const baseUrl = getOpenAiBaseUrl(params.openAi);
|
|
586
|
+
const res = await fetch(`${baseUrl}/batches/${params.batchId}`, { headers: getOpenAiHeaders(params.openAi, { json: true }) });
|
|
587
|
+
if (!res.ok) {
|
|
588
|
+
const text = await res.text();
|
|
589
|
+
throw new Error(`openai batch status failed: ${res.status} ${text}`);
|
|
590
|
+
}
|
|
591
|
+
return await res.json();
|
|
592
|
+
}
|
|
593
|
+
async function fetchOpenAiFileContent(params) {
|
|
594
|
+
const baseUrl = getOpenAiBaseUrl(params.openAi);
|
|
595
|
+
const res = await fetch(`${baseUrl}/files/${params.fileId}/content`, { headers: getOpenAiHeaders(params.openAi, { json: true }) });
|
|
596
|
+
if (!res.ok) {
|
|
597
|
+
const text = await res.text();
|
|
598
|
+
throw new Error(`openai batch file content failed: ${res.status} ${text}`);
|
|
599
|
+
}
|
|
600
|
+
return await res.text();
|
|
601
|
+
}
|
|
602
|
+
function parseOpenAiBatchOutput(text) {
|
|
603
|
+
if (!text.trim()) return [];
|
|
604
|
+
return text.split("\n").map((line) => line.trim()).filter(Boolean).map((line) => JSON.parse(line));
|
|
605
|
+
}
|
|
606
|
+
async function readOpenAiBatchError(params) {
|
|
607
|
+
try {
|
|
608
|
+
const first = parseOpenAiBatchOutput(await fetchOpenAiFileContent({
|
|
609
|
+
openAi: params.openAi,
|
|
610
|
+
fileId: params.errorFileId
|
|
611
|
+
})).find((line) => line.error?.message || line.response?.body?.error);
|
|
612
|
+
return first?.error?.message ?? (typeof first?.response?.body?.error?.message === "string" ? first?.response?.body?.error?.message : void 0);
|
|
613
|
+
} catch (err) {
|
|
614
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
615
|
+
return message ? `error file unavailable: ${message}` : void 0;
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
async function waitForOpenAiBatch(params) {
|
|
619
|
+
const start = Date.now();
|
|
620
|
+
let current = params.initial;
|
|
621
|
+
while (true) {
|
|
622
|
+
const status = current ?? await fetchOpenAiBatchStatus({
|
|
623
|
+
openAi: params.openAi,
|
|
624
|
+
batchId: params.batchId
|
|
625
|
+
});
|
|
626
|
+
const state = status.status ?? "unknown";
|
|
627
|
+
if (state === "completed") {
|
|
628
|
+
if (!status.output_file_id) throw new Error(`openai batch ${params.batchId} completed without output file`);
|
|
629
|
+
return {
|
|
630
|
+
outputFileId: status.output_file_id,
|
|
631
|
+
errorFileId: status.error_file_id ?? void 0
|
|
632
|
+
};
|
|
633
|
+
}
|
|
634
|
+
if ([
|
|
635
|
+
"failed",
|
|
636
|
+
"expired",
|
|
637
|
+
"cancelled",
|
|
638
|
+
"canceled"
|
|
639
|
+
].includes(state)) {
|
|
640
|
+
const detail = status.error_file_id ? await readOpenAiBatchError({
|
|
641
|
+
openAi: params.openAi,
|
|
642
|
+
errorFileId: status.error_file_id
|
|
643
|
+
}) : void 0;
|
|
644
|
+
const suffix = detail ? `: ${detail}` : "";
|
|
645
|
+
throw new Error(`openai batch ${params.batchId} ${state}${suffix}`);
|
|
646
|
+
}
|
|
647
|
+
if (!params.wait) throw new Error(`openai batch ${params.batchId} still ${state}; wait disabled`);
|
|
648
|
+
if (Date.now() - start > params.timeoutMs) throw new Error(`openai batch ${params.batchId} timed out after ${params.timeoutMs}ms`);
|
|
649
|
+
params.debug?.(`openai batch ${params.batchId} ${state}; waiting ${params.pollIntervalMs}ms`);
|
|
650
|
+
await new Promise((resolve) => setTimeout(resolve, params.pollIntervalMs));
|
|
651
|
+
current = void 0;
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
async function runWithConcurrency(tasks, limit) {
|
|
655
|
+
if (tasks.length === 0) return [];
|
|
656
|
+
const resolvedLimit = Math.max(1, Math.min(limit, tasks.length));
|
|
657
|
+
const results = Array.from({ length: tasks.length });
|
|
658
|
+
let next = 0;
|
|
659
|
+
let firstError = null;
|
|
660
|
+
const workers = Array.from({ length: resolvedLimit }, async () => {
|
|
661
|
+
while (true) {
|
|
662
|
+
if (firstError) return;
|
|
663
|
+
const index = next;
|
|
664
|
+
next += 1;
|
|
665
|
+
if (index >= tasks.length) return;
|
|
666
|
+
try {
|
|
667
|
+
results[index] = await tasks[index]();
|
|
668
|
+
} catch (err) {
|
|
669
|
+
firstError = err;
|
|
670
|
+
return;
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
});
|
|
674
|
+
await Promise.allSettled(workers);
|
|
675
|
+
if (firstError) throw firstError;
|
|
676
|
+
return results;
|
|
677
|
+
}
|
|
678
|
+
async function runOpenAiEmbeddingBatches(params) {
|
|
679
|
+
if (params.requests.length === 0) return /* @__PURE__ */ new Map();
|
|
680
|
+
const groups = splitOpenAiBatchRequests(params.requests);
|
|
681
|
+
const byCustomId = /* @__PURE__ */ new Map();
|
|
682
|
+
const tasks = groups.map((group, groupIndex) => async () => {
|
|
683
|
+
const batchInfo = await submitOpenAiBatch({
|
|
684
|
+
openAi: params.openAi,
|
|
685
|
+
requests: group,
|
|
686
|
+
agentId: params.agentId
|
|
687
|
+
});
|
|
688
|
+
if (!batchInfo.id) throw new Error("openai batch create failed: missing batch id");
|
|
689
|
+
params.debug?.("memory embeddings: openai batch created", {
|
|
690
|
+
batchId: batchInfo.id,
|
|
691
|
+
status: batchInfo.status,
|
|
692
|
+
group: groupIndex + 1,
|
|
693
|
+
groups: groups.length,
|
|
694
|
+
requests: group.length
|
|
695
|
+
});
|
|
696
|
+
if (!params.wait && batchInfo.status !== "completed") throw new Error(`openai batch ${batchInfo.id} submitted; enable remote.batch.wait to await completion`);
|
|
697
|
+
const completed = batchInfo.status === "completed" ? {
|
|
698
|
+
outputFileId: batchInfo.output_file_id ?? "",
|
|
699
|
+
errorFileId: batchInfo.error_file_id ?? void 0
|
|
700
|
+
} : await waitForOpenAiBatch({
|
|
701
|
+
openAi: params.openAi,
|
|
702
|
+
batchId: batchInfo.id,
|
|
703
|
+
wait: params.wait,
|
|
704
|
+
pollIntervalMs: params.pollIntervalMs,
|
|
705
|
+
timeoutMs: params.timeoutMs,
|
|
706
|
+
debug: params.debug,
|
|
707
|
+
initial: batchInfo
|
|
708
|
+
});
|
|
709
|
+
if (!completed.outputFileId) throw new Error(`openai batch ${batchInfo.id} completed without output file`);
|
|
710
|
+
const outputLines = parseOpenAiBatchOutput(await fetchOpenAiFileContent({
|
|
711
|
+
openAi: params.openAi,
|
|
712
|
+
fileId: completed.outputFileId
|
|
713
|
+
}));
|
|
714
|
+
const errors = [];
|
|
715
|
+
const remaining = new Set(group.map((request) => request.custom_id));
|
|
716
|
+
for (const line of outputLines) {
|
|
717
|
+
const customId = line.custom_id;
|
|
718
|
+
if (!customId) continue;
|
|
719
|
+
remaining.delete(customId);
|
|
720
|
+
if (line.error?.message) {
|
|
721
|
+
errors.push(`${customId}: ${line.error.message}`);
|
|
722
|
+
continue;
|
|
723
|
+
}
|
|
724
|
+
const response = line.response;
|
|
725
|
+
if ((response?.status_code ?? 0) >= 400) {
|
|
726
|
+
const message = response?.body?.error?.message ?? (typeof response?.body === "string" ? response.body : void 0) ?? "unknown error";
|
|
727
|
+
errors.push(`${customId}: ${message}`);
|
|
728
|
+
continue;
|
|
729
|
+
}
|
|
730
|
+
const embedding = (response?.body?.data ?? [])[0]?.embedding ?? [];
|
|
731
|
+
if (embedding.length === 0) {
|
|
732
|
+
errors.push(`${customId}: empty embedding`);
|
|
733
|
+
continue;
|
|
734
|
+
}
|
|
735
|
+
byCustomId.set(customId, embedding);
|
|
736
|
+
}
|
|
737
|
+
if (errors.length > 0) throw new Error(`openai batch ${batchInfo.id} failed: ${errors.join("; ")}`);
|
|
738
|
+
if (remaining.size > 0) throw new Error(`openai batch ${batchInfo.id} missing ${remaining.size} embedding responses`);
|
|
739
|
+
});
|
|
740
|
+
params.debug?.("memory embeddings: openai batch submit", {
|
|
741
|
+
requests: params.requests.length,
|
|
742
|
+
groups: groups.length,
|
|
743
|
+
wait: params.wait,
|
|
744
|
+
concurrency: params.concurrency,
|
|
745
|
+
pollIntervalMs: params.pollIntervalMs,
|
|
746
|
+
timeoutMs: params.timeoutMs
|
|
747
|
+
});
|
|
748
|
+
await runWithConcurrency(tasks, params.concurrency);
|
|
749
|
+
return byCustomId;
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
//#endregion
|
|
753
|
+
//#region src/memory/embeddings-gemini.ts
|
|
754
|
+
const DEFAULT_GEMINI_BASE_URL = "https://generativelanguage.googleapis.com/v1beta";
|
|
755
|
+
const DEFAULT_GEMINI_EMBEDDING_MODEL = "gemini-embedding-001";
|
|
756
|
+
const debugEmbeddings = isTruthyEnvValue(process.env.OPENCLAW_DEBUG_MEMORY_EMBEDDINGS);
|
|
757
|
+
const log$1 = createSubsystemLogger("memory/embeddings");
|
|
758
|
+
const debugLog = (message, meta) => {
|
|
759
|
+
if (!debugEmbeddings) return;
|
|
760
|
+
const suffix = meta ? ` ${JSON.stringify(meta)}` : "";
|
|
761
|
+
log$1.raw(`${message}${suffix}`);
|
|
762
|
+
};
|
|
763
|
+
function resolveRemoteApiKey(remoteApiKey) {
|
|
764
|
+
const trimmed = remoteApiKey?.trim();
|
|
765
|
+
if (!trimmed) return;
|
|
766
|
+
if (trimmed === "GOOGLE_API_KEY" || trimmed === "GEMINI_API_KEY") return process.env[trimmed]?.trim();
|
|
767
|
+
return trimmed;
|
|
768
|
+
}
|
|
769
|
+
function normalizeGeminiModel(model) {
|
|
770
|
+
const trimmed = model.trim();
|
|
771
|
+
if (!trimmed) return DEFAULT_GEMINI_EMBEDDING_MODEL;
|
|
772
|
+
const withoutPrefix = trimmed.replace(/^models\//, "");
|
|
773
|
+
if (withoutPrefix.startsWith("gemini/")) return withoutPrefix.slice(7);
|
|
774
|
+
if (withoutPrefix.startsWith("google/")) return withoutPrefix.slice(7);
|
|
775
|
+
return withoutPrefix;
|
|
776
|
+
}
|
|
777
|
+
function normalizeGeminiBaseUrl(raw) {
|
|
778
|
+
const trimmed = raw.replace(/\/+$/, "");
|
|
779
|
+
const openAiIndex = trimmed.indexOf("/openai");
|
|
780
|
+
if (openAiIndex > -1) return trimmed.slice(0, openAiIndex);
|
|
781
|
+
return trimmed;
|
|
782
|
+
}
|
|
783
|
+
function buildGeminiModelPath(model) {
|
|
784
|
+
return model.startsWith("models/") ? model : `models/${model}`;
|
|
785
|
+
}
|
|
786
|
+
async function createGeminiEmbeddingProvider(options) {
|
|
787
|
+
const client = await resolveGeminiEmbeddingClient(options);
|
|
788
|
+
const baseUrl = client.baseUrl.replace(/\/$/, "");
|
|
789
|
+
const embedUrl = `${baseUrl}/${client.modelPath}:embedContent`;
|
|
790
|
+
const batchUrl = `${baseUrl}/${client.modelPath}:batchEmbedContents`;
|
|
791
|
+
const embedQuery = async (text) => {
|
|
792
|
+
if (!text.trim()) return [];
|
|
793
|
+
const res = await fetch(embedUrl, {
|
|
794
|
+
method: "POST",
|
|
795
|
+
headers: client.headers,
|
|
796
|
+
body: JSON.stringify({
|
|
797
|
+
content: { parts: [{ text }] },
|
|
798
|
+
taskType: "RETRIEVAL_QUERY"
|
|
799
|
+
})
|
|
800
|
+
});
|
|
801
|
+
if (!res.ok) {
|
|
802
|
+
const payload = await res.text();
|
|
803
|
+
throw new Error(`gemini embeddings failed: ${res.status} ${payload}`);
|
|
804
|
+
}
|
|
805
|
+
return (await res.json()).embedding?.values ?? [];
|
|
806
|
+
};
|
|
807
|
+
const embedBatch = async (texts) => {
|
|
808
|
+
if (texts.length === 0) return [];
|
|
809
|
+
const requests = texts.map((text) => ({
|
|
810
|
+
model: client.modelPath,
|
|
811
|
+
content: { parts: [{ text }] },
|
|
812
|
+
taskType: "RETRIEVAL_DOCUMENT"
|
|
813
|
+
}));
|
|
814
|
+
const res = await fetch(batchUrl, {
|
|
815
|
+
method: "POST",
|
|
816
|
+
headers: client.headers,
|
|
817
|
+
body: JSON.stringify({ requests })
|
|
818
|
+
});
|
|
819
|
+
if (!res.ok) {
|
|
820
|
+
const payload = await res.text();
|
|
821
|
+
throw new Error(`gemini embeddings failed: ${res.status} ${payload}`);
|
|
822
|
+
}
|
|
823
|
+
const payload = await res.json();
|
|
824
|
+
const embeddings = Array.isArray(payload.embeddings) ? payload.embeddings : [];
|
|
825
|
+
return texts.map((_, index) => embeddings[index]?.values ?? []);
|
|
826
|
+
};
|
|
827
|
+
return {
|
|
828
|
+
provider: {
|
|
829
|
+
id: "gemini",
|
|
830
|
+
model: client.model,
|
|
831
|
+
embedQuery,
|
|
832
|
+
embedBatch
|
|
833
|
+
},
|
|
834
|
+
client
|
|
835
|
+
};
|
|
836
|
+
}
|
|
837
|
+
async function resolveGeminiEmbeddingClient(options) {
|
|
838
|
+
const remote = options.remote;
|
|
839
|
+
const remoteApiKey = resolveRemoteApiKey(remote?.apiKey);
|
|
840
|
+
const remoteBaseUrl = remote?.baseUrl?.trim();
|
|
841
|
+
const apiKey = remoteApiKey ? remoteApiKey : requireApiKey(await resolveApiKeyForProvider({
|
|
842
|
+
provider: "google",
|
|
843
|
+
cfg: options.config,
|
|
844
|
+
agentDir: options.agentDir
|
|
845
|
+
}), "google");
|
|
846
|
+
const providerConfig = options.config.models?.providers?.google;
|
|
847
|
+
const rawBaseUrl = remoteBaseUrl || providerConfig?.baseUrl?.trim() || DEFAULT_GEMINI_BASE_URL;
|
|
848
|
+
const baseUrl = normalizeGeminiBaseUrl(rawBaseUrl);
|
|
849
|
+
const headerOverrides = Object.assign({}, providerConfig?.headers, remote?.headers);
|
|
850
|
+
const headers = {
|
|
851
|
+
"Content-Type": "application/json",
|
|
852
|
+
"x-goog-api-key": apiKey,
|
|
853
|
+
...headerOverrides
|
|
854
|
+
};
|
|
855
|
+
const model = normalizeGeminiModel(options.model);
|
|
856
|
+
const modelPath = buildGeminiModelPath(model);
|
|
857
|
+
debugLog("memory embeddings: gemini client", {
|
|
858
|
+
rawBaseUrl,
|
|
859
|
+
baseUrl,
|
|
860
|
+
model,
|
|
861
|
+
modelPath,
|
|
862
|
+
embedEndpoint: `${baseUrl}/${modelPath}:embedContent`,
|
|
863
|
+
batchEndpoint: `${baseUrl}/${modelPath}:batchEmbedContents`
|
|
864
|
+
});
|
|
865
|
+
return {
|
|
866
|
+
baseUrl,
|
|
867
|
+
headers,
|
|
868
|
+
model,
|
|
869
|
+
modelPath
|
|
870
|
+
};
|
|
871
|
+
}
|
|
872
|
+
|
|
873
|
+
//#endregion
|
|
874
|
+
//#region src/memory/embeddings-openai.ts
|
|
875
|
+
const DEFAULT_OPENAI_EMBEDDING_MODEL = "text-embedding-3-small";
|
|
876
|
+
const DEFAULT_OPENAI_BASE_URL = "https://api.openai.com/v1";
|
|
877
|
+
function normalizeOpenAiModel(model) {
|
|
878
|
+
const trimmed = model.trim();
|
|
879
|
+
if (!trimmed) return DEFAULT_OPENAI_EMBEDDING_MODEL;
|
|
880
|
+
if (trimmed.startsWith("openai/")) return trimmed.slice(7);
|
|
881
|
+
return trimmed;
|
|
882
|
+
}
|
|
883
|
+
async function createOpenAiEmbeddingProvider(options) {
|
|
884
|
+
const client = await resolveOpenAiEmbeddingClient(options);
|
|
885
|
+
const url = `${client.baseUrl.replace(/\/$/, "")}/embeddings`;
|
|
886
|
+
const embed = async (input) => {
|
|
887
|
+
if (input.length === 0) return [];
|
|
888
|
+
const res = await fetch(url, {
|
|
889
|
+
method: "POST",
|
|
890
|
+
headers: client.headers,
|
|
891
|
+
body: JSON.stringify({
|
|
892
|
+
model: client.model,
|
|
893
|
+
input
|
|
894
|
+
})
|
|
895
|
+
});
|
|
896
|
+
if (!res.ok) {
|
|
897
|
+
const text = await res.text();
|
|
898
|
+
throw new Error(`openai embeddings failed: ${res.status} ${text}`);
|
|
899
|
+
}
|
|
900
|
+
return ((await res.json()).data ?? []).map((entry) => entry.embedding ?? []);
|
|
901
|
+
};
|
|
902
|
+
return {
|
|
903
|
+
provider: {
|
|
904
|
+
id: "openai",
|
|
905
|
+
model: client.model,
|
|
906
|
+
embedQuery: async (text) => {
|
|
907
|
+
const [vec] = await embed([text]);
|
|
908
|
+
return vec ?? [];
|
|
909
|
+
},
|
|
910
|
+
embedBatch: embed
|
|
911
|
+
},
|
|
912
|
+
client
|
|
913
|
+
};
|
|
914
|
+
}
|
|
915
|
+
async function resolveOpenAiEmbeddingClient(options) {
|
|
916
|
+
const remote = options.remote;
|
|
917
|
+
const remoteApiKey = remote?.apiKey?.trim();
|
|
918
|
+
const remoteBaseUrl = remote?.baseUrl?.trim();
|
|
919
|
+
const apiKey = remoteApiKey ? remoteApiKey : requireApiKey(await resolveApiKeyForProvider({
|
|
920
|
+
provider: "openai",
|
|
921
|
+
cfg: options.config,
|
|
922
|
+
agentDir: options.agentDir
|
|
923
|
+
}), "openai");
|
|
924
|
+
const providerConfig = options.config.models?.providers?.openai;
|
|
925
|
+
const baseUrl = remoteBaseUrl || providerConfig?.baseUrl?.trim() || DEFAULT_OPENAI_BASE_URL;
|
|
926
|
+
const headerOverrides = Object.assign({}, providerConfig?.headers, remote?.headers);
|
|
927
|
+
return {
|
|
928
|
+
baseUrl,
|
|
929
|
+
headers: {
|
|
930
|
+
"Content-Type": "application/json",
|
|
931
|
+
Authorization: `Bearer ${apiKey}`,
|
|
932
|
+
...headerOverrides
|
|
933
|
+
},
|
|
934
|
+
model: normalizeOpenAiModel(options.model)
|
|
935
|
+
};
|
|
936
|
+
}
|
|
937
|
+
|
|
938
|
+
//#endregion
|
|
939
|
+
//#region src/memory/node-llama.ts
|
|
940
|
+
async function importNodeLlamaCpp() {
|
|
941
|
+
return import("node-llama-cpp");
|
|
942
|
+
}
|
|
943
|
+
|
|
944
|
+
//#endregion
|
|
945
|
+
//#region src/memory/embeddings.ts
|
|
946
|
+
function sanitizeAndNormalizeEmbedding(vec) {
|
|
947
|
+
const sanitized = vec.map((value) => Number.isFinite(value) ? value : 0);
|
|
948
|
+
const magnitude = Math.sqrt(sanitized.reduce((sum, value) => sum + value * value, 0));
|
|
949
|
+
if (magnitude < 1e-10) return sanitized;
|
|
950
|
+
return sanitized.map((value) => value / magnitude);
|
|
951
|
+
}
|
|
952
|
+
const DEFAULT_LOCAL_MODEL = "hf:ggml-org/embeddinggemma-300M-GGUF/embeddinggemma-300M-Q8_0.gguf";
|
|
953
|
+
function canAutoSelectLocal(options) {
|
|
954
|
+
const modelPath = options.local?.modelPath?.trim();
|
|
955
|
+
if (!modelPath) return false;
|
|
956
|
+
if (/^(hf:|https?:)/i.test(modelPath)) return false;
|
|
957
|
+
const resolved = resolveUserPath(modelPath);
|
|
958
|
+
try {
|
|
959
|
+
return fs.statSync(resolved).isFile();
|
|
960
|
+
} catch {
|
|
961
|
+
return false;
|
|
962
|
+
}
|
|
963
|
+
}
|
|
964
|
+
function isMissingApiKeyError(err) {
|
|
965
|
+
return formatError(err).includes("No API key found for provider");
|
|
966
|
+
}
|
|
967
|
+
async function createLocalEmbeddingProvider(options) {
|
|
968
|
+
const modelPath = options.local?.modelPath?.trim() || DEFAULT_LOCAL_MODEL;
|
|
969
|
+
const modelCacheDir = options.local?.modelCacheDir?.trim();
|
|
970
|
+
const { getLlama, resolveModelFile, LlamaLogLevel } = await importNodeLlamaCpp();
|
|
971
|
+
let llama = null;
|
|
972
|
+
let embeddingModel = null;
|
|
973
|
+
let embeddingContext = null;
|
|
974
|
+
const ensureContext = async () => {
|
|
975
|
+
if (!llama) llama = await getLlama({ logLevel: LlamaLogLevel.error });
|
|
976
|
+
if (!embeddingModel) {
|
|
977
|
+
const resolved = await resolveModelFile(modelPath, modelCacheDir || void 0);
|
|
978
|
+
embeddingModel = await llama.loadModel({ modelPath: resolved });
|
|
979
|
+
}
|
|
980
|
+
if (!embeddingContext) embeddingContext = await embeddingModel.createEmbeddingContext();
|
|
981
|
+
return embeddingContext;
|
|
982
|
+
};
|
|
983
|
+
return {
|
|
984
|
+
id: "local",
|
|
985
|
+
model: modelPath,
|
|
986
|
+
embedQuery: async (text) => {
|
|
987
|
+
const embedding = await (await ensureContext()).getEmbeddingFor(text);
|
|
988
|
+
return sanitizeAndNormalizeEmbedding(Array.from(embedding.vector));
|
|
989
|
+
},
|
|
990
|
+
embedBatch: async (texts) => {
|
|
991
|
+
const ctx = await ensureContext();
|
|
992
|
+
return await Promise.all(texts.map(async (text) => {
|
|
993
|
+
const embedding = await ctx.getEmbeddingFor(text);
|
|
994
|
+
return sanitizeAndNormalizeEmbedding(Array.from(embedding.vector));
|
|
995
|
+
}));
|
|
996
|
+
}
|
|
997
|
+
};
|
|
998
|
+
}
|
|
999
|
+
async function createEmbeddingProvider(options) {
|
|
1000
|
+
const requestedProvider = options.provider;
|
|
1001
|
+
const fallback = options.fallback;
|
|
1002
|
+
const createProvider = async (id) => {
|
|
1003
|
+
if (id === "local") return { provider: await createLocalEmbeddingProvider(options) };
|
|
1004
|
+
if (id === "gemini") {
|
|
1005
|
+
const { provider, client } = await createGeminiEmbeddingProvider(options);
|
|
1006
|
+
return {
|
|
1007
|
+
provider,
|
|
1008
|
+
gemini: client
|
|
1009
|
+
};
|
|
1010
|
+
}
|
|
1011
|
+
const { provider, client } = await createOpenAiEmbeddingProvider(options);
|
|
1012
|
+
return {
|
|
1013
|
+
provider,
|
|
1014
|
+
openAi: client
|
|
1015
|
+
};
|
|
1016
|
+
};
|
|
1017
|
+
const formatPrimaryError = (err, provider) => provider === "local" ? formatLocalSetupError(err) : formatError(err);
|
|
1018
|
+
if (requestedProvider === "auto") {
|
|
1019
|
+
const missingKeyErrors = [];
|
|
1020
|
+
let localError = null;
|
|
1021
|
+
if (canAutoSelectLocal(options)) try {
|
|
1022
|
+
return {
|
|
1023
|
+
...await createProvider("local"),
|
|
1024
|
+
requestedProvider
|
|
1025
|
+
};
|
|
1026
|
+
} catch (err) {
|
|
1027
|
+
localError = formatLocalSetupError(err);
|
|
1028
|
+
}
|
|
1029
|
+
for (const provider of ["openai", "gemini"]) try {
|
|
1030
|
+
return {
|
|
1031
|
+
...await createProvider(provider),
|
|
1032
|
+
requestedProvider
|
|
1033
|
+
};
|
|
1034
|
+
} catch (err) {
|
|
1035
|
+
const message = formatPrimaryError(err, provider);
|
|
1036
|
+
if (isMissingApiKeyError(err)) {
|
|
1037
|
+
missingKeyErrors.push(message);
|
|
1038
|
+
continue;
|
|
1039
|
+
}
|
|
1040
|
+
throw new Error(message, { cause: err });
|
|
1041
|
+
}
|
|
1042
|
+
const details = [...missingKeyErrors, localError].filter(Boolean);
|
|
1043
|
+
if (details.length > 0) throw new Error(details.join("\n\n"));
|
|
1044
|
+
throw new Error("No embeddings provider available.");
|
|
1045
|
+
}
|
|
1046
|
+
try {
|
|
1047
|
+
return {
|
|
1048
|
+
...await createProvider(requestedProvider),
|
|
1049
|
+
requestedProvider
|
|
1050
|
+
};
|
|
1051
|
+
} catch (primaryErr) {
|
|
1052
|
+
const reason = formatPrimaryError(primaryErr, requestedProvider);
|
|
1053
|
+
if (fallback && fallback !== "none" && fallback !== requestedProvider) try {
|
|
1054
|
+
return {
|
|
1055
|
+
...await createProvider(fallback),
|
|
1056
|
+
requestedProvider,
|
|
1057
|
+
fallbackFrom: requestedProvider,
|
|
1058
|
+
fallbackReason: reason
|
|
1059
|
+
};
|
|
1060
|
+
} catch (fallbackErr) {
|
|
1061
|
+
throw new Error(`${reason}\n\nFallback to ${fallback} failed: ${formatError(fallbackErr)}`, { cause: fallbackErr });
|
|
1062
|
+
}
|
|
1063
|
+
throw new Error(reason, { cause: primaryErr });
|
|
1064
|
+
}
|
|
1065
|
+
}
|
|
1066
|
+
function formatError(err) {
|
|
1067
|
+
if (err instanceof Error) return err.message;
|
|
1068
|
+
return String(err);
|
|
1069
|
+
}
|
|
1070
|
+
function isNodeLlamaCppMissing(err) {
|
|
1071
|
+
if (!(err instanceof Error)) return false;
|
|
1072
|
+
if (err.code === "ERR_MODULE_NOT_FOUND") return err.message.includes("node-llama-cpp");
|
|
1073
|
+
return false;
|
|
1074
|
+
}
|
|
1075
|
+
function formatLocalSetupError(err) {
|
|
1076
|
+
const detail = formatError(err);
|
|
1077
|
+
const missing = isNodeLlamaCppMissing(err);
|
|
1078
|
+
return [
|
|
1079
|
+
"Local embeddings unavailable.",
|
|
1080
|
+
missing ? "Reason: optional dependency node-llama-cpp is missing (or failed to install)." : detail ? `Reason: ${detail}` : void 0,
|
|
1081
|
+
missing && detail ? `Detail: ${detail}` : null,
|
|
1082
|
+
"To enable local embeddings:",
|
|
1083
|
+
"1) Use Node 22 LTS (recommended for installs/updates)",
|
|
1084
|
+
missing ? "2) Reinstall OpenClaw (this should install node-llama-cpp): npm i -g openclaw@latest" : null,
|
|
1085
|
+
"3) If you use pnpm: pnpm approve-builds (select node-llama-cpp), then pnpm rebuild node-llama-cpp",
|
|
1086
|
+
"Or set agents.defaults.memorySearch.provider = \"openai\" (remote)."
|
|
1087
|
+
].filter(Boolean).join("\n");
|
|
1088
|
+
}
|
|
1089
|
+
|
|
1090
|
+
//#endregion
|
|
1091
|
+
//#region src/memory/hybrid.ts
|
|
1092
|
+
function buildFtsQuery(raw) {
|
|
1093
|
+
const tokens = raw.match(/[A-Za-z0-9_]+/g)?.map((t) => t.trim()).filter(Boolean) ?? [];
|
|
1094
|
+
if (tokens.length === 0) return null;
|
|
1095
|
+
return tokens.map((t) => `"${t.replaceAll("\"", "")}"`).join(" AND ");
|
|
1096
|
+
}
|
|
1097
|
+
function bm25RankToScore(rank) {
|
|
1098
|
+
return 1 / (1 + (Number.isFinite(rank) ? Math.max(0, rank) : 999));
|
|
1099
|
+
}
|
|
1100
|
+
function mergeHybridResults(params) {
|
|
1101
|
+
const byId = /* @__PURE__ */ new Map();
|
|
1102
|
+
for (const r of params.vector) byId.set(r.id, {
|
|
1103
|
+
id: r.id,
|
|
1104
|
+
path: r.path,
|
|
1105
|
+
startLine: r.startLine,
|
|
1106
|
+
endLine: r.endLine,
|
|
1107
|
+
source: r.source,
|
|
1108
|
+
snippet: r.snippet,
|
|
1109
|
+
vectorScore: r.vectorScore,
|
|
1110
|
+
textScore: 0
|
|
1111
|
+
});
|
|
1112
|
+
for (const r of params.keyword) {
|
|
1113
|
+
const existing = byId.get(r.id);
|
|
1114
|
+
if (existing) {
|
|
1115
|
+
existing.textScore = r.textScore;
|
|
1116
|
+
if (r.snippet && r.snippet.length > 0) existing.snippet = r.snippet;
|
|
1117
|
+
} else byId.set(r.id, {
|
|
1118
|
+
id: r.id,
|
|
1119
|
+
path: r.path,
|
|
1120
|
+
startLine: r.startLine,
|
|
1121
|
+
endLine: r.endLine,
|
|
1122
|
+
source: r.source,
|
|
1123
|
+
snippet: r.snippet,
|
|
1124
|
+
vectorScore: 0,
|
|
1125
|
+
textScore: r.textScore
|
|
1126
|
+
});
|
|
1127
|
+
}
|
|
1128
|
+
return Array.from(byId.values()).map((entry) => {
|
|
1129
|
+
const score = params.vectorWeight * entry.vectorScore + params.textWeight * entry.textScore;
|
|
1130
|
+
return {
|
|
1131
|
+
path: entry.path,
|
|
1132
|
+
startLine: entry.startLine,
|
|
1133
|
+
endLine: entry.endLine,
|
|
1134
|
+
score,
|
|
1135
|
+
snippet: entry.snippet,
|
|
1136
|
+
source: entry.source
|
|
1137
|
+
};
|
|
1138
|
+
}).toSorted((a, b) => b.score - a.score);
|
|
1139
|
+
}
|
|
1140
|
+
|
|
1141
|
+
//#endregion
|
|
1142
|
+
//#region src/memory/manager-search.ts
|
|
1143
|
+
const vectorToBlob$1 = (embedding) => Buffer.from(new Float32Array(embedding).buffer);
|
|
1144
|
+
async function searchVector(params) {
|
|
1145
|
+
if (params.queryVec.length === 0 || params.limit <= 0) return [];
|
|
1146
|
+
if (await params.ensureVectorReady(params.queryVec.length)) return params.db.prepare(`SELECT c.id, c.path, c.start_line, c.end_line, c.text,
|
|
1147
|
+
c.source,
|
|
1148
|
+
vec_distance_cosine(v.embedding, ?) AS dist
|
|
1149
|
+
FROM ${params.vectorTable} v\n JOIN chunks c ON c.id = v.id\n WHERE c.model = ?${params.sourceFilterVec.sql}\n ORDER BY dist ASC\n LIMIT ?`).all(vectorToBlob$1(params.queryVec), params.providerModel, ...params.sourceFilterVec.params, params.limit).map((row) => ({
|
|
1150
|
+
id: row.id,
|
|
1151
|
+
path: row.path,
|
|
1152
|
+
startLine: row.start_line,
|
|
1153
|
+
endLine: row.end_line,
|
|
1154
|
+
score: 1 - row.dist,
|
|
1155
|
+
snippet: truncateUtf16Safe(row.text, params.snippetMaxChars),
|
|
1156
|
+
source: row.source
|
|
1157
|
+
}));
|
|
1158
|
+
return listChunks({
|
|
1159
|
+
db: params.db,
|
|
1160
|
+
providerModel: params.providerModel,
|
|
1161
|
+
sourceFilter: params.sourceFilterChunks
|
|
1162
|
+
}).map((chunk) => ({
|
|
1163
|
+
chunk,
|
|
1164
|
+
score: cosineSimilarity(params.queryVec, chunk.embedding)
|
|
1165
|
+
})).filter((entry) => Number.isFinite(entry.score)).toSorted((a, b) => b.score - a.score).slice(0, params.limit).map((entry) => ({
|
|
1166
|
+
id: entry.chunk.id,
|
|
1167
|
+
path: entry.chunk.path,
|
|
1168
|
+
startLine: entry.chunk.startLine,
|
|
1169
|
+
endLine: entry.chunk.endLine,
|
|
1170
|
+
score: entry.score,
|
|
1171
|
+
snippet: truncateUtf16Safe(entry.chunk.text, params.snippetMaxChars),
|
|
1172
|
+
source: entry.chunk.source
|
|
1173
|
+
}));
|
|
1174
|
+
}
|
|
1175
|
+
function listChunks(params) {
|
|
1176
|
+
return params.db.prepare(`SELECT id, path, start_line, end_line, text, embedding, source
|
|
1177
|
+
FROM chunks
|
|
1178
|
+
WHERE model = ?${params.sourceFilter.sql}`).all(params.providerModel, ...params.sourceFilter.params).map((row) => ({
|
|
1179
|
+
id: row.id,
|
|
1180
|
+
path: row.path,
|
|
1181
|
+
startLine: row.start_line,
|
|
1182
|
+
endLine: row.end_line,
|
|
1183
|
+
text: row.text,
|
|
1184
|
+
embedding: parseEmbedding(row.embedding),
|
|
1185
|
+
source: row.source
|
|
1186
|
+
}));
|
|
1187
|
+
}
|
|
1188
|
+
async function searchKeyword(params) {
|
|
1189
|
+
if (params.limit <= 0) return [];
|
|
1190
|
+
const ftsQuery = params.buildFtsQuery(params.query);
|
|
1191
|
+
if (!ftsQuery) return [];
|
|
1192
|
+
return params.db.prepare(`SELECT id, path, source, start_line, end_line, text,\n bm25(${params.ftsTable}) AS rank\n FROM ${params.ftsTable}\n WHERE ${params.ftsTable} MATCH ? AND model = ?${params.sourceFilter.sql}\n ORDER BY rank ASC\n LIMIT ?`).all(ftsQuery, params.providerModel, ...params.sourceFilter.params, params.limit).map((row) => {
|
|
1193
|
+
const textScore = params.bm25RankToScore(row.rank);
|
|
1194
|
+
return {
|
|
1195
|
+
id: row.id,
|
|
1196
|
+
path: row.path,
|
|
1197
|
+
startLine: row.start_line,
|
|
1198
|
+
endLine: row.end_line,
|
|
1199
|
+
score: textScore,
|
|
1200
|
+
textScore,
|
|
1201
|
+
snippet: truncateUtf16Safe(row.text, params.snippetMaxChars),
|
|
1202
|
+
source: row.source
|
|
1203
|
+
};
|
|
1204
|
+
});
|
|
1205
|
+
}
|
|
1206
|
+
|
|
1207
|
+
//#endregion
|
|
1208
|
+
//#region src/memory/memory-schema.ts
|
|
1209
|
+
function ensureMemoryIndexSchema(params) {
|
|
1210
|
+
params.db.exec(`
|
|
1211
|
+
CREATE TABLE IF NOT EXISTS meta (
|
|
1212
|
+
key TEXT PRIMARY KEY,
|
|
1213
|
+
value TEXT NOT NULL
|
|
1214
|
+
);
|
|
1215
|
+
`);
|
|
1216
|
+
params.db.exec(`
|
|
1217
|
+
CREATE TABLE IF NOT EXISTS files (
|
|
1218
|
+
path TEXT PRIMARY KEY,
|
|
1219
|
+
source TEXT NOT NULL DEFAULT 'memory',
|
|
1220
|
+
hash TEXT NOT NULL,
|
|
1221
|
+
mtime INTEGER NOT NULL,
|
|
1222
|
+
size INTEGER NOT NULL
|
|
1223
|
+
);
|
|
1224
|
+
`);
|
|
1225
|
+
params.db.exec(`
|
|
1226
|
+
CREATE TABLE IF NOT EXISTS chunks (
|
|
1227
|
+
id TEXT PRIMARY KEY,
|
|
1228
|
+
path TEXT NOT NULL,
|
|
1229
|
+
source TEXT NOT NULL DEFAULT 'memory',
|
|
1230
|
+
start_line INTEGER NOT NULL,
|
|
1231
|
+
end_line INTEGER NOT NULL,
|
|
1232
|
+
hash TEXT NOT NULL,
|
|
1233
|
+
model TEXT NOT NULL,
|
|
1234
|
+
text TEXT NOT NULL,
|
|
1235
|
+
embedding TEXT NOT NULL,
|
|
1236
|
+
updated_at INTEGER NOT NULL
|
|
1237
|
+
);
|
|
1238
|
+
`);
|
|
1239
|
+
params.db.exec(`
|
|
1240
|
+
CREATE TABLE IF NOT EXISTS ${params.embeddingCacheTable} (
|
|
1241
|
+
provider TEXT NOT NULL,
|
|
1242
|
+
model TEXT NOT NULL,
|
|
1243
|
+
provider_key TEXT NOT NULL,
|
|
1244
|
+
hash TEXT NOT NULL,
|
|
1245
|
+
embedding TEXT NOT NULL,
|
|
1246
|
+
dims INTEGER,
|
|
1247
|
+
updated_at INTEGER NOT NULL,
|
|
1248
|
+
PRIMARY KEY (provider, model, provider_key, hash)
|
|
1249
|
+
);
|
|
1250
|
+
`);
|
|
1251
|
+
params.db.exec(`CREATE INDEX IF NOT EXISTS idx_embedding_cache_updated_at ON ${params.embeddingCacheTable}(updated_at);`);
|
|
1252
|
+
let ftsAvailable = false;
|
|
1253
|
+
let ftsError;
|
|
1254
|
+
if (params.ftsEnabled) try {
|
|
1255
|
+
params.db.exec(`CREATE VIRTUAL TABLE IF NOT EXISTS ${params.ftsTable} USING fts5(\n text,\n id UNINDEXED,\n path UNINDEXED,\n source UNINDEXED,\n model UNINDEXED,\n start_line UNINDEXED,\n end_line UNINDEXED\n);`);
|
|
1256
|
+
ftsAvailable = true;
|
|
1257
|
+
} catch (err) {
|
|
1258
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
1259
|
+
ftsAvailable = false;
|
|
1260
|
+
ftsError = message;
|
|
1261
|
+
}
|
|
1262
|
+
ensureColumn(params.db, "files", "source", "TEXT NOT NULL DEFAULT 'memory'");
|
|
1263
|
+
ensureColumn(params.db, "chunks", "source", "TEXT NOT NULL DEFAULT 'memory'");
|
|
1264
|
+
params.db.exec(`CREATE INDEX IF NOT EXISTS idx_chunks_path ON chunks(path);`);
|
|
1265
|
+
params.db.exec(`CREATE INDEX IF NOT EXISTS idx_chunks_source ON chunks(source);`);
|
|
1266
|
+
return {
|
|
1267
|
+
ftsAvailable,
|
|
1268
|
+
...ftsError ? { ftsError } : {}
|
|
1269
|
+
};
|
|
1270
|
+
}
|
|
1271
|
+
function ensureColumn(db, table, column, definition) {
|
|
1272
|
+
if (db.prepare(`PRAGMA table_info(${table})`).all().some((row) => row.name === column)) return;
|
|
1273
|
+
db.exec(`ALTER TABLE ${table} ADD COLUMN ${column} ${definition}`);
|
|
1274
|
+
}
|
|
1275
|
+
|
|
1276
|
+
//#endregion
|
|
1277
|
+
//#region src/memory/sqlite-vec.ts
|
|
1278
|
+
async function loadSqliteVecExtension(params) {
|
|
1279
|
+
try {
|
|
1280
|
+
const sqliteVec = await import("sqlite-vec");
|
|
1281
|
+
const resolvedPath = params.extensionPath?.trim() ? params.extensionPath.trim() : void 0;
|
|
1282
|
+
const extensionPath = resolvedPath ?? sqliteVec.getLoadablePath();
|
|
1283
|
+
params.db.enableLoadExtension(true);
|
|
1284
|
+
if (resolvedPath) params.db.loadExtension(extensionPath);
|
|
1285
|
+
else sqliteVec.load(params.db);
|
|
1286
|
+
return {
|
|
1287
|
+
ok: true,
|
|
1288
|
+
extensionPath
|
|
1289
|
+
};
|
|
1290
|
+
} catch (err) {
|
|
1291
|
+
return {
|
|
1292
|
+
ok: false,
|
|
1293
|
+
error: err instanceof Error ? err.message : String(err)
|
|
1294
|
+
};
|
|
1295
|
+
}
|
|
1296
|
+
}
|
|
1297
|
+
|
|
1298
|
+
//#endregion
|
|
1299
|
+
//#region src/memory/manager.ts
|
|
1300
|
+
var manager_exports = /* @__PURE__ */ __exportAll({ MemoryIndexManager: () => MemoryIndexManager });
|
|
1301
|
+
const META_KEY = "memory_index_meta_v1";
|
|
1302
|
+
const SNIPPET_MAX_CHARS = 700;
|
|
1303
|
+
const VECTOR_TABLE = "chunks_vec";
|
|
1304
|
+
const FTS_TABLE = "chunks_fts";
|
|
1305
|
+
const EMBEDDING_CACHE_TABLE = "embedding_cache";
|
|
1306
|
+
const SESSION_DIRTY_DEBOUNCE_MS = 5e3;
|
|
1307
|
+
const EMBEDDING_BATCH_MAX_TOKENS = 8e3;
|
|
1308
|
+
const EMBEDDING_APPROX_CHARS_PER_TOKEN = 1;
|
|
1309
|
+
const EMBEDDING_INDEX_CONCURRENCY = 4;
|
|
1310
|
+
const EMBEDDING_RETRY_MAX_ATTEMPTS = 3;
|
|
1311
|
+
const EMBEDDING_RETRY_BASE_DELAY_MS = 500;
|
|
1312
|
+
const EMBEDDING_RETRY_MAX_DELAY_MS = 8e3;
|
|
1313
|
+
const BATCH_FAILURE_LIMIT = 2;
|
|
1314
|
+
const SESSION_DELTA_READ_CHUNK_BYTES = 64 * 1024;
|
|
1315
|
+
const VECTOR_LOAD_TIMEOUT_MS = 3e4;
|
|
1316
|
+
const EMBEDDING_QUERY_TIMEOUT_REMOTE_MS = 6e4;
|
|
1317
|
+
const EMBEDDING_QUERY_TIMEOUT_LOCAL_MS = 5 * 6e4;
|
|
1318
|
+
const EMBEDDING_BATCH_TIMEOUT_REMOTE_MS = 2 * 6e4;
|
|
1319
|
+
const EMBEDDING_BATCH_TIMEOUT_LOCAL_MS = 10 * 6e4;
|
|
1320
|
+
const log = createSubsystemLogger("memory");
|
|
1321
|
+
const INDEX_CACHE = /* @__PURE__ */ new Map();
|
|
1322
|
+
const vectorToBlob = (embedding) => Buffer.from(new Float32Array(embedding).buffer);
|
|
1323
|
+
var MemoryIndexManager = class MemoryIndexManager {
|
|
1324
|
+
static async get(params) {
|
|
1325
|
+
const { cfg, agentId } = params;
|
|
1326
|
+
const settings = resolveMemorySearchConfig(cfg, agentId);
|
|
1327
|
+
if (!settings) return null;
|
|
1328
|
+
const workspaceDir = resolveAgentWorkspaceDir(cfg, agentId);
|
|
1329
|
+
const key = `${agentId}:${workspaceDir}:${JSON.stringify(settings)}`;
|
|
1330
|
+
const existing = INDEX_CACHE.get(key);
|
|
1331
|
+
if (existing) return existing;
|
|
1332
|
+
const manager = new MemoryIndexManager({
|
|
1333
|
+
cacheKey: key,
|
|
1334
|
+
cfg,
|
|
1335
|
+
agentId,
|
|
1336
|
+
workspaceDir,
|
|
1337
|
+
settings,
|
|
1338
|
+
providerResult: await createEmbeddingProvider({
|
|
1339
|
+
config: cfg,
|
|
1340
|
+
agentDir: resolveAgentDir(cfg, agentId),
|
|
1341
|
+
provider: settings.provider,
|
|
1342
|
+
remote: settings.remote,
|
|
1343
|
+
model: settings.model,
|
|
1344
|
+
fallback: settings.fallback,
|
|
1345
|
+
local: settings.local
|
|
1346
|
+
})
|
|
1347
|
+
});
|
|
1348
|
+
INDEX_CACHE.set(key, manager);
|
|
1349
|
+
return manager;
|
|
1350
|
+
}
|
|
1351
|
+
constructor(params) {
|
|
1352
|
+
this.batchFailureCount = 0;
|
|
1353
|
+
this.batchFailureLock = Promise.resolve();
|
|
1354
|
+
this.vectorReady = null;
|
|
1355
|
+
this.watcher = null;
|
|
1356
|
+
this.watchTimer = null;
|
|
1357
|
+
this.sessionWatchTimer = null;
|
|
1358
|
+
this.sessionUnsubscribe = null;
|
|
1359
|
+
this.intervalTimer = null;
|
|
1360
|
+
this.closed = false;
|
|
1361
|
+
this.dirty = false;
|
|
1362
|
+
this.sessionsDirty = false;
|
|
1363
|
+
this.sessionsDirtyFiles = /* @__PURE__ */ new Set();
|
|
1364
|
+
this.sessionPendingFiles = /* @__PURE__ */ new Set();
|
|
1365
|
+
this.sessionDeltas = /* @__PURE__ */ new Map();
|
|
1366
|
+
this.sessionWarm = /* @__PURE__ */ new Set();
|
|
1367
|
+
this.syncing = null;
|
|
1368
|
+
this.cacheKey = params.cacheKey;
|
|
1369
|
+
this.cfg = params.cfg;
|
|
1370
|
+
this.agentId = params.agentId;
|
|
1371
|
+
this.workspaceDir = params.workspaceDir;
|
|
1372
|
+
this.settings = params.settings;
|
|
1373
|
+
this.provider = params.providerResult.provider;
|
|
1374
|
+
this.requestedProvider = params.providerResult.requestedProvider;
|
|
1375
|
+
this.fallbackFrom = params.providerResult.fallbackFrom;
|
|
1376
|
+
this.fallbackReason = params.providerResult.fallbackReason;
|
|
1377
|
+
this.openAi = params.providerResult.openAi;
|
|
1378
|
+
this.gemini = params.providerResult.gemini;
|
|
1379
|
+
this.sources = new Set(params.settings.sources);
|
|
1380
|
+
this.db = this.openDatabase();
|
|
1381
|
+
this.providerKey = this.computeProviderKey();
|
|
1382
|
+
this.cache = {
|
|
1383
|
+
enabled: params.settings.cache.enabled,
|
|
1384
|
+
maxEntries: params.settings.cache.maxEntries
|
|
1385
|
+
};
|
|
1386
|
+
this.fts = {
|
|
1387
|
+
enabled: params.settings.query.hybrid.enabled,
|
|
1388
|
+
available: false
|
|
1389
|
+
};
|
|
1390
|
+
this.ensureSchema();
|
|
1391
|
+
this.vector = {
|
|
1392
|
+
enabled: params.settings.store.vector.enabled,
|
|
1393
|
+
available: null,
|
|
1394
|
+
extensionPath: params.settings.store.vector.extensionPath
|
|
1395
|
+
};
|
|
1396
|
+
const meta = this.readMeta();
|
|
1397
|
+
if (meta?.vectorDims) this.vector.dims = meta.vectorDims;
|
|
1398
|
+
this.ensureWatcher();
|
|
1399
|
+
this.ensureSessionListener();
|
|
1400
|
+
this.ensureIntervalSync();
|
|
1401
|
+
this.dirty = this.sources.has("memory");
|
|
1402
|
+
this.batch = this.resolveBatchConfig();
|
|
1403
|
+
}
|
|
1404
|
+
async warmSession(sessionKey) {
|
|
1405
|
+
if (!this.settings.sync.onSessionStart) return;
|
|
1406
|
+
const key = sessionKey?.trim() || "";
|
|
1407
|
+
if (key && this.sessionWarm.has(key)) return;
|
|
1408
|
+
this.sync({ reason: "session-start" }).catch((err) => {
|
|
1409
|
+
log.warn(`memory sync failed (session-start): ${String(err)}`);
|
|
1410
|
+
});
|
|
1411
|
+
if (key) this.sessionWarm.add(key);
|
|
1412
|
+
}
|
|
1413
|
+
async search(query, opts) {
|
|
1414
|
+
this.warmSession(opts?.sessionKey);
|
|
1415
|
+
if (this.settings.sync.onSearch && (this.dirty || this.sessionsDirty)) this.sync({ reason: "search" }).catch((err) => {
|
|
1416
|
+
log.warn(`memory sync failed (search): ${String(err)}`);
|
|
1417
|
+
});
|
|
1418
|
+
const cleaned = query.trim();
|
|
1419
|
+
if (!cleaned) return [];
|
|
1420
|
+
const minScore = opts?.minScore ?? this.settings.query.minScore;
|
|
1421
|
+
const maxResults = opts?.maxResults ?? this.settings.query.maxResults;
|
|
1422
|
+
const hybrid = this.settings.query.hybrid;
|
|
1423
|
+
const candidates = Math.min(200, Math.max(1, Math.floor(maxResults * hybrid.candidateMultiplier)));
|
|
1424
|
+
const keywordResults = hybrid.enabled ? await this.searchKeyword(cleaned, candidates).catch(() => []) : [];
|
|
1425
|
+
const queryVec = await this.embedQueryWithTimeout(cleaned);
|
|
1426
|
+
const vectorResults = queryVec.some((v) => v !== 0) ? await this.searchVector(queryVec, candidates).catch(() => []) : [];
|
|
1427
|
+
if (!hybrid.enabled) return vectorResults.filter((entry) => entry.score >= minScore).slice(0, maxResults);
|
|
1428
|
+
return this.mergeHybridResults({
|
|
1429
|
+
vector: vectorResults,
|
|
1430
|
+
keyword: keywordResults,
|
|
1431
|
+
vectorWeight: hybrid.vectorWeight,
|
|
1432
|
+
textWeight: hybrid.textWeight
|
|
1433
|
+
}).filter((entry) => entry.score >= minScore).slice(0, maxResults);
|
|
1434
|
+
}
|
|
1435
|
+
async searchVector(queryVec, limit) {
|
|
1436
|
+
return (await searchVector({
|
|
1437
|
+
db: this.db,
|
|
1438
|
+
vectorTable: VECTOR_TABLE,
|
|
1439
|
+
providerModel: this.provider.model,
|
|
1440
|
+
queryVec,
|
|
1441
|
+
limit,
|
|
1442
|
+
snippetMaxChars: SNIPPET_MAX_CHARS,
|
|
1443
|
+
ensureVectorReady: async (dimensions) => await this.ensureVectorReady(dimensions),
|
|
1444
|
+
sourceFilterVec: this.buildSourceFilter("c"),
|
|
1445
|
+
sourceFilterChunks: this.buildSourceFilter()
|
|
1446
|
+
})).map((entry) => entry);
|
|
1447
|
+
}
|
|
1448
|
+
buildFtsQuery(raw) {
|
|
1449
|
+
return buildFtsQuery(raw);
|
|
1450
|
+
}
|
|
1451
|
+
async searchKeyword(query, limit) {
|
|
1452
|
+
if (!this.fts.enabled || !this.fts.available) return [];
|
|
1453
|
+
const sourceFilter = this.buildSourceFilter();
|
|
1454
|
+
return (await searchKeyword({
|
|
1455
|
+
db: this.db,
|
|
1456
|
+
ftsTable: FTS_TABLE,
|
|
1457
|
+
providerModel: this.provider.model,
|
|
1458
|
+
query,
|
|
1459
|
+
limit,
|
|
1460
|
+
snippetMaxChars: SNIPPET_MAX_CHARS,
|
|
1461
|
+
sourceFilter,
|
|
1462
|
+
buildFtsQuery: (raw) => this.buildFtsQuery(raw),
|
|
1463
|
+
bm25RankToScore
|
|
1464
|
+
})).map((entry) => entry);
|
|
1465
|
+
}
|
|
1466
|
+
mergeHybridResults(params) {
|
|
1467
|
+
return mergeHybridResults({
|
|
1468
|
+
vector: params.vector.map((r) => ({
|
|
1469
|
+
id: r.id,
|
|
1470
|
+
path: r.path,
|
|
1471
|
+
startLine: r.startLine,
|
|
1472
|
+
endLine: r.endLine,
|
|
1473
|
+
source: r.source,
|
|
1474
|
+
snippet: r.snippet,
|
|
1475
|
+
vectorScore: r.score
|
|
1476
|
+
})),
|
|
1477
|
+
keyword: params.keyword.map((r) => ({
|
|
1478
|
+
id: r.id,
|
|
1479
|
+
path: r.path,
|
|
1480
|
+
startLine: r.startLine,
|
|
1481
|
+
endLine: r.endLine,
|
|
1482
|
+
source: r.source,
|
|
1483
|
+
snippet: r.snippet,
|
|
1484
|
+
textScore: r.textScore
|
|
1485
|
+
})),
|
|
1486
|
+
vectorWeight: params.vectorWeight,
|
|
1487
|
+
textWeight: params.textWeight
|
|
1488
|
+
}).map((entry) => entry);
|
|
1489
|
+
}
|
|
1490
|
+
async sync(params) {
|
|
1491
|
+
if (this.syncing) return this.syncing;
|
|
1492
|
+
this.syncing = this.runSync(params).finally(() => {
|
|
1493
|
+
this.syncing = null;
|
|
1494
|
+
});
|
|
1495
|
+
return this.syncing;
|
|
1496
|
+
}
|
|
1497
|
+
async readFile(params) {
|
|
1498
|
+
const rawPath = params.relPath.trim();
|
|
1499
|
+
if (!rawPath) throw new Error("path required");
|
|
1500
|
+
const absPath = path.isAbsolute(rawPath) ? path.resolve(rawPath) : path.resolve(this.workspaceDir, rawPath);
|
|
1501
|
+
const relPath = path.relative(this.workspaceDir, absPath).replace(/\\/g, "/");
|
|
1502
|
+
const allowedWorkspace = relPath.length > 0 && !relPath.startsWith("..") && !path.isAbsolute(relPath) && isMemoryPath(relPath);
|
|
1503
|
+
let allowedAdditional = false;
|
|
1504
|
+
if (!allowedWorkspace && this.settings.extraPaths.length > 0) {
|
|
1505
|
+
const additionalPaths = normalizeExtraMemoryPaths(this.workspaceDir, this.settings.extraPaths);
|
|
1506
|
+
for (const additionalPath of additionalPaths) try {
|
|
1507
|
+
const stat = await fs$1.lstat(additionalPath);
|
|
1508
|
+
if (stat.isSymbolicLink()) continue;
|
|
1509
|
+
if (stat.isDirectory()) {
|
|
1510
|
+
if (absPath === additionalPath || absPath.startsWith(`${additionalPath}${path.sep}`)) {
|
|
1511
|
+
allowedAdditional = true;
|
|
1512
|
+
break;
|
|
1513
|
+
}
|
|
1514
|
+
continue;
|
|
1515
|
+
}
|
|
1516
|
+
if (stat.isFile()) {
|
|
1517
|
+
if (absPath === additionalPath && absPath.endsWith(".md")) {
|
|
1518
|
+
allowedAdditional = true;
|
|
1519
|
+
break;
|
|
1520
|
+
}
|
|
1521
|
+
}
|
|
1522
|
+
} catch {}
|
|
1523
|
+
}
|
|
1524
|
+
if (!allowedWorkspace && !allowedAdditional) throw new Error("path required");
|
|
1525
|
+
if (!absPath.endsWith(".md")) throw new Error("path required");
|
|
1526
|
+
const stat = await fs$1.lstat(absPath);
|
|
1527
|
+
if (stat.isSymbolicLink() || !stat.isFile()) throw new Error("path required");
|
|
1528
|
+
const content = await fs$1.readFile(absPath, "utf-8");
|
|
1529
|
+
if (!params.from && !params.lines) return {
|
|
1530
|
+
text: content,
|
|
1531
|
+
path: relPath
|
|
1532
|
+
};
|
|
1533
|
+
const lines = content.split("\n");
|
|
1534
|
+
const start = Math.max(1, params.from ?? 1);
|
|
1535
|
+
const count = Math.max(1, params.lines ?? lines.length);
|
|
1536
|
+
return {
|
|
1537
|
+
text: lines.slice(start - 1, start - 1 + count).join("\n"),
|
|
1538
|
+
path: relPath
|
|
1539
|
+
};
|
|
1540
|
+
}
|
|
1541
|
+
status() {
|
|
1542
|
+
const sourceFilter = this.buildSourceFilter();
|
|
1543
|
+
const files = this.db.prepare(`SELECT COUNT(*) as c FROM files WHERE 1=1${sourceFilter.sql}`).get(...sourceFilter.params);
|
|
1544
|
+
const chunks = this.db.prepare(`SELECT COUNT(*) as c FROM chunks WHERE 1=1${sourceFilter.sql}`).get(...sourceFilter.params);
|
|
1545
|
+
const sourceCounts = (() => {
|
|
1546
|
+
const sources = Array.from(this.sources);
|
|
1547
|
+
if (sources.length === 0) return [];
|
|
1548
|
+
const bySource = /* @__PURE__ */ new Map();
|
|
1549
|
+
for (const source of sources) bySource.set(source, {
|
|
1550
|
+
files: 0,
|
|
1551
|
+
chunks: 0
|
|
1552
|
+
});
|
|
1553
|
+
const fileRows = this.db.prepare(`SELECT source, COUNT(*) as c FROM files WHERE 1=1${sourceFilter.sql} GROUP BY source`).all(...sourceFilter.params);
|
|
1554
|
+
for (const row of fileRows) {
|
|
1555
|
+
const entry = bySource.get(row.source) ?? {
|
|
1556
|
+
files: 0,
|
|
1557
|
+
chunks: 0
|
|
1558
|
+
};
|
|
1559
|
+
entry.files = row.c ?? 0;
|
|
1560
|
+
bySource.set(row.source, entry);
|
|
1561
|
+
}
|
|
1562
|
+
const chunkRows = this.db.prepare(`SELECT source, COUNT(*) as c FROM chunks WHERE 1=1${sourceFilter.sql} GROUP BY source`).all(...sourceFilter.params);
|
|
1563
|
+
for (const row of chunkRows) {
|
|
1564
|
+
const entry = bySource.get(row.source) ?? {
|
|
1565
|
+
files: 0,
|
|
1566
|
+
chunks: 0
|
|
1567
|
+
};
|
|
1568
|
+
entry.chunks = row.c ?? 0;
|
|
1569
|
+
bySource.set(row.source, entry);
|
|
1570
|
+
}
|
|
1571
|
+
return sources.map((source) => Object.assign({ source }, bySource.get(source)));
|
|
1572
|
+
})();
|
|
1573
|
+
return {
|
|
1574
|
+
backend: "builtin",
|
|
1575
|
+
files: files?.c ?? 0,
|
|
1576
|
+
chunks: chunks?.c ?? 0,
|
|
1577
|
+
dirty: this.dirty || this.sessionsDirty,
|
|
1578
|
+
workspaceDir: this.workspaceDir,
|
|
1579
|
+
dbPath: this.settings.store.path,
|
|
1580
|
+
provider: this.provider.id,
|
|
1581
|
+
model: this.provider.model,
|
|
1582
|
+
requestedProvider: this.requestedProvider,
|
|
1583
|
+
sources: Array.from(this.sources),
|
|
1584
|
+
extraPaths: this.settings.extraPaths,
|
|
1585
|
+
sourceCounts,
|
|
1586
|
+
cache: this.cache.enabled ? {
|
|
1587
|
+
enabled: true,
|
|
1588
|
+
entries: this.db.prepare(`SELECT COUNT(*) as c FROM ${EMBEDDING_CACHE_TABLE}`).get()?.c ?? 0,
|
|
1589
|
+
maxEntries: this.cache.maxEntries
|
|
1590
|
+
} : {
|
|
1591
|
+
enabled: false,
|
|
1592
|
+
maxEntries: this.cache.maxEntries
|
|
1593
|
+
},
|
|
1594
|
+
fts: {
|
|
1595
|
+
enabled: this.fts.enabled,
|
|
1596
|
+
available: this.fts.available,
|
|
1597
|
+
error: this.fts.loadError
|
|
1598
|
+
},
|
|
1599
|
+
fallback: this.fallbackReason ? {
|
|
1600
|
+
from: this.fallbackFrom ?? "local",
|
|
1601
|
+
reason: this.fallbackReason
|
|
1602
|
+
} : void 0,
|
|
1603
|
+
vector: {
|
|
1604
|
+
enabled: this.vector.enabled,
|
|
1605
|
+
available: this.vector.available ?? void 0,
|
|
1606
|
+
extensionPath: this.vector.extensionPath,
|
|
1607
|
+
loadError: this.vector.loadError,
|
|
1608
|
+
dims: this.vector.dims
|
|
1609
|
+
},
|
|
1610
|
+
batch: {
|
|
1611
|
+
enabled: this.batch.enabled,
|
|
1612
|
+
failures: this.batchFailureCount,
|
|
1613
|
+
limit: BATCH_FAILURE_LIMIT,
|
|
1614
|
+
wait: this.batch.wait,
|
|
1615
|
+
concurrency: this.batch.concurrency,
|
|
1616
|
+
pollIntervalMs: this.batch.pollIntervalMs,
|
|
1617
|
+
timeoutMs: this.batch.timeoutMs,
|
|
1618
|
+
lastError: this.batchFailureLastError,
|
|
1619
|
+
lastProvider: this.batchFailureLastProvider
|
|
1620
|
+
}
|
|
1621
|
+
};
|
|
1622
|
+
}
|
|
1623
|
+
async probeVectorAvailability() {
|
|
1624
|
+
if (!this.vector.enabled) return false;
|
|
1625
|
+
return this.ensureVectorReady();
|
|
1626
|
+
}
|
|
1627
|
+
async probeEmbeddingAvailability() {
|
|
1628
|
+
try {
|
|
1629
|
+
await this.embedBatchWithRetry(["ping"]);
|
|
1630
|
+
return { ok: true };
|
|
1631
|
+
} catch (err) {
|
|
1632
|
+
return {
|
|
1633
|
+
ok: false,
|
|
1634
|
+
error: err instanceof Error ? err.message : String(err)
|
|
1635
|
+
};
|
|
1636
|
+
}
|
|
1637
|
+
}
|
|
1638
|
+
async close() {
|
|
1639
|
+
if (this.closed) return;
|
|
1640
|
+
this.closed = true;
|
|
1641
|
+
if (this.watchTimer) {
|
|
1642
|
+
clearTimeout(this.watchTimer);
|
|
1643
|
+
this.watchTimer = null;
|
|
1644
|
+
}
|
|
1645
|
+
if (this.sessionWatchTimer) {
|
|
1646
|
+
clearTimeout(this.sessionWatchTimer);
|
|
1647
|
+
this.sessionWatchTimer = null;
|
|
1648
|
+
}
|
|
1649
|
+
if (this.intervalTimer) {
|
|
1650
|
+
clearInterval(this.intervalTimer);
|
|
1651
|
+
this.intervalTimer = null;
|
|
1652
|
+
}
|
|
1653
|
+
if (this.watcher) {
|
|
1654
|
+
await this.watcher.close();
|
|
1655
|
+
this.watcher = null;
|
|
1656
|
+
}
|
|
1657
|
+
if (this.sessionUnsubscribe) {
|
|
1658
|
+
this.sessionUnsubscribe();
|
|
1659
|
+
this.sessionUnsubscribe = null;
|
|
1660
|
+
}
|
|
1661
|
+
this.db.close();
|
|
1662
|
+
INDEX_CACHE.delete(this.cacheKey);
|
|
1663
|
+
}
|
|
1664
|
+
async ensureVectorReady(dimensions) {
|
|
1665
|
+
if (!this.vector.enabled) return false;
|
|
1666
|
+
if (!this.vectorReady) this.vectorReady = this.withTimeout(this.loadVectorExtension(), VECTOR_LOAD_TIMEOUT_MS, `sqlite-vec load timed out after ${Math.round(VECTOR_LOAD_TIMEOUT_MS / 1e3)}s`);
|
|
1667
|
+
let ready = false;
|
|
1668
|
+
try {
|
|
1669
|
+
ready = await this.vectorReady;
|
|
1670
|
+
} catch (err) {
|
|
1671
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
1672
|
+
this.vector.available = false;
|
|
1673
|
+
this.vector.loadError = message;
|
|
1674
|
+
this.vectorReady = null;
|
|
1675
|
+
log.warn(`sqlite-vec unavailable: ${message}`);
|
|
1676
|
+
return false;
|
|
1677
|
+
}
|
|
1678
|
+
if (ready && typeof dimensions === "number" && dimensions > 0) this.ensureVectorTable(dimensions);
|
|
1679
|
+
return ready;
|
|
1680
|
+
}
|
|
1681
|
+
async loadVectorExtension() {
|
|
1682
|
+
if (this.vector.available !== null) return this.vector.available;
|
|
1683
|
+
if (!this.vector.enabled) {
|
|
1684
|
+
this.vector.available = false;
|
|
1685
|
+
return false;
|
|
1686
|
+
}
|
|
1687
|
+
try {
|
|
1688
|
+
const resolvedPath = this.vector.extensionPath?.trim() ? resolveUserPath(this.vector.extensionPath) : void 0;
|
|
1689
|
+
const loaded = await loadSqliteVecExtension({
|
|
1690
|
+
db: this.db,
|
|
1691
|
+
extensionPath: resolvedPath
|
|
1692
|
+
});
|
|
1693
|
+
if (!loaded.ok) throw new Error(loaded.error ?? "unknown sqlite-vec load error");
|
|
1694
|
+
this.vector.extensionPath = loaded.extensionPath;
|
|
1695
|
+
this.vector.available = true;
|
|
1696
|
+
return true;
|
|
1697
|
+
} catch (err) {
|
|
1698
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
1699
|
+
this.vector.available = false;
|
|
1700
|
+
this.vector.loadError = message;
|
|
1701
|
+
log.warn(`sqlite-vec unavailable: ${message}`);
|
|
1702
|
+
return false;
|
|
1703
|
+
}
|
|
1704
|
+
}
|
|
1705
|
+
ensureVectorTable(dimensions) {
|
|
1706
|
+
if (this.vector.dims === dimensions) return;
|
|
1707
|
+
if (this.vector.dims && this.vector.dims !== dimensions) this.dropVectorTable();
|
|
1708
|
+
this.db.exec(`CREATE VIRTUAL TABLE IF NOT EXISTS ${VECTOR_TABLE} USING vec0(\n id TEXT PRIMARY KEY,\n embedding FLOAT[${dimensions}]\n)`);
|
|
1709
|
+
this.vector.dims = dimensions;
|
|
1710
|
+
}
|
|
1711
|
+
dropVectorTable() {
|
|
1712
|
+
try {
|
|
1713
|
+
this.db.exec(`DROP TABLE IF EXISTS ${VECTOR_TABLE}`);
|
|
1714
|
+
} catch (err) {
|
|
1715
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
1716
|
+
log.debug(`Failed to drop ${VECTOR_TABLE}: ${message}`);
|
|
1717
|
+
}
|
|
1718
|
+
}
|
|
1719
|
+
buildSourceFilter(alias) {
|
|
1720
|
+
const sources = Array.from(this.sources);
|
|
1721
|
+
if (sources.length === 0) return {
|
|
1722
|
+
sql: "",
|
|
1723
|
+
params: []
|
|
1724
|
+
};
|
|
1725
|
+
return {
|
|
1726
|
+
sql: ` AND ${alias ? `${alias}.source` : "source"} IN (${sources.map(() => "?").join(", ")})`,
|
|
1727
|
+
params: sources
|
|
1728
|
+
};
|
|
1729
|
+
}
|
|
1730
|
+
openDatabase() {
|
|
1731
|
+
const dbPath = resolveUserPath(this.settings.store.path);
|
|
1732
|
+
return this.openDatabaseAtPath(dbPath);
|
|
1733
|
+
}
|
|
1734
|
+
openDatabaseAtPath(dbPath) {
|
|
1735
|
+
ensureDir(path.dirname(dbPath));
|
|
1736
|
+
const { DatabaseSync } = requireNodeSqlite();
|
|
1737
|
+
return new DatabaseSync(dbPath, { allowExtension: this.settings.store.vector.enabled });
|
|
1738
|
+
}
|
|
1739
|
+
seedEmbeddingCache(sourceDb) {
|
|
1740
|
+
if (!this.cache.enabled) return;
|
|
1741
|
+
try {
|
|
1742
|
+
const rows = sourceDb.prepare(`SELECT provider, model, provider_key, hash, embedding, dims, updated_at FROM ${EMBEDDING_CACHE_TABLE}`).all();
|
|
1743
|
+
if (!rows.length) return;
|
|
1744
|
+
const insert = this.db.prepare(`INSERT INTO ${EMBEDDING_CACHE_TABLE} (provider, model, provider_key, hash, embedding, dims, updated_at)
|
|
1745
|
+
VALUES (?, ?, ?, ?, ?, ?, ?)
|
|
1746
|
+
ON CONFLICT(provider, model, provider_key, hash) DO UPDATE SET
|
|
1747
|
+
embedding=excluded.embedding,
|
|
1748
|
+
dims=excluded.dims,
|
|
1749
|
+
updated_at=excluded.updated_at`);
|
|
1750
|
+
this.db.exec("BEGIN");
|
|
1751
|
+
for (const row of rows) insert.run(row.provider, row.model, row.provider_key, row.hash, row.embedding, row.dims, row.updated_at);
|
|
1752
|
+
this.db.exec("COMMIT");
|
|
1753
|
+
} catch (err) {
|
|
1754
|
+
try {
|
|
1755
|
+
this.db.exec("ROLLBACK");
|
|
1756
|
+
} catch {}
|
|
1757
|
+
throw err;
|
|
1758
|
+
}
|
|
1759
|
+
}
|
|
1760
|
+
async swapIndexFiles(targetPath, tempPath) {
|
|
1761
|
+
const backupPath = `${targetPath}.backup-${randomUUID()}`;
|
|
1762
|
+
await this.moveIndexFiles(targetPath, backupPath);
|
|
1763
|
+
try {
|
|
1764
|
+
await this.moveIndexFiles(tempPath, targetPath);
|
|
1765
|
+
} catch (err) {
|
|
1766
|
+
await this.moveIndexFiles(backupPath, targetPath);
|
|
1767
|
+
throw err;
|
|
1768
|
+
}
|
|
1769
|
+
await this.removeIndexFiles(backupPath);
|
|
1770
|
+
}
|
|
1771
|
+
async moveIndexFiles(sourceBase, targetBase) {
|
|
1772
|
+
for (const suffix of [
|
|
1773
|
+
"",
|
|
1774
|
+
"-wal",
|
|
1775
|
+
"-shm"
|
|
1776
|
+
]) {
|
|
1777
|
+
const source = `${sourceBase}${suffix}`;
|
|
1778
|
+
const target = `${targetBase}${suffix}`;
|
|
1779
|
+
try {
|
|
1780
|
+
await fs$1.rename(source, target);
|
|
1781
|
+
} catch (err) {
|
|
1782
|
+
if (err.code !== "ENOENT") throw err;
|
|
1783
|
+
}
|
|
1784
|
+
}
|
|
1785
|
+
}
|
|
1786
|
+
async removeIndexFiles(basePath) {
|
|
1787
|
+
await Promise.all([
|
|
1788
|
+
"",
|
|
1789
|
+
"-wal",
|
|
1790
|
+
"-shm"
|
|
1791
|
+
].map((suffix) => fs$1.rm(`${basePath}${suffix}`, { force: true })));
|
|
1792
|
+
}
|
|
1793
|
+
ensureSchema() {
|
|
1794
|
+
const result = ensureMemoryIndexSchema({
|
|
1795
|
+
db: this.db,
|
|
1796
|
+
embeddingCacheTable: EMBEDDING_CACHE_TABLE,
|
|
1797
|
+
ftsTable: FTS_TABLE,
|
|
1798
|
+
ftsEnabled: this.fts.enabled
|
|
1799
|
+
});
|
|
1800
|
+
this.fts.available = result.ftsAvailable;
|
|
1801
|
+
if (result.ftsError) {
|
|
1802
|
+
this.fts.loadError = result.ftsError;
|
|
1803
|
+
log.warn(`fts unavailable: ${result.ftsError}`);
|
|
1804
|
+
}
|
|
1805
|
+
}
|
|
1806
|
+
ensureWatcher() {
|
|
1807
|
+
if (!this.sources.has("memory") || !this.settings.sync.watch || this.watcher) return;
|
|
1808
|
+
const additionalPaths = normalizeExtraMemoryPaths(this.workspaceDir, this.settings.extraPaths).map((entry) => {
|
|
1809
|
+
try {
|
|
1810
|
+
return fs.lstatSync(entry).isSymbolicLink() ? null : entry;
|
|
1811
|
+
} catch {
|
|
1812
|
+
return null;
|
|
1813
|
+
}
|
|
1814
|
+
}).filter((entry) => Boolean(entry));
|
|
1815
|
+
const watchPaths = new Set([
|
|
1816
|
+
path.join(this.workspaceDir, "MEMORY.md"),
|
|
1817
|
+
path.join(this.workspaceDir, "memory.md"),
|
|
1818
|
+
path.join(this.workspaceDir, "memory"),
|
|
1819
|
+
...additionalPaths
|
|
1820
|
+
]);
|
|
1821
|
+
this.watcher = chokidar.watch(Array.from(watchPaths), {
|
|
1822
|
+
ignoreInitial: true,
|
|
1823
|
+
awaitWriteFinish: {
|
|
1824
|
+
stabilityThreshold: this.settings.sync.watchDebounceMs,
|
|
1825
|
+
pollInterval: 100
|
|
1826
|
+
}
|
|
1827
|
+
});
|
|
1828
|
+
const markDirty = () => {
|
|
1829
|
+
this.dirty = true;
|
|
1830
|
+
this.scheduleWatchSync();
|
|
1831
|
+
};
|
|
1832
|
+
this.watcher.on("add", markDirty);
|
|
1833
|
+
this.watcher.on("change", markDirty);
|
|
1834
|
+
this.watcher.on("unlink", markDirty);
|
|
1835
|
+
}
|
|
1836
|
+
ensureSessionListener() {
|
|
1837
|
+
if (!this.sources.has("sessions") || this.sessionUnsubscribe) return;
|
|
1838
|
+
this.sessionUnsubscribe = onSessionTranscriptUpdate((update) => {
|
|
1839
|
+
if (this.closed) return;
|
|
1840
|
+
const sessionFile = update.sessionFile;
|
|
1841
|
+
if (!this.isSessionFileForAgent(sessionFile)) return;
|
|
1842
|
+
this.scheduleSessionDirty(sessionFile);
|
|
1843
|
+
});
|
|
1844
|
+
}
|
|
1845
|
+
scheduleSessionDirty(sessionFile) {
|
|
1846
|
+
this.sessionPendingFiles.add(sessionFile);
|
|
1847
|
+
if (this.sessionWatchTimer) return;
|
|
1848
|
+
this.sessionWatchTimer = setTimeout(() => {
|
|
1849
|
+
this.sessionWatchTimer = null;
|
|
1850
|
+
this.processSessionDeltaBatch().catch((err) => {
|
|
1851
|
+
log.warn(`memory session delta failed: ${String(err)}`);
|
|
1852
|
+
});
|
|
1853
|
+
}, SESSION_DIRTY_DEBOUNCE_MS);
|
|
1854
|
+
}
|
|
1855
|
+
async processSessionDeltaBatch() {
|
|
1856
|
+
if (this.sessionPendingFiles.size === 0) return;
|
|
1857
|
+
const pending = Array.from(this.sessionPendingFiles);
|
|
1858
|
+
this.sessionPendingFiles.clear();
|
|
1859
|
+
let shouldSync = false;
|
|
1860
|
+
for (const sessionFile of pending) {
|
|
1861
|
+
const delta = await this.updateSessionDelta(sessionFile);
|
|
1862
|
+
if (!delta) continue;
|
|
1863
|
+
const bytesThreshold = delta.deltaBytes;
|
|
1864
|
+
const messagesThreshold = delta.deltaMessages;
|
|
1865
|
+
const bytesHit = bytesThreshold <= 0 ? delta.pendingBytes > 0 : delta.pendingBytes >= bytesThreshold;
|
|
1866
|
+
const messagesHit = messagesThreshold <= 0 ? delta.pendingMessages > 0 : delta.pendingMessages >= messagesThreshold;
|
|
1867
|
+
if (!bytesHit && !messagesHit) continue;
|
|
1868
|
+
this.sessionsDirtyFiles.add(sessionFile);
|
|
1869
|
+
this.sessionsDirty = true;
|
|
1870
|
+
delta.pendingBytes = bytesThreshold > 0 ? Math.max(0, delta.pendingBytes - bytesThreshold) : 0;
|
|
1871
|
+
delta.pendingMessages = messagesThreshold > 0 ? Math.max(0, delta.pendingMessages - messagesThreshold) : 0;
|
|
1872
|
+
shouldSync = true;
|
|
1873
|
+
}
|
|
1874
|
+
if (shouldSync) this.sync({ reason: "session-delta" }).catch((err) => {
|
|
1875
|
+
log.warn(`memory sync failed (session-delta): ${String(err)}`);
|
|
1876
|
+
});
|
|
1877
|
+
}
|
|
1878
|
+
async updateSessionDelta(sessionFile) {
|
|
1879
|
+
const thresholds = this.settings.sync.sessions;
|
|
1880
|
+
if (!thresholds) return null;
|
|
1881
|
+
let stat;
|
|
1882
|
+
try {
|
|
1883
|
+
stat = await fs$1.stat(sessionFile);
|
|
1884
|
+
} catch {
|
|
1885
|
+
return null;
|
|
1886
|
+
}
|
|
1887
|
+
const size = stat.size;
|
|
1888
|
+
let state = this.sessionDeltas.get(sessionFile);
|
|
1889
|
+
if (!state) {
|
|
1890
|
+
state = {
|
|
1891
|
+
lastSize: 0,
|
|
1892
|
+
pendingBytes: 0,
|
|
1893
|
+
pendingMessages: 0
|
|
1894
|
+
};
|
|
1895
|
+
this.sessionDeltas.set(sessionFile, state);
|
|
1896
|
+
}
|
|
1897
|
+
const deltaBytes = Math.max(0, size - state.lastSize);
|
|
1898
|
+
if (deltaBytes === 0 && size === state.lastSize) return {
|
|
1899
|
+
deltaBytes: thresholds.deltaBytes,
|
|
1900
|
+
deltaMessages: thresholds.deltaMessages,
|
|
1901
|
+
pendingBytes: state.pendingBytes,
|
|
1902
|
+
pendingMessages: state.pendingMessages
|
|
1903
|
+
};
|
|
1904
|
+
if (size < state.lastSize) {
|
|
1905
|
+
state.lastSize = size;
|
|
1906
|
+
state.pendingBytes += size;
|
|
1907
|
+
if (thresholds.deltaMessages > 0 && (thresholds.deltaBytes <= 0 || state.pendingBytes < thresholds.deltaBytes)) state.pendingMessages += await this.countNewlines(sessionFile, 0, size);
|
|
1908
|
+
} else {
|
|
1909
|
+
state.pendingBytes += deltaBytes;
|
|
1910
|
+
if (thresholds.deltaMessages > 0 && (thresholds.deltaBytes <= 0 || state.pendingBytes < thresholds.deltaBytes)) state.pendingMessages += await this.countNewlines(sessionFile, state.lastSize, size);
|
|
1911
|
+
state.lastSize = size;
|
|
1912
|
+
}
|
|
1913
|
+
this.sessionDeltas.set(sessionFile, state);
|
|
1914
|
+
return {
|
|
1915
|
+
deltaBytes: thresholds.deltaBytes,
|
|
1916
|
+
deltaMessages: thresholds.deltaMessages,
|
|
1917
|
+
pendingBytes: state.pendingBytes,
|
|
1918
|
+
pendingMessages: state.pendingMessages
|
|
1919
|
+
};
|
|
1920
|
+
}
|
|
1921
|
+
async countNewlines(absPath, start, end) {
|
|
1922
|
+
if (end <= start) return 0;
|
|
1923
|
+
const handle = await fs$1.open(absPath, "r");
|
|
1924
|
+
try {
|
|
1925
|
+
let offset = start;
|
|
1926
|
+
let count = 0;
|
|
1927
|
+
const buffer = Buffer.alloc(SESSION_DELTA_READ_CHUNK_BYTES);
|
|
1928
|
+
while (offset < end) {
|
|
1929
|
+
const toRead = Math.min(buffer.length, end - offset);
|
|
1930
|
+
const { bytesRead } = await handle.read(buffer, 0, toRead, offset);
|
|
1931
|
+
if (bytesRead <= 0) break;
|
|
1932
|
+
for (let i = 0; i < bytesRead; i += 1) if (buffer[i] === 10) count += 1;
|
|
1933
|
+
offset += bytesRead;
|
|
1934
|
+
}
|
|
1935
|
+
return count;
|
|
1936
|
+
} finally {
|
|
1937
|
+
await handle.close();
|
|
1938
|
+
}
|
|
1939
|
+
}
|
|
1940
|
+
resetSessionDelta(absPath, size) {
|
|
1941
|
+
const state = this.sessionDeltas.get(absPath);
|
|
1942
|
+
if (!state) return;
|
|
1943
|
+
state.lastSize = size;
|
|
1944
|
+
state.pendingBytes = 0;
|
|
1945
|
+
state.pendingMessages = 0;
|
|
1946
|
+
}
|
|
1947
|
+
isSessionFileForAgent(sessionFile) {
|
|
1948
|
+
if (!sessionFile) return false;
|
|
1949
|
+
const sessionsDir = resolveSessionTranscriptsDirForAgent(this.agentId);
|
|
1950
|
+
const resolvedFile = path.resolve(sessionFile);
|
|
1951
|
+
const resolvedDir = path.resolve(sessionsDir);
|
|
1952
|
+
return resolvedFile.startsWith(`${resolvedDir}${path.sep}`);
|
|
1953
|
+
}
|
|
1954
|
+
ensureIntervalSync() {
|
|
1955
|
+
const minutes = this.settings.sync.intervalMinutes;
|
|
1956
|
+
if (!minutes || minutes <= 0 || this.intervalTimer) return;
|
|
1957
|
+
const ms = minutes * 60 * 1e3;
|
|
1958
|
+
this.intervalTimer = setInterval(() => {
|
|
1959
|
+
this.sync({ reason: "interval" }).catch((err) => {
|
|
1960
|
+
log.warn(`memory sync failed (interval): ${String(err)}`);
|
|
1961
|
+
});
|
|
1962
|
+
}, ms);
|
|
1963
|
+
}
|
|
1964
|
+
scheduleWatchSync() {
|
|
1965
|
+
if (!this.sources.has("memory") || !this.settings.sync.watch) return;
|
|
1966
|
+
if (this.watchTimer) clearTimeout(this.watchTimer);
|
|
1967
|
+
this.watchTimer = setTimeout(() => {
|
|
1968
|
+
this.watchTimer = null;
|
|
1969
|
+
this.sync({ reason: "watch" }).catch((err) => {
|
|
1970
|
+
log.warn(`memory sync failed (watch): ${String(err)}`);
|
|
1971
|
+
});
|
|
1972
|
+
}, this.settings.sync.watchDebounceMs);
|
|
1973
|
+
}
|
|
1974
|
+
shouldSyncSessions(params, needsFullReindex = false) {
|
|
1975
|
+
if (!this.sources.has("sessions")) return false;
|
|
1976
|
+
if (params?.force) return true;
|
|
1977
|
+
const reason = params?.reason;
|
|
1978
|
+
if (reason === "session-start" || reason === "watch") return false;
|
|
1979
|
+
if (needsFullReindex) return true;
|
|
1980
|
+
return this.sessionsDirty && this.sessionsDirtyFiles.size > 0;
|
|
1981
|
+
}
|
|
1982
|
+
async syncMemoryFiles(params) {
|
|
1983
|
+
const files = await listMemoryFiles(this.workspaceDir, this.settings.extraPaths);
|
|
1984
|
+
const fileEntries = await Promise.all(files.map(async (file) => buildFileEntry(file, this.workspaceDir)));
|
|
1985
|
+
log.debug("memory sync: indexing memory files", {
|
|
1986
|
+
files: fileEntries.length,
|
|
1987
|
+
needsFullReindex: params.needsFullReindex,
|
|
1988
|
+
batch: this.batch.enabled,
|
|
1989
|
+
concurrency: this.getIndexConcurrency()
|
|
1990
|
+
});
|
|
1991
|
+
const activePaths = new Set(fileEntries.map((entry) => entry.path));
|
|
1992
|
+
if (params.progress) {
|
|
1993
|
+
params.progress.total += fileEntries.length;
|
|
1994
|
+
params.progress.report({
|
|
1995
|
+
completed: params.progress.completed,
|
|
1996
|
+
total: params.progress.total,
|
|
1997
|
+
label: this.batch.enabled ? "Indexing memory files (batch)..." : "Indexing memory files…"
|
|
1998
|
+
});
|
|
1999
|
+
}
|
|
2000
|
+
const tasks = fileEntries.map((entry) => async () => {
|
|
2001
|
+
const record = this.db.prepare(`SELECT hash FROM files WHERE path = ? AND source = ?`).get(entry.path, "memory");
|
|
2002
|
+
if (!params.needsFullReindex && record?.hash === entry.hash) {
|
|
2003
|
+
if (params.progress) {
|
|
2004
|
+
params.progress.completed += 1;
|
|
2005
|
+
params.progress.report({
|
|
2006
|
+
completed: params.progress.completed,
|
|
2007
|
+
total: params.progress.total
|
|
2008
|
+
});
|
|
2009
|
+
}
|
|
2010
|
+
return;
|
|
2011
|
+
}
|
|
2012
|
+
await this.indexFile(entry, { source: "memory" });
|
|
2013
|
+
if (params.progress) {
|
|
2014
|
+
params.progress.completed += 1;
|
|
2015
|
+
params.progress.report({
|
|
2016
|
+
completed: params.progress.completed,
|
|
2017
|
+
total: params.progress.total
|
|
2018
|
+
});
|
|
2019
|
+
}
|
|
2020
|
+
});
|
|
2021
|
+
await this.runWithConcurrency(tasks, this.getIndexConcurrency());
|
|
2022
|
+
const staleRows = this.db.prepare(`SELECT path FROM files WHERE source = ?`).all("memory");
|
|
2023
|
+
for (const stale of staleRows) {
|
|
2024
|
+
if (activePaths.has(stale.path)) continue;
|
|
2025
|
+
this.db.prepare(`DELETE FROM files WHERE path = ? AND source = ?`).run(stale.path, "memory");
|
|
2026
|
+
try {
|
|
2027
|
+
this.db.prepare(`DELETE FROM ${VECTOR_TABLE} WHERE id IN (SELECT id FROM chunks WHERE path = ? AND source = ?)`).run(stale.path, "memory");
|
|
2028
|
+
} catch {}
|
|
2029
|
+
this.db.prepare(`DELETE FROM chunks WHERE path = ? AND source = ?`).run(stale.path, "memory");
|
|
2030
|
+
if (this.fts.enabled && this.fts.available) try {
|
|
2031
|
+
this.db.prepare(`DELETE FROM ${FTS_TABLE} WHERE path = ? AND source = ? AND model = ?`).run(stale.path, "memory", this.provider.model);
|
|
2032
|
+
} catch {}
|
|
2033
|
+
}
|
|
2034
|
+
}
|
|
2035
|
+
async syncSessionFiles(params) {
|
|
2036
|
+
const files = await this.listSessionFiles();
|
|
2037
|
+
const activePaths = new Set(files.map((file) => this.sessionPathForFile(file)));
|
|
2038
|
+
const indexAll = params.needsFullReindex || this.sessionsDirtyFiles.size === 0;
|
|
2039
|
+
log.debug("memory sync: indexing session files", {
|
|
2040
|
+
files: files.length,
|
|
2041
|
+
indexAll,
|
|
2042
|
+
dirtyFiles: this.sessionsDirtyFiles.size,
|
|
2043
|
+
batch: this.batch.enabled,
|
|
2044
|
+
concurrency: this.getIndexConcurrency()
|
|
2045
|
+
});
|
|
2046
|
+
if (params.progress) {
|
|
2047
|
+
params.progress.total += files.length;
|
|
2048
|
+
params.progress.report({
|
|
2049
|
+
completed: params.progress.completed,
|
|
2050
|
+
total: params.progress.total,
|
|
2051
|
+
label: this.batch.enabled ? "Indexing session files (batch)..." : "Indexing session files…"
|
|
2052
|
+
});
|
|
2053
|
+
}
|
|
2054
|
+
const tasks = files.map((absPath) => async () => {
|
|
2055
|
+
if (!indexAll && !this.sessionsDirtyFiles.has(absPath)) {
|
|
2056
|
+
if (params.progress) {
|
|
2057
|
+
params.progress.completed += 1;
|
|
2058
|
+
params.progress.report({
|
|
2059
|
+
completed: params.progress.completed,
|
|
2060
|
+
total: params.progress.total
|
|
2061
|
+
});
|
|
2062
|
+
}
|
|
2063
|
+
return;
|
|
2064
|
+
}
|
|
2065
|
+
const entry = await this.buildSessionEntry(absPath);
|
|
2066
|
+
if (!entry) {
|
|
2067
|
+
if (params.progress) {
|
|
2068
|
+
params.progress.completed += 1;
|
|
2069
|
+
params.progress.report({
|
|
2070
|
+
completed: params.progress.completed,
|
|
2071
|
+
total: params.progress.total
|
|
2072
|
+
});
|
|
2073
|
+
}
|
|
2074
|
+
return;
|
|
2075
|
+
}
|
|
2076
|
+
const record = this.db.prepare(`SELECT hash FROM files WHERE path = ? AND source = ?`).get(entry.path, "sessions");
|
|
2077
|
+
if (!params.needsFullReindex && record?.hash === entry.hash) {
|
|
2078
|
+
if (params.progress) {
|
|
2079
|
+
params.progress.completed += 1;
|
|
2080
|
+
params.progress.report({
|
|
2081
|
+
completed: params.progress.completed,
|
|
2082
|
+
total: params.progress.total
|
|
2083
|
+
});
|
|
2084
|
+
}
|
|
2085
|
+
this.resetSessionDelta(absPath, entry.size);
|
|
2086
|
+
return;
|
|
2087
|
+
}
|
|
2088
|
+
await this.indexFile(entry, {
|
|
2089
|
+
source: "sessions",
|
|
2090
|
+
content: entry.content
|
|
2091
|
+
});
|
|
2092
|
+
this.resetSessionDelta(absPath, entry.size);
|
|
2093
|
+
if (params.progress) {
|
|
2094
|
+
params.progress.completed += 1;
|
|
2095
|
+
params.progress.report({
|
|
2096
|
+
completed: params.progress.completed,
|
|
2097
|
+
total: params.progress.total
|
|
2098
|
+
});
|
|
2099
|
+
}
|
|
2100
|
+
});
|
|
2101
|
+
await this.runWithConcurrency(tasks, this.getIndexConcurrency());
|
|
2102
|
+
const staleRows = this.db.prepare(`SELECT path FROM files WHERE source = ?`).all("sessions");
|
|
2103
|
+
for (const stale of staleRows) {
|
|
2104
|
+
if (activePaths.has(stale.path)) continue;
|
|
2105
|
+
this.db.prepare(`DELETE FROM files WHERE path = ? AND source = ?`).run(stale.path, "sessions");
|
|
2106
|
+
try {
|
|
2107
|
+
this.db.prepare(`DELETE FROM ${VECTOR_TABLE} WHERE id IN (SELECT id FROM chunks WHERE path = ? AND source = ?)`).run(stale.path, "sessions");
|
|
2108
|
+
} catch {}
|
|
2109
|
+
this.db.prepare(`DELETE FROM chunks WHERE path = ? AND source = ?`).run(stale.path, "sessions");
|
|
2110
|
+
if (this.fts.enabled && this.fts.available) try {
|
|
2111
|
+
this.db.prepare(`DELETE FROM ${FTS_TABLE} WHERE path = ? AND source = ? AND model = ?`).run(stale.path, "sessions", this.provider.model);
|
|
2112
|
+
} catch {}
|
|
2113
|
+
}
|
|
2114
|
+
}
|
|
2115
|
+
createSyncProgress(onProgress) {
|
|
2116
|
+
const state = {
|
|
2117
|
+
completed: 0,
|
|
2118
|
+
total: 0,
|
|
2119
|
+
label: void 0,
|
|
2120
|
+
report: (update) => {
|
|
2121
|
+
if (update.label) state.label = update.label;
|
|
2122
|
+
const label = update.total > 0 && state.label ? `${state.label} ${update.completed}/${update.total}` : state.label;
|
|
2123
|
+
onProgress({
|
|
2124
|
+
completed: update.completed,
|
|
2125
|
+
total: update.total,
|
|
2126
|
+
label
|
|
2127
|
+
});
|
|
2128
|
+
}
|
|
2129
|
+
};
|
|
2130
|
+
return state;
|
|
2131
|
+
}
|
|
2132
|
+
async runSync(params) {
|
|
2133
|
+
const progress = params?.progress ? this.createSyncProgress(params.progress) : void 0;
|
|
2134
|
+
if (progress) progress.report({
|
|
2135
|
+
completed: progress.completed,
|
|
2136
|
+
total: progress.total,
|
|
2137
|
+
label: "Loading vector extension…"
|
|
2138
|
+
});
|
|
2139
|
+
const vectorReady = await this.ensureVectorReady();
|
|
2140
|
+
const meta = this.readMeta();
|
|
2141
|
+
const needsFullReindex = params?.force || !meta || meta.model !== this.provider.model || meta.provider !== this.provider.id || meta.providerKey !== this.providerKey || meta.chunkTokens !== this.settings.chunking.tokens || meta.chunkOverlap !== this.settings.chunking.overlap || vectorReady && !meta?.vectorDims;
|
|
2142
|
+
try {
|
|
2143
|
+
if (needsFullReindex) {
|
|
2144
|
+
await this.runSafeReindex({
|
|
2145
|
+
reason: params?.reason,
|
|
2146
|
+
force: params?.force,
|
|
2147
|
+
progress: progress ?? void 0
|
|
2148
|
+
});
|
|
2149
|
+
return;
|
|
2150
|
+
}
|
|
2151
|
+
const shouldSyncMemory = this.sources.has("memory") && (params?.force || needsFullReindex || this.dirty);
|
|
2152
|
+
const shouldSyncSessions = this.shouldSyncSessions(params, needsFullReindex);
|
|
2153
|
+
if (shouldSyncMemory) {
|
|
2154
|
+
await this.syncMemoryFiles({
|
|
2155
|
+
needsFullReindex,
|
|
2156
|
+
progress: progress ?? void 0
|
|
2157
|
+
});
|
|
2158
|
+
this.dirty = false;
|
|
2159
|
+
}
|
|
2160
|
+
if (shouldSyncSessions) {
|
|
2161
|
+
await this.syncSessionFiles({
|
|
2162
|
+
needsFullReindex,
|
|
2163
|
+
progress: progress ?? void 0
|
|
2164
|
+
});
|
|
2165
|
+
this.sessionsDirty = false;
|
|
2166
|
+
this.sessionsDirtyFiles.clear();
|
|
2167
|
+
} else if (this.sessionsDirtyFiles.size > 0) this.sessionsDirty = true;
|
|
2168
|
+
else this.sessionsDirty = false;
|
|
2169
|
+
} catch (err) {
|
|
2170
|
+
const reason = err instanceof Error ? err.message : String(err);
|
|
2171
|
+
if (this.shouldFallbackOnError(reason) && await this.activateFallbackProvider(reason)) {
|
|
2172
|
+
await this.runSafeReindex({
|
|
2173
|
+
reason: params?.reason ?? "fallback",
|
|
2174
|
+
force: true,
|
|
2175
|
+
progress: progress ?? void 0
|
|
2176
|
+
});
|
|
2177
|
+
return;
|
|
2178
|
+
}
|
|
2179
|
+
throw err;
|
|
2180
|
+
}
|
|
2181
|
+
}
|
|
2182
|
+
shouldFallbackOnError(message) {
|
|
2183
|
+
return /embedding|embeddings|batch/i.test(message);
|
|
2184
|
+
}
|
|
2185
|
+
resolveBatchConfig() {
|
|
2186
|
+
const batch = this.settings.remote?.batch;
|
|
2187
|
+
return {
|
|
2188
|
+
enabled: Boolean(batch?.enabled && (this.openAi && this.provider.id === "openai" || this.gemini && this.provider.id === "gemini")),
|
|
2189
|
+
wait: batch?.wait ?? true,
|
|
2190
|
+
concurrency: Math.max(1, batch?.concurrency ?? 2),
|
|
2191
|
+
pollIntervalMs: batch?.pollIntervalMs ?? 2e3,
|
|
2192
|
+
timeoutMs: (batch?.timeoutMinutes ?? 60) * 60 * 1e3
|
|
2193
|
+
};
|
|
2194
|
+
}
|
|
2195
|
+
async activateFallbackProvider(reason) {
|
|
2196
|
+
const fallback = this.settings.fallback;
|
|
2197
|
+
if (!fallback || fallback === "none" || fallback === this.provider.id) return false;
|
|
2198
|
+
if (this.fallbackFrom) return false;
|
|
2199
|
+
const fallbackFrom = this.provider.id;
|
|
2200
|
+
const fallbackModel = fallback === "gemini" ? DEFAULT_GEMINI_EMBEDDING_MODEL : fallback === "openai" ? DEFAULT_OPENAI_EMBEDDING_MODEL : this.settings.model;
|
|
2201
|
+
const fallbackResult = await createEmbeddingProvider({
|
|
2202
|
+
config: this.cfg,
|
|
2203
|
+
agentDir: resolveAgentDir(this.cfg, this.agentId),
|
|
2204
|
+
provider: fallback,
|
|
2205
|
+
remote: this.settings.remote,
|
|
2206
|
+
model: fallbackModel,
|
|
2207
|
+
fallback: "none",
|
|
2208
|
+
local: this.settings.local
|
|
2209
|
+
});
|
|
2210
|
+
this.fallbackFrom = fallbackFrom;
|
|
2211
|
+
this.fallbackReason = reason;
|
|
2212
|
+
this.provider = fallbackResult.provider;
|
|
2213
|
+
this.openAi = fallbackResult.openAi;
|
|
2214
|
+
this.gemini = fallbackResult.gemini;
|
|
2215
|
+
this.providerKey = this.computeProviderKey();
|
|
2216
|
+
this.batch = this.resolveBatchConfig();
|
|
2217
|
+
log.warn(`memory embeddings: switched to fallback provider (${fallback})`, { reason });
|
|
2218
|
+
return true;
|
|
2219
|
+
}
|
|
2220
|
+
async runSafeReindex(params) {
|
|
2221
|
+
const dbPath = resolveUserPath(this.settings.store.path);
|
|
2222
|
+
const tempDbPath = `${dbPath}.tmp-${randomUUID()}`;
|
|
2223
|
+
const tempDb = this.openDatabaseAtPath(tempDbPath);
|
|
2224
|
+
const originalDb = this.db;
|
|
2225
|
+
let originalDbClosed = false;
|
|
2226
|
+
const originalState = {
|
|
2227
|
+
ftsAvailable: this.fts.available,
|
|
2228
|
+
ftsError: this.fts.loadError,
|
|
2229
|
+
vectorAvailable: this.vector.available,
|
|
2230
|
+
vectorLoadError: this.vector.loadError,
|
|
2231
|
+
vectorDims: this.vector.dims,
|
|
2232
|
+
vectorReady: this.vectorReady
|
|
2233
|
+
};
|
|
2234
|
+
const restoreOriginalState = () => {
|
|
2235
|
+
if (originalDbClosed) this.db = this.openDatabaseAtPath(dbPath);
|
|
2236
|
+
else this.db = originalDb;
|
|
2237
|
+
this.fts.available = originalState.ftsAvailable;
|
|
2238
|
+
this.fts.loadError = originalState.ftsError;
|
|
2239
|
+
this.vector.available = originalDbClosed ? null : originalState.vectorAvailable;
|
|
2240
|
+
this.vector.loadError = originalState.vectorLoadError;
|
|
2241
|
+
this.vector.dims = originalState.vectorDims;
|
|
2242
|
+
this.vectorReady = originalDbClosed ? null : originalState.vectorReady;
|
|
2243
|
+
};
|
|
2244
|
+
this.db = tempDb;
|
|
2245
|
+
this.vectorReady = null;
|
|
2246
|
+
this.vector.available = null;
|
|
2247
|
+
this.vector.loadError = void 0;
|
|
2248
|
+
this.vector.dims = void 0;
|
|
2249
|
+
this.fts.available = false;
|
|
2250
|
+
this.fts.loadError = void 0;
|
|
2251
|
+
this.ensureSchema();
|
|
2252
|
+
let nextMeta = null;
|
|
2253
|
+
try {
|
|
2254
|
+
this.seedEmbeddingCache(originalDb);
|
|
2255
|
+
const shouldSyncMemory = this.sources.has("memory");
|
|
2256
|
+
const shouldSyncSessions = this.shouldSyncSessions({
|
|
2257
|
+
reason: params.reason,
|
|
2258
|
+
force: params.force
|
|
2259
|
+
}, true);
|
|
2260
|
+
if (shouldSyncMemory) {
|
|
2261
|
+
await this.syncMemoryFiles({
|
|
2262
|
+
needsFullReindex: true,
|
|
2263
|
+
progress: params.progress
|
|
2264
|
+
});
|
|
2265
|
+
this.dirty = false;
|
|
2266
|
+
}
|
|
2267
|
+
if (shouldSyncSessions) {
|
|
2268
|
+
await this.syncSessionFiles({
|
|
2269
|
+
needsFullReindex: true,
|
|
2270
|
+
progress: params.progress
|
|
2271
|
+
});
|
|
2272
|
+
this.sessionsDirty = false;
|
|
2273
|
+
this.sessionsDirtyFiles.clear();
|
|
2274
|
+
} else if (this.sessionsDirtyFiles.size > 0) this.sessionsDirty = true;
|
|
2275
|
+
else this.sessionsDirty = false;
|
|
2276
|
+
nextMeta = {
|
|
2277
|
+
model: this.provider.model,
|
|
2278
|
+
provider: this.provider.id,
|
|
2279
|
+
providerKey: this.providerKey,
|
|
2280
|
+
chunkTokens: this.settings.chunking.tokens,
|
|
2281
|
+
chunkOverlap: this.settings.chunking.overlap
|
|
2282
|
+
};
|
|
2283
|
+
if (this.vector.available && this.vector.dims) nextMeta.vectorDims = this.vector.dims;
|
|
2284
|
+
this.writeMeta(nextMeta);
|
|
2285
|
+
this.pruneEmbeddingCacheIfNeeded();
|
|
2286
|
+
this.db.close();
|
|
2287
|
+
originalDb.close();
|
|
2288
|
+
originalDbClosed = true;
|
|
2289
|
+
await this.swapIndexFiles(dbPath, tempDbPath);
|
|
2290
|
+
this.db = this.openDatabaseAtPath(dbPath);
|
|
2291
|
+
this.vectorReady = null;
|
|
2292
|
+
this.vector.available = null;
|
|
2293
|
+
this.vector.loadError = void 0;
|
|
2294
|
+
this.ensureSchema();
|
|
2295
|
+
this.vector.dims = nextMeta.vectorDims;
|
|
2296
|
+
} catch (err) {
|
|
2297
|
+
try {
|
|
2298
|
+
this.db.close();
|
|
2299
|
+
} catch {}
|
|
2300
|
+
await this.removeIndexFiles(tempDbPath);
|
|
2301
|
+
restoreOriginalState();
|
|
2302
|
+
throw err;
|
|
2303
|
+
}
|
|
2304
|
+
}
|
|
2305
|
+
resetIndex() {
|
|
2306
|
+
this.db.exec(`DELETE FROM files`);
|
|
2307
|
+
this.db.exec(`DELETE FROM chunks`);
|
|
2308
|
+
if (this.fts.enabled && this.fts.available) try {
|
|
2309
|
+
this.db.exec(`DELETE FROM ${FTS_TABLE}`);
|
|
2310
|
+
} catch {}
|
|
2311
|
+
this.dropVectorTable();
|
|
2312
|
+
this.vector.dims = void 0;
|
|
2313
|
+
this.sessionsDirtyFiles.clear();
|
|
2314
|
+
}
|
|
2315
|
+
readMeta() {
|
|
2316
|
+
const row = this.db.prepare(`SELECT value FROM meta WHERE key = ?`).get(META_KEY);
|
|
2317
|
+
if (!row?.value) return null;
|
|
2318
|
+
try {
|
|
2319
|
+
return JSON.parse(row.value);
|
|
2320
|
+
} catch {
|
|
2321
|
+
return null;
|
|
2322
|
+
}
|
|
2323
|
+
}
|
|
2324
|
+
writeMeta(meta) {
|
|
2325
|
+
const value = JSON.stringify(meta);
|
|
2326
|
+
this.db.prepare(`INSERT INTO meta (key, value) VALUES (?, ?) ON CONFLICT(key) DO UPDATE SET value=excluded.value`).run(META_KEY, value);
|
|
2327
|
+
}
|
|
2328
|
+
async listSessionFiles() {
|
|
2329
|
+
const dir = resolveSessionTranscriptsDirForAgent(this.agentId);
|
|
2330
|
+
try {
|
|
2331
|
+
return (await fs$1.readdir(dir, { withFileTypes: true })).filter((entry) => entry.isFile()).map((entry) => entry.name).filter((name) => name.endsWith(".jsonl")).map((name) => path.join(dir, name));
|
|
2332
|
+
} catch {
|
|
2333
|
+
return [];
|
|
2334
|
+
}
|
|
2335
|
+
}
|
|
2336
|
+
sessionPathForFile(absPath) {
|
|
2337
|
+
return path.join("sessions", path.basename(absPath)).replace(/\\/g, "/");
|
|
2338
|
+
}
|
|
2339
|
+
normalizeSessionText(value) {
|
|
2340
|
+
return value.replace(/\s*\n+\s*/g, " ").replace(/\s+/g, " ").trim();
|
|
2341
|
+
}
|
|
2342
|
+
extractSessionText(content) {
|
|
2343
|
+
if (typeof content === "string") {
|
|
2344
|
+
const normalized = this.normalizeSessionText(content);
|
|
2345
|
+
return normalized ? normalized : null;
|
|
2346
|
+
}
|
|
2347
|
+
if (!Array.isArray(content)) return null;
|
|
2348
|
+
const parts = [];
|
|
2349
|
+
for (const block of content) {
|
|
2350
|
+
if (!block || typeof block !== "object") continue;
|
|
2351
|
+
const record = block;
|
|
2352
|
+
if (record.type !== "text" || typeof record.text !== "string") continue;
|
|
2353
|
+
const normalized = this.normalizeSessionText(record.text);
|
|
2354
|
+
if (normalized) parts.push(normalized);
|
|
2355
|
+
}
|
|
2356
|
+
if (parts.length === 0) return null;
|
|
2357
|
+
return parts.join(" ");
|
|
2358
|
+
}
|
|
2359
|
+
async buildSessionEntry(absPath) {
|
|
2360
|
+
try {
|
|
2361
|
+
const stat = await fs$1.stat(absPath);
|
|
2362
|
+
const lines = (await fs$1.readFile(absPath, "utf-8")).split("\n");
|
|
2363
|
+
const collected = [];
|
|
2364
|
+
for (const line of lines) {
|
|
2365
|
+
if (!line.trim()) continue;
|
|
2366
|
+
let record;
|
|
2367
|
+
try {
|
|
2368
|
+
record = JSON.parse(line);
|
|
2369
|
+
} catch {
|
|
2370
|
+
continue;
|
|
2371
|
+
}
|
|
2372
|
+
if (!record || typeof record !== "object" || record.type !== "message") continue;
|
|
2373
|
+
const message = record.message;
|
|
2374
|
+
if (!message || typeof message.role !== "string") continue;
|
|
2375
|
+
if (message.role !== "user" && message.role !== "assistant") continue;
|
|
2376
|
+
const text = this.extractSessionText(message.content);
|
|
2377
|
+
if (!text) continue;
|
|
2378
|
+
const label = message.role === "user" ? "User" : "Assistant";
|
|
2379
|
+
collected.push(`${label}: ${text}`);
|
|
2380
|
+
}
|
|
2381
|
+
const content = collected.join("\n");
|
|
2382
|
+
return {
|
|
2383
|
+
path: this.sessionPathForFile(absPath),
|
|
2384
|
+
absPath,
|
|
2385
|
+
mtimeMs: stat.mtimeMs,
|
|
2386
|
+
size: stat.size,
|
|
2387
|
+
hash: hashText(content),
|
|
2388
|
+
content
|
|
2389
|
+
};
|
|
2390
|
+
} catch (err) {
|
|
2391
|
+
log.debug(`Failed reading session file ${absPath}: ${String(err)}`);
|
|
2392
|
+
return null;
|
|
2393
|
+
}
|
|
2394
|
+
}
|
|
2395
|
+
estimateEmbeddingTokens(text) {
|
|
2396
|
+
if (!text) return 0;
|
|
2397
|
+
return Math.ceil(text.length / EMBEDDING_APPROX_CHARS_PER_TOKEN);
|
|
2398
|
+
}
|
|
2399
|
+
buildEmbeddingBatches(chunks) {
|
|
2400
|
+
const batches = [];
|
|
2401
|
+
let current = [];
|
|
2402
|
+
let currentTokens = 0;
|
|
2403
|
+
for (const chunk of chunks) {
|
|
2404
|
+
const estimate = this.estimateEmbeddingTokens(chunk.text);
|
|
2405
|
+
if (current.length > 0 && currentTokens + estimate > EMBEDDING_BATCH_MAX_TOKENS) {
|
|
2406
|
+
batches.push(current);
|
|
2407
|
+
current = [];
|
|
2408
|
+
currentTokens = 0;
|
|
2409
|
+
}
|
|
2410
|
+
if (current.length === 0 && estimate > EMBEDDING_BATCH_MAX_TOKENS) {
|
|
2411
|
+
batches.push([chunk]);
|
|
2412
|
+
continue;
|
|
2413
|
+
}
|
|
2414
|
+
current.push(chunk);
|
|
2415
|
+
currentTokens += estimate;
|
|
2416
|
+
}
|
|
2417
|
+
if (current.length > 0) batches.push(current);
|
|
2418
|
+
return batches;
|
|
2419
|
+
}
|
|
2420
|
+
loadEmbeddingCache(hashes) {
|
|
2421
|
+
if (!this.cache.enabled) return /* @__PURE__ */ new Map();
|
|
2422
|
+
if (hashes.length === 0) return /* @__PURE__ */ new Map();
|
|
2423
|
+
const unique = [];
|
|
2424
|
+
const seen = /* @__PURE__ */ new Set();
|
|
2425
|
+
for (const hash of hashes) {
|
|
2426
|
+
if (!hash) continue;
|
|
2427
|
+
if (seen.has(hash)) continue;
|
|
2428
|
+
seen.add(hash);
|
|
2429
|
+
unique.push(hash);
|
|
2430
|
+
}
|
|
2431
|
+
if (unique.length === 0) return /* @__PURE__ */ new Map();
|
|
2432
|
+
const out = /* @__PURE__ */ new Map();
|
|
2433
|
+
const baseParams = [
|
|
2434
|
+
this.provider.id,
|
|
2435
|
+
this.provider.model,
|
|
2436
|
+
this.providerKey
|
|
2437
|
+
];
|
|
2438
|
+
const batchSize = 400;
|
|
2439
|
+
for (let start = 0; start < unique.length; start += batchSize) {
|
|
2440
|
+
const batch = unique.slice(start, start + batchSize);
|
|
2441
|
+
const placeholders = batch.map(() => "?").join(", ");
|
|
2442
|
+
const rows = this.db.prepare(`SELECT hash, embedding FROM ${EMBEDDING_CACHE_TABLE}\n WHERE provider = ? AND model = ? AND provider_key = ? AND hash IN (${placeholders})`).all(...baseParams, ...batch);
|
|
2443
|
+
for (const row of rows) out.set(row.hash, parseEmbedding(row.embedding));
|
|
2444
|
+
}
|
|
2445
|
+
return out;
|
|
2446
|
+
}
|
|
2447
|
+
upsertEmbeddingCache(entries) {
|
|
2448
|
+
if (!this.cache.enabled) return;
|
|
2449
|
+
if (entries.length === 0) return;
|
|
2450
|
+
const now = Date.now();
|
|
2451
|
+
const stmt = this.db.prepare(`INSERT INTO ${EMBEDDING_CACHE_TABLE} (provider, model, provider_key, hash, embedding, dims, updated_at)\n VALUES (?, ?, ?, ?, ?, ?, ?)\n ON CONFLICT(provider, model, provider_key, hash) DO UPDATE SET\n embedding=excluded.embedding,\n dims=excluded.dims,\n updated_at=excluded.updated_at`);
|
|
2452
|
+
for (const entry of entries) {
|
|
2453
|
+
const embedding = entry.embedding ?? [];
|
|
2454
|
+
stmt.run(this.provider.id, this.provider.model, this.providerKey, entry.hash, JSON.stringify(embedding), embedding.length, now);
|
|
2455
|
+
}
|
|
2456
|
+
}
|
|
2457
|
+
pruneEmbeddingCacheIfNeeded() {
|
|
2458
|
+
if (!this.cache.enabled) return;
|
|
2459
|
+
const max = this.cache.maxEntries;
|
|
2460
|
+
if (!max || max <= 0) return;
|
|
2461
|
+
const count = this.db.prepare(`SELECT COUNT(*) as c FROM ${EMBEDDING_CACHE_TABLE}`).get()?.c ?? 0;
|
|
2462
|
+
if (count <= max) return;
|
|
2463
|
+
const excess = count - max;
|
|
2464
|
+
this.db.prepare(`DELETE FROM ${EMBEDDING_CACHE_TABLE}\n WHERE rowid IN (\n SELECT rowid FROM ${EMBEDDING_CACHE_TABLE}\n ORDER BY updated_at ASC\n LIMIT ?\n )`).run(excess);
|
|
2465
|
+
}
|
|
2466
|
+
async embedChunksInBatches(chunks) {
|
|
2467
|
+
if (chunks.length === 0) return [];
|
|
2468
|
+
const cached = this.loadEmbeddingCache(chunks.map((chunk) => chunk.hash));
|
|
2469
|
+
const embeddings = Array.from({ length: chunks.length }, () => []);
|
|
2470
|
+
const missing = [];
|
|
2471
|
+
for (let i = 0; i < chunks.length; i += 1) {
|
|
2472
|
+
const chunk = chunks[i];
|
|
2473
|
+
const hit = chunk?.hash ? cached.get(chunk.hash) : void 0;
|
|
2474
|
+
if (hit && hit.length > 0) embeddings[i] = hit;
|
|
2475
|
+
else if (chunk) missing.push({
|
|
2476
|
+
index: i,
|
|
2477
|
+
chunk
|
|
2478
|
+
});
|
|
2479
|
+
}
|
|
2480
|
+
if (missing.length === 0) return embeddings;
|
|
2481
|
+
const missingChunks = missing.map((m) => m.chunk);
|
|
2482
|
+
const batches = this.buildEmbeddingBatches(missingChunks);
|
|
2483
|
+
const toCache = [];
|
|
2484
|
+
let cursor = 0;
|
|
2485
|
+
for (const batch of batches) {
|
|
2486
|
+
const batchEmbeddings = await this.embedBatchWithRetry(batch.map((chunk) => chunk.text));
|
|
2487
|
+
for (let i = 0; i < batch.length; i += 1) {
|
|
2488
|
+
const item = missing[cursor + i];
|
|
2489
|
+
const embedding = batchEmbeddings[i] ?? [];
|
|
2490
|
+
if (item) {
|
|
2491
|
+
embeddings[item.index] = embedding;
|
|
2492
|
+
toCache.push({
|
|
2493
|
+
hash: item.chunk.hash,
|
|
2494
|
+
embedding
|
|
2495
|
+
});
|
|
2496
|
+
}
|
|
2497
|
+
}
|
|
2498
|
+
cursor += batch.length;
|
|
2499
|
+
}
|
|
2500
|
+
this.upsertEmbeddingCache(toCache);
|
|
2501
|
+
return embeddings;
|
|
2502
|
+
}
|
|
2503
|
+
computeProviderKey() {
|
|
2504
|
+
if (this.provider.id === "openai" && this.openAi) {
|
|
2505
|
+
const entries = Object.entries(this.openAi.headers).filter(([key]) => key.toLowerCase() !== "authorization").toSorted(([a], [b]) => a.localeCompare(b)).map(([key, value]) => [key, value]);
|
|
2506
|
+
return hashText(JSON.stringify({
|
|
2507
|
+
provider: "openai",
|
|
2508
|
+
baseUrl: this.openAi.baseUrl,
|
|
2509
|
+
model: this.openAi.model,
|
|
2510
|
+
headers: entries
|
|
2511
|
+
}));
|
|
2512
|
+
}
|
|
2513
|
+
if (this.provider.id === "gemini" && this.gemini) {
|
|
2514
|
+
const entries = Object.entries(this.gemini.headers).filter(([key]) => {
|
|
2515
|
+
const lower = key.toLowerCase();
|
|
2516
|
+
return lower !== "authorization" && lower !== "x-goog-api-key";
|
|
2517
|
+
}).toSorted(([a], [b]) => a.localeCompare(b)).map(([key, value]) => [key, value]);
|
|
2518
|
+
return hashText(JSON.stringify({
|
|
2519
|
+
provider: "gemini",
|
|
2520
|
+
baseUrl: this.gemini.baseUrl,
|
|
2521
|
+
model: this.gemini.model,
|
|
2522
|
+
headers: entries
|
|
2523
|
+
}));
|
|
2524
|
+
}
|
|
2525
|
+
return hashText(JSON.stringify({
|
|
2526
|
+
provider: this.provider.id,
|
|
2527
|
+
model: this.provider.model
|
|
2528
|
+
}));
|
|
2529
|
+
}
|
|
2530
|
+
async embedChunksWithBatch(chunks, entry, source) {
|
|
2531
|
+
if (this.provider.id === "openai" && this.openAi) return this.embedChunksWithOpenAiBatch(chunks, entry, source);
|
|
2532
|
+
if (this.provider.id === "gemini" && this.gemini) return this.embedChunksWithGeminiBatch(chunks, entry, source);
|
|
2533
|
+
return this.embedChunksInBatches(chunks);
|
|
2534
|
+
}
|
|
2535
|
+
async embedChunksWithOpenAiBatch(chunks, entry, source) {
|
|
2536
|
+
const openAi = this.openAi;
|
|
2537
|
+
if (!openAi) return this.embedChunksInBatches(chunks);
|
|
2538
|
+
if (chunks.length === 0) return [];
|
|
2539
|
+
const cached = this.loadEmbeddingCache(chunks.map((chunk) => chunk.hash));
|
|
2540
|
+
const embeddings = Array.from({ length: chunks.length }, () => []);
|
|
2541
|
+
const missing = [];
|
|
2542
|
+
for (let i = 0; i < chunks.length; i += 1) {
|
|
2543
|
+
const chunk = chunks[i];
|
|
2544
|
+
const hit = chunk?.hash ? cached.get(chunk.hash) : void 0;
|
|
2545
|
+
if (hit && hit.length > 0) embeddings[i] = hit;
|
|
2546
|
+
else if (chunk) missing.push({
|
|
2547
|
+
index: i,
|
|
2548
|
+
chunk
|
|
2549
|
+
});
|
|
2550
|
+
}
|
|
2551
|
+
if (missing.length === 0) return embeddings;
|
|
2552
|
+
const requests = [];
|
|
2553
|
+
const mapping = /* @__PURE__ */ new Map();
|
|
2554
|
+
for (const item of missing) {
|
|
2555
|
+
const chunk = item.chunk;
|
|
2556
|
+
const customId = hashText(`${source}:${entry.path}:${chunk.startLine}:${chunk.endLine}:${chunk.hash}:${item.index}`);
|
|
2557
|
+
mapping.set(customId, {
|
|
2558
|
+
index: item.index,
|
|
2559
|
+
hash: chunk.hash
|
|
2560
|
+
});
|
|
2561
|
+
requests.push({
|
|
2562
|
+
custom_id: customId,
|
|
2563
|
+
method: "POST",
|
|
2564
|
+
url: OPENAI_BATCH_ENDPOINT,
|
|
2565
|
+
body: {
|
|
2566
|
+
model: this.openAi?.model ?? this.provider.model,
|
|
2567
|
+
input: chunk.text
|
|
2568
|
+
}
|
|
2569
|
+
});
|
|
2570
|
+
}
|
|
2571
|
+
const batchResult = await this.runBatchWithFallback({
|
|
2572
|
+
provider: "openai",
|
|
2573
|
+
run: async () => await runOpenAiEmbeddingBatches({
|
|
2574
|
+
openAi,
|
|
2575
|
+
agentId: this.agentId,
|
|
2576
|
+
requests,
|
|
2577
|
+
wait: this.batch.wait,
|
|
2578
|
+
concurrency: this.batch.concurrency,
|
|
2579
|
+
pollIntervalMs: this.batch.pollIntervalMs,
|
|
2580
|
+
timeoutMs: this.batch.timeoutMs,
|
|
2581
|
+
debug: (message, data) => log.debug(message, {
|
|
2582
|
+
...data,
|
|
2583
|
+
source,
|
|
2584
|
+
chunks: chunks.length
|
|
2585
|
+
})
|
|
2586
|
+
}),
|
|
2587
|
+
fallback: async () => await this.embedChunksInBatches(chunks)
|
|
2588
|
+
});
|
|
2589
|
+
if (Array.isArray(batchResult)) return batchResult;
|
|
2590
|
+
const byCustomId = batchResult;
|
|
2591
|
+
const toCache = [];
|
|
2592
|
+
for (const [customId, embedding] of byCustomId.entries()) {
|
|
2593
|
+
const mapped = mapping.get(customId);
|
|
2594
|
+
if (!mapped) continue;
|
|
2595
|
+
embeddings[mapped.index] = embedding;
|
|
2596
|
+
toCache.push({
|
|
2597
|
+
hash: mapped.hash,
|
|
2598
|
+
embedding
|
|
2599
|
+
});
|
|
2600
|
+
}
|
|
2601
|
+
this.upsertEmbeddingCache(toCache);
|
|
2602
|
+
return embeddings;
|
|
2603
|
+
}
|
|
2604
|
+
async embedChunksWithGeminiBatch(chunks, entry, source) {
|
|
2605
|
+
const gemini = this.gemini;
|
|
2606
|
+
if (!gemini) return this.embedChunksInBatches(chunks);
|
|
2607
|
+
if (chunks.length === 0) return [];
|
|
2608
|
+
const cached = this.loadEmbeddingCache(chunks.map((chunk) => chunk.hash));
|
|
2609
|
+
const embeddings = Array.from({ length: chunks.length }, () => []);
|
|
2610
|
+
const missing = [];
|
|
2611
|
+
for (let i = 0; i < chunks.length; i += 1) {
|
|
2612
|
+
const chunk = chunks[i];
|
|
2613
|
+
const hit = chunk?.hash ? cached.get(chunk.hash) : void 0;
|
|
2614
|
+
if (hit && hit.length > 0) embeddings[i] = hit;
|
|
2615
|
+
else if (chunk) missing.push({
|
|
2616
|
+
index: i,
|
|
2617
|
+
chunk
|
|
2618
|
+
});
|
|
2619
|
+
}
|
|
2620
|
+
if (missing.length === 0) return embeddings;
|
|
2621
|
+
const requests = [];
|
|
2622
|
+
const mapping = /* @__PURE__ */ new Map();
|
|
2623
|
+
for (const item of missing) {
|
|
2624
|
+
const chunk = item.chunk;
|
|
2625
|
+
const customId = hashText(`${source}:${entry.path}:${chunk.startLine}:${chunk.endLine}:${chunk.hash}:${item.index}`);
|
|
2626
|
+
mapping.set(customId, {
|
|
2627
|
+
index: item.index,
|
|
2628
|
+
hash: chunk.hash
|
|
2629
|
+
});
|
|
2630
|
+
requests.push({
|
|
2631
|
+
custom_id: customId,
|
|
2632
|
+
content: { parts: [{ text: chunk.text }] },
|
|
2633
|
+
taskType: "RETRIEVAL_DOCUMENT"
|
|
2634
|
+
});
|
|
2635
|
+
}
|
|
2636
|
+
const batchResult = await this.runBatchWithFallback({
|
|
2637
|
+
provider: "gemini",
|
|
2638
|
+
run: async () => await runGeminiEmbeddingBatches({
|
|
2639
|
+
gemini,
|
|
2640
|
+
agentId: this.agentId,
|
|
2641
|
+
requests,
|
|
2642
|
+
wait: this.batch.wait,
|
|
2643
|
+
concurrency: this.batch.concurrency,
|
|
2644
|
+
pollIntervalMs: this.batch.pollIntervalMs,
|
|
2645
|
+
timeoutMs: this.batch.timeoutMs,
|
|
2646
|
+
debug: (message, data) => log.debug(message, {
|
|
2647
|
+
...data,
|
|
2648
|
+
source,
|
|
2649
|
+
chunks: chunks.length
|
|
2650
|
+
})
|
|
2651
|
+
}),
|
|
2652
|
+
fallback: async () => await this.embedChunksInBatches(chunks)
|
|
2653
|
+
});
|
|
2654
|
+
if (Array.isArray(batchResult)) return batchResult;
|
|
2655
|
+
const byCustomId = batchResult;
|
|
2656
|
+
const toCache = [];
|
|
2657
|
+
for (const [customId, embedding] of byCustomId.entries()) {
|
|
2658
|
+
const mapped = mapping.get(customId);
|
|
2659
|
+
if (!mapped) continue;
|
|
2660
|
+
embeddings[mapped.index] = embedding;
|
|
2661
|
+
toCache.push({
|
|
2662
|
+
hash: mapped.hash,
|
|
2663
|
+
embedding
|
|
2664
|
+
});
|
|
2665
|
+
}
|
|
2666
|
+
this.upsertEmbeddingCache(toCache);
|
|
2667
|
+
return embeddings;
|
|
2668
|
+
}
|
|
2669
|
+
async embedBatchWithRetry(texts) {
|
|
2670
|
+
if (texts.length === 0) return [];
|
|
2671
|
+
let attempt = 0;
|
|
2672
|
+
let delayMs = EMBEDDING_RETRY_BASE_DELAY_MS;
|
|
2673
|
+
while (true) try {
|
|
2674
|
+
const timeoutMs = this.resolveEmbeddingTimeout("batch");
|
|
2675
|
+
log.debug("memory embeddings: batch start", {
|
|
2676
|
+
provider: this.provider.id,
|
|
2677
|
+
items: texts.length,
|
|
2678
|
+
timeoutMs
|
|
2679
|
+
});
|
|
2680
|
+
return await this.withTimeout(this.provider.embedBatch(texts), timeoutMs, `memory embeddings batch timed out after ${Math.round(timeoutMs / 1e3)}s`);
|
|
2681
|
+
} catch (err) {
|
|
2682
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
2683
|
+
if (!this.isRetryableEmbeddingError(message) || attempt >= EMBEDDING_RETRY_MAX_ATTEMPTS) throw err;
|
|
2684
|
+
const waitMs = Math.min(EMBEDDING_RETRY_MAX_DELAY_MS, Math.round(delayMs * (1 + Math.random() * .2)));
|
|
2685
|
+
log.warn(`memory embeddings rate limited; retrying in ${waitMs}ms`);
|
|
2686
|
+
await new Promise((resolve) => setTimeout(resolve, waitMs));
|
|
2687
|
+
delayMs *= 2;
|
|
2688
|
+
attempt += 1;
|
|
2689
|
+
}
|
|
2690
|
+
}
|
|
2691
|
+
isRetryableEmbeddingError(message) {
|
|
2692
|
+
return /(rate[_ ]limit|too many requests|429|resource has been exhausted|5\d\d|cloudflare)/i.test(message);
|
|
2693
|
+
}
|
|
2694
|
+
resolveEmbeddingTimeout(kind) {
|
|
2695
|
+
const isLocal = this.provider.id === "local";
|
|
2696
|
+
if (kind === "query") return isLocal ? EMBEDDING_QUERY_TIMEOUT_LOCAL_MS : EMBEDDING_QUERY_TIMEOUT_REMOTE_MS;
|
|
2697
|
+
return isLocal ? EMBEDDING_BATCH_TIMEOUT_LOCAL_MS : EMBEDDING_BATCH_TIMEOUT_REMOTE_MS;
|
|
2698
|
+
}
|
|
2699
|
+
async embedQueryWithTimeout(text) {
|
|
2700
|
+
const timeoutMs = this.resolveEmbeddingTimeout("query");
|
|
2701
|
+
log.debug("memory embeddings: query start", {
|
|
2702
|
+
provider: this.provider.id,
|
|
2703
|
+
timeoutMs
|
|
2704
|
+
});
|
|
2705
|
+
return await this.withTimeout(this.provider.embedQuery(text), timeoutMs, `memory embeddings query timed out after ${Math.round(timeoutMs / 1e3)}s`);
|
|
2706
|
+
}
|
|
2707
|
+
async withTimeout(promise, timeoutMs, message) {
|
|
2708
|
+
if (!Number.isFinite(timeoutMs) || timeoutMs <= 0) return await promise;
|
|
2709
|
+
let timer = null;
|
|
2710
|
+
const timeoutPromise = new Promise((_, reject) => {
|
|
2711
|
+
timer = setTimeout(() => reject(new Error(message)), timeoutMs);
|
|
2712
|
+
});
|
|
2713
|
+
try {
|
|
2714
|
+
return await Promise.race([promise, timeoutPromise]);
|
|
2715
|
+
} finally {
|
|
2716
|
+
if (timer) clearTimeout(timer);
|
|
2717
|
+
}
|
|
2718
|
+
}
|
|
2719
|
+
async runWithConcurrency(tasks, limit) {
|
|
2720
|
+
if (tasks.length === 0) return [];
|
|
2721
|
+
const resolvedLimit = Math.max(1, Math.min(limit, tasks.length));
|
|
2722
|
+
const results = Array.from({ length: tasks.length });
|
|
2723
|
+
let next = 0;
|
|
2724
|
+
let firstError = null;
|
|
2725
|
+
const workers = Array.from({ length: resolvedLimit }, async () => {
|
|
2726
|
+
while (true) {
|
|
2727
|
+
if (firstError) return;
|
|
2728
|
+
const index = next;
|
|
2729
|
+
next += 1;
|
|
2730
|
+
if (index >= tasks.length) return;
|
|
2731
|
+
try {
|
|
2732
|
+
results[index] = await tasks[index]();
|
|
2733
|
+
} catch (err) {
|
|
2734
|
+
firstError = err;
|
|
2735
|
+
return;
|
|
2736
|
+
}
|
|
2737
|
+
}
|
|
2738
|
+
});
|
|
2739
|
+
await Promise.allSettled(workers);
|
|
2740
|
+
if (firstError) throw firstError;
|
|
2741
|
+
return results;
|
|
2742
|
+
}
|
|
2743
|
+
async withBatchFailureLock(fn) {
|
|
2744
|
+
let release;
|
|
2745
|
+
const wait = this.batchFailureLock;
|
|
2746
|
+
this.batchFailureLock = new Promise((resolve) => {
|
|
2747
|
+
release = resolve;
|
|
2748
|
+
});
|
|
2749
|
+
await wait;
|
|
2750
|
+
try {
|
|
2751
|
+
return await fn();
|
|
2752
|
+
} finally {
|
|
2753
|
+
release();
|
|
2754
|
+
}
|
|
2755
|
+
}
|
|
2756
|
+
async resetBatchFailureCount() {
|
|
2757
|
+
await this.withBatchFailureLock(async () => {
|
|
2758
|
+
if (this.batchFailureCount > 0) log.debug("memory embeddings: batch recovered; resetting failure count");
|
|
2759
|
+
this.batchFailureCount = 0;
|
|
2760
|
+
this.batchFailureLastError = void 0;
|
|
2761
|
+
this.batchFailureLastProvider = void 0;
|
|
2762
|
+
});
|
|
2763
|
+
}
|
|
2764
|
+
async recordBatchFailure(params) {
|
|
2765
|
+
return await this.withBatchFailureLock(async () => {
|
|
2766
|
+
if (!this.batch.enabled) return {
|
|
2767
|
+
disabled: true,
|
|
2768
|
+
count: this.batchFailureCount
|
|
2769
|
+
};
|
|
2770
|
+
const increment = params.forceDisable ? BATCH_FAILURE_LIMIT : Math.max(1, params.attempts ?? 1);
|
|
2771
|
+
this.batchFailureCount += increment;
|
|
2772
|
+
this.batchFailureLastError = params.message;
|
|
2773
|
+
this.batchFailureLastProvider = params.provider;
|
|
2774
|
+
const disabled = params.forceDisable || this.batchFailureCount >= BATCH_FAILURE_LIMIT;
|
|
2775
|
+
if (disabled) this.batch.enabled = false;
|
|
2776
|
+
return {
|
|
2777
|
+
disabled,
|
|
2778
|
+
count: this.batchFailureCount
|
|
2779
|
+
};
|
|
2780
|
+
});
|
|
2781
|
+
}
|
|
2782
|
+
isBatchTimeoutError(message) {
|
|
2783
|
+
return /timed out|timeout/i.test(message);
|
|
2784
|
+
}
|
|
2785
|
+
async runBatchWithTimeoutRetry(params) {
|
|
2786
|
+
try {
|
|
2787
|
+
return await params.run();
|
|
2788
|
+
} catch (err) {
|
|
2789
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
2790
|
+
if (this.isBatchTimeoutError(message)) {
|
|
2791
|
+
log.warn(`memory embeddings: ${params.provider} batch timed out; retrying once`);
|
|
2792
|
+
try {
|
|
2793
|
+
return await params.run();
|
|
2794
|
+
} catch (retryErr) {
|
|
2795
|
+
retryErr.batchAttempts = 2;
|
|
2796
|
+
throw retryErr;
|
|
2797
|
+
}
|
|
2798
|
+
}
|
|
2799
|
+
throw err;
|
|
2800
|
+
}
|
|
2801
|
+
}
|
|
2802
|
+
async runBatchWithFallback(params) {
|
|
2803
|
+
if (!this.batch.enabled) return await params.fallback();
|
|
2804
|
+
try {
|
|
2805
|
+
const result = await this.runBatchWithTimeoutRetry({
|
|
2806
|
+
provider: params.provider,
|
|
2807
|
+
run: params.run
|
|
2808
|
+
});
|
|
2809
|
+
await this.resetBatchFailureCount();
|
|
2810
|
+
return result;
|
|
2811
|
+
} catch (err) {
|
|
2812
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
2813
|
+
const attempts = err.batchAttempts ?? 1;
|
|
2814
|
+
const forceDisable = /asyncBatchEmbedContent not available/i.test(message);
|
|
2815
|
+
const failure = await this.recordBatchFailure({
|
|
2816
|
+
provider: params.provider,
|
|
2817
|
+
message,
|
|
2818
|
+
attempts,
|
|
2819
|
+
forceDisable
|
|
2820
|
+
});
|
|
2821
|
+
const suffix = failure.disabled ? "disabling batch" : "keeping batch enabled";
|
|
2822
|
+
log.warn(`memory embeddings: ${params.provider} batch failed (${failure.count}/${BATCH_FAILURE_LIMIT}); ${suffix}; falling back to non-batch embeddings: ${message}`);
|
|
2823
|
+
return await params.fallback();
|
|
2824
|
+
}
|
|
2825
|
+
}
|
|
2826
|
+
getIndexConcurrency() {
|
|
2827
|
+
return this.batch.enabled ? this.batch.concurrency : EMBEDDING_INDEX_CONCURRENCY;
|
|
2828
|
+
}
|
|
2829
|
+
async indexFile(entry, options) {
|
|
2830
|
+
const chunks = chunkMarkdown(options.content ?? await fs$1.readFile(entry.absPath, "utf-8"), this.settings.chunking).filter((chunk) => chunk.text.trim().length > 0);
|
|
2831
|
+
const embeddings = this.batch.enabled ? await this.embedChunksWithBatch(chunks, entry, options.source) : await this.embedChunksInBatches(chunks);
|
|
2832
|
+
const sample = embeddings.find((embedding) => embedding.length > 0);
|
|
2833
|
+
const vectorReady = sample ? await this.ensureVectorReady(sample.length) : false;
|
|
2834
|
+
const now = Date.now();
|
|
2835
|
+
if (vectorReady) try {
|
|
2836
|
+
this.db.prepare(`DELETE FROM ${VECTOR_TABLE} WHERE id IN (SELECT id FROM chunks WHERE path = ? AND source = ?)`).run(entry.path, options.source);
|
|
2837
|
+
} catch {}
|
|
2838
|
+
if (this.fts.enabled && this.fts.available) try {
|
|
2839
|
+
this.db.prepare(`DELETE FROM ${FTS_TABLE} WHERE path = ? AND source = ? AND model = ?`).run(entry.path, options.source, this.provider.model);
|
|
2840
|
+
} catch {}
|
|
2841
|
+
this.db.prepare(`DELETE FROM chunks WHERE path = ? AND source = ?`).run(entry.path, options.source);
|
|
2842
|
+
for (let i = 0; i < chunks.length; i++) {
|
|
2843
|
+
const chunk = chunks[i];
|
|
2844
|
+
const embedding = embeddings[i] ?? [];
|
|
2845
|
+
const id = hashText(`${options.source}:${entry.path}:${chunk.startLine}:${chunk.endLine}:${chunk.hash}:${this.provider.model}`);
|
|
2846
|
+
this.db.prepare(`INSERT INTO chunks (id, path, source, start_line, end_line, hash, model, text, embedding, updated_at)
|
|
2847
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
2848
|
+
ON CONFLICT(id) DO UPDATE SET
|
|
2849
|
+
hash=excluded.hash,
|
|
2850
|
+
model=excluded.model,
|
|
2851
|
+
text=excluded.text,
|
|
2852
|
+
embedding=excluded.embedding,
|
|
2853
|
+
updated_at=excluded.updated_at`).run(id, entry.path, options.source, chunk.startLine, chunk.endLine, chunk.hash, this.provider.model, chunk.text, JSON.stringify(embedding), now);
|
|
2854
|
+
if (vectorReady && embedding.length > 0) {
|
|
2855
|
+
try {
|
|
2856
|
+
this.db.prepare(`DELETE FROM ${VECTOR_TABLE} WHERE id = ?`).run(id);
|
|
2857
|
+
} catch {}
|
|
2858
|
+
this.db.prepare(`INSERT INTO ${VECTOR_TABLE} (id, embedding) VALUES (?, ?)`).run(id, vectorToBlob(embedding));
|
|
2859
|
+
}
|
|
2860
|
+
if (this.fts.enabled && this.fts.available) this.db.prepare(`INSERT INTO ${FTS_TABLE} (text, id, path, source, model, start_line, end_line)\n VALUES (?, ?, ?, ?, ?, ?, ?)`).run(chunk.text, id, entry.path, options.source, this.provider.model, chunk.startLine, chunk.endLine);
|
|
2861
|
+
}
|
|
2862
|
+
this.db.prepare(`INSERT INTO files (path, source, hash, mtime, size) VALUES (?, ?, ?, ?, ?)
|
|
2863
|
+
ON CONFLICT(path) DO UPDATE SET
|
|
2864
|
+
source=excluded.source,
|
|
2865
|
+
hash=excluded.hash,
|
|
2866
|
+
mtime=excluded.mtime,
|
|
2867
|
+
size=excluded.size`).run(entry.path, options.source, entry.hash, entry.mtimeMs, entry.size);
|
|
2868
|
+
}
|
|
2869
|
+
};
|
|
2870
|
+
|
|
2871
|
+
//#endregion
|
|
2872
|
+
export { resolveMemorySearchConfig as i, resolveRetryConfig as n, retryAsync as r, manager_exports as t };
|