@kodelyth/discord 2026.5.42 → 2026.6.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/klaw.plugin.json +3822 -2
- package/package.json +18 -6
- package/account-inspect-api.ts +0 -6
- package/action-runtime-api.ts +0 -1
- package/api.ts +0 -130
- 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 -31
- package/runtime-api.ts +0 -181
- 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 -128
- package/src/accounts.test.ts +0 -381
- package/src/accounts.ts +0 -205
- package/src/actions/handle-action.guild-admin.ts +0 -421
- package/src/actions/handle-action.test.ts +0 -480
- package/src/actions/handle-action.ts +0 -402
- package/src/actions/runtime.guild.ts +0 -446
- package/src/actions/runtime.messaging.messages.ts +0 -226
- package/src/actions/runtime.messaging.reactions.ts +0 -67
- package/src/actions/runtime.messaging.runtime.ts +0 -73
- package/src/actions/runtime.messaging.send.ts +0 -336
- 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 -165
- package/src/actions/runtime.presence.ts +0 -117
- package/src/actions/runtime.shared.ts +0 -86
- package/src/actions/runtime.test.ts +0 -1337
- package/src/actions/runtime.ts +0 -87
- package/src/api-barrel.test.ts +0 -78
- package/src/api.test.ts +0 -152
- package/src/api.ts +0 -215
- package/src/approval-handler.runtime.test.ts +0 -41
- package/src/approval-handler.runtime.ts +0 -633
- 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 -50
- package/src/audit-core.ts +0 -178
- package/src/audit.test.ts +0 -204
- 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 -504
- package/src/channel-actions.ts +0 -254
- package/src/channel-api.ts +0 -29
- package/src/channel.conversation.ts +0 -159
- package/src/channel.loaders.ts +0 -50
- package/src/channel.message-adapter.test.ts +0 -230
- package/src/channel.runtime.ts +0 -1
- package/src/channel.setup.ts +0 -12
- package/src/channel.test.ts +0 -828
- package/src/channel.ts +0 -728
- package/src/chunk.test.ts +0 -170
- package/src/chunk.ts +0 -321
- package/src/client.proxy.test.ts +0 -177
- package/src/client.test.ts +0 -83
- package/src/client.ts +0 -143
- 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 -345
- package/src/components.ts +0 -54
- package/src/components.types.ts +0 -187
- package/src/config-schema.test.ts +0 -439
- package/src/config-schema.ts +0 -6
- package/src/config-ui-hints.ts +0 -354
- package/src/conversation-identity.ts +0 -58
- package/src/delivery-retry.ts +0 -52
- 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 -141
- 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 -393
- 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 -193
- package/src/draft-stream.ts +0 -162
- package/src/durable-delivery.test.ts +0 -103
- 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/inbound-event-delivery.ts +0 -135
- 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 -260
- 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 -472
- package/src/internal/client.ts +0 -310
- package/src/internal/command-deploy.test.ts +0 -197
- package/src/internal/command-deploy.ts +0 -352
- 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 -185
- 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.test.ts +0 -114
- package/src/internal/gateway-lifecycle.ts +0 -75
- package/src/internal/gateway-rate-limit.ts +0 -104
- package/src/internal/gateway.test.ts +0 -676
- package/src/internal/gateway.ts +0 -479
- 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 -329
- package/src/internal/interactions.ts +0 -378
- package/src/internal/listeners.ts +0 -91
- 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 -681
- 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/ack-reactions.ts +0 -70
- package/src/monitor/acp-bind-here.integration.test.ts +0 -219
- 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 -177
- package/src/monitor/agent-components-guild-auth.ts +0 -322
- package/src/monitor/agent-components-helpers.runtime.ts +0 -3
- 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 -359
- 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 -215
- 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 -171
- 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 -631
- package/src/monitor/auto-presence.test.ts +0 -184
- package/src/monitor/auto-presence.ts +0 -356
- package/src/monitor/channel-access.test.ts +0 -113
- 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 -274
- package/src/monitor/dm-command-auth.ts +0 -259
- package/src/monitor/dm-command-decision.test.ts +0 -108
- package/src/monitor/dm-command-decision.ts +0 -49
- package/src/monitor/exec-approvals.test.ts +0 -225
- package/src/monitor/exec-approvals.ts +0 -158
- package/src/monitor/format.ts +0 -45
- package/src/monitor/gateway-handle.ts +0 -33
- 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 -320
- package/src/monitor/gateway-plugin.ts +0 -302
- package/src/monitor/gateway-registry.ts +0 -37
- package/src/monitor/gateway-supervisor.test.ts +0 -157
- 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 -112
- package/src/monitor/inbound-context.ts +0 -95
- package/src/monitor/inbound-dedupe.ts +0 -79
- package/src/monitor/inbound-job.test.ts +0 -216
- package/src/monitor/inbound-job.ts +0 -118
- package/src/monitor/listeners.queue.ts +0 -91
- package/src/monitor/listeners.reactions.ts +0 -594
- package/src/monitor/listeners.test.ts +0 -209
- package/src/monitor/listeners.ts +0 -150
- package/src/monitor/message-channel-info.ts +0 -96
- package/src/monitor/message-forwarded.ts +0 -114
- 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 -492
- package/src/monitor/message-handler.dm-preflight.ts +0 -119
- package/src/monitor/message-handler.draft-preview.ts +0 -426
- 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 -61
- 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 -371
- package/src/monitor/message-handler.preflight.test-helpers.ts +0 -114
- package/src/monitor/message-handler.preflight.test.ts +0 -2255
- package/src/monitor/message-handler.preflight.ts +0 -822
- package/src/monitor/message-handler.preflight.types.ts +0 -115
- package/src/monitor/message-handler.process.test.ts +0 -2520
- package/src/monitor/message-handler.process.ts +0 -1027
- package/src/monitor/message-handler.queue.test.ts +0 -680
- 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 -309
- package/src/monitor/message-media.ts +0 -536
- 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 -1234
- package/src/monitor/message-utils.ts +0 -34
- 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 -869
- package/src/monitor/model-picker.ts +0 -38
- package/src/monitor/model-picker.view.ts +0 -722
- package/src/monitor/monitor.agent-components.test.ts +0 -410
- package/src/monitor/monitor.test.ts +0 -919
- package/src/monitor/monitor.threading-utils.test.ts +0 -614
- 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 -309
- package/src/monitor/native-command-bypass.ts +0 -13
- package/src/monitor/native-command-context.test.ts +0 -105
- package/src/monitor/native-command-context.ts +0 -109
- package/src/monitor/native-command-dispatch.ts +0 -35
- package/src/monitor/native-command-model-picker-apply.ts +0 -209
- package/src/monitor/native-command-model-picker-interaction.ts +0 -516
- package/src/monitor/native-command-model-picker-ui.ts +0 -357
- 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 -108
- package/src/monitor/native-command.commands-allowfrom.test.ts +0 -504
- package/src/monitor/native-command.model-picker.test.ts +0 -930
- package/src/monitor/native-command.options.test.ts +0 -379
- package/src/monitor/native-command.options.ts +0 -153
- package/src/monitor/native-command.plugin-dispatch.test.ts +0 -1212
- package/src/monitor/native-command.runtime.ts +0 -51
- package/src/monitor/native-command.status-direct.test.ts +0 -278
- package/src/monitor/native-command.test-helpers.ts +0 -64
- package/src/monitor/native-command.think-autocomplete.test.ts +0 -411
- package/src/monitor/native-command.ts +0 -747
- 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 -61
- 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 -217
- package/src/monitor/provider.allowlist.ts +0 -398
- 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 -734
- package/src/monitor/provider.lifecycle.ts +0 -562
- package/src/monitor/provider.proxy.test.ts +0 -804
- package/src/monitor/provider.rest-proxy.test.ts +0 -389
- 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 -440
- package/src/monitor/provider.startup.ts +0 -323
- package/src/monitor/provider.test.ts +0 -1173
- package/src/monitor/provider.ts +0 -688
- package/src/monitor/reply-context.ts +0 -64
- package/src/monitor/reply-delivery.test.ts +0 -474
- package/src/monitor/reply-delivery.ts +0 -212
- package/src/monitor/reply-safety.ts +0 -96
- package/src/monitor/rest-fetch.ts +0 -94
- package/src/monitor/route-resolution.test.ts +0 -209
- 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 -250
- package/src/monitor/thread-bindings.discord-api.ts +0 -310
- package/src/monitor/thread-bindings.lifecycle.test.ts +0 -1994
- package/src/monitor/thread-bindings.lifecycle.ts +0 -354
- package/src/monitor/thread-bindings.manager.ts +0 -551
- 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 -39
- 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 -209
- 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 -330
- 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 -279
- package/src/monitor/threading.starter.ts +0 -288
- 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 -1416
- package/src/monitor.ts +0 -28
- package/src/network-config.test.ts +0 -92
- package/src/network-config.ts +0 -79
- package/src/normalize.test.ts +0 -56
- package/src/normalize.ts +0 -86
- package/src/outbound-adapter.interactive-order.test.ts +0 -82
- package/src/outbound-adapter.test-harness.ts +0 -207
- package/src/outbound-adapter.test.ts +0 -804
- package/src/outbound-adapter.ts +0 -326
- package/src/outbound-approval.ts +0 -29
- package/src/outbound-components.ts +0 -86
- package/src/outbound-payload.contract.test.ts +0 -49
- package/src/outbound-payload.ts +0 -208
- package/src/outbound-send-context.ts +0 -89
- package/src/outbound-session-route.test.ts +0 -42
- 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 -18
- 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 -100
- package/src/proxy-request-client.ts +0 -21
- package/src/recipient-resolution.ts +0 -39
- package/src/resolve-allowlist-common.test.ts +0 -40
- package/src/resolve-allowlist-common.ts +0 -39
- package/src/resolve-channels.test.ts +0 -341
- package/src/resolve-channels.ts +0 -369
- package/src/resolve-users.test.ts +0 -243
- 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 -61
- package/src/runtime-config.ts +0 -16
- 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 -245
- 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 -330
- package/src/send.components.ts +0 -391
- package/src/send.creates-thread.test.ts +0 -681
- package/src/send.emojis-stickers.ts +0 -57
- package/src/send.guild.ts +0 -170
- package/src/send.message-request.ts +0 -112
- package/src/send.messages.test.ts +0 -59
- package/src/send.messages.ts +0 -229
- package/src/send.outbound.ts +0 -459
- package/src/send.permissions.authz.test.ts +0 -190
- package/src/send.permissions.ts +0 -283
- package/src/send.reactions.ts +0 -155
- package/src/send.receipt.ts +0 -69
- package/src/send.sends-basic-channel-messages.test.ts +0 -1068
- package/src/send.shared.ts +0 -469
- package/src/send.test-harness.ts +0 -56
- package/src/send.ts +0 -82
- package/src/send.types.ts +0 -191
- package/src/send.typing.test.ts +0 -41
- package/src/send.typing.ts +0 -9
- package/src/send.voice.ts +0 -136
- package/src/send.webhook-activity.test.ts +0 -152
- package/src/send.webhook.proxy.test.ts +0 -210
- package/src/send.webhook.ts +0 -137
- 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 -113
- package/src/setup-account-state.ts +0 -141
- package/src/setup-adapter.ts +0 -14
- package/src/setup-core.ts +0 -215
- package/src/setup-runtime-helpers.ts +0 -10
- package/src/setup-surface.test.ts +0 -137
- package/src/setup-surface.ts +0 -132
- package/src/shared-interactive.test.ts +0 -153
- package/src/shared-interactive.ts +0 -161
- package/src/shared.test.ts +0 -186
- package/src/shared.ts +0 -197
- package/src/status-issues.test.ts +0 -97
- package/src/status-issues.ts +0 -198
- package/src/subagent-hooks.test.ts +0 -465
- package/src/subagent-hooks.ts +0 -232
- package/src/target-parsing.ts +0 -70
- package/src/target-resolver.ts +0 -129
- package/src/targets.test.ts +0 -393
- package/src/targets.ts +0 -12
- package/src/test-http-helpers.ts +0 -10
- package/src/test-support/component-runtime.ts +0 -194
- 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 -547
- package/src/token.test.ts +0 -174
- package/src/token.ts +0 -107
- package/src/ui-colors.ts +0 -27
- package/src/ui.ts +0 -20
- package/src/voice/access.test.ts +0 -288
- package/src/voice/access.ts +0 -126
- package/src/voice/audio.test.ts +0 -47
- package/src/voice/audio.ts +0 -249
- package/src/voice/capture-state.test.ts +0 -48
- package/src/voice/capture-state.ts +0 -120
- package/src/voice/command.test.ts +0 -170
- package/src/voice/command.ts +0 -284
- package/src/voice/config.ts +0 -8
- package/src/voice/ingress.ts +0 -164
- package/src/voice/manager.e2e.test.ts +0 -3286
- package/src/voice/manager.ready-listener.test.ts +0 -54
- package/src/voice/manager.runtime.ts +0 -14
- package/src/voice/manager.ts +0 -1155
- package/src/voice/prompt.test.ts +0 -30
- package/src/voice/prompt.ts +0 -22
- package/src/voice/realtime.ts +0 -1370
- package/src/voice/receive-recovery.test.ts +0 -81
- package/src/voice/receive-recovery.ts +0 -159
- package/src/voice/sanitize.test.ts +0 -34
- package/src/voice/sanitize.ts +0 -29
- package/src/voice/sdk-runtime.ts +0 -14
- package/src/voice/segment.ts +0 -160
- package/src/voice/session.ts +0 -81
- package/src/voice/speaker-context.ts +0 -127
- package/src/voice/tts.ts +0 -151
- package/src/voice-message.test.ts +0 -376
- package/src/voice-message.ts +0 -474
- 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
|
@@ -1,1027 +0,0 @@
|
|
|
1
|
-
import path from "node:path";
|
|
2
|
-
import { MessageFlags } from "discord-api-types/v10";
|
|
3
|
-
import {
|
|
4
|
-
formatReasoningMessage,
|
|
5
|
-
resolveAckReaction,
|
|
6
|
-
resolveHumanDelayConfig,
|
|
7
|
-
} from "klaw/plugin-sdk/agent-runtime";
|
|
8
|
-
import {
|
|
9
|
-
createStatusReactionController,
|
|
10
|
-
DEFAULT_TIMING,
|
|
11
|
-
logAckFailure,
|
|
12
|
-
logTypingFailure,
|
|
13
|
-
shouldAckReaction as shouldAckReactionGate,
|
|
14
|
-
} from "klaw/plugin-sdk/channel-feedback";
|
|
15
|
-
import {
|
|
16
|
-
createChannelMessageReplyPipeline,
|
|
17
|
-
defineFinalizableLivePreviewAdapter,
|
|
18
|
-
deliverWithFinalizableLivePreviewAdapter,
|
|
19
|
-
resolveChannelMessageSourceReplyDeliveryMode,
|
|
20
|
-
} from "klaw/plugin-sdk/channel-message";
|
|
21
|
-
import {
|
|
22
|
-
buildChannelProgressDraftLine,
|
|
23
|
-
buildChannelProgressDraftLineForEntry,
|
|
24
|
-
resolveChannelStreamingBlockEnabled,
|
|
25
|
-
resolveTranscriptBackedChannelFinalText,
|
|
26
|
-
} from "klaw/plugin-sdk/channel-streaming";
|
|
27
|
-
import { recordInboundSession } from "klaw/plugin-sdk/conversation-runtime";
|
|
28
|
-
import {
|
|
29
|
-
hasFinalInboundReplyDispatch,
|
|
30
|
-
recordChannelBotPairLoopAndCheckSuppression,
|
|
31
|
-
runPreparedInboundReplyTurn,
|
|
32
|
-
} from "klaw/plugin-sdk/inbound-reply-dispatch";
|
|
33
|
-
import { resolveMarkdownTableMode } from "klaw/plugin-sdk/markdown-table-runtime";
|
|
34
|
-
import { getAgentScopedMediaLocalRoots } from "klaw/plugin-sdk/media-runtime";
|
|
35
|
-
import { resolveChunkMode } from "klaw/plugin-sdk/reply-chunking";
|
|
36
|
-
import type { ReplyPayload } from "klaw/plugin-sdk/reply-dispatch-runtime";
|
|
37
|
-
import { createChannelHistoryWindow } from "klaw/plugin-sdk/reply-history";
|
|
38
|
-
import {
|
|
39
|
-
buildTtsSupplementMediaPayload,
|
|
40
|
-
getReplyPayloadTtsSupplement,
|
|
41
|
-
resolveSendableOutboundReplyParts,
|
|
42
|
-
} from "klaw/plugin-sdk/reply-payload";
|
|
43
|
-
import { danger, logVerbose, shouldLogVerbose } from "klaw/plugin-sdk/runtime-env";
|
|
44
|
-
import {
|
|
45
|
-
loadSessionStore,
|
|
46
|
-
readLatestAssistantTextFromSessionTranscript,
|
|
47
|
-
resolveAndPersistSessionFile,
|
|
48
|
-
resolveSessionStoreEntry,
|
|
49
|
-
resolveStorePath,
|
|
50
|
-
} from "klaw/plugin-sdk/session-store-runtime";
|
|
51
|
-
import { resolveDiscordMaxLinesPerMessage } from "../accounts.js";
|
|
52
|
-
import { createDiscordRestClient } from "../client.js";
|
|
53
|
-
import { beginDiscordInboundEventDeliveryCorrelation } from "../inbound-event-delivery.js";
|
|
54
|
-
import { removeReactionDiscord } from "../send.js";
|
|
55
|
-
import { editMessageDiscord } from "../send.messages.js";
|
|
56
|
-
import { resolveDiscordTargetChannelId } from "../send.shared.js";
|
|
57
|
-
import { resolveDiscordChannelId } from "../targets.js";
|
|
58
|
-
import {
|
|
59
|
-
createDiscordAckReactionAdapter,
|
|
60
|
-
createDiscordAckReactionContext,
|
|
61
|
-
queueInitialDiscordAckReaction,
|
|
62
|
-
} from "./ack-reactions.js";
|
|
63
|
-
import { buildDiscordMessageProcessContext } from "./message-handler.context.js";
|
|
64
|
-
import { createDiscordDraftPreviewController } from "./message-handler.draft-preview.js";
|
|
65
|
-
import type { DiscordMessagePreflightContext } from "./message-handler.preflight.js";
|
|
66
|
-
import { resolveForwardedMediaList, resolveMediaList } from "./message-utils.js";
|
|
67
|
-
import { deliverDiscordReply } from "./reply-delivery.js";
|
|
68
|
-
import {
|
|
69
|
-
DISCORD_ATTACHMENT_IDLE_TIMEOUT_MS,
|
|
70
|
-
DISCORD_ATTACHMENT_TOTAL_TIMEOUT_MS,
|
|
71
|
-
} from "./timeouts.js";
|
|
72
|
-
import { sendTyping } from "./typing.js";
|
|
73
|
-
|
|
74
|
-
function sleep(ms: number): Promise<void> {
|
|
75
|
-
return new Promise((resolve) => {
|
|
76
|
-
setTimeout(resolve, ms);
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
const DISCORD_TYPING_MAX_DURATION_MS = 20 * 60_000;
|
|
81
|
-
let replyRuntimePromise: Promise<typeof import("klaw/plugin-sdk/reply-runtime")> | undefined;
|
|
82
|
-
|
|
83
|
-
async function loadReplyRuntime() {
|
|
84
|
-
replyRuntimePromise ??= import("klaw/plugin-sdk/reply-runtime");
|
|
85
|
-
return await replyRuntimePromise;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
function isProcessAborted(abortSignal?: AbortSignal): boolean {
|
|
89
|
-
return Boolean(abortSignal?.aborted);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
function formatDiscordReplyDeliveryFailure(params: {
|
|
93
|
-
kind: string;
|
|
94
|
-
err: unknown;
|
|
95
|
-
target: string;
|
|
96
|
-
sessionKey?: string;
|
|
97
|
-
}) {
|
|
98
|
-
const context = [
|
|
99
|
-
`target=${params.target}`,
|
|
100
|
-
params.sessionKey ? `session=${params.sessionKey}` : undefined,
|
|
101
|
-
]
|
|
102
|
-
.filter(Boolean)
|
|
103
|
-
.join(" ");
|
|
104
|
-
return `discord ${params.kind} reply failed (${context}): ${String(params.err)}`;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
type DiscordMessageProcessObserver = {
|
|
108
|
-
onFinalReplyStart?: () => void;
|
|
109
|
-
onFinalReplyDelivered?: () => void;
|
|
110
|
-
onReplyPlanResolved?: (params: { createdThreadId?: string; sessionKey?: string }) => void;
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
type ToolStartPayload = {
|
|
114
|
-
name?: string;
|
|
115
|
-
phase?: string;
|
|
116
|
-
args?: Record<string, unknown>;
|
|
117
|
-
detailMode?: "explain" | "raw";
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
function readToolStringArg(args: Record<string, unknown>, key: string): string | undefined {
|
|
121
|
-
const value = args[key];
|
|
122
|
-
return typeof value === "string" && value.trim() ? value.trim() : undefined;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
function readToolBooleanArg(args: Record<string, unknown>, key: string): boolean {
|
|
126
|
-
return args[key] === true;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
export async function processDiscordMessage(
|
|
130
|
-
ctx: DiscordMessagePreflightContext,
|
|
131
|
-
observer?: DiscordMessageProcessObserver,
|
|
132
|
-
) {
|
|
133
|
-
const dispatchStartedAt = Date.now();
|
|
134
|
-
const {
|
|
135
|
-
cfg,
|
|
136
|
-
discordConfig,
|
|
137
|
-
accountId,
|
|
138
|
-
token,
|
|
139
|
-
runtime,
|
|
140
|
-
guildHistories,
|
|
141
|
-
historyLimit,
|
|
142
|
-
mediaMaxBytes,
|
|
143
|
-
textLimit,
|
|
144
|
-
replyToMode,
|
|
145
|
-
ackReactionScope,
|
|
146
|
-
message,
|
|
147
|
-
messageChannelId,
|
|
148
|
-
isGuildMessage,
|
|
149
|
-
isDirectMessage,
|
|
150
|
-
isGroupDm,
|
|
151
|
-
messageText,
|
|
152
|
-
shouldRequireMention,
|
|
153
|
-
canDetectMention,
|
|
154
|
-
effectiveWasMentioned,
|
|
155
|
-
shouldBypassMention,
|
|
156
|
-
channelConfig,
|
|
157
|
-
threadBindings,
|
|
158
|
-
route,
|
|
159
|
-
discordRestFetch,
|
|
160
|
-
abortSignal,
|
|
161
|
-
botLoopProtection,
|
|
162
|
-
} = ctx;
|
|
163
|
-
if (isProcessAborted(abortSignal)) {
|
|
164
|
-
return;
|
|
165
|
-
}
|
|
166
|
-
if (botLoopProtection) {
|
|
167
|
-
const botLoopResult = recordChannelBotPairLoopAndCheckSuppression(botLoopProtection);
|
|
168
|
-
if (botLoopResult.suppressed) {
|
|
169
|
-
logVerbose(
|
|
170
|
-
`discord: bot-to-bot loop detected before dispatch setup, suppressing for ${Math.max(0, Math.ceil((botLoopResult.cooldownUntilMs - Date.now()) / 1000))}s`,
|
|
171
|
-
);
|
|
172
|
-
return;
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
const ssrfPolicy = cfg.browser?.ssrfPolicy;
|
|
177
|
-
const mediaResolveOptions = {
|
|
178
|
-
fetchImpl: discordRestFetch,
|
|
179
|
-
ssrfPolicy,
|
|
180
|
-
readIdleTimeoutMs: DISCORD_ATTACHMENT_IDLE_TIMEOUT_MS,
|
|
181
|
-
totalTimeoutMs: DISCORD_ATTACHMENT_TOTAL_TIMEOUT_MS,
|
|
182
|
-
abortSignal,
|
|
183
|
-
};
|
|
184
|
-
const mediaList = await resolveMediaList(message, mediaMaxBytes, mediaResolveOptions);
|
|
185
|
-
if (isProcessAborted(abortSignal)) {
|
|
186
|
-
return;
|
|
187
|
-
}
|
|
188
|
-
const forwardedMediaList = await resolveForwardedMediaList(
|
|
189
|
-
message,
|
|
190
|
-
mediaMaxBytes,
|
|
191
|
-
mediaResolveOptions,
|
|
192
|
-
);
|
|
193
|
-
if (isProcessAborted(abortSignal)) {
|
|
194
|
-
return;
|
|
195
|
-
}
|
|
196
|
-
mediaList.push(...forwardedMediaList);
|
|
197
|
-
const text = messageText;
|
|
198
|
-
if (!text) {
|
|
199
|
-
logVerbose("discord: drop message " + message.id + " (empty content)");
|
|
200
|
-
return;
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
const boundThreadId = ctx.threadBinding?.conversation?.conversationId?.trim();
|
|
204
|
-
if (boundThreadId && typeof threadBindings.touchThread === "function") {
|
|
205
|
-
threadBindings.touchThread({ threadId: boundThreadId });
|
|
206
|
-
}
|
|
207
|
-
const { createReplyDispatcherWithTyping, dispatchInboundMessage, settleReplyDispatcher } =
|
|
208
|
-
await loadReplyRuntime();
|
|
209
|
-
const sourceReplyDeliveryMode = resolveChannelMessageSourceReplyDeliveryMode({
|
|
210
|
-
cfg,
|
|
211
|
-
ctx: {
|
|
212
|
-
ChatType: isDirectMessage
|
|
213
|
-
? "direct"
|
|
214
|
-
: isGroupDm
|
|
215
|
-
? "group"
|
|
216
|
-
: isGuildMessage
|
|
217
|
-
? "channel"
|
|
218
|
-
: undefined,
|
|
219
|
-
InboundEventKind: ctx.inboundEventKind,
|
|
220
|
-
},
|
|
221
|
-
});
|
|
222
|
-
const sourceRepliesAreToolOnly = sourceReplyDeliveryMode === "message_tool_only";
|
|
223
|
-
const ackReaction = resolveAckReaction(cfg, route.agentId, {
|
|
224
|
-
channel: "discord",
|
|
225
|
-
accountId,
|
|
226
|
-
});
|
|
227
|
-
const removeAckAfterReply = cfg.messages?.removeAckAfterReply ?? false;
|
|
228
|
-
const mediaLocalRoots = getAgentScopedMediaLocalRoots(cfg, route.agentId);
|
|
229
|
-
const isRoomEvent = ctx.inboundEventKind === "room_event";
|
|
230
|
-
const shouldAckReaction = () =>
|
|
231
|
-
Boolean(
|
|
232
|
-
!isRoomEvent &&
|
|
233
|
-
ackReaction &&
|
|
234
|
-
shouldAckReactionGate({
|
|
235
|
-
scope: ackReactionScope,
|
|
236
|
-
isDirect: isDirectMessage,
|
|
237
|
-
isGroup: isGuildMessage || isGroupDm,
|
|
238
|
-
isMentionableGroup: isGuildMessage,
|
|
239
|
-
requireMention: shouldRequireMention,
|
|
240
|
-
canDetectMention,
|
|
241
|
-
effectiveWasMentioned,
|
|
242
|
-
shouldBypassMention,
|
|
243
|
-
}),
|
|
244
|
-
);
|
|
245
|
-
const shouldSendAckReaction = shouldAckReaction();
|
|
246
|
-
const statusReactionsExplicitlyEnabled = cfg.messages?.statusReactions?.enabled === true;
|
|
247
|
-
const statusReactionsEnabled =
|
|
248
|
-
!isRoomEvent &&
|
|
249
|
-
shouldSendAckReaction &&
|
|
250
|
-
cfg.messages?.statusReactions?.enabled !== false &&
|
|
251
|
-
(!sourceRepliesAreToolOnly || statusReactionsExplicitlyEnabled);
|
|
252
|
-
const feedbackRest = createDiscordRestClient({
|
|
253
|
-
cfg,
|
|
254
|
-
token,
|
|
255
|
-
accountId,
|
|
256
|
-
}).rest;
|
|
257
|
-
const deliveryRest = createDiscordRestClient({
|
|
258
|
-
cfg,
|
|
259
|
-
token,
|
|
260
|
-
accountId,
|
|
261
|
-
}).rest;
|
|
262
|
-
// Discord outbound helpers expect the internal REST client shape explicitly.
|
|
263
|
-
const ackReactionContext = createDiscordAckReactionContext({
|
|
264
|
-
rest: feedbackRest,
|
|
265
|
-
cfg,
|
|
266
|
-
accountId,
|
|
267
|
-
});
|
|
268
|
-
const discordAdapter = createDiscordAckReactionAdapter({
|
|
269
|
-
channelId: messageChannelId,
|
|
270
|
-
messageId: message.id,
|
|
271
|
-
reactionContext: ackReactionContext,
|
|
272
|
-
});
|
|
273
|
-
let statusReactionTarget = `${messageChannelId}/${message.id}`;
|
|
274
|
-
let statusReactionsActive = statusReactionsEnabled;
|
|
275
|
-
let statusReactions = createStatusReactionController({
|
|
276
|
-
enabled: statusReactionsEnabled,
|
|
277
|
-
adapter: discordAdapter,
|
|
278
|
-
initialEmoji: ackReaction,
|
|
279
|
-
emojis: cfg.messages?.statusReactions?.emojis,
|
|
280
|
-
timing: cfg.messages?.statusReactions?.timing,
|
|
281
|
-
onError: (err) => {
|
|
282
|
-
logAckFailure({
|
|
283
|
-
log: logVerbose,
|
|
284
|
-
channel: "discord",
|
|
285
|
-
target: statusReactionTarget,
|
|
286
|
-
error: err,
|
|
287
|
-
});
|
|
288
|
-
},
|
|
289
|
-
});
|
|
290
|
-
const resolveTrackedReactionChannelId = async (
|
|
291
|
-
args: Record<string, unknown>,
|
|
292
|
-
): Promise<string> => {
|
|
293
|
-
const target =
|
|
294
|
-
readToolStringArg(args, "channelId") ??
|
|
295
|
-
readToolStringArg(args, "channel_id") ??
|
|
296
|
-
readToolStringArg(args, "to");
|
|
297
|
-
if (!target) {
|
|
298
|
-
return messageChannelId;
|
|
299
|
-
}
|
|
300
|
-
try {
|
|
301
|
-
return resolveDiscordChannelId(target);
|
|
302
|
-
} catch {
|
|
303
|
-
return (
|
|
304
|
-
await resolveDiscordTargetChannelId(target, {
|
|
305
|
-
cfg,
|
|
306
|
-
token,
|
|
307
|
-
accountId,
|
|
308
|
-
})
|
|
309
|
-
).channelId;
|
|
310
|
-
}
|
|
311
|
-
};
|
|
312
|
-
const maybeBindStatusReactionsToToolReaction = async (payload: ToolStartPayload) => {
|
|
313
|
-
if (
|
|
314
|
-
sourceRepliesAreToolOnly ||
|
|
315
|
-
cfg.messages?.statusReactions?.enabled === false ||
|
|
316
|
-
payload.phase !== "start" ||
|
|
317
|
-
payload.name !== "message" ||
|
|
318
|
-
!payload.args
|
|
319
|
-
) {
|
|
320
|
-
return;
|
|
321
|
-
}
|
|
322
|
-
const args = payload.args;
|
|
323
|
-
const action = readToolStringArg(args, "action")?.toLowerCase();
|
|
324
|
-
if (action !== "react") {
|
|
325
|
-
return;
|
|
326
|
-
}
|
|
327
|
-
const shouldTrack =
|
|
328
|
-
readToolBooleanArg(args, "trackToolCalls") || readToolBooleanArg(args, "track_tool_calls");
|
|
329
|
-
if (!shouldTrack) {
|
|
330
|
-
return;
|
|
331
|
-
}
|
|
332
|
-
const emoji = readToolStringArg(args, "emoji");
|
|
333
|
-
const remove = readToolBooleanArg(args, "remove");
|
|
334
|
-
if (!emoji || remove) {
|
|
335
|
-
return;
|
|
336
|
-
}
|
|
337
|
-
const trackedMessageId =
|
|
338
|
-
readToolStringArg(args, "messageId") ?? readToolStringArg(args, "message_id") ?? message.id;
|
|
339
|
-
let trackedChannelId: string;
|
|
340
|
-
try {
|
|
341
|
-
trackedChannelId = await resolveTrackedReactionChannelId(args);
|
|
342
|
-
} catch (err) {
|
|
343
|
-
logAckFailure({
|
|
344
|
-
log: logVerbose,
|
|
345
|
-
channel: "discord",
|
|
346
|
-
target: `${readToolStringArg(args, "to") ?? readToolStringArg(args, "channelId") ?? messageChannelId}/${trackedMessageId}`,
|
|
347
|
-
error: err,
|
|
348
|
-
});
|
|
349
|
-
return;
|
|
350
|
-
}
|
|
351
|
-
statusReactionTarget = `${trackedChannelId}/${trackedMessageId}`;
|
|
352
|
-
if (statusReactionsActive) {
|
|
353
|
-
void statusReactions.clear();
|
|
354
|
-
}
|
|
355
|
-
const trackedAdapter = createDiscordAckReactionAdapter({
|
|
356
|
-
channelId: trackedChannelId,
|
|
357
|
-
messageId: trackedMessageId,
|
|
358
|
-
reactionContext: ackReactionContext,
|
|
359
|
-
});
|
|
360
|
-
statusReactions = createStatusReactionController({
|
|
361
|
-
enabled: true,
|
|
362
|
-
adapter: trackedAdapter,
|
|
363
|
-
initialEmoji: emoji,
|
|
364
|
-
emojis: cfg.messages?.statusReactions?.emojis,
|
|
365
|
-
timing: cfg.messages?.statusReactions?.timing,
|
|
366
|
-
onError: (err) => {
|
|
367
|
-
logAckFailure({
|
|
368
|
-
log: logVerbose,
|
|
369
|
-
channel: "discord",
|
|
370
|
-
target: statusReactionTarget,
|
|
371
|
-
error: err,
|
|
372
|
-
});
|
|
373
|
-
},
|
|
374
|
-
});
|
|
375
|
-
statusReactionsActive = true;
|
|
376
|
-
void statusReactions.setQueued();
|
|
377
|
-
};
|
|
378
|
-
queueInitialDiscordAckReaction({
|
|
379
|
-
enabled: statusReactionsEnabled,
|
|
380
|
-
shouldSendAckReaction,
|
|
381
|
-
ackReaction,
|
|
382
|
-
statusReactions,
|
|
383
|
-
reactionAdapter: discordAdapter,
|
|
384
|
-
target: `${messageChannelId}/${message.id}`,
|
|
385
|
-
});
|
|
386
|
-
const processContext = await buildDiscordMessageProcessContext({
|
|
387
|
-
ctx,
|
|
388
|
-
text,
|
|
389
|
-
mediaList,
|
|
390
|
-
});
|
|
391
|
-
if (!processContext) {
|
|
392
|
-
return;
|
|
393
|
-
}
|
|
394
|
-
const {
|
|
395
|
-
ctxPayload,
|
|
396
|
-
persistedSessionKey,
|
|
397
|
-
turn,
|
|
398
|
-
replyPlan,
|
|
399
|
-
deliverTarget,
|
|
400
|
-
replyTarget,
|
|
401
|
-
replyReference,
|
|
402
|
-
} = processContext;
|
|
403
|
-
observer?.onReplyPlanResolved?.({
|
|
404
|
-
createdThreadId: replyPlan.createdThreadId,
|
|
405
|
-
sessionKey: persistedSessionKey,
|
|
406
|
-
});
|
|
407
|
-
|
|
408
|
-
const typingChannelId = deliverTarget.startsWith("channel:")
|
|
409
|
-
? deliverTarget.slice("channel:".length)
|
|
410
|
-
: messageChannelId;
|
|
411
|
-
|
|
412
|
-
const { onModelSelected, ...replyPipeline } = createChannelMessageReplyPipeline({
|
|
413
|
-
cfg,
|
|
414
|
-
agentId: route.agentId,
|
|
415
|
-
channel: "discord",
|
|
416
|
-
accountId: route.accountId,
|
|
417
|
-
typing: {
|
|
418
|
-
start: () => sendTyping({ rest: feedbackRest, channelId: typingChannelId }),
|
|
419
|
-
onStartError: (err) => {
|
|
420
|
-
logTypingFailure({
|
|
421
|
-
log: logVerbose,
|
|
422
|
-
channel: "discord",
|
|
423
|
-
target: typingChannelId,
|
|
424
|
-
error: err,
|
|
425
|
-
});
|
|
426
|
-
},
|
|
427
|
-
// Long tool-heavy runs are expected on Discord; keep heartbeats alive.
|
|
428
|
-
maxDurationMs: DISCORD_TYPING_MAX_DURATION_MS,
|
|
429
|
-
},
|
|
430
|
-
});
|
|
431
|
-
const tableMode = resolveMarkdownTableMode({
|
|
432
|
-
cfg,
|
|
433
|
-
channel: "discord",
|
|
434
|
-
accountId,
|
|
435
|
-
});
|
|
436
|
-
const maxLinesPerMessage = resolveDiscordMaxLinesPerMessage({
|
|
437
|
-
cfg,
|
|
438
|
-
discordConfig,
|
|
439
|
-
accountId,
|
|
440
|
-
});
|
|
441
|
-
const chunkMode = resolveChunkMode(cfg, "discord", accountId);
|
|
442
|
-
const clearGroupHistory = () => {
|
|
443
|
-
if (isDirectMessage) {
|
|
444
|
-
return;
|
|
445
|
-
}
|
|
446
|
-
createChannelHistoryWindow({ historyMap: guildHistories }).clear({
|
|
447
|
-
historyKey: messageChannelId,
|
|
448
|
-
limit: historyLimit,
|
|
449
|
-
});
|
|
450
|
-
};
|
|
451
|
-
const beginDeliveryCorrelation = () =>
|
|
452
|
-
isRoomEvent
|
|
453
|
-
? beginDiscordInboundEventDeliveryCorrelation(
|
|
454
|
-
ctxPayload.SessionKey,
|
|
455
|
-
{
|
|
456
|
-
outboundTo: messageChannelId,
|
|
457
|
-
outboundAccountId: route.accountId,
|
|
458
|
-
markInboundEventDelivered: clearGroupHistory,
|
|
459
|
-
},
|
|
460
|
-
{ inboundEventKind: ctxPayload.InboundEventKind },
|
|
461
|
-
)
|
|
462
|
-
: () => {};
|
|
463
|
-
const endDiscordInboundEventDeliveryCorrelation = beginDeliveryCorrelation();
|
|
464
|
-
const resolveCurrentTurnTranscriptFinalText = async (): Promise<string | undefined> => {
|
|
465
|
-
const sessionKey = ctxPayload.SessionKey;
|
|
466
|
-
if (!sessionKey) {
|
|
467
|
-
return undefined;
|
|
468
|
-
}
|
|
469
|
-
try {
|
|
470
|
-
const storePath = resolveStorePath(cfg.session?.store, { agentId: route.agentId });
|
|
471
|
-
const store = loadSessionStore(storePath, { clone: false });
|
|
472
|
-
const sessionEntry = resolveSessionStoreEntry({ store, sessionKey }).existing;
|
|
473
|
-
if (!sessionEntry?.sessionId) {
|
|
474
|
-
return undefined;
|
|
475
|
-
}
|
|
476
|
-
const { sessionFile } = await resolveAndPersistSessionFile({
|
|
477
|
-
sessionId: sessionEntry.sessionId,
|
|
478
|
-
sessionKey,
|
|
479
|
-
sessionStore: store,
|
|
480
|
-
storePath,
|
|
481
|
-
sessionEntry,
|
|
482
|
-
agentId: route.agentId,
|
|
483
|
-
sessionsDir: path.dirname(storePath),
|
|
484
|
-
});
|
|
485
|
-
const latest = await readLatestAssistantTextFromSessionTranscript(sessionFile);
|
|
486
|
-
if (!latest?.timestamp || latest.timestamp < dispatchStartedAt) {
|
|
487
|
-
return undefined;
|
|
488
|
-
}
|
|
489
|
-
return latest.text;
|
|
490
|
-
} catch (err) {
|
|
491
|
-
logVerbose(`discord transcript final candidate lookup failed: ${String(err)}`);
|
|
492
|
-
return undefined;
|
|
493
|
-
}
|
|
494
|
-
};
|
|
495
|
-
|
|
496
|
-
const deliverChannelId = deliverTarget.startsWith("channel:")
|
|
497
|
-
? deliverTarget.slice("channel:".length)
|
|
498
|
-
: messageChannelId;
|
|
499
|
-
const draftPreview = createDiscordDraftPreviewController({
|
|
500
|
-
cfg,
|
|
501
|
-
discordConfig,
|
|
502
|
-
accountId,
|
|
503
|
-
sourceRepliesAreToolOnly,
|
|
504
|
-
textLimit,
|
|
505
|
-
deliveryRest,
|
|
506
|
-
deliverChannelId,
|
|
507
|
-
replyReference,
|
|
508
|
-
tableMode,
|
|
509
|
-
maxLinesPerMessage,
|
|
510
|
-
chunkMode,
|
|
511
|
-
log: logVerbose,
|
|
512
|
-
});
|
|
513
|
-
const finalPreviewFlags =
|
|
514
|
-
(discordConfig?.suppressEmbeds ?? true) ? MessageFlags.SuppressEmbeds : undefined;
|
|
515
|
-
let finalReplyStartNotified = false;
|
|
516
|
-
const notifyFinalReplyStart = () => {
|
|
517
|
-
if (finalReplyStartNotified) {
|
|
518
|
-
return;
|
|
519
|
-
}
|
|
520
|
-
finalReplyStartNotified = true;
|
|
521
|
-
observer?.onFinalReplyStart?.();
|
|
522
|
-
};
|
|
523
|
-
|
|
524
|
-
const { dispatcher, replyOptions, markDispatchIdle, markRunComplete } =
|
|
525
|
-
createReplyDispatcherWithTyping({
|
|
526
|
-
...replyPipeline,
|
|
527
|
-
humanDelay: resolveHumanDelayConfig(cfg, route.agentId),
|
|
528
|
-
deliver: async (payload: ReplyPayload, info) => {
|
|
529
|
-
if (isProcessAborted(abortSignal)) {
|
|
530
|
-
return;
|
|
531
|
-
}
|
|
532
|
-
const isFinal = info.kind === "final";
|
|
533
|
-
if (payload.isReasoning) {
|
|
534
|
-
// Reasoning/thinking payloads should not be delivered to Discord.
|
|
535
|
-
return;
|
|
536
|
-
}
|
|
537
|
-
const finalText =
|
|
538
|
-
isFinal && typeof payload.text === "string"
|
|
539
|
-
? await resolveTranscriptBackedChannelFinalText({
|
|
540
|
-
finalText: payload.text,
|
|
541
|
-
resolveCandidateText: resolveCurrentTurnTranscriptFinalText,
|
|
542
|
-
})
|
|
543
|
-
: payload.text;
|
|
544
|
-
const effectivePayload =
|
|
545
|
-
finalText !== payload.text ? { ...payload, text: finalText } : payload;
|
|
546
|
-
const draftStream = draftPreview.draftStream;
|
|
547
|
-
if (draftStream && draftPreview.isProgressMode && info.kind === "block") {
|
|
548
|
-
const reply = resolveSendableOutboundReplyParts(effectivePayload);
|
|
549
|
-
if (!reply.hasMedia && !payload.isError) {
|
|
550
|
-
return;
|
|
551
|
-
}
|
|
552
|
-
}
|
|
553
|
-
if (
|
|
554
|
-
draftStream &&
|
|
555
|
-
isFinal &&
|
|
556
|
-
(!draftPreview.isProgressMode || draftPreview.hasProgressDraftStarted)
|
|
557
|
-
) {
|
|
558
|
-
const reply = resolveSendableOutboundReplyParts(effectivePayload);
|
|
559
|
-
const hasMedia = reply.hasMedia;
|
|
560
|
-
const ttsSupplement = getReplyPayloadTtsSupplement(effectivePayload);
|
|
561
|
-
const previewSourceText = finalText ?? ttsSupplement?.spokenText;
|
|
562
|
-
const previewFinalText = draftPreview.resolvePreviewFinalText(previewSourceText);
|
|
563
|
-
const previewReplyToId = replyReference.peek();
|
|
564
|
-
const hasExplicitReplyDirective =
|
|
565
|
-
Boolean(effectivePayload.replyToTag || effectivePayload.replyToCurrent) ||
|
|
566
|
-
(typeof previewSourceText === "string" &&
|
|
567
|
-
/\[\[\s*reply_to(?:_current|\s*:)/i.test(previewSourceText));
|
|
568
|
-
|
|
569
|
-
const result = await deliverWithFinalizableLivePreviewAdapter({
|
|
570
|
-
kind: info.kind,
|
|
571
|
-
payload: effectivePayload,
|
|
572
|
-
adapter: defineFinalizableLivePreviewAdapter({
|
|
573
|
-
draft: {
|
|
574
|
-
flush: () => draftPreview.flush(),
|
|
575
|
-
clear: () => draftStream.clear(),
|
|
576
|
-
discardPending: () => draftStream.discardPending(),
|
|
577
|
-
seal: () => draftStream.seal(),
|
|
578
|
-
id: draftStream.messageId,
|
|
579
|
-
},
|
|
580
|
-
buildFinalEdit: () => {
|
|
581
|
-
if (
|
|
582
|
-
draftPreview.finalizedViaPreviewMessage ||
|
|
583
|
-
(hasMedia && !ttsSupplement) ||
|
|
584
|
-
typeof previewFinalText !== "string" ||
|
|
585
|
-
hasExplicitReplyDirective ||
|
|
586
|
-
payload.isError
|
|
587
|
-
) {
|
|
588
|
-
return undefined;
|
|
589
|
-
}
|
|
590
|
-
return {
|
|
591
|
-
content: previewFinalText,
|
|
592
|
-
...(finalPreviewFlags ? { flags: finalPreviewFlags } : {}),
|
|
593
|
-
};
|
|
594
|
-
},
|
|
595
|
-
editFinal: async (previewMessageId, edit) => {
|
|
596
|
-
if (isProcessAborted(abortSignal)) {
|
|
597
|
-
throw new Error("process aborted");
|
|
598
|
-
}
|
|
599
|
-
notifyFinalReplyStart();
|
|
600
|
-
await editMessageDiscord(deliverChannelId, previewMessageId, edit, {
|
|
601
|
-
cfg,
|
|
602
|
-
accountId,
|
|
603
|
-
rest: deliveryRest,
|
|
604
|
-
});
|
|
605
|
-
},
|
|
606
|
-
onPreviewFinalized: () => {
|
|
607
|
-
draftPreview.markFinalReplyDelivered();
|
|
608
|
-
draftPreview.markPreviewFinalized();
|
|
609
|
-
replyReference.markSent();
|
|
610
|
-
observer?.onFinalReplyDelivered?.();
|
|
611
|
-
},
|
|
612
|
-
buildSupplementalPayload: () =>
|
|
613
|
-
ttsSupplement ? buildTtsSupplementMediaPayload(effectivePayload) : undefined,
|
|
614
|
-
deliverSupplemental: async (supplementalPayload) => {
|
|
615
|
-
if (isProcessAborted(abortSignal)) {
|
|
616
|
-
return false;
|
|
617
|
-
}
|
|
618
|
-
const supplementalReplyToId =
|
|
619
|
-
previewReplyToId ??
|
|
620
|
-
replyReference.peek() ??
|
|
621
|
-
(replyToMode === "all"
|
|
622
|
-
? typeof message.id === "string" && message.id
|
|
623
|
-
? message.id
|
|
624
|
-
: ctxPayload.MessageSid
|
|
625
|
-
: undefined);
|
|
626
|
-
await deliverDiscordReply({
|
|
627
|
-
cfg,
|
|
628
|
-
replies: [supplementalPayload],
|
|
629
|
-
target: deliverTarget,
|
|
630
|
-
token,
|
|
631
|
-
accountId,
|
|
632
|
-
rest: deliveryRest,
|
|
633
|
-
runtime,
|
|
634
|
-
replyToId: supplementalReplyToId,
|
|
635
|
-
replyToMode,
|
|
636
|
-
textLimit,
|
|
637
|
-
maxLinesPerMessage,
|
|
638
|
-
tableMode,
|
|
639
|
-
chunkMode,
|
|
640
|
-
sessionKey: ctxPayload.SessionKey,
|
|
641
|
-
threadBindings,
|
|
642
|
-
mediaLocalRoots,
|
|
643
|
-
kind: info.kind,
|
|
644
|
-
});
|
|
645
|
-
return true;
|
|
646
|
-
},
|
|
647
|
-
logPreviewEditFailure: (err) => {
|
|
648
|
-
logVerbose(
|
|
649
|
-
`discord: preview final edit failed; falling back to standard send (${String(err)})`,
|
|
650
|
-
);
|
|
651
|
-
},
|
|
652
|
-
}),
|
|
653
|
-
deliverNormally: async () => {
|
|
654
|
-
if (isProcessAborted(abortSignal)) {
|
|
655
|
-
return false;
|
|
656
|
-
}
|
|
657
|
-
const fallbackPayload =
|
|
658
|
-
ttsSupplement &&
|
|
659
|
-
ttsSupplement.visibleTextAlreadyDelivered !== true &&
|
|
660
|
-
!effectivePayload.text?.trim()
|
|
661
|
-
? { ...effectivePayload, text: ttsSupplement.spokenText }
|
|
662
|
-
: effectivePayload;
|
|
663
|
-
const replyToId = replyReference.use();
|
|
664
|
-
notifyFinalReplyStart();
|
|
665
|
-
await deliverDiscordReply({
|
|
666
|
-
cfg,
|
|
667
|
-
replies: [fallbackPayload],
|
|
668
|
-
target: deliverTarget,
|
|
669
|
-
token,
|
|
670
|
-
accountId,
|
|
671
|
-
rest: deliveryRest,
|
|
672
|
-
runtime,
|
|
673
|
-
replyToId,
|
|
674
|
-
replyToMode,
|
|
675
|
-
textLimit,
|
|
676
|
-
maxLinesPerMessage,
|
|
677
|
-
tableMode,
|
|
678
|
-
chunkMode,
|
|
679
|
-
sessionKey: ctxPayload.SessionKey,
|
|
680
|
-
threadBindings,
|
|
681
|
-
mediaLocalRoots,
|
|
682
|
-
kind: info.kind,
|
|
683
|
-
});
|
|
684
|
-
return true;
|
|
685
|
-
},
|
|
686
|
-
onNormalDelivered: () => {
|
|
687
|
-
draftPreview.markFinalReplyDelivered();
|
|
688
|
-
replyReference.markSent();
|
|
689
|
-
observer?.onFinalReplyDelivered?.();
|
|
690
|
-
},
|
|
691
|
-
});
|
|
692
|
-
if (result.kind !== "normal-skipped") {
|
|
693
|
-
return;
|
|
694
|
-
}
|
|
695
|
-
}
|
|
696
|
-
if (isProcessAborted(abortSignal)) {
|
|
697
|
-
return;
|
|
698
|
-
}
|
|
699
|
-
|
|
700
|
-
const replyToId = replyReference.use();
|
|
701
|
-
if (isFinal) {
|
|
702
|
-
notifyFinalReplyStart();
|
|
703
|
-
}
|
|
704
|
-
await deliverDiscordReply({
|
|
705
|
-
cfg,
|
|
706
|
-
replies: [effectivePayload],
|
|
707
|
-
target: deliverTarget,
|
|
708
|
-
token,
|
|
709
|
-
accountId,
|
|
710
|
-
rest: deliveryRest,
|
|
711
|
-
runtime,
|
|
712
|
-
replyToId,
|
|
713
|
-
replyToMode,
|
|
714
|
-
textLimit,
|
|
715
|
-
maxLinesPerMessage,
|
|
716
|
-
tableMode,
|
|
717
|
-
chunkMode,
|
|
718
|
-
sessionKey: ctxPayload.SessionKey,
|
|
719
|
-
threadBindings,
|
|
720
|
-
mediaLocalRoots,
|
|
721
|
-
kind: info.kind,
|
|
722
|
-
});
|
|
723
|
-
replyReference.markSent();
|
|
724
|
-
if (isFinal) {
|
|
725
|
-
observer?.onFinalReplyDelivered?.();
|
|
726
|
-
}
|
|
727
|
-
},
|
|
728
|
-
onError: (err, info) => {
|
|
729
|
-
runtime.error?.(
|
|
730
|
-
danger(
|
|
731
|
-
formatDiscordReplyDeliveryFailure({
|
|
732
|
-
kind: info.kind,
|
|
733
|
-
err,
|
|
734
|
-
target: deliverTarget,
|
|
735
|
-
sessionKey: ctxPayload.SessionKey,
|
|
736
|
-
}),
|
|
737
|
-
),
|
|
738
|
-
);
|
|
739
|
-
},
|
|
740
|
-
onReplyStart: async () => {
|
|
741
|
-
if (isProcessAborted(abortSignal)) {
|
|
742
|
-
return;
|
|
743
|
-
}
|
|
744
|
-
await replyPipeline.typingCallbacks?.onReplyStart();
|
|
745
|
-
await statusReactions.setThinking();
|
|
746
|
-
},
|
|
747
|
-
});
|
|
748
|
-
|
|
749
|
-
const resolvedBlockStreamingEnabled = resolveChannelStreamingBlockEnabled(discordConfig);
|
|
750
|
-
let dispatchResult: Awaited<ReturnType<typeof dispatchInboundMessage>> | null = null;
|
|
751
|
-
let dispatchError = false;
|
|
752
|
-
let dispatchAborted = false;
|
|
753
|
-
let dispatchSettledBeforeStart = false;
|
|
754
|
-
const settleDispatchBeforeStart = async () => {
|
|
755
|
-
dispatchSettledBeforeStart = true;
|
|
756
|
-
await settleReplyDispatcher({
|
|
757
|
-
dispatcher,
|
|
758
|
-
onSettled: () => {
|
|
759
|
-
markRunComplete();
|
|
760
|
-
markDispatchIdle();
|
|
761
|
-
},
|
|
762
|
-
});
|
|
763
|
-
};
|
|
764
|
-
try {
|
|
765
|
-
if (isProcessAborted(abortSignal)) {
|
|
766
|
-
dispatchAborted = true;
|
|
767
|
-
await settleDispatchBeforeStart();
|
|
768
|
-
return;
|
|
769
|
-
}
|
|
770
|
-
const preparedResult = await runPreparedInboundReplyTurn({
|
|
771
|
-
channel: "discord",
|
|
772
|
-
accountId: route.accountId,
|
|
773
|
-
routeSessionKey: persistedSessionKey,
|
|
774
|
-
storePath: turn.storePath,
|
|
775
|
-
ctxPayload,
|
|
776
|
-
recordInboundSession,
|
|
777
|
-
record: turn.record,
|
|
778
|
-
history: isRoomEvent
|
|
779
|
-
? undefined
|
|
780
|
-
: {
|
|
781
|
-
isGroup: isGuildMessage,
|
|
782
|
-
historyKey: messageChannelId,
|
|
783
|
-
historyMap: guildHistories,
|
|
784
|
-
limit: historyLimit,
|
|
785
|
-
},
|
|
786
|
-
onPreDispatchFailure: settleDispatchBeforeStart,
|
|
787
|
-
runDispatch: async () =>
|
|
788
|
-
await dispatchInboundMessage({
|
|
789
|
-
ctx: ctxPayload,
|
|
790
|
-
cfg,
|
|
791
|
-
dispatcher,
|
|
792
|
-
replyOptions: {
|
|
793
|
-
...replyOptions,
|
|
794
|
-
abortSignal,
|
|
795
|
-
skillFilter: channelConfig?.skills,
|
|
796
|
-
sourceReplyDeliveryMode,
|
|
797
|
-
queuedDeliveryCorrelations: isRoomEvent
|
|
798
|
-
? [{ begin: beginDeliveryCorrelation }]
|
|
799
|
-
: undefined,
|
|
800
|
-
suppressTyping: isRoomEvent ? true : undefined,
|
|
801
|
-
allowProgressCallbacksWhenSourceDeliverySuppressed:
|
|
802
|
-
sourceRepliesAreToolOnly && draftPreview.draftStream && draftPreview.isProgressMode
|
|
803
|
-
? true
|
|
804
|
-
: undefined,
|
|
805
|
-
disableBlockStreaming: sourceRepliesAreToolOnly
|
|
806
|
-
? true
|
|
807
|
-
: (draftPreview.disableBlockStreamingForDraft ??
|
|
808
|
-
(typeof resolvedBlockStreamingEnabled === "boolean"
|
|
809
|
-
? !resolvedBlockStreamingEnabled
|
|
810
|
-
: undefined)),
|
|
811
|
-
onPartialReply:
|
|
812
|
-
draftPreview.draftStream && !draftPreview.isProgressMode
|
|
813
|
-
? (payload) => draftPreview.updateFromPartial(payload.text)
|
|
814
|
-
: undefined,
|
|
815
|
-
onAssistantMessageStart: draftPreview.draftStream
|
|
816
|
-
? () => draftPreview.handleAssistantMessageBoundary()
|
|
817
|
-
: undefined,
|
|
818
|
-
onReasoningEnd: draftPreview.draftStream
|
|
819
|
-
? () => draftPreview.handleAssistantMessageBoundary()
|
|
820
|
-
: undefined,
|
|
821
|
-
onModelSelected,
|
|
822
|
-
suppressDefaultToolProgressMessages: draftPreview.suppressDefaultToolProgressMessages
|
|
823
|
-
? true
|
|
824
|
-
: undefined,
|
|
825
|
-
onReasoningStream: async (payload) => {
|
|
826
|
-
await statusReactions.setThinking();
|
|
827
|
-
const formattedText = payload?.text
|
|
828
|
-
? formatReasoningMessage(payload.text)
|
|
829
|
-
: undefined;
|
|
830
|
-
await draftPreview.pushReasoningProgress(formattedText);
|
|
831
|
-
},
|
|
832
|
-
onToolStart: async (payload) => {
|
|
833
|
-
if (isProcessAborted(abortSignal)) {
|
|
834
|
-
return;
|
|
835
|
-
}
|
|
836
|
-
await maybeBindStatusReactionsToToolReaction(payload);
|
|
837
|
-
await statusReactions.setTool(payload.name);
|
|
838
|
-
await draftPreview.pushToolProgress(
|
|
839
|
-
buildChannelProgressDraftLineForEntry(
|
|
840
|
-
discordConfig,
|
|
841
|
-
{
|
|
842
|
-
event: "tool",
|
|
843
|
-
name: payload.name,
|
|
844
|
-
phase: payload.phase,
|
|
845
|
-
args: payload.args,
|
|
846
|
-
},
|
|
847
|
-
payload.detailMode ? { detailMode: payload.detailMode } : undefined,
|
|
848
|
-
),
|
|
849
|
-
{ toolName: payload.name },
|
|
850
|
-
);
|
|
851
|
-
},
|
|
852
|
-
onItemEvent: async (payload) => {
|
|
853
|
-
await draftPreview.pushToolProgress(
|
|
854
|
-
buildChannelProgressDraftLineForEntry(discordConfig, {
|
|
855
|
-
event: "item",
|
|
856
|
-
itemId: payload.itemId,
|
|
857
|
-
itemKind: payload.kind,
|
|
858
|
-
title: payload.title,
|
|
859
|
-
name: payload.name,
|
|
860
|
-
phase: payload.phase,
|
|
861
|
-
status: payload.status,
|
|
862
|
-
summary: payload.summary,
|
|
863
|
-
progressText: payload.progressText,
|
|
864
|
-
meta: payload.meta,
|
|
865
|
-
}),
|
|
866
|
-
);
|
|
867
|
-
},
|
|
868
|
-
onPlanUpdate: async (payload) => {
|
|
869
|
-
if (payload.phase !== "update") {
|
|
870
|
-
return;
|
|
871
|
-
}
|
|
872
|
-
await draftPreview.pushToolProgress(
|
|
873
|
-
buildChannelProgressDraftLine({
|
|
874
|
-
event: "plan",
|
|
875
|
-
phase: payload.phase,
|
|
876
|
-
title: payload.title,
|
|
877
|
-
explanation: payload.explanation,
|
|
878
|
-
steps: payload.steps,
|
|
879
|
-
}),
|
|
880
|
-
);
|
|
881
|
-
},
|
|
882
|
-
onApprovalEvent: async (payload) => {
|
|
883
|
-
if (payload.phase !== "requested") {
|
|
884
|
-
return;
|
|
885
|
-
}
|
|
886
|
-
await draftPreview.pushToolProgress(
|
|
887
|
-
buildChannelProgressDraftLine({
|
|
888
|
-
event: "approval",
|
|
889
|
-
phase: payload.phase,
|
|
890
|
-
title: payload.title,
|
|
891
|
-
command: payload.command,
|
|
892
|
-
reason: payload.reason,
|
|
893
|
-
message: payload.message,
|
|
894
|
-
}),
|
|
895
|
-
);
|
|
896
|
-
},
|
|
897
|
-
onCommandOutput: async (payload) => {
|
|
898
|
-
if (payload.phase !== "end") {
|
|
899
|
-
return;
|
|
900
|
-
}
|
|
901
|
-
await draftPreview.pushToolProgress(
|
|
902
|
-
buildChannelProgressDraftLine({
|
|
903
|
-
event: "command-output",
|
|
904
|
-
phase: payload.phase,
|
|
905
|
-
title: payload.title,
|
|
906
|
-
name: payload.name,
|
|
907
|
-
status: payload.status,
|
|
908
|
-
exitCode: payload.exitCode,
|
|
909
|
-
}),
|
|
910
|
-
);
|
|
911
|
-
},
|
|
912
|
-
onPatchSummary: async (payload) => {
|
|
913
|
-
if (payload.phase !== "end") {
|
|
914
|
-
return;
|
|
915
|
-
}
|
|
916
|
-
await draftPreview.pushToolProgress(
|
|
917
|
-
buildChannelProgressDraftLine({
|
|
918
|
-
event: "patch",
|
|
919
|
-
phase: payload.phase,
|
|
920
|
-
title: payload.title,
|
|
921
|
-
name: payload.name,
|
|
922
|
-
added: payload.added,
|
|
923
|
-
modified: payload.modified,
|
|
924
|
-
deleted: payload.deleted,
|
|
925
|
-
summary: payload.summary,
|
|
926
|
-
}),
|
|
927
|
-
);
|
|
928
|
-
},
|
|
929
|
-
onCompactionStart: async () => {
|
|
930
|
-
if (isProcessAborted(abortSignal)) {
|
|
931
|
-
return;
|
|
932
|
-
}
|
|
933
|
-
await statusReactions.setCompacting();
|
|
934
|
-
},
|
|
935
|
-
onCompactionEnd: async () => {
|
|
936
|
-
if (isProcessAborted(abortSignal)) {
|
|
937
|
-
return;
|
|
938
|
-
}
|
|
939
|
-
statusReactions.cancelPending();
|
|
940
|
-
await statusReactions.setThinking();
|
|
941
|
-
},
|
|
942
|
-
},
|
|
943
|
-
}),
|
|
944
|
-
});
|
|
945
|
-
if (!preparedResult.dispatched) {
|
|
946
|
-
return;
|
|
947
|
-
}
|
|
948
|
-
dispatchResult = preparedResult.dispatchResult;
|
|
949
|
-
if (isProcessAborted(abortSignal)) {
|
|
950
|
-
dispatchAborted = true;
|
|
951
|
-
return;
|
|
952
|
-
}
|
|
953
|
-
} catch (err) {
|
|
954
|
-
if (isProcessAborted(abortSignal)) {
|
|
955
|
-
dispatchAborted = true;
|
|
956
|
-
return;
|
|
957
|
-
}
|
|
958
|
-
dispatchError = true;
|
|
959
|
-
throw err;
|
|
960
|
-
} finally {
|
|
961
|
-
endDiscordInboundEventDeliveryCorrelation();
|
|
962
|
-
try {
|
|
963
|
-
await draftPreview.cleanup();
|
|
964
|
-
} finally {
|
|
965
|
-
if (!dispatchSettledBeforeStart) {
|
|
966
|
-
markRunComplete();
|
|
967
|
-
markDispatchIdle();
|
|
968
|
-
}
|
|
969
|
-
}
|
|
970
|
-
const finalDeliveryFailed = (dispatchResult?.failedCounts?.final ?? 0) > 0;
|
|
971
|
-
if (statusReactionsActive) {
|
|
972
|
-
if (dispatchAborted) {
|
|
973
|
-
if (removeAckAfterReply) {
|
|
974
|
-
void statusReactions.clear();
|
|
975
|
-
} else {
|
|
976
|
-
void statusReactions.restoreInitial();
|
|
977
|
-
}
|
|
978
|
-
} else {
|
|
979
|
-
if (dispatchError || finalDeliveryFailed) {
|
|
980
|
-
await statusReactions.setError();
|
|
981
|
-
} else {
|
|
982
|
-
await statusReactions.setDone();
|
|
983
|
-
}
|
|
984
|
-
if (removeAckAfterReply) {
|
|
985
|
-
void (async () => {
|
|
986
|
-
await sleep(
|
|
987
|
-
dispatchError || finalDeliveryFailed
|
|
988
|
-
? DEFAULT_TIMING.errorHoldMs
|
|
989
|
-
: DEFAULT_TIMING.doneHoldMs,
|
|
990
|
-
);
|
|
991
|
-
await statusReactions.clear();
|
|
992
|
-
})();
|
|
993
|
-
} else {
|
|
994
|
-
void statusReactions.restoreInitial();
|
|
995
|
-
}
|
|
996
|
-
}
|
|
997
|
-
} else if (shouldSendAckReaction && ackReaction && removeAckAfterReply) {
|
|
998
|
-
void removeReactionDiscord(
|
|
999
|
-
messageChannelId,
|
|
1000
|
-
message.id,
|
|
1001
|
-
ackReaction,
|
|
1002
|
-
ackReactionContext,
|
|
1003
|
-
).catch((err: unknown) => {
|
|
1004
|
-
logAckFailure({
|
|
1005
|
-
log: logVerbose,
|
|
1006
|
-
channel: "discord",
|
|
1007
|
-
target: `${messageChannelId}/${message.id}`,
|
|
1008
|
-
error: err,
|
|
1009
|
-
});
|
|
1010
|
-
});
|
|
1011
|
-
}
|
|
1012
|
-
}
|
|
1013
|
-
if (dispatchAborted) {
|
|
1014
|
-
return;
|
|
1015
|
-
}
|
|
1016
|
-
|
|
1017
|
-
const finalDispatchResult = dispatchResult;
|
|
1018
|
-
if (!finalDispatchResult || !hasFinalInboundReplyDispatch(finalDispatchResult)) {
|
|
1019
|
-
return;
|
|
1020
|
-
}
|
|
1021
|
-
if (shouldLogVerbose()) {
|
|
1022
|
-
const finalCount = finalDispatchResult.counts.final;
|
|
1023
|
-
logVerbose(
|
|
1024
|
-
`discord: delivered ${finalCount} reply${finalCount === 1 ? "" : "ies"} to ${replyTarget}`,
|
|
1025
|
-
);
|
|
1026
|
-
}
|
|
1027
|
-
}
|