squidclaw 3.0.19 → 3.0.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{accounts-s5e9zidf.js → accounts-C7pGQPcS.js} +2 -2
- package/dist/{accounts-Bkb-J8V6.js → accounts-DjhBQg_8.js} +2 -2
- package/dist/{accounts-B6F_XCgS.js → accounts-DwGoZKGm.js} +17 -17
- package/dist/{active-listener-6-Svu8Dx.js → active-listener-DPc_PGsA.js} +2 -2
- package/dist/{agents-DL8uYsUq.js → agents-DXKtU4Il.js} +4 -4
- package/dist/{agents.config-B4KAAVvR.js → agents.config-BM-2SLCh.js} +1 -1
- package/dist/{agents.config-D93fF1eJ.js → agents.config-eMSUW-iw.js} +1 -1
- package/dist/{plugin-sdk/api-key-rotation-DyjMI2n3.js → api-key-rotation-DVyYtQxC.js} +2 -2
- package/dist/{audio-preflight-DZ1LNMJp.js → audio-preflight-BUCBED7N.js} +32 -32
- package/dist/{audio-preflight-Bzo_zN4j.js → audio-preflight-lT9iRnYi.js} +4 -4
- package/dist/{audio-transcription-runner-B3u2x_ja.js → audio-transcription-runner-Cv0Q47cM.js} +12 -12
- package/dist/{audio-transcription-runner-Cp_lkLCv.js → audio-transcription-runner-YiR1ym3a.js} +1 -1
- package/dist/{audit-membership-runtime-w23FnNAN.js → audit-membership-runtime-DyLj-uhz.js} +4 -4
- package/dist/{auth-choice-Ba4AEm_k.js → auth-choice-CXepQc7c.js} +1 -1
- package/dist/{auth-choice-ziFj5bXd.js → auth-choice-D2JrMJn-.js} +1 -1
- package/dist/{banner-DDih2slD.js → banner-DMfuBV69.js} +1 -1
- package/dist/build-info.json +3 -3
- package/dist/bundled/boot-md/handler.js +51 -51
- package/dist/bundled/bootstrap-extra-files/handler.js +6 -6
- package/dist/bundled/command-logger/handler.js +2 -2
- package/dist/bundled/session-memory/handler.js +687 -51
- package/dist/canvas-host/a2ui/a2ui.bundle.js +1 -17815
- package/dist/{channel-activity-CxJbx4sD.js → channel-activity-CPpt4XaL.js} +3 -3
- package/dist/{channel-options-DTDfU0R6.js → channel-options-CQ-gER0J.js} +1 -1
- package/dist/{channel-options-BBSsevyl.js → channel-options-SijIkAlT.js} +1 -1
- package/dist/{channel-web-BXl9jCKV.js → channel-web-7t1a2N13.js} +1 -1
- package/dist/{channel-web-SF18oYqo.js → channel-web-LLzBxZrT.js} +1 -1
- package/dist/{channels-cli-BiuWJpJu.js → channels-cli-D4xUEYYC.js} +6 -6
- package/dist/{channels-cli-BDLabpWH.js → channels-cli-DYaFNMme.js} +6 -6
- package/dist/{chrome-CZQnp4VH.js → chrome-CuBHInKC.js} +8 -8
- package/dist/{chrome-Dxm25ptH.js → chrome-OgCChbC_.js} +26 -26
- package/dist/{cli-CfgDCCuC.js → cli-CAID9zkL.js} +1 -1
- package/dist/{cli-DAZ1MKrJ.js → cli-Dlc9IFWZ.js} +1 -1
- package/dist/{command-registry-DkjNuW8w.js → command-registry-AHS8_9da.js} +9 -9
- package/dist/{commands-registry-B44COZFz.js → commands-registry-BJjv8_oR.js} +4 -4
- package/dist/{completion-cli-DbNma3J9.js → completion-cli-B8xjpHDs.js} +1 -1
- package/dist/{completion-cli-Du8H92bM.js → completion-cli-BR1r9_h4.js} +2 -2
- package/dist/{config-cli-CQhQ8Bcc.js → config-cli-D0A8Awoo.js} +1 -1
- package/dist/{config-cli-D16tlTWa.js → config-cli-D4Rxoozg.js} +1 -1
- package/dist/{configure-B9b3cQTC.js → configure-DOiI8_8c.js} +3 -3
- package/dist/{configure-B4TiK50K.js → configure-XmOqwwy9.js} +3 -3
- package/dist/control-ui/assets/{index-cM5P_3w7.js → index-BqxuPQOl.js} +2 -2
- package/dist/control-ui/assets/{index-cM5P_3w7.js.map → index-BqxuPQOl.js.map} +1 -1
- package/dist/control-ui/index.html +1 -1
- package/dist/{deliver-B4WWPQvt.js → deliver-6zfT7daI.js} +1 -1
- package/dist/{deliver-BcnsjbAB.js → deliver-DMTUTpTM.js} +21 -21
- package/dist/deliver-runtime-B80olQwJ.js +36 -0
- package/dist/{deliver-runtime-CeE1X9si.js → deliver-runtime-MBexxUuG.js} +3 -3
- package/dist/deps-send-discord.runtime-GIuvX7Xw.js +26 -0
- package/dist/deps-send-imessage.runtime-B3TC7G80.js +25 -0
- package/dist/deps-send-signal.runtime-CuVJyw7n.js +24 -0
- package/dist/deps-send-slack.runtime-cbfFoLZ4.js +22 -0
- package/dist/deps-send-telegram.runtime-CRyP-xDQ.js +27 -0
- package/dist/deps-send-whatsapp.runtime-4aOUBP2J.js +60 -0
- package/dist/{deps-send-whatsapp.runtime-B9uivfkM.js → deps-send-whatsapp.runtime-CETLGt-t.js} +3 -3
- package/dist/{deps-send-whatsapp.runtime-miTfQkK9.js → deps-send-whatsapp.runtime-CrxkfP31.js} +7 -7
- package/dist/{deps-send-whatsapp.runtime-CFnZsKW0.js → deps-send-whatsapp.runtime-__ogpmJj.js} +3 -3
- package/dist/{diagnostic-C2lklhkn.js → diagnostic-CnVwZNbm.js} +2 -2
- package/dist/{doctor-completion-ujZ_JdIz.js → doctor-completion-CZoEdMS-.js} +1 -1
- package/dist/{doctor-completion-CEiVFPte.js → doctor-completion-DhLEFUhN.js} +1 -1
- package/dist/entry.js +2 -2
- package/dist/{plugin-sdk/errors-B8oJXuCF.js → errors-kkRuS2Cs.js} +1 -1
- package/dist/extensionAPI.js +6 -6
- package/dist/{fetch-b8tSR7_e.js → fetch-DP-JjB6Z.js} +5 -5
- package/dist/{fetch-guard-D16tjNsZ.js → fetch-guard-BDy975wP.js} +2 -2
- package/dist/{frontmatter-CjKtFduT.js → frontmatter-Cq1TcIQ2.js} +3 -3
- package/dist/{fs-safe-CwHbZdFH.js → fs-safe-BoB4X3GD.js} +4 -4
- package/dist/{gateway-cli-NXeo-J8r.js → gateway-cli-BJHBChfI.js} +8 -8
- package/dist/{gateway-cli-2jaWM_Ci.js → gateway-cli-BpHskeDd.js} +8 -8
- package/dist/{github-copilot-token-Cw3tAXM9.js → github-copilot-token-B5cPlwaz.js} +7 -7
- package/dist/{health-BPZALM__.js → health-TmpUGSqu.js} +1 -1
- package/dist/{health-DFZKMrW2.js → health-XFKFZ7ZJ.js} +1 -1
- package/dist/{hooks-cli-B3rkhWcT.js → hooks-cli-CXsZK8H9.js} +2 -2
- package/dist/{hooks-cli-BO_gZJVD.js → hooks-cli-DsDV-Pxz.js} +2 -2
- package/dist/{image-DKkuLtZ4.js → image-VgwN31FZ.js} +1 -1
- package/dist/{image-C-8Kd2Mh.js → image-kKMG59st.js} +6 -6
- package/dist/{image-ops-BoN1E_WZ.js → image-ops-Dg8iraUV.js} +2 -2
- package/dist/image-runtime-BqIv7p_K.js +29 -0
- package/dist/{image-runtime-BMavqm9n.js → image-runtime-CwMuTYvd.js} +3 -3
- package/dist/index.js +6 -6
- package/dist/{ir-Dut0zXyS.js → ir-CKK03mBV.js} +8 -8
- package/dist/{legacy-names-B0wgIP0Q.js → legacy-names-aGJJuzM_.js} +1 -1
- package/dist/llm-slug-generator.js +51 -51
- package/dist/{logger-oGKcCLZ5.js → logger-CnTSBL7T.js} +7 -7
- package/dist/{login-DJ357UQV.js → login-CeKDrz6_.js} +5 -5
- package/dist/{login-qr-C0fDBnpM.js → login-qr-KbOpR0GQ.js} +10 -10
- package/dist/{manager-BPGhs30n.js → manager-DINhLnMi.js} +13 -13
- package/dist/manager-runtime-D6ckUNSs.js +18 -0
- package/dist/{model-selection-CHnojCCK.js → model-selection-DuNLFQPR.js} +43 -43
- package/dist/{models-Bb-GYqHr.js → models-5VXwJBU2.js} +2 -2
- package/dist/{models-cli-DffAz0ji.js → models-cli-Br56IHfy.js} +3 -3
- package/dist/{models-cli-CAIJM1Wh.js → models-cli-CrR1RN3j.js} +2 -2
- package/dist/{npm-resolution-D2_zGJM-.js → npm-resolution-CKtyq4FH.js} +1 -1
- package/dist/{npm-resolution-D5pBCkUw.js → npm-resolution-CPk7dS7F.js} +1 -1
- package/dist/{onboard-DcVsL9Jx.js → onboard-DUnBamC0.js} +2 -2
- package/dist/{onboard-channels-mNXKTvFs.js → onboard-channels-D45grihx.js} +1 -1
- package/dist/{onboard-channels-C-cQFUBH.js → onboard-channels-_kVo3Apf.js} +1 -1
- package/dist/{onboard-dhG2YBez.js → onboard-lFwpCpC3.js} +2 -2
- package/dist/{onboarding-B3-IwkNi.js → onboarding-CyCSQ__q.js} +3 -3
- package/dist/{onboarding-Cl6kW_iq.js → onboarding-EEd_g8Zg.js} +3 -3
- package/dist/{onboarding.finalize-CCU-ykTR.js → onboarding.finalize-CbMq7C4K.js} +5 -5
- package/dist/{onboarding.finalize-BZqsNG2H.js → onboarding.finalize-Cs1ukjFN.js} +6 -6
- package/dist/{outbound-qTioiTJg.js → outbound-C9svt6RH.js} +6 -6
- package/dist/{outbound-attachment-rlW7G5df.js → outbound-attachment-DwupUxYF.js} +2 -2
- package/dist/{path-alias-guards-Cpsiv2KL.js → path-alias-guards-DORgbZ1w.js} +1 -1
- package/dist/{paths-CSdAWKDO.js → paths-DA5srn0U.js} +5 -5
- package/dist/{paths-CXClY8zC.js → paths-DSd911Oe.js} +4 -4
- package/dist/{pi-embedded-B79nZERv.js → pi-embedded-BN8fghaF.js} +123 -26
- package/dist/{pi-embedded-C5U8Qxn6.js → pi-embedded-BiC4tIJ8.js} +266 -169
- package/dist/{pi-embedded-helpers-CEHpGDRs.js → pi-embedded-helpers-A9VYPVCH.js} +3 -3
- package/dist/{pi-embedded-helpers-DQ7IaeOi.js → pi-embedded-helpers-Di58J7Eh.js} +52 -52
- package/dist/{pi-model-discovery-o-WX5w2t.js → pi-model-discovery-V-InbjOM.js} +7 -7
- package/dist/pi-model-discovery-runtime--t6tAlar.js +11 -0
- package/dist/{pi-tools.before-tool-call.runtime-B_LUttg1.js → pi-tools.before-tool-call.runtime-Bpk4qTgV.js} +9 -9
- package/dist/{plugin-registry-CB47SSz1.js → plugin-registry-CXm125Uz.js} +1 -1
- package/dist/{plugin-registry-Gy_VByyf.js → plugin-registry-D3PnPE1D.js} +1 -1
- package/dist/plugin-sdk/{accounts-0kF5cxkn.js → accounts-C5PAuCTj.js} +2 -2
- package/dist/plugin-sdk/{accounts-u0-JAHzj.js → accounts-DC5cbH9r.js} +2 -2
- package/dist/plugin-sdk/{accounts-xZOA23tQ.js → accounts-DncG0Hx9.js} +3 -3
- package/dist/plugin-sdk/{active-listener-BO7eBEG_.js → active-listener-Bd3HH2km.js} +2 -2
- package/dist/plugin-sdk/agents/agent-tier.d.ts +22 -2
- package/dist/plugin-sdk/{api-key-rotation-C4C_mDsg.js → api-key-rotation-BAZ0GD26.js} +2 -2
- package/dist/plugin-sdk/{audio-preflight-C0q7lu6y.js → audio-preflight-tpVm-t9O.js} +26 -26
- package/dist/plugin-sdk/{audio-transcription-runner-Ced47O1H.js → audio-transcription-runner-DSScb434.js} +11 -11
- package/dist/plugin-sdk/{audit-membership-runtime-Xl20kCBe.js → audit-membership-runtime-DHQDvH4u.js} +2 -2
- package/dist/plugin-sdk/{channel-activity-CNffKOEQ.js → channel-activity-cYEaofTH.js} +3 -3
- package/dist/plugin-sdk/{channel-web-vB3Dcd8-.js → channel-web-CbeCrQ4C.js} +18 -18
- package/dist/plugin-sdk/{channel-web-BrhP6FQO.js → channel-web-CqiSEc52.js} +1 -1
- package/dist/plugin-sdk/{chrome-DJQWo149.js → chrome-DB2h0uN0.js} +6 -6
- package/dist/plugin-sdk/{commands-registry-_kBPE22q.js → commands-registry-DGZ1oFXJ.js} +4 -4
- package/dist/plugin-sdk/{common-J8vIST9Q.js → common-D5lLWoCW.js} +2 -2
- package/dist/plugin-sdk/compat.js +50 -50
- package/dist/plugin-sdk/{config-CnZ1TlEw.js → config-Bt-c7PWF.js} +7 -7
- package/dist/plugin-sdk/{deliver-Xh6voz9H.js → deliver-MvrkIeKJ.js} +10 -10
- package/dist/plugin-sdk/deliver-runtime-i50kjcNM.js +32 -0
- package/dist/plugin-sdk/deps-send-discord.runtime-hOYq9ov0.js +23 -0
- package/dist/plugin-sdk/deps-send-imessage.runtime-D5n9DXyL.js +22 -0
- package/dist/plugin-sdk/deps-send-signal.runtime-CwEaRyJU.js +21 -0
- package/dist/plugin-sdk/deps-send-slack.runtime-DOZeLIaC.js +19 -0
- package/dist/plugin-sdk/deps-send-telegram.runtime-BW1hSPKh.js +24 -0
- package/dist/plugin-sdk/{deps-send-whatsapp.runtime-Ce4Gzz-J.js → deps-send-whatsapp.runtime-DvxhnHR_.js} +3 -3
- package/dist/plugin-sdk/deps-send-whatsapp.runtime-JKmTtCFM.js +57 -0
- package/dist/plugin-sdk/{diagnostic-DKsyROPi.js → diagnostic-B6F3BtCX.js} +2 -2
- package/dist/plugin-sdk/{errors-CgRPdp3o.js → errors-9oVz7reJ.js} +1 -1
- package/dist/plugin-sdk/{fetch-guard-BBAT8G-1.js → fetch-guard-cfPCfkrw.js} +2 -2
- package/dist/plugin-sdk/{fs-safe-DqCO1D4C.js → fs-safe-DFbwq9CS.js} +3 -3
- package/dist/plugin-sdk/{image-4ay2cw7G.js → image-FK5xhY5u.js} +6 -6
- package/dist/plugin-sdk/{image-ops-G8KoEfY8.js → image-ops-BSYgrL7E.js} +2 -2
- package/dist/plugin-sdk/image-runtime-B95EPFpg.js +25 -0
- package/dist/plugin-sdk/index.js +2 -2
- package/dist/plugin-sdk/{ir-DXj1KGnL.js → ir-CWmryq5f.js} +7 -7
- package/dist/plugin-sdk/{local-roots-ovKHgVSP.js → local-roots-U25IdeDH.js} +4 -4
- package/dist/plugin-sdk/{logger-DIb2cGHp.js → logger-Bg4vIUJn.js} +2 -2
- package/dist/plugin-sdk/{login-Cgtm70by.js → login-8qzl2H7G.js} +4 -4
- package/dist/plugin-sdk/{login-qr-BrixqhMx.js → login-qr-kalCTJEw.js} +5 -5
- package/dist/plugin-sdk/{manager-PEQ_cPYF.js → manager-ijYHktIt.js} +8 -8
- package/dist/plugin-sdk/manager-runtime--JrLQE03.js +15 -0
- package/dist/plugin-sdk/{outbound-BK75h9CQ.js → outbound-BIVf0aPq.js} +5 -5
- package/dist/plugin-sdk/{outbound-attachment-BI1QngTS.js → outbound-attachment-F5tzeNUD.js} +2 -2
- package/dist/plugin-sdk/{path-alias-guards-TnxupPQC.js → path-alias-guards-DA0MhfkG.js} +1 -1
- package/dist/plugin-sdk/{paths-B7_75Pdr.js → paths-CP67O8eN.js} +1 -1
- package/dist/plugin-sdk/{pi-embedded-helpers-BioULNev.js → pi-embedded-helpers-CxMnPQ37.js} +16 -16
- package/dist/plugin-sdk/{pi-model-discovery-BMmAbnil.js → pi-model-discovery-8OL77kCh.js} +1 -1
- package/dist/plugin-sdk/pi-model-discovery-runtime-DGRFpUfd.js +8 -0
- package/dist/plugin-sdk/{pi-tools.before-tool-call.runtime-rdRqZ9lk.js → pi-tools.before-tool-call.runtime-B7FW36KX.js} +4 -4
- package/dist/plugin-sdk/{plugins-BqKpJkqt.js → plugins-D3mrhffi.js} +4 -4
- package/dist/plugin-sdk/{proxy-env-C4s12rr8.js → proxy-env-CUUXO6rv.js} +1 -1
- package/dist/plugin-sdk/{proxy-fetch-ZPEvp58f.js → proxy-fetch-Cf3IUSDw.js} +1 -1
- package/dist/plugin-sdk/{pw-ai-Cb0ZDSq4.js → pw-ai-dPmKdw_w.js} +9 -9
- package/dist/plugin-sdk/{qmd-manager-Bei6TaFq.js → qmd-manager-Ov9ElEfG.js} +7 -7
- package/dist/plugin-sdk/{query-expansion-POz2za8a.js → query-expansion-CzjwW461.js} +4 -4
- package/dist/plugin-sdk/{redact-9WsNyb7S.js → redact-DfACyt0X.js} +1 -1
- package/dist/plugin-sdk/{reply-DxvpiQBp.js → reply-BczXGzC_.js} +137 -40
- package/dist/plugin-sdk/{reply-sFKB3ofA.js → reply-Dfjh1YtV.js} +206 -109
- package/dist/plugin-sdk/{resolve-outbound-target-DL1adXpk.js → resolve-outbound-target-BeIB_jm0.js} +2 -2
- package/dist/plugin-sdk/{run-with-concurrency-DmTrN5JG.js → run-with-concurrency-kVooFCVo.js} +1 -1
- package/dist/plugin-sdk/runtime-whatsapp-login.runtime-B6EcC22F.js +10 -0
- package/dist/plugin-sdk/runtime-whatsapp-outbound.runtime-DH8J0Ie7.js +19 -0
- package/dist/plugin-sdk/{send-BCVXt-3e.js → send-CgkNzAhS.js} +8 -8
- package/dist/plugin-sdk/{send-CAG0Or0G.js → send-CuENGOhq.js} +7 -7
- package/dist/plugin-sdk/{send-X6QuS7x0.js → send-D6Uh2D1D.js} +5 -5
- package/dist/plugin-sdk/{send-BNePC8CO.js → send-DV5kR0Hg.js} +6 -6
- package/dist/plugin-sdk/{send-DhGDAZnT.js → send-DtA6ngBJ.js} +13 -13
- package/dist/plugin-sdk/{session-CAqYQVhe.js → session-CnlZn-bR.js} +3 -3
- package/dist/plugin-sdk/{skill-commands-Bk-IFyNw.js → skill-commands-Ckfii7h8.js} +4 -4
- package/dist/plugin-sdk/{skills-C5bT9-q4.js → skills-v0WQqKTa.js} +6 -6
- package/dist/plugin-sdk/slash-commands.runtime-BYoxsxkX.js +13 -0
- package/dist/plugin-sdk/{slash-dispatch.runtime-Dyb_EkUt.js → slash-dispatch.runtime-DOo1IzuY.js} +1 -1
- package/dist/plugin-sdk/slash-dispatch.runtime-JfFr7bNy.js +52 -0
- package/dist/plugin-sdk/slash-skill-commands.runtime-D0399tia.js +16 -0
- package/dist/plugin-sdk/{store-D3lgWnS2.js → store-C_UrNuM3.js} +2 -2
- package/dist/plugin-sdk/{subagent-registry-runtime-hdnabonI.js → subagent-registry-runtime-DLvup9ph.js} +1 -1
- package/dist/plugin-sdk/subagent-registry-runtime-DVl5xKOW.js +52 -0
- package/dist/plugin-sdk/{tables-Dmlu4_q_.js → tables-CJP05iMa.js} +1 -1
- package/dist/plugin-sdk/{thinking-DRNOh5Xx.js → thinking-BhP3vn1l.js} +7 -7
- package/dist/plugin-sdk/{tokens-CTIYTLWu.js → tokens-DAL_5WHL.js} +1 -1
- package/dist/plugin-sdk/{tool-images-GSlvf6RP.js → tool-images-ZE5G5UM0.js} +2 -2
- package/dist/plugin-sdk/{web-D9LAdsuU.js → web-C2Sj2WW0.js} +2 -2
- package/dist/plugin-sdk/web-CNY_ky8h.js +56 -0
- package/dist/plugin-sdk/{whatsapp-actions-BCJYmWCB.js → whatsapp-actions-DJmx6ihj.js} +17 -17
- package/dist/plugin-sdk/whatsapp.js +50 -50
- package/dist/{plugins-AqsVZZk3.js → plugins-DvejjZnJ.js} +11 -11
- package/dist/{plugins-cli-BYnoJwF1.js → plugins-cli-BA_2daJe.js} +2 -2
- package/dist/{plugins-cli-gtgkmDcv.js → plugins-cli-C0WKWrZo.js} +2 -2
- package/dist/{program-BGlgDpHI.js → program-D_xdLzmM.js} +7 -7
- package/dist/{program-context-M4FTWqqg.js → program-context-DfmCIQ91.js} +17 -17
- package/dist/{prompt-select-styled-AL5Tm3yO.js → prompt-select-styled-ApPSadr5.js} +4 -4
- package/dist/{prompt-select-styled-BVC2byQV.js → prompt-select-styled-BsheNEnh.js} +4 -4
- package/dist/{provider-auth-helpers-DDgrFku5.js → provider-auth-helpers-B5kD4Lt6.js} +1 -1
- package/dist/{provider-auth-helpers-Q7aIhDgv.js → provider-auth-helpers-DpOFkV28.js} +1 -1
- package/dist/{proxy-env-DXXfs2WL.js → proxy-env-D-fike7s.js} +1 -1
- package/dist/{plugin-sdk/proxy-fetch-Dt5BedH8.js → proxy-fetch-lH6RsRTE.js} +1 -1
- package/dist/{push-apns-Ga8xvhkh.js → push-apns-BbenjEX4.js} +1 -1
- package/dist/{push-apns-FyGbUyh2.js → push-apns-Ci2sdIKf.js} +1 -1
- package/dist/{pw-ai-GOBxzChI.js → pw-ai-B8ymIYub.js} +14 -14
- package/dist/{pw-ai-Du22SYoO.js → pw-ai-CM87tQwG.js} +1 -1
- package/dist/{qmd-manager-CO-shcLU.js → qmd-manager-BN0siR2Z.js} +10 -10
- package/dist/{query-expansion-DlQOkf-g.js → query-expansion-Dzxt6kXo.js} +6 -6
- package/dist/{redact-NmPEVjIo.js → redact-DvzicBMu.js} +1 -1
- package/dist/{register.agent-koAXw1ay.js → register.agent-CY6R-7fn.js} +6 -6
- package/dist/{register.agent-zP8a-sNB.js → register.agent-Dk_5V5oA.js} +7 -7
- package/dist/{register.configure-CUuP5J8W.js → register.configure-C8OFfGln.js} +7 -7
- package/dist/{register.configure-CYrmyjlf.js → register.configure-DT1RLeTR.js} +7 -7
- package/dist/{register.maintenance-BZuEljPU.js → register.maintenance-CluQOq8b.js} +8 -8
- package/dist/{register.maintenance-ByEQ2CVH.js → register.maintenance-YHXmOQzf.js} +7 -7
- package/dist/{register.message-BkSXhv9I.js → register.message-BCTXT5yK.js} +2 -2
- package/dist/{register.message-CgHfmDHm.js → register.message-BuoFjRqA.js} +2 -2
- package/dist/{register.onboard-HcQwPAEK.js → register.onboard-BJaRMtxU.js} +2 -2
- package/dist/{register.onboard-4ke40MNP.js → register.onboard-C64oXnvq.js} +2 -2
- package/dist/{register.setup-B41xZb1r.js → register.setup-Dl3nk2Ui.js} +2 -2
- package/dist/{register.setup-xAb7Cvzy.js → register.setup-Drc55K_w.js} +2 -2
- package/dist/{register.status-health-sessions-CcOVL0x8.js → register.status-health-sessions-BHtbPeCO.js} +3 -3
- package/dist/{register.status-health-sessions-BbHAAKwv.js → register.status-health-sessions-xgC_gtEM.js} +3 -3
- package/dist/{register.subclis-_uSASnfC.js → register.subclis-CDMFyaKR.js} +9 -9
- package/dist/{reply-BFTOdZcK.js → reply-DwjHsBuj.js} +137 -40
- package/dist/{run-main-C1eZrW-5.js → run-main-BcA22Ipv.js} +14 -14
- package/dist/{run-with-concurrency-FczpX8ng.js → run-with-concurrency-BFR3ReeF.js} +4 -4
- package/dist/runtime-whatsapp-login.runtime-DxV9iv6l.js +13 -0
- package/dist/runtime-whatsapp-outbound.runtime-DQqIlwhS.js +22 -0
- package/dist/{send-Bx9CqcZr.js → send-4nRsZJXH.js} +7 -7
- package/dist/{send-D5D0ZGht.js → send-BGlcHjUD.js} +26 -26
- package/dist/{send-DtHQ7_6Z.js → send-BTUU1jWM.js} +8 -8
- package/dist/{send-B9H0BkfO.js → send-DdBbRpTP.js} +6 -6
- package/dist/{send-B5QEmMJ4.js → send-dTQd-IyJ.js} +5 -5
- package/dist/{server-node-events-pYrJmi9w.js → server-node-events-Q0cT2ifj.js} +2 -2
- package/dist/{server-node-events-DbS1jJ5j.js → server-node-events-YN5eJeHa.js} +2 -2
- package/dist/{session-DLTCuoUD.js → session-CnCwDJke.js} +8 -8
- package/dist/{skill-commands-BwTLQRR8.js → skill-commands-Cz45_nme.js} +9 -9
- package/dist/{skills-B9N2bqKU.js → skills-CdCS1HeL.js} +22 -22
- package/dist/slash-commands.runtime-CZz6v6b3.js +16 -0
- package/dist/{slash-dispatch.runtime-PX9_08Hm.js → slash-dispatch.runtime-BOMEVFk0.js} +1 -1
- package/dist/{slash-dispatch.runtime-DmFVOi3w.js → slash-dispatch.runtime-DB1QsBRc.js} +1 -1
- package/dist/slash-dispatch.runtime-SO7HOe8q.js +56 -0
- package/dist/{slash-dispatch.runtime-BGXbtMX6.js → slash-dispatch.runtime-sXaUYn4v.js} +6 -6
- package/dist/slash-skill-commands.runtime-Bawt7j0r.js +20 -0
- package/dist/{status-DtiapFqq.js → status-Bh5x6DsW.js} +2 -2
- package/dist/{status-B4eVRJcO.js → status-cU9cJReo.js} +2 -2
- package/dist/{store-CvQ41zCV.js → store-D9z0dn7D.js} +2 -2
- package/dist/{subagent-registry-Ctrhw4X-.js → subagent-registry-CIgFD2oi.js} +103 -6
- package/dist/{subagent-registry-runtime-CezPaX9P.js → subagent-registry-runtime-232sNNT6.js} +6 -6
- package/dist/subagent-registry-runtime-D2rUxU5J.js +56 -0
- package/dist/{subagent-registry-runtime-Cy7dsGqF.js → subagent-registry-runtime-D7ubAnDZ.js} +1 -1
- package/dist/{subagent-registry-runtime-CTjx4TK5.js → subagent-registry-runtime-DGTjU9Lb.js} +1 -1
- package/dist/{subsystem-BaLYRf7D.js → subsystem-6v7sWnAD.js} +14 -14
- package/dist/{tables-BRYYxYs7.js → tables-BTFiZyRU.js} +1 -1
- package/dist/{target-errors-D0ZJUbbf.js → target-errors-DgNRx3Nr.js} +2 -2
- package/dist/{thinking-B-A99X3F.js → thinking-B75CXkTT.js} +7 -7
- package/dist/{tokens-D2XhLqIz.js → tokens-DfbMVF9y.js} +1 -1
- package/dist/{tool-images-Zn6jVmkX.js → tool-images-Dp5OiXeA.js} +2 -2
- package/dist/{update-cli-_FsTRdQZ.js → update-cli-CktBOXZF.js} +7 -7
- package/dist/{update-cli-DLOWRdjv.js → update-cli-DM_dUip_.js} +8 -8
- package/dist/{update-runner-BY3l7ytB.js → update-runner-BBJZmfZ4.js} +1 -1
- package/dist/{update-runner-BKWHnVYI.js → update-runner-BYGPkHXG.js} +1 -1
- package/dist/{web-BdZ3mX3p.js → web-CZhZC1EA.js} +2 -2
- package/dist/{web-B46aOGK0.js → web-Chw1dtKA.js} +6 -6
- package/dist/{web-BNfDYvlW.js → web-DWRZAXj9.js} +2 -2
- package/dist/{web-1D0d1RHD.js → web-QsxgXbNK.js} +55 -55
- package/dist/{whatsapp-actions-Cuy0qeQK.js → whatsapp-actions-CzqsuSGx.js} +21 -21
- package/dist/{workspace-TqfVSQuO.js → workspace-kVMIaBrV.js} +20 -20
- package/extensions/acpx/node_modules/.bin/acpx +2 -2
- package/extensions/diagnostics-otel/node_modules/.bin/acorn +2 -2
- package/extensions/diffs/node_modules/.bin/playwright-core +2 -2
- package/extensions/googlechat/node_modules/.bin/squidclaw +2 -2
- package/extensions/matrix/node_modules/.bin/markdown-it +2 -2
- package/extensions/memory-core/node_modules/.bin/squidclaw +2 -2
- package/extensions/memory-lancedb/node_modules/.bin/arrow2csv +2 -2
- package/extensions/memory-lancedb/node_modules/.bin/openai +2 -2
- package/extensions/nostr/node_modules/.bin/tsc +2 -2
- package/extensions/nostr/node_modules/.bin/tsserver +2 -2
- package/extensions/tlon/node_modules/.bin/tlon +2 -2
- package/package.json +1 -1
- package/dist/api-key-rotation-TRwuCWbu.js +0 -181
- package/dist/canvas-host/a2ui/.bundle.hash +0 -1
- package/dist/deliver-runtime-_mBfV_4S.js +0 -36
- package/dist/deps-send-discord.runtime-CUTAK2hy.js +0 -26
- package/dist/deps-send-imessage.runtime-CQOiEIuA.js +0 -25
- package/dist/deps-send-signal.runtime-wN7MkzLw.js +0 -24
- package/dist/deps-send-slack.runtime-HEEwW4uU.js +0 -22
- package/dist/deps-send-telegram.runtime-DHlcnjQO.js +0 -27
- package/dist/deps-send-whatsapp.runtime-Cw7U9orE.js +0 -60
- package/dist/errors-DfgAh2Ml.js +0 -54
- package/dist/export-html/vendor/highlight.min.js +0 -1213
- package/dist/export-html/vendor/marked.min.js +0 -6
- package/dist/image-runtime-D11wBIC8.js +0 -29
- package/dist/manager-runtime-BB9lcoFR.js +0 -18
- package/dist/pi-model-discovery-runtime-DBkQoIJw.js +0 -11
- package/dist/plugin-sdk/accounts-CUEuUR3C.js +0 -46
- package/dist/plugin-sdk/accounts-D0W2pELU.js +0 -288
- package/dist/plugin-sdk/accounts-ucj0odJq.js +0 -35
- package/dist/plugin-sdk/active-listener-C5xPUSTb.js +0 -50
- package/dist/plugin-sdk/audio-preflight-Cqdo0JKm.js +0 -69
- package/dist/plugin-sdk/audio-transcription-runner-DnEooIyE.js +0 -2176
- package/dist/plugin-sdk/audit-membership-runtime-B9b-zRwg.js +0 -58
- package/dist/plugin-sdk/channel-activity-BMWLw4o2.js +0 -94
- package/dist/plugin-sdk/channel-web-D9WdAFlv.js +0 -2256
- package/dist/plugin-sdk/chrome-CV-q0Lmc.js +0 -2415
- package/dist/plugin-sdk/commands-registry-e7YoqrbP.js +0 -1125
- package/dist/plugin-sdk/config-B2B64aX0.js +0 -17911
- package/dist/plugin-sdk/deliver-BkyBtcLR.js +0 -1694
- package/dist/plugin-sdk/deliver-runtime-5UVcSskg.js +0 -32
- package/dist/plugin-sdk/deliver-runtime-O4lwAWMw.js +0 -32
- package/dist/plugin-sdk/deps-send-discord.runtime-BAeeBldY.js +0 -23
- package/dist/plugin-sdk/deps-send-discord.runtime-DTspXSCt.js +0 -23
- package/dist/plugin-sdk/deps-send-imessage.runtime-EL-CfikZ.js +0 -22
- package/dist/plugin-sdk/deps-send-imessage.runtime-qThAwDEe.js +0 -22
- package/dist/plugin-sdk/deps-send-signal.runtime-BeemHeUu.js +0 -21
- package/dist/plugin-sdk/deps-send-signal.runtime-DnjnVzZF.js +0 -21
- package/dist/plugin-sdk/deps-send-slack.runtime-CbKevLnv.js +0 -19
- package/dist/plugin-sdk/deps-send-slack.runtime-DTttkC0N.js +0 -19
- package/dist/plugin-sdk/deps-send-telegram.runtime-C6y29O9E.js +0 -24
- package/dist/plugin-sdk/deps-send-telegram.runtime-Dsf9Cnka.js +0 -24
- package/dist/plugin-sdk/deps-send-whatsapp.runtime-CCS71r77.js +0 -57
- package/dist/plugin-sdk/deps-send-whatsapp.runtime-CuxKhIE0.js +0 -57
- package/dist/plugin-sdk/diagnostic-DPRVoKTk.js +0 -319
- package/dist/plugin-sdk/fetch-guard-F0Fnqisy.js +0 -156
- package/dist/plugin-sdk/fs-safe-Dqmpk-Fr.js +0 -352
- package/dist/plugin-sdk/image-cBW8L8pp.js +0 -2310
- package/dist/plugin-sdk/image-ops-BP8ix1GC.js +0 -584
- package/dist/plugin-sdk/image-runtime-9xkgSlNz.js +0 -25
- package/dist/plugin-sdk/image-runtime-CpfepTDc.js +0 -25
- package/dist/plugin-sdk/ir-DWEc6zOp.js +0 -1296
- package/dist/plugin-sdk/local-roots-BIPT8uAO.js +0 -186
- package/dist/plugin-sdk/logger-DDdrdbDu.js +0 -1163
- package/dist/plugin-sdk/login-BMTiGutN.js +0 -57
- package/dist/plugin-sdk/login-qr-BFxqYUkc.js +0 -320
- package/dist/plugin-sdk/manager-BD-aYaZ8.js +0 -3917
- package/dist/plugin-sdk/manager-runtime-BmgTeb5G.js +0 -15
- package/dist/plugin-sdk/manager-runtime-C5bRwUlz.js +0 -15
- package/dist/plugin-sdk/outbound-Bm07xvO6.js +0 -212
- package/dist/plugin-sdk/outbound-attachment-DLsaxDsc.js +0 -19
- package/dist/plugin-sdk/path-alias-guards-gBhrAn14.js +0 -43
- package/dist/plugin-sdk/paths-C6W4VHoa.js +0 -166
- package/dist/plugin-sdk/pi-embedded-helpers-BExwPvTh.js +0 -9627
- package/dist/plugin-sdk/pi-model-discovery-DdctvBeX.js +0 -134
- package/dist/plugin-sdk/pi-model-discovery-runtime-COnuGwZt.js +0 -8
- package/dist/plugin-sdk/pi-model-discovery-runtime-DrtpLJjk.js +0 -8
- package/dist/plugin-sdk/pi-tools.before-tool-call.runtime-rgTz3FBl.js +0 -354
- package/dist/plugin-sdk/plugins-BN64HHZA.js +0 -864
- package/dist/plugin-sdk/pw-ai-DBm3RdBK.js +0 -1938
- package/dist/plugin-sdk/qmd-manager-6bozlfFg.js +0 -1448
- package/dist/plugin-sdk/query-expansion-eeVz_aEm.js +0 -1011
- package/dist/plugin-sdk/redact-BoNEjbpF.js +0 -319
- package/dist/plugin-sdk/reply-CqXMy3Yd.js +0 -98731
- package/dist/plugin-sdk/resolve-outbound-target-DXfjGlZQ.js +0 -40
- package/dist/plugin-sdk/run-with-concurrency-5DMu9szx.js +0 -1994
- package/dist/plugin-sdk/runtime-whatsapp-login.runtime-99sCh8RG.js +0 -10
- package/dist/plugin-sdk/runtime-whatsapp-login.runtime-D2hkJBa-.js +0 -10
- package/dist/plugin-sdk/runtime-whatsapp-outbound.runtime-C06I4adi.js +0 -19
- package/dist/plugin-sdk/runtime-whatsapp-outbound.runtime-dTkDaXHl.js +0 -19
- package/dist/plugin-sdk/send-B9xnwtQ-.js +0 -540
- package/dist/plugin-sdk/send-BxySs-Cu.js +0 -2587
- package/dist/plugin-sdk/send-D9THKp_J.js +0 -414
- package/dist/plugin-sdk/send-DCuaaP2w.js +0 -503
- package/dist/plugin-sdk/send-Dm_-_xje.js +0 -3135
- package/dist/plugin-sdk/session-DDzIZHxt.js +0 -169
- package/dist/plugin-sdk/skill-commands-DRvqtuFC.js +0 -342
- package/dist/plugin-sdk/skills-BWwlfbVj.js +0 -1428
- package/dist/plugin-sdk/slash-commands.runtime-BzYsaTST.js +0 -13
- package/dist/plugin-sdk/slash-commands.runtime-EAZKpRKq.js +0 -13
- package/dist/plugin-sdk/slash-dispatch.runtime-BC3IAF-I.js +0 -52
- package/dist/plugin-sdk/slash-dispatch.runtime-C7u7mlny.js +0 -52
- package/dist/plugin-sdk/slash-skill-commands.runtime-DGd_JSWX.js +0 -16
- package/dist/plugin-sdk/slash-skill-commands.runtime-sg98L8BK.js +0 -16
- package/dist/plugin-sdk/ssrf-DOBwjFow.js +0 -202
- package/dist/plugin-sdk/store-BKDR_-Qk.js +0 -81
- package/dist/plugin-sdk/subagent-registry-runtime-B6l6PxqP.js +0 -52
- package/dist/plugin-sdk/subagent-registry-runtime-Ceu7AzWi.js +0 -52
- package/dist/plugin-sdk/tables-GIj79us5.js +0 -55
- package/dist/plugin-sdk/target-errors-jlLHihbX.js +0 -195
- package/dist/plugin-sdk/thinking-BgdUnMZ2.js +0 -1206
- package/dist/plugin-sdk/tokens-CLE20fRI.js +0 -52
- package/dist/plugin-sdk/tool-images-BY1gsRyE.js +0 -274
- package/dist/plugin-sdk/web-BK2-uaOo.js +0 -56
- package/dist/plugin-sdk/web-Bnn82S4u.js +0 -56
- package/dist/plugin-sdk/whatsapp-actions-DQpK_5Ds.js +0 -80
- package/dist/proxy-fetch-C2v-Utgg.js +0 -38
- package/dist/runtime-whatsapp-login.runtime-DumUjKRz.js +0 -13
- package/dist/runtime-whatsapp-outbound.runtime-Cgu2MfqR.js +0 -22
- package/dist/slash-commands.runtime-CjBXruwG.js +0 -16
- package/dist/slash-dispatch.runtime-DqZVfX4H.js +0 -56
- package/dist/slash-skill-commands.runtime-DYK20Lxf.js +0 -20
- package/dist/subagent-registry-runtime-BIKGAzgI.js +0 -56
- package/docs/reference/templates/IDENTITY.md +0 -29
- package/docs/reference/templates/USER.md +0 -23
- package/docs/zh-CN/reference/templates/IDENTITY.md +0 -36
- package/docs/zh-CN/reference/templates/USER.md +0 -30
- package/skills/sherpa-onnx-tts/bin/sherpa-onnx-tts +0 -178
|
@@ -1,1694 +0,0 @@
|
|
|
1
|
-
import { ot as normalizeAccountId, st as normalizeOptionalAccountId } from "./run-with-concurrency-5DMu9szx.js";
|
|
2
|
-
import { c as resolveStateDir } from "./paths-8xF5kDne.js";
|
|
3
|
-
import { Et as getActivePluginRegistryVersion, It as createInternalHookEvent, Lt as triggerInternalHook, wt as getActivePluginRegistry } from "./config-B2B64aX0.js";
|
|
4
|
-
import { L as logVerbose, a as createSubsystemLogger } from "./logger-DDdrdbDu.js";
|
|
5
|
-
import { d as getChannelDock } from "./thinking-BgdUnMZ2.js";
|
|
6
|
-
import { Ft as parseInlineDirectives, ht as resolveMirroredTranscriptText, i as isMessagingToolDuplicate, mt as appendAssistantMessageToSessionTranscript } from "./pi-embedded-helpers-BExwPvTh.js";
|
|
7
|
-
import { r as normalizeChannelId, t as getChannelPlugin } from "./plugins-BN64HHZA.js";
|
|
8
|
-
import { t as getAgentScopedMediaLocalRoots } from "./local-roots-BIPT8uAO.js";
|
|
9
|
-
import { c as chunkMarkdownTextWithMode, d as resolveChunkMode, f as resolveTextChunkLimit, g as parseFenceSpans, i as resolveMarkdownTableMode, o as chunkByParagraph } from "./ir-DWEc6zOp.js";
|
|
10
|
-
import { i as isSilentReplyText, n as SILENT_REPLY_TOKEN } from "./tokens-CTIYTLWu.js";
|
|
11
|
-
import { r as parseTelegramTarget } from "./targets-D46Aqz9j.js";
|
|
12
|
-
import { n as generateSecureUuid } from "./secure-random-IkuYAMEf.js";
|
|
13
|
-
import { c as markdownToSignalTextChunks, t as sendMessageSignal } from "./send-B9xnwtQ-.js";
|
|
14
|
-
import fs from "node:fs";
|
|
15
|
-
import path from "node:path";
|
|
16
|
-
|
|
17
|
-
//#region src/channels/plugins/media-limits.ts
|
|
18
|
-
const MB = 1024 * 1024;
|
|
19
|
-
function resolveChannelMediaMaxBytes(params) {
|
|
20
|
-
const accountId = normalizeAccountId(params.accountId);
|
|
21
|
-
const channelLimit = params.resolveChannelLimitMb({
|
|
22
|
-
cfg: params.cfg,
|
|
23
|
-
accountId
|
|
24
|
-
});
|
|
25
|
-
if (channelLimit) return channelLimit * MB;
|
|
26
|
-
if (params.cfg.agents?.defaults?.mediaMaxMb) return params.cfg.agents.defaults.mediaMaxMb * MB;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
//#endregion
|
|
30
|
-
//#region src/plugins/hooks.ts
|
|
31
|
-
/**
|
|
32
|
-
* Get hooks for a specific hook name, sorted by priority (higher first).
|
|
33
|
-
*/
|
|
34
|
-
function getHooksForName(registry, hookName) {
|
|
35
|
-
return registry.typedHooks.filter((h) => h.hookName === hookName).toSorted((a, b) => (b.priority ?? 0) - (a.priority ?? 0));
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Create a hook runner for a specific registry.
|
|
39
|
-
*/
|
|
40
|
-
function createHookRunner(registry, options = {}) {
|
|
41
|
-
const logger = options.logger;
|
|
42
|
-
const catchErrors = options.catchErrors ?? true;
|
|
43
|
-
const mergeBeforeModelResolve = (acc, next) => ({
|
|
44
|
-
modelOverride: acc?.modelOverride ?? next.modelOverride,
|
|
45
|
-
providerOverride: acc?.providerOverride ?? next.providerOverride
|
|
46
|
-
});
|
|
47
|
-
const mergeBeforePromptBuild = (acc, next) => ({
|
|
48
|
-
systemPrompt: next.systemPrompt ?? acc?.systemPrompt,
|
|
49
|
-
prependContext: acc?.prependContext && next.prependContext ? `${acc.prependContext}\n\n${next.prependContext}` : next.prependContext ?? acc?.prependContext
|
|
50
|
-
});
|
|
51
|
-
const mergeSubagentSpawningResult = (acc, next) => {
|
|
52
|
-
if (acc?.status === "error") return acc;
|
|
53
|
-
if (next.status === "error") return next;
|
|
54
|
-
return {
|
|
55
|
-
status: "ok",
|
|
56
|
-
threadBindingReady: Boolean(acc?.threadBindingReady || next.threadBindingReady)
|
|
57
|
-
};
|
|
58
|
-
};
|
|
59
|
-
const mergeSubagentDeliveryTargetResult = (acc, next) => {
|
|
60
|
-
if (acc?.origin) return acc;
|
|
61
|
-
return next;
|
|
62
|
-
};
|
|
63
|
-
const handleHookError = (params) => {
|
|
64
|
-
const msg = `[hooks] ${params.hookName} handler from ${params.pluginId} failed: ${String(params.error)}`;
|
|
65
|
-
if (catchErrors) {
|
|
66
|
-
logger?.error(msg);
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
throw new Error(msg, { cause: params.error });
|
|
70
|
-
};
|
|
71
|
-
/**
|
|
72
|
-
* Run a hook that doesn't return a value (fire-and-forget style).
|
|
73
|
-
* All handlers are executed in parallel for performance.
|
|
74
|
-
*/
|
|
75
|
-
async function runVoidHook(hookName, event, ctx) {
|
|
76
|
-
const hooks = getHooksForName(registry, hookName);
|
|
77
|
-
if (hooks.length === 0) return;
|
|
78
|
-
logger?.debug?.(`[hooks] running ${hookName} (${hooks.length} handlers)`);
|
|
79
|
-
const promises = hooks.map(async (hook) => {
|
|
80
|
-
try {
|
|
81
|
-
await hook.handler(event, ctx);
|
|
82
|
-
} catch (err) {
|
|
83
|
-
handleHookError({
|
|
84
|
-
hookName,
|
|
85
|
-
pluginId: hook.pluginId,
|
|
86
|
-
error: err
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
|
-
await Promise.all(promises);
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* Run a hook that can return a modifying result.
|
|
94
|
-
* Handlers are executed sequentially in priority order, and results are merged.
|
|
95
|
-
*/
|
|
96
|
-
async function runModifyingHook(hookName, event, ctx, mergeResults) {
|
|
97
|
-
const hooks = getHooksForName(registry, hookName);
|
|
98
|
-
if (hooks.length === 0) return;
|
|
99
|
-
logger?.debug?.(`[hooks] running ${hookName} (${hooks.length} handlers, sequential)`);
|
|
100
|
-
let result;
|
|
101
|
-
for (const hook of hooks) try {
|
|
102
|
-
const handlerResult = await hook.handler(event, ctx);
|
|
103
|
-
if (handlerResult !== void 0 && handlerResult !== null) if (mergeResults && result !== void 0) result = mergeResults(result, handlerResult);
|
|
104
|
-
else result = handlerResult;
|
|
105
|
-
} catch (err) {
|
|
106
|
-
handleHookError({
|
|
107
|
-
hookName,
|
|
108
|
-
pluginId: hook.pluginId,
|
|
109
|
-
error: err
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
return result;
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* Run before_model_resolve hook.
|
|
116
|
-
* Allows plugins to override provider/model before model resolution.
|
|
117
|
-
*/
|
|
118
|
-
async function runBeforeModelResolve(event, ctx) {
|
|
119
|
-
return runModifyingHook("before_model_resolve", event, ctx, mergeBeforeModelResolve);
|
|
120
|
-
}
|
|
121
|
-
/**
|
|
122
|
-
* Run before_prompt_build hook.
|
|
123
|
-
* Allows plugins to inject context and system prompt before prompt submission.
|
|
124
|
-
*/
|
|
125
|
-
async function runBeforePromptBuild(event, ctx) {
|
|
126
|
-
return runModifyingHook("before_prompt_build", event, ctx, mergeBeforePromptBuild);
|
|
127
|
-
}
|
|
128
|
-
/**
|
|
129
|
-
* Run before_agent_start hook.
|
|
130
|
-
* Legacy compatibility hook that combines model resolve + prompt build phases.
|
|
131
|
-
*/
|
|
132
|
-
async function runBeforeAgentStart(event, ctx) {
|
|
133
|
-
return runModifyingHook("before_agent_start", event, ctx, (acc, next) => ({
|
|
134
|
-
...mergeBeforePromptBuild(acc, next),
|
|
135
|
-
...mergeBeforeModelResolve(acc, next)
|
|
136
|
-
}));
|
|
137
|
-
}
|
|
138
|
-
/**
|
|
139
|
-
* Run agent_end hook.
|
|
140
|
-
* Allows plugins to analyze completed conversations.
|
|
141
|
-
* Runs in parallel (fire-and-forget).
|
|
142
|
-
*/
|
|
143
|
-
async function runAgentEnd(event, ctx) {
|
|
144
|
-
return runVoidHook("agent_end", event, ctx);
|
|
145
|
-
}
|
|
146
|
-
/**
|
|
147
|
-
* Run llm_input hook.
|
|
148
|
-
* Allows plugins to observe the exact input payload sent to the LLM.
|
|
149
|
-
* Runs in parallel (fire-and-forget).
|
|
150
|
-
*/
|
|
151
|
-
async function runLlmInput(event, ctx) {
|
|
152
|
-
return runVoidHook("llm_input", event, ctx);
|
|
153
|
-
}
|
|
154
|
-
/**
|
|
155
|
-
* Run llm_output hook.
|
|
156
|
-
* Allows plugins to observe the exact output payload returned by the LLM.
|
|
157
|
-
* Runs in parallel (fire-and-forget).
|
|
158
|
-
*/
|
|
159
|
-
async function runLlmOutput(event, ctx) {
|
|
160
|
-
return runVoidHook("llm_output", event, ctx);
|
|
161
|
-
}
|
|
162
|
-
/**
|
|
163
|
-
* Run before_compaction hook.
|
|
164
|
-
*/
|
|
165
|
-
async function runBeforeCompaction(event, ctx) {
|
|
166
|
-
return runVoidHook("before_compaction", event, ctx);
|
|
167
|
-
}
|
|
168
|
-
/**
|
|
169
|
-
* Run after_compaction hook.
|
|
170
|
-
*/
|
|
171
|
-
async function runAfterCompaction(event, ctx) {
|
|
172
|
-
return runVoidHook("after_compaction", event, ctx);
|
|
173
|
-
}
|
|
174
|
-
/**
|
|
175
|
-
* Run before_reset hook.
|
|
176
|
-
* Fired when /new or /reset clears a session, before messages are lost.
|
|
177
|
-
* Runs in parallel (fire-and-forget).
|
|
178
|
-
*/
|
|
179
|
-
async function runBeforeReset(event, ctx) {
|
|
180
|
-
return runVoidHook("before_reset", event, ctx);
|
|
181
|
-
}
|
|
182
|
-
/**
|
|
183
|
-
* Run message_received hook.
|
|
184
|
-
* Runs in parallel (fire-and-forget).
|
|
185
|
-
*/
|
|
186
|
-
async function runMessageReceived(event, ctx) {
|
|
187
|
-
return runVoidHook("message_received", event, ctx);
|
|
188
|
-
}
|
|
189
|
-
/**
|
|
190
|
-
* Run message_sending hook.
|
|
191
|
-
* Allows plugins to modify or cancel outgoing messages.
|
|
192
|
-
* Runs sequentially.
|
|
193
|
-
*/
|
|
194
|
-
async function runMessageSending(event, ctx) {
|
|
195
|
-
return runModifyingHook("message_sending", event, ctx, (acc, next) => ({
|
|
196
|
-
content: next.content ?? acc?.content,
|
|
197
|
-
cancel: next.cancel ?? acc?.cancel
|
|
198
|
-
}));
|
|
199
|
-
}
|
|
200
|
-
/**
|
|
201
|
-
* Run message_sent hook.
|
|
202
|
-
* Runs in parallel (fire-and-forget).
|
|
203
|
-
*/
|
|
204
|
-
async function runMessageSent(event, ctx) {
|
|
205
|
-
return runVoidHook("message_sent", event, ctx);
|
|
206
|
-
}
|
|
207
|
-
/**
|
|
208
|
-
* Run before_tool_call hook.
|
|
209
|
-
* Allows plugins to modify or block tool calls.
|
|
210
|
-
* Runs sequentially.
|
|
211
|
-
*/
|
|
212
|
-
async function runBeforeToolCall(event, ctx) {
|
|
213
|
-
return runModifyingHook("before_tool_call", event, ctx, (acc, next) => ({
|
|
214
|
-
params: next.params ?? acc?.params,
|
|
215
|
-
block: next.block ?? acc?.block,
|
|
216
|
-
blockReason: next.blockReason ?? acc?.blockReason
|
|
217
|
-
}));
|
|
218
|
-
}
|
|
219
|
-
/**
|
|
220
|
-
* Run after_tool_call hook.
|
|
221
|
-
* Runs in parallel (fire-and-forget).
|
|
222
|
-
*/
|
|
223
|
-
async function runAfterToolCall(event, ctx) {
|
|
224
|
-
return runVoidHook("after_tool_call", event, ctx);
|
|
225
|
-
}
|
|
226
|
-
/**
|
|
227
|
-
* Run tool_result_persist hook.
|
|
228
|
-
*
|
|
229
|
-
* This hook is intentionally synchronous: it runs in hot paths where session
|
|
230
|
-
* transcripts are appended synchronously.
|
|
231
|
-
*
|
|
232
|
-
* Handlers are executed sequentially in priority order (higher first). Each
|
|
233
|
-
* handler may return `{ message }` to replace the message passed to the next
|
|
234
|
-
* handler.
|
|
235
|
-
*/
|
|
236
|
-
function runToolResultPersist(event, ctx) {
|
|
237
|
-
const hooks = getHooksForName(registry, "tool_result_persist");
|
|
238
|
-
if (hooks.length === 0) return;
|
|
239
|
-
let current = event.message;
|
|
240
|
-
for (const hook of hooks) try {
|
|
241
|
-
const out = hook.handler({
|
|
242
|
-
...event,
|
|
243
|
-
message: current
|
|
244
|
-
}, ctx);
|
|
245
|
-
if (out && typeof out.then === "function") {
|
|
246
|
-
const msg = `[hooks] tool_result_persist handler from ${hook.pluginId} returned a Promise; this hook is synchronous and the result was ignored.`;
|
|
247
|
-
if (catchErrors) {
|
|
248
|
-
logger?.warn?.(msg);
|
|
249
|
-
continue;
|
|
250
|
-
}
|
|
251
|
-
throw new Error(msg);
|
|
252
|
-
}
|
|
253
|
-
const next = out?.message;
|
|
254
|
-
if (next) current = next;
|
|
255
|
-
} catch (err) {
|
|
256
|
-
const msg = `[hooks] tool_result_persist handler from ${hook.pluginId} failed: ${String(err)}`;
|
|
257
|
-
if (catchErrors) logger?.error(msg);
|
|
258
|
-
else throw new Error(msg, { cause: err });
|
|
259
|
-
}
|
|
260
|
-
return { message: current };
|
|
261
|
-
}
|
|
262
|
-
/**
|
|
263
|
-
* Run before_message_write hook.
|
|
264
|
-
*
|
|
265
|
-
* This hook is intentionally synchronous: it runs on the hot path where
|
|
266
|
-
* session transcripts are appended synchronously.
|
|
267
|
-
*
|
|
268
|
-
* Handlers are executed sequentially in priority order (higher first).
|
|
269
|
-
* If any handler returns { block: true }, the message is NOT written
|
|
270
|
-
* to the session JSONL and we return immediately.
|
|
271
|
-
* If a handler returns { message }, the modified message replaces the
|
|
272
|
-
* original for subsequent handlers and the final write.
|
|
273
|
-
*/
|
|
274
|
-
function runBeforeMessageWrite(event, ctx) {
|
|
275
|
-
const hooks = getHooksForName(registry, "before_message_write");
|
|
276
|
-
if (hooks.length === 0) return;
|
|
277
|
-
let current = event.message;
|
|
278
|
-
for (const hook of hooks) try {
|
|
279
|
-
const out = hook.handler({
|
|
280
|
-
...event,
|
|
281
|
-
message: current
|
|
282
|
-
}, ctx);
|
|
283
|
-
if (out && typeof out.then === "function") {
|
|
284
|
-
const msg = `[hooks] before_message_write handler from ${hook.pluginId} returned a Promise; this hook is synchronous and the result was ignored.`;
|
|
285
|
-
if (catchErrors) {
|
|
286
|
-
logger?.warn?.(msg);
|
|
287
|
-
continue;
|
|
288
|
-
}
|
|
289
|
-
throw new Error(msg);
|
|
290
|
-
}
|
|
291
|
-
const result = out;
|
|
292
|
-
if (result?.block) return { block: true };
|
|
293
|
-
if (result?.message) current = result.message;
|
|
294
|
-
} catch (err) {
|
|
295
|
-
const msg = `[hooks] before_message_write handler from ${hook.pluginId} failed: ${String(err)}`;
|
|
296
|
-
if (catchErrors) logger?.error(msg);
|
|
297
|
-
else throw new Error(msg, { cause: err });
|
|
298
|
-
}
|
|
299
|
-
if (current !== event.message) return { message: current };
|
|
300
|
-
}
|
|
301
|
-
/**
|
|
302
|
-
* Run session_start hook.
|
|
303
|
-
* Runs in parallel (fire-and-forget).
|
|
304
|
-
*/
|
|
305
|
-
async function runSessionStart(event, ctx) {
|
|
306
|
-
return runVoidHook("session_start", event, ctx);
|
|
307
|
-
}
|
|
308
|
-
/**
|
|
309
|
-
* Run session_end hook.
|
|
310
|
-
* Runs in parallel (fire-and-forget).
|
|
311
|
-
*/
|
|
312
|
-
async function runSessionEnd(event, ctx) {
|
|
313
|
-
return runVoidHook("session_end", event, ctx);
|
|
314
|
-
}
|
|
315
|
-
/**
|
|
316
|
-
* Run subagent_spawning hook.
|
|
317
|
-
* Runs sequentially so channel plugins can deterministically provision session bindings.
|
|
318
|
-
*/
|
|
319
|
-
async function runSubagentSpawning(event, ctx) {
|
|
320
|
-
return runModifyingHook("subagent_spawning", event, ctx, mergeSubagentSpawningResult);
|
|
321
|
-
}
|
|
322
|
-
/**
|
|
323
|
-
* Run subagent_delivery_target hook.
|
|
324
|
-
* Runs sequentially so channel plugins can deterministically resolve routing.
|
|
325
|
-
*/
|
|
326
|
-
async function runSubagentDeliveryTarget(event, ctx) {
|
|
327
|
-
return runModifyingHook("subagent_delivery_target", event, ctx, mergeSubagentDeliveryTargetResult);
|
|
328
|
-
}
|
|
329
|
-
/**
|
|
330
|
-
* Run subagent_spawned hook.
|
|
331
|
-
* Runs in parallel (fire-and-forget).
|
|
332
|
-
*/
|
|
333
|
-
async function runSubagentSpawned(event, ctx) {
|
|
334
|
-
return runVoidHook("subagent_spawned", event, ctx);
|
|
335
|
-
}
|
|
336
|
-
/**
|
|
337
|
-
* Run subagent_ended hook.
|
|
338
|
-
* Runs in parallel (fire-and-forget).
|
|
339
|
-
*/
|
|
340
|
-
async function runSubagentEnded(event, ctx) {
|
|
341
|
-
return runVoidHook("subagent_ended", event, ctx);
|
|
342
|
-
}
|
|
343
|
-
/**
|
|
344
|
-
* Run gateway_start hook.
|
|
345
|
-
* Runs in parallel (fire-and-forget).
|
|
346
|
-
*/
|
|
347
|
-
async function runGatewayStart(event, ctx) {
|
|
348
|
-
return runVoidHook("gateway_start", event, ctx);
|
|
349
|
-
}
|
|
350
|
-
/**
|
|
351
|
-
* Run gateway_stop hook.
|
|
352
|
-
* Runs in parallel (fire-and-forget).
|
|
353
|
-
*/
|
|
354
|
-
async function runGatewayStop(event, ctx) {
|
|
355
|
-
return runVoidHook("gateway_stop", event, ctx);
|
|
356
|
-
}
|
|
357
|
-
/**
|
|
358
|
-
* Check if any hooks are registered for a given hook name.
|
|
359
|
-
*/
|
|
360
|
-
function hasHooks(hookName) {
|
|
361
|
-
return registry.typedHooks.some((h) => h.hookName === hookName);
|
|
362
|
-
}
|
|
363
|
-
/**
|
|
364
|
-
* Get count of registered hooks for a given hook name.
|
|
365
|
-
*/
|
|
366
|
-
function getHookCount(hookName) {
|
|
367
|
-
return registry.typedHooks.filter((h) => h.hookName === hookName).length;
|
|
368
|
-
}
|
|
369
|
-
return {
|
|
370
|
-
runBeforeModelResolve,
|
|
371
|
-
runBeforePromptBuild,
|
|
372
|
-
runBeforeAgentStart,
|
|
373
|
-
runLlmInput,
|
|
374
|
-
runLlmOutput,
|
|
375
|
-
runAgentEnd,
|
|
376
|
-
runBeforeCompaction,
|
|
377
|
-
runAfterCompaction,
|
|
378
|
-
runBeforeReset,
|
|
379
|
-
runMessageReceived,
|
|
380
|
-
runMessageSending,
|
|
381
|
-
runMessageSent,
|
|
382
|
-
runBeforeToolCall,
|
|
383
|
-
runAfterToolCall,
|
|
384
|
-
runToolResultPersist,
|
|
385
|
-
runBeforeMessageWrite,
|
|
386
|
-
runSessionStart,
|
|
387
|
-
runSessionEnd,
|
|
388
|
-
runSubagentSpawning,
|
|
389
|
-
runSubagentDeliveryTarget,
|
|
390
|
-
runSubagentSpawned,
|
|
391
|
-
runSubagentEnded,
|
|
392
|
-
runGatewayStart,
|
|
393
|
-
runGatewayStop,
|
|
394
|
-
hasHooks,
|
|
395
|
-
getHookCount
|
|
396
|
-
};
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
//#endregion
|
|
400
|
-
//#region src/plugins/hook-runner-global.ts
|
|
401
|
-
/**
|
|
402
|
-
* Global Plugin Hook Runner
|
|
403
|
-
*
|
|
404
|
-
* Singleton hook runner that's initialized when plugins are loaded
|
|
405
|
-
* and can be called from anywhere in the codebase.
|
|
406
|
-
*/
|
|
407
|
-
const log$1 = createSubsystemLogger("plugins");
|
|
408
|
-
let globalHookRunner = null;
|
|
409
|
-
let globalRegistry = null;
|
|
410
|
-
/**
|
|
411
|
-
* Initialize the global hook runner with a plugin registry.
|
|
412
|
-
* Called once when plugins are loaded during gateway startup.
|
|
413
|
-
*/
|
|
414
|
-
function initializeGlobalHookRunner(registry) {
|
|
415
|
-
globalRegistry = registry;
|
|
416
|
-
globalHookRunner = createHookRunner(registry, {
|
|
417
|
-
logger: {
|
|
418
|
-
debug: (msg) => log$1.debug(msg),
|
|
419
|
-
warn: (msg) => log$1.warn(msg),
|
|
420
|
-
error: (msg) => log$1.error(msg)
|
|
421
|
-
},
|
|
422
|
-
catchErrors: true
|
|
423
|
-
});
|
|
424
|
-
const hookCount = registry.hooks.length;
|
|
425
|
-
if (hookCount > 0) log$1.info(`hook runner initialized with ${hookCount} registered hooks`);
|
|
426
|
-
}
|
|
427
|
-
/**
|
|
428
|
-
* Get the global hook runner.
|
|
429
|
-
* Returns null if plugins haven't been loaded yet.
|
|
430
|
-
*/
|
|
431
|
-
function getGlobalHookRunner() {
|
|
432
|
-
return globalHookRunner;
|
|
433
|
-
}
|
|
434
|
-
|
|
435
|
-
//#endregion
|
|
436
|
-
//#region src/infra/outbound/target-normalization.ts
|
|
437
|
-
function normalizeChannelTargetInput(raw) {
|
|
438
|
-
return raw.trim();
|
|
439
|
-
}
|
|
440
|
-
const targetNormalizerCacheByChannelId = /* @__PURE__ */ new Map();
|
|
441
|
-
function resolveTargetNormalizer(channelId) {
|
|
442
|
-
const version = getActivePluginRegistryVersion();
|
|
443
|
-
const cached = targetNormalizerCacheByChannelId.get(channelId);
|
|
444
|
-
if (cached?.version === version) return cached.normalizer;
|
|
445
|
-
const normalizer = getChannelPlugin(channelId)?.messaging?.normalizeTarget;
|
|
446
|
-
targetNormalizerCacheByChannelId.set(channelId, {
|
|
447
|
-
version,
|
|
448
|
-
normalizer
|
|
449
|
-
});
|
|
450
|
-
return normalizer;
|
|
451
|
-
}
|
|
452
|
-
function normalizeTargetForProvider(provider, raw) {
|
|
453
|
-
if (!raw) return;
|
|
454
|
-
const fallback = raw.trim() || void 0;
|
|
455
|
-
if (!fallback) return;
|
|
456
|
-
const providerId = normalizeChannelId(provider);
|
|
457
|
-
return ((providerId ? resolveTargetNormalizer(providerId) : void 0)?.(raw) ?? fallback) || void 0;
|
|
458
|
-
}
|
|
459
|
-
function buildTargetResolverSignature(channel) {
|
|
460
|
-
const resolver = getChannelPlugin(channel)?.messaging?.targetResolver;
|
|
461
|
-
const hint = resolver?.hint ?? "";
|
|
462
|
-
const looksLike = resolver?.looksLikeId;
|
|
463
|
-
return hashSignature(`${hint}|${looksLike ? looksLike.toString() : ""}`);
|
|
464
|
-
}
|
|
465
|
-
function hashSignature(value) {
|
|
466
|
-
let hash = 5381;
|
|
467
|
-
for (let i = 0; i < value.length; i += 1) hash = (hash << 5) + hash ^ value.charCodeAt(i);
|
|
468
|
-
return (hash >>> 0).toString(36);
|
|
469
|
-
}
|
|
470
|
-
|
|
471
|
-
//#endregion
|
|
472
|
-
//#region src/auto-reply/reply/reply-tags.ts
|
|
473
|
-
function extractReplyToTag(text, currentMessageId) {
|
|
474
|
-
const result = parseInlineDirectives(text, {
|
|
475
|
-
currentMessageId,
|
|
476
|
-
stripAudioTag: false
|
|
477
|
-
});
|
|
478
|
-
return {
|
|
479
|
-
cleaned: result.text,
|
|
480
|
-
replyToId: result.replyToId,
|
|
481
|
-
replyToCurrent: result.replyToCurrent,
|
|
482
|
-
hasTag: result.hasReplyTag
|
|
483
|
-
};
|
|
484
|
-
}
|
|
485
|
-
|
|
486
|
-
//#endregion
|
|
487
|
-
//#region src/auto-reply/reply/reply-threading.ts
|
|
488
|
-
function resolveReplyToMode(cfg, channel, accountId, chatType) {
|
|
489
|
-
const provider = normalizeChannelId(channel);
|
|
490
|
-
if (!provider) return "all";
|
|
491
|
-
return getChannelDock(provider)?.threading?.resolveReplyToMode?.({
|
|
492
|
-
cfg,
|
|
493
|
-
accountId,
|
|
494
|
-
chatType
|
|
495
|
-
}) ?? "all";
|
|
496
|
-
}
|
|
497
|
-
function createReplyToModeFilter(mode, opts = {}) {
|
|
498
|
-
let hasThreaded = false;
|
|
499
|
-
return (payload) => {
|
|
500
|
-
if (!payload.replyToId) return payload;
|
|
501
|
-
if (mode === "off") {
|
|
502
|
-
const isExplicit = Boolean(payload.replyToTag) || Boolean(payload.replyToCurrent);
|
|
503
|
-
if (opts.allowExplicitReplyTagsWhenOff && isExplicit) return payload;
|
|
504
|
-
return {
|
|
505
|
-
...payload,
|
|
506
|
-
replyToId: void 0
|
|
507
|
-
};
|
|
508
|
-
}
|
|
509
|
-
if (mode === "all") return payload;
|
|
510
|
-
if (hasThreaded) return {
|
|
511
|
-
...payload,
|
|
512
|
-
replyToId: void 0
|
|
513
|
-
};
|
|
514
|
-
hasThreaded = true;
|
|
515
|
-
return payload;
|
|
516
|
-
};
|
|
517
|
-
}
|
|
518
|
-
function createReplyToModeFilterForChannel(mode, channel) {
|
|
519
|
-
const provider = normalizeChannelId(channel);
|
|
520
|
-
const isWebchat = (typeof channel === "string" ? channel.trim().toLowerCase() : void 0) === "webchat";
|
|
521
|
-
const dock = provider ? getChannelDock(provider) : void 0;
|
|
522
|
-
return createReplyToModeFilter(mode, { allowExplicitReplyTagsWhenOff: provider ? dock?.threading?.allowExplicitReplyTagsWhenOff ?? dock?.threading?.allowTagsWhenOff ?? true : isWebchat });
|
|
523
|
-
}
|
|
524
|
-
|
|
525
|
-
//#endregion
|
|
526
|
-
//#region src/auto-reply/reply/reply-payloads.ts
|
|
527
|
-
function resolveReplyThreadingForPayload(params) {
|
|
528
|
-
const implicitReplyToId = params.implicitReplyToId?.trim() || void 0;
|
|
529
|
-
const currentMessageId = params.currentMessageId?.trim() || void 0;
|
|
530
|
-
let resolved = params.payload.replyToId || params.payload.replyToCurrent === false || !implicitReplyToId ? params.payload : {
|
|
531
|
-
...params.payload,
|
|
532
|
-
replyToId: implicitReplyToId
|
|
533
|
-
};
|
|
534
|
-
if (typeof resolved.text === "string" && resolved.text.includes("[[")) {
|
|
535
|
-
const { cleaned, replyToId, replyToCurrent, hasTag } = extractReplyToTag(resolved.text, currentMessageId);
|
|
536
|
-
resolved = {
|
|
537
|
-
...resolved,
|
|
538
|
-
text: cleaned ? cleaned : void 0,
|
|
539
|
-
replyToId: replyToId ?? resolved.replyToId,
|
|
540
|
-
replyToTag: hasTag || resolved.replyToTag,
|
|
541
|
-
replyToCurrent: replyToCurrent || resolved.replyToCurrent
|
|
542
|
-
};
|
|
543
|
-
}
|
|
544
|
-
if (resolved.replyToCurrent && !resolved.replyToId && currentMessageId) resolved = {
|
|
545
|
-
...resolved,
|
|
546
|
-
replyToId: currentMessageId
|
|
547
|
-
};
|
|
548
|
-
return resolved;
|
|
549
|
-
}
|
|
550
|
-
function applyReplyTagsToPayload(payload, currentMessageId) {
|
|
551
|
-
return resolveReplyThreadingForPayload({
|
|
552
|
-
payload,
|
|
553
|
-
currentMessageId
|
|
554
|
-
});
|
|
555
|
-
}
|
|
556
|
-
function isRenderablePayload(payload) {
|
|
557
|
-
return Boolean(payload.text || payload.mediaUrl || payload.mediaUrls && payload.mediaUrls.length > 0 || payload.audioAsVoice || payload.channelData);
|
|
558
|
-
}
|
|
559
|
-
function shouldSuppressReasoningPayload(payload) {
|
|
560
|
-
return payload.isReasoning === true;
|
|
561
|
-
}
|
|
562
|
-
function applyReplyThreading(params) {
|
|
563
|
-
const { payloads, replyToMode, replyToChannel, currentMessageId } = params;
|
|
564
|
-
const applyReplyToMode = createReplyToModeFilterForChannel(replyToMode, replyToChannel);
|
|
565
|
-
const implicitReplyToId = currentMessageId?.trim() || void 0;
|
|
566
|
-
return payloads.map((payload) => resolveReplyThreadingForPayload({
|
|
567
|
-
payload,
|
|
568
|
-
implicitReplyToId,
|
|
569
|
-
currentMessageId
|
|
570
|
-
})).filter(isRenderablePayload).map(applyReplyToMode);
|
|
571
|
-
}
|
|
572
|
-
function filterMessagingToolDuplicates(params) {
|
|
573
|
-
const { payloads, sentTexts } = params;
|
|
574
|
-
if (sentTexts.length === 0) return payloads;
|
|
575
|
-
return payloads.filter((payload) => !isMessagingToolDuplicate(payload.text ?? "", sentTexts));
|
|
576
|
-
}
|
|
577
|
-
function filterMessagingToolMediaDuplicates(params) {
|
|
578
|
-
const normalizeMediaForDedupe = (value) => {
|
|
579
|
-
const trimmed = value.trim();
|
|
580
|
-
if (!trimmed) return "";
|
|
581
|
-
if (!trimmed.toLowerCase().startsWith("file://")) return trimmed;
|
|
582
|
-
try {
|
|
583
|
-
const parsed = new URL(trimmed);
|
|
584
|
-
if (parsed.protocol === "file:") return decodeURIComponent(parsed.pathname || "");
|
|
585
|
-
} catch {}
|
|
586
|
-
return trimmed.replace(/^file:\/\//i, "");
|
|
587
|
-
};
|
|
588
|
-
const { payloads, sentMediaUrls } = params;
|
|
589
|
-
if (sentMediaUrls.length === 0) return payloads;
|
|
590
|
-
const sentSet = new Set(sentMediaUrls.map(normalizeMediaForDedupe).filter(Boolean));
|
|
591
|
-
return payloads.map((payload) => {
|
|
592
|
-
const mediaUrl = payload.mediaUrl;
|
|
593
|
-
const mediaUrls = payload.mediaUrls;
|
|
594
|
-
const stripSingle = mediaUrl && sentSet.has(normalizeMediaForDedupe(mediaUrl));
|
|
595
|
-
const filteredUrls = mediaUrls?.filter((u) => !sentSet.has(normalizeMediaForDedupe(u)));
|
|
596
|
-
if (!stripSingle && (!mediaUrls || filteredUrls?.length === mediaUrls.length)) return payload;
|
|
597
|
-
return {
|
|
598
|
-
...payload,
|
|
599
|
-
mediaUrl: stripSingle ? void 0 : mediaUrl,
|
|
600
|
-
mediaUrls: filteredUrls?.length ? filteredUrls : void 0
|
|
601
|
-
};
|
|
602
|
-
});
|
|
603
|
-
}
|
|
604
|
-
const PROVIDER_ALIAS_MAP = { lark: "feishu" };
|
|
605
|
-
function normalizeProviderForComparison(value) {
|
|
606
|
-
const trimmed = value?.trim();
|
|
607
|
-
if (!trimmed) return;
|
|
608
|
-
const lowered = trimmed.toLowerCase();
|
|
609
|
-
const normalizedChannel = normalizeChannelId(trimmed);
|
|
610
|
-
if (normalizedChannel) return normalizedChannel;
|
|
611
|
-
return PROVIDER_ALIAS_MAP[lowered] ?? lowered;
|
|
612
|
-
}
|
|
613
|
-
function normalizeThreadIdForComparison(value) {
|
|
614
|
-
const trimmed = value?.trim();
|
|
615
|
-
if (!trimmed) return;
|
|
616
|
-
if (/^-?\d+$/.test(trimmed)) return String(Number.parseInt(trimmed, 10));
|
|
617
|
-
return trimmed.toLowerCase();
|
|
618
|
-
}
|
|
619
|
-
function resolveTargetProviderForComparison(params) {
|
|
620
|
-
const targetProvider = normalizeProviderForComparison(params.targetProvider);
|
|
621
|
-
if (!targetProvider || targetProvider === "message") return params.currentProvider;
|
|
622
|
-
return targetProvider;
|
|
623
|
-
}
|
|
624
|
-
function targetsMatchForSuppression(params) {
|
|
625
|
-
if (params.provider !== "telegram") return params.targetKey === params.originTarget;
|
|
626
|
-
const origin = parseTelegramTarget(params.originTarget);
|
|
627
|
-
const target = parseTelegramTarget(params.targetKey);
|
|
628
|
-
const targetThreadId = normalizeThreadIdForComparison(params.targetThreadId) ?? (target.messageThreadId != null ? String(target.messageThreadId) : void 0);
|
|
629
|
-
const originThreadId = origin.messageThreadId != null ? String(origin.messageThreadId) : void 0;
|
|
630
|
-
if (origin.chatId.trim().toLowerCase() !== target.chatId.trim().toLowerCase()) return false;
|
|
631
|
-
if (originThreadId && targetThreadId != null) return originThreadId === targetThreadId;
|
|
632
|
-
if (originThreadId && targetThreadId == null) return false;
|
|
633
|
-
if (!originThreadId && targetThreadId != null) return false;
|
|
634
|
-
return true;
|
|
635
|
-
}
|
|
636
|
-
function shouldSuppressMessagingToolReplies(params) {
|
|
637
|
-
const provider = normalizeProviderForComparison(params.messageProvider);
|
|
638
|
-
if (!provider) return false;
|
|
639
|
-
const originTarget = normalizeTargetForProvider(provider, params.originatingTo);
|
|
640
|
-
if (!originTarget) return false;
|
|
641
|
-
const originAccount = normalizeOptionalAccountId(params.accountId);
|
|
642
|
-
const sentTargets = params.messagingToolSentTargets ?? [];
|
|
643
|
-
if (sentTargets.length === 0) return false;
|
|
644
|
-
return sentTargets.some((target) => {
|
|
645
|
-
const targetProvider = resolveTargetProviderForComparison({
|
|
646
|
-
currentProvider: provider,
|
|
647
|
-
targetProvider: target?.provider
|
|
648
|
-
});
|
|
649
|
-
if (targetProvider !== provider) return false;
|
|
650
|
-
const targetKey = normalizeTargetForProvider(targetProvider, target.to);
|
|
651
|
-
if (!targetKey) return false;
|
|
652
|
-
const targetAccount = normalizeOptionalAccountId(target.accountId);
|
|
653
|
-
if (originAccount && targetAccount && originAccount !== targetAccount) return false;
|
|
654
|
-
return targetsMatchForSuppression({
|
|
655
|
-
provider,
|
|
656
|
-
originTarget,
|
|
657
|
-
targetKey,
|
|
658
|
-
targetThreadId: target.threadId
|
|
659
|
-
});
|
|
660
|
-
});
|
|
661
|
-
}
|
|
662
|
-
|
|
663
|
-
//#endregion
|
|
664
|
-
//#region src/hooks/fire-and-forget.ts
|
|
665
|
-
function fireAndForgetHook(task, label, logger = logVerbose) {
|
|
666
|
-
task.catch((err) => {
|
|
667
|
-
logger(`${label}: ${String(err)}`);
|
|
668
|
-
});
|
|
669
|
-
}
|
|
670
|
-
|
|
671
|
-
//#endregion
|
|
672
|
-
//#region src/hooks/message-hook-mappers.ts
|
|
673
|
-
function deriveInboundMessageHookContext(ctx, overrides) {
|
|
674
|
-
const content = overrides?.content ?? (typeof ctx.BodyForCommands === "string" ? ctx.BodyForCommands : typeof ctx.RawBody === "string" ? ctx.RawBody : typeof ctx.Body === "string" ? ctx.Body : "");
|
|
675
|
-
const channelId = (ctx.OriginatingChannel ?? ctx.Surface ?? ctx.Provider ?? "").toLowerCase();
|
|
676
|
-
const conversationId = ctx.OriginatingTo ?? ctx.To ?? ctx.From ?? void 0;
|
|
677
|
-
const isGroup = Boolean(ctx.GroupSubject || ctx.GroupChannel);
|
|
678
|
-
return {
|
|
679
|
-
from: ctx.From ?? "",
|
|
680
|
-
to: ctx.To,
|
|
681
|
-
content,
|
|
682
|
-
body: ctx.Body,
|
|
683
|
-
bodyForAgent: ctx.BodyForAgent,
|
|
684
|
-
transcript: ctx.Transcript,
|
|
685
|
-
timestamp: typeof ctx.Timestamp === "number" && Number.isFinite(ctx.Timestamp) ? ctx.Timestamp : void 0,
|
|
686
|
-
channelId,
|
|
687
|
-
accountId: ctx.AccountId,
|
|
688
|
-
conversationId,
|
|
689
|
-
messageId: overrides?.messageId ?? ctx.MessageSidFull ?? ctx.MessageSid ?? ctx.MessageSidFirst ?? ctx.MessageSidLast,
|
|
690
|
-
senderId: ctx.SenderId,
|
|
691
|
-
senderName: ctx.SenderName,
|
|
692
|
-
senderUsername: ctx.SenderUsername,
|
|
693
|
-
senderE164: ctx.SenderE164,
|
|
694
|
-
provider: ctx.Provider,
|
|
695
|
-
surface: ctx.Surface,
|
|
696
|
-
threadId: ctx.MessageThreadId,
|
|
697
|
-
mediaPath: ctx.MediaPath,
|
|
698
|
-
mediaType: ctx.MediaType,
|
|
699
|
-
originatingChannel: ctx.OriginatingChannel,
|
|
700
|
-
originatingTo: ctx.OriginatingTo,
|
|
701
|
-
guildId: ctx.GroupSpace,
|
|
702
|
-
channelName: ctx.GroupChannel,
|
|
703
|
-
isGroup,
|
|
704
|
-
groupId: isGroup ? conversationId : void 0
|
|
705
|
-
};
|
|
706
|
-
}
|
|
707
|
-
function buildCanonicalSentMessageHookContext(params) {
|
|
708
|
-
return {
|
|
709
|
-
to: params.to,
|
|
710
|
-
content: params.content,
|
|
711
|
-
success: params.success,
|
|
712
|
-
error: params.error,
|
|
713
|
-
channelId: params.channelId,
|
|
714
|
-
accountId: params.accountId,
|
|
715
|
-
conversationId: params.conversationId ?? params.to,
|
|
716
|
-
messageId: params.messageId,
|
|
717
|
-
isGroup: params.isGroup,
|
|
718
|
-
groupId: params.groupId
|
|
719
|
-
};
|
|
720
|
-
}
|
|
721
|
-
function toPluginMessageContext(canonical) {
|
|
722
|
-
return {
|
|
723
|
-
channelId: canonical.channelId,
|
|
724
|
-
accountId: canonical.accountId,
|
|
725
|
-
conversationId: canonical.conversationId
|
|
726
|
-
};
|
|
727
|
-
}
|
|
728
|
-
function toPluginMessageReceivedEvent(canonical) {
|
|
729
|
-
return {
|
|
730
|
-
from: canonical.from,
|
|
731
|
-
content: canonical.content,
|
|
732
|
-
timestamp: canonical.timestamp,
|
|
733
|
-
metadata: {
|
|
734
|
-
to: canonical.to,
|
|
735
|
-
provider: canonical.provider,
|
|
736
|
-
surface: canonical.surface,
|
|
737
|
-
threadId: canonical.threadId,
|
|
738
|
-
originatingChannel: canonical.originatingChannel,
|
|
739
|
-
originatingTo: canonical.originatingTo,
|
|
740
|
-
messageId: canonical.messageId,
|
|
741
|
-
senderId: canonical.senderId,
|
|
742
|
-
senderName: canonical.senderName,
|
|
743
|
-
senderUsername: canonical.senderUsername,
|
|
744
|
-
senderE164: canonical.senderE164,
|
|
745
|
-
guildId: canonical.guildId,
|
|
746
|
-
channelName: canonical.channelName
|
|
747
|
-
}
|
|
748
|
-
};
|
|
749
|
-
}
|
|
750
|
-
function toPluginMessageSentEvent(canonical) {
|
|
751
|
-
return {
|
|
752
|
-
to: canonical.to,
|
|
753
|
-
content: canonical.content,
|
|
754
|
-
success: canonical.success,
|
|
755
|
-
...canonical.error ? { error: canonical.error } : {}
|
|
756
|
-
};
|
|
757
|
-
}
|
|
758
|
-
function toInternalMessageReceivedContext(canonical) {
|
|
759
|
-
return {
|
|
760
|
-
from: canonical.from,
|
|
761
|
-
content: canonical.content,
|
|
762
|
-
timestamp: canonical.timestamp,
|
|
763
|
-
channelId: canonical.channelId,
|
|
764
|
-
accountId: canonical.accountId,
|
|
765
|
-
conversationId: canonical.conversationId,
|
|
766
|
-
messageId: canonical.messageId,
|
|
767
|
-
metadata: {
|
|
768
|
-
to: canonical.to,
|
|
769
|
-
provider: canonical.provider,
|
|
770
|
-
surface: canonical.surface,
|
|
771
|
-
threadId: canonical.threadId,
|
|
772
|
-
senderId: canonical.senderId,
|
|
773
|
-
senderName: canonical.senderName,
|
|
774
|
-
senderUsername: canonical.senderUsername,
|
|
775
|
-
senderE164: canonical.senderE164,
|
|
776
|
-
guildId: canonical.guildId,
|
|
777
|
-
channelName: canonical.channelName
|
|
778
|
-
}
|
|
779
|
-
};
|
|
780
|
-
}
|
|
781
|
-
function toInternalMessageTranscribedContext(canonical, cfg) {
|
|
782
|
-
return {
|
|
783
|
-
from: canonical.from,
|
|
784
|
-
to: canonical.to,
|
|
785
|
-
body: canonical.body,
|
|
786
|
-
bodyForAgent: canonical.bodyForAgent,
|
|
787
|
-
transcript: canonical.transcript ?? "",
|
|
788
|
-
timestamp: canonical.timestamp,
|
|
789
|
-
channelId: canonical.channelId,
|
|
790
|
-
conversationId: canonical.conversationId,
|
|
791
|
-
messageId: canonical.messageId,
|
|
792
|
-
senderId: canonical.senderId,
|
|
793
|
-
senderName: canonical.senderName,
|
|
794
|
-
senderUsername: canonical.senderUsername,
|
|
795
|
-
provider: canonical.provider,
|
|
796
|
-
surface: canonical.surface,
|
|
797
|
-
mediaPath: canonical.mediaPath,
|
|
798
|
-
mediaType: canonical.mediaType,
|
|
799
|
-
cfg
|
|
800
|
-
};
|
|
801
|
-
}
|
|
802
|
-
function toInternalMessagePreprocessedContext(canonical, cfg) {
|
|
803
|
-
return {
|
|
804
|
-
from: canonical.from,
|
|
805
|
-
to: canonical.to,
|
|
806
|
-
body: canonical.body,
|
|
807
|
-
bodyForAgent: canonical.bodyForAgent,
|
|
808
|
-
transcript: canonical.transcript,
|
|
809
|
-
timestamp: canonical.timestamp,
|
|
810
|
-
channelId: canonical.channelId,
|
|
811
|
-
conversationId: canonical.conversationId,
|
|
812
|
-
messageId: canonical.messageId,
|
|
813
|
-
senderId: canonical.senderId,
|
|
814
|
-
senderName: canonical.senderName,
|
|
815
|
-
senderUsername: canonical.senderUsername,
|
|
816
|
-
provider: canonical.provider,
|
|
817
|
-
surface: canonical.surface,
|
|
818
|
-
mediaPath: canonical.mediaPath,
|
|
819
|
-
mediaType: canonical.mediaType,
|
|
820
|
-
isGroup: canonical.isGroup,
|
|
821
|
-
groupId: canonical.groupId,
|
|
822
|
-
cfg
|
|
823
|
-
};
|
|
824
|
-
}
|
|
825
|
-
function toInternalMessageSentContext(canonical) {
|
|
826
|
-
return {
|
|
827
|
-
to: canonical.to,
|
|
828
|
-
content: canonical.content,
|
|
829
|
-
success: canonical.success,
|
|
830
|
-
...canonical.error ? { error: canonical.error } : {},
|
|
831
|
-
channelId: canonical.channelId,
|
|
832
|
-
accountId: canonical.accountId,
|
|
833
|
-
conversationId: canonical.conversationId,
|
|
834
|
-
messageId: canonical.messageId,
|
|
835
|
-
...canonical.isGroup != null ? { isGroup: canonical.isGroup } : {},
|
|
836
|
-
...canonical.groupId ? { groupId: canonical.groupId } : {}
|
|
837
|
-
};
|
|
838
|
-
}
|
|
839
|
-
|
|
840
|
-
//#endregion
|
|
841
|
-
//#region src/media/audio-tags.ts
|
|
842
|
-
/**
|
|
843
|
-
* Extract audio mode tag from text.
|
|
844
|
-
* Supports [[audio_as_voice]] to send audio as voice bubble instead of file.
|
|
845
|
-
* Default is file (preserves backward compatibility).
|
|
846
|
-
*/
|
|
847
|
-
function parseAudioTag(text) {
|
|
848
|
-
const result = parseInlineDirectives(text, { stripReplyTags: false });
|
|
849
|
-
return {
|
|
850
|
-
text: result.text,
|
|
851
|
-
audioAsVoice: result.audioAsVoice,
|
|
852
|
-
hadTag: result.hasAudioTag
|
|
853
|
-
};
|
|
854
|
-
}
|
|
855
|
-
|
|
856
|
-
//#endregion
|
|
857
|
-
//#region src/media/parse.ts
|
|
858
|
-
const MEDIA_TOKEN_RE = /\bMEDIA:\s*`?([^\n]+)`?/gi;
|
|
859
|
-
function normalizeMediaSource(src) {
|
|
860
|
-
return src.startsWith("file://") ? src.replace("file://", "") : src;
|
|
861
|
-
}
|
|
862
|
-
function cleanCandidate(raw) {
|
|
863
|
-
return raw.replace(/^[`"'[{(]+/, "").replace(/[`"'\\})\],]+$/, "");
|
|
864
|
-
}
|
|
865
|
-
const WINDOWS_DRIVE_RE = /^[a-zA-Z]:[\\/]/;
|
|
866
|
-
const SCHEME_RE = /^[a-zA-Z][a-zA-Z0-9+.-]*:/;
|
|
867
|
-
const HAS_FILE_EXT = /\.\w{1,10}$/;
|
|
868
|
-
function isLikelyLocalPath(candidate) {
|
|
869
|
-
return candidate.startsWith("/") || candidate.startsWith("./") || candidate.startsWith("../") || candidate.startsWith("~") || WINDOWS_DRIVE_RE.test(candidate) || candidate.startsWith("\\\\") || !SCHEME_RE.test(candidate) && (candidate.includes("/") || candidate.includes("\\"));
|
|
870
|
-
}
|
|
871
|
-
function isValidMedia(candidate, opts) {
|
|
872
|
-
if (!candidate) return false;
|
|
873
|
-
if (candidate.length > 4096) return false;
|
|
874
|
-
if (!opts?.allowSpaces && /\s/.test(candidate)) return false;
|
|
875
|
-
if (/^https?:\/\//i.test(candidate)) return true;
|
|
876
|
-
if (isLikelyLocalPath(candidate)) return true;
|
|
877
|
-
if (opts?.allowBareFilename && !SCHEME_RE.test(candidate) && HAS_FILE_EXT.test(candidate)) return true;
|
|
878
|
-
return false;
|
|
879
|
-
}
|
|
880
|
-
function unwrapQuoted(value) {
|
|
881
|
-
const trimmed = value.trim();
|
|
882
|
-
if (trimmed.length < 2) return;
|
|
883
|
-
const first = trimmed[0];
|
|
884
|
-
if (first !== trimmed[trimmed.length - 1]) return;
|
|
885
|
-
if (first !== `"` && first !== "'" && first !== "`") return;
|
|
886
|
-
return trimmed.slice(1, -1).trim();
|
|
887
|
-
}
|
|
888
|
-
function mayContainFenceMarkers(input) {
|
|
889
|
-
return input.includes("```") || input.includes("~~~");
|
|
890
|
-
}
|
|
891
|
-
function isInsideFence(fenceSpans, offset) {
|
|
892
|
-
return fenceSpans.some((span) => offset >= span.start && offset < span.end);
|
|
893
|
-
}
|
|
894
|
-
function splitMediaFromOutput(raw) {
|
|
895
|
-
const trimmedRaw = raw.trimEnd();
|
|
896
|
-
if (!trimmedRaw.trim()) return { text: "" };
|
|
897
|
-
const mayContainMediaToken = /media:/i.test(trimmedRaw);
|
|
898
|
-
const mayContainAudioTag = trimmedRaw.includes("[[");
|
|
899
|
-
if (!mayContainMediaToken && !mayContainAudioTag) return { text: trimmedRaw };
|
|
900
|
-
const media = [];
|
|
901
|
-
let foundMediaToken = false;
|
|
902
|
-
const hasFenceMarkers = mayContainFenceMarkers(trimmedRaw);
|
|
903
|
-
const fenceSpans = hasFenceMarkers ? parseFenceSpans(trimmedRaw) : [];
|
|
904
|
-
const lines = trimmedRaw.split("\n");
|
|
905
|
-
const keptLines = [];
|
|
906
|
-
let lineOffset = 0;
|
|
907
|
-
for (const line of lines) {
|
|
908
|
-
if (hasFenceMarkers && isInsideFence(fenceSpans, lineOffset)) {
|
|
909
|
-
keptLines.push(line);
|
|
910
|
-
lineOffset += line.length + 1;
|
|
911
|
-
continue;
|
|
912
|
-
}
|
|
913
|
-
if (!line.trimStart().startsWith("MEDIA:")) {
|
|
914
|
-
keptLines.push(line);
|
|
915
|
-
lineOffset += line.length + 1;
|
|
916
|
-
continue;
|
|
917
|
-
}
|
|
918
|
-
const matches = Array.from(line.matchAll(MEDIA_TOKEN_RE));
|
|
919
|
-
if (matches.length === 0) {
|
|
920
|
-
keptLines.push(line);
|
|
921
|
-
lineOffset += line.length + 1;
|
|
922
|
-
continue;
|
|
923
|
-
}
|
|
924
|
-
const pieces = [];
|
|
925
|
-
let cursor = 0;
|
|
926
|
-
for (const match of matches) {
|
|
927
|
-
const start = match.index ?? 0;
|
|
928
|
-
pieces.push(line.slice(cursor, start));
|
|
929
|
-
const payload = match[1];
|
|
930
|
-
const unwrapped = unwrapQuoted(payload);
|
|
931
|
-
const payloadValue = unwrapped ?? payload;
|
|
932
|
-
const parts = unwrapped ? [unwrapped] : payload.split(/\s+/).filter(Boolean);
|
|
933
|
-
const mediaStartIndex = media.length;
|
|
934
|
-
let validCount = 0;
|
|
935
|
-
const invalidParts = [];
|
|
936
|
-
let hasValidMedia = false;
|
|
937
|
-
for (const part of parts) {
|
|
938
|
-
const candidate = normalizeMediaSource(cleanCandidate(part));
|
|
939
|
-
if (isValidMedia(candidate, unwrapped ? { allowSpaces: true } : void 0)) {
|
|
940
|
-
media.push(candidate);
|
|
941
|
-
hasValidMedia = true;
|
|
942
|
-
foundMediaToken = true;
|
|
943
|
-
validCount += 1;
|
|
944
|
-
} else invalidParts.push(part);
|
|
945
|
-
}
|
|
946
|
-
const trimmedPayload = payloadValue.trim();
|
|
947
|
-
const looksLikeLocalPath = isLikelyLocalPath(trimmedPayload) || trimmedPayload.startsWith("file://");
|
|
948
|
-
if (!unwrapped && validCount === 1 && invalidParts.length > 0 && /\s/.test(payloadValue) && looksLikeLocalPath) {
|
|
949
|
-
const fallback = normalizeMediaSource(cleanCandidate(payloadValue));
|
|
950
|
-
if (isValidMedia(fallback, { allowSpaces: true })) {
|
|
951
|
-
media.splice(mediaStartIndex, media.length - mediaStartIndex, fallback);
|
|
952
|
-
hasValidMedia = true;
|
|
953
|
-
foundMediaToken = true;
|
|
954
|
-
validCount = 1;
|
|
955
|
-
invalidParts.length = 0;
|
|
956
|
-
}
|
|
957
|
-
}
|
|
958
|
-
if (!hasValidMedia) {
|
|
959
|
-
const fallback = normalizeMediaSource(cleanCandidate(payloadValue));
|
|
960
|
-
if (isValidMedia(fallback, {
|
|
961
|
-
allowSpaces: true,
|
|
962
|
-
allowBareFilename: true
|
|
963
|
-
})) {
|
|
964
|
-
media.push(fallback);
|
|
965
|
-
hasValidMedia = true;
|
|
966
|
-
foundMediaToken = true;
|
|
967
|
-
invalidParts.length = 0;
|
|
968
|
-
}
|
|
969
|
-
}
|
|
970
|
-
if (hasValidMedia) {
|
|
971
|
-
if (invalidParts.length > 0) pieces.push(invalidParts.join(" "));
|
|
972
|
-
} else if (looksLikeLocalPath) foundMediaToken = true;
|
|
973
|
-
else pieces.push(match[0]);
|
|
974
|
-
cursor = start + match[0].length;
|
|
975
|
-
}
|
|
976
|
-
pieces.push(line.slice(cursor));
|
|
977
|
-
const cleanedLine = pieces.join("").replace(/[ \t]{2,}/g, " ").trim();
|
|
978
|
-
if (cleanedLine) keptLines.push(cleanedLine);
|
|
979
|
-
lineOffset += line.length + 1;
|
|
980
|
-
}
|
|
981
|
-
let cleanedText = keptLines.join("\n").replace(/[ \t]+\n/g, "\n").replace(/[ \t]{2,}/g, " ").replace(/\n{2,}/g, "\n").trim();
|
|
982
|
-
const audioTagResult = parseAudioTag(cleanedText);
|
|
983
|
-
const hasAudioAsVoice = audioTagResult.audioAsVoice;
|
|
984
|
-
if (audioTagResult.hadTag) cleanedText = audioTagResult.text.replace(/\n{2,}/g, "\n").trim();
|
|
985
|
-
if (media.length === 0) {
|
|
986
|
-
const result = { text: foundMediaToken || hasAudioAsVoice ? cleanedText : trimmedRaw };
|
|
987
|
-
if (hasAudioAsVoice) result.audioAsVoice = true;
|
|
988
|
-
return result;
|
|
989
|
-
}
|
|
990
|
-
return {
|
|
991
|
-
text: cleanedText,
|
|
992
|
-
mediaUrls: media,
|
|
993
|
-
mediaUrl: media[0],
|
|
994
|
-
...hasAudioAsVoice ? { audioAsVoice: true } : {}
|
|
995
|
-
};
|
|
996
|
-
}
|
|
997
|
-
|
|
998
|
-
//#endregion
|
|
999
|
-
//#region src/auto-reply/reply/reply-directives.ts
|
|
1000
|
-
function parseReplyDirectives(raw, options = {}) {
|
|
1001
|
-
const split = splitMediaFromOutput(raw);
|
|
1002
|
-
let text = split.text ?? "";
|
|
1003
|
-
const replyParsed = parseInlineDirectives(text, {
|
|
1004
|
-
currentMessageId: options.currentMessageId,
|
|
1005
|
-
stripAudioTag: false,
|
|
1006
|
-
stripReplyTags: true
|
|
1007
|
-
});
|
|
1008
|
-
if (replyParsed.hasReplyTag) text = replyParsed.text;
|
|
1009
|
-
const silentToken = options.silentToken ?? SILENT_REPLY_TOKEN;
|
|
1010
|
-
const isSilent = isSilentReplyText(text, silentToken);
|
|
1011
|
-
if (isSilent) text = "";
|
|
1012
|
-
return {
|
|
1013
|
-
text,
|
|
1014
|
-
mediaUrls: split.mediaUrls,
|
|
1015
|
-
mediaUrl: split.mediaUrl,
|
|
1016
|
-
replyToId: replyParsed.replyToId,
|
|
1017
|
-
replyToCurrent: replyParsed.replyToCurrent,
|
|
1018
|
-
replyToTag: replyParsed.hasReplyTag,
|
|
1019
|
-
audioAsVoice: split.audioAsVoice,
|
|
1020
|
-
isSilent
|
|
1021
|
-
};
|
|
1022
|
-
}
|
|
1023
|
-
|
|
1024
|
-
//#endregion
|
|
1025
|
-
//#region src/infra/outbound/abort.ts
|
|
1026
|
-
/**
|
|
1027
|
-
* Utility for checking AbortSignal state and throwing a standard AbortError.
|
|
1028
|
-
*/
|
|
1029
|
-
/**
|
|
1030
|
-
* Throws an AbortError if the given signal has been aborted.
|
|
1031
|
-
* Use at async checkpoints to support cancellation.
|
|
1032
|
-
*/
|
|
1033
|
-
function throwIfAborted(abortSignal) {
|
|
1034
|
-
if (abortSignal?.aborted) {
|
|
1035
|
-
const err = /* @__PURE__ */ new Error("Operation aborted");
|
|
1036
|
-
err.name = "AbortError";
|
|
1037
|
-
throw err;
|
|
1038
|
-
}
|
|
1039
|
-
}
|
|
1040
|
-
|
|
1041
|
-
//#endregion
|
|
1042
|
-
//#region src/channels/plugins/registry-loader.ts
|
|
1043
|
-
function createChannelRegistryLoader(resolveValue) {
|
|
1044
|
-
const cache = /* @__PURE__ */ new Map();
|
|
1045
|
-
let lastRegistry = null;
|
|
1046
|
-
return async (id) => {
|
|
1047
|
-
const registry = getActivePluginRegistry();
|
|
1048
|
-
if (registry !== lastRegistry) {
|
|
1049
|
-
cache.clear();
|
|
1050
|
-
lastRegistry = registry;
|
|
1051
|
-
}
|
|
1052
|
-
const cached = cache.get(id);
|
|
1053
|
-
if (cached) return cached;
|
|
1054
|
-
const pluginEntry = registry?.channels.find((entry) => entry.plugin.id === id);
|
|
1055
|
-
if (!pluginEntry) return;
|
|
1056
|
-
const resolved = resolveValue(pluginEntry);
|
|
1057
|
-
if (resolved) cache.set(id, resolved);
|
|
1058
|
-
return resolved;
|
|
1059
|
-
};
|
|
1060
|
-
}
|
|
1061
|
-
|
|
1062
|
-
//#endregion
|
|
1063
|
-
//#region src/channels/plugins/outbound/load.ts
|
|
1064
|
-
const loadOutboundAdapterFromRegistry = createChannelRegistryLoader((entry) => entry.plugin.outbound);
|
|
1065
|
-
async function loadChannelOutboundAdapter(id) {
|
|
1066
|
-
return loadOutboundAdapterFromRegistry(id);
|
|
1067
|
-
}
|
|
1068
|
-
|
|
1069
|
-
//#endregion
|
|
1070
|
-
//#region src/infra/outbound/delivery-queue.ts
|
|
1071
|
-
const QUEUE_DIRNAME = "delivery-queue";
|
|
1072
|
-
const FAILED_DIRNAME = "failed";
|
|
1073
|
-
function resolveQueueDir(stateDir) {
|
|
1074
|
-
const base = stateDir ?? resolveStateDir();
|
|
1075
|
-
return path.join(base, QUEUE_DIRNAME);
|
|
1076
|
-
}
|
|
1077
|
-
function resolveFailedDir(stateDir) {
|
|
1078
|
-
return path.join(resolveQueueDir(stateDir), FAILED_DIRNAME);
|
|
1079
|
-
}
|
|
1080
|
-
/** Ensure the queue directory (and failed/ subdirectory) exist. */
|
|
1081
|
-
async function ensureQueueDir(stateDir) {
|
|
1082
|
-
const queueDir = resolveQueueDir(stateDir);
|
|
1083
|
-
await fs.promises.mkdir(queueDir, {
|
|
1084
|
-
recursive: true,
|
|
1085
|
-
mode: 448
|
|
1086
|
-
});
|
|
1087
|
-
await fs.promises.mkdir(resolveFailedDir(stateDir), {
|
|
1088
|
-
recursive: true,
|
|
1089
|
-
mode: 448
|
|
1090
|
-
});
|
|
1091
|
-
return queueDir;
|
|
1092
|
-
}
|
|
1093
|
-
async function enqueueDelivery(params, stateDir) {
|
|
1094
|
-
const queueDir = await ensureQueueDir(stateDir);
|
|
1095
|
-
const id = generateSecureUuid();
|
|
1096
|
-
const entry = {
|
|
1097
|
-
id,
|
|
1098
|
-
enqueuedAt: Date.now(),
|
|
1099
|
-
channel: params.channel,
|
|
1100
|
-
to: params.to,
|
|
1101
|
-
accountId: params.accountId,
|
|
1102
|
-
payloads: params.payloads,
|
|
1103
|
-
threadId: params.threadId,
|
|
1104
|
-
replyToId: params.replyToId,
|
|
1105
|
-
bestEffort: params.bestEffort,
|
|
1106
|
-
gifPlayback: params.gifPlayback,
|
|
1107
|
-
silent: params.silent,
|
|
1108
|
-
mirror: params.mirror,
|
|
1109
|
-
retryCount: 0
|
|
1110
|
-
};
|
|
1111
|
-
const filePath = path.join(queueDir, `${id}.json`);
|
|
1112
|
-
const tmp = `${filePath}.${process.pid}.tmp`;
|
|
1113
|
-
const json = JSON.stringify(entry, null, 2);
|
|
1114
|
-
await fs.promises.writeFile(tmp, json, {
|
|
1115
|
-
encoding: "utf-8",
|
|
1116
|
-
mode: 384
|
|
1117
|
-
});
|
|
1118
|
-
await fs.promises.rename(tmp, filePath);
|
|
1119
|
-
return id;
|
|
1120
|
-
}
|
|
1121
|
-
/** Remove a successfully delivered entry from the queue. */
|
|
1122
|
-
async function ackDelivery(id, stateDir) {
|
|
1123
|
-
const filePath = path.join(resolveQueueDir(stateDir), `${id}.json`);
|
|
1124
|
-
try {
|
|
1125
|
-
await fs.promises.unlink(filePath);
|
|
1126
|
-
} catch (err) {
|
|
1127
|
-
if ((err && typeof err === "object" && "code" in err ? String(err.code) : null) !== "ENOENT") throw err;
|
|
1128
|
-
}
|
|
1129
|
-
}
|
|
1130
|
-
/** Update a queue entry after a failed delivery attempt. */
|
|
1131
|
-
async function failDelivery(id, error, stateDir) {
|
|
1132
|
-
const filePath = path.join(resolveQueueDir(stateDir), `${id}.json`);
|
|
1133
|
-
const raw = await fs.promises.readFile(filePath, "utf-8");
|
|
1134
|
-
const entry = JSON.parse(raw);
|
|
1135
|
-
entry.retryCount += 1;
|
|
1136
|
-
entry.lastAttemptAt = Date.now();
|
|
1137
|
-
entry.lastError = error;
|
|
1138
|
-
const tmp = `${filePath}.${process.pid}.tmp`;
|
|
1139
|
-
await fs.promises.writeFile(tmp, JSON.stringify(entry, null, 2), {
|
|
1140
|
-
encoding: "utf-8",
|
|
1141
|
-
mode: 384
|
|
1142
|
-
});
|
|
1143
|
-
await fs.promises.rename(tmp, filePath);
|
|
1144
|
-
}
|
|
1145
|
-
|
|
1146
|
-
//#endregion
|
|
1147
|
-
//#region src/infra/outbound/payloads.ts
|
|
1148
|
-
function mergeMediaUrls(...lists) {
|
|
1149
|
-
const seen = /* @__PURE__ */ new Set();
|
|
1150
|
-
const merged = [];
|
|
1151
|
-
for (const list of lists) {
|
|
1152
|
-
if (!list) continue;
|
|
1153
|
-
for (const entry of list) {
|
|
1154
|
-
const trimmed = entry?.trim();
|
|
1155
|
-
if (!trimmed) continue;
|
|
1156
|
-
if (seen.has(trimmed)) continue;
|
|
1157
|
-
seen.add(trimmed);
|
|
1158
|
-
merged.push(trimmed);
|
|
1159
|
-
}
|
|
1160
|
-
}
|
|
1161
|
-
return merged;
|
|
1162
|
-
}
|
|
1163
|
-
function normalizeReplyPayloadsForDelivery(payloads) {
|
|
1164
|
-
const normalized = [];
|
|
1165
|
-
for (const payload of payloads) {
|
|
1166
|
-
if (shouldSuppressReasoningPayload(payload)) continue;
|
|
1167
|
-
const parsed = parseReplyDirectives(payload.text ?? "");
|
|
1168
|
-
const explicitMediaUrls = payload.mediaUrls ?? parsed.mediaUrls;
|
|
1169
|
-
const explicitMediaUrl = payload.mediaUrl ?? parsed.mediaUrl;
|
|
1170
|
-
const mergedMedia = mergeMediaUrls(explicitMediaUrls, explicitMediaUrl ? [explicitMediaUrl] : void 0);
|
|
1171
|
-
const resolvedMediaUrl = (explicitMediaUrls?.length ?? 0) > 1 ? void 0 : explicitMediaUrl;
|
|
1172
|
-
const next = {
|
|
1173
|
-
...payload,
|
|
1174
|
-
text: parsed.text ?? "",
|
|
1175
|
-
mediaUrls: mergedMedia.length ? mergedMedia : void 0,
|
|
1176
|
-
mediaUrl: resolvedMediaUrl,
|
|
1177
|
-
replyToId: payload.replyToId ?? parsed.replyToId,
|
|
1178
|
-
replyToTag: payload.replyToTag || parsed.replyToTag,
|
|
1179
|
-
replyToCurrent: payload.replyToCurrent || parsed.replyToCurrent,
|
|
1180
|
-
audioAsVoice: Boolean(payload.audioAsVoice || parsed.audioAsVoice)
|
|
1181
|
-
};
|
|
1182
|
-
if (parsed.isSilent && mergedMedia.length === 0) continue;
|
|
1183
|
-
if (!isRenderablePayload(next)) continue;
|
|
1184
|
-
normalized.push(next);
|
|
1185
|
-
}
|
|
1186
|
-
return normalized;
|
|
1187
|
-
}
|
|
1188
|
-
function normalizeOutboundPayloads(payloads) {
|
|
1189
|
-
const normalizedPayloads = [];
|
|
1190
|
-
for (const payload of normalizeReplyPayloadsForDelivery(payloads)) {
|
|
1191
|
-
const mediaUrls = payload.mediaUrls ?? (payload.mediaUrl ? [payload.mediaUrl] : []);
|
|
1192
|
-
const channelData = payload.channelData;
|
|
1193
|
-
const hasChannelData = Boolean(channelData && Object.keys(channelData).length > 0);
|
|
1194
|
-
const text = payload.text ?? "";
|
|
1195
|
-
if (!text && mediaUrls.length === 0 && !hasChannelData) continue;
|
|
1196
|
-
normalizedPayloads.push({
|
|
1197
|
-
text,
|
|
1198
|
-
mediaUrls,
|
|
1199
|
-
...hasChannelData ? { channelData } : {}
|
|
1200
|
-
});
|
|
1201
|
-
}
|
|
1202
|
-
return normalizedPayloads;
|
|
1203
|
-
}
|
|
1204
|
-
function normalizeOutboundPayloadsForJson(payloads) {
|
|
1205
|
-
const normalized = [];
|
|
1206
|
-
for (const payload of normalizeReplyPayloadsForDelivery(payloads)) normalized.push({
|
|
1207
|
-
text: payload.text ?? "",
|
|
1208
|
-
mediaUrl: payload.mediaUrl ?? null,
|
|
1209
|
-
mediaUrls: payload.mediaUrls ?? (payload.mediaUrl ? [payload.mediaUrl] : void 0),
|
|
1210
|
-
channelData: payload.channelData
|
|
1211
|
-
});
|
|
1212
|
-
return normalized;
|
|
1213
|
-
}
|
|
1214
|
-
function formatOutboundPayloadLog(payload) {
|
|
1215
|
-
const lines = [];
|
|
1216
|
-
if (payload.text) lines.push(payload.text.trimEnd());
|
|
1217
|
-
for (const url of payload.mediaUrls) lines.push(`MEDIA:${url}`);
|
|
1218
|
-
return lines.join("\n");
|
|
1219
|
-
}
|
|
1220
|
-
|
|
1221
|
-
//#endregion
|
|
1222
|
-
//#region src/infra/outbound/sanitize-text.ts
|
|
1223
|
-
/**
|
|
1224
|
-
* Sanitize model output for plain-text messaging surfaces.
|
|
1225
|
-
*
|
|
1226
|
-
* LLMs occasionally produce HTML tags (`<br>`, `<b>`, `<i>`, etc.) that render
|
|
1227
|
-
* correctly on web but appear as literal text on WhatsApp, Signal, SMS, and IRC.
|
|
1228
|
-
*
|
|
1229
|
-
* Converts common inline HTML to lightweight-markup equivalents used by
|
|
1230
|
-
* WhatsApp/Signal/Telegram and strips any remaining tags.
|
|
1231
|
-
*
|
|
1232
|
-
* @see https://github.com/squidclaw/squidclaw/issues/31884
|
|
1233
|
-
* @see https://github.com/squidclaw/squidclaw/issues/18558
|
|
1234
|
-
*/
|
|
1235
|
-
/** Channels where HTML tags should be converted/stripped. */
|
|
1236
|
-
const PLAIN_TEXT_SURFACES = new Set([
|
|
1237
|
-
"whatsapp",
|
|
1238
|
-
"signal",
|
|
1239
|
-
"sms",
|
|
1240
|
-
"irc",
|
|
1241
|
-
"telegram",
|
|
1242
|
-
"imessage",
|
|
1243
|
-
"googlechat"
|
|
1244
|
-
]);
|
|
1245
|
-
/** Returns `true` when the channel cannot render raw HTML. */
|
|
1246
|
-
function isPlainTextSurface(channelId) {
|
|
1247
|
-
return PLAIN_TEXT_SURFACES.has(channelId.toLowerCase());
|
|
1248
|
-
}
|
|
1249
|
-
/**
|
|
1250
|
-
* Convert common HTML tags to their plain-text/lightweight-markup equivalents
|
|
1251
|
-
* and strip anything that remains.
|
|
1252
|
-
*
|
|
1253
|
-
* The function is intentionally conservative — it only targets tags that models
|
|
1254
|
-
* are known to produce and avoids false positives on angle brackets in normal
|
|
1255
|
-
* prose (e.g. `a < b`).
|
|
1256
|
-
*/
|
|
1257
|
-
function sanitizeForPlainText(text) {
|
|
1258
|
-
return text.replace(/<((?:https?:\/\/|mailto:)[^<>\s]+)>/gi, "$1").replace(/<br\s*\/?>/gi, "\n").replace(/<\/?(p|div)>/gi, "\n").replace(/<(b|strong)>(.*?)<\/\1>/gi, "*$2*").replace(/<(i|em)>(.*?)<\/\1>/gi, "_$2_").replace(/<(s|strike|del)>(.*?)<\/\1>/gi, "~$2~").replace(/<code>(.*?)<\/code>/gi, "`$1`").replace(/<h[1-6][^>]*>(.*?)<\/h[1-6]>/gi, "\n*$1*\n").replace(/<li[^>]*>(.*?)<\/li>/gi, "• $1\n").replace(/<\/?[a-z][a-z0-9]*\b[^>]*>/gi, "").replace(/\n{3,}/g, "\n\n");
|
|
1259
|
-
}
|
|
1260
|
-
|
|
1261
|
-
//#endregion
|
|
1262
|
-
//#region src/infra/outbound/deliver.ts
|
|
1263
|
-
const log = createSubsystemLogger("outbound/deliver");
|
|
1264
|
-
const TELEGRAM_TEXT_LIMIT = 4096;
|
|
1265
|
-
async function createChannelHandler(params) {
|
|
1266
|
-
const outbound = await loadChannelOutboundAdapter(params.channel);
|
|
1267
|
-
const handler = createPluginHandler({
|
|
1268
|
-
...params,
|
|
1269
|
-
outbound
|
|
1270
|
-
});
|
|
1271
|
-
if (!handler) throw new Error(`Outbound not configured for channel: ${params.channel}`);
|
|
1272
|
-
return handler;
|
|
1273
|
-
}
|
|
1274
|
-
function createPluginHandler(params) {
|
|
1275
|
-
const outbound = params.outbound;
|
|
1276
|
-
if (!outbound?.sendText || !outbound?.sendMedia) return null;
|
|
1277
|
-
const baseCtx = createChannelOutboundContextBase(params);
|
|
1278
|
-
const sendText = outbound.sendText;
|
|
1279
|
-
const sendMedia = outbound.sendMedia;
|
|
1280
|
-
const chunker = outbound.chunker ?? null;
|
|
1281
|
-
const chunkerMode = outbound.chunkerMode;
|
|
1282
|
-
const resolveCtx = (overrides) => ({
|
|
1283
|
-
...baseCtx,
|
|
1284
|
-
replyToId: overrides?.replyToId ?? baseCtx.replyToId,
|
|
1285
|
-
threadId: overrides?.threadId ?? baseCtx.threadId
|
|
1286
|
-
});
|
|
1287
|
-
return {
|
|
1288
|
-
chunker,
|
|
1289
|
-
chunkerMode,
|
|
1290
|
-
textChunkLimit: outbound.textChunkLimit,
|
|
1291
|
-
sendPayload: outbound.sendPayload ? async (payload, overrides) => outbound.sendPayload({
|
|
1292
|
-
...resolveCtx(overrides),
|
|
1293
|
-
text: payload.text ?? "",
|
|
1294
|
-
mediaUrl: payload.mediaUrl,
|
|
1295
|
-
payload
|
|
1296
|
-
}) : void 0,
|
|
1297
|
-
sendText: async (text, overrides) => sendText({
|
|
1298
|
-
...resolveCtx(overrides),
|
|
1299
|
-
text
|
|
1300
|
-
}),
|
|
1301
|
-
sendMedia: async (caption, mediaUrl, overrides) => sendMedia({
|
|
1302
|
-
...resolveCtx(overrides),
|
|
1303
|
-
text: caption,
|
|
1304
|
-
mediaUrl
|
|
1305
|
-
})
|
|
1306
|
-
};
|
|
1307
|
-
}
|
|
1308
|
-
function createChannelOutboundContextBase(params) {
|
|
1309
|
-
return {
|
|
1310
|
-
cfg: params.cfg,
|
|
1311
|
-
to: params.to,
|
|
1312
|
-
accountId: params.accountId,
|
|
1313
|
-
replyToId: params.replyToId,
|
|
1314
|
-
threadId: params.threadId,
|
|
1315
|
-
identity: params.identity,
|
|
1316
|
-
gifPlayback: params.gifPlayback,
|
|
1317
|
-
deps: params.deps,
|
|
1318
|
-
silent: params.silent,
|
|
1319
|
-
mediaLocalRoots: params.mediaLocalRoots
|
|
1320
|
-
};
|
|
1321
|
-
}
|
|
1322
|
-
const isAbortError = (err) => err instanceof Error && err.name === "AbortError";
|
|
1323
|
-
function hasMediaPayload(payload) {
|
|
1324
|
-
return Boolean(payload.mediaUrl) || (payload.mediaUrls?.length ?? 0) > 0;
|
|
1325
|
-
}
|
|
1326
|
-
function hasChannelDataPayload(payload) {
|
|
1327
|
-
return Boolean(payload.channelData && Object.keys(payload.channelData).length > 0);
|
|
1328
|
-
}
|
|
1329
|
-
function normalizePayloadForChannelDelivery(payload, channelId) {
|
|
1330
|
-
const hasMedia = hasMediaPayload(payload);
|
|
1331
|
-
const hasChannelData = hasChannelDataPayload(payload);
|
|
1332
|
-
const rawText = typeof payload.text === "string" ? payload.text : "";
|
|
1333
|
-
const normalizedText = channelId === "whatsapp" ? rawText.replace(/^(?:[ \t]*\r?\n)+/, "") : rawText;
|
|
1334
|
-
if (!normalizedText.trim()) {
|
|
1335
|
-
if (!hasMedia && !hasChannelData) return null;
|
|
1336
|
-
return {
|
|
1337
|
-
...payload,
|
|
1338
|
-
text: ""
|
|
1339
|
-
};
|
|
1340
|
-
}
|
|
1341
|
-
if (normalizedText === rawText) return payload;
|
|
1342
|
-
return {
|
|
1343
|
-
...payload,
|
|
1344
|
-
text: normalizedText
|
|
1345
|
-
};
|
|
1346
|
-
}
|
|
1347
|
-
function normalizePayloadsForChannelDelivery(payloads, channel) {
|
|
1348
|
-
const normalizedPayloads = [];
|
|
1349
|
-
for (const payload of normalizeReplyPayloadsForDelivery(payloads)) {
|
|
1350
|
-
let sanitizedPayload = payload;
|
|
1351
|
-
if (isPlainTextSurface(channel) && payload.text) {
|
|
1352
|
-
if (!(channel === "telegram" && payload.channelData)) sanitizedPayload = {
|
|
1353
|
-
...payload,
|
|
1354
|
-
text: sanitizeForPlainText(payload.text)
|
|
1355
|
-
};
|
|
1356
|
-
}
|
|
1357
|
-
const normalized = normalizePayloadForChannelDelivery(sanitizedPayload, channel);
|
|
1358
|
-
if (normalized) normalizedPayloads.push(normalized);
|
|
1359
|
-
}
|
|
1360
|
-
return normalizedPayloads;
|
|
1361
|
-
}
|
|
1362
|
-
function buildPayloadSummary(payload) {
|
|
1363
|
-
return {
|
|
1364
|
-
text: payload.text ?? "",
|
|
1365
|
-
mediaUrls: payload.mediaUrls ?? (payload.mediaUrl ? [payload.mediaUrl] : []),
|
|
1366
|
-
channelData: payload.channelData
|
|
1367
|
-
};
|
|
1368
|
-
}
|
|
1369
|
-
function createMessageSentEmitter(params) {
|
|
1370
|
-
const hasMessageSentHooks = params.hookRunner?.hasHooks("message_sent") ?? false;
|
|
1371
|
-
const canEmitInternalHook = Boolean(params.sessionKeyForInternalHooks);
|
|
1372
|
-
const emitMessageSent = (event) => {
|
|
1373
|
-
if (!hasMessageSentHooks && !canEmitInternalHook) return;
|
|
1374
|
-
const canonical = buildCanonicalSentMessageHookContext({
|
|
1375
|
-
to: params.to,
|
|
1376
|
-
content: event.content,
|
|
1377
|
-
success: event.success,
|
|
1378
|
-
error: event.error,
|
|
1379
|
-
channelId: params.channel,
|
|
1380
|
-
accountId: params.accountId ?? void 0,
|
|
1381
|
-
conversationId: params.to,
|
|
1382
|
-
messageId: event.messageId,
|
|
1383
|
-
isGroup: params.mirrorIsGroup,
|
|
1384
|
-
groupId: params.mirrorGroupId
|
|
1385
|
-
});
|
|
1386
|
-
if (hasMessageSentHooks) fireAndForgetHook(params.hookRunner.runMessageSent(toPluginMessageSentEvent(canonical), toPluginMessageContext(canonical)), "deliverOutboundPayloads: message_sent plugin hook failed", (message) => {
|
|
1387
|
-
log.warn(message);
|
|
1388
|
-
});
|
|
1389
|
-
if (!canEmitInternalHook) return;
|
|
1390
|
-
fireAndForgetHook(triggerInternalHook(createInternalHookEvent("message", "sent", params.sessionKeyForInternalHooks, toInternalMessageSentContext(canonical))), "deliverOutboundPayloads: message:sent internal hook failed", (message) => {
|
|
1391
|
-
log.warn(message);
|
|
1392
|
-
});
|
|
1393
|
-
};
|
|
1394
|
-
return {
|
|
1395
|
-
emitMessageSent,
|
|
1396
|
-
hasMessageSentHooks
|
|
1397
|
-
};
|
|
1398
|
-
}
|
|
1399
|
-
async function applyMessageSendingHook(params) {
|
|
1400
|
-
if (!params.enabled) return {
|
|
1401
|
-
cancelled: false,
|
|
1402
|
-
payload: params.payload,
|
|
1403
|
-
payloadSummary: params.payloadSummary
|
|
1404
|
-
};
|
|
1405
|
-
try {
|
|
1406
|
-
const sendingResult = await params.hookRunner.runMessageSending({
|
|
1407
|
-
to: params.to,
|
|
1408
|
-
content: params.payloadSummary.text,
|
|
1409
|
-
metadata: {
|
|
1410
|
-
channel: params.channel,
|
|
1411
|
-
accountId: params.accountId,
|
|
1412
|
-
mediaUrls: params.payloadSummary.mediaUrls
|
|
1413
|
-
}
|
|
1414
|
-
}, {
|
|
1415
|
-
channelId: params.channel,
|
|
1416
|
-
accountId: params.accountId ?? void 0
|
|
1417
|
-
});
|
|
1418
|
-
if (sendingResult?.cancel) return {
|
|
1419
|
-
cancelled: true,
|
|
1420
|
-
payload: params.payload,
|
|
1421
|
-
payloadSummary: params.payloadSummary
|
|
1422
|
-
};
|
|
1423
|
-
if (sendingResult?.content == null) return {
|
|
1424
|
-
cancelled: false,
|
|
1425
|
-
payload: params.payload,
|
|
1426
|
-
payloadSummary: params.payloadSummary
|
|
1427
|
-
};
|
|
1428
|
-
return {
|
|
1429
|
-
cancelled: false,
|
|
1430
|
-
payload: {
|
|
1431
|
-
...params.payload,
|
|
1432
|
-
text: sendingResult.content
|
|
1433
|
-
},
|
|
1434
|
-
payloadSummary: {
|
|
1435
|
-
...params.payloadSummary,
|
|
1436
|
-
text: sendingResult.content
|
|
1437
|
-
}
|
|
1438
|
-
};
|
|
1439
|
-
} catch {
|
|
1440
|
-
return {
|
|
1441
|
-
cancelled: false,
|
|
1442
|
-
payload: params.payload,
|
|
1443
|
-
payloadSummary: params.payloadSummary
|
|
1444
|
-
};
|
|
1445
|
-
}
|
|
1446
|
-
}
|
|
1447
|
-
async function deliverOutboundPayloads(params) {
|
|
1448
|
-
const { channel, to, payloads } = params;
|
|
1449
|
-
const queueId = params.skipQueue ? null : await enqueueDelivery({
|
|
1450
|
-
channel,
|
|
1451
|
-
to,
|
|
1452
|
-
accountId: params.accountId,
|
|
1453
|
-
payloads,
|
|
1454
|
-
threadId: params.threadId,
|
|
1455
|
-
replyToId: params.replyToId,
|
|
1456
|
-
bestEffort: params.bestEffort,
|
|
1457
|
-
gifPlayback: params.gifPlayback,
|
|
1458
|
-
silent: params.silent,
|
|
1459
|
-
mirror: params.mirror
|
|
1460
|
-
}).catch(() => null);
|
|
1461
|
-
let hadPartialFailure = false;
|
|
1462
|
-
const wrappedParams = params.onError ? {
|
|
1463
|
-
...params,
|
|
1464
|
-
onError: (err, payload) => {
|
|
1465
|
-
hadPartialFailure = true;
|
|
1466
|
-
params.onError(err, payload);
|
|
1467
|
-
}
|
|
1468
|
-
} : params;
|
|
1469
|
-
try {
|
|
1470
|
-
const results = await deliverOutboundPayloadsCore(wrappedParams);
|
|
1471
|
-
if (queueId) if (hadPartialFailure) await failDelivery(queueId, "partial delivery failure (bestEffort)").catch(() => {});
|
|
1472
|
-
else await ackDelivery(queueId).catch(() => {});
|
|
1473
|
-
return results;
|
|
1474
|
-
} catch (err) {
|
|
1475
|
-
if (queueId) if (isAbortError(err)) await ackDelivery(queueId).catch(() => {});
|
|
1476
|
-
else await failDelivery(queueId, err instanceof Error ? err.message : String(err)).catch(() => {});
|
|
1477
|
-
throw err;
|
|
1478
|
-
}
|
|
1479
|
-
}
|
|
1480
|
-
/** Core delivery logic (extracted for queue wrapper). */
|
|
1481
|
-
async function deliverOutboundPayloadsCore(params) {
|
|
1482
|
-
const { cfg, channel, to, payloads } = params;
|
|
1483
|
-
const accountId = params.accountId;
|
|
1484
|
-
const deps = params.deps;
|
|
1485
|
-
const abortSignal = params.abortSignal;
|
|
1486
|
-
const sendSignal = params.deps?.sendSignal ?? sendMessageSignal;
|
|
1487
|
-
const mediaLocalRoots = getAgentScopedMediaLocalRoots(cfg, params.session?.agentId ?? params.mirror?.agentId);
|
|
1488
|
-
const results = [];
|
|
1489
|
-
const handler = await createChannelHandler({
|
|
1490
|
-
cfg,
|
|
1491
|
-
channel,
|
|
1492
|
-
to,
|
|
1493
|
-
deps,
|
|
1494
|
-
accountId,
|
|
1495
|
-
replyToId: params.replyToId,
|
|
1496
|
-
threadId: params.threadId,
|
|
1497
|
-
identity: params.identity,
|
|
1498
|
-
gifPlayback: params.gifPlayback,
|
|
1499
|
-
silent: params.silent,
|
|
1500
|
-
mediaLocalRoots
|
|
1501
|
-
});
|
|
1502
|
-
const configuredTextLimit = handler.chunker ? resolveTextChunkLimit(cfg, channel, accountId, { fallbackLimit: handler.textChunkLimit }) : void 0;
|
|
1503
|
-
const textLimit = channel === "telegram" && typeof configuredTextLimit === "number" ? Math.min(configuredTextLimit, TELEGRAM_TEXT_LIMIT) : configuredTextLimit;
|
|
1504
|
-
const chunkMode = handler.chunker ? resolveChunkMode(cfg, channel, accountId) : "length";
|
|
1505
|
-
const isSignalChannel = channel === "signal";
|
|
1506
|
-
const signalTableMode = isSignalChannel ? resolveMarkdownTableMode({
|
|
1507
|
-
cfg,
|
|
1508
|
-
channel: "signal",
|
|
1509
|
-
accountId
|
|
1510
|
-
}) : "code";
|
|
1511
|
-
const signalMaxBytes = isSignalChannel ? resolveChannelMediaMaxBytes({
|
|
1512
|
-
cfg,
|
|
1513
|
-
resolveChannelLimitMb: ({ cfg, accountId }) => cfg.channels?.signal?.accounts?.[accountId]?.mediaMaxMb ?? cfg.channels?.signal?.mediaMaxMb,
|
|
1514
|
-
accountId
|
|
1515
|
-
}) : void 0;
|
|
1516
|
-
const sendTextChunks = async (text, overrides) => {
|
|
1517
|
-
throwIfAborted(abortSignal);
|
|
1518
|
-
if (!handler.chunker || textLimit === void 0) {
|
|
1519
|
-
results.push(await handler.sendText(text, overrides));
|
|
1520
|
-
return;
|
|
1521
|
-
}
|
|
1522
|
-
if (chunkMode === "newline") {
|
|
1523
|
-
const blockChunks = (handler.chunkerMode ?? "text") === "markdown" ? chunkMarkdownTextWithMode(text, textLimit, "newline") : chunkByParagraph(text, textLimit);
|
|
1524
|
-
if (!blockChunks.length && text) blockChunks.push(text);
|
|
1525
|
-
for (const blockChunk of blockChunks) {
|
|
1526
|
-
const chunks = handler.chunker(blockChunk, textLimit);
|
|
1527
|
-
if (!chunks.length && blockChunk) chunks.push(blockChunk);
|
|
1528
|
-
for (const chunk of chunks) {
|
|
1529
|
-
throwIfAborted(abortSignal);
|
|
1530
|
-
results.push(await handler.sendText(chunk, overrides));
|
|
1531
|
-
}
|
|
1532
|
-
}
|
|
1533
|
-
return;
|
|
1534
|
-
}
|
|
1535
|
-
const chunks = handler.chunker(text, textLimit);
|
|
1536
|
-
for (const chunk of chunks) {
|
|
1537
|
-
throwIfAborted(abortSignal);
|
|
1538
|
-
results.push(await handler.sendText(chunk, overrides));
|
|
1539
|
-
}
|
|
1540
|
-
};
|
|
1541
|
-
const sendSignalText = async (text, styles) => {
|
|
1542
|
-
throwIfAborted(abortSignal);
|
|
1543
|
-
return {
|
|
1544
|
-
channel: "signal",
|
|
1545
|
-
...await sendSignal(to, text, {
|
|
1546
|
-
cfg,
|
|
1547
|
-
maxBytes: signalMaxBytes,
|
|
1548
|
-
accountId: accountId ?? void 0,
|
|
1549
|
-
textMode: "plain",
|
|
1550
|
-
textStyles: styles
|
|
1551
|
-
})
|
|
1552
|
-
};
|
|
1553
|
-
};
|
|
1554
|
-
const sendSignalTextChunks = async (text) => {
|
|
1555
|
-
throwIfAborted(abortSignal);
|
|
1556
|
-
let signalChunks = textLimit === void 0 ? markdownToSignalTextChunks(text, Number.POSITIVE_INFINITY, { tableMode: signalTableMode }) : markdownToSignalTextChunks(text, textLimit, { tableMode: signalTableMode });
|
|
1557
|
-
if (signalChunks.length === 0 && text) signalChunks = [{
|
|
1558
|
-
text,
|
|
1559
|
-
styles: []
|
|
1560
|
-
}];
|
|
1561
|
-
for (const chunk of signalChunks) {
|
|
1562
|
-
throwIfAborted(abortSignal);
|
|
1563
|
-
results.push(await sendSignalText(chunk.text, chunk.styles));
|
|
1564
|
-
}
|
|
1565
|
-
};
|
|
1566
|
-
const sendSignalMedia = async (caption, mediaUrl) => {
|
|
1567
|
-
throwIfAborted(abortSignal);
|
|
1568
|
-
const formatted = markdownToSignalTextChunks(caption, Number.POSITIVE_INFINITY, { tableMode: signalTableMode })[0] ?? {
|
|
1569
|
-
text: caption,
|
|
1570
|
-
styles: []
|
|
1571
|
-
};
|
|
1572
|
-
return {
|
|
1573
|
-
channel: "signal",
|
|
1574
|
-
...await sendSignal(to, formatted.text, {
|
|
1575
|
-
cfg,
|
|
1576
|
-
mediaUrl,
|
|
1577
|
-
maxBytes: signalMaxBytes,
|
|
1578
|
-
accountId: accountId ?? void 0,
|
|
1579
|
-
textMode: "plain",
|
|
1580
|
-
textStyles: formatted.styles,
|
|
1581
|
-
mediaLocalRoots
|
|
1582
|
-
})
|
|
1583
|
-
};
|
|
1584
|
-
};
|
|
1585
|
-
const normalizedPayloads = normalizePayloadsForChannelDelivery(payloads, channel);
|
|
1586
|
-
const hookRunner = getGlobalHookRunner();
|
|
1587
|
-
const sessionKeyForInternalHooks = params.mirror?.sessionKey ?? params.session?.key;
|
|
1588
|
-
const mirrorIsGroup = params.mirror?.isGroup;
|
|
1589
|
-
const mirrorGroupId = params.mirror?.groupId;
|
|
1590
|
-
const { emitMessageSent, hasMessageSentHooks } = createMessageSentEmitter({
|
|
1591
|
-
hookRunner,
|
|
1592
|
-
channel,
|
|
1593
|
-
to,
|
|
1594
|
-
accountId,
|
|
1595
|
-
sessionKeyForInternalHooks,
|
|
1596
|
-
mirrorIsGroup,
|
|
1597
|
-
mirrorGroupId
|
|
1598
|
-
});
|
|
1599
|
-
const hasMessageSendingHooks = hookRunner?.hasHooks("message_sending") ?? false;
|
|
1600
|
-
if (hasMessageSentHooks && params.session?.agentId && !sessionKeyForInternalHooks) log.warn("deliverOutboundPayloads: session.agentId present without session key; internal message:sent hook will be skipped", {
|
|
1601
|
-
channel,
|
|
1602
|
-
to,
|
|
1603
|
-
agentId: params.session.agentId
|
|
1604
|
-
});
|
|
1605
|
-
for (const payload of normalizedPayloads) {
|
|
1606
|
-
let payloadSummary = buildPayloadSummary(payload);
|
|
1607
|
-
try {
|
|
1608
|
-
throwIfAborted(abortSignal);
|
|
1609
|
-
const hookResult = await applyMessageSendingHook({
|
|
1610
|
-
hookRunner,
|
|
1611
|
-
enabled: hasMessageSendingHooks,
|
|
1612
|
-
payload,
|
|
1613
|
-
payloadSummary,
|
|
1614
|
-
to,
|
|
1615
|
-
channel,
|
|
1616
|
-
accountId
|
|
1617
|
-
});
|
|
1618
|
-
if (hookResult.cancelled) continue;
|
|
1619
|
-
const effectivePayload = hookResult.payload;
|
|
1620
|
-
payloadSummary = hookResult.payloadSummary;
|
|
1621
|
-
params.onPayload?.(payloadSummary);
|
|
1622
|
-
const sendOverrides = {
|
|
1623
|
-
replyToId: effectivePayload.replyToId ?? params.replyToId ?? void 0,
|
|
1624
|
-
threadId: params.threadId ?? void 0
|
|
1625
|
-
};
|
|
1626
|
-
if (handler.sendPayload && effectivePayload.channelData) {
|
|
1627
|
-
const delivery = await handler.sendPayload(effectivePayload, sendOverrides);
|
|
1628
|
-
results.push(delivery);
|
|
1629
|
-
emitMessageSent({
|
|
1630
|
-
success: true,
|
|
1631
|
-
content: payloadSummary.text,
|
|
1632
|
-
messageId: delivery.messageId
|
|
1633
|
-
});
|
|
1634
|
-
continue;
|
|
1635
|
-
}
|
|
1636
|
-
if (payloadSummary.mediaUrls.length === 0) {
|
|
1637
|
-
const beforeCount = results.length;
|
|
1638
|
-
if (isSignalChannel) await sendSignalTextChunks(payloadSummary.text);
|
|
1639
|
-
else await sendTextChunks(payloadSummary.text, sendOverrides);
|
|
1640
|
-
const messageId = results.at(-1)?.messageId;
|
|
1641
|
-
emitMessageSent({
|
|
1642
|
-
success: results.length > beforeCount,
|
|
1643
|
-
content: payloadSummary.text,
|
|
1644
|
-
messageId
|
|
1645
|
-
});
|
|
1646
|
-
continue;
|
|
1647
|
-
}
|
|
1648
|
-
let first = true;
|
|
1649
|
-
let lastMessageId;
|
|
1650
|
-
for (const url of payloadSummary.mediaUrls) {
|
|
1651
|
-
throwIfAborted(abortSignal);
|
|
1652
|
-
const caption = first ? payloadSummary.text : "";
|
|
1653
|
-
first = false;
|
|
1654
|
-
if (isSignalChannel) {
|
|
1655
|
-
const delivery = await sendSignalMedia(caption, url);
|
|
1656
|
-
results.push(delivery);
|
|
1657
|
-
lastMessageId = delivery.messageId;
|
|
1658
|
-
} else {
|
|
1659
|
-
const delivery = await handler.sendMedia(caption, url, sendOverrides);
|
|
1660
|
-
results.push(delivery);
|
|
1661
|
-
lastMessageId = delivery.messageId;
|
|
1662
|
-
}
|
|
1663
|
-
}
|
|
1664
|
-
emitMessageSent({
|
|
1665
|
-
success: true,
|
|
1666
|
-
content: payloadSummary.text,
|
|
1667
|
-
messageId: lastMessageId
|
|
1668
|
-
});
|
|
1669
|
-
} catch (err) {
|
|
1670
|
-
emitMessageSent({
|
|
1671
|
-
success: false,
|
|
1672
|
-
content: payloadSummary.text,
|
|
1673
|
-
error: err instanceof Error ? err.message : String(err)
|
|
1674
|
-
});
|
|
1675
|
-
if (!params.bestEffort) throw err;
|
|
1676
|
-
params.onError?.(err, payloadSummary);
|
|
1677
|
-
}
|
|
1678
|
-
}
|
|
1679
|
-
if (params.mirror && results.length > 0) {
|
|
1680
|
-
const mirrorText = resolveMirroredTranscriptText({
|
|
1681
|
-
text: params.mirror.text,
|
|
1682
|
-
mediaUrls: params.mirror.mediaUrls
|
|
1683
|
-
});
|
|
1684
|
-
if (mirrorText) await appendAssistantMessageToSessionTranscript({
|
|
1685
|
-
agentId: params.mirror.agentId,
|
|
1686
|
-
sessionKey: params.mirror.sessionKey,
|
|
1687
|
-
text: mirrorText
|
|
1688
|
-
});
|
|
1689
|
-
}
|
|
1690
|
-
return results;
|
|
1691
|
-
}
|
|
1692
|
-
|
|
1693
|
-
//#endregion
|
|
1694
|
-
export { resolveChannelMediaMaxBytes as A, createReplyToModeFilterForChannel as C, normalizeTargetForProvider as D, normalizeChannelTargetInput as E, getGlobalHookRunner as O, shouldSuppressReasoningPayload as S, buildTargetResolverSignature as T, applyReplyThreading as _, normalizeReplyPayloadsForDelivery as a, isRenderablePayload as b, splitMediaFromOutput as c, toInternalMessageReceivedContext as d, toInternalMessageTranscribedContext as f, applyReplyTagsToPayload as g, fireAndForgetHook as h, normalizeOutboundPayloadsForJson as i, initializeGlobalHookRunner as k, deriveInboundMessageHookContext as l, toPluginMessageReceivedEvent as m, formatOutboundPayloadLog as n, throwIfAborted as o, toPluginMessageContext as p, normalizeOutboundPayloads as r, parseReplyDirectives as s, deliverOutboundPayloads as t, toInternalMessagePreprocessedContext as u, filterMessagingToolDuplicates as v, resolveReplyToMode as w, shouldSuppressMessagingToolReplies as x, filterMessagingToolMediaDuplicates as y };
|