@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,2557 @@
|
|
|
1
|
+
import { t as __exportAll } from "./rolldown-runtime-Cbj13DAv.js";
|
|
2
|
+
import { A as normalizeAccountId$1 } from "./agent-scope-Csu2B6AM.js";
|
|
3
|
+
import { H as logVerbose, N as resolveUserPath, W as shouldLogVerbose, b as getActivePluginRegistry } from "./exec-BMnoMcZW.js";
|
|
4
|
+
import { At as resizeToJpeg, Cn as mediaKindFromMime, En as getChannelPlugin, Et as convertHeicToJpeg, Ft as createPinnedDispatcher, It as resolvePinnedHostname, Lt as resolvePinnedHostnameWithPolicy, Mt as saveMediaBuffer, On as normalizeChannelId, Ot as hasAlphaChannel, Pt as closeDispatcher, Sn as maxBytesForKind, Tn as resolveSignalAccount, U as appendAssistantMessageToSessionTranscript, W as resolveMirroredTranscriptText, hn as extensionForMime, kt as optimizeImageToPng, m as isMessagingToolDuplicate, mn as detectMime, mt as getChannelDock, rn as INTERNAL_MESSAGE_CHANNEL } from "./pi-embedded-helpers-C19wUpMB.js";
|
|
5
|
+
import { t as loadConfig } from "./config-_d7_WcRv.js";
|
|
6
|
+
import path from "node:path";
|
|
7
|
+
import fs from "node:fs/promises";
|
|
8
|
+
import { fileURLToPath } from "node:url";
|
|
9
|
+
import { randomUUID } from "node:crypto";
|
|
10
|
+
import MarkdownIt from "markdown-it";
|
|
11
|
+
|
|
12
|
+
//#region src/auto-reply/tokens.ts
|
|
13
|
+
const HEARTBEAT_TOKEN = "HEARTBEAT_OK";
|
|
14
|
+
const SILENT_REPLY_TOKEN = "NO_REPLY";
|
|
15
|
+
function escapeRegExp(value) {
|
|
16
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
17
|
+
}
|
|
18
|
+
function isSilentReplyText(text, token = SILENT_REPLY_TOKEN) {
|
|
19
|
+
if (!text) return false;
|
|
20
|
+
const escaped = escapeRegExp(token);
|
|
21
|
+
if (new RegExp(`^\\s*${escaped}(?=$|\\W)`).test(text)) return true;
|
|
22
|
+
return new RegExp(`\\b${escaped}\\b\\W*$`).test(text);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
//#endregion
|
|
26
|
+
//#region src/markdown/fences.ts
|
|
27
|
+
function parseFenceSpans(buffer) {
|
|
28
|
+
const spans = [];
|
|
29
|
+
let open;
|
|
30
|
+
let offset = 0;
|
|
31
|
+
while (offset <= buffer.length) {
|
|
32
|
+
const nextNewline = buffer.indexOf("\n", offset);
|
|
33
|
+
const lineEnd = nextNewline === -1 ? buffer.length : nextNewline;
|
|
34
|
+
const line = buffer.slice(offset, lineEnd);
|
|
35
|
+
const match = line.match(/^( {0,3})(`{3,}|~{3,})(.*)$/);
|
|
36
|
+
if (match) {
|
|
37
|
+
const indent = match[1];
|
|
38
|
+
const marker = match[2];
|
|
39
|
+
const markerChar = marker[0];
|
|
40
|
+
const markerLen = marker.length;
|
|
41
|
+
if (!open) open = {
|
|
42
|
+
start: offset,
|
|
43
|
+
markerChar,
|
|
44
|
+
markerLen,
|
|
45
|
+
openLine: line,
|
|
46
|
+
marker,
|
|
47
|
+
indent
|
|
48
|
+
};
|
|
49
|
+
else if (open.markerChar === markerChar && markerLen >= open.markerLen) {
|
|
50
|
+
const end = lineEnd;
|
|
51
|
+
spans.push({
|
|
52
|
+
start: open.start,
|
|
53
|
+
end,
|
|
54
|
+
openLine: open.openLine,
|
|
55
|
+
marker: open.marker,
|
|
56
|
+
indent: open.indent
|
|
57
|
+
});
|
|
58
|
+
open = void 0;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
if (nextNewline === -1) break;
|
|
62
|
+
offset = nextNewline + 1;
|
|
63
|
+
}
|
|
64
|
+
if (open) spans.push({
|
|
65
|
+
start: open.start,
|
|
66
|
+
end: buffer.length,
|
|
67
|
+
openLine: open.openLine,
|
|
68
|
+
marker: open.marker,
|
|
69
|
+
indent: open.indent
|
|
70
|
+
});
|
|
71
|
+
return spans;
|
|
72
|
+
}
|
|
73
|
+
function findFenceSpanAt(spans, index) {
|
|
74
|
+
return spans.find((span) => index > span.start && index < span.end);
|
|
75
|
+
}
|
|
76
|
+
function isSafeFenceBreak(spans, index) {
|
|
77
|
+
return !findFenceSpanAt(spans, index);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
//#endregion
|
|
81
|
+
//#region src/auto-reply/chunk.ts
|
|
82
|
+
const DEFAULT_CHUNK_LIMIT = 4e3;
|
|
83
|
+
const DEFAULT_CHUNK_MODE = "length";
|
|
84
|
+
function resolveChunkLimitForProvider(cfgSection, accountId) {
|
|
85
|
+
if (!cfgSection) return;
|
|
86
|
+
const normalizedAccountId = normalizeAccountId$1(accountId);
|
|
87
|
+
const accounts = cfgSection.accounts;
|
|
88
|
+
if (accounts && typeof accounts === "object") {
|
|
89
|
+
const direct = accounts[normalizedAccountId];
|
|
90
|
+
if (typeof direct?.textChunkLimit === "number") return direct.textChunkLimit;
|
|
91
|
+
const matchKey = Object.keys(accounts).find((key) => key.toLowerCase() === normalizedAccountId.toLowerCase());
|
|
92
|
+
const match = matchKey ? accounts[matchKey] : void 0;
|
|
93
|
+
if (typeof match?.textChunkLimit === "number") return match.textChunkLimit;
|
|
94
|
+
}
|
|
95
|
+
return cfgSection.textChunkLimit;
|
|
96
|
+
}
|
|
97
|
+
function resolveTextChunkLimit(cfg, provider, accountId, opts) {
|
|
98
|
+
const fallback = typeof opts?.fallbackLimit === "number" && opts.fallbackLimit > 0 ? opts.fallbackLimit : DEFAULT_CHUNK_LIMIT;
|
|
99
|
+
const providerOverride = (() => {
|
|
100
|
+
if (!provider || provider === INTERNAL_MESSAGE_CHANNEL) return;
|
|
101
|
+
return resolveChunkLimitForProvider((cfg?.channels)?.[provider] ?? cfg?.[provider], accountId);
|
|
102
|
+
})();
|
|
103
|
+
if (typeof providerOverride === "number" && providerOverride > 0) return providerOverride;
|
|
104
|
+
return fallback;
|
|
105
|
+
}
|
|
106
|
+
function resolveChunkModeForProvider(cfgSection, accountId) {
|
|
107
|
+
if (!cfgSection) return;
|
|
108
|
+
const normalizedAccountId = normalizeAccountId$1(accountId);
|
|
109
|
+
const accounts = cfgSection.accounts;
|
|
110
|
+
if (accounts && typeof accounts === "object") {
|
|
111
|
+
const direct = accounts[normalizedAccountId];
|
|
112
|
+
if (direct?.chunkMode) return direct.chunkMode;
|
|
113
|
+
const matchKey = Object.keys(accounts).find((key) => key.toLowerCase() === normalizedAccountId.toLowerCase());
|
|
114
|
+
const match = matchKey ? accounts[matchKey] : void 0;
|
|
115
|
+
if (match?.chunkMode) return match.chunkMode;
|
|
116
|
+
}
|
|
117
|
+
return cfgSection.chunkMode;
|
|
118
|
+
}
|
|
119
|
+
function resolveChunkMode(cfg, provider, accountId) {
|
|
120
|
+
if (!provider || provider === INTERNAL_MESSAGE_CHANNEL) return DEFAULT_CHUNK_MODE;
|
|
121
|
+
return resolveChunkModeForProvider((cfg?.channels)?.[provider] ?? cfg?.[provider], accountId) ?? DEFAULT_CHUNK_MODE;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Split text on newlines, trimming line whitespace.
|
|
125
|
+
* Blank lines are folded into the next non-empty line as leading "\n" prefixes.
|
|
126
|
+
* Long lines can be split by length (default) or kept intact via splitLongLines:false.
|
|
127
|
+
*/
|
|
128
|
+
function chunkByNewline(text, maxLineLength, opts) {
|
|
129
|
+
if (!text) return [];
|
|
130
|
+
if (maxLineLength <= 0) return text.trim() ? [text] : [];
|
|
131
|
+
const splitLongLines = opts?.splitLongLines !== false;
|
|
132
|
+
const trimLines = opts?.trimLines !== false;
|
|
133
|
+
const lines = splitByNewline(text, opts?.isSafeBreak);
|
|
134
|
+
const chunks = [];
|
|
135
|
+
let pendingBlankLines = 0;
|
|
136
|
+
for (const line of lines) {
|
|
137
|
+
const trimmed = line.trim();
|
|
138
|
+
if (!trimmed) {
|
|
139
|
+
pendingBlankLines += 1;
|
|
140
|
+
continue;
|
|
141
|
+
}
|
|
142
|
+
const maxPrefix = Math.max(0, maxLineLength - 1);
|
|
143
|
+
const cappedBlankLines = pendingBlankLines > 0 ? Math.min(pendingBlankLines, maxPrefix) : 0;
|
|
144
|
+
const prefix = cappedBlankLines > 0 ? "\n".repeat(cappedBlankLines) : "";
|
|
145
|
+
pendingBlankLines = 0;
|
|
146
|
+
const lineValue = trimLines ? trimmed : line;
|
|
147
|
+
if (!splitLongLines || lineValue.length + prefix.length <= maxLineLength) {
|
|
148
|
+
chunks.push(prefix + lineValue);
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
151
|
+
const firstLimit = Math.max(1, maxLineLength - prefix.length);
|
|
152
|
+
const first = lineValue.slice(0, firstLimit);
|
|
153
|
+
chunks.push(prefix + first);
|
|
154
|
+
const remaining = lineValue.slice(firstLimit);
|
|
155
|
+
if (remaining) chunks.push(...chunkText(remaining, maxLineLength));
|
|
156
|
+
}
|
|
157
|
+
if (pendingBlankLines > 0 && chunks.length > 0) chunks[chunks.length - 1] += "\n".repeat(pendingBlankLines);
|
|
158
|
+
return chunks;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Split text into chunks on paragraph boundaries (blank lines), preserving lists and
|
|
162
|
+
* single-newline line wraps inside paragraphs.
|
|
163
|
+
*
|
|
164
|
+
* - Only breaks at paragraph separators ("\n\n" or more, allowing whitespace on blank lines)
|
|
165
|
+
* - Packs multiple paragraphs into a single chunk up to `limit`
|
|
166
|
+
* - Falls back to length-based splitting when a single paragraph exceeds `limit`
|
|
167
|
+
* (unless `splitLongParagraphs` is disabled)
|
|
168
|
+
*/
|
|
169
|
+
function chunkByParagraph(text, limit, opts) {
|
|
170
|
+
if (!text) return [];
|
|
171
|
+
if (limit <= 0) return [text];
|
|
172
|
+
const splitLongParagraphs = opts?.splitLongParagraphs !== false;
|
|
173
|
+
const normalized = text.replace(/\r\n?/g, "\n");
|
|
174
|
+
if (!/\n[\t ]*\n+/.test(normalized)) {
|
|
175
|
+
if (normalized.length <= limit) return [normalized];
|
|
176
|
+
if (!splitLongParagraphs) return [normalized];
|
|
177
|
+
return chunkText(normalized, limit);
|
|
178
|
+
}
|
|
179
|
+
const spans = parseFenceSpans(normalized);
|
|
180
|
+
const parts = [];
|
|
181
|
+
const re = /\n[\t ]*\n+/g;
|
|
182
|
+
let lastIndex = 0;
|
|
183
|
+
for (const match of normalized.matchAll(re)) {
|
|
184
|
+
const idx = match.index ?? 0;
|
|
185
|
+
if (!isSafeFenceBreak(spans, idx)) continue;
|
|
186
|
+
parts.push(normalized.slice(lastIndex, idx));
|
|
187
|
+
lastIndex = idx + match[0].length;
|
|
188
|
+
}
|
|
189
|
+
parts.push(normalized.slice(lastIndex));
|
|
190
|
+
const chunks = [];
|
|
191
|
+
for (const part of parts) {
|
|
192
|
+
const paragraph = part.replace(/\s+$/g, "");
|
|
193
|
+
if (!paragraph.trim()) continue;
|
|
194
|
+
if (paragraph.length <= limit) chunks.push(paragraph);
|
|
195
|
+
else if (!splitLongParagraphs) chunks.push(paragraph);
|
|
196
|
+
else chunks.push(...chunkText(paragraph, limit));
|
|
197
|
+
}
|
|
198
|
+
return chunks;
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Unified chunking function that dispatches based on mode.
|
|
202
|
+
*/
|
|
203
|
+
function chunkTextWithMode(text, limit, mode) {
|
|
204
|
+
if (mode === "newline") return chunkByParagraph(text, limit);
|
|
205
|
+
return chunkText(text, limit);
|
|
206
|
+
}
|
|
207
|
+
function chunkMarkdownTextWithMode(text, limit, mode) {
|
|
208
|
+
if (mode === "newline") {
|
|
209
|
+
const paragraphChunks = chunkByParagraph(text, limit, { splitLongParagraphs: false });
|
|
210
|
+
const out = [];
|
|
211
|
+
for (const chunk of paragraphChunks) {
|
|
212
|
+
const nested = chunkMarkdownText(chunk, limit);
|
|
213
|
+
if (!nested.length && chunk) out.push(chunk);
|
|
214
|
+
else out.push(...nested);
|
|
215
|
+
}
|
|
216
|
+
return out;
|
|
217
|
+
}
|
|
218
|
+
return chunkMarkdownText(text, limit);
|
|
219
|
+
}
|
|
220
|
+
function splitByNewline(text, isSafeBreak = () => true) {
|
|
221
|
+
const lines = [];
|
|
222
|
+
let start = 0;
|
|
223
|
+
for (let i = 0; i < text.length; i++) if (text[i] === "\n" && isSafeBreak(i)) {
|
|
224
|
+
lines.push(text.slice(start, i));
|
|
225
|
+
start = i + 1;
|
|
226
|
+
}
|
|
227
|
+
lines.push(text.slice(start));
|
|
228
|
+
return lines;
|
|
229
|
+
}
|
|
230
|
+
function chunkText(text, limit) {
|
|
231
|
+
if (!text) return [];
|
|
232
|
+
if (limit <= 0) return [text];
|
|
233
|
+
if (text.length <= limit) return [text];
|
|
234
|
+
const chunks = [];
|
|
235
|
+
let remaining = text;
|
|
236
|
+
while (remaining.length > limit) {
|
|
237
|
+
const { lastNewline, lastWhitespace } = scanParenAwareBreakpoints(remaining.slice(0, limit));
|
|
238
|
+
let breakIdx = lastNewline > 0 ? lastNewline : lastWhitespace;
|
|
239
|
+
if (breakIdx <= 0) breakIdx = limit;
|
|
240
|
+
const chunk = remaining.slice(0, breakIdx).trimEnd();
|
|
241
|
+
if (chunk.length > 0) chunks.push(chunk);
|
|
242
|
+
const brokeOnSeparator = breakIdx < remaining.length && /\s/.test(remaining[breakIdx]);
|
|
243
|
+
const nextStart = Math.min(remaining.length, breakIdx + (brokeOnSeparator ? 1 : 0));
|
|
244
|
+
remaining = remaining.slice(nextStart).trimStart();
|
|
245
|
+
}
|
|
246
|
+
if (remaining.length) chunks.push(remaining);
|
|
247
|
+
return chunks;
|
|
248
|
+
}
|
|
249
|
+
function chunkMarkdownText(text, limit) {
|
|
250
|
+
if (!text) return [];
|
|
251
|
+
if (limit <= 0) return [text];
|
|
252
|
+
if (text.length <= limit) return [text];
|
|
253
|
+
const chunks = [];
|
|
254
|
+
let remaining = text;
|
|
255
|
+
while (remaining.length > limit) {
|
|
256
|
+
const spans = parseFenceSpans(remaining);
|
|
257
|
+
const softBreak = pickSafeBreakIndex(remaining.slice(0, limit), spans);
|
|
258
|
+
let breakIdx = softBreak > 0 ? softBreak : limit;
|
|
259
|
+
const initialFence = isSafeFenceBreak(spans, breakIdx) ? void 0 : findFenceSpanAt(spans, breakIdx);
|
|
260
|
+
let fenceToSplit = initialFence;
|
|
261
|
+
if (initialFence) {
|
|
262
|
+
const closeLine = `${initialFence.indent}${initialFence.marker}`;
|
|
263
|
+
const maxIdxIfNeedNewline = limit - (closeLine.length + 1);
|
|
264
|
+
if (maxIdxIfNeedNewline <= 0) {
|
|
265
|
+
fenceToSplit = void 0;
|
|
266
|
+
breakIdx = limit;
|
|
267
|
+
} else {
|
|
268
|
+
const minProgressIdx = Math.min(remaining.length, initialFence.start + initialFence.openLine.length + 2);
|
|
269
|
+
const maxIdxIfAlreadyNewline = limit - closeLine.length;
|
|
270
|
+
let pickedNewline = false;
|
|
271
|
+
let lastNewline = remaining.lastIndexOf("\n", Math.max(0, maxIdxIfAlreadyNewline - 1));
|
|
272
|
+
while (lastNewline !== -1) {
|
|
273
|
+
const candidateBreak = lastNewline + 1;
|
|
274
|
+
if (candidateBreak < minProgressIdx) break;
|
|
275
|
+
const candidateFence = findFenceSpanAt(spans, candidateBreak);
|
|
276
|
+
if (candidateFence && candidateFence.start === initialFence.start) {
|
|
277
|
+
breakIdx = Math.max(1, candidateBreak);
|
|
278
|
+
pickedNewline = true;
|
|
279
|
+
break;
|
|
280
|
+
}
|
|
281
|
+
lastNewline = remaining.lastIndexOf("\n", lastNewline - 1);
|
|
282
|
+
}
|
|
283
|
+
if (!pickedNewline) if (minProgressIdx > maxIdxIfAlreadyNewline) {
|
|
284
|
+
fenceToSplit = void 0;
|
|
285
|
+
breakIdx = limit;
|
|
286
|
+
} else breakIdx = Math.max(minProgressIdx, maxIdxIfNeedNewline);
|
|
287
|
+
}
|
|
288
|
+
const fenceAtBreak = findFenceSpanAt(spans, breakIdx);
|
|
289
|
+
fenceToSplit = fenceAtBreak && fenceAtBreak.start === initialFence.start ? fenceAtBreak : void 0;
|
|
290
|
+
}
|
|
291
|
+
let rawChunk = remaining.slice(0, breakIdx);
|
|
292
|
+
if (!rawChunk) break;
|
|
293
|
+
const brokeOnSeparator = breakIdx < remaining.length && /\s/.test(remaining[breakIdx]);
|
|
294
|
+
const nextStart = Math.min(remaining.length, breakIdx + (brokeOnSeparator ? 1 : 0));
|
|
295
|
+
let next = remaining.slice(nextStart);
|
|
296
|
+
if (fenceToSplit) {
|
|
297
|
+
const closeLine = `${fenceToSplit.indent}${fenceToSplit.marker}`;
|
|
298
|
+
rawChunk = rawChunk.endsWith("\n") ? `${rawChunk}${closeLine}` : `${rawChunk}\n${closeLine}`;
|
|
299
|
+
next = `${fenceToSplit.openLine}\n${next}`;
|
|
300
|
+
} else next = stripLeadingNewlines(next);
|
|
301
|
+
chunks.push(rawChunk);
|
|
302
|
+
remaining = next;
|
|
303
|
+
}
|
|
304
|
+
if (remaining.length) chunks.push(remaining);
|
|
305
|
+
return chunks;
|
|
306
|
+
}
|
|
307
|
+
function stripLeadingNewlines(value) {
|
|
308
|
+
let i = 0;
|
|
309
|
+
while (i < value.length && value[i] === "\n") i++;
|
|
310
|
+
return i > 0 ? value.slice(i) : value;
|
|
311
|
+
}
|
|
312
|
+
function pickSafeBreakIndex(window, spans) {
|
|
313
|
+
const { lastNewline, lastWhitespace } = scanParenAwareBreakpoints(window, (index) => isSafeFenceBreak(spans, index));
|
|
314
|
+
if (lastNewline > 0) return lastNewline;
|
|
315
|
+
if (lastWhitespace > 0) return lastWhitespace;
|
|
316
|
+
return -1;
|
|
317
|
+
}
|
|
318
|
+
function scanParenAwareBreakpoints(window, isAllowed = () => true) {
|
|
319
|
+
let lastNewline = -1;
|
|
320
|
+
let lastWhitespace = -1;
|
|
321
|
+
let depth = 0;
|
|
322
|
+
for (let i = 0; i < window.length; i++) {
|
|
323
|
+
if (!isAllowed(i)) continue;
|
|
324
|
+
const char = window[i];
|
|
325
|
+
if (char === "(") {
|
|
326
|
+
depth += 1;
|
|
327
|
+
continue;
|
|
328
|
+
}
|
|
329
|
+
if (char === ")" && depth > 0) {
|
|
330
|
+
depth -= 1;
|
|
331
|
+
continue;
|
|
332
|
+
}
|
|
333
|
+
if (depth !== 0) continue;
|
|
334
|
+
if (char === "\n") lastNewline = i;
|
|
335
|
+
else if (/\s/.test(char)) lastWhitespace = i;
|
|
336
|
+
}
|
|
337
|
+
return {
|
|
338
|
+
lastNewline,
|
|
339
|
+
lastWhitespace
|
|
340
|
+
};
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
//#endregion
|
|
344
|
+
//#region src/config/markdown-tables.ts
|
|
345
|
+
const DEFAULT_TABLE_MODES = new Map([["signal", "bullets"], ["whatsapp", "bullets"]]);
|
|
346
|
+
const isMarkdownTableMode = (value) => value === "off" || value === "bullets" || value === "code";
|
|
347
|
+
function resolveMarkdownModeFromSection(section, accountId) {
|
|
348
|
+
if (!section) return;
|
|
349
|
+
const normalizedAccountId = normalizeAccountId$1(accountId);
|
|
350
|
+
const accounts = section.accounts;
|
|
351
|
+
if (accounts && typeof accounts === "object") {
|
|
352
|
+
const directMode = accounts[normalizedAccountId]?.markdown?.tables;
|
|
353
|
+
if (isMarkdownTableMode(directMode)) return directMode;
|
|
354
|
+
const matchKey = Object.keys(accounts).find((key) => key.toLowerCase() === normalizedAccountId.toLowerCase());
|
|
355
|
+
const matchMode = (matchKey ? accounts[matchKey] : void 0)?.markdown?.tables;
|
|
356
|
+
if (isMarkdownTableMode(matchMode)) return matchMode;
|
|
357
|
+
}
|
|
358
|
+
const sectionMode = section.markdown?.tables;
|
|
359
|
+
return isMarkdownTableMode(sectionMode) ? sectionMode : void 0;
|
|
360
|
+
}
|
|
361
|
+
function resolveMarkdownTableMode(params) {
|
|
362
|
+
const channel = normalizeChannelId(params.channel);
|
|
363
|
+
const defaultMode = channel ? DEFAULT_TABLE_MODES.get(channel) ?? "code" : "code";
|
|
364
|
+
if (!channel || !params.cfg) return defaultMode;
|
|
365
|
+
return resolveMarkdownModeFromSection(params.cfg.channels?.[channel] ?? params.cfg?.[channel], params.accountId) ?? defaultMode;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
//#endregion
|
|
369
|
+
//#region src/infra/net/fetch-guard.ts
|
|
370
|
+
const DEFAULT_MAX_REDIRECTS = 3;
|
|
371
|
+
function isRedirectStatus(status) {
|
|
372
|
+
return status === 301 || status === 302 || status === 303 || status === 307 || status === 308;
|
|
373
|
+
}
|
|
374
|
+
function buildAbortSignal(params) {
|
|
375
|
+
const { timeoutMs, signal } = params;
|
|
376
|
+
if (!timeoutMs && !signal) return {
|
|
377
|
+
signal: void 0,
|
|
378
|
+
cleanup: () => {}
|
|
379
|
+
};
|
|
380
|
+
if (!timeoutMs) return {
|
|
381
|
+
signal,
|
|
382
|
+
cleanup: () => {}
|
|
383
|
+
};
|
|
384
|
+
const controller = new AbortController();
|
|
385
|
+
const timeoutId = setTimeout(() => controller.abort(), timeoutMs);
|
|
386
|
+
const onAbort = () => controller.abort();
|
|
387
|
+
if (signal) if (signal.aborted) controller.abort();
|
|
388
|
+
else signal.addEventListener("abort", onAbort, { once: true });
|
|
389
|
+
const cleanup = () => {
|
|
390
|
+
clearTimeout(timeoutId);
|
|
391
|
+
if (signal) signal.removeEventListener("abort", onAbort);
|
|
392
|
+
};
|
|
393
|
+
return {
|
|
394
|
+
signal: controller.signal,
|
|
395
|
+
cleanup
|
|
396
|
+
};
|
|
397
|
+
}
|
|
398
|
+
async function fetchWithSsrFGuard(params) {
|
|
399
|
+
const fetcher = params.fetchImpl ?? globalThis.fetch;
|
|
400
|
+
if (!fetcher) throw new Error("fetch is not available");
|
|
401
|
+
const maxRedirects = typeof params.maxRedirects === "number" && Number.isFinite(params.maxRedirects) ? Math.max(0, Math.floor(params.maxRedirects)) : DEFAULT_MAX_REDIRECTS;
|
|
402
|
+
const { signal, cleanup } = buildAbortSignal({
|
|
403
|
+
timeoutMs: params.timeoutMs,
|
|
404
|
+
signal: params.signal
|
|
405
|
+
});
|
|
406
|
+
let released = false;
|
|
407
|
+
const release = async (dispatcher) => {
|
|
408
|
+
if (released) return;
|
|
409
|
+
released = true;
|
|
410
|
+
cleanup();
|
|
411
|
+
await closeDispatcher(dispatcher ?? void 0);
|
|
412
|
+
};
|
|
413
|
+
const visited = /* @__PURE__ */ new Set();
|
|
414
|
+
let currentUrl = params.url;
|
|
415
|
+
let redirectCount = 0;
|
|
416
|
+
while (true) {
|
|
417
|
+
let parsedUrl;
|
|
418
|
+
try {
|
|
419
|
+
parsedUrl = new URL(currentUrl);
|
|
420
|
+
} catch {
|
|
421
|
+
await release();
|
|
422
|
+
throw new Error("Invalid URL: must be http or https");
|
|
423
|
+
}
|
|
424
|
+
if (!["http:", "https:"].includes(parsedUrl.protocol)) {
|
|
425
|
+
await release();
|
|
426
|
+
throw new Error("Invalid URL: must be http or https");
|
|
427
|
+
}
|
|
428
|
+
let dispatcher = null;
|
|
429
|
+
try {
|
|
430
|
+
const pinned = Boolean(params.policy?.allowPrivateNetwork || params.policy?.allowedHostnames?.length) ? await resolvePinnedHostnameWithPolicy(parsedUrl.hostname, {
|
|
431
|
+
lookupFn: params.lookupFn,
|
|
432
|
+
policy: params.policy
|
|
433
|
+
}) : await resolvePinnedHostname(parsedUrl.hostname, params.lookupFn);
|
|
434
|
+
if (params.pinDns !== false) dispatcher = createPinnedDispatcher(pinned);
|
|
435
|
+
const init = {
|
|
436
|
+
...params.init ? { ...params.init } : {},
|
|
437
|
+
redirect: "manual",
|
|
438
|
+
...dispatcher ? { dispatcher } : {},
|
|
439
|
+
...signal ? { signal } : {}
|
|
440
|
+
};
|
|
441
|
+
const response = await fetcher(parsedUrl.toString(), init);
|
|
442
|
+
if (isRedirectStatus(response.status)) {
|
|
443
|
+
const location = response.headers.get("location");
|
|
444
|
+
if (!location) {
|
|
445
|
+
await release(dispatcher);
|
|
446
|
+
throw new Error(`Redirect missing location header (${response.status})`);
|
|
447
|
+
}
|
|
448
|
+
redirectCount += 1;
|
|
449
|
+
if (redirectCount > maxRedirects) {
|
|
450
|
+
await release(dispatcher);
|
|
451
|
+
throw new Error(`Too many redirects (limit: ${maxRedirects})`);
|
|
452
|
+
}
|
|
453
|
+
const nextUrl = new URL(location, parsedUrl).toString();
|
|
454
|
+
if (visited.has(nextUrl)) {
|
|
455
|
+
await release(dispatcher);
|
|
456
|
+
throw new Error("Redirect loop detected");
|
|
457
|
+
}
|
|
458
|
+
visited.add(nextUrl);
|
|
459
|
+
response.body?.cancel();
|
|
460
|
+
await closeDispatcher(dispatcher);
|
|
461
|
+
currentUrl = nextUrl;
|
|
462
|
+
continue;
|
|
463
|
+
}
|
|
464
|
+
return {
|
|
465
|
+
response,
|
|
466
|
+
finalUrl: currentUrl,
|
|
467
|
+
release: async () => release(dispatcher)
|
|
468
|
+
};
|
|
469
|
+
} catch (err) {
|
|
470
|
+
await release(dispatcher);
|
|
471
|
+
throw err;
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
//#endregion
|
|
477
|
+
//#region src/media/fetch.ts
|
|
478
|
+
var MediaFetchError = class extends Error {
|
|
479
|
+
constructor(code, message) {
|
|
480
|
+
super(message);
|
|
481
|
+
this.code = code;
|
|
482
|
+
this.name = "MediaFetchError";
|
|
483
|
+
}
|
|
484
|
+
};
|
|
485
|
+
function stripQuotes(value) {
|
|
486
|
+
return value.replace(/^["']|["']$/g, "");
|
|
487
|
+
}
|
|
488
|
+
function parseContentDispositionFileName(header) {
|
|
489
|
+
if (!header) return;
|
|
490
|
+
const starMatch = /filename\*\s*=\s*([^;]+)/i.exec(header);
|
|
491
|
+
if (starMatch?.[1]) {
|
|
492
|
+
const cleaned = stripQuotes(starMatch[1].trim());
|
|
493
|
+
const encoded = cleaned.split("''").slice(1).join("''") || cleaned;
|
|
494
|
+
try {
|
|
495
|
+
return path.basename(decodeURIComponent(encoded));
|
|
496
|
+
} catch {
|
|
497
|
+
return path.basename(encoded);
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
const match = /filename\s*=\s*([^;]+)/i.exec(header);
|
|
501
|
+
if (match?.[1]) return path.basename(stripQuotes(match[1].trim()));
|
|
502
|
+
}
|
|
503
|
+
async function readErrorBodySnippet(res, maxChars = 200) {
|
|
504
|
+
try {
|
|
505
|
+
const text = await res.text();
|
|
506
|
+
if (!text) return;
|
|
507
|
+
const collapsed = text.replace(/\s+/g, " ").trim();
|
|
508
|
+
if (!collapsed) return;
|
|
509
|
+
if (collapsed.length <= maxChars) return collapsed;
|
|
510
|
+
return `${collapsed.slice(0, maxChars)}…`;
|
|
511
|
+
} catch {
|
|
512
|
+
return;
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
async function fetchRemoteMedia(options) {
|
|
516
|
+
const { url, fetchImpl, filePathHint, maxBytes, maxRedirects, ssrfPolicy, lookupFn } = options;
|
|
517
|
+
let res;
|
|
518
|
+
let finalUrl = url;
|
|
519
|
+
let release = null;
|
|
520
|
+
try {
|
|
521
|
+
const result = await fetchWithSsrFGuard({
|
|
522
|
+
url,
|
|
523
|
+
fetchImpl,
|
|
524
|
+
maxRedirects,
|
|
525
|
+
policy: ssrfPolicy,
|
|
526
|
+
lookupFn
|
|
527
|
+
});
|
|
528
|
+
res = result.response;
|
|
529
|
+
finalUrl = result.finalUrl;
|
|
530
|
+
release = result.release;
|
|
531
|
+
} catch (err) {
|
|
532
|
+
throw new MediaFetchError("fetch_failed", `Failed to fetch media from ${url}: ${String(err)}`);
|
|
533
|
+
}
|
|
534
|
+
try {
|
|
535
|
+
if (!res.ok) {
|
|
536
|
+
const statusText = res.statusText ? ` ${res.statusText}` : "";
|
|
537
|
+
const redirected = finalUrl !== url ? ` (redirected to ${finalUrl})` : "";
|
|
538
|
+
let detail = `HTTP ${res.status}${statusText}`;
|
|
539
|
+
if (!res.body) detail = `HTTP ${res.status}${statusText}; empty response body`;
|
|
540
|
+
else {
|
|
541
|
+
const snippet = await readErrorBodySnippet(res);
|
|
542
|
+
if (snippet) detail += `; body: ${snippet}`;
|
|
543
|
+
}
|
|
544
|
+
throw new MediaFetchError("http_error", `Failed to fetch media from ${url}${redirected}: ${detail}`);
|
|
545
|
+
}
|
|
546
|
+
const contentLength = res.headers.get("content-length");
|
|
547
|
+
if (maxBytes && contentLength) {
|
|
548
|
+
const length = Number(contentLength);
|
|
549
|
+
if (Number.isFinite(length) && length > maxBytes) throw new MediaFetchError("max_bytes", `Failed to fetch media from ${url}: content length ${length} exceeds maxBytes ${maxBytes}`);
|
|
550
|
+
}
|
|
551
|
+
const buffer = maxBytes ? await readResponseWithLimit(res, maxBytes) : Buffer.from(await res.arrayBuffer());
|
|
552
|
+
let fileNameFromUrl;
|
|
553
|
+
try {
|
|
554
|
+
const parsed = new URL(finalUrl);
|
|
555
|
+
fileNameFromUrl = path.basename(parsed.pathname) || void 0;
|
|
556
|
+
} catch {}
|
|
557
|
+
const headerFileName = parseContentDispositionFileName(res.headers.get("content-disposition"));
|
|
558
|
+
let fileName = headerFileName || fileNameFromUrl || (filePathHint ? path.basename(filePathHint) : void 0);
|
|
559
|
+
const filePathForMime = headerFileName && path.extname(headerFileName) ? headerFileName : filePathHint ?? finalUrl;
|
|
560
|
+
const contentType = await detectMime({
|
|
561
|
+
buffer,
|
|
562
|
+
headerMime: res.headers.get("content-type"),
|
|
563
|
+
filePath: filePathForMime
|
|
564
|
+
});
|
|
565
|
+
if (fileName && !path.extname(fileName) && contentType) {
|
|
566
|
+
const ext = extensionForMime(contentType);
|
|
567
|
+
if (ext) fileName = `${fileName}${ext}`;
|
|
568
|
+
}
|
|
569
|
+
return {
|
|
570
|
+
buffer,
|
|
571
|
+
contentType: contentType ?? void 0,
|
|
572
|
+
fileName
|
|
573
|
+
};
|
|
574
|
+
} finally {
|
|
575
|
+
if (release) await release();
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
async function readResponseWithLimit(res, maxBytes) {
|
|
579
|
+
const body = res.body;
|
|
580
|
+
if (!body || typeof body.getReader !== "function") {
|
|
581
|
+
const fallback = Buffer.from(await res.arrayBuffer());
|
|
582
|
+
if (fallback.length > maxBytes) throw new MediaFetchError("max_bytes", `Failed to fetch media from ${res.url || "response"}: payload exceeds maxBytes ${maxBytes}`);
|
|
583
|
+
return fallback;
|
|
584
|
+
}
|
|
585
|
+
const reader = body.getReader();
|
|
586
|
+
const chunks = [];
|
|
587
|
+
let total = 0;
|
|
588
|
+
try {
|
|
589
|
+
while (true) {
|
|
590
|
+
const { done, value } = await reader.read();
|
|
591
|
+
if (done) break;
|
|
592
|
+
if (value?.length) {
|
|
593
|
+
total += value.length;
|
|
594
|
+
if (total > maxBytes) {
|
|
595
|
+
try {
|
|
596
|
+
await reader.cancel();
|
|
597
|
+
} catch {}
|
|
598
|
+
throw new MediaFetchError("max_bytes", `Failed to fetch media from ${res.url || "response"}: payload exceeds maxBytes ${maxBytes}`);
|
|
599
|
+
}
|
|
600
|
+
chunks.push(value);
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
} finally {
|
|
604
|
+
try {
|
|
605
|
+
reader.releaseLock();
|
|
606
|
+
} catch {}
|
|
607
|
+
}
|
|
608
|
+
return Buffer.concat(chunks.map((chunk) => Buffer.from(chunk)), total);
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
//#endregion
|
|
612
|
+
//#region src/web/media.ts
|
|
613
|
+
const HEIC_MIME_RE = /^image\/hei[cf]$/i;
|
|
614
|
+
const HEIC_EXT_RE = /\.(heic|heif)$/i;
|
|
615
|
+
const MB$1 = 1024 * 1024;
|
|
616
|
+
function formatMb(bytes, digits = 2) {
|
|
617
|
+
return (bytes / MB$1).toFixed(digits);
|
|
618
|
+
}
|
|
619
|
+
function formatCapLimit(label, cap, size) {
|
|
620
|
+
return `${label} exceeds ${formatMb(cap, 0)}MB limit (got ${formatMb(size)}MB)`;
|
|
621
|
+
}
|
|
622
|
+
function formatCapReduce(label, cap, size) {
|
|
623
|
+
return `${label} could not be reduced below ${formatMb(cap, 0)}MB (got ${formatMb(size)}MB)`;
|
|
624
|
+
}
|
|
625
|
+
function isHeicSource(opts) {
|
|
626
|
+
if (opts.contentType && HEIC_MIME_RE.test(opts.contentType.trim())) return true;
|
|
627
|
+
if (opts.fileName && HEIC_EXT_RE.test(opts.fileName.trim())) return true;
|
|
628
|
+
return false;
|
|
629
|
+
}
|
|
630
|
+
function toJpegFileName(fileName) {
|
|
631
|
+
if (!fileName) return;
|
|
632
|
+
const trimmed = fileName.trim();
|
|
633
|
+
if (!trimmed) return fileName;
|
|
634
|
+
const parsed = path.parse(trimmed);
|
|
635
|
+
if (!parsed.ext || HEIC_EXT_RE.test(parsed.ext)) return path.format({
|
|
636
|
+
dir: parsed.dir,
|
|
637
|
+
name: parsed.name || trimmed,
|
|
638
|
+
ext: ".jpg"
|
|
639
|
+
});
|
|
640
|
+
return path.format({
|
|
641
|
+
dir: parsed.dir,
|
|
642
|
+
name: parsed.name,
|
|
643
|
+
ext: ".jpg"
|
|
644
|
+
});
|
|
645
|
+
}
|
|
646
|
+
function logOptimizedImage(params) {
|
|
647
|
+
if (!shouldLogVerbose()) return;
|
|
648
|
+
if (params.optimized.optimizedSize >= params.originalSize) return;
|
|
649
|
+
if (params.optimized.format === "png") {
|
|
650
|
+
logVerbose(`Optimized PNG (preserving alpha) from ${formatMb(params.originalSize)}MB to ${formatMb(params.optimized.optimizedSize)}MB (side≤${params.optimized.resizeSide}px)`);
|
|
651
|
+
return;
|
|
652
|
+
}
|
|
653
|
+
logVerbose(`Optimized media from ${formatMb(params.originalSize)}MB to ${formatMb(params.optimized.optimizedSize)}MB (side≤${params.optimized.resizeSide}px, q=${params.optimized.quality})`);
|
|
654
|
+
}
|
|
655
|
+
async function optimizeImageWithFallback(params) {
|
|
656
|
+
const { buffer, cap, meta } = params;
|
|
657
|
+
if ((meta?.contentType === "image/png" || meta?.fileName?.toLowerCase().endsWith(".png")) && await hasAlphaChannel(buffer)) {
|
|
658
|
+
const optimized = await optimizeImageToPng(buffer, cap);
|
|
659
|
+
if (optimized.buffer.length <= cap) return {
|
|
660
|
+
...optimized,
|
|
661
|
+
format: "png"
|
|
662
|
+
};
|
|
663
|
+
if (shouldLogVerbose()) logVerbose(`PNG with alpha still exceeds ${formatMb(cap, 0)}MB after optimization; falling back to JPEG`);
|
|
664
|
+
}
|
|
665
|
+
return {
|
|
666
|
+
...await optimizeImageToJpeg(buffer, cap, meta),
|
|
667
|
+
format: "jpeg"
|
|
668
|
+
};
|
|
669
|
+
}
|
|
670
|
+
async function loadWebMediaInternal(mediaUrl, options = {}) {
|
|
671
|
+
const { maxBytes, optimizeImages = true, ssrfPolicy } = options;
|
|
672
|
+
if (mediaUrl.startsWith("file://")) try {
|
|
673
|
+
mediaUrl = fileURLToPath(mediaUrl);
|
|
674
|
+
} catch {
|
|
675
|
+
throw new Error(`Invalid file:// URL: ${mediaUrl}`);
|
|
676
|
+
}
|
|
677
|
+
const optimizeAndClampImage = async (buffer, cap, meta) => {
|
|
678
|
+
const originalSize = buffer.length;
|
|
679
|
+
const optimized = await optimizeImageWithFallback({
|
|
680
|
+
buffer,
|
|
681
|
+
cap,
|
|
682
|
+
meta
|
|
683
|
+
});
|
|
684
|
+
logOptimizedImage({
|
|
685
|
+
originalSize,
|
|
686
|
+
optimized
|
|
687
|
+
});
|
|
688
|
+
if (optimized.buffer.length > cap) throw new Error(formatCapReduce("Media", cap, optimized.buffer.length));
|
|
689
|
+
const contentType = optimized.format === "png" ? "image/png" : "image/jpeg";
|
|
690
|
+
const fileName = optimized.format === "jpeg" && meta && isHeicSource(meta) ? toJpegFileName(meta.fileName) : meta?.fileName;
|
|
691
|
+
return {
|
|
692
|
+
buffer: optimized.buffer,
|
|
693
|
+
contentType,
|
|
694
|
+
kind: "image",
|
|
695
|
+
fileName
|
|
696
|
+
};
|
|
697
|
+
};
|
|
698
|
+
const clampAndFinalize = async (params) => {
|
|
699
|
+
const cap = maxBytes !== void 0 ? maxBytes : maxBytesForKind(params.kind);
|
|
700
|
+
if (params.kind === "image") {
|
|
701
|
+
const isGif = params.contentType === "image/gif";
|
|
702
|
+
if (isGif || !optimizeImages) {
|
|
703
|
+
if (params.buffer.length > cap) throw new Error(formatCapLimit(isGif ? "GIF" : "Media", cap, params.buffer.length));
|
|
704
|
+
return {
|
|
705
|
+
buffer: params.buffer,
|
|
706
|
+
contentType: params.contentType,
|
|
707
|
+
kind: params.kind,
|
|
708
|
+
fileName: params.fileName
|
|
709
|
+
};
|
|
710
|
+
}
|
|
711
|
+
return { ...await optimizeAndClampImage(params.buffer, cap, {
|
|
712
|
+
contentType: params.contentType,
|
|
713
|
+
fileName: params.fileName
|
|
714
|
+
}) };
|
|
715
|
+
}
|
|
716
|
+
if (params.buffer.length > cap) throw new Error(formatCapLimit("Media", cap, params.buffer.length));
|
|
717
|
+
return {
|
|
718
|
+
buffer: params.buffer,
|
|
719
|
+
contentType: params.contentType ?? void 0,
|
|
720
|
+
kind: params.kind,
|
|
721
|
+
fileName: params.fileName
|
|
722
|
+
};
|
|
723
|
+
};
|
|
724
|
+
if (/^https?:\/\//i.test(mediaUrl)) {
|
|
725
|
+
const defaultFetchCap = maxBytesForKind("unknown");
|
|
726
|
+
const { buffer, contentType, fileName } = await fetchRemoteMedia({
|
|
727
|
+
url: mediaUrl,
|
|
728
|
+
maxBytes: maxBytes === void 0 ? defaultFetchCap : optimizeImages ? Math.max(maxBytes, defaultFetchCap) : maxBytes,
|
|
729
|
+
ssrfPolicy
|
|
730
|
+
});
|
|
731
|
+
return await clampAndFinalize({
|
|
732
|
+
buffer,
|
|
733
|
+
contentType,
|
|
734
|
+
kind: mediaKindFromMime(contentType),
|
|
735
|
+
fileName
|
|
736
|
+
});
|
|
737
|
+
}
|
|
738
|
+
if (mediaUrl.startsWith("~")) mediaUrl = resolveUserPath(mediaUrl);
|
|
739
|
+
const data = await fs.readFile(mediaUrl);
|
|
740
|
+
const mime = await detectMime({
|
|
741
|
+
buffer: data,
|
|
742
|
+
filePath: mediaUrl
|
|
743
|
+
});
|
|
744
|
+
const kind = mediaKindFromMime(mime);
|
|
745
|
+
let fileName = path.basename(mediaUrl) || void 0;
|
|
746
|
+
if (fileName && !path.extname(fileName) && mime) {
|
|
747
|
+
const ext = extensionForMime(mime);
|
|
748
|
+
if (ext) fileName = `${fileName}${ext}`;
|
|
749
|
+
}
|
|
750
|
+
return await clampAndFinalize({
|
|
751
|
+
buffer: data,
|
|
752
|
+
contentType: mime,
|
|
753
|
+
kind,
|
|
754
|
+
fileName
|
|
755
|
+
});
|
|
756
|
+
}
|
|
757
|
+
async function loadWebMedia(mediaUrl, maxBytes, options) {
|
|
758
|
+
return await loadWebMediaInternal(mediaUrl, {
|
|
759
|
+
maxBytes,
|
|
760
|
+
optimizeImages: true,
|
|
761
|
+
ssrfPolicy: options?.ssrfPolicy
|
|
762
|
+
});
|
|
763
|
+
}
|
|
764
|
+
async function loadWebMediaRaw(mediaUrl, maxBytes, options) {
|
|
765
|
+
return await loadWebMediaInternal(mediaUrl, {
|
|
766
|
+
maxBytes,
|
|
767
|
+
optimizeImages: false,
|
|
768
|
+
ssrfPolicy: options?.ssrfPolicy
|
|
769
|
+
});
|
|
770
|
+
}
|
|
771
|
+
async function optimizeImageToJpeg(buffer, maxBytes, opts = {}) {
|
|
772
|
+
let source = buffer;
|
|
773
|
+
if (isHeicSource(opts)) try {
|
|
774
|
+
source = await convertHeicToJpeg(buffer);
|
|
775
|
+
} catch (err) {
|
|
776
|
+
throw new Error(`HEIC image conversion failed: ${String(err)}`, { cause: err });
|
|
777
|
+
}
|
|
778
|
+
const sides = [
|
|
779
|
+
2048,
|
|
780
|
+
1536,
|
|
781
|
+
1280,
|
|
782
|
+
1024,
|
|
783
|
+
800
|
|
784
|
+
];
|
|
785
|
+
const qualities = [
|
|
786
|
+
80,
|
|
787
|
+
70,
|
|
788
|
+
60,
|
|
789
|
+
50,
|
|
790
|
+
40
|
|
791
|
+
];
|
|
792
|
+
let smallest = null;
|
|
793
|
+
for (const side of sides) for (const quality of qualities) try {
|
|
794
|
+
const out = await resizeToJpeg({
|
|
795
|
+
buffer: source,
|
|
796
|
+
maxSide: side,
|
|
797
|
+
quality,
|
|
798
|
+
withoutEnlargement: true
|
|
799
|
+
});
|
|
800
|
+
const size = out.length;
|
|
801
|
+
if (!smallest || size < smallest.size) smallest = {
|
|
802
|
+
buffer: out,
|
|
803
|
+
size,
|
|
804
|
+
resizeSide: side,
|
|
805
|
+
quality
|
|
806
|
+
};
|
|
807
|
+
if (size <= maxBytes) return {
|
|
808
|
+
buffer: out,
|
|
809
|
+
optimizedSize: size,
|
|
810
|
+
resizeSide: side,
|
|
811
|
+
quality
|
|
812
|
+
};
|
|
813
|
+
} catch {}
|
|
814
|
+
if (smallest) return {
|
|
815
|
+
buffer: smallest.buffer,
|
|
816
|
+
optimizedSize: smallest.size,
|
|
817
|
+
resizeSide: smallest.resizeSide,
|
|
818
|
+
quality: smallest.quality
|
|
819
|
+
};
|
|
820
|
+
throw new Error("Failed to optimize image");
|
|
821
|
+
}
|
|
822
|
+
|
|
823
|
+
//#endregion
|
|
824
|
+
//#region src/markdown/ir.ts
|
|
825
|
+
function createMarkdownIt(options) {
|
|
826
|
+
const md = new MarkdownIt({
|
|
827
|
+
html: false,
|
|
828
|
+
linkify: options.linkify ?? true,
|
|
829
|
+
breaks: false,
|
|
830
|
+
typographer: false
|
|
831
|
+
});
|
|
832
|
+
md.enable("strikethrough");
|
|
833
|
+
if (options.tableMode && options.tableMode !== "off") md.enable("table");
|
|
834
|
+
else md.disable("table");
|
|
835
|
+
if (options.autolink === false) md.disable("autolink");
|
|
836
|
+
return md;
|
|
837
|
+
}
|
|
838
|
+
function getAttr(token, name) {
|
|
839
|
+
if (token.attrGet) return token.attrGet(name);
|
|
840
|
+
if (token.attrs) {
|
|
841
|
+
for (const [key, value] of token.attrs) if (key === name) return value;
|
|
842
|
+
}
|
|
843
|
+
return null;
|
|
844
|
+
}
|
|
845
|
+
function createTextToken(base, content) {
|
|
846
|
+
return {
|
|
847
|
+
...base,
|
|
848
|
+
type: "text",
|
|
849
|
+
content,
|
|
850
|
+
children: void 0
|
|
851
|
+
};
|
|
852
|
+
}
|
|
853
|
+
function applySpoilerTokens(tokens) {
|
|
854
|
+
for (const token of tokens) if (token.children && token.children.length > 0) token.children = injectSpoilersIntoInline(token.children);
|
|
855
|
+
}
|
|
856
|
+
function injectSpoilersIntoInline(tokens) {
|
|
857
|
+
const result = [];
|
|
858
|
+
const state = { spoilerOpen: false };
|
|
859
|
+
for (const token of tokens) {
|
|
860
|
+
if (token.type !== "text") {
|
|
861
|
+
result.push(token);
|
|
862
|
+
continue;
|
|
863
|
+
}
|
|
864
|
+
const content = token.content ?? "";
|
|
865
|
+
if (!content.includes("||")) {
|
|
866
|
+
result.push(token);
|
|
867
|
+
continue;
|
|
868
|
+
}
|
|
869
|
+
let index = 0;
|
|
870
|
+
while (index < content.length) {
|
|
871
|
+
const next = content.indexOf("||", index);
|
|
872
|
+
if (next === -1) {
|
|
873
|
+
if (index < content.length) result.push(createTextToken(token, content.slice(index)));
|
|
874
|
+
break;
|
|
875
|
+
}
|
|
876
|
+
if (next > index) result.push(createTextToken(token, content.slice(index, next)));
|
|
877
|
+
state.spoilerOpen = !state.spoilerOpen;
|
|
878
|
+
result.push({ type: state.spoilerOpen ? "spoiler_open" : "spoiler_close" });
|
|
879
|
+
index = next + 2;
|
|
880
|
+
}
|
|
881
|
+
}
|
|
882
|
+
return result;
|
|
883
|
+
}
|
|
884
|
+
function initRenderTarget() {
|
|
885
|
+
return {
|
|
886
|
+
text: "",
|
|
887
|
+
styles: [],
|
|
888
|
+
openStyles: [],
|
|
889
|
+
links: [],
|
|
890
|
+
linkStack: []
|
|
891
|
+
};
|
|
892
|
+
}
|
|
893
|
+
function resolveRenderTarget(state) {
|
|
894
|
+
return state.table?.currentCell ?? state;
|
|
895
|
+
}
|
|
896
|
+
function appendText(state, value) {
|
|
897
|
+
if (!value) return;
|
|
898
|
+
const target = resolveRenderTarget(state);
|
|
899
|
+
target.text += value;
|
|
900
|
+
}
|
|
901
|
+
function openStyle(state, style) {
|
|
902
|
+
const target = resolveRenderTarget(state);
|
|
903
|
+
target.openStyles.push({
|
|
904
|
+
style,
|
|
905
|
+
start: target.text.length
|
|
906
|
+
});
|
|
907
|
+
}
|
|
908
|
+
function closeStyle(state, style) {
|
|
909
|
+
const target = resolveRenderTarget(state);
|
|
910
|
+
for (let i = target.openStyles.length - 1; i >= 0; i -= 1) if (target.openStyles[i]?.style === style) {
|
|
911
|
+
const start = target.openStyles[i].start;
|
|
912
|
+
target.openStyles.splice(i, 1);
|
|
913
|
+
const end = target.text.length;
|
|
914
|
+
if (end > start) target.styles.push({
|
|
915
|
+
start,
|
|
916
|
+
end,
|
|
917
|
+
style
|
|
918
|
+
});
|
|
919
|
+
return;
|
|
920
|
+
}
|
|
921
|
+
}
|
|
922
|
+
function appendParagraphSeparator(state) {
|
|
923
|
+
if (state.env.listStack.length > 0) return;
|
|
924
|
+
if (state.table) return;
|
|
925
|
+
state.text += "\n\n";
|
|
926
|
+
}
|
|
927
|
+
function appendListPrefix(state) {
|
|
928
|
+
const stack = state.env.listStack;
|
|
929
|
+
const top = stack[stack.length - 1];
|
|
930
|
+
if (!top) return;
|
|
931
|
+
top.index += 1;
|
|
932
|
+
const indent = " ".repeat(Math.max(0, stack.length - 1));
|
|
933
|
+
const prefix = top.type === "ordered" ? `${top.index}. ` : "• ";
|
|
934
|
+
state.text += `${indent}${prefix}`;
|
|
935
|
+
}
|
|
936
|
+
function renderInlineCode(state, content) {
|
|
937
|
+
if (!content) return;
|
|
938
|
+
const target = resolveRenderTarget(state);
|
|
939
|
+
const start = target.text.length;
|
|
940
|
+
target.text += content;
|
|
941
|
+
target.styles.push({
|
|
942
|
+
start,
|
|
943
|
+
end: start + content.length,
|
|
944
|
+
style: "code"
|
|
945
|
+
});
|
|
946
|
+
}
|
|
947
|
+
function renderCodeBlock(state, content) {
|
|
948
|
+
let code = content ?? "";
|
|
949
|
+
if (!code.endsWith("\n")) code = `${code}\n`;
|
|
950
|
+
const target = resolveRenderTarget(state);
|
|
951
|
+
const start = target.text.length;
|
|
952
|
+
target.text += code;
|
|
953
|
+
target.styles.push({
|
|
954
|
+
start,
|
|
955
|
+
end: start + code.length,
|
|
956
|
+
style: "code_block"
|
|
957
|
+
});
|
|
958
|
+
if (state.env.listStack.length === 0) target.text += "\n";
|
|
959
|
+
}
|
|
960
|
+
function handleLinkClose(state) {
|
|
961
|
+
const target = resolveRenderTarget(state);
|
|
962
|
+
const link = target.linkStack.pop();
|
|
963
|
+
if (!link?.href) return;
|
|
964
|
+
const href = link.href.trim();
|
|
965
|
+
if (!href) return;
|
|
966
|
+
const start = link.labelStart;
|
|
967
|
+
const end = target.text.length;
|
|
968
|
+
if (end <= start) {
|
|
969
|
+
target.links.push({
|
|
970
|
+
start,
|
|
971
|
+
end,
|
|
972
|
+
href
|
|
973
|
+
});
|
|
974
|
+
return;
|
|
975
|
+
}
|
|
976
|
+
target.links.push({
|
|
977
|
+
start,
|
|
978
|
+
end,
|
|
979
|
+
href
|
|
980
|
+
});
|
|
981
|
+
}
|
|
982
|
+
function initTableState() {
|
|
983
|
+
return {
|
|
984
|
+
headers: [],
|
|
985
|
+
rows: [],
|
|
986
|
+
currentRow: [],
|
|
987
|
+
currentCell: null,
|
|
988
|
+
inHeader: false
|
|
989
|
+
};
|
|
990
|
+
}
|
|
991
|
+
function finishTableCell(cell) {
|
|
992
|
+
closeRemainingStyles(cell);
|
|
993
|
+
return {
|
|
994
|
+
text: cell.text,
|
|
995
|
+
styles: cell.styles,
|
|
996
|
+
links: cell.links
|
|
997
|
+
};
|
|
998
|
+
}
|
|
999
|
+
function trimCell(cell) {
|
|
1000
|
+
const text = cell.text;
|
|
1001
|
+
let start = 0;
|
|
1002
|
+
let end = text.length;
|
|
1003
|
+
while (start < end && /\s/.test(text[start] ?? "")) start += 1;
|
|
1004
|
+
while (end > start && /\s/.test(text[end - 1] ?? "")) end -= 1;
|
|
1005
|
+
if (start === 0 && end === text.length) return cell;
|
|
1006
|
+
const trimmedText = text.slice(start, end);
|
|
1007
|
+
const trimmedLength = trimmedText.length;
|
|
1008
|
+
const trimmedStyles = [];
|
|
1009
|
+
for (const span of cell.styles) {
|
|
1010
|
+
const sliceStart = Math.max(0, span.start - start);
|
|
1011
|
+
const sliceEnd = Math.min(trimmedLength, span.end - start);
|
|
1012
|
+
if (sliceEnd > sliceStart) trimmedStyles.push({
|
|
1013
|
+
start: sliceStart,
|
|
1014
|
+
end: sliceEnd,
|
|
1015
|
+
style: span.style
|
|
1016
|
+
});
|
|
1017
|
+
}
|
|
1018
|
+
const trimmedLinks = [];
|
|
1019
|
+
for (const span of cell.links) {
|
|
1020
|
+
const sliceStart = Math.max(0, span.start - start);
|
|
1021
|
+
const sliceEnd = Math.min(trimmedLength, span.end - start);
|
|
1022
|
+
if (sliceEnd > sliceStart) trimmedLinks.push({
|
|
1023
|
+
start: sliceStart,
|
|
1024
|
+
end: sliceEnd,
|
|
1025
|
+
href: span.href
|
|
1026
|
+
});
|
|
1027
|
+
}
|
|
1028
|
+
return {
|
|
1029
|
+
text: trimmedText,
|
|
1030
|
+
styles: trimmedStyles,
|
|
1031
|
+
links: trimmedLinks
|
|
1032
|
+
};
|
|
1033
|
+
}
|
|
1034
|
+
function appendCell(state, cell) {
|
|
1035
|
+
if (!cell.text) return;
|
|
1036
|
+
const start = state.text.length;
|
|
1037
|
+
state.text += cell.text;
|
|
1038
|
+
for (const span of cell.styles) state.styles.push({
|
|
1039
|
+
start: start + span.start,
|
|
1040
|
+
end: start + span.end,
|
|
1041
|
+
style: span.style
|
|
1042
|
+
});
|
|
1043
|
+
for (const link of cell.links) state.links.push({
|
|
1044
|
+
start: start + link.start,
|
|
1045
|
+
end: start + link.end,
|
|
1046
|
+
href: link.href
|
|
1047
|
+
});
|
|
1048
|
+
}
|
|
1049
|
+
function renderTableAsBullets(state) {
|
|
1050
|
+
if (!state.table) return;
|
|
1051
|
+
const headers = state.table.headers.map(trimCell);
|
|
1052
|
+
const rows = state.table.rows.map((row) => row.map(trimCell));
|
|
1053
|
+
if (headers.length === 0 && rows.length === 0) return;
|
|
1054
|
+
if (headers.length > 1 && rows.length > 0) for (const row of rows) {
|
|
1055
|
+
if (row.length === 0) continue;
|
|
1056
|
+
const rowLabel = row[0];
|
|
1057
|
+
if (rowLabel?.text) {
|
|
1058
|
+
const labelStart = state.text.length;
|
|
1059
|
+
appendCell(state, rowLabel);
|
|
1060
|
+
const labelEnd = state.text.length;
|
|
1061
|
+
if (labelEnd > labelStart) state.styles.push({
|
|
1062
|
+
start: labelStart,
|
|
1063
|
+
end: labelEnd,
|
|
1064
|
+
style: "bold"
|
|
1065
|
+
});
|
|
1066
|
+
state.text += "\n";
|
|
1067
|
+
}
|
|
1068
|
+
for (let i = 1; i < row.length; i++) {
|
|
1069
|
+
const header = headers[i];
|
|
1070
|
+
const value = row[i];
|
|
1071
|
+
if (!value?.text) continue;
|
|
1072
|
+
state.text += "• ";
|
|
1073
|
+
if (header?.text) {
|
|
1074
|
+
appendCell(state, header);
|
|
1075
|
+
state.text += ": ";
|
|
1076
|
+
} else state.text += `Column ${i}: `;
|
|
1077
|
+
appendCell(state, value);
|
|
1078
|
+
state.text += "\n";
|
|
1079
|
+
}
|
|
1080
|
+
state.text += "\n";
|
|
1081
|
+
}
|
|
1082
|
+
else for (const row of rows) {
|
|
1083
|
+
for (let i = 0; i < row.length; i++) {
|
|
1084
|
+
const header = headers[i];
|
|
1085
|
+
const value = row[i];
|
|
1086
|
+
if (!value?.text) continue;
|
|
1087
|
+
state.text += "• ";
|
|
1088
|
+
if (header?.text) {
|
|
1089
|
+
appendCell(state, header);
|
|
1090
|
+
state.text += ": ";
|
|
1091
|
+
}
|
|
1092
|
+
appendCell(state, value);
|
|
1093
|
+
state.text += "\n";
|
|
1094
|
+
}
|
|
1095
|
+
state.text += "\n";
|
|
1096
|
+
}
|
|
1097
|
+
}
|
|
1098
|
+
function renderTableAsCode(state) {
|
|
1099
|
+
if (!state.table) return;
|
|
1100
|
+
const headers = state.table.headers.map(trimCell);
|
|
1101
|
+
const rows = state.table.rows.map((row) => row.map(trimCell));
|
|
1102
|
+
const columnCount = Math.max(headers.length, ...rows.map((row) => row.length));
|
|
1103
|
+
if (columnCount === 0) return;
|
|
1104
|
+
const widths = Array.from({ length: columnCount }, () => 0);
|
|
1105
|
+
const updateWidths = (cells) => {
|
|
1106
|
+
for (let i = 0; i < columnCount; i += 1) {
|
|
1107
|
+
const width = cells[i]?.text.length ?? 0;
|
|
1108
|
+
if (widths[i] < width) widths[i] = width;
|
|
1109
|
+
}
|
|
1110
|
+
};
|
|
1111
|
+
updateWidths(headers);
|
|
1112
|
+
for (const row of rows) updateWidths(row);
|
|
1113
|
+
const codeStart = state.text.length;
|
|
1114
|
+
const appendRow = (cells) => {
|
|
1115
|
+
state.text += "|";
|
|
1116
|
+
for (let i = 0; i < columnCount; i += 1) {
|
|
1117
|
+
state.text += " ";
|
|
1118
|
+
const cell = cells[i];
|
|
1119
|
+
if (cell) appendCell(state, cell);
|
|
1120
|
+
const pad = widths[i] - (cell?.text.length ?? 0);
|
|
1121
|
+
if (pad > 0) state.text += " ".repeat(pad);
|
|
1122
|
+
state.text += " |";
|
|
1123
|
+
}
|
|
1124
|
+
state.text += "\n";
|
|
1125
|
+
};
|
|
1126
|
+
const appendDivider = () => {
|
|
1127
|
+
state.text += "|";
|
|
1128
|
+
for (let i = 0; i < columnCount; i += 1) {
|
|
1129
|
+
const dashCount = Math.max(3, widths[i]);
|
|
1130
|
+
state.text += ` ${"-".repeat(dashCount)} |`;
|
|
1131
|
+
}
|
|
1132
|
+
state.text += "\n";
|
|
1133
|
+
};
|
|
1134
|
+
appendRow(headers);
|
|
1135
|
+
appendDivider();
|
|
1136
|
+
for (const row of rows) appendRow(row);
|
|
1137
|
+
const codeEnd = state.text.length;
|
|
1138
|
+
if (codeEnd > codeStart) state.styles.push({
|
|
1139
|
+
start: codeStart,
|
|
1140
|
+
end: codeEnd,
|
|
1141
|
+
style: "code_block"
|
|
1142
|
+
});
|
|
1143
|
+
if (state.env.listStack.length === 0) state.text += "\n";
|
|
1144
|
+
}
|
|
1145
|
+
function renderTokens(tokens, state) {
|
|
1146
|
+
for (const token of tokens) switch (token.type) {
|
|
1147
|
+
case "inline":
|
|
1148
|
+
if (token.children) renderTokens(token.children, state);
|
|
1149
|
+
break;
|
|
1150
|
+
case "text":
|
|
1151
|
+
appendText(state, token.content ?? "");
|
|
1152
|
+
break;
|
|
1153
|
+
case "em_open":
|
|
1154
|
+
openStyle(state, "italic");
|
|
1155
|
+
break;
|
|
1156
|
+
case "em_close":
|
|
1157
|
+
closeStyle(state, "italic");
|
|
1158
|
+
break;
|
|
1159
|
+
case "strong_open":
|
|
1160
|
+
openStyle(state, "bold");
|
|
1161
|
+
break;
|
|
1162
|
+
case "strong_close":
|
|
1163
|
+
closeStyle(state, "bold");
|
|
1164
|
+
break;
|
|
1165
|
+
case "s_open":
|
|
1166
|
+
openStyle(state, "strikethrough");
|
|
1167
|
+
break;
|
|
1168
|
+
case "s_close":
|
|
1169
|
+
closeStyle(state, "strikethrough");
|
|
1170
|
+
break;
|
|
1171
|
+
case "code_inline":
|
|
1172
|
+
renderInlineCode(state, token.content ?? "");
|
|
1173
|
+
break;
|
|
1174
|
+
case "spoiler_open":
|
|
1175
|
+
if (state.enableSpoilers) openStyle(state, "spoiler");
|
|
1176
|
+
break;
|
|
1177
|
+
case "spoiler_close":
|
|
1178
|
+
if (state.enableSpoilers) closeStyle(state, "spoiler");
|
|
1179
|
+
break;
|
|
1180
|
+
case "link_open": {
|
|
1181
|
+
const href = getAttr(token, "href") ?? "";
|
|
1182
|
+
const target = resolveRenderTarget(state);
|
|
1183
|
+
target.linkStack.push({
|
|
1184
|
+
href,
|
|
1185
|
+
labelStart: target.text.length
|
|
1186
|
+
});
|
|
1187
|
+
break;
|
|
1188
|
+
}
|
|
1189
|
+
case "link_close":
|
|
1190
|
+
handleLinkClose(state);
|
|
1191
|
+
break;
|
|
1192
|
+
case "image":
|
|
1193
|
+
appendText(state, token.content ?? "");
|
|
1194
|
+
break;
|
|
1195
|
+
case "softbreak":
|
|
1196
|
+
case "hardbreak":
|
|
1197
|
+
appendText(state, "\n");
|
|
1198
|
+
break;
|
|
1199
|
+
case "paragraph_close":
|
|
1200
|
+
appendParagraphSeparator(state);
|
|
1201
|
+
break;
|
|
1202
|
+
case "heading_open":
|
|
1203
|
+
if (state.headingStyle === "bold") openStyle(state, "bold");
|
|
1204
|
+
break;
|
|
1205
|
+
case "heading_close":
|
|
1206
|
+
if (state.headingStyle === "bold") closeStyle(state, "bold");
|
|
1207
|
+
appendParagraphSeparator(state);
|
|
1208
|
+
break;
|
|
1209
|
+
case "blockquote_open":
|
|
1210
|
+
if (state.blockquotePrefix) state.text += state.blockquotePrefix;
|
|
1211
|
+
break;
|
|
1212
|
+
case "blockquote_close":
|
|
1213
|
+
state.text += "\n";
|
|
1214
|
+
break;
|
|
1215
|
+
case "bullet_list_open":
|
|
1216
|
+
state.env.listStack.push({
|
|
1217
|
+
type: "bullet",
|
|
1218
|
+
index: 0
|
|
1219
|
+
});
|
|
1220
|
+
break;
|
|
1221
|
+
case "bullet_list_close":
|
|
1222
|
+
state.env.listStack.pop();
|
|
1223
|
+
break;
|
|
1224
|
+
case "ordered_list_open": {
|
|
1225
|
+
const start = Number(getAttr(token, "start") ?? "1");
|
|
1226
|
+
state.env.listStack.push({
|
|
1227
|
+
type: "ordered",
|
|
1228
|
+
index: start - 1
|
|
1229
|
+
});
|
|
1230
|
+
break;
|
|
1231
|
+
}
|
|
1232
|
+
case "ordered_list_close":
|
|
1233
|
+
state.env.listStack.pop();
|
|
1234
|
+
break;
|
|
1235
|
+
case "list_item_open":
|
|
1236
|
+
appendListPrefix(state);
|
|
1237
|
+
break;
|
|
1238
|
+
case "list_item_close":
|
|
1239
|
+
state.text += "\n";
|
|
1240
|
+
break;
|
|
1241
|
+
case "code_block":
|
|
1242
|
+
case "fence":
|
|
1243
|
+
renderCodeBlock(state, token.content ?? "");
|
|
1244
|
+
break;
|
|
1245
|
+
case "html_block":
|
|
1246
|
+
case "html_inline":
|
|
1247
|
+
appendText(state, token.content ?? "");
|
|
1248
|
+
break;
|
|
1249
|
+
case "table_open":
|
|
1250
|
+
if (state.tableMode !== "off") {
|
|
1251
|
+
state.table = initTableState();
|
|
1252
|
+
state.hasTables = true;
|
|
1253
|
+
}
|
|
1254
|
+
break;
|
|
1255
|
+
case "table_close":
|
|
1256
|
+
if (state.table) {
|
|
1257
|
+
if (state.tableMode === "bullets") renderTableAsBullets(state);
|
|
1258
|
+
else if (state.tableMode === "code") renderTableAsCode(state);
|
|
1259
|
+
}
|
|
1260
|
+
state.table = null;
|
|
1261
|
+
break;
|
|
1262
|
+
case "thead_open":
|
|
1263
|
+
if (state.table) state.table.inHeader = true;
|
|
1264
|
+
break;
|
|
1265
|
+
case "thead_close":
|
|
1266
|
+
if (state.table) state.table.inHeader = false;
|
|
1267
|
+
break;
|
|
1268
|
+
case "tbody_open":
|
|
1269
|
+
case "tbody_close": break;
|
|
1270
|
+
case "tr_open":
|
|
1271
|
+
if (state.table) state.table.currentRow = [];
|
|
1272
|
+
break;
|
|
1273
|
+
case "tr_close":
|
|
1274
|
+
if (state.table) {
|
|
1275
|
+
if (state.table.inHeader) state.table.headers = state.table.currentRow;
|
|
1276
|
+
else state.table.rows.push(state.table.currentRow);
|
|
1277
|
+
state.table.currentRow = [];
|
|
1278
|
+
}
|
|
1279
|
+
break;
|
|
1280
|
+
case "th_open":
|
|
1281
|
+
case "td_open":
|
|
1282
|
+
if (state.table) state.table.currentCell = initRenderTarget();
|
|
1283
|
+
break;
|
|
1284
|
+
case "th_close":
|
|
1285
|
+
case "td_close":
|
|
1286
|
+
if (state.table?.currentCell) {
|
|
1287
|
+
state.table.currentRow.push(finishTableCell(state.table.currentCell));
|
|
1288
|
+
state.table.currentCell = null;
|
|
1289
|
+
}
|
|
1290
|
+
break;
|
|
1291
|
+
case "hr":
|
|
1292
|
+
state.text += "\n";
|
|
1293
|
+
break;
|
|
1294
|
+
default:
|
|
1295
|
+
if (token.children) renderTokens(token.children, state);
|
|
1296
|
+
break;
|
|
1297
|
+
}
|
|
1298
|
+
}
|
|
1299
|
+
function closeRemainingStyles(target) {
|
|
1300
|
+
for (let i = target.openStyles.length - 1; i >= 0; i -= 1) {
|
|
1301
|
+
const open = target.openStyles[i];
|
|
1302
|
+
const end = target.text.length;
|
|
1303
|
+
if (end > open.start) target.styles.push({
|
|
1304
|
+
start: open.start,
|
|
1305
|
+
end,
|
|
1306
|
+
style: open.style
|
|
1307
|
+
});
|
|
1308
|
+
}
|
|
1309
|
+
target.openStyles = [];
|
|
1310
|
+
}
|
|
1311
|
+
function clampStyleSpans(spans, maxLength) {
|
|
1312
|
+
const clamped = [];
|
|
1313
|
+
for (const span of spans) {
|
|
1314
|
+
const start = Math.max(0, Math.min(span.start, maxLength));
|
|
1315
|
+
const end = Math.max(start, Math.min(span.end, maxLength));
|
|
1316
|
+
if (end > start) clamped.push({
|
|
1317
|
+
start,
|
|
1318
|
+
end,
|
|
1319
|
+
style: span.style
|
|
1320
|
+
});
|
|
1321
|
+
}
|
|
1322
|
+
return clamped;
|
|
1323
|
+
}
|
|
1324
|
+
function clampLinkSpans(spans, maxLength) {
|
|
1325
|
+
const clamped = [];
|
|
1326
|
+
for (const span of spans) {
|
|
1327
|
+
const start = Math.max(0, Math.min(span.start, maxLength));
|
|
1328
|
+
const end = Math.max(start, Math.min(span.end, maxLength));
|
|
1329
|
+
if (end > start) clamped.push({
|
|
1330
|
+
start,
|
|
1331
|
+
end,
|
|
1332
|
+
href: span.href
|
|
1333
|
+
});
|
|
1334
|
+
}
|
|
1335
|
+
return clamped;
|
|
1336
|
+
}
|
|
1337
|
+
function mergeStyleSpans(spans) {
|
|
1338
|
+
const sorted = [...spans].toSorted((a, b) => {
|
|
1339
|
+
if (a.start !== b.start) return a.start - b.start;
|
|
1340
|
+
if (a.end !== b.end) return a.end - b.end;
|
|
1341
|
+
return a.style.localeCompare(b.style);
|
|
1342
|
+
});
|
|
1343
|
+
const merged = [];
|
|
1344
|
+
for (const span of sorted) {
|
|
1345
|
+
const prev = merged[merged.length - 1];
|
|
1346
|
+
if (prev && prev.style === span.style && span.start <= prev.end) {
|
|
1347
|
+
prev.end = Math.max(prev.end, span.end);
|
|
1348
|
+
continue;
|
|
1349
|
+
}
|
|
1350
|
+
merged.push({ ...span });
|
|
1351
|
+
}
|
|
1352
|
+
return merged;
|
|
1353
|
+
}
|
|
1354
|
+
function sliceStyleSpans(spans, start, end) {
|
|
1355
|
+
if (spans.length === 0) return [];
|
|
1356
|
+
const sliced = [];
|
|
1357
|
+
for (const span of spans) {
|
|
1358
|
+
const sliceStart = Math.max(span.start, start);
|
|
1359
|
+
const sliceEnd = Math.min(span.end, end);
|
|
1360
|
+
if (sliceEnd > sliceStart) sliced.push({
|
|
1361
|
+
start: sliceStart - start,
|
|
1362
|
+
end: sliceEnd - start,
|
|
1363
|
+
style: span.style
|
|
1364
|
+
});
|
|
1365
|
+
}
|
|
1366
|
+
return mergeStyleSpans(sliced);
|
|
1367
|
+
}
|
|
1368
|
+
function sliceLinkSpans(spans, start, end) {
|
|
1369
|
+
if (spans.length === 0) return [];
|
|
1370
|
+
const sliced = [];
|
|
1371
|
+
for (const span of spans) {
|
|
1372
|
+
const sliceStart = Math.max(span.start, start);
|
|
1373
|
+
const sliceEnd = Math.min(span.end, end);
|
|
1374
|
+
if (sliceEnd > sliceStart) sliced.push({
|
|
1375
|
+
start: sliceStart - start,
|
|
1376
|
+
end: sliceEnd - start,
|
|
1377
|
+
href: span.href
|
|
1378
|
+
});
|
|
1379
|
+
}
|
|
1380
|
+
return sliced;
|
|
1381
|
+
}
|
|
1382
|
+
function markdownToIR(markdown, options = {}) {
|
|
1383
|
+
return markdownToIRWithMeta(markdown, options).ir;
|
|
1384
|
+
}
|
|
1385
|
+
function markdownToIRWithMeta(markdown, options = {}) {
|
|
1386
|
+
const env = { listStack: [] };
|
|
1387
|
+
const tokens = createMarkdownIt(options).parse(markdown ?? "", env);
|
|
1388
|
+
if (options.enableSpoilers) applySpoilerTokens(tokens);
|
|
1389
|
+
const tableMode = options.tableMode ?? "off";
|
|
1390
|
+
const state = {
|
|
1391
|
+
text: "",
|
|
1392
|
+
styles: [],
|
|
1393
|
+
openStyles: [],
|
|
1394
|
+
links: [],
|
|
1395
|
+
linkStack: [],
|
|
1396
|
+
env,
|
|
1397
|
+
headingStyle: options.headingStyle ?? "none",
|
|
1398
|
+
blockquotePrefix: options.blockquotePrefix ?? "",
|
|
1399
|
+
enableSpoilers: options.enableSpoilers ?? false,
|
|
1400
|
+
tableMode,
|
|
1401
|
+
table: null,
|
|
1402
|
+
hasTables: false
|
|
1403
|
+
};
|
|
1404
|
+
renderTokens(tokens, state);
|
|
1405
|
+
closeRemainingStyles(state);
|
|
1406
|
+
const trimmedLength = state.text.trimEnd().length;
|
|
1407
|
+
let codeBlockEnd = 0;
|
|
1408
|
+
for (const span of state.styles) {
|
|
1409
|
+
if (span.style !== "code_block") continue;
|
|
1410
|
+
if (span.end > codeBlockEnd) codeBlockEnd = span.end;
|
|
1411
|
+
}
|
|
1412
|
+
const finalLength = Math.max(trimmedLength, codeBlockEnd);
|
|
1413
|
+
return {
|
|
1414
|
+
ir: {
|
|
1415
|
+
text: finalLength === state.text.length ? state.text : state.text.slice(0, finalLength),
|
|
1416
|
+
styles: mergeStyleSpans(clampStyleSpans(state.styles, finalLength)),
|
|
1417
|
+
links: clampLinkSpans(state.links, finalLength)
|
|
1418
|
+
},
|
|
1419
|
+
hasTables: state.hasTables
|
|
1420
|
+
};
|
|
1421
|
+
}
|
|
1422
|
+
function chunkMarkdownIR(ir, limit) {
|
|
1423
|
+
if (!ir.text) return [];
|
|
1424
|
+
if (limit <= 0 || ir.text.length <= limit) return [ir];
|
|
1425
|
+
const chunks = chunkText(ir.text, limit);
|
|
1426
|
+
const results = [];
|
|
1427
|
+
let cursor = 0;
|
|
1428
|
+
chunks.forEach((chunk, index) => {
|
|
1429
|
+
if (!chunk) return;
|
|
1430
|
+
if (index > 0) while (cursor < ir.text.length && /\s/.test(ir.text[cursor] ?? "")) cursor += 1;
|
|
1431
|
+
const start = cursor;
|
|
1432
|
+
const end = Math.min(ir.text.length, start + chunk.length);
|
|
1433
|
+
results.push({
|
|
1434
|
+
text: chunk,
|
|
1435
|
+
styles: sliceStyleSpans(ir.styles, start, end),
|
|
1436
|
+
links: sliceLinkSpans(ir.links, start, end)
|
|
1437
|
+
});
|
|
1438
|
+
cursor = end;
|
|
1439
|
+
});
|
|
1440
|
+
return results;
|
|
1441
|
+
}
|
|
1442
|
+
|
|
1443
|
+
//#endregion
|
|
1444
|
+
//#region src/infra/fetch.ts
|
|
1445
|
+
function withDuplex(init, input) {
|
|
1446
|
+
const hasInitBody = init?.body != null;
|
|
1447
|
+
const hasRequestBody = !hasInitBody && typeof Request !== "undefined" && input instanceof Request && input.body != null;
|
|
1448
|
+
if (!hasInitBody && !hasRequestBody) return init;
|
|
1449
|
+
if (init && "duplex" in init) return init;
|
|
1450
|
+
return init ? {
|
|
1451
|
+
...init,
|
|
1452
|
+
duplex: "half"
|
|
1453
|
+
} : { duplex: "half" };
|
|
1454
|
+
}
|
|
1455
|
+
function wrapFetchWithAbortSignal(fetchImpl) {
|
|
1456
|
+
const wrapped = ((input, init) => {
|
|
1457
|
+
const patchedInit = withDuplex(init, input);
|
|
1458
|
+
const signal = patchedInit?.signal;
|
|
1459
|
+
if (!signal) return fetchImpl(input, patchedInit);
|
|
1460
|
+
if (typeof AbortSignal !== "undefined" && signal instanceof AbortSignal) return fetchImpl(input, patchedInit);
|
|
1461
|
+
if (typeof AbortController === "undefined") return fetchImpl(input, patchedInit);
|
|
1462
|
+
if (typeof signal.addEventListener !== "function") return fetchImpl(input, patchedInit);
|
|
1463
|
+
const controller = new AbortController();
|
|
1464
|
+
const onAbort = () => controller.abort();
|
|
1465
|
+
if (signal.aborted) controller.abort();
|
|
1466
|
+
else signal.addEventListener("abort", onAbort, { once: true });
|
|
1467
|
+
const response = fetchImpl(input, {
|
|
1468
|
+
...patchedInit,
|
|
1469
|
+
signal: controller.signal
|
|
1470
|
+
});
|
|
1471
|
+
if (typeof signal.removeEventListener === "function") response.finally(() => {
|
|
1472
|
+
signal.removeEventListener("abort", onAbort);
|
|
1473
|
+
});
|
|
1474
|
+
return response;
|
|
1475
|
+
});
|
|
1476
|
+
const fetchWithPreconnect = fetchImpl;
|
|
1477
|
+
wrapped.preconnect = typeof fetchWithPreconnect.preconnect === "function" ? fetchWithPreconnect.preconnect.bind(fetchWithPreconnect) : () => {};
|
|
1478
|
+
return Object.assign(wrapped, fetchImpl);
|
|
1479
|
+
}
|
|
1480
|
+
function resolveFetch(fetchImpl) {
|
|
1481
|
+
const resolved = fetchImpl ?? globalThis.fetch;
|
|
1482
|
+
if (!resolved) return;
|
|
1483
|
+
return wrapFetchWithAbortSignal(resolved);
|
|
1484
|
+
}
|
|
1485
|
+
|
|
1486
|
+
//#endregion
|
|
1487
|
+
//#region src/utils/directive-tags.ts
|
|
1488
|
+
const AUDIO_TAG_RE = /\[\[\s*audio_as_voice\s*\]\]/gi;
|
|
1489
|
+
const REPLY_TAG_RE = /\[\[\s*(?:reply_to_current|reply_to\s*:\s*([^\]\n]+))\s*\]\]/gi;
|
|
1490
|
+
function normalizeDirectiveWhitespace(text) {
|
|
1491
|
+
return text.replace(/[ \t]+/g, " ").replace(/[ \t]*\n[ \t]*/g, "\n").trim();
|
|
1492
|
+
}
|
|
1493
|
+
function parseInlineDirectives(text, options = {}) {
|
|
1494
|
+
const { currentMessageId, stripAudioTag = true, stripReplyTags = true } = options;
|
|
1495
|
+
if (!text) return {
|
|
1496
|
+
text: "",
|
|
1497
|
+
audioAsVoice: false,
|
|
1498
|
+
replyToCurrent: false,
|
|
1499
|
+
hasAudioTag: false,
|
|
1500
|
+
hasReplyTag: false
|
|
1501
|
+
};
|
|
1502
|
+
let cleaned = text;
|
|
1503
|
+
let audioAsVoice = false;
|
|
1504
|
+
let hasAudioTag = false;
|
|
1505
|
+
let hasReplyTag = false;
|
|
1506
|
+
let sawCurrent = false;
|
|
1507
|
+
let lastExplicitId;
|
|
1508
|
+
cleaned = cleaned.replace(AUDIO_TAG_RE, (match) => {
|
|
1509
|
+
audioAsVoice = true;
|
|
1510
|
+
hasAudioTag = true;
|
|
1511
|
+
return stripAudioTag ? " " : match;
|
|
1512
|
+
});
|
|
1513
|
+
cleaned = cleaned.replace(REPLY_TAG_RE, (match, idRaw) => {
|
|
1514
|
+
hasReplyTag = true;
|
|
1515
|
+
if (idRaw === void 0) sawCurrent = true;
|
|
1516
|
+
else {
|
|
1517
|
+
const id = idRaw.trim();
|
|
1518
|
+
if (id) lastExplicitId = id;
|
|
1519
|
+
}
|
|
1520
|
+
return stripReplyTags ? " " : match;
|
|
1521
|
+
});
|
|
1522
|
+
cleaned = normalizeDirectiveWhitespace(cleaned);
|
|
1523
|
+
const replyToId = lastExplicitId ?? (sawCurrent ? currentMessageId?.trim() || void 0 : void 0);
|
|
1524
|
+
return {
|
|
1525
|
+
text: cleaned,
|
|
1526
|
+
audioAsVoice,
|
|
1527
|
+
replyToId,
|
|
1528
|
+
replyToExplicitId: lastExplicitId,
|
|
1529
|
+
replyToCurrent: sawCurrent,
|
|
1530
|
+
hasAudioTag,
|
|
1531
|
+
hasReplyTag
|
|
1532
|
+
};
|
|
1533
|
+
}
|
|
1534
|
+
|
|
1535
|
+
//#endregion
|
|
1536
|
+
//#region src/media/audio-tags.ts
|
|
1537
|
+
/**
|
|
1538
|
+
* Extract audio mode tag from text.
|
|
1539
|
+
* Supports [[audio_as_voice]] to send audio as voice bubble instead of file.
|
|
1540
|
+
* Default is file (preserves backward compatibility).
|
|
1541
|
+
*/
|
|
1542
|
+
function parseAudioTag(text) {
|
|
1543
|
+
const result = parseInlineDirectives(text, { stripReplyTags: false });
|
|
1544
|
+
return {
|
|
1545
|
+
text: result.text,
|
|
1546
|
+
audioAsVoice: result.audioAsVoice,
|
|
1547
|
+
hadTag: result.hasAudioTag
|
|
1548
|
+
};
|
|
1549
|
+
}
|
|
1550
|
+
|
|
1551
|
+
//#endregion
|
|
1552
|
+
//#region src/media/parse.ts
|
|
1553
|
+
const MEDIA_TOKEN_RE = /\bMEDIA:\s*`?([^\n]+)`?/gi;
|
|
1554
|
+
function normalizeMediaSource(src) {
|
|
1555
|
+
return src.startsWith("file://") ? src.replace("file://", "") : src;
|
|
1556
|
+
}
|
|
1557
|
+
function cleanCandidate(raw) {
|
|
1558
|
+
return raw.replace(/^[`"'[{(]+/, "").replace(/[`"'\\})\],]+$/, "");
|
|
1559
|
+
}
|
|
1560
|
+
function isValidMedia(candidate, opts) {
|
|
1561
|
+
if (!candidate) return false;
|
|
1562
|
+
if (candidate.length > 4096) return false;
|
|
1563
|
+
if (!opts?.allowSpaces && /\s/.test(candidate)) return false;
|
|
1564
|
+
if (/^https?:\/\//i.test(candidate)) return true;
|
|
1565
|
+
return candidate.startsWith("./") && !candidate.includes("..");
|
|
1566
|
+
}
|
|
1567
|
+
function unwrapQuoted(value) {
|
|
1568
|
+
const trimmed = value.trim();
|
|
1569
|
+
if (trimmed.length < 2) return;
|
|
1570
|
+
const first = trimmed[0];
|
|
1571
|
+
if (first !== trimmed[trimmed.length - 1]) return;
|
|
1572
|
+
if (first !== `"` && first !== "'" && first !== "`") return;
|
|
1573
|
+
return trimmed.slice(1, -1).trim();
|
|
1574
|
+
}
|
|
1575
|
+
function isInsideFence(fenceSpans, offset) {
|
|
1576
|
+
return fenceSpans.some((span) => offset >= span.start && offset < span.end);
|
|
1577
|
+
}
|
|
1578
|
+
function splitMediaFromOutput(raw) {
|
|
1579
|
+
const trimmedRaw = raw.trimEnd();
|
|
1580
|
+
if (!trimmedRaw.trim()) return { text: "" };
|
|
1581
|
+
const media = [];
|
|
1582
|
+
let foundMediaToken = false;
|
|
1583
|
+
const fenceSpans = parseFenceSpans(trimmedRaw);
|
|
1584
|
+
const lines = trimmedRaw.split("\n");
|
|
1585
|
+
const keptLines = [];
|
|
1586
|
+
let lineOffset = 0;
|
|
1587
|
+
for (const line of lines) {
|
|
1588
|
+
if (isInsideFence(fenceSpans, lineOffset)) {
|
|
1589
|
+
keptLines.push(line);
|
|
1590
|
+
lineOffset += line.length + 1;
|
|
1591
|
+
continue;
|
|
1592
|
+
}
|
|
1593
|
+
if (!line.trimStart().startsWith("MEDIA:")) {
|
|
1594
|
+
keptLines.push(line);
|
|
1595
|
+
lineOffset += line.length + 1;
|
|
1596
|
+
continue;
|
|
1597
|
+
}
|
|
1598
|
+
const matches = Array.from(line.matchAll(MEDIA_TOKEN_RE));
|
|
1599
|
+
if (matches.length === 0) {
|
|
1600
|
+
keptLines.push(line);
|
|
1601
|
+
lineOffset += line.length + 1;
|
|
1602
|
+
continue;
|
|
1603
|
+
}
|
|
1604
|
+
const pieces = [];
|
|
1605
|
+
let cursor = 0;
|
|
1606
|
+
for (const match of matches) {
|
|
1607
|
+
const start = match.index ?? 0;
|
|
1608
|
+
pieces.push(line.slice(cursor, start));
|
|
1609
|
+
const payload = match[1];
|
|
1610
|
+
const unwrapped = unwrapQuoted(payload);
|
|
1611
|
+
const payloadValue = unwrapped ?? payload;
|
|
1612
|
+
const parts = unwrapped ? [unwrapped] : payload.split(/\s+/).filter(Boolean);
|
|
1613
|
+
const mediaStartIndex = media.length;
|
|
1614
|
+
let validCount = 0;
|
|
1615
|
+
const invalidParts = [];
|
|
1616
|
+
let hasValidMedia = false;
|
|
1617
|
+
for (const part of parts) {
|
|
1618
|
+
const candidate = normalizeMediaSource(cleanCandidate(part));
|
|
1619
|
+
if (isValidMedia(candidate, unwrapped ? { allowSpaces: true } : void 0)) {
|
|
1620
|
+
media.push(candidate);
|
|
1621
|
+
hasValidMedia = true;
|
|
1622
|
+
foundMediaToken = true;
|
|
1623
|
+
validCount += 1;
|
|
1624
|
+
} else invalidParts.push(part);
|
|
1625
|
+
}
|
|
1626
|
+
const trimmedPayload = payloadValue.trim();
|
|
1627
|
+
const looksLikeLocalPath = trimmedPayload.startsWith("/") || trimmedPayload.startsWith("./") || trimmedPayload.startsWith("../") || trimmedPayload.startsWith("~") || trimmedPayload.startsWith("file://");
|
|
1628
|
+
if (!unwrapped && validCount === 1 && invalidParts.length > 0 && /\s/.test(payloadValue) && looksLikeLocalPath) {
|
|
1629
|
+
const fallback = normalizeMediaSource(cleanCandidate(payloadValue));
|
|
1630
|
+
if (isValidMedia(fallback, { allowSpaces: true })) {
|
|
1631
|
+
media.splice(mediaStartIndex, media.length - mediaStartIndex, fallback);
|
|
1632
|
+
hasValidMedia = true;
|
|
1633
|
+
foundMediaToken = true;
|
|
1634
|
+
validCount = 1;
|
|
1635
|
+
invalidParts.length = 0;
|
|
1636
|
+
}
|
|
1637
|
+
}
|
|
1638
|
+
if (!hasValidMedia) {
|
|
1639
|
+
const fallback = normalizeMediaSource(cleanCandidate(payloadValue));
|
|
1640
|
+
if (isValidMedia(fallback, { allowSpaces: true })) {
|
|
1641
|
+
media.push(fallback);
|
|
1642
|
+
hasValidMedia = true;
|
|
1643
|
+
foundMediaToken = true;
|
|
1644
|
+
invalidParts.length = 0;
|
|
1645
|
+
}
|
|
1646
|
+
}
|
|
1647
|
+
if (hasValidMedia) {
|
|
1648
|
+
if (invalidParts.length > 0) pieces.push(invalidParts.join(" "));
|
|
1649
|
+
} else pieces.push(match[0]);
|
|
1650
|
+
cursor = start + match[0].length;
|
|
1651
|
+
}
|
|
1652
|
+
pieces.push(line.slice(cursor));
|
|
1653
|
+
const cleanedLine = pieces.join("").replace(/[ \t]{2,}/g, " ").trim();
|
|
1654
|
+
if (cleanedLine) keptLines.push(cleanedLine);
|
|
1655
|
+
lineOffset += line.length + 1;
|
|
1656
|
+
}
|
|
1657
|
+
let cleanedText = keptLines.join("\n").replace(/[ \t]+\n/g, "\n").replace(/[ \t]{2,}/g, " ").replace(/\n{2,}/g, "\n").trim();
|
|
1658
|
+
const audioTagResult = parseAudioTag(cleanedText);
|
|
1659
|
+
const hasAudioAsVoice = audioTagResult.audioAsVoice;
|
|
1660
|
+
if (audioTagResult.hadTag) cleanedText = audioTagResult.text.replace(/\n{2,}/g, "\n").trim();
|
|
1661
|
+
if (media.length === 0) {
|
|
1662
|
+
const result = { text: foundMediaToken || hasAudioAsVoice ? cleanedText : trimmedRaw };
|
|
1663
|
+
if (hasAudioAsVoice) result.audioAsVoice = true;
|
|
1664
|
+
return result;
|
|
1665
|
+
}
|
|
1666
|
+
return {
|
|
1667
|
+
text: cleanedText,
|
|
1668
|
+
mediaUrls: media,
|
|
1669
|
+
mediaUrl: media[0],
|
|
1670
|
+
...hasAudioAsVoice ? { audioAsVoice: true } : {}
|
|
1671
|
+
};
|
|
1672
|
+
}
|
|
1673
|
+
|
|
1674
|
+
//#endregion
|
|
1675
|
+
//#region src/auto-reply/reply/reply-directives.ts
|
|
1676
|
+
function parseReplyDirectives(raw, options = {}) {
|
|
1677
|
+
const split = splitMediaFromOutput(raw);
|
|
1678
|
+
let text = split.text ?? "";
|
|
1679
|
+
const replyParsed = parseInlineDirectives(text, {
|
|
1680
|
+
currentMessageId: options.currentMessageId,
|
|
1681
|
+
stripAudioTag: false,
|
|
1682
|
+
stripReplyTags: true
|
|
1683
|
+
});
|
|
1684
|
+
if (replyParsed.hasReplyTag) text = replyParsed.text;
|
|
1685
|
+
const silentToken = options.silentToken ?? SILENT_REPLY_TOKEN;
|
|
1686
|
+
const isSilent = isSilentReplyText(text, silentToken);
|
|
1687
|
+
if (isSilent) text = "";
|
|
1688
|
+
return {
|
|
1689
|
+
text,
|
|
1690
|
+
mediaUrls: split.mediaUrls,
|
|
1691
|
+
mediaUrl: split.mediaUrl,
|
|
1692
|
+
replyToId: replyParsed.replyToId,
|
|
1693
|
+
replyToCurrent: replyParsed.replyToCurrent,
|
|
1694
|
+
replyToTag: replyParsed.hasReplyTag,
|
|
1695
|
+
audioAsVoice: split.audioAsVoice,
|
|
1696
|
+
isSilent
|
|
1697
|
+
};
|
|
1698
|
+
}
|
|
1699
|
+
|
|
1700
|
+
//#endregion
|
|
1701
|
+
//#region src/infra/outbound/target-normalization.ts
|
|
1702
|
+
function normalizeChannelTargetInput(raw) {
|
|
1703
|
+
return raw.trim();
|
|
1704
|
+
}
|
|
1705
|
+
function normalizeTargetForProvider(provider, raw) {
|
|
1706
|
+
if (!raw) return;
|
|
1707
|
+
const providerId = normalizeChannelId(provider);
|
|
1708
|
+
return ((providerId ? getChannelPlugin(providerId) : void 0)?.messaging?.normalizeTarget?.(raw) ?? (raw.trim().toLowerCase() || void 0)) || void 0;
|
|
1709
|
+
}
|
|
1710
|
+
function buildTargetResolverSignature(channel) {
|
|
1711
|
+
const resolver = getChannelPlugin(channel)?.messaging?.targetResolver;
|
|
1712
|
+
const hint = resolver?.hint ?? "";
|
|
1713
|
+
const looksLike = resolver?.looksLikeId;
|
|
1714
|
+
return hashSignature(`${hint}|${looksLike ? looksLike.toString() : ""}`);
|
|
1715
|
+
}
|
|
1716
|
+
function hashSignature(value) {
|
|
1717
|
+
let hash = 5381;
|
|
1718
|
+
for (let i = 0; i < value.length; i += 1) hash = (hash << 5) + hash ^ value.charCodeAt(i);
|
|
1719
|
+
return (hash >>> 0).toString(36);
|
|
1720
|
+
}
|
|
1721
|
+
|
|
1722
|
+
//#endregion
|
|
1723
|
+
//#region src/channels/plugins/media-limits.ts
|
|
1724
|
+
const MB = 1024 * 1024;
|
|
1725
|
+
function resolveChannelMediaMaxBytes(params) {
|
|
1726
|
+
const accountId = normalizeAccountId$1(params.accountId);
|
|
1727
|
+
const channelLimit = params.resolveChannelLimitMb({
|
|
1728
|
+
cfg: params.cfg,
|
|
1729
|
+
accountId
|
|
1730
|
+
});
|
|
1731
|
+
if (channelLimit) return channelLimit * MB;
|
|
1732
|
+
if (params.cfg.agents?.defaults?.mediaMaxMb) return params.cfg.agents.defaults.mediaMaxMb * MB;
|
|
1733
|
+
}
|
|
1734
|
+
|
|
1735
|
+
//#endregion
|
|
1736
|
+
//#region src/channels/plugins/outbound/load.ts
|
|
1737
|
+
const cache = /* @__PURE__ */ new Map();
|
|
1738
|
+
let lastRegistry = null;
|
|
1739
|
+
function ensureCacheForRegistry(registry) {
|
|
1740
|
+
if (registry === lastRegistry) return;
|
|
1741
|
+
cache.clear();
|
|
1742
|
+
lastRegistry = registry;
|
|
1743
|
+
}
|
|
1744
|
+
async function loadChannelOutboundAdapter(id) {
|
|
1745
|
+
const registry = getActivePluginRegistry();
|
|
1746
|
+
ensureCacheForRegistry(registry);
|
|
1747
|
+
const cached = cache.get(id);
|
|
1748
|
+
if (cached) return cached;
|
|
1749
|
+
const outbound = (registry?.channels.find((entry) => entry.plugin.id === id))?.plugin.outbound;
|
|
1750
|
+
if (outbound) {
|
|
1751
|
+
cache.set(id, outbound);
|
|
1752
|
+
return outbound;
|
|
1753
|
+
}
|
|
1754
|
+
}
|
|
1755
|
+
|
|
1756
|
+
//#endregion
|
|
1757
|
+
//#region src/signal/format.ts
|
|
1758
|
+
function mapStyle(style) {
|
|
1759
|
+
switch (style) {
|
|
1760
|
+
case "bold": return "BOLD";
|
|
1761
|
+
case "italic": return "ITALIC";
|
|
1762
|
+
case "strikethrough": return "STRIKETHROUGH";
|
|
1763
|
+
case "code":
|
|
1764
|
+
case "code_block": return "MONOSPACE";
|
|
1765
|
+
case "spoiler": return "SPOILER";
|
|
1766
|
+
default: return null;
|
|
1767
|
+
}
|
|
1768
|
+
}
|
|
1769
|
+
function mergeStyles(styles) {
|
|
1770
|
+
const sorted = [...styles].toSorted((a, b) => {
|
|
1771
|
+
if (a.start !== b.start) return a.start - b.start;
|
|
1772
|
+
if (a.length !== b.length) return a.length - b.length;
|
|
1773
|
+
return a.style.localeCompare(b.style);
|
|
1774
|
+
});
|
|
1775
|
+
const merged = [];
|
|
1776
|
+
for (const style of sorted) {
|
|
1777
|
+
const prev = merged[merged.length - 1];
|
|
1778
|
+
if (prev && prev.style === style.style && style.start <= prev.start + prev.length) {
|
|
1779
|
+
const prevEnd = prev.start + prev.length;
|
|
1780
|
+
prev.length = Math.max(prevEnd, style.start + style.length) - prev.start;
|
|
1781
|
+
continue;
|
|
1782
|
+
}
|
|
1783
|
+
merged.push({ ...style });
|
|
1784
|
+
}
|
|
1785
|
+
return merged;
|
|
1786
|
+
}
|
|
1787
|
+
function clampStyles(styles, maxLength) {
|
|
1788
|
+
const clamped = [];
|
|
1789
|
+
for (const style of styles) {
|
|
1790
|
+
const start = Math.max(0, Math.min(style.start, maxLength));
|
|
1791
|
+
const length = Math.min(style.start + style.length, maxLength) - start;
|
|
1792
|
+
if (length > 0) clamped.push({
|
|
1793
|
+
start,
|
|
1794
|
+
length,
|
|
1795
|
+
style: style.style
|
|
1796
|
+
});
|
|
1797
|
+
}
|
|
1798
|
+
return clamped;
|
|
1799
|
+
}
|
|
1800
|
+
function applyInsertionsToStyles(spans, insertions) {
|
|
1801
|
+
if (insertions.length === 0) return spans;
|
|
1802
|
+
const sortedInsertions = [...insertions].toSorted((a, b) => a.pos - b.pos);
|
|
1803
|
+
let updated = spans;
|
|
1804
|
+
for (const insertion of sortedInsertions) {
|
|
1805
|
+
const next = [];
|
|
1806
|
+
for (const span of updated) {
|
|
1807
|
+
if (span.end <= insertion.pos) {
|
|
1808
|
+
next.push(span);
|
|
1809
|
+
continue;
|
|
1810
|
+
}
|
|
1811
|
+
if (span.start >= insertion.pos) {
|
|
1812
|
+
next.push({
|
|
1813
|
+
start: span.start + insertion.length,
|
|
1814
|
+
end: span.end + insertion.length,
|
|
1815
|
+
style: span.style
|
|
1816
|
+
});
|
|
1817
|
+
continue;
|
|
1818
|
+
}
|
|
1819
|
+
if (span.start < insertion.pos && span.end > insertion.pos) {
|
|
1820
|
+
if (insertion.pos > span.start) next.push({
|
|
1821
|
+
start: span.start,
|
|
1822
|
+
end: insertion.pos,
|
|
1823
|
+
style: span.style
|
|
1824
|
+
});
|
|
1825
|
+
const shiftedStart = insertion.pos + insertion.length;
|
|
1826
|
+
const shiftedEnd = span.end + insertion.length;
|
|
1827
|
+
if (shiftedEnd > shiftedStart) next.push({
|
|
1828
|
+
start: shiftedStart,
|
|
1829
|
+
end: shiftedEnd,
|
|
1830
|
+
style: span.style
|
|
1831
|
+
});
|
|
1832
|
+
}
|
|
1833
|
+
}
|
|
1834
|
+
updated = next;
|
|
1835
|
+
}
|
|
1836
|
+
return updated;
|
|
1837
|
+
}
|
|
1838
|
+
function renderSignalText(ir) {
|
|
1839
|
+
const text = ir.text ?? "";
|
|
1840
|
+
if (!text) return {
|
|
1841
|
+
text: "",
|
|
1842
|
+
styles: []
|
|
1843
|
+
};
|
|
1844
|
+
const sortedLinks = [...ir.links].toSorted((a, b) => a.start - b.start);
|
|
1845
|
+
let out = "";
|
|
1846
|
+
let cursor = 0;
|
|
1847
|
+
const insertions = [];
|
|
1848
|
+
for (const link of sortedLinks) {
|
|
1849
|
+
if (link.start < cursor) continue;
|
|
1850
|
+
out += text.slice(cursor, link.end);
|
|
1851
|
+
const href = link.href.trim();
|
|
1852
|
+
const trimmedLabel = text.slice(link.start, link.end).trim();
|
|
1853
|
+
const comparableHref = href.startsWith("mailto:") ? href.slice(7) : href;
|
|
1854
|
+
if (href) {
|
|
1855
|
+
if (!trimmedLabel) {
|
|
1856
|
+
out += href;
|
|
1857
|
+
insertions.push({
|
|
1858
|
+
pos: link.end,
|
|
1859
|
+
length: href.length
|
|
1860
|
+
});
|
|
1861
|
+
} else if (trimmedLabel !== href && trimmedLabel !== comparableHref) {
|
|
1862
|
+
const addition = ` (${href})`;
|
|
1863
|
+
out += addition;
|
|
1864
|
+
insertions.push({
|
|
1865
|
+
pos: link.end,
|
|
1866
|
+
length: addition.length
|
|
1867
|
+
});
|
|
1868
|
+
}
|
|
1869
|
+
}
|
|
1870
|
+
cursor = link.end;
|
|
1871
|
+
}
|
|
1872
|
+
out += text.slice(cursor);
|
|
1873
|
+
const adjusted = applyInsertionsToStyles(ir.styles.map((span) => {
|
|
1874
|
+
const mapped = mapStyle(span.style);
|
|
1875
|
+
if (!mapped) return null;
|
|
1876
|
+
return {
|
|
1877
|
+
start: span.start,
|
|
1878
|
+
end: span.end,
|
|
1879
|
+
style: mapped
|
|
1880
|
+
};
|
|
1881
|
+
}).filter((span) => span !== null), insertions);
|
|
1882
|
+
const trimmedText = out.trimEnd();
|
|
1883
|
+
const trimmedLength = trimmedText.length;
|
|
1884
|
+
return {
|
|
1885
|
+
text: trimmedText,
|
|
1886
|
+
styles: mergeStyles(clampStyles(adjusted.map((span) => ({
|
|
1887
|
+
start: span.start,
|
|
1888
|
+
length: span.end - span.start,
|
|
1889
|
+
style: span.style
|
|
1890
|
+
})), trimmedLength))
|
|
1891
|
+
};
|
|
1892
|
+
}
|
|
1893
|
+
function markdownToSignalText(markdown, options = {}) {
|
|
1894
|
+
return renderSignalText(markdownToIR(markdown ?? "", {
|
|
1895
|
+
linkify: true,
|
|
1896
|
+
enableSpoilers: true,
|
|
1897
|
+
headingStyle: "none",
|
|
1898
|
+
blockquotePrefix: "",
|
|
1899
|
+
tableMode: options.tableMode
|
|
1900
|
+
}));
|
|
1901
|
+
}
|
|
1902
|
+
function markdownToSignalTextChunks(markdown, limit, options = {}) {
|
|
1903
|
+
return chunkMarkdownIR(markdownToIR(markdown ?? "", {
|
|
1904
|
+
linkify: true,
|
|
1905
|
+
enableSpoilers: true,
|
|
1906
|
+
headingStyle: "none",
|
|
1907
|
+
blockquotePrefix: "",
|
|
1908
|
+
tableMode: options.tableMode
|
|
1909
|
+
}), limit).map((chunk) => renderSignalText(chunk));
|
|
1910
|
+
}
|
|
1911
|
+
|
|
1912
|
+
//#endregion
|
|
1913
|
+
//#region src/signal/client.ts
|
|
1914
|
+
const DEFAULT_TIMEOUT_MS = 1e4;
|
|
1915
|
+
function normalizeBaseUrl(url) {
|
|
1916
|
+
const trimmed = url.trim();
|
|
1917
|
+
if (!trimmed) throw new Error("Signal base URL is required");
|
|
1918
|
+
if (/^https?:\/\//i.test(trimmed)) return trimmed.replace(/\/+$/, "");
|
|
1919
|
+
return `http://${trimmed}`.replace(/\/+$/, "");
|
|
1920
|
+
}
|
|
1921
|
+
async function fetchWithTimeout(url, init, timeoutMs) {
|
|
1922
|
+
const fetchImpl = resolveFetch();
|
|
1923
|
+
if (!fetchImpl) throw new Error("fetch is not available");
|
|
1924
|
+
const controller = new AbortController();
|
|
1925
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
1926
|
+
try {
|
|
1927
|
+
return await fetchImpl(url, {
|
|
1928
|
+
...init,
|
|
1929
|
+
signal: controller.signal
|
|
1930
|
+
});
|
|
1931
|
+
} finally {
|
|
1932
|
+
clearTimeout(timer);
|
|
1933
|
+
}
|
|
1934
|
+
}
|
|
1935
|
+
async function signalRpcRequest(method, params, opts) {
|
|
1936
|
+
const baseUrl = normalizeBaseUrl(opts.baseUrl);
|
|
1937
|
+
const id = randomUUID();
|
|
1938
|
+
const body = JSON.stringify({
|
|
1939
|
+
jsonrpc: "2.0",
|
|
1940
|
+
method,
|
|
1941
|
+
params,
|
|
1942
|
+
id
|
|
1943
|
+
});
|
|
1944
|
+
const res = await fetchWithTimeout(`${baseUrl}/api/v1/rpc`, {
|
|
1945
|
+
method: "POST",
|
|
1946
|
+
headers: { "Content-Type": "application/json" },
|
|
1947
|
+
body
|
|
1948
|
+
}, opts.timeoutMs ?? DEFAULT_TIMEOUT_MS);
|
|
1949
|
+
if (res.status === 201) return;
|
|
1950
|
+
const text = await res.text();
|
|
1951
|
+
if (!text) throw new Error(`Signal RPC empty response (status ${res.status})`);
|
|
1952
|
+
const parsed = JSON.parse(text);
|
|
1953
|
+
if (parsed.error) {
|
|
1954
|
+
const code = parsed.error.code ?? "unknown";
|
|
1955
|
+
const msg = parsed.error.message ?? "Signal RPC error";
|
|
1956
|
+
throw new Error(`Signal RPC ${code}: ${msg}`);
|
|
1957
|
+
}
|
|
1958
|
+
return parsed.result;
|
|
1959
|
+
}
|
|
1960
|
+
async function signalCheck(baseUrl, timeoutMs = DEFAULT_TIMEOUT_MS) {
|
|
1961
|
+
const normalized = normalizeBaseUrl(baseUrl);
|
|
1962
|
+
try {
|
|
1963
|
+
const res = await fetchWithTimeout(`${normalized}/api/v1/check`, { method: "GET" }, timeoutMs);
|
|
1964
|
+
if (!res.ok) return {
|
|
1965
|
+
ok: false,
|
|
1966
|
+
status: res.status,
|
|
1967
|
+
error: `HTTP ${res.status}`
|
|
1968
|
+
};
|
|
1969
|
+
return {
|
|
1970
|
+
ok: true,
|
|
1971
|
+
status: res.status,
|
|
1972
|
+
error: null
|
|
1973
|
+
};
|
|
1974
|
+
} catch (err) {
|
|
1975
|
+
return {
|
|
1976
|
+
ok: false,
|
|
1977
|
+
status: null,
|
|
1978
|
+
error: err instanceof Error ? err.message : String(err)
|
|
1979
|
+
};
|
|
1980
|
+
}
|
|
1981
|
+
}
|
|
1982
|
+
async function streamSignalEvents(params) {
|
|
1983
|
+
const baseUrl = normalizeBaseUrl(params.baseUrl);
|
|
1984
|
+
const url = new URL(`${baseUrl}/api/v1/events`);
|
|
1985
|
+
if (params.account) url.searchParams.set("account", params.account);
|
|
1986
|
+
const fetchImpl = resolveFetch();
|
|
1987
|
+
if (!fetchImpl) throw new Error("fetch is not available");
|
|
1988
|
+
const res = await fetchImpl(url, {
|
|
1989
|
+
method: "GET",
|
|
1990
|
+
headers: { Accept: "text/event-stream" },
|
|
1991
|
+
signal: params.abortSignal
|
|
1992
|
+
});
|
|
1993
|
+
if (!res.ok || !res.body) throw new Error(`Signal SSE failed (${res.status} ${res.statusText || "error"})`);
|
|
1994
|
+
const reader = res.body.getReader();
|
|
1995
|
+
const decoder = new TextDecoder();
|
|
1996
|
+
let buffer = "";
|
|
1997
|
+
let currentEvent = {};
|
|
1998
|
+
const flushEvent = () => {
|
|
1999
|
+
if (!currentEvent.data && !currentEvent.event && !currentEvent.id) return;
|
|
2000
|
+
params.onEvent({
|
|
2001
|
+
event: currentEvent.event,
|
|
2002
|
+
data: currentEvent.data,
|
|
2003
|
+
id: currentEvent.id
|
|
2004
|
+
});
|
|
2005
|
+
currentEvent = {};
|
|
2006
|
+
};
|
|
2007
|
+
while (true) {
|
|
2008
|
+
const { value, done } = await reader.read();
|
|
2009
|
+
if (done) break;
|
|
2010
|
+
buffer += decoder.decode(value, { stream: true });
|
|
2011
|
+
let lineEnd = buffer.indexOf("\n");
|
|
2012
|
+
while (lineEnd !== -1) {
|
|
2013
|
+
let line = buffer.slice(0, lineEnd);
|
|
2014
|
+
buffer = buffer.slice(lineEnd + 1);
|
|
2015
|
+
if (line.endsWith("\r")) line = line.slice(0, -1);
|
|
2016
|
+
if (line === "") {
|
|
2017
|
+
flushEvent();
|
|
2018
|
+
lineEnd = buffer.indexOf("\n");
|
|
2019
|
+
continue;
|
|
2020
|
+
}
|
|
2021
|
+
if (line.startsWith(":")) {
|
|
2022
|
+
lineEnd = buffer.indexOf("\n");
|
|
2023
|
+
continue;
|
|
2024
|
+
}
|
|
2025
|
+
const [rawField, ...rest] = line.split(":");
|
|
2026
|
+
const field = rawField.trim();
|
|
2027
|
+
const rawValue = rest.join(":");
|
|
2028
|
+
const value = rawValue.startsWith(" ") ? rawValue.slice(1) : rawValue;
|
|
2029
|
+
if (field === "event") currentEvent.event = value;
|
|
2030
|
+
else if (field === "data") currentEvent.data = currentEvent.data ? `${currentEvent.data}\n${value}` : value;
|
|
2031
|
+
else if (field === "id") currentEvent.id = value;
|
|
2032
|
+
lineEnd = buffer.indexOf("\n");
|
|
2033
|
+
}
|
|
2034
|
+
}
|
|
2035
|
+
flushEvent();
|
|
2036
|
+
}
|
|
2037
|
+
|
|
2038
|
+
//#endregion
|
|
2039
|
+
//#region src/signal/send.ts
|
|
2040
|
+
function parseTarget(raw) {
|
|
2041
|
+
let value = raw.trim();
|
|
2042
|
+
if (!value) throw new Error("Signal recipient is required");
|
|
2043
|
+
if (value.toLowerCase().startsWith("signal:")) value = value.slice(7).trim();
|
|
2044
|
+
const normalized = value.toLowerCase();
|
|
2045
|
+
if (normalized.startsWith("group:")) return {
|
|
2046
|
+
type: "group",
|
|
2047
|
+
groupId: value.slice(6).trim()
|
|
2048
|
+
};
|
|
2049
|
+
if (normalized.startsWith("username:")) return {
|
|
2050
|
+
type: "username",
|
|
2051
|
+
username: value.slice(9).trim()
|
|
2052
|
+
};
|
|
2053
|
+
if (normalized.startsWith("u:")) return {
|
|
2054
|
+
type: "username",
|
|
2055
|
+
username: value.trim()
|
|
2056
|
+
};
|
|
2057
|
+
return {
|
|
2058
|
+
type: "recipient",
|
|
2059
|
+
recipient: value
|
|
2060
|
+
};
|
|
2061
|
+
}
|
|
2062
|
+
function buildTargetParams(target, allow) {
|
|
2063
|
+
if (target.type === "recipient") {
|
|
2064
|
+
if (!allow.recipient) return null;
|
|
2065
|
+
return { recipient: [target.recipient] };
|
|
2066
|
+
}
|
|
2067
|
+
if (target.type === "group") {
|
|
2068
|
+
if (!allow.group) return null;
|
|
2069
|
+
return { groupId: target.groupId };
|
|
2070
|
+
}
|
|
2071
|
+
if (target.type === "username") {
|
|
2072
|
+
if (!allow.username) return null;
|
|
2073
|
+
return { username: [target.username] };
|
|
2074
|
+
}
|
|
2075
|
+
return null;
|
|
2076
|
+
}
|
|
2077
|
+
function resolveSignalRpcContext(opts, accountInfo) {
|
|
2078
|
+
const hasBaseUrl = Boolean(opts.baseUrl?.trim());
|
|
2079
|
+
const hasAccount = Boolean(opts.account?.trim());
|
|
2080
|
+
const resolvedAccount = accountInfo || (!hasBaseUrl || !hasAccount ? resolveSignalAccount({
|
|
2081
|
+
cfg: loadConfig(),
|
|
2082
|
+
accountId: opts.accountId
|
|
2083
|
+
}) : void 0);
|
|
2084
|
+
const baseUrl = opts.baseUrl?.trim() || resolvedAccount?.baseUrl;
|
|
2085
|
+
if (!baseUrl) throw new Error("Signal base URL is required");
|
|
2086
|
+
return {
|
|
2087
|
+
baseUrl,
|
|
2088
|
+
account: opts.account?.trim() || resolvedAccount?.config.account?.trim()
|
|
2089
|
+
};
|
|
2090
|
+
}
|
|
2091
|
+
async function resolveAttachment(mediaUrl, maxBytes) {
|
|
2092
|
+
const media = await loadWebMedia(mediaUrl, maxBytes);
|
|
2093
|
+
const saved = await saveMediaBuffer(media.buffer, media.contentType ?? void 0, "outbound", maxBytes);
|
|
2094
|
+
return {
|
|
2095
|
+
path: saved.path,
|
|
2096
|
+
contentType: saved.contentType
|
|
2097
|
+
};
|
|
2098
|
+
}
|
|
2099
|
+
async function sendMessageSignal(to, text, opts = {}) {
|
|
2100
|
+
const cfg = loadConfig();
|
|
2101
|
+
const accountInfo = resolveSignalAccount({
|
|
2102
|
+
cfg,
|
|
2103
|
+
accountId: opts.accountId
|
|
2104
|
+
});
|
|
2105
|
+
const { baseUrl, account } = resolveSignalRpcContext(opts, accountInfo);
|
|
2106
|
+
const target = parseTarget(to);
|
|
2107
|
+
let message = text ?? "";
|
|
2108
|
+
let messageFromPlaceholder = false;
|
|
2109
|
+
let textStyles = [];
|
|
2110
|
+
const textMode = opts.textMode ?? "markdown";
|
|
2111
|
+
const maxBytes = (() => {
|
|
2112
|
+
if (typeof opts.maxBytes === "number") return opts.maxBytes;
|
|
2113
|
+
if (typeof accountInfo.config.mediaMaxMb === "number") return accountInfo.config.mediaMaxMb * 1024 * 1024;
|
|
2114
|
+
if (typeof cfg.agents?.defaults?.mediaMaxMb === "number") return cfg.agents.defaults.mediaMaxMb * 1024 * 1024;
|
|
2115
|
+
return 8 * 1024 * 1024;
|
|
2116
|
+
})();
|
|
2117
|
+
let attachments;
|
|
2118
|
+
if (opts.mediaUrl?.trim()) {
|
|
2119
|
+
const resolved = await resolveAttachment(opts.mediaUrl.trim(), maxBytes);
|
|
2120
|
+
attachments = [resolved.path];
|
|
2121
|
+
const kind = mediaKindFromMime(resolved.contentType ?? void 0);
|
|
2122
|
+
if (!message && kind) {
|
|
2123
|
+
message = kind === "image" ? "<media:image>" : `<media:${kind}>`;
|
|
2124
|
+
messageFromPlaceholder = true;
|
|
2125
|
+
}
|
|
2126
|
+
}
|
|
2127
|
+
if (message.trim() && !messageFromPlaceholder) if (textMode === "plain") textStyles = opts.textStyles ?? [];
|
|
2128
|
+
else {
|
|
2129
|
+
const tableMode = resolveMarkdownTableMode({
|
|
2130
|
+
cfg,
|
|
2131
|
+
channel: "signal",
|
|
2132
|
+
accountId: accountInfo.accountId
|
|
2133
|
+
});
|
|
2134
|
+
const formatted = markdownToSignalText(message, { tableMode });
|
|
2135
|
+
message = formatted.text;
|
|
2136
|
+
textStyles = formatted.styles;
|
|
2137
|
+
}
|
|
2138
|
+
if (!message.trim() && (!attachments || attachments.length === 0)) throw new Error("Signal send requires text or media");
|
|
2139
|
+
const params = { message };
|
|
2140
|
+
if (textStyles.length > 0) params["text-style"] = textStyles.map((style) => `${style.start}:${style.length}:${style.style}`);
|
|
2141
|
+
if (account) params.account = account;
|
|
2142
|
+
if (attachments && attachments.length > 0) params.attachments = attachments;
|
|
2143
|
+
const targetParams = buildTargetParams(target, {
|
|
2144
|
+
recipient: true,
|
|
2145
|
+
group: true,
|
|
2146
|
+
username: true
|
|
2147
|
+
});
|
|
2148
|
+
if (!targetParams) throw new Error("Signal recipient is required");
|
|
2149
|
+
Object.assign(params, targetParams);
|
|
2150
|
+
const timestamp = (await signalRpcRequest("send", params, {
|
|
2151
|
+
baseUrl,
|
|
2152
|
+
timeoutMs: opts.timeoutMs
|
|
2153
|
+
}))?.timestamp;
|
|
2154
|
+
return {
|
|
2155
|
+
messageId: timestamp ? String(timestamp) : "unknown",
|
|
2156
|
+
timestamp
|
|
2157
|
+
};
|
|
2158
|
+
}
|
|
2159
|
+
async function sendTypingSignal(to, opts = {}) {
|
|
2160
|
+
const { baseUrl, account } = resolveSignalRpcContext(opts);
|
|
2161
|
+
const targetParams = buildTargetParams(parseTarget(to), {
|
|
2162
|
+
recipient: true,
|
|
2163
|
+
group: true
|
|
2164
|
+
});
|
|
2165
|
+
if (!targetParams) return false;
|
|
2166
|
+
const params = { ...targetParams };
|
|
2167
|
+
if (account) params.account = account;
|
|
2168
|
+
if (opts.stop) params.stop = true;
|
|
2169
|
+
await signalRpcRequest("sendTyping", params, {
|
|
2170
|
+
baseUrl,
|
|
2171
|
+
timeoutMs: opts.timeoutMs
|
|
2172
|
+
});
|
|
2173
|
+
return true;
|
|
2174
|
+
}
|
|
2175
|
+
async function sendReadReceiptSignal(to, targetTimestamp, opts = {}) {
|
|
2176
|
+
if (!Number.isFinite(targetTimestamp) || targetTimestamp <= 0) return false;
|
|
2177
|
+
const { baseUrl, account } = resolveSignalRpcContext(opts);
|
|
2178
|
+
const targetParams = buildTargetParams(parseTarget(to), { recipient: true });
|
|
2179
|
+
if (!targetParams) return false;
|
|
2180
|
+
const params = {
|
|
2181
|
+
...targetParams,
|
|
2182
|
+
targetTimestamp,
|
|
2183
|
+
type: opts.type ?? "read"
|
|
2184
|
+
};
|
|
2185
|
+
if (account) params.account = account;
|
|
2186
|
+
await signalRpcRequest("sendReceipt", params, {
|
|
2187
|
+
baseUrl,
|
|
2188
|
+
timeoutMs: opts.timeoutMs
|
|
2189
|
+
});
|
|
2190
|
+
return true;
|
|
2191
|
+
}
|
|
2192
|
+
|
|
2193
|
+
//#endregion
|
|
2194
|
+
//#region src/auto-reply/reply/reply-tags.ts
|
|
2195
|
+
function extractReplyToTag(text, currentMessageId) {
|
|
2196
|
+
const result = parseInlineDirectives(text, {
|
|
2197
|
+
currentMessageId,
|
|
2198
|
+
stripAudioTag: false
|
|
2199
|
+
});
|
|
2200
|
+
return {
|
|
2201
|
+
cleaned: result.text,
|
|
2202
|
+
replyToId: result.replyToId,
|
|
2203
|
+
replyToCurrent: result.replyToCurrent,
|
|
2204
|
+
hasTag: result.hasReplyTag
|
|
2205
|
+
};
|
|
2206
|
+
}
|
|
2207
|
+
|
|
2208
|
+
//#endregion
|
|
2209
|
+
//#region src/auto-reply/reply/reply-threading.ts
|
|
2210
|
+
function resolveReplyToMode(cfg, channel, accountId, chatType) {
|
|
2211
|
+
const provider = normalizeChannelId(channel);
|
|
2212
|
+
if (!provider) return "all";
|
|
2213
|
+
return getChannelDock(provider)?.threading?.resolveReplyToMode?.({
|
|
2214
|
+
cfg,
|
|
2215
|
+
accountId,
|
|
2216
|
+
chatType
|
|
2217
|
+
}) ?? "all";
|
|
2218
|
+
}
|
|
2219
|
+
function createReplyToModeFilter(mode, opts = {}) {
|
|
2220
|
+
let hasThreaded = false;
|
|
2221
|
+
return (payload) => {
|
|
2222
|
+
if (!payload.replyToId) return payload;
|
|
2223
|
+
if (mode === "off") {
|
|
2224
|
+
if (opts.allowTagsWhenOff && payload.replyToTag) return payload;
|
|
2225
|
+
return {
|
|
2226
|
+
...payload,
|
|
2227
|
+
replyToId: void 0
|
|
2228
|
+
};
|
|
2229
|
+
}
|
|
2230
|
+
if (mode === "all") return payload;
|
|
2231
|
+
if (hasThreaded) return {
|
|
2232
|
+
...payload,
|
|
2233
|
+
replyToId: void 0
|
|
2234
|
+
};
|
|
2235
|
+
hasThreaded = true;
|
|
2236
|
+
return payload;
|
|
2237
|
+
};
|
|
2238
|
+
}
|
|
2239
|
+
function createReplyToModeFilterForChannel(mode, channel) {
|
|
2240
|
+
const provider = normalizeChannelId(channel);
|
|
2241
|
+
return createReplyToModeFilter(mode, { allowTagsWhenOff: provider ? Boolean(getChannelDock(provider)?.threading?.allowTagsWhenOff) : false });
|
|
2242
|
+
}
|
|
2243
|
+
|
|
2244
|
+
//#endregion
|
|
2245
|
+
//#region src/auto-reply/reply/reply-payloads.ts
|
|
2246
|
+
function applyReplyTagsToPayload(payload, currentMessageId) {
|
|
2247
|
+
if (typeof payload.text !== "string") {
|
|
2248
|
+
if (!payload.replyToCurrent || payload.replyToId) return payload;
|
|
2249
|
+
return {
|
|
2250
|
+
...payload,
|
|
2251
|
+
replyToId: currentMessageId?.trim() || void 0
|
|
2252
|
+
};
|
|
2253
|
+
}
|
|
2254
|
+
if (!payload.text.includes("[[")) {
|
|
2255
|
+
if (!payload.replyToCurrent || payload.replyToId) return payload;
|
|
2256
|
+
return {
|
|
2257
|
+
...payload,
|
|
2258
|
+
replyToId: currentMessageId?.trim() || void 0,
|
|
2259
|
+
replyToTag: payload.replyToTag ?? true
|
|
2260
|
+
};
|
|
2261
|
+
}
|
|
2262
|
+
const { cleaned, replyToId, replyToCurrent, hasTag } = extractReplyToTag(payload.text, currentMessageId);
|
|
2263
|
+
return {
|
|
2264
|
+
...payload,
|
|
2265
|
+
text: cleaned ? cleaned : void 0,
|
|
2266
|
+
replyToId: replyToId ?? payload.replyToId,
|
|
2267
|
+
replyToTag: hasTag || payload.replyToTag,
|
|
2268
|
+
replyToCurrent: replyToCurrent || payload.replyToCurrent
|
|
2269
|
+
};
|
|
2270
|
+
}
|
|
2271
|
+
function isRenderablePayload(payload) {
|
|
2272
|
+
return Boolean(payload.text || payload.mediaUrl || payload.mediaUrls && payload.mediaUrls.length > 0 || payload.audioAsVoice || payload.channelData);
|
|
2273
|
+
}
|
|
2274
|
+
function applyReplyThreading(params) {
|
|
2275
|
+
const { payloads, replyToMode, replyToChannel, currentMessageId } = params;
|
|
2276
|
+
const applyReplyToMode = createReplyToModeFilterForChannel(replyToMode, replyToChannel);
|
|
2277
|
+
return payloads.map((payload) => applyReplyTagsToPayload(payload, currentMessageId)).filter(isRenderablePayload).map(applyReplyToMode);
|
|
2278
|
+
}
|
|
2279
|
+
function filterMessagingToolDuplicates(params) {
|
|
2280
|
+
const { payloads, sentTexts } = params;
|
|
2281
|
+
if (sentTexts.length === 0) return payloads;
|
|
2282
|
+
return payloads.filter((payload) => !isMessagingToolDuplicate(payload.text ?? "", sentTexts));
|
|
2283
|
+
}
|
|
2284
|
+
function normalizeAccountId(value) {
|
|
2285
|
+
const trimmed = value?.trim();
|
|
2286
|
+
return trimmed ? trimmed.toLowerCase() : void 0;
|
|
2287
|
+
}
|
|
2288
|
+
function shouldSuppressMessagingToolReplies(params) {
|
|
2289
|
+
const provider = params.messageProvider?.trim().toLowerCase();
|
|
2290
|
+
if (!provider) return false;
|
|
2291
|
+
const originTarget = normalizeTargetForProvider(provider, params.originatingTo);
|
|
2292
|
+
if (!originTarget) return false;
|
|
2293
|
+
const originAccount = normalizeAccountId(params.accountId);
|
|
2294
|
+
const sentTargets = params.messagingToolSentTargets ?? [];
|
|
2295
|
+
if (sentTargets.length === 0) return false;
|
|
2296
|
+
return sentTargets.some((target) => {
|
|
2297
|
+
if (!target?.provider) return false;
|
|
2298
|
+
if (target.provider.trim().toLowerCase() !== provider) return false;
|
|
2299
|
+
const targetKey = normalizeTargetForProvider(provider, target.to);
|
|
2300
|
+
if (!targetKey) return false;
|
|
2301
|
+
const targetAccount = normalizeAccountId(target.accountId);
|
|
2302
|
+
if (originAccount && targetAccount && originAccount !== targetAccount) return false;
|
|
2303
|
+
return targetKey === originTarget;
|
|
2304
|
+
});
|
|
2305
|
+
}
|
|
2306
|
+
|
|
2307
|
+
//#endregion
|
|
2308
|
+
//#region src/infra/outbound/payloads.ts
|
|
2309
|
+
function mergeMediaUrls(...lists) {
|
|
2310
|
+
const seen = /* @__PURE__ */ new Set();
|
|
2311
|
+
const merged = [];
|
|
2312
|
+
for (const list of lists) {
|
|
2313
|
+
if (!list) continue;
|
|
2314
|
+
for (const entry of list) {
|
|
2315
|
+
const trimmed = entry?.trim();
|
|
2316
|
+
if (!trimmed) continue;
|
|
2317
|
+
if (seen.has(trimmed)) continue;
|
|
2318
|
+
seen.add(trimmed);
|
|
2319
|
+
merged.push(trimmed);
|
|
2320
|
+
}
|
|
2321
|
+
}
|
|
2322
|
+
return merged;
|
|
2323
|
+
}
|
|
2324
|
+
function normalizeReplyPayloadsForDelivery(payloads) {
|
|
2325
|
+
return payloads.flatMap((payload) => {
|
|
2326
|
+
const parsed = parseReplyDirectives(payload.text ?? "");
|
|
2327
|
+
const explicitMediaUrls = payload.mediaUrls ?? parsed.mediaUrls;
|
|
2328
|
+
const explicitMediaUrl = payload.mediaUrl ?? parsed.mediaUrl;
|
|
2329
|
+
const mergedMedia = mergeMediaUrls(explicitMediaUrls, explicitMediaUrl ? [explicitMediaUrl] : void 0);
|
|
2330
|
+
const resolvedMediaUrl = (explicitMediaUrls?.length ?? 0) > 1 ? void 0 : explicitMediaUrl;
|
|
2331
|
+
const next = {
|
|
2332
|
+
...payload,
|
|
2333
|
+
text: parsed.text ?? "",
|
|
2334
|
+
mediaUrls: mergedMedia.length ? mergedMedia : void 0,
|
|
2335
|
+
mediaUrl: resolvedMediaUrl,
|
|
2336
|
+
replyToId: payload.replyToId ?? parsed.replyToId,
|
|
2337
|
+
replyToTag: payload.replyToTag || parsed.replyToTag,
|
|
2338
|
+
replyToCurrent: payload.replyToCurrent || parsed.replyToCurrent,
|
|
2339
|
+
audioAsVoice: Boolean(payload.audioAsVoice || parsed.audioAsVoice)
|
|
2340
|
+
};
|
|
2341
|
+
if (parsed.isSilent && mergedMedia.length === 0) return [];
|
|
2342
|
+
if (!isRenderablePayload(next)) return [];
|
|
2343
|
+
return [next];
|
|
2344
|
+
});
|
|
2345
|
+
}
|
|
2346
|
+
|
|
2347
|
+
//#endregion
|
|
2348
|
+
//#region src/infra/outbound/deliver.ts
|
|
2349
|
+
var deliver_exports = /* @__PURE__ */ __exportAll({ deliverOutboundPayloads: () => deliverOutboundPayloads });
|
|
2350
|
+
function throwIfAborted(abortSignal) {
|
|
2351
|
+
if (abortSignal?.aborted) throw new Error("Outbound delivery aborted");
|
|
2352
|
+
}
|
|
2353
|
+
async function createChannelHandler(params) {
|
|
2354
|
+
const outbound = await loadChannelOutboundAdapter(params.channel);
|
|
2355
|
+
if (!outbound?.sendText || !outbound?.sendMedia) throw new Error(`Outbound not configured for channel: ${params.channel}`);
|
|
2356
|
+
const handler = createPluginHandler({
|
|
2357
|
+
outbound,
|
|
2358
|
+
cfg: params.cfg,
|
|
2359
|
+
channel: params.channel,
|
|
2360
|
+
to: params.to,
|
|
2361
|
+
accountId: params.accountId,
|
|
2362
|
+
replyToId: params.replyToId,
|
|
2363
|
+
threadId: params.threadId,
|
|
2364
|
+
deps: params.deps,
|
|
2365
|
+
gifPlayback: params.gifPlayback
|
|
2366
|
+
});
|
|
2367
|
+
if (!handler) throw new Error(`Outbound not configured for channel: ${params.channel}`);
|
|
2368
|
+
return handler;
|
|
2369
|
+
}
|
|
2370
|
+
function createPluginHandler(params) {
|
|
2371
|
+
const outbound = params.outbound;
|
|
2372
|
+
if (!outbound?.sendText || !outbound?.sendMedia) return null;
|
|
2373
|
+
const sendText = outbound.sendText;
|
|
2374
|
+
const sendMedia = outbound.sendMedia;
|
|
2375
|
+
return {
|
|
2376
|
+
chunker: outbound.chunker ?? null,
|
|
2377
|
+
chunkerMode: outbound.chunkerMode,
|
|
2378
|
+
textChunkLimit: outbound.textChunkLimit,
|
|
2379
|
+
sendPayload: outbound.sendPayload ? async (payload) => outbound.sendPayload({
|
|
2380
|
+
cfg: params.cfg,
|
|
2381
|
+
to: params.to,
|
|
2382
|
+
text: payload.text ?? "",
|
|
2383
|
+
mediaUrl: payload.mediaUrl,
|
|
2384
|
+
accountId: params.accountId,
|
|
2385
|
+
replyToId: params.replyToId,
|
|
2386
|
+
threadId: params.threadId,
|
|
2387
|
+
gifPlayback: params.gifPlayback,
|
|
2388
|
+
deps: params.deps,
|
|
2389
|
+
payload
|
|
2390
|
+
}) : void 0,
|
|
2391
|
+
sendText: async (text) => sendText({
|
|
2392
|
+
cfg: params.cfg,
|
|
2393
|
+
to: params.to,
|
|
2394
|
+
text,
|
|
2395
|
+
accountId: params.accountId,
|
|
2396
|
+
replyToId: params.replyToId,
|
|
2397
|
+
threadId: params.threadId,
|
|
2398
|
+
gifPlayback: params.gifPlayback,
|
|
2399
|
+
deps: params.deps
|
|
2400
|
+
}),
|
|
2401
|
+
sendMedia: async (caption, mediaUrl) => sendMedia({
|
|
2402
|
+
cfg: params.cfg,
|
|
2403
|
+
to: params.to,
|
|
2404
|
+
text: caption,
|
|
2405
|
+
mediaUrl,
|
|
2406
|
+
accountId: params.accountId,
|
|
2407
|
+
replyToId: params.replyToId,
|
|
2408
|
+
threadId: params.threadId,
|
|
2409
|
+
gifPlayback: params.gifPlayback,
|
|
2410
|
+
deps: params.deps
|
|
2411
|
+
})
|
|
2412
|
+
};
|
|
2413
|
+
}
|
|
2414
|
+
async function deliverOutboundPayloads(params) {
|
|
2415
|
+
const { cfg, channel, to, payloads } = params;
|
|
2416
|
+
const accountId = params.accountId;
|
|
2417
|
+
const deps = params.deps;
|
|
2418
|
+
const abortSignal = params.abortSignal;
|
|
2419
|
+
const sendSignal = params.deps?.sendSignal ?? sendMessageSignal;
|
|
2420
|
+
const results = [];
|
|
2421
|
+
const handler = await createChannelHandler({
|
|
2422
|
+
cfg,
|
|
2423
|
+
channel,
|
|
2424
|
+
to,
|
|
2425
|
+
deps,
|
|
2426
|
+
accountId,
|
|
2427
|
+
replyToId: params.replyToId,
|
|
2428
|
+
threadId: params.threadId,
|
|
2429
|
+
gifPlayback: params.gifPlayback
|
|
2430
|
+
});
|
|
2431
|
+
const textLimit = handler.chunker ? resolveTextChunkLimit(cfg, channel, accountId, { fallbackLimit: handler.textChunkLimit }) : void 0;
|
|
2432
|
+
const chunkMode = handler.chunker ? resolveChunkMode(cfg, channel, accountId) : "length";
|
|
2433
|
+
const isSignalChannel = channel === "signal";
|
|
2434
|
+
const signalTableMode = isSignalChannel ? resolveMarkdownTableMode({
|
|
2435
|
+
cfg,
|
|
2436
|
+
channel: "signal",
|
|
2437
|
+
accountId
|
|
2438
|
+
}) : "code";
|
|
2439
|
+
const signalMaxBytes = isSignalChannel ? resolveChannelMediaMaxBytes({
|
|
2440
|
+
cfg,
|
|
2441
|
+
resolveChannelLimitMb: ({ cfg, accountId }) => cfg.channels?.signal?.accounts?.[accountId]?.mediaMaxMb ?? cfg.channels?.signal?.mediaMaxMb,
|
|
2442
|
+
accountId
|
|
2443
|
+
}) : void 0;
|
|
2444
|
+
const sendTextChunks = async (text) => {
|
|
2445
|
+
throwIfAborted(abortSignal);
|
|
2446
|
+
if (!handler.chunker || textLimit === void 0) {
|
|
2447
|
+
results.push(await handler.sendText(text));
|
|
2448
|
+
return;
|
|
2449
|
+
}
|
|
2450
|
+
if (chunkMode === "newline") {
|
|
2451
|
+
const blockChunks = (handler.chunkerMode ?? "text") === "markdown" ? chunkMarkdownTextWithMode(text, textLimit, "newline") : chunkByParagraph(text, textLimit);
|
|
2452
|
+
if (!blockChunks.length && text) blockChunks.push(text);
|
|
2453
|
+
for (const blockChunk of blockChunks) {
|
|
2454
|
+
const chunks = handler.chunker(blockChunk, textLimit);
|
|
2455
|
+
if (!chunks.length && blockChunk) chunks.push(blockChunk);
|
|
2456
|
+
for (const chunk of chunks) {
|
|
2457
|
+
throwIfAborted(abortSignal);
|
|
2458
|
+
results.push(await handler.sendText(chunk));
|
|
2459
|
+
}
|
|
2460
|
+
}
|
|
2461
|
+
return;
|
|
2462
|
+
}
|
|
2463
|
+
const chunks = handler.chunker(text, textLimit);
|
|
2464
|
+
for (const chunk of chunks) {
|
|
2465
|
+
throwIfAborted(abortSignal);
|
|
2466
|
+
results.push(await handler.sendText(chunk));
|
|
2467
|
+
}
|
|
2468
|
+
};
|
|
2469
|
+
const sendSignalText = async (text, styles) => {
|
|
2470
|
+
throwIfAborted(abortSignal);
|
|
2471
|
+
return {
|
|
2472
|
+
channel: "signal",
|
|
2473
|
+
...await sendSignal(to, text, {
|
|
2474
|
+
maxBytes: signalMaxBytes,
|
|
2475
|
+
accountId: accountId ?? void 0,
|
|
2476
|
+
textMode: "plain",
|
|
2477
|
+
textStyles: styles
|
|
2478
|
+
})
|
|
2479
|
+
};
|
|
2480
|
+
};
|
|
2481
|
+
const sendSignalTextChunks = async (text) => {
|
|
2482
|
+
throwIfAborted(abortSignal);
|
|
2483
|
+
let signalChunks = textLimit === void 0 ? markdownToSignalTextChunks(text, Number.POSITIVE_INFINITY, { tableMode: signalTableMode }) : markdownToSignalTextChunks(text, textLimit, { tableMode: signalTableMode });
|
|
2484
|
+
if (signalChunks.length === 0 && text) signalChunks = [{
|
|
2485
|
+
text,
|
|
2486
|
+
styles: []
|
|
2487
|
+
}];
|
|
2488
|
+
for (const chunk of signalChunks) {
|
|
2489
|
+
throwIfAborted(abortSignal);
|
|
2490
|
+
results.push(await sendSignalText(chunk.text, chunk.styles));
|
|
2491
|
+
}
|
|
2492
|
+
};
|
|
2493
|
+
const sendSignalMedia = async (caption, mediaUrl) => {
|
|
2494
|
+
throwIfAborted(abortSignal);
|
|
2495
|
+
const formatted = markdownToSignalTextChunks(caption, Number.POSITIVE_INFINITY, { tableMode: signalTableMode })[0] ?? {
|
|
2496
|
+
text: caption,
|
|
2497
|
+
styles: []
|
|
2498
|
+
};
|
|
2499
|
+
return {
|
|
2500
|
+
channel: "signal",
|
|
2501
|
+
...await sendSignal(to, formatted.text, {
|
|
2502
|
+
mediaUrl,
|
|
2503
|
+
maxBytes: signalMaxBytes,
|
|
2504
|
+
accountId: accountId ?? void 0,
|
|
2505
|
+
textMode: "plain",
|
|
2506
|
+
textStyles: formatted.styles
|
|
2507
|
+
})
|
|
2508
|
+
};
|
|
2509
|
+
};
|
|
2510
|
+
const normalizedPayloads = normalizeReplyPayloadsForDelivery(payloads);
|
|
2511
|
+
for (const payload of normalizedPayloads) {
|
|
2512
|
+
const payloadSummary = {
|
|
2513
|
+
text: payload.text ?? "",
|
|
2514
|
+
mediaUrls: payload.mediaUrls ?? (payload.mediaUrl ? [payload.mediaUrl] : []),
|
|
2515
|
+
channelData: payload.channelData
|
|
2516
|
+
};
|
|
2517
|
+
try {
|
|
2518
|
+
throwIfAborted(abortSignal);
|
|
2519
|
+
params.onPayload?.(payloadSummary);
|
|
2520
|
+
if (handler.sendPayload && payload.channelData) {
|
|
2521
|
+
results.push(await handler.sendPayload(payload));
|
|
2522
|
+
continue;
|
|
2523
|
+
}
|
|
2524
|
+
if (payloadSummary.mediaUrls.length === 0) {
|
|
2525
|
+
if (isSignalChannel) await sendSignalTextChunks(payloadSummary.text);
|
|
2526
|
+
else await sendTextChunks(payloadSummary.text);
|
|
2527
|
+
continue;
|
|
2528
|
+
}
|
|
2529
|
+
let first = true;
|
|
2530
|
+
for (const url of payloadSummary.mediaUrls) {
|
|
2531
|
+
throwIfAborted(abortSignal);
|
|
2532
|
+
const caption = first ? payloadSummary.text : "";
|
|
2533
|
+
first = false;
|
|
2534
|
+
if (isSignalChannel) results.push(await sendSignalMedia(caption, url));
|
|
2535
|
+
else results.push(await handler.sendMedia(caption, url));
|
|
2536
|
+
}
|
|
2537
|
+
} catch (err) {
|
|
2538
|
+
if (!params.bestEffort) throw err;
|
|
2539
|
+
params.onError?.(err, payloadSummary);
|
|
2540
|
+
}
|
|
2541
|
+
}
|
|
2542
|
+
if (params.mirror && results.length > 0) {
|
|
2543
|
+
const mirrorText = resolveMirroredTranscriptText({
|
|
2544
|
+
text: params.mirror.text,
|
|
2545
|
+
mediaUrls: params.mirror.mediaUrls
|
|
2546
|
+
});
|
|
2547
|
+
if (mirrorText) await appendAssistantMessageToSessionTranscript({
|
|
2548
|
+
agentId: params.mirror.agentId,
|
|
2549
|
+
sessionKey: params.mirror.sessionKey,
|
|
2550
|
+
text: mirrorText
|
|
2551
|
+
});
|
|
2552
|
+
}
|
|
2553
|
+
return results;
|
|
2554
|
+
}
|
|
2555
|
+
|
|
2556
|
+
//#endregion
|
|
2557
|
+
export { MediaFetchError as A, resolveTextChunkLimit as B, resolveFetch as C, markdownToIRWithMeta as D, markdownToIR as E, chunkMarkdownText as F, SILENT_REPLY_TOKEN as G, isSafeFenceBreak as H, chunkMarkdownTextWithMode as I, isSilentReplyText as K, chunkText as L, fetchWithSsrFGuard as M, resolveMarkdownTableMode as N, loadWebMedia as O, chunkByNewline as P, chunkTextWithMode as R, parseInlineDirectives as S, chunkMarkdownIR as T, parseFenceSpans as U, findFenceSpanAt as V, HEARTBEAT_TOKEN as W, buildTargetResolverSignature as _, applyReplyThreading as a, parseReplyDirectives as b, shouldSuppressMessagingToolReplies as c, sendMessageSignal as d, sendReadReceiptSignal as f, streamSignalEvents as g, signalRpcRequest as h, applyReplyTagsToPayload as i, fetchRemoteMedia as j, loadWebMediaRaw as k, createReplyToModeFilterForChannel as l, signalCheck as m, deliver_exports as n, filterMessagingToolDuplicates as o, sendTypingSignal as p, normalizeReplyPayloadsForDelivery as r, isRenderablePayload as s, deliverOutboundPayloads as t, resolveReplyToMode as u, normalizeChannelTargetInput as v, wrapFetchWithAbortSignal as w, splitMediaFromOutput as x, normalizeTargetForProvider as y, resolveChunkMode as z };
|