@ashx-j/lunr-dev 0.2.21-dev.12.1 → 0.2.25-dev.13.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +25 -2
- package/dist/builtin-extensions/ashxj-tui.d.ts.map +1 -1
- package/dist/builtin-extensions/ashxj-tui.js +2 -2
- package/dist/builtin-extensions/ashxj-tui.js.map +1 -1
- package/dist/builtin-extensions/index.d.ts.map +1 -1
- package/dist/builtin-extensions/index.js +1 -0
- package/dist/builtin-extensions/index.js.map +1 -1
- package/dist/builtin-extensions/lunr-browser.d.ts +9 -0
- package/dist/builtin-extensions/lunr-browser.d.ts.map +1 -0
- package/dist/builtin-extensions/lunr-browser.js +169 -0
- package/dist/builtin-extensions/lunr-browser.js.map +1 -0
- package/dist/builtin-extensions/lunr-computer-use.d.ts.map +1 -1
- package/dist/builtin-extensions/lunr-computer-use.js +3 -3
- package/dist/builtin-extensions/lunr-computer-use.js.map +1 -1
- package/dist/builtin-extensions/lunr-plan-tools.d.ts +7 -7
- package/dist/builtin-extensions/lunr-plan-tools.d.ts.map +1 -1
- package/dist/builtin-extensions/lunr-plan-tools.js +12 -12
- package/dist/builtin-extensions/lunr-plan-tools.js.map +1 -1
- package/dist/builtin-extensions/lunr-todos.d.ts.map +1 -1
- package/dist/builtin-extensions/lunr-todos.js +15 -0
- package/dist/builtin-extensions/lunr-todos.js.map +1 -1
- package/dist/builtin-extensions/pi-intercom/index.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-intercom/index.js +5 -0
- package/dist/builtin-extensions/pi-intercom/index.js.map +1 -1
- package/dist/builtin-extensions/pi-mcp-adapter/direct-tools.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-mcp-adapter/direct-tools.js +1 -0
- package/dist/builtin-extensions/pi-mcp-adapter/direct-tools.js.map +1 -1
- package/dist/builtin-extensions/pi-mcp-adapter/index.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-mcp-adapter/index.js +1 -1
- package/dist/builtin-extensions/pi-mcp-adapter/index.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/extension/control-notices.d.ts +1 -1
- package/dist/builtin-extensions/pi-subagents/src/extension/control-notices.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/extension/control-notices.js +5 -1
- package/dist/builtin-extensions/pi-subagents/src/extension/control-notices.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/extension/index.d.ts +2 -2
- package/dist/builtin-extensions/pi-subagents/src/extension/index.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/extension/index.js +18 -5
- package/dist/builtin-extensions/pi-subagents/src/extension/index.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/extension/schemas.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/extension/schemas.js +1 -1
- package/dist/builtin-extensions/pi-subagents/src/extension/schemas.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/extension/tool-description.d.ts +4 -3
- package/dist/builtin-extensions/pi-subagents/src/extension/tool-description.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/extension/tool-description.js +8 -3
- package/dist/builtin-extensions/pi-subagents/src/extension/tool-description.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/intercom/communication.d.ts +17 -0
- package/dist/builtin-extensions/pi-subagents/src/intercom/communication.d.ts.map +1 -0
- package/dist/builtin-extensions/pi-subagents/src/intercom/communication.js +45 -0
- package/dist/builtin-extensions/pi-subagents/src/intercom/communication.js.map +1 -0
- package/dist/builtin-extensions/pi-subagents/src/intercom/intercom-bridge.d.ts +2 -0
- package/dist/builtin-extensions/pi-subagents/src/intercom/intercom-bridge.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/intercom/intercom-bridge.js +10 -14
- package/dist/builtin-extensions/pi-subagents/src/intercom/intercom-bridge.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/intercom/native-supervisor-channel.d.ts +4 -1
- package/dist/builtin-extensions/pi-subagents/src/intercom/native-supervisor-channel.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/intercom/native-supervisor-channel.js +167 -53
- package/dist/builtin-extensions/pi-subagents/src/intercom/native-supervisor-channel.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/intercom/supervisor-ask.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/intercom/supervisor-ask.js +5 -0
- package/dist/builtin-extensions/pi-subagents/src/intercom/supervisor-ask.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/intercom/supervisor-questions.d.ts +2 -0
- package/dist/builtin-extensions/pi-subagents/src/intercom/supervisor-questions.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/intercom/supervisor-questions.js +3 -2
- package/dist/builtin-extensions/pi-subagents/src/intercom/supervisor-questions.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/background/async-execution.d.ts +2 -0
- package/dist/builtin-extensions/pi-subagents/src/runs/background/async-execution.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/background/async-execution.js +4 -0
- package/dist/builtin-extensions/pi-subagents/src/runs/background/async-execution.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/background/auto-drain.d.ts +1 -0
- package/dist/builtin-extensions/pi-subagents/src/runs/background/auto-drain.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/background/auto-drain.js +2 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/background/auto-drain.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/background/subagent-runner.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/background/subagent-runner.js +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/background/subagent-runner.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/background/subagent-wait.d.ts +3 -0
- package/dist/builtin-extensions/pi-subagents/src/runs/background/subagent-wait.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/background/subagent-wait.js +11 -0
- package/dist/builtin-extensions/pi-subagents/src/runs/background/subagent-wait.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/background/wait-tool.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/background/wait-tool.js +41 -3
- package/dist/builtin-extensions/pi-subagents/src/runs/background/wait-tool.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/foreground/chain-execution.d.ts +1 -0
- package/dist/builtin-extensions/pi-subagents/src/runs/foreground/chain-execution.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/foreground/chain-execution.js +5 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/foreground/chain-execution.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/foreground/execution.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/foreground/execution.js +3 -2
- package/dist/builtin-extensions/pi-subagents/src/runs/foreground/execution.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/foreground/subagent-executor.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/foreground/subagent-executor.js +23 -0
- package/dist/builtin-extensions/pi-subagents/src/runs/foreground/subagent-executor.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/shared/child-tools.d.ts +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/shared/child-tools.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/shared/child-tools.js +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/shared/child-tools.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/shared/pi-args.d.ts +2 -0
- package/dist/builtin-extensions/pi-subagents/src/runs/shared/pi-args.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/shared/pi-args.js +20 -15
- package/dist/builtin-extensions/pi-subagents/src/runs/shared/pi-args.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/shared/subagent-control.d.ts +1 -0
- package/dist/builtin-extensions/pi-subagents/src/runs/shared/subagent-control.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/shared/subagent-control.js +3 -0
- package/dist/builtin-extensions/pi-subagents/src/runs/shared/subagent-control.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/shared/subagent-prompt-runtime.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/shared/subagent-prompt-runtime.js +4 -2
- package/dist/builtin-extensions/pi-subagents/src/runs/shared/subagent-prompt-runtime.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/shared/child-spec.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/shared/child-spec.js +2 -2
- package/dist/builtin-extensions/pi-subagents/src/shared/child-spec.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/shared/types.d.ts +2 -0
- package/dist/builtin-extensions/pi-subagents/src/shared/types.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/shared/types.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/tui/communication.d.ts +18 -0
- package/dist/builtin-extensions/pi-subagents/src/tui/communication.d.ts.map +1 -0
- package/dist/builtin-extensions/pi-subagents/src/tui/communication.js +48 -0
- package/dist/builtin-extensions/pi-subagents/src/tui/communication.js.map +1 -0
- package/dist/builtin-extensions/pi-web-access/index.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-web-access/index.js +11 -7
- package/dist/builtin-extensions/pi-web-access/index.js.map +1 -1
- package/dist/cli/args.d.ts.map +1 -1
- package/dist/cli/args.js +2 -1
- package/dist/cli/args.js.map +1 -1
- package/dist/cli/install-cli.d.ts.map +1 -1
- package/dist/cli/install-cli.js +15 -45
- package/dist/cli/install-cli.js.map +1 -1
- package/dist/core/agent-session-runtime.d.ts +9 -0
- package/dist/core/agent-session-runtime.d.ts.map +1 -1
- package/dist/core/agent-session-runtime.js +126 -29
- package/dist/core/agent-session-runtime.js.map +1 -1
- package/dist/core/agent-session.d.ts +23 -1
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +255 -109
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/browser/network.d.ts +9 -0
- package/dist/core/browser/network.d.ts.map +1 -0
- package/dist/core/browser/network.js +146 -0
- package/dist/core/browser/network.js.map +1 -0
- package/dist/core/browser/runtime.d.ts +24 -0
- package/dist/core/browser/runtime.d.ts.map +1 -0
- package/dist/core/browser/runtime.js +289 -0
- package/dist/core/browser/runtime.js.map +1 -0
- package/dist/core/browser/schema.d.ts +16 -0
- package/dist/core/browser/schema.d.ts.map +1 -0
- package/dist/core/browser/schema.js +36 -0
- package/dist/core/browser/schema.js.map +1 -0
- package/dist/core/browser/settings.d.ts +8 -0
- package/dist/core/browser/settings.d.ts.map +1 -0
- package/dist/core/browser/settings.js +30 -0
- package/dist/core/browser/settings.js.map +1 -0
- package/dist/core/browser/setup.d.ts +2 -0
- package/dist/core/browser/setup.d.ts.map +1 -0
- package/dist/core/browser/setup.js +16 -0
- package/dist/core/browser/setup.js.map +1 -0
- package/dist/core/catalog-cache-scope.d.ts.map +1 -1
- package/dist/core/catalog-cache-scope.js +3 -1
- package/dist/core/catalog-cache-scope.js.map +1 -1
- package/dist/core/computer-use/image.d.ts +1 -0
- package/dist/core/computer-use/image.d.ts.map +1 -1
- package/dist/core/computer-use/image.js +8 -0
- package/dist/core/computer-use/image.js.map +1 -1
- package/dist/core/computer-use/schemas.d.ts +1 -0
- package/dist/core/computer-use/schemas.d.ts.map +1 -1
- package/dist/core/computer-use/schemas.js +2 -1
- package/dist/core/computer-use/schemas.js.map +1 -1
- package/dist/core/computer-use/workflow.d.ts.map +1 -1
- package/dist/core/computer-use/workflow.js +89 -23
- package/dist/core/computer-use/workflow.js.map +1 -1
- package/dist/core/customize.d.ts.map +1 -1
- package/dist/core/customize.js +15 -14
- package/dist/core/customize.js.map +1 -1
- package/dist/core/export-html/index.d.ts.map +1 -1
- package/dist/core/export-html/index.js +1 -1
- package/dist/core/export-html/index.js.map +1 -1
- package/dist/core/extensions/loader.d.ts.map +1 -1
- package/dist/core/extensions/loader.js +4 -0
- package/dist/core/extensions/loader.js.map +1 -1
- package/dist/core/extensions/runner.d.ts +1 -0
- package/dist/core/extensions/runner.d.ts.map +1 -1
- package/dist/core/extensions/runner.js +1 -1
- package/dist/core/extensions/runner.js.map +1 -1
- package/dist/core/extensions/types.d.ts +1 -1
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.js.map +1 -1
- package/dist/core/install-features.d.ts.map +1 -1
- package/dist/core/install-features.js +10 -8
- package/dist/core/install-features.js.map +1 -1
- package/dist/core/memory-cap.d.ts.map +1 -1
- package/dist/core/memory-cap.js +5 -3
- package/dist/core/memory-cap.js.map +1 -1
- package/dist/core/model-runtime.d.ts.map +1 -1
- package/dist/core/model-runtime.js +3 -2
- package/dist/core/model-runtime.js.map +1 -1
- package/dist/core/model-tiers.d.ts.map +1 -1
- package/dist/core/model-tiers.js +9 -6
- package/dist/core/model-tiers.js.map +1 -1
- package/dist/core/permissions.d.ts +16 -23
- package/dist/core/permissions.d.ts.map +1 -1
- package/dist/core/permissions.js +71 -142
- package/dist/core/permissions.js.map +1 -1
- package/dist/core/plan-mode.d.ts +10 -12
- package/dist/core/plan-mode.d.ts.map +1 -1
- package/dist/core/plan-mode.js +20 -19
- package/dist/core/plan-mode.js.map +1 -1
- package/dist/core/process-registry.d.ts.map +1 -1
- package/dist/core/process-registry.js +6 -4
- package/dist/core/process-registry.js.map +1 -1
- package/dist/core/runtime-bridges.d.ts.map +1 -1
- package/dist/core/runtime-bridges.js +2 -0
- package/dist/core/runtime-bridges.js.map +1 -1
- package/dist/core/runtime-scope.d.ts +11 -0
- package/dist/core/runtime-scope.d.ts.map +1 -0
- package/dist/core/runtime-scope.js +3 -0
- package/dist/core/runtime-scope.js.map +1 -0
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +26 -6
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/session-handoff.d.ts +35 -0
- package/dist/core/session-handoff.d.ts.map +1 -0
- package/dist/core/session-handoff.js +214 -0
- package/dist/core/session-handoff.js.map +1 -0
- package/dist/core/session-manager.d.ts +20 -0
- package/dist/core/session-manager.d.ts.map +1 -1
- package/dist/core/session-manager.js +191 -22
- package/dist/core/session-manager.js.map +1 -1
- package/dist/core/session-ownership.d.ts +28 -0
- package/dist/core/session-ownership.d.ts.map +1 -0
- package/dist/core/session-ownership.js +138 -0
- package/dist/core/session-ownership.js.map +1 -0
- package/dist/core/session-retention.d.ts.map +1 -1
- package/dist/core/session-retention.js +11 -2
- package/dist/core/session-retention.js.map +1 -1
- package/dist/core/settings-manager.d.ts +20 -1
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +67 -1
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/slash-commands.d.ts.map +1 -1
- package/dist/core/slash-commands.js +6 -4
- package/dist/core/slash-commands.js.map +1 -1
- package/dist/core/subagent-permission-inherit.d.ts +6 -10
- package/dist/core/subagent-permission-inherit.d.ts.map +1 -1
- package/dist/core/subagent-permission-inherit.js +14 -14
- package/dist/core/subagent-permission-inherit.js.map +1 -1
- package/dist/core/subagent-wait-interruption.d.ts +11 -0
- package/dist/core/subagent-wait-interruption.d.ts.map +1 -0
- package/dist/core/subagent-wait-interruption.js +19 -0
- package/dist/core/subagent-wait-interruption.js.map +1 -0
- package/dist/core/system-prompt.d.ts +2 -0
- package/dist/core/system-prompt.d.ts.map +1 -1
- package/dist/core/system-prompt.js +14 -4
- package/dist/core/system-prompt.js.map +1 -1
- package/dist/core/todo-settings.d.ts +5 -0
- package/dist/core/todo-settings.d.ts.map +1 -0
- package/dist/core/todo-settings.js +7 -0
- package/dist/core/todo-settings.js.map +1 -0
- package/dist/core/tools/bash.d.ts.map +1 -1
- package/dist/core/tools/bash.js +4 -4
- package/dist/core/tools/bash.js.map +1 -1
- package/dist/core/tools/edit.d.ts.map +1 -1
- package/dist/core/tools/edit.js +5 -3
- package/dist/core/tools/edit.js.map +1 -1
- package/dist/core/tools/find.d.ts.map +1 -1
- package/dist/core/tools/find.js +4 -4
- package/dist/core/tools/find.js.map +1 -1
- package/dist/core/tools/grep.d.ts.map +1 -1
- package/dist/core/tools/grep.js +4 -4
- package/dist/core/tools/grep.js.map +1 -1
- package/dist/core/tools/ls.d.ts.map +1 -1
- package/dist/core/tools/ls.js +4 -4
- package/dist/core/tools/ls.js.map +1 -1
- package/dist/core/tools/read.d.ts.map +1 -1
- package/dist/core/tools/read.js +4 -4
- package/dist/core/tools/read.js.map +1 -1
- package/dist/core/tools/render-utils.d.ts +14 -5
- package/dist/core/tools/render-utils.d.ts.map +1 -1
- package/dist/core/tools/render-utils.js +34 -7
- package/dist/core/tools/render-utils.js.map +1 -1
- package/dist/core/tools/write.d.ts.map +1 -1
- package/dist/core/tools/write.js +4 -4
- package/dist/core/tools/write.js.map +1 -1
- package/dist/core/usage-service.d.ts.map +1 -1
- package/dist/core/usage-service.js +5 -3
- package/dist/core/usage-service.js.map +1 -1
- package/dist/gateway/adapters/discord.d.ts +12 -1
- package/dist/gateway/adapters/discord.d.ts.map +1 -1
- package/dist/gateway/adapters/discord.js +114 -24
- package/dist/gateway/adapters/discord.js.map +1 -1
- package/dist/gateway/adapters/telegram.d.ts +4 -2
- package/dist/gateway/adapters/telegram.d.ts.map +1 -1
- package/dist/gateway/adapters/telegram.js +41 -11
- package/dist/gateway/adapters/telegram.js.map +1 -1
- package/dist/gateway/agent-bridge.d.ts +18 -4
- package/dist/gateway/agent-bridge.d.ts.map +1 -1
- package/dist/gateway/agent-bridge.js +305 -73
- package/dist/gateway/agent-bridge.js.map +1 -1
- package/dist/gateway/approval.d.ts +3 -6
- package/dist/gateway/approval.d.ts.map +1 -1
- package/dist/gateway/approval.js +62 -24
- package/dist/gateway/approval.js.map +1 -1
- package/dist/gateway/authz.d.ts +2 -0
- package/dist/gateway/authz.d.ts.map +1 -1
- package/dist/gateway/authz.js +13 -0
- package/dist/gateway/authz.js.map +1 -1
- package/dist/gateway/buttons.d.ts +3 -1
- package/dist/gateway/buttons.d.ts.map +1 -1
- package/dist/gateway/buttons.js +45 -20
- package/dist/gateway/buttons.js.map +1 -1
- package/dist/gateway/command.d.ts.map +1 -1
- package/dist/gateway/command.js +49 -4
- package/dist/gateway/command.js.map +1 -1
- package/dist/gateway/commands.d.ts +2 -0
- package/dist/gateway/commands.d.ts.map +1 -1
- package/dist/gateway/commands.js +52 -16
- package/dist/gateway/commands.js.map +1 -1
- package/dist/gateway/config.d.ts +6 -0
- package/dist/gateway/config.d.ts.map +1 -1
- package/dist/gateway/config.js +7 -0
- package/dist/gateway/config.js.map +1 -1
- package/dist/gateway/conversations.d.ts +14 -0
- package/dist/gateway/conversations.d.ts.map +1 -0
- package/dist/gateway/conversations.js +30 -0
- package/dist/gateway/conversations.js.map +1 -0
- package/dist/gateway/cron.d.ts +1 -1
- package/dist/gateway/cron.d.ts.map +1 -1
- package/dist/gateway/cron.js +2 -2
- package/dist/gateway/cron.js.map +1 -1
- package/dist/gateway/download.d.ts +2 -0
- package/dist/gateway/download.d.ts.map +1 -0
- package/dist/gateway/download.js +36 -0
- package/dist/gateway/download.js.map +1 -0
- package/dist/gateway/index.d.ts.map +1 -1
- package/dist/gateway/index.js +106 -47
- package/dist/gateway/index.js.map +1 -1
- package/dist/gateway/mobile-commands.d.ts +24 -0
- package/dist/gateway/mobile-commands.d.ts.map +1 -0
- package/dist/gateway/mobile-commands.js +423 -0
- package/dist/gateway/mobile-commands.js.map +1 -0
- package/dist/gateway/presenter.d.ts +27 -0
- package/dist/gateway/presenter.d.ts.map +1 -0
- package/dist/gateway/presenter.js +308 -0
- package/dist/gateway/presenter.js.map +1 -0
- package/dist/gateway/router.d.ts +6 -5
- package/dist/gateway/router.d.ts.map +1 -1
- package/dist/gateway/router.js +126 -43
- package/dist/gateway/router.js.map +1 -1
- package/dist/gateway/service.d.ts +46 -0
- package/dist/gateway/service.d.ts.map +1 -0
- package/dist/gateway/service.js +404 -0
- package/dist/gateway/service.js.map +1 -0
- package/dist/gateway/setup.d.ts +9 -0
- package/dist/gateway/setup.d.ts.map +1 -0
- package/dist/gateway/setup.js +202 -0
- package/dist/gateway/setup.js.map +1 -0
- package/dist/gateway/stream.d.ts +6 -5
- package/dist/gateway/stream.d.ts.map +1 -1
- package/dist/gateway/stream.js +24 -11
- package/dist/gateway/stream.js.map +1 -1
- package/dist/gateway/types.d.ts +4 -2
- package/dist/gateway/types.d.ts.map +1 -1
- package/dist/gateway/types.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +3 -3
- package/dist/main.js.map +1 -1
- package/dist/modes/interactive/components/assistant-message.d.ts +19 -2
- package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/assistant-message.js +78 -17
- package/dist/modes/interactive/components/assistant-message.js.map +1 -1
- package/dist/modes/interactive/components/copyable-text.d.ts +27 -0
- package/dist/modes/interactive/components/copyable-text.d.ts.map +1 -0
- package/dist/modes/interactive/components/copyable-text.js +156 -0
- package/dist/modes/interactive/components/copyable-text.js.map +1 -0
- package/dist/modes/interactive/components/custom-entry.d.ts +1 -0
- package/dist/modes/interactive/components/custom-entry.d.ts.map +1 -1
- package/dist/modes/interactive/components/custom-entry.js +8 -0
- package/dist/modes/interactive/components/custom-entry.js.map +1 -1
- package/dist/modes/interactive/components/custom-message.d.ts +1 -0
- package/dist/modes/interactive/components/custom-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/custom-message.js +8 -0
- package/dist/modes/interactive/components/custom-message.js.map +1 -1
- package/dist/modes/interactive/components/session-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/session-selector.js +16 -0
- package/dist/modes/interactive/components/session-selector.js.map +1 -1
- package/dist/modes/interactive/components/settings-selector.d.ts +12 -1
- package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/settings-selector.js +74 -3
- package/dist/modes/interactive/components/settings-selector.js.map +1 -1
- package/dist/modes/interactive/components/thinking-tail.d.ts +9 -2
- package/dist/modes/interactive/components/thinking-tail.d.ts.map +1 -1
- package/dist/modes/interactive/components/thinking-tail.js +43 -1
- package/dist/modes/interactive/components/thinking-tail.js.map +1 -1
- package/dist/modes/interactive/components/tool-execution.d.ts +5 -3
- package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
- package/dist/modes/interactive/components/tool-execution.js +44 -45
- package/dist/modes/interactive/components/tool-execution.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts +10 -2
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +342 -133
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/interactive/theme/theme.d.ts +1 -0
- package/dist/modes/interactive/theme/theme.d.ts.map +1 -1
- package/dist/modes/interactive/theme/theme.js +23 -0
- package/dist/modes/interactive/theme/theme.js.map +1 -1
- package/dist/node-runtime/agent-session-services-MQUPZSIN.js +51 -0
- package/dist/node-runtime/{builtin-extensions-SRCYQPZ6.js → builtin-extensions-4GNDR6U3.js} +7 -6
- package/dist/node-runtime/{chunk-LTXUQJI4.js → chunk-24C5IAJ4.js} +1 -6
- package/dist/node-runtime/chunk-2BLXLDJR.js +144 -0
- package/dist/node-runtime/{chunk-RQ5DNUNG.js → chunk-2CMV4L24.js} +21 -124
- package/dist/node-runtime/{chunk-LTYWTR3V.js → chunk-2MI5OPMN.js} +17 -2
- package/dist/node-runtime/{chunk-W3CVH5RX.js → chunk-2TKODGBZ.js} +11 -6
- package/dist/node-runtime/{chunk-GT5F3OKM.js → chunk-33SIKK3Y.js} +38 -164
- package/dist/node-runtime/{chunk-GZQHMEWL.js → chunk-3DKIWPKN.js} +19 -4
- package/dist/node-runtime/{chunk-3GHXVUAK.js → chunk-3VEY2IYY.js} +1 -1
- package/dist/node-runtime/chunk-4ER2ZV4Z.js +537 -0
- package/dist/node-runtime/chunk-4EULYYR4.js +62 -0
- package/dist/node-runtime/{chunk-LOYUC2ID.js → chunk-4SBQAI4T.js} +27 -27
- package/dist/node-runtime/{chunk-CZUBYPFP.js → chunk-53ARRUHA.js} +674 -257
- package/dist/node-runtime/{chunk-VTPM5V35.js → chunk-5Q4A37RB.js} +10 -4
- package/dist/node-runtime/{chunk-SWSN6HAB.js → chunk-5UZOPGE3.js} +1 -1
- package/dist/node-runtime/{chunk-XSRCAQK2.js → chunk-5Z5PCXGY.js} +263 -222
- package/dist/node-runtime/chunk-7JIYPIQU.js +356 -0
- package/dist/node-runtime/{chunk-D466UAID.js → chunk-AJ6R5VTV.js} +60 -88
- package/dist/node-runtime/chunk-ATIF3RX5.js +352 -0
- package/dist/node-runtime/{chunk-A3KMVBZV.js → chunk-BBUVIEZB.js} +1 -10
- package/dist/node-runtime/chunk-CCCN2UCX.js +14 -0
- package/dist/node-runtime/chunk-CJS4KQFI.js +3412 -0
- package/dist/node-runtime/chunk-DO6PALE2.js +205 -0
- package/dist/node-runtime/{chunk-N3PNL74S.js → chunk-DRJI7ZSC.js} +63 -163
- package/dist/node-runtime/{chunk-VTGEKB7R.js → chunk-E75WFZ33.js} +1 -1
- package/dist/node-runtime/{chunk-MJQDX3BA.js → chunk-EBB4BJW4.js} +3 -3
- package/dist/node-runtime/{chunk-VQ4UBWSA.js → chunk-EOEAQIJV.js} +63 -6
- package/dist/node-runtime/chunk-EOPL2HMM.js +117 -0
- package/dist/node-runtime/chunk-H4K3JDRB.js +47 -0
- package/dist/node-runtime/{chunk-HRS4HMDX.js → chunk-HT2XEJNP.js} +19 -3
- package/dist/node-runtime/chunk-IMLCWLPI.js +9 -0
- package/dist/node-runtime/{chunk-BJ6H7DPI.js → chunk-JJWZB7S3.js} +62 -50
- package/dist/node-runtime/chunk-KFFOQR4G.js +672 -0
- package/dist/node-runtime/chunk-L5LZUGT7.js +40 -0
- package/dist/node-runtime/chunk-LV6CEFW2.js +97 -0
- package/dist/node-runtime/{chunk-VSELYKWU.js → chunk-LWYIVUGV.js} +2 -1
- package/dist/node-runtime/{chunk-BYQ2MOFI.js → chunk-MFV2LOOX.js} +184 -2192
- package/dist/node-runtime/{chunk-5SQDLSZJ.js → chunk-MNRO3UCV.js} +2 -2
- package/dist/node-runtime/{chunk-JHYKXIMM.js → chunk-MPKSOJBT.js} +1 -1
- package/dist/node-runtime/{chunk-C4O2RSQQ.js → chunk-N4TUWAGA.js} +1 -1
- package/dist/node-runtime/{chunk-7NBZ5P7I.js → chunk-NAY6UUQZ.js} +1 -1
- package/dist/node-runtime/chunk-NKH2QBKF.js +773 -0
- package/dist/node-runtime/chunk-O2AT4MEU.js +124 -0
- package/dist/node-runtime/chunk-OAR4TYZE.js +146 -0
- package/dist/node-runtime/{chunk-DDGMHUOW.js → chunk-OGJN3OZV.js} +2 -1
- package/dist/node-runtime/{chunk-MX3GJNXJ.js → chunk-PLGA743X.js} +23 -0
- package/dist/node-runtime/chunk-Q3FEOEDA.js +1364 -0
- package/dist/node-runtime/{chunk-H2BI7G7T.js → chunk-QFADHUQV.js} +2 -1
- package/dist/node-runtime/{chunk-W3SILANP.js → chunk-RBZQU6TJ.js} +12 -9
- package/dist/node-runtime/{chunk-ZVSORYRM.js → chunk-RVOQBXTA.js} +10 -6
- package/dist/node-runtime/{chunk-HXJS2PJM.js → chunk-RW4PYFNE.js} +14 -94
- package/dist/node-runtime/chunk-TP7K7YWS.js +2830 -0
- package/dist/node-runtime/{chunk-ZOIIMEN6.js → chunk-TVLBDVTR.js} +32 -21
- package/dist/node-runtime/chunk-UAEOTO52.js +119 -0
- package/dist/node-runtime/{chunk-MGWCVY6Y.js → chunk-UDKX3PFN.js} +3 -3
- package/dist/node-runtime/{chunk-AY6CAJSL.js → chunk-UJOCPOMX.js} +6 -3
- package/dist/node-runtime/{chunk-WJVFOIB5.js → chunk-UQUCFAJ3.js} +1 -1
- package/dist/node-runtime/chunk-US544NN6.js +13 -0
- package/dist/node-runtime/{chunk-7AFOFSDY.js → chunk-V3HK3FE7.js} +1 -1
- package/dist/node-runtime/{chunk-6UB6NKA3.js → chunk-VIVYOI7C.js} +130 -27
- package/dist/node-runtime/{chunk-MW2XJZIK.js → chunk-XHIRAZ26.js} +1 -1
- package/dist/node-runtime/chunk-YPHAIRZT.js +10 -0
- package/dist/node-runtime/{chunk-3RCWXWAY.js → chunk-YRUY57IN.js} +1 -1
- package/dist/node-runtime/cli-runtime.js +2 -2
- package/dist/node-runtime/command-PYBNGLPP.js +45 -0
- package/dist/node-runtime/{commands-BZGSLIP7.js → commands-EMBQQVVT.js} +13 -13
- package/dist/node-runtime/commands-Y2OUC2T7.js +37 -0
- package/dist/node-runtime/config-7DYMNJUO.js +20 -0
- package/dist/node-runtime/{customize-LF5VST47.js → customize-VFJV3U6A.js} +2 -1
- package/dist/node-runtime/{direct-tool-executor-BSZDHIYR.js → direct-tool-executor-4D7UXYU4.js} +10 -10
- package/dist/node-runtime/{export-html-E4DT6ZJQ.js → export-html-ETFOKW3M.js} +4 -3
- package/dist/node-runtime/{extension-input-RV5N6APL.js → extension-input-7QODTFAS.js} +4 -4
- package/dist/node-runtime/{extension-selector-CPD5LWDD.js → extension-selector-T65JEDJ5.js} +4 -4
- package/dist/node-runtime/{extract-XLQSJN4V.js → extract-EQJE7FZZ.js} +2 -2
- package/dist/node-runtime/gateway-QENRQA5X.js +1476 -0
- package/dist/node-runtime/{gemini-search-U7SUMPQA.js → gemini-search-35OCRFLN.js} +1 -1
- package/dist/node-runtime/{gemini-url-context-PXWCBQHK.js → gemini-url-context-UQY3PHHW.js} +2 -2
- package/dist/node-runtime/index.js +113 -73
- package/dist/node-runtime/{init-DVJUAOUO.js → init-P5AUV77I.js} +5 -5
- package/dist/node-runtime/{install-cli-TH7IJJQQ.js → install-cli-KHAXYBOO.js} +21 -82
- package/dist/node-runtime/interactive-mode-IN77GQGX.js +74 -0
- package/dist/node-runtime/{interactive-view-N6F4KUIT.js → interactive-view-OMWDFGUQ.js} +10 -10
- package/dist/node-runtime/lunr-browser-VVPRWC3F.js +174 -0
- package/dist/node-runtime/{lunr-computer-use-TJNDAMWM.js → lunr-computer-use-IAUNXSXH.js} +11 -8
- package/dist/node-runtime/{lunr-cron-J64I72C6.js → lunr-cron-P6ZJGVEF.js} +21 -7
- package/dist/node-runtime/main.js +47 -34
- package/dist/node-runtime/{mcp-auth-flow-YL6RWPYG.js → mcp-auth-flow-QVLFVLEO.js} +2 -2
- package/dist/node-runtime/{memory-cap-3S4XRLNP.js → memory-cap-EL3KL4JJ.js} +2 -1
- package/dist/node-runtime/mobile-commands-WKFSFACZ.js +33 -0
- package/dist/node-runtime/model-runtime-YXGJS5OJ.js +16 -0
- package/dist/node-runtime/{model-tiers-NJLHUEGK.js → model-tiers-OU3U5CZG.js} +2 -1
- package/dist/node-runtime/{package-manager-cli-VMYX4Y2S.js → package-manager-cli-J337RKTI.js} +25 -17
- package/dist/node-runtime/{pi-intercom-NV2LW6X7.js → pi-intercom-QM53RLTS.js} +6 -1
- package/dist/node-runtime/{pi-mcp-adapter-JLB5YL2F.js → pi-mcp-adapter-3PHF4KZ4.js} +8 -7
- package/dist/node-runtime/{pi-subagents-WEHV3W7H.js → pi-subagents-RCHPB6UK.js} +255 -88
- package/dist/node-runtime/{pi-web-access-FN5YC5T6.js → pi-web-access-PNG35XW7.js} +15 -15
- package/dist/node-runtime/process-registry-PVJ44F7H.js +31 -0
- package/dist/node-runtime/{proxy-modes-OR7ISBXK.js → proxy-modes-5FAPSZEZ.js} +11 -11
- package/dist/node-runtime/rpc-entry.js +47 -34
- package/dist/node-runtime/{rpc-mode-SJNSOA4G.js → rpc-mode-SH7VB4RH.js} +2 -2
- package/dist/node-runtime/runtime-4VA6JKNF.js +373 -0
- package/dist/node-runtime/runtime-bridges-3CQHWVVY.js +21 -0
- package/dist/node-runtime/service-HGGU3STY.js +36 -0
- package/dist/node-runtime/session-handoff-IAFIK7QP.js +33 -0
- package/dist/node-runtime/{session-manager-QEMZBMTM.js → session-manager-TCEFDKBL.js} +2 -1
- package/dist/node-runtime/{session-selector-URVJLOTK.js → session-selector-HG5J4BDZ.js} +5 -4
- package/dist/node-runtime/{settings-manager-3CCU326G.js → settings-manager-HIBIUNBK.js} +12 -5
- package/dist/node-runtime/setup-JBKOLJ6F.js +18 -0
- package/dist/node-runtime/setup-YU5LKRL3.js +215 -0
- package/dist/node-runtime/{subagent-executor-CXKXQDHH.js → subagent-executor-2BH76MMS.js} +64 -23
- package/dist/node-runtime/theme-WTJWZSGD.js +68 -0
- package/dist/node-runtime/trust-manager-6ZQANSBX.js +17 -0
- package/dist/node-runtime/{update-cli-NM7B4CKL.js → update-cli-TVTPVUNM.js} +6 -3
- package/dist/node-runtime/usage-service-LFB2SWYV.js +37 -0
- package/dist/node-runtime/{video-extract-OYT5WKS5.js → video-extract-OOZHR7SU.js} +2 -2
- package/dist/node-runtime/{workflow-C26QCUTW.js → workflow-TVJNKKQP.js} +80 -39
- package/dist/node-runtime/{youtube-extract-TQYKGFGS.js → youtube-extract-FNPAUNHU.js} +6 -6
- package/dist/startup/interactive-view.d.ts.map +1 -1
- package/dist/startup/interactive-view.js +5 -1
- package/dist/startup/interactive-view.js.map +1 -1
- package/dist/utils/image-resize-core.d.ts +2 -0
- package/dist/utils/image-resize-core.d.ts.map +1 -1
- package/dist/utils/image-resize-core.js +10 -0
- package/dist/utils/image-resize-core.js.map +1 -1
- package/docs/browser.md +86 -0
- package/docs/computer-use.md +134 -48
- package/docs/extensions.md +2 -0
- package/docs/features.md +108 -27
- package/docs/index.md +1 -1
- package/docs/interactive-startup.md +2 -1
- package/docs/keybindings.md +1 -1
- package/docs/providers.md +6 -2
- package/docs/quickstart.md +2 -2
- package/docs/sessions.md +10 -0
- package/docs/settings.md +3 -1
- package/docs/tui.md +2 -0
- package/docs/usage.md +20 -4
- package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
- package/examples/extensions/custom-provider-anthropic/package.json +1 -1
- package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
- package/examples/extensions/gondolin/package-lock.json +2 -2
- package/examples/extensions/gondolin/package.json +1 -1
- package/examples/extensions/plan-mode/README.md +1 -1
- package/examples/extensions/sandbox/package-lock.json +2 -2
- package/examples/extensions/sandbox/package.json +1 -1
- package/examples/extensions/with-deps/package-lock.json +2 -2
- package/examples/extensions/with-deps/package.json +1 -1
- package/install-lock/package-lock.json +39 -25
- package/install-lock/package.json +2 -2
- package/npm-shrinkwrap.json +36 -22
- package/package.json +10 -7
- package/scripts/install-browser.mjs +20 -0
- package/dist/node-runtime/agent-session-services-QANFGM2V.js +0 -40
- package/dist/node-runtime/chunk-LISUTZS3.js +0 -19
- package/dist/node-runtime/chunk-VGYZ3APQ.js +0 -59
- package/dist/node-runtime/chunk-XAUQOKYK.js +0 -6011
- package/dist/node-runtime/command-ZURZJDXF.js +0 -13
- package/dist/node-runtime/gateway-FWHRIBK5.js +0 -2139
- package/dist/node-runtime/interactive-mode-BBASNWHN.js +0 -62
- package/dist/node-runtime/runtime-bridges-2VQTLPOZ.js +0 -12
- package/dist/node-runtime/{chunk-U6C7VTR5.js → chunk-7IQGBKBJ.js} +3 -3
- package/dist/node-runtime/{mcp-panel-IIGMXQGP.js → mcp-panel-KTTFXJZ4.js} +3 -3
- package/dist/node-runtime/{src-BPQFJR76.js → src-IVPNZ2BX.js} +9 -9
|
@@ -0,0 +1,1476 @@
|
|
|
1
|
+
import { createRequire as __lunrRequire } from "node:module"; const require = __lunrRequire(import.meta.url);
|
|
2
|
+
import {
|
|
3
|
+
AgentBridge,
|
|
4
|
+
QUEUED,
|
|
5
|
+
startGatewayCron
|
|
6
|
+
} from "./chunk-5Z5PCXGY.js";
|
|
7
|
+
import {
|
|
8
|
+
CHAT_COMMANDS,
|
|
9
|
+
botCommandSpecs,
|
|
10
|
+
runChatCommand,
|
|
11
|
+
sendCommandReply
|
|
12
|
+
} from "./chunk-4ER2ZV4Z.js";
|
|
13
|
+
import {
|
|
14
|
+
resolveWithinRoots
|
|
15
|
+
} from "./chunk-7JIYPIQU.js";
|
|
16
|
+
import {
|
|
17
|
+
acceptGatewayInput,
|
|
18
|
+
addAllowedUser,
|
|
19
|
+
bindConversation,
|
|
20
|
+
conversationBinding,
|
|
21
|
+
gatewayEpoch,
|
|
22
|
+
getSession,
|
|
23
|
+
handleApprovalCallback,
|
|
24
|
+
handleCallback,
|
|
25
|
+
invalidateGatewayDialogs,
|
|
26
|
+
isAuthorized,
|
|
27
|
+
isGatewayOwner,
|
|
28
|
+
listSessions,
|
|
29
|
+
queueGatewayText,
|
|
30
|
+
registerGatewayApprovalHandler,
|
|
31
|
+
rememberGatewayRole,
|
|
32
|
+
requireGatewayOwner,
|
|
33
|
+
runWithApprovalContext,
|
|
34
|
+
splitMessage,
|
|
35
|
+
startButtonSweeper,
|
|
36
|
+
startGatewayPresenter,
|
|
37
|
+
stopButtonSweeper,
|
|
38
|
+
stopGatewayPresenter
|
|
39
|
+
} from "./chunk-NKH2QBKF.js";
|
|
40
|
+
import {
|
|
41
|
+
createPairingStore
|
|
42
|
+
} from "./chunk-EOPL2HMM.js";
|
|
43
|
+
import {
|
|
44
|
+
claimGateway
|
|
45
|
+
} from "./chunk-ATIF3RX5.js";
|
|
46
|
+
import "./chunk-CJECDQKP.js";
|
|
47
|
+
import "./chunk-V3HK3FE7.js";
|
|
48
|
+
import "./chunk-XHIRAZ26.js";
|
|
49
|
+
import "./chunk-5Q4A37RB.js";
|
|
50
|
+
import {
|
|
51
|
+
isFeatureEnabled
|
|
52
|
+
} from "./chunk-2CMV4L24.js";
|
|
53
|
+
import "./chunk-MNRO3UCV.js";
|
|
54
|
+
import "./chunk-KFFOQR4G.js";
|
|
55
|
+
import "./chunk-CGBXPL3E.js";
|
|
56
|
+
import "./chunk-BBUVIEZB.js";
|
|
57
|
+
import "./chunk-AJ6R5VTV.js";
|
|
58
|
+
import "./chunk-M3LZLQW2.js";
|
|
59
|
+
import "./chunk-3ONQTOMR.js";
|
|
60
|
+
import "./chunk-2BLXLDJR.js";
|
|
61
|
+
import "./chunk-ZCHMJ34K.js";
|
|
62
|
+
import "./chunk-DO6PALE2.js";
|
|
63
|
+
import "./chunk-VIVYOI7C.js";
|
|
64
|
+
import "./chunk-FVDOXRUD.js";
|
|
65
|
+
import "./chunk-IMLCWLPI.js";
|
|
66
|
+
import "./chunk-UAEOTO52.js";
|
|
67
|
+
import "./chunk-RQ2Q5IYR.js";
|
|
68
|
+
import {
|
|
69
|
+
gatewayConfigPath,
|
|
70
|
+
loadGatewayConfig,
|
|
71
|
+
platformConfigFor,
|
|
72
|
+
resolvePlatformToken,
|
|
73
|
+
saveGatewayConfig
|
|
74
|
+
} from "./chunk-O2AT4MEU.js";
|
|
75
|
+
import "./chunk-OGJN3OZV.js";
|
|
76
|
+
import "./chunk-PLGA743X.js";
|
|
77
|
+
import "./chunk-PCIGF2XK.js";
|
|
78
|
+
import "./chunk-Q4Q6D4IY.js";
|
|
79
|
+
import "./chunk-BRJX2PRC.js";
|
|
80
|
+
|
|
81
|
+
// packages/coding-agent/dist/gateway/adapters/discord.js
|
|
82
|
+
import { ActionRowBuilder, ApplicationCommandOptionType, ButtonBuilder, ButtonStyle, ChannelType, Client, Events, GatewayIntentBits } from "discord.js";
|
|
83
|
+
|
|
84
|
+
// packages/coding-agent/dist/gateway/download.js
|
|
85
|
+
async function downloadAttachment(url, limit = 8 * 1024 * 1024) {
|
|
86
|
+
let response = await fetch(url, { signal: AbortSignal.timeout(3e4) });
|
|
87
|
+
if (!response.ok || !response.body)
|
|
88
|
+
throw new Error(`Attachment request failed with HTTP ${response.status}.`);
|
|
89
|
+
if (Number(response.headers.get("content-length")) > limit)
|
|
90
|
+
throw await response.body.cancel(), new Error("Attachment exceeds the 8 MB limit.");
|
|
91
|
+
let reader = response.body.getReader(), parts = [], size = 0;
|
|
92
|
+
try {
|
|
93
|
+
for (; ; ) {
|
|
94
|
+
let part = await reader.read();
|
|
95
|
+
if (part.done)
|
|
96
|
+
break;
|
|
97
|
+
if (size += part.value.byteLength, size > limit)
|
|
98
|
+
throw await reader.cancel(), new Error("Attachment exceeds the 8 MB limit.");
|
|
99
|
+
parts.push(part.value);
|
|
100
|
+
}
|
|
101
|
+
} finally {
|
|
102
|
+
reader.releaseLock();
|
|
103
|
+
}
|
|
104
|
+
let bytes = new Uint8Array(size), offset = 0;
|
|
105
|
+
for (let part of parts)
|
|
106
|
+
bytes.set(part, offset), offset += part.byteLength;
|
|
107
|
+
return bytes;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// packages/coding-agent/dist/gateway/adapters/discord.js
|
|
111
|
+
var DEFAULT_DEBOUNCE_MS = 600, TYPING_INTERVAL_MS = 8e3, TYPING_SAFETY_MS = 12e4, REPLY_TO_TEXT_MAX = 500, THREAD_NAME_MAX = 40, SEEN_CAP = 500, SENT_CHANNEL_CAP = 500, CALLBACK_INTERACTION_CAP = 500, CHANNEL_CACHE_CAP = 500, PARTICIPATING_THREAD_CAP = 500, ERR_INVALID_FORM_BODY = 50035, ERR_UNKNOWN_MESSAGE = 10008, THREAD_TYPES = [
|
|
112
|
+
ChannelType.PublicThread,
|
|
113
|
+
ChannelType.PrivateThread,
|
|
114
|
+
ChannelType.AnnouncementThread
|
|
115
|
+
];
|
|
116
|
+
function errMessage(err) {
|
|
117
|
+
return err instanceof Error ? err.message : String(err);
|
|
118
|
+
}
|
|
119
|
+
function discordErrorCode(err) {
|
|
120
|
+
let code = err?.code;
|
|
121
|
+
return typeof code == "number" ? code : void 0;
|
|
122
|
+
}
|
|
123
|
+
function isImageContentType(contentType) {
|
|
124
|
+
return typeof contentType == "string" && contentType.split(";")[0]?.trim().toLowerCase().startsWith("image/");
|
|
125
|
+
}
|
|
126
|
+
function collectDiscordImageAttachments(message) {
|
|
127
|
+
return Array.from(message.attachments?.values() ?? []).filter((attachment) => isImageContentType(attachment.contentType));
|
|
128
|
+
}
|
|
129
|
+
function messageToEvent(message, botUser, options = {}) {
|
|
130
|
+
let author = message.author;
|
|
131
|
+
if (!author || author.id === botUser.id || author.bot || message.system)
|
|
132
|
+
return null;
|
|
133
|
+
let content = (message.content ?? "").trim(), imageAttachments = collectDiscordImageAttachments(message);
|
|
134
|
+
if (content === "" && imageAttachments.length === 0 && !Array.from(message.attachments?.values() ?? []).length)
|
|
135
|
+
return null;
|
|
136
|
+
let channel = message.channel, ignored = options.ignoredChannels ?? [];
|
|
137
|
+
if (ignored.includes(channel.id) || channel.parentId != null && ignored.includes(channel.parentId))
|
|
138
|
+
return null;
|
|
139
|
+
let chatType, chatId, threadId;
|
|
140
|
+
if (channel.type === ChannelType.DM)
|
|
141
|
+
chatType = "dm", chatId = channel.id;
|
|
142
|
+
else if (THREAD_TYPES.includes(channel.type))
|
|
143
|
+
chatType = "thread", chatId = channel.parentId ?? channel.id, threadId = channel.id;
|
|
144
|
+
else if (channel.type === ChannelType.GuildText || channel.type === ChannelType.GuildAnnouncement)
|
|
145
|
+
chatType = "group", chatId = channel.id;
|
|
146
|
+
else
|
|
147
|
+
return null;
|
|
148
|
+
let explicitMention = message.mentions?.has(botUser) === !0, participating = threadId !== void 0 && options.participatingThreads?.has(threadId) === !0, mentionedBot2 = explicitMention || participating;
|
|
149
|
+
if (!mentionedBot2 && chatType !== "dm" && [...content.matchAll(/<@!?(\d+)>/g)].map((m) => m[1]).some((id) => id !== botUser.id))
|
|
150
|
+
return null;
|
|
151
|
+
let text = content;
|
|
152
|
+
explicitMention && (text = text.replace(new RegExp(`<@!?${botUser.id}>`, "g"), "").trim());
|
|
153
|
+
let refId = message.reference?.messageId, cachedReply = refId != null ? channel.messages?.cache?.get(refId)?.content : void 0;
|
|
154
|
+
return {
|
|
155
|
+
text,
|
|
156
|
+
messageId: message.id,
|
|
157
|
+
replyToText: cachedReply !== void 0 ? cachedReply.slice(0, REPLY_TO_TEXT_MAX) : void 0,
|
|
158
|
+
source: {
|
|
159
|
+
platform: "discord",
|
|
160
|
+
chatId,
|
|
161
|
+
chatType,
|
|
162
|
+
userId: author.id,
|
|
163
|
+
userName: author.username,
|
|
164
|
+
threadId
|
|
165
|
+
},
|
|
166
|
+
metadata: mentionedBot2 ? { mentionedBot: !0 } : void 0
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
function mapDiscordChannel(channel) {
|
|
170
|
+
return channel.type === ChannelType.DM ? { chatType: "dm", chatId: channel.id } : THREAD_TYPES.includes(channel.type) ? { chatType: "thread", chatId: channel.parentId ?? channel.id, threadId: channel.id } : channel.type === ChannelType.GuildText || channel.type === ChannelType.GuildAnnouncement ? { chatType: "group", chatId: channel.id } : null;
|
|
171
|
+
}
|
|
172
|
+
function buttonInteractionToEvent(interaction) {
|
|
173
|
+
let channel = interaction.message.channel, mapped = mapDiscordChannel(channel);
|
|
174
|
+
return mapped ? {
|
|
175
|
+
id: interaction.id,
|
|
176
|
+
chatId: mapped.chatId,
|
|
177
|
+
messageId: interaction.message.id,
|
|
178
|
+
userId: interaction.user.id,
|
|
179
|
+
userName: interaction.user.username,
|
|
180
|
+
data: interaction.customId,
|
|
181
|
+
threadId: mapped.threadId
|
|
182
|
+
} : null;
|
|
183
|
+
}
|
|
184
|
+
function buildDiscordComponents(buttons) {
|
|
185
|
+
let rows = [];
|
|
186
|
+
for (let row of buttons) {
|
|
187
|
+
let actionRow = new ActionRowBuilder();
|
|
188
|
+
for (let button of row) {
|
|
189
|
+
let style = button.data === "" ? ButtonStyle.Secondary : ButtonStyle.Secondary, builder = new ButtonBuilder().setCustomId(button.data).setLabel(button.label).setStyle(style);
|
|
190
|
+
button.data === "" && builder.setDisabled(!0), actionRow.addComponents(builder);
|
|
191
|
+
}
|
|
192
|
+
rows.push(actionRow);
|
|
193
|
+
}
|
|
194
|
+
return rows;
|
|
195
|
+
}
|
|
196
|
+
var seenMessageIds = /* @__PURE__ */ new Set();
|
|
197
|
+
function markMessageSeen(id) {
|
|
198
|
+
if (seenMessageIds.has(id))
|
|
199
|
+
return !0;
|
|
200
|
+
if (seenMessageIds.add(id), seenMessageIds.size > SEEN_CAP) {
|
|
201
|
+
let oldest = seenMessageIds.values().next().value;
|
|
202
|
+
oldest !== void 0 && seenMessageIds.delete(oldest);
|
|
203
|
+
}
|
|
204
|
+
return !1;
|
|
205
|
+
}
|
|
206
|
+
var defaultScheduler = {
|
|
207
|
+
setTimeout: (fn, ms) => {
|
|
208
|
+
let handle = setTimeout(fn, ms);
|
|
209
|
+
return handle.unref?.(), handle;
|
|
210
|
+
},
|
|
211
|
+
clearTimeout: (handle) => clearTimeout(handle),
|
|
212
|
+
setInterval: (fn, ms) => {
|
|
213
|
+
let handle = setInterval(fn, ms);
|
|
214
|
+
return handle.unref?.(), handle;
|
|
215
|
+
},
|
|
216
|
+
clearInterval: (handle) => clearInterval(handle)
|
|
217
|
+
};
|
|
218
|
+
function defaultClientFactory() {
|
|
219
|
+
return new Client({
|
|
220
|
+
intents: [
|
|
221
|
+
GatewayIntentBits.Guilds,
|
|
222
|
+
GatewayIntentBits.GuildMessages,
|
|
223
|
+
GatewayIntentBits.DirectMessages,
|
|
224
|
+
GatewayIntentBits.MessageContent
|
|
225
|
+
]
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
function typingKey(chatId, threadId) {
|
|
229
|
+
return `${chatId}:${threadId ?? ""}`;
|
|
230
|
+
}
|
|
231
|
+
var DiscordAdapter = class {
|
|
232
|
+
platform = "discord";
|
|
233
|
+
maxMessageLength = 2e3;
|
|
234
|
+
cfg;
|
|
235
|
+
clientFactory;
|
|
236
|
+
downloadAttachment;
|
|
237
|
+
maxMediaBytes;
|
|
238
|
+
scheduler;
|
|
239
|
+
debounceMs;
|
|
240
|
+
now;
|
|
241
|
+
client;
|
|
242
|
+
botUserId;
|
|
243
|
+
handler;
|
|
244
|
+
commandSuggestions;
|
|
245
|
+
callbackHandler;
|
|
246
|
+
pending = /* @__PURE__ */ new Map();
|
|
247
|
+
typing = /* @__PURE__ */ new Map();
|
|
248
|
+
channelCache = /* @__PURE__ */ new Map();
|
|
249
|
+
/** Threads the bot has spoken in (session memory only; hermes persists this). */
|
|
250
|
+
participatingThreads = /* @__PURE__ */ new Set();
|
|
251
|
+
/** messageId → channel it was sent to, so editMessage finds thread messages. */
|
|
252
|
+
sentMessageChannels = /* @__PURE__ */ new Map();
|
|
253
|
+
/** callbackId → interaction, so answerCallback can acknowledge the click. */
|
|
254
|
+
callbackInteractions = /* @__PURE__ */ new Map();
|
|
255
|
+
constructor(cfg, options = {}) {
|
|
256
|
+
if (this.cfg = cfg, this.scheduler = options.scheduler ?? defaultScheduler, this.debounceMs = options.debounceMs ?? DEFAULT_DEBOUNCE_MS, this.now = options.now ?? Date.now, options.clientFactory)
|
|
257
|
+
this.clientFactory = options.clientFactory;
|
|
258
|
+
else {
|
|
259
|
+
if (!cfg.token)
|
|
260
|
+
throw new Error("DiscordAdapter: no bot token (set discord.token or LUNR_DISCORD_BOT_TOKEN)");
|
|
261
|
+
this.clientFactory = defaultClientFactory;
|
|
262
|
+
}
|
|
263
|
+
this.downloadAttachment = options.downloadAttachment ?? downloadAttachment, this.maxMediaBytes = options.maxMediaBytes ?? 10 * 1024 * 1024;
|
|
264
|
+
}
|
|
265
|
+
setCommandSuggestions(handler) {
|
|
266
|
+
this.commandSuggestions = handler;
|
|
267
|
+
}
|
|
268
|
+
onMessage(handler) {
|
|
269
|
+
this.handler = handler;
|
|
270
|
+
}
|
|
271
|
+
onCallback(handler) {
|
|
272
|
+
this.callbackHandler = handler;
|
|
273
|
+
}
|
|
274
|
+
async connect() {
|
|
275
|
+
if (!this.cfg.token)
|
|
276
|
+
throw new Error("DiscordAdapter: no bot token (set discord.token or LUNR_DISCORD_BOT_TOKEN)");
|
|
277
|
+
let client = this.clientFactory();
|
|
278
|
+
this.client = client, client.on(Events.MessageCreate, (message) => {
|
|
279
|
+
this.handleMessage(message).catch((err) => {
|
|
280
|
+
console.error(`[gateway] discord message handling error: ${errMessage(err)}`);
|
|
281
|
+
});
|
|
282
|
+
}), client.on(Events.InteractionCreate, (interaction) => {
|
|
283
|
+
let event = interaction;
|
|
284
|
+
(event.isButton() ? this.handleInteraction(interaction) : this.handleNativeCommand(event)).catch((err) => {
|
|
285
|
+
console.error(`[gateway] discord interaction handling error: ${errMessage(err)}`);
|
|
286
|
+
});
|
|
287
|
+
});
|
|
288
|
+
let ready = new Promise((resolve) => client.once(Events.ClientReady, () => resolve()));
|
|
289
|
+
try {
|
|
290
|
+
await client.login(this.cfg.token);
|
|
291
|
+
} catch (err) {
|
|
292
|
+
return console.error(`[gateway] discord login failed: ${errMessage(err)}`), !1;
|
|
293
|
+
}
|
|
294
|
+
return await ready, this.botUserId = client.user?.id, this.botUserId === void 0 ? (console.error("[gateway] discord: client ready without a user \u2014 cannot map messages"), !1) : !0;
|
|
295
|
+
}
|
|
296
|
+
async disconnect() {
|
|
297
|
+
for (let key of [...this.pending.keys()])
|
|
298
|
+
this.cancelPending(key);
|
|
299
|
+
for (let key of [...this.typing.keys()])
|
|
300
|
+
this.stopTyping(key);
|
|
301
|
+
this.channelCache.clear(), this.callbackInteractions.clear(), this.client?.destroy(), this.client = void 0;
|
|
302
|
+
}
|
|
303
|
+
// -----------------------------------------------------------------------
|
|
304
|
+
// Inbound dispatch + debounce
|
|
305
|
+
// -----------------------------------------------------------------------
|
|
306
|
+
async handleMessage(message) {
|
|
307
|
+
if (!this.botUserId || !this.handler || markMessageSeen(message.id))
|
|
308
|
+
return;
|
|
309
|
+
let event = messageToEvent(message, { id: this.botUserId }, {
|
|
310
|
+
ignoredChannels: this.cfg.ignoredChannels,
|
|
311
|
+
participatingThreads: this.participatingThreads
|
|
312
|
+
});
|
|
313
|
+
if (event) {
|
|
314
|
+
if (!isAuthorized(event.source, { ...loadGatewayConfig(), discord: this.cfg }, createPairingStore())) {
|
|
315
|
+
this.dispatchEvent(event);
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
318
|
+
await this.resolveReplyToText(message, event), await this.maybeAutoThread(message, event), await this.downloadAttachments(message, event), this.dispatchEvent(event);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
/** Download and encode attachments after authorization. */
|
|
322
|
+
async downloadAttachments(message, event) {
|
|
323
|
+
let imageAttachments = Array.from(message.attachments?.values() ?? []);
|
|
324
|
+
if (imageAttachments.length === 0)
|
|
325
|
+
return;
|
|
326
|
+
let attachments = [];
|
|
327
|
+
for (let attachment of imageAttachments)
|
|
328
|
+
if (!(attachment.size !== void 0 && attachment.size > this.maxMediaBytes))
|
|
329
|
+
try {
|
|
330
|
+
let bytes = await this.downloadAttachment(attachment.url);
|
|
331
|
+
if (bytes.byteLength > this.maxMediaBytes)
|
|
332
|
+
continue;
|
|
333
|
+
attachments.push({
|
|
334
|
+
data: Buffer.from(bytes).toString("base64"),
|
|
335
|
+
mimeType: attachment.contentType ?? "application/octet-stream",
|
|
336
|
+
...attachment.name ? { filename: attachment.name } : {}
|
|
337
|
+
});
|
|
338
|
+
} catch {
|
|
339
|
+
}
|
|
340
|
+
attachments.length > 0 && (event.attachments = attachments);
|
|
341
|
+
}
|
|
342
|
+
async registerCommands(commands) {
|
|
343
|
+
this.client?.application && await this.client.application.commands.set(commands.slice(0, 95).map((command) => ({
|
|
344
|
+
name: command.name,
|
|
345
|
+
description: command.description.slice(0, 100),
|
|
346
|
+
options: [
|
|
347
|
+
{
|
|
348
|
+
name: "args",
|
|
349
|
+
description: "Command arguments or search",
|
|
350
|
+
type: ApplicationCommandOptionType.String,
|
|
351
|
+
required: !1,
|
|
352
|
+
autocomplete: ["mode", "thinking", "project", "sessions"].includes(command.name)
|
|
353
|
+
}
|
|
354
|
+
]
|
|
355
|
+
})));
|
|
356
|
+
}
|
|
357
|
+
async handleNativeCommand(interaction) {
|
|
358
|
+
if (!interaction.isChatInputCommand?.() && !interaction.isAutocomplete?.() || !interaction.isChatInputCommand() && !interaction.isAutocomplete())
|
|
359
|
+
return !1;
|
|
360
|
+
let thread = interaction.channel?.isThread() ? interaction.channel : void 0, source = {
|
|
361
|
+
platform: "discord",
|
|
362
|
+
chatId: thread?.parentId ?? interaction.channelId ?? interaction.user.id,
|
|
363
|
+
threadId: thread?.id,
|
|
364
|
+
chatType: thread ? "thread" : interaction.inGuild() ? "channel" : "dm",
|
|
365
|
+
userId: interaction.user.id,
|
|
366
|
+
userName: interaction.user.username
|
|
367
|
+
}, cfg = loadGatewayConfig(), authorized = isAuthorized(source, cfg, createPairingStore());
|
|
368
|
+
if (interaction.isAutocomplete()) {
|
|
369
|
+
if (!authorized || !isGatewayOwner(source, cfg))
|
|
370
|
+
return await interaction.respond([]), !0;
|
|
371
|
+
let query = String(interaction.options.getFocused()).toLowerCase(), values = [];
|
|
372
|
+
if (interaction.commandName === "mode" && (values = ["yolo", "auto", "read-only"]), this.commandSuggestions && ["thinking", "model"].includes(interaction.commandName) && (values = [...await this.commandSuggestions(source, interaction.commandName)]), interaction.commandName === "project" && (values = cfg.projectRoots ?? []), interaction.commandName === "sessions") {
|
|
373
|
+
let { SessionManager } = await import("./session-manager-TCEFDKBL.js");
|
|
374
|
+
values = (await Promise.race([
|
|
375
|
+
SessionManager.listAll(),
|
|
376
|
+
new Promise((resolve) => setTimeout(() => resolve([]), 1500))
|
|
377
|
+
])).map((s) => s.name || s.id);
|
|
378
|
+
}
|
|
379
|
+
return await interaction.respond(values.filter((s) => s.toLowerCase().includes(query)).slice(0, 25).map((value) => ({ name: value.slice(0, 100), value: value.slice(0, 100) }))), !0;
|
|
380
|
+
}
|
|
381
|
+
return await interaction.reply({
|
|
382
|
+
content: authorized ? "Command received." : "Pair your account before using this command. Send the bot a private message for a pairing code.",
|
|
383
|
+
ephemeral: !0
|
|
384
|
+
}), authorized && this.handler?.({
|
|
385
|
+
text: `/${interaction.commandName}${interaction.options.getString("args") ? ` ${interaction.options.getString("args")}` : ""}`,
|
|
386
|
+
source,
|
|
387
|
+
messageId: "",
|
|
388
|
+
metadata: { mentionedBot: !0, nativeCommand: !0 }
|
|
389
|
+
}), !0;
|
|
390
|
+
}
|
|
391
|
+
async sendFile(chatId, file, opts) {
|
|
392
|
+
let channel = await this.fetchChannel(opts?.threadId ?? chatId);
|
|
393
|
+
if (!channel?.send)
|
|
394
|
+
return { success: !1, error: "Channel is unavailable." };
|
|
395
|
+
try {
|
|
396
|
+
return { success: !0, messageId: (await channel.send({ content: "", files: [file] })).id };
|
|
397
|
+
} catch (error) {
|
|
398
|
+
return { success: !1, error: errMessage(error) };
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
async handleInteraction(interaction) {
|
|
402
|
+
if (!this.callbackHandler || !interaction.isButton())
|
|
403
|
+
return;
|
|
404
|
+
let event = buttonInteractionToEvent(interaction);
|
|
405
|
+
if (event) {
|
|
406
|
+
if (this.callbackInteractions.set(interaction.id, interaction), this.callbackInteractions.size > CALLBACK_INTERACTION_CAP) {
|
|
407
|
+
let oldest = this.callbackInteractions.keys().next().value;
|
|
408
|
+
oldest !== void 0 && this.callbackInteractions.delete(oldest);
|
|
409
|
+
}
|
|
410
|
+
this.callbackHandler(event);
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
/** Best-effort: fill replyToText from the referenced message when it wasn't cached. */
|
|
414
|
+
async resolveReplyToText(message, event) {
|
|
415
|
+
if (event.replyToText !== void 0)
|
|
416
|
+
return;
|
|
417
|
+
let refId = message.reference?.messageId;
|
|
418
|
+
if (refId == null)
|
|
419
|
+
return;
|
|
420
|
+
let messages = message.channel.messages;
|
|
421
|
+
if (messages)
|
|
422
|
+
try {
|
|
423
|
+
let referenced = await messages.fetch(refId);
|
|
424
|
+
referenced?.content && (event.replyToText = referenced.content.slice(0, REPLY_TO_TEXT_MAX));
|
|
425
|
+
} catch {
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
/** autoThread: spin a thread off a bot-mentioning guild-text message and re-target the event. */
|
|
429
|
+
async maybeAutoThread(message, event) {
|
|
430
|
+
if (this.cfg.autoThread && event.metadata?.mentionedBot === !0 && message.channel.type === ChannelType.GuildText && typeof message.startThread == "function")
|
|
431
|
+
try {
|
|
432
|
+
let thread = await message.startThread({
|
|
433
|
+
name: (event.text || "conversation").slice(0, THREAD_NAME_MAX),
|
|
434
|
+
autoArchiveDuration: 60
|
|
435
|
+
});
|
|
436
|
+
if (this.participatingThreads.add(thread.id), this.participatingThreads.size > PARTICIPATING_THREAD_CAP) {
|
|
437
|
+
let oldest = this.participatingThreads.values().next().value;
|
|
438
|
+
oldest !== void 0 && this.participatingThreads.delete(oldest);
|
|
439
|
+
}
|
|
440
|
+
event.source = { ...event.source, chatType: "thread", chatId: message.channel.id, threadId: thread.id };
|
|
441
|
+
} catch {
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
debounceKey(event) {
|
|
445
|
+
return `${event.source.chatId}:${event.source.threadId ?? ""}:${event.source.userId}`;
|
|
446
|
+
}
|
|
447
|
+
dispatchEvent(event) {
|
|
448
|
+
let key = this.debounceKey(event);
|
|
449
|
+
if (event.text.trimStart().startsWith("/")) {
|
|
450
|
+
this.flushPending(key), this.handler?.(event);
|
|
451
|
+
return;
|
|
452
|
+
}
|
|
453
|
+
let existing = this.pending.get(key);
|
|
454
|
+
if (existing) {
|
|
455
|
+
this.scheduler.clearTimeout(existing.timer);
|
|
456
|
+
let mergedAttachments = [...existing.event.attachments ?? [], ...event.attachments ?? []];
|
|
457
|
+
existing.event = {
|
|
458
|
+
...event,
|
|
459
|
+
text: `${existing.event.text}
|
|
460
|
+
${event.text}`,
|
|
461
|
+
...mergedAttachments.length > 0 ? { attachments: mergedAttachments } : {}
|
|
462
|
+
}, existing.timer = this.scheduler.setTimeout(() => this.flushPending(key), this.debounceMs);
|
|
463
|
+
} else {
|
|
464
|
+
let timer = this.scheduler.setTimeout(() => this.flushPending(key), this.debounceMs);
|
|
465
|
+
this.pending.set(key, { event, timer });
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
flushPending(key) {
|
|
469
|
+
let entry = this.pending.get(key);
|
|
470
|
+
entry && (this.scheduler.clearTimeout(entry.timer), this.pending.delete(key), this.handler?.(entry.event));
|
|
471
|
+
}
|
|
472
|
+
cancelPending(key) {
|
|
473
|
+
let entry = this.pending.get(key);
|
|
474
|
+
entry && (this.scheduler.clearTimeout(entry.timer), this.pending.delete(key));
|
|
475
|
+
}
|
|
476
|
+
// -----------------------------------------------------------------------
|
|
477
|
+
// Outbound
|
|
478
|
+
// -----------------------------------------------------------------------
|
|
479
|
+
async fetchChannel(id) {
|
|
480
|
+
if (this.channelCache.has(id))
|
|
481
|
+
return this.channelCache.get(id) ?? null;
|
|
482
|
+
if (!this.client)
|
|
483
|
+
return null;
|
|
484
|
+
try {
|
|
485
|
+
let channel = await this.client.channels.fetch(id);
|
|
486
|
+
if (channel && this.channelCache.set(id, channel), this.channelCache.size > CHANNEL_CACHE_CAP) {
|
|
487
|
+
let oldest = this.channelCache.keys().next().value;
|
|
488
|
+
oldest !== void 0 && this.channelCache.delete(oldest);
|
|
489
|
+
}
|
|
490
|
+
return channel;
|
|
491
|
+
} catch {
|
|
492
|
+
return null;
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
recordSent(messageId, channel) {
|
|
496
|
+
if (THREAD_TYPES.includes(channel.type) && this.participatingThreads.add(channel.id), this.participatingThreads.size > PARTICIPATING_THREAD_CAP) {
|
|
497
|
+
let oldest = this.participatingThreads.values().next().value;
|
|
498
|
+
oldest !== void 0 && this.participatingThreads.delete(oldest);
|
|
499
|
+
}
|
|
500
|
+
if (this.sentMessageChannels.set(messageId, channel.id), this.sentMessageChannels.size > SENT_CHANNEL_CAP) {
|
|
501
|
+
let oldest = this.sentMessageChannels.keys().next().value;
|
|
502
|
+
oldest !== void 0 && this.sentMessageChannels.delete(oldest);
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
async trySend(channel, payload) {
|
|
506
|
+
if (typeof channel.send != "function")
|
|
507
|
+
return { success: !1, error: `channel ${channel.id} is not sendable` };
|
|
508
|
+
try {
|
|
509
|
+
let sent = await channel.send(payload);
|
|
510
|
+
return this.recordSent(sent.id, channel), { success: !0, messageId: sent.id };
|
|
511
|
+
} catch (err) {
|
|
512
|
+
return { success: !1, error: errMessage(err), retryable: discordErrorCode(err) !== ERR_INVALID_FORM_BODY };
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
async send(chatId, text, opts) {
|
|
516
|
+
this.stopTyping(typingKey(chatId, opts?.threadId));
|
|
517
|
+
let channel = await this.fetchChannel(opts?.threadId ?? chatId);
|
|
518
|
+
if (!channel)
|
|
519
|
+
return { success: !1, error: `channel ${opts?.threadId ?? chatId} not found` };
|
|
520
|
+
let result = await this.trySend(channel, {
|
|
521
|
+
content: text,
|
|
522
|
+
reply: opts?.replyTo !== void 0 ? { messageReference: opts.replyTo } : void 0
|
|
523
|
+
});
|
|
524
|
+
return !result.success && opts?.replyTo !== void 0 ? this.trySend(channel, { content: text }) : result;
|
|
525
|
+
}
|
|
526
|
+
async sendButtons(chatId, text, buttons, opts) {
|
|
527
|
+
this.stopTyping(typingKey(chatId, opts?.threadId));
|
|
528
|
+
let channel = await this.fetchChannel(opts?.threadId ?? chatId);
|
|
529
|
+
if (!channel)
|
|
530
|
+
return { success: !1, error: `channel ${opts?.threadId ?? chatId} not found` };
|
|
531
|
+
let result = await this.trySend(channel, {
|
|
532
|
+
content: text,
|
|
533
|
+
reply: opts?.replyTo !== void 0 ? { messageReference: opts.replyTo } : void 0,
|
|
534
|
+
components: buildDiscordComponents(buttons)
|
|
535
|
+
});
|
|
536
|
+
return !result.success && opts?.replyTo !== void 0 ? this.trySend(channel, { content: text, components: buildDiscordComponents(buttons) }) : result;
|
|
537
|
+
}
|
|
538
|
+
async answerCallback(id, text) {
|
|
539
|
+
let interaction = this.callbackInteractions.get(id);
|
|
540
|
+
if (interaction) {
|
|
541
|
+
this.callbackInteractions.delete(id);
|
|
542
|
+
try {
|
|
543
|
+
text !== void 0 && interaction.reply ? await interaction.reply({ content: text, ephemeral: !0 }) : await interaction.deferUpdate();
|
|
544
|
+
} catch {
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
async editMessage(chatId, messageId, text, buttons) {
|
|
549
|
+
let channel = await this.fetchChannel(this.sentMessageChannels.get(messageId) ?? chatId);
|
|
550
|
+
if (!channel?.messages)
|
|
551
|
+
return { success: !1, error: `channel ${this.sentMessageChannels.get(messageId) ?? chatId} not found` };
|
|
552
|
+
try {
|
|
553
|
+
let message = await channel.messages.fetch(messageId);
|
|
554
|
+
if (!message || typeof message.edit != "function")
|
|
555
|
+
return { success: !1, error: `message ${messageId} not found` };
|
|
556
|
+
let editOptions = { content: text };
|
|
557
|
+
return buttons !== void 0 && (editOptions.components = buildDiscordComponents(buttons)), await message.edit(editOptions), { success: !0, messageId };
|
|
558
|
+
} catch (err) {
|
|
559
|
+
return discordErrorCode(err) === ERR_UNKNOWN_MESSAGE ? { success: !1, error: errMessage(err) } : { success: !1, error: errMessage(err), retryable: !0 };
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
async sendTyping(chatId, threadId) {
|
|
563
|
+
let key = typingKey(chatId, threadId), targetId = threadId ?? chatId;
|
|
564
|
+
await this.doTyping(targetId);
|
|
565
|
+
let existing = this.typing.get(key);
|
|
566
|
+
if (existing) {
|
|
567
|
+
existing.lastRefresh = this.now();
|
|
568
|
+
return;
|
|
569
|
+
}
|
|
570
|
+
let interval = this.scheduler.setInterval(() => {
|
|
571
|
+
let entry = this.typing.get(key);
|
|
572
|
+
if (entry) {
|
|
573
|
+
if (this.now() - entry.lastRefresh > TYPING_SAFETY_MS) {
|
|
574
|
+
this.stopTyping(key);
|
|
575
|
+
return;
|
|
576
|
+
}
|
|
577
|
+
this.doTyping(targetId);
|
|
578
|
+
}
|
|
579
|
+
}, TYPING_INTERVAL_MS);
|
|
580
|
+
this.typing.set(key, { interval, lastRefresh: this.now() });
|
|
581
|
+
}
|
|
582
|
+
async doTyping(channelId) {
|
|
583
|
+
try {
|
|
584
|
+
await (await this.fetchChannel(channelId))?.sendTyping?.();
|
|
585
|
+
} catch {
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
stopTyping(key) {
|
|
589
|
+
let entry = this.typing.get(key);
|
|
590
|
+
entry && (this.scheduler.clearInterval(entry.interval), this.typing.delete(key));
|
|
591
|
+
}
|
|
592
|
+
};
|
|
593
|
+
|
|
594
|
+
// packages/coding-agent/dist/gateway/adapters/telegram.js
|
|
595
|
+
import { readFileSync } from "node:fs";
|
|
596
|
+
import { basename } from "node:path";
|
|
597
|
+
var API_BASE = "https://api.telegram.org", DEFAULT_DEBOUNCE_MS2 = 300, TYPING_INTERVAL_MS2 = 4e3, TYPING_SAFETY_MS2 = 12e4, REPLY_TO_TEXT_MAX2 = 500, MARKDOWN_PARSE_ERROR_RE = /can't parse|parse entities/i, NOT_MODIFIED_RE = /message is not modified/i, TelegramApiError = class extends Error {
|
|
598
|
+
status;
|
|
599
|
+
retryAfter;
|
|
600
|
+
constructor(status, description, retryAfter) {
|
|
601
|
+
super(description), this.name = "TelegramApiError", this.status = status, this.retryAfter = retryAfter;
|
|
602
|
+
}
|
|
603
|
+
}, BACKOFF_DELAYS_MS = [1e3, 2e3, 5e3, 1e4, 3e4];
|
|
604
|
+
function backoffDelayMs(consecutiveFailures) {
|
|
605
|
+
let index = Math.min(Math.max(consecutiveFailures, 0), BACKOFF_DELAYS_MS.length - 1);
|
|
606
|
+
return BACKOFF_DELAYS_MS[index];
|
|
607
|
+
}
|
|
608
|
+
var defaultScheduler2 = {
|
|
609
|
+
setTimeout: (fn, ms) => {
|
|
610
|
+
let handle = setTimeout(fn, ms);
|
|
611
|
+
return handle.unref?.(), handle;
|
|
612
|
+
},
|
|
613
|
+
clearTimeout: (handle) => clearTimeout(handle),
|
|
614
|
+
setInterval: (fn, ms) => {
|
|
615
|
+
let handle = setInterval(fn, ms);
|
|
616
|
+
return handle.unref?.(), handle;
|
|
617
|
+
},
|
|
618
|
+
clearInterval: (handle) => clearInterval(handle)
|
|
619
|
+
};
|
|
620
|
+
async function defaultCallApi(token, method, body, signal) {
|
|
621
|
+
let res = await fetch(`${API_BASE}/bot${token}/${method}`, {
|
|
622
|
+
method: "POST",
|
|
623
|
+
headers: { "content-type": "application/json" },
|
|
624
|
+
body: JSON.stringify(body),
|
|
625
|
+
signal
|
|
626
|
+
}), data = await res.json().catch(() => {
|
|
627
|
+
});
|
|
628
|
+
if (res.status === 429)
|
|
629
|
+
throw new TelegramApiError(429, data?.description ?? "rate limited", data?.parameters?.retry_after);
|
|
630
|
+
if (!res.ok || !data?.ok)
|
|
631
|
+
throw new TelegramApiError(data?.error_code ?? res.status, data?.description ?? `HTTP ${res.status}`, data?.parameters?.retry_after);
|
|
632
|
+
return data.result;
|
|
633
|
+
}
|
|
634
|
+
async function defaultDownloadFile(token, filePath) {
|
|
635
|
+
return downloadAttachment(`${API_BASE}/file/bot${token}/${filePath}`);
|
|
636
|
+
}
|
|
637
|
+
function errMessage2(err) {
|
|
638
|
+
return err instanceof Error ? err.message : String(err);
|
|
639
|
+
}
|
|
640
|
+
function chatTypeOf(chat) {
|
|
641
|
+
switch (chat.type) {
|
|
642
|
+
case "private":
|
|
643
|
+
return "dm";
|
|
644
|
+
case "group":
|
|
645
|
+
case "supergroup":
|
|
646
|
+
return "group";
|
|
647
|
+
case "channel":
|
|
648
|
+
return "channel";
|
|
649
|
+
default:
|
|
650
|
+
return null;
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
function extractMention(text, entities, botInfo) {
|
|
654
|
+
if (!botInfo.botUsername)
|
|
655
|
+
return { text: text.trim(), mentioned: !1 };
|
|
656
|
+
let botAt = `@${botInfo.botUsername}`.toLowerCase(), removals = [], mentioned = !1;
|
|
657
|
+
for (let entity of entities) {
|
|
658
|
+
let slice = text.slice(entity.offset, entity.offset + entity.length);
|
|
659
|
+
if (entity.type === "mention" && slice.toLowerCase() === botAt)
|
|
660
|
+
mentioned = !0, removals.push([entity.offset, entity.offset + entity.length]);
|
|
661
|
+
else if (entity.type === "text_mention" && entity.user?.id === botInfo.botId)
|
|
662
|
+
mentioned = !0, removals.push([entity.offset, entity.offset + entity.length]);
|
|
663
|
+
else if (entity.type === "bot_command" && slice.toLowerCase().includes(botAt)) {
|
|
664
|
+
mentioned = !0;
|
|
665
|
+
let at = slice.toLowerCase().indexOf(botAt);
|
|
666
|
+
removals.push([entity.offset + at, entity.offset + at + botAt.length]);
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
if (removals.length === 0)
|
|
670
|
+
return { text: text.trim(), mentioned };
|
|
671
|
+
removals.sort((a, b) => a[0] - b[0]);
|
|
672
|
+
let out = "", pos = 0;
|
|
673
|
+
for (let [start, end] of removals)
|
|
674
|
+
out += text.slice(pos, start), pos = Math.max(pos, end);
|
|
675
|
+
return out += text.slice(pos), { text: out.trim(), mentioned };
|
|
676
|
+
}
|
|
677
|
+
function collectTelegramMedia(message) {
|
|
678
|
+
let descriptors = [];
|
|
679
|
+
if (message.photo && message.photo.length > 0) {
|
|
680
|
+
let largest = message.photo[message.photo.length - 1];
|
|
681
|
+
descriptors.push({
|
|
682
|
+
fileId: largest.file_id,
|
|
683
|
+
mimeType: "image/jpeg",
|
|
684
|
+
...largest.file_size !== void 0 ? { fileSize: largest.file_size } : {}
|
|
685
|
+
});
|
|
686
|
+
}
|
|
687
|
+
return message.document && descriptors.push({
|
|
688
|
+
fileId: message.document.file_id,
|
|
689
|
+
mimeType: message.document.mime_type ?? "application/octet-stream",
|
|
690
|
+
...message.document.file_name ? { filename: message.document.file_name } : {},
|
|
691
|
+
...message.document.file_size !== void 0 ? { fileSize: message.document.file_size } : {}
|
|
692
|
+
}), descriptors;
|
|
693
|
+
}
|
|
694
|
+
function updateToEvent(update, botInfo) {
|
|
695
|
+
let message = update.message;
|
|
696
|
+
if (!message)
|
|
697
|
+
return null;
|
|
698
|
+
let from = message.from;
|
|
699
|
+
if (!from || from.id === botInfo.botId || from.is_bot)
|
|
700
|
+
return null;
|
|
701
|
+
let hasMedia = collectTelegramMedia(message).length > 0, rawText = message.text ?? message.caption;
|
|
702
|
+
if (!rawText && !hasMedia)
|
|
703
|
+
return null;
|
|
704
|
+
let rawEntities = message.text !== void 0 ? message.entities : message.caption_entities, chatType = chatTypeOf(message.chat);
|
|
705
|
+
if (chatType === null)
|
|
706
|
+
return null;
|
|
707
|
+
let threadId = message.chat.is_forum === !0 && message.message_thread_id !== void 0 && message.message_thread_id !== 1 ? String(message.message_thread_id) : void 0, { text, mentioned } = extractMention(rawText ?? "", rawEntities ?? [], botInfo), replyText = message.reply_to_message?.text;
|
|
708
|
+
return {
|
|
709
|
+
text,
|
|
710
|
+
messageId: String(message.message_id),
|
|
711
|
+
replyToText: replyText !== void 0 ? replyText.slice(0, REPLY_TO_TEXT_MAX2) : void 0,
|
|
712
|
+
source: {
|
|
713
|
+
platform: "telegram",
|
|
714
|
+
chatId: String(message.chat.id),
|
|
715
|
+
chatType,
|
|
716
|
+
userId: String(from.id),
|
|
717
|
+
userName: from.username ?? from.first_name,
|
|
718
|
+
threadId
|
|
719
|
+
},
|
|
720
|
+
metadata: mentioned ? { mentionedBot: !0 } : void 0
|
|
721
|
+
};
|
|
722
|
+
}
|
|
723
|
+
function callbackQueryToEvent(query) {
|
|
724
|
+
let message = query.message;
|
|
725
|
+
if (!message)
|
|
726
|
+
return null;
|
|
727
|
+
let from = query.from;
|
|
728
|
+
return chatTypeOf(message.chat) === null ? null : {
|
|
729
|
+
id: query.id,
|
|
730
|
+
chatId: String(message.chat.id),
|
|
731
|
+
messageId: String(message.message_id),
|
|
732
|
+
userId: String(from.id),
|
|
733
|
+
userName: from.username ?? from.first_name,
|
|
734
|
+
data: query.data ?? "",
|
|
735
|
+
threadId: message.chat.is_forum === !0 && message.message_thread_id !== void 0 && message.message_thread_id !== 1 ? String(message.message_thread_id) : void 0
|
|
736
|
+
};
|
|
737
|
+
}
|
|
738
|
+
var TelegramAdapter = class {
|
|
739
|
+
platform = "telegram";
|
|
740
|
+
maxMessageLength = 4096;
|
|
741
|
+
callApi;
|
|
742
|
+
downloadFile;
|
|
743
|
+
maxMediaBytes;
|
|
744
|
+
scheduler;
|
|
745
|
+
debounceMs;
|
|
746
|
+
now;
|
|
747
|
+
handler;
|
|
748
|
+
callbackHandler;
|
|
749
|
+
botInfo;
|
|
750
|
+
offset = 0;
|
|
751
|
+
abortController;
|
|
752
|
+
pending = /* @__PURE__ */ new Map();
|
|
753
|
+
typing = /* @__PURE__ */ new Map();
|
|
754
|
+
cfg;
|
|
755
|
+
constructor(cfg, options = {}) {
|
|
756
|
+
if (this.cfg = cfg, this.scheduler = options.scheduler ?? defaultScheduler2, this.debounceMs = options.debounceMs ?? DEFAULT_DEBOUNCE_MS2, this.now = options.now ?? Date.now, options.callApi)
|
|
757
|
+
this.callApi = options.callApi;
|
|
758
|
+
else {
|
|
759
|
+
if (!cfg.token)
|
|
760
|
+
throw new Error("TelegramAdapter: no bot token (set telegram.token or LUNR_TELEGRAM_BOT_TOKEN)");
|
|
761
|
+
let token = cfg.token;
|
|
762
|
+
this.callApi = (method, body, signal) => defaultCallApi(token, method, body, signal);
|
|
763
|
+
}
|
|
764
|
+
this.downloadFile = options.downloadFile ?? ((filePath) => defaultDownloadFile(cfg.token ?? "", filePath)), this.maxMediaBytes = options.maxMediaBytes ?? 10 * 1024 * 1024;
|
|
765
|
+
}
|
|
766
|
+
onMessage(handler) {
|
|
767
|
+
this.handler = handler;
|
|
768
|
+
}
|
|
769
|
+
onCallback(handler) {
|
|
770
|
+
this.callbackHandler = handler;
|
|
771
|
+
}
|
|
772
|
+
async connect() {
|
|
773
|
+
let me = await this.callApi("getMe", {});
|
|
774
|
+
return this.botInfo = { botId: me.id, botUsername: me.username ?? "" }, this.abortController = new AbortController(), this.pollLoop(this.abortController.signal), !0;
|
|
775
|
+
}
|
|
776
|
+
async disconnect() {
|
|
777
|
+
this.abortController?.abort();
|
|
778
|
+
for (let key of [...this.pending.keys()])
|
|
779
|
+
this.cancelPending(key);
|
|
780
|
+
for (let key of [...this.typing.keys()])
|
|
781
|
+
this.stopTyping(key);
|
|
782
|
+
}
|
|
783
|
+
// -----------------------------------------------------------------------
|
|
784
|
+
// Long-poll loop
|
|
785
|
+
// -----------------------------------------------------------------------
|
|
786
|
+
async pollLoop(signal) {
|
|
787
|
+
let failures = 0;
|
|
788
|
+
for (; !signal.aborted; )
|
|
789
|
+
try {
|
|
790
|
+
let updates = await this.callApi("getUpdates", { offset: this.offset, timeout: 30, allowed_updates: ["message", "callback_query"] }, signal);
|
|
791
|
+
failures = 0;
|
|
792
|
+
for (let update of updates)
|
|
793
|
+
this.offset = update.update_id + 1, await this.dispatchUpdate(update);
|
|
794
|
+
} catch (err) {
|
|
795
|
+
if (signal.aborted)
|
|
796
|
+
return;
|
|
797
|
+
if (err instanceof TelegramApiError && err.status === 429) {
|
|
798
|
+
let retryAfter = Math.min(err.retryAfter ?? 1, 30);
|
|
799
|
+
await this.sleep(retryAfter * 1e3, signal);
|
|
800
|
+
continue;
|
|
801
|
+
}
|
|
802
|
+
let delay = backoffDelayMs(failures);
|
|
803
|
+
failures += 1, console.error(`[gateway] telegram poll error (retry in ${delay}ms): ${errMessage2(err)}`), await this.sleep(delay, signal);
|
|
804
|
+
}
|
|
805
|
+
}
|
|
806
|
+
sleep(ms, signal) {
|
|
807
|
+
return new Promise((resolve) => {
|
|
808
|
+
let timer = this.scheduler.setTimeout(resolve, ms);
|
|
809
|
+
signal?.addEventListener("abort", () => {
|
|
810
|
+
this.scheduler.clearTimeout(timer), resolve();
|
|
811
|
+
}, { once: !0 });
|
|
812
|
+
});
|
|
813
|
+
}
|
|
814
|
+
// -----------------------------------------------------------------------
|
|
815
|
+
// Inbound dispatch + debounce
|
|
816
|
+
// -----------------------------------------------------------------------
|
|
817
|
+
debounceKey(event) {
|
|
818
|
+
return `${event.source.chatId}:${event.source.threadId ?? ""}:${event.source.userId}`;
|
|
819
|
+
}
|
|
820
|
+
async dispatchUpdate(update) {
|
|
821
|
+
if (!this.botInfo)
|
|
822
|
+
return;
|
|
823
|
+
if (update.callback_query) {
|
|
824
|
+
let event2 = callbackQueryToEvent(update.callback_query);
|
|
825
|
+
event2 && this.callbackHandler?.(event2);
|
|
826
|
+
return;
|
|
827
|
+
}
|
|
828
|
+
if (!this.handler)
|
|
829
|
+
return;
|
|
830
|
+
let event = updateToEvent(update, this.botInfo);
|
|
831
|
+
if (!event)
|
|
832
|
+
return;
|
|
833
|
+
if (update.message && isAuthorized(event.source, { ...loadGatewayConfig(), telegram: this.cfg }, createPairingStore())) {
|
|
834
|
+
let attachments = await this.downloadMedia(update.message);
|
|
835
|
+
attachments.length > 0 && (event.attachments = attachments);
|
|
836
|
+
}
|
|
837
|
+
let key = this.debounceKey(event);
|
|
838
|
+
if (event.text.trimStart().startsWith("/")) {
|
|
839
|
+
this.flushPending(key), this.handler(event);
|
|
840
|
+
return;
|
|
841
|
+
}
|
|
842
|
+
let existing = this.pending.get(key);
|
|
843
|
+
if (existing) {
|
|
844
|
+
this.scheduler.clearTimeout(existing.timer);
|
|
845
|
+
let mergedAttachments = [...existing.event.attachments ?? [], ...event.attachments ?? []];
|
|
846
|
+
existing.event = {
|
|
847
|
+
...event,
|
|
848
|
+
text: `${existing.event.text}
|
|
849
|
+
${event.text}`,
|
|
850
|
+
...mergedAttachments.length > 0 ? { attachments: mergedAttachments } : {}
|
|
851
|
+
}, existing.timer = this.scheduler.setTimeout(() => this.flushPending(key), this.debounceMs);
|
|
852
|
+
} else {
|
|
853
|
+
let timer = this.scheduler.setTimeout(() => this.flushPending(key), this.debounceMs);
|
|
854
|
+
this.pending.set(key, { event, timer });
|
|
855
|
+
}
|
|
856
|
+
}
|
|
857
|
+
/** lunr: download + base64-encode inbound image media for one Telegram message. */
|
|
858
|
+
async downloadMedia(message) {
|
|
859
|
+
let descriptors = collectTelegramMedia(message);
|
|
860
|
+
if (descriptors.length === 0)
|
|
861
|
+
return [];
|
|
862
|
+
let attachments = [];
|
|
863
|
+
for (let descriptor of descriptors)
|
|
864
|
+
if (!(descriptor.fileSize !== void 0 && descriptor.fileSize > this.maxMediaBytes))
|
|
865
|
+
try {
|
|
866
|
+
let fileResult = await this.callApi("getFile", { file_id: descriptor.fileId }), filePath = fileResult?.file_path;
|
|
867
|
+
if (!filePath || fileResult?.file_size !== void 0 && fileResult.file_size > this.maxMediaBytes)
|
|
868
|
+
continue;
|
|
869
|
+
let bytes = await this.downloadFile(filePath);
|
|
870
|
+
if (bytes.byteLength > this.maxMediaBytes)
|
|
871
|
+
continue;
|
|
872
|
+
attachments.push({
|
|
873
|
+
data: Buffer.from(bytes).toString("base64"),
|
|
874
|
+
mimeType: descriptor.mimeType,
|
|
875
|
+
...descriptor.filename ? { filename: descriptor.filename } : {}
|
|
876
|
+
});
|
|
877
|
+
} catch {
|
|
878
|
+
}
|
|
879
|
+
return attachments;
|
|
880
|
+
}
|
|
881
|
+
flushPending(key) {
|
|
882
|
+
let entry = this.pending.get(key);
|
|
883
|
+
entry && (this.scheduler.clearTimeout(entry.timer), this.pending.delete(key), this.handler?.(entry.event));
|
|
884
|
+
}
|
|
885
|
+
cancelPending(key) {
|
|
886
|
+
let entry = this.pending.get(key);
|
|
887
|
+
entry && (this.scheduler.clearTimeout(entry.timer), this.pending.delete(key));
|
|
888
|
+
}
|
|
889
|
+
// -----------------------------------------------------------------------
|
|
890
|
+
// Outbound
|
|
891
|
+
// -----------------------------------------------------------------------
|
|
892
|
+
buildSendBody(chatId, text, opts) {
|
|
893
|
+
let body = { chat_id: chatId, text, parse_mode: "Markdown" };
|
|
894
|
+
return opts?.threadId !== void 0 && (body.message_thread_id = Number(opts.threadId)), opts?.replyTo !== void 0 && (body.reply_parameters = { message_id: Number(opts.replyTo) }), body;
|
|
895
|
+
}
|
|
896
|
+
buildReplyMarkup(buttons) {
|
|
897
|
+
if (buttons !== void 0)
|
|
898
|
+
return {
|
|
899
|
+
inline_keyboard: buttons.map((row) => row.map((b) => ({ text: b.label, callback_data: b.data })))
|
|
900
|
+
};
|
|
901
|
+
}
|
|
902
|
+
async send(chatId, text, opts) {
|
|
903
|
+
this.stopTyping(typingKey2(chatId, opts?.threadId));
|
|
904
|
+
let body = this.buildSendBody(chatId, text, opts);
|
|
905
|
+
return this.callSend(body);
|
|
906
|
+
}
|
|
907
|
+
async sendButtons(chatId, text, buttons, opts) {
|
|
908
|
+
this.stopTyping(typingKey2(chatId, opts?.threadId));
|
|
909
|
+
let body = this.buildSendBody(chatId, text, opts), markup = this.buildReplyMarkup(buttons);
|
|
910
|
+
return markup && (body.reply_markup = markup), this.callSend(body);
|
|
911
|
+
}
|
|
912
|
+
async answerCallback(id, text) {
|
|
913
|
+
let body = { callback_query_id: id };
|
|
914
|
+
text !== void 0 && (body.text = text), await this.callApi("answerCallbackQuery", body).catch(() => {
|
|
915
|
+
});
|
|
916
|
+
}
|
|
917
|
+
/** lunr: register the bot's slash-command menu (Telegram client autocomplete). Best-effort — caller catches. */
|
|
918
|
+
async sendFile(chatId, file, opts) {
|
|
919
|
+
try {
|
|
920
|
+
let data = new FormData();
|
|
921
|
+
data.set("chat_id", chatId), opts?.threadId && data.set("message_thread_id", opts.threadId), data.set("document", new Blob([new Uint8Array(readFileSync(file))]), basename(file));
|
|
922
|
+
let response = await fetch(`${API_BASE}/bot${this.cfg.token}/sendDocument`, {
|
|
923
|
+
method: "POST",
|
|
924
|
+
body: data,
|
|
925
|
+
signal: AbortSignal.timeout(3e4)
|
|
926
|
+
});
|
|
927
|
+
return response.ok ? { success: !0 } : { success: !1, error: `Telegram file delivery failed: HTTP ${response.status}` };
|
|
928
|
+
} catch {
|
|
929
|
+
return { success: !1, error: "Telegram file delivery failed. Check your connection." };
|
|
930
|
+
}
|
|
931
|
+
}
|
|
932
|
+
async registerCommands(commands) {
|
|
933
|
+
let valid = commands.filter((c) => /^[a-z0-9_]{1,32}$/.test(c.name) && c.description.trim().length > 0).map((c) => ({ command: c.name, description: c.description.trim().slice(0, 256) }));
|
|
934
|
+
valid.length !== 0 && await this.callApi("setMyCommands", { commands: valid });
|
|
935
|
+
}
|
|
936
|
+
async callSend(body) {
|
|
937
|
+
try {
|
|
938
|
+
let result = await this.callApi("sendMessage", body);
|
|
939
|
+
return { success: !0, messageId: String(result.message_id) };
|
|
940
|
+
} catch (err) {
|
|
941
|
+
if (err instanceof TelegramApiError && err.status === 400 && body.reply_parameters !== void 0 && /message to be replied not found/i.test(err.message)) {
|
|
942
|
+
let { reply_parameters: _dropped, ...plain } = body;
|
|
943
|
+
return this.callSend(plain);
|
|
944
|
+
}
|
|
945
|
+
if (err instanceof TelegramApiError && err.status === 400 && body.parse_mode !== void 0 && MARKDOWN_PARSE_ERROR_RE.test(err.message)) {
|
|
946
|
+
let { parse_mode: _dropped, ...plain } = body;
|
|
947
|
+
return this.callSend(plain);
|
|
948
|
+
}
|
|
949
|
+
if (err instanceof TelegramApiError && err.status === 429) {
|
|
950
|
+
await this.sleep((err.retryAfter ?? 1) * 1e3);
|
|
951
|
+
try {
|
|
952
|
+
let result = await this.callApi("sendMessage", body);
|
|
953
|
+
return { success: !0, messageId: String(result.message_id) };
|
|
954
|
+
} catch (retryErr) {
|
|
955
|
+
return { success: !1, error: errMessage2(retryErr), retryable: !0 };
|
|
956
|
+
}
|
|
957
|
+
}
|
|
958
|
+
return {
|
|
959
|
+
success: !1,
|
|
960
|
+
error: errMessage2(err),
|
|
961
|
+
retryable: !(err instanceof TelegramApiError) || err.status >= 500
|
|
962
|
+
};
|
|
963
|
+
}
|
|
964
|
+
}
|
|
965
|
+
async editMessage(chatId, messageId, text, buttons) {
|
|
966
|
+
let body = {
|
|
967
|
+
chat_id: chatId,
|
|
968
|
+
message_id: Number(messageId),
|
|
969
|
+
text,
|
|
970
|
+
parse_mode: "Markdown"
|
|
971
|
+
}, markup = this.buildReplyMarkup(buttons);
|
|
972
|
+
markup !== void 0 && (body.reply_markup = markup);
|
|
973
|
+
try {
|
|
974
|
+
return await this.callApi("editMessageText", body), { success: !0, messageId };
|
|
975
|
+
} catch (err) {
|
|
976
|
+
if (err instanceof TelegramApiError && err.status === 400) {
|
|
977
|
+
if (NOT_MODIFIED_RE.test(err.message))
|
|
978
|
+
return { success: !0, messageId };
|
|
979
|
+
if (MARKDOWN_PARSE_ERROR_RE.test(err.message) && body.parse_mode !== void 0) {
|
|
980
|
+
let { parse_mode: _dropped, ...plain } = body;
|
|
981
|
+
try {
|
|
982
|
+
return await this.callApi("editMessageText", plain), { success: !0, messageId };
|
|
983
|
+
} catch (retryErr) {
|
|
984
|
+
return { success: !1, error: errMessage2(retryErr) };
|
|
985
|
+
}
|
|
986
|
+
}
|
|
987
|
+
}
|
|
988
|
+
return {
|
|
989
|
+
success: !1,
|
|
990
|
+
error: errMessage2(err),
|
|
991
|
+
retryable: !(err instanceof TelegramApiError) || err.status >= 500
|
|
992
|
+
};
|
|
993
|
+
}
|
|
994
|
+
}
|
|
995
|
+
async sendTyping(chatId, threadId) {
|
|
996
|
+
let key = typingKey2(chatId, threadId), body = { chat_id: chatId, action: "typing" };
|
|
997
|
+
threadId !== void 0 && (body.message_thread_id = Number(threadId)), await this.callApi("sendChatAction", body).catch(() => {
|
|
998
|
+
});
|
|
999
|
+
let existing = this.typing.get(key);
|
|
1000
|
+
if (existing) {
|
|
1001
|
+
existing.lastRefresh = this.now();
|
|
1002
|
+
return;
|
|
1003
|
+
}
|
|
1004
|
+
let interval = this.scheduler.setInterval(() => {
|
|
1005
|
+
let entry = this.typing.get(key);
|
|
1006
|
+
if (entry) {
|
|
1007
|
+
if (this.now() - entry.lastRefresh > TYPING_SAFETY_MS2) {
|
|
1008
|
+
this.stopTyping(key);
|
|
1009
|
+
return;
|
|
1010
|
+
}
|
|
1011
|
+
this.callApi("sendChatAction", body).catch(() => {
|
|
1012
|
+
});
|
|
1013
|
+
}
|
|
1014
|
+
}, TYPING_INTERVAL_MS2);
|
|
1015
|
+
this.typing.set(key, { interval, lastRefresh: this.now() });
|
|
1016
|
+
}
|
|
1017
|
+
stopTyping(key) {
|
|
1018
|
+
let entry = this.typing.get(key);
|
|
1019
|
+
entry && (this.scheduler.clearInterval(entry.interval), this.typing.delete(key));
|
|
1020
|
+
}
|
|
1021
|
+
};
|
|
1022
|
+
function typingKey2(chatId, threadId) {
|
|
1023
|
+
return `${chatId}:${threadId ?? ""}`;
|
|
1024
|
+
}
|
|
1025
|
+
|
|
1026
|
+
// packages/coding-agent/dist/gateway/router.js
|
|
1027
|
+
import { existsSync } from "node:fs";
|
|
1028
|
+
|
|
1029
|
+
// packages/coding-agent/dist/gateway/session-keys.js
|
|
1030
|
+
var SESSION_KEY_PREFIX = "agent:main";
|
|
1031
|
+
function sanitize(component) {
|
|
1032
|
+
return component.replace(/[\s:]+/g, "_");
|
|
1033
|
+
}
|
|
1034
|
+
function buildSessionKey(source, options) {
|
|
1035
|
+
let parts = [source.platform, source.chatType, source.chatId].map(sanitize);
|
|
1036
|
+
return source.threadId ? parts.push(sanitize(source.threadId)) : (source.chatType === "group" || source.chatType === "channel") && options.groupSessionsPerUser && parts.push(sanitize(source.userId)), [SESSION_KEY_PREFIX, ...parts].join(":");
|
|
1037
|
+
}
|
|
1038
|
+
|
|
1039
|
+
// packages/coding-agent/dist/gateway/stream.js
|
|
1040
|
+
var SILENCE_MARKERS = /* @__PURE__ */ new Set(["[SILENT]", "NO_REPLY"]);
|
|
1041
|
+
function isMarkerLine(line) {
|
|
1042
|
+
return SILENCE_MARKERS.has(line.trim());
|
|
1043
|
+
}
|
|
1044
|
+
function applySilenceFilter(text) {
|
|
1045
|
+
let trimmed = text.trim();
|
|
1046
|
+
if (trimmed.length === 0 || isMarkerLine(trimmed))
|
|
1047
|
+
return null;
|
|
1048
|
+
let lines = trimmed.split(`
|
|
1049
|
+
`);
|
|
1050
|
+
lines.length > 0 && isMarkerLine(lines[0]) && lines.shift(), lines.length > 0 && isMarkerLine(lines[lines.length - 1]) && lines.pop();
|
|
1051
|
+
let result = lines.join(`
|
|
1052
|
+
`).trim();
|
|
1053
|
+
return result.length > 0 ? result : null;
|
|
1054
|
+
}
|
|
1055
|
+
var StreamConsumer = class {
|
|
1056
|
+
options;
|
|
1057
|
+
buffer = "";
|
|
1058
|
+
flushedLen = 0;
|
|
1059
|
+
lastPreview = "";
|
|
1060
|
+
messageId = null;
|
|
1061
|
+
lastFlushAt = 0;
|
|
1062
|
+
chain = Promise.resolve();
|
|
1063
|
+
maxPreview;
|
|
1064
|
+
now;
|
|
1065
|
+
constructor(options) {
|
|
1066
|
+
this.options = options, this.maxPreview = options.maxPreview ?? 4096, this.now = options.now ?? (() => Date.now());
|
|
1067
|
+
}
|
|
1068
|
+
/** Accumulate a delta; schedule a flush when both gates (chars, interval) pass. */
|
|
1069
|
+
push(delta) {
|
|
1070
|
+
this.buffer += delta, this.buffer.length - this.flushedLen >= this.options.threshold && this.now() - this.lastFlushAt >= this.options.intervalMs && this.schedule();
|
|
1071
|
+
}
|
|
1072
|
+
/** Wait for pending previews; final delivery belongs to the router. */
|
|
1073
|
+
async finalize() {
|
|
1074
|
+
return await this.chain, this.buffer;
|
|
1075
|
+
}
|
|
1076
|
+
/** The platform message id of the preview, when one was successfully sent. */
|
|
1077
|
+
get sentMessageId() {
|
|
1078
|
+
return this.messageId;
|
|
1079
|
+
}
|
|
1080
|
+
/** True when the preview had to truncate the full text (buffer > maxPreview). */
|
|
1081
|
+
get truncated() {
|
|
1082
|
+
return this.buffer.length > this.maxPreview;
|
|
1083
|
+
}
|
|
1084
|
+
/** Preview visible text without a trailing silence-marker fragment. */
|
|
1085
|
+
preview() {
|
|
1086
|
+
let lines = this.buffer.split(`
|
|
1087
|
+
`), last = lines.at(-1)?.trim() ?? "";
|
|
1088
|
+
(SILENCE_MARKERS.has(last) || last && [...SILENCE_MARKERS].some((marker) => marker.startsWith(last))) && lines.pop(), lines.length && isMarkerLine(lines[0]) && lines.shift();
|
|
1089
|
+
let visible = lines.join(`
|
|
1090
|
+
`).trim();
|
|
1091
|
+
if (!visible)
|
|
1092
|
+
return "";
|
|
1093
|
+
if (visible.length <= this.maxPreview)
|
|
1094
|
+
return visible;
|
|
1095
|
+
let cut = this.maxPreview - 3, code = visible.charCodeAt(cut - 1);
|
|
1096
|
+
return code >= 55296 && code <= 56319 && (cut -= 1), `${visible.slice(0, cut)}\u2026`;
|
|
1097
|
+
}
|
|
1098
|
+
schedule(force = !1) {
|
|
1099
|
+
this.chain = this.chain.then(() => this.flush(force)).catch(() => {
|
|
1100
|
+
});
|
|
1101
|
+
}
|
|
1102
|
+
async flush(force) {
|
|
1103
|
+
if (!(this.buffer.length > this.flushedLen) || !force && this.messageId !== null && this.now() - this.lastFlushAt < this.options.intervalMs)
|
|
1104
|
+
return;
|
|
1105
|
+
let text = this.preview();
|
|
1106
|
+
if (!text || text === this.lastPreview)
|
|
1107
|
+
return;
|
|
1108
|
+
let length = this.buffer.length;
|
|
1109
|
+
if (this.messageId === null) {
|
|
1110
|
+
if (this.messageId = await this.options.sendInitial(text), this.messageId === null)
|
|
1111
|
+
return;
|
|
1112
|
+
} else
|
|
1113
|
+
await this.options.edit(this.messageId, text);
|
|
1114
|
+
this.flushedLen = length, this.lastPreview = text, this.lastFlushAt = this.now();
|
|
1115
|
+
}
|
|
1116
|
+
};
|
|
1117
|
+
|
|
1118
|
+
// packages/coding-agent/dist/gateway/router.js
|
|
1119
|
+
function oneLine(text) {
|
|
1120
|
+
return text.replace(/\s+/g, " ").trim().slice(0, 200);
|
|
1121
|
+
}
|
|
1122
|
+
function formatPairingCode(code) {
|
|
1123
|
+
return code.length === 8 ? `${code.slice(0, 4)}-${code.slice(4)}` : code;
|
|
1124
|
+
}
|
|
1125
|
+
function mentionedBot(event) {
|
|
1126
|
+
return event.metadata?.mentionedBot === !0;
|
|
1127
|
+
}
|
|
1128
|
+
function createRouter(deps) {
|
|
1129
|
+
let { adapters, cfg: initialCfg, pairing, bridge, reloadConfig } = deps;
|
|
1130
|
+
registerGatewayApprovalHandler();
|
|
1131
|
+
function freshCfg() {
|
|
1132
|
+
if (!reloadConfig)
|
|
1133
|
+
return initialCfg;
|
|
1134
|
+
try {
|
|
1135
|
+
if (existsSync(gatewayConfigPath()))
|
|
1136
|
+
return loadGatewayConfig();
|
|
1137
|
+
} catch {
|
|
1138
|
+
}
|
|
1139
|
+
return initialCfg;
|
|
1140
|
+
}
|
|
1141
|
+
async function sendError(adapter, event, key, cfg, message, epoch) {
|
|
1142
|
+
await queueGatewayText(key, event.source, adapter, `\u26A0 ${oneLine(message)}`, {
|
|
1143
|
+
kind: "notice",
|
|
1144
|
+
replyTo: event.messageId,
|
|
1145
|
+
cfg,
|
|
1146
|
+
epoch
|
|
1147
|
+
});
|
|
1148
|
+
}
|
|
1149
|
+
function isGroupGated(event, cfg) {
|
|
1150
|
+
let { source } = event;
|
|
1151
|
+
if (source.chatType === "dm")
|
|
1152
|
+
return !1;
|
|
1153
|
+
let platformCfg = platformConfigFor(cfg, source.platform);
|
|
1154
|
+
if (!platformCfg)
|
|
1155
|
+
return !0;
|
|
1156
|
+
let freeResponse = platformCfg.freeResponseChats.includes(source.chatId);
|
|
1157
|
+
return !!(platformCfg.allowedChats.length > 0 && !platformCfg.allowedChats.includes(source.chatId) && !freeResponse && !mentionedBot(event) || platformCfg.requireMention && !freeResponse && !mentionedBot(event));
|
|
1158
|
+
}
|
|
1159
|
+
async function isDenied(adapter, event, cfg) {
|
|
1160
|
+
if (isAuthorized(event.source, cfg, pairing))
|
|
1161
|
+
return !1;
|
|
1162
|
+
let { source } = event;
|
|
1163
|
+
if (source.chatType !== "dm" || cfg.unauthorizedDmBehavior !== "pair")
|
|
1164
|
+
return !0;
|
|
1165
|
+
let code = pairing.issueCode(source.platform, source.userId);
|
|
1166
|
+
return code === null || await adapter.send(source.chatId, `Your lunR pairing code: ${formatPairingCode(code)}. Ask the computer's owner to run lunr gateway pair approve ${source.platform} ${formatPairingCode(code)} --owner if this is their account. Approval without --owner grants chat access only.`, { replyTo: event.messageId, threadId: source.threadId }), !0;
|
|
1167
|
+
}
|
|
1168
|
+
function workspaceReadiness(event, key, cfg) {
|
|
1169
|
+
if (getSession(key) || conversationBinding(key)?.cwd)
|
|
1170
|
+
return;
|
|
1171
|
+
if (!isGatewayOwner(event.source, cfg))
|
|
1172
|
+
return "This chat is paired but has no project. Ask the computer's gateway owner to configure your access locally. /project and /continue require owner access.";
|
|
1173
|
+
let root = cfg.defaultProject;
|
|
1174
|
+
if (!root)
|
|
1175
|
+
return "No default project selected. Use /project in this private chat to choose an approved folder.";
|
|
1176
|
+
try {
|
|
1177
|
+
let cwd = resolveWithinRoots(root, cfg.projectRoots ?? []);
|
|
1178
|
+
bindConversation(key, event.source, { cwd, owner: event.source.userId });
|
|
1179
|
+
return;
|
|
1180
|
+
} catch {
|
|
1181
|
+
return "Default project is no longer an approved folder. Use /project to choose an approved folder.";
|
|
1182
|
+
}
|
|
1183
|
+
}
|
|
1184
|
+
async function handleSlash(adapter, event, key) {
|
|
1185
|
+
let text = event.text.trim();
|
|
1186
|
+
if (!text.startsWith("/"))
|
|
1187
|
+
return !1;
|
|
1188
|
+
let firstToken = text.split(/\s+/, 1)[0].toLowerCase(), commandWord = firstToken.split("@")[0].slice(1), args = text.slice(firstToken.length).trim();
|
|
1189
|
+
if (deps.remoteControls) {
|
|
1190
|
+
let { handleMobileCommand, cancelMobileTransfer } = await import("./mobile-commands-WKFSFACZ.js");
|
|
1191
|
+
if (["stop", "stopall", "new", "cancel"].includes(commandWord) && cancelMobileTransfer(key), commandWord === "cancel")
|
|
1192
|
+
return invalidateGatewayDialogs(key), await adapter.send(event.source.chatId, "Cancelled the pending selection or transfer.", {
|
|
1193
|
+
threadId: event.source.threadId
|
|
1194
|
+
}), !0;
|
|
1195
|
+
if (await runWithApprovalContext({ key, adapter, source: event.source }, () => handleMobileCommand({ key, event, adapter, bridge, cfg: freshCfg() }, commandWord, args)))
|
|
1196
|
+
return !0;
|
|
1197
|
+
if (!event.text.startsWith("/"))
|
|
1198
|
+
return !1;
|
|
1199
|
+
}
|
|
1200
|
+
if (commandWord === "start") {
|
|
1201
|
+
let issue = deps.remoteControls ? workspaceReadiness(event, key, freshCfg()) : void 0;
|
|
1202
|
+
if (issue)
|
|
1203
|
+
return await sendCommandReply(adapter, event, issue), !0;
|
|
1204
|
+
try {
|
|
1205
|
+
let session = await bridge.getSession(key, !0), models = await session?.modelRuntime.getAvailable();
|
|
1206
|
+
models?.length ? !session?.model || !models.some((model) => model.id === session.model?.id && model.provider === session.model.provider) ? await sendCommandReply(adapter, event, "No available model selected. Use /model here to choose one.") : await sendCommandReply(adapter, event, "Ready. Send a message to begin, or use /model to choose a model.") : await sendCommandReply(adapter, event, "No authenticated model available. Use /login on your computer, then try /start again.");
|
|
1207
|
+
} catch {
|
|
1208
|
+
await sendCommandReply(adapter, event, "Session setup failed. Run lunr gateway doctor on your computer, then try /start again.");
|
|
1209
|
+
}
|
|
1210
|
+
return !0;
|
|
1211
|
+
}
|
|
1212
|
+
if (deps.remoteControls && commandWord === "model") {
|
|
1213
|
+
let issue = workspaceReadiness(event, key, freshCfg());
|
|
1214
|
+
if (issue)
|
|
1215
|
+
return await sendCommandReply(adapter, event, issue), !0;
|
|
1216
|
+
}
|
|
1217
|
+
let cmd = CHAT_COMMANDS.find((c) => c.name === commandWord || c.aliases?.includes(commandWord));
|
|
1218
|
+
if (!cmd)
|
|
1219
|
+
return event.source.chatType !== "dm";
|
|
1220
|
+
let ctx = {
|
|
1221
|
+
event,
|
|
1222
|
+
key,
|
|
1223
|
+
adapter,
|
|
1224
|
+
bridge,
|
|
1225
|
+
cfg: freshCfg(),
|
|
1226
|
+
args,
|
|
1227
|
+
reply: (message) => sendCommandReply(adapter, event, message)
|
|
1228
|
+
};
|
|
1229
|
+
return runWithApprovalContext({ key, adapter, source: event.source }, () => runChatCommand(cmd, ctx));
|
|
1230
|
+
}
|
|
1231
|
+
async function deliver(adapter, event, text, key, cfg, opts) {
|
|
1232
|
+
let filtered = applySilenceFilter(text);
|
|
1233
|
+
if (filtered !== null) {
|
|
1234
|
+
if (opts.editMessageId) {
|
|
1235
|
+
let chunks = splitMessage(filtered, adapter.maxMessageLength);
|
|
1236
|
+
if ((await adapter.editMessage(event.source.chatId, opts.editMessageId, opts.previewTruncated ? chunks[0] : filtered).catch(() => ({ success: !1 }))).success) {
|
|
1237
|
+
if (!opts.previewTruncated)
|
|
1238
|
+
return;
|
|
1239
|
+
await queueGatewayText(key, event.source, adapter, chunks.slice(1).join(""), {
|
|
1240
|
+
kind: "result",
|
|
1241
|
+
cfg,
|
|
1242
|
+
chunks: chunks.slice(1)
|
|
1243
|
+
});
|
|
1244
|
+
return;
|
|
1245
|
+
}
|
|
1246
|
+
}
|
|
1247
|
+
await queueGatewayText(key, event.source, adapter, filtered, {
|
|
1248
|
+
kind: "result",
|
|
1249
|
+
replyTo: opts.reply ? event.messageId : void 0,
|
|
1250
|
+
cfg
|
|
1251
|
+
});
|
|
1252
|
+
}
|
|
1253
|
+
}
|
|
1254
|
+
async function runTurn(adapter, event, key, cfg) {
|
|
1255
|
+
let epoch = gatewayEpoch(key), streaming = cfg.streaming.enabled && typeof adapter.editMessage == "function", consumer;
|
|
1256
|
+
streaming && (consumer = new StreamConsumer({
|
|
1257
|
+
sendInitial: async (text) => {
|
|
1258
|
+
let result2 = await adapter.send(event.source.chatId, text, {
|
|
1259
|
+
replyTo: event.messageId,
|
|
1260
|
+
threadId: event.source.threadId
|
|
1261
|
+
});
|
|
1262
|
+
return result2.success ? result2.messageId ?? null : null;
|
|
1263
|
+
},
|
|
1264
|
+
edit: async (messageId, text) => {
|
|
1265
|
+
let result2 = await adapter.editMessage(event.source.chatId, messageId, text);
|
|
1266
|
+
if (!result2.success)
|
|
1267
|
+
throw new Error(result2.error ?? "Preview edit failed");
|
|
1268
|
+
},
|
|
1269
|
+
intervalMs: cfg.streaming.editIntervalMs,
|
|
1270
|
+
threshold: cfg.streaming.bufferThreshold,
|
|
1271
|
+
maxPreview: adapter.maxMessageLength
|
|
1272
|
+
}));
|
|
1273
|
+
let callbacks = {
|
|
1274
|
+
onDelta: consumer ? (delta) => consumer.push(delta) : void 0,
|
|
1275
|
+
onFollowUpResult: (text) => {
|
|
1276
|
+
deliver(adapter, event, text, key, cfg, { reply: !1 }).catch((error) => console.error("[gateway] follow-up delivery failed:", error));
|
|
1277
|
+
},
|
|
1278
|
+
onError: (message) => {
|
|
1279
|
+
sendError(adapter, event, key, cfg, message, epoch).catch((error) => console.error("[gateway] error delivery failed:", error));
|
|
1280
|
+
}
|
|
1281
|
+
}, result = await runWithApprovalContext({ key, adapter, source: event.source }, () => bridge.runTurn(key, event, callbacks));
|
|
1282
|
+
result !== QUEUED && (consumer && await consumer.finalize(), await deliver(adapter, event, result, key, cfg, {
|
|
1283
|
+
reply: !consumer,
|
|
1284
|
+
editMessageId: consumer?.sentMessageId ?? void 0,
|
|
1285
|
+
previewTruncated: consumer?.truncated ?? !1
|
|
1286
|
+
}));
|
|
1287
|
+
}
|
|
1288
|
+
return {
|
|
1289
|
+
async handleEvent(event) {
|
|
1290
|
+
let adapter = adapters.get(event.source.platform);
|
|
1291
|
+
if (!adapter)
|
|
1292
|
+
return;
|
|
1293
|
+
let cfg = freshCfg(), key = buildSessionKey(event.source, { groupSessionsPerUser: cfg.groupSessionsPerUser }), epoch = gatewayEpoch(key);
|
|
1294
|
+
try {
|
|
1295
|
+
if (isGroupGated(event, cfg) || (rememberGatewayRole(key, event.source), await isDenied(adapter, event, cfg)))
|
|
1296
|
+
return;
|
|
1297
|
+
if (deps.remoteControls) {
|
|
1298
|
+
let binding = conversationBinding(key);
|
|
1299
|
+
if (binding?.owner && (requireGatewayOwner(event.source, cfg), binding.owner !== event.source.userId))
|
|
1300
|
+
throw new Error("This session belongs to a different owner.");
|
|
1301
|
+
if (bindConversation(key, event.source), acceptGatewayInput(key, event))
|
|
1302
|
+
return;
|
|
1303
|
+
}
|
|
1304
|
+
if (await handleSlash(adapter, event, key))
|
|
1305
|
+
return;
|
|
1306
|
+
let issue = deps.remoteControls ? workspaceReadiness(event, key, cfg) : void 0;
|
|
1307
|
+
if (issue) {
|
|
1308
|
+
await sendCommandReply(adapter, event, issue);
|
|
1309
|
+
return;
|
|
1310
|
+
}
|
|
1311
|
+
await adapter.sendTyping(event.source.chatId, event.source.threadId).catch(() => {
|
|
1312
|
+
}), await runTurn(adapter, event, key, cfg);
|
|
1313
|
+
} catch (err) {
|
|
1314
|
+
await sendError(adapter, event, key, cfg, err instanceof Error ? err.message : String(err), epoch).catch(() => {
|
|
1315
|
+
});
|
|
1316
|
+
}
|
|
1317
|
+
}
|
|
1318
|
+
};
|
|
1319
|
+
}
|
|
1320
|
+
|
|
1321
|
+
// packages/coding-agent/dist/gateway/index.js
|
|
1322
|
+
var ADAPTER_FACTORIES = {
|
|
1323
|
+
telegram: (cfg) => new TelegramAdapter(cfg),
|
|
1324
|
+
discord: (cfg) => new DiscordAdapter(cfg)
|
|
1325
|
+
}, KNOWN_PLATFORMS = ["telegram", "discord"], SETUP_INSTRUCTIONS = {
|
|
1326
|
+
telegram: ["Telegram: run lunr gateway setup locally to configure the bot token and owner ID."],
|
|
1327
|
+
discord: ["Discord: run lunr gateway setup locally to configure the bot token and owner ID."]
|
|
1328
|
+
};
|
|
1329
|
+
function printSetupInstructions(enabledButUnrunnable) {
|
|
1330
|
+
console.log("lunR gateway: no runnable platforms configured.");
|
|
1331
|
+
for (let platform of enabledButUnrunnable)
|
|
1332
|
+
console.log(` (platform "${platform}" is enabled but has no registered adapter or resolvable token)`);
|
|
1333
|
+
for (let platform of KNOWN_PLATFORMS)
|
|
1334
|
+
for (let line of SETUP_INSTRUCTIONS[platform])
|
|
1335
|
+
console.log(line);
|
|
1336
|
+
}
|
|
1337
|
+
async function runPairApprove(platform, code, owner = !1) {
|
|
1338
|
+
if (!code)
|
|
1339
|
+
return console.error("Usage: lunr gateway pair approve <platform> <code> [--owner]"), 1;
|
|
1340
|
+
let userId = createPairingStore().approve(platform, code);
|
|
1341
|
+
if (userId === null)
|
|
1342
|
+
return console.error(`Pairing failed: no valid pending code "${code}" for ${platform} (wrong, expired, or locked out).`), 1;
|
|
1343
|
+
try {
|
|
1344
|
+
if (owner) {
|
|
1345
|
+
let cfg = loadGatewayConfig();
|
|
1346
|
+
if (platform !== "telegram" && platform !== "discord")
|
|
1347
|
+
throw new Error("Unknown platform.");
|
|
1348
|
+
cfg.owners ??= { telegram: [], discord: [] }, cfg.owners[platform] = [.../* @__PURE__ */ new Set([...cfg.owners[platform], userId])], cfg[platform].allowedUsers = [.../* @__PURE__ */ new Set([...cfg[platform].allowedUsers, userId])], saveGatewayConfig(cfg);
|
|
1349
|
+
} else
|
|
1350
|
+
addAllowedUser(platform, userId);
|
|
1351
|
+
} catch (err) {
|
|
1352
|
+
return console.error(`Paired ${platform} user ${userId}, but could not persist allowedUsers: ${err}`), 1;
|
|
1353
|
+
}
|
|
1354
|
+
return console.log(`Approved ${platform} user ${userId}${owner ? " as owner with local project and TUI access" : " for chat only; owner access requires local --owner approval"}.`), 0;
|
|
1355
|
+
}
|
|
1356
|
+
function runPairList() {
|
|
1357
|
+
let pairing = createPairingStore(), pending = pairing.listPending(), approved = pairing.listApproved();
|
|
1358
|
+
if (console.log("Pending pairing codes:"), pending.length === 0)
|
|
1359
|
+
console.log(" (none)");
|
|
1360
|
+
else
|
|
1361
|
+
for (let p of pending)
|
|
1362
|
+
console.log(` ${p.platform} ${p.code} user=${p.userId} expires ${new Date(p.expiresAt).toISOString()}`);
|
|
1363
|
+
if (console.log("Paired users:"), approved.length === 0)
|
|
1364
|
+
console.log(" (none)");
|
|
1365
|
+
else
|
|
1366
|
+
for (let u of approved)
|
|
1367
|
+
console.log(` ${u.platform} ${u.userId} approved ${new Date(u.approvedAt).toISOString()}`);
|
|
1368
|
+
return 0;
|
|
1369
|
+
}
|
|
1370
|
+
function runStatus() {
|
|
1371
|
+
let cfg = loadGatewayConfig();
|
|
1372
|
+
console.log(`chat-platforms: ${isFeatureEnabled("chat-platforms") ? "enabled" : "disabled"} (install-features.json)`), console.log("lunR gateway status:");
|
|
1373
|
+
for (let platform of KNOWN_PLATFORMS) {
|
|
1374
|
+
let platformCfg = platformConfigFor(cfg, platform);
|
|
1375
|
+
if (!platformCfg)
|
|
1376
|
+
continue;
|
|
1377
|
+
let token = resolvePlatformToken(platform, platformCfg), adapter = ADAPTER_FACTORIES[platform] === void 0 ? "no adapter" : "adapter registered";
|
|
1378
|
+
console.log(` ${platform}: ${platformCfg.enabled ? "enabled" : "disabled"} \xB7 token ${token ? "resolved" : "missing"} \xB7 ${adapter}`);
|
|
1379
|
+
}
|
|
1380
|
+
let sessions = listSessions();
|
|
1381
|
+
return console.log(` sessions: ${Object.keys(sessions).length} stored`), 0;
|
|
1382
|
+
}
|
|
1383
|
+
async function runDaemon() {
|
|
1384
|
+
if (!isFeatureEnabled("chat-platforms"))
|
|
1385
|
+
return console.error("lunR gateway: chat platforms are not enabled."), console.error("Enable with: lunr features enable chat-platforms"), 1;
|
|
1386
|
+
let cfg = loadGatewayConfig(), adapters = /* @__PURE__ */ new Map(), skipped = [];
|
|
1387
|
+
for (let platform of KNOWN_PLATFORMS) {
|
|
1388
|
+
let platformCfg = platformConfigFor(cfg, platform);
|
|
1389
|
+
if (!platformCfg?.enabled)
|
|
1390
|
+
continue;
|
|
1391
|
+
let factory = ADAPTER_FACTORIES[platform];
|
|
1392
|
+
if (factory === void 0) {
|
|
1393
|
+
skipped.push(platform);
|
|
1394
|
+
continue;
|
|
1395
|
+
}
|
|
1396
|
+
let token = resolvePlatformToken(platform, platformCfg);
|
|
1397
|
+
if (!token) {
|
|
1398
|
+
skipped.push(platform);
|
|
1399
|
+
continue;
|
|
1400
|
+
}
|
|
1401
|
+
adapters.set(platform, factory({ ...platformCfg, token }));
|
|
1402
|
+
}
|
|
1403
|
+
if (adapters.size === 0)
|
|
1404
|
+
return printSetupInstructions(skipped), 1;
|
|
1405
|
+
let pairing = createPairingStore(), bridge = new AgentBridge();
|
|
1406
|
+
for (let adapter of adapters.values())
|
|
1407
|
+
adapter.setCommandSuggestions?.(async (source, command) => {
|
|
1408
|
+
let session = bridge.peekSession(buildSessionKey(source, loadGatewayConfig()));
|
|
1409
|
+
return session ? command === "thinking" ? session.getAvailableThinkingLevels() : command === "model" ? (await session.modelRuntime.getAvailable()).map((model) => `${model.provider}/${model.id}`) : [] : [];
|
|
1410
|
+
});
|
|
1411
|
+
let router = createRouter({ adapters, cfg, pairing, bridge, reloadConfig: !0, remoteControls: !0 }), finish, stopped = new Promise((resolve) => {
|
|
1412
|
+
finish = resolve;
|
|
1413
|
+
}), stopping = !1, cron, platformStatus = {}, retries = /* @__PURE__ */ new Set(), shutdown = () => {
|
|
1414
|
+
if (!stopping) {
|
|
1415
|
+
stopping = !0, owner.update(platformStatus, "stopping"), cron?.stop();
|
|
1416
|
+
for (let timer of retries)
|
|
1417
|
+
clearTimeout(timer);
|
|
1418
|
+
stopButtonSweeper(), (async () => {
|
|
1419
|
+
await bridge.shutdown(), await Promise.all([...adapters.values()].map((adapter) => adapter.disconnect().catch(() => {
|
|
1420
|
+
}))), stopGatewayPresenter(), owner.release(), process.removeListener("SIGINT", shutdown), process.removeListener("SIGTERM", shutdown), finish();
|
|
1421
|
+
})().catch((error) => {
|
|
1422
|
+
console.error("Gateway shutdown failed:", error instanceof Error ? error.message : String(error)), stopping = !1, owner.update(platformStatus, Object.values(platformStatus).includes("connected") ? "ready" : "starting"), startButtonSweeper(), cron = startGatewayCron({ adapters, cfg });
|
|
1423
|
+
for (let [platform, adapter] of adapters)
|
|
1424
|
+
platformStatus[platform] !== "connected" && connect(platform, adapter);
|
|
1425
|
+
});
|
|
1426
|
+
}
|
|
1427
|
+
}, owner = claimGateway(shutdown);
|
|
1428
|
+
process.on("SIGINT", shutdown), process.on("SIGTERM", shutdown), startGatewayPresenter(adapters), startButtonSweeper();
|
|
1429
|
+
let connect = async (platform, adapter) => {
|
|
1430
|
+
if (!stopping) {
|
|
1431
|
+
try {
|
|
1432
|
+
if (platformStatus[platform] = "connecting", owner.update(platformStatus, Object.values(platformStatus).includes("connected") ? "ready" : "starting"), !await adapter.connect())
|
|
1433
|
+
throw new Error("Connection failed");
|
|
1434
|
+
adapter.onMessage((event) => {
|
|
1435
|
+
router.handleEvent(event);
|
|
1436
|
+
}), adapter.onCallback(async (event) => {
|
|
1437
|
+
await handleApprovalCallback(event, adapter) || handleCallback(event, { adapters, cfg: loadGatewayConfig(), pairing, bridge, adapter });
|
|
1438
|
+
});
|
|
1439
|
+
try {
|
|
1440
|
+
await adapter.registerCommands?.(botCommandSpecs());
|
|
1441
|
+
} catch (err) {
|
|
1442
|
+
console.error(`[gateway] ${platform}: command menu registration failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
1443
|
+
}
|
|
1444
|
+
if (stopping) {
|
|
1445
|
+
await adapter.disconnect();
|
|
1446
|
+
return;
|
|
1447
|
+
}
|
|
1448
|
+
platformStatus[platform] = "connected", console.log(`lunR gateway: ${platform} connected`);
|
|
1449
|
+
} catch {
|
|
1450
|
+
if (platformStatus[platform] = "disconnected, retrying (check gateway logs)", await adapter.disconnect().catch(() => {
|
|
1451
|
+
}), !stopping) {
|
|
1452
|
+
let retry = setTimeout(() => {
|
|
1453
|
+
retries.delete(retry), connect(platform, adapter);
|
|
1454
|
+
}, 5e3);
|
|
1455
|
+
retries.add(retry);
|
|
1456
|
+
}
|
|
1457
|
+
}
|
|
1458
|
+
stopping || owner.update(platformStatus, Object.values(platformStatus).includes("connected") ? "ready" : "starting");
|
|
1459
|
+
}
|
|
1460
|
+
};
|
|
1461
|
+
for (let [platform, adapter] of adapters)
|
|
1462
|
+
connect(platform, adapter);
|
|
1463
|
+
return cron = startGatewayCron({ adapters, cfg }), console.log(`lunR gateway: cron scheduler started (${cron.intervalMs / 1e3}s interval)`), owner.update(platformStatus, "starting"), await stopped, 0;
|
|
1464
|
+
}
|
|
1465
|
+
async function runGateway(args) {
|
|
1466
|
+
let [sub, ...rest] = args;
|
|
1467
|
+
if (sub === "pair") {
|
|
1468
|
+
let [action, platform, code, flag] = rest;
|
|
1469
|
+
return action === "approve" && platform && (flag === void 0 || flag === "--owner") ? runPairApprove(platform, code, flag === "--owner") : action === "list" ? runPairList() : (console.error("Usage: lunr gateway pair approve <platform> <code> [--owner] | lunr gateway pair list"), 1);
|
|
1470
|
+
}
|
|
1471
|
+
return sub === "status" ? runStatus() : sub === void 0 ? runDaemon() : (console.error(`Unknown gateway sub-command "${sub}". Expected: pair approve | pair list | status`), 1);
|
|
1472
|
+
}
|
|
1473
|
+
export {
|
|
1474
|
+
ADAPTER_FACTORIES,
|
|
1475
|
+
runGateway
|
|
1476
|
+
};
|