@theowlops/boombot 0.0.0-stage → 1.1.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/README.md +69 -3
- package/dist/LICENSE +21 -0
- package/dist/bin/boombot.js +16 -0
- package/dist/cli/api-key.js +123 -0
- package/dist/cli/bin-bun.js +17 -0
- package/dist/cli/bin.js +34 -0
- package/dist/cli/cli/cli-error.js +61 -0
- package/dist/cli/cli/dispatch.js +138 -0
- package/dist/cli/cli/help.js +83 -0
- package/dist/cli/cli/parser.js +89 -0
- package/dist/cli/cli/registry.js +185 -0
- package/dist/cli/cli/spec.js +41 -0
- package/dist/cli/cli/suggest.js +125 -0
- package/dist/cli/cli/version.js +30 -0
- package/dist/cli/cli/vocabulary.js +87 -0
- package/dist/cli/commands/doctor.js +365 -0
- package/dist/cli/commands/gateway.js +290 -0
- package/dist/cli/commands/migrate.js +270 -0
- package/dist/cli/commands/plugin.js +97 -0
- package/dist/cli/commands/setup.js +244 -0
- package/dist/cli/config-file.js +133 -0
- package/dist/cli/master-key.js +78 -0
- package/dist/cli/open-browser.js +59 -0
- package/dist/cli/web-assets.js +58 -0
- package/dist/gateway/auth.js +46 -0
- package/dist/gateway/config-format.js +202 -0
- package/dist/gateway/config.js +427 -0
- package/dist/gateway/context.js +1 -0
- package/dist/gateway/env-file.js +129 -0
- package/dist/gateway/events.js +172 -0
- package/dist/gateway/guard/tagging.js +505 -0
- package/dist/gateway/handlers/index.js +66 -0
- package/dist/gateway/handlers/memory.js +54 -0
- package/dist/gateway/handlers/providers.js +73 -0
- package/dist/gateway/handlers/registry.js +39 -0
- package/dist/gateway/handlers/sessions.js +188 -0
- package/dist/gateway/handlers/system.js +12 -0
- package/dist/gateway/handlers/tasks.js +191 -0
- package/dist/gateway/handlers/turn.js +100 -0
- package/dist/gateway/index.js +126 -0
- package/dist/gateway/main.js +23 -0
- package/dist/gateway/server.js +354 -0
- package/dist/gateway/services/context-limits.js +75 -0
- package/dist/gateway/services/history-normalizer.js +42 -0
- package/dist/gateway/services/image-pipeline.js +56 -0
- package/dist/gateway/services/key-roulette-client.js +43 -0
- package/dist/gateway/services/llm-client.js +593 -0
- package/dist/gateway/services/llm-decoder.js +200 -0
- package/dist/gateway/services/local-fallback.js +135 -0
- package/dist/gateway/services/memory.js +511 -0
- package/dist/gateway/services/persistent-memory.js +196 -0
- package/dist/gateway/services/providers.js +44 -0
- package/dist/gateway/services/tasks.js +237 -0
- package/dist/gateway/services/verification.js +124 -0
- package/dist/gateway/services/vision-payload.js +48 -0
- package/dist/gateway/services.js +257 -0
- package/dist/gateway/session-snapshot.js +19 -0
- package/dist/gateway/sessions.js +701 -0
- package/dist/gateway/static.js +239 -0
- package/dist/gateway/turns/clarify-tool.js +57 -0
- package/dist/gateway/turns/cronjob-tool.js +96 -0
- package/dist/gateway/turns/deferred-tools.js +154 -0
- package/dist/gateway/turns/execute-code-tool.js +84 -0
- package/dist/gateway/turns/file-tool-defs.js +178 -0
- package/dist/gateway/turns/file-tool-ops.js +178 -0
- package/dist/gateway/turns/file-tool-scan.js +182 -0
- package/dist/gateway/turns/file-tool.js +302 -0
- package/dist/gateway/turns/index.js +416 -0
- package/dist/gateway/turns/jev-middleware.js +91 -0
- package/dist/gateway/turns/local-reply.js +156 -0
- package/dist/gateway/turns/mcp-client.js +643 -0
- package/dist/gateway/turns/memory-tool.js +171 -0
- package/dist/gateway/turns/middleware.js +96 -0
- package/dist/gateway/turns/python-core.js +397 -0
- package/dist/gateway/turns/routing/index.js +3 -0
- package/dist/gateway/turns/routing/intent-classifier.js +60 -0
- package/dist/gateway/turns/routing/planner-adapter.js +91 -0
- package/dist/gateway/turns/routing/types.js +1 -0
- package/dist/gateway/turns/runtime-deps.js +228 -0
- package/dist/gateway/turns/self-config-tool.js +277 -0
- package/dist/gateway/turns/service-types.js +11 -0
- package/dist/gateway/turns/service.js +820 -0
- package/dist/gateway/turns/session-adapter.js +158 -0
- package/dist/gateway/turns/session-tool.js +49 -0
- package/dist/gateway/turns/shell-tool.js +190 -0
- package/dist/gateway/turns/skill-tool.js +239 -0
- package/dist/gateway/turns/spillover.js +201 -0
- package/dist/gateway/turns/subagent-tool.js +140 -0
- package/dist/gateway/turns/system-prompt.js +121 -0
- package/dist/gateway/turns/tool-schema.js +90 -0
- package/dist/gateway/turns/turn-utils.js +58 -0
- package/dist/gateway/turns/vision-tool.js +120 -0
- package/dist/gateway/types.js +1 -0
- package/dist/native/win32-x64/boombot-native-host.exe +0 -0
- package/dist/node_modules/@boombot/channels/handlers.d.ts +9 -0
- package/dist/node_modules/@boombot/channels/handlers.js +109 -0
- package/dist/node_modules/@boombot/channels/index.d.ts +12 -0
- package/dist/node_modules/@boombot/channels/index.js +12 -0
- package/dist/node_modules/@boombot/channels/package.json +9 -0
- package/dist/node_modules/@boombot/channels/service.d.ts +62 -0
- package/dist/node_modules/@boombot/channels/service.js +608 -0
- package/dist/node_modules/@boombot/channels/tool.d.ts +10 -0
- package/dist/node_modules/@boombot/channels/tool.js +46 -0
- package/dist/node_modules/@boombot/channels/transports/common/dedup.d.ts +17 -0
- package/dist/node_modules/@boombot/channels/transports/common/dedup.js +42 -0
- package/dist/node_modules/@boombot/channels/transports/common/handoff.d.ts +19 -0
- package/dist/node_modules/@boombot/channels/transports/common/handoff.js +32 -0
- package/dist/node_modules/@boombot/channels/transports/common/index.d.ts +3 -0
- package/dist/node_modules/@boombot/channels/transports/common/index.js +3 -0
- package/dist/node_modules/@boombot/channels/transports/common/types.d.ts +99 -0
- package/dist/node_modules/@boombot/channels/transports/common/types.js +54 -0
- package/dist/node_modules/@boombot/channels/transports/common.d.ts +2 -0
- package/dist/node_modules/@boombot/channels/transports/common.js +2 -0
- package/dist/node_modules/@boombot/channels/transports/dedup/index.d.ts +1 -0
- package/dist/node_modules/@boombot/channels/transports/dedup/index.js +1 -0
- package/dist/node_modules/@boombot/channels/transports/dedup.d.ts +2 -0
- package/dist/node_modules/@boombot/channels/transports/dedup.js +2 -0
- package/dist/node_modules/@boombot/channels/transports/discord/index.d.ts +1 -0
- package/dist/node_modules/@boombot/channels/transports/discord/index.js +1 -0
- package/dist/node_modules/@boombot/channels/transports/discord/transport.d.ts +36 -0
- package/dist/node_modules/@boombot/channels/transports/discord/transport.js +199 -0
- package/dist/node_modules/@boombot/channels/transports/discord.d.ts +2 -0
- package/dist/node_modules/@boombot/channels/transports/discord.js +2 -0
- package/dist/node_modules/@boombot/channels/transports/handoff.d.ts +2 -0
- package/dist/node_modules/@boombot/channels/transports/handoff.js +2 -0
- package/dist/node_modules/@boombot/channels/transports/messenger/index.d.ts +1 -0
- package/dist/node_modules/@boombot/channels/transports/messenger/index.js +1 -0
- package/dist/node_modules/@boombot/channels/transports/messenger/transport.d.ts +34 -0
- package/dist/node_modules/@boombot/channels/transports/messenger/transport.js +180 -0
- package/dist/node_modules/@boombot/channels/transports/messenger.d.ts +2 -0
- package/dist/node_modules/@boombot/channels/transports/messenger.js +2 -0
- package/dist/node_modules/@boombot/channels/transports/slack/index.d.ts +1 -0
- package/dist/node_modules/@boombot/channels/transports/slack/index.js +1 -0
- package/dist/node_modules/@boombot/channels/transports/slack/transport.d.ts +35 -0
- package/dist/node_modules/@boombot/channels/transports/slack/transport.js +183 -0
- package/dist/node_modules/@boombot/channels/transports/slack.d.ts +2 -0
- package/dist/node_modules/@boombot/channels/transports/slack.js +2 -0
- package/dist/node_modules/@boombot/channels/transports/streamer/index.d.ts +1 -0
- package/dist/node_modules/@boombot/channels/transports/streamer/index.js +1 -0
- package/dist/node_modules/@boombot/channels/transports/streamer/streamer.d.ts +31 -0
- package/dist/node_modules/@boombot/channels/transports/streamer/streamer.js +141 -0
- package/dist/node_modules/@boombot/channels/transports/streamer.d.ts +2 -0
- package/dist/node_modules/@boombot/channels/transports/streamer.js +2 -0
- package/dist/node_modules/@boombot/channels/transports/telegram/index.d.ts +1 -0
- package/dist/node_modules/@boombot/channels/transports/telegram/index.js +1 -0
- package/dist/node_modules/@boombot/channels/transports/telegram/transport.d.ts +75 -0
- package/dist/node_modules/@boombot/channels/transports/telegram/transport.js +395 -0
- package/dist/node_modules/@boombot/channels/transports/telegram.d.ts +2 -0
- package/dist/node_modules/@boombot/channels/transports/telegram.js +2 -0
- package/dist/node_modules/@boombot/channels/transports/tiktok/index.d.ts +1 -0
- package/dist/node_modules/@boombot/channels/transports/tiktok/index.js +1 -0
- package/dist/node_modules/@boombot/channels/transports/tiktok/transport.d.ts +27 -0
- package/dist/node_modules/@boombot/channels/transports/tiktok/transport.js +97 -0
- package/dist/node_modules/@boombot/channels/transports/tiktok.d.ts +2 -0
- package/dist/node_modules/@boombot/channels/transports/tiktok.js +2 -0
- package/dist/node_modules/@boombot/channels/transports/whatsapp/index.d.ts +1 -0
- package/dist/node_modules/@boombot/channels/transports/whatsapp/index.js +1 -0
- package/dist/node_modules/@boombot/channels/transports/whatsapp/transport.d.ts +38 -0
- package/dist/node_modules/@boombot/channels/transports/whatsapp/transport.js +189 -0
- package/dist/node_modules/@boombot/channels/transports/whatsapp.d.ts +2 -0
- package/dist/node_modules/@boombot/channels/transports/whatsapp.js +2 -0
- package/dist/node_modules/@boombot/channels/transports/zalo/index.d.ts +2 -0
- package/dist/node_modules/@boombot/channels/transports/zalo/index.js +2 -0
- package/dist/node_modules/@boombot/channels/transports/zalo/oa.d.ts +28 -0
- package/dist/node_modules/@boombot/channels/transports/zalo/oa.js +94 -0
- package/dist/node_modules/@boombot/channels/transports/zalo/personal.d.ts +106 -0
- package/dist/node_modules/@boombot/channels/transports/zalo/personal.js +171 -0
- package/dist/node_modules/@boombot/channels/transports/zalo-personal.d.ts +2 -0
- package/dist/node_modules/@boombot/channels/transports/zalo-personal.js +2 -0
- package/dist/node_modules/@boombot/channels/transports/zalo.d.ts +2 -0
- package/dist/node_modules/@boombot/channels/transports/zalo.js +2 -0
- package/dist/node_modules/@boombot/core/agent-core/index.d.ts +12 -0
- package/dist/node_modules/@boombot/core/agent-core/index.js +12 -0
- package/dist/node_modules/@boombot/core/agent-core/middleware.d.ts +60 -0
- package/dist/node_modules/@boombot/core/agent-core/middleware.js +152 -0
- package/dist/node_modules/@boombot/core/agent-core/routing.d.ts +128 -0
- package/dist/node_modules/@boombot/core/agent-core/routing.js +437 -0
- package/dist/node_modules/@boombot/core/agent-core/runtime-deps.d.ts +88 -0
- package/dist/node_modules/@boombot/core/agent-core/runtime-deps.js +8 -0
- package/dist/node_modules/@boombot/core/agent-core/tool-errors.d.ts +44 -0
- package/dist/node_modules/@boombot/core/agent-core/tool-errors.js +60 -0
- package/dist/node_modules/@boombot/core/agent-core/turn-loop.d.ts +21 -0
- package/dist/node_modules/@boombot/core/agent-core/turn-loop.js +561 -0
- package/dist/node_modules/@boombot/core/agent-core/types.d.ts +189 -0
- package/dist/node_modules/@boombot/core/agent-core/types.js +7 -0
- package/dist/node_modules/@boombot/core/compaction/compactor.d.ts +19 -0
- package/dist/node_modules/@boombot/core/compaction/compactor.js +127 -0
- package/dist/node_modules/@boombot/core/compaction/estimator.d.ts +10 -0
- package/dist/node_modules/@boombot/core/compaction/estimator.js +48 -0
- package/dist/node_modules/@boombot/core/compaction/index.d.ts +3 -0
- package/dist/node_modules/@boombot/core/compaction/index.js +3 -0
- package/dist/node_modules/@boombot/core/compaction/types.d.ts +31 -0
- package/dist/node_modules/@boombot/core/compaction/types.js +7 -0
- package/dist/node_modules/@boombot/core/index.d.ts +9 -0
- package/dist/node_modules/@boombot/core/index.js +9 -0
- package/dist/node_modules/@boombot/core/jev/index.d.ts +2 -0
- package/dist/node_modules/@boombot/core/jev/index.js +2 -0
- package/dist/node_modules/@boombot/core/jev/jev.d.ts +30 -0
- package/dist/node_modules/@boombot/core/jev/jev.js +164 -0
- package/dist/node_modules/@boombot/core/jev/types.d.ts +22 -0
- package/dist/node_modules/@boombot/core/jev/types.js +1 -0
- package/dist/node_modules/@boombot/core/memory/consolidation/budget.d.ts +63 -0
- package/dist/node_modules/@boombot/core/memory/consolidation/budget.js +94 -0
- package/dist/node_modules/@boombot/core/memory/consolidation/consolidator.d.ts +152 -0
- package/dist/node_modules/@boombot/core/memory/consolidation/consolidator.js +318 -0
- package/dist/node_modules/@boombot/core/memory/consolidation/index.d.ts +12 -0
- package/dist/node_modules/@boombot/core/memory/consolidation/index.js +12 -0
- package/dist/node_modules/@boombot/core/memory/curation.d.ts +86 -0
- package/dist/node_modules/@boombot/core/memory/curation.js +120 -0
- package/dist/node_modules/@boombot/core/memory/errors.d.ts +12 -0
- package/dist/node_modules/@boombot/core/memory/errors.js +20 -0
- package/dist/node_modules/@boombot/core/memory/hybrid-search.d.ts +29 -0
- package/dist/node_modules/@boombot/core/memory/hybrid-search.js +52 -0
- package/dist/node_modules/@boombot/core/memory/index.d.ts +23 -0
- package/dist/node_modules/@boombot/core/memory/index.js +23 -0
- package/dist/node_modules/@boombot/core/memory/indexer.d.ts +47 -0
- package/dist/node_modules/@boombot/core/memory/indexer.js +138 -0
- package/dist/node_modules/@boombot/core/memory/lifecycle.d.ts +12 -0
- package/dist/node_modules/@boombot/core/memory/lifecycle.js +66 -0
- package/dist/node_modules/@boombot/core/memory/provider.d.ts +84 -0
- package/dist/node_modules/@boombot/core/memory/provider.js +117 -0
- package/dist/node_modules/@boombot/core/memory/recall.d.ts +7 -0
- package/dist/node_modules/@boombot/core/memory/recall.js +111 -0
- package/dist/node_modules/@boombot/core/memory/scope-resolver.d.ts +27 -0
- package/dist/node_modules/@boombot/core/memory/scope-resolver.js +60 -0
- package/dist/node_modules/@boombot/core/memory/search.d.ts +37 -0
- package/dist/node_modules/@boombot/core/memory/search.js +158 -0
- package/dist/node_modules/@boombot/core/memory/store.d.ts +60 -0
- package/dist/node_modules/@boombot/core/memory/store.js +289 -0
- package/dist/node_modules/@boombot/core/memory/types.d.ts +121 -0
- package/dist/node_modules/@boombot/core/memory/types.js +21 -0
- package/dist/node_modules/@boombot/core/memory/vector-index.d.ts +34 -0
- package/dist/node_modules/@boombot/core/memory/vector-index.js +65 -0
- package/dist/node_modules/@boombot/core/package.json +9 -0
- package/dist/node_modules/@boombot/core/reflection/classifier.d.ts +13 -0
- package/dist/node_modules/@boombot/core/reflection/classifier.js +77 -0
- package/dist/node_modules/@boombot/core/reflection/index.d.ts +2 -0
- package/dist/node_modules/@boombot/core/reflection/index.js +2 -0
- package/dist/node_modules/@boombot/core/reflection/types.d.ts +13 -0
- package/dist/node_modules/@boombot/core/reflection/types.js +4 -0
- package/dist/node_modules/@boombot/core/research/config.d.ts +89 -0
- package/dist/node_modules/@boombot/core/research/config.js +206 -0
- package/dist/node_modules/@boombot/core/research/crawl.d.ts +36 -0
- package/dist/node_modules/@boombot/core/research/crawl.js +179 -0
- package/dist/node_modules/@boombot/core/research/factory.d.ts +26 -0
- package/dist/node_modules/@boombot/core/research/factory.js +46 -0
- package/dist/node_modules/@boombot/core/research/http.d.ts +87 -0
- package/dist/node_modules/@boombot/core/research/http.js +250 -0
- package/dist/node_modules/@boombot/core/research/index.d.ts +17 -0
- package/dist/node_modules/@boombot/core/research/index.js +10 -0
- package/dist/node_modules/@boombot/core/research/orchestrator.d.ts +113 -0
- package/dist/node_modules/@boombot/core/research/orchestrator.js +252 -0
- package/dist/node_modules/@boombot/core/research/parse/docx.d.ts +24 -0
- package/dist/node_modules/@boombot/core/research/parse/docx.js +183 -0
- package/dist/node_modules/@boombot/core/research/parse/guards.d.ts +89 -0
- package/dist/node_modules/@boombot/core/research/parse/guards.js +171 -0
- package/dist/node_modules/@boombot/core/research/parse/index.d.ts +68 -0
- package/dist/node_modules/@boombot/core/research/parse/index.js +219 -0
- package/dist/node_modules/@boombot/core/research/parse/pdf.d.ts +38 -0
- package/dist/node_modules/@boombot/core/research/parse/pdf.js +567 -0
- package/dist/node_modules/@boombot/core/research/providers/arxiv.d.ts +9 -0
- package/dist/node_modules/@boombot/core/research/providers/arxiv.js +72 -0
- package/dist/node_modules/@boombot/core/research/providers/brave.d.ts +11 -0
- package/dist/node_modules/@boombot/core/research/providers/brave.js +36 -0
- package/dist/node_modules/@boombot/core/research/providers/duckduckgo.d.ts +9 -0
- package/dist/node_modules/@boombot/core/research/providers/duckduckgo.js +78 -0
- package/dist/node_modules/@boombot/core/research/providers/exa.d.ts +11 -0
- package/dist/node_modules/@boombot/core/research/providers/exa.js +34 -0
- package/dist/node_modules/@boombot/core/research/providers/firecrawl.d.ts +16 -0
- package/dist/node_modules/@boombot/core/research/providers/firecrawl.js +47 -0
- package/dist/node_modules/@boombot/core/research/providers/index.d.ts +17 -0
- package/dist/node_modules/@boombot/core/research/providers/index.js +11 -0
- package/dist/node_modules/@boombot/core/research/providers/jina.d.ts +13 -0
- package/dist/node_modules/@boombot/core/research/providers/jina.js +114 -0
- package/dist/node_modules/@boombot/core/research/providers/openalex.d.ts +14 -0
- package/dist/node_modules/@boombot/core/research/providers/openalex.js +66 -0
- package/dist/node_modules/@boombot/core/research/providers/semantic-scholar.d.ts +9 -0
- package/dist/node_modules/@boombot/core/research/providers/semantic-scholar.js +56 -0
- package/dist/node_modules/@boombot/core/research/providers/tavily.d.ts +11 -0
- package/dist/node_modules/@boombot/core/research/providers/tavily.js +35 -0
- package/dist/node_modules/@boombot/core/research/providers/wikipedia.d.ts +12 -0
- package/dist/node_modules/@boombot/core/research/providers/wikipedia.js +47 -0
- package/dist/node_modules/@boombot/core/research/tools.d.ts +27 -0
- package/dist/node_modules/@boombot/core/research/tools.js +251 -0
- package/dist/node_modules/@boombot/core/research/types.d.ts +133 -0
- package/dist/node_modules/@boombot/core/research/types.js +8 -0
- package/dist/node_modules/@boombot/core/research/wiring.d.ts +25 -0
- package/dist/node_modules/@boombot/core/research/wiring.js +51 -0
- package/dist/node_modules/@boombot/core/scheduler/cron.d.ts +34 -0
- package/dist/node_modules/@boombot/core/scheduler/cron.js +147 -0
- package/dist/node_modules/@boombot/core/scheduler/evaluator.d.ts +42 -0
- package/dist/node_modules/@boombot/core/scheduler/evaluator.js +148 -0
- package/dist/node_modules/@boombot/core/scheduler/index.d.ts +15 -0
- package/dist/node_modules/@boombot/core/scheduler/index.js +15 -0
- package/dist/node_modules/@boombot/core/scheduler/registry.d.ts +81 -0
- package/dist/node_modules/@boombot/core/scheduler/registry.js +263 -0
- package/dist/node_modules/@boombot/core/scheduler/runner.d.ts +59 -0
- package/dist/node_modules/@boombot/core/scheduler/runner.js +257 -0
- package/dist/node_modules/@boombot/core/scheduler/store.d.ts +150 -0
- package/dist/node_modules/@boombot/core/scheduler/store.js +526 -0
- package/dist/node_modules/@boombot/core/scheduler/timezone.d.ts +35 -0
- package/dist/node_modules/@boombot/core/scheduler/timezone.js +96 -0
- package/dist/node_modules/@boombot/core/scheduler/types.d.ts +157 -0
- package/dist/node_modules/@boombot/core/scheduler/types.js +89 -0
- package/dist/node_modules/@boombot/core/task-runner/index.d.ts +7 -0
- package/dist/node_modules/@boombot/core/task-runner/index.js +5 -0
- package/dist/node_modules/@boombot/core/task-runner/planner.d.ts +37 -0
- package/dist/node_modules/@boombot/core/task-runner/planner.js +154 -0
- package/dist/node_modules/@boombot/core/task-runner/runner.d.ts +8 -0
- package/dist/node_modules/@boombot/core/task-runner/runner.js +564 -0
- package/dist/node_modules/@boombot/core/task-runner/store.d.ts +28 -0
- package/dist/node_modules/@boombot/core/task-runner/store.js +126 -0
- package/dist/node_modules/@boombot/core/task-runner/types.d.ts +138 -0
- package/dist/node_modules/@boombot/core/task-runner/types.js +11 -0
- package/dist/node_modules/@boombot/core/workflow/dag.d.ts +16 -0
- package/dist/node_modules/@boombot/core/workflow/dag.js +109 -0
- package/dist/node_modules/@boombot/core/workflow/engine.d.ts +34 -0
- package/dist/node_modules/@boombot/core/workflow/engine.js +304 -0
- package/dist/node_modules/@boombot/core/workflow/index.d.ts +3 -0
- package/dist/node_modules/@boombot/core/workflow/index.js +3 -0
- package/dist/node_modules/@boombot/core/workflow/types.d.ts +98 -0
- package/dist/node_modules/@boombot/core/workflow/types.js +21 -0
- package/dist/node_modules/@boombot/cronjobs/handlers.d.ts +11 -0
- package/dist/node_modules/@boombot/cronjobs/handlers.js +174 -0
- package/dist/node_modules/@boombot/cronjobs/index.d.ts +2 -0
- package/dist/node_modules/@boombot/cronjobs/index.js +2 -0
- package/dist/node_modules/@boombot/cronjobs/package.json +9 -0
- package/dist/node_modules/@boombot/cronjobs/service.d.ts +53 -0
- package/dist/node_modules/@boombot/cronjobs/service.js +200 -0
- package/dist/node_modules/@boombot/plugins/index.d.ts +2 -0
- package/dist/node_modules/@boombot/plugins/index.js +2 -0
- package/dist/node_modules/@boombot/plugins/installer.d.ts +45 -0
- package/dist/node_modules/@boombot/plugins/installer.js +487 -0
- package/dist/node_modules/@boombot/plugins/manager.d.ts +23 -0
- package/dist/node_modules/@boombot/plugins/manager.js +243 -0
- package/dist/node_modules/@boombot/plugins/package.json +9 -0
- package/dist/node_modules/@boombot/protocol/gateway-protocol/commands-channels.d.ts +125 -0
- package/dist/node_modules/@boombot/protocol/gateway-protocol/commands-channels.js +76 -0
- package/dist/node_modules/@boombot/protocol/gateway-protocol/commands-plugins.d.ts +220 -0
- package/dist/node_modules/@boombot/protocol/gateway-protocol/commands-plugins.js +60 -0
- package/dist/node_modules/@boombot/protocol/gateway-protocol/commands-scheduler.d.ts +33 -0
- package/dist/node_modules/@boombot/protocol/gateway-protocol/commands-scheduler.js +25 -0
- package/dist/node_modules/@boombot/protocol/gateway-protocol/commands.d.ts +4349 -0
- package/dist/node_modules/@boombot/protocol/gateway-protocol/commands.js +563 -0
- package/dist/node_modules/@boombot/protocol/gateway-protocol/envelope.d.ts +32 -0
- package/dist/node_modules/@boombot/protocol/gateway-protocol/envelope.js +61 -0
- package/dist/node_modules/@boombot/protocol/gateway-protocol/errors.d.ts +13 -0
- package/dist/node_modules/@boombot/protocol/gateway-protocol/errors.js +16 -0
- package/dist/node_modules/@boombot/protocol/gateway-protocol/events.d.ts +567 -0
- package/dist/node_modules/@boombot/protocol/gateway-protocol/events.js +395 -0
- package/dist/node_modules/@boombot/protocol/gateway-protocol/index.d.ts +20 -0
- package/dist/node_modules/@boombot/protocol/gateway-protocol/index.js +13 -0
- package/dist/node_modules/@boombot/protocol/gateway-protocol/types.d.ts +91 -0
- package/dist/node_modules/@boombot/protocol/gateway-protocol/types.js +7 -0
- package/dist/node_modules/@boombot/protocol/index.d.ts +4 -0
- package/dist/node_modules/@boombot/protocol/index.js +3 -0
- package/dist/node_modules/@boombot/protocol/package.json +9 -0
- package/dist/node_modules/@boombot/protocol/plugin-sdk/channel.d.ts +41 -0
- package/dist/node_modules/@boombot/protocol/plugin-sdk/channel.js +17 -0
- package/dist/node_modules/@boombot/protocol/plugin-sdk/index.d.ts +10 -0
- package/dist/node_modules/@boombot/protocol/plugin-sdk/index.js +10 -0
- package/dist/node_modules/@boombot/protocol/plugin-sdk/manifest.d.ts +58 -0
- package/dist/node_modules/@boombot/protocol/plugin-sdk/manifest.js +116 -0
- package/dist/node_modules/@boombot/protocol/plugin-sdk/plugin.d.ts +25 -0
- package/dist/node_modules/@boombot/protocol/plugin-sdk/plugin.js +1 -0
- package/dist/node_modules/@boombot/protocol/providers/cipher.d.ts +7 -0
- package/dist/node_modules/@boombot/protocol/providers/cipher.js +52 -0
- package/dist/node_modules/@boombot/protocol/providers/index.d.ts +19 -0
- package/dist/node_modules/@boombot/protocol/providers/index.js +19 -0
- package/dist/node_modules/@boombot/protocol/providers/key-roulette.d.ts +79 -0
- package/dist/node_modules/@boombot/protocol/providers/key-roulette.js +81 -0
- package/dist/node_modules/@boombot/protocol/providers/probe.d.ts +29 -0
- package/dist/node_modules/@boombot/protocol/providers/probe.js +96 -0
- package/dist/node_modules/@boombot/protocol/providers/profiles/anthropic.d.ts +11 -0
- package/dist/node_modules/@boombot/protocol/providers/profiles/anthropic.js +11 -0
- package/dist/node_modules/@boombot/protocol/providers/profiles/custom.d.ts +22 -0
- package/dist/node_modules/@boombot/protocol/providers/profiles/custom.js +222 -0
- package/dist/node_modules/@boombot/protocol/providers/profiles/deepseek.d.ts +7 -0
- package/dist/node_modules/@boombot/protocol/providers/profiles/deepseek.js +9 -0
- package/dist/node_modules/@boombot/protocol/providers/profiles/google.d.ts +10 -0
- package/dist/node_modules/@boombot/protocol/providers/profiles/google.js +10 -0
- package/dist/node_modules/@boombot/protocol/providers/profiles/index.d.ts +31 -0
- package/dist/node_modules/@boombot/protocol/providers/profiles/index.js +56 -0
- package/dist/node_modules/@boombot/protocol/providers/profiles/local.d.ts +10 -0
- package/dist/node_modules/@boombot/protocol/providers/profiles/local.js +11 -0
- package/dist/node_modules/@boombot/protocol/providers/profiles/mistral.d.ts +7 -0
- package/dist/node_modules/@boombot/protocol/providers/profiles/mistral.js +9 -0
- package/dist/node_modules/@boombot/protocol/providers/profiles/openai-compatible.d.ts +10 -0
- package/dist/node_modules/@boombot/protocol/providers/profiles/openai-compatible.js +10 -0
- package/dist/node_modules/@boombot/protocol/providers/profiles/openai.d.ts +7 -0
- package/dist/node_modules/@boombot/protocol/providers/profiles/openai.js +11 -0
- package/dist/node_modules/@boombot/protocol/providers/profiles/types.d.ts +58 -0
- package/dist/node_modules/@boombot/protocol/providers/profiles/types.js +1 -0
- package/dist/node_modules/@boombot/protocol/providers/profiles/xai.d.ts +7 -0
- package/dist/node_modules/@boombot/protocol/providers/profiles/xai.js +10 -0
- package/dist/node_modules/@boombot/protocol/providers/request-profile.d.ts +102 -0
- package/dist/node_modules/@boombot/protocol/providers/request-profile.js +118 -0
- package/dist/node_modules/@boombot/protocol/providers/service.d.ts +2 -0
- package/dist/node_modules/@boombot/protocol/providers/service.js +418 -0
- package/dist/node_modules/@boombot/protocol/providers/types.d.ts +141 -0
- package/dist/node_modules/@boombot/protocol/providers/types.js +16 -0
- package/dist/node_modules/@boombot/sandbox/fs-path.d.ts +13 -0
- package/dist/node_modules/@boombot/sandbox/fs-path.js +79 -0
- package/dist/node_modules/@boombot/sandbox/index.d.ts +13 -0
- package/dist/node_modules/@boombot/sandbox/index.js +13 -0
- package/dist/node_modules/@boombot/sandbox/native.d.ts +39 -0
- package/dist/node_modules/@boombot/sandbox/native.js +224 -0
- package/dist/node_modules/@boombot/sandbox/package.json +9 -0
- package/dist/node_modules/@boombot/sandbox/sandbox.d.ts +92 -0
- package/dist/node_modules/@boombot/sandbox/sandbox.js +229 -0
- package/dist/node_modules/@boombot/security/harness-guard/boundary.d.ts +22 -0
- package/dist/node_modules/@boombot/security/harness-guard/boundary.js +105 -0
- package/dist/node_modules/@boombot/security/harness-guard/gates.d.ts +90 -0
- package/dist/node_modules/@boombot/security/harness-guard/gates.js +791 -0
- package/dist/node_modules/@boombot/security/harness-guard/index.d.ts +23 -0
- package/dist/node_modules/@boombot/security/harness-guard/index.js +23 -0
- package/dist/node_modules/@boombot/security/harness-guard/policy.d.ts +20 -0
- package/dist/node_modules/@boombot/security/harness-guard/policy.js +70 -0
- package/dist/node_modules/@boombot/security/harness-guard/sanitizer.d.ts +53 -0
- package/dist/node_modules/@boombot/security/harness-guard/sanitizer.js +145 -0
- package/dist/node_modules/@boombot/security/harness-guard/types.d.ts +71 -0
- package/dist/node_modules/@boombot/security/harness-guard/types.js +10 -0
- package/dist/node_modules/@boombot/security/harness-guard/verifier.d.ts +59 -0
- package/dist/node_modules/@boombot/security/harness-guard/verifier.js +169 -0
- package/dist/node_modules/@boombot/security/index.d.ts +5 -0
- package/dist/node_modules/@boombot/security/index.js +9 -0
- package/dist/node_modules/@boombot/security/package.json +9 -0
- package/dist/node_modules/@boombot/security/policy/approval.d.ts +117 -0
- package/dist/node_modules/@boombot/security/policy/approval.js +223 -0
- package/dist/node_modules/@boombot/security/reasoning-guard/claim-extractor.d.ts +10 -0
- package/dist/node_modules/@boombot/security/reasoning-guard/claim-extractor.js +124 -0
- package/dist/node_modules/@boombot/security/reasoning-guard/evidence-ledger.d.ts +25 -0
- package/dist/node_modules/@boombot/security/reasoning-guard/evidence-ledger.js +70 -0
- package/dist/node_modules/@boombot/security/reasoning-guard/gate.d.ts +38 -0
- package/dist/node_modules/@boombot/security/reasoning-guard/gate.js +61 -0
- package/dist/node_modules/@boombot/security/reasoning-guard/grounding-check.d.ts +12 -0
- package/dist/node_modules/@boombot/security/reasoning-guard/grounding-check.js +234 -0
- package/dist/node_modules/@boombot/security/reasoning-guard/index.d.ts +17 -0
- package/dist/node_modules/@boombot/security/reasoning-guard/index.js +13 -0
- package/dist/node_modules/@boombot/security/reasoning-guard/policy.d.ts +15 -0
- package/dist/node_modules/@boombot/security/reasoning-guard/policy.js +39 -0
- package/dist/node_modules/@boombot/security/reasoning-guard/types.d.ts +46 -0
- package/dist/node_modules/@boombot/security/reasoning-guard/types.js +7 -0
- package/dist/node_modules/@boombot/security/security/approval.d.ts +63 -0
- package/dist/node_modules/@boombot/security/security/approval.js +140 -0
- package/dist/node_modules/@boombot/security/security/audit.d.ts +39 -0
- package/dist/node_modules/@boombot/security/security/audit.js +70 -0
- package/dist/node_modules/@boombot/security/security/index.d.ts +12 -0
- package/dist/node_modules/@boombot/security/security/index.js +12 -0
- package/dist/node_modules/@boombot/security/security/trust.d.ts +79 -0
- package/dist/node_modules/@boombot/security/security/trust.js +87 -0
- package/dist/package.json +5 -0
- package/dist/proto/agent_core.proto +56 -0
- package/dist/python/agent-core-python/pyproject.toml +40 -0
- package/dist/python/agent-core-python/src/boombot_agent/__init__.py +5 -0
- package/dist/python/agent-core-python/src/boombot_agent/generated/__init__.py +0 -0
- package/dist/python/agent-core-python/src/boombot_agent/generated/agent_core_pb2.py +54 -0
- package/dist/python/agent-core-python/src/boombot_agent/generated/agent_core_pb2_grpc.py +140 -0
- package/dist/python/agent-core-python/src/boombot_agent/rpc.py +265 -0
- package/dist/python/agent-core-python/src/boombot_agent/turn.py +577 -0
- package/dist/python/agent-core-python/src/boombot_ml/__init__.py +12 -0
- package/dist/python/agent-core-python/src/boombot_ml/embeddings.py +58 -0
- package/dist/python/agent-core-python/src/boombot_ml/training.py +156 -0
- package/dist/python/agent-core-python/uv.lock +2856 -0
- package/dist/web/assets/ChatView-BZrSD-64.js +262 -0
- package/dist/web/assets/ChatView-Cahbjez6.css +1 -0
- package/dist/web/assets/KaTeX_AMS-Regular-BQhdFMY1.woff2 +0 -0
- package/dist/web/assets/KaTeX_AMS-Regular-DMm9YOAa.woff +0 -0
- package/dist/web/assets/KaTeX_AMS-Regular-DRggAlZN.ttf +0 -0
- package/dist/web/assets/KaTeX_Caligraphic-Bold-ATXxdsX0.ttf +0 -0
- package/dist/web/assets/KaTeX_Caligraphic-Bold-BEiXGLvX.woff +0 -0
- package/dist/web/assets/KaTeX_Caligraphic-Bold-Dq_IR9rO.woff2 +0 -0
- package/dist/web/assets/KaTeX_Caligraphic-Regular-CTRA-rTL.woff +0 -0
- package/dist/web/assets/KaTeX_Caligraphic-Regular-Di6jR-x-.woff2 +0 -0
- package/dist/web/assets/KaTeX_Caligraphic-Regular-wX97UBjC.ttf +0 -0
- package/dist/web/assets/KaTeX_Fraktur-Bold-BdnERNNW.ttf +0 -0
- package/dist/web/assets/KaTeX_Fraktur-Bold-BsDP51OF.woff +0 -0
- package/dist/web/assets/KaTeX_Fraktur-Bold-CL6g_b3V.woff2 +0 -0
- package/dist/web/assets/KaTeX_Fraktur-Regular-CB_wures.ttf +0 -0
- package/dist/web/assets/KaTeX_Fraktur-Regular-CTYiF6lA.woff2 +0 -0
- package/dist/web/assets/KaTeX_Fraktur-Regular-Dxdc4cR9.woff +0 -0
- package/dist/web/assets/KaTeX_Main-Bold-Cx986IdX.woff2 +0 -0
- package/dist/web/assets/KaTeX_Main-Bold-Jm3AIy58.woff +0 -0
- package/dist/web/assets/KaTeX_Main-Bold-waoOVXN0.ttf +0 -0
- package/dist/web/assets/KaTeX_Main-BoldItalic-DxDJ3AOS.woff2 +0 -0
- package/dist/web/assets/KaTeX_Main-BoldItalic-DzxPMmG6.ttf +0 -0
- package/dist/web/assets/KaTeX_Main-BoldItalic-SpSLRI95.woff +0 -0
- package/dist/web/assets/KaTeX_Main-Italic-3WenGoN9.ttf +0 -0
- package/dist/web/assets/KaTeX_Main-Italic-BMLOBm91.woff +0 -0
- package/dist/web/assets/KaTeX_Main-Italic-NWA7e6Wa.woff2 +0 -0
- package/dist/web/assets/KaTeX_Main-Regular-B22Nviop.woff2 +0 -0
- package/dist/web/assets/KaTeX_Main-Regular-Dr94JaBh.woff +0 -0
- package/dist/web/assets/KaTeX_Main-Regular-ypZvNtVU.ttf +0 -0
- package/dist/web/assets/KaTeX_Math-BoldItalic-B3XSjfu4.ttf +0 -0
- package/dist/web/assets/KaTeX_Math-BoldItalic-CZnvNsCZ.woff2 +0 -0
- package/dist/web/assets/KaTeX_Math-BoldItalic-iY-2wyZ7.woff +0 -0
- package/dist/web/assets/KaTeX_Math-Italic-DA0__PXp.woff +0 -0
- package/dist/web/assets/KaTeX_Math-Italic-flOr_0UB.ttf +0 -0
- package/dist/web/assets/KaTeX_Math-Italic-t53AETM-.woff2 +0 -0
- package/dist/web/assets/KaTeX_SansSerif-Bold-CFMepnvq.ttf +0 -0
- package/dist/web/assets/KaTeX_SansSerif-Bold-D1sUS0GD.woff2 +0 -0
- package/dist/web/assets/KaTeX_SansSerif-Bold-DbIhKOiC.woff +0 -0
- package/dist/web/assets/KaTeX_SansSerif-Italic-C3H0VqGB.woff2 +0 -0
- package/dist/web/assets/KaTeX_SansSerif-Italic-DN2j7dab.woff +0 -0
- package/dist/web/assets/KaTeX_SansSerif-Italic-YYjJ1zSn.ttf +0 -0
- package/dist/web/assets/KaTeX_SansSerif-Regular-BNo7hRIc.ttf +0 -0
- package/dist/web/assets/KaTeX_SansSerif-Regular-CS6fqUqJ.woff +0 -0
- package/dist/web/assets/KaTeX_SansSerif-Regular-DDBCnlJ7.woff2 +0 -0
- package/dist/web/assets/KaTeX_Script-Regular-C5JkGWo-.ttf +0 -0
- package/dist/web/assets/KaTeX_Script-Regular-D3wIWfF6.woff2 +0 -0
- package/dist/web/assets/KaTeX_Script-Regular-D5yQViql.woff +0 -0
- package/dist/web/assets/KaTeX_Size1-Regular-C195tn64.woff +0 -0
- package/dist/web/assets/KaTeX_Size1-Regular-Dbsnue_I.ttf +0 -0
- package/dist/web/assets/KaTeX_Size1-Regular-mCD8mA8B.woff2 +0 -0
- package/dist/web/assets/KaTeX_Size2-Regular-B7gKUWhC.ttf +0 -0
- package/dist/web/assets/KaTeX_Size2-Regular-Dy4dx90m.woff2 +0 -0
- package/dist/web/assets/KaTeX_Size2-Regular-oD1tc_U0.woff +0 -0
- package/dist/web/assets/KaTeX_Size3-Regular-CTq5MqoE.woff +0 -0
- package/dist/web/assets/KaTeX_Size3-Regular-DgpXs0kz.ttf +0 -0
- package/dist/web/assets/KaTeX_Size4-Regular-BF-4gkZK.woff +0 -0
- package/dist/web/assets/KaTeX_Size4-Regular-DWFBv043.ttf +0 -0
- package/dist/web/assets/KaTeX_Size4-Regular-Dl5lxZxV.woff2 +0 -0
- package/dist/web/assets/KaTeX_Typewriter-Regular-C0xS9mPB.woff +0 -0
- package/dist/web/assets/KaTeX_Typewriter-Regular-CO6r4hn1.woff2 +0 -0
- package/dist/web/assets/KaTeX_Typewriter-Regular-D3Ib7_Hf.ttf +0 -0
- package/dist/web/assets/MemoryView-BJbXqqs7.css +1 -0
- package/dist/web/assets/MemoryView-BfMq_6CD.js +1 -0
- package/dist/web/assets/SchedulesView-B22QmPR-.js +1 -0
- package/dist/web/assets/SchedulesView-C6XK7A8a.css +1 -0
- package/dist/web/assets/SessionsView-C1dqdhxI.css +1 -0
- package/dist/web/assets/SessionsView-DS0-aH2a.js +1 -0
- package/dist/web/assets/TasksView-Dtasg4hd.css +1 -0
- package/dist/web/assets/TasksView-ey0FLsW8.js +2 -0
- package/dist/web/assets/Textarea-DN3Zybl1.js +1 -0
- package/dist/web/assets/Tooltip-Bn2cqFPz.css +1 -0
- package/dist/web/assets/Tooltip-MzV2Gqnc.js +1 -0
- package/dist/web/assets/browser-Bnt73-Ub.js +8 -0
- package/dist/web/assets/index-BL8bi7Yt.css +1 -0
- package/dist/web/assets/index-CuPR73Tn.js +73 -0
- package/dist/web/favicon.svg +4 -0
- package/dist/web/index.html +26 -0
- package/dist/web/logo.jpg +0 -0
- package/dist/web/logo.png +0 -0
- package/package.json +51 -4
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import { createHmac, timingSafeEqual } from 'node:crypto';
|
|
2
|
+
import {} from '../common/index.js';
|
|
3
|
+
import { MessageDeduplicator } from '../common/index.js';
|
|
4
|
+
const GRAPH_API_BASE = 'https://graph.facebook.com/v22.0';
|
|
5
|
+
const MAX_TEXT_LENGTH = 4096;
|
|
6
|
+
export class WhatsAppTransport {
|
|
7
|
+
kind = 'whatsapp';
|
|
8
|
+
displayName = 'WhatsApp';
|
|
9
|
+
enabled;
|
|
10
|
+
phoneNumberId;
|
|
11
|
+
accessToken;
|
|
12
|
+
verifyToken;
|
|
13
|
+
appSecret;
|
|
14
|
+
allowlist;
|
|
15
|
+
log;
|
|
16
|
+
turnService;
|
|
17
|
+
subscribeTurnDone;
|
|
18
|
+
pendingReplies = new Map();
|
|
19
|
+
deduplicator = new MessageDeduplicator();
|
|
20
|
+
unsubscribeTurnDone;
|
|
21
|
+
status = 'disconnected';
|
|
22
|
+
statusDetail = 'NOT_CONFIGURED';
|
|
23
|
+
constructor(config, log, inbound = {}) {
|
|
24
|
+
this.enabled = config.enabled !== false;
|
|
25
|
+
this.phoneNumberId = config.phoneNumberId?.trim() || undefined;
|
|
26
|
+
this.accessToken = config.accessToken?.trim() || undefined;
|
|
27
|
+
this.verifyToken = config.verifyToken?.trim() || undefined;
|
|
28
|
+
this.appSecret = config.appSecret?.trim() || undefined;
|
|
29
|
+
this.allowlist = new Set(config.allowlistChatIds ?? []);
|
|
30
|
+
this.log = log;
|
|
31
|
+
this.turnService = inbound.turnService;
|
|
32
|
+
this.subscribeTurnDone = inbound.subscribeTurnDone;
|
|
33
|
+
}
|
|
34
|
+
async start() {
|
|
35
|
+
if (!this.enabled) {
|
|
36
|
+
this.statusDetail = 'DISABLED';
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
this.unsubscribeTurnDone ??= this.subscribeTurnDone?.((payload) => this.onTurnDone(payload));
|
|
40
|
+
if (this.phoneNumberId === undefined || this.accessToken === undefined) {
|
|
41
|
+
this.statusDetail = 'NOT_CONFIGURED';
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
try {
|
|
45
|
+
const response = await fetch(`${GRAPH_API_BASE}/${this.phoneNumberId}?fields=id`, {
|
|
46
|
+
headers: { authorization: `Bearer ${this.accessToken}` },
|
|
47
|
+
signal: AbortSignal.timeout(15_000),
|
|
48
|
+
});
|
|
49
|
+
const data = (await response.json());
|
|
50
|
+
if (data.error !== undefined)
|
|
51
|
+
throw new Error(data.error.message ?? 'credential check failed');
|
|
52
|
+
this.status = 'connected';
|
|
53
|
+
this.statusDetail = undefined;
|
|
54
|
+
this.log.info('whatsapp: connected');
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
this.status = 'error';
|
|
58
|
+
this.statusDetail = error instanceof Error ? error.message : 'CONNECT_FAILED';
|
|
59
|
+
this.log.error('whatsapp: credential check failed', { detail: this.statusDetail });
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
async stop() {
|
|
63
|
+
this.unsubscribeTurnDone?.();
|
|
64
|
+
this.unsubscribeTurnDone = undefined;
|
|
65
|
+
this.pendingReplies.clear();
|
|
66
|
+
if (this.status === 'connected') {
|
|
67
|
+
this.status = 'disconnected';
|
|
68
|
+
this.statusDetail = 'STOPPED';
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
getStatus() {
|
|
72
|
+
return this.statusDetail === undefined
|
|
73
|
+
? { status: this.status }
|
|
74
|
+
: { status: this.status, detail: this.statusDetail };
|
|
75
|
+
}
|
|
76
|
+
async handleWebhook(request) {
|
|
77
|
+
if (!this.enabled)
|
|
78
|
+
return { status: 503 };
|
|
79
|
+
if (request.method === 'GET') {
|
|
80
|
+
const valid = request.query.get('hub.mode') === 'subscribe'
|
|
81
|
+
&& this.verifyToken !== undefined
|
|
82
|
+
&& request.query.get('hub.verify_token') === this.verifyToken;
|
|
83
|
+
return valid
|
|
84
|
+
? { status: 200, contentType: 'text/plain; charset=utf-8', body: request.query.get('hub.challenge') ?? '' }
|
|
85
|
+
: { status: 401 };
|
|
86
|
+
}
|
|
87
|
+
if (this.appSecret === undefined ||
|
|
88
|
+
this.phoneNumberId === undefined ||
|
|
89
|
+
this.accessToken === undefined)
|
|
90
|
+
return { status: 503 };
|
|
91
|
+
const signatureValue = request.headers['x-hub-signature-256'];
|
|
92
|
+
const signature = typeof signatureValue === 'string' ? signatureValue : (signatureValue?.[0] ?? '');
|
|
93
|
+
const expected = `sha256=${createHmac('sha256', this.appSecret).update(request.rawBody).digest('hex')}`;
|
|
94
|
+
const actualBytes = Buffer.from(signature);
|
|
95
|
+
const expectedBytes = Buffer.from(expected);
|
|
96
|
+
if (actualBytes.length !== expectedBytes.length || !timingSafeEqual(actualBytes, expectedBytes)) {
|
|
97
|
+
return { status: 401 };
|
|
98
|
+
}
|
|
99
|
+
let body;
|
|
100
|
+
try {
|
|
101
|
+
body = JSON.parse(request.rawBody.toString('utf8'));
|
|
102
|
+
}
|
|
103
|
+
catch {
|
|
104
|
+
return { status: 400 };
|
|
105
|
+
}
|
|
106
|
+
for (const message of extractMessages(body)) {
|
|
107
|
+
if (message.type !== 'text' ||
|
|
108
|
+
message.text?.body?.trim() === '' ||
|
|
109
|
+
!this.allowlist.has(message.from) ||
|
|
110
|
+
!this.deduplicator.checkAndRecord(message.id) ||
|
|
111
|
+
this.turnService === undefined)
|
|
112
|
+
continue;
|
|
113
|
+
try {
|
|
114
|
+
const result = await this.turnService.submit({
|
|
115
|
+
input: message.text?.body ?? '',
|
|
116
|
+
channel: 'whatsapp',
|
|
117
|
+
replyTo: message.from,
|
|
118
|
+
});
|
|
119
|
+
this.pendingReplies.set(result.turnId, message.from);
|
|
120
|
+
}
|
|
121
|
+
catch (error) {
|
|
122
|
+
this.log.error('whatsapp: submit failed', {
|
|
123
|
+
error: error instanceof Error ? error.message : String(error),
|
|
124
|
+
});
|
|
125
|
+
return { status: 500 };
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return { status: 200 };
|
|
129
|
+
}
|
|
130
|
+
async send(target, text) {
|
|
131
|
+
if (this.phoneNumberId === undefined || this.accessToken === undefined) {
|
|
132
|
+
throw new Error('NOT_CONFIGURED: whatsapp phoneNumberId/accessToken missing');
|
|
133
|
+
}
|
|
134
|
+
const to = target.trim();
|
|
135
|
+
if (to === '' || text.trim() === '')
|
|
136
|
+
throw new Error('INVALID_ARGUMENT: target/text empty');
|
|
137
|
+
const points = Array.from(text);
|
|
138
|
+
for (let index = 0; index < points.length; index += MAX_TEXT_LENGTH) {
|
|
139
|
+
const response = await fetch(`${GRAPH_API_BASE}/${this.phoneNumberId}/messages`, {
|
|
140
|
+
method: 'POST',
|
|
141
|
+
headers: { authorization: `Bearer ${this.accessToken}`, 'content-type': 'application/json' },
|
|
142
|
+
body: JSON.stringify({
|
|
143
|
+
messaging_product: 'whatsapp',
|
|
144
|
+
to,
|
|
145
|
+
type: 'text',
|
|
146
|
+
text: { body: points.slice(index, index + MAX_TEXT_LENGTH).join('') },
|
|
147
|
+
}),
|
|
148
|
+
signal: AbortSignal.timeout(15_000),
|
|
149
|
+
});
|
|
150
|
+
const data = (await response.json());
|
|
151
|
+
if (data.error !== undefined)
|
|
152
|
+
throw new Error(`SEND_FAILED: ${data.error.message ?? 'unknown error'}`);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
onTurnDone(payload) {
|
|
156
|
+
const target = this.pendingReplies.get(payload.turnId)
|
|
157
|
+
?? (payload.channel === 'whatsapp' ? payload.replyTo : undefined);
|
|
158
|
+
if (target === undefined)
|
|
159
|
+
return;
|
|
160
|
+
this.pendingReplies.delete(payload.turnId);
|
|
161
|
+
void this.send(target, payload.status === 'completed'
|
|
162
|
+
? (payload.output?.trim() || '(empty response)')
|
|
163
|
+
: `Turn failed${payload.error ? `: ${payload.error}` : ''}.`).catch((error) => this.log.error('whatsapp: reply failed', {
|
|
164
|
+
error: error instanceof Error ? error.message : String(error),
|
|
165
|
+
}));
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
function extractMessages(value) {
|
|
169
|
+
if (!isRecord(value) || !Array.isArray(value['entry']))
|
|
170
|
+
return [];
|
|
171
|
+
const messages = [];
|
|
172
|
+
for (const entry of value['entry']) {
|
|
173
|
+
if (!isRecord(entry) || !Array.isArray(entry['changes']))
|
|
174
|
+
continue;
|
|
175
|
+
for (const change of entry['changes']) {
|
|
176
|
+
if (!isRecord(change) || !isRecord(change['value']) || !Array.isArray(change['value']['messages']))
|
|
177
|
+
continue;
|
|
178
|
+
for (const message of change['value']['messages']) {
|
|
179
|
+
if (isRecord(message) && typeof message['id'] === 'string' && typeof message['from'] === 'string') {
|
|
180
|
+
messages.push(message);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
return messages;
|
|
186
|
+
}
|
|
187
|
+
function isRecord(value) {
|
|
188
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
189
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { ChannelKind } from '@boombot/protocol';
|
|
2
|
+
import type { ChannelLogger, ChannelRuntimeStatus, ChannelTransport } from '../common/index.js';
|
|
3
|
+
export interface ZaloTransportConfig {
|
|
4
|
+
readonly enabled?: boolean;
|
|
5
|
+
readonly appId?: string;
|
|
6
|
+
readonly appSecret?: string;
|
|
7
|
+
/** Reserved for a future documented personal-Zalo bridge contract. */
|
|
8
|
+
readonly bridgeUrl?: string;
|
|
9
|
+
readonly oaToken?: string;
|
|
10
|
+
}
|
|
11
|
+
export declare class ZaloTransport implements ChannelTransport {
|
|
12
|
+
readonly kind: ChannelKind;
|
|
13
|
+
readonly displayName = "Zalo";
|
|
14
|
+
private readonly enabled;
|
|
15
|
+
private readonly bridgeUrl;
|
|
16
|
+
private readonly oaToken;
|
|
17
|
+
private readonly log;
|
|
18
|
+
private status;
|
|
19
|
+
private statusDetail;
|
|
20
|
+
constructor(config: ZaloTransportConfig, log: ChannelLogger);
|
|
21
|
+
start(): Promise<void>;
|
|
22
|
+
stop(): Promise<void>;
|
|
23
|
+
send(target: string, text: string): Promise<void>;
|
|
24
|
+
getStatus(): {
|
|
25
|
+
status: ChannelRuntimeStatus;
|
|
26
|
+
detail?: string;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
const ZALO_API_BASE = 'https://openapi.zalo.me/v3.0/oa';
|
|
2
|
+
export class ZaloTransport {
|
|
3
|
+
kind = 'zalo';
|
|
4
|
+
displayName = 'Zalo';
|
|
5
|
+
enabled;
|
|
6
|
+
bridgeUrl;
|
|
7
|
+
oaToken;
|
|
8
|
+
log;
|
|
9
|
+
status = 'disconnected';
|
|
10
|
+
statusDetail = 'NOT_CONFIGURED';
|
|
11
|
+
constructor(config, log) {
|
|
12
|
+
this.enabled = config.enabled !== false;
|
|
13
|
+
this.bridgeUrl = config.bridgeUrl?.trim() || undefined;
|
|
14
|
+
this.oaToken = config.oaToken?.trim() || undefined;
|
|
15
|
+
this.log = log;
|
|
16
|
+
}
|
|
17
|
+
async start() {
|
|
18
|
+
if (!this.enabled) {
|
|
19
|
+
this.statusDetail = 'DISABLED';
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
if (this.oaToken === undefined) {
|
|
23
|
+
this.statusDetail =
|
|
24
|
+
this.bridgeUrl === undefined ? 'NOT_CONFIGURED' : 'UNSUPPORTED_BRIDGE';
|
|
25
|
+
this.log.info(this.bridgeUrl === undefined
|
|
26
|
+
? 'zalo: missing oaToken'
|
|
27
|
+
: 'zalo: bridgeUrl is not supported without a bridge contract');
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
try {
|
|
31
|
+
const data = encodeURIComponent(JSON.stringify({ offset: 0, count: 1 }));
|
|
32
|
+
const response = await fetch(`${ZALO_API_BASE}/user/getlist?data=${data}`, {
|
|
33
|
+
headers: { access_token: this.oaToken },
|
|
34
|
+
signal: AbortSignal.timeout(15_000),
|
|
35
|
+
});
|
|
36
|
+
const body = (await response.json());
|
|
37
|
+
if (!response.ok || body.error !== 0) {
|
|
38
|
+
throw new Error(body.error === undefined ? `HTTP ${response.status}` : `API ${body.error}`);
|
|
39
|
+
}
|
|
40
|
+
this.status = 'connected';
|
|
41
|
+
this.statusDetail = undefined;
|
|
42
|
+
this.log.info('zalo: connected (OA outbound only)');
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
this.status = 'error';
|
|
46
|
+
this.statusDetail =
|
|
47
|
+
error instanceof Error ? error.message : 'CONNECT_FAILED';
|
|
48
|
+
this.log.error('zalo: credential check failed', {
|
|
49
|
+
detail: this.statusDetail,
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
async stop() {
|
|
54
|
+
if (this.status === 'connected') {
|
|
55
|
+
this.status = 'disconnected';
|
|
56
|
+
this.statusDetail = 'STOPPED';
|
|
57
|
+
}
|
|
58
|
+
this.log.info('zalo: stopped');
|
|
59
|
+
}
|
|
60
|
+
async send(target, text) {
|
|
61
|
+
if (!this.enabled)
|
|
62
|
+
throw new Error('DISABLED: zalo is disabled');
|
|
63
|
+
if (this.oaToken === undefined) {
|
|
64
|
+
throw new Error(this.bridgeUrl === undefined
|
|
65
|
+
? 'NOT_CONFIGURED: zalo missing oaToken'
|
|
66
|
+
: 'UNSUPPORTED: zalo bridgeUrl has no documented bridge contract');
|
|
67
|
+
}
|
|
68
|
+
const userId = target.trim();
|
|
69
|
+
if (userId === '' || text.trim() === '') {
|
|
70
|
+
throw new Error('INVALID_ARGUMENT: target/text must not be empty');
|
|
71
|
+
}
|
|
72
|
+
const response = await fetch(`${ZALO_API_BASE}/message/cs`, {
|
|
73
|
+
method: 'POST',
|
|
74
|
+
headers: {
|
|
75
|
+
access_token: this.oaToken,
|
|
76
|
+
'content-type': 'application/json',
|
|
77
|
+
},
|
|
78
|
+
body: JSON.stringify({
|
|
79
|
+
recipient: { user_id: userId },
|
|
80
|
+
message: { text },
|
|
81
|
+
}),
|
|
82
|
+
signal: AbortSignal.timeout(15_000),
|
|
83
|
+
});
|
|
84
|
+
const data = (await response.json().catch(() => undefined));
|
|
85
|
+
if (!response.ok || data?.error !== 0) {
|
|
86
|
+
throw new Error(`SEND_FAILED: ${data?.message ?? (data?.error === undefined ? `HTTP ${response.status}` : `API ${data.error}`)}`);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
getStatus() {
|
|
90
|
+
return this.statusDetail === undefined
|
|
91
|
+
? { status: this.status }
|
|
92
|
+
: { status: this.status, detail: this.statusDetail };
|
|
93
|
+
}
|
|
94
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import type { ChannelKind } from '@boombot/protocol';
|
|
2
|
+
import { type ChannelLogger, type ChannelRuntimeStatus, type ChannelTransport, type TurnDonePayload, type TurnSubmitter } from '../common/index.js';
|
|
3
|
+
export interface ZaloPersonalCredentials {
|
|
4
|
+
readonly imei: string;
|
|
5
|
+
readonly userAgent: string;
|
|
6
|
+
readonly language?: string;
|
|
7
|
+
readonly cookie: unknown;
|
|
8
|
+
}
|
|
9
|
+
export interface ZaloPersonalMessage {
|
|
10
|
+
readonly type: number;
|
|
11
|
+
readonly threadId: string;
|
|
12
|
+
readonly isSelf: boolean;
|
|
13
|
+
readonly data: {
|
|
14
|
+
readonly content: unknown;
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
export interface ZaloPersonalApi {
|
|
18
|
+
readonly listener: {
|
|
19
|
+
on(event: 'message', handler: (message: ZaloPersonalMessage) => void): unknown;
|
|
20
|
+
on(event: 'error', handler: (error: unknown) => void): unknown;
|
|
21
|
+
on(event: 'closed', handler: (code: number, reason: string) => void): unknown;
|
|
22
|
+
start(options: {
|
|
23
|
+
retryOnClose: boolean;
|
|
24
|
+
}): void;
|
|
25
|
+
stop(): void;
|
|
26
|
+
};
|
|
27
|
+
sendMessage(message: {
|
|
28
|
+
msg: string;
|
|
29
|
+
}, threadId: string, type: number): Promise<unknown>;
|
|
30
|
+
getGroupInfo(threadId: string): Promise<{
|
|
31
|
+
readonly gridInfoMap: Record<string, unknown>;
|
|
32
|
+
}>;
|
|
33
|
+
getContext(): {
|
|
34
|
+
imei: string;
|
|
35
|
+
userAgent: string;
|
|
36
|
+
language?: string;
|
|
37
|
+
};
|
|
38
|
+
getCookie(): {
|
|
39
|
+
serializeSync(): {
|
|
40
|
+
cookies?: unknown[];
|
|
41
|
+
} | undefined;
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
export interface ZaloQrEvent {
|
|
45
|
+
readonly type: number;
|
|
46
|
+
readonly data: {
|
|
47
|
+
readonly image: string;
|
|
48
|
+
} | null;
|
|
49
|
+
readonly actions: {
|
|
50
|
+
abort(): unknown;
|
|
51
|
+
} | null;
|
|
52
|
+
}
|
|
53
|
+
interface ZaloPersonalClient {
|
|
54
|
+
login(credentials: ZaloPersonalCredentials): Promise<ZaloPersonalApi>;
|
|
55
|
+
loginQR(options: object, callback: (event: ZaloQrEvent) => void): Promise<ZaloPersonalApi>;
|
|
56
|
+
}
|
|
57
|
+
export declare const ZALO_THREAD_USER: number;
|
|
58
|
+
export declare const ZALO_THREAD_GROUP: number;
|
|
59
|
+
export declare const ZALO_QR_EVENT: {
|
|
60
|
+
readonly QRCodeGenerated: number;
|
|
61
|
+
readonly QRCodeExpired: number;
|
|
62
|
+
readonly QRCodeDeclined: number;
|
|
63
|
+
};
|
|
64
|
+
export declare function createZaloPersonalClient(): ZaloPersonalClient;
|
|
65
|
+
export interface ZaloPersonalTransportOptions {
|
|
66
|
+
readonly credentials?: ZaloPersonalCredentials;
|
|
67
|
+
readonly api?: ZaloPersonalApi;
|
|
68
|
+
readonly dataDir: string;
|
|
69
|
+
readonly log: ChannelLogger;
|
|
70
|
+
readonly turnService?: TurnSubmitter;
|
|
71
|
+
readonly subscribeTurnDone?: (handler: (payload: TurnDonePayload) => void) => () => void;
|
|
72
|
+
}
|
|
73
|
+
export declare class ZaloPersonalTransport implements ChannelTransport {
|
|
74
|
+
readonly kind: ChannelKind;
|
|
75
|
+
readonly displayName = "Zalo Personal";
|
|
76
|
+
private api;
|
|
77
|
+
private readonly credentials;
|
|
78
|
+
private readonly log;
|
|
79
|
+
private readonly statePath;
|
|
80
|
+
private readonly turnService;
|
|
81
|
+
private readonly subscribeTurnDone;
|
|
82
|
+
private readonly allowlist;
|
|
83
|
+
private readonly pendingReplies;
|
|
84
|
+
private readonly threadTypes;
|
|
85
|
+
private pairing;
|
|
86
|
+
private status;
|
|
87
|
+
private detail;
|
|
88
|
+
private unsubscribeTurnDone;
|
|
89
|
+
constructor(options: ZaloPersonalTransportOptions);
|
|
90
|
+
start(): Promise<void>;
|
|
91
|
+
stop(): Promise<void>;
|
|
92
|
+
send(target: string, text: string): Promise<void>;
|
|
93
|
+
getStatus(): {
|
|
94
|
+
status: ChannelRuntimeStatus;
|
|
95
|
+
detail?: string;
|
|
96
|
+
};
|
|
97
|
+
createPairingCode(): string;
|
|
98
|
+
unpairThread(threadId: string): void;
|
|
99
|
+
private onMessage;
|
|
100
|
+
private onTurnDone;
|
|
101
|
+
private resolveThreadType;
|
|
102
|
+
private loadState;
|
|
103
|
+
private saveState;
|
|
104
|
+
private prunePairing;
|
|
105
|
+
}
|
|
106
|
+
export {};
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { randomInt } from 'node:crypto';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import * as zca from 'zca-js';
|
|
4
|
+
import { readJsonFile, writeJsonFile, } from '../common/index.js';
|
|
5
|
+
const PAIRING_TTL_MS = 10 * 60 * 1000;
|
|
6
|
+
const PAIRING_CODE_PATTERN = /^BOOM-\d{6}$/;
|
|
7
|
+
const runtime = zca;
|
|
8
|
+
export const ZALO_THREAD_USER = runtime.ThreadType.User;
|
|
9
|
+
export const ZALO_THREAD_GROUP = runtime.ThreadType.Group;
|
|
10
|
+
export const ZALO_QR_EVENT = runtime.LoginQRCallbackEventType;
|
|
11
|
+
export function createZaloPersonalClient() {
|
|
12
|
+
return new runtime.Zalo();
|
|
13
|
+
}
|
|
14
|
+
export class ZaloPersonalTransport {
|
|
15
|
+
kind = 'zalo';
|
|
16
|
+
displayName = 'Zalo Personal';
|
|
17
|
+
api;
|
|
18
|
+
credentials;
|
|
19
|
+
log;
|
|
20
|
+
statePath;
|
|
21
|
+
turnService;
|
|
22
|
+
subscribeTurnDone;
|
|
23
|
+
allowlist = new Set();
|
|
24
|
+
pendingReplies = new Map();
|
|
25
|
+
threadTypes = new Map();
|
|
26
|
+
pairing = [];
|
|
27
|
+
status = 'disconnected';
|
|
28
|
+
detail = 'NOT_CONFIGURED';
|
|
29
|
+
unsubscribeTurnDone;
|
|
30
|
+
constructor(options) {
|
|
31
|
+
this.api = options.api;
|
|
32
|
+
this.credentials = options.credentials;
|
|
33
|
+
this.log = options.log;
|
|
34
|
+
this.statePath = join(options.dataDir, 'channels', 'zalo-personal', 'state.json');
|
|
35
|
+
this.turnService = options.turnService;
|
|
36
|
+
this.subscribeTurnDone = options.subscribeTurnDone;
|
|
37
|
+
}
|
|
38
|
+
async start() {
|
|
39
|
+
this.loadState();
|
|
40
|
+
try {
|
|
41
|
+
this.api ??= this.credentials
|
|
42
|
+
? await createZaloPersonalClient().login(this.credentials)
|
|
43
|
+
: undefined;
|
|
44
|
+
if (!this.api)
|
|
45
|
+
throw new Error('NOT_CONFIGURED');
|
|
46
|
+
this.api.listener.on('message', (message) => {
|
|
47
|
+
void this.onMessage(message).catch((error) => {
|
|
48
|
+
this.log.error('zalo personal: inbound message failed', {
|
|
49
|
+
detail: error instanceof Error ? error.message : String(error),
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
this.api.listener.on('error', (error) => {
|
|
54
|
+
this.log.error('zalo personal: listener error', {
|
|
55
|
+
detail: error instanceof Error ? error.message : String(error),
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
this.api.listener.on('closed', (_code, reason) => {
|
|
59
|
+
this.status = 'error';
|
|
60
|
+
this.detail = reason || 'SESSION_CLOSED';
|
|
61
|
+
});
|
|
62
|
+
this.api.listener.start({ retryOnClose: true });
|
|
63
|
+
this.unsubscribeTurnDone = this.subscribeTurnDone?.((payload) => void this.onTurnDone(payload));
|
|
64
|
+
this.status = 'connected';
|
|
65
|
+
this.detail = undefined;
|
|
66
|
+
this.log.info('zalo personal: connected');
|
|
67
|
+
}
|
|
68
|
+
catch (error) {
|
|
69
|
+
this.status = 'error';
|
|
70
|
+
this.detail = error instanceof Error ? error.message : 'CONNECT_FAILED';
|
|
71
|
+
this.log.error('zalo personal: connection failed', { detail: this.detail });
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
async stop() {
|
|
75
|
+
this.api?.listener.stop();
|
|
76
|
+
this.unsubscribeTurnDone?.();
|
|
77
|
+
this.unsubscribeTurnDone = undefined;
|
|
78
|
+
this.saveState();
|
|
79
|
+
this.status = 'disconnected';
|
|
80
|
+
this.detail = 'STOPPED';
|
|
81
|
+
}
|
|
82
|
+
async send(target, text) {
|
|
83
|
+
if (!this.api)
|
|
84
|
+
throw new Error('NOT_CONFIGURED: zalo personal is not connected');
|
|
85
|
+
const threadId = target.trim();
|
|
86
|
+
if (!threadId || !text.trim())
|
|
87
|
+
throw new Error('INVALID_ARGUMENT: target/text must not be empty');
|
|
88
|
+
const type = await this.resolveThreadType(threadId);
|
|
89
|
+
await this.api.sendMessage({ msg: text }, threadId, type);
|
|
90
|
+
}
|
|
91
|
+
getStatus() {
|
|
92
|
+
this.prunePairing();
|
|
93
|
+
if (this.status === 'connected' && this.pairing.length > 0) {
|
|
94
|
+
return { status: 'pending', detail: 'PAIRING' };
|
|
95
|
+
}
|
|
96
|
+
return this.detail ? { status: this.status, detail: this.detail } : { status: this.status };
|
|
97
|
+
}
|
|
98
|
+
createPairingCode() {
|
|
99
|
+
this.prunePairing();
|
|
100
|
+
const code = `BOOM-${String(randomInt(0, 1_000_000)).padStart(6, '0')}`;
|
|
101
|
+
this.pairing.push({ code, createdAt: Date.now() });
|
|
102
|
+
this.saveState();
|
|
103
|
+
return code;
|
|
104
|
+
}
|
|
105
|
+
unpairThread(threadId) {
|
|
106
|
+
this.allowlist.delete(threadId.trim());
|
|
107
|
+
this.saveState();
|
|
108
|
+
}
|
|
109
|
+
async onMessage(message) {
|
|
110
|
+
if (message.isSelf)
|
|
111
|
+
return;
|
|
112
|
+
const threadId = String(message.threadId);
|
|
113
|
+
const text = typeof message.data.content === 'string' ? message.data.content.trim() : '';
|
|
114
|
+
this.threadTypes.set(threadId, message.type);
|
|
115
|
+
if (PAIRING_CODE_PATTERN.test(text.toUpperCase())) {
|
|
116
|
+
const index = this.pairing.findIndex((entry) => entry.code === text.toUpperCase());
|
|
117
|
+
if (index === -1)
|
|
118
|
+
return;
|
|
119
|
+
this.pairing.splice(index, 1);
|
|
120
|
+
this.allowlist.add(threadId);
|
|
121
|
+
this.saveState();
|
|
122
|
+
await this.send(threadId, 'Đã ghép nối chat này với BoomBot.');
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
if (!text || !this.allowlist.has(threadId) || !this.turnService)
|
|
126
|
+
return;
|
|
127
|
+
const result = await this.turnService.submit({ input: text, channel: 'zalo', replyTo: threadId });
|
|
128
|
+
this.pendingReplies.set(result.turnId, threadId);
|
|
129
|
+
}
|
|
130
|
+
async onTurnDone(payload) {
|
|
131
|
+
const threadId = this.pendingReplies.get(payload.turnId);
|
|
132
|
+
if (!threadId)
|
|
133
|
+
return;
|
|
134
|
+
this.pendingReplies.delete(payload.turnId);
|
|
135
|
+
const text = payload.status === 'error' ? payload.error : payload.output;
|
|
136
|
+
if (text)
|
|
137
|
+
await this.send(threadId, text).catch((error) => {
|
|
138
|
+
this.log.error('zalo personal: reply failed', {
|
|
139
|
+
detail: error instanceof Error ? error.message : String(error),
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
async resolveThreadType(threadId) {
|
|
144
|
+
const known = this.threadTypes.get(threadId);
|
|
145
|
+
if (known !== undefined)
|
|
146
|
+
return known;
|
|
147
|
+
try {
|
|
148
|
+
const info = await this.api?.getGroupInfo(threadId);
|
|
149
|
+
const type = info?.gridInfoMap[threadId] ? ZALO_THREAD_GROUP : ZALO_THREAD_USER;
|
|
150
|
+
this.threadTypes.set(threadId, type);
|
|
151
|
+
return type;
|
|
152
|
+
}
|
|
153
|
+
catch {
|
|
154
|
+
return ZALO_THREAD_USER;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
loadState() {
|
|
158
|
+
const state = readJsonFile(this.statePath);
|
|
159
|
+
for (const id of state?.allowlist ?? [])
|
|
160
|
+
this.allowlist.add(id);
|
|
161
|
+
this.pairing = [...(state?.pairing ?? [])];
|
|
162
|
+
this.prunePairing();
|
|
163
|
+
}
|
|
164
|
+
saveState() {
|
|
165
|
+
writeJsonFile(this.statePath, { allowlist: [...this.allowlist], pairing: this.pairing });
|
|
166
|
+
}
|
|
167
|
+
prunePairing() {
|
|
168
|
+
const cutoff = Date.now() - PAIRING_TTL_MS;
|
|
169
|
+
this.pairing = this.pairing.filter((entry) => entry.createdAt >= cutoff);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@boombot/core` — transport-agnostic gateway contracts and middleware.
|
|
3
|
+
*
|
|
4
|
+
* Boundary rule: this package MUST NOT import `@boombot/protocol`
|
|
5
|
+
* or any other BoomBot package.
|
|
6
|
+
*/
|
|
7
|
+
export * from './types.js';
|
|
8
|
+
export * from './runtime-deps.js';
|
|
9
|
+
export * from './middleware.js';
|
|
10
|
+
export * from './tool-errors.js';
|
|
11
|
+
export * from './routing.js';
|
|
12
|
+
export * from './turn-loop.js';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@boombot/core` — transport-agnostic gateway contracts and middleware.
|
|
3
|
+
*
|
|
4
|
+
* Boundary rule: this package MUST NOT import `@boombot/protocol`
|
|
5
|
+
* or any other BoomBot package.
|
|
6
|
+
*/
|
|
7
|
+
export * from './types.js';
|
|
8
|
+
export * from './runtime-deps.js';
|
|
9
|
+
export * from './middleware.js';
|
|
10
|
+
export * from './tool-errors.js';
|
|
11
|
+
export * from './routing.js';
|
|
12
|
+
export * from './turn-loop.js';
|