@openclaw/discord 2026.5.2 → 2026.5.3-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/access-B9ujuUtS.js +89 -0
- package/dist/account-inspect-C2UEUhbG.js +81 -0
- package/dist/account-inspect-api.js +10 -0
- package/dist/accounts-BKnkNaoA.js +128 -0
- package/dist/action-runtime-api.js +2 -0
- package/dist/agent-components.runtime-DUhLr9hy.js +4 -0
- package/dist/allow-list-ek-1hMKN.js +336 -0
- package/dist/api-DzNBVTto.js +130 -0
- package/dist/api.js +24 -0
- package/dist/approval-handler.runtime-v8nzQHlT.js +426 -0
- package/dist/approval-native-DqWGp0bM.js +153 -0
- package/dist/approval-shared-DKnwwjZM.js +93 -0
- package/dist/audit-CJ92YD6J.js +102 -0
- package/dist/channel-B3aTtBj1.js +745 -0
- package/dist/channel-access-ewDxhd9q.js +62 -0
- package/dist/channel-actions-TNih7k3w.js +140 -0
- package/dist/channel-actions.runtime-CaPytiY4.js +236 -0
- package/dist/channel-api-CTSWMrnD.js +21 -0
- package/dist/channel-config-api.js +2 -0
- package/dist/channel-plugin-api.js +2 -0
- package/dist/channel.setup-Dt4tIDrl.js +336 -0
- package/dist/components-BapWDmDM.js +760 -0
- package/dist/config-api-CFZtoMaS.js +2 -0
- package/dist/config-schema-DwFkL904.js +252 -0
- package/dist/configured-state.js +6 -0
- package/dist/contract-api.js +8 -0
- package/dist/conversation-identity-BN9wSmxJ.js +31 -0
- package/dist/directory-cache-D93eSrpB.js +62 -0
- package/dist/directory-config-LyMP0sdv.js +49 -0
- package/dist/directory-contract-api.js +2 -0
- package/dist/directory-live-BQapdpkZ.js +101 -0
- package/dist/discord-D1kDh0X_.js +2751 -0
- package/dist/doctor-B2G7WqO0.js +244 -0
- package/dist/doctor-contract-D3pSutkb.js +383 -0
- package/dist/doctor-contract-api.js +2 -0
- package/dist/doctor-shared-DU8RcnF5.js +4 -0
- package/dist/format-D8TsaXxW.js +24 -0
- package/dist/gateway-registry-BKG4KIVC.js +74 -0
- package/dist/handle-action.guild-admin-BuqsSVXu.js +283 -0
- package/dist/inbound-context-e_oBBJtF.js +51 -0
- package/dist/index.js +26 -0
- package/dist/manager.runtime-M2aAa7qA.js +1019 -0
- package/dist/mentions-BPZUaFk7.js +88 -0
- package/dist/message-handler-D6JfFV3P.js +381 -0
- package/dist/message-handler.preflight-DqaF3vHm.js +1022 -0
- package/dist/message-handler.process-tl3Nwnhr.js +1124 -0
- package/dist/message-utils-Dmgu-7fC.js +512 -0
- package/dist/normalize-B-ktw-T_.js +275 -0
- package/dist/outbound-adapter-DJf9_sfH.js +451 -0
- package/dist/outbound-session-route-uHGLDP-Y.js +43 -0
- package/dist/pluralkit-voQvSN3g.js +22 -0
- package/dist/preflight-audio-BpYtUAT6.js +72 -0
- package/dist/preflight-audio.runtime-BAGmU6uO.js +7 -0
- package/dist/preview-streaming-C0O92Qqz.js +14 -0
- package/dist/probe-DcNEodPI.js +139 -0
- package/dist/probe.runtime-P-e4r1Hl.js +2 -0
- package/dist/provider-CMvXOp-3.js +8440 -0
- package/dist/provider-session.runtime-JFemrDZT.js +6 -0
- package/dist/provider.runtime-BO007oR2.js +2 -0
- package/dist/reply-delivery-D9So77a6.js +131 -0
- package/dist/resolve-allowlist-common-DqqFY_qa.js +34 -0
- package/dist/resolve-channels-CGPntufJ.js +265 -0
- package/dist/resolve-users-CDvSlW0V.js +120 -0
- package/dist/rolldown-runtime-C3SqQTfK.js +28 -0
- package/dist/route-resolution-BYiC-6Cc.js +236 -0
- package/dist/runtime-K9RT6Egn.js +8 -0
- package/dist/runtime-api.actions.js +3 -0
- package/dist/runtime-api.js +31 -0
- package/dist/runtime-api.lookup.js +7 -0
- package/dist/runtime-api.monitor-BC-XN0tY.js +6 -0
- package/dist/runtime-api.monitor.js +9 -0
- package/dist/runtime-api.send.js +6 -0
- package/dist/runtime-api.threads.js +6 -0
- package/dist/runtime-n5xZHW55.js +1001 -0
- package/dist/runtime-setter-api.js +2 -0
- package/dist/secret-config-contract-CoGryS5c.js +115 -0
- package/dist/secret-contract-api.js +2 -0
- package/dist/security-audit-Cdz2iq3m.js +120 -0
- package/dist/security-audit-contract-api.js +2 -0
- package/dist/security-audit.runtime-DBV1T1_N.js +2 -0
- package/dist/security-contract-api.js +2 -0
- package/dist/security-contract-ei3Mz8Sa.js +26 -0
- package/dist/security-doctor-CzTzpXV8.js +18 -0
- package/dist/send-B_frVn_Q.js +845 -0
- package/dist/send.components-B1EgHAds.js +468 -0
- package/dist/send.outbound-DlBAuW7y.js +211 -0
- package/dist/send.shared-Db0opnak.js +708 -0
- package/dist/sender-identity-BiSDAk2P.js +43 -0
- package/dist/session-contract-goJZckp2.js +6 -0
- package/dist/session-key-api.js +2 -0
- package/dist/session-key-normalization-Daag9II6.js +23 -0
- package/dist/setup-entry.js +11 -0
- package/dist/setup-plugin-api.js +2 -0
- package/dist/shared-CqlrJmSs.js +166 -0
- package/dist/shared-interactive-KgJjCqnB.js +79 -0
- package/dist/subagent-hooks-api.js +22 -0
- package/dist/subagent-hooks-mEK5ARfP.js +113 -0
- package/dist/system-events-Bu9jmO4W.js +34 -0
- package/dist/targets-kKlbZ4ai.js +3 -0
- package/dist/test-api.js +45 -0
- package/dist/thread-binding-api.js +4 -0
- package/dist/thread-bindings-Bj1R-6QH.js +256 -0
- package/dist/thread-bindings.discord-api-ClPMuIr8.js +184 -0
- package/dist/thread-bindings.manager-BaN0l4y8.js +535 -0
- package/dist/thread-bindings.session-updates-TTP020qQ.js +54 -0
- package/dist/thread-bindings.state-Dzu1gCE7.js +318 -0
- package/dist/threading-CWhdYHVx.js +475 -0
- package/dist/timeouts-C7jeTtGs.js +52 -0
- package/dist/timeouts.js +2 -0
- package/dist/token-D-w3Rigl.js +42 -0
- package/dist/typing-CJiowRTZ.js +15 -0
- package/package.json +14 -6
- package/account-inspect-api.ts +0 -6
- package/action-runtime-api.ts +0 -1
- package/api.ts +0 -132
- package/channel-config-api.ts +0 -1
- package/channel-plugin-api.ts +0 -3
- package/config-api.ts +0 -4
- package/configured-state.ts +0 -6
- package/contract-api.ts +0 -21
- package/directory-contract-api.ts +0 -4
- package/doctor-contract-api.ts +0 -1
- package/index.test.ts +0 -13
- package/index.ts +0 -24
- package/runtime-api.actions.ts +0 -15
- package/runtime-api.lookup.ts +0 -22
- package/runtime-api.monitor.ts +0 -50
- package/runtime-api.send.ts +0 -79
- package/runtime-api.threads.ts +0 -30
- package/runtime-api.ts +0 -180
- package/runtime-setter-api.ts +0 -3
- package/secret-contract-api.ts +0 -4
- package/security-audit-contract-api.ts +0 -1
- package/security-contract-api.ts +0 -4
- package/session-key-api.ts +0 -1
- package/setup-entry.ts +0 -9
- package/setup-plugin-api.ts +0 -3
- package/src/account-inspect.test.ts +0 -126
- package/src/account-inspect.ts +0 -132
- package/src/accounts.test.ts +0 -247
- package/src/accounts.ts +0 -196
- package/src/actions/handle-action.guild-admin.ts +0 -411
- package/src/actions/handle-action.test.ts +0 -306
- package/src/actions/handle-action.ts +0 -372
- package/src/actions/runtime.guild.ts +0 -446
- package/src/actions/runtime.messaging.messages.ts +0 -205
- package/src/actions/runtime.messaging.reactions.ts +0 -67
- package/src/actions/runtime.messaging.runtime.ts +0 -69
- package/src/actions/runtime.messaging.send.ts +0 -248
- package/src/actions/runtime.messaging.shared.ts +0 -97
- package/src/actions/runtime.messaging.ts +0 -37
- package/src/actions/runtime.moderation-shared.ts +0 -48
- package/src/actions/runtime.moderation.authz.test.ts +0 -151
- package/src/actions/runtime.moderation.ts +0 -116
- package/src/actions/runtime.presence.test.ts +0 -160
- package/src/actions/runtime.presence.ts +0 -117
- package/src/actions/runtime.shared.ts +0 -83
- package/src/actions/runtime.test.ts +0 -1087
- package/src/actions/runtime.ts +0 -87
- package/src/api-barrel.test.ts +0 -80
- package/src/api.test.ts +0 -130
- package/src/api.ts +0 -169
- package/src/approval-handler.runtime.test.ts +0 -41
- package/src/approval-handler.runtime.ts +0 -632
- package/src/approval-native.test.ts +0 -330
- package/src/approval-native.ts +0 -219
- package/src/approval-runtime.ts +0 -14
- package/src/approval-shared.ts +0 -53
- package/src/audit-core.ts +0 -141
- package/src/audit.test.ts +0 -145
- package/src/audit.ts +0 -32
- package/src/channel-actions.contract.test.ts +0 -45
- package/src/channel-actions.runtime.ts +0 -1
- package/src/channel-actions.test.ts +0 -275
- package/src/channel-actions.ts +0 -203
- package/src/channel-api.ts +0 -29
- package/src/channel.conversation.ts +0 -159
- package/src/channel.loaders.ts +0 -47
- package/src/channel.runtime.ts +0 -1
- package/src/channel.setup.ts +0 -12
- package/src/channel.test.ts +0 -571
- package/src/channel.ts +0 -629
- package/src/chunk.test.ts +0 -157
- package/src/chunk.ts +0 -321
- package/src/client.proxy.test.ts +0 -176
- package/src/client.test.ts +0 -76
- package/src/client.ts +0 -132
- package/src/component-custom-id.ts +0 -72
- package/src/components-registry.ts +0 -356
- package/src/components.builders.ts +0 -409
- package/src/components.modal.ts +0 -124
- package/src/components.parse.ts +0 -407
- package/src/components.test.ts +0 -312
- package/src/components.ts +0 -54
- package/src/components.types.ts +0 -187
- package/src/config-schema.test.ts +0 -325
- package/src/config-schema.ts +0 -6
- package/src/config-ui-hints.ts +0 -249
- package/src/conversation-identity.ts +0 -58
- package/src/delivery-retry.ts +0 -56
- package/src/directory-cache.ts +0 -116
- package/src/directory-config.ts +0 -58
- package/src/directory-contract.test.ts +0 -129
- package/src/directory-live.test.ts +0 -126
- package/src/directory-live.ts +0 -135
- package/src/doctor-contract.ts +0 -477
- package/src/doctor-shared.ts +0 -5
- package/src/doctor.test.ts +0 -405
- package/src/doctor.ts +0 -340
- package/src/draft-chunking.test.ts +0 -64
- package/src/draft-chunking.ts +0 -43
- package/src/draft-stream.test.ts +0 -159
- package/src/draft-stream.ts +0 -154
- package/src/error-body.ts +0 -38
- package/src/exec-approvals.test.ts +0 -88
- package/src/exec-approvals.ts +0 -110
- package/src/gateway-logging.test.ts +0 -98
- package/src/gateway-logging.ts +0 -67
- package/src/group-policy.ts +0 -113
- package/src/guilds.ts +0 -29
- package/src/inbound-context.contract.test.ts +0 -11
- package/src/interactive-dispatch.ts +0 -104
- package/src/internal/api.commands.ts +0 -51
- package/src/internal/api.guild.ts +0 -164
- package/src/internal/api.interactions.ts +0 -53
- package/src/internal/api.messages.ts +0 -113
- package/src/internal/api.reactions.ts +0 -38
- package/src/internal/api.test.ts +0 -262
- package/src/internal/api.ts +0 -61
- package/src/internal/api.users.ts +0 -19
- package/src/internal/api.webhooks.ts +0 -13
- package/src/internal/client.test.ts +0 -440
- package/src/internal/client.ts +0 -310
- package/src/internal/command-deploy.ts +0 -297
- package/src/internal/commands.ts +0 -188
- package/src/internal/components.base.ts +0 -65
- package/src/internal/components.message.ts +0 -279
- package/src/internal/components.modal.ts +0 -95
- package/src/internal/components.ts +0 -31
- package/src/internal/discord.ts +0 -11
- package/src/internal/embeds.ts +0 -35
- package/src/internal/entity-cache.ts +0 -98
- package/src/internal/event-queue.ts +0 -162
- package/src/internal/gateway-close-codes.ts +0 -25
- package/src/internal/gateway-dispatch.ts +0 -96
- package/src/internal/gateway-identify-limiter.ts +0 -26
- package/src/internal/gateway-lifecycle.ts +0 -61
- package/src/internal/gateway-rate-limit.ts +0 -104
- package/src/internal/gateway.test.ts +0 -603
- package/src/internal/gateway.ts +0 -476
- package/src/internal/interaction-dispatch.test.ts +0 -148
- package/src/internal/interaction-dispatch.ts +0 -162
- package/src/internal/interaction-options.ts +0 -98
- package/src/internal/interaction-response.ts +0 -53
- package/src/internal/interactions.test.ts +0 -325
- package/src/internal/interactions.ts +0 -378
- package/src/internal/listeners.ts +0 -85
- package/src/internal/live-smoke.live.test.ts +0 -26
- package/src/internal/modal-fields.ts +0 -95
- package/src/internal/payload.ts +0 -69
- package/src/internal/rest-body.ts +0 -115
- package/src/internal/rest-errors.ts +0 -88
- package/src/internal/rest-routes.ts +0 -50
- package/src/internal/rest-scheduler.ts +0 -557
- package/src/internal/rest.test.ts +0 -673
- package/src/internal/rest.ts +0 -322
- package/src/internal/schemas.ts +0 -36
- package/src/internal/structures.test.ts +0 -43
- package/src/internal/structures.ts +0 -280
- package/src/internal/test-builders.test-support.ts +0 -167
- package/src/internal/voice.ts +0 -49
- package/src/media-detection.ts +0 -28
- package/src/mentions.test.ts +0 -111
- package/src/mentions.ts +0 -147
- package/src/monitor/access-groups.ts +0 -55
- package/src/monitor/ack-reactions.ts +0 -70
- package/src/monitor/acp-bind-here.integration.test.ts +0 -211
- package/src/monitor/agent-components-auth.ts +0 -7
- package/src/monitor/agent-components-context.ts +0 -154
- package/src/monitor/agent-components-data.ts +0 -224
- package/src/monitor/agent-components-dm-auth.ts +0 -221
- package/src/monitor/agent-components-guild-auth.ts +0 -322
- package/src/monitor/agent-components-helpers.runtime.ts +0 -5
- package/src/monitor/agent-components-helpers.ts +0 -34
- package/src/monitor/agent-components-reply.ts +0 -10
- package/src/monitor/agent-components.deps.runtime.ts +0 -2
- package/src/monitor/agent-components.dispatch.ts +0 -366
- package/src/monitor/agent-components.handlers.ts +0 -303
- package/src/monitor/agent-components.modal.ts +0 -160
- package/src/monitor/agent-components.plugin-interactive.ts +0 -187
- package/src/monitor/agent-components.runtime.ts +0 -14
- package/src/monitor/agent-components.system-controls.ts +0 -211
- package/src/monitor/agent-components.ts +0 -70
- package/src/monitor/agent-components.types.ts +0 -58
- package/src/monitor/agent-components.wildcard-controls.ts +0 -168
- package/src/monitor/agent-components.wildcard.test.ts +0 -71
- package/src/monitor/allow-list.test.ts +0 -14
- package/src/monitor/allow-list.ts +0 -633
- package/src/monitor/auto-presence.test.ts +0 -156
- package/src/monitor/auto-presence.ts +0 -356
- package/src/monitor/channel-access.test.ts +0 -99
- package/src/monitor/channel-access.ts +0 -102
- package/src/monitor/commands.test.ts +0 -24
- package/src/monitor/commands.ts +0 -9
- package/src/monitor/dm-command-auth.test.ts +0 -197
- package/src/monitor/dm-command-auth.ts +0 -158
- package/src/monitor/dm-command-decision.test.ts +0 -113
- package/src/monitor/dm-command-decision.ts +0 -49
- package/src/monitor/exec-approvals.test.ts +0 -226
- package/src/monitor/exec-approvals.ts +0 -158
- package/src/monitor/format.ts +0 -45
- package/src/monitor/gateway-handle.ts +0 -34
- package/src/monitor/gateway-metadata.test.ts +0 -29
- package/src/monitor/gateway-metadata.ts +0 -298
- package/src/monitor/gateway-plugin.test.ts +0 -297
- package/src/monitor/gateway-plugin.ts +0 -294
- package/src/monitor/gateway-registry.ts +0 -37
- package/src/monitor/gateway-supervisor.test.ts +0 -150
- package/src/monitor/gateway-supervisor.ts +0 -206
- package/src/monitor/inbound-context.test-helpers.ts +0 -37
- package/src/monitor/inbound-context.test.ts +0 -106
- package/src/monitor/inbound-context.ts +0 -103
- package/src/monitor/inbound-dedupe.ts +0 -79
- package/src/monitor/inbound-job.test.ts +0 -203
- package/src/monitor/inbound-job.ts +0 -118
- package/src/monitor/listeners.queue.ts +0 -91
- package/src/monitor/listeners.reactions.ts +0 -610
- package/src/monitor/listeners.test.ts +0 -200
- package/src/monitor/listeners.ts +0 -150
- package/src/monitor/message-channel-info.ts +0 -96
- package/src/monitor/message-forwarded.ts +0 -107
- package/src/monitor/message-handler.batch-gate.test.ts +0 -22
- package/src/monitor/message-handler.batch-gate.ts +0 -19
- package/src/monitor/message-handler.bot-self-filter.test.ts +0 -68
- package/src/monitor/message-handler.context.ts +0 -406
- package/src/monitor/message-handler.dm-preflight.ts +0 -123
- package/src/monitor/message-handler.draft-preview.ts +0 -246
- package/src/monitor/message-handler.hydration.test.ts +0 -80
- package/src/monitor/message-handler.hydration.ts +0 -198
- package/src/monitor/message-handler.inbound-context.test.ts +0 -59
- package/src/monitor/message-handler.module-test-helpers.ts +0 -31
- package/src/monitor/message-handler.preflight-channel-access.ts +0 -86
- package/src/monitor/message-handler.preflight-channel-context.test.ts +0 -18
- package/src/monitor/message-handler.preflight-channel-context.ts +0 -58
- package/src/monitor/message-handler.preflight-context.ts +0 -54
- package/src/monitor/message-handler.preflight-helpers.ts +0 -164
- package/src/monitor/message-handler.preflight-history.ts +0 -23
- package/src/monitor/message-handler.preflight-logging.ts +0 -36
- package/src/monitor/message-handler.preflight-pluralkit.ts +0 -26
- package/src/monitor/message-handler.preflight-runtime.ts +0 -28
- package/src/monitor/message-handler.preflight-thread.ts +0 -49
- package/src/monitor/message-handler.preflight.acp-bindings.test.ts +0 -369
- package/src/monitor/message-handler.preflight.test-helpers.ts +0 -111
- package/src/monitor/message-handler.preflight.test.ts +0 -1623
- package/src/monitor/message-handler.preflight.ts +0 -679
- package/src/monitor/message-handler.preflight.types.ts +0 -110
- package/src/monitor/message-handler.process.test.ts +0 -1369
- package/src/monitor/message-handler.process.ts +0 -686
- package/src/monitor/message-handler.queue.test.ts +0 -496
- package/src/monitor/message-handler.routing-preflight.ts +0 -112
- package/src/monitor/message-handler.test-harness.ts +0 -99
- package/src/monitor/message-handler.test-helpers.ts +0 -75
- package/src/monitor/message-handler.ts +0 -274
- package/src/monitor/message-media.ts +0 -509
- package/src/monitor/message-run-queue.ts +0 -101
- package/src/monitor/message-text.ts +0 -171
- package/src/monitor/message-utils.test.ts +0 -1157
- package/src/monitor/message-utils.ts +0 -32
- package/src/monitor/model-picker-preferences.test.ts +0 -67
- package/src/monitor/model-picker-preferences.ts +0 -184
- package/src/monitor/model-picker.state.ts +0 -364
- package/src/monitor/model-picker.test-utils.ts +0 -26
- package/src/monitor/model-picker.test.ts +0 -794
- package/src/monitor/model-picker.ts +0 -38
- package/src/monitor/model-picker.view.ts +0 -695
- package/src/monitor/monitor.agent-components.test.ts +0 -375
- package/src/monitor/monitor.test.ts +0 -849
- package/src/monitor/monitor.threading-utils.test.ts +0 -598
- package/src/monitor/native-command-agent-reply.ts +0 -125
- package/src/monitor/native-command-arg-ui.ts +0 -233
- package/src/monitor/native-command-auth.ts +0 -308
- package/src/monitor/native-command-bypass.ts +0 -13
- package/src/monitor/native-command-context.test.ts +0 -98
- package/src/monitor/native-command-context.ts +0 -103
- package/src/monitor/native-command-dispatch.ts +0 -35
- package/src/monitor/native-command-model-picker-apply.ts +0 -177
- package/src/monitor/native-command-model-picker-interaction.ts +0 -461
- package/src/monitor/native-command-model-picker-ui.ts +0 -368
- package/src/monitor/native-command-reply.test.ts +0 -68
- package/src/monitor/native-command-reply.ts +0 -185
- package/src/monitor/native-command-route.ts +0 -91
- package/src/monitor/native-command-status.ts +0 -76
- package/src/monitor/native-command-ui.ts +0 -26
- package/src/monitor/native-command-ui.types.ts +0 -20
- package/src/monitor/native-command.args.ts +0 -45
- package/src/monitor/native-command.command-arg.test.ts +0 -99
- package/src/monitor/native-command.commands-allowfrom.test.ts +0 -490
- package/src/monitor/native-command.model-picker.test.ts +0 -767
- package/src/monitor/native-command.options.test.ts +0 -369
- package/src/monitor/native-command.options.ts +0 -153
- package/src/monitor/native-command.plugin-dispatch.test.ts +0 -961
- package/src/monitor/native-command.runtime.ts +0 -50
- package/src/monitor/native-command.status-direct.test.ts +0 -272
- package/src/monitor/native-command.test-helpers.ts +0 -64
- package/src/monitor/native-command.think-autocomplete.test.ts +0 -416
- package/src/monitor/native-command.ts +0 -700
- package/src/monitor/native-command.types.ts +0 -9
- package/src/monitor/native-interaction-channel-context.ts +0 -50
- package/src/monitor/preflight-audio.runtime.ts +0 -9
- package/src/monitor/preflight-audio.test.ts +0 -157
- package/src/monitor/preflight-audio.ts +0 -130
- package/src/monitor/presence-cache.ts +0 -61
- package/src/monitor/presence.test.ts +0 -44
- package/src/monitor/presence.ts +0 -50
- package/src/monitor/provider-session.runtime.ts +0 -12
- package/src/monitor/provider.acp.ts +0 -89
- package/src/monitor/provider.allowlist.test.ts +0 -149
- package/src/monitor/provider.allowlist.ts +0 -394
- package/src/monitor/provider.cleanup.ts +0 -41
- package/src/monitor/provider.commands.ts +0 -129
- package/src/monitor/provider.config-log.ts +0 -45
- package/src/monitor/provider.deploy-errors.ts +0 -362
- package/src/monitor/provider.deploy.ts +0 -221
- package/src/monitor/provider.interactions.ts +0 -160
- package/src/monitor/provider.lifecycle.test.ts +0 -713
- package/src/monitor/provider.lifecycle.ts +0 -552
- package/src/monitor/provider.proxy.test.ts +0 -745
- package/src/monitor/provider.rest-proxy.test.ts +0 -121
- package/src/monitor/provider.runtime.ts +0 -1
- package/src/monitor/provider.skill-dedupe.test.ts +0 -42
- package/src/monitor/provider.startup-log.ts +0 -32
- package/src/monitor/provider.startup.test.ts +0 -426
- package/src/monitor/provider.startup.ts +0 -330
- package/src/monitor/provider.test.ts +0 -1111
- package/src/monitor/provider.ts +0 -713
- package/src/monitor/reply-context.ts +0 -64
- package/src/monitor/reply-delivery.test.ts +0 -244
- package/src/monitor/reply-delivery.ts +0 -203
- package/src/monitor/rest-fetch.ts +0 -43
- package/src/monitor/route-resolution.test.ts +0 -204
- package/src/monitor/route-resolution.ts +0 -140
- package/src/monitor/sender-identity.ts +0 -81
- package/src/monitor/startup-status.test.ts +0 -30
- package/src/monitor/startup-status.ts +0 -10
- package/src/monitor/status.ts +0 -22
- package/src/monitor/system-events.ts +0 -55
- package/src/monitor/thread-bindings.config.ts +0 -35
- package/src/monitor/thread-bindings.discord-api.test.ts +0 -229
- package/src/monitor/thread-bindings.discord-api.ts +0 -310
- package/src/monitor/thread-bindings.lifecycle.test.ts +0 -1871
- package/src/monitor/thread-bindings.lifecycle.ts +0 -354
- package/src/monitor/thread-bindings.manager.ts +0 -553
- package/src/monitor/thread-bindings.messages.ts +0 -6
- package/src/monitor/thread-bindings.persona.test.ts +0 -34
- package/src/monitor/thread-bindings.persona.ts +0 -25
- package/src/monitor/thread-bindings.session-adapter.ts +0 -229
- package/src/monitor/thread-bindings.session-shared.ts +0 -59
- package/src/monitor/thread-bindings.session-updates.ts +0 -35
- package/src/monitor/thread-bindings.shared-state.test.ts +0 -36
- package/src/monitor/thread-bindings.state.ts +0 -540
- package/src/monitor/thread-bindings.ts +0 -48
- package/src/monitor/thread-bindings.types.ts +0 -83
- package/src/monitor/thread-channel-context.ts +0 -112
- package/src/monitor/thread-session-close.test.ts +0 -180
- package/src/monitor/thread-session-close.ts +0 -63
- package/src/monitor/thread-title.generate.test.ts +0 -197
- package/src/monitor/thread-title.test.ts +0 -31
- package/src/monitor/thread-title.ts +0 -181
- package/src/monitor/threading.auto-thread.test.ts +0 -327
- package/src/monitor/threading.auto-thread.ts +0 -287
- package/src/monitor/threading.cache.ts +0 -45
- package/src/monitor/threading.parent-info.test.ts +0 -156
- package/src/monitor/threading.starter.test.ts +0 -260
- package/src/monitor/threading.starter.ts +0 -287
- package/src/monitor/threading.ts +0 -20
- package/src/monitor/threading.types.ts +0 -102
- package/src/monitor/timeouts.ts +0 -84
- package/src/monitor/typing.test.ts +0 -42
- package/src/monitor/typing.ts +0 -17
- package/src/monitor.gateway.test.ts +0 -187
- package/src/monitor.gateway.ts +0 -75
- package/src/monitor.test.ts +0 -1397
- package/src/monitor.ts +0 -28
- package/src/normalize.test.ts +0 -56
- package/src/normalize.ts +0 -86
- package/src/outbound-adapter.interactive-order.test.ts +0 -64
- package/src/outbound-adapter.test-harness.ts +0 -207
- package/src/outbound-adapter.test.ts +0 -696
- package/src/outbound-adapter.ts +0 -291
- package/src/outbound-approval.ts +0 -29
- package/src/outbound-components.ts +0 -81
- package/src/outbound-payload.contract.test.ts +0 -38
- package/src/outbound-payload.ts +0 -134
- package/src/outbound-send-context.ts +0 -92
- package/src/outbound-session-route.test.ts +0 -34
- package/src/outbound-session-route.ts +0 -72
- package/src/pluralkit.test.ts +0 -67
- package/src/pluralkit.ts +0 -58
- package/src/preview-streaming.ts +0 -32
- package/src/probe.intents.test.ts +0 -94
- package/src/probe.parse-token.test.ts +0 -43
- package/src/probe.runtime.ts +0 -1
- package/src/probe.ts +0 -237
- package/src/proxy-fetch.ts +0 -92
- package/src/proxy-request-client.test.ts +0 -78
- package/src/proxy-request-client.ts +0 -21
- package/src/recipient-resolution.ts +0 -39
- package/src/resolve-allowlist-common.test.ts +0 -36
- package/src/resolve-allowlist-common.ts +0 -39
- package/src/resolve-channels.test.ts +0 -340
- package/src/resolve-channels.ts +0 -369
- package/src/resolve-users.test.ts +0 -222
- package/src/resolve-users.ts +0 -184
- package/src/retry.test.ts +0 -83
- package/src/retry.ts +0 -98
- package/src/runtime-api.ts +0 -64
- package/src/runtime.ts +0 -23
- package/src/secret-config-contract.ts +0 -140
- package/src/security-audit.runtime.ts +0 -1
- package/src/security-audit.test.ts +0 -246
- package/src/security-audit.ts +0 -208
- package/src/security-contract.ts +0 -47
- package/src/security-doctor.test.ts +0 -25
- package/src/security-doctor.ts +0 -20
- package/src/security.ts +0 -60
- package/src/send-target-parsing.ts +0 -14
- package/src/send.channels.ts +0 -139
- package/src/send.components.test.ts +0 -275
- package/src/send.components.ts +0 -381
- package/src/send.creates-thread.test.ts +0 -643
- package/src/send.emojis-stickers.ts +0 -57
- package/src/send.guild.ts +0 -170
- package/src/send.message-request.ts +0 -97
- package/src/send.messages.test.ts +0 -53
- package/src/send.messages.ts +0 -225
- package/src/send.outbound.ts +0 -413
- package/src/send.permissions.authz.test.ts +0 -188
- package/src/send.permissions.ts +0 -283
- package/src/send.reactions.ts +0 -155
- package/src/send.sends-basic-channel-messages.test.ts +0 -941
- package/src/send.shared.ts +0 -447
- package/src/send.test-harness.ts +0 -56
- package/src/send.ts +0 -82
- package/src/send.types.ts +0 -188
- package/src/send.typing.test.ts +0 -41
- package/src/send.typing.ts +0 -9
- package/src/send.voice.ts +0 -134
- package/src/send.webhook-activity.test.ts +0 -105
- package/src/send.webhook.proxy.test.ts +0 -191
- package/src/send.webhook.ts +0 -133
- package/src/session-contract.ts +0 -3
- package/src/session-key-normalization.test.ts +0 -44
- package/src/session-key-normalization.ts +0 -47
- package/src/setup-account-state.test.ts +0 -91
- package/src/setup-account-state.ts +0 -144
- package/src/setup-adapter.ts +0 -12
- package/src/setup-core.ts +0 -212
- package/src/setup-runtime-helpers.ts +0 -10
- package/src/setup-surface.test.ts +0 -137
- package/src/setup-surface.ts +0 -129
- package/src/shared-interactive.test.ts +0 -153
- package/src/shared-interactive.ts +0 -124
- package/src/shared.test.ts +0 -165
- package/src/shared.ts +0 -190
- package/src/status-issues.test.ts +0 -70
- package/src/status-issues.ts +0 -169
- package/src/subagent-hooks.test.ts +0 -432
- package/src/subagent-hooks.ts +0 -214
- package/src/target-parsing.ts +0 -53
- package/src/target-resolver.ts +0 -129
- package/src/targets.test.ts +0 -367
- package/src/targets.ts +0 -12
- package/src/test-http-helpers.ts +0 -10
- package/src/test-support/component-runtime.ts +0 -190
- package/src/test-support/config.ts +0 -7
- package/src/test-support/configured-binding-runtime.ts +0 -29
- package/src/test-support/partial-channel.ts +0 -26
- package/src/test-support/provider.test-support.ts +0 -545
- package/src/token.test.ts +0 -107
- package/src/token.ts +0 -60
- package/src/ui-colors.ts +0 -27
- package/src/ui.ts +0 -20
- package/src/voice/access.test.ts +0 -217
- package/src/voice/access.ts +0 -124
- package/src/voice/audio.ts +0 -173
- package/src/voice/capture-state.test.ts +0 -48
- package/src/voice/capture-state.ts +0 -120
- package/src/voice/command.test.ts +0 -164
- package/src/voice/command.ts +0 -283
- package/src/voice/config.ts +0 -8
- package/src/voice/manager.e2e.test.ts +0 -928
- package/src/voice/manager.ready-listener.test.ts +0 -37
- package/src/voice/manager.runtime.ts +0 -11
- package/src/voice/manager.ts +0 -691
- package/src/voice/prompt.test.ts +0 -16
- package/src/voice/prompt.ts +0 -17
- package/src/voice/receive-recovery.test.ts +0 -79
- package/src/voice/receive-recovery.ts +0 -159
- package/src/voice/sanitize.test.ts +0 -34
- package/src/voice/sanitize.ts +0 -32
- package/src/voice/sdk-runtime.ts +0 -14
- package/src/voice/segment.ts +0 -156
- package/src/voice/session.ts +0 -50
- package/src/voice/speaker-context.ts +0 -127
- package/src/voice/tts.ts +0 -125
- package/src/voice-message.test.ts +0 -234
- package/src/voice-message.ts +0 -444
- package/subagent-hooks-api.ts +0 -27
- package/test-api.ts +0 -4
- package/thread-binding-api.ts +0 -1
- package/timeouts.ts +0 -6
- package/tsconfig.json +0 -16
|
@@ -0,0 +1,1124 @@
|
|
|
1
|
+
import { f as resolveDiscordMaxLinesPerMessage } from "./accounts-BKnkNaoA.js";
|
|
2
|
+
import { a as chunkDiscordTextWithMode, s as resolveDiscordChannelId } from "./normalize-B-ktw-T_.js";
|
|
3
|
+
import { $ as createChannelMessage, it as editChannelMessage, nt as deleteChannelMessage, t as discord_exports } from "./discord-D1kDh0X_.js";
|
|
4
|
+
import { N as createDiscordRestClient, P as createDiscordRuntimeAccountContext, d as resolveDiscordTargetChannelId } from "./send.shared-Db0opnak.js";
|
|
5
|
+
import { i as resolveTimestampMs } from "./format-D8TsaXxW.js";
|
|
6
|
+
import { a as normalizeDiscordSlug, r as normalizeDiscordAllowList } from "./allow-list-ek-1hMKN.js";
|
|
7
|
+
import { a as removeReactionDiscord, f as editMessageDiscord, r as reactMessageDiscord } from "./send-B_frVn_Q.js";
|
|
8
|
+
import "./targets-kKlbZ4ai.js";
|
|
9
|
+
import { t as resolveDiscordConversationIdentity } from "./conversation-identity-BN9wSmxJ.js";
|
|
10
|
+
import { t as DISCORD_TEXT_CHUNK_LIMIT } from "./outbound-adapter-DJf9_sfH.js";
|
|
11
|
+
import { t as resolveDiscordPreviewStreamMode } from "./preview-streaming-C0O92Qqz.js";
|
|
12
|
+
import { n as DISCORD_ATTACHMENT_TOTAL_TIMEOUT_MS, t as DISCORD_ATTACHMENT_IDLE_TIMEOUT_MS } from "./timeouts-C7jeTtGs.js";
|
|
13
|
+
import { a as resolveForwardedMediaList, i as buildDiscordMediaPayload, o as resolveMediaList, r as resolveDiscordMessageText } from "./message-utils-Dmgu-7fC.js";
|
|
14
|
+
import { a as resolveDiscordThreadStarter, n as resolveDiscordAutoThreadReplyPlan } from "./threading-CWhdYHVx.js";
|
|
15
|
+
import { t as sendTyping } from "./typing-CJiowRTZ.js";
|
|
16
|
+
import { n as buildDiscordInboundAccessContext, r as createDiscordSupplementalContextAccessChecker } from "./inbound-context-e_oBBJtF.js";
|
|
17
|
+
import { i as resolveReplyContext, n as buildDirectLabel, r as buildGuildLabel, t as deliverDiscordReply } from "./reply-delivery-D9So77a6.js";
|
|
18
|
+
import { convertMarkdownTables, stripInlineDirectiveTagsForDelivery, stripReasoningTagsFromText, truncateUtf16Safe } from "openclaw/plugin-sdk/text-runtime";
|
|
19
|
+
import { buildAgentSessionKey, normalizeAccountId, resolveAccountEntry, resolveThreadSessionKeys } from "openclaw/plugin-sdk/routing";
|
|
20
|
+
import { getAgentScopedMediaLocalRoots } from "openclaw/plugin-sdk/media-runtime";
|
|
21
|
+
import { resolveSendableOutboundReplyParts } from "openclaw/plugin-sdk/reply-payload";
|
|
22
|
+
import { resolveChunkMode, resolveTextChunkLimit } from "openclaw/plugin-sdk/reply-chunking";
|
|
23
|
+
import { danger, logVerbose, shouldLogVerbose } from "openclaw/plugin-sdk/runtime-env";
|
|
24
|
+
import { formatErrorMessage } from "openclaw/plugin-sdk/error-runtime";
|
|
25
|
+
import { resolveMarkdownTableMode } from "openclaw/plugin-sdk/markdown-table-runtime";
|
|
26
|
+
import { recordInboundSession, resolvePinnedMainDmOwnerFromAllowlist } from "openclaw/plugin-sdk/conversation-runtime";
|
|
27
|
+
import { EmbeddedBlockChunker, resolveAckReaction, resolveHumanDelayConfig } from "openclaw/plugin-sdk/agent-runtime";
|
|
28
|
+
import { isDangerousNameMatchingEnabled } from "openclaw/plugin-sdk/dangerous-name-runtime";
|
|
29
|
+
import { evaluateSupplementalContextVisibility } from "openclaw/plugin-sdk/security-runtime";
|
|
30
|
+
import { readSessionUpdatedAt, resolveStorePath } from "openclaw/plugin-sdk/session-store-runtime";
|
|
31
|
+
import { formatInboundEnvelope, resolveEnvelopeFormatOptions } from "openclaw/plugin-sdk/channel-inbound";
|
|
32
|
+
import { createFinalizableDraftLifecycle, deliverFinalizableDraftPreview } from "openclaw/plugin-sdk/channel-lifecycle";
|
|
33
|
+
import { createChannelReplyPipeline, resolveChannelSourceReplyDeliveryMode } from "openclaw/plugin-sdk/channel-reply-pipeline";
|
|
34
|
+
import { resolveChannelStreamingBlockEnabled, resolveChannelStreamingPreviewChunk, resolveChannelStreamingPreviewToolProgress } from "openclaw/plugin-sdk/channel-streaming";
|
|
35
|
+
import { finalizeInboundContext } from "openclaw/plugin-sdk/reply-dispatch-runtime";
|
|
36
|
+
import { hasFinalInboundReplyDispatch, runInboundReplyTurn } from "openclaw/plugin-sdk/inbound-reply-dispatch";
|
|
37
|
+
import { buildPendingHistoryContextFromMap } from "openclaw/plugin-sdk/reply-history";
|
|
38
|
+
import { DEFAULT_TIMING, createStatusReactionController, logAckFailure, logTypingFailure, shouldAckReaction } from "openclaw/plugin-sdk/channel-feedback";
|
|
39
|
+
import { resolveChannelContextVisibilityMode } from "openclaw/plugin-sdk/context-visibility-runtime";
|
|
40
|
+
//#region extensions/discord/src/monitor/ack-reactions.ts
|
|
41
|
+
function createDiscordAckReactionContext(params) {
|
|
42
|
+
return {
|
|
43
|
+
rest: params.rest,
|
|
44
|
+
...createDiscordRuntimeAccountContext({
|
|
45
|
+
cfg: params.cfg,
|
|
46
|
+
accountId: params.accountId
|
|
47
|
+
})
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
function createDiscordAckReactionAdapter(params) {
|
|
51
|
+
return {
|
|
52
|
+
setReaction: async (emoji) => {
|
|
53
|
+
await reactMessageDiscord(params.channelId, params.messageId, emoji, params.reactionContext);
|
|
54
|
+
},
|
|
55
|
+
removeReaction: async (emoji) => {
|
|
56
|
+
await removeReactionDiscord(params.channelId, params.messageId, emoji, params.reactionContext);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
function queueInitialDiscordAckReaction(params) {
|
|
61
|
+
if (params.enabled) {
|
|
62
|
+
params.statusReactions.setQueued();
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
if (!params.shouldSendAckReaction || !params.ackReaction) return;
|
|
66
|
+
params.reactionAdapter.setReaction(params.ackReaction).catch((err) => {
|
|
67
|
+
logAckFailure({
|
|
68
|
+
log: logVerbose,
|
|
69
|
+
channel: "discord",
|
|
70
|
+
target: params.target,
|
|
71
|
+
error: err
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
//#endregion
|
|
76
|
+
//#region extensions/discord/src/monitor/message-handler.context.ts
|
|
77
|
+
function normalizeDiscordDmOwnerEntry(entry) {
|
|
78
|
+
const candidate = normalizeDiscordAllowList([entry], [
|
|
79
|
+
"discord:",
|
|
80
|
+
"user:",
|
|
81
|
+
"pk:"
|
|
82
|
+
])?.ids.values().next().value;
|
|
83
|
+
return typeof candidate === "string" && /^\d+$/.test(candidate) ? candidate : void 0;
|
|
84
|
+
}
|
|
85
|
+
async function buildDiscordMessageProcessContext(params) {
|
|
86
|
+
const { ctx, text, mediaList } = params;
|
|
87
|
+
const { cfg, discordConfig, accountId, runtime, guildHistories, historyLimit, replyToMode, message, author, sender, canonicalMessageId, data, client, channelInfo, channelName, messageChannelId, isGuildMessage, isDirectMessage, baseText, preflightAudioTranscript, threadChannel, threadParentId, threadParentName, threadParentType, threadName, displayChannelSlug, guildInfo, guildSlug, memberRoleIds, channelConfig, baseSessionKey, boundSessionKey, route, commandAuthorized } = ctx;
|
|
88
|
+
const fromLabel = isDirectMessage ? buildDirectLabel(author) : buildGuildLabel({
|
|
89
|
+
guild: data.guild ?? void 0,
|
|
90
|
+
channelName: channelName ?? messageChannelId,
|
|
91
|
+
channelId: messageChannelId
|
|
92
|
+
});
|
|
93
|
+
const senderLabel = sender.label;
|
|
94
|
+
const isForumParent = threadParentType === discord_exports.ChannelType.GuildForum || threadParentType === discord_exports.ChannelType.GuildMedia;
|
|
95
|
+
const forumParentSlug = isForumParent && threadParentName ? normalizeDiscordSlug(threadParentName) : "";
|
|
96
|
+
const threadChannelId = threadChannel?.id;
|
|
97
|
+
const threadParentInheritanceEnabled = discordConfig?.thread?.inheritParent ?? false;
|
|
98
|
+
const forumContextLine = Boolean(threadChannelId && isForumParent && forumParentSlug) && message.id === threadChannelId ? `[Forum parent: #${forumParentSlug}]` : null;
|
|
99
|
+
const groupChannel = isGuildMessage && displayChannelSlug ? `#${displayChannelSlug}` : void 0;
|
|
100
|
+
const groupSubject = isDirectMessage ? void 0 : groupChannel;
|
|
101
|
+
const senderName = sender.isPluralKit ? sender.name ?? author.username : data.member?.nickname ?? author.globalName ?? author.username;
|
|
102
|
+
const senderUsername = sender.isPluralKit ? sender.tag ?? sender.name ?? author.username : author.username;
|
|
103
|
+
const { groupSystemPrompt, ownerAllowFrom, untrustedContext } = buildDiscordInboundAccessContext({
|
|
104
|
+
channelConfig,
|
|
105
|
+
guildInfo,
|
|
106
|
+
sender: {
|
|
107
|
+
id: sender.id,
|
|
108
|
+
name: sender.name,
|
|
109
|
+
tag: sender.tag
|
|
110
|
+
},
|
|
111
|
+
allowNameMatching: isDangerousNameMatchingEnabled(discordConfig),
|
|
112
|
+
isGuild: isGuildMessage,
|
|
113
|
+
channelTopic: channelInfo?.topic,
|
|
114
|
+
messageBody: text
|
|
115
|
+
});
|
|
116
|
+
const pinnedMainDmOwner = isDirectMessage ? resolvePinnedMainDmOwnerFromAllowlist({
|
|
117
|
+
dmScope: cfg.session?.dmScope,
|
|
118
|
+
allowFrom: channelConfig?.users ?? guildInfo?.users,
|
|
119
|
+
normalizeEntry: normalizeDiscordDmOwnerEntry
|
|
120
|
+
}) : null;
|
|
121
|
+
const contextVisibilityMode = resolveChannelContextVisibilityMode({
|
|
122
|
+
cfg,
|
|
123
|
+
channel: "discord",
|
|
124
|
+
accountId
|
|
125
|
+
});
|
|
126
|
+
const isSupplementalContextSenderAllowed = createDiscordSupplementalContextAccessChecker({
|
|
127
|
+
channelConfig,
|
|
128
|
+
guildInfo,
|
|
129
|
+
allowNameMatching: isDangerousNameMatchingEnabled(discordConfig),
|
|
130
|
+
isGuild: isGuildMessage
|
|
131
|
+
});
|
|
132
|
+
const storePath = resolveStorePath(cfg.session?.store, { agentId: route.agentId });
|
|
133
|
+
const envelopeOptions = resolveEnvelopeFormatOptions(cfg);
|
|
134
|
+
const previousTimestamp = readSessionUpdatedAt({
|
|
135
|
+
storePath,
|
|
136
|
+
sessionKey: route.sessionKey
|
|
137
|
+
});
|
|
138
|
+
let combinedBody = formatInboundEnvelope({
|
|
139
|
+
channel: "Discord",
|
|
140
|
+
from: fromLabel,
|
|
141
|
+
timestamp: resolveTimestampMs(message.timestamp),
|
|
142
|
+
body: text,
|
|
143
|
+
chatType: isDirectMessage ? "direct" : "channel",
|
|
144
|
+
senderLabel,
|
|
145
|
+
previousTimestamp,
|
|
146
|
+
envelope: envelopeOptions
|
|
147
|
+
});
|
|
148
|
+
const shouldIncludeChannelHistory = !isDirectMessage && !(isGuildMessage && channelConfig?.autoThread && !threadChannel);
|
|
149
|
+
if (shouldIncludeChannelHistory) combinedBody = buildPendingHistoryContextFromMap({
|
|
150
|
+
historyMap: guildHistories,
|
|
151
|
+
historyKey: messageChannelId,
|
|
152
|
+
limit: historyLimit,
|
|
153
|
+
currentMessage: combinedBody,
|
|
154
|
+
formatEntry: (entry) => formatInboundEnvelope({
|
|
155
|
+
channel: "Discord",
|
|
156
|
+
from: fromLabel,
|
|
157
|
+
timestamp: entry.timestamp,
|
|
158
|
+
body: `${entry.body} [id:${entry.messageId ?? "unknown"} channel:${messageChannelId}]`,
|
|
159
|
+
chatType: "channel",
|
|
160
|
+
senderLabel: entry.sender,
|
|
161
|
+
envelope: envelopeOptions
|
|
162
|
+
})
|
|
163
|
+
});
|
|
164
|
+
const replyContext = resolveReplyContext(message, resolveDiscordMessageText);
|
|
165
|
+
const replyVisibility = replyContext ? evaluateSupplementalContextVisibility({
|
|
166
|
+
mode: contextVisibilityMode,
|
|
167
|
+
kind: "quote",
|
|
168
|
+
senderAllowed: isSupplementalContextSenderAllowed({
|
|
169
|
+
id: replyContext.senderId,
|
|
170
|
+
name: replyContext.senderName,
|
|
171
|
+
tag: replyContext.senderTag,
|
|
172
|
+
memberRoleIds: replyContext.memberRoleIds
|
|
173
|
+
})
|
|
174
|
+
}) : null;
|
|
175
|
+
const filteredReplyContext = replyContext && replyVisibility?.include ? replyContext : null;
|
|
176
|
+
if (replyContext && !filteredReplyContext && isGuildMessage) logVerbose(`discord: drop reply context (mode=${contextVisibilityMode})`);
|
|
177
|
+
if (forumContextLine) combinedBody = `${combinedBody}\n${forumContextLine}`;
|
|
178
|
+
let threadStarterBody;
|
|
179
|
+
let threadLabel;
|
|
180
|
+
let parentSessionKey;
|
|
181
|
+
let modelParentSessionKey;
|
|
182
|
+
if (threadChannel) {
|
|
183
|
+
if (channelConfig?.includeThreadStarter !== false) {
|
|
184
|
+
const starter = await resolveDiscordThreadStarter({
|
|
185
|
+
channel: threadChannel,
|
|
186
|
+
client,
|
|
187
|
+
parentId: threadParentId,
|
|
188
|
+
parentType: threadParentType,
|
|
189
|
+
resolveTimestampMs
|
|
190
|
+
});
|
|
191
|
+
if (starter?.text) if (evaluateSupplementalContextVisibility({
|
|
192
|
+
mode: contextVisibilityMode,
|
|
193
|
+
kind: "thread",
|
|
194
|
+
senderAllowed: isSupplementalContextSenderAllowed({
|
|
195
|
+
id: starter.authorId,
|
|
196
|
+
name: starter.authorName ?? starter.author,
|
|
197
|
+
tag: starter.authorTag,
|
|
198
|
+
memberRoleIds: starter.memberRoleIds
|
|
199
|
+
})
|
|
200
|
+
}).include) threadStarterBody = starter.text;
|
|
201
|
+
else logVerbose(`discord: drop thread starter context (mode=${contextVisibilityMode})`);
|
|
202
|
+
}
|
|
203
|
+
const parentName = threadParentName ?? "parent";
|
|
204
|
+
threadLabel = threadName ? `Discord thread #${normalizeDiscordSlug(parentName)} › ${threadName}` : `Discord thread #${normalizeDiscordSlug(parentName)}`;
|
|
205
|
+
if (threadParentId) {
|
|
206
|
+
parentSessionKey = buildAgentSessionKey({
|
|
207
|
+
agentId: route.agentId,
|
|
208
|
+
channel: route.channel,
|
|
209
|
+
peer: {
|
|
210
|
+
kind: "channel",
|
|
211
|
+
id: threadParentId
|
|
212
|
+
}
|
|
213
|
+
});
|
|
214
|
+
modelParentSessionKey = parentSessionKey;
|
|
215
|
+
}
|
|
216
|
+
if (!threadParentInheritanceEnabled) parentSessionKey = void 0;
|
|
217
|
+
}
|
|
218
|
+
const mediaPayload = buildDiscordMediaPayload(mediaList);
|
|
219
|
+
const preflightAudioIndex = preflightAudioTranscript === void 0 ? -1 : mediaList.findIndex((media) => media.contentType?.startsWith("audio/"));
|
|
220
|
+
const threadKeys = resolveThreadSessionKeys({
|
|
221
|
+
baseSessionKey,
|
|
222
|
+
threadId: threadChannel ? messageChannelId : void 0,
|
|
223
|
+
parentSessionKey,
|
|
224
|
+
useSuffix: false
|
|
225
|
+
});
|
|
226
|
+
const replyPlan = await resolveDiscordAutoThreadReplyPlan({
|
|
227
|
+
client,
|
|
228
|
+
message,
|
|
229
|
+
messageChannelId,
|
|
230
|
+
isGuildMessage,
|
|
231
|
+
channelConfig,
|
|
232
|
+
threadChannel,
|
|
233
|
+
channelType: channelInfo?.type,
|
|
234
|
+
channelName: channelInfo?.name,
|
|
235
|
+
channelDescription: channelInfo?.topic,
|
|
236
|
+
baseText: baseText ?? "",
|
|
237
|
+
combinedBody,
|
|
238
|
+
replyToMode,
|
|
239
|
+
agentId: route.agentId,
|
|
240
|
+
channel: route.channel,
|
|
241
|
+
cfg,
|
|
242
|
+
threadParentInheritanceEnabled
|
|
243
|
+
});
|
|
244
|
+
const deliverTarget = replyPlan.deliverTarget;
|
|
245
|
+
const replyTarget = replyPlan.replyTarget;
|
|
246
|
+
const replyReference = replyPlan.replyReference;
|
|
247
|
+
const autoThreadContext = replyPlan.autoThreadContext;
|
|
248
|
+
const effectiveFrom = isDirectMessage ? `discord:${author.id}` : autoThreadContext?.From ?? `discord:channel:${messageChannelId}`;
|
|
249
|
+
const dmConversationTarget = isDirectMessage ? resolveDiscordConversationIdentity({
|
|
250
|
+
isDirectMessage,
|
|
251
|
+
userId: author.id
|
|
252
|
+
}) : void 0;
|
|
253
|
+
const effectiveTo = autoThreadContext?.To ?? dmConversationTarget ?? replyTarget;
|
|
254
|
+
if (!effectiveTo) {
|
|
255
|
+
runtime.error?.(danger("discord: missing reply target"));
|
|
256
|
+
return null;
|
|
257
|
+
}
|
|
258
|
+
const lastRouteTo = dmConversationTarget ?? effectiveTo;
|
|
259
|
+
const inboundHistory = shouldIncludeChannelHistory && historyLimit > 0 ? (guildHistories.get(messageChannelId) ?? []).map((entry) => ({
|
|
260
|
+
sender: entry.sender,
|
|
261
|
+
body: entry.body,
|
|
262
|
+
timestamp: entry.timestamp
|
|
263
|
+
})) : void 0;
|
|
264
|
+
const originatingTo = autoThreadContext?.OriginatingTo ?? dmConversationTarget ?? replyTarget;
|
|
265
|
+
const effectiveSessionKey = boundSessionKey ?? autoThreadContext?.SessionKey ?? threadKeys.sessionKey;
|
|
266
|
+
const effectivePreviousTimestamp = effectiveSessionKey === route.sessionKey ? previousTimestamp : readSessionUpdatedAt({
|
|
267
|
+
storePath,
|
|
268
|
+
sessionKey: effectiveSessionKey
|
|
269
|
+
});
|
|
270
|
+
const ctxPayload = finalizeInboundContext({
|
|
271
|
+
Body: combinedBody,
|
|
272
|
+
BodyForAgent: preflightAudioTranscript ?? baseText ?? text,
|
|
273
|
+
InboundHistory: inboundHistory,
|
|
274
|
+
RawBody: preflightAudioTranscript ?? baseText,
|
|
275
|
+
CommandBody: preflightAudioTranscript ?? baseText,
|
|
276
|
+
...preflightAudioTranscript !== void 0 ? { Transcript: preflightAudioTranscript } : {},
|
|
277
|
+
From: effectiveFrom,
|
|
278
|
+
To: effectiveTo,
|
|
279
|
+
SessionKey: effectiveSessionKey,
|
|
280
|
+
AccountId: route.accountId,
|
|
281
|
+
ChatType: isDirectMessage ? "direct" : "channel",
|
|
282
|
+
ConversationLabel: fromLabel,
|
|
283
|
+
SenderName: senderName,
|
|
284
|
+
SenderId: sender.id,
|
|
285
|
+
SenderUsername: senderUsername,
|
|
286
|
+
SenderTag: sender.tag,
|
|
287
|
+
GroupSubject: groupSubject,
|
|
288
|
+
GroupChannel: groupChannel,
|
|
289
|
+
MemberRoleIds: memberRoleIds,
|
|
290
|
+
UntrustedContext: untrustedContext,
|
|
291
|
+
GroupSystemPrompt: isGuildMessage ? groupSystemPrompt : void 0,
|
|
292
|
+
GroupSpace: isGuildMessage ? (guildInfo?.id ?? guildSlug) || void 0 : void 0,
|
|
293
|
+
OwnerAllowFrom: ownerAllowFrom,
|
|
294
|
+
Provider: "discord",
|
|
295
|
+
Surface: "discord",
|
|
296
|
+
WasMentioned: ctx.effectiveWasMentioned,
|
|
297
|
+
MessageSid: canonicalMessageId ?? message.id,
|
|
298
|
+
...canonicalMessageId && canonicalMessageId !== message.id ? { MessageSidFull: message.id } : {},
|
|
299
|
+
ReplyToId: filteredReplyContext?.id,
|
|
300
|
+
ReplyToBody: filteredReplyContext?.body,
|
|
301
|
+
ReplyToSender: filteredReplyContext?.sender,
|
|
302
|
+
ParentSessionKey: autoThreadContext?.ParentSessionKey ?? threadKeys.parentSessionKey,
|
|
303
|
+
ModelParentSessionKey: autoThreadContext?.ModelParentSessionKey ?? modelParentSessionKey ?? void 0,
|
|
304
|
+
MessageThreadId: threadChannel?.id ?? autoThreadContext?.createdThreadId ?? void 0,
|
|
305
|
+
ThreadStarterBody: !effectivePreviousTimestamp ? threadStarterBody : void 0,
|
|
306
|
+
ThreadLabel: threadLabel,
|
|
307
|
+
Timestamp: resolveTimestampMs(message.timestamp),
|
|
308
|
+
...mediaPayload,
|
|
309
|
+
...preflightAudioIndex >= 0 ? { MediaTranscribedIndexes: [preflightAudioIndex] } : {},
|
|
310
|
+
CommandAuthorized: commandAuthorized,
|
|
311
|
+
CommandSource: "text",
|
|
312
|
+
OriginatingChannel: "discord",
|
|
313
|
+
OriginatingTo: originatingTo
|
|
314
|
+
});
|
|
315
|
+
const persistedSessionKey = ctxPayload.SessionKey ?? route.sessionKey;
|
|
316
|
+
if (shouldLogVerbose()) {
|
|
317
|
+
const preview = truncateUtf16Safe(combinedBody, 200).replace(/\n/g, "\\n");
|
|
318
|
+
logVerbose(`discord inbound: channel=${messageChannelId} deliver=${deliverTarget} from=${ctxPayload.From} preview="${preview}"`);
|
|
319
|
+
}
|
|
320
|
+
return {
|
|
321
|
+
ctxPayload,
|
|
322
|
+
persistedSessionKey,
|
|
323
|
+
turn: {
|
|
324
|
+
storePath,
|
|
325
|
+
record: {
|
|
326
|
+
updateLastRoute: {
|
|
327
|
+
sessionKey: persistedSessionKey,
|
|
328
|
+
channel: "discord",
|
|
329
|
+
to: lastRouteTo,
|
|
330
|
+
accountId: route.accountId,
|
|
331
|
+
mainDmOwnerPin: isDirectMessage && persistedSessionKey === route.mainSessionKey && pinnedMainDmOwner ? {
|
|
332
|
+
ownerRecipient: pinnedMainDmOwner,
|
|
333
|
+
senderRecipient: author.id,
|
|
334
|
+
onSkip: ({ ownerRecipient, senderRecipient }) => {
|
|
335
|
+
logVerbose(`discord: skip main-session last route for ${senderRecipient} (pinned owner ${ownerRecipient})`);
|
|
336
|
+
}
|
|
337
|
+
} : void 0
|
|
338
|
+
},
|
|
339
|
+
onRecordError: (err) => {
|
|
340
|
+
logVerbose(`discord: failed updating session meta: ${String(err)}`);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
},
|
|
344
|
+
replyPlan,
|
|
345
|
+
deliverTarget,
|
|
346
|
+
replyTarget,
|
|
347
|
+
replyReference
|
|
348
|
+
};
|
|
349
|
+
}
|
|
350
|
+
//#endregion
|
|
351
|
+
//#region extensions/discord/src/draft-chunking.ts
|
|
352
|
+
const DEFAULT_DISCORD_DRAFT_STREAM_MIN = 200;
|
|
353
|
+
const DEFAULT_DISCORD_DRAFT_STREAM_MAX = 800;
|
|
354
|
+
function resolveDiscordDraftStreamingChunking(cfg, accountId) {
|
|
355
|
+
const textLimit = resolveTextChunkLimit(cfg, "discord", accountId, { fallbackLimit: DISCORD_TEXT_CHUNK_LIMIT });
|
|
356
|
+
const normalizedAccountId = normalizeAccountId(accountId);
|
|
357
|
+
const draftCfg = resolveChannelStreamingPreviewChunk(resolveAccountEntry(cfg?.channels?.discord?.accounts, normalizedAccountId)) ?? resolveChannelStreamingPreviewChunk(cfg?.channels?.discord);
|
|
358
|
+
const maxRequested = Math.max(1, Math.floor(draftCfg?.maxChars ?? DEFAULT_DISCORD_DRAFT_STREAM_MAX));
|
|
359
|
+
const maxChars = Math.max(1, Math.min(maxRequested, textLimit));
|
|
360
|
+
const minRequested = Math.max(1, Math.floor(draftCfg?.minChars ?? DEFAULT_DISCORD_DRAFT_STREAM_MIN));
|
|
361
|
+
return {
|
|
362
|
+
minChars: Math.min(minRequested, maxChars),
|
|
363
|
+
maxChars,
|
|
364
|
+
breakPreference: draftCfg?.breakPreference === "newline" || draftCfg?.breakPreference === "sentence" ? draftCfg.breakPreference : "paragraph"
|
|
365
|
+
};
|
|
366
|
+
}
|
|
367
|
+
//#endregion
|
|
368
|
+
//#region extensions/discord/src/draft-stream.ts
|
|
369
|
+
/** Discord messages cap at 2000 characters. */
|
|
370
|
+
const DISCORD_STREAM_MAX_CHARS = 2e3;
|
|
371
|
+
const DEFAULT_THROTTLE_MS = 1200;
|
|
372
|
+
const DISCORD_PREVIEW_ALLOWED_MENTIONS = { parse: [] };
|
|
373
|
+
function createDiscordDraftStream(params) {
|
|
374
|
+
const maxChars = Math.min(params.maxChars ?? DISCORD_STREAM_MAX_CHARS, DISCORD_STREAM_MAX_CHARS);
|
|
375
|
+
const throttleMs = Math.max(250, params.throttleMs ?? DEFAULT_THROTTLE_MS);
|
|
376
|
+
const minInitialChars = params.minInitialChars;
|
|
377
|
+
const channelId = params.channelId;
|
|
378
|
+
const rest = params.rest;
|
|
379
|
+
const resolveReplyToMessageId = () => typeof params.replyToMessageId === "function" ? params.replyToMessageId() : params.replyToMessageId;
|
|
380
|
+
const streamState = {
|
|
381
|
+
stopped: false,
|
|
382
|
+
final: false
|
|
383
|
+
};
|
|
384
|
+
let streamMessageId;
|
|
385
|
+
let lastSentText = "";
|
|
386
|
+
const sendOrEditStreamMessage = async (text) => {
|
|
387
|
+
if (streamState.stopped && !streamState.final) return false;
|
|
388
|
+
const trimmed = text.trimEnd();
|
|
389
|
+
if (!trimmed) return false;
|
|
390
|
+
if (trimmed.length > maxChars) {
|
|
391
|
+
streamState.stopped = true;
|
|
392
|
+
params.warn?.(`discord stream preview stopped (text length ${trimmed.length} > ${maxChars})`);
|
|
393
|
+
return false;
|
|
394
|
+
}
|
|
395
|
+
if (trimmed === lastSentText) return true;
|
|
396
|
+
if (streamMessageId === void 0 && minInitialChars != null && !streamState.final) {
|
|
397
|
+
if (trimmed.length < minInitialChars) return false;
|
|
398
|
+
}
|
|
399
|
+
lastSentText = trimmed;
|
|
400
|
+
try {
|
|
401
|
+
if (streamMessageId !== void 0) {
|
|
402
|
+
await editChannelMessage(rest, channelId, streamMessageId, { body: {
|
|
403
|
+
content: trimmed,
|
|
404
|
+
allowed_mentions: DISCORD_PREVIEW_ALLOWED_MENTIONS
|
|
405
|
+
} });
|
|
406
|
+
return true;
|
|
407
|
+
}
|
|
408
|
+
const replyToMessageId = resolveReplyToMessageId()?.trim();
|
|
409
|
+
const messageReference = replyToMessageId ? {
|
|
410
|
+
message_id: replyToMessageId,
|
|
411
|
+
fail_if_not_exists: false
|
|
412
|
+
} : void 0;
|
|
413
|
+
const sentMessageId = (await createChannelMessage(rest, channelId, { body: {
|
|
414
|
+
content: trimmed,
|
|
415
|
+
allowed_mentions: DISCORD_PREVIEW_ALLOWED_MENTIONS,
|
|
416
|
+
...messageReference ? { message_reference: messageReference } : {}
|
|
417
|
+
} }))?.id;
|
|
418
|
+
if (typeof sentMessageId !== "string" || !sentMessageId) {
|
|
419
|
+
streamState.stopped = true;
|
|
420
|
+
params.warn?.("discord stream preview stopped (missing message id from send)");
|
|
421
|
+
return false;
|
|
422
|
+
}
|
|
423
|
+
streamMessageId = sentMessageId;
|
|
424
|
+
return true;
|
|
425
|
+
} catch (err) {
|
|
426
|
+
streamState.stopped = true;
|
|
427
|
+
params.warn?.(`discord stream preview failed: ${formatErrorMessage(err)}`);
|
|
428
|
+
return false;
|
|
429
|
+
}
|
|
430
|
+
};
|
|
431
|
+
const readMessageId = () => streamMessageId;
|
|
432
|
+
const clearMessageId = () => {
|
|
433
|
+
streamMessageId = void 0;
|
|
434
|
+
};
|
|
435
|
+
const isValidStreamMessageId = (value) => typeof value === "string";
|
|
436
|
+
const deleteStreamMessage = async (messageId) => {
|
|
437
|
+
await deleteChannelMessage(rest, channelId, messageId);
|
|
438
|
+
};
|
|
439
|
+
const { loop, update, stop, clear, discardPending, seal } = createFinalizableDraftLifecycle({
|
|
440
|
+
throttleMs,
|
|
441
|
+
state: streamState,
|
|
442
|
+
sendOrEditStreamMessage,
|
|
443
|
+
readMessageId,
|
|
444
|
+
clearMessageId,
|
|
445
|
+
isValidMessageId: isValidStreamMessageId,
|
|
446
|
+
deleteMessage: deleteStreamMessage,
|
|
447
|
+
warn: params.warn,
|
|
448
|
+
warnPrefix: "discord stream preview cleanup failed"
|
|
449
|
+
});
|
|
450
|
+
const forceNewMessage = () => {
|
|
451
|
+
streamMessageId = void 0;
|
|
452
|
+
lastSentText = "";
|
|
453
|
+
loop.resetPending();
|
|
454
|
+
};
|
|
455
|
+
params.log?.(`discord stream preview ready (maxChars=${maxChars}, throttleMs=${throttleMs})`);
|
|
456
|
+
return {
|
|
457
|
+
update,
|
|
458
|
+
flush: loop.flush,
|
|
459
|
+
messageId: () => streamMessageId,
|
|
460
|
+
clear,
|
|
461
|
+
discardPending,
|
|
462
|
+
seal,
|
|
463
|
+
stop,
|
|
464
|
+
forceNewMessage
|
|
465
|
+
};
|
|
466
|
+
}
|
|
467
|
+
//#endregion
|
|
468
|
+
//#region extensions/discord/src/monitor/message-handler.draft-preview.ts
|
|
469
|
+
function createDiscordDraftPreviewController(params) {
|
|
470
|
+
const discordStreamMode = resolveDiscordPreviewStreamMode(params.discordConfig);
|
|
471
|
+
const draftMaxChars = Math.min(params.textLimit, 2e3);
|
|
472
|
+
const accountBlockStreamingEnabled = resolveChannelStreamingBlockEnabled(params.discordConfig) ?? params.cfg.agents?.defaults?.blockStreamingDefault === "on";
|
|
473
|
+
const draftStream = !params.sourceRepliesAreToolOnly && discordStreamMode !== "off" && !accountBlockStreamingEnabled ? createDiscordDraftStream({
|
|
474
|
+
rest: params.deliveryRest,
|
|
475
|
+
channelId: params.deliverChannelId,
|
|
476
|
+
maxChars: draftMaxChars,
|
|
477
|
+
replyToMessageId: () => params.replyReference.peek(),
|
|
478
|
+
minInitialChars: 30,
|
|
479
|
+
throttleMs: 1200,
|
|
480
|
+
log: params.log,
|
|
481
|
+
warn: params.log
|
|
482
|
+
}) : void 0;
|
|
483
|
+
const draftChunking = draftStream && discordStreamMode === "block" ? resolveDiscordDraftStreamingChunking(params.cfg, params.accountId) : void 0;
|
|
484
|
+
const shouldSplitPreviewMessages = discordStreamMode === "block";
|
|
485
|
+
const draftChunker = draftChunking ? new EmbeddedBlockChunker(draftChunking) : void 0;
|
|
486
|
+
let lastPartialText = "";
|
|
487
|
+
let draftText = "";
|
|
488
|
+
let hasStreamedMessage = false;
|
|
489
|
+
let finalizedViaPreviewMessage = false;
|
|
490
|
+
let finalDeliveryHandled = false;
|
|
491
|
+
const previewToolProgressEnabled = Boolean(draftStream) && resolveChannelStreamingPreviewToolProgress(params.discordConfig);
|
|
492
|
+
let previewToolProgressSuppressed = false;
|
|
493
|
+
let previewToolProgressLines = [];
|
|
494
|
+
const resetProgressState = () => {
|
|
495
|
+
lastPartialText = "";
|
|
496
|
+
draftText = "";
|
|
497
|
+
draftChunker?.reset();
|
|
498
|
+
previewToolProgressSuppressed = false;
|
|
499
|
+
previewToolProgressLines = [];
|
|
500
|
+
};
|
|
501
|
+
const forceNewMessageIfNeeded = () => {
|
|
502
|
+
if (shouldSplitPreviewMessages && hasStreamedMessage) {
|
|
503
|
+
params.log("discord: calling forceNewMessage() for draft stream");
|
|
504
|
+
draftStream?.forceNewMessage();
|
|
505
|
+
}
|
|
506
|
+
resetProgressState();
|
|
507
|
+
};
|
|
508
|
+
return {
|
|
509
|
+
draftStream,
|
|
510
|
+
previewToolProgressEnabled,
|
|
511
|
+
get finalizedViaPreviewMessage() {
|
|
512
|
+
return finalizedViaPreviewMessage;
|
|
513
|
+
},
|
|
514
|
+
markFinalDeliveryHandled() {
|
|
515
|
+
finalDeliveryHandled = true;
|
|
516
|
+
},
|
|
517
|
+
markPreviewFinalized() {
|
|
518
|
+
finalizedViaPreviewMessage = true;
|
|
519
|
+
},
|
|
520
|
+
disableBlockStreamingForDraft: draftStream ? true : void 0,
|
|
521
|
+
pushToolProgress(line) {
|
|
522
|
+
if (!draftStream || !previewToolProgressEnabled || previewToolProgressSuppressed) return;
|
|
523
|
+
const normalized = line?.replace(/\s+/g, " ").trim();
|
|
524
|
+
if (!normalized) return;
|
|
525
|
+
if (previewToolProgressLines.at(-1) === normalized) return;
|
|
526
|
+
previewToolProgressLines = [...previewToolProgressLines, normalized].slice(-8);
|
|
527
|
+
const previewText = ["Working…", ...previewToolProgressLines.map((entry) => `• ${entry}`)].join("\n");
|
|
528
|
+
lastPartialText = previewText;
|
|
529
|
+
draftText = previewText;
|
|
530
|
+
hasStreamedMessage = true;
|
|
531
|
+
draftChunker?.reset();
|
|
532
|
+
draftStream.update(previewText);
|
|
533
|
+
},
|
|
534
|
+
resolvePreviewFinalText(text) {
|
|
535
|
+
if (typeof text !== "string") return;
|
|
536
|
+
const formatted = convertMarkdownTables(stripInlineDirectiveTagsForDelivery(text).text, params.tableMode);
|
|
537
|
+
const chunks = chunkDiscordTextWithMode(formatted, {
|
|
538
|
+
maxChars: draftMaxChars,
|
|
539
|
+
maxLines: params.maxLinesPerMessage,
|
|
540
|
+
chunkMode: params.chunkMode
|
|
541
|
+
});
|
|
542
|
+
if (!chunks.length && formatted) chunks.push(formatted);
|
|
543
|
+
if (chunks.length !== 1) return;
|
|
544
|
+
const trimmed = chunks[0].trim();
|
|
545
|
+
if (!trimmed) return;
|
|
546
|
+
const currentPreviewText = discordStreamMode === "block" ? draftText : lastPartialText;
|
|
547
|
+
if (currentPreviewText && currentPreviewText.startsWith(trimmed) && trimmed.length < currentPreviewText.length) return;
|
|
548
|
+
return trimmed;
|
|
549
|
+
},
|
|
550
|
+
updateFromPartial(text) {
|
|
551
|
+
if (!draftStream || !text) return;
|
|
552
|
+
const cleaned = stripInlineDirectiveTagsForDelivery(stripReasoningTagsFromText(text, {
|
|
553
|
+
mode: "strict",
|
|
554
|
+
trim: "both"
|
|
555
|
+
})).text;
|
|
556
|
+
if (!cleaned || cleaned.startsWith("Reasoning:\n")) return;
|
|
557
|
+
if (cleaned === lastPartialText) return;
|
|
558
|
+
previewToolProgressSuppressed = true;
|
|
559
|
+
previewToolProgressLines = [];
|
|
560
|
+
hasStreamedMessage = true;
|
|
561
|
+
if (discordStreamMode === "partial") {
|
|
562
|
+
if (lastPartialText && lastPartialText.startsWith(cleaned) && cleaned.length < lastPartialText.length) return;
|
|
563
|
+
lastPartialText = cleaned;
|
|
564
|
+
draftStream.update(cleaned);
|
|
565
|
+
return;
|
|
566
|
+
}
|
|
567
|
+
let delta = cleaned;
|
|
568
|
+
if (cleaned.startsWith(lastPartialText)) delta = cleaned.slice(lastPartialText.length);
|
|
569
|
+
else {
|
|
570
|
+
draftChunker?.reset();
|
|
571
|
+
draftText = "";
|
|
572
|
+
}
|
|
573
|
+
lastPartialText = cleaned;
|
|
574
|
+
if (!delta) return;
|
|
575
|
+
if (!draftChunker) {
|
|
576
|
+
draftText = cleaned;
|
|
577
|
+
draftStream.update(draftText);
|
|
578
|
+
return;
|
|
579
|
+
}
|
|
580
|
+
draftChunker.append(delta);
|
|
581
|
+
draftChunker.drain({
|
|
582
|
+
force: false,
|
|
583
|
+
emit: (chunk) => {
|
|
584
|
+
draftText += chunk;
|
|
585
|
+
draftStream.update(draftText);
|
|
586
|
+
}
|
|
587
|
+
});
|
|
588
|
+
},
|
|
589
|
+
handleAssistantMessageBoundary: forceNewMessageIfNeeded,
|
|
590
|
+
async flush() {
|
|
591
|
+
if (!draftStream) return;
|
|
592
|
+
if (draftChunker?.hasBuffered()) {
|
|
593
|
+
draftChunker.drain({
|
|
594
|
+
force: true,
|
|
595
|
+
emit: (chunk) => {
|
|
596
|
+
draftText += chunk;
|
|
597
|
+
}
|
|
598
|
+
});
|
|
599
|
+
draftChunker.reset();
|
|
600
|
+
if (draftText) draftStream.update(draftText);
|
|
601
|
+
}
|
|
602
|
+
await draftStream.flush();
|
|
603
|
+
},
|
|
604
|
+
async cleanup() {
|
|
605
|
+
try {
|
|
606
|
+
if (!finalDeliveryHandled) await draftStream?.discardPending();
|
|
607
|
+
if (!finalDeliveryHandled && !finalizedViaPreviewMessage && draftStream?.messageId()) await draftStream.clear();
|
|
608
|
+
} catch (err) {
|
|
609
|
+
params.log(`discord: draft cleanup failed: ${String(err)}`);
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
};
|
|
613
|
+
}
|
|
614
|
+
//#endregion
|
|
615
|
+
//#region extensions/discord/src/monitor/message-handler.process.ts
|
|
616
|
+
function sleep(ms) {
|
|
617
|
+
return new Promise((resolve) => {
|
|
618
|
+
setTimeout(resolve, ms);
|
|
619
|
+
});
|
|
620
|
+
}
|
|
621
|
+
const DISCORD_TYPING_MAX_DURATION_MS = 20 * 6e4;
|
|
622
|
+
let replyRuntimePromise;
|
|
623
|
+
async function loadReplyRuntime() {
|
|
624
|
+
replyRuntimePromise ??= import("openclaw/plugin-sdk/reply-runtime");
|
|
625
|
+
return await replyRuntimePromise;
|
|
626
|
+
}
|
|
627
|
+
function isProcessAborted(abortSignal) {
|
|
628
|
+
return Boolean(abortSignal?.aborted);
|
|
629
|
+
}
|
|
630
|
+
function formatDiscordReplyDeliveryFailure(params) {
|
|
631
|
+
const context = [`target=${params.target}`, params.sessionKey ? `session=${params.sessionKey}` : void 0].filter(Boolean).join(" ");
|
|
632
|
+
return `discord ${params.kind} reply failed (${context}): ${String(params.err)}`;
|
|
633
|
+
}
|
|
634
|
+
function readToolStringArg(args, key) {
|
|
635
|
+
const value = args[key];
|
|
636
|
+
return typeof value === "string" && value.trim() ? value.trim() : void 0;
|
|
637
|
+
}
|
|
638
|
+
function readToolBooleanArg(args, key) {
|
|
639
|
+
return args[key] === true;
|
|
640
|
+
}
|
|
641
|
+
async function processDiscordMessage(ctx, observer) {
|
|
642
|
+
const { cfg, discordConfig, accountId, token, runtime, guildHistories, historyLimit, mediaMaxBytes, textLimit, replyToMode, ackReactionScope, message, messageChannelId, isGuildMessage, isDirectMessage, isGroupDm, messageText, shouldRequireMention, canDetectMention, effectiveWasMentioned, shouldBypassMention, channelConfig, threadBindings, route, discordRestFetch, abortSignal } = ctx;
|
|
643
|
+
if (isProcessAborted(abortSignal)) return;
|
|
644
|
+
const mediaResolveOptions = {
|
|
645
|
+
fetchImpl: discordRestFetch,
|
|
646
|
+
ssrfPolicy: cfg.browser?.ssrfPolicy,
|
|
647
|
+
readIdleTimeoutMs: DISCORD_ATTACHMENT_IDLE_TIMEOUT_MS,
|
|
648
|
+
totalTimeoutMs: DISCORD_ATTACHMENT_TOTAL_TIMEOUT_MS,
|
|
649
|
+
abortSignal
|
|
650
|
+
};
|
|
651
|
+
const mediaList = await resolveMediaList(message, mediaMaxBytes, mediaResolveOptions);
|
|
652
|
+
if (isProcessAborted(abortSignal)) return;
|
|
653
|
+
const forwardedMediaList = await resolveForwardedMediaList(message, mediaMaxBytes, mediaResolveOptions);
|
|
654
|
+
if (isProcessAborted(abortSignal)) return;
|
|
655
|
+
mediaList.push(...forwardedMediaList);
|
|
656
|
+
const text = messageText;
|
|
657
|
+
if (!text) {
|
|
658
|
+
logVerbose("discord: drop message " + message.id + " (empty content)");
|
|
659
|
+
return;
|
|
660
|
+
}
|
|
661
|
+
const boundThreadId = ctx.threadBinding?.conversation?.conversationId?.trim();
|
|
662
|
+
if (boundThreadId && typeof threadBindings.touchThread === "function") threadBindings.touchThread({ threadId: boundThreadId });
|
|
663
|
+
const { createReplyDispatcherWithTyping, dispatchInboundMessage, settleReplyDispatcher } = await loadReplyRuntime();
|
|
664
|
+
const sourceReplyDeliveryMode = resolveChannelSourceReplyDeliveryMode({
|
|
665
|
+
cfg,
|
|
666
|
+
ctx: { ChatType: isGuildMessage ? "channel" : void 0 }
|
|
667
|
+
});
|
|
668
|
+
const sourceRepliesAreToolOnly = sourceReplyDeliveryMode === "message_tool_only";
|
|
669
|
+
const ackReaction = resolveAckReaction(cfg, route.agentId, {
|
|
670
|
+
channel: "discord",
|
|
671
|
+
accountId
|
|
672
|
+
});
|
|
673
|
+
const removeAckAfterReply = cfg.messages?.removeAckAfterReply ?? false;
|
|
674
|
+
const mediaLocalRoots = getAgentScopedMediaLocalRoots(cfg, route.agentId);
|
|
675
|
+
const shouldAckReaction$1 = () => Boolean(ackReaction && shouldAckReaction({
|
|
676
|
+
scope: ackReactionScope,
|
|
677
|
+
isDirect: isDirectMessage,
|
|
678
|
+
isGroup: isGuildMessage || isGroupDm,
|
|
679
|
+
isMentionableGroup: isGuildMessage,
|
|
680
|
+
requireMention: shouldRequireMention,
|
|
681
|
+
canDetectMention,
|
|
682
|
+
effectiveWasMentioned,
|
|
683
|
+
shouldBypassMention
|
|
684
|
+
}));
|
|
685
|
+
const shouldSendAckReaction = shouldAckReaction$1();
|
|
686
|
+
const statusReactionsExplicitlyEnabled = cfg.messages?.statusReactions?.enabled === true;
|
|
687
|
+
const statusReactionsEnabled = shouldSendAckReaction && cfg.messages?.statusReactions?.enabled !== false && (!sourceRepliesAreToolOnly || statusReactionsExplicitlyEnabled);
|
|
688
|
+
const feedbackRest = createDiscordRestClient({
|
|
689
|
+
cfg,
|
|
690
|
+
token,
|
|
691
|
+
accountId
|
|
692
|
+
}).rest;
|
|
693
|
+
const deliveryRest = createDiscordRestClient({
|
|
694
|
+
cfg,
|
|
695
|
+
token,
|
|
696
|
+
accountId
|
|
697
|
+
}).rest;
|
|
698
|
+
const ackReactionContext = createDiscordAckReactionContext({
|
|
699
|
+
rest: feedbackRest,
|
|
700
|
+
cfg,
|
|
701
|
+
accountId
|
|
702
|
+
});
|
|
703
|
+
const discordAdapter = createDiscordAckReactionAdapter({
|
|
704
|
+
channelId: messageChannelId,
|
|
705
|
+
messageId: message.id,
|
|
706
|
+
reactionContext: ackReactionContext
|
|
707
|
+
});
|
|
708
|
+
let statusReactionTarget = `${messageChannelId}/${message.id}`;
|
|
709
|
+
let statusReactionsActive = statusReactionsEnabled;
|
|
710
|
+
let statusReactions = createStatusReactionController({
|
|
711
|
+
enabled: statusReactionsEnabled,
|
|
712
|
+
adapter: discordAdapter,
|
|
713
|
+
initialEmoji: ackReaction,
|
|
714
|
+
emojis: cfg.messages?.statusReactions?.emojis,
|
|
715
|
+
timing: cfg.messages?.statusReactions?.timing,
|
|
716
|
+
onError: (err) => {
|
|
717
|
+
logAckFailure({
|
|
718
|
+
log: logVerbose,
|
|
719
|
+
channel: "discord",
|
|
720
|
+
target: statusReactionTarget,
|
|
721
|
+
error: err
|
|
722
|
+
});
|
|
723
|
+
}
|
|
724
|
+
});
|
|
725
|
+
const resolveTrackedReactionChannelId = async (args) => {
|
|
726
|
+
const target = readToolStringArg(args, "channelId") ?? readToolStringArg(args, "channel_id") ?? readToolStringArg(args, "to");
|
|
727
|
+
if (!target) return messageChannelId;
|
|
728
|
+
try {
|
|
729
|
+
return resolveDiscordChannelId(target);
|
|
730
|
+
} catch {
|
|
731
|
+
return (await resolveDiscordTargetChannelId(target, {
|
|
732
|
+
cfg,
|
|
733
|
+
token,
|
|
734
|
+
accountId
|
|
735
|
+
})).channelId;
|
|
736
|
+
}
|
|
737
|
+
};
|
|
738
|
+
const maybeBindStatusReactionsToToolReaction = async (payload) => {
|
|
739
|
+
if (sourceRepliesAreToolOnly || cfg.messages?.statusReactions?.enabled === false || payload.phase !== "start" || payload.name !== "message" || !payload.args) return;
|
|
740
|
+
const args = payload.args;
|
|
741
|
+
if (readToolStringArg(args, "action")?.toLowerCase() !== "react") return;
|
|
742
|
+
if (!(readToolBooleanArg(args, "trackToolCalls") || readToolBooleanArg(args, "track_tool_calls"))) return;
|
|
743
|
+
const emoji = readToolStringArg(args, "emoji");
|
|
744
|
+
const remove = readToolBooleanArg(args, "remove");
|
|
745
|
+
if (!emoji || remove) return;
|
|
746
|
+
const trackedMessageId = readToolStringArg(args, "messageId") ?? readToolStringArg(args, "message_id") ?? message.id;
|
|
747
|
+
let trackedChannelId;
|
|
748
|
+
try {
|
|
749
|
+
trackedChannelId = await resolveTrackedReactionChannelId(args);
|
|
750
|
+
} catch (err) {
|
|
751
|
+
logAckFailure({
|
|
752
|
+
log: logVerbose,
|
|
753
|
+
channel: "discord",
|
|
754
|
+
target: `${readToolStringArg(args, "to") ?? readToolStringArg(args, "channelId") ?? messageChannelId}/${trackedMessageId}`,
|
|
755
|
+
error: err
|
|
756
|
+
});
|
|
757
|
+
return;
|
|
758
|
+
}
|
|
759
|
+
statusReactionTarget = `${trackedChannelId}/${trackedMessageId}`;
|
|
760
|
+
if (statusReactionsActive) statusReactions.clear();
|
|
761
|
+
statusReactions = createStatusReactionController({
|
|
762
|
+
enabled: true,
|
|
763
|
+
adapter: createDiscordAckReactionAdapter({
|
|
764
|
+
channelId: trackedChannelId,
|
|
765
|
+
messageId: trackedMessageId,
|
|
766
|
+
reactionContext: ackReactionContext
|
|
767
|
+
}),
|
|
768
|
+
initialEmoji: emoji,
|
|
769
|
+
emojis: cfg.messages?.statusReactions?.emojis,
|
|
770
|
+
timing: cfg.messages?.statusReactions?.timing,
|
|
771
|
+
onError: (err) => {
|
|
772
|
+
logAckFailure({
|
|
773
|
+
log: logVerbose,
|
|
774
|
+
channel: "discord",
|
|
775
|
+
target: statusReactionTarget,
|
|
776
|
+
error: err
|
|
777
|
+
});
|
|
778
|
+
}
|
|
779
|
+
});
|
|
780
|
+
statusReactionsActive = true;
|
|
781
|
+
statusReactions.setQueued();
|
|
782
|
+
};
|
|
783
|
+
queueInitialDiscordAckReaction({
|
|
784
|
+
enabled: statusReactionsEnabled,
|
|
785
|
+
shouldSendAckReaction,
|
|
786
|
+
ackReaction,
|
|
787
|
+
statusReactions,
|
|
788
|
+
reactionAdapter: discordAdapter,
|
|
789
|
+
target: `${messageChannelId}/${message.id}`
|
|
790
|
+
});
|
|
791
|
+
const processContext = await buildDiscordMessageProcessContext({
|
|
792
|
+
ctx,
|
|
793
|
+
text,
|
|
794
|
+
mediaList
|
|
795
|
+
});
|
|
796
|
+
if (!processContext) return;
|
|
797
|
+
const { ctxPayload, persistedSessionKey, turn, replyPlan, deliverTarget, replyTarget, replyReference } = processContext;
|
|
798
|
+
observer?.onReplyPlanResolved?.({
|
|
799
|
+
createdThreadId: replyPlan.createdThreadId,
|
|
800
|
+
sessionKey: persistedSessionKey
|
|
801
|
+
});
|
|
802
|
+
const typingChannelId = deliverTarget.startsWith("channel:") ? deliverTarget.slice(8) : messageChannelId;
|
|
803
|
+
const { onModelSelected, ...replyPipeline } = createChannelReplyPipeline({
|
|
804
|
+
cfg,
|
|
805
|
+
agentId: route.agentId,
|
|
806
|
+
channel: "discord",
|
|
807
|
+
accountId: route.accountId,
|
|
808
|
+
typing: {
|
|
809
|
+
start: () => sendTyping({
|
|
810
|
+
rest: feedbackRest,
|
|
811
|
+
channelId: typingChannelId
|
|
812
|
+
}),
|
|
813
|
+
onStartError: (err) => {
|
|
814
|
+
logTypingFailure({
|
|
815
|
+
log: logVerbose,
|
|
816
|
+
channel: "discord",
|
|
817
|
+
target: typingChannelId,
|
|
818
|
+
error: err
|
|
819
|
+
});
|
|
820
|
+
},
|
|
821
|
+
maxDurationMs: DISCORD_TYPING_MAX_DURATION_MS
|
|
822
|
+
}
|
|
823
|
+
});
|
|
824
|
+
const tableMode = resolveMarkdownTableMode({
|
|
825
|
+
cfg,
|
|
826
|
+
channel: "discord",
|
|
827
|
+
accountId
|
|
828
|
+
});
|
|
829
|
+
const maxLinesPerMessage = resolveDiscordMaxLinesPerMessage({
|
|
830
|
+
cfg,
|
|
831
|
+
discordConfig,
|
|
832
|
+
accountId
|
|
833
|
+
});
|
|
834
|
+
const chunkMode = resolveChunkMode(cfg, "discord", accountId);
|
|
835
|
+
const deliverChannelId = deliverTarget.startsWith("channel:") ? deliverTarget.slice(8) : messageChannelId;
|
|
836
|
+
const draftPreview = createDiscordDraftPreviewController({
|
|
837
|
+
cfg,
|
|
838
|
+
discordConfig,
|
|
839
|
+
accountId,
|
|
840
|
+
sourceRepliesAreToolOnly,
|
|
841
|
+
textLimit,
|
|
842
|
+
deliveryRest,
|
|
843
|
+
deliverChannelId,
|
|
844
|
+
replyReference,
|
|
845
|
+
tableMode,
|
|
846
|
+
maxLinesPerMessage,
|
|
847
|
+
chunkMode,
|
|
848
|
+
log: logVerbose
|
|
849
|
+
});
|
|
850
|
+
let finalReplyStartNotified = false;
|
|
851
|
+
const notifyFinalReplyStart = () => {
|
|
852
|
+
if (finalReplyStartNotified) return;
|
|
853
|
+
finalReplyStartNotified = true;
|
|
854
|
+
observer?.onFinalReplyStart?.();
|
|
855
|
+
};
|
|
856
|
+
const { dispatcher, replyOptions, markDispatchIdle, markRunComplete } = createReplyDispatcherWithTyping({
|
|
857
|
+
...replyPipeline,
|
|
858
|
+
humanDelay: resolveHumanDelayConfig(cfg, route.agentId),
|
|
859
|
+
deliver: async (payload, info) => {
|
|
860
|
+
if (isProcessAborted(abortSignal)) return;
|
|
861
|
+
const isFinal = info.kind === "final";
|
|
862
|
+
if (payload.isReasoning) return;
|
|
863
|
+
const draftStream = draftPreview.draftStream;
|
|
864
|
+
if (draftStream && isFinal) {
|
|
865
|
+
draftPreview.markFinalDeliveryHandled();
|
|
866
|
+
const hasMedia = resolveSendableOutboundReplyParts(payload).hasMedia;
|
|
867
|
+
const finalText = payload.text;
|
|
868
|
+
const previewFinalText = draftPreview.resolvePreviewFinalText(finalText);
|
|
869
|
+
const hasExplicitReplyDirective = Boolean(payload.replyToTag || payload.replyToCurrent) || typeof finalText === "string" && /\[\[\s*reply_to(?:_current|\s*:)/i.test(finalText);
|
|
870
|
+
if (await deliverFinalizableDraftPreview({
|
|
871
|
+
kind: info.kind,
|
|
872
|
+
payload,
|
|
873
|
+
draft: {
|
|
874
|
+
flush: () => draftPreview.flush(),
|
|
875
|
+
clear: () => draftStream.clear(),
|
|
876
|
+
discardPending: () => draftStream.discardPending(),
|
|
877
|
+
seal: () => draftStream.seal(),
|
|
878
|
+
id: draftStream.messageId
|
|
879
|
+
},
|
|
880
|
+
buildFinalEdit: () => {
|
|
881
|
+
if (draftPreview.finalizedViaPreviewMessage || hasMedia || typeof previewFinalText !== "string" || hasExplicitReplyDirective || payload.isError) return;
|
|
882
|
+
return { content: previewFinalText };
|
|
883
|
+
},
|
|
884
|
+
editFinal: async (previewMessageId, edit) => {
|
|
885
|
+
if (isProcessAborted(abortSignal)) throw new Error("process aborted");
|
|
886
|
+
notifyFinalReplyStart();
|
|
887
|
+
await editMessageDiscord(deliverChannelId, previewMessageId, edit, {
|
|
888
|
+
cfg,
|
|
889
|
+
accountId,
|
|
890
|
+
rest: deliveryRest
|
|
891
|
+
});
|
|
892
|
+
},
|
|
893
|
+
deliverNormally: async () => {
|
|
894
|
+
if (isProcessAborted(abortSignal)) return false;
|
|
895
|
+
const replyToId = replyReference.use();
|
|
896
|
+
notifyFinalReplyStart();
|
|
897
|
+
await deliverDiscordReply({
|
|
898
|
+
cfg,
|
|
899
|
+
replies: [payload],
|
|
900
|
+
target: deliverTarget,
|
|
901
|
+
token,
|
|
902
|
+
accountId,
|
|
903
|
+
rest: deliveryRest,
|
|
904
|
+
runtime,
|
|
905
|
+
replyToId,
|
|
906
|
+
replyToMode,
|
|
907
|
+
textLimit,
|
|
908
|
+
maxLinesPerMessage,
|
|
909
|
+
tableMode,
|
|
910
|
+
chunkMode,
|
|
911
|
+
sessionKey: ctxPayload.SessionKey,
|
|
912
|
+
threadBindings,
|
|
913
|
+
mediaLocalRoots
|
|
914
|
+
});
|
|
915
|
+
replyReference.markSent();
|
|
916
|
+
observer?.onFinalReplyDelivered?.();
|
|
917
|
+
return true;
|
|
918
|
+
},
|
|
919
|
+
onPreviewFinalized: () => {
|
|
920
|
+
draftPreview.markPreviewFinalized();
|
|
921
|
+
replyReference.markSent();
|
|
922
|
+
observer?.onFinalReplyDelivered?.();
|
|
923
|
+
},
|
|
924
|
+
logPreviewEditFailure: (err) => {
|
|
925
|
+
logVerbose(`discord: preview final edit failed; falling back to standard send (${String(err)})`);
|
|
926
|
+
}
|
|
927
|
+
}) !== "normal-skipped") return;
|
|
928
|
+
}
|
|
929
|
+
if (isProcessAborted(abortSignal)) return;
|
|
930
|
+
const replyToId = replyReference.use();
|
|
931
|
+
if (isFinal) notifyFinalReplyStart();
|
|
932
|
+
await deliverDiscordReply({
|
|
933
|
+
cfg,
|
|
934
|
+
replies: [payload],
|
|
935
|
+
target: deliverTarget,
|
|
936
|
+
token,
|
|
937
|
+
accountId,
|
|
938
|
+
rest: deliveryRest,
|
|
939
|
+
runtime,
|
|
940
|
+
replyToId,
|
|
941
|
+
replyToMode,
|
|
942
|
+
textLimit,
|
|
943
|
+
maxLinesPerMessage,
|
|
944
|
+
tableMode,
|
|
945
|
+
chunkMode,
|
|
946
|
+
sessionKey: ctxPayload.SessionKey,
|
|
947
|
+
threadBindings,
|
|
948
|
+
mediaLocalRoots
|
|
949
|
+
});
|
|
950
|
+
replyReference.markSent();
|
|
951
|
+
if (isFinal) observer?.onFinalReplyDelivered?.();
|
|
952
|
+
},
|
|
953
|
+
onError: (err, info) => {
|
|
954
|
+
runtime.error?.(danger(formatDiscordReplyDeliveryFailure({
|
|
955
|
+
kind: info.kind,
|
|
956
|
+
err,
|
|
957
|
+
target: deliverTarget,
|
|
958
|
+
sessionKey: ctxPayload.SessionKey
|
|
959
|
+
})));
|
|
960
|
+
},
|
|
961
|
+
onReplyStart: async () => {
|
|
962
|
+
if (isProcessAborted(abortSignal)) return;
|
|
963
|
+
await replyPipeline.typingCallbacks?.onReplyStart();
|
|
964
|
+
await statusReactions.setThinking();
|
|
965
|
+
}
|
|
966
|
+
});
|
|
967
|
+
const resolvedBlockStreamingEnabled = resolveChannelStreamingBlockEnabled(discordConfig);
|
|
968
|
+
let dispatchResult = null;
|
|
969
|
+
let dispatchError = false;
|
|
970
|
+
let dispatchAborted = false;
|
|
971
|
+
let dispatchSettledBeforeStart = false;
|
|
972
|
+
const settleDispatchBeforeStart = async () => {
|
|
973
|
+
dispatchSettledBeforeStart = true;
|
|
974
|
+
await settleReplyDispatcher({
|
|
975
|
+
dispatcher,
|
|
976
|
+
onSettled: () => {
|
|
977
|
+
markRunComplete();
|
|
978
|
+
markDispatchIdle();
|
|
979
|
+
}
|
|
980
|
+
});
|
|
981
|
+
};
|
|
982
|
+
try {
|
|
983
|
+
if (isProcessAborted(abortSignal)) {
|
|
984
|
+
dispatchAborted = true;
|
|
985
|
+
await settleDispatchBeforeStart();
|
|
986
|
+
return;
|
|
987
|
+
}
|
|
988
|
+
const preparedResult = await runInboundReplyTurn({
|
|
989
|
+
channel: "discord",
|
|
990
|
+
accountId: route.accountId,
|
|
991
|
+
raw: ctx,
|
|
992
|
+
adapter: {
|
|
993
|
+
ingest: () => ({
|
|
994
|
+
id: message.id,
|
|
995
|
+
timestamp: message.timestamp ? Date.parse(message.timestamp) : void 0,
|
|
996
|
+
rawText: text,
|
|
997
|
+
textForAgent: ctxPayload.BodyForAgent,
|
|
998
|
+
textForCommands: ctxPayload.CommandBody,
|
|
999
|
+
raw: message
|
|
1000
|
+
}),
|
|
1001
|
+
resolveTurn: () => ({
|
|
1002
|
+
channel: "discord",
|
|
1003
|
+
accountId: route.accountId,
|
|
1004
|
+
routeSessionKey: persistedSessionKey,
|
|
1005
|
+
storePath: turn.storePath,
|
|
1006
|
+
ctxPayload,
|
|
1007
|
+
recordInboundSession,
|
|
1008
|
+
record: turn.record,
|
|
1009
|
+
history: {
|
|
1010
|
+
isGroup: isGuildMessage,
|
|
1011
|
+
historyKey: messageChannelId,
|
|
1012
|
+
historyMap: guildHistories,
|
|
1013
|
+
limit: historyLimit
|
|
1014
|
+
},
|
|
1015
|
+
onPreDispatchFailure: settleDispatchBeforeStart,
|
|
1016
|
+
runDispatch: () => dispatchInboundMessage({
|
|
1017
|
+
ctx: ctxPayload,
|
|
1018
|
+
cfg,
|
|
1019
|
+
dispatcher,
|
|
1020
|
+
replyOptions: {
|
|
1021
|
+
...replyOptions,
|
|
1022
|
+
abortSignal,
|
|
1023
|
+
skillFilter: channelConfig?.skills,
|
|
1024
|
+
sourceReplyDeliveryMode,
|
|
1025
|
+
disableBlockStreaming: sourceRepliesAreToolOnly ? true : draftPreview.disableBlockStreamingForDraft ?? (typeof resolvedBlockStreamingEnabled === "boolean" ? !resolvedBlockStreamingEnabled : void 0),
|
|
1026
|
+
onPartialReply: draftPreview.draftStream ? (payload) => draftPreview.updateFromPartial(payload.text) : void 0,
|
|
1027
|
+
onAssistantMessageStart: draftPreview.draftStream ? draftPreview.handleAssistantMessageBoundary : void 0,
|
|
1028
|
+
onReasoningEnd: draftPreview.draftStream ? draftPreview.handleAssistantMessageBoundary : void 0,
|
|
1029
|
+
onModelSelected,
|
|
1030
|
+
suppressDefaultToolProgressMessages: draftPreview.previewToolProgressEnabled ? true : void 0,
|
|
1031
|
+
onReasoningStream: async () => {
|
|
1032
|
+
await statusReactions.setThinking();
|
|
1033
|
+
},
|
|
1034
|
+
onToolStart: async (payload) => {
|
|
1035
|
+
if (isProcessAborted(abortSignal)) return;
|
|
1036
|
+
await maybeBindStatusReactionsToToolReaction(payload);
|
|
1037
|
+
await statusReactions.setTool(payload.name);
|
|
1038
|
+
draftPreview.pushToolProgress(payload.name ? `tool: ${payload.name}` : "tool running");
|
|
1039
|
+
},
|
|
1040
|
+
onItemEvent: async (payload) => {
|
|
1041
|
+
draftPreview.pushToolProgress(payload.progressText ?? payload.summary ?? payload.title ?? payload.name);
|
|
1042
|
+
},
|
|
1043
|
+
onPlanUpdate: async (payload) => {
|
|
1044
|
+
if (payload.phase !== "update") return;
|
|
1045
|
+
draftPreview.pushToolProgress(payload.explanation ?? payload.steps?.[0] ?? "planning");
|
|
1046
|
+
},
|
|
1047
|
+
onApprovalEvent: async (payload) => {
|
|
1048
|
+
if (payload.phase !== "requested") return;
|
|
1049
|
+
draftPreview.pushToolProgress(payload.command ? `approval: ${payload.command}` : "approval requested");
|
|
1050
|
+
},
|
|
1051
|
+
onCommandOutput: async (payload) => {
|
|
1052
|
+
if (payload.phase !== "end") return;
|
|
1053
|
+
draftPreview.pushToolProgress(payload.name ? `${payload.name}${payload.exitCode === 0 ? " ✓" : payload.exitCode != null ? ` (exit ${payload.exitCode})` : ""}` : payload.title);
|
|
1054
|
+
},
|
|
1055
|
+
onPatchSummary: async (payload) => {
|
|
1056
|
+
if (payload.phase !== "end") return;
|
|
1057
|
+
draftPreview.pushToolProgress(payload.summary ?? payload.title ?? "patch applied");
|
|
1058
|
+
},
|
|
1059
|
+
onCompactionStart: async () => {
|
|
1060
|
+
if (isProcessAborted(abortSignal)) return;
|
|
1061
|
+
await statusReactions.setCompacting();
|
|
1062
|
+
},
|
|
1063
|
+
onCompactionEnd: async () => {
|
|
1064
|
+
if (isProcessAborted(abortSignal)) return;
|
|
1065
|
+
statusReactions.cancelPending();
|
|
1066
|
+
await statusReactions.setThinking();
|
|
1067
|
+
}
|
|
1068
|
+
}
|
|
1069
|
+
})
|
|
1070
|
+
})
|
|
1071
|
+
}
|
|
1072
|
+
});
|
|
1073
|
+
if (!preparedResult.dispatched) return;
|
|
1074
|
+
dispatchResult = preparedResult.dispatchResult;
|
|
1075
|
+
if (isProcessAborted(abortSignal)) {
|
|
1076
|
+
dispatchAborted = true;
|
|
1077
|
+
return;
|
|
1078
|
+
}
|
|
1079
|
+
} catch (err) {
|
|
1080
|
+
if (isProcessAborted(abortSignal)) {
|
|
1081
|
+
dispatchAborted = true;
|
|
1082
|
+
return;
|
|
1083
|
+
}
|
|
1084
|
+
dispatchError = true;
|
|
1085
|
+
throw err;
|
|
1086
|
+
} finally {
|
|
1087
|
+
try {
|
|
1088
|
+
await draftPreview.cleanup();
|
|
1089
|
+
} finally {
|
|
1090
|
+
if (!dispatchSettledBeforeStart) {
|
|
1091
|
+
markRunComplete();
|
|
1092
|
+
markDispatchIdle();
|
|
1093
|
+
}
|
|
1094
|
+
}
|
|
1095
|
+
if (statusReactionsActive) if (dispatchAborted) if (removeAckAfterReply) statusReactions.clear();
|
|
1096
|
+
else statusReactions.restoreInitial();
|
|
1097
|
+
else {
|
|
1098
|
+
if (dispatchError) await statusReactions.setError();
|
|
1099
|
+
else await statusReactions.setDone();
|
|
1100
|
+
if (removeAckAfterReply) (async () => {
|
|
1101
|
+
await sleep(dispatchError ? DEFAULT_TIMING.errorHoldMs : DEFAULT_TIMING.doneHoldMs);
|
|
1102
|
+
await statusReactions.clear();
|
|
1103
|
+
})();
|
|
1104
|
+
else statusReactions.restoreInitial();
|
|
1105
|
+
}
|
|
1106
|
+
else if (shouldSendAckReaction && ackReaction && removeAckAfterReply) removeReactionDiscord(messageChannelId, message.id, ackReaction, ackReactionContext).catch((err) => {
|
|
1107
|
+
logAckFailure({
|
|
1108
|
+
log: logVerbose,
|
|
1109
|
+
channel: "discord",
|
|
1110
|
+
target: `${messageChannelId}/${message.id}`,
|
|
1111
|
+
error: err
|
|
1112
|
+
});
|
|
1113
|
+
});
|
|
1114
|
+
}
|
|
1115
|
+
if (dispatchAborted) return;
|
|
1116
|
+
const finalDispatchResult = dispatchResult;
|
|
1117
|
+
if (!finalDispatchResult || !hasFinalInboundReplyDispatch(finalDispatchResult)) return;
|
|
1118
|
+
if (shouldLogVerbose()) {
|
|
1119
|
+
const finalCount = finalDispatchResult.counts.final;
|
|
1120
|
+
logVerbose(`discord: delivered ${finalCount} reply${finalCount === 1 ? "" : "ies"} to ${replyTarget}`);
|
|
1121
|
+
}
|
|
1122
|
+
}
|
|
1123
|
+
//#endregion
|
|
1124
|
+
export { processDiscordMessage };
|