fengming 0.3.7 → 0.3.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/dist/abort-CCR8oZyg.js +277 -0
- package/dist/abort.runtime-eqx84NZa.js +2 -0
- package/dist/abort.runtime.js +1 -1
- package/dist/acp-spawn-BcDyvaXh.js +2 -0
- package/dist/acp-spawn-CCtSel-_.js +1286 -0
- package/dist/acp-stateful-target-driver-B3pCvuOV.js +89 -0
- package/dist/active-tool-schema-warnings-Cf-5q5WU.js +105 -0
- package/dist/active-tool-schema-warnings-Dzt3XE-y.js +2 -0
- package/dist/agent-1M2dVE2G.js +2 -0
- package/dist/agent-DLDIbUT4.js +1825 -0
- package/dist/agent-DZi6j3o6.js +3 -0
- package/dist/agent-command-ppfDBwET.js +1435 -0
- package/dist/agent-harness-runtime-C0bo62eY.d.ts +913 -0
- package/dist/agent-harness-runtime-RkTGiliR.js +207 -0
- package/dist/agent-runner-utils-B4YeVAO_.js +267 -0
- package/dist/agent-runner.runtime-T_3tlZN1.js +3784 -0
- package/dist/agent-runner.runtime.js +1 -1
- package/dist/agent-runtime-CloshyK-.d.ts +207 -0
- package/dist/agent-runtime-DZsmp1xr.js +199 -0
- package/dist/agent-tools-CET9usCz.js +2506 -0
- package/dist/agent-via-gateway-CZ0X0YkM.js +486 -0
- package/dist/agent-wait-dedupe-I81_F2tr.js +180 -0
- package/dist/agents/embedded-agent-runner/run/runtime-context-prompt.d.ts +1 -1
- package/dist/agents/embedded-agent-runner/tool-split.d.ts +1 -1
- package/dist/agents/model-catalog.runtime.d.ts +1 -1
- package/dist/api-BDB5xHYj.js +3 -0
- package/dist/api-BH7bfI5d.js +6 -0
- package/dist/api-BxJNXitd.js +2 -0
- package/dist/approval-client-helpers-CfQA9Jzh.d.ts +78 -0
- package/dist/approval-native-helpers-B2zyhxWc.d.ts +241 -0
- package/dist/approval-renderers-CMqSXyvm.d.ts +39 -0
- package/dist/assistant-Cu_Mzzgu.js +291 -0
- package/dist/attachment-normalize-Bb3v5iCC.js +213 -0
- package/dist/attempt-execution-BskbAq5I.js +584 -0
- package/dist/attempt-execution.runtime-BuT1wpNS.js +3 -0
- package/dist/attempt-execution.runtime.js +1 -1
- package/dist/attempt.prompt-helpers-ByKj-vQ7.js +543 -0
- package/dist/auto-reply/reply/commands-crestodian.d.ts +1 -1
- package/dist/binding-routing-EGRNvRC4.js +113 -0
- package/dist/binding-targets-B9vYS8n6.js +121 -0
- package/dist/bridge-server-DG9YtKQe.js +113 -0
- package/dist/browser-cli-B0Ou-Nbm.js +2 -0
- package/dist/browser-cli-GF25gL6M.js +230 -0
- package/dist/browser-cli-actions-input-CuER6RVe.js +522 -0
- package/dist/browser-cli-actions-observe-Dq-Zz_FA.js +81 -0
- package/dist/browser-cli-debug-7hvb49S1.js +137 -0
- package/dist/browser-cli-inspect-WU5KeWOK.js +117 -0
- package/dist/browser-cli-manage-B9D9BvSe.js +446 -0
- package/dist/browser-cli-resize-BUOusOPb.js +32 -0
- package/dist/browser-cli-shared-DmpSN-Qi.js +69 -0
- package/dist/browser-cli-state-D_YxTqRw.js +371 -0
- package/dist/browser-control-auth-Cqd1n9FA.js +2 -0
- package/dist/browser-profiles-9tQ05wYh.js +2 -0
- package/dist/browser-runtime-Bbzumoha.js +389 -0
- package/dist/build-CBXuT2K1.js +261 -0
- package/dist/build-info.json +3 -3
- package/dist/bundled/boot-md/handler.js +2 -2
- package/dist/bundled/session-memory/handler.js +1 -1
- package/dist/bundled-channel-config-schema-DpdKMATU.d.ts +3168 -0
- package/dist/canvas-host/a2ui/.bundle.hash +1 -1
- package/dist/capability-cli-CiVGX7ut.js +1809 -0
- package/dist/channel-BIVwHq7P.js +2309 -0
- package/dist/channel-CiA2FVdL.d.ts +427 -0
- package/dist/channel-core-Cj9JTqeu.js +5 -0
- package/dist/channel-core-DjVpcH1C.d.ts +6 -0
- package/dist/channel-entry-contract-Bs_54m1D.d.ts +114 -0
- package/dist/channel-inbound-CdUdeQRa.js +121 -0
- package/dist/channel-inbound-iGiqx6CS.d.ts +97 -0
- package/dist/channel-message-C3QPaDUk.js +12 -0
- package/dist/channel-message-CXDjxb2U.d.ts +9 -0
- package/dist/channel-outbound-ofvvmMSK.d.ts +325 -0
- package/dist/channel-pairing-DKscOV1K.d.ts +58 -0
- package/dist/channel.runtime-VW6PW_ez.js +697 -0
- package/dist/channel.runtime.js +1 -1
- package/dist/chat-CFkQepUQ.js +3 -0
- package/dist/chat-Czh_tXM0.js +2940 -0
- package/dist/chrome-B2cq8YyH.js +1517 -0
- package/dist/cli/run-main.js +5 -5
- package/dist/cli-compaction-Dxv4nt7R.js +363 -0
- package/dist/cli-runner-CimXSTVs.js +2 -0
- package/dist/cli-runner-orCzE1Sr.js +597 -0
- package/dist/cli-runner.runtime-CsW0dXJW.js +3 -0
- package/dist/cli-runner.runtime-DgPrc1do.js +4 -0
- package/dist/cli-runner.runtime.js +1 -1
- package/dist/cli-startup-metadata.json +10 -12
- package/dist/command-registry-C5ooX6PF.js +4 -0
- package/dist/command-registry-DMB-HKIk.js +9 -0
- package/dist/command-registry-core-B2w_XWvn.js +114 -0
- package/dist/command-status.runtime-Bdy3Dkar.js +90 -0
- package/dist/command-status.runtime.js +1 -1
- package/dist/commands-compact.runtime-Bk2jTQo6.js +10 -0
- package/dist/commands-compact.runtime.js +1 -1
- package/dist/commands-handlers.runtime-Csw1og0U.js +6327 -0
- package/dist/commands-handlers.runtime.js +1 -1
- package/dist/commands-mRqmLIVz.d.ts +117 -0
- package/dist/commands-status-Dgrj_ubK.js +3 -0
- package/dist/commands-status-s32HJOpD.js +16 -0
- package/dist/commands-status.runtime-Dgrj_ubK.js +3 -0
- package/dist/commands-status.runtime.js +1 -1
- package/dist/commands-subagents-control.runtime-C_hnOO9l.js +2 -0
- package/dist/commands-subagents-control.runtime.js +1 -1
- package/dist/commands-system-prompt-CQV742Cc.js +2 -0
- package/dist/commands-system-prompt-DTfsKwK1.js +161 -0
- package/dist/commands-types-MXHhrssO.d.ts +132 -0
- package/dist/commands.runtime-akiVK67l.js +175 -0
- package/dist/commands.runtime.js +1 -1
- package/dist/commitments/runtime.js +1 -1
- package/dist/compact-U6ZhvPtD.js +1165 -0
- package/dist/compact.runtime-36E5vKsC.js +12 -0
- package/dist/compact.runtime.js +1 -1
- package/dist/completion-cli-Bf4mEw2W.js +393 -0
- package/dist/config-BJJhHN9E.js +374 -0
- package/dist/config-mutations-swLu-j_p.js +161 -0
- package/dist/config-schema-Tjner6bM.d.ts +20 -0
- package/dist/context-engine-host-compat-6fkn_daV.js +280 -0
- package/dist/context-engine-host-compat-DtAZC1bS.js +2 -0
- package/dist/context-engine-lifecycle-R__Idxi1.js +627 -0
- package/dist/control-auth-DnkI94_D.js +114 -0
- package/dist/control-service-BBsamNjq.js +40 -0
- package/dist/control-service-BGpHj7RL.js +3 -0
- package/dist/control-ui/assets/activity-B2W-IeAT.js +124 -0
- package/dist/control-ui/assets/agents-mRUyNVCz.js +1030 -0
- package/dist/control-ui/assets/channels-8QHOqBnt.js +120 -0
- package/dist/control-ui/assets/cron-H3unP_mO.js +1016 -0
- package/dist/control-ui/assets/debug-CxLsQ9vH.js +97 -0
- package/dist/control-ui/assets/index-jtIYT0Eh.js +7214 -0
- package/dist/control-ui/assets/instances-B1JQeCRb.js +57 -0
- package/dist/control-ui/assets/nodes-RGOmq_1l.js +444 -0
- package/dist/control-ui/assets/sessions-C2O-Jgpg.js +425 -0
- package/dist/control-ui/assets/skills-jyJOYA4I.js +362 -0
- package/dist/control-ui/assets/workboard-uM_kK8cQ.js +402 -0
- package/dist/control-ui/index.html +1 -1
- package/dist/control-ui/sw.js +1 -1
- package/dist/conversation-runtime-DDekWU-U.js +31 -0
- package/dist/core-Bpk-qSJH.js +284 -0
- package/dist/core-Chrz4oRB.d.ts +223 -0
- package/dist/core-api-DSpUKNVW.js +2 -0
- package/dist/core-api-hLsW03Wo.js +5 -0
- package/dist/crestodian/crestodian.js +1 -1
- package/dist/crestodian/rescue-message.d.ts +1 -1
- package/dist/crestodian/rescue-message.js +1 -1
- package/dist/crestodian-C0x7JjF-.js +55 -0
- package/dist/delegate-BArFIZ4B.d.ts +30 -0
- package/dist/deliver-BnVp3VbL.d.ts +111 -0
- package/dist/delivery-queue-BFOASdf5.d.ts +161 -0
- package/dist/delivery-queue-runtime-BFfc8AEs.d.ts +9 -0
- package/dist/dialogue-No0NvYX7.js +37 -0
- package/dist/direct-dm-C-h88JJH.d.ts +79 -0
- package/dist/directive-handling.fast-lane-DTyDKhZb.js +70 -0
- package/dist/directive-handling.impl-DMReM6tu.js +2 -0
- package/dist/directive-handling.impl-DzPouhV-.js +823 -0
- package/dist/directive-handling.model-selection-BjwTBAZJ.js +122 -0
- package/dist/directive-handling.persist.runtime-D_O1okkR.js +274 -0
- package/dist/directive-handling.persist.runtime.js +1 -1
- package/dist/dispatch-Dtl-oRuN.js +2057 -0
- package/dist/dispatch-acp-transcript.runtime-M4y0Dq74.js +40 -0
- package/dist/dispatch-acp-transcript.runtime.js +1 -1
- package/dist/dispatch-acp.runtime-B8uCIKZS.js +18 -0
- package/dist/dispatch-acp.runtime.js +1 -1
- package/dist/dispatcher-DslvaRcj.js +106 -0
- package/dist/doctor-config-flow-LU2C94af.js +1819 -0
- package/dist/doctor-core-checks-BqcjExIZ.js +666 -0
- package/dist/doctor-core-checks-Diuk8l0N.js +2 -0
- package/dist/doctor-core-checks.runtime-DbS-kMZN.js +278 -0
- package/dist/doctor-core-checks.runtime.js +1 -1
- package/dist/doctor-health-BdqHwfYE.js +65 -0
- package/dist/doctor-health-contributions-DLLTVnll.js +874 -0
- package/dist/doctor-lint-PZqkVMWf.js +95 -0
- package/dist/doctor-mRfJMSb5.js +6 -0
- package/dist/doctor-state-integrity-Cdlm-peH.js +1257 -0
- package/dist/draft-stream-controls-B7uLonbw.d.ts +159 -0
- package/dist/embedded-agent-CEpOPW6X.js +4 -0
- package/dist/embedded-agent-CNINO_M-.d.ts +5 -0
- package/dist/embedded-agent-DxwzoZkp.js +4074 -0
- package/dist/embedded-agent.runtime-DDbhA85-.js +4 -0
- package/dist/embedded-agent.runtime.js +1 -1
- package/dist/embedded-backend-ChaKCepC.js +1581 -0
- package/dist/embedded-gateway-stub.runtime-e_ZxGhcW.js +12 -0
- package/dist/embedded-gateway-stub.runtime.js +1 -1
- package/dist/entry.d.ts +1 -1
- package/dist/extensionAPI.d.ts +2 -2
- package/dist/extensionAPI.js +1 -1
- package/dist/extensions/active-memory/index.d.ts +1 -1
- package/dist/extensions/active-memory/index.js +1 -1
- package/dist/extensions/admin-http-rpc/index.d.ts +1 -1
- package/dist/extensions/admin-http-rpc/index.js +1 -1
- package/dist/extensions/bonjour/index.d.ts +1 -1
- package/dist/extensions/browser/browser-bridge.js +1 -1
- package/dist/extensions/browser/browser-config.js +4 -4
- package/dist/extensions/browser/browser-control-auth.js +2 -2
- package/dist/extensions/browser/browser-doctor.js +2 -2
- package/dist/extensions/browser/browser-maintenance.js +1 -1
- package/dist/extensions/browser/browser-profiles.js +2 -2
- package/dist/extensions/browser/browser-runtime-api.js +12 -12
- package/dist/extensions/browser/cli-metadata.d.ts +1 -1
- package/dist/extensions/browser/cli-metadata.js +1 -1
- package/dist/extensions/browser/index.d.ts +1 -1
- package/dist/extensions/browser/index.js +1 -1
- package/dist/extensions/browser/plugin-registration.d.ts +1 -1
- package/dist/extensions/browser/plugin-registration.js +1 -1
- package/dist/extensions/browser/register.runtime.d.ts +2 -2
- package/dist/extensions/browser/register.runtime.js +4 -4
- package/dist/extensions/browser/runtime-api.d.ts +3 -3
- package/dist/extensions/browser/runtime-api.js +14 -14
- package/dist/extensions/browser/setup-api.d.ts +1 -1
- package/dist/extensions/canvas/cli-metadata.d.ts +1 -1
- package/dist/extensions/canvas/index.d.ts +1 -1
- package/dist/extensions/canvas/index.js +1 -1
- package/dist/extensions/canvas/setup-api.d.ts +1 -1
- package/dist/extensions/deepseek/api.d.ts +1 -1
- package/dist/extensions/deepseek/index.d.ts +1 -1
- package/dist/extensions/deepseek/provider-discovery.d.ts +1 -1
- package/dist/extensions/deepseek/stream.d.ts +1 -1
- package/dist/extensions/device-pair/api.d.ts +4 -4
- package/dist/extensions/device-pair/api.js +1 -1
- package/dist/extensions/device-pair/index.d.ts +1 -1
- package/dist/extensions/device-pair/notify.d.ts +1 -1
- package/dist/extensions/device-pair/pair-command-approve.js +1 -1
- package/dist/extensions/device-pair/qr-image.d.ts +1 -1
- package/dist/extensions/memory-core/api.d.ts +1 -1
- package/dist/extensions/memory-core/cli-metadata.d.ts +1 -1
- package/dist/extensions/memory-core/cli-metadata.js +1 -1
- package/dist/extensions/memory-core/index.d.ts +1 -1
- package/dist/extensions/memory-core/manager-runtime.d.ts +1 -1
- package/dist/extensions/memory-core/runtime-api.d.ts +3 -3
- package/dist/extensions/skill-workshop/api.d.ts +2 -2
- package/dist/extensions/skill-workshop/api.js +1 -1
- package/dist/extensions/skill-workshop/index.d.ts +1 -1
- package/dist/extensions/skill-workshop/index.js +2 -2
- package/dist/extensions/tavily/index.d.ts +1 -1
- package/dist/extensions/tavily/web-search-contract-api.d.ts +1 -1
- package/dist/extensions/tavily/web-search-provider.d.ts +1 -1
- package/dist/extensions/thread-ownership/api.d.ts +2 -2
- package/dist/extensions/thread-ownership/index.d.ts +1 -1
- package/dist/extensions/webhooks/api.d.ts +2 -2
- package/dist/extensions/webhooks/api.js +1 -1
- package/dist/extensions/webhooks/index.d.ts +1 -1
- package/dist/extensions/webhooks/index.js +1 -1
- package/dist/extensions/webhooks/runtime-api.d.ts +1 -1
- package/dist/extensions/workboard/api.d.ts +2 -2
- package/dist/extensions/workboard/index.d.ts +1 -1
- package/dist/extensions/workboard/index.js +1 -1
- package/dist/extensions/workboard/runtime-api.d.ts +1 -1
- package/dist/fengming-runtime-CtRd5677.d.ts +153 -0
- package/dist/fengming-tools-DBLsJfsf.js +12221 -0
- package/dist/gateway/protocol/index.d.ts +1 -1
- package/dist/gateway-cli-BgDV2HF9.js +443 -0
- package/dist/gateway-method-runtime-d9oN_XO9.js +21 -0
- package/dist/get-reply-CEMtvaTJ.js +5198 -0
- package/dist/get-reply-from-config.runtime-CE8zmX7o.js +2 -0
- package/dist/get-reply-from-config.runtime.js +1 -1
- package/dist/heartbeat-runner-H8SmaKmJ.js +5 -0
- package/dist/heartbeat-runner.runtime-6hUaxEbl.js +3 -0
- package/dist/heartbeat-runner.runtime.js +1 -1
- package/dist/hooks-DkEvkwzS.js +536 -0
- package/dist/host-compat-DeAq3dnI.d.ts +21 -0
- package/dist/http-registry-BDoApjTY.d.ts +23 -0
- package/dist/inbound-reply-dispatch-CIYP2OPo.d.ts +156 -0
- package/dist/inbound-reply-dispatch-geHu6oUK.js +147 -0
- package/dist/inbound-reply-dispatch-vwW5Hl-_.js +2 -0
- package/dist/index-DhOQs6M_.d.ts +1497 -0
- package/dist/index.js +1 -1
- package/dist/init-DpE_6dG4.js +59 -0
- package/dist/interactive-Cb_1f91G.d.ts +26 -0
- package/dist/isolated-agent-B_upYOOM.js +2 -0
- package/dist/isolated-agent-KH9uwWhw.js +1097 -0
- package/dist/kernel-BHnBXnm2.d.ts +241 -0
- package/dist/lifecycle-BmZwopzF.js +570 -0
- package/dist/list.probe-5kzWm9Jk.js +451 -0
- package/dist/list.probe-9zBcGGQ4.js +2 -0
- package/dist/list.status-command-DY2ifqp1.js +815 -0
- package/dist/llm-slug-generator-Bmx0I84M.js +78 -0
- package/dist/llm-slug-generator.js +1 -1
- package/dist/loader-BVz75gSb.d.ts +142 -0
- package/dist/local-dispatch.runtime-CX3IOY1E.js +10 -0
- package/dist/local-dispatch.runtime.js +1 -1
- package/dist/manager-BXGg8bfG.d.ts +409 -0
- package/dist/mcp-http-B1lnh67s.js +2 -0
- package/dist/mcp-http-CamghE-W.js +583 -0
- package/dist/media-runtime-DpykroJR.d.ts +261 -0
- package/dist/memory-core-host-engine-embeddings-N2dX5P40.d.ts +324 -0
- package/dist/memory-core-host-engine-storage-WQfkQMer.d.ts +54 -0
- package/dist/message-handler-Ca_pqGVS.js +1806 -0
- package/dist/model-catalog-BBMLIjhq.d.ts +88 -0
- package/dist/model-selection-Cq82FXLy.js +352 -0
- package/dist/models-cli-Dm_393dw.js +257 -0
- package/dist/monitor-d0eyE2k0.js +60 -0
- package/dist/monitor.account-vLQ3bKHu.js +5382 -0
- package/dist/nodes-Bunvrb33.js +1483 -0
- package/dist/nodes-edNlxb2I.js +3 -0
- package/dist/nodes-pending-DEIwVh9v.js +211 -0
- package/dist/openai-compat-errors-CvWEoG98.js +136 -0
- package/dist/openai-http-Bskdv4Tv.js +836 -0
- package/dist/openresponses-http-DxdgCxFU.js +1175 -0
- package/dist/operations-Z85LFqsT.js +805 -0
- package/dist/outbound.types-DVkbsxo8.d.ts +291 -0
- package/dist/plugin-enabled-fvhTpvYS.js +232 -0
- package/dist/plugin-entry-CunlVUw6.d.ts +47 -0
- package/dist/plugin-registration-9ovnK_Tk.js +97 -0
- package/dist/plugin-runtime-DH2ZM9P5.d.ts +117 -0
- package/dist/plugin-sdk/.boundary-entry-shims.stamp +1 -1
- package/dist/plugin-sdk/acp-runtime-backend.js +1 -1
- package/dist/plugin-sdk/acp-runtime.js +1 -1
- package/dist/plugin-sdk/agent-harness-runtime.js +5 -5
- package/dist/plugin-sdk/agent-harness-task-runtime.js +1 -1
- package/dist/plugin-sdk/agent-harness.js +6 -6
- package/dist/plugin-sdk/agent-runtime.js +2 -2
- package/dist/plugin-sdk/bundled-channel-config-schema-Dfn3b8sF.d.ts +3169 -0
- package/dist/plugin-sdk/bundled-channel-config-schema.d.ts +1 -1
- package/dist/plugin-sdk/channel-config-schema-legacy.d.ts +1 -1
- package/dist/plugin-sdk/channel-core.js +2 -2
- package/dist/plugin-sdk/channel-envelope.js +1 -1
- package/dist/plugin-sdk/channel-inbound-roots.js +1 -1
- package/dist/plugin-sdk/channel-inbound.js +2 -2
- package/dist/plugin-sdk/channel-location.js +1 -1
- package/dist/plugin-sdk/channel-message-runtime.js +3 -3
- package/dist/plugin-sdk/channel-message.js +2 -2
- package/dist/plugin-sdk/channel-runtime.js +0 -1
- package/dist/plugin-sdk/command-status-runtime.js +1 -1
- package/dist/plugin-sdk/compat.js +1 -1
- package/dist/plugin-sdk/conversation-binding-runtime.js +1 -1
- package/dist/plugin-sdk/conversation-runtime.js +3 -3
- package/dist/plugin-sdk/core.js +2 -2
- package/dist/plugin-sdk/discord.d.ts +1 -1
- package/dist/plugin-sdk/gateway-method-runtime.js +1 -1
- package/dist/plugin-sdk/health.js +1 -1
- package/dist/plugin-sdk/hook-runtime.js +0 -1
- package/dist/plugin-sdk/inbound-reply-dispatch.js +2 -2
- package/dist/plugin-sdk/index.js +1 -1
- package/dist/plugin-sdk/infra-runtime.js +3 -1
- package/dist/plugin-sdk/provider-auth-api-key.js +0 -1
- package/dist/plugin-sdk/provider-stream-family.js +0 -1
- package/dist/plugin-sdk/provider-usage.js +649 -1
- package/dist/plugin-sdk/reply-runtime.js +4 -4
- package/dist/plugin-sdk/scripts/lib/plugin-sdk-doc-metadata.d.ts +122 -0
- package/dist/plugin-sdk/video-generation.js +206 -1
- package/dist/plugin-service-BdZxoKBZ.js +1249 -0
- package/dist/plugin-service-quTl5hT0.d.ts +24 -0
- package/dist/plugins/build-smoke-entry.d.ts +2 -2
- package/dist/plugins/loader.d.ts +1 -1
- package/dist/plugins/provider-discovery.runtime.d.ts +1 -1
- package/dist/plugins/provider-runtime.runtime.d.ts +1 -1
- package/dist/plugins/runtime/index.d.ts +1 -1
- package/dist/plugins/runtime/index.js +4 -4
- package/dist/plugins/tools.d.ts +1 -1
- package/dist/prepare.runtime-DFvkUqBZ.js +798 -0
- package/dist/prepare.runtime.js +1 -1
- package/dist/preview-warnings-CGzc8ccG.js +618 -0
- package/dist/program-D19g2jaa.js +131 -0
- package/dist/provider-api-key-auth-B8GgTfo8.d.ts +27 -0
- package/dist/provider-auth-result-Diw-woMA.d.ts +21 -0
- package/dist/provider-catalog-shared-hMvzzDgL.d.ts +62 -0
- package/dist/provider-dispatcher-DCTc4lG_.js +22 -0
- package/dist/provider-dispatcher.runtime.js +1 -1
- package/dist/provider-model-shared-BUCh3uCL.d.ts +143 -0
- package/dist/provider-registry-BIokPlxa.d.ts +8 -0
- package/dist/provider-registry-CyUOXHG-.d.ts +8 -0
- package/dist/provider-registry-i--H79Ao.d.ts +29 -0
- package/dist/provider-self-hosted-setup-BF8UR8wg.d.ts +74 -0
- package/dist/provider-stream-NF0XJnar.d.ts +139 -0
- package/dist/provider-stream-shared-DLwDaYed.d.ts +132 -0
- package/dist/provider-web-search-contract-fields-D61Vl5Kl.d.ts +25 -0
- package/dist/pw-ai-DYR-D7xR.js +3064 -0
- package/dist/register.agent-DwW0mQPk.js +152 -0
- package/dist/register.crestodian-BhIukKDA.js +24 -0
- package/dist/register.maintenance-DWHlvztJ.js +85 -0
- package/dist/register.subclis-Bsvdh8RI.js +3 -0
- package/dist/register.subclis-DVk0HU4k.js +31 -0
- package/dist/register.subclis-core-BK7nVvl6.js +278 -0
- package/dist/registry-hscEPAcC.d.ts +8 -0
- package/dist/registry-types-Ce-n1tuw.d.ts +392 -0
- package/dist/repair-sequencing-0-qGNSUO.js +652 -0
- package/dist/reply-payload-mCw4ZND6.d.ts +200 -0
- package/dist/reply-turn-admission-DMWNadoS.js +2056 -0
- package/dist/reply.runtime-CE8zmX7o.js +2 -0
- package/dist/reply.runtime.js +1 -1
- package/dist/result-fallback-classifier-BZmv2ACy.js +98 -0
- package/dist/route-qQ-jYpFa.js +475 -0
- package/dist/routes-dTCmw98g.js +2 -0
- package/dist/routes-r8DRKa83.js +3701 -0
- package/dist/run-BgH7EPGH.js +1162 -0
- package/dist/run-command-DCsM-BVh.js +23 -0
- package/dist/run-command-I2ib4dwS.js +2 -0
- package/dist/run-context-CWaKUKKJ.js +66 -0
- package/dist/run-embedded.runtime-CBnDBWN0.js +4 -0
- package/dist/run-embedded.runtime.js +1 -1
- package/dist/run-execution-cli.runtime-DlYXI-lw.js +4 -0
- package/dist/run-execution-cli.runtime.js +1 -1
- package/dist/run-executor.runtime-DwepGrmB.js +330 -0
- package/dist/run-executor.runtime.js +1 -1
- package/dist/run-subagent-registry.runtime-CeVpoIhj.js +2 -0
- package/dist/run-subagent-registry.runtime.js +1 -1
- package/dist/runtime-D2ee-rNh.js +436 -0
- package/dist/runtime-api-B99ZlkNt.d.ts +5 -0
- package/dist/runtime-api-Cta2L_Yo.js +12 -0
- package/dist/runtime-channel-LKOkML3M.js +2 -0
- package/dist/runtime-channel-UtWvrTZ5.js +148 -0
- package/dist/runtime-embedded-agent.runtime-9O2Idzyb.js +2 -0
- package/dist/runtime-embedded-agent.runtime.js +1 -1
- package/dist/runtime-forwarders-DjI8RFL5.d.ts +39 -0
- package/dist/sdk-setup-tools-B-X04pa6.js +8 -0
- package/dist/selection-B02h8Old.js +3 -0
- package/dist/selection-DEPvzrW2.js +18365 -0
- package/dist/server-CMYi8gDo.js +24 -0
- package/dist/server-Cx07rsiY.js +72 -0
- package/dist/server-close.runtime.js +1 -1
- package/dist/server-context-BIemGRt4.js +2 -0
- package/dist/server-context-CB_an9iy.js +955 -0
- package/dist/server-cron-BeyuBUjb.js +3173 -0
- package/dist/server-cron-CV7KkVeB.js +2 -0
- package/dist/server-methods-C7EnpOhB.js +497 -0
- package/dist/server-node-events-DMMzZciN.js +597 -0
- package/dist/server-plugin-bootstrap-O6MzvzL8.js +71 -0
- package/dist/server-plugins-Dwnaz9kX.js +435 -0
- package/dist/server-reload-handlers-C-6TyPvI.js +719 -0
- package/dist/server-restart-sentinel-Dc35eYgk.js +700 -0
- package/dist/server-runtime-services-DCs-gqh_.js +3 -0
- package/dist/server-runtime-services-DF2fzzVd.js +147 -0
- package/dist/server-startup-plugins-t-YeYibm.js +127 -0
- package/dist/server-startup-post-attach-CiEki-DC.js +793 -0
- package/dist/server-ws-runtime-uaUpI-e8.js +374 -0
- package/dist/server.impl-MoHjSMr5.js +2622 -0
- package/dist/session-kill-http-CYCiQpt2.js +121 -0
- package/dist/session-reset-service-BYbADY57.js +651 -0
- package/dist/session-status.runtime-8NASbeO4.js +2 -0
- package/dist/session-status.runtime.js +1 -1
- package/dist/session-subagent-reactivation.runtime-DGeNY2Rb.js +2 -0
- package/dist/session-subagent-reactivation.runtime.js +1 -1
- package/dist/session-tab-registry-C2eElZrt.js +551 -0
- package/dist/sessions-DXAdVXIx.js +1917 -0
- package/dist/sessions-history-http-BwK7b8OH.js +432 -0
- package/dist/sessions-patch-BYC5gvY1.js +401 -0
- package/dist/sessions-resolve-C3ORcdmo.js +180 -0
- package/dist/sessions.runtime-BijldeSY.js +2 -0
- package/dist/sessions.runtime.js +1 -1
- package/dist/snapshot-urls-C5CfP3Co.js +317 -0
- package/dist/speech-core-wWkTZPpQ.d.ts +49 -0
- package/dist/standalone-CHrieUsw.js +42 -0
- package/dist/startup-context-CZfmG8-g.js +314 -0
- package/dist/status-subagents.runtime-D2XMebiS.js +32 -0
- package/dist/status-subagents.runtime.js +1 -1
- package/dist/status-text-JR7IPyzZ.js +301 -0
- package/dist/stream-BJgTkLEI.d.ts +5 -0
- package/dist/subagent-announce-B9cfs_KZ.js +353 -0
- package/dist/subagent-announce-delivery-CtmEvLTS.js +1369 -0
- package/dist/subagent-control-DVqLHi9O.js +492 -0
- package/dist/subagent-hooks-D251uSvy.js +230 -0
- package/dist/subagent-hooks-api-DvdMKxsC.js +23 -0
- package/dist/subagent-hooks-uLORYChc.js +2 -0
- package/dist/subagent-registry-BW2l_oYu.js +3 -0
- package/dist/subagent-registry-BxEMHuiN.js +2627 -0
- package/dist/subagent-registry.runtime.d.ts +1 -1
- package/dist/subagent-registry.runtime.js +1 -1
- package/dist/subagent-session-cleanup-BC5wV2qQ.js +390 -0
- package/dist/system-fvgHsr2x.js +111 -0
- package/dist/talk-DU0Sod_K.js +2454 -0
- package/dist/target-id-BR2xJIkd.js +107 -0
- package/dist/task-registry-control.runtime.js +1 -1
- package/dist/thread-bindings-8XNu5U2p.js +228 -0
- package/dist/tool-Boeg0N5g.js +143 -0
- package/dist/tool-dispatch-BhLLaL2g.js +155 -0
- package/dist/tool-resolution-CzsLs-87.js +153 -0
- package/dist/tool-split-Bedy42Ms.d.ts +19 -0
- package/dist/tools-B6egHpE3.d.ts +38 -0
- package/dist/tools-effective-NXscxK8n.js +442 -0
- package/dist/tools-effective-inventory-NsGMUVo-.js +379 -0
- package/dist/tools-invoke-_sSu96Kq.js +51 -0
- package/dist/tools-invoke-http-BDhlRl-G.js +68 -0
- package/dist/tools-invoke-shared-BH-T9Bcg.js +200 -0
- package/dist/tts-runtime-C1wu3o15.d.ts +230 -0
- package/dist/tui-C733Qov0.js +2 -0
- package/dist/tui-DqbscVN5.js +3 -0
- package/dist/tui-backend-_Pn3Byj-.js +257 -0
- package/dist/tui-cli-CAiC39zd.js +40 -0
- package/dist/tui-ink-run-ChXEGj1h.js +7414 -0
- package/dist/tui-ink-run-D4mSfLHj.js +2 -0
- package/dist/types-BQw1qXGl.d.ts +7034 -0
- package/dist/types-BzMoU6-C.d.ts +111 -0
- package/dist/types-DltHmoCX.d.ts +393 -0
- package/dist/types.public-C_bVIMBl.d.ts +70 -0
- package/dist/web-fetch/runtime.d.ts +1 -1
- package/dist/webhook-targets-DW2jhddP.d.ts +99 -0
- package/dist/zod-schema.core-Cuz0lz6m.d.ts +166 -0
- package/npm-shrinkwrap.json +12861 -11889
- package/package.json +1 -1
- package/skills/batch/SKILL.md +118 -0
- package/skills/code-review/SKILL.md +107 -0
- package/skills/debug/SKILL.md +83 -0
- package/skills/loop/SKILL.md +118 -0
- package/skills/run/SKILL.md +79 -0
- package/skills/run-skill-generator/SKILL.md +179 -0
- package/skills/verify/SKILL.md +103 -0
- package/dist/abort-DGskei2p.js +0 -277
- package/dist/abort.runtime-Buq9IZxn.js +0 -2
- package/dist/acp-spawn-DC6IyYaB.js +0 -1286
- package/dist/acp-spawn-Diqb3nel.js +0 -2
- package/dist/acp-stateful-target-driver-Clhe_L8v.js +0 -89
- package/dist/active-tool-schema-warnings-BRhKkyvt.js +0 -2
- package/dist/active-tool-schema-warnings-C6N0-ce6.js +0 -105
- package/dist/agent-C5lhsEZJ.js +0 -2
- package/dist/agent-WEb757bl.js +0 -1825
- package/dist/agent-command-iLD_nsVY.js +0 -1435
- package/dist/agent-core-BeDN8Ns5.d.ts +0 -13
- package/dist/agent-harness-runtime-C89_Q-bW.d.ts +0 -913
- package/dist/agent-harness-runtime-Dfn5rik2.js +0 -207
- package/dist/agent-runner-utils-DNiuuo43.js +0 -267
- package/dist/agent-runner.runtime-CFF_qJ5V.js +0 -3784
- package/dist/agent-runtime-BkMtWXxn.js +0 -199
- package/dist/agent-runtime-HufMO_YR.d.ts +0 -207
- package/dist/agent-tools-HmaDv4ot.js +0 -2506
- package/dist/agent-via-gateway-CZQG8RYL.js +0 -486
- package/dist/agent-wait-dedupe-C3xQk2Ww.js +0 -180
- package/dist/agent-z1cs3c7n.js +0 -3
- package/dist/api-B4IMKjSe.js +0 -3
- package/dist/api-BwSbBWI8.js +0 -3
- package/dist/api-CE9In9m4.js +0 -5
- package/dist/api-ClPvYNGa.js +0 -32
- package/dist/api-CntBCaZf.js +0 -3
- package/dist/api-DBZBwTsn.js +0 -6
- package/dist/api-OCPwGOvK.js +0 -2
- package/dist/api-yYhEo7gK.js +0 -4
- package/dist/approval-client-helpers-CfdQ3-vv.d.ts +0 -78
- package/dist/approval-native-helpers-DSHPksK4.d.ts +0 -241
- package/dist/approval-renderers-BfEfwk44.d.ts +0 -39
- package/dist/assistant-v5fdOYu7.js +0 -291
- package/dist/attachment-normalize-BHAbLiL2.js +0 -213
- package/dist/attempt-execution-5w9WYbaJ.js +0 -584
- package/dist/attempt-execution.runtime-DnhOWGzr.js +0 -3
- package/dist/attempt.prompt-helpers-C4M4erF7.js +0 -543
- package/dist/binding-routing-Dpes-QF1.js +0 -113
- package/dist/binding-targets-B6H5Pd-A.js +0 -121
- package/dist/bridge-server-BCpxCRm_.js +0 -113
- package/dist/browser-cli-DMhXHopl.js +0 -230
- package/dist/browser-cli-Dy_VugK0.js +0 -2
- package/dist/browser-cli-actions-input-WMP7_lm6.js +0 -522
- package/dist/browser-cli-actions-observe-DQWAWhwU.js +0 -81
- package/dist/browser-cli-debug-CaT2ZKAx.js +0 -137
- package/dist/browser-cli-inspect-DU-LUXq1.js +0 -117
- package/dist/browser-cli-manage-DAuogqIh.js +0 -446
- package/dist/browser-cli-resize-Cz5uO_aR.js +0 -32
- package/dist/browser-cli-shared-CjPZcG3j.js +0 -69
- package/dist/browser-cli-state-CC3l77-K.js +0 -371
- package/dist/browser-control-auth-ELccIUZy.js +0 -2
- package/dist/browser-profiles-Cuy4ia6_.js +0 -2
- package/dist/browser-runtime-De-iUfME.js +0 -389
- package/dist/build-DEF8Per9.js +0 -261
- package/dist/bundled-channel-config-schema-Bte--ZlY.d.ts +0 -3168
- package/dist/capability-cli-Bydel4E7.js +0 -1809
- package/dist/channel-6SGL4R5P.js +0 -2309
- package/dist/channel-D3Q3b8J-.d.ts +0 -427
- package/dist/channel-core-Bj71kAB5.d.ts +0 -6
- package/dist/channel-core-DMvyWnHg.js +0 -5
- package/dist/channel-entry-contract-zYxRmEdf.d.ts +0 -114
- package/dist/channel-inbound-DVJzBcJ8.d.ts +0 -97
- package/dist/channel-inbound-DlCa7eJe.js +0 -121
- package/dist/channel-message-CyPGMMFB.js +0 -12
- package/dist/channel-message-Czl4cdoA.d.ts +0 -9
- package/dist/channel-outbound-BNbhmruA.d.ts +0 -325
- package/dist/channel-pairing-BiS-tSvl.d.ts +0 -58
- package/dist/channel-runtime-D8hntg7H.js +0 -7
- package/dist/channel.runtime-DxErReJR.js +0 -697
- package/dist/chat-BLA8ORQI.js +0 -3
- package/dist/chat-DWRXkuvU.js +0 -2940
- package/dist/chrome-DPwFYi-g.js +0 -1517
- package/dist/cli-compaction-YZpssARf.js +0 -363
- package/dist/cli-runner-D2OAqxu3.js +0 -597
- package/dist/cli-runner-DO4SORQf.js +0 -2
- package/dist/cli-runner.runtime-CNSIpbeT.js +0 -4
- package/dist/cli-runner.runtime-DAOYvpVQ.js +0 -3
- package/dist/command-registry-DpD0fb8D.js +0 -4
- package/dist/command-registry-core-Cl3tLG8G.js +0 -114
- package/dist/command-registry-nbP7c8RT.js +0 -9
- package/dist/command-status.runtime-BBuXTkq0.js +0 -90
- package/dist/commands-CR8MVvlD.d.ts +0 -117
- package/dist/commands-compact.runtime-BoafIjjg.js +0 -10
- package/dist/commands-handlers.runtime-D9jViG_x.js +0 -6327
- package/dist/commands-status-BqqJ7PVq.js +0 -16
- package/dist/commands-status-CMd41Vxf.js +0 -3
- package/dist/commands-status.runtime-CMd41Vxf.js +0 -3
- package/dist/commands-subagents-control.runtime-CU4I3A_n.js +0 -2
- package/dist/commands-system-prompt-CTtu1D3-.js +0 -2
- package/dist/commands-system-prompt-xswhORdM.js +0 -161
- package/dist/commands-types-B67CsqXf.d.ts +0 -132
- package/dist/commands.runtime-BUFhkrjQ.js +0 -175
- package/dist/compact-Dz_WvRkQ.js +0 -1165
- package/dist/compact.runtime-n-AKErni.js +0 -12
- package/dist/completion-cli-DJYs_L4_.js +0 -393
- package/dist/config-CFMbHJb0.js +0 -374
- package/dist/config-mutations-DCAloTKR.js +0 -161
- package/dist/config-schema-Drw1zrnG.d.ts +0 -20
- package/dist/context-engine-host-compat-4mNm1HCE.js +0 -2
- package/dist/context-engine-host-compat-BzJ7fUIn.js +0 -280
- package/dist/context-engine-lifecycle-V4PNQp6k.js +0 -627
- package/dist/control-auth-DG_cw-aN.js +0 -114
- package/dist/control-service-CurYipgK.js +0 -3
- package/dist/control-service-VyncoV7j.js +0 -40
- package/dist/control-ui/assets/activity-BvGWC_j9.js +0 -124
- package/dist/control-ui/assets/agents-XOPBFHre.js +0 -1030
- package/dist/control-ui/assets/channels-B3E6Zw4-.js +0 -120
- package/dist/control-ui/assets/cron-r1sJdAbI.js +0 -1016
- package/dist/control-ui/assets/debug-EJlC-Qxz.js +0 -97
- package/dist/control-ui/assets/index-DBWFWpqU.js +0 -7214
- package/dist/control-ui/assets/instances-DqYhTGuq.js +0 -57
- package/dist/control-ui/assets/nodes-CPozuEst.js +0 -444
- package/dist/control-ui/assets/sessions-vJlr6aBb.js +0 -425
- package/dist/control-ui/assets/skills-wNA5l4y0.js +0 -362
- package/dist/control-ui/assets/workboard-BwoP_UJU.js +0 -402
- package/dist/conversation-runtime-DgaABwHh.js +0 -31
- package/dist/core-BeBXdneV.js +0 -284
- package/dist/core-Chqb7X6l.d.ts +0 -223
- package/dist/core-api-BlK0FgBM.js +0 -2
- package/dist/core-api-pAvYk716.js +0 -5
- package/dist/crestodian-FeGTBqO1.js +0 -55
- package/dist/delegate-BjIjSU_E.d.ts +0 -30
- package/dist/deliver-CvtWN4Ey.d.ts +0 -111
- package/dist/delivery-queue-CQ-cj3KG.d.ts +0 -161
- package/dist/delivery-queue-runtime-ut7MG04m.d.ts +0 -9
- package/dist/detect-BjXPyrwn.js +0 -115
- package/dist/detect-C1xeIemQ.d.ts +0 -16
- package/dist/dialogue-BowVYhEC.js +0 -37
- package/dist/direct-dm-DoZZHpA0.d.ts +0 -79
- package/dist/directive-handling.fast-lane-hnmQ_CvD.js +0 -70
- package/dist/directive-handling.impl-Cai-CFS1.js +0 -2
- package/dist/directive-handling.impl-DY84qIfU.js +0 -823
- package/dist/directive-handling.model-selection-DASssLFQ.js +0 -122
- package/dist/directive-handling.persist.runtime-BY7tJUs2.js +0 -274
- package/dist/dispatch-D5iG5A8j.js +0 -2057
- package/dist/dispatch-acp-transcript.runtime-D3r16hbD.js +0 -40
- package/dist/dispatch-acp.runtime-CAIau5qX.js +0 -18
- package/dist/dispatcher-7-d2gw3J.js +0 -106
- package/dist/doctor-DD5YEMmf.js +0 -6
- package/dist/doctor-config-flow-CdlLHJmX.js +0 -1819
- package/dist/doctor-core-checks-6MP99TQG.js +0 -666
- package/dist/doctor-core-checks-Dm_o576z.js +0 -2
- package/dist/doctor-core-checks.runtime-B2qbKATd.js +0 -278
- package/dist/doctor-health-BKrhOv1v.js +0 -65
- package/dist/doctor-health-contributions-bIBLmw69.js +0 -874
- package/dist/doctor-lint-aOLOWli4.js +0 -95
- package/dist/doctor-state-integrity-23NQNNuo.js +0 -1257
- package/dist/draft-stream-controls-Bk1GVJ1l.d.ts +0 -159
- package/dist/embedded-agent-BeK8FhZr.d.ts +0 -5
- package/dist/embedded-agent-CNp_y7jW.js +0 -4074
- package/dist/embedded-agent-NEmNlXDR.js +0 -4
- package/dist/embedded-agent.runtime-hEby8P2s.js +0 -4
- package/dist/embedded-backend-BdbgfpBP.js +0 -1581
- package/dist/embedded-gateway-stub.runtime-ySZUA3Gy.js +0 -12
- package/dist/extensions/alibaba/fengming.plugin.json +0 -47
- package/dist/extensions/alibaba/index.d.ts +0 -12
- package/dist/extensions/alibaba/index.js +0 -13
- package/dist/extensions/alibaba/package.json +0 -15
- package/dist/extensions/alibaba/video-generation-provider.d.ts +0 -6
- package/dist/extensions/alibaba/video-generation-provider.js +0 -2
- package/dist/extensions/baichuan/fengming.plugin.json +0 -69
- package/dist/extensions/baichuan/index.d.ts +0 -11
- package/dist/extensions/baichuan/index.js +0 -45
- package/dist/extensions/baichuan/models.d.ts +0 -7
- package/dist/extensions/baichuan/models.js +0 -2
- package/dist/extensions/baichuan/onboard.d.ts +0 -5
- package/dist/extensions/baichuan/onboard.js +0 -2
- package/dist/extensions/baichuan/package.json +0 -15
- package/dist/extensions/baichuan/provider-catalog.d.ts +0 -2
- package/dist/extensions/baichuan/provider-catalog.js +0 -2
- package/dist/extensions/baichuan/provider-discovery.d.ts +0 -2
- package/dist/extensions/baichuan/provider-discovery.js +0 -5
- package/dist/extensions/byteplus/api.d.ts +0 -3
- package/dist/extensions/byteplus/api.js +0 -3
- package/dist/extensions/byteplus/fengming.plugin.json +0 -196
- package/dist/extensions/byteplus/index.d.ts +0 -12
- package/dist/extensions/byteplus/index.js +0 -85
- package/dist/extensions/byteplus/models.d.ts +0 -2
- package/dist/extensions/byteplus/models.js +0 -2
- package/dist/extensions/byteplus/package.json +0 -15
- package/dist/extensions/byteplus/provider-catalog.d.ts +0 -2
- package/dist/extensions/byteplus/provider-catalog.js +0 -2
- package/dist/extensions/byteplus/provider-discovery.d.ts +0 -5
- package/dist/extensions/byteplus/provider-discovery.js +0 -23
- package/dist/extensions/byteplus/video-generation-provider.d.ts +0 -6
- package/dist/extensions/byteplus/video-generation-provider.js +0 -2
- package/dist/extensions/longcat/fengming.plugin.json +0 -84
- package/dist/extensions/longcat/index.d.ts +0 -11
- package/dist/extensions/longcat/index.js +0 -45
- package/dist/extensions/longcat/models.d.ts +0 -7
- package/dist/extensions/longcat/models.js +0 -2
- package/dist/extensions/longcat/onboard.d.ts +0 -5
- package/dist/extensions/longcat/onboard.js +0 -2
- package/dist/extensions/longcat/package.json +0 -15
- package/dist/extensions/longcat/provider-catalog.d.ts +0 -2
- package/dist/extensions/longcat/provider-catalog.js +0 -2
- package/dist/extensions/longcat/provider-discovery.d.ts +0 -2
- package/dist/extensions/longcat/provider-discovery.js +0 -5
- package/dist/extensions/minimax/api.d.ts +0 -5
- package/dist/extensions/minimax/api.js +0 -6
- package/dist/extensions/minimax/fengming.plugin.json +0 -206
- package/dist/extensions/minimax/image-generation-provider.d.ts +0 -6
- package/dist/extensions/minimax/image-generation-provider.js +0 -2
- package/dist/extensions/minimax/index.d.ts +0 -12
- package/dist/extensions/minimax/index.js +0 -29
- package/dist/extensions/minimax/media-understanding-provider.d.ts +0 -6
- package/dist/extensions/minimax/media-understanding-provider.js +0 -2
- package/dist/extensions/minimax/model-definitions.d.ts +0 -2
- package/dist/extensions/minimax/model-definitions.js +0 -2
- package/dist/extensions/minimax/music-generation-provider.d.ts +0 -6
- package/dist/extensions/minimax/music-generation-provider.js +0 -2
- package/dist/extensions/minimax/oauth.d.ts +0 -2
- package/dist/extensions/minimax/oauth.js +0 -2
- package/dist/extensions/minimax/oauth.runtime.d.ts +0 -2
- package/dist/extensions/minimax/oauth.runtime.js +0 -2
- package/dist/extensions/minimax/onboard.d.ts +0 -2
- package/dist/extensions/minimax/onboard.js +0 -2
- package/dist/extensions/minimax/package.json +0 -15
- package/dist/extensions/minimax/provider-catalog.d.ts +0 -2
- package/dist/extensions/minimax/provider-catalog.js +0 -2
- package/dist/extensions/minimax/provider-contract-api.d.ts +0 -6
- package/dist/extensions/minimax/provider-contract-api.js +0 -77
- package/dist/extensions/minimax/provider-discovery.d.ts +0 -5
- package/dist/extensions/minimax/provider-discovery.js +0 -23
- package/dist/extensions/minimax/provider-models.d.ts +0 -2
- package/dist/extensions/minimax/provider-models.js +0 -2
- package/dist/extensions/minimax/provider-registration.d.ts +0 -7
- package/dist/extensions/minimax/provider-registration.js +0 -2
- package/dist/extensions/minimax/speech-provider.d.ts +0 -5
- package/dist/extensions/minimax/speech-provider.js +0 -2
- package/dist/extensions/minimax/tts.d.ts +0 -20
- package/dist/extensions/minimax/tts.js +0 -2
- package/dist/extensions/minimax/video-generation-provider.d.ts +0 -7
- package/dist/extensions/minimax/video-generation-provider.js +0 -2
- package/dist/extensions/minimax/web-search-contract-api.d.ts +0 -5
- package/dist/extensions/minimax/web-search-contract-api.js +0 -31
- package/dist/extensions/minimax/web-search-provider.d.ts +0 -5
- package/dist/extensions/minimax/web-search-provider.js +0 -2
- package/dist/extensions/moonshot/api.d.ts +0 -3
- package/dist/extensions/moonshot/api.js +0 -4
- package/dist/extensions/moonshot/fengming.plugin.json +0 -250
- package/dist/extensions/moonshot/index.d.ts +0 -11
- package/dist/extensions/moonshot/index.js +0 -70
- package/dist/extensions/moonshot/media-understanding-provider.d.ts +0 -6
- package/dist/extensions/moonshot/media-understanding-provider.js +0 -2
- package/dist/extensions/moonshot/onboard.d.ts +0 -2
- package/dist/extensions/moonshot/onboard.js +0 -2
- package/dist/extensions/moonshot/package.json +0 -15
- package/dist/extensions/moonshot/provider-catalog.d.ts +0 -2
- package/dist/extensions/moonshot/provider-catalog.js +0 -2
- package/dist/extensions/moonshot/provider-contract-api.d.ts +0 -5
- package/dist/extensions/moonshot/provider-contract-api.js +0 -27
- package/dist/extensions/moonshot/provider-discovery.d.ts +0 -5
- package/dist/extensions/moonshot/provider-discovery.js +0 -15
- package/dist/extensions/moonshot/web-search-contract-api.d.ts +0 -5
- package/dist/extensions/moonshot/web-search-contract-api.js +0 -29
- package/dist/extensions/moonshot/web-search-provider.d.ts +0 -5
- package/dist/extensions/moonshot/web-search-provider.js +0 -2
- package/dist/extensions/qianfan/api.d.ts +0 -3
- package/dist/extensions/qianfan/api.js +0 -3
- package/dist/extensions/qianfan/fengming.plugin.json +0 -89
- package/dist/extensions/qianfan/index.d.ts +0 -11
- package/dist/extensions/qianfan/index.js +0 -26
- package/dist/extensions/qianfan/onboard.d.ts +0 -2
- package/dist/extensions/qianfan/onboard.js +0 -2
- package/dist/extensions/qianfan/package.json +0 -15
- package/dist/extensions/qianfan/provider-catalog.d.ts +0 -2
- package/dist/extensions/qianfan/provider-catalog.js +0 -2
- package/dist/extensions/qwen/api.d.ts +0 -4
- package/dist/extensions/qwen/api.js +0 -5
- package/dist/extensions/qwen/fengming.plugin.json +0 -389
- package/dist/extensions/qwen/index.d.ts +0 -11
- package/dist/extensions/qwen/index.js +0 -202
- package/dist/extensions/qwen/media-understanding-provider.d.ts +0 -6
- package/dist/extensions/qwen/media-understanding-provider.js +0 -2
- package/dist/extensions/qwen/model-definitions.d.ts +0 -2
- package/dist/extensions/qwen/model-definitions.js +0 -2
- package/dist/extensions/qwen/models.d.ts +0 -2
- package/dist/extensions/qwen/models.js +0 -2
- package/dist/extensions/qwen/onboard.d.ts +0 -21
- package/dist/extensions/qwen/onboard.js +0 -2
- package/dist/extensions/qwen/package.json +0 -15
- package/dist/extensions/qwen/provider-catalog.d.ts +0 -2
- package/dist/extensions/qwen/provider-catalog.js +0 -2
- package/dist/extensions/qwen/stream.d.ts +0 -2
- package/dist/extensions/qwen/stream.js +0 -2
- package/dist/extensions/qwen/video-generation-provider.d.ts +0 -6
- package/dist/extensions/qwen/video-generation-provider.js +0 -2
- package/dist/extensions/sensenova/fengming.plugin.json +0 -69
- package/dist/extensions/sensenova/index.d.ts +0 -11
- package/dist/extensions/sensenova/index.js +0 -45
- package/dist/extensions/sensenova/models.d.ts +0 -7
- package/dist/extensions/sensenova/models.js +0 -2
- package/dist/extensions/sensenova/onboard.d.ts +0 -5
- package/dist/extensions/sensenova/onboard.js +0 -2
- package/dist/extensions/sensenova/package.json +0 -15
- package/dist/extensions/sensenova/provider-catalog.d.ts +0 -2
- package/dist/extensions/sensenova/provider-catalog.js +0 -2
- package/dist/extensions/sensenova/provider-discovery.d.ts +0 -2
- package/dist/extensions/sensenova/provider-discovery.js +0 -5
- package/dist/extensions/stepfun/fengming.plugin.json +0 -162
- package/dist/extensions/stepfun/index.d.ts +0 -12
- package/dist/extensions/stepfun/index.js +0 -165
- package/dist/extensions/stepfun/onboard.d.ts +0 -7
- package/dist/extensions/stepfun/onboard.js +0 -2
- package/dist/extensions/stepfun/package.json +0 -15
- package/dist/extensions/stepfun/provider-catalog.d.ts +0 -14
- package/dist/extensions/stepfun/provider-catalog.js +0 -2
- package/dist/extensions/tencent/api.d.ts +0 -3
- package/dist/extensions/tencent/api.js +0 -4
- package/dist/extensions/tencent/fengming.plugin.json +0 -105
- package/dist/extensions/tencent/index.d.ts +0 -12
- package/dist/extensions/tencent/index.js +0 -62
- package/dist/extensions/tencent/models.d.ts +0 -2
- package/dist/extensions/tencent/models.js +0 -2
- package/dist/extensions/tencent/onboard.d.ts +0 -6
- package/dist/extensions/tencent/onboard.js +0 -2
- package/dist/extensions/tencent/package.json +0 -15
- package/dist/extensions/tencent/provider-catalog.d.ts +0 -2
- package/dist/extensions/tencent/provider-catalog.js +0 -2
- package/dist/extensions/tencent/provider-discovery.d.ts +0 -5
- package/dist/extensions/tencent/provider-discovery.js +0 -14
- package/dist/extensions/tiangong/fengming.plugin.json +0 -69
- package/dist/extensions/tiangong/index.d.ts +0 -11
- package/dist/extensions/tiangong/index.js +0 -45
- package/dist/extensions/tiangong/models.d.ts +0 -7
- package/dist/extensions/tiangong/models.js +0 -2
- package/dist/extensions/tiangong/onboard.d.ts +0 -5
- package/dist/extensions/tiangong/onboard.js +0 -2
- package/dist/extensions/tiangong/package.json +0 -15
- package/dist/extensions/tiangong/provider-catalog.d.ts +0 -2
- package/dist/extensions/tiangong/provider-catalog.js +0 -2
- package/dist/extensions/tiangong/provider-discovery.d.ts +0 -2
- package/dist/extensions/tiangong/provider-discovery.js +0 -5
- package/dist/extensions/volcengine/api.d.ts +0 -12
- package/dist/extensions/volcengine/api.js +0 -4
- package/dist/extensions/volcengine/fengming.plugin.json +0 -263
- package/dist/extensions/volcengine/index.d.ts +0 -12
- package/dist/extensions/volcengine/index.js +0 -88
- package/dist/extensions/volcengine/models.d.ts +0 -2
- package/dist/extensions/volcengine/models.js +0 -2
- package/dist/extensions/volcengine/package.json +0 -15
- package/dist/extensions/volcengine/provider-catalog.d.ts +0 -2
- package/dist/extensions/volcengine/provider-catalog.js +0 -2
- package/dist/extensions/volcengine/provider-discovery.d.ts +0 -5
- package/dist/extensions/volcengine/provider-discovery.js +0 -23
- package/dist/extensions/volcengine/speech-provider.d.ts +0 -5
- package/dist/extensions/volcengine/speech-provider.js +0 -2
- package/dist/extensions/volcengine/tts.d.ts +0 -22
- package/dist/extensions/volcengine/tts.js +0 -2
- package/dist/extensions/weixin/fengming.plugin.json +0 -22
- package/dist/extensions/weixin/index.d.ts +0 -26
- package/dist/extensions/weixin/index.js +0 -862
- package/dist/extensions/weixin/package.json +0 -45
- package/dist/extensions/xiaomi/api.d.ts +0 -3
- package/dist/extensions/xiaomi/api.js +0 -3
- package/dist/extensions/xiaomi/fengming.plugin.json +0 -260
- package/dist/extensions/xiaomi/index.d.ts +0 -12
- package/dist/extensions/xiaomi/index.js +0 -284
- package/dist/extensions/xiaomi/onboard.d.ts +0 -2
- package/dist/extensions/xiaomi/onboard.js +0 -2
- package/dist/extensions/xiaomi/package.json +0 -15
- package/dist/extensions/xiaomi/provider-catalog.d.ts +0 -2
- package/dist/extensions/xiaomi/provider-catalog.js +0 -2
- package/dist/extensions/xiaomi/speech-provider.d.ts +0 -5
- package/dist/extensions/xiaomi/speech-provider.js +0 -2
- package/dist/extensions/xiaomi/stream.d.ts +0 -5
- package/dist/extensions/xiaomi/stream.js +0 -2
- package/dist/extensions/xiaomi/thinking.d.ts +0 -11
- package/dist/extensions/xiaomi/thinking.js +0 -2
- package/dist/extensions/xingchen/fengming.plugin.json +0 -69
- package/dist/extensions/xingchen/index.d.ts +0 -11
- package/dist/extensions/xingchen/index.js +0 -45
- package/dist/extensions/xingchen/models.d.ts +0 -7
- package/dist/extensions/xingchen/models.js +0 -2
- package/dist/extensions/xingchen/onboard.d.ts +0 -5
- package/dist/extensions/xingchen/onboard.js +0 -2
- package/dist/extensions/xingchen/package.json +0 -15
- package/dist/extensions/xingchen/provider-catalog.d.ts +0 -2
- package/dist/extensions/xingchen/provider-catalog.js +0 -2
- package/dist/extensions/xingchen/provider-discovery.d.ts +0 -2
- package/dist/extensions/xingchen/provider-discovery.js +0 -5
- package/dist/extensions/yi/fengming.plugin.json +0 -84
- package/dist/extensions/yi/index.d.ts +0 -11
- package/dist/extensions/yi/index.js +0 -45
- package/dist/extensions/yi/models.d.ts +0 -7
- package/dist/extensions/yi/models.js +0 -2
- package/dist/extensions/yi/onboard.d.ts +0 -5
- package/dist/extensions/yi/onboard.js +0 -2
- package/dist/extensions/yi/package.json +0 -15
- package/dist/extensions/yi/provider-catalog.d.ts +0 -2
- package/dist/extensions/yi/provider-catalog.js +0 -2
- package/dist/extensions/yi/provider-discovery.d.ts +0 -2
- package/dist/extensions/yi/provider-discovery.js +0 -5
- package/dist/extensions/zai/api.d.ts +0 -4
- package/dist/extensions/zai/api.js +0 -4
- package/dist/extensions/zai/detect.d.ts +0 -2
- package/dist/extensions/zai/detect.js +0 -2
- package/dist/extensions/zai/fengming.plugin.json +0 -377
- package/dist/extensions/zai/index.d.ts +0 -12
- package/dist/extensions/zai/index.js +0 -297
- package/dist/extensions/zai/media-understanding-provider.d.ts +0 -5
- package/dist/extensions/zai/media-understanding-provider.js +0 -2
- package/dist/extensions/zai/model-definitions.d.ts +0 -2
- package/dist/extensions/zai/model-definitions.js +0 -2
- package/dist/extensions/zai/onboard.d.ts +0 -2
- package/dist/extensions/zai/onboard.js +0 -2
- package/dist/extensions/zai/package.json +0 -15
- package/dist/extensions/zai/runtime-api.d.ts +0 -2
- package/dist/extensions/zai/runtime-api.js +0 -2
- package/dist/extensions/zhinao/fengming.plugin.json +0 -69
- package/dist/extensions/zhinao/index.d.ts +0 -11
- package/dist/extensions/zhinao/index.js +0 -45
- package/dist/extensions/zhinao/models.d.ts +0 -7
- package/dist/extensions/zhinao/models.js +0 -2
- package/dist/extensions/zhinao/onboard.d.ts +0 -5
- package/dist/extensions/zhinao/onboard.js +0 -2
- package/dist/extensions/zhinao/package.json +0 -15
- package/dist/extensions/zhinao/provider-catalog.d.ts +0 -2
- package/dist/extensions/zhinao/provider-catalog.js +0 -2
- package/dist/extensions/zhinao/provider-discovery.d.ts +0 -2
- package/dist/extensions/zhinao/provider-discovery.js +0 -5
- package/dist/fengming-runtime-0jdu_329.d.ts +0 -153
- package/dist/fengming-tools-gQkwsWYz.js +0 -12221
- package/dist/fengming.plugin-C-Kdi1_5.js +0 -130
- package/dist/fengming.plugin-CRPqMj85.js +0 -166
- package/dist/gateway-cli-BV1V43-D.js +0 -443
- package/dist/gateway-method-runtime-J2OPP_oH.js +0 -21
- package/dist/get-reply-BE8ZGJos.js +0 -5198
- package/dist/get-reply-from-config.runtime-C5wfxVI_.js +0 -2
- package/dist/heartbeat-runner-_0HlObMb.js +0 -5
- package/dist/heartbeat-runner.runtime-DvYz_4Z3.js +0 -3
- package/dist/hook-runtime-BH9moP5T.js +0 -4
- package/dist/hooks-icCwsmrQ.js +0 -536
- package/dist/host-compat-dfJvEfe7.d.ts +0 -21
- package/dist/http-registry-Buj7R-F_.d.ts +0 -23
- package/dist/image-generation-provider-hrRXkkGc.js +0 -152
- package/dist/inbound-reply-dispatch-5AYt56Yt.js +0 -147
- package/dist/inbound-reply-dispatch-B5weFW8i.js +0 -2
- package/dist/inbound-reply-dispatch-cJh4H31y.d.ts +0 -156
- package/dist/index-DbpfOFUf.d.ts +0 -1497
- package/dist/infra-runtime-3_0R8nmO.js +0 -32
- package/dist/init-BnfkYG_k.js +0 -59
- package/dist/interactive-V8NfYsTW.d.ts +0 -26
- package/dist/isolated-agent-CgH7dfOj.js +0 -1097
- package/dist/isolated-agent-dBWkiw0a.js +0 -2
- package/dist/kernel-Ds2aqAJF.d.ts +0 -241
- package/dist/kimi-web-search-provider-QJT3Ftj3.js +0 -80
- package/dist/kimi-web-search-provider.runtime-Dj3SS4T5.js +0 -307
- package/dist/kimi-web-search-provider.runtime.js +0 -1
- package/dist/lib-Dg4yjNFQ.js +0 -871
- package/dist/lifecycle-B9k7QGsS.js +0 -570
- package/dist/list.probe-CbVHFNwf.js +0 -2
- package/dist/list.probe-CxiEBmyW.js +0 -451
- package/dist/list.status-command-DE-edGgB.js +0 -815
- package/dist/llm-slug-generator-DJgq9eFd.js +0 -78
- package/dist/loader-5AqYM9PC.d.ts +0 -142
- package/dist/local-dispatch.runtime-D3F4v51B.js +0 -10
- package/dist/manager-BWf1ks-Z.d.ts +0 -409
- package/dist/mcp-http-DU7Nsg4P.js +0 -583
- package/dist/mcp-http-iZCW6Cet.js +0 -2
- package/dist/media-runtime-DZ5RpQN7.d.ts +0 -261
- package/dist/media-understanding-DEdEyoQB.d.ts +0 -46
- package/dist/media-understanding-provider-4JHrQOUE.js +0 -70
- package/dist/media-understanding-provider-BV7O82XV.js +0 -29
- package/dist/media-understanding-provider-BlPRhYkx.js +0 -69
- package/dist/media-understanding-provider-BuX8eQLj.js +0 -13
- package/dist/memory-core-host-engine-embeddings-BDu5fx8E.d.ts +0 -324
- package/dist/memory-core-host-engine-storage-CdCuH-E2.d.ts +0 -54
- package/dist/message-handler-L6QLWNVP.js +0 -1806
- package/dist/minimax-web-search-provider-_gxeEOy8.js +0 -58
- package/dist/minimax-web-search-provider.runtime-BF4mGi6U.js +0 -148
- package/dist/minimax-web-search-provider.runtime.js +0 -1
- package/dist/model-catalog-DCnRkX8f.d.ts +0 -88
- package/dist/model-definitions-B2gY43hI.d.ts +0 -34
- package/dist/model-definitions-BLOyeH5h.js +0 -73
- package/dist/model-definitions-CoByf5mT.js +0 -243
- package/dist/model-definitions-WP3OmzbS.d.ts +0 -57
- package/dist/model-selection-DhTE6GZD.js +0 -352
- package/dist/models--iAR9QkZ.js +0 -175
- package/dist/models-8ImVEkvh.js +0 -36
- package/dist/models-BIDM8htk.js +0 -48
- package/dist/models-BRgRfrcS.js +0 -36
- package/dist/models-Bib5-APc.js +0 -67
- package/dist/models-Bl67zOoe.js +0 -36
- package/dist/models-BqDDYFE3.d.ts +0 -65
- package/dist/models-BtRQoRIu.js +0 -36
- package/dist/models-BvXmOXik.js +0 -48
- package/dist/models-C-sJciOD.d.ts +0 -9
- package/dist/models-COnXPdlL.js +0 -24
- package/dist/models-CXTmk-Da.d.ts +0 -8
- package/dist/models-Cz0C_8re.js +0 -36
- package/dist/models-DbwEIt-m.d.ts +0 -15
- package/dist/models-DgXkSADi.js +0 -30
- package/dist/models-cli-Bv3y3JgQ.js +0 -257
- package/dist/monitor-BiVOsbbN.js +0 -1024
- package/dist/monitor-BumfRp1t.js +0 -60
- package/dist/monitor.account-Cd6EwtuZ.js +0 -5382
- package/dist/music-generation-provider-ZdDMiC-c.js +0 -308
- package/dist/nodes-C0f8XgD5.js +0 -1483
- package/dist/nodes-Dk4vOgg9.js +0 -3
- package/dist/nodes-pending-Cjg09MXz.js +0 -211
- package/dist/oauth-BIO69Qw0.d.ts +0 -25
- package/dist/oauth-CnO10TN2.js +0 -207
- package/dist/onboard-B3BYT5k7.js +0 -34
- package/dist/onboard-BDMNV6RE.js +0 -23
- package/dist/onboard-B_WNNy5F.d.ts +0 -6
- package/dist/onboard-BbyMaErU.js +0 -69
- package/dist/onboard-BuYPNE6j2.js +0 -23
- package/dist/onboard-C394zMnM.d.ts +0 -11
- package/dist/onboard-CHn4oVbY.js +0 -24
- package/dist/onboard-CPpVbb0O.js +0 -73
- package/dist/onboard-CWDx7Crt.js +0 -23
- package/dist/onboard-CbzkwBzu.d.ts +0 -12
- package/dist/onboard-D099qUd0.js +0 -23
- package/dist/onboard-D7dbzfHc.js +0 -23
- package/dist/onboard-DB-x0nHF.js +0 -30
- package/dist/onboard-DFVrRnxJ.js +0 -23
- package/dist/onboard-DFiqoOc2.d.ts +0 -7
- package/dist/onboard-DJaMK3rr.d.ts +0 -6
- package/dist/onboard-DMdK8D_h.js +0 -67
- package/dist/onboard-J-KL-I6m.js +0 -48
- package/dist/onboard-MIBU-Rmv.js +0 -39
- package/dist/onboard-vmGylfFe.js +0 -23
- package/dist/openai-compat-errors-Dcr5Y8bF.js +0 -136
- package/dist/openai-http-CcqspzU6.js +0 -836
- package/dist/openresponses-http-BnyYYvUF.js +0 -1175
- package/dist/operations-H2Oq0KYz.js +0 -805
- package/dist/outbound.types-BhRehecY.d.ts +0 -291
- package/dist/plugin-enabled-CEIKWKrq.js +0 -232
- package/dist/plugin-entry-CTVRRaaA.d.ts +0 -47
- package/dist/plugin-registration-BTyO5Fwt.js +0 -97
- package/dist/plugin-runtime-_XF2N_UQ.d.ts +0 -117
- package/dist/plugin-sdk/bundled-channel-config-schema-BsOWCrJT.d.ts +0 -3169
- package/dist/plugin-service-B91jVlmZ.d.ts +0 -24
- package/dist/plugin-service-CtGwVz8V.js +0 -1249
- package/dist/postinstall-inventory.json +0 -5410
- package/dist/prepare.runtime-9dlboph7.js +0 -798
- package/dist/preview-warnings-DJx4KJpC.js +0 -618
- package/dist/program-CWC-NBBB.js +0 -131
- package/dist/provider-api-key-auth-BmNcYRMl.d.ts +0 -27
- package/dist/provider-auth-api-key-CCaFiqY3.js +0 -5
- package/dist/provider-auth-result-D_E9dcVc.d.ts +0 -21
- package/dist/provider-catalog-5KZLmrDO.js +0 -11
- package/dist/provider-catalog-7P6AvDzS.js +0 -11
- package/dist/provider-catalog-B2gyTjTU.js +0 -88
- package/dist/provider-catalog-B3YBhe77.js +0 -17
- package/dist/provider-catalog-B7XEeuUm.js +0 -11
- package/dist/provider-catalog-BFGPRd9v.js +0 -17
- package/dist/provider-catalog-BLvkIMSk.d.ts +0 -6
- package/dist/provider-catalog-BPBL9mJf.d.ts +0 -5
- package/dist/provider-catalog-BRkZ6-HD.d.ts +0 -5
- package/dist/provider-catalog-Bfl_AoTZ.js +0 -142
- package/dist/provider-catalog-BpiHWHu1.js +0 -11
- package/dist/provider-catalog-C1qDLekT.d.ts +0 -5
- package/dist/provider-catalog-CKWNCfry.js +0 -11
- package/dist/provider-catalog-CUHB2pSt.d.ts +0 -7
- package/dist/provider-catalog-CWqN2j6J.d.ts +0 -5
- package/dist/provider-catalog-CZ8oYbx3.js +0 -11
- package/dist/provider-catalog-CcQ5-4ZW.d.ts +0 -6
- package/dist/provider-catalog-Cd16uZ0U.js +0 -20
- package/dist/provider-catalog-CpF2D0VK.js +0 -61
- package/dist/provider-catalog-CvXq36zW.d.ts +0 -5
- package/dist/provider-catalog-D2pgEME3.js +0 -48
- package/dist/provider-catalog-DPzcupEl.d.ts +0 -5
- package/dist/provider-catalog-DaeI606G.d.ts +0 -9
- package/dist/provider-catalog-DrOCtTb-.js +0 -11
- package/dist/provider-catalog-DwZ1J2Al.d.ts +0 -6
- package/dist/provider-catalog-Dy7IcHmS.js +0 -107
- package/dist/provider-catalog-TsZS52nq.d.ts +0 -10
- package/dist/provider-catalog-YqIFRCND.d.ts +0 -5
- package/dist/provider-catalog-Ywb5jRwG.d.ts +0 -5
- package/dist/provider-catalog-evknl1oN.js +0 -11
- package/dist/provider-catalog-l0hFpFO2.d.ts +0 -17
- package/dist/provider-catalog-shared-DsRBv0Tp.d.ts +0 -62
- package/dist/provider-dispatcher-BMy9mBJ1.js +0 -22
- package/dist/provider-model-shared-CPAfQBNs.d.ts +0 -143
- package/dist/provider-models-Diu65OcG.d.ts +0 -18
- package/dist/provider-models-LE7PlLYY.js +0 -22
- package/dist/provider-onboard-CpvXEmvz.d.ts +0 -91
- package/dist/provider-registration-DF-LkmNE.js +0 -235
- package/dist/provider-registry-D9cTPW1F.d.ts +0 -8
- package/dist/provider-registry-DI7gMKUP.d.ts +0 -8
- package/dist/provider-registry-DZtgZDkl.d.ts +0 -29
- package/dist/provider-self-hosted-setup-CoHvoyKm.d.ts +0 -74
- package/dist/provider-stream-BpXJr5Ap.d.ts +0 -139
- package/dist/provider-stream-family-Bj5aBD8w.js +0 -2
- package/dist/provider-stream-shared-BaUkhUHj.d.ts +0 -132
- package/dist/provider-usage-DFUhW2do.js +0 -651
- package/dist/provider-web-search-contract-fields-CkXzSsWu.d.ts +0 -25
- package/dist/pw-ai-9Q_dIq4B.js +0 -3064
- package/dist/register.agent-CbfrlzXB.js +0 -152
- package/dist/register.crestodian-CEg0rPfK.js +0 -24
- package/dist/register.maintenance-k9N8I4Wg.js +0 -85
- package/dist/register.subclis-CrXOeaS3.js +0 -3
- package/dist/register.subclis-DfKlni8N.js +0 -31
- package/dist/register.subclis-core-Bg4wbDsO.js +0 -278
- package/dist/registry-Bh3-P2HL.d.ts +0 -8
- package/dist/registry-types-BmEUS4d3.d.ts +0 -392
- package/dist/repair-sequencing-E4yViXG9.js +0 -652
- package/dist/reply-payload-S2mrc_Mh.d.ts +0 -200
- package/dist/reply-turn-admission-BBoPjmGB.js +0 -2056
- package/dist/reply.runtime-C5wfxVI_.js +0 -2
- package/dist/result-fallback-classifier-CX4iLD1G.js +0 -98
- package/dist/route-CifxcQZ1.js +0 -475
- package/dist/routes-B3XAOeWo.js +0 -2
- package/dist/routes-H185h3U-.js +0 -3701
- package/dist/run-CTJFbwbB.js +0 -1162
- package/dist/run-command-B7B53tYk.js +0 -23
- package/dist/run-command-BFuxRDxS.js +0 -2
- package/dist/run-context-C7im9ICg.js +0 -66
- package/dist/run-embedded.runtime-TljBTbzh.js +0 -4
- package/dist/run-execution-cli.runtime-Bt5zwx1W.js +0 -4
- package/dist/run-executor.runtime-hmbWX2Ct.js +0 -330
- package/dist/run-subagent-registry.runtime-B70X80nS.js +0 -2
- package/dist/runtime-DoKE0o7v.js +0 -436
- package/dist/runtime-api-Ca4Llbgf.js +0 -12
- package/dist/runtime-api-pa8xcEmg.d.ts +0 -5
- package/dist/runtime-channel-CFQ59svm.js +0 -148
- package/dist/runtime-channel-DRwCWGUx.js +0 -2
- package/dist/runtime-embedded-agent.runtime-DwmqKUVp.js +0 -2
- package/dist/runtime-forwarders-BMThPHg_.d.ts +0 -39
- package/dist/sdk-setup-tools-Cg_Tabrf.js +0 -8
- package/dist/selection-COhr7g82.js +0 -18365
- package/dist/selection-_G44EVqd.js +0 -3
- package/dist/send-media-BNc67G7I.js +0 -2072
- package/dist/server-5rR0RCpI.js +0 -24
- package/dist/server-context-BhiPROPA.js +0 -955
- package/dist/server-context-OShBAJZQ.js +0 -2
- package/dist/server-cron-Bkzb9edh.js +0 -3173
- package/dist/server-cron-DdR-ugiU.js +0 -2
- package/dist/server-lwtC1vaS.js +0 -72
- package/dist/server-methods-BY_ZqDFJ.js +0 -497
- package/dist/server-node-events-CLvE94AS.js +0 -597
- package/dist/server-plugin-bootstrap-cKOAH5GL.js +0 -71
- package/dist/server-plugins-CPpUykw5.js +0 -435
- package/dist/server-reload-handlers-uzt4VDZ-.js +0 -719
- package/dist/server-restart-sentinel-CpvV0t4O.js +0 -700
- package/dist/server-runtime-services-BhOHoerM.js +0 -147
- package/dist/server-runtime-services-D3Ig68nC.js +0 -3
- package/dist/server-startup-plugins-DslzKVHK.js +0 -127
- package/dist/server-startup-post-attach-DPFBTQez.js +0 -793
- package/dist/server-ws-runtime-D0zoWoiz.js +0 -374
- package/dist/server.impl-CzqLQ3qt.js +0 -2622
- package/dist/session-kill-http-D8JhwZVS.js +0 -121
- package/dist/session-reset-service-uoi7E4Xp.js +0 -651
- package/dist/session-status.runtime-CZK5IU8w.js +0 -2
- package/dist/session-subagent-reactivation.runtime-BSO00-FY.js +0 -2
- package/dist/session-tab-registry-DM9U7e3o.js +0 -551
- package/dist/sessions-B-SkIoaa.js +0 -1917
- package/dist/sessions-history-http-DCiOG4FK.js +0 -432
- package/dist/sessions-patch-DlAAvQvB.js +0 -401
- package/dist/sessions-resolve-DfMXookg.js +0 -180
- package/dist/sessions.runtime-0V2YxKxB.js +0 -2
- package/dist/snapshot-urls-Ble1-NEW.js +0 -317
- package/dist/speech-core-Bk60ZS_y.d.ts +0 -49
- package/dist/speech-provider-DQO9eZd0.js +0 -233
- package/dist/speech-provider-DnBCla4V.js +0 -171
- package/dist/speech-provider-DyYHFxT5.js +0 -227
- package/dist/standalone-9EWfcxeO.js +0 -42
- package/dist/startup-context-nti4X0_w.js +0 -314
- package/dist/status-subagents.runtime-CPZb1EF1.js +0 -32
- package/dist/status-text-C1Hf37lF.js +0 -301
- package/dist/stream-9VBt1MDs.js +0 -26
- package/dist/stream-B_3P7v7P.js +0 -86
- package/dist/stream-CXsue2-v.d.ts +0 -9
- package/dist/stream-oNBFxfKt.d.ts +0 -5
- package/dist/subagent-announce-CPjQQLy8.js +0 -353
- package/dist/subagent-announce-delivery-B6iBOicL.js +0 -1369
- package/dist/subagent-control-DP72sk-l.js +0 -492
- package/dist/subagent-hooks-B1oUIYH3.js +0 -2
- package/dist/subagent-hooks-BkGj4_xI.js +0 -230
- package/dist/subagent-hooks-api-D2mulK3S.js +0 -23
- package/dist/subagent-registry-CEKAUB5h.js +0 -3
- package/dist/subagent-registry-OUVucPAn.js +0 -2627
- package/dist/subagent-session-cleanup-Bx8d3kw0.js +0 -390
- package/dist/system-CelaP2zI.js +0 -111
- package/dist/talk-DGOI3Lu3.js +0 -2454
- package/dist/target-id-BXRG7x9x.js +0 -107
- package/dist/thinking-B8V29FhB.js +0 -35
- package/dist/thread-bindings-DpVdEPZ0.js +0 -228
- package/dist/tool-DHzDpxE4.js +0 -143
- package/dist/tool-dispatch-ClP3Rc7g.js +0 -155
- package/dist/tool-resolution-CZcLod1d.js +0 -153
- package/dist/tool-split-BhiQ8676.d.ts +0 -19
- package/dist/tools-ZvSvbsCW.d.ts +0 -38
- package/dist/tools-effective-C2mHZT-A.js +0 -442
- package/dist/tools-effective-inventory-ctnM7hc6.js +0 -379
- package/dist/tools-invoke-Ci6Rux2s.js +0 -51
- package/dist/tools-invoke-http-CJflXcJk.js +0 -68
- package/dist/tools-invoke-shared-BLu_mJEX.js +0 -200
- package/dist/tts-B2rPJPij.js +0 -83
- package/dist/tts-Gp9FI3_n.js +0 -163
- package/dist/tts-runtime-DNi1HXPF.d.ts +0 -230
- package/dist/tui-BUhfQ9vD.js +0 -3
- package/dist/tui-BhH5mvLf.js +0 -2
- package/dist/tui-backend-C_4ajTHI.js +0 -257
- package/dist/tui-cli-BhWJ-QoB.js +0 -40
- package/dist/tui-ink-run-BTWbUQGb.js +0 -7414
- package/dist/tui-ink-run-DfTdivkh.js +0 -2
- package/dist/types-B4fW3r5y.d.ts +0 -111
- package/dist/types-DI62NfFe.d.ts +0 -7034
- package/dist/types-sAih_uQb.d.ts +0 -393
- package/dist/types.public-B3MKhuo2.d.ts +0 -70
- package/dist/video-generation-B9c6a5cw.js +0 -207
- package/dist/video-generation-BgJp7UIA.d.ts +0 -224
- package/dist/video-generation-provider-BjiVjf40.js +0 -325
- package/dist/video-generation-provider-CsnQJg_h.js +0 -297
- package/dist/video-generation-provider-DtU-ZPqP.js +0 -64
- package/dist/video-generation-provider-wZ0bzv0e.js +0 -77
- package/dist/webhook-targets-Cy8e7y3g.d.ts +0 -99
- package/dist/zod-schema.core-BGLctDlK.d.ts +0 -166
- package/skills/canvas/SKILL.md +0 -78
- package/skills/clawhub/SKILL.md +0 -77
- package/skills/coding-agent/SKILL.md +0 -143
- package/skills/diagram-maker/SKILL.md +0 -53
- package/skills/diagram-maker/references/excalidraw-patterns.md +0 -85
- package/skills/diagram-maker/references/svg-template.md +0 -112
- package/skills/gemini/SKILL.md +0 -47
- package/skills/gh-issues/SKILL.md +0 -213
- package/skills/gifgrep/SKILL.md +0 -85
- package/skills/github/SKILL.md +0 -84
- package/skills/healthcheck/SKILL.md +0 -105
- package/skills/mcporter/SKILL.md +0 -61
- package/skills/meme-maker/SKILL.md +0 -42
- package/skills/meme-maker/references/templates.json +0 -358
- package/skills/meme-maker/scripts/meme.mjs +0 -398
- package/skills/model-usage/SKILL.md +0 -71
- package/skills/model-usage/references/codexbar-cli.md +0 -33
- package/skills/model-usage/scripts/model_usage.py +0 -319
- package/skills/model-usage/scripts/test_model_usage.py +0 -40
- package/skills/nano-pdf/SKILL.md +0 -38
- package/skills/node-connect/SKILL.md +0 -143
- package/skills/node-inspect-debugger/SKILL.md +0 -85
- package/skills/openai-whisper/SKILL.md +0 -38
- package/skills/openai-whisper-api/SKILL.md +0 -71
- package/skills/openai-whisper-api/scripts/transcribe.sh +0 -154
- package/skills/oracle/SKILL.md +0 -126
- package/skills/pyproject.toml +0 -10
- package/skills/python-debugpy/SKILL.md +0 -73
- package/skills/sag/SKILL.md +0 -87
- package/skills/session-logs/SKILL.md +0 -151
- package/skills/sherpa-onnx-tts/SKILL.md +0 -109
- package/skills/sherpa-onnx-tts/bin/sherpa-onnx-tts +0 -178
- package/skills/skill-creator/SKILL.md +0 -78
- package/skills/skill-creator/license.txt +0 -202
- package/skills/skill-creator/scripts/init_skill.py +0 -378
- package/skills/skill-creator/scripts/package_skill.py +0 -139
- package/skills/skill-creator/scripts/quick_validate.py +0 -169
- package/skills/skill-creator/scripts/test_package_skill.py +0 -161
- package/skills/skill-creator/scripts/test_quick_validate.py +0 -116
- package/skills/spike/SKILL.md +0 -51
- package/skills/summarize/SKILL.md +0 -87
- package/skills/taskflow/SKILL.md +0 -149
- package/skills/taskflow/examples/inbox-triage.lobster +0 -33
- package/skills/taskflow/examples/pr-intake.lobster +0 -32
- package/skills/taskflow-inbox-triage/SKILL.md +0 -119
- package/skills/video-frames/SKILL.md +0 -46
- package/skills/video-frames/scripts/frame.sh +0 -81
- package/skills/voice-call/SKILL.md +0 -45
- package/skills/weather/SKILL.md +0 -64
- /package/dist/{acp-runtime-backend-DbchQ02o.js → acp-runtime-backend-DZ1Lnt7f.js} +0 -0
- /package/dist/{delegate-k1aptKei.js → delegate-CwhxUdeb.js} +0 -0
- /package/dist/{dispatch-acp-CD4YxPpf.js → dispatch-acp-BP4I5ZQf.js} +0 -0
- /package/dist/{exec-approvals-ByWUCFQM.js → exec-approvals-ByWUCFQM2.js} +0 -0
- /package/dist/{heartbeat-runner-CM0UZxa_.js → heartbeat-runner-CL3alQ8-.js} +0 -0
- /package/dist/{index-B0VJdRJQ.d.ts → index-B0VJdRJQ2.d.ts} +0 -0
- /package/dist/{library-CQ71yATP.js → library-CiTr_aqC.js} +0 -0
- /package/dist/{run-session-state-DbDeH-q6.js → run-session-state-BOMUtBKZ.js} +0 -0
- /package/dist/{session-subagent-reactivation-Bj91A2ms.js → session-subagent-reactivation-CH0C2I6Y.js} +0 -0
- /package/dist/{types-C4HgagiY2.d.ts → types-C4HgagiY.d.ts} +0 -0
package/dist/chat-DWRXkuvU.js
DELETED
|
@@ -1,2940 +0,0 @@
|
|
|
1
|
-
import { a as normalizeLowercaseStringOrEmpty } from "./string-coerce-DKw2K5wM.js";
|
|
2
|
-
import { a as asFiniteNumber } from "./number-coercion-D1aDmIZp.js";
|
|
3
|
-
import { i as asOptionalRecord } from "./record-coerce-Btbek4uV.js";
|
|
4
|
-
import { a as formatUncaughtError, i as formatErrorMessage } from "./errors-C_Wa6a5T.js";
|
|
5
|
-
import { _ as uniqueStrings } from "./string-normalization-B8G0vlWE.js";
|
|
6
|
-
import { S as safeFileURLToPath, v as assertNoWindowsNetworkPath } from "./fs-safe-CR_om3kX.js";
|
|
7
|
-
import { r as openLocalFileSafely } from "./secure-temp-dir-BvCzS-gM.js";
|
|
8
|
-
import { _ as resolveSessionAgentId } from "./agent-scope-EEbMCF2I.js";
|
|
9
|
-
import { c as parseAgentSessionKey } from "./session-key-utils-CdfsDYvz.js";
|
|
10
|
-
import { h as scopeLegacySessionKeyToAgent, l as normalizeAgentId } from "./session-key-CJf5_zWs.js";
|
|
11
|
-
import { c as resolveDefaultAgentId, n as listAgentIds, o as resolveAgentWorkspaceDir } from "./agent-scope-config-BHdZonI2.js";
|
|
12
|
-
import { c as measureDiagnosticsTimelineSpan, l as measureDiagnosticsTimelineSpanSync } from "./plugin-metadata-snapshot-CHymO30I.js";
|
|
13
|
-
import { r as resolveProviderIdForAuth } from "./provider-auth-aliases-hXKyFMus.js";
|
|
14
|
-
import { a as hasGatewayClientCap, i as GATEWAY_CLIENT_NAMES, r as GATEWAY_CLIENT_MODES, t as GATEWAY_CLIENT_CAPS } from "./client-info-D6_UASoA.js";
|
|
15
|
-
import { C as validateChatSendParams, Ri as ErrorCodes, S as validateChatInjectParams, t as formatValidationErrors, x as validateChatHistoryParams, y as validateChatAbortParams, zi as errorShape } from "./src-B1Y482-m.js";
|
|
16
|
-
import { i as INTERNAL_MESSAGE_CHANNEL } from "./message-channel-core-rOsWksPZ.js";
|
|
17
|
-
import { i as normalizeMessageChannel } from "./message-channel-normalize-CaOaCinb.js";
|
|
18
|
-
import { a as isOperatorUiClient, n as isGatewayCliClient, o as isWebchatClient } from "./message-channel-DcN_7tYD.js";
|
|
19
|
-
import { t as ADMIN_SCOPE } from "./operator-scopes-DGvgHuOd.js";
|
|
20
|
-
import "./method-scopes-CTk-6mpm.js";
|
|
21
|
-
import { a as getReplyPayloadTtsSupplement, c as isReplyPayloadTtsSupplement, i as getReplyPayloadMetadata, n as buildTtsSupplementMediaPayload } from "./reply-payload-DM17pxMC.js";
|
|
22
|
-
import "./local-file-access-CF5H6Z2a.js";
|
|
23
|
-
import { t as isPassThroughRemoteMediaSource } from "./media-source-url-B2V2UVFP.js";
|
|
24
|
-
import { i as resolveSessionStoreKey } from "./session-store-key-dbCfepNe.js";
|
|
25
|
-
import { n as deliveryContextFromSession } from "./delivery-context.shared-CHlZnq4E.js";
|
|
26
|
-
import { i as resolveSessionFilePath } from "./paths-C79m3Aob.js";
|
|
27
|
-
import { o as isAudioFileName } from "./mime-TnUOZVhx.js";
|
|
28
|
-
import "./sessions-CtMqsEs2.js";
|
|
29
|
-
import { o as resolveMirroredTranscriptText, s as appendSessionTranscriptMessage } from "./transcript-g0svEjnG.js";
|
|
30
|
-
import { t as emitSessionTranscriptUpdate } from "./transcript-events-CX3wuAgS.js";
|
|
31
|
-
import "./transcript-jsonl-LFU2CQ2E.js";
|
|
32
|
-
import { r as resolveAgentTimeoutMs } from "./task-completion-contract-BqW0VJsk.js";
|
|
33
|
-
import { h as stripEnvelopeFromMessage, i as readRecentSessionMessagesAsync, m as readSessionTranscriptIndex, n as capArrayByJsonBytes, x as jsonUtf8Bytes } from "./session-utils.fs-D-Ly08WB.js";
|
|
34
|
-
import { s as normalizeInputProvenance } from "./input-provenance-DCrP7aPH.js";
|
|
35
|
-
import { i as stripInlineDirectiveTagsForDisplay, n as sanitizeReplyDirectiveId } from "./directive-tags-DBD-mk-0.js";
|
|
36
|
-
import { c as loadSessionEntry, d as resolveDeletedAgentIdFromSessionKey, h as resolveGatewaySessionThinkingDefault, p as resolveGatewayModelSupportsImages, v as resolveSessionModelRef } from "./session-utils-pgndLXV7.js";
|
|
37
|
-
import { n as getSessionBindingService } from "./session-binding-service-BjjMIxQb.js";
|
|
38
|
-
import { m as resolveSendableOutboundReplyParts } from "./reply-payload-swpu2tGD.js";
|
|
39
|
-
import { t as dispatchInboundMessage } from "./dispatch-D5iG5A8j.js";
|
|
40
|
-
import { ot as createUserTurnTranscriptRecorder } from "./selection-COhr7g82.js";
|
|
41
|
-
import { n as estimateBase64DecodedBytes } from "./base64-D03BM6T6.js";
|
|
42
|
-
import { i as deleteMediaBuffer, t as MEDIA_MAX_BYTES, u as saveMediaBuffer } from "./store-BCRjjjf9.js";
|
|
43
|
-
import { r as getAgentScopedMediaLocalRoots, t as appendLocalMediaParentRoots } from "./local-roots-B0mKVk2X.js";
|
|
44
|
-
import { n as assertLocalMediaAllowed, t as LocalMediaAccessError } from "./local-media-access-BHSyRG_b.js";
|
|
45
|
-
import { i as normalizeReplyPayloadsForDelivery } from "./payloads-DHTHYd7R.js";
|
|
46
|
-
import { a as ensureSandboxWorkspaceForSession } from "./sandbox-CRE56oUs.js";
|
|
47
|
-
import { t as rewriteTranscriptEntriesInSessionFile } from "./transcript-rewrite-Dt9DsZGc.js";
|
|
48
|
-
import { u as isPluginOwnedSessionBindingRecord } from "./conversation-binding-BsrrLxjw.js";
|
|
49
|
-
import { n as resolveSendPolicy } from "./send-policy-C6dhXszH.js";
|
|
50
|
-
import { s as augmentChatHistoryWithCliSessionImports } from "./attempt-execution.helpers-ZwDOhq8d.js";
|
|
51
|
-
import { n as createReplyMediaPathNormalizer } from "./reply-media-paths.runtime-DYqLiKDF.js";
|
|
52
|
-
import { t as createReplyDispatcher } from "./reply-dispatcher-DjSNvGzA.js";
|
|
53
|
-
import { i as registerChatAbortController, o as updateChatRunProvider, r as isChatStopCommandText, t as abortChatRunById } from "./chat-abort-wipQF0Ih.js";
|
|
54
|
-
import { t as createChannelReplyPipeline } from "./reply-pipeline-4jiTFHlm.js";
|
|
55
|
-
import { n as runAgentHarnessBeforeMessageWriteHook } from "./hook-helpers-CZvYp1Qk.js";
|
|
56
|
-
import "./channel-outbound-Bt45s9Ss.js";
|
|
57
|
-
import { t as logLargePayload } from "./diagnostic-payload-BP1TpHgP.js";
|
|
58
|
-
import { c as getMaxChatHistoryMessagesBytes } from "./server-constants-BGwLM6XN.js";
|
|
59
|
-
import { t as formatForLog } from "./ws-log-BzGc41ZC.js";
|
|
60
|
-
import { n as isSuppressedControlReplyText } from "./control-reply-text-dCt9wdi8.js";
|
|
61
|
-
import { a as projectRecentChatDisplayMessages, n as isToolHistoryBlockType, o as resolveEffectiveChatHistoryMaxChars, r as projectChatDisplayMessage } from "./chat-display-projection-DCLQ90zy.js";
|
|
62
|
-
import { t as stageSandboxMedia } from "./stage-sandbox-media-vdDrHBMY.js";
|
|
63
|
-
import { a as resolveChatAttachmentMaxBytes, i as parseMessageWithAttachments, n as MediaOffloadError, r as UnsupportedAttachmentError, t as normalizeRpcAttachmentsToChatAttachments } from "./attachment-normalize-BHAbLiL2.js";
|
|
64
|
-
import { i as createManagedOutgoingImageBlocks, n as attachManagedOutgoingImagesToMessage, r as cleanupManagedOutgoingImageRecords } from "./managed-image-attachments-Df4qeJ_S.js";
|
|
65
|
-
import { n as timestampOptsFromConfig, t as injectTimestamp } from "./agent-timestamp-ClgiA1GA.js";
|
|
66
|
-
import { n as setGatewayDedupeEntry } from "./agent-wait-dedupe-C3xQk2Ww.js";
|
|
67
|
-
import fs from "node:fs";
|
|
68
|
-
import path from "node:path";
|
|
69
|
-
import { createHash } from "node:crypto";
|
|
70
|
-
//#region src/chat/canvas-render.ts
|
|
71
|
-
function tryParseJsonRecord(value) {
|
|
72
|
-
if (typeof value !== "string") return;
|
|
73
|
-
try {
|
|
74
|
-
return asOptionalRecord(JSON.parse(value));
|
|
75
|
-
} catch {
|
|
76
|
-
return;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
function getRecordStringField(record, key) {
|
|
80
|
-
const value = record?.[key];
|
|
81
|
-
return typeof value === "string" && value.trim() ? value : void 0;
|
|
82
|
-
}
|
|
83
|
-
function getRecordNumberField(record, key) {
|
|
84
|
-
const value = record?.[key];
|
|
85
|
-
return asFiniteNumber(value);
|
|
86
|
-
}
|
|
87
|
-
function getNestedRecord(record, key) {
|
|
88
|
-
const value = record?.[key];
|
|
89
|
-
return asOptionalRecord(value);
|
|
90
|
-
}
|
|
91
|
-
function normalizeSurface(value) {
|
|
92
|
-
return value === "assistant_message" ? value : void 0;
|
|
93
|
-
}
|
|
94
|
-
function normalizePreferredHeight(value) {
|
|
95
|
-
return typeof value === "number" && Number.isFinite(value) && value >= 160 ? Math.min(Math.trunc(value), 1200) : void 0;
|
|
96
|
-
}
|
|
97
|
-
function coerceCanvasPreview(record) {
|
|
98
|
-
if (!record) return;
|
|
99
|
-
if (getRecordStringField(record, "kind")?.trim().toLowerCase() !== "canvas") return;
|
|
100
|
-
const presentation = getNestedRecord(record, "presentation");
|
|
101
|
-
const view = getNestedRecord(record, "view");
|
|
102
|
-
const source = getNestedRecord(record, "source");
|
|
103
|
-
const requestedSurface = getRecordStringField(presentation, "target") ?? getRecordStringField(record, "target");
|
|
104
|
-
const surface = requestedSurface ? normalizeSurface(requestedSurface) : "assistant_message";
|
|
105
|
-
if (!surface) return;
|
|
106
|
-
const title = getRecordStringField(presentation, "title") ?? getRecordStringField(view, "title");
|
|
107
|
-
const preferredHeight = normalizePreferredHeight(getRecordNumberField(presentation, "preferred_height") ?? getRecordNumberField(presentation, "preferredHeight") ?? getRecordNumberField(view, "preferred_height") ?? getRecordNumberField(view, "preferredHeight"));
|
|
108
|
-
const className = getRecordStringField(presentation, "class_name") ?? getRecordStringField(presentation, "className");
|
|
109
|
-
const style = getRecordStringField(presentation, "style");
|
|
110
|
-
const viewUrl = getRecordStringField(view, "url") ?? getRecordStringField(view, "entryUrl");
|
|
111
|
-
const viewId = getRecordStringField(view, "id") ?? getRecordStringField(view, "docId");
|
|
112
|
-
if (viewUrl) return {
|
|
113
|
-
kind: "canvas",
|
|
114
|
-
surface,
|
|
115
|
-
render: "url",
|
|
116
|
-
url: viewUrl,
|
|
117
|
-
...viewId ? { viewId } : {},
|
|
118
|
-
...title ? { title } : {},
|
|
119
|
-
...preferredHeight ? { preferredHeight } : {},
|
|
120
|
-
...className ? { className } : {},
|
|
121
|
-
...style ? { style } : {}
|
|
122
|
-
};
|
|
123
|
-
if (getRecordStringField(source, "type")?.trim().toLowerCase() === "url") {
|
|
124
|
-
const url = getRecordStringField(source, "url");
|
|
125
|
-
if (!url) return;
|
|
126
|
-
return {
|
|
127
|
-
kind: "canvas",
|
|
128
|
-
surface,
|
|
129
|
-
render: "url",
|
|
130
|
-
url,
|
|
131
|
-
...title ? { title } : {},
|
|
132
|
-
...preferredHeight ? { preferredHeight } : {},
|
|
133
|
-
...className ? { className } : {},
|
|
134
|
-
...style ? { style } : {}
|
|
135
|
-
};
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
function extractCanvasFromText(outputText, _toolName) {
|
|
139
|
-
return coerceCanvasPreview(tryParseJsonRecord(outputText));
|
|
140
|
-
}
|
|
141
|
-
//#endregion
|
|
142
|
-
//#region src/gateway/server-methods/chat-reply-media.ts
|
|
143
|
-
function isDataUrlMedia(mediaUrl) {
|
|
144
|
-
return mediaUrl.trim().toLowerCase().startsWith("data:");
|
|
145
|
-
}
|
|
146
|
-
function shouldPreserveDisplayMediaUrl(payload, mediaUrl) {
|
|
147
|
-
if (isDataUrlMedia(mediaUrl)) return true;
|
|
148
|
-
if (!isAudioFileName(mediaUrl)) return false;
|
|
149
|
-
if (isPassThroughRemoteMediaSource(mediaUrl)) return true;
|
|
150
|
-
return payload.trustedLocalMedia === true;
|
|
151
|
-
}
|
|
152
|
-
async function normalizeWebchatReplyMediaPathsForDisplay(params) {
|
|
153
|
-
if (params.payloads.length === 0) return params.payloads;
|
|
154
|
-
const workspaceDir = params.workspaceDir ?? resolveAgentWorkspaceDir(params.cfg, params.agentId);
|
|
155
|
-
if (!workspaceDir) return params.payloads;
|
|
156
|
-
const normalizeMediaPaths = createReplyMediaPathNormalizer({
|
|
157
|
-
cfg: params.cfg,
|
|
158
|
-
sessionKey: params.sessionKey,
|
|
159
|
-
agentId: params.agentId,
|
|
160
|
-
workspaceDir,
|
|
161
|
-
accountId: params.accountId
|
|
162
|
-
});
|
|
163
|
-
const normalized = [];
|
|
164
|
-
for (const payload of params.payloads) {
|
|
165
|
-
if (payload.sensitiveMedia === true) {
|
|
166
|
-
normalized.push(payload);
|
|
167
|
-
continue;
|
|
168
|
-
}
|
|
169
|
-
const mediaUrls = resolveSendableOutboundReplyParts(payload).mediaUrls;
|
|
170
|
-
if (!mediaUrls.some((mediaUrl) => shouldPreserveDisplayMediaUrl(payload, mediaUrl))) {
|
|
171
|
-
normalized.push(await normalizeMediaPaths(payload));
|
|
172
|
-
continue;
|
|
173
|
-
}
|
|
174
|
-
if (!mediaUrls.some((mediaUrl) => !shouldPreserveDisplayMediaUrl(payload, mediaUrl))) {
|
|
175
|
-
normalized.push(payload);
|
|
176
|
-
continue;
|
|
177
|
-
}
|
|
178
|
-
const mergedMediaUrls = [];
|
|
179
|
-
let text = payload.text;
|
|
180
|
-
for (const mediaUrl of mediaUrls) {
|
|
181
|
-
if (shouldPreserveDisplayMediaUrl(payload, mediaUrl)) {
|
|
182
|
-
mergedMediaUrls.push(mediaUrl);
|
|
183
|
-
continue;
|
|
184
|
-
}
|
|
185
|
-
const normalizedMediaUrls = resolveSendableOutboundReplyParts(await normalizeMediaPaths({
|
|
186
|
-
...payload,
|
|
187
|
-
mediaUrl,
|
|
188
|
-
mediaUrls: [mediaUrl]
|
|
189
|
-
})).mediaUrls;
|
|
190
|
-
if (normalizedMediaUrls.length === 0) continue;
|
|
191
|
-
mergedMediaUrls.push(...normalizedMediaUrls);
|
|
192
|
-
}
|
|
193
|
-
normalized.push({
|
|
194
|
-
...payload,
|
|
195
|
-
text,
|
|
196
|
-
mediaUrl: mergedMediaUrls[0],
|
|
197
|
-
mediaUrls: mergedMediaUrls
|
|
198
|
-
});
|
|
199
|
-
}
|
|
200
|
-
return normalized;
|
|
201
|
-
}
|
|
202
|
-
//#endregion
|
|
203
|
-
//#region src/gateway/server-methods/chat-transcript-inject.ts
|
|
204
|
-
function resolveInjectedAssistantContent(params) {
|
|
205
|
-
const labelPrefix = params.label ? `[${params.label}]\n\n` : "";
|
|
206
|
-
if (params.content && params.content.length > 0) {
|
|
207
|
-
if (!labelPrefix) return params.content;
|
|
208
|
-
const first = params.content[0];
|
|
209
|
-
if (first && typeof first === "object" && first.type === "text" && typeof first.text === "string") return [{
|
|
210
|
-
...first,
|
|
211
|
-
text: `${labelPrefix}${first.text}`
|
|
212
|
-
}, ...params.content.slice(1)];
|
|
213
|
-
return [{
|
|
214
|
-
type: "text",
|
|
215
|
-
text: labelPrefix.trim()
|
|
216
|
-
}, ...params.content];
|
|
217
|
-
}
|
|
218
|
-
return [{
|
|
219
|
-
type: "text",
|
|
220
|
-
text: `${labelPrefix}${params.message}`
|
|
221
|
-
}];
|
|
222
|
-
}
|
|
223
|
-
async function appendInjectedAssistantMessageToTranscript(params) {
|
|
224
|
-
const now = params.now ?? Date.now();
|
|
225
|
-
const messageBody = {
|
|
226
|
-
role: "assistant",
|
|
227
|
-
content: resolveInjectedAssistantContent({
|
|
228
|
-
message: params.message,
|
|
229
|
-
label: params.label,
|
|
230
|
-
content: params.content
|
|
231
|
-
}),
|
|
232
|
-
timestamp: now,
|
|
233
|
-
stopReason: "stop",
|
|
234
|
-
usage: {
|
|
235
|
-
input: 0,
|
|
236
|
-
output: 0,
|
|
237
|
-
cacheRead: 0,
|
|
238
|
-
cacheWrite: 0,
|
|
239
|
-
totalTokens: 0,
|
|
240
|
-
cost: {
|
|
241
|
-
input: 0,
|
|
242
|
-
output: 0,
|
|
243
|
-
cacheRead: 0,
|
|
244
|
-
cacheWrite: 0,
|
|
245
|
-
total: 0
|
|
246
|
-
}
|
|
247
|
-
},
|
|
248
|
-
api: "openai-responses",
|
|
249
|
-
provider: "fengming",
|
|
250
|
-
model: "gateway-injected",
|
|
251
|
-
...params.idempotencyKey ? { idempotencyKey: params.idempotencyKey } : {},
|
|
252
|
-
...params.ttsSupplement ? { fengmingTtsSupplement: params.ttsSupplement } : {},
|
|
253
|
-
...params.abortMeta ? { fengmingAbort: {
|
|
254
|
-
aborted: true,
|
|
255
|
-
origin: params.abortMeta.origin,
|
|
256
|
-
runId: params.abortMeta.runId
|
|
257
|
-
} } : {}
|
|
258
|
-
};
|
|
259
|
-
try {
|
|
260
|
-
const { messageId, message: appendedMessage } = await appendSessionTranscriptMessage({
|
|
261
|
-
transcriptPath: params.transcriptPath,
|
|
262
|
-
message: messageBody,
|
|
263
|
-
now,
|
|
264
|
-
useRawWhenLinear: true,
|
|
265
|
-
config: params.config
|
|
266
|
-
});
|
|
267
|
-
emitSessionTranscriptUpdate({
|
|
268
|
-
sessionFile: params.transcriptPath,
|
|
269
|
-
...params.sessionKey ? { sessionKey: params.sessionKey } : {},
|
|
270
|
-
...params.agentId ? { agentId: params.agentId } : {},
|
|
271
|
-
message: appendedMessage,
|
|
272
|
-
messageId
|
|
273
|
-
});
|
|
274
|
-
return {
|
|
275
|
-
ok: true,
|
|
276
|
-
messageId,
|
|
277
|
-
message: appendedMessage
|
|
278
|
-
};
|
|
279
|
-
} catch (err) {
|
|
280
|
-
return {
|
|
281
|
-
ok: false,
|
|
282
|
-
error: formatErrorMessage(err)
|
|
283
|
-
};
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
//#endregion
|
|
287
|
-
//#region src/gateway/server-methods/chat-webchat-media.ts
|
|
288
|
-
/** Cap local audio files exposed through assistant media. */
|
|
289
|
-
const MAX_WEBCHAT_AUDIO_BYTES = 15 * 1024 * 1024;
|
|
290
|
-
const MAX_WEBCHAT_IMAGE_DATA_URL_CHARS = 2e6;
|
|
291
|
-
const MAX_WEBCHAT_IMAGE_DATA_BYTES = 15e5;
|
|
292
|
-
const ALLOWED_WEBCHAT_DATA_IMAGE_MEDIA_TYPES = new Set([
|
|
293
|
-
"image/apng",
|
|
294
|
-
"image/avif",
|
|
295
|
-
"image/bmp",
|
|
296
|
-
"image/gif",
|
|
297
|
-
"image/jpeg",
|
|
298
|
-
"image/png",
|
|
299
|
-
"image/webp"
|
|
300
|
-
]);
|
|
301
|
-
const MIME_BY_EXT = {
|
|
302
|
-
".aac": "audio/aac",
|
|
303
|
-
".m4a": "audio/mp4",
|
|
304
|
-
".mp3": "audio/mpeg",
|
|
305
|
-
".oga": "audio/ogg",
|
|
306
|
-
".ogg": "audio/ogg",
|
|
307
|
-
".opus": "audio/opus",
|
|
308
|
-
".wav": "audio/wav",
|
|
309
|
-
".webm": "audio/webm"
|
|
310
|
-
};
|
|
311
|
-
/** Map `mediaUrl` strings to an absolute filesystem path for local embedding (plain paths or `file:` URLs). */
|
|
312
|
-
function resolveLocalMediaPathForEmbedding(raw) {
|
|
313
|
-
const trimmed = raw.trim();
|
|
314
|
-
if (!trimmed) return null;
|
|
315
|
-
if (/^data:/i.test(trimmed)) return null;
|
|
316
|
-
if (/^https?:/i.test(trimmed)) return null;
|
|
317
|
-
if (trimmed.startsWith("file:")) try {
|
|
318
|
-
const p = safeFileURLToPath(trimmed);
|
|
319
|
-
if (!path.isAbsolute(p)) return null;
|
|
320
|
-
return p;
|
|
321
|
-
} catch {
|
|
322
|
-
return null;
|
|
323
|
-
}
|
|
324
|
-
if (!path.isAbsolute(trimmed)) return null;
|
|
325
|
-
try {
|
|
326
|
-
assertNoWindowsNetworkPath(trimmed, "Local media path");
|
|
327
|
-
} catch {
|
|
328
|
-
return null;
|
|
329
|
-
}
|
|
330
|
-
return trimmed;
|
|
331
|
-
}
|
|
332
|
-
async function readLocalAudioContentBlockForEmbedding(payload, raw, options) {
|
|
333
|
-
if (payload.trustedLocalMedia !== true) return null;
|
|
334
|
-
const resolved = resolveLocalMediaPathForEmbedding(raw);
|
|
335
|
-
if (!resolved) return null;
|
|
336
|
-
if (!isAudioFileName(resolved)) return null;
|
|
337
|
-
let opened;
|
|
338
|
-
try {
|
|
339
|
-
await assertLocalMediaAllowed(resolved, options?.localRoots);
|
|
340
|
-
opened = await openLocalFileSafely({ filePath: resolved });
|
|
341
|
-
await assertLocalMediaAllowed(opened.realPath, options?.localRoots);
|
|
342
|
-
if (opened.stat.size > MAX_WEBCHAT_AUDIO_BYTES) return null;
|
|
343
|
-
return {
|
|
344
|
-
path: opened.realPath,
|
|
345
|
-
block: {
|
|
346
|
-
type: "attachment",
|
|
347
|
-
attachment: {
|
|
348
|
-
url: opened.realPath,
|
|
349
|
-
kind: "audio",
|
|
350
|
-
label: path.basename(opened.realPath),
|
|
351
|
-
mimeType: mimeTypeForPath(opened.realPath),
|
|
352
|
-
...payload.audioAsVoice === true ? { isVoiceNote: true } : {}
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
};
|
|
356
|
-
} catch (err) {
|
|
357
|
-
if (err instanceof LocalMediaAccessError) options?.onLocalAudioAccessDenied?.(err);
|
|
358
|
-
return null;
|
|
359
|
-
} finally {
|
|
360
|
-
await opened?.handle.close().catch(() => {});
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
function mimeTypeForPath(filePath) {
|
|
364
|
-
return MIME_BY_EXT[normalizeLowercaseStringOrEmpty(path.extname(filePath))] ?? "audio/mpeg";
|
|
365
|
-
}
|
|
366
|
-
function isBase64DataPayload(value) {
|
|
367
|
-
if (value.length === 0) return false;
|
|
368
|
-
for (let index = 0; index < value.length; index += 1) {
|
|
369
|
-
const code = value.charCodeAt(index);
|
|
370
|
-
if (!(code >= 65 && code <= 90 || code >= 97 && code <= 122 || code >= 48 && code <= 57 || code === 43 || code === 47 || code === 61) && !(code === 9 || code === 10 || code === 11 || code === 12 || code === 13 || code === 32)) return false;
|
|
371
|
-
}
|
|
372
|
-
return true;
|
|
373
|
-
}
|
|
374
|
-
function resolveEmbeddableImageUrl(url) {
|
|
375
|
-
const trimmed = url.trim();
|
|
376
|
-
if (!trimmed) return null;
|
|
377
|
-
if (trimmed.length > MAX_WEBCHAT_IMAGE_DATA_URL_CHARS) return null;
|
|
378
|
-
const commaIndex = trimmed.indexOf(",");
|
|
379
|
-
if (commaIndex < 0) return null;
|
|
380
|
-
const metadata = trimmed.slice(0, commaIndex);
|
|
381
|
-
const match = /^data:(image\/[a-z0-9.+-]+);base64$/i.exec(metadata);
|
|
382
|
-
const base64Data = trimmed.slice(commaIndex + 1);
|
|
383
|
-
if (!match || !isBase64DataPayload(base64Data)) return null;
|
|
384
|
-
const mediaType = normalizeLowercaseStringOrEmpty(match[1]);
|
|
385
|
-
if (!ALLOWED_WEBCHAT_DATA_IMAGE_MEDIA_TYPES.has(mediaType)) return null;
|
|
386
|
-
if (estimateBase64DecodedBytes(base64Data) > MAX_WEBCHAT_IMAGE_DATA_BYTES) return null;
|
|
387
|
-
return trimmed;
|
|
388
|
-
}
|
|
389
|
-
function resolveReplyDirectivePrefix(payload) {
|
|
390
|
-
const replyToId = sanitizeReplyDirectiveId(payload.replyToId);
|
|
391
|
-
if (replyToId) return `[[reply_to:${replyToId}]]`;
|
|
392
|
-
if (payload.replyToCurrent) return "[[reply_to_current]]";
|
|
393
|
-
return "";
|
|
394
|
-
}
|
|
395
|
-
/**
|
|
396
|
-
* Build Control UI / transcript `content` blocks for local TTS (or other) audio files
|
|
397
|
-
* referenced by slash-command / agent replies when the webchat path only had text aggregation.
|
|
398
|
-
*/
|
|
399
|
-
async function buildWebchatAudioContentBlocksFromReplyPayloads(payloads, options) {
|
|
400
|
-
const seen = /* @__PURE__ */ new Set();
|
|
401
|
-
const blocks = [];
|
|
402
|
-
for (const payload of payloads) {
|
|
403
|
-
if (payload.isReasoning === true) continue;
|
|
404
|
-
const parts = resolveSendableOutboundReplyParts(payload);
|
|
405
|
-
for (const raw of parts.mediaUrls) {
|
|
406
|
-
const url = raw.trim();
|
|
407
|
-
if (!url) continue;
|
|
408
|
-
const audio = await readLocalAudioContentBlockForEmbedding(payload, url, options);
|
|
409
|
-
if (!audio || seen.has(audio.path)) continue;
|
|
410
|
-
seen.add(audio.path);
|
|
411
|
-
blocks.push(audio.block);
|
|
412
|
-
}
|
|
413
|
-
}
|
|
414
|
-
return blocks;
|
|
415
|
-
}
|
|
416
|
-
async function buildWebchatAssistantMessageFromReplyPayloads(payloads, options) {
|
|
417
|
-
const content = [];
|
|
418
|
-
const transcriptTextParts = [];
|
|
419
|
-
const seenAudio = /* @__PURE__ */ new Set();
|
|
420
|
-
const seenImages = /* @__PURE__ */ new Set();
|
|
421
|
-
let hasAudio = false;
|
|
422
|
-
let hasImage = false;
|
|
423
|
-
for (const payload of payloads) {
|
|
424
|
-
if (payload.isReasoning === true) continue;
|
|
425
|
-
const visibleText = payload.text?.trim();
|
|
426
|
-
const text = visibleText && !isSuppressedControlReplyText(visibleText) ? visibleText : void 0;
|
|
427
|
-
const replyDirectivePrefix = resolveReplyDirectivePrefix(payload);
|
|
428
|
-
let payloadHasAudio = false;
|
|
429
|
-
let payloadHasImage = false;
|
|
430
|
-
const payloadMediaBlocks = [];
|
|
431
|
-
const parts = resolveSendableOutboundReplyParts(payload);
|
|
432
|
-
for (const raw of parts.mediaUrls) {
|
|
433
|
-
const url = raw.trim();
|
|
434
|
-
if (!url) continue;
|
|
435
|
-
const audio = await readLocalAudioContentBlockForEmbedding(payload, url, options);
|
|
436
|
-
if (audio) {
|
|
437
|
-
if (seenAudio.has(audio.path)) continue;
|
|
438
|
-
seenAudio.add(audio.path);
|
|
439
|
-
payloadMediaBlocks.push(audio.block);
|
|
440
|
-
hasAudio = true;
|
|
441
|
-
payloadHasAudio = true;
|
|
442
|
-
continue;
|
|
443
|
-
}
|
|
444
|
-
const imageUrl = resolveEmbeddableImageUrl(url);
|
|
445
|
-
if (!imageUrl || seenImages.has(imageUrl)) continue;
|
|
446
|
-
seenImages.add(imageUrl);
|
|
447
|
-
payloadMediaBlocks.push({
|
|
448
|
-
type: "input_image",
|
|
449
|
-
image_url: imageUrl
|
|
450
|
-
});
|
|
451
|
-
hasImage = true;
|
|
452
|
-
payloadHasImage = true;
|
|
453
|
-
}
|
|
454
|
-
const syntheticText = payloadMediaBlocks.length > 0 && (!text || replyDirectivePrefix) && transcriptTextParts.length === 0 ? payloadHasAudio && payloadHasImage ? "Media reply" : payloadHasAudio ? "Audio reply" : "Image reply" : void 0;
|
|
455
|
-
const blockText = text ?? syntheticText;
|
|
456
|
-
if (blockText) {
|
|
457
|
-
const fullText = replyDirectivePrefix ? `${replyDirectivePrefix}${blockText}` : blockText;
|
|
458
|
-
transcriptTextParts.push(fullText);
|
|
459
|
-
content.push({
|
|
460
|
-
type: "text",
|
|
461
|
-
text: fullText
|
|
462
|
-
});
|
|
463
|
-
} else if (replyDirectivePrefix) {
|
|
464
|
-
transcriptTextParts.push(replyDirectivePrefix);
|
|
465
|
-
content.push({
|
|
466
|
-
type: "text",
|
|
467
|
-
text: replyDirectivePrefix
|
|
468
|
-
});
|
|
469
|
-
}
|
|
470
|
-
content.push(...payloadMediaBlocks);
|
|
471
|
-
}
|
|
472
|
-
if (!hasAudio && !hasImage) return null;
|
|
473
|
-
const transcriptText = transcriptTextParts.join("\n\n").trim() || (hasAudio && hasImage ? "Media reply" : hasAudio ? "Audio reply" : "Image reply");
|
|
474
|
-
if (transcriptTextParts.length === 0) content.unshift({
|
|
475
|
-
type: "text",
|
|
476
|
-
text: transcriptText
|
|
477
|
-
});
|
|
478
|
-
return {
|
|
479
|
-
content,
|
|
480
|
-
transcriptText
|
|
481
|
-
};
|
|
482
|
-
}
|
|
483
|
-
//#endregion
|
|
484
|
-
//#region src/gateway/server-methods/chat.ts
|
|
485
|
-
function normalizeUnknownText(value) {
|
|
486
|
-
return typeof value === "string" ? normalizeOptionalText(value) : void 0;
|
|
487
|
-
}
|
|
488
|
-
/** True when a reply payload carries at least one media reference (mediaUrl or mediaUrls). */
|
|
489
|
-
function isMediaBearingPayload(payload) {
|
|
490
|
-
if (payload.isReasoning === true) return false;
|
|
491
|
-
if (payload.mediaUrl?.trim()) return true;
|
|
492
|
-
if (payload.mediaUrls?.some((url) => url.trim())) return true;
|
|
493
|
-
return false;
|
|
494
|
-
}
|
|
495
|
-
function stripVisibleTextFromTtsSupplement(payload) {
|
|
496
|
-
return isReplyPayloadTtsSupplement(payload) ? buildTtsSupplementMediaPayload(payload) : payload;
|
|
497
|
-
}
|
|
498
|
-
function resolveTtsSupplementMarkerText(text) {
|
|
499
|
-
const trimmed = text.trim();
|
|
500
|
-
const projected = projectChatDisplayMessage({
|
|
501
|
-
role: "assistant",
|
|
502
|
-
content: [{
|
|
503
|
-
type: "text",
|
|
504
|
-
text: trimmed
|
|
505
|
-
}]
|
|
506
|
-
}, { maxChars: Number.MAX_SAFE_INTEGER });
|
|
507
|
-
return extractAssistantDisplayTextFromContent(Array.isArray(projected?.content) ? projected.content : void 0) ?? (typeof projected?.text === "string" ? projected.text.trim() : void 0) ?? trimmed;
|
|
508
|
-
}
|
|
509
|
-
function buildTtsSupplementTranscriptMarker(payload) {
|
|
510
|
-
const supplement = getReplyPayloadTtsSupplement(payload);
|
|
511
|
-
if (!supplement) return;
|
|
512
|
-
const visibleText = resolveTtsSupplementMarkerText(payload.text?.trim() || supplement.spokenText.trim());
|
|
513
|
-
return { textSha256: createHash("sha256").update(visibleText).digest("hex") };
|
|
514
|
-
}
|
|
515
|
-
function buildMediaOnlyTtsSupplementTranscriptMarker(payload) {
|
|
516
|
-
if (payload.text?.trim()) return;
|
|
517
|
-
return buildTtsSupplementTranscriptMarker(payload);
|
|
518
|
-
}
|
|
519
|
-
async function buildWebchatAssistantMediaMessage(payloads, options) {
|
|
520
|
-
return buildWebchatAssistantMessageFromReplyPayloads(payloads, {
|
|
521
|
-
localRoots: options?.localRoots,
|
|
522
|
-
onLocalAudioAccessDenied: (err) => {
|
|
523
|
-
options?.onLocalAudioAccessDenied?.(formatForLog(err));
|
|
524
|
-
}
|
|
525
|
-
});
|
|
526
|
-
}
|
|
527
|
-
const CHAT_HISTORY_MAX_SINGLE_MESSAGE_BYTES = 128 * 1024;
|
|
528
|
-
const CHAT_HISTORY_OVERSIZED_PLACEHOLDER = "[chat.history omitted: message too large]";
|
|
529
|
-
const MANAGED_OUTGOING_IMAGE_PATH_PREFIX = "/api/chat/media/outgoing/";
|
|
530
|
-
let chatHistoryPlaceholderEmitCount = 0;
|
|
531
|
-
const chatHistoryManagedImageCleanupState = /* @__PURE__ */ new Map();
|
|
532
|
-
const CHANNEL_AGNOSTIC_SESSION_SCOPES = new Set([
|
|
533
|
-
"main",
|
|
534
|
-
"direct",
|
|
535
|
-
"dm",
|
|
536
|
-
"group",
|
|
537
|
-
"channel",
|
|
538
|
-
"cron",
|
|
539
|
-
"run",
|
|
540
|
-
"subagent",
|
|
541
|
-
"acp",
|
|
542
|
-
"thread",
|
|
543
|
-
"topic"
|
|
544
|
-
]);
|
|
545
|
-
const CHANNEL_SCOPED_SESSION_SHAPES = new Set([
|
|
546
|
-
"direct",
|
|
547
|
-
"dm",
|
|
548
|
-
"group",
|
|
549
|
-
"channel"
|
|
550
|
-
]);
|
|
551
|
-
const ACTIVE_CHAT_SEND_DEDUPE_PREFIX = "chat:active-send";
|
|
552
|
-
function resolveActiveChatSendRunId(value) {
|
|
553
|
-
if (!value || typeof value !== "object" || Array.isArray(value)) return null;
|
|
554
|
-
const runId = value.runId;
|
|
555
|
-
return typeof runId === "string" && runId.trim() ? runId : null;
|
|
556
|
-
}
|
|
557
|
-
function buildActiveChatSendDedupeKey(params) {
|
|
558
|
-
const message = params.message.trim();
|
|
559
|
-
if (!message || message.startsWith("/") || params.attachmentCount > 0 || params.explicitDeliverRoute || normalizeMessageChannel(params.originatingChannel) !== "webchat") return null;
|
|
560
|
-
return `${ACTIVE_CHAT_SEND_DEDUPE_PREFIX}:${createHash("sha256").update(JSON.stringify([params.sessionKey, message])).digest("hex").slice(0, 32)}`;
|
|
561
|
-
}
|
|
562
|
-
function validateChatSelectedAgent(params) {
|
|
563
|
-
const agentId = params.agentId ? normalizeAgentId(params.agentId) : void 0;
|
|
564
|
-
if (!agentId) return { ok: true };
|
|
565
|
-
if (!listAgentIds(params.cfg).includes(agentId)) return {
|
|
566
|
-
ok: false,
|
|
567
|
-
error: `Unknown agent id "${params.agentId}"`
|
|
568
|
-
};
|
|
569
|
-
const requestedSessionKey = params.requestedSessionKey.trim();
|
|
570
|
-
const parsed = parseAgentSessionKey(requestedSessionKey);
|
|
571
|
-
if (parsed && normalizeAgentId(parsed.agentId) !== agentId) return {
|
|
572
|
-
ok: false,
|
|
573
|
-
error: `agentId "${params.agentId}" does not match session key "${params.requestedSessionKey}"`
|
|
574
|
-
};
|
|
575
|
-
if (requestedSessionKey.toLowerCase() === "global") return {
|
|
576
|
-
ok: true,
|
|
577
|
-
agentId
|
|
578
|
-
};
|
|
579
|
-
if (resolveSessionStoreKey({
|
|
580
|
-
cfg: params.cfg,
|
|
581
|
-
sessionKey: requestedSessionKey
|
|
582
|
-
}) === "global") return {
|
|
583
|
-
ok: true,
|
|
584
|
-
agentId
|
|
585
|
-
};
|
|
586
|
-
if (!parsed || normalizeAgentId(parsed.agentId) !== agentId) return {
|
|
587
|
-
ok: false,
|
|
588
|
-
error: `agentId "${params.agentId}" does not match session key "${params.requestedSessionKey}"`
|
|
589
|
-
};
|
|
590
|
-
return {
|
|
591
|
-
ok: true,
|
|
592
|
-
agentId
|
|
593
|
-
};
|
|
594
|
-
}
|
|
595
|
-
function resolveRequestedChatAgentId(params) {
|
|
596
|
-
const explicitAgentId = normalizeOptionalText(params.agentId);
|
|
597
|
-
if (explicitAgentId) return normalizeAgentId(explicitAgentId);
|
|
598
|
-
if (!params.cfg) return;
|
|
599
|
-
const parsed = parseAgentSessionKey(params.requestedSessionKey.trim());
|
|
600
|
-
if (!parsed?.agentId || resolveSessionStoreKey({
|
|
601
|
-
cfg: params.cfg,
|
|
602
|
-
sessionKey: params.requestedSessionKey
|
|
603
|
-
}) !== "global") return;
|
|
604
|
-
return normalizeAgentId(parsed.agentId);
|
|
605
|
-
}
|
|
606
|
-
function resolveChatSendActiveScopeKey(params) {
|
|
607
|
-
if (params.sessionKey !== "global" || !params.agentId) return params.sessionKey;
|
|
608
|
-
return scopeLegacySessionKeyToAgent({
|
|
609
|
-
agentId: params.agentId,
|
|
610
|
-
sessionKey: params.sessionKey,
|
|
611
|
-
mainKey: params.mainKey
|
|
612
|
-
}) ?? params.sessionKey;
|
|
613
|
-
}
|
|
614
|
-
function formatAttachmentFailureForLog(err) {
|
|
615
|
-
const primary = formatUncaughtError(err);
|
|
616
|
-
const cause = err instanceof Error ? err.cause : void 0;
|
|
617
|
-
if (cause === void 0) return primary;
|
|
618
|
-
const causeText = formatUncaughtError(cause);
|
|
619
|
-
if (!causeText || causeText === primary) return primary;
|
|
620
|
-
return `${primary}\nCaused by: ${causeText}`;
|
|
621
|
-
}
|
|
622
|
-
function logAttachmentFailure(logGateway, label, err) {
|
|
623
|
-
logGateway.error(label, {
|
|
624
|
-
error: formatAttachmentFailureForLog(err),
|
|
625
|
-
consoleMessage: `${label}: ${formatForLog(err)}`
|
|
626
|
-
});
|
|
627
|
-
}
|
|
628
|
-
function buildTranscriptReplyText(payloads) {
|
|
629
|
-
return payloads.map((payload) => {
|
|
630
|
-
if (payload.isReasoning === true) return "";
|
|
631
|
-
const parts = resolveSendableOutboundReplyParts(payload);
|
|
632
|
-
const lines = [];
|
|
633
|
-
const replyToId = sanitizeReplyDirectiveId(payload.replyToId);
|
|
634
|
-
if (replyToId) lines.push(`[[reply_to:${replyToId}]]`);
|
|
635
|
-
else if (payload.replyToCurrent) lines.push("[[reply_to_current]]");
|
|
636
|
-
const text = payload.text?.trim();
|
|
637
|
-
if (text && !isSuppressedControlReplyText(text)) lines.push(text);
|
|
638
|
-
for (const mediaUrl of parts.mediaUrls) {
|
|
639
|
-
if (payload.sensitiveMedia === true) continue;
|
|
640
|
-
const trimmed = mediaUrl.trim();
|
|
641
|
-
if (trimmed) lines.push(`MEDIA:${trimmed}`);
|
|
642
|
-
}
|
|
643
|
-
if (payload.audioAsVoice && parts.mediaUrls.some((mediaUrl) => isAudioFileName(mediaUrl))) lines.push("[[audio_as_voice]]");
|
|
644
|
-
return lines.join("\n").trim();
|
|
645
|
-
}).filter(Boolean).join("\n\n").trim();
|
|
646
|
-
}
|
|
647
|
-
function hasSensitiveMediaPayload(payloads) {
|
|
648
|
-
return payloads.some((payload) => payload.sensitiveMedia === true && isMediaBearingPayload(payload));
|
|
649
|
-
}
|
|
650
|
-
function sanitizeAssistantDisplayText(value) {
|
|
651
|
-
if (!value) return;
|
|
652
|
-
const withoutEnvelope = stripEnvelopeFromMessage(value);
|
|
653
|
-
return stripInlineDirectiveTagsForDisplay(typeof withoutEnvelope === "string" ? withoutEnvelope : value).text.trim() || void 0;
|
|
654
|
-
}
|
|
655
|
-
function extractAssistantDisplayTextFromContent(content) {
|
|
656
|
-
if (!Array.isArray(content) || content.length === 0) return;
|
|
657
|
-
const parts = content.map((block) => {
|
|
658
|
-
if (block?.type !== "text" || typeof block.text !== "string") return "";
|
|
659
|
-
return block.text.trim();
|
|
660
|
-
}).filter(Boolean);
|
|
661
|
-
return parts.length > 0 ? parts.join("\n\n") : void 0;
|
|
662
|
-
}
|
|
663
|
-
async function buildAssistantDisplayContentFromReplyPayloads(params) {
|
|
664
|
-
const rawTextPayloadCount = params.payloads.filter((payload) => payload.isReasoning !== true && typeof payload.text === "string" && payload.text.trim().length > 0).length;
|
|
665
|
-
const normalized = normalizeReplyPayloadsForDelivery(params.payloads);
|
|
666
|
-
if (normalized.length === 0) return rawTextPayloadCount > 0 ? [{
|
|
667
|
-
type: "text",
|
|
668
|
-
text: ""
|
|
669
|
-
}] : void 0;
|
|
670
|
-
const content = [];
|
|
671
|
-
let strippedTextPayloadCount = 0;
|
|
672
|
-
for (const payload of normalized) {
|
|
673
|
-
const text = sanitizeAssistantDisplayText(payload.text);
|
|
674
|
-
if (text) content.push({
|
|
675
|
-
type: "text",
|
|
676
|
-
text
|
|
677
|
-
});
|
|
678
|
-
else if (typeof payload.text === "string" && payload.text.trim().length > 0) strippedTextPayloadCount += 1;
|
|
679
|
-
if (params.includeSensitiveMedia === false && payload.sensitiveMedia === true) continue;
|
|
680
|
-
const audioBlocks = await buildWebchatAudioContentBlocksFromReplyPayloads([payload], {
|
|
681
|
-
localRoots: Array.isArray(params.managedImageLocalRoots) ? params.managedImageLocalRoots : void 0,
|
|
682
|
-
onLocalAudioAccessDenied: (err) => {
|
|
683
|
-
params.onLocalAudioAccessDenied?.(formatForLog(err));
|
|
684
|
-
}
|
|
685
|
-
});
|
|
686
|
-
content.push(...audioBlocks);
|
|
687
|
-
const mediaUrls = Array.from(new Set([...Array.isArray(payload.mediaUrls) ? payload.mediaUrls : [], ...typeof payload.mediaUrl === "string" ? [payload.mediaUrl] : []]));
|
|
688
|
-
const imageBlocks = await createManagedOutgoingImageBlocks({
|
|
689
|
-
sessionKey: params.sessionKey,
|
|
690
|
-
...params.sessionKey === "global" && params.agentId ? { agentId: params.agentId } : {},
|
|
691
|
-
mediaUrls,
|
|
692
|
-
localRoots: params.managedImageLocalRoots,
|
|
693
|
-
continueOnPrepareError: true,
|
|
694
|
-
onPrepareError: (error) => {
|
|
695
|
-
params.onManagedImagePrepareError?.(error.message);
|
|
696
|
-
}
|
|
697
|
-
});
|
|
698
|
-
if (imageBlocks.length > 0) content.push(...imageBlocks);
|
|
699
|
-
}
|
|
700
|
-
if (content.length > 0) return content;
|
|
701
|
-
return strippedTextPayloadCount > 0 ? [{
|
|
702
|
-
type: "text",
|
|
703
|
-
text: ""
|
|
704
|
-
}] : void 0;
|
|
705
|
-
}
|
|
706
|
-
function replaceAssistantContentTextBlocks(content, transcriptMediaMessage) {
|
|
707
|
-
const transcriptTextBlocks = (transcriptMediaMessage?.content ?? []).filter((block) => Boolean(block) && typeof block === "object" && block.type === "text" && typeof block.text === "string");
|
|
708
|
-
if (transcriptTextBlocks.length === 0) return content ? [...content] : void 0;
|
|
709
|
-
if (!content || content.length === 0) return [...transcriptTextBlocks];
|
|
710
|
-
const merged = [];
|
|
711
|
-
let transcriptTextIndex = 0;
|
|
712
|
-
for (const block of content) {
|
|
713
|
-
if (block?.type === "text" && typeof block.text === "string" && transcriptTextIndex < transcriptTextBlocks.length) {
|
|
714
|
-
merged.push(transcriptTextBlocks[transcriptTextIndex++]);
|
|
715
|
-
continue;
|
|
716
|
-
}
|
|
717
|
-
merged.push(block);
|
|
718
|
-
}
|
|
719
|
-
if (transcriptTextIndex < transcriptTextBlocks.length) merged.unshift(...transcriptTextBlocks.slice(transcriptTextIndex));
|
|
720
|
-
return merged;
|
|
721
|
-
}
|
|
722
|
-
function isManagedOutgoingImageUrl(value) {
|
|
723
|
-
if (typeof value !== "string" || !value.trim()) return false;
|
|
724
|
-
try {
|
|
725
|
-
return new URL(value, "http://localhost").pathname.startsWith(MANAGED_OUTGOING_IMAGE_PATH_PREFIX);
|
|
726
|
-
} catch {
|
|
727
|
-
return false;
|
|
728
|
-
}
|
|
729
|
-
}
|
|
730
|
-
function stripManagedOutgoingAssistantContentBlocks(content) {
|
|
731
|
-
if (!content || content.length === 0) return;
|
|
732
|
-
const filtered = content.filter((block) => {
|
|
733
|
-
if (block?.type !== "image") return true;
|
|
734
|
-
return !(isManagedOutgoingImageUrl(block.url) || isManagedOutgoingImageUrl(block.openUrl));
|
|
735
|
-
});
|
|
736
|
-
return filtered.length > 0 ? filtered : void 0;
|
|
737
|
-
}
|
|
738
|
-
function extractAssistantDisplayText(content) {
|
|
739
|
-
if (!content || content.length === 0) return;
|
|
740
|
-
return content.map((block) => block?.type === "text" && typeof block.text === "string" ? block.text : "").filter(Boolean).join("\n\n").trim() || void 0;
|
|
741
|
-
}
|
|
742
|
-
function hasAssistantDisplayMediaContent(content) {
|
|
743
|
-
return Boolean(content?.some((block) => block?.type !== "text"));
|
|
744
|
-
}
|
|
745
|
-
function hasManagedOutgoingAssistantContent(content) {
|
|
746
|
-
return Boolean(content?.some((block) => block?.type === "image" && (isManagedOutgoingImageUrl(block.url) || isManagedOutgoingImageUrl(block.openUrl))));
|
|
747
|
-
}
|
|
748
|
-
function scheduleChatHistoryManagedImageCleanup(params) {
|
|
749
|
-
const cleanupKey = params.sessionKey === "global" && params.agentId ? `agent:${params.agentId}:global` : params.sessionKey;
|
|
750
|
-
if (chatHistoryManagedImageCleanupState.has(cleanupKey)) return;
|
|
751
|
-
const pending = cleanupManagedOutgoingImageRecords({
|
|
752
|
-
sessionKey: params.sessionKey,
|
|
753
|
-
...params.sessionKey === "global" && params.agentId ? { agentId: params.agentId } : {}
|
|
754
|
-
}).then(() => void 0).catch((error) => {
|
|
755
|
-
params.context.logGateway.debug(`chat.history managed image cleanup skipped sessionKey=${JSON.stringify(params.sessionKey)} error=${formatForLog(error)}`);
|
|
756
|
-
}).finally(() => {
|
|
757
|
-
if (chatHistoryManagedImageCleanupState.get(cleanupKey) === pending) chatHistoryManagedImageCleanupState.delete(cleanupKey);
|
|
758
|
-
});
|
|
759
|
-
chatHistoryManagedImageCleanupState.set(cleanupKey, pending);
|
|
760
|
-
}
|
|
761
|
-
function resolveChatSendOriginatingRoute(params) {
|
|
762
|
-
if (params.explicitOrigin?.originatingChannel && params.explicitOrigin.originatingTo) return {
|
|
763
|
-
originatingChannel: params.explicitOrigin.originatingChannel,
|
|
764
|
-
originatingTo: params.explicitOrigin.originatingTo,
|
|
765
|
-
...params.explicitOrigin.accountId ? { accountId: params.explicitOrigin.accountId } : {},
|
|
766
|
-
...params.explicitOrigin.messageThreadId ? { messageThreadId: params.explicitOrigin.messageThreadId } : {},
|
|
767
|
-
explicitDeliverRoute: params.deliver === true
|
|
768
|
-
};
|
|
769
|
-
if (!(params.deliver === true)) return {
|
|
770
|
-
originatingChannel: INTERNAL_MESSAGE_CHANNEL,
|
|
771
|
-
explicitDeliverRoute: false
|
|
772
|
-
};
|
|
773
|
-
const sessionDeliveryContext = deliveryContextFromSession(params.entry);
|
|
774
|
-
const routeChannelCandidate = normalizeMessageChannel(sessionDeliveryContext?.channel ?? params.entry?.lastChannel ?? params.entry?.origin?.provider);
|
|
775
|
-
const routeToCandidate = sessionDeliveryContext?.to ?? params.entry?.lastTo;
|
|
776
|
-
const routeAccountIdCandidate = sessionDeliveryContext?.accountId ?? params.entry?.lastAccountId ?? params.entry?.origin?.accountId ?? void 0;
|
|
777
|
-
const routeThreadIdCandidate = sessionDeliveryContext?.threadId ?? params.entry?.lastThreadId ?? params.entry?.origin?.threadId;
|
|
778
|
-
if (params.sessionKey.length > 512) return {
|
|
779
|
-
originatingChannel: INTERNAL_MESSAGE_CHANNEL,
|
|
780
|
-
explicitDeliverRoute: false
|
|
781
|
-
};
|
|
782
|
-
const sessionScopeParts = (parseAgentSessionKey(params.sessionKey)?.rest ?? params.sessionKey).split(":", 3).filter(Boolean);
|
|
783
|
-
const sessionScopeHead = sessionScopeParts[0];
|
|
784
|
-
const sessionChannelHint = normalizeMessageChannel(sessionScopeHead);
|
|
785
|
-
const normalizedSessionScopeHead = (sessionScopeHead ?? "").trim().toLowerCase();
|
|
786
|
-
const sessionPeerShapeCandidates = [sessionScopeParts[1], sessionScopeParts[2]].map((part) => (part ?? "").trim().toLowerCase()).filter(Boolean);
|
|
787
|
-
const isChannelAgnosticSessionScope = CHANNEL_AGNOSTIC_SESSION_SCOPES.has(normalizedSessionScopeHead);
|
|
788
|
-
const isChannelScopedSession = sessionPeerShapeCandidates.some((part) => CHANNEL_SCOPED_SESSION_SHAPES.has(part));
|
|
789
|
-
const hasLegacyChannelPeerShape = !isChannelScopedSession && typeof sessionScopeParts[1] === "string" && sessionChannelHint === routeChannelCandidate;
|
|
790
|
-
const isFromWebchatClient = isWebchatClient(params.client);
|
|
791
|
-
const isFromGatewayCliClient = isGatewayCliClient(params.client);
|
|
792
|
-
const hasClientMetadata = typeof params.client?.mode === "string" && params.client.mode.trim().length > 0 || typeof params.client?.id === "string" && params.client.id.trim().length > 0;
|
|
793
|
-
const configuredMainKey = (params.mainKey ?? "main").trim().toLowerCase();
|
|
794
|
-
const canInheritConfiguredMainRoute = normalizedSessionScopeHead.length > 0 && normalizedSessionScopeHead === configuredMainKey && params.hasConnectedClient && (isFromGatewayCliClient || !hasClientMetadata);
|
|
795
|
-
if (!(Boolean(!isFromWebchatClient && sessionChannelHint && sessionChannelHint !== "webchat" && (!isChannelAgnosticSessionScope && (isChannelScopedSession || hasLegacyChannelPeerShape) || canInheritConfiguredMainRoute)) && routeChannelCandidate && routeChannelCandidate !== "webchat" && typeof routeToCandidate === "string" && routeToCandidate.trim().length > 0)) return {
|
|
796
|
-
originatingChannel: INTERNAL_MESSAGE_CHANNEL,
|
|
797
|
-
explicitDeliverRoute: false
|
|
798
|
-
};
|
|
799
|
-
return {
|
|
800
|
-
originatingChannel: routeChannelCandidate,
|
|
801
|
-
originatingTo: routeToCandidate,
|
|
802
|
-
accountId: routeAccountIdCandidate,
|
|
803
|
-
messageThreadId: routeThreadIdCandidate,
|
|
804
|
-
explicitDeliverRoute: true
|
|
805
|
-
};
|
|
806
|
-
}
|
|
807
|
-
function isAcpSessionKey(sessionKey) {
|
|
808
|
-
return Boolean(sessionKey?.split(":").includes("acp"));
|
|
809
|
-
}
|
|
810
|
-
function explicitOriginTargetsAcpSession(origin) {
|
|
811
|
-
if (!origin?.originatingChannel || !origin.originatingTo || !origin.accountId) return false;
|
|
812
|
-
const channel = normalizeMessageChannel(origin.originatingChannel);
|
|
813
|
-
if (!channel || channel === "webchat") return false;
|
|
814
|
-
return isAcpSessionKey(getSessionBindingService().resolveByConversation({
|
|
815
|
-
channel,
|
|
816
|
-
accountId: origin.accountId,
|
|
817
|
-
conversationId: origin.originatingTo
|
|
818
|
-
})?.targetSessionKey);
|
|
819
|
-
}
|
|
820
|
-
function explicitOriginTargetsPluginBinding(origin) {
|
|
821
|
-
if (!origin?.originatingChannel || !origin.originatingTo || !origin.accountId) return false;
|
|
822
|
-
const channel = normalizeMessageChannel(origin.originatingChannel);
|
|
823
|
-
if (!channel || channel === "webchat") return false;
|
|
824
|
-
return isPluginOwnedSessionBindingRecord(getSessionBindingService().resolveByConversation({
|
|
825
|
-
channel,
|
|
826
|
-
accountId: origin.accountId,
|
|
827
|
-
conversationId: origin.originatingTo
|
|
828
|
-
}));
|
|
829
|
-
}
|
|
830
|
-
function stripDisallowedChatControlChars(message) {
|
|
831
|
-
let output = "";
|
|
832
|
-
for (const char of message) {
|
|
833
|
-
const code = char.charCodeAt(0);
|
|
834
|
-
if (code === 9 || code === 10 || code === 13 || code >= 32 && code !== 127) output += char;
|
|
835
|
-
}
|
|
836
|
-
return output;
|
|
837
|
-
}
|
|
838
|
-
function sanitizeChatSendMessageInput(message) {
|
|
839
|
-
const normalized = message.normalize("NFC");
|
|
840
|
-
if (normalized.includes("\0")) return {
|
|
841
|
-
ok: false,
|
|
842
|
-
error: "message must not contain null bytes"
|
|
843
|
-
};
|
|
844
|
-
return {
|
|
845
|
-
ok: true,
|
|
846
|
-
message: stripDisallowedChatControlChars(normalized)
|
|
847
|
-
};
|
|
848
|
-
}
|
|
849
|
-
function normalizeOptionalChatSystemReceipt(value) {
|
|
850
|
-
if (value == null) return { ok: true };
|
|
851
|
-
if (typeof value !== "string") return {
|
|
852
|
-
ok: false,
|
|
853
|
-
error: "systemProvenanceReceipt must be a string"
|
|
854
|
-
};
|
|
855
|
-
const sanitized = sanitizeChatSendMessageInput(value);
|
|
856
|
-
if (!sanitized.ok) return sanitized;
|
|
857
|
-
return {
|
|
858
|
-
ok: true,
|
|
859
|
-
receipt: sanitized.message.trim() || void 0
|
|
860
|
-
};
|
|
861
|
-
}
|
|
862
|
-
function isAcpBridgeClient(client) {
|
|
863
|
-
const info = client?.connect?.client;
|
|
864
|
-
return info?.id === GATEWAY_CLIENT_NAMES.CLI && info?.mode === GATEWAY_CLIENT_MODES.CLI && info?.displayName === "ACP" && info?.version === "acp";
|
|
865
|
-
}
|
|
866
|
-
function canInjectSystemProvenance(client) {
|
|
867
|
-
return (Array.isArray(client?.connect?.scopes) ? client.connect.scopes : []).includes(ADMIN_SCOPE);
|
|
868
|
-
}
|
|
869
|
-
async function persistChatSendImages(params) {
|
|
870
|
-
if (params.images.length === 0 && params.offloadedRefs.length === 0 || isAcpBridgeClient(params.client)) return [];
|
|
871
|
-
const inlineSaved = [];
|
|
872
|
-
for (const img of params.images) try {
|
|
873
|
-
inlineSaved.push(await saveMediaBuffer(Buffer.from(img.data, "base64"), img.mimeType, "inbound"));
|
|
874
|
-
} catch (err) {
|
|
875
|
-
params.logGateway.warn(`chat.send: failed to persist inbound image (${img.mimeType}): ${formatForLog(err)}`);
|
|
876
|
-
}
|
|
877
|
-
const imageOffloadedSaved = [];
|
|
878
|
-
const nonImageOffloadedSaved = [];
|
|
879
|
-
for (const ref of params.offloadedRefs) {
|
|
880
|
-
const entry = {
|
|
881
|
-
id: ref.id,
|
|
882
|
-
path: ref.path,
|
|
883
|
-
size: 0,
|
|
884
|
-
contentType: ref.mimeType
|
|
885
|
-
};
|
|
886
|
-
if (ref.mimeType.startsWith("image/")) imageOffloadedSaved.push(entry);
|
|
887
|
-
else nonImageOffloadedSaved.push(entry);
|
|
888
|
-
}
|
|
889
|
-
if (params.imageOrder.length === 0) return [
|
|
890
|
-
...inlineSaved,
|
|
891
|
-
...imageOffloadedSaved,
|
|
892
|
-
...nonImageOffloadedSaved
|
|
893
|
-
];
|
|
894
|
-
const saved = [];
|
|
895
|
-
let inlineIndex = 0;
|
|
896
|
-
let offloadedIndex = 0;
|
|
897
|
-
for (const entry of params.imageOrder) {
|
|
898
|
-
if (entry === "inline") {
|
|
899
|
-
const inline = inlineSaved[inlineIndex++];
|
|
900
|
-
if (inline) saved.push(inline);
|
|
901
|
-
continue;
|
|
902
|
-
}
|
|
903
|
-
const offloaded = imageOffloadedSaved[offloadedIndex++];
|
|
904
|
-
if (offloaded) saved.push(offloaded);
|
|
905
|
-
}
|
|
906
|
-
for (; inlineIndex < inlineSaved.length; inlineIndex++) {
|
|
907
|
-
const inline = inlineSaved[inlineIndex];
|
|
908
|
-
if (inline) saved.push(inline);
|
|
909
|
-
}
|
|
910
|
-
for (; offloadedIndex < imageOffloadedSaved.length; offloadedIndex++) {
|
|
911
|
-
const offloaded = imageOffloadedSaved[offloadedIndex];
|
|
912
|
-
if (offloaded) saved.push(offloaded);
|
|
913
|
-
}
|
|
914
|
-
for (const offloaded of nonImageOffloadedSaved) saved.push(offloaded);
|
|
915
|
-
return saved;
|
|
916
|
-
}
|
|
917
|
-
function stripTrailingOffloadedMediaMarkers(message, refs) {
|
|
918
|
-
if (refs.length === 0) return message;
|
|
919
|
-
const removableRefs = new Set(refs.map((ref) => ref.mediaRef));
|
|
920
|
-
const lines = message.split(/\r?\n/);
|
|
921
|
-
while (lines.length > 0) {
|
|
922
|
-
const last = lines[lines.length - 1]?.trim() ?? "";
|
|
923
|
-
const match = /^\[media attached:\s*(media:\/\/inbound\/[^\]\s]+)\]$/.exec(last);
|
|
924
|
-
if (!match?.[1] || !removableRefs.delete(match[1])) break;
|
|
925
|
-
lines.pop();
|
|
926
|
-
}
|
|
927
|
-
return lines.join("\n").trimEnd();
|
|
928
|
-
}
|
|
929
|
-
async function prestageMediaPathOffloads(params) {
|
|
930
|
-
const mediaPathRefs = params.offloadedRefs.filter((ref) => params.includeImageRefs || !ref.mimeType.startsWith("image/"));
|
|
931
|
-
if (mediaPathRefs.length === 0) return {
|
|
932
|
-
paths: [],
|
|
933
|
-
types: []
|
|
934
|
-
};
|
|
935
|
-
try {
|
|
936
|
-
const workspaceDir = resolveAgentWorkspaceDir(params.cfg, params.agentId);
|
|
937
|
-
const sandbox = await ensureSandboxWorkspaceForSession({
|
|
938
|
-
config: params.cfg,
|
|
939
|
-
sessionKey: params.sessionKey,
|
|
940
|
-
workspaceDir
|
|
941
|
-
});
|
|
942
|
-
if (!sandbox) return {
|
|
943
|
-
paths: mediaPathRefs.map((ref) => ref.path),
|
|
944
|
-
types: mediaPathRefs.map((ref) => ref.mimeType)
|
|
945
|
-
};
|
|
946
|
-
const oversizedForSandbox = mediaPathRefs.filter((ref) => ref.sizeBytes > MEDIA_MAX_BYTES);
|
|
947
|
-
if (oversizedForSandbox.length > 0) throw new UnsupportedAttachmentError("non-image-too-large-for-sandbox", `attachments exceed sandbox staging limit (${MEDIA_MAX_BYTES} bytes): ${oversizedForSandbox.map((ref) => `${ref.label} (${ref.sizeBytes} bytes)`).join(", ")}`);
|
|
948
|
-
const stagingCtx = {
|
|
949
|
-
MediaPath: mediaPathRefs[0].path,
|
|
950
|
-
MediaPaths: mediaPathRefs.map((ref) => ref.path),
|
|
951
|
-
MediaType: mediaPathRefs[0].mimeType,
|
|
952
|
-
MediaTypes: mediaPathRefs.map((ref) => ref.mimeType)
|
|
953
|
-
};
|
|
954
|
-
const stagedSources = (await stageSandboxMedia({
|
|
955
|
-
ctx: stagingCtx,
|
|
956
|
-
sessionCtx: stagingCtx,
|
|
957
|
-
cfg: params.cfg,
|
|
958
|
-
sessionKey: params.sessionKey,
|
|
959
|
-
workspaceDir
|
|
960
|
-
})).staged;
|
|
961
|
-
const missing = mediaPathRefs.filter((ref) => !stagedSources.has(ref.path));
|
|
962
|
-
if (missing.length > 0) throw new Error(`attachment staging incomplete: ${stagedSources.size}/${mediaPathRefs.length} paths staged into sandbox workspace (missing: ${missing.map((ref) => ref.path).join(", ")})`);
|
|
963
|
-
return {
|
|
964
|
-
paths: stagingCtx.MediaPaths ?? [],
|
|
965
|
-
types: stagingCtx.MediaTypes ?? mediaPathRefs.map((ref) => ref.mimeType),
|
|
966
|
-
workspaceDir: sandbox.workspaceDir
|
|
967
|
-
};
|
|
968
|
-
} catch (err) {
|
|
969
|
-
await Promise.allSettled(params.offloadedRefs.map((ref) => deleteMediaBuffer(ref.id, "inbound")));
|
|
970
|
-
if (err instanceof MediaOffloadError) throw err;
|
|
971
|
-
if (err instanceof UnsupportedAttachmentError) throw err;
|
|
972
|
-
throw new MediaOffloadError(`[Gateway Error] Failed to stage attachments into agent workspace: ${formatErrorMessage(err)}`, { cause: err });
|
|
973
|
-
}
|
|
974
|
-
}
|
|
975
|
-
function resolveChatSendManagedMediaFields(savedImages) {
|
|
976
|
-
const mediaPaths = savedImages.map((entry) => entry.path);
|
|
977
|
-
if (mediaPaths.length === 0) return {};
|
|
978
|
-
const mediaTypes = savedImages.map((entry) => entry.contentType ?? "application/octet-stream");
|
|
979
|
-
return {
|
|
980
|
-
MediaPath: mediaPaths[0],
|
|
981
|
-
MediaPaths: mediaPaths,
|
|
982
|
-
MediaType: mediaTypes[0],
|
|
983
|
-
MediaTypes: mediaTypes
|
|
984
|
-
};
|
|
985
|
-
}
|
|
986
|
-
function applyChatSendManagedMediaFields(ctx, fields) {
|
|
987
|
-
if (!ctx.MediaStaged) {
|
|
988
|
-
Object.assign(ctx, fields);
|
|
989
|
-
return;
|
|
990
|
-
}
|
|
991
|
-
if (ctx.MediaPath === void 0 && fields.MediaPath !== void 0) ctx.MediaPath = fields.MediaPath;
|
|
992
|
-
if (ctx.MediaPaths === void 0 && fields.MediaPaths !== void 0) ctx.MediaPaths = fields.MediaPaths;
|
|
993
|
-
if (ctx.MediaType === void 0 && fields.MediaType !== void 0) ctx.MediaType = fields.MediaType;
|
|
994
|
-
if (ctx.MediaTypes === void 0 && fields.MediaTypes !== void 0) ctx.MediaTypes = fields.MediaTypes;
|
|
995
|
-
}
|
|
996
|
-
function buildChatSendUserTurnMedia(savedMedia) {
|
|
997
|
-
return savedMedia.map((entry) => ({
|
|
998
|
-
path: entry.path,
|
|
999
|
-
contentType: entry.contentType
|
|
1000
|
-
}));
|
|
1001
|
-
}
|
|
1002
|
-
function extractChatHistoryBlockText(message) {
|
|
1003
|
-
if (!message || typeof message !== "object") return;
|
|
1004
|
-
const entry = message;
|
|
1005
|
-
if (typeof entry.content === "string") return entry.content;
|
|
1006
|
-
if (typeof entry.text === "string") return entry.text;
|
|
1007
|
-
if (!Array.isArray(entry.content)) return;
|
|
1008
|
-
const textParts = entry.content.map((block) => {
|
|
1009
|
-
if (!block || typeof block !== "object") return;
|
|
1010
|
-
const typed = block;
|
|
1011
|
-
return typeof typed.text === "string" ? typed.text : void 0;
|
|
1012
|
-
}).filter((value) => typeof value === "string");
|
|
1013
|
-
return textParts.length > 0 ? textParts.join("\n") : void 0;
|
|
1014
|
-
}
|
|
1015
|
-
function appendCanvasBlockToAssistantHistoryMessage(params) {
|
|
1016
|
-
const preview = params.preview;
|
|
1017
|
-
if (!preview || !params.message || typeof params.message !== "object") return params.message;
|
|
1018
|
-
const entry = params.message;
|
|
1019
|
-
const baseContent = Array.isArray(entry.content) ? [...entry.content] : typeof entry.content === "string" ? [{
|
|
1020
|
-
type: "text",
|
|
1021
|
-
text: entry.content
|
|
1022
|
-
}] : typeof entry.text === "string" ? [{
|
|
1023
|
-
type: "text",
|
|
1024
|
-
text: entry.text
|
|
1025
|
-
}] : [];
|
|
1026
|
-
if (!baseContent.some((block) => {
|
|
1027
|
-
if (!block || typeof block !== "object") return false;
|
|
1028
|
-
const typed = block;
|
|
1029
|
-
return typed.type === "canvas" && typed.preview && typeof typed.preview === "object" && (typed.preview.viewId && typed.preview.viewId === preview.viewId || typed.preview.url && typed.preview.url === preview.url);
|
|
1030
|
-
})) baseContent.push({
|
|
1031
|
-
type: "canvas",
|
|
1032
|
-
preview,
|
|
1033
|
-
rawText: params.rawText
|
|
1034
|
-
});
|
|
1035
|
-
return {
|
|
1036
|
-
...entry,
|
|
1037
|
-
content: baseContent
|
|
1038
|
-
};
|
|
1039
|
-
}
|
|
1040
|
-
function messageContainsToolHistoryContent(message) {
|
|
1041
|
-
if (!message || typeof message !== "object") return false;
|
|
1042
|
-
const entry = message;
|
|
1043
|
-
if (typeof entry.toolCallId === "string" || typeof entry.tool_call_id === "string" || typeof entry.toolName === "string" || typeof entry.tool_name === "string") return true;
|
|
1044
|
-
if (!Array.isArray(entry.content)) return false;
|
|
1045
|
-
return entry.content.some((block) => {
|
|
1046
|
-
if (!block || typeof block !== "object") return false;
|
|
1047
|
-
return isToolHistoryBlockType(block.type);
|
|
1048
|
-
});
|
|
1049
|
-
}
|
|
1050
|
-
function augmentChatHistoryWithCanvasBlocks(messages) {
|
|
1051
|
-
if (messages.length === 0) return messages;
|
|
1052
|
-
const next = [...messages];
|
|
1053
|
-
let changed = false;
|
|
1054
|
-
let lastAssistantIndex = -1;
|
|
1055
|
-
let lastRenderableAssistantIndex = -1;
|
|
1056
|
-
const pending = [];
|
|
1057
|
-
for (let index = 0; index < next.length; index++) {
|
|
1058
|
-
const message = next[index];
|
|
1059
|
-
if (!message || typeof message !== "object") continue;
|
|
1060
|
-
const entry = message;
|
|
1061
|
-
if ((typeof entry.role === "string" ? entry.role.toLowerCase() : "") === "assistant") {
|
|
1062
|
-
lastAssistantIndex = index;
|
|
1063
|
-
if (!messageContainsToolHistoryContent(entry)) {
|
|
1064
|
-
lastRenderableAssistantIndex = index;
|
|
1065
|
-
if (pending.length > 0) {
|
|
1066
|
-
let target = next[index];
|
|
1067
|
-
for (const item of pending) target = appendCanvasBlockToAssistantHistoryMessage({
|
|
1068
|
-
message: target,
|
|
1069
|
-
preview: item.preview,
|
|
1070
|
-
rawText: item.rawText
|
|
1071
|
-
});
|
|
1072
|
-
next[index] = target;
|
|
1073
|
-
pending.length = 0;
|
|
1074
|
-
changed = true;
|
|
1075
|
-
}
|
|
1076
|
-
}
|
|
1077
|
-
continue;
|
|
1078
|
-
}
|
|
1079
|
-
if (!messageContainsToolHistoryContent(entry)) continue;
|
|
1080
|
-
const toolName = typeof entry.toolName === "string" ? entry.toolName : typeof entry.tool_name === "string" ? entry.tool_name : void 0;
|
|
1081
|
-
const text = extractChatHistoryBlockText(entry);
|
|
1082
|
-
const preview = extractCanvasFromText(text, toolName);
|
|
1083
|
-
if (!preview) continue;
|
|
1084
|
-
pending.push({
|
|
1085
|
-
preview,
|
|
1086
|
-
rawText: text ?? null
|
|
1087
|
-
});
|
|
1088
|
-
}
|
|
1089
|
-
if (pending.length > 0) {
|
|
1090
|
-
const targetIndex = lastRenderableAssistantIndex >= 0 ? lastRenderableAssistantIndex : lastAssistantIndex;
|
|
1091
|
-
if (targetIndex >= 0) {
|
|
1092
|
-
let target = next[targetIndex];
|
|
1093
|
-
for (const item of pending) target = appendCanvasBlockToAssistantHistoryMessage({
|
|
1094
|
-
message: target,
|
|
1095
|
-
preview: item.preview,
|
|
1096
|
-
rawText: item.rawText
|
|
1097
|
-
});
|
|
1098
|
-
next[targetIndex] = target;
|
|
1099
|
-
changed = true;
|
|
1100
|
-
}
|
|
1101
|
-
}
|
|
1102
|
-
return changed ? next : messages;
|
|
1103
|
-
}
|
|
1104
|
-
function buildOversizedHistoryPlaceholder(message) {
|
|
1105
|
-
return {
|
|
1106
|
-
role: message && typeof message === "object" && typeof message.role === "string" ? message.role : "assistant",
|
|
1107
|
-
timestamp: message && typeof message === "object" && typeof message.timestamp === "number" ? message.timestamp : Date.now(),
|
|
1108
|
-
content: [{
|
|
1109
|
-
type: "text",
|
|
1110
|
-
text: CHAT_HISTORY_OVERSIZED_PLACEHOLDER
|
|
1111
|
-
}],
|
|
1112
|
-
__fengming: {
|
|
1113
|
-
truncated: true,
|
|
1114
|
-
reason: "oversized"
|
|
1115
|
-
}
|
|
1116
|
-
};
|
|
1117
|
-
}
|
|
1118
|
-
function replaceOversizedChatHistoryMessages(params) {
|
|
1119
|
-
const { messages, maxSingleMessageBytes } = params;
|
|
1120
|
-
if (messages.length === 0) return {
|
|
1121
|
-
messages,
|
|
1122
|
-
replacedCount: 0
|
|
1123
|
-
};
|
|
1124
|
-
let replacedCount = 0;
|
|
1125
|
-
const next = messages.map((message) => {
|
|
1126
|
-
if (jsonUtf8Bytes(message) <= maxSingleMessageBytes) return message;
|
|
1127
|
-
replacedCount += 1;
|
|
1128
|
-
return buildOversizedHistoryPlaceholder(message);
|
|
1129
|
-
});
|
|
1130
|
-
return {
|
|
1131
|
-
messages: replacedCount > 0 ? next : messages,
|
|
1132
|
-
replacedCount
|
|
1133
|
-
};
|
|
1134
|
-
}
|
|
1135
|
-
function enforceChatHistoryFinalBudget(params) {
|
|
1136
|
-
const { messages, maxBytes } = params;
|
|
1137
|
-
if (messages.length === 0) return {
|
|
1138
|
-
messages,
|
|
1139
|
-
placeholderCount: 0
|
|
1140
|
-
};
|
|
1141
|
-
if (jsonUtf8Bytes(messages) <= maxBytes) return {
|
|
1142
|
-
messages,
|
|
1143
|
-
placeholderCount: 0
|
|
1144
|
-
};
|
|
1145
|
-
const last = messages.at(-1);
|
|
1146
|
-
if (last && jsonUtf8Bytes([last]) <= maxBytes) return {
|
|
1147
|
-
messages: [last],
|
|
1148
|
-
placeholderCount: 0
|
|
1149
|
-
};
|
|
1150
|
-
const placeholder = buildOversizedHistoryPlaceholder(last);
|
|
1151
|
-
if (jsonUtf8Bytes([placeholder]) <= maxBytes) return {
|
|
1152
|
-
messages: [placeholder],
|
|
1153
|
-
placeholderCount: 1
|
|
1154
|
-
};
|
|
1155
|
-
return {
|
|
1156
|
-
messages: [],
|
|
1157
|
-
placeholderCount: 0
|
|
1158
|
-
};
|
|
1159
|
-
}
|
|
1160
|
-
function resolveTranscriptPath(params) {
|
|
1161
|
-
const { sessionId, storePath, sessionFile, agentId } = params;
|
|
1162
|
-
if (!storePath && !sessionFile) return null;
|
|
1163
|
-
try {
|
|
1164
|
-
const sessionsDir = storePath ? path.dirname(storePath) : void 0;
|
|
1165
|
-
return resolveSessionFilePath(sessionId, sessionFile ? { sessionFile } : void 0, sessionsDir || agentId ? {
|
|
1166
|
-
sessionsDir,
|
|
1167
|
-
agentId
|
|
1168
|
-
} : void 0);
|
|
1169
|
-
} catch {
|
|
1170
|
-
return null;
|
|
1171
|
-
}
|
|
1172
|
-
}
|
|
1173
|
-
function ensureTranscriptFile(params) {
|
|
1174
|
-
if (fs.existsSync(params.transcriptPath)) return { ok: true };
|
|
1175
|
-
try {
|
|
1176
|
-
fs.mkdirSync(path.dirname(params.transcriptPath), { recursive: true });
|
|
1177
|
-
const header = {
|
|
1178
|
-
type: "session",
|
|
1179
|
-
version: 3,
|
|
1180
|
-
id: params.sessionId,
|
|
1181
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1182
|
-
cwd: process.cwd()
|
|
1183
|
-
};
|
|
1184
|
-
fs.writeFileSync(params.transcriptPath, `${JSON.stringify(header)}\n`, {
|
|
1185
|
-
encoding: "utf-8",
|
|
1186
|
-
mode: 384
|
|
1187
|
-
});
|
|
1188
|
-
return { ok: true };
|
|
1189
|
-
} catch (err) {
|
|
1190
|
-
return {
|
|
1191
|
-
ok: false,
|
|
1192
|
-
error: err instanceof Error ? err.message : String(err)
|
|
1193
|
-
};
|
|
1194
|
-
}
|
|
1195
|
-
}
|
|
1196
|
-
async function findAssistantTranscriptMessageByIdempotencyKey(transcriptPath, idempotencyKey) {
|
|
1197
|
-
const trimmedIdempotencyKey = idempotencyKey.trim();
|
|
1198
|
-
if (!trimmedIdempotencyKey) return null;
|
|
1199
|
-
const target = (await readSessionTranscriptIndex(transcriptPath))?.entries.toReversed().find((entry) => {
|
|
1200
|
-
const message = entry.record.message;
|
|
1201
|
-
return message?.role === "assistant" && message.idempotencyKey === trimmedIdempotencyKey;
|
|
1202
|
-
});
|
|
1203
|
-
const message = target?.record.message;
|
|
1204
|
-
if (!target || !message) return null;
|
|
1205
|
-
return {
|
|
1206
|
-
messageId: target.id ?? trimmedIdempotencyKey,
|
|
1207
|
-
message
|
|
1208
|
-
};
|
|
1209
|
-
}
|
|
1210
|
-
async function findSourceReplyTranscriptMirrorByIdempotencyKey(transcriptPath, idempotencyKey) {
|
|
1211
|
-
const found = await findAssistantTranscriptMessageByIdempotencyKey(transcriptPath, idempotencyKey);
|
|
1212
|
-
if (found?.message.provider !== "fengming" || found.message.model !== "delivery-mirror") return null;
|
|
1213
|
-
return found;
|
|
1214
|
-
}
|
|
1215
|
-
function extractAssistantTranscriptText(message) {
|
|
1216
|
-
const content = message.content;
|
|
1217
|
-
if (!Array.isArray(content)) return;
|
|
1218
|
-
return content.map((block) => block && typeof block === "object" && block.type === "text" && typeof block.text === "string" ? block.text.trim() ?? "" : "").filter(Boolean).join("\n").trim() || void 0;
|
|
1219
|
-
}
|
|
1220
|
-
async function findSourceReplyTranscriptMirrorByMetadata(params) {
|
|
1221
|
-
const byIdempotencyKey = await findSourceReplyTranscriptMirrorByIdempotencyKey(params.transcriptPath, params.idempotencyKey);
|
|
1222
|
-
if (byIdempotencyKey) return byIdempotencyKey;
|
|
1223
|
-
const expectedText = resolveMirroredTranscriptText({
|
|
1224
|
-
text: params.metadata?.text,
|
|
1225
|
-
mediaUrls: params.metadata?.mediaUrls
|
|
1226
|
-
});
|
|
1227
|
-
if (!expectedText) return null;
|
|
1228
|
-
const target = (await readSessionTranscriptIndex(params.transcriptPath))?.entries.toReversed().find((entry) => {
|
|
1229
|
-
const message = entry.record.message;
|
|
1230
|
-
return typeof entry.id === "string" && entry.id.trim().length > 0 && message?.role === "assistant" && message.provider === "fengming" && message.model === "delivery-mirror" && extractAssistantTranscriptText(message) === expectedText;
|
|
1231
|
-
});
|
|
1232
|
-
const message = target?.record.message;
|
|
1233
|
-
if (!target?.id || !message) return null;
|
|
1234
|
-
return {
|
|
1235
|
-
messageId: target.id,
|
|
1236
|
-
message
|
|
1237
|
-
};
|
|
1238
|
-
}
|
|
1239
|
-
async function appendAssistantTranscriptMessage(params) {
|
|
1240
|
-
const transcriptPath = resolveTranscriptPath({
|
|
1241
|
-
sessionId: params.sessionId,
|
|
1242
|
-
storePath: params.storePath,
|
|
1243
|
-
sessionFile: params.sessionFile,
|
|
1244
|
-
agentId: params.agentId
|
|
1245
|
-
});
|
|
1246
|
-
if (!transcriptPath) return {
|
|
1247
|
-
ok: false,
|
|
1248
|
-
error: "transcript path not resolved"
|
|
1249
|
-
};
|
|
1250
|
-
if (!fs.existsSync(transcriptPath)) {
|
|
1251
|
-
if (!params.createIfMissing) return {
|
|
1252
|
-
ok: false,
|
|
1253
|
-
error: "transcript file not found"
|
|
1254
|
-
};
|
|
1255
|
-
const ensured = ensureTranscriptFile({
|
|
1256
|
-
transcriptPath,
|
|
1257
|
-
sessionId: params.sessionId
|
|
1258
|
-
});
|
|
1259
|
-
if (!ensured.ok) return {
|
|
1260
|
-
ok: false,
|
|
1261
|
-
error: ensured.error ?? "failed to create transcript file"
|
|
1262
|
-
};
|
|
1263
|
-
}
|
|
1264
|
-
if (params.idempotencyKey) {
|
|
1265
|
-
const existing = await findAssistantTranscriptMessageByIdempotencyKey(transcriptPath, params.idempotencyKey);
|
|
1266
|
-
if (existing) return {
|
|
1267
|
-
ok: true,
|
|
1268
|
-
messageId: existing.messageId,
|
|
1269
|
-
message: existing.message
|
|
1270
|
-
};
|
|
1271
|
-
}
|
|
1272
|
-
return await appendInjectedAssistantMessageToTranscript({
|
|
1273
|
-
transcriptPath,
|
|
1274
|
-
sessionKey: params.sessionKey,
|
|
1275
|
-
...params.agentId ? { agentId: params.agentId } : {},
|
|
1276
|
-
message: params.message,
|
|
1277
|
-
label: params.label,
|
|
1278
|
-
content: params.content,
|
|
1279
|
-
idempotencyKey: params.idempotencyKey,
|
|
1280
|
-
abortMeta: params.abortMeta,
|
|
1281
|
-
ttsSupplement: params.ttsSupplement,
|
|
1282
|
-
config: params.cfg
|
|
1283
|
-
});
|
|
1284
|
-
}
|
|
1285
|
-
function collectSessionAbortPartials(params) {
|
|
1286
|
-
const out = [];
|
|
1287
|
-
for (const [runId, active] of params.chatAbortControllers) {
|
|
1288
|
-
if (!params.runIds.has(runId)) continue;
|
|
1289
|
-
const text = params.chatRunBuffers.get(runId);
|
|
1290
|
-
if (!text || !text.trim()) continue;
|
|
1291
|
-
out.push({
|
|
1292
|
-
runId,
|
|
1293
|
-
sessionId: active.sessionId,
|
|
1294
|
-
agentId: active.agentId,
|
|
1295
|
-
text,
|
|
1296
|
-
abortOrigin: params.abortOrigin
|
|
1297
|
-
});
|
|
1298
|
-
}
|
|
1299
|
-
return out;
|
|
1300
|
-
}
|
|
1301
|
-
async function persistAbortedPartials(params) {
|
|
1302
|
-
if (params.snapshots.length === 0) return;
|
|
1303
|
-
for (const snapshot of params.snapshots) {
|
|
1304
|
-
const sessionLoadOptions = params.sessionKey === "global" && snapshot.agentId ? { agentId: snapshot.agentId } : void 0;
|
|
1305
|
-
const { cfg, storePath, entry } = loadSessionEntry(params.sessionKey, sessionLoadOptions);
|
|
1306
|
-
const sessionId = entry?.sessionId ?? snapshot.sessionId ?? snapshot.runId;
|
|
1307
|
-
const appended = await appendAssistantTranscriptMessage({
|
|
1308
|
-
sessionKey: params.sessionKey,
|
|
1309
|
-
message: snapshot.text,
|
|
1310
|
-
sessionId,
|
|
1311
|
-
storePath,
|
|
1312
|
-
sessionFile: entry?.sessionFile,
|
|
1313
|
-
...snapshot.agentId ? { agentId: snapshot.agentId } : {},
|
|
1314
|
-
createIfMissing: true,
|
|
1315
|
-
idempotencyKey: `${snapshot.runId}:assistant`,
|
|
1316
|
-
cfg,
|
|
1317
|
-
abortMeta: {
|
|
1318
|
-
aborted: true,
|
|
1319
|
-
origin: snapshot.abortOrigin,
|
|
1320
|
-
runId: snapshot.runId
|
|
1321
|
-
}
|
|
1322
|
-
});
|
|
1323
|
-
if (!appended.ok) params.context.logGateway.warn(`chat.abort transcript append failed: ${appended.error ?? "unknown error"}`);
|
|
1324
|
-
}
|
|
1325
|
-
}
|
|
1326
|
-
function createChatAbortOps(context) {
|
|
1327
|
-
return {
|
|
1328
|
-
chatAbortControllers: context.chatAbortControllers,
|
|
1329
|
-
chatRunBuffers: context.chatRunBuffers,
|
|
1330
|
-
chatAbortedRuns: context.chatAbortedRuns,
|
|
1331
|
-
clearChatRunState: context.clearChatRunState,
|
|
1332
|
-
removeChatRun: context.removeChatRun,
|
|
1333
|
-
agentRunSeq: context.agentRunSeq,
|
|
1334
|
-
getRuntimeConfig: context.getRuntimeConfig,
|
|
1335
|
-
broadcast: context.broadcast,
|
|
1336
|
-
nodeSendToSession: context.nodeSendToSession
|
|
1337
|
-
};
|
|
1338
|
-
}
|
|
1339
|
-
function normalizeOptionalText(value) {
|
|
1340
|
-
return value?.trim() || void 0;
|
|
1341
|
-
}
|
|
1342
|
-
function normalizeExplicitChatSendOrigin(params) {
|
|
1343
|
-
const originatingChannel = normalizeOptionalText(params.originatingChannel);
|
|
1344
|
-
const originatingTo = normalizeOptionalText(params.originatingTo);
|
|
1345
|
-
const accountId = normalizeOptionalText(params.accountId);
|
|
1346
|
-
const messageThreadId = normalizeOptionalText(params.messageThreadId);
|
|
1347
|
-
if (!Boolean(originatingChannel || originatingTo || accountId || messageThreadId)) return { ok: true };
|
|
1348
|
-
const normalizedChannel = normalizeMessageChannel(originatingChannel);
|
|
1349
|
-
if (!normalizedChannel) return {
|
|
1350
|
-
ok: false,
|
|
1351
|
-
error: "originatingChannel is required when using originating route fields"
|
|
1352
|
-
};
|
|
1353
|
-
if (!originatingTo) return {
|
|
1354
|
-
ok: false,
|
|
1355
|
-
error: "originatingTo is required when using originating route fields"
|
|
1356
|
-
};
|
|
1357
|
-
return {
|
|
1358
|
-
ok: true,
|
|
1359
|
-
value: {
|
|
1360
|
-
originatingChannel: normalizedChannel,
|
|
1361
|
-
originatingTo,
|
|
1362
|
-
...accountId ? { accountId } : {},
|
|
1363
|
-
...messageThreadId ? { messageThreadId } : {}
|
|
1364
|
-
}
|
|
1365
|
-
};
|
|
1366
|
-
}
|
|
1367
|
-
function resolveChatAbortRequester(client) {
|
|
1368
|
-
const scopes = Array.isArray(client?.connect?.scopes) ? client.connect.scopes : [];
|
|
1369
|
-
return {
|
|
1370
|
-
connId: normalizeOptionalText(client?.connId),
|
|
1371
|
-
deviceId: normalizeOptionalText(client?.connect?.device?.id),
|
|
1372
|
-
isAdmin: scopes.includes(ADMIN_SCOPE)
|
|
1373
|
-
};
|
|
1374
|
-
}
|
|
1375
|
-
function canRequesterAbortChatRun(entry, requester) {
|
|
1376
|
-
if (requester.isAdmin) return true;
|
|
1377
|
-
const ownerDeviceId = normalizeOptionalText(entry.ownerDeviceId);
|
|
1378
|
-
const ownerConnId = normalizeOptionalText(entry.ownerConnId);
|
|
1379
|
-
if (!ownerDeviceId && !ownerConnId) return true;
|
|
1380
|
-
if (ownerDeviceId && requester.deviceId && ownerDeviceId === requester.deviceId) return true;
|
|
1381
|
-
if (ownerConnId && requester.connId && ownerConnId === requester.connId) return true;
|
|
1382
|
-
return false;
|
|
1383
|
-
}
|
|
1384
|
-
function canRequesterAbortChatRunWithoutSessionMatch(entry, requester) {
|
|
1385
|
-
if (requester.isAdmin) return true;
|
|
1386
|
-
const ownerDeviceId = normalizeOptionalText(entry.ownerDeviceId);
|
|
1387
|
-
const ownerConnId = normalizeOptionalText(entry.ownerConnId);
|
|
1388
|
-
return Boolean(ownerDeviceId && requester.deviceId && ownerDeviceId === requester.deviceId || ownerConnId && requester.connId && ownerConnId === requester.connId);
|
|
1389
|
-
}
|
|
1390
|
-
function readPreRegisteredAgentDedupePayloadForSession(params) {
|
|
1391
|
-
if (!params.entry?.ok) return;
|
|
1392
|
-
const payload = params.entry.payload;
|
|
1393
|
-
if (payload?.status !== "accepted") return;
|
|
1394
|
-
const payloadRunId = normalizeUnknownText(payload.runId);
|
|
1395
|
-
if (payloadRunId && payloadRunId !== params.runId) return;
|
|
1396
|
-
if (normalizeUnknownText(payload.sessionKey) !== params.sessionKey) return;
|
|
1397
|
-
const agentId = normalizeOptionalText(params.agentId)?.toLowerCase();
|
|
1398
|
-
if (agentId) {
|
|
1399
|
-
const parsed = parseAgentSessionKey(params.sessionKey);
|
|
1400
|
-
const sessionAgentId = params.sessionKey === "global" ? resolveStoredGlobalRunAgentId(normalizeUnknownText(payload.agentId), params.defaultAgentId) : parsed?.agentId ? normalizeAgentId(parsed.agentId) : void 0;
|
|
1401
|
-
if (sessionAgentId && sessionAgentId !== agentId) return;
|
|
1402
|
-
}
|
|
1403
|
-
return payload;
|
|
1404
|
-
}
|
|
1405
|
-
function readPreRegisteredAgentRun(params) {
|
|
1406
|
-
if (!params.key.startsWith("agent:") || !params.entry?.ok) return;
|
|
1407
|
-
const payload = params.entry.payload;
|
|
1408
|
-
if (payload?.status !== "accepted") return;
|
|
1409
|
-
const runId = normalizeUnknownText(payload.runId) ?? normalizeOptionalText(params.key.slice(6));
|
|
1410
|
-
const sessionKey = normalizeUnknownText(payload.sessionKey);
|
|
1411
|
-
if (!runId || !sessionKey) return;
|
|
1412
|
-
return {
|
|
1413
|
-
runId,
|
|
1414
|
-
sessionKey,
|
|
1415
|
-
payload
|
|
1416
|
-
};
|
|
1417
|
-
}
|
|
1418
|
-
function canRequesterAbortPreRegisteredAgentRun(payload, requester) {
|
|
1419
|
-
return canRequesterAbortChatRun({
|
|
1420
|
-
controller: new AbortController(),
|
|
1421
|
-
sessionId: "",
|
|
1422
|
-
sessionKey: normalizeUnknownText(payload.sessionKey) ?? "",
|
|
1423
|
-
startedAtMs: 0,
|
|
1424
|
-
expiresAtMs: 0,
|
|
1425
|
-
ownerConnId: normalizeUnknownText(payload.ownerConnId),
|
|
1426
|
-
ownerDeviceId: normalizeUnknownText(payload.ownerDeviceId),
|
|
1427
|
-
kind: "agent"
|
|
1428
|
-
}, requester);
|
|
1429
|
-
}
|
|
1430
|
-
function resolvePreRegisteredAgentDedupeKeys(payload, runId) {
|
|
1431
|
-
const keys = [`agent:${runId}`];
|
|
1432
|
-
const payloadKeys = Array.isArray(payload.dedupeKeys) ? payload.dedupeKeys : [];
|
|
1433
|
-
for (const key of payloadKeys) {
|
|
1434
|
-
const normalized = normalizeUnknownText(key);
|
|
1435
|
-
if (normalized?.startsWith("agent:")) keys.push(normalized);
|
|
1436
|
-
}
|
|
1437
|
-
return uniqueStrings(keys);
|
|
1438
|
-
}
|
|
1439
|
-
function resolveStoredGlobalRunAgentId(agentId, defaultAgentId) {
|
|
1440
|
-
return normalizeOptionalText(agentId)?.toLowerCase() ?? defaultAgentId.toLowerCase();
|
|
1441
|
-
}
|
|
1442
|
-
function writePreRegisteredAgentAbort(params) {
|
|
1443
|
-
const endedAt = params.endedAt ?? Date.now();
|
|
1444
|
-
const payloadAgentId = normalizeUnknownText(params.payload.agentId);
|
|
1445
|
-
for (const key of resolvePreRegisteredAgentDedupeKeys(params.payload, params.runId)) setGatewayDedupeEntry({
|
|
1446
|
-
dedupe: params.context.dedupe,
|
|
1447
|
-
key,
|
|
1448
|
-
entry: {
|
|
1449
|
-
ts: endedAt,
|
|
1450
|
-
ok: true,
|
|
1451
|
-
payload: {
|
|
1452
|
-
runId: params.runId,
|
|
1453
|
-
sessionKey: params.sessionKey,
|
|
1454
|
-
...payloadAgentId ? { agentId: payloadAgentId } : {},
|
|
1455
|
-
status: "timeout",
|
|
1456
|
-
summary: "aborted",
|
|
1457
|
-
stopReason: params.stopReason,
|
|
1458
|
-
endedAt
|
|
1459
|
-
}
|
|
1460
|
-
}
|
|
1461
|
-
});
|
|
1462
|
-
}
|
|
1463
|
-
function resolveAuthorizedPreRegisteredAgentRunsForSessionKeys(params) {
|
|
1464
|
-
const sessionKeys = new Set(Array.from(params.sessionKeys, (sessionKey) => normalizeOptionalText(sessionKey)).filter((sessionKey) => Boolean(sessionKey)));
|
|
1465
|
-
const authorizedByRunId = /* @__PURE__ */ new Map();
|
|
1466
|
-
let matchedSessionRuns = 0;
|
|
1467
|
-
for (const [key, entry] of params.context.dedupe) {
|
|
1468
|
-
const run = readPreRegisteredAgentRun({
|
|
1469
|
-
key,
|
|
1470
|
-
entry
|
|
1471
|
-
});
|
|
1472
|
-
if (!run || !sessionKeys.has(run.sessionKey)) continue;
|
|
1473
|
-
if (params.context.chatAbortControllers.has(run.runId)) continue;
|
|
1474
|
-
const agentId = normalizeOptionalText(params.agentId)?.toLowerCase();
|
|
1475
|
-
if (agentId && run.sessionKey === "global" && resolveStoredGlobalRunAgentId(normalizeUnknownText(run.payload.agentId), params.defaultAgentId) !== agentId) continue;
|
|
1476
|
-
matchedSessionRuns += 1;
|
|
1477
|
-
if (canRequesterAbortPreRegisteredAgentRun(run.payload, params.requester)) authorizedByRunId.set(run.runId, run);
|
|
1478
|
-
}
|
|
1479
|
-
return {
|
|
1480
|
-
matchedSessionRuns,
|
|
1481
|
-
authorizedRuns: [...authorizedByRunId.values()]
|
|
1482
|
-
};
|
|
1483
|
-
}
|
|
1484
|
-
function resolveAuthorizedRunsForSessionKeys(params) {
|
|
1485
|
-
const sessionKeys = new Set(Array.from(params.sessionKeys, (sessionKey) => normalizeOptionalText(sessionKey)).filter((sessionKey) => Boolean(sessionKey)));
|
|
1486
|
-
const sessionIds = new Set(Array.from(params.sessionIds ?? [], (sessionId) => normalizeOptionalText(sessionId)).filter((sessionId) => Boolean(sessionId)));
|
|
1487
|
-
const agentId = normalizeOptionalText(params.agentId)?.toLowerCase();
|
|
1488
|
-
const authorizedRuns = [];
|
|
1489
|
-
let matchedSessionRuns = 0;
|
|
1490
|
-
for (const [runId, active] of params.chatAbortControllers) {
|
|
1491
|
-
if (!sessionKeys.has(active.sessionKey) && !sessionIds.has(active.sessionId)) continue;
|
|
1492
|
-
if (agentId && active.sessionKey === "global" && resolveStoredGlobalRunAgentId(active.agentId, params.defaultAgentId) !== agentId) continue;
|
|
1493
|
-
matchedSessionRuns += 1;
|
|
1494
|
-
if (canRequesterAbortChatRun(active, params.requester)) authorizedRuns.push({
|
|
1495
|
-
runId,
|
|
1496
|
-
sessionKey: active.sessionKey
|
|
1497
|
-
});
|
|
1498
|
-
}
|
|
1499
|
-
return {
|
|
1500
|
-
matchedSessionRuns,
|
|
1501
|
-
authorizedRuns
|
|
1502
|
-
};
|
|
1503
|
-
}
|
|
1504
|
-
async function abortChatRunsForSessionKeyWithPartials(params) {
|
|
1505
|
-
const sessionKeys = [params.sessionKey, ...params.sessionKeyAliases ?? []];
|
|
1506
|
-
const { matchedSessionRuns, authorizedRuns } = resolveAuthorizedRunsForSessionKeys({
|
|
1507
|
-
chatAbortControllers: params.context.chatAbortControllers,
|
|
1508
|
-
sessionKeys,
|
|
1509
|
-
sessionIds: [params.sessionId],
|
|
1510
|
-
agentId: params.agentId,
|
|
1511
|
-
defaultAgentId: params.defaultAgentId,
|
|
1512
|
-
requester: params.requester
|
|
1513
|
-
});
|
|
1514
|
-
const { matchedSessionRuns: matchedPendingAgentRuns, authorizedRuns: authorizedPendingAgentRuns } = resolveAuthorizedPreRegisteredAgentRunsForSessionKeys({
|
|
1515
|
-
context: params.context,
|
|
1516
|
-
sessionKeys,
|
|
1517
|
-
agentId: params.agentId,
|
|
1518
|
-
defaultAgentId: params.defaultAgentId,
|
|
1519
|
-
requester: params.requester
|
|
1520
|
-
});
|
|
1521
|
-
if (authorizedRuns.length === 0 && authorizedPendingAgentRuns.length === 0) return {
|
|
1522
|
-
aborted: false,
|
|
1523
|
-
runIds: [],
|
|
1524
|
-
unauthorized: matchedSessionRuns > 0 || matchedPendingAgentRuns > 0
|
|
1525
|
-
};
|
|
1526
|
-
const authorizedRunIdSet = new Set(authorizedRuns.map((run) => run.runId));
|
|
1527
|
-
const snapshots = collectSessionAbortPartials({
|
|
1528
|
-
chatAbortControllers: params.context.chatAbortControllers,
|
|
1529
|
-
chatRunBuffers: params.context.chatRunBuffers,
|
|
1530
|
-
runIds: authorizedRunIdSet,
|
|
1531
|
-
abortOrigin: params.abortOrigin
|
|
1532
|
-
});
|
|
1533
|
-
const runIds = [];
|
|
1534
|
-
for (const { runId, sessionKey } of authorizedRuns) if (abortChatRunById(params.ops, {
|
|
1535
|
-
runId,
|
|
1536
|
-
sessionKey,
|
|
1537
|
-
stopReason: params.stopReason
|
|
1538
|
-
}).aborted) runIds.push(runId);
|
|
1539
|
-
const endedAt = Date.now();
|
|
1540
|
-
const stopReason = params.stopReason ?? "rpc";
|
|
1541
|
-
for (const { runId, sessionKey, payload } of authorizedPendingAgentRuns) {
|
|
1542
|
-
writePreRegisteredAgentAbort({
|
|
1543
|
-
context: params.context,
|
|
1544
|
-
runId,
|
|
1545
|
-
sessionKey,
|
|
1546
|
-
payload,
|
|
1547
|
-
stopReason,
|
|
1548
|
-
endedAt
|
|
1549
|
-
});
|
|
1550
|
-
runIds.push(runId);
|
|
1551
|
-
}
|
|
1552
|
-
const res = {
|
|
1553
|
-
aborted: runIds.length > 0,
|
|
1554
|
-
runIds,
|
|
1555
|
-
unauthorized: false
|
|
1556
|
-
};
|
|
1557
|
-
if (res.aborted) await persistAbortedPartials({
|
|
1558
|
-
context: params.context,
|
|
1559
|
-
sessionKey: params.persistSessionKey ?? params.sessionKey,
|
|
1560
|
-
snapshots
|
|
1561
|
-
});
|
|
1562
|
-
return res;
|
|
1563
|
-
}
|
|
1564
|
-
function nextChatSeq(context, runId) {
|
|
1565
|
-
const next = (context.agentRunSeq.get(runId) ?? 0) + 1;
|
|
1566
|
-
context.agentRunSeq.set(runId, next);
|
|
1567
|
-
return next;
|
|
1568
|
-
}
|
|
1569
|
-
function broadcastChatFinal(params) {
|
|
1570
|
-
const seq = nextChatSeq({ agentRunSeq: params.context.agentRunSeq }, params.runId);
|
|
1571
|
-
const payloadAgentId = params.sessionKey === "global" ? params.agentId : void 0;
|
|
1572
|
-
const payload = {
|
|
1573
|
-
runId: params.runId,
|
|
1574
|
-
sessionKey: params.sessionKey,
|
|
1575
|
-
...payloadAgentId ? { agentId: payloadAgentId } : {},
|
|
1576
|
-
seq,
|
|
1577
|
-
state: "final",
|
|
1578
|
-
message: projectChatDisplayMessage(params.message)
|
|
1579
|
-
};
|
|
1580
|
-
params.context.broadcast("chat", payload);
|
|
1581
|
-
sendGlobalAwareNodeChatPayload({
|
|
1582
|
-
context: params.context,
|
|
1583
|
-
sessionKey: params.sessionKey,
|
|
1584
|
-
agentId: payloadAgentId,
|
|
1585
|
-
event: "chat",
|
|
1586
|
-
payload
|
|
1587
|
-
});
|
|
1588
|
-
params.context.agentRunSeq.delete(params.runId);
|
|
1589
|
-
}
|
|
1590
|
-
function isBtwReplyPayload(payload) {
|
|
1591
|
-
return typeof payload?.btw?.question === "string" && payload.btw.question.trim().length > 0 && typeof payload.text === "string" && payload.text.trim().length > 0;
|
|
1592
|
-
}
|
|
1593
|
-
function broadcastSideResult(params) {
|
|
1594
|
-
const seq = nextChatSeq({ agentRunSeq: params.context.agentRunSeq }, params.payload.runId);
|
|
1595
|
-
const payloadAgentId = params.payload.sessionKey === "global" ? params.payload.agentId : void 0;
|
|
1596
|
-
const payload = {
|
|
1597
|
-
...params.payload,
|
|
1598
|
-
...payloadAgentId ? { agentId: payloadAgentId } : {},
|
|
1599
|
-
seq
|
|
1600
|
-
};
|
|
1601
|
-
params.context.broadcast("chat.side_result", payload);
|
|
1602
|
-
sendGlobalAwareNodeChatPayload({
|
|
1603
|
-
context: params.context,
|
|
1604
|
-
sessionKey: params.payload.sessionKey,
|
|
1605
|
-
agentId: payloadAgentId,
|
|
1606
|
-
event: "chat.side_result",
|
|
1607
|
-
payload
|
|
1608
|
-
});
|
|
1609
|
-
}
|
|
1610
|
-
function broadcastChatError(params) {
|
|
1611
|
-
const seq = nextChatSeq({ agentRunSeq: params.context.agentRunSeq }, params.runId);
|
|
1612
|
-
const payloadAgentId = params.sessionKey === "global" ? params.agentId : void 0;
|
|
1613
|
-
const errorText = params.errorMessage?.trim();
|
|
1614
|
-
const payload = {
|
|
1615
|
-
runId: params.runId,
|
|
1616
|
-
sessionKey: params.sessionKey,
|
|
1617
|
-
...payloadAgentId ? { agentId: payloadAgentId } : {},
|
|
1618
|
-
seq,
|
|
1619
|
-
state: "error",
|
|
1620
|
-
errorMessage: params.errorMessage,
|
|
1621
|
-
...errorText ? { message: {
|
|
1622
|
-
role: "assistant",
|
|
1623
|
-
content: [{
|
|
1624
|
-
type: "text",
|
|
1625
|
-
text: errorText.startsWith("⚠️") || errorText.startsWith("Error:") ? errorText : `Error: ${errorText}`
|
|
1626
|
-
}],
|
|
1627
|
-
timestamp: Date.now()
|
|
1628
|
-
} } : {}
|
|
1629
|
-
};
|
|
1630
|
-
params.context.broadcast("chat", payload);
|
|
1631
|
-
sendGlobalAwareNodeChatPayload({
|
|
1632
|
-
context: params.context,
|
|
1633
|
-
sessionKey: params.sessionKey,
|
|
1634
|
-
agentId: payloadAgentId,
|
|
1635
|
-
event: "chat",
|
|
1636
|
-
payload
|
|
1637
|
-
});
|
|
1638
|
-
params.context.agentRunSeq.delete(params.runId);
|
|
1639
|
-
}
|
|
1640
|
-
function sendGlobalAwareNodeChatPayload(params) {
|
|
1641
|
-
const deliveryKeys = resolveGlobalAwareNodeChatDeliveryKeys({
|
|
1642
|
-
cfg: params.context.getRuntimeConfig?.() ?? {},
|
|
1643
|
-
sessionKey: params.sessionKey,
|
|
1644
|
-
agentId: params.agentId
|
|
1645
|
-
});
|
|
1646
|
-
for (const deliveryKey of deliveryKeys) params.context.nodeSendToSession(deliveryKey, params.event, params.payload);
|
|
1647
|
-
}
|
|
1648
|
-
function resolveGlobalAwareNodeChatDeliveryKeys(params) {
|
|
1649
|
-
if (params.sessionKey !== "global") return [params.sessionKey];
|
|
1650
|
-
const defaultAgentId = resolveDefaultAgentId(params.cfg);
|
|
1651
|
-
const scopedAgentId = params.agentId ?? defaultAgentId;
|
|
1652
|
-
const keys = [`agent:${scopedAgentId}:global`];
|
|
1653
|
-
if (scopedAgentId === defaultAgentId) keys.push("global");
|
|
1654
|
-
return keys;
|
|
1655
|
-
}
|
|
1656
|
-
function isSourceReplyTranscriptMirrorPayload(payload) {
|
|
1657
|
-
return Boolean(payload && getReplyPayloadMetadata(payload)?.sourceReplyTranscriptMirror);
|
|
1658
|
-
}
|
|
1659
|
-
function readChatHistoryRecordTimestampMs(message) {
|
|
1660
|
-
const value = asOptionalRecord(asOptionalRecord(message)?.["__fengming"])?.recordTimestampMs;
|
|
1661
|
-
if (typeof value === "number" && Number.isFinite(value)) return value;
|
|
1662
|
-
const timestamp = asOptionalRecord(message)?.timestamp;
|
|
1663
|
-
return typeof timestamp === "number" && Number.isFinite(timestamp) ? timestamp : void 0;
|
|
1664
|
-
}
|
|
1665
|
-
function isSubagentAnnounceInterSessionUserChatHistoryMessage(message) {
|
|
1666
|
-
const record = asOptionalRecord(message);
|
|
1667
|
-
if (!record || record.role !== "user") return false;
|
|
1668
|
-
const provenance = normalizeInputProvenance(record.provenance);
|
|
1669
|
-
if (provenance?.kind === "inter_session" && provenance.sourceTool === "subagent_announce") return true;
|
|
1670
|
-
const text = extractChatHistoryBlockText(record);
|
|
1671
|
-
return typeof text === "string" && text.includes("[Inter-session message]") && text.includes("sourceTool=subagent_announce");
|
|
1672
|
-
}
|
|
1673
|
-
function isChatHistoryAssistantMessage(message) {
|
|
1674
|
-
return asOptionalRecord(message)?.role === "assistant";
|
|
1675
|
-
}
|
|
1676
|
-
function dropPreSessionStartAnnouncePairs(messages, sessionStartedAt) {
|
|
1677
|
-
if (sessionStartedAt === void 0 || messages.length === 0) return messages;
|
|
1678
|
-
let changed = false;
|
|
1679
|
-
const kept = [];
|
|
1680
|
-
for (let i = 0; i < messages.length; i++) {
|
|
1681
|
-
const current = messages[i];
|
|
1682
|
-
if (isSubagentAnnounceInterSessionUserChatHistoryMessage(current)) {
|
|
1683
|
-
const ts = readChatHistoryRecordTimestampMs(current);
|
|
1684
|
-
if (typeof ts === "number" && ts < sessionStartedAt) {
|
|
1685
|
-
const next = messages[i + 1];
|
|
1686
|
-
const nextTs = readChatHistoryRecordTimestampMs(next);
|
|
1687
|
-
if (isChatHistoryAssistantMessage(next) && typeof nextTs === "number" && nextTs < sessionStartedAt) i++;
|
|
1688
|
-
changed = true;
|
|
1689
|
-
continue;
|
|
1690
|
-
}
|
|
1691
|
-
}
|
|
1692
|
-
kept.push(current);
|
|
1693
|
-
}
|
|
1694
|
-
return changed ? kept : messages;
|
|
1695
|
-
}
|
|
1696
|
-
function dropLocalHistoryOverreadContextMessage(messages, contextMessage) {
|
|
1697
|
-
if (contextMessage === void 0) return messages;
|
|
1698
|
-
const index = messages.indexOf(contextMessage);
|
|
1699
|
-
if (index < 0) return messages;
|
|
1700
|
-
return [...messages.slice(0, index), ...messages.slice(index + 1)];
|
|
1701
|
-
}
|
|
1702
|
-
const chatHandlers = {
|
|
1703
|
-
"chat.history": async ({ params, respond, context }) => {
|
|
1704
|
-
if (!validateChatHistoryParams(params)) {
|
|
1705
|
-
respond(false, void 0, errorShape(ErrorCodes.INVALID_REQUEST, `invalid chat.history params: ${formatValidationErrors(validateChatHistoryParams.errors)}`));
|
|
1706
|
-
return;
|
|
1707
|
-
}
|
|
1708
|
-
const { sessionKey, limit, maxChars } = params;
|
|
1709
|
-
const agentIdOverride = normalizeOptionalText(params.agentId);
|
|
1710
|
-
const requestedAgentId = resolveRequestedChatAgentId({
|
|
1711
|
-
cfg: context.getRuntimeConfig?.(),
|
|
1712
|
-
requestedSessionKey: sessionKey,
|
|
1713
|
-
agentId: agentIdOverride
|
|
1714
|
-
});
|
|
1715
|
-
const { cfg, storePath, entry } = loadSessionEntry(sessionKey, requestedAgentId ? { agentId: requestedAgentId } : void 0);
|
|
1716
|
-
const selectedAgent = validateChatSelectedAgent({
|
|
1717
|
-
cfg,
|
|
1718
|
-
requestedSessionKey: sessionKey,
|
|
1719
|
-
agentId: requestedAgentId
|
|
1720
|
-
});
|
|
1721
|
-
if (!selectedAgent.ok) {
|
|
1722
|
-
respond(false, void 0, errorShape(ErrorCodes.INVALID_REQUEST, selectedAgent.error));
|
|
1723
|
-
return;
|
|
1724
|
-
}
|
|
1725
|
-
const sessionId = entry?.sessionId;
|
|
1726
|
-
const sessionAgentId = resolveSessionAgentId({
|
|
1727
|
-
sessionKey,
|
|
1728
|
-
config: cfg,
|
|
1729
|
-
agentId: selectedAgent.agentId
|
|
1730
|
-
});
|
|
1731
|
-
const resolvedSessionModel = resolveSessionModelRef(cfg, entry, sessionAgentId);
|
|
1732
|
-
const max = Math.min(1e3, typeof limit === "number" ? limit : 200);
|
|
1733
|
-
const localReadMax = max > 0 ? max + 1 : 0;
|
|
1734
|
-
const maxHistoryBytes = getMaxChatHistoryMessagesBytes();
|
|
1735
|
-
const localMessages = sessionId && storePath ? await readRecentSessionMessagesAsync(sessionId, storePath, entry?.sessionFile, {
|
|
1736
|
-
maxMessages: localReadMax,
|
|
1737
|
-
maxBytes: Math.max(maxHistoryBytes * 2, 1024 * 1024)
|
|
1738
|
-
}) : [];
|
|
1739
|
-
const overreadContextMessage = localMessages.length > max ? localMessages[0] : void 0;
|
|
1740
|
-
const localMessagesWithBoundaryFilter = dropLocalHistoryOverreadContextMessage(dropPreSessionStartAnnouncePairs(localMessages, typeof entry?.sessionStartedAt === "number" ? entry.sessionStartedAt : void 0), overreadContextMessage);
|
|
1741
|
-
const normalized = augmentChatHistoryWithCanvasBlocks(projectRecentChatDisplayMessages(dropPreSessionStartAnnouncePairs(augmentChatHistoryWithCliSessionImports({
|
|
1742
|
-
entry,
|
|
1743
|
-
provider: resolvedSessionModel.provider,
|
|
1744
|
-
localMessages: localMessagesWithBoundaryFilter
|
|
1745
|
-
}), typeof entry?.sessionStartedAt === "number" ? entry.sessionStartedAt : void 0), {
|
|
1746
|
-
maxChars: resolveEffectiveChatHistoryMaxChars(cfg, maxChars),
|
|
1747
|
-
maxMessages: max
|
|
1748
|
-
}));
|
|
1749
|
-
const replaced = replaceOversizedChatHistoryMessages({
|
|
1750
|
-
messages: normalized,
|
|
1751
|
-
maxSingleMessageBytes: Math.min(CHAT_HISTORY_MAX_SINGLE_MESSAGE_BYTES, maxHistoryBytes)
|
|
1752
|
-
});
|
|
1753
|
-
scheduleChatHistoryManagedImageCleanup({
|
|
1754
|
-
sessionKey,
|
|
1755
|
-
...selectedAgent.agentId ? { agentId: selectedAgent.agentId } : {},
|
|
1756
|
-
context
|
|
1757
|
-
});
|
|
1758
|
-
const capped = capArrayByJsonBytes(replaced.messages, maxHistoryBytes).items;
|
|
1759
|
-
const bounded = enforceChatHistoryFinalBudget({
|
|
1760
|
-
messages: capped,
|
|
1761
|
-
maxBytes: maxHistoryBytes
|
|
1762
|
-
});
|
|
1763
|
-
const placeholderCount = replaced.replacedCount + bounded.placeholderCount;
|
|
1764
|
-
if (placeholderCount > 0) {
|
|
1765
|
-
chatHistoryPlaceholderEmitCount += placeholderCount;
|
|
1766
|
-
logLargePayload({
|
|
1767
|
-
surface: "gateway.chat.history",
|
|
1768
|
-
action: "truncated",
|
|
1769
|
-
bytes: jsonUtf8Bytes(normalized),
|
|
1770
|
-
limitBytes: maxHistoryBytes,
|
|
1771
|
-
count: placeholderCount,
|
|
1772
|
-
reason: "chat_history_budget"
|
|
1773
|
-
});
|
|
1774
|
-
context.logGateway.debug(`chat.history omitted oversized payloads placeholders=${placeholderCount} total=${chatHistoryPlaceholderEmitCount}`);
|
|
1775
|
-
}
|
|
1776
|
-
let thinkingLevel = entry?.thinkingLevel;
|
|
1777
|
-
if (!thinkingLevel) thinkingLevel = resolveGatewaySessionThinkingDefault({
|
|
1778
|
-
cfg,
|
|
1779
|
-
agentId: sessionAgentId,
|
|
1780
|
-
provider: resolvedSessionModel.provider,
|
|
1781
|
-
model: resolvedSessionModel.model
|
|
1782
|
-
});
|
|
1783
|
-
const verboseLevel = entry?.verboseLevel ?? cfg.agents?.defaults?.verboseDefault;
|
|
1784
|
-
respond(true, {
|
|
1785
|
-
sessionKey,
|
|
1786
|
-
sessionId,
|
|
1787
|
-
messages: bounded.messages,
|
|
1788
|
-
thinkingLevel,
|
|
1789
|
-
fastMode: entry?.fastMode,
|
|
1790
|
-
verboseLevel
|
|
1791
|
-
});
|
|
1792
|
-
},
|
|
1793
|
-
"chat.abort": async ({ params, respond, context, client }) => {
|
|
1794
|
-
if (!validateChatAbortParams(params)) {
|
|
1795
|
-
respond(false, void 0, errorShape(ErrorCodes.INVALID_REQUEST, `invalid chat.abort params: ${formatValidationErrors(validateChatAbortParams.errors)}`));
|
|
1796
|
-
return;
|
|
1797
|
-
}
|
|
1798
|
-
const { sessionKey: rawSessionKey, runId } = params;
|
|
1799
|
-
const agentIdOverride = normalizeOptionalText(params.agentId);
|
|
1800
|
-
const abortCfg = context.getRuntimeConfig();
|
|
1801
|
-
const defaultAgentId = resolveDefaultAgentId(abortCfg);
|
|
1802
|
-
const parsedAbortSessionKey = parseAgentSessionKey(rawSessionKey);
|
|
1803
|
-
const abortSessionResolvesGlobal = resolveSessionStoreKey({
|
|
1804
|
-
cfg: abortCfg,
|
|
1805
|
-
sessionKey: rawSessionKey
|
|
1806
|
-
}) === "global";
|
|
1807
|
-
const inferredGlobalAgentId = !agentIdOverride && parsedAbortSessionKey && abortSessionResolvesGlobal ? normalizeAgentId(parsedAbortSessionKey.agentId) : void 0;
|
|
1808
|
-
const abortAgentId = agentIdOverride ?? inferredGlobalAgentId ?? (abortSessionResolvesGlobal ? defaultAgentId : void 0);
|
|
1809
|
-
if (agentIdOverride && parsedAbortSessionKey && normalizeAgentId(parsedAbortSessionKey.agentId) !== normalizeAgentId(agentIdOverride)) {
|
|
1810
|
-
respond(false, void 0, errorShape(ErrorCodes.INVALID_REQUEST, `agentId "${agentIdOverride}" does not match session key "${rawSessionKey}"`));
|
|
1811
|
-
return;
|
|
1812
|
-
}
|
|
1813
|
-
const canonicalAbortSessionKey = abortAgentId && abortSessionResolvesGlobal ? "global" : rawSessionKey;
|
|
1814
|
-
const ops = createChatAbortOps(context);
|
|
1815
|
-
const requester = resolveChatAbortRequester(client);
|
|
1816
|
-
if (!runId) {
|
|
1817
|
-
const res = await abortChatRunsForSessionKeyWithPartials({
|
|
1818
|
-
context,
|
|
1819
|
-
ops,
|
|
1820
|
-
sessionKey: canonicalAbortSessionKey,
|
|
1821
|
-
sessionKeyAliases: canonicalAbortSessionKey === rawSessionKey ? void 0 : [rawSessionKey],
|
|
1822
|
-
agentId: abortAgentId,
|
|
1823
|
-
defaultAgentId,
|
|
1824
|
-
abortOrigin: "rpc",
|
|
1825
|
-
stopReason: "rpc",
|
|
1826
|
-
requester
|
|
1827
|
-
});
|
|
1828
|
-
if (res.unauthorized) {
|
|
1829
|
-
respond(false, void 0, errorShape(ErrorCodes.INVALID_REQUEST, "unauthorized"));
|
|
1830
|
-
return;
|
|
1831
|
-
}
|
|
1832
|
-
respond(true, {
|
|
1833
|
-
ok: true,
|
|
1834
|
-
aborted: res.aborted,
|
|
1835
|
-
runIds: res.runIds
|
|
1836
|
-
});
|
|
1837
|
-
return;
|
|
1838
|
-
}
|
|
1839
|
-
const normalizedAgentIdOverride = abortAgentId?.toLowerCase();
|
|
1840
|
-
const active = context.chatAbortControllers.get(runId);
|
|
1841
|
-
if (!active) {
|
|
1842
|
-
const pendingAgentEntry = context.dedupe.get(`agent:${runId}`);
|
|
1843
|
-
const pendingAgentMatch = (() => {
|
|
1844
|
-
const canonicalMatch = readPreRegisteredAgentDedupePayloadForSession({
|
|
1845
|
-
entry: pendingAgentEntry,
|
|
1846
|
-
runId,
|
|
1847
|
-
sessionKey: canonicalAbortSessionKey,
|
|
1848
|
-
agentId: abortAgentId,
|
|
1849
|
-
defaultAgentId
|
|
1850
|
-
});
|
|
1851
|
-
if (canonicalMatch) return {
|
|
1852
|
-
sessionKey: canonicalAbortSessionKey,
|
|
1853
|
-
payload: canonicalMatch
|
|
1854
|
-
};
|
|
1855
|
-
if (rawSessionKey === canonicalAbortSessionKey) return;
|
|
1856
|
-
const aliasMatch = readPreRegisteredAgentDedupePayloadForSession({
|
|
1857
|
-
entry: pendingAgentEntry,
|
|
1858
|
-
runId,
|
|
1859
|
-
sessionKey: rawSessionKey,
|
|
1860
|
-
agentId: abortAgentId,
|
|
1861
|
-
defaultAgentId
|
|
1862
|
-
});
|
|
1863
|
-
return aliasMatch ? {
|
|
1864
|
-
sessionKey: rawSessionKey,
|
|
1865
|
-
payload: aliasMatch
|
|
1866
|
-
} : void 0;
|
|
1867
|
-
})();
|
|
1868
|
-
if (pendingAgentMatch) {
|
|
1869
|
-
const pendingAgentPayload = pendingAgentMatch.payload;
|
|
1870
|
-
if (!canRequesterAbortPreRegisteredAgentRun(pendingAgentPayload, requester)) {
|
|
1871
|
-
respond(false, void 0, errorShape(ErrorCodes.INVALID_REQUEST, "unauthorized"));
|
|
1872
|
-
return;
|
|
1873
|
-
}
|
|
1874
|
-
writePreRegisteredAgentAbort({
|
|
1875
|
-
context,
|
|
1876
|
-
runId,
|
|
1877
|
-
sessionKey: pendingAgentMatch.sessionKey,
|
|
1878
|
-
payload: pendingAgentPayload,
|
|
1879
|
-
stopReason: "rpc"
|
|
1880
|
-
});
|
|
1881
|
-
respond(true, {
|
|
1882
|
-
ok: true,
|
|
1883
|
-
aborted: true,
|
|
1884
|
-
runIds: [runId]
|
|
1885
|
-
});
|
|
1886
|
-
return;
|
|
1887
|
-
}
|
|
1888
|
-
respond(true, {
|
|
1889
|
-
ok: true,
|
|
1890
|
-
aborted: false,
|
|
1891
|
-
runIds: []
|
|
1892
|
-
});
|
|
1893
|
-
return;
|
|
1894
|
-
}
|
|
1895
|
-
if (!new Set([rawSessionKey, canonicalAbortSessionKey]).has(active.sessionKey) && !canRequesterAbortChatRunWithoutSessionMatch(active, requester)) {
|
|
1896
|
-
respond(false, void 0, errorShape(ErrorCodes.INVALID_REQUEST, "runId does not match sessionKey"));
|
|
1897
|
-
return;
|
|
1898
|
-
}
|
|
1899
|
-
if (normalizedAgentIdOverride && active.sessionKey === "global" && resolveStoredGlobalRunAgentId(active.agentId, defaultAgentId) !== normalizedAgentIdOverride) {
|
|
1900
|
-
respond(false, void 0, errorShape(ErrorCodes.INVALID_REQUEST, "runId does not match agentId"));
|
|
1901
|
-
return;
|
|
1902
|
-
}
|
|
1903
|
-
if (!canRequesterAbortChatRun(active, requester)) {
|
|
1904
|
-
respond(false, void 0, errorShape(ErrorCodes.INVALID_REQUEST, "unauthorized"));
|
|
1905
|
-
return;
|
|
1906
|
-
}
|
|
1907
|
-
const partialText = context.chatRunBuffers.get(runId);
|
|
1908
|
-
const res = abortChatRunById(ops, {
|
|
1909
|
-
runId,
|
|
1910
|
-
sessionKey: active.sessionKey,
|
|
1911
|
-
stopReason: "rpc"
|
|
1912
|
-
});
|
|
1913
|
-
if (res.aborted && partialText && partialText.trim()) await persistAbortedPartials({
|
|
1914
|
-
context,
|
|
1915
|
-
sessionKey: active.sessionKey,
|
|
1916
|
-
snapshots: [{
|
|
1917
|
-
runId,
|
|
1918
|
-
sessionId: active.sessionId,
|
|
1919
|
-
agentId: active.agentId,
|
|
1920
|
-
text: partialText,
|
|
1921
|
-
abortOrigin: "rpc"
|
|
1922
|
-
}]
|
|
1923
|
-
});
|
|
1924
|
-
respond(true, {
|
|
1925
|
-
ok: true,
|
|
1926
|
-
aborted: res.aborted,
|
|
1927
|
-
runIds: res.aborted ? [runId] : []
|
|
1928
|
-
});
|
|
1929
|
-
},
|
|
1930
|
-
"chat.send": async ({ params, respond, context, client }) => {
|
|
1931
|
-
if (!validateChatSendParams(params)) {
|
|
1932
|
-
respond(false, void 0, errorShape(ErrorCodes.INVALID_REQUEST, `invalid chat.send params: ${formatValidationErrors(validateChatSendParams.errors)}`));
|
|
1933
|
-
return;
|
|
1934
|
-
}
|
|
1935
|
-
const p = params;
|
|
1936
|
-
const explicitOriginResult = normalizeExplicitChatSendOrigin({
|
|
1937
|
-
originatingChannel: p.originatingChannel,
|
|
1938
|
-
originatingTo: p.originatingTo,
|
|
1939
|
-
accountId: p.originatingAccountId,
|
|
1940
|
-
messageThreadId: p.originatingThreadId
|
|
1941
|
-
});
|
|
1942
|
-
if (!explicitOriginResult.ok) {
|
|
1943
|
-
respond(false, void 0, errorShape(ErrorCodes.INVALID_REQUEST, explicitOriginResult.error));
|
|
1944
|
-
return;
|
|
1945
|
-
}
|
|
1946
|
-
if ((p.systemInputProvenance || p.systemProvenanceReceipt || explicitOriginResult.value) && !canInjectSystemProvenance(client)) {
|
|
1947
|
-
respond(false, void 0, errorShape(ErrorCodes.INVALID_REQUEST, p.systemInputProvenance || p.systemProvenanceReceipt ? "system provenance fields require admin scope" : "originating route fields require admin scope"));
|
|
1948
|
-
return;
|
|
1949
|
-
}
|
|
1950
|
-
const sanitizedMessageResult = sanitizeChatSendMessageInput(p.message);
|
|
1951
|
-
if (!sanitizedMessageResult.ok) {
|
|
1952
|
-
respond(false, void 0, errorShape(ErrorCodes.INVALID_REQUEST, sanitizedMessageResult.error));
|
|
1953
|
-
return;
|
|
1954
|
-
}
|
|
1955
|
-
const systemReceiptResult = normalizeOptionalChatSystemReceipt(p.systemProvenanceReceipt);
|
|
1956
|
-
if (!systemReceiptResult.ok) {
|
|
1957
|
-
respond(false, void 0, errorShape(ErrorCodes.INVALID_REQUEST, systemReceiptResult.error));
|
|
1958
|
-
return;
|
|
1959
|
-
}
|
|
1960
|
-
const inboundMessage = sanitizedMessageResult.message;
|
|
1961
|
-
const systemInputProvenance = normalizeInputProvenance(p.systemInputProvenance);
|
|
1962
|
-
const systemProvenanceReceipt = systemReceiptResult.receipt;
|
|
1963
|
-
const stopCommand = isChatStopCommandText(inboundMessage);
|
|
1964
|
-
const normalizedAttachments = normalizeRpcAttachmentsToChatAttachments(p.attachments);
|
|
1965
|
-
const rawMessage = inboundMessage.trim();
|
|
1966
|
-
if (!rawMessage && normalizedAttachments.length === 0) {
|
|
1967
|
-
respond(false, void 0, errorShape(ErrorCodes.INVALID_REQUEST, "message or attachment required"));
|
|
1968
|
-
return;
|
|
1969
|
-
}
|
|
1970
|
-
const rawSessionKey = p.sessionKey;
|
|
1971
|
-
const agentIdOverride = normalizeOptionalText(p.agentId);
|
|
1972
|
-
const requestedAgentId = resolveRequestedChatAgentId({
|
|
1973
|
-
cfg: context.getRuntimeConfig?.(),
|
|
1974
|
-
requestedSessionKey: rawSessionKey,
|
|
1975
|
-
agentId: agentIdOverride
|
|
1976
|
-
});
|
|
1977
|
-
const sessionLoadOptions = requestedAgentId ? { agentId: requestedAgentId } : void 0;
|
|
1978
|
-
const { cfg, entry, canonicalKey: sessionKey } = measureDiagnosticsTimelineSpanSync("gateway.chat_send.load_session", () => loadSessionEntry(rawSessionKey, sessionLoadOptions), {
|
|
1979
|
-
phase: "agent-turn",
|
|
1980
|
-
attributes: {
|
|
1981
|
-
hasAttachments: normalizedAttachments.length > 0,
|
|
1982
|
-
hasExplicitOrigin: explicitOriginResult.value !== void 0
|
|
1983
|
-
}
|
|
1984
|
-
});
|
|
1985
|
-
const selectedAgent = validateChatSelectedAgent({
|
|
1986
|
-
cfg,
|
|
1987
|
-
requestedSessionKey: rawSessionKey,
|
|
1988
|
-
agentId: requestedAgentId
|
|
1989
|
-
});
|
|
1990
|
-
if (!selectedAgent.ok) {
|
|
1991
|
-
respond(false, void 0, errorShape(ErrorCodes.INVALID_REQUEST, selectedAgent.error));
|
|
1992
|
-
return;
|
|
1993
|
-
}
|
|
1994
|
-
const requestedSessionId = normalizeOptionalText(p.sessionId);
|
|
1995
|
-
const backingSessionId = entry?.sessionId ?? requestedSessionId;
|
|
1996
|
-
const deletedAgentId = resolveDeletedAgentIdFromSessionKey(cfg, sessionKey);
|
|
1997
|
-
if (deletedAgentId !== null) {
|
|
1998
|
-
respond(false, void 0, errorShape(ErrorCodes.INVALID_REQUEST, `Agent "${deletedAgentId}" no longer exists in configuration`));
|
|
1999
|
-
return;
|
|
2000
|
-
}
|
|
2001
|
-
const agentId = resolveSessionAgentId({
|
|
2002
|
-
sessionKey,
|
|
2003
|
-
config: cfg,
|
|
2004
|
-
agentId: selectedAgent.agentId
|
|
2005
|
-
});
|
|
2006
|
-
const activeRunScopeKey = resolveChatSendActiveScopeKey({
|
|
2007
|
-
sessionKey,
|
|
2008
|
-
agentId: selectedAgent.agentId,
|
|
2009
|
-
mainKey: cfg.session?.mainKey
|
|
2010
|
-
});
|
|
2011
|
-
const resolvedSessionModel = resolveSessionModelRef(cfg, entry, agentId);
|
|
2012
|
-
const resolvedSessionAuthProvider = resolveProviderIdForAuth(resolvedSessionModel.provider, { config: cfg });
|
|
2013
|
-
let parsedMessage = inboundMessage;
|
|
2014
|
-
let parsedImages = [];
|
|
2015
|
-
let imageOrder = [];
|
|
2016
|
-
let offloadedRefs = [];
|
|
2017
|
-
let mediaPathOffloadPaths = [];
|
|
2018
|
-
let mediaPathOffloadTypes = [];
|
|
2019
|
-
let mediaPathOffloadWorkspaceDir;
|
|
2020
|
-
const timeoutMs = resolveAgentTimeoutMs({
|
|
2021
|
-
cfg,
|
|
2022
|
-
overrideMs: p.timeoutMs
|
|
2023
|
-
});
|
|
2024
|
-
const now = Date.now();
|
|
2025
|
-
const clientRunId = p.idempotencyKey;
|
|
2026
|
-
if (resolveSendPolicy({
|
|
2027
|
-
cfg,
|
|
2028
|
-
entry,
|
|
2029
|
-
sessionKey,
|
|
2030
|
-
channel: entry?.channel,
|
|
2031
|
-
chatType: entry?.chatType
|
|
2032
|
-
}) === "deny") {
|
|
2033
|
-
respond(false, void 0, errorShape(ErrorCodes.INVALID_REQUEST, "send blocked by session policy"));
|
|
2034
|
-
return;
|
|
2035
|
-
}
|
|
2036
|
-
if (stopCommand) {
|
|
2037
|
-
const defaultAgentId = resolveDefaultAgentId(cfg);
|
|
2038
|
-
const stopAgentId = sessionKey === "global" ? selectedAgent.agentId ?? defaultAgentId : selectedAgent.agentId;
|
|
2039
|
-
const res = await abortChatRunsForSessionKeyWithPartials({
|
|
2040
|
-
context,
|
|
2041
|
-
ops: createChatAbortOps(context),
|
|
2042
|
-
sessionKey: rawSessionKey,
|
|
2043
|
-
sessionKeyAliases: sessionKey === rawSessionKey ? void 0 : [sessionKey],
|
|
2044
|
-
agentId: stopAgentId,
|
|
2045
|
-
sessionId: entry?.sessionId,
|
|
2046
|
-
persistSessionKey: sessionKey,
|
|
2047
|
-
defaultAgentId,
|
|
2048
|
-
abortOrigin: "stop-command",
|
|
2049
|
-
stopReason: "stop",
|
|
2050
|
-
requester: resolveChatAbortRequester(client)
|
|
2051
|
-
});
|
|
2052
|
-
if (res.unauthorized) {
|
|
2053
|
-
respond(false, void 0, errorShape(ErrorCodes.INVALID_REQUEST, "unauthorized"));
|
|
2054
|
-
return;
|
|
2055
|
-
}
|
|
2056
|
-
respond(true, {
|
|
2057
|
-
ok: true,
|
|
2058
|
-
aborted: res.aborted,
|
|
2059
|
-
runIds: res.runIds
|
|
2060
|
-
});
|
|
2061
|
-
return;
|
|
2062
|
-
}
|
|
2063
|
-
const cached = context.dedupe.get(`chat:${clientRunId}`);
|
|
2064
|
-
if (cached) {
|
|
2065
|
-
respond(cached.ok, cached.payload, cached.error, { cached: true });
|
|
2066
|
-
return;
|
|
2067
|
-
}
|
|
2068
|
-
if (context.chatAbortControllers.get(clientRunId)) {
|
|
2069
|
-
respond(true, {
|
|
2070
|
-
runId: clientRunId,
|
|
2071
|
-
status: "in_flight"
|
|
2072
|
-
}, void 0, {
|
|
2073
|
-
cached: true,
|
|
2074
|
-
runId: clientRunId
|
|
2075
|
-
});
|
|
2076
|
-
return;
|
|
2077
|
-
}
|
|
2078
|
-
const clientInfo = client?.connect?.client;
|
|
2079
|
-
const originatingRoute = resolveChatSendOriginatingRoute({
|
|
2080
|
-
client: clientInfo,
|
|
2081
|
-
deliver: p.deliver,
|
|
2082
|
-
entry,
|
|
2083
|
-
explicitOrigin: explicitOriginResult.value,
|
|
2084
|
-
hasConnectedClient: client?.connect !== void 0,
|
|
2085
|
-
mainKey: cfg.session?.mainKey,
|
|
2086
|
-
sessionKey
|
|
2087
|
-
});
|
|
2088
|
-
const activeChatSendDedupeKey = buildActiveChatSendDedupeKey({
|
|
2089
|
-
attachmentCount: normalizedAttachments.length,
|
|
2090
|
-
explicitDeliverRoute: originatingRoute.explicitDeliverRoute,
|
|
2091
|
-
message: rawMessage,
|
|
2092
|
-
originatingChannel: originatingRoute.originatingChannel,
|
|
2093
|
-
sessionKey: activeRunScopeKey
|
|
2094
|
-
});
|
|
2095
|
-
if (activeChatSendDedupeKey) {
|
|
2096
|
-
const activeRunId = resolveActiveChatSendRunId(context.dedupe.get(activeChatSendDedupeKey)?.payload);
|
|
2097
|
-
if (activeRunId && context.chatAbortControllers.has(activeRunId)) {
|
|
2098
|
-
respond(true, {
|
|
2099
|
-
runId: activeRunId,
|
|
2100
|
-
status: "in_flight"
|
|
2101
|
-
}, void 0, {
|
|
2102
|
-
cached: true,
|
|
2103
|
-
runId: activeRunId
|
|
2104
|
-
});
|
|
2105
|
-
return;
|
|
2106
|
-
}
|
|
2107
|
-
}
|
|
2108
|
-
const explicitOriginTargetsPlugin = explicitOriginTargetsPluginBinding(explicitOriginResult.value);
|
|
2109
|
-
if (normalizedAttachments.length > 0) try {
|
|
2110
|
-
await measureDiagnosticsTimelineSpan("gateway.chat_send.prepare_attachments", async () => {
|
|
2111
|
-
const supportsSessionModelImages = await resolveGatewayModelSupportsImages({
|
|
2112
|
-
loadGatewayModelCatalog: context.loadGatewayModelCatalog,
|
|
2113
|
-
provider: resolvedSessionModel.provider,
|
|
2114
|
-
model: resolvedSessionModel.model
|
|
2115
|
-
});
|
|
2116
|
-
const explicitOriginSupportsInlineImages = explicitOriginTargetsAcpSession(explicitOriginResult.value) || explicitOriginTargetsPlugin;
|
|
2117
|
-
const supportsImages = supportsSessionModelImages || explicitOriginSupportsInlineImages;
|
|
2118
|
-
const routeImageOffloadsAsMediaPaths = !supportsImages;
|
|
2119
|
-
const parsed = await parseMessageWithAttachments(inboundMessage, normalizedAttachments, {
|
|
2120
|
-
maxBytes: resolveChatAttachmentMaxBytes(cfg),
|
|
2121
|
-
log: context.logGateway,
|
|
2122
|
-
supportsImages,
|
|
2123
|
-
acceptNonImage: true
|
|
2124
|
-
});
|
|
2125
|
-
parsedMessage = stripTrailingOffloadedMediaMarkers(parsed.message, routeImageOffloadsAsMediaPaths ? parsed.offloadedRefs.filter((ref) => ref.mimeType.startsWith("image/")) : []);
|
|
2126
|
-
parsedImages = parsed.images;
|
|
2127
|
-
imageOrder = routeImageOffloadsAsMediaPaths ? [] : parsed.imageOrder;
|
|
2128
|
-
offloadedRefs = parsed.offloadedRefs;
|
|
2129
|
-
({paths: mediaPathOffloadPaths, types: mediaPathOffloadTypes, workspaceDir: mediaPathOffloadWorkspaceDir} = await prestageMediaPathOffloads({
|
|
2130
|
-
offloadedRefs,
|
|
2131
|
-
includeImageRefs: routeImageOffloadsAsMediaPaths,
|
|
2132
|
-
cfg,
|
|
2133
|
-
sessionKey,
|
|
2134
|
-
agentId
|
|
2135
|
-
}));
|
|
2136
|
-
}, {
|
|
2137
|
-
phase: "agent-turn",
|
|
2138
|
-
config: cfg,
|
|
2139
|
-
attributes: {
|
|
2140
|
-
attachmentCount: normalizedAttachments.length,
|
|
2141
|
-
hasExplicitOrigin: explicitOriginResult.value !== void 0
|
|
2142
|
-
}
|
|
2143
|
-
});
|
|
2144
|
-
} catch (err) {
|
|
2145
|
-
logAttachmentFailure(context.logGateway, "chat.send attachment parse/stage failed", err);
|
|
2146
|
-
respond(false, void 0, errorShape(err instanceof MediaOffloadError ? ErrorCodes.UNAVAILABLE : ErrorCodes.INVALID_REQUEST, String(err)));
|
|
2147
|
-
return;
|
|
2148
|
-
}
|
|
2149
|
-
try {
|
|
2150
|
-
const activeRunAbort = registerChatAbortController({
|
|
2151
|
-
chatAbortControllers: context.chatAbortControllers,
|
|
2152
|
-
runId: clientRunId,
|
|
2153
|
-
sessionId: backingSessionId ?? clientRunId,
|
|
2154
|
-
sessionKey,
|
|
2155
|
-
agentId: selectedAgent.agentId,
|
|
2156
|
-
timeoutMs,
|
|
2157
|
-
now,
|
|
2158
|
-
ownerConnId: normalizeOptionalText(client?.connId),
|
|
2159
|
-
ownerDeviceId: normalizeOptionalText(client?.connect?.device?.id),
|
|
2160
|
-
providerId: resolvedSessionModel.provider,
|
|
2161
|
-
authProviderId: resolvedSessionAuthProvider,
|
|
2162
|
-
kind: "chat-send"
|
|
2163
|
-
});
|
|
2164
|
-
if (!activeRunAbort.registered) {
|
|
2165
|
-
respond(true, {
|
|
2166
|
-
runId: clientRunId,
|
|
2167
|
-
status: "in_flight"
|
|
2168
|
-
}, void 0, {
|
|
2169
|
-
cached: true,
|
|
2170
|
-
runId: clientRunId
|
|
2171
|
-
});
|
|
2172
|
-
return;
|
|
2173
|
-
}
|
|
2174
|
-
if (activeChatSendDedupeKey) context.dedupe.set(activeChatSendDedupeKey, {
|
|
2175
|
-
ts: now,
|
|
2176
|
-
ok: true,
|
|
2177
|
-
payload: { runId: clientRunId }
|
|
2178
|
-
});
|
|
2179
|
-
context.addChatRun(clientRunId, {
|
|
2180
|
-
sessionKey,
|
|
2181
|
-
agentId: selectedAgent.agentId,
|
|
2182
|
-
clientRunId
|
|
2183
|
-
});
|
|
2184
|
-
respond(true, {
|
|
2185
|
-
runId: clientRunId,
|
|
2186
|
-
status: "started"
|
|
2187
|
-
}, void 0, { runId: clientRunId });
|
|
2188
|
-
const persistedImagesPromise = persistChatSendImages({
|
|
2189
|
-
images: parsedImages,
|
|
2190
|
-
imageOrder,
|
|
2191
|
-
offloadedRefs,
|
|
2192
|
-
client,
|
|
2193
|
-
logGateway: context.logGateway
|
|
2194
|
-
});
|
|
2195
|
-
let persistedMediaForTranscript;
|
|
2196
|
-
const getPersistedMediaForTranscript = async () => {
|
|
2197
|
-
if (!persistedMediaForTranscript) persistedMediaForTranscript = await persistedImagesPromise;
|
|
2198
|
-
return persistedMediaForTranscript;
|
|
2199
|
-
};
|
|
2200
|
-
const preparedUserTurnMediaPromise = normalizedAttachments.length > 0 ? getPersistedMediaForTranscript() : Promise.resolve([]);
|
|
2201
|
-
const userTurnMediaPromise = preparedUserTurnMediaPromise.then(buildChatSendUserTurnMedia);
|
|
2202
|
-
const baseUserTurnInput = {
|
|
2203
|
-
text: rawMessage,
|
|
2204
|
-
timestamp: now,
|
|
2205
|
-
idempotencyKey: `${clientRunId}:user`,
|
|
2206
|
-
...systemInputProvenance ? { provenance: systemInputProvenance } : {}
|
|
2207
|
-
};
|
|
2208
|
-
const userTurnInputPromise = userTurnMediaPromise.then((media) => ({
|
|
2209
|
-
...baseUserTurnInput,
|
|
2210
|
-
...media.length > 0 ? {
|
|
2211
|
-
media,
|
|
2212
|
-
mediaOnlyText: "[User sent media without caption]"
|
|
2213
|
-
} : {}
|
|
2214
|
-
}));
|
|
2215
|
-
const pluginBoundMediaFieldsPromise = explicitOriginTargetsPlugin && parsedImages.length > 0 ? preparedUserTurnMediaPromise.then(resolveChatSendManagedMediaFields) : Promise.resolve({});
|
|
2216
|
-
const trimmedMessage = parsedMessage.trim();
|
|
2217
|
-
const commandBody = Boolean(p.thinking && trimmedMessage && !trimmedMessage.startsWith("/")) ? `/think ${p.thinking} ${parsedMessage}` : parsedMessage;
|
|
2218
|
-
const commandSource = trimmedMessage.startsWith("/") ? "text" : void 0;
|
|
2219
|
-
const messageForAgent = systemProvenanceReceipt ? [systemProvenanceReceipt, parsedMessage].filter(Boolean).join("\n\n") : parsedMessage;
|
|
2220
|
-
const { originatingChannel, originatingTo, accountId, messageThreadId, explicitDeliverRoute } = originatingRoute;
|
|
2221
|
-
const ctx = {
|
|
2222
|
-
Body: messageForAgent,
|
|
2223
|
-
BodyForAgent: injectTimestamp(messageForAgent, timestampOptsFromConfig(cfg)),
|
|
2224
|
-
BodyForCommands: commandBody,
|
|
2225
|
-
RawBody: parsedMessage,
|
|
2226
|
-
CommandBody: commandBody,
|
|
2227
|
-
InputProvenance: systemInputProvenance,
|
|
2228
|
-
SessionKey: sessionKey,
|
|
2229
|
-
AgentId: agentId,
|
|
2230
|
-
Provider: INTERNAL_MESSAGE_CHANNEL,
|
|
2231
|
-
Surface: INTERNAL_MESSAGE_CHANNEL,
|
|
2232
|
-
OriginatingChannel: originatingChannel,
|
|
2233
|
-
OriginatingTo: originatingTo,
|
|
2234
|
-
ExplicitDeliverRoute: explicitDeliverRoute,
|
|
2235
|
-
AccountId: accountId,
|
|
2236
|
-
MessageThreadId: messageThreadId,
|
|
2237
|
-
ChatType: "direct",
|
|
2238
|
-
...commandSource ? { CommandSource: commandSource } : {},
|
|
2239
|
-
CommandAuthorized: true,
|
|
2240
|
-
CommandTurn: commandSource ? {
|
|
2241
|
-
kind: "text-slash",
|
|
2242
|
-
source: commandSource,
|
|
2243
|
-
authorized: true,
|
|
2244
|
-
body: commandBody
|
|
2245
|
-
} : {
|
|
2246
|
-
kind: "normal",
|
|
2247
|
-
source: "message",
|
|
2248
|
-
authorized: false,
|
|
2249
|
-
body: commandBody
|
|
2250
|
-
},
|
|
2251
|
-
MessageSid: clientRunId,
|
|
2252
|
-
...!isOperatorUiClient(clientInfo) ? {
|
|
2253
|
-
SenderId: clientInfo?.id,
|
|
2254
|
-
SenderName: clientInfo?.displayName,
|
|
2255
|
-
SenderUsername: clientInfo?.displayName
|
|
2256
|
-
} : {},
|
|
2257
|
-
GatewayClientScopes: client?.connect?.scopes ?? []
|
|
2258
|
-
};
|
|
2259
|
-
if (mediaPathOffloadPaths.length > 0) {
|
|
2260
|
-
ctx.MediaPath = mediaPathOffloadPaths[0];
|
|
2261
|
-
ctx.MediaPaths = mediaPathOffloadPaths;
|
|
2262
|
-
ctx.MediaType = mediaPathOffloadTypes[0];
|
|
2263
|
-
ctx.MediaTypes = mediaPathOffloadTypes;
|
|
2264
|
-
ctx.MediaWorkspaceDir = mediaPathOffloadWorkspaceDir;
|
|
2265
|
-
ctx.MediaStaged = true;
|
|
2266
|
-
}
|
|
2267
|
-
const replyOptionImages = mediaPathOffloadTypes.some((type) => type.startsWith("image/")) ? void 0 : parsedImages.length > 0 ? parsedImages : void 0;
|
|
2268
|
-
const { onModelSelected, ...replyPipeline } = createChannelReplyPipeline({
|
|
2269
|
-
cfg,
|
|
2270
|
-
agentId,
|
|
2271
|
-
channel: INTERNAL_MESSAGE_CHANNEL
|
|
2272
|
-
});
|
|
2273
|
-
const chatSendTraceAttributes = {
|
|
2274
|
-
hasAttachments: normalizedAttachments.length > 0,
|
|
2275
|
-
hasExplicitOrigin: explicitOriginResult.value !== void 0,
|
|
2276
|
-
hasConnectedClient: client?.connect !== void 0
|
|
2277
|
-
};
|
|
2278
|
-
const deliveredReplies = [];
|
|
2279
|
-
let appendedWebchatAgentMedia = false;
|
|
2280
|
-
let agentRunStarted = false;
|
|
2281
|
-
const userTurnRecorder = createUserTurnTranscriptRecorder({
|
|
2282
|
-
input: baseUserTurnInput,
|
|
2283
|
-
resolveInput: () => userTurnInputPromise,
|
|
2284
|
-
target: () => {
|
|
2285
|
-
const { storePath: latestStorePath, entry: latestEntry } = loadSessionEntry(sessionKey, sessionLoadOptions);
|
|
2286
|
-
const resolvedSessionId = latestEntry?.sessionId ?? backingSessionId;
|
|
2287
|
-
if (!resolvedSessionId) return;
|
|
2288
|
-
return {
|
|
2289
|
-
sessionId: resolvedSessionId,
|
|
2290
|
-
sessionKey,
|
|
2291
|
-
sessionEntry: latestEntry ?? entry,
|
|
2292
|
-
storePath: latestStorePath,
|
|
2293
|
-
agentId,
|
|
2294
|
-
config: cfg
|
|
2295
|
-
};
|
|
2296
|
-
},
|
|
2297
|
-
errorContext: "gateway chat user turn transcript",
|
|
2298
|
-
beforeMessageWrite: runAgentHarnessBeforeMessageWriteHook,
|
|
2299
|
-
onPersistenceError: (error) => {
|
|
2300
|
-
context.logGateway.warn(`gateway user transcript persistence failed: ${formatForLog(error)}`);
|
|
2301
|
-
}
|
|
2302
|
-
});
|
|
2303
|
-
const persistGatewayUserTurnTranscript = async () => {
|
|
2304
|
-
await measureDiagnosticsTimelineSpan("gateway.chat_send.persist_user_transcript", async () => {
|
|
2305
|
-
await userTurnRecorder.persistFallback();
|
|
2306
|
-
}, {
|
|
2307
|
-
phase: "agent-turn",
|
|
2308
|
-
config: cfg,
|
|
2309
|
-
attributes: chatSendTraceAttributes
|
|
2310
|
-
});
|
|
2311
|
-
};
|
|
2312
|
-
const persistGatewayUserTurnTranscriptBestEffort = async () => {
|
|
2313
|
-
await persistGatewayUserTurnTranscript().catch(() => void 0);
|
|
2314
|
-
};
|
|
2315
|
-
const appendWebchatAgentMediaTranscriptIfNeeded = async (payload) => {
|
|
2316
|
-
if (!agentRunStarted || appendedWebchatAgentMedia || !isMediaBearingPayload(payload)) return;
|
|
2317
|
-
if (isSourceReplyTranscriptMirrorPayload(payload)) return;
|
|
2318
|
-
const ttsSupplementMarker = buildTtsSupplementTranscriptMarker(payload);
|
|
2319
|
-
const [transcriptPayload] = await normalizeWebchatReplyMediaPathsForDisplay({
|
|
2320
|
-
cfg,
|
|
2321
|
-
sessionKey,
|
|
2322
|
-
agentId,
|
|
2323
|
-
accountId,
|
|
2324
|
-
payloads: [stripVisibleTextFromTtsSupplement(payload)]
|
|
2325
|
-
});
|
|
2326
|
-
if (!transcriptPayload) return;
|
|
2327
|
-
const { storePath: latestStorePath, entry: latestEntry } = loadSessionEntry(sessionKey, sessionLoadOptions);
|
|
2328
|
-
const sessionId = latestEntry?.sessionId ?? backingSessionId ?? clientRunId;
|
|
2329
|
-
const resolvedTranscriptPath = resolveTranscriptPath({
|
|
2330
|
-
sessionId,
|
|
2331
|
-
storePath: latestStorePath,
|
|
2332
|
-
sessionFile: latestEntry?.sessionFile ?? entry?.sessionFile,
|
|
2333
|
-
agentId
|
|
2334
|
-
});
|
|
2335
|
-
const mediaLocalRoots = appendLocalMediaParentRoots(getAgentScopedMediaLocalRoots(cfg, agentId), resolvedTranscriptPath ? [resolvedTranscriptPath] : void 0);
|
|
2336
|
-
const assistantContent = await buildAssistantDisplayContentFromReplyPayloads({
|
|
2337
|
-
sessionKey,
|
|
2338
|
-
agentId,
|
|
2339
|
-
payloads: [transcriptPayload],
|
|
2340
|
-
managedImageLocalRoots: mediaLocalRoots,
|
|
2341
|
-
includeSensitiveMedia: transcriptPayload.sensitiveMedia !== true,
|
|
2342
|
-
onLocalAudioAccessDenied: (message) => {
|
|
2343
|
-
context.logGateway.warn(`webchat audio embedding denied local path: ${message}`);
|
|
2344
|
-
},
|
|
2345
|
-
onManagedImagePrepareError: (message) => {
|
|
2346
|
-
context.logGateway.warn(`webchat image embedding skipped attachment: ${message}`);
|
|
2347
|
-
}
|
|
2348
|
-
});
|
|
2349
|
-
const mediaMessage = await buildWebchatAssistantMediaMessage([transcriptPayload], {
|
|
2350
|
-
localRoots: mediaLocalRoots,
|
|
2351
|
-
onLocalAudioAccessDenied: (message) => {
|
|
2352
|
-
context.logGateway.warn(`webchat audio embedding denied local path: ${message}`);
|
|
2353
|
-
}
|
|
2354
|
-
});
|
|
2355
|
-
const persistedAssistantContent = replaceAssistantContentTextBlocks(assistantContent, mediaMessage);
|
|
2356
|
-
const persistedContentForAppend = hasAssistantDisplayMediaContent(persistedAssistantContent) ? persistedAssistantContent : void 0;
|
|
2357
|
-
if (!persistedContentForAppend?.length) return;
|
|
2358
|
-
const transcriptReply = mediaMessage?.transcriptText ?? extractAssistantDisplayTextFromContent(assistantContent) ?? buildTranscriptReplyText([transcriptPayload]);
|
|
2359
|
-
if (!transcriptReply && !persistedAssistantContent?.length && !assistantContent?.length) return;
|
|
2360
|
-
const appended = await appendAssistantTranscriptMessage({
|
|
2361
|
-
sessionKey,
|
|
2362
|
-
message: transcriptReply,
|
|
2363
|
-
...persistedContentForAppend?.length ? { content: persistedContentForAppend } : {},
|
|
2364
|
-
sessionId,
|
|
2365
|
-
storePath: latestStorePath,
|
|
2366
|
-
sessionFile: latestEntry?.sessionFile,
|
|
2367
|
-
agentId,
|
|
2368
|
-
createIfMissing: true,
|
|
2369
|
-
idempotencyKey: `${clientRunId}:assistant-media`,
|
|
2370
|
-
ttsSupplement: ttsSupplementMarker,
|
|
2371
|
-
cfg
|
|
2372
|
-
});
|
|
2373
|
-
if (appended.ok) {
|
|
2374
|
-
if (appended.messageId && assistantContent?.length) await attachManagedOutgoingImagesToMessage({
|
|
2375
|
-
messageId: appended.messageId,
|
|
2376
|
-
blocks: assistantContent
|
|
2377
|
-
});
|
|
2378
|
-
appendedWebchatAgentMedia = true;
|
|
2379
|
-
return;
|
|
2380
|
-
}
|
|
2381
|
-
context.logGateway.warn(`webchat transcript append failed for media reply: ${appended.error ?? "unknown error"}`);
|
|
2382
|
-
};
|
|
2383
|
-
const dispatcher = createReplyDispatcher({
|
|
2384
|
-
...replyPipeline,
|
|
2385
|
-
onError: (err) => {
|
|
2386
|
-
context.logGateway.warn(`webchat dispatch failed: ${formatForLog(err)}`);
|
|
2387
|
-
},
|
|
2388
|
-
deliver: async (payload, info) => {
|
|
2389
|
-
if (getReplyPayloadMetadata(payload)?.beforeAgentRunBlocked === true) userTurnRecorder.markBlocked();
|
|
2390
|
-
switch (info.kind) {
|
|
2391
|
-
case "block":
|
|
2392
|
-
case "final":
|
|
2393
|
-
deliveredReplies.push({
|
|
2394
|
-
payload,
|
|
2395
|
-
kind: info.kind
|
|
2396
|
-
});
|
|
2397
|
-
await appendWebchatAgentMediaTranscriptIfNeeded(payload);
|
|
2398
|
-
break;
|
|
2399
|
-
case "tool":
|
|
2400
|
-
if (isMediaBearingPayload(payload)) deliveredReplies.push({
|
|
2401
|
-
payload: {
|
|
2402
|
-
...payload,
|
|
2403
|
-
text: void 0
|
|
2404
|
-
},
|
|
2405
|
-
kind: "final"
|
|
2406
|
-
});
|
|
2407
|
-
break;
|
|
2408
|
-
}
|
|
2409
|
-
}
|
|
2410
|
-
});
|
|
2411
|
-
measureDiagnosticsTimelineSpan("gateway.chat_send.dispatch_inbound", async () => {
|
|
2412
|
-
applyChatSendManagedMediaFields(ctx, await pluginBoundMediaFieldsPromise);
|
|
2413
|
-
const dispatchResult = await dispatchInboundMessage({
|
|
2414
|
-
ctx,
|
|
2415
|
-
cfg,
|
|
2416
|
-
dispatcher,
|
|
2417
|
-
replyOptions: {
|
|
2418
|
-
runId: clientRunId,
|
|
2419
|
-
abortSignal: activeRunAbort.controller.signal,
|
|
2420
|
-
images: replyOptionImages,
|
|
2421
|
-
imageOrder: imageOrder.length > 0 ? imageOrder : void 0,
|
|
2422
|
-
thinkingLevelOverride: p.thinking,
|
|
2423
|
-
fastModeOverride: p.fastMode,
|
|
2424
|
-
userTurnTranscriptRecorder: userTurnRecorder,
|
|
2425
|
-
onAgentRunStart: (runId) => {
|
|
2426
|
-
agentRunStarted = true;
|
|
2427
|
-
const connId = typeof client?.connId === "string" ? client.connId : void 0;
|
|
2428
|
-
const wantsToolEvents = hasGatewayClientCap(client?.connect?.caps, GATEWAY_CLIENT_CAPS.TOOL_EVENTS);
|
|
2429
|
-
if (connId && wantsToolEvents) {
|
|
2430
|
-
context.registerToolEventRecipient(runId, connId);
|
|
2431
|
-
const defaultAgentId = resolveDefaultAgentId(cfg);
|
|
2432
|
-
const selectedGlobalAgentId = sessionKey === "global" ? selectedAgent.agentId ?? defaultAgentId : void 0;
|
|
2433
|
-
for (const [activeRunId, active] of context.chatAbortControllers) {
|
|
2434
|
-
const activeGlobalAgentId = active.sessionKey === "global" ? active.agentId ?? defaultAgentId : void 0;
|
|
2435
|
-
const sameSelectedGlobalAgent = sessionKey === "global" && selectedGlobalAgentId !== void 0 && activeGlobalAgentId === selectedGlobalAgentId;
|
|
2436
|
-
const sameSession = active.sessionKey === sessionKey && (sessionKey !== "global" || sameSelectedGlobalAgent);
|
|
2437
|
-
if (activeRunId !== runId && sameSession) context.registerToolEventRecipient(activeRunId, connId);
|
|
2438
|
-
}
|
|
2439
|
-
}
|
|
2440
|
-
},
|
|
2441
|
-
onModelSelected: (modelSelection) => {
|
|
2442
|
-
updateChatRunProvider(context.chatAbortControllers, {
|
|
2443
|
-
runId: clientRunId,
|
|
2444
|
-
providerId: modelSelection.provider,
|
|
2445
|
-
authProviderId: resolveProviderIdForAuth(modelSelection.provider, { config: cfg })
|
|
2446
|
-
});
|
|
2447
|
-
onModelSelected(modelSelection);
|
|
2448
|
-
}
|
|
2449
|
-
}
|
|
2450
|
-
});
|
|
2451
|
-
if (dispatchResult.beforeAgentRunBlocked === true) userTurnRecorder.markBlocked();
|
|
2452
|
-
return dispatchResult;
|
|
2453
|
-
}, {
|
|
2454
|
-
phase: "agent-turn",
|
|
2455
|
-
config: cfg,
|
|
2456
|
-
attributes: chatSendTraceAttributes
|
|
2457
|
-
}).then(async () => {
|
|
2458
|
-
await measureDiagnosticsTimelineSpan("gateway.chat_send.post_dispatch", async () => {
|
|
2459
|
-
const returnedAgentErrorPayloads = agentRunStarted ? deliveredReplies.map((entry) => entry.payload).filter((payload) => payload.isError) : [];
|
|
2460
|
-
const returnedAgentErrorMessage = returnedAgentErrorPayloads.map((payload) => payload.text?.trim()).filter((text) => Boolean(text)).join(" | ") || void 0;
|
|
2461
|
-
if (agentRunStarted && returnedAgentErrorPayloads.length > 0 && !userTurnRecorder.hasPersisted() && !userTurnRecorder.isBlocked()) await persistGatewayUserTurnTranscriptBestEffort();
|
|
2462
|
-
if (agentRunStarted && returnedAgentErrorPayloads.length === 0 && !userTurnRecorder.hasPersisted() && !userTurnRecorder.isBlocked() && userTurnRecorder.hasRuntimePersistencePending()) await persistGatewayUserTurnTranscriptBestEffort();
|
|
2463
|
-
let broadcastedSourceReplyFinal = false;
|
|
2464
|
-
if (!agentRunStarted) {
|
|
2465
|
-
const btwReplies = deliveredReplies.map((entry) => entry.payload).filter(isBtwReplyPayload);
|
|
2466
|
-
const btwText = btwReplies.map((payload) => payload.text.trim()).filter(Boolean).join("\n\n").trim();
|
|
2467
|
-
if (btwReplies.length > 0 && btwText) {
|
|
2468
|
-
broadcastSideResult({
|
|
2469
|
-
context,
|
|
2470
|
-
payload: {
|
|
2471
|
-
kind: "btw",
|
|
2472
|
-
runId: clientRunId,
|
|
2473
|
-
sessionKey,
|
|
2474
|
-
...sessionKey === "global" && agentId ? { agentId } : {},
|
|
2475
|
-
question: btwReplies[0].btw.question.trim(),
|
|
2476
|
-
text: btwText,
|
|
2477
|
-
isError: btwReplies.some((payload) => payload.isError),
|
|
2478
|
-
ts: Date.now()
|
|
2479
|
-
}
|
|
2480
|
-
});
|
|
2481
|
-
broadcastChatFinal({
|
|
2482
|
-
context,
|
|
2483
|
-
runId: clientRunId,
|
|
2484
|
-
sessionKey,
|
|
2485
|
-
agentId
|
|
2486
|
-
});
|
|
2487
|
-
} else {
|
|
2488
|
-
await persistGatewayUserTurnTranscriptBestEffort();
|
|
2489
|
-
const finalPayloads = await normalizeWebchatReplyMediaPathsForDisplay({
|
|
2490
|
-
cfg,
|
|
2491
|
-
sessionKey,
|
|
2492
|
-
agentId,
|
|
2493
|
-
accountId,
|
|
2494
|
-
payloads: appendedWebchatAgentMedia ? [] : deliveredReplies.filter((entry) => entry.kind === "final").map((entry) => entry.payload)
|
|
2495
|
-
});
|
|
2496
|
-
const { storePath: latestStorePath, entry: latestEntry } = loadSessionEntry(sessionKey, sessionLoadOptions);
|
|
2497
|
-
const sessionId = latestEntry?.sessionId ?? backingSessionId ?? clientRunId;
|
|
2498
|
-
const resolvedTranscriptPath = resolveTranscriptPath({
|
|
2499
|
-
sessionId,
|
|
2500
|
-
storePath: latestStorePath,
|
|
2501
|
-
sessionFile: latestEntry?.sessionFile ?? entry?.sessionFile,
|
|
2502
|
-
agentId
|
|
2503
|
-
});
|
|
2504
|
-
const mediaLocalRoots = appendLocalMediaParentRoots(getAgentScopedMediaLocalRoots(cfg, agentId), resolvedTranscriptPath ? [resolvedTranscriptPath] : void 0);
|
|
2505
|
-
const assistantContent = await buildAssistantDisplayContentFromReplyPayloads({
|
|
2506
|
-
sessionKey,
|
|
2507
|
-
agentId,
|
|
2508
|
-
payloads: finalPayloads,
|
|
2509
|
-
managedImageLocalRoots: mediaLocalRoots,
|
|
2510
|
-
includeSensitiveMedia: false,
|
|
2511
|
-
onLocalAudioAccessDenied: (message) => {
|
|
2512
|
-
context.logGateway.warn(`webchat audio embedding denied local path: ${message}`);
|
|
2513
|
-
},
|
|
2514
|
-
onManagedImagePrepareError: (message) => {
|
|
2515
|
-
context.logGateway.warn(`webchat image embedding skipped attachment: ${message}`);
|
|
2516
|
-
}
|
|
2517
|
-
});
|
|
2518
|
-
const mediaMessage = await buildWebchatAssistantMediaMessage(finalPayloads, {
|
|
2519
|
-
localRoots: mediaLocalRoots,
|
|
2520
|
-
onLocalAudioAccessDenied: (message) => {
|
|
2521
|
-
context.logGateway.warn(`webchat audio embedding denied local path: ${message}`);
|
|
2522
|
-
}
|
|
2523
|
-
});
|
|
2524
|
-
const hasSensitiveMedia = hasSensitiveMediaPayload(finalPayloads);
|
|
2525
|
-
const ttsSupplementMarker = finalPayloads.map((payload) => buildMediaOnlyTtsSupplementTranscriptMarker(payload)).find((marker) => Boolean(marker));
|
|
2526
|
-
const persistedAssistantContent = replaceAssistantContentTextBlocks(hasSensitiveMedia ? await buildAssistantDisplayContentFromReplyPayloads({
|
|
2527
|
-
sessionKey,
|
|
2528
|
-
agentId,
|
|
2529
|
-
payloads: finalPayloads,
|
|
2530
|
-
managedImageLocalRoots: mediaLocalRoots,
|
|
2531
|
-
includeSensitiveMedia: false,
|
|
2532
|
-
onLocalAudioAccessDenied: (message) => {
|
|
2533
|
-
context.logGateway.warn(`webchat audio embedding denied local path: ${message}`);
|
|
2534
|
-
},
|
|
2535
|
-
onManagedImagePrepareError: (message) => {
|
|
2536
|
-
context.logGateway.warn(`webchat image embedding skipped attachment: ${message}`);
|
|
2537
|
-
}
|
|
2538
|
-
}) : assistantContent, mediaMessage);
|
|
2539
|
-
const persistedContentForAppend = hasAssistantDisplayMediaContent(persistedAssistantContent) ? persistedAssistantContent : void 0;
|
|
2540
|
-
const broadcastAssistantContent = hasAssistantDisplayMediaContent(assistantContent) ? assistantContent : hasAssistantDisplayMediaContent(mediaMessage?.content) ? mediaMessage?.content : assistantContent;
|
|
2541
|
-
const displayReply = extractAssistantDisplayTextFromContent(assistantContent) ?? buildTranscriptReplyText(finalPayloads);
|
|
2542
|
-
const transcriptReply = mediaMessage?.transcriptText || buildTranscriptReplyText(finalPayloads) || displayReply;
|
|
2543
|
-
let message;
|
|
2544
|
-
if (transcriptReply || persistedContentForAppend?.length || assistantContent?.length) {
|
|
2545
|
-
const appended = await appendAssistantTranscriptMessage({
|
|
2546
|
-
sessionKey,
|
|
2547
|
-
message: transcriptReply,
|
|
2548
|
-
...persistedContentForAppend?.length ? { content: persistedContentForAppend } : {},
|
|
2549
|
-
sessionId,
|
|
2550
|
-
storePath: latestStorePath,
|
|
2551
|
-
sessionFile: latestEntry?.sessionFile,
|
|
2552
|
-
agentId,
|
|
2553
|
-
createIfMissing: true,
|
|
2554
|
-
idempotencyKey: clientRunId,
|
|
2555
|
-
ttsSupplement: ttsSupplementMarker,
|
|
2556
|
-
cfg
|
|
2557
|
-
});
|
|
2558
|
-
if (appended.ok) {
|
|
2559
|
-
if (appended.messageId && assistantContent?.length) await attachManagedOutgoingImagesToMessage({
|
|
2560
|
-
messageId: appended.messageId,
|
|
2561
|
-
blocks: assistantContent
|
|
2562
|
-
});
|
|
2563
|
-
message = broadcastAssistantContent?.length ? {
|
|
2564
|
-
...appended.message,
|
|
2565
|
-
content: broadcastAssistantContent
|
|
2566
|
-
} : appended.message;
|
|
2567
|
-
} else {
|
|
2568
|
-
context.logGateway.warn(`webchat transcript append failed: ${appended.error ?? "unknown error"}`);
|
|
2569
|
-
const fallbackAssistantContent = stripManagedOutgoingAssistantContentBlocks(persistedAssistantContent) ?? stripManagedOutgoingAssistantContentBlocks(assistantContent);
|
|
2570
|
-
const fallbackText = extractAssistantDisplayText(fallbackAssistantContent) ?? displayReply;
|
|
2571
|
-
const now = Date.now();
|
|
2572
|
-
message = {
|
|
2573
|
-
role: "assistant",
|
|
2574
|
-
...fallbackAssistantContent?.length ? { content: fallbackAssistantContent } : fallbackText ? { content: [{
|
|
2575
|
-
type: "text",
|
|
2576
|
-
text: fallbackText
|
|
2577
|
-
}] } : {},
|
|
2578
|
-
...fallbackText ? { text: fallbackText } : {},
|
|
2579
|
-
timestamp: now,
|
|
2580
|
-
...ttsSupplementMarker ? { fengmingTtsSupplement: ttsSupplementMarker } : {},
|
|
2581
|
-
stopReason: "stop",
|
|
2582
|
-
usage: {
|
|
2583
|
-
input: 0,
|
|
2584
|
-
output: 0,
|
|
2585
|
-
totalTokens: 0
|
|
2586
|
-
}
|
|
2587
|
-
};
|
|
2588
|
-
}
|
|
2589
|
-
}
|
|
2590
|
-
broadcastChatFinal({
|
|
2591
|
-
context,
|
|
2592
|
-
runId: clientRunId,
|
|
2593
|
-
sessionKey,
|
|
2594
|
-
agentId,
|
|
2595
|
-
message
|
|
2596
|
-
});
|
|
2597
|
-
}
|
|
2598
|
-
} else {
|
|
2599
|
-
const sourceReplyPayloads = deliveredReplies.filter((entry) => entry.kind === "final").map((entry) => entry.payload).filter(isSourceReplyTranscriptMirrorPayload);
|
|
2600
|
-
if (sourceReplyPayloads.length > 0) {
|
|
2601
|
-
const finalPayloads = await normalizeWebchatReplyMediaPathsForDisplay({
|
|
2602
|
-
cfg,
|
|
2603
|
-
sessionKey,
|
|
2604
|
-
agentId,
|
|
2605
|
-
accountId,
|
|
2606
|
-
payloads: sourceReplyPayloads
|
|
2607
|
-
});
|
|
2608
|
-
const { storePath: latestStorePath, entry: latestEntry } = loadSessionEntry(sessionKey, sessionLoadOptions);
|
|
2609
|
-
const resolvedTranscriptPath = resolveTranscriptPath({
|
|
2610
|
-
sessionId: latestEntry?.sessionId ?? backingSessionId ?? clientRunId,
|
|
2611
|
-
storePath: latestStorePath,
|
|
2612
|
-
sessionFile: latestEntry?.sessionFile ?? entry?.sessionFile,
|
|
2613
|
-
agentId
|
|
2614
|
-
});
|
|
2615
|
-
const mediaLocalRoots = appendLocalMediaParentRoots(getAgentScopedMediaLocalRoots(cfg, agentId), resolvedTranscriptPath ? [resolvedTranscriptPath] : void 0);
|
|
2616
|
-
const buildReplyAssistantContent = async (payloads) => await buildAssistantDisplayContentFromReplyPayloads({
|
|
2617
|
-
sessionKey,
|
|
2618
|
-
agentId,
|
|
2619
|
-
payloads,
|
|
2620
|
-
managedImageLocalRoots: mediaLocalRoots,
|
|
2621
|
-
includeSensitiveMedia: false,
|
|
2622
|
-
onLocalAudioAccessDenied: (message) => {
|
|
2623
|
-
context.logGateway.warn(`webchat audio embedding denied local path: ${message}`);
|
|
2624
|
-
},
|
|
2625
|
-
onManagedImagePrepareError: (message) => {
|
|
2626
|
-
context.logGateway.warn(`webchat image embedding skipped attachment: ${message}`);
|
|
2627
|
-
}
|
|
2628
|
-
});
|
|
2629
|
-
const buildReplyMediaMessage = async (payloads) => await buildWebchatAssistantMediaMessage(payloads, {
|
|
2630
|
-
localRoots: mediaLocalRoots,
|
|
2631
|
-
onLocalAudioAccessDenied: (message) => {
|
|
2632
|
-
context.logGateway.warn(`webchat audio embedding denied local path: ${message}`);
|
|
2633
|
-
}
|
|
2634
|
-
});
|
|
2635
|
-
const combinedAssistantContent = sourceReplyPayloads.length === 1 ? await buildReplyAssistantContent(finalPayloads) : void 0;
|
|
2636
|
-
const combinedMediaMessage = sourceReplyPayloads.length === 1 ? await buildReplyMediaMessage(finalPayloads) : void 0;
|
|
2637
|
-
const sourceReplyContentStates = [];
|
|
2638
|
-
const sourceReplyBroadcastContent = [];
|
|
2639
|
-
for (const [replyIndex] of sourceReplyPayloads.entries()) {
|
|
2640
|
-
const finalPayload = finalPayloads[replyIndex];
|
|
2641
|
-
if (!finalPayload) continue;
|
|
2642
|
-
const replyAssistantContent = sourceReplyPayloads.length === 1 ? combinedAssistantContent : await buildReplyAssistantContent([finalPayload]);
|
|
2643
|
-
const replyMediaMessage = sourceReplyPayloads.length === 1 ? combinedMediaMessage : await buildReplyMediaMessage([finalPayload]);
|
|
2644
|
-
const replyBroadcastContent = hasAssistantDisplayMediaContent(replyAssistantContent) ? replyAssistantContent : hasAssistantDisplayMediaContent(replyMediaMessage?.content) ? replyMediaMessage?.content : replyAssistantContent;
|
|
2645
|
-
const persistedContent = replaceAssistantContentTextBlocks(replyAssistantContent, replyMediaMessage ?? null);
|
|
2646
|
-
const state = {
|
|
2647
|
-
broadcastContent: replyBroadcastContent ? [...replyBroadcastContent] : [],
|
|
2648
|
-
persistedContent: persistedContent ? [...persistedContent] : [],
|
|
2649
|
-
hasManagedOutgoingContent: hasManagedOutgoingAssistantContent(persistedContent),
|
|
2650
|
-
backedManagedOutgoingContent: false
|
|
2651
|
-
};
|
|
2652
|
-
sourceReplyContentStates[replyIndex] = state;
|
|
2653
|
-
if (state.broadcastContent.length > 0) sourceReplyBroadcastContent.push(...state.broadcastContent);
|
|
2654
|
-
}
|
|
2655
|
-
const displayReply = extractAssistantDisplayTextFromContent(sourceReplyBroadcastContent) ?? buildTranscriptReplyText(finalPayloads);
|
|
2656
|
-
if (sourceReplyBroadcastContent.length || displayReply) {
|
|
2657
|
-
const sourceReplyPersistenceRequests = [];
|
|
2658
|
-
for (const [replyIndex, sourceReplyPayload] of sourceReplyPayloads.entries()) {
|
|
2659
|
-
const state = sourceReplyContentStates[replyIndex];
|
|
2660
|
-
if (!state || !hasAssistantDisplayMediaContent(state.persistedContent)) continue;
|
|
2661
|
-
const mirrorMetadata = getReplyPayloadMetadata(sourceReplyPayload)?.sourceReplyTranscriptMirror;
|
|
2662
|
-
const mirrorIdempotencyKey = mirrorMetadata?.idempotencyKey;
|
|
2663
|
-
if (typeof mirrorIdempotencyKey !== "string" || mirrorIdempotencyKey.trim().length === 0) continue;
|
|
2664
|
-
if (!state.hasManagedOutgoingContent) state.backedManagedOutgoingContent = true;
|
|
2665
|
-
sourceReplyPersistenceRequests.push({
|
|
2666
|
-
idempotencyKey: mirrorIdempotencyKey,
|
|
2667
|
-
metadata: mirrorMetadata,
|
|
2668
|
-
state
|
|
2669
|
-
});
|
|
2670
|
-
}
|
|
2671
|
-
const attachSourceReplyManagedImages = async (params) => {
|
|
2672
|
-
if (!params.request.state.hasManagedOutgoingContent) {
|
|
2673
|
-
params.request.state.backedManagedOutgoingContent = true;
|
|
2674
|
-
return;
|
|
2675
|
-
}
|
|
2676
|
-
if (!params.messageId) return;
|
|
2677
|
-
await attachManagedOutgoingImagesToMessage({
|
|
2678
|
-
messageId: params.messageId,
|
|
2679
|
-
blocks: params.request.state.persistedContent
|
|
2680
|
-
});
|
|
2681
|
-
params.request.state.backedManagedOutgoingContent = true;
|
|
2682
|
-
};
|
|
2683
|
-
if (resolvedTranscriptPath && sourceReplyPersistenceRequests.length > 0) {
|
|
2684
|
-
const allowedSourceReplyMirrorIds = /* @__PURE__ */ new Set();
|
|
2685
|
-
for (const [replyIndex, sourceReplyPayload] of sourceReplyPayloads.entries()) {
|
|
2686
|
-
if (!sourceReplyContentStates[replyIndex]) continue;
|
|
2687
|
-
const mirrorIdempotencyKey = getReplyPayloadMetadata(sourceReplyPayload)?.sourceReplyTranscriptMirror?.idempotencyKey;
|
|
2688
|
-
const mirrorMetadata = getReplyPayloadMetadata(sourceReplyPayload)?.sourceReplyTranscriptMirror;
|
|
2689
|
-
if (typeof mirrorIdempotencyKey !== "string" || mirrorIdempotencyKey.trim().length === 0 || !mirrorMetadata) continue;
|
|
2690
|
-
const target = await findSourceReplyTranscriptMirrorByMetadata({
|
|
2691
|
-
transcriptPath: resolvedTranscriptPath,
|
|
2692
|
-
idempotencyKey: mirrorIdempotencyKey,
|
|
2693
|
-
metadata: mirrorMetadata
|
|
2694
|
-
});
|
|
2695
|
-
if (target) allowedSourceReplyMirrorIds.add(target.messageId);
|
|
2696
|
-
}
|
|
2697
|
-
const rewriteTargets = [];
|
|
2698
|
-
for (const request of sourceReplyPersistenceRequests) {
|
|
2699
|
-
const target = await findSourceReplyTranscriptMirrorByMetadata({
|
|
2700
|
-
transcriptPath: resolvedTranscriptPath,
|
|
2701
|
-
idempotencyKey: request.idempotencyKey,
|
|
2702
|
-
metadata: request.metadata
|
|
2703
|
-
});
|
|
2704
|
-
if (target) rewriteTargets.push({
|
|
2705
|
-
request,
|
|
2706
|
-
...target
|
|
2707
|
-
});
|
|
2708
|
-
}
|
|
2709
|
-
if (rewriteTargets.length > 0) {
|
|
2710
|
-
const rewriteTargetIds = new Set(rewriteTargets.map((target) => target.messageId));
|
|
2711
|
-
const rewriteIndex = await readSessionTranscriptIndex(resolvedTranscriptPath);
|
|
2712
|
-
const firstRewriteEntryIndex = rewriteIndex?.entries.findIndex((entry) => typeof entry.id === "string" && rewriteTargetIds.has(entry.id)) ?? -1;
|
|
2713
|
-
if (firstRewriteEntryIndex >= 0 && rewriteIndex?.entries.slice(firstRewriteEntryIndex).every((entry) => typeof entry.id !== "string" || allowedSourceReplyMirrorIds.has(entry.id)) === true) {
|
|
2714
|
-
if ((await rewriteTranscriptEntriesInSessionFile({
|
|
2715
|
-
sessionFile: resolvedTranscriptPath,
|
|
2716
|
-
sessionKey,
|
|
2717
|
-
agentId,
|
|
2718
|
-
config: cfg,
|
|
2719
|
-
request: {
|
|
2720
|
-
allowedRewriteSuffixEntryIds: [...allowedSourceReplyMirrorIds],
|
|
2721
|
-
replacements: rewriteTargets.map((target) => ({
|
|
2722
|
-
entryId: target.messageId,
|
|
2723
|
-
message: {
|
|
2724
|
-
...target.message,
|
|
2725
|
-
idempotencyKey: target.request.idempotencyKey,
|
|
2726
|
-
content: target.request.state.persistedContent
|
|
2727
|
-
}
|
|
2728
|
-
}))
|
|
2729
|
-
}
|
|
2730
|
-
})).changed) for (const target of rewriteTargets) await attachSourceReplyManagedImages({
|
|
2731
|
-
messageId: (await findSourceReplyTranscriptMirrorByIdempotencyKey(resolvedTranscriptPath, target.request.idempotencyKey))?.messageId,
|
|
2732
|
-
request: target.request
|
|
2733
|
-
});
|
|
2734
|
-
}
|
|
2735
|
-
}
|
|
2736
|
-
}
|
|
2737
|
-
const sourceReplyContent = sourceReplyContentStates.flatMap((state) => {
|
|
2738
|
-
if (state.hasManagedOutgoingContent && !state.backedManagedOutgoingContent) {
|
|
2739
|
-
const stripped = stripManagedOutgoingAssistantContentBlocks(state.broadcastContent);
|
|
2740
|
-
return stripped?.length ? stripped : [{
|
|
2741
|
-
type: "text",
|
|
2742
|
-
text: "Media reply could not be displayed."
|
|
2743
|
-
}];
|
|
2744
|
-
}
|
|
2745
|
-
return state.broadcastContent;
|
|
2746
|
-
}).filter((block) => Boolean(block));
|
|
2747
|
-
const sourceReplyText = extractAssistantDisplayTextFromContent(sourceReplyContent) ?? (sourceReplyContent.length === 0 ? displayReply : void 0);
|
|
2748
|
-
const now = Date.now();
|
|
2749
|
-
broadcastChatFinal({
|
|
2750
|
-
context,
|
|
2751
|
-
runId: clientRunId,
|
|
2752
|
-
sessionKey,
|
|
2753
|
-
agentId,
|
|
2754
|
-
message: {
|
|
2755
|
-
role: "assistant",
|
|
2756
|
-
...sourceReplyContent?.length ? { content: sourceReplyContent } : sourceReplyText ? { content: [{
|
|
2757
|
-
type: "text",
|
|
2758
|
-
text: sourceReplyText
|
|
2759
|
-
}] } : {},
|
|
2760
|
-
...sourceReplyText ? { text: sourceReplyText } : {},
|
|
2761
|
-
timestamp: now,
|
|
2762
|
-
stopReason: "stop",
|
|
2763
|
-
usage: {
|
|
2764
|
-
input: 0,
|
|
2765
|
-
output: 0,
|
|
2766
|
-
totalTokens: 0
|
|
2767
|
-
}
|
|
2768
|
-
}
|
|
2769
|
-
});
|
|
2770
|
-
broadcastedSourceReplyFinal = true;
|
|
2771
|
-
}
|
|
2772
|
-
}
|
|
2773
|
-
}
|
|
2774
|
-
const shouldBroadcastAgentError = returnedAgentErrorPayloads.length > 0 && !broadcastedSourceReplyFinal;
|
|
2775
|
-
if (shouldBroadcastAgentError) broadcastChatError({
|
|
2776
|
-
context,
|
|
2777
|
-
runId: clientRunId,
|
|
2778
|
-
sessionKey,
|
|
2779
|
-
agentId,
|
|
2780
|
-
errorMessage: returnedAgentErrorMessage
|
|
2781
|
-
});
|
|
2782
|
-
if (!context.chatAbortedRuns.has(clientRunId)) {
|
|
2783
|
-
const returnedAgentError = shouldBroadcastAgentError ? errorShape(ErrorCodes.UNAVAILABLE, returnedAgentErrorMessage ?? "agent returned an error payload") : void 0;
|
|
2784
|
-
setGatewayDedupeEntry({
|
|
2785
|
-
dedupe: context.dedupe,
|
|
2786
|
-
key: `chat:${clientRunId}`,
|
|
2787
|
-
entry: {
|
|
2788
|
-
ts: Date.now(),
|
|
2789
|
-
ok: !shouldBroadcastAgentError,
|
|
2790
|
-
payload: shouldBroadcastAgentError ? {
|
|
2791
|
-
runId: clientRunId,
|
|
2792
|
-
status: "error",
|
|
2793
|
-
summary: returnedAgentErrorMessage ?? "agent returned an error payload"
|
|
2794
|
-
} : {
|
|
2795
|
-
runId: clientRunId,
|
|
2796
|
-
status: "ok"
|
|
2797
|
-
},
|
|
2798
|
-
...returnedAgentError ? { error: returnedAgentError } : {}
|
|
2799
|
-
}
|
|
2800
|
-
});
|
|
2801
|
-
}
|
|
2802
|
-
}, {
|
|
2803
|
-
phase: "agent-turn",
|
|
2804
|
-
config: cfg,
|
|
2805
|
-
attributes: chatSendTraceAttributes
|
|
2806
|
-
});
|
|
2807
|
-
}).catch(async (err) => {
|
|
2808
|
-
await (userTurnRecorder.hasPersisted() || userTurnRecorder.isBlocked() ? Promise.resolve() : persistGatewayUserTurnTranscript()).catch((transcriptErr) => {
|
|
2809
|
-
context.logGateway.warn(`webchat user transcript update failed after error: ${formatForLog(transcriptErr)}`);
|
|
2810
|
-
});
|
|
2811
|
-
const error = errorShape(ErrorCodes.UNAVAILABLE, String(err));
|
|
2812
|
-
setGatewayDedupeEntry({
|
|
2813
|
-
dedupe: context.dedupe,
|
|
2814
|
-
key: `chat:${clientRunId}`,
|
|
2815
|
-
entry: {
|
|
2816
|
-
ts: Date.now(),
|
|
2817
|
-
ok: false,
|
|
2818
|
-
payload: {
|
|
2819
|
-
runId: clientRunId,
|
|
2820
|
-
status: "error",
|
|
2821
|
-
summary: String(err)
|
|
2822
|
-
},
|
|
2823
|
-
error
|
|
2824
|
-
}
|
|
2825
|
-
});
|
|
2826
|
-
broadcastChatError({
|
|
2827
|
-
context,
|
|
2828
|
-
runId: clientRunId,
|
|
2829
|
-
sessionKey,
|
|
2830
|
-
agentId,
|
|
2831
|
-
errorMessage: String(err)
|
|
2832
|
-
});
|
|
2833
|
-
}).finally(() => {
|
|
2834
|
-
activeRunAbort.cleanup();
|
|
2835
|
-
context.removeChatRun(clientRunId, clientRunId, sessionKey);
|
|
2836
|
-
});
|
|
2837
|
-
} catch (err) {
|
|
2838
|
-
context.chatAbortControllers.delete(clientRunId);
|
|
2839
|
-
context.removeChatRun(clientRunId, clientRunId, sessionKey);
|
|
2840
|
-
const error = errorShape(ErrorCodes.UNAVAILABLE, String(err));
|
|
2841
|
-
const payload = {
|
|
2842
|
-
runId: clientRunId,
|
|
2843
|
-
status: "error",
|
|
2844
|
-
summary: String(err)
|
|
2845
|
-
};
|
|
2846
|
-
setGatewayDedupeEntry({
|
|
2847
|
-
dedupe: context.dedupe,
|
|
2848
|
-
key: `chat:${clientRunId}`,
|
|
2849
|
-
entry: {
|
|
2850
|
-
ts: Date.now(),
|
|
2851
|
-
ok: false,
|
|
2852
|
-
payload,
|
|
2853
|
-
error
|
|
2854
|
-
}
|
|
2855
|
-
});
|
|
2856
|
-
respond(false, payload, error, {
|
|
2857
|
-
runId: clientRunId,
|
|
2858
|
-
error: formatForLog(err)
|
|
2859
|
-
});
|
|
2860
|
-
broadcastChatError({
|
|
2861
|
-
context,
|
|
2862
|
-
runId: clientRunId,
|
|
2863
|
-
sessionKey,
|
|
2864
|
-
agentId,
|
|
2865
|
-
errorMessage: String(err)
|
|
2866
|
-
});
|
|
2867
|
-
}
|
|
2868
|
-
},
|
|
2869
|
-
"chat.inject": async ({ params, respond, context }) => {
|
|
2870
|
-
if (!validateChatInjectParams(params)) {
|
|
2871
|
-
respond(false, void 0, errorShape(ErrorCodes.INVALID_REQUEST, `invalid chat.inject params: ${formatValidationErrors(validateChatInjectParams.errors)}`));
|
|
2872
|
-
return;
|
|
2873
|
-
}
|
|
2874
|
-
const p = params;
|
|
2875
|
-
const rawSessionKey = p.sessionKey;
|
|
2876
|
-
const requestedAgentId = resolveRequestedChatAgentId({
|
|
2877
|
-
cfg: context.getRuntimeConfig?.(),
|
|
2878
|
-
requestedSessionKey: rawSessionKey,
|
|
2879
|
-
agentId: p.agentId
|
|
2880
|
-
});
|
|
2881
|
-
const { cfg, storePath, entry, canonicalKey: sessionKey } = loadSessionEntry(rawSessionKey, requestedAgentId ? { agentId: requestedAgentId } : void 0);
|
|
2882
|
-
const selectedAgent = validateChatSelectedAgent({
|
|
2883
|
-
cfg,
|
|
2884
|
-
requestedSessionKey: rawSessionKey,
|
|
2885
|
-
agentId: requestedAgentId
|
|
2886
|
-
});
|
|
2887
|
-
if (!selectedAgent.ok) {
|
|
2888
|
-
respond(false, void 0, errorShape(ErrorCodes.INVALID_REQUEST, selectedAgent.error));
|
|
2889
|
-
return;
|
|
2890
|
-
}
|
|
2891
|
-
const sessionId = entry?.sessionId;
|
|
2892
|
-
if (!sessionId || !storePath) {
|
|
2893
|
-
respond(false, void 0, errorShape(ErrorCodes.INVALID_REQUEST, "session not found"));
|
|
2894
|
-
return;
|
|
2895
|
-
}
|
|
2896
|
-
const agentId = resolveSessionAgentId({
|
|
2897
|
-
sessionKey,
|
|
2898
|
-
config: cfg,
|
|
2899
|
-
agentId: selectedAgent.agentId
|
|
2900
|
-
});
|
|
2901
|
-
const appended = await appendAssistantTranscriptMessage({
|
|
2902
|
-
sessionKey,
|
|
2903
|
-
message: p.message,
|
|
2904
|
-
label: p.label,
|
|
2905
|
-
sessionId,
|
|
2906
|
-
storePath,
|
|
2907
|
-
sessionFile: entry?.sessionFile,
|
|
2908
|
-
agentId,
|
|
2909
|
-
createIfMissing: true,
|
|
2910
|
-
cfg
|
|
2911
|
-
});
|
|
2912
|
-
if (!appended.ok || !appended.messageId || !appended.message) {
|
|
2913
|
-
respond(false, void 0, errorShape(ErrorCodes.UNAVAILABLE, `failed to write transcript: ${appended.error ?? "unknown error"}`));
|
|
2914
|
-
return;
|
|
2915
|
-
}
|
|
2916
|
-
const message = projectChatDisplayMessage(appended.message, { maxChars: resolveEffectiveChatHistoryMaxChars(cfg) });
|
|
2917
|
-
const chatPayload = {
|
|
2918
|
-
runId: `inject-${appended.messageId}`,
|
|
2919
|
-
sessionKey,
|
|
2920
|
-
...sessionKey === "global" && agentId ? { agentId } : {},
|
|
2921
|
-
seq: 0,
|
|
2922
|
-
state: "final",
|
|
2923
|
-
message
|
|
2924
|
-
};
|
|
2925
|
-
context.broadcast("chat", chatPayload);
|
|
2926
|
-
sendGlobalAwareNodeChatPayload({
|
|
2927
|
-
context,
|
|
2928
|
-
sessionKey,
|
|
2929
|
-
agentId,
|
|
2930
|
-
event: "chat",
|
|
2931
|
-
payload: chatPayload
|
|
2932
|
-
});
|
|
2933
|
-
respond(true, {
|
|
2934
|
-
ok: true,
|
|
2935
|
-
messageId: appended.messageId
|
|
2936
|
-
});
|
|
2937
|
-
}
|
|
2938
|
-
};
|
|
2939
|
-
//#endregion
|
|
2940
|
-
export { dropPreSessionStartAnnouncePairs as a, sanitizeChatSendMessageInput as c, chatHandlers as i, augmentChatHistoryWithCanvasBlocks as n, enforceChatHistoryFinalBudget as o, buildOversizedHistoryPlaceholder as r, replaceOversizedChatHistoryMessages as s, CHAT_HISTORY_MAX_SINGLE_MESSAGE_BYTES as t };
|