@spinabot/brigade 0.1.1 → 1.0.0
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/LICENSE +1 -1
- package/README.md +746 -93
- package/brigade.mjs +150 -73
- package/dist/agents/a2a-policy-canonicalize.d.ts +60 -0
- package/dist/agents/a2a-policy-canonicalize.d.ts.map +1 -0
- package/dist/agents/a2a-policy-canonicalize.js +103 -0
- package/dist/agents/a2a-policy-canonicalize.js.map +1 -0
- package/dist/agents/agent-event-bus.d.ts +221 -0
- package/dist/agents/agent-event-bus.d.ts.map +1 -0
- package/dist/agents/agent-event-bus.js +88 -0
- package/dist/agents/agent-event-bus.js.map +1 -0
- package/dist/agents/agent-events.d.ts +84 -0
- package/dist/agents/agent-events.d.ts.map +1 -0
- package/dist/agents/agent-events.js +309 -0
- package/dist/agents/agent-events.js.map +1 -0
- package/dist/agents/agent-events.types.d.ts +139 -0
- package/dist/agents/agent-events.types.d.ts.map +1 -0
- package/dist/agents/agent-events.types.js +27 -0
- package/dist/agents/agent-events.types.js.map +1 -0
- package/dist/agents/agent-loop.d.ts +145 -0
- package/dist/agents/agent-loop.d.ts.map +1 -0
- package/dist/agents/agent-loop.js +1938 -0
- package/dist/agents/agent-loop.js.map +1 -0
- package/dist/agents/agent-scope.d.ts +28 -0
- package/dist/agents/agent-scope.d.ts.map +1 -0
- package/dist/agents/agent-scope.js +39 -0
- package/dist/agents/agent-scope.js.map +1 -0
- package/dist/agents/approval-bridge.d.ts +139 -0
- package/dist/agents/approval-bridge.d.ts.map +1 -0
- package/dist/agents/approval-bridge.js +178 -0
- package/dist/agents/approval-bridge.js.map +1 -0
- package/dist/agents/carrow.d.ts +49 -0
- package/dist/agents/carrow.d.ts.map +1 -0
- package/dist/agents/carrow.js +57 -0
- package/dist/agents/carrow.js.map +1 -0
- package/dist/agents/channels/abort-triggers.d.ts +17 -0
- package/dist/agents/channels/abort-triggers.d.ts.map +1 -0
- package/dist/agents/channels/abort-triggers.js +52 -0
- package/dist/agents/channels/abort-triggers.js.map +1 -0
- package/dist/agents/channels/access-control/index.d.ts +5 -0
- package/dist/agents/channels/access-control/index.d.ts.map +1 -0
- package/dist/agents/channels/access-control/index.js +4 -0
- package/dist/agents/channels/access-control/index.js.map +1 -0
- package/dist/agents/channels/access-control/policy.d.ts +69 -0
- package/dist/agents/channels/access-control/policy.d.ts.map +1 -0
- package/dist/agents/channels/access-control/policy.js +123 -0
- package/dist/agents/channels/access-control/policy.js.map +1 -0
- package/dist/agents/channels/access-control/store.d.ts +86 -0
- package/dist/agents/channels/access-control/store.d.ts.map +1 -0
- package/dist/agents/channels/access-control/store.js +482 -0
- package/dist/agents/channels/access-control/store.js.map +1 -0
- package/dist/agents/channels/access-control/types.d.ts +52 -0
- package/dist/agents/channels/access-control/types.d.ts.map +1 -0
- package/dist/agents/channels/access-control/types.js +20 -0
- package/dist/agents/channels/access-control/types.js.map +1 -0
- package/dist/agents/channels/active-manager.d.ts +31 -0
- package/dist/agents/channels/active-manager.d.ts.map +1 -0
- package/dist/agents/channels/active-manager.js +41 -0
- package/dist/agents/channels/active-manager.js.map +1 -0
- package/dist/agents/channels/agent-switch-command.d.ts +53 -0
- package/dist/agents/channels/agent-switch-command.d.ts.map +1 -0
- package/dist/agents/channels/agent-switch-command.js +349 -0
- package/dist/agents/channels/agent-switch-command.js.map +1 -0
- package/dist/agents/channels/approval-router.d.ts +158 -0
- package/dist/agents/channels/approval-router.d.ts.map +1 -0
- package/dist/agents/channels/approval-router.js +446 -0
- package/dist/agents/channels/approval-router.js.map +1 -0
- package/dist/agents/channels/channel-entry-contract.d.ts +70 -0
- package/dist/agents/channels/channel-entry-contract.d.ts.map +1 -0
- package/dist/agents/channels/channel-entry-contract.js +48 -0
- package/dist/agents/channels/channel-entry-contract.js.map +1 -0
- package/dist/agents/channels/channel-plugin-manager.d.ts +86 -0
- package/dist/agents/channels/channel-plugin-manager.d.ts.map +1 -0
- package/dist/agents/channels/channel-plugin-manager.js +345 -0
- package/dist/agents/channels/channel-plugin-manager.js.map +1 -0
- package/dist/agents/channels/chat-type.d.ts +27 -0
- package/dist/agents/channels/chat-type.d.ts.map +1 -0
- package/dist/agents/channels/chat-type.js +33 -0
- package/dist/agents/channels/chat-type.js.map +1 -0
- package/dist/agents/channels/dedupe.d.ts +44 -0
- package/dist/agents/channels/dedupe.d.ts.map +1 -0
- package/dist/agents/channels/dedupe.js +80 -0
- package/dist/agents/channels/dedupe.js.map +1 -0
- package/dist/agents/channels/inbound-pipeline.d.ts +90 -0
- package/dist/agents/channels/inbound-pipeline.d.ts.map +1 -0
- package/dist/agents/channels/inbound-pipeline.js +721 -0
- package/dist/agents/channels/inbound-pipeline.js.map +1 -0
- package/dist/agents/channels/last-channel.d.ts +56 -0
- package/dist/agents/channels/last-channel.d.ts.map +1 -0
- package/dist/agents/channels/last-channel.js +65 -0
- package/dist/agents/channels/last-channel.js.map +1 -0
- package/dist/agents/channels/manager.d.ts +76 -0
- package/dist/agents/channels/manager.d.ts.map +1 -0
- package/dist/agents/channels/manager.js +132 -0
- package/dist/agents/channels/manager.js.map +1 -0
- package/dist/agents/channels/media-capture.d.ts +23 -0
- package/dist/agents/channels/media-capture.d.ts.map +1 -0
- package/dist/agents/channels/media-capture.js +40 -0
- package/dist/agents/channels/media-capture.js.map +1 -0
- package/dist/agents/channels/plugin-channel-manager-facade.d.ts +18 -0
- package/dist/agents/channels/plugin-channel-manager-facade.d.ts.map +1 -0
- package/dist/agents/channels/plugin-channel-manager-facade.js +52 -0
- package/dist/agents/channels/plugin-channel-manager-facade.js.map +1 -0
- package/dist/agents/channels/reply-sanitizer.d.ts +38 -0
- package/dist/agents/channels/reply-sanitizer.d.ts.map +1 -0
- package/dist/agents/channels/reply-sanitizer.js +94 -0
- package/dist/agents/channels/reply-sanitizer.js.map +1 -0
- package/dist/agents/channels/retryable-inbound.d.ts +31 -0
- package/dist/agents/channels/retryable-inbound.d.ts.map +1 -0
- package/dist/agents/channels/retryable-inbound.js +37 -0
- package/dist/agents/channels/retryable-inbound.js.map +1 -0
- package/dist/agents/channels/types.adapters.d.ts +399 -0
- package/dist/agents/channels/types.adapters.d.ts.map +1 -0
- package/dist/agents/channels/types.adapters.js +33 -0
- package/dist/agents/channels/types.adapters.js.map +1 -0
- package/dist/agents/channels/types.core.d.ts +134 -0
- package/dist/agents/channels/types.core.d.ts.map +1 -0
- package/dist/agents/channels/types.core.js +32 -0
- package/dist/agents/channels/types.core.js.map +1 -0
- package/dist/agents/channels/types.plugin.d.ts +78 -0
- package/dist/agents/channels/types.plugin.d.ts.map +1 -0
- package/dist/agents/channels/types.plugin.js +30 -0
- package/dist/agents/channels/types.plugin.js.map +1 -0
- package/dist/agents/channels/whatsapp/account-config.d.ts +50 -0
- package/dist/agents/channels/whatsapp/account-config.d.ts.map +1 -0
- package/dist/agents/channels/whatsapp/account-config.js +105 -0
- package/dist/agents/channels/whatsapp/account-config.js.map +1 -0
- package/dist/agents/channels/whatsapp/adapter.d.ts +22 -0
- package/dist/agents/channels/whatsapp/adapter.d.ts.map +1 -0
- package/dist/agents/channels/whatsapp/adapter.js +270 -0
- package/dist/agents/channels/whatsapp/adapter.js.map +1 -0
- package/dist/agents/channels/whatsapp/chunk.d.ts +26 -0
- package/dist/agents/channels/whatsapp/chunk.d.ts.map +1 -0
- package/dist/agents/channels/whatsapp/chunk.js +123 -0
- package/dist/agents/channels/whatsapp/chunk.js.map +1 -0
- package/dist/agents/channels/whatsapp/connection.d.ts +249 -0
- package/dist/agents/channels/whatsapp/connection.d.ts.map +1 -0
- package/dist/agents/channels/whatsapp/connection.js +1628 -0
- package/dist/agents/channels/whatsapp/connection.js.map +1 -0
- package/dist/agents/channels/whatsapp/convex-auth-state.d.ts +34 -0
- package/dist/agents/channels/whatsapp/convex-auth-state.d.ts.map +1 -0
- package/dist/agents/channels/whatsapp/convex-auth-state.js +168 -0
- package/dist/agents/channels/whatsapp/convex-auth-state.js.map +1 -0
- package/dist/agents/channels/whatsapp/format.d.ts +15 -0
- package/dist/agents/channels/whatsapp/format.d.ts.map +1 -0
- package/dist/agents/channels/whatsapp/format.js +66 -0
- package/dist/agents/channels/whatsapp/format.js.map +1 -0
- package/dist/agents/channels/whatsapp/inbound-extras.d.ts +30 -0
- package/dist/agents/channels/whatsapp/inbound-extras.d.ts.map +1 -0
- package/dist/agents/channels/whatsapp/inbound-extras.js +146 -0
- package/dist/agents/channels/whatsapp/inbound-extras.js.map +1 -0
- package/dist/agents/channels/whatsapp/index.d.ts +7 -0
- package/dist/agents/channels/whatsapp/index.d.ts.map +1 -0
- package/dist/agents/channels/whatsapp/index.js +7 -0
- package/dist/agents/channels/whatsapp/index.js.map +1 -0
- package/dist/agents/channels/whatsapp/media.d.ts +47 -0
- package/dist/agents/channels/whatsapp/media.d.ts.map +1 -0
- package/dist/agents/channels/whatsapp/media.js +192 -0
- package/dist/agents/channels/whatsapp/media.js.map +1 -0
- package/dist/agents/channels/whatsapp/module.d.ts +10 -0
- package/dist/agents/channels/whatsapp/module.d.ts.map +1 -0
- package/dist/agents/channels/whatsapp/module.js +17 -0
- package/dist/agents/channels/whatsapp/module.js.map +1 -0
- package/dist/agents/channels/whatsapp/plugin.d.ts +60 -0
- package/dist/agents/channels/whatsapp/plugin.d.ts.map +1 -0
- package/dist/agents/channels/whatsapp/plugin.js +238 -0
- package/dist/agents/channels/whatsapp/plugin.js.map +1 -0
- package/dist/agents/cmd-ism-guard.d.ts +47 -0
- package/dist/agents/cmd-ism-guard.d.ts.map +1 -0
- package/dist/agents/cmd-ism-guard.js +100 -0
- package/dist/agents/cmd-ism-guard.js.map +1 -0
- package/dist/agents/config-write-guard.d.ts +25 -0
- package/dist/agents/config-write-guard.d.ts.map +1 -0
- package/dist/agents/config-write-guard.js +95 -0
- package/dist/agents/config-write-guard.js.map +1 -0
- package/dist/agents/content-quality-retry.d.ts +66 -0
- package/dist/agents/content-quality-retry.d.ts.map +1 -0
- package/dist/agents/content-quality-retry.js +140 -0
- package/dist/agents/content-quality-retry.js.map +1 -0
- package/dist/agents/error-classifier.d.ts +89 -0
- package/dist/agents/error-classifier.d.ts.map +1 -0
- package/dist/agents/error-classifier.js +630 -0
- package/dist/agents/error-classifier.js.map +1 -0
- package/dist/agents/exec-gate.d.ts +113 -0
- package/dist/agents/exec-gate.d.ts.map +1 -0
- package/dist/agents/exec-gate.js +335 -0
- package/dist/agents/exec-gate.js.map +1 -0
- package/dist/agents/exec-session-allow.d.ts +30 -0
- package/dist/agents/exec-session-allow.d.ts.map +1 -0
- package/dist/agents/exec-session-allow.js +50 -0
- package/dist/agents/exec-session-allow.js.map +1 -0
- package/dist/agents/extensions/active-registry.d.ts +4 -0
- package/dist/agents/extensions/active-registry.d.ts.map +1 -0
- package/dist/agents/extensions/active-registry.js +18 -0
- package/dist/agents/extensions/active-registry.js.map +1 -0
- package/dist/agents/extensions/discovery.d.ts +84 -0
- package/dist/agents/extensions/discovery.d.ts.map +1 -0
- package/dist/agents/extensions/discovery.js +249 -0
- package/dist/agents/extensions/discovery.js.map +1 -0
- package/dist/agents/extensions/hook-runner.d.ts +67 -0
- package/dist/agents/extensions/hook-runner.d.ts.map +1 -0
- package/dist/agents/extensions/hook-runner.js +155 -0
- package/dist/agents/extensions/hook-runner.js.map +1 -0
- package/dist/agents/extensions/index.d.ts +15 -0
- package/dist/agents/extensions/index.d.ts.map +1 -0
- package/dist/agents/extensions/index.js +14 -0
- package/dist/agents/extensions/index.js.map +1 -0
- package/dist/agents/extensions/loader.d.ts +38 -0
- package/dist/agents/extensions/loader.d.ts.map +1 -0
- package/dist/agents/extensions/loader.js +142 -0
- package/dist/agents/extensions/loader.js.map +1 -0
- package/dist/agents/extensions/modules/arxiv.d.ts +28 -0
- package/dist/agents/extensions/modules/arxiv.d.ts.map +1 -0
- package/dist/agents/extensions/modules/arxiv.js +145 -0
- package/dist/agents/extensions/modules/arxiv.js.map +1 -0
- package/dist/agents/extensions/modules/brave.d.ts +28 -0
- package/dist/agents/extensions/modules/brave.d.ts.map +1 -0
- package/dist/agents/extensions/modules/brave.js +489 -0
- package/dist/agents/extensions/modules/brave.js.map +1 -0
- package/dist/agents/extensions/modules/duckduckgo.d.ts +27 -0
- package/dist/agents/extensions/modules/duckduckgo.d.ts.map +1 -0
- package/dist/agents/extensions/modules/duckduckgo.js +263 -0
- package/dist/agents/extensions/modules/duckduckgo.js.map +1 -0
- package/dist/agents/extensions/modules/exa.d.ts +19 -0
- package/dist/agents/extensions/modules/exa.d.ts.map +1 -0
- package/dist/agents/extensions/modules/exa.js +208 -0
- package/dist/agents/extensions/modules/exa.js.map +1 -0
- package/dist/agents/extensions/modules/firecrawl.d.ts +51 -0
- package/dist/agents/extensions/modules/firecrawl.d.ts.map +1 -0
- package/dist/agents/extensions/modules/firecrawl.js +280 -0
- package/dist/agents/extensions/modules/firecrawl.js.map +1 -0
- package/dist/agents/extensions/modules/github-search.d.ts +29 -0
- package/dist/agents/extensions/modules/github-search.d.ts.map +1 -0
- package/dist/agents/extensions/modules/github-search.js +197 -0
- package/dist/agents/extensions/modules/github-search.js.map +1 -0
- package/dist/agents/extensions/modules/hackernews.d.ts +17 -0
- package/dist/agents/extensions/modules/hackernews.d.ts.map +1 -0
- package/dist/agents/extensions/modules/hackernews.js +144 -0
- package/dist/agents/extensions/modules/hackernews.js.map +1 -0
- package/dist/agents/extensions/modules/index.d.ts +11 -0
- package/dist/agents/extensions/modules/index.d.ts.map +1 -0
- package/dist/agents/extensions/modules/index.js +64 -0
- package/dist/agents/extensions/modules/index.js.map +1 -0
- package/dist/agents/extensions/modules/npm-search.d.ts +15 -0
- package/dist/agents/extensions/modules/npm-search.d.ts.map +1 -0
- package/dist/agents/extensions/modules/npm-search.js +126 -0
- package/dist/agents/extensions/modules/npm-search.js.map +1 -0
- package/dist/agents/extensions/modules/ollama-search.d.ts +30 -0
- package/dist/agents/extensions/modules/ollama-search.d.ts.map +1 -0
- package/dist/agents/extensions/modules/ollama-search.js +171 -0
- package/dist/agents/extensions/modules/ollama-search.js.map +1 -0
- package/dist/agents/extensions/modules/perplexity.d.ts +19 -0
- package/dist/agents/extensions/modules/perplexity.d.ts.map +1 -0
- package/dist/agents/extensions/modules/perplexity.js +358 -0
- package/dist/agents/extensions/modules/perplexity.js.map +1 -0
- package/dist/agents/extensions/modules/searxng.d.ts +43 -0
- package/dist/agents/extensions/modules/searxng.d.ts.map +1 -0
- package/dist/agents/extensions/modules/searxng.js +191 -0
- package/dist/agents/extensions/modules/searxng.js.map +1 -0
- package/dist/agents/extensions/modules/tavily.d.ts +71 -0
- package/dist/agents/extensions/modules/tavily.d.ts.map +1 -0
- package/dist/agents/extensions/modules/tavily.js +330 -0
- package/dist/agents/extensions/modules/tavily.js.map +1 -0
- package/dist/agents/extensions/modules/web-provider-helpers.d.ts +89 -0
- package/dist/agents/extensions/modules/web-provider-helpers.d.ts.map +1 -0
- package/dist/agents/extensions/modules/web-provider-helpers.js +146 -0
- package/dist/agents/extensions/modules/web-provider-helpers.js.map +1 -0
- package/dist/agents/extensions/modules/web-search-filters.d.ts +62 -0
- package/dist/agents/extensions/modules/web-search-filters.d.ts.map +1 -0
- package/dist/agents/extensions/modules/web-search-filters.js +179 -0
- package/dist/agents/extensions/modules/web-search-filters.js.map +1 -0
- package/dist/agents/extensions/modules/wikipedia.d.ts +16 -0
- package/dist/agents/extensions/modules/wikipedia.d.ts.map +1 -0
- package/dist/agents/extensions/modules/wikipedia.js +138 -0
- package/dist/agents/extensions/modules/wikipedia.js.map +1 -0
- package/dist/agents/extensions/registry-cache.d.ts +74 -0
- package/dist/agents/extensions/registry-cache.d.ts.map +1 -0
- package/dist/agents/extensions/registry-cache.js +117 -0
- package/dist/agents/extensions/registry-cache.js.map +1 -0
- package/dist/agents/extensions/registry.d.ts +184 -0
- package/dist/agents/extensions/registry.d.ts.map +1 -0
- package/dist/agents/extensions/registry.js +512 -0
- package/dist/agents/extensions/registry.js.map +1 -0
- package/dist/agents/extensions/types.d.ts +1195 -0
- package/dist/agents/extensions/types.d.ts.map +1 -0
- package/dist/agents/extensions/types.js +28 -0
- package/dist/agents/extensions/types.js.map +1 -0
- package/dist/agents/gateway-call.d.ts +171 -0
- package/dist/agents/gateway-call.d.ts.map +1 -0
- package/dist/agents/gateway-call.js +74 -0
- package/dist/agents/gateway-call.js.map +1 -0
- package/dist/agents/heartbeat-runner.d.ts +100 -0
- package/dist/agents/heartbeat-runner.d.ts.map +1 -0
- package/dist/agents/heartbeat-runner.js +268 -0
- package/dist/agents/heartbeat-runner.js.map +1 -0
- package/dist/agents/heartbeat-scheduler.d.ts +56 -0
- package/dist/agents/heartbeat-scheduler.d.ts.map +1 -0
- package/dist/agents/heartbeat-scheduler.js +366 -0
- package/dist/agents/heartbeat-scheduler.js.map +1 -0
- package/dist/agents/heartbeat-wake.d.ts +99 -0
- package/dist/agents/heartbeat-wake.d.ts.map +1 -0
- package/dist/agents/heartbeat-wake.js +304 -0
- package/dist/agents/heartbeat-wake.js.map +1 -0
- package/dist/agents/identity-file.d.ts +26 -0
- package/dist/agents/identity-file.d.ts.map +1 -0
- package/dist/agents/identity-file.js +86 -0
- package/dist/agents/identity-file.js.map +1 -0
- package/dist/agents/identity-links.d.ts +44 -0
- package/dist/agents/identity-links.d.ts.map +1 -0
- package/dist/agents/identity-links.js +51 -0
- package/dist/agents/identity-links.js.map +1 -0
- package/dist/agents/loop/autonomous-agent.d.ts +55 -0
- package/dist/agents/loop/autonomous-agent.d.ts.map +1 -0
- package/dist/agents/loop/autonomous-agent.js +91 -0
- package/dist/agents/loop/autonomous-agent.js.map +1 -0
- package/dist/agents/loop/loop-guards.d.ts +95 -0
- package/dist/agents/loop/loop-guards.d.ts.map +1 -0
- package/dist/agents/loop/loop-guards.js +169 -0
- package/dist/agents/loop/loop-guards.js.map +1 -0
- package/dist/agents/loop/loop-runner.d.ts +72 -0
- package/dist/agents/loop/loop-runner.d.ts.map +1 -0
- package/dist/agents/loop/loop-runner.js +114 -0
- package/dist/agents/loop/loop-runner.js.map +1 -0
- package/dist/agents/memory/auto-recall.d.ts +69 -0
- package/dist/agents/memory/auto-recall.d.ts.map +1 -0
- package/dist/agents/memory/auto-recall.js +147 -0
- package/dist/agents/memory/auto-recall.js.map +1 -0
- package/dist/agents/memory/behavior-review.d.ts +68 -0
- package/dist/agents/memory/behavior-review.d.ts.map +1 -0
- package/dist/agents/memory/behavior-review.js +131 -0
- package/dist/agents/memory/behavior-review.js.map +1 -0
- package/dist/agents/memory/consolidate.d.ts +62 -0
- package/dist/agents/memory/consolidate.d.ts.map +1 -0
- package/dist/agents/memory/consolidate.js +275 -0
- package/dist/agents/memory/consolidate.js.map +1 -0
- package/dist/agents/memory/contradiction.d.ts +44 -0
- package/dist/agents/memory/contradiction.d.ts.map +1 -0
- package/dist/agents/memory/contradiction.js +86 -0
- package/dist/agents/memory/contradiction.js.map +1 -0
- package/dist/agents/memory/curator.d.ts +22 -0
- package/dist/agents/memory/curator.d.ts.map +1 -0
- package/dist/agents/memory/curator.js +52 -0
- package/dist/agents/memory/curator.js.map +1 -0
- package/dist/agents/memory/decay.d.ts +32 -0
- package/dist/agents/memory/decay.d.ts.map +1 -0
- package/dist/agents/memory/decay.js +86 -0
- package/dist/agents/memory/decay.js.map +1 -0
- package/dist/agents/memory/dream.d.ts +52 -0
- package/dist/agents/memory/dream.d.ts.map +1 -0
- package/dist/agents/memory/dream.js +192 -0
- package/dist/agents/memory/dream.js.map +1 -0
- package/dist/agents/memory/embedder-providers.d.ts +114 -0
- package/dist/agents/memory/embedder-providers.d.ts.map +1 -0
- package/dist/agents/memory/embedder-providers.js +213 -0
- package/dist/agents/memory/embedder-providers.js.map +1 -0
- package/dist/agents/memory/embedder.d.ts +84 -0
- package/dist/agents/memory/embedder.d.ts.map +1 -0
- package/dist/agents/memory/embedder.js +218 -0
- package/dist/agents/memory/embedder.js.map +1 -0
- package/dist/agents/memory/eval/asr-bench.d.ts +33 -0
- package/dist/agents/memory/eval/asr-bench.d.ts.map +1 -0
- package/dist/agents/memory/eval/asr-bench.js +129 -0
- package/dist/agents/memory/eval/asr-bench.js.map +1 -0
- package/dist/agents/memory/eval/capabilities.d.ts +97 -0
- package/dist/agents/memory/eval/capabilities.d.ts.map +1 -0
- package/dist/agents/memory/eval/capabilities.js +210 -0
- package/dist/agents/memory/eval/capabilities.js.map +1 -0
- package/dist/agents/memory/eval/gold-export.d.ts +44 -0
- package/dist/agents/memory/eval/gold-export.d.ts.map +1 -0
- package/dist/agents/memory/eval/gold-export.js +85 -0
- package/dist/agents/memory/eval/gold-export.js.map +1 -0
- package/dist/agents/memory/eval/gold-hard.d.ts +35 -0
- package/dist/agents/memory/eval/gold-hard.d.ts.map +1 -0
- package/dist/agents/memory/eval/gold-hard.js +113 -0
- package/dist/agents/memory/eval/gold-hard.js.map +1 -0
- package/dist/agents/memory/eval/gold-rich.d.ts +33 -0
- package/dist/agents/memory/eval/gold-rich.d.ts.map +1 -0
- package/dist/agents/memory/eval/gold-rich.js +82 -0
- package/dist/agents/memory/eval/gold-rich.js.map +1 -0
- package/dist/agents/memory/eval/gold-synthetic.d.ts +19 -0
- package/dist/agents/memory/eval/gold-synthetic.d.ts.map +1 -0
- package/dist/agents/memory/eval/gold-synthetic.js +65 -0
- package/dist/agents/memory/eval/gold-synthetic.js.map +1 -0
- package/dist/agents/memory/eval/gold.d.ts +73 -0
- package/dist/agents/memory/eval/gold.d.ts.map +1 -0
- package/dist/agents/memory/eval/gold.js +174 -0
- package/dist/agents/memory/eval/gold.js.map +1 -0
- package/dist/agents/memory/eval/harness.d.ts +110 -0
- package/dist/agents/memory/eval/harness.d.ts.map +1 -0
- package/dist/agents/memory/eval/harness.js +123 -0
- package/dist/agents/memory/eval/harness.js.map +1 -0
- package/dist/agents/memory/eval/metrics.d.ts +71 -0
- package/dist/agents/memory/eval/metrics.d.ts.map +1 -0
- package/dist/agents/memory/eval/metrics.js +169 -0
- package/dist/agents/memory/eval/metrics.js.map +1 -0
- package/dist/agents/memory/event-log.d.ts +52 -0
- package/dist/agents/memory/event-log.d.ts.map +1 -0
- package/dist/agents/memory/event-log.js +65 -0
- package/dist/agents/memory/event-log.js.map +1 -0
- package/dist/agents/memory/extract.d.ts +155 -0
- package/dist/agents/memory/extract.d.ts.map +1 -0
- package/dist/agents/memory/extract.js +571 -0
- package/dist/agents/memory/extract.js.map +1 -0
- package/dist/agents/memory/governance.d.ts +45 -0
- package/dist/agents/memory/governance.d.ts.map +1 -0
- package/dist/agents/memory/governance.js +113 -0
- package/dist/agents/memory/governance.js.map +1 -0
- package/dist/agents/memory/graph-export.d.ts +59 -0
- package/dist/agents/memory/graph-export.d.ts.map +1 -0
- package/dist/agents/memory/graph-export.js +181 -0
- package/dist/agents/memory/graph-export.js.map +1 -0
- package/dist/agents/memory/graph-recall.d.ts +42 -0
- package/dist/agents/memory/graph-recall.d.ts.map +1 -0
- package/dist/agents/memory/graph-recall.js +165 -0
- package/dist/agents/memory/graph-recall.js.map +1 -0
- package/dist/agents/memory/graph.d.ts +92 -0
- package/dist/agents/memory/graph.d.ts.map +1 -0
- package/dist/agents/memory/graph.js +266 -0
- package/dist/agents/memory/graph.js.map +1 -0
- package/dist/agents/memory/host-ports.d.ts +27 -0
- package/dist/agents/memory/host-ports.d.ts.map +1 -0
- package/dist/agents/memory/host-ports.js +31 -0
- package/dist/agents/memory/host-ports.js.map +1 -0
- package/dist/agents/memory/hybrid.d.ts +46 -0
- package/dist/agents/memory/hybrid.d.ts.map +1 -0
- package/dist/agents/memory/hybrid.js +184 -0
- package/dist/agents/memory/hybrid.js.map +1 -0
- package/dist/agents/memory/index.d.ts +13 -0
- package/dist/agents/memory/index.d.ts.map +1 -0
- package/dist/agents/memory/index.js +13 -0
- package/dist/agents/memory/index.js.map +1 -0
- package/dist/agents/memory/json-scan.d.ts +14 -0
- package/dist/agents/memory/json-scan.d.ts.map +1 -0
- package/dist/agents/memory/json-scan.js +47 -0
- package/dist/agents/memory/json-scan.js.map +1 -0
- package/dist/agents/memory/links.d.ts +92 -0
- package/dist/agents/memory/links.d.ts.map +1 -0
- package/dist/agents/memory/links.js +140 -0
- package/dist/agents/memory/links.js.map +1 -0
- package/dist/agents/memory/maintenance.d.ts +18 -0
- package/dist/agents/memory/maintenance.d.ts.map +1 -0
- package/dist/agents/memory/maintenance.js +66 -0
- package/dist/agents/memory/maintenance.js.map +1 -0
- package/dist/agents/memory/memory-mcp-server.d.ts +39 -0
- package/dist/agents/memory/memory-mcp-server.d.ts.map +1 -0
- package/dist/agents/memory/memory-mcp-server.js +122 -0
- package/dist/agents/memory/memory-mcp-server.js.map +1 -0
- package/dist/agents/memory/memory-mcp.d.ts +34 -0
- package/dist/agents/memory/memory-mcp.d.ts.map +1 -0
- package/dist/agents/memory/memory-mcp.js +130 -0
- package/dist/agents/memory/memory-mcp.js.map +1 -0
- package/dist/agents/memory/plugin-runtime.d.ts +133 -0
- package/dist/agents/memory/plugin-runtime.d.ts.map +1 -0
- package/dist/agents/memory/plugin-runtime.js +149 -0
- package/dist/agents/memory/plugin-runtime.js.map +1 -0
- package/dist/agents/memory/query.d.ts +50 -0
- package/dist/agents/memory/query.d.ts.map +1 -0
- package/dist/agents/memory/query.js +94 -0
- package/dist/agents/memory/query.js.map +1 -0
- package/dist/agents/memory/records.d.ts +617 -0
- package/dist/agents/memory/records.d.ts.map +1 -0
- package/dist/agents/memory/records.js +1327 -0
- package/dist/agents/memory/records.js.map +1 -0
- package/dist/agents/memory/reembed.d.ts +42 -0
- package/dist/agents/memory/reembed.d.ts.map +1 -0
- package/dist/agents/memory/reembed.js +60 -0
- package/dist/agents/memory/reembed.js.map +1 -0
- package/dist/agents/memory/relationship-extract.d.ts +259 -0
- package/dist/agents/memory/relationship-extract.d.ts.map +1 -0
- package/dist/agents/memory/relationship-extract.js +454 -0
- package/dist/agents/memory/relationship-extract.js.map +1 -0
- package/dist/agents/memory/rerank.d.ts +37 -0
- package/dist/agents/memory/rerank.d.ts.map +1 -0
- package/dist/agents/memory/rerank.js +43 -0
- package/dist/agents/memory/rerank.js.map +1 -0
- package/dist/agents/memory/scoring.d.ts +85 -0
- package/dist/agents/memory/scoring.d.ts.map +1 -0
- package/dist/agents/memory/scoring.js +139 -0
- package/dist/agents/memory/scoring.js.map +1 -0
- package/dist/agents/memory/self-improve.d.ts +56 -0
- package/dist/agents/memory/self-improve.d.ts.map +1 -0
- package/dist/agents/memory/self-improve.js +98 -0
- package/dist/agents/memory/self-improve.js.map +1 -0
- package/dist/agents/memory/self-review.d.ts +68 -0
- package/dist/agents/memory/self-review.d.ts.map +1 -0
- package/dist/agents/memory/self-review.js +109 -0
- package/dist/agents/memory/self-review.js.map +1 -0
- package/dist/agents/memory/storage.d.ts +156 -0
- package/dist/agents/memory/storage.d.ts.map +1 -0
- package/dist/agents/memory/storage.js +359 -0
- package/dist/agents/memory/storage.js.map +1 -0
- package/dist/agents/memory/tideline.d.ts +203 -0
- package/dist/agents/memory/tideline.d.ts.map +1 -0
- package/dist/agents/memory/tideline.js +189 -0
- package/dist/agents/memory/tideline.js.map +1 -0
- package/dist/agents/memory/vault.d.ts +142 -0
- package/dist/agents/memory/vault.d.ts.map +1 -0
- package/dist/agents/memory/vault.js +787 -0
- package/dist/agents/memory/vault.js.map +1 -0
- package/dist/agents/memory/write-gate.d.ts +76 -0
- package/dist/agents/memory/write-gate.d.ts.map +1 -0
- package/dist/agents/memory/write-gate.js +140 -0
- package/dist/agents/memory/write-gate.js.map +1 -0
- package/dist/agents/mid-turn-switch.d.ts +25 -0
- package/dist/agents/mid-turn-switch.d.ts.map +1 -0
- package/dist/agents/mid-turn-switch.js +103 -0
- package/dist/agents/mid-turn-switch.js.map +1 -0
- package/dist/agents/model-fallback.d.ts +50 -0
- package/dist/agents/model-fallback.d.ts.map +1 -0
- package/dist/agents/model-fallback.js +226 -0
- package/dist/agents/model-fallback.js.map +1 -0
- package/dist/agents/model-resolution.d.ts +38 -0
- package/dist/agents/model-resolution.d.ts.map +1 -0
- package/dist/agents/model-resolution.js +155 -0
- package/dist/agents/model-resolution.js.map +1 -0
- package/dist/agents/org/a2a-adapter.d.ts +49 -0
- package/dist/agents/org/a2a-adapter.d.ts.map +1 -0
- package/dist/agents/org/a2a-adapter.js +92 -0
- package/dist/agents/org/a2a-adapter.js.map +1 -0
- package/dist/agents/org/assets/mascots/README.md +34 -0
- package/dist/agents/org/assets/mascots/Untitled-1.png +0 -0
- package/dist/agents/org/assets/mascots/brigade_biceps.png +0 -0
- package/dist/agents/org/audit-log.d.ts +22 -0
- package/dist/agents/org/audit-log.d.ts.map +1 -0
- package/dist/agents/org/audit-log.js +37 -0
- package/dist/agents/org/audit-log.js.map +1 -0
- package/dist/agents/org/auto-derive.d.ts +22 -0
- package/dist/agents/org/auto-derive.d.ts.map +1 -0
- package/dist/agents/org/auto-derive.js +66 -0
- package/dist/agents/org/auto-derive.js.map +1 -0
- package/dist/agents/org/delivery-kind.d.ts +89 -0
- package/dist/agents/org/delivery-kind.d.ts.map +1 -0
- package/dist/agents/org/delivery-kind.js +149 -0
- package/dist/agents/org/delivery-kind.js.map +1 -0
- package/dist/agents/org/derive-graph.d.ts +34 -0
- package/dist/agents/org/derive-graph.d.ts.map +1 -0
- package/dist/agents/org/derive-graph.js +266 -0
- package/dist/agents/org/derive-graph.js.map +1 -0
- package/dist/agents/org/lints.d.ts +21 -0
- package/dist/agents/org/lints.d.ts.map +1 -0
- package/dist/agents/org/lints.js +133 -0
- package/dist/agents/org/lints.js.map +1 -0
- package/dist/agents/org/pride-html.d.ts +61 -0
- package/dist/agents/org/pride-html.d.ts.map +1 -0
- package/dist/agents/org/pride-html.js +565 -0
- package/dist/agents/org/pride-html.js.map +1 -0
- package/dist/agents/org/pride-image.d.ts +101 -0
- package/dist/agents/org/pride-image.d.ts.map +1 -0
- package/dist/agents/org/pride-image.js +210 -0
- package/dist/agents/org/pride-image.js.map +1 -0
- package/dist/agents/org/pride-taunts.d.ts +47 -0
- package/dist/agents/org/pride-taunts.d.ts.map +1 -0
- package/dist/agents/org/pride-taunts.js +411 -0
- package/dist/agents/org/pride-taunts.js.map +1 -0
- package/dist/agents/org/pride-template.d.ts +272 -0
- package/dist/agents/org/pride-template.d.ts.map +1 -0
- package/dist/agents/org/pride-template.js +892 -0
- package/dist/agents/org/pride-template.js.map +1 -0
- package/dist/agents/org/pride-themes.d.ts +80 -0
- package/dist/agents/org/pride-themes.d.ts.map +1 -0
- package/dist/agents/org/pride-themes.js +7596 -0
- package/dist/agents/org/pride-themes.js.map +1 -0
- package/dist/agents/org/structured-errors.d.ts +47 -0
- package/dist/agents/org/structured-errors.d.ts.map +1 -0
- package/dist/agents/org/structured-errors.js +97 -0
- package/dist/agents/org/structured-errors.js.map +1 -0
- package/dist/agents/org/types.d.ts +139 -0
- package/dist/agents/org/types.d.ts.map +1 -0
- package/dist/agents/org/types.js +43 -0
- package/dist/agents/org/types.js.map +1 -0
- package/dist/agents/org/validate.d.ts +36 -0
- package/dist/agents/org/validate.d.ts.map +1 -0
- package/dist/agents/org/validate.js +135 -0
- package/dist/agents/org/validate.js.map +1 -0
- package/dist/agents/path-write-guard.d.ts +82 -0
- package/dist/agents/path-write-guard.d.ts.map +1 -0
- package/dist/agents/path-write-guard.js +722 -0
- package/dist/agents/path-write-guard.js.map +1 -0
- package/dist/agents/payload-mutators.d.ts +175 -0
- package/dist/agents/payload-mutators.d.ts.map +1 -0
- package/dist/agents/payload-mutators.js +994 -0
- package/dist/agents/payload-mutators.js.map +1 -0
- package/dist/agents/pending-system-events.d.ts +76 -0
- package/dist/agents/pending-system-events.d.ts.map +1 -0
- package/dist/agents/pending-system-events.js +115 -0
- package/dist/agents/pending-system-events.js.map +1 -0
- package/dist/agents/provider-attribution.d.ts +19 -0
- package/dist/agents/provider-attribution.d.ts.map +1 -0
- package/dist/agents/provider-attribution.js +62 -0
- package/dist/agents/provider-attribution.js.map +1 -0
- package/dist/agents/quality/slop-detector.d.ts +40 -0
- package/dist/agents/quality/slop-detector.d.ts.map +1 -0
- package/dist/agents/quality/slop-detector.js +108 -0
- package/dist/agents/quality/slop-detector.js.map +1 -0
- package/dist/agents/quality/slop-index.d.ts +27 -0
- package/dist/agents/quality/slop-index.d.ts.map +1 -0
- package/dist/agents/quality/slop-index.js +124 -0
- package/dist/agents/quality/slop-index.js.map +1 -0
- package/dist/agents/retry-policy.d.ts +38 -0
- package/dist/agents/retry-policy.d.ts.map +1 -0
- package/dist/agents/retry-policy.js +276 -0
- package/dist/agents/retry-policy.js.map +1 -0
- package/dist/agents/routing/account-id.d.ts +43 -0
- package/dist/agents/routing/account-id.d.ts.map +1 -0
- package/dist/agents/routing/account-id.js +103 -0
- package/dist/agents/routing/account-id.js.map +1 -0
- package/dist/agents/routing/bindings.d.ts +20 -0
- package/dist/agents/routing/bindings.d.ts.map +1 -0
- package/dist/agents/routing/bindings.js +22 -0
- package/dist/agents/routing/bindings.js.map +1 -0
- package/dist/agents/routing/dm-scope-warning.d.ts +37 -0
- package/dist/agents/routing/dm-scope-warning.d.ts.map +1 -0
- package/dist/agents/routing/dm-scope-warning.js +110 -0
- package/dist/agents/routing/dm-scope-warning.js.map +1 -0
- package/dist/agents/routing/identity-links.d.ts +45 -0
- package/dist/agents/routing/identity-links.d.ts.map +1 -0
- package/dist/agents/routing/identity-links.js +85 -0
- package/dist/agents/routing/identity-links.js.map +1 -0
- package/dist/agents/routing/resolve-route.d.ts +91 -0
- package/dist/agents/routing/resolve-route.d.ts.map +1 -0
- package/dist/agents/routing/resolve-route.js +653 -0
- package/dist/agents/routing/resolve-route.js.map +1 -0
- package/dist/agents/routing/session-key.d.ts +168 -0
- package/dist/agents/routing/session-key.d.ts.map +1 -0
- package/dist/agents/routing/session-key.js +268 -0
- package/dist/agents/routing/session-key.js.map +1 -0
- package/dist/agents/sanitize-surrogates.d.ts +30 -0
- package/dist/agents/sanitize-surrogates.d.ts.map +1 -0
- package/dist/agents/sanitize-surrogates.js +56 -0
- package/dist/agents/sanitize-surrogates.js.map +1 -0
- package/dist/agents/session-context.d.ts +80 -0
- package/dist/agents/session-context.d.ts.map +1 -0
- package/dist/agents/session-context.js +76 -0
- package/dist/agents/session-context.js.map +1 -0
- package/dist/agents/session-event-prompt.d.ts +124 -0
- package/dist/agents/session-event-prompt.d.ts.map +1 -0
- package/dist/agents/session-event-prompt.js +179 -0
- package/dist/agents/session-event-prompt.js.map +1 -0
- package/dist/agents/session-inbox.d.ts +129 -0
- package/dist/agents/session-inbox.d.ts.map +1 -0
- package/dist/agents/session-inbox.js +492 -0
- package/dist/agents/session-inbox.js.map +1 -0
- package/dist/agents/session-registry.d.ts +148 -0
- package/dist/agents/session-registry.d.ts.map +1 -0
- package/dist/agents/session-registry.js +405 -0
- package/dist/agents/session-registry.js.map +1 -0
- package/dist/agents/session-wiring.d.ts +214 -0
- package/dist/agents/session-wiring.d.ts.map +1 -0
- package/dist/agents/session-wiring.js +278 -0
- package/dist/agents/session-wiring.js.map +1 -0
- package/dist/agents/session-write-lock.d.ts +15 -0
- package/dist/agents/session-write-lock.d.ts.map +1 -0
- package/dist/agents/session-write-lock.js +15 -0
- package/dist/agents/session-write-lock.js.map +1 -0
- package/dist/agents/skills/agent-filter.d.ts +43 -0
- package/dist/agents/skills/agent-filter.d.ts.map +1 -0
- package/dist/agents/skills/agent-filter.js +89 -0
- package/dist/agents/skills/agent-filter.js.map +1 -0
- package/dist/agents/skills/discovery.d.ts +97 -0
- package/dist/agents/skills/discovery.d.ts.map +1 -0
- package/dist/agents/skills/discovery.js +136 -0
- package/dist/agents/skills/discovery.js.map +1 -0
- package/dist/agents/skills/eligibility.d.ts +118 -0
- package/dist/agents/skills/eligibility.d.ts.map +1 -0
- package/dist/agents/skills/eligibility.js +280 -0
- package/dist/agents/skills/eligibility.js.map +1 -0
- package/dist/agents/skills/grant.d.ts +70 -0
- package/dist/agents/skills/grant.d.ts.map +1 -0
- package/dist/agents/skills/grant.js +106 -0
- package/dist/agents/skills/grant.js.map +1 -0
- package/dist/agents/skills/index.d.ts +35 -0
- package/dist/agents/skills/index.d.ts.map +1 -0
- package/dist/agents/skills/index.js +88 -0
- package/dist/agents/skills/index.js.map +1 -0
- package/dist/agents/skills/install-spec.d.ts +51 -0
- package/dist/agents/skills/install-spec.d.ts.map +1 -0
- package/dist/agents/skills/install-spec.js +21 -0
- package/dist/agents/skills/install-spec.js.map +1 -0
- package/dist/agents/skills/install.d.ts +68 -0
- package/dist/agents/skills/install.d.ts.map +1 -0
- package/dist/agents/skills/install.js +206 -0
- package/dist/agents/skills/install.js.map +1 -0
- package/dist/agents/skills/org-access.d.ts +27 -0
- package/dist/agents/skills/org-access.d.ts.map +1 -0
- package/dist/agents/skills/org-access.js +87 -0
- package/dist/agents/skills/org-access.js.map +1 -0
- package/dist/agents/skills/skill-consolidate.d.ts +76 -0
- package/dist/agents/skills/skill-consolidate.d.ts.map +1 -0
- package/dist/agents/skills/skill-consolidate.js +264 -0
- package/dist/agents/skills/skill-consolidate.js.map +1 -0
- package/dist/agents/skills/skill-curator.d.ts +91 -0
- package/dist/agents/skills/skill-curator.d.ts.map +1 -0
- package/dist/agents/skills/skill-curator.js +239 -0
- package/dist/agents/skills/skill-curator.js.map +1 -0
- package/dist/agents/skills/skill-manifest.d.ts +35 -0
- package/dist/agents/skills/skill-manifest.d.ts.map +1 -0
- package/dist/agents/skills/skill-manifest.js +82 -0
- package/dist/agents/skills/skill-manifest.js.map +1 -0
- package/dist/agents/skills/skill-review.d.ts +91 -0
- package/dist/agents/skills/skill-review.d.ts.map +1 -0
- package/dist/agents/skills/skill-review.js +271 -0
- package/dist/agents/skills/skill-review.js.map +1 -0
- package/dist/agents/skills/skill-usage.d.ts +81 -0
- package/dist/agents/skills/skill-usage.d.ts.map +1 -0
- package/dist/agents/skills/skill-usage.js +208 -0
- package/dist/agents/skills/skill-usage.js.map +1 -0
- package/dist/agents/skills/status.d.ts +68 -0
- package/dist/agents/skills/status.d.ts.map +1 -0
- package/dist/agents/skills/status.js +147 -0
- package/dist/agents/skills/status.js.map +1 -0
- package/dist/agents/skills/update-config.d.ts +32 -0
- package/dist/agents/skills/update-config.d.ts.map +1 -0
- package/dist/agents/skills/update-config.js +53 -0
- package/dist/agents/skills/update-config.js.map +1 -0
- package/dist/agents/slash-commands.d.ts +25 -0
- package/dist/agents/slash-commands.d.ts.map +1 -0
- package/dist/agents/slash-commands.js +151 -0
- package/dist/agents/slash-commands.js.map +1 -0
- package/dist/agents/smart-compaction.d.ts +105 -0
- package/dist/agents/smart-compaction.d.ts.map +1 -0
- package/dist/agents/smart-compaction.js +355 -0
- package/dist/agents/smart-compaction.js.map +1 -0
- package/dist/agents/stream-wrappers.d.ts +20 -0
- package/dist/agents/stream-wrappers.d.ts.map +1 -0
- package/dist/agents/stream-wrappers.js +307 -0
- package/dist/agents/stream-wrappers.js.map +1 -0
- package/dist/agents/subagent-abort-cascade.d.ts +31 -0
- package/dist/agents/subagent-abort-cascade.d.ts.map +1 -0
- package/dist/agents/subagent-abort-cascade.js +124 -0
- package/dist/agents/subagent-abort-cascade.js.map +1 -0
- package/dist/agents/subagent-announce-delivery.d.ts +83 -0
- package/dist/agents/subagent-announce-delivery.d.ts.map +1 -0
- package/dist/agents/subagent-announce-delivery.js +159 -0
- package/dist/agents/subagent-announce-delivery.js.map +1 -0
- package/dist/agents/subagent-budget.d.ts +36 -0
- package/dist/agents/subagent-budget.d.ts.map +1 -0
- package/dist/agents/subagent-budget.js +93 -0
- package/dist/agents/subagent-budget.js.map +1 -0
- package/dist/agents/subagent-completion-bridge.d.ts +42 -0
- package/dist/agents/subagent-completion-bridge.d.ts.map +1 -0
- package/dist/agents/subagent-completion-bridge.js +338 -0
- package/dist/agents/subagent-completion-bridge.js.map +1 -0
- package/dist/agents/subagent-lifecycle-events.d.ts +31 -0
- package/dist/agents/subagent-lifecycle-events.d.ts.map +1 -0
- package/dist/agents/subagent-lifecycle-events.js +21 -0
- package/dist/agents/subagent-lifecycle-events.js.map +1 -0
- package/dist/agents/subagent-policy.d.ts +206 -0
- package/dist/agents/subagent-policy.d.ts.map +1 -0
- package/dist/agents/subagent-policy.js +295 -0
- package/dist/agents/subagent-policy.js.map +1 -0
- package/dist/agents/subagent-registry-completion.d.ts +69 -0
- package/dist/agents/subagent-registry-completion.d.ts.map +1 -0
- package/dist/agents/subagent-registry-completion.js +128 -0
- package/dist/agents/subagent-registry-completion.js.map +1 -0
- package/dist/agents/subagent-registry.d.ts +85 -0
- package/dist/agents/subagent-registry.d.ts.map +1 -0
- package/dist/agents/subagent-registry.js +215 -0
- package/dist/agents/subagent-registry.js.map +1 -0
- package/dist/agents/subagent-registry.types.d.ts +94 -0
- package/dist/agents/subagent-registry.types.d.ts.map +1 -0
- package/dist/agents/subagent-registry.types.js +19 -0
- package/dist/agents/subagent-registry.types.js.map +1 -0
- package/dist/agents/subagent-runner.d.ts +75 -0
- package/dist/agents/subagent-runner.d.ts.map +1 -0
- package/dist/agents/subagent-runner.js +358 -0
- package/dist/agents/subagent-runner.js.map +1 -0
- package/dist/agents/subagent-spawn-abort-marker.d.ts +46 -0
- package/dist/agents/subagent-spawn-abort-marker.d.ts.map +1 -0
- package/dist/agents/subagent-spawn-abort-marker.js +81 -0
- package/dist/agents/subagent-spawn-abort-marker.js.map +1 -0
- package/dist/agents/subagent-spawn.d.ts +104 -0
- package/dist/agents/subagent-spawn.d.ts.map +1 -0
- package/dist/agents/subagent-spawn.js +358 -0
- package/dist/agents/subagent-spawn.js.map +1 -0
- package/dist/agents/thinking-fallback.d.ts +49 -0
- package/dist/agents/thinking-fallback.d.ts.map +1 -0
- package/dist/agents/thinking-fallback.js +97 -0
- package/dist/agents/thinking-fallback.js.map +1 -0
- package/dist/agents/tool-guard.d.ts +71 -0
- package/dist/agents/tool-guard.d.ts.map +1 -0
- package/dist/agents/tool-guard.js +154 -0
- package/dist/agents/tool-guard.js.map +1 -0
- package/dist/agents/tool-loop-detector.d.ts +115 -0
- package/dist/agents/tool-loop-detector.d.ts.map +1 -0
- package/dist/agents/tool-loop-detector.js +0 -0
- package/dist/agents/tool-loop-detector.js.map +1 -0
- package/dist/agents/tool-summaries.d.ts +3 -0
- package/dist/agents/tool-summaries.d.ts.map +1 -0
- package/dist/agents/tool-summaries.js +78 -0
- package/dist/agents/tool-summaries.js.map +1 -0
- package/dist/agents/tools/agents-list-tool.d.ts +51 -0
- package/dist/agents/tools/agents-list-tool.d.ts.map +1 -0
- package/dist/agents/tools/agents-list-tool.js +167 -0
- package/dist/agents/tools/agents-list-tool.js.map +1 -0
- package/dist/agents/tools/browser.d.ts +144 -0
- package/dist/agents/tools/browser.d.ts.map +1 -0
- package/dist/agents/tools/browser.js +1538 -0
- package/dist/agents/tools/browser.js.map +1 -0
- package/dist/agents/tools/common.d.ts +208 -0
- package/dist/agents/tools/common.d.ts.map +1 -0
- package/dist/agents/tools/common.js +405 -0
- package/dist/agents/tools/common.js.map +1 -0
- package/dist/agents/tools/composio-tool.d.ts +179 -0
- package/dist/agents/tools/composio-tool.d.ts.map +1 -0
- package/dist/agents/tools/composio-tool.js +474 -0
- package/dist/agents/tools/composio-tool.js.map +1 -0
- package/dist/agents/tools/cron-tool.d.ts +187 -0
- package/dist/agents/tools/cron-tool.d.ts.map +1 -0
- package/dist/agents/tools/cron-tool.js +985 -0
- package/dist/agents/tools/cron-tool.js.map +1 -0
- package/dist/agents/tools/find-tool.d.ts +55 -0
- package/dist/agents/tools/find-tool.d.ts.map +1 -0
- package/dist/agents/tools/find-tool.js +163 -0
- package/dist/agents/tools/find-tool.js.map +1 -0
- package/dist/agents/tools/generate-image-tool.d.ts +77 -0
- package/dist/agents/tools/generate-image-tool.d.ts.map +1 -0
- package/dist/agents/tools/generate-image-tool.js +421 -0
- package/dist/agents/tools/generate-image-tool.js.map +1 -0
- package/dist/agents/tools/index.d.ts +14 -0
- package/dist/agents/tools/index.d.ts.map +1 -0
- package/dist/agents/tools/index.js +12 -0
- package/dist/agents/tools/index.js.map +1 -0
- package/dist/agents/tools/manage-access-tool.d.ts +64 -0
- package/dist/agents/tools/manage-access-tool.d.ts.map +1 -0
- package/dist/agents/tools/manage-access-tool.js +188 -0
- package/dist/agents/tools/manage-access-tool.js.map +1 -0
- package/dist/agents/tools/manage-agent-tool.d.ts +50 -0
- package/dist/agents/tools/manage-agent-tool.d.ts.map +1 -0
- package/dist/agents/tools/manage-agent-tool.js +232 -0
- package/dist/agents/tools/manage-agent-tool.js.map +1 -0
- package/dist/agents/tools/manage-channel-access-tool.d.ts +44 -0
- package/dist/agents/tools/manage-channel-access-tool.d.ts.map +1 -0
- package/dist/agents/tools/manage-channel-access-tool.js +144 -0
- package/dist/agents/tools/manage-channel-access-tool.js.map +1 -0
- package/dist/agents/tools/manage-memory-tool.d.ts +30 -0
- package/dist/agents/tools/manage-memory-tool.d.ts.map +1 -0
- package/dist/agents/tools/manage-memory-tool.js +309 -0
- package/dist/agents/tools/manage-memory-tool.js.map +1 -0
- package/dist/agents/tools/manage-provider-tool.d.ts +65 -0
- package/dist/agents/tools/manage-provider-tool.d.ts.map +1 -0
- package/dist/agents/tools/manage-provider-tool.js +249 -0
- package/dist/agents/tools/manage-provider-tool.js.map +1 -0
- package/dist/agents/tools/manage-skill-tool.d.ts +121 -0
- package/dist/agents/tools/manage-skill-tool.d.ts.map +1 -0
- package/dist/agents/tools/manage-skill-tool.js +722 -0
- package/dist/agents/tools/manage-skill-tool.js.map +1 -0
- package/dist/agents/tools/memory-tools.d.ts +172 -0
- package/dist/agents/tools/memory-tools.d.ts.map +1 -0
- package/dist/agents/tools/memory-tools.js +561 -0
- package/dist/agents/tools/memory-tools.js.map +1 -0
- package/dist/agents/tools/oauth-authorize-tool.d.ts +94 -0
- package/dist/agents/tools/oauth-authorize-tool.d.ts.map +1 -0
- package/dist/agents/tools/oauth-authorize-tool.js +670 -0
- package/dist/agents/tools/oauth-authorize-tool.js.map +1 -0
- package/dist/agents/tools/org-tool.d.ts +208 -0
- package/dist/agents/tools/org-tool.d.ts.map +1 -0
- package/dist/agents/tools/org-tool.js +790 -0
- package/dist/agents/tools/org-tool.js.map +1 -0
- package/dist/agents/tools/registry.d.ts +146 -0
- package/dist/agents/tools/registry.d.ts.map +1 -0
- package/dist/agents/tools/registry.js +396 -0
- package/dist/agents/tools/registry.js.map +1 -0
- package/dist/agents/tools/send-media-tool.d.ts +92 -0
- package/dist/agents/tools/send-media-tool.d.ts.map +1 -0
- package/dist/agents/tools/send-media-tool.js +512 -0
- package/dist/agents/tools/send-media-tool.js.map +1 -0
- package/dist/agents/tools/send-message-tool.d.ts +84 -0
- package/dist/agents/tools/send-message-tool.d.ts.map +1 -0
- package/dist/agents/tools/send-message-tool.js +226 -0
- package/dist/agents/tools/send-message-tool.js.map +1 -0
- package/dist/agents/tools/sessions/history.d.ts +53 -0
- package/dist/agents/tools/sessions/history.d.ts.map +1 -0
- package/dist/agents/tools/sessions/history.js +138 -0
- package/dist/agents/tools/sessions/history.js.map +1 -0
- package/dist/agents/tools/sessions/index.d.ts +92 -0
- package/dist/agents/tools/sessions/index.d.ts.map +1 -0
- package/dist/agents/tools/sessions/index.js +125 -0
- package/dist/agents/tools/sessions/index.js.map +1 -0
- package/dist/agents/tools/sessions/list.d.ts +53 -0
- package/dist/agents/tools/sessions/list.d.ts.map +1 -0
- package/dist/agents/tools/sessions/list.js +134 -0
- package/dist/agents/tools/sessions/list.js.map +1 -0
- package/dist/agents/tools/sessions/resolve-access.d.ts +34 -0
- package/dist/agents/tools/sessions/resolve-access.d.ts.map +1 -0
- package/dist/agents/tools/sessions/resolve-access.js +67 -0
- package/dist/agents/tools/sessions/resolve-access.js.map +1 -0
- package/dist/agents/tools/sessions/send.d.ts +68 -0
- package/dist/agents/tools/sessions/send.d.ts.map +1 -0
- package/dist/agents/tools/sessions/send.js +556 -0
- package/dist/agents/tools/sessions/send.js.map +1 -0
- package/dist/agents/tools/sessions/shared.d.ts +145 -0
- package/dist/agents/tools/sessions/shared.d.ts.map +1 -0
- package/dist/agents/tools/sessions/shared.js +352 -0
- package/dist/agents/tools/sessions/shared.js.map +1 -0
- package/dist/agents/tools/sessions/spawn.d.ts +71 -0
- package/dist/agents/tools/sessions/spawn.d.ts.map +1 -0
- package/dist/agents/tools/sessions/spawn.js +132 -0
- package/dist/agents/tools/sessions/spawn.js.map +1 -0
- package/dist/agents/tools/spawn-agent-tool.d.ts +87 -0
- package/dist/agents/tools/spawn-agent-tool.d.ts.map +1 -0
- package/dist/agents/tools/spawn-agent-tool.js +189 -0
- package/dist/agents/tools/spawn-agent-tool.js.map +1 -0
- package/dist/agents/tools/spawn-agents-tool.d.ts +75 -0
- package/dist/agents/tools/spawn-agents-tool.d.ts.map +1 -0
- package/dist/agents/tools/spawn-agents-tool.js +267 -0
- package/dist/agents/tools/spawn-agents-tool.js.map +1 -0
- package/dist/agents/tools/types.d.ts +55 -0
- package/dist/agents/tools/types.d.ts.map +1 -0
- package/dist/agents/tools/types.js +28 -0
- package/dist/agents/tools/types.js.map +1 -0
- package/dist/agents/tools/web-fetch-utils.d.ts +114 -0
- package/dist/agents/tools/web-fetch-utils.d.ts.map +1 -0
- package/dist/agents/tools/web-fetch-utils.js +560 -0
- package/dist/agents/tools/web-fetch-utils.js.map +1 -0
- package/dist/agents/tools/web-fetch.d.ts +97 -0
- package/dist/agents/tools/web-fetch.d.ts.map +1 -0
- package/dist/agents/tools/web-fetch.js +369 -0
- package/dist/agents/tools/web-fetch.js.map +1 -0
- package/dist/agents/tools/web-retry.d.ts +55 -0
- package/dist/agents/tools/web-retry.d.ts.map +1 -0
- package/dist/agents/tools/web-retry.js +172 -0
- package/dist/agents/tools/web-retry.js.map +1 -0
- package/dist/agents/tools/web-search.d.ts +96 -0
- package/dist/agents/tools/web-search.d.ts.map +1 -0
- package/dist/agents/tools/web-search.js +459 -0
- package/dist/agents/tools/web-search.js.map +1 -0
- package/dist/agents/tools/web-shared.d.ts +123 -0
- package/dist/agents/tools/web-shared.d.ts.map +1 -0
- package/dist/agents/tools/web-shared.js +207 -0
- package/dist/agents/tools/web-shared.js.map +1 -0
- package/dist/assets/brigade-favicon.png +0 -0
- package/dist/auth/profile-cooldown.d.ts +105 -0
- package/dist/auth/profile-cooldown.d.ts.map +1 -0
- package/dist/auth/profile-cooldown.js +466 -0
- package/dist/auth/profile-cooldown.js.map +1 -0
- package/dist/auth/profiles.d.ts +93 -0
- package/dist/auth/profiles.d.ts.map +1 -0
- package/dist/auth/profiles.js +321 -0
- package/dist/auth/profiles.js.map +1 -0
- package/dist/buildstamp.json +1 -0
- package/dist/cli/argv.d.ts +20 -0
- package/dist/cli/argv.d.ts.map +1 -0
- package/dist/cli/argv.js +47 -0
- package/dist/cli/argv.js.map +1 -0
- package/dist/cli/commands/agent.d.ts +19 -0
- package/dist/cli/commands/agent.d.ts.map +1 -0
- package/dist/cli/commands/agent.js +297 -0
- package/dist/cli/commands/agent.js.map +1 -0
- package/dist/cli/commands/agents-bindings.d.ts +80 -0
- package/dist/cli/commands/agents-bindings.d.ts.map +1 -0
- package/dist/cli/commands/agents-bindings.js +252 -0
- package/dist/cli/commands/agents-bindings.js.map +1 -0
- package/dist/cli/commands/agents-cmd.d.ts +160 -0
- package/dist/cli/commands/agents-cmd.d.ts.map +1 -0
- package/dist/cli/commands/agents-cmd.js +1199 -0
- package/dist/cli/commands/agents-cmd.js.map +1 -0
- package/dist/cli/commands/agents-config.d.ts +102 -0
- package/dist/cli/commands/agents-config.d.ts.map +1 -0
- package/dist/cli/commands/agents-config.js +294 -0
- package/dist/cli/commands/agents-config.js.map +1 -0
- package/dist/cli/commands/agents-shared.d.ts +57 -0
- package/dist/cli/commands/agents-shared.d.ts.map +1 -0
- package/dist/cli/commands/agents-shared.js +83 -0
- package/dist/cli/commands/agents-shared.js.map +1 -0
- package/dist/cli/commands/backup.d.ts +36 -0
- package/dist/cli/commands/backup.d.ts.map +1 -0
- package/dist/cli/commands/backup.js +244 -0
- package/dist/cli/commands/backup.js.map +1 -0
- package/dist/cli/commands/channels.d.ts +106 -0
- package/dist/cli/commands/channels.d.ts.map +1 -0
- package/dist/cli/commands/channels.js +830 -0
- package/dist/cli/commands/channels.js.map +1 -0
- package/dist/cli/commands/chat.d.ts +43 -0
- package/dist/cli/commands/chat.d.ts.map +1 -0
- package/dist/cli/commands/chat.js +84 -0
- package/dist/cli/commands/chat.js.map +1 -0
- package/dist/cli/commands/config-cmd.d.ts +62 -0
- package/dist/cli/commands/config-cmd.d.ts.map +1 -0
- package/dist/cli/commands/config-cmd.js +404 -0
- package/dist/cli/commands/config-cmd.js.map +1 -0
- package/dist/cli/commands/connect.d.ts +73 -0
- package/dist/cli/commands/connect.d.ts.map +1 -0
- package/dist/cli/commands/connect.js +1952 -0
- package/dist/cli/commands/connect.js.map +1 -0
- package/dist/cli/commands/cron.d.ts +58 -0
- package/dist/cli/commands/cron.d.ts.map +1 -0
- package/dist/cli/commands/cron.js +250 -0
- package/dist/cli/commands/cron.js.map +1 -0
- package/dist/cli/commands/doctor.d.ts +25 -0
- package/dist/cli/commands/doctor.d.ts.map +1 -0
- package/dist/cli/commands/doctor.js +618 -0
- package/dist/cli/commands/doctor.js.map +1 -0
- package/dist/cli/commands/encrypt-cmd.d.ts +12 -0
- package/dist/cli/commands/encrypt-cmd.d.ts.map +1 -0
- package/dist/cli/commands/encrypt-cmd.js +119 -0
- package/dist/cli/commands/encrypt-cmd.js.map +1 -0
- package/dist/cli/commands/exec-cmd.d.ts +55 -0
- package/dist/cli/commands/exec-cmd.d.ts.map +1 -0
- package/dist/cli/commands/exec-cmd.js +253 -0
- package/dist/cli/commands/exec-cmd.js.map +1 -0
- package/dist/cli/commands/gateway-install.d.ts +21 -0
- package/dist/cli/commands/gateway-install.d.ts.map +1 -0
- package/dist/cli/commands/gateway-install.js +71 -0
- package/dist/cli/commands/gateway-install.js.map +1 -0
- package/dist/cli/commands/gateway-supervise.d.ts +102 -0
- package/dist/cli/commands/gateway-supervise.d.ts.map +1 -0
- package/dist/cli/commands/gateway-supervise.js +194 -0
- package/dist/cli/commands/gateway-supervise.js.map +1 -0
- package/dist/cli/commands/gateway.d.ts +58 -0
- package/dist/cli/commands/gateway.d.ts.map +1 -0
- package/dist/cli/commands/gateway.js +497 -0
- package/dist/cli/commands/gateway.js.map +1 -0
- package/dist/cli/commands/logs.d.ts +14 -0
- package/dist/cli/commands/logs.d.ts.map +1 -0
- package/dist/cli/commands/logs.js +93 -0
- package/dist/cli/commands/logs.js.map +1 -0
- package/dist/cli/commands/mcp-cmd.d.ts +4 -0
- package/dist/cli/commands/mcp-cmd.d.ts.map +1 -0
- package/dist/cli/commands/mcp-cmd.js +30 -0
- package/dist/cli/commands/mcp-cmd.js.map +1 -0
- package/dist/cli/commands/onboard-config.d.ts +23 -0
- package/dist/cli/commands/onboard-config.d.ts.map +1 -0
- package/dist/cli/commands/onboard-config.js +33 -0
- package/dist/cli/commands/onboard-config.js.map +1 -0
- package/dist/cli/commands/onboard.d.ts +48 -0
- package/dist/cli/commands/onboard.d.ts.map +1 -0
- package/dist/cli/commands/onboard.js +397 -0
- package/dist/cli/commands/onboard.js.map +1 -0
- package/dist/cli/commands/org-cmd.d.ts +87 -0
- package/dist/cli/commands/org-cmd.d.ts.map +1 -0
- package/dist/cli/commands/org-cmd.js +394 -0
- package/dist/cli/commands/org-cmd.js.map +1 -0
- package/dist/cli/commands/org-cmd.templates.d.ts +66 -0
- package/dist/cli/commands/org-cmd.templates.d.ts.map +1 -0
- package/dist/cli/commands/org-cmd.templates.js +145 -0
- package/dist/cli/commands/org-cmd.templates.js.map +1 -0
- package/dist/cli/commands/org-slash.d.ts +107 -0
- package/dist/cli/commands/org-slash.d.ts.map +1 -0
- package/dist/cli/commands/org-slash.js +263 -0
- package/dist/cli/commands/org-slash.js.map +1 -0
- package/dist/cli/commands/pairing.d.ts +33 -0
- package/dist/cli/commands/pairing.d.ts.map +1 -0
- package/dist/cli/commands/pairing.js +155 -0
- package/dist/cli/commands/pairing.js.map +1 -0
- package/dist/cli/commands/secrets-audit.d.ts +17 -0
- package/dist/cli/commands/secrets-audit.d.ts.map +1 -0
- package/dist/cli/commands/secrets-audit.js +109 -0
- package/dist/cli/commands/secrets-audit.js.map +1 -0
- package/dist/cli/commands/sessions.d.ts +22 -0
- package/dist/cli/commands/sessions.d.ts.map +1 -0
- package/dist/cli/commands/sessions.js +99 -0
- package/dist/cli/commands/sessions.js.map +1 -0
- package/dist/cli/commands/skills.d.ts +17 -0
- package/dist/cli/commands/skills.d.ts.map +1 -0
- package/dist/cli/commands/skills.js +100 -0
- package/dist/cli/commands/skills.js.map +1 -0
- package/dist/cli/commands/status.d.ts +26 -0
- package/dist/cli/commands/status.d.ts.map +1 -0
- package/dist/cli/commands/status.js +252 -0
- package/dist/cli/commands/status.js.map +1 -0
- package/dist/cli/commands/store-cmd.d.ts +36 -0
- package/dist/cli/commands/store-cmd.d.ts.map +1 -0
- package/dist/cli/commands/store-cmd.js +405 -0
- package/dist/cli/commands/store-cmd.js.map +1 -0
- package/dist/cli/flows/web-setup.d.ts +47 -0
- package/dist/cli/flows/web-setup.d.ts.map +1 -0
- package/dist/cli/flows/web-setup.js +324 -0
- package/dist/cli/flows/web-setup.js.map +1 -0
- package/dist/cli/program/build-program.d.ts +3 -0
- package/dist/cli/program/build-program.d.ts.map +1 -0
- package/dist/cli/program/build-program.js +1326 -0
- package/dist/cli/program/build-program.js.map +1 -0
- package/dist/cli/run-main.d.ts +2 -0
- package/dist/cli/run-main.d.ts.map +1 -0
- package/dist/cli/run-main.js +63 -0
- package/dist/cli/run-main.js.map +1 -0
- package/dist/config/agent-limits.d.ts +22 -0
- package/dist/config/agent-limits.d.ts.map +1 -0
- package/dist/config/agent-limits.js +34 -0
- package/dist/config/agent-limits.js.map +1 -0
- package/dist/config/io.d.ts +378 -0
- package/dist/config/io.d.ts.map +1 -0
- package/dist/config/io.js +602 -0
- package/dist/config/io.js.map +1 -0
- package/dist/config/paths.d.ts +80 -0
- package/dist/config/paths.d.ts.map +1 -0
- package/dist/config/paths.js +342 -0
- package/dist/config/paths.js.map +1 -0
- package/dist/config/types.d.ts +12 -0
- package/dist/config/types.d.ts.map +1 -0
- package/dist/config/types.js +12 -0
- package/dist/config/types.js.map +1 -0
- package/dist/core/agent-dispatcher.d.ts +91 -0
- package/dist/core/agent-dispatcher.d.ts.map +1 -0
- package/dist/core/agent-dispatcher.js +251 -0
- package/dist/core/agent-dispatcher.js.map +1 -0
- package/dist/core/agent-events-stream.d.ts +76 -0
- package/dist/core/agent-events-stream.d.ts.map +1 -0
- package/dist/core/agent-events-stream.js +185 -0
- package/dist/core/agent-events-stream.js.map +1 -0
- package/dist/core/agent-runtime-persist.d.ts +53 -0
- package/dist/core/agent-runtime-persist.d.ts.map +1 -0
- package/dist/core/agent-runtime-persist.js +114 -0
- package/dist/core/agent-runtime-persist.js.map +1 -0
- package/dist/core/auth-bridge.d.ts +8 -0
- package/dist/core/auth-bridge.d.ts.map +1 -0
- package/dist/core/auth-bridge.js +102 -0
- package/dist/core/auth-bridge.js.map +1 -0
- package/dist/core/auth-error.d.ts +49 -0
- package/dist/core/auth-error.d.ts.map +1 -0
- package/dist/core/auth-error.js.map +1 -0
- package/dist/core/brigade-config.d.ts +205 -0
- package/dist/core/brigade-config.d.ts.map +1 -0
- package/dist/core/brigade-config.js +58 -6
- package/dist/core/brigade-config.js.map +1 -0
- package/dist/core/config.d.ts +17 -0
- package/dist/core/config.d.ts.map +1 -0
- package/dist/core/config.js +92 -246
- package/dist/core/config.js.map +1 -0
- package/dist/core/console-stream.d.ts +52 -0
- package/dist/core/console-stream.d.ts.map +1 -0
- package/dist/core/console-stream.js +49 -3
- package/dist/core/console-stream.js.map +1 -0
- package/dist/core/daemon/launchd.d.ts +19 -0
- package/dist/core/daemon/launchd.d.ts.map +1 -0
- package/dist/core/daemon/launchd.js +117 -0
- package/dist/core/daemon/launchd.js.map +1 -0
- package/dist/core/daemon/schtasks.d.ts +23 -0
- package/dist/core/daemon/schtasks.d.ts.map +1 -0
- package/dist/core/daemon/schtasks.js +139 -0
- package/dist/core/daemon/schtasks.js.map +1 -0
- package/dist/core/daemon/service.d.ts +56 -0
- package/dist/core/daemon/service.d.ts.map +1 -0
- package/dist/core/daemon/service.js +54 -0
- package/dist/core/daemon/service.js.map +1 -0
- package/dist/core/daemon/systemd.d.ts +19 -0
- package/dist/core/daemon/systemd.d.ts.map +1 -0
- package/dist/core/daemon/systemd.js +117 -0
- package/dist/core/daemon/systemd.js.map +1 -0
- package/dist/core/event-logger.d.ts +74 -0
- package/dist/core/event-logger.d.ts.map +1 -0
- package/dist/core/event-logger.js +299 -6
- package/dist/core/event-logger.js.map +1 -0
- package/dist/core/exec-approvals.d.ts +178 -0
- package/dist/core/exec-approvals.d.ts.map +1 -0
- package/dist/core/exec-approvals.js +591 -266
- package/dist/core/exec-approvals.js.map +1 -0
- package/dist/core/extension-lifecycle.d.ts +27 -0
- package/dist/core/extension-lifecycle.d.ts.map +1 -0
- package/dist/core/extension-lifecycle.js +45 -0
- package/dist/core/extension-lifecycle.js.map +1 -0
- package/dist/core/gateway-caller-impl.d.ts +42 -0
- package/dist/core/gateway-caller-impl.d.ts.map +1 -0
- package/dist/core/gateway-caller-impl.js +95 -0
- package/dist/core/gateway-caller-impl.js.map +1 -0
- package/dist/core/gateway-lock.d.ts +88 -0
- package/dist/core/gateway-lock.d.ts.map +1 -0
- package/dist/core/gateway-lock.js +204 -0
- package/dist/core/gateway-lock.js.map +1 -0
- package/dist/core/gateway-probe.d.ts +148 -0
- package/dist/core/gateway-probe.d.ts.map +1 -0
- package/dist/core/gateway-probe.js +319 -0
- package/dist/core/gateway-probe.js.map +1 -0
- package/dist/core/gateway-spawn.d.ts +40 -0
- package/dist/core/gateway-spawn.d.ts.map +1 -0
- package/dist/core/gateway-spawn.js +156 -0
- package/dist/core/gateway-spawn.js.map +1 -0
- package/dist/core/model-caps.d.ts +85 -0
- package/dist/core/model-caps.d.ts.map +1 -0
- package/dist/core/model-caps.js +88 -2
- package/dist/core/model-caps.js.map +1 -0
- package/dist/core/port-inspect.d.ts +37 -0
- package/dist/core/port-inspect.d.ts.map +1 -0
- package/dist/core/port-inspect.js +165 -0
- package/dist/core/port-inspect.js.map +1 -0
- package/dist/core/server-lanes.d.ts +25 -0
- package/dist/core/server-lanes.d.ts.map +1 -0
- package/dist/core/server-lanes.js +31 -0
- package/dist/core/server-lanes.js.map +1 -0
- package/dist/core/server-methods/cron.d.ts +104 -0
- package/dist/core/server-methods/cron.d.ts.map +1 -0
- package/dist/core/server-methods/cron.js +183 -0
- package/dist/core/server-methods/cron.js.map +1 -0
- package/dist/core/server-methods/health.d.ts +36 -0
- package/dist/core/server-methods/health.d.ts.map +1 -0
- package/dist/core/server-methods/health.js +51 -0
- package/dist/core/server-methods/health.js.map +1 -0
- package/dist/core/server-methods/org.d.ts +93 -0
- package/dist/core/server-methods/org.d.ts.map +1 -0
- package/dist/core/server-methods/org.js +95 -0
- package/dist/core/server-methods/org.js.map +1 -0
- package/dist/core/server-methods/sessions.d.ts +133 -0
- package/dist/core/server-methods/sessions.d.ts.map +1 -0
- package/dist/core/server-methods/sessions.js +209 -0
- package/dist/core/server-methods/sessions.js.map +1 -0
- package/dist/core/server.d.ts +46 -0
- package/dist/core/server.d.ts.map +1 -0
- package/dist/core/server.js +4716 -249
- package/dist/core/server.js.map +1 -0
- package/dist/core/system-prompt.d.ts +92 -0
- package/dist/core/system-prompt.d.ts.map +1 -0
- package/dist/core/system-prompt.js +180 -1584
- package/dist/core/system-prompt.js.map +1 -0
- package/dist/core/version.d.ts +4 -0
- package/dist/core/version.d.ts.map +1 -0
- package/dist/core/version.js +8 -13
- package/dist/core/version.js.map +1 -0
- package/dist/core/webhook-guards.d.ts +131 -0
- package/dist/core/webhook-guards.d.ts.map +1 -0
- package/dist/core/webhook-guards.js +283 -0
- package/dist/core/webhook-guards.js.map +1 -0
- package/dist/core/ws-subscription-filter.d.ts +9 -0
- package/dist/core/ws-subscription-filter.d.ts.map +1 -0
- package/dist/core/ws-subscription-filter.js +39 -0
- package/dist/core/ws-subscription-filter.js.map +1 -0
- package/dist/cron/active-service.d.ts +30 -0
- package/dist/cron/active-service.d.ts.map +1 -0
- package/dist/cron/active-service.js +48 -0
- package/dist/cron/active-service.js.map +1 -0
- package/dist/cron/isolated-agent/run-executor.d.ts +49 -0
- package/dist/cron/isolated-agent/run-executor.d.ts.map +1 -0
- package/dist/cron/isolated-agent/run-executor.js +343 -0
- package/dist/cron/isolated-agent/run-executor.js.map +1 -0
- package/dist/cron/isolated-agent/run.d.ts +27 -0
- package/dist/cron/isolated-agent/run.d.ts.map +1 -0
- package/dist/cron/isolated-agent/run.js +29 -0
- package/dist/cron/isolated-agent/run.js.map +1 -0
- package/dist/cron/normalize.d.ts +103 -0
- package/dist/cron/normalize.d.ts.map +1 -0
- package/dist/cron/normalize.js +376 -0
- package/dist/cron/normalize.js.map +1 -0
- package/dist/cron/parse.d.ts +27 -0
- package/dist/cron/parse.d.ts.map +1 -0
- package/dist/cron/parse.js +55 -0
- package/dist/cron/parse.js.map +1 -0
- package/dist/cron/reminder-context.d.ts +78 -0
- package/dist/cron/reminder-context.d.ts.map +1 -0
- package/dist/cron/reminder-context.js +167 -0
- package/dist/cron/reminder-context.js.map +1 -0
- package/dist/cron/run-log.d.ts +48 -0
- package/dist/cron/run-log.d.ts.map +1 -0
- package/dist/cron/run-log.js +225 -0
- package/dist/cron/run-log.js.map +1 -0
- package/dist/cron/schedule.d.ts +46 -0
- package/dist/cron/schedule.d.ts.map +1 -0
- package/dist/cron/schedule.js +144 -0
- package/dist/cron/schedule.js.map +1 -0
- package/dist/cron/service/jobs.d.ts +138 -0
- package/dist/cron/service/jobs.d.ts.map +1 -0
- package/dist/cron/service/jobs.js +370 -0
- package/dist/cron/service/jobs.js.map +1 -0
- package/dist/cron/service/locked.d.ts +46 -0
- package/dist/cron/service/locked.d.ts.map +1 -0
- package/dist/cron/service/locked.js +54 -0
- package/dist/cron/service/locked.js.map +1 -0
- package/dist/cron/service/ops.d.ts +124 -0
- package/dist/cron/service/ops.d.ts.map +1 -0
- package/dist/cron/service/ops.js +415 -0
- package/dist/cron/service/ops.js.map +1 -0
- package/dist/cron/service/state.d.ts +254 -0
- package/dist/cron/service/state.d.ts.map +1 -0
- package/dist/cron/service/state.js +50 -0
- package/dist/cron/service/state.js.map +1 -0
- package/dist/cron/service/store.d.ts +65 -0
- package/dist/cron/service/store.d.ts.map +1 -0
- package/dist/cron/service/store.js +350 -0
- package/dist/cron/service/store.js.map +1 -0
- package/dist/cron/service/timer.d.ts +113 -0
- package/dist/cron/service/timer.d.ts.map +1 -0
- package/dist/cron/service/timer.js +1081 -0
- package/dist/cron/service/timer.js.map +1 -0
- package/dist/cron/session-reaper.d.ts +62 -0
- package/dist/cron/session-reaper.d.ts.map +1 -0
- package/dist/cron/session-reaper.js +152 -0
- package/dist/cron/session-reaper.js.map +1 -0
- package/dist/cron/session-target.d.ts +56 -0
- package/dist/cron/session-target.d.ts.map +1 -0
- package/dist/cron/session-target.js +96 -0
- package/dist/cron/session-target.js.map +1 -0
- package/dist/cron/stagger.d.ts +34 -0
- package/dist/cron/stagger.d.ts.map +1 -0
- package/dist/cron/stagger.js +69 -0
- package/dist/cron/stagger.js.map +1 -0
- package/dist/cron/types.d.ts +287 -0
- package/dist/cron/types.d.ts.map +1 -0
- package/dist/cron/types.js +22 -0
- package/dist/cron/types.js.map +1 -0
- package/dist/cron/validate-timestamp.d.ts +33 -0
- package/dist/cron/validate-timestamp.d.ts.map +1 -0
- package/dist/cron/validate-timestamp.js +54 -0
- package/dist/cron/validate-timestamp.js.map +1 -0
- package/dist/entry.d.ts +2 -0
- package/dist/entry.d.ts.map +1 -0
- package/dist/entry.js +57 -0
- package/dist/entry.js.map +1 -0
- package/dist/extension-sdk.d.ts +28 -0
- package/dist/extension-sdk.d.ts.map +1 -0
- package/dist/extension-sdk.js +26 -0
- package/dist/extension-sdk.js.map +1 -0
- package/dist/identity/device.d.ts +19 -0
- package/dist/identity/device.d.ts.map +1 -0
- package/dist/identity/device.js +88 -0
- package/dist/identity/device.js.map +1 -0
- package/dist/infra/backoff.d.ts +24 -0
- package/dist/infra/backoff.d.ts.map +1 -0
- package/dist/infra/backoff.js +48 -0
- package/dist/infra/backoff.js.map +1 -0
- package/dist/infra/errors.d.ts +35 -0
- package/dist/infra/errors.d.ts.map +1 -0
- package/dist/infra/errors.js +54 -0
- package/dist/infra/errors.js.map +1 -0
- package/dist/infra/fs/atomic-rename.d.ts +31 -0
- package/dist/infra/fs/atomic-rename.d.ts.map +1 -0
- package/dist/infra/fs/atomic-rename.js +75 -0
- package/dist/infra/fs/atomic-rename.js.map +1 -0
- package/dist/infra/json-file.d.ts +25 -0
- package/dist/infra/json-file.d.ts.map +1 -0
- package/dist/infra/json-file.js +49 -0
- package/dist/infra/json-file.js.map +1 -0
- package/dist/infra/json-utf8-bytes.d.ts +14 -0
- package/dist/infra/json-utf8-bytes.d.ts.map +1 -0
- package/dist/infra/json-utf8-bytes.js +20 -0
- package/dist/infra/json-utf8-bytes.js.map +1 -0
- package/dist/infra/net/dns-pinning.d.ts +66 -0
- package/dist/infra/net/dns-pinning.d.ts.map +1 -0
- package/dist/infra/net/dns-pinning.js +128 -0
- package/dist/infra/net/dns-pinning.js.map +1 -0
- package/dist/infra/net/fetch-guard.d.ts +85 -0
- package/dist/infra/net/fetch-guard.d.ts.map +1 -0
- package/dist/infra/net/fetch-guard.js +439 -0
- package/dist/infra/net/fetch-guard.js.map +1 -0
- package/dist/infra/prototype-keys.d.ts +19 -0
- package/dist/infra/prototype-keys.d.ts.map +1 -0
- package/dist/infra/prototype-keys.js +22 -0
- package/dist/infra/prototype-keys.js.map +1 -0
- package/dist/integrations/ollama.d.ts +67 -0
- package/dist/integrations/ollama.d.ts.map +1 -0
- package/dist/integrations/ollama.js +53 -0
- package/dist/integrations/ollama.js.map +1 -0
- package/dist/integrations/provider-discovery.d.ts +66 -0
- package/dist/integrations/provider-discovery.d.ts.map +1 -0
- package/dist/integrations/provider-discovery.js +166 -0
- package/dist/integrations/provider-discovery.js.map +1 -0
- package/dist/logging/redact.d.ts +28 -0
- package/dist/logging/redact.d.ts.map +1 -0
- package/dist/logging/redact.js +51 -0
- package/dist/logging/redact.js.map +1 -0
- package/dist/logging/subsystem-logger.d.ts +77 -0
- package/dist/logging/subsystem-logger.d.ts.map +1 -0
- package/dist/logging/subsystem-logger.js +577 -0
- package/dist/logging/subsystem-logger.js.map +1 -0
- package/dist/logging/subsystem.d.ts +13 -0
- package/dist/logging/subsystem.d.ts.map +1 -0
- package/dist/logging/subsystem.js +12 -0
- package/dist/logging/subsystem.js.map +1 -0
- package/dist/process/command-queue.d.ts +152 -0
- package/dist/process/command-queue.d.ts.map +1 -0
- package/dist/process/command-queue.js +420 -0
- package/dist/process/command-queue.js.map +1 -0
- package/dist/process/lanes.d.ts +102 -0
- package/dist/process/lanes.d.ts.map +1 -0
- package/dist/process/lanes.js +117 -0
- package/dist/process/lanes.js.map +1 -0
- package/dist/process/session-lane.d.ts +31 -0
- package/dist/process/session-lane.d.ts.map +1 -0
- package/dist/process/session-lane.js +45 -0
- package/dist/process/session-lane.js.map +1 -0
- package/dist/protocol/errors.d.ts +35 -0
- package/dist/protocol/errors.d.ts.map +1 -0
- package/dist/protocol/errors.js +36 -0
- package/dist/protocol/errors.js.map +1 -0
- package/dist/protocol/handshake.d.ts +101 -0
- package/dist/protocol/handshake.d.ts.map +1 -0
- package/dist/protocol/handshake.js +49 -0
- package/dist/protocol/handshake.js.map +1 -0
- package/dist/protocol/messages.d.ts +68 -0
- package/dist/protocol/messages.d.ts.map +1 -0
- package/dist/protocol/messages.js +20 -0
- package/dist/protocol/messages.js.map +1 -0
- package/dist/protocol/methods.d.ts +312 -0
- package/dist/protocol/methods.d.ts.map +1 -0
- package/dist/protocol/methods.js +16 -0
- package/dist/protocol/methods.js.map +1 -0
- package/dist/protocol.d.ts +598 -0
- package/dist/protocol.d.ts.map +1 -0
- package/dist/protocol.js +12 -0
- package/dist/protocol.js.map +1 -0
- package/dist/providers/auth-methods.d.ts +82 -0
- package/dist/providers/auth-methods.d.ts.map +1 -0
- package/dist/providers/auth-methods.js +180 -0
- package/dist/providers/auth-methods.js.map +1 -0
- package/dist/providers/catalog.d.ts +85 -0
- package/dist/providers/catalog.d.ts.map +1 -0
- package/dist/providers/catalog.js +41 -0
- package/dist/providers/catalog.js.map +1 -0
- package/dist/providers/validate-key.d.ts +42 -0
- package/dist/providers/validate-key.d.ts.map +1 -0
- package/dist/providers/validate-key.js.map +1 -0
- package/dist/security/external-content.d.ts +67 -0
- package/dist/security/external-content.d.ts.map +1 -0
- package/dist/security/external-content.js +80 -0
- package/dist/security/external-content.js.map +1 -0
- package/dist/security/injection-patterns.d.ts +33 -0
- package/dist/security/injection-patterns.d.ts.map +1 -0
- package/dist/security/injection-patterns.js +97 -0
- package/dist/security/injection-patterns.js.map +1 -0
- package/dist/security/media-path-guard.d.ts +25 -0
- package/dist/security/media-path-guard.d.ts.map +1 -0
- package/dist/security/media-path-guard.js +98 -0
- package/dist/security/media-path-guard.js.map +1 -0
- package/dist/security/terminal-input-sanitizer.d.ts +30 -0
- package/dist/security/terminal-input-sanitizer.d.ts.map +1 -0
- package/dist/security/terminal-input-sanitizer.js +70 -0
- package/dist/security/terminal-input-sanitizer.js.map +1 -0
- package/dist/sessions/bootstrap-marker.d.ts +5 -0
- package/dist/sessions/bootstrap-marker.d.ts.map +1 -0
- package/dist/sessions/bootstrap-marker.js +120 -0
- package/dist/sessions/bootstrap-marker.js.map +1 -0
- package/dist/sessions/session-file-repair.d.ts +12 -0
- package/dist/sessions/session-file-repair.d.ts.map +1 -0
- package/dist/sessions/session-file-repair.js +155 -0
- package/dist/sessions/session-file-repair.js.map +1 -0
- package/dist/sessions/session-key-utils.d.ts +54 -0
- package/dist/sessions/session-key-utils.d.ts.map +1 -0
- package/dist/sessions/session-key-utils.js +133 -0
- package/dist/sessions/session-key-utils.js.map +1 -0
- package/dist/sessions/session-manager-factory.d.ts +21 -0
- package/dist/sessions/session-manager-factory.d.ts.map +1 -0
- package/dist/sessions/session-manager-factory.js +142 -0
- package/dist/sessions/session-manager-factory.js.map +1 -0
- package/dist/sessions/session-store.d.ts +154 -0
- package/dist/sessions/session-store.d.ts.map +1 -0
- package/dist/sessions/session-store.js +498 -0
- package/dist/sessions/session-store.js.map +1 -0
- package/dist/sessions/session-write-lock.d.ts +10 -0
- package/dist/sessions/session-write-lock.d.ts.map +1 -0
- package/dist/sessions/session-write-lock.js +167 -0
- package/dist/sessions/session-write-lock.js.map +1 -0
- package/dist/sessions/transcript-reader.d.ts +37 -0
- package/dist/sessions/transcript-reader.d.ts.map +1 -0
- package/dist/sessions/transcript-reader.js +136 -0
- package/dist/sessions/transcript-reader.js.map +1 -0
- package/dist/sessions/transcript-repair.d.ts +16 -0
- package/dist/sessions/transcript-repair.d.ts.map +1 -0
- package/dist/sessions/transcript-repair.js +214 -0
- package/dist/sessions/transcript-repair.js.map +1 -0
- package/dist/shared/global-singleton.d.ts +27 -0
- package/dist/shared/global-singleton.d.ts.map +1 -0
- package/dist/shared/global-singleton.js +35 -0
- package/dist/shared/global-singleton.js.map +1 -0
- package/dist/shared/string-coerce.d.ts +12 -0
- package/dist/shared/string-coerce.d.ts.map +1 -0
- package/dist/shared/string-coerce.js +12 -0
- package/dist/shared/string-coerce.js.map +1 -0
- package/dist/storage/boot.d.ts +28 -0
- package/dist/storage/boot.d.ts.map +1 -0
- package/dist/storage/boot.js +588 -0
- package/dist/storage/boot.js.map +1 -0
- package/dist/storage/config-cache.d.ts +23 -0
- package/dist/storage/config-cache.d.ts.map +1 -0
- package/dist/storage/config-cache.js +58 -0
- package/dist/storage/config-cache.js.map +1 -0
- package/dist/storage/convex/auth-store.d.ts +52 -0
- package/dist/storage/convex/auth-store.d.ts.map +1 -0
- package/dist/storage/convex/auth-store.js +282 -0
- package/dist/storage/convex/auth-store.js.map +1 -0
- package/dist/storage/convex/blob-store.d.ts +20 -0
- package/dist/storage/convex/blob-store.d.ts.map +1 -0
- package/dist/storage/convex/blob-store.js +74 -0
- package/dist/storage/convex/blob-store.js.map +1 -0
- package/dist/storage/convex/channel-store.d.ts +112 -0
- package/dist/storage/convex/channel-store.d.ts.map +1 -0
- package/dist/storage/convex/channel-store.js +267 -0
- package/dist/storage/convex/channel-store.js.map +1 -0
- package/dist/storage/convex/client.d.ts +53 -0
- package/dist/storage/convex/client.d.ts.map +1 -0
- package/dist/storage/convex/client.js +121 -0
- package/dist/storage/convex/client.js.map +1 -0
- package/dist/storage/convex/config-store.d.ts +29 -0
- package/dist/storage/convex/config-store.d.ts.map +1 -0
- package/dist/storage/convex/config-store.js +205 -0
- package/dist/storage/convex/config-store.js.map +1 -0
- package/dist/storage/convex/cron-store.d.ts +86 -0
- package/dist/storage/convex/cron-store.d.ts.map +1 -0
- package/dist/storage/convex/cron-store.js +428 -0
- package/dist/storage/convex/cron-store.js.map +1 -0
- package/dist/storage/convex/exec-approval-store.d.ts +38 -0
- package/dist/storage/convex/exec-approval-store.d.ts.map +1 -0
- package/dist/storage/convex/exec-approval-store.js +147 -0
- package/dist/storage/convex/exec-approval-store.js.map +1 -0
- package/dist/storage/convex/extension-store.d.ts +28 -0
- package/dist/storage/convex/extension-store.d.ts.map +1 -0
- package/dist/storage/convex/extension-store.js +39 -0
- package/dist/storage/convex/extension-store.js.map +1 -0
- package/dist/storage/convex/index.d.ts +35 -0
- package/dist/storage/convex/index.d.ts.map +1 -0
- package/dist/storage/convex/index.js +141 -0
- package/dist/storage/convex/index.js.map +1 -0
- package/dist/storage/convex/instance-store.d.ts +37 -0
- package/dist/storage/convex/instance-store.d.ts.map +1 -0
- package/dist/storage/convex/instance-store.js +88 -0
- package/dist/storage/convex/instance-store.js.map +1 -0
- package/dist/storage/convex/log-store.d.ts +36 -0
- package/dist/storage/convex/log-store.d.ts.map +1 -0
- package/dist/storage/convex/log-store.js +213 -0
- package/dist/storage/convex/log-store.js.map +1 -0
- package/dist/storage/convex/memory-store.d.ts +50 -0
- package/dist/storage/convex/memory-store.d.ts.map +1 -0
- package/dist/storage/convex/memory-store.js +537 -0
- package/dist/storage/convex/memory-store.js.map +1 -0
- package/dist/storage/convex/message-store.d.ts +32 -0
- package/dist/storage/convex/message-store.d.ts.map +1 -0
- package/dist/storage/convex/message-store.js +272 -0
- package/dist/storage/convex/message-store.js.map +1 -0
- package/dist/storage/convex/org-store.d.ts +46 -0
- package/dist/storage/convex/org-store.d.ts.map +1 -0
- package/dist/storage/convex/org-store.js +101 -0
- package/dist/storage/convex/org-store.js.map +1 -0
- package/dist/storage/convex/session-store.d.ts +44 -0
- package/dist/storage/convex/session-store.d.ts.map +1 -0
- package/dist/storage/convex/session-store.js +257 -0
- package/dist/storage/convex/session-store.js.map +1 -0
- package/dist/storage/convex/skill-store.d.ts +49 -0
- package/dist/storage/convex/skill-store.d.ts.map +1 -0
- package/dist/storage/convex/skill-store.js +84 -0
- package/dist/storage/convex/skill-store.js.map +1 -0
- package/dist/storage/convex/subagent-store.d.ts +28 -0
- package/dist/storage/convex/subagent-store.d.ts.map +1 -0
- package/dist/storage/convex/subagent-store.js +83 -0
- package/dist/storage/convex/subagent-store.js.map +1 -0
- package/dist/storage/convex/workspace-store.d.ts +25 -0
- package/dist/storage/convex/workspace-store.d.ts.map +1 -0
- package/dist/storage/convex/workspace-store.js +127 -0
- package/dist/storage/convex/workspace-store.js.map +1 -0
- package/dist/storage/cron-cache.d.ts +17 -0
- package/dist/storage/cron-cache.d.ts.map +1 -0
- package/dist/storage/cron-cache.js +67 -0
- package/dist/storage/cron-cache.js.map +1 -0
- package/dist/storage/encryption.d.ts +69 -0
- package/dist/storage/encryption.d.ts.map +1 -0
- package/dist/storage/encryption.js +389 -0
- package/dist/storage/encryption.js.map +1 -0
- package/dist/storage/factory-reset.d.ts +7 -0
- package/dist/storage/factory-reset.d.ts.map +1 -0
- package/dist/storage/factory-reset.js +34 -0
- package/dist/storage/factory-reset.js.map +1 -0
- package/dist/storage/facts-cache.d.ts +24 -0
- package/dist/storage/facts-cache.d.ts.map +1 -0
- package/dist/storage/facts-cache.js +110 -0
- package/dist/storage/facts-cache.js.map +1 -0
- package/dist/storage/flush.d.ts +4 -0
- package/dist/storage/flush.d.ts.map +1 -0
- package/dist/storage/flush.js +128 -0
- package/dist/storage/flush.js.map +1 -0
- package/dist/storage/instance-admin.d.ts +52 -0
- package/dist/storage/instance-admin.d.ts.map +1 -0
- package/dist/storage/instance-admin.js +90 -0
- package/dist/storage/instance-admin.js.map +1 -0
- package/dist/storage/local/auth-store.d.ts +44 -0
- package/dist/storage/local/auth-store.d.ts.map +1 -0
- package/dist/storage/local/auth-store.js +252 -0
- package/dist/storage/local/auth-store.js.map +1 -0
- package/dist/storage/local/blob-store.d.ts +14 -0
- package/dist/storage/local/blob-store.d.ts.map +1 -0
- package/dist/storage/local/blob-store.js +87 -0
- package/dist/storage/local/blob-store.js.map +1 -0
- package/dist/storage/local/channel-store.d.ts +107 -0
- package/dist/storage/local/channel-store.d.ts.map +1 -0
- package/dist/storage/local/channel-store.js +147 -0
- package/dist/storage/local/channel-store.js.map +1 -0
- package/dist/storage/local/config-store.d.ts +23 -0
- package/dist/storage/local/config-store.d.ts.map +1 -0
- package/dist/storage/local/config-store.js +98 -0
- package/dist/storage/local/config-store.js.map +1 -0
- package/dist/storage/local/cron-store.d.ts +30 -0
- package/dist/storage/local/cron-store.d.ts.map +1 -0
- package/dist/storage/local/cron-store.js +186 -0
- package/dist/storage/local/cron-store.js.map +1 -0
- package/dist/storage/local/exec-approval-store.d.ts +41 -0
- package/dist/storage/local/exec-approval-store.d.ts.map +1 -0
- package/dist/storage/local/exec-approval-store.js +78 -0
- package/dist/storage/local/exec-approval-store.js.map +1 -0
- package/dist/storage/local/extension-store.d.ts +13 -0
- package/dist/storage/local/extension-store.d.ts.map +1 -0
- package/dist/storage/local/extension-store.js +36 -0
- package/dist/storage/local/extension-store.js.map +1 -0
- package/dist/storage/local/file-watcher.d.ts +24 -0
- package/dist/storage/local/file-watcher.d.ts.map +1 -0
- package/dist/storage/local/file-watcher.js +141 -0
- package/dist/storage/local/file-watcher.js.map +1 -0
- package/dist/storage/local/index.d.ts +33 -0
- package/dist/storage/local/index.d.ts.map +1 -0
- package/dist/storage/local/index.js +143 -0
- package/dist/storage/local/index.js.map +1 -0
- package/dist/storage/local/instance-store.d.ts +30 -0
- package/dist/storage/local/instance-store.d.ts.map +1 -0
- package/dist/storage/local/instance-store.js +83 -0
- package/dist/storage/local/instance-store.js.map +1 -0
- package/dist/storage/local/log-store.d.ts +27 -0
- package/dist/storage/local/log-store.d.ts.map +1 -0
- package/dist/storage/local/log-store.js +185 -0
- package/dist/storage/local/log-store.js.map +1 -0
- package/dist/storage/local/memory-store.d.ts +39 -0
- package/dist/storage/local/memory-store.d.ts.map +1 -0
- package/dist/storage/local/memory-store.js +258 -0
- package/dist/storage/local/memory-store.js.map +1 -0
- package/dist/storage/local/message-store.d.ts +27 -0
- package/dist/storage/local/message-store.d.ts.map +1 -0
- package/dist/storage/local/message-store.js +253 -0
- package/dist/storage/local/message-store.js.map +1 -0
- package/dist/storage/local/org-store.d.ts +39 -0
- package/dist/storage/local/org-store.d.ts.map +1 -0
- package/dist/storage/local/org-store.js +155 -0
- package/dist/storage/local/org-store.js.map +1 -0
- package/dist/storage/local/session-store.d.ts +30 -0
- package/dist/storage/local/session-store.d.ts.map +1 -0
- package/dist/storage/local/session-store.js +82 -0
- package/dist/storage/local/session-store.js.map +1 -0
- package/dist/storage/local/skill-store.d.ts +40 -0
- package/dist/storage/local/skill-store.d.ts.map +1 -0
- package/dist/storage/local/skill-store.js +121 -0
- package/dist/storage/local/skill-store.js.map +1 -0
- package/dist/storage/local/subagent-store.d.ts +20 -0
- package/dist/storage/local/subagent-store.d.ts.map +1 -0
- package/dist/storage/local/subagent-store.js +71 -0
- package/dist/storage/local/subagent-store.js.map +1 -0
- package/dist/storage/local/workspace-store.d.ts +22 -0
- package/dist/storage/local/workspace-store.d.ts.map +1 -0
- package/dist/storage/local/workspace-store.js +190 -0
- package/dist/storage/local/workspace-store.js.map +1 -0
- package/dist/storage/migrate.d.ts +64 -0
- package/dist/storage/migrate.d.ts.map +1 -0
- package/dist/storage/migrate.js +581 -0
- package/dist/storage/migrate.js.map +1 -0
- package/dist/storage/runtime-context.d.ts +35 -0
- package/dist/storage/runtime-context.d.ts.map +1 -0
- package/dist/storage/runtime-context.js +145 -0
- package/dist/storage/runtime-context.js.map +1 -0
- package/dist/storage/sentinel.d.ts +28 -0
- package/dist/storage/sentinel.d.ts.map +1 -0
- package/dist/storage/sentinel.js +98 -0
- package/dist/storage/sentinel.js.map +1 -0
- package/dist/storage/session-cache.d.ts +15 -0
- package/dist/storage/session-cache.d.ts.map +1 -0
- package/dist/storage/session-cache.js +81 -0
- package/dist/storage/session-cache.js.map +1 -0
- package/dist/storage/store.d.ts +745 -0
- package/dist/storage/store.d.ts.map +1 -0
- package/dist/storage/store.js +36 -0
- package/dist/storage/store.js.map +1 -0
- package/dist/storage/strict-guard.d.ts +17 -0
- package/dist/storage/strict-guard.d.ts.map +1 -0
- package/dist/storage/strict-guard.js +200 -0
- package/dist/storage/strict-guard.js.map +1 -0
- package/dist/storage/workspace-live-mirror.d.ts +33 -0
- package/dist/storage/workspace-live-mirror.d.ts.map +1 -0
- package/dist/storage/workspace-live-mirror.js +207 -0
- package/dist/storage/workspace-live-mirror.js.map +1 -0
- package/dist/system-prompt/assembler.d.ts +113 -0
- package/dist/system-prompt/assembler.d.ts.map +1 -0
- package/dist/system-prompt/assembler.js +649 -0
- package/dist/system-prompt/assembler.js.map +1 -0
- package/dist/system-prompt/bootstrap-budget.d.ts +22 -0
- package/dist/system-prompt/bootstrap-budget.d.ts.map +1 -0
- package/dist/system-prompt/bootstrap-budget.js +83 -0
- package/dist/system-prompt/bootstrap-budget.js.map +1 -0
- package/dist/system-prompt/cache-boundary.d.ts +13 -0
- package/dist/system-prompt/cache-boundary.d.ts.map +1 -0
- package/dist/system-prompt/cache-boundary.js +56 -0
- package/dist/system-prompt/cache-boundary.js.map +1 -0
- package/dist/system-prompt/cache-stability.d.ts +3 -0
- package/dist/system-prompt/cache-stability.d.ts.map +1 -0
- package/dist/system-prompt/cache-stability.js +18 -0
- package/dist/system-prompt/cache-stability.js.map +1 -0
- package/dist/system-prompt/guidance.d.ts +147 -0
- package/dist/system-prompt/guidance.d.ts.map +1 -0
- package/dist/system-prompt/guidance.js +352 -0
- package/dist/system-prompt/guidance.js.map +1 -0
- package/dist/system-prompt/identity-defaults.d.ts +50 -0
- package/dist/system-prompt/identity-defaults.d.ts.map +1 -0
- package/dist/system-prompt/identity-defaults.js +119 -0
- package/dist/system-prompt/identity-defaults.js.map +1 -0
- package/dist/system-prompt/org/escalation-inbox.d.ts +53 -0
- package/dist/system-prompt/org/escalation-inbox.d.ts.map +1 -0
- package/dist/system-prompt/org/escalation-inbox.js +71 -0
- package/dist/system-prompt/org/escalation-inbox.js.map +1 -0
- package/dist/system-prompt/org/receiver-hint.d.ts +72 -0
- package/dist/system-prompt/org/receiver-hint.d.ts.map +1 -0
- package/dist/system-prompt/org/receiver-hint.js +116 -0
- package/dist/system-prompt/org/receiver-hint.js.map +1 -0
- package/dist/system-prompt/org/render-org-block.d.ts +42 -0
- package/dist/system-prompt/org/render-org-block.d.ts.map +1 -0
- package/dist/system-prompt/org/render-org-block.js +57 -0
- package/dist/system-prompt/org/render-org-block.js.map +1 -0
- package/dist/system-prompt/org/sub-agent-anchor.d.ts +30 -0
- package/dist/system-prompt/org/sub-agent-anchor.d.ts.map +1 -0
- package/dist/system-prompt/org/sub-agent-anchor.js +36 -0
- package/dist/system-prompt/org/sub-agent-anchor.js.map +1 -0
- package/dist/system-prompt/override.d.ts +7 -0
- package/dist/system-prompt/override.d.ts.map +1 -0
- package/dist/system-prompt/override.js +13 -0
- package/dist/system-prompt/override.js.map +1 -0
- package/dist/system-prompt/pi-injection.d.ts +5 -0
- package/dist/system-prompt/pi-injection.d.ts.map +1 -0
- package/dist/system-prompt/pi-injection.js +33 -0
- package/dist/system-prompt/pi-injection.js.map +1 -0
- package/dist/system-prompt/runtime-params.d.ts +34 -0
- package/dist/system-prompt/runtime-params.d.ts.map +1 -0
- package/dist/system-prompt/runtime-params.js +108 -0
- package/dist/system-prompt/runtime-params.js.map +1 -0
- package/dist/system-prompt/sanitize.d.ts +7 -0
- package/dist/system-prompt/sanitize.d.ts.map +1 -0
- package/dist/system-prompt/sanitize.js +31 -0
- package/dist/system-prompt/sanitize.js.map +1 -0
- package/dist/system-prompt/types.d.ts +7 -0
- package/dist/system-prompt/types.d.ts.map +1 -0
- package/dist/system-prompt/types.js +3 -0
- package/dist/system-prompt/types.js.map +1 -0
- package/dist/system-prompt/workspace-loader.d.ts +12 -0
- package/dist/system-prompt/workspace-loader.d.ts.map +1 -0
- package/dist/system-prompt/workspace-loader.js +115 -0
- package/dist/system-prompt/workspace-loader.js.map +1 -0
- package/dist/tideline/advanced.d.ts +25 -0
- package/dist/tideline/advanced.d.ts.map +1 -0
- package/dist/tideline/advanced.js +34 -0
- package/dist/tideline/advanced.js.map +1 -0
- package/dist/tideline/eval.d.ts +19 -0
- package/dist/tideline/eval.d.ts.map +1 -0
- package/dist/tideline/eval.js +24 -0
- package/dist/tideline/eval.js.map +1 -0
- package/dist/tideline/host-ports.standalone.d.ts +49 -0
- package/dist/tideline/host-ports.standalone.d.ts.map +1 -0
- package/dist/tideline/host-ports.standalone.js +61 -0
- package/dist/tideline/host-ports.standalone.js.map +1 -0
- package/dist/tideline/index.d.ts +34 -0
- package/dist/tideline/index.d.ts.map +1 -0
- package/dist/tideline/index.js +42 -0
- package/dist/tideline/index.js.map +1 -0
- package/dist/tui/approval-prompt.d.ts +73 -0
- package/dist/tui/approval-prompt.d.ts.map +1 -0
- package/dist/tui/approval-prompt.js +272 -0
- package/dist/tui/approval-prompt.js.map +1 -0
- package/dist/tui/client.d.ts +89 -0
- package/dist/tui/client.d.ts.map +1 -0
- package/dist/tui/client.js.map +1 -0
- package/dist/ui/brand-frames-cli.d.ts +19 -0
- package/dist/ui/brand-frames-cli.d.ts.map +1 -0
- package/dist/ui/brand-frames-cli.js +8 -13
- package/dist/ui/brand-frames-cli.js.map +1 -0
- package/dist/ui/brand.d.ts +41 -0
- package/dist/ui/brand.d.ts.map +1 -0
- package/dist/ui/brand.js +28 -6
- package/dist/ui/brand.js.map +1 -0
- package/dist/ui/editor.d.ts +30 -0
- package/dist/ui/editor.d.ts.map +1 -0
- package/dist/ui/editor.js +73 -0
- package/dist/ui/editor.js.map +1 -0
- package/dist/ui/format-session.d.ts +68 -0
- package/dist/ui/format-session.d.ts.map +1 -0
- package/dist/ui/format-session.js +181 -0
- package/dist/ui/format-session.js.map +1 -0
- package/dist/ui/markdown.d.ts +48 -0
- package/dist/ui/markdown.d.ts.map +1 -0
- package/dist/ui/markdown.js +60 -0
- package/dist/ui/markdown.js.map +1 -0
- package/dist/ui/onboard-storage-mode.d.ts +17 -0
- package/dist/ui/onboard-storage-mode.d.ts.map +1 -0
- package/dist/ui/onboard-storage-mode.js +638 -0
- package/dist/ui/onboard-storage-mode.js.map +1 -0
- package/dist/ui/onboarding.d.ts +97 -0
- package/dist/ui/onboarding.d.ts.map +1 -0
- package/dist/ui/onboarding.js +259 -111
- package/dist/ui/onboarding.js.map +1 -0
- package/dist/ui/searchable-select.d.ts +48 -0
- package/dist/ui/searchable-select.d.ts.map +1 -0
- package/dist/ui/searchable-select.js +108 -0
- package/dist/ui/searchable-select.js.map +1 -0
- package/dist/ui/syntax-theme.d.ts +30 -0
- package/dist/ui/syntax-theme.d.ts.map +1 -0
- package/dist/ui/syntax-theme.js +72 -0
- package/dist/ui/syntax-theme.js.map +1 -0
- package/dist/ui/terminal-cleanup.d.ts +46 -0
- package/dist/ui/terminal-cleanup.d.ts.map +1 -0
- package/dist/ui/terminal-cleanup.js +17 -5
- package/dist/ui/terminal-cleanup.js.map +1 -0
- package/dist/ui/theme.d.ts +21 -0
- package/dist/ui/theme.d.ts.map +1 -0
- package/dist/ui/theme.js +66 -2
- package/dist/ui/theme.js.map +1 -0
- package/dist/ui/tool-result.d.ts +47 -0
- package/dist/ui/tool-result.d.ts.map +1 -0
- package/dist/ui/tool-result.js +100 -0
- package/dist/ui/tool-result.js.map +1 -0
- package/dist/utils/delivery-context.d.ts +50 -0
- package/dist/utils/delivery-context.d.ts.map +1 -0
- package/dist/utils/delivery-context.js +82 -0
- package/dist/utils/delivery-context.js.map +1 -0
- package/dist/utils/message-channel.d.ts +60 -0
- package/dist/utils/message-channel.d.ts.map +1 -0
- package/dist/utils/message-channel.js +103 -0
- package/dist/utils/message-channel.js.map +1 -0
- package/dist/utils/string-coerce.d.ts +50 -0
- package/dist/utils/string-coerce.d.ts.map +1 -0
- package/dist/utils/string-coerce.js +101 -0
- package/dist/utils/string-coerce.js.map +1 -0
- package/dist/version.d.ts +20 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +54 -0
- package/dist/version.js.map +1 -0
- package/dist/workspace/bootstrap.d.ts +12 -0
- package/dist/workspace/bootstrap.d.ts.map +1 -0
- package/dist/workspace/bootstrap.js +123 -0
- package/dist/workspace/bootstrap.js.map +1 -0
- package/dist/workspace/fs-utils.d.ts +2 -0
- package/dist/workspace/fs-utils.d.ts.map +1 -0
- package/dist/workspace/fs-utils.js +14 -0
- package/dist/workspace/fs-utils.js.map +1 -0
- package/dist/workspace/git-init.d.ts +5 -0
- package/dist/workspace/git-init.d.ts.map +1 -0
- package/dist/workspace/git-init.js +71 -0
- package/dist/workspace/git-init.js.map +1 -0
- package/dist/workspace/state.d.ts +13 -0
- package/dist/workspace/state.d.ts.map +1 -0
- package/dist/workspace/state.js +128 -0
- package/dist/workspace/state.js.map +1 -0
- package/dist/workspace/template-loader.d.ts +15 -0
- package/dist/workspace/template-loader.d.ts.map +1 -0
- package/dist/workspace/template-loader.js +214 -0
- package/dist/workspace/template-loader.js.map +1 -0
- package/package.json +173 -68
- package/scripts/build-done.mjs +125 -0
- package/scripts/run-brigade.mjs +208 -0
- package/skills/1password/SKILL.md +70 -0
- package/skills/1password/references/cli-examples.md +29 -0
- package/skills/1password/references/get-started.md +17 -0
- package/skills/apple-notes/SKILL.md +77 -0
- package/skills/apple-reminders/SKILL.md +118 -0
- package/skills/bear-notes/SKILL.md +107 -0
- package/skills/blogwatcher/SKILL.md +69 -0
- package/skills/blucli/SKILL.md +47 -0
- package/skills/bluebubbles/SKILL.md +136 -0
- package/skills/camsnap/SKILL.md +45 -0
- package/skills/canvas/SKILL.md +204 -0
- package/skills/coding-agent/SKILL.md +316 -0
- package/skills/discord/SKILL.md +197 -0
- package/skills/eightctl/SKILL.md +50 -0
- package/skills/gemini/SKILL.md +43 -0
- package/skills/gh-issues/SKILL.md +885 -0
- package/skills/gifgrep/SKILL.md +79 -0
- package/skills/git-commit/SKILL.md +40 -0
- package/skills/github/SKILL.md +163 -0
- package/skills/gog/SKILL.md +116 -0
- package/skills/goplaces/SKILL.md +52 -0
- package/skills/healthcheck/SKILL.md +245 -0
- package/skills/himalaya/SKILL.md +257 -0
- package/skills/himalaya/references/configuration.md +184 -0
- package/skills/himalaya/references/message-composition.md +199 -0
- package/skills/imsg/SKILL.md +122 -0
- package/skills/lead-scout/SKILL.md +46 -0
- package/skills/mcporter/SKILL.md +61 -0
- package/skills/model-usage/SKILL.md +69 -0
- package/skills/nano-pdf/SKILL.md +38 -0
- package/skills/node-connect/SKILL.md +142 -0
- package/skills/notion/SKILL.md +174 -0
- package/skills/oauth-setup/SKILL.md +55 -0
- package/skills/obsidian/SKILL.md +81 -0
- package/skills/openai-whisper/SKILL.md +38 -0
- package/skills/openai-whisper-api/SKILL.md +62 -0
- package/skills/openai-whisper-api/scripts/transcribe.sh +88 -0
- package/skills/openhue/SKILL.md +112 -0
- package/skills/oracle/SKILL.md +125 -0
- package/skills/ordercli/SKILL.md +78 -0
- package/skills/peekaboo/SKILL.md +190 -0
- package/skills/sag/SKILL.md +87 -0
- package/skills/session-logs/SKILL.md +151 -0
- package/skills/share-skills/SKILL.md +72 -0
- package/skills/sherpa-onnx-tts/SKILL.md +109 -0
- package/skills/sherpa-onnx-tts/bin/sherpa-onnx-tts +178 -0
- package/skills/skill-creator/SKILL.md +372 -0
- package/skills/skill-creator/license.txt +202 -0
- package/skills/skill-creator/scripts/init_skill.py +378 -0
- package/skills/skill-creator/scripts/package_skill.py +139 -0
- package/skills/skill-creator/scripts/quick_validate.py +159 -0
- package/skills/skill-creator/scripts/test_package_skill.py +160 -0
- package/skills/skill-creator/scripts/test_quick_validate.py +72 -0
- package/skills/slack/SKILL.md +144 -0
- package/skills/songsee/SKILL.md +49 -0
- package/skills/sonoscli/SKILL.md +65 -0
- package/skills/spotify-player/SKILL.md +64 -0
- package/skills/summarize/SKILL.md +87 -0
- package/skills/taskflow/SKILL.md +149 -0
- package/skills/taskflow-inbox-triage/SKILL.md +119 -0
- package/skills/things-mac/SKILL.md +86 -0
- package/skills/tmux/SKILL.md +170 -0
- package/skills/tmux/scripts/find-sessions.sh +112 -0
- package/skills/tmux/scripts/wait-for-text.sh +83 -0
- package/skills/trello/SKILL.md +108 -0
- package/skills/video-frames/SKILL.md +46 -0
- package/skills/video-frames/scripts/frame.sh +81 -0
- package/skills/voice-call/SKILL.md +45 -0
- package/skills/wacli/SKILL.md +72 -0
- package/skills/weather/SKILL.md +129 -0
- package/skills/xurl/SKILL.md +461 -0
- package/templates/workspace/AGENTS.md +223 -0
- package/templates/workspace/BOOTSTRAP.md +64 -0
- package/templates/workspace/HEARTBEAT.md +15 -0
- package/templates/workspace/IDENTITY.md +31 -0
- package/templates/workspace/SOUL.md +47 -0
- package/templates/workspace/TOOLS.md +48 -0
- package/templates/workspace/USER.md +25 -0
- package/CHANGELOG.md +0 -41
- package/SECURITY.md +0 -208
- package/assets/brigade-wordmark.png +0 -0
- package/dist/cli/chat-cmd.js +0 -191
- package/dist/cli/config-cmd.js +0 -171
- package/dist/cli/connect-cmd.js +0 -487
- package/dist/cli/doctor-cmd.js +0 -387
- package/dist/cli/gateway-cmd.js +0 -155
- package/dist/cli.js +0 -328
- package/dist/core/agent.js +0 -1123
- package/dist/core/auth-label.js +0 -147
- package/dist/core/cli-error.js +0 -94
- package/dist/core/error-classifier.js +0 -354
- package/dist/core/provider-payload-mutators.js +0 -517
- package/dist/core/provider-quirks.js +0 -285
- package/dist/core/smart-compaction.js +0 -209
- package/dist/core/system-prompt-defaults.js +0 -264
- package/dist/core/system-prompt-guidance.js +0 -271
- package/dist/index.js +0 -32
- package/dist/ui/brand-frames.js +0 -36
- package/dist/ui/chat.js +0 -1008
|
@@ -0,0 +1,1628 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WhatsApp Web connection (Baileys).
|
|
3
|
+
*
|
|
4
|
+
* A multi-file auth store on disk, QR-on-first-link, auto-reconnect with
|
|
5
|
+
* backoff, and a normalized text-message callback. Baileys is a heavy
|
|
6
|
+
* dependency, so it is lazy-imported here — the gateway only pays for it when a
|
|
7
|
+
* WhatsApp channel actually starts. Types are imported `type`-only (erased at
|
|
8
|
+
* build) so the static import never pulls the runtime in.
|
|
9
|
+
*
|
|
10
|
+
* Reconnect discipline: on a transient drop the live socket is fully torn down
|
|
11
|
+
* (listeners removed + ended) BEFORE a replacement is built, and the rebuild is
|
|
12
|
+
* scheduled on a backoff timer rather than synchronously inside the close
|
|
13
|
+
* handler — so a flapping link can never fork into parallel reconnect chains or
|
|
14
|
+
* leak listeners. A logged-out close stops reconnection entirely (creds are
|
|
15
|
+
* dead). `close()` cancels any pending reconnect and tears the socket down.
|
|
16
|
+
*
|
|
17
|
+
* Scope (this phase): text in / text out. Media, reactions, groups-as-rooms,
|
|
18
|
+
* and presence are deliberately out of scope and slot in later behind the same
|
|
19
|
+
* ChannelAdapter contract.
|
|
20
|
+
*/
|
|
21
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
22
|
+
import { access, chmod, copyFile, readFile, rename, unlink, writeFile } from "node:fs/promises";
|
|
23
|
+
import { join as joinPath } from "node:path";
|
|
24
|
+
import { tryGetRuntimeContext } from "../../../storage/runtime-context.js";
|
|
25
|
+
import { validateOutboundMediaPath } from "../../../security/media-path-guard.js";
|
|
26
|
+
import { createDedupeCache } from "../dedupe.js";
|
|
27
|
+
import { chunkText } from "./chunk.js";
|
|
28
|
+
import { lookupLidReverseSync, useConvexAuthState } from "./convex-auth-state.js";
|
|
29
|
+
import { markdownToWhatsApp } from "./format.js";
|
|
30
|
+
import { extractMentions, extractReplyContext } from "./inbound-extras.js";
|
|
31
|
+
import { downloadInboundMedia, hasInboundMedia } from "./media.js";
|
|
32
|
+
/**
|
|
33
|
+
* Extract the canonical phone-number id (digits-only E.164) from a regular
|
|
34
|
+
* WhatsApp jid like `15551234567@s.whatsapp.net`, a participant jid with a
|
|
35
|
+
* device suffix like `15551234567:1@s.whatsapp.net`, or a raw E.164 string.
|
|
36
|
+
* Returns `""` when no digits are present.
|
|
37
|
+
*
|
|
38
|
+
* ⚠ DO NOT use this on LID-suffixed jids (`@lid` / `@hosted.lid`). LIDs are
|
|
39
|
+
* privacy aliases — the leading digits are an opaque WhatsApp-internal id, NOT
|
|
40
|
+
* a phone number. Use {@link resolveJidToE164} (async) which calls Baileys'
|
|
41
|
+
* `signalRepository.lidMapping.getPNForLID` to map the alias to a real phone.
|
|
42
|
+
*/
|
|
43
|
+
export function canonicalWhatsAppId(raw) {
|
|
44
|
+
if (!raw)
|
|
45
|
+
return "";
|
|
46
|
+
// Strip everything except digits — drops `+`, `-`, spaces, jid suffix, and
|
|
47
|
+
// the device-id `:N` segment that follows the number in participant ids.
|
|
48
|
+
const at = raw.indexOf("@");
|
|
49
|
+
const head = at === -1 ? raw : raw.slice(0, at);
|
|
50
|
+
const beforeColon = head.split(":")[0] ?? head;
|
|
51
|
+
return beforeColon.replace(/\D/g, "");
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Coerce ANY operator-shaped target into a sendable WhatsApp JID. Accepts:
|
|
55
|
+
*
|
|
56
|
+
* - `"+1 555 010 0001"` / `"+15550100001"` / `"15550100001"` → strips
|
|
57
|
+
* formatting, treats as a personal phone number, returns
|
|
58
|
+
* `"15550100001@s.whatsapp.net"`.
|
|
59
|
+
* - `"15550100001@s.whatsapp.net"` → returned unchanged (already canonical).
|
|
60
|
+
* - `"123-456-789@g.us"` → returned unchanged (group jid).
|
|
61
|
+
* - `"260451430568126@lid"` → returned unchanged (LID alias — Baileys handles
|
|
62
|
+
* the lookup internally during send).
|
|
63
|
+
*
|
|
64
|
+
* Returns `""` when the input has no recoverable digits AND no `@`.
|
|
65
|
+
*
|
|
66
|
+
* The Baileys `sendMessage` API parses the recipient via `jidDecode` and
|
|
67
|
+
* crashes with `"Cannot destructure property 'user' of 'jidDecode(...)' as
|
|
68
|
+
* it is undefined"` when the input is a bare `"+phonenumber"` — `jidDecode`
|
|
69
|
+
* returns undefined because there's no `@`. Normalising at the adapter
|
|
70
|
+
* boundary means the operator (and the model) can address peers by phone
|
|
71
|
+
* number in the natural shape and never has to know about JID syntax.
|
|
72
|
+
*/
|
|
73
|
+
export function toWhatsAppJid(raw) {
|
|
74
|
+
if (!raw)
|
|
75
|
+
return "";
|
|
76
|
+
const trimmed = raw.trim();
|
|
77
|
+
if (!trimmed)
|
|
78
|
+
return "";
|
|
79
|
+
// Already a jid → pass through unchanged. Covers @s.whatsapp.net (personal),
|
|
80
|
+
// @g.us (group), @lid / @hosted.lid (LID alias), @broadcast (status).
|
|
81
|
+
if (trimmed.includes("@"))
|
|
82
|
+
return trimmed;
|
|
83
|
+
// Bare phone — strip formatting (`+`, spaces, hyphens, parens) and append
|
|
84
|
+
// the personal-jid suffix. We DO NOT validate the number's country-code
|
|
85
|
+
// shape; Baileys will reject with a clear error if the number is invalid.
|
|
86
|
+
const digits = trimmed.replace(/\D/g, "");
|
|
87
|
+
if (!digits)
|
|
88
|
+
return "";
|
|
89
|
+
return `${digits}@s.whatsapp.net`;
|
|
90
|
+
}
|
|
91
|
+
// Regular phone-number jid (with optional device suffix). The capture is the
|
|
92
|
+
// raw E.164 digits — no leading `+`, callers add it when displaying.
|
|
93
|
+
const WA_PHONE_JID_RE = /^(\d+)(?::\d+)?@(s\.whatsapp\.net|hosted)$/;
|
|
94
|
+
// Privacy-alias (LID) jid. The leading digits look like a phone number but
|
|
95
|
+
// are NOT — they're an opaque alias the user opted into to hide their real
|
|
96
|
+
// number. The only way to map LID → phone is `signalRepository.lidMapping`.
|
|
97
|
+
const WA_LID_JID_RE = /^(\d+)(?::\d+)?@(lid|hosted\.lid)$/;
|
|
98
|
+
/**
|
|
99
|
+
* Read the on-disk LID-reverse mapping file Baileys writes alongside its
|
|
100
|
+
* multi-file auth store. When `signalRepository.lidMapping.getPNForLID` hasn't
|
|
101
|
+
* cached a mapping yet (typical right after a fresh link), the cached reverse
|
|
102
|
+
* file is the only place to find the LID → phone translation. Path shape:
|
|
103
|
+
* `<authDir>/lid-mapping-<lid>_reverse.json` → JSON containing the phone
|
|
104
|
+
* number (string or number) the LID is aliased to.
|
|
105
|
+
*
|
|
106
|
+
* Sync (single small JSON file, microseconds); the caller's outer resolver is
|
|
107
|
+
* async because the runtime lookup is async. Returns null when the file is
|
|
108
|
+
* absent, unreadable, or carries a null/empty value.
|
|
109
|
+
*/
|
|
110
|
+
function readLidReverseMappingSync(authDir, lidDigits, accountId = "default") {
|
|
111
|
+
if (!lidDigits)
|
|
112
|
+
return null;
|
|
113
|
+
// Convex mode — the lid-mapping keys live in the keystore; the
|
|
114
|
+
// auth-state module mirrors reverse entries for exactly this sync read.
|
|
115
|
+
// The mirror is keyed by accountId, so the lookup MUST use the same
|
|
116
|
+
// accountId the auth-state was loaded with (not a hardcoded "default",
|
|
117
|
+
// which silently misses for any non-default WhatsApp account → inbound
|
|
118
|
+
// LID-form senders get dropped).
|
|
119
|
+
if (tryGetRuntimeContext()?.mode === "convex") {
|
|
120
|
+
return lookupLidReverseSync(accountId, lidDigits);
|
|
121
|
+
}
|
|
122
|
+
if (!authDir)
|
|
123
|
+
return null;
|
|
124
|
+
// Best-effort filesystem read — gated by a quick exists check so the
|
|
125
|
+
// happy-path "no mapping yet" branch doesn't spam the disk.
|
|
126
|
+
try {
|
|
127
|
+
const mappingPath = joinPath(authDir, `lid-mapping-${lidDigits}_reverse.json`);
|
|
128
|
+
if (!existsSync(mappingPath))
|
|
129
|
+
return null;
|
|
130
|
+
const raw = readFileSync(mappingPath, "utf8");
|
|
131
|
+
const parsed = JSON.parse(raw);
|
|
132
|
+
if (parsed === null || parsed === undefined)
|
|
133
|
+
return null;
|
|
134
|
+
const digits = String(parsed).replace(/\D/g, "");
|
|
135
|
+
return digits.length >= 7 ? digits : null;
|
|
136
|
+
}
|
|
137
|
+
catch {
|
|
138
|
+
// Missing / malformed / racing-with-write — degrade silently to the
|
|
139
|
+
// runtime-lookup path so a transient read error doesn't drop the msg.
|
|
140
|
+
return null;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Resolve a WhatsApp jid to a canonical phone number (digits-only E.164),
|
|
145
|
+
* including LID-aliased jids that need a runtime lookup. Resolution order
|
|
146
|
+
* for LID jids:
|
|
147
|
+
* 1. On-disk reverse mapping at `<authDir>/lid-mapping-<lid>_reverse.json`
|
|
148
|
+
* (Baileys persists these across reconnects — survives the cold-start
|
|
149
|
+
* window where `signalRepository.lidMapping` is empty).
|
|
150
|
+
* 2. `signalRepository.lidMapping.getPNForLID()` — the live in-memory cache.
|
|
151
|
+
*
|
|
152
|
+
* Returns `null` when:
|
|
153
|
+
* - `jid` is empty/missing
|
|
154
|
+
* - the jid is in LID form AND neither resolution path yields a phone
|
|
155
|
+
* - the resolved value isn't a recognized phone-jid shape
|
|
156
|
+
*
|
|
157
|
+
* Callers MUST drop messages with a `null` resolution rather than inventing a
|
|
158
|
+
* fake sender id from raw LID digits — those digits aren't a phone number, and
|
|
159
|
+
* downstream pairing/allow-list code keys on E.164.
|
|
160
|
+
*
|
|
161
|
+
* `authDir` is optional so tests can call without an on-disk store; when
|
|
162
|
+
* omitted only the runtime lookup is consulted.
|
|
163
|
+
*/
|
|
164
|
+
export async function resolveJidToE164(sock, jid, authDir, accountId) {
|
|
165
|
+
if (!jid)
|
|
166
|
+
return null;
|
|
167
|
+
const direct = jid.match(WA_PHONE_JID_RE);
|
|
168
|
+
if (direct)
|
|
169
|
+
return direct[1] ?? null;
|
|
170
|
+
const lidMatch = jid.match(WA_LID_JID_RE);
|
|
171
|
+
if (!lidMatch)
|
|
172
|
+
return null;
|
|
173
|
+
const lidDigits = lidMatch[1] ?? "";
|
|
174
|
+
// First: on-disk reverse mapping. Baileys' multi-file auth store writes
|
|
175
|
+
// these the moment it sees a LID's phone translation, so right after a
|
|
176
|
+
// fresh link they're available even while the in-memory `lidMapping` is
|
|
177
|
+
// still warming up.
|
|
178
|
+
const fromDisk = readLidReverseMappingSync(authDir, lidDigits, accountId);
|
|
179
|
+
if (fromDisk)
|
|
180
|
+
return fromDisk;
|
|
181
|
+
// Then: runtime lookup. Some Baileys builds expose
|
|
182
|
+
// `signalRepository.lidMapping`; older / partially-initialized sockets
|
|
183
|
+
// don't. Treat a missing lookup as "unresolvable" — we already tried disk.
|
|
184
|
+
const lookup = sock?.signalRepository
|
|
185
|
+
?.lidMapping;
|
|
186
|
+
if (!lookup?.getPNForLID)
|
|
187
|
+
return null;
|
|
188
|
+
try {
|
|
189
|
+
const pnJid = await lookup.getPNForLID(jid);
|
|
190
|
+
if (!pnJid)
|
|
191
|
+
return null;
|
|
192
|
+
const m = pnJid.match(WA_PHONE_JID_RE);
|
|
193
|
+
return m ? (m[1] ?? null) : null;
|
|
194
|
+
}
|
|
195
|
+
catch {
|
|
196
|
+
// Lookup failure (e.g. mapping not cached yet) → fall through.
|
|
197
|
+
return null;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
/** Strip a device-id suffix (`:NN`) from a jid, leaving the bare user jid. */
|
|
201
|
+
export function normalizeDeviceScopedJid(jid) {
|
|
202
|
+
return jid ? jid.replace(/:\d+/, "") : null;
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Resolve an inbound sender jid to a STABLE channel identity that NEVER drops a
|
|
206
|
+
* usable sender. Mirrors the reference codebase's identity model
|
|
207
|
+
* (`getPrimaryIdentityId`: e164 || jid || lid): try the phone number first, and
|
|
208
|
+
* when it can't be resolved — e.g. an unmapped `@lid` privacy alias, the common
|
|
209
|
+
* case for group participants — fall back to the canonical LID jid so the
|
|
210
|
+
* message still reaches the access-control gate instead of being silently
|
|
211
|
+
* dropped at the socket layer. The LID is a perfectly stable "same person"
|
|
212
|
+
* handle: routing, allow-lists, and per-sender sessions all key off the
|
|
213
|
+
* returned `id` exactly the way they key off a phone number.
|
|
214
|
+
*
|
|
215
|
+
* Returns:
|
|
216
|
+
* { id: "<e164 digits>", e164: "<e164 digits>" } — phone resolved
|
|
217
|
+
* { id: "<digits>@lid", lid: "<digits>@lid" } — LID alias, unmapped
|
|
218
|
+
* { id: "<normalized jid>" } — other jid shape
|
|
219
|
+
* null — empty / unusable input
|
|
220
|
+
*/
|
|
221
|
+
export async function resolveSenderIdentity(sock, jid, authDir, accountId) {
|
|
222
|
+
if (!jid)
|
|
223
|
+
return null;
|
|
224
|
+
// Capture the LID alias whenever the sender came in via one — even when it
|
|
225
|
+
// DID map to a phone number — so the access-control gate can match on either
|
|
226
|
+
// the number or the LID (mirrors the reference codebase's identity overlap).
|
|
227
|
+
const lid = WA_LID_JID_RE.test(jid) ? (normalizeDeviceScopedJid(jid) ?? undefined) : undefined;
|
|
228
|
+
const e164 = await resolveJidToE164(sock, jid, authDir, accountId);
|
|
229
|
+
if (e164)
|
|
230
|
+
return { id: e164, e164, ...(lid ? { lid } : {}) };
|
|
231
|
+
const normalized = normalizeDeviceScopedJid(jid) ?? jid;
|
|
232
|
+
if (!normalized)
|
|
233
|
+
return null;
|
|
234
|
+
// Unmapped LID privacy alias — keep it verbatim as the stable identity.
|
|
235
|
+
if (lid || /@(lid|hosted\.lid)$/i.test(normalized)) {
|
|
236
|
+
return { id: normalized, lid: lid ?? normalized };
|
|
237
|
+
}
|
|
238
|
+
// Some other jid shape we couldn't map — keep it rather than dropping.
|
|
239
|
+
return { id: normalized };
|
|
240
|
+
}
|
|
241
|
+
// Reconnect backoff: 2s → 30s, ×1.8 with ±25% jitter, capped attempts so a
|
|
242
|
+
// permanently-broken link stops hammering WhatsApp instead of looping forever.
|
|
243
|
+
const RECONNECT_INITIAL_MS = 2_000;
|
|
244
|
+
const RECONNECT_MAX_MS = 30_000;
|
|
245
|
+
const RECONNECT_FACTOR = 1.8;
|
|
246
|
+
const RECONNECT_JITTER = 0.25;
|
|
247
|
+
const RECONNECT_MAX_ATTEMPTS = 12;
|
|
248
|
+
function backoffDelay(attempt) {
|
|
249
|
+
const base = Math.min(RECONNECT_MAX_MS, RECONNECT_INITIAL_MS * RECONNECT_FACTOR ** attempt);
|
|
250
|
+
const jitter = base * RECONNECT_JITTER * (Math.random() * 2 - 1);
|
|
251
|
+
return Math.max(0, Math.round(base + jitter));
|
|
252
|
+
}
|
|
253
|
+
// How often to send an outbound "available" presence ping while the link is
|
|
254
|
+
// otherwise idle. WhatsApp's servers can silently mark a long-idle linked
|
|
255
|
+
// device offline (queueing inbound until the next reconnect) — a periodic
|
|
256
|
+
// nudge keeps the link warm. Defaults to 5 minutes; tune with the env var
|
|
257
|
+
// when debugging suspicious overnight stalls.
|
|
258
|
+
const PRESENCE_PING_MS_DEFAULT = 5 * 60 * 1_000;
|
|
259
|
+
function presencePingMs() {
|
|
260
|
+
const raw = process.env.BRIGADE_WHATSAPP_PRESENCE_PING_MS;
|
|
261
|
+
const parsed = raw ? Number(raw) : NaN;
|
|
262
|
+
return Number.isFinite(parsed) && parsed >= 30_000 ? parsed : PRESENCE_PING_MS_DEFAULT;
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Cold-start presence nudges. After EVERY `connection: "open"` event we
|
|
266
|
+
* fire `sendPresenceUpdate("available")` once immediately, then again at
|
|
267
|
+
* these offsets. WhatsApp's server has a "is the device really ready"
|
|
268
|
+
* debounce — one presence ping is often not enough to convince it to
|
|
269
|
+
* flush a queued message backlog, leaving the operator staring at a
|
|
270
|
+
* silent chat for ~60s on first connect. Three quick re-pings during
|
|
271
|
+
* the cold-start window pull that floor down to ~5-15 s. Cheap (one
|
|
272
|
+
* outbound stanza each) and cancelled the moment a real inbound flows.
|
|
273
|
+
*
|
|
274
|
+
* Tuning rationale: 5s catches the case where the first presence beat
|
|
275
|
+
* the server's "device-ready" decision; 15s catches the case where the
|
|
276
|
+
* server held the queue waiting for a steady-state signal; 30s is the
|
|
277
|
+
* outer envelope before the regular 5-min ping cadence takes over.
|
|
278
|
+
*/
|
|
279
|
+
const COLD_START_NUDGES_MS = [5_000, 15_000, 30_000];
|
|
280
|
+
// Long-lived sessions accumulate Signal-protocol state drift; a clean recycle
|
|
281
|
+
// every N hours costs one reconnect and avoids a midnight stall against a
|
|
282
|
+
// session the server has quietly invalidated. 6h default — long enough to
|
|
283
|
+
// avoid churn during a normal workday, short enough to recover before the
|
|
284
|
+
// next morning.
|
|
285
|
+
const MAX_SESSION_AGE_MS_DEFAULT = 6 * 60 * 60 * 1_000;
|
|
286
|
+
function maxSessionAgeMs() {
|
|
287
|
+
const raw = process.env.BRIGADE_WHATSAPP_MAX_SESSION_AGE_MS;
|
|
288
|
+
const parsed = raw ? Number(raw) : NaN;
|
|
289
|
+
// Minimum 10 min so a misconfigured "0" doesn't reconnect-storm.
|
|
290
|
+
return Number.isFinite(parsed) && parsed >= 10 * 60_000 ? parsed : MAX_SESSION_AGE_MS_DEFAULT;
|
|
291
|
+
}
|
|
292
|
+
// Baileys DisconnectReason value emitted when a NEW WhatsApp Web session opens
|
|
293
|
+
// against the same number — another linked Brigade or a manual Web login. Two
|
|
294
|
+
// sessions reconnecting on the same number get into a 440-conflict ping-pong
|
|
295
|
+
// loop, so this code is treated as terminal (same as logged-out) instead of
|
|
296
|
+
// retried.
|
|
297
|
+
const MULTI_DEVICE_CONFLICT_CODE = 440;
|
|
298
|
+
/**
|
|
299
|
+
* Detect Signal-protocol crypto errors that bubble up from Baileys as
|
|
300
|
+
* unhandled promise rejections instead of through the `connection.update`
|
|
301
|
+
* event (the protocol library throws inside its own async ratchet). When a
|
|
302
|
+
* pre-key rotation goes wrong or a session entry desyncs we'd otherwise wait
|
|
303
|
+
* for the watchdog to time out; trapping the rejection lets us force-reconnect
|
|
304
|
+
* immediately and recover the link in seconds.
|
|
305
|
+
*
|
|
306
|
+
* The attribution-keyword list is deliberately narrow: only stack-frame
|
|
307
|
+
* markers unique to Baileys' WhatsApp transport. Broader markers (e.g. the
|
|
308
|
+
* generic "signal" token, which can appear in unrelated libsignal builds,
|
|
309
|
+
* crypto-library stacks, or even our own log lines) would cause false
|
|
310
|
+
* positives that force-reconnect a healthy socket on unrelated rejections.
|
|
311
|
+
*/
|
|
312
|
+
export function isWaCryptoError(reason) {
|
|
313
|
+
const message = String(reason?.message ?? reason ?? "").toLowerCase();
|
|
314
|
+
const cryptoHit = message.includes("unsupported state or unable to authenticate data") ||
|
|
315
|
+
message.includes("bad mac");
|
|
316
|
+
if (!cryptoHit)
|
|
317
|
+
return false;
|
|
318
|
+
return (message.includes("baileys") ||
|
|
319
|
+
message.includes("noise-handler") ||
|
|
320
|
+
message.includes("aesdecryptgcm") ||
|
|
321
|
+
message.includes("@whiskeysockets"));
|
|
322
|
+
}
|
|
323
|
+
/**
|
|
324
|
+
* Extract plain text from a Baileys message, unwrapping the common envelopes
|
|
325
|
+
* (`ephemeralMessage`, `viewOnceMessage*`, `documentWithCaptionMessage`) and
|
|
326
|
+
* surfacing placeholder text for content kinds without a natural body —
|
|
327
|
+
* shared contacts, location pins, polls — so the LLM at least sees that the
|
|
328
|
+
* user sent SOMETHING and can acknowledge it instead of silently dropping
|
|
329
|
+
* the inbound.
|
|
330
|
+
*/
|
|
331
|
+
function extractText(message, normalize) {
|
|
332
|
+
// `normalize` is Baileys' own envelope-flattener; we still wrap it in our
|
|
333
|
+
// wrapper-chain walk in case `normalize` itself leaves a wrapper in place
|
|
334
|
+
// for shapes it doesn't recognize (newer Baileys variants).
|
|
335
|
+
const flattened = (normalize(message) ?? {});
|
|
336
|
+
let content = flattened;
|
|
337
|
+
const fromWrappers = unwrapWrapperEnvelopes(flattened);
|
|
338
|
+
if (fromWrappers)
|
|
339
|
+
content = fromWrappers;
|
|
340
|
+
if (typeof content.conversation === "string")
|
|
341
|
+
return content.conversation;
|
|
342
|
+
const ext = content.extendedTextMessage;
|
|
343
|
+
if (ext && typeof ext.text === "string")
|
|
344
|
+
return ext.text;
|
|
345
|
+
// Image/video/document with a caption — treat the caption as the text.
|
|
346
|
+
const img = content.imageMessage;
|
|
347
|
+
if (img && typeof img.caption === "string")
|
|
348
|
+
return img.caption;
|
|
349
|
+
const vid = content.videoMessage;
|
|
350
|
+
if (vid && typeof vid.caption === "string")
|
|
351
|
+
return vid.caption;
|
|
352
|
+
const doc = content.documentMessage;
|
|
353
|
+
if (doc && typeof doc.caption === "string")
|
|
354
|
+
return doc.caption;
|
|
355
|
+
// Contact card — placeholder so the LLM knows a contact was shared.
|
|
356
|
+
const contact = content.contactMessage;
|
|
357
|
+
if (contact && typeof contact.displayName === "string" && contact.displayName.length > 0) {
|
|
358
|
+
return `[contact shared: ${contact.displayName}]`;
|
|
359
|
+
}
|
|
360
|
+
const contactsArray = content.contactsArrayMessage;
|
|
361
|
+
if (contactsArray?.contacts && contactsArray.contacts.length > 0) {
|
|
362
|
+
const names = contactsArray.contacts
|
|
363
|
+
.map((c) => (typeof c?.displayName === "string" ? c.displayName : ""))
|
|
364
|
+
.filter(Boolean);
|
|
365
|
+
if (names.length > 0)
|
|
366
|
+
return `[contacts shared: ${names.join(", ")}]`;
|
|
367
|
+
}
|
|
368
|
+
// Location pin — placeholder with lat/lon when present.
|
|
369
|
+
const loc = content.locationMessage;
|
|
370
|
+
if (loc && (typeof loc.degreesLatitude === "number" || typeof loc.name === "string")) {
|
|
371
|
+
const named = typeof loc.name === "string" && loc.name ? `"${loc.name}"` : "";
|
|
372
|
+
const coords = typeof loc.degreesLatitude === "number" && typeof loc.degreesLongitude === "number"
|
|
373
|
+
? `(${loc.degreesLatitude.toFixed(6)}, ${loc.degreesLongitude.toFixed(6)})`
|
|
374
|
+
: "";
|
|
375
|
+
return `[location shared ${named}${named && coords ? " " : ""}${coords}]`.trim();
|
|
376
|
+
}
|
|
377
|
+
// Live-location update — placeholder so a stream of these doesn't drop silently.
|
|
378
|
+
if (content.liveLocationMessage)
|
|
379
|
+
return "[live location update]";
|
|
380
|
+
return "";
|
|
381
|
+
}
|
|
382
|
+
/**
|
|
383
|
+
* Wrapper envelopes Baileys' own `normalizeMessageContent` may not unwrap
|
|
384
|
+
* (newer message kinds, hosted-LID variants). Walks the chain in lock-step
|
|
385
|
+
* with `inbound-extras.ts:unwrapMessage` so caller behavior is consistent.
|
|
386
|
+
*/
|
|
387
|
+
const WRAPPER_KEYS = [
|
|
388
|
+
"ephemeralMessage",
|
|
389
|
+
"viewOnceMessage",
|
|
390
|
+
"viewOnceMessageV2",
|
|
391
|
+
"viewOnceMessageV2Extension",
|
|
392
|
+
"documentWithCaptionMessage",
|
|
393
|
+
"botInvokeMessage",
|
|
394
|
+
"groupMentionedMessage",
|
|
395
|
+
];
|
|
396
|
+
function unwrapWrapperEnvelopes(message) {
|
|
397
|
+
let current = message;
|
|
398
|
+
for (let depth = 0; depth < 8 && current; depth += 1) {
|
|
399
|
+
const obj = current;
|
|
400
|
+
let inner;
|
|
401
|
+
for (const key of WRAPPER_KEYS) {
|
|
402
|
+
const wrapper = obj[key];
|
|
403
|
+
if (wrapper?.message) {
|
|
404
|
+
inner = wrapper.message;
|
|
405
|
+
break;
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
if (!inner)
|
|
409
|
+
return current;
|
|
410
|
+
current = inner;
|
|
411
|
+
}
|
|
412
|
+
return current;
|
|
413
|
+
}
|
|
414
|
+
/**
|
|
415
|
+
* Establish a WhatsApp Web connection with auto-reconnect. Resolves once the
|
|
416
|
+
* first socket is constructed (NOT once connected — QR/open events arrive via
|
|
417
|
+
* the callbacks). The returned handle owns the reconnect loop.
|
|
418
|
+
*/
|
|
419
|
+
/**
|
|
420
|
+
* Patch `console.info` ONCE per process so the libsignal protocol library
|
|
421
|
+
* (Baileys' Signal implementation) stops dumping massive `Closing session:
|
|
422
|
+
* SessionEntry { … }` objects into the gateway log on every key-ratchet step.
|
|
423
|
+
* That's a debug print inside `libsignal/src/session_record.js` we can't reach
|
|
424
|
+
* to remove; filtering at the console layer keeps the gateway log readable
|
|
425
|
+
* without losing real `console.info` calls.
|
|
426
|
+
*
|
|
427
|
+
* Idempotent — the patch checks for its own marker so a second `connectWhatsApp`
|
|
428
|
+
* call doesn't double-wrap.
|
|
429
|
+
*/
|
|
430
|
+
const LIBSIGNAL_FILTER_MARKER = Symbol.for("brigade.libsignal.console.filter");
|
|
431
|
+
function installLibsignalConsoleFilter() {
|
|
432
|
+
const flag = console;
|
|
433
|
+
if (flag[LIBSIGNAL_FILTER_MARKER])
|
|
434
|
+
return;
|
|
435
|
+
const original = console.info.bind(console);
|
|
436
|
+
console.info = ((...callArgs) => {
|
|
437
|
+
const first = callArgs[0];
|
|
438
|
+
if (typeof first === "string" && first.startsWith("Closing session:"))
|
|
439
|
+
return;
|
|
440
|
+
original(...callArgs);
|
|
441
|
+
});
|
|
442
|
+
flag[LIBSIGNAL_FILTER_MARKER] = true;
|
|
443
|
+
}
|
|
444
|
+
// Filesystem-mode creds durability. Baileys' useMultiFileAuthState persists
|
|
445
|
+
// creds.json with a single non-atomic fs.writeFile and keeps no backup, so a
|
|
446
|
+
// crash mid-save can truncate the file; on the next boot the parse fails,
|
|
447
|
+
// Baileys falls back to a fresh unlinked identity, and the operator is forced
|
|
448
|
+
// to re-scan the QR. The WhatsApp link surviving a restart is a stated Brigade
|
|
449
|
+
// priority (see the final creds flush in close()), so the filesystem branch
|
|
450
|
+
// wraps creds persistence to be crash-safe: a parseable on-disk copy is mirrored
|
|
451
|
+
// to a sibling backup before each write, and the new state is written to a temp
|
|
452
|
+
// file then atomically renamed into place. Convex mode is unaffected — it rides
|
|
453
|
+
// useConvexAuthState with its own write-behind store.
|
|
454
|
+
const FS_CREDS_FILE_NAME = "creds.json";
|
|
455
|
+
const FS_CREDS_BACKUP_FILE_NAME = "creds.json.bak";
|
|
456
|
+
/** True iff `path` exists and its contents parse as JSON. Best-effort. */
|
|
457
|
+
async function fileParsesAsJson(path) {
|
|
458
|
+
try {
|
|
459
|
+
const raw = await readFile(path, "utf8");
|
|
460
|
+
JSON.parse(raw);
|
|
461
|
+
return true;
|
|
462
|
+
}
|
|
463
|
+
catch {
|
|
464
|
+
return false;
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
/**
|
|
468
|
+
* Before the first socket is built, recover from a half-written creds.json:
|
|
469
|
+
* when the live creds file is missing/empty/unparseable but the sibling backup
|
|
470
|
+
* parses cleanly, copy the backup over creds.json so Baileys loads the last
|
|
471
|
+
* good identity instead of minting a fresh one (which would force a re-pair).
|
|
472
|
+
* Best-effort — any failure degrades to Baileys' own fresh-creds path.
|
|
473
|
+
*/
|
|
474
|
+
async function restoreFsCredsFromBackupIfNeeded(authDir, log) {
|
|
475
|
+
try {
|
|
476
|
+
const credsPath = joinPath(authDir, FS_CREDS_FILE_NAME);
|
|
477
|
+
const backupPath = joinPath(authDir, FS_CREDS_BACKUP_FILE_NAME);
|
|
478
|
+
// Live file already good — nothing to do.
|
|
479
|
+
if (await fileParsesAsJson(credsPath))
|
|
480
|
+
return;
|
|
481
|
+
// No usable backup — leave Baileys to mint fresh creds.
|
|
482
|
+
if (!(await fileParsesAsJson(backupPath)))
|
|
483
|
+
return;
|
|
484
|
+
await copyFile(backupPath, credsPath);
|
|
485
|
+
try {
|
|
486
|
+
await chmod(credsPath, 0o600);
|
|
487
|
+
}
|
|
488
|
+
catch {
|
|
489
|
+
// chmod is a no-op / unsupported on some filesystems — ignore.
|
|
490
|
+
}
|
|
491
|
+
log("restored WhatsApp creds from backup after a corrupt/missing creds file");
|
|
492
|
+
}
|
|
493
|
+
catch (err) {
|
|
494
|
+
// Restore is opportunistic — never let it block a connect.
|
|
495
|
+
log("WhatsApp creds backup-restore skipped", {
|
|
496
|
+
error: err instanceof Error ? err.message : String(err),
|
|
497
|
+
});
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
/**
|
|
501
|
+
* Build a crash-safe replacement for Baileys' raw saveCreds (filesystem branch
|
|
502
|
+
* only). Baileys' saveCreds writes only creds.json, so fully owning that one
|
|
503
|
+
* write is sufficient. Each save: (1) mirror a currently-parseable creds.json to
|
|
504
|
+
* creds.json.bak — skipped when the live file is missing/corrupt so a known-good
|
|
505
|
+
* backup is never clobbered; (2) serialize the live creds with Baileys'
|
|
506
|
+
* BufferJSON.replacer to a unique temp file, then fs.rename it onto creds.json
|
|
507
|
+
* (atomic on the same filesystem). The temp file is cleaned up on error.
|
|
508
|
+
* `liveCreds` is the same object Baileys mutates in state.creds, so it always
|
|
509
|
+
* reflects the latest credentials at write time.
|
|
510
|
+
*/
|
|
511
|
+
function makeFsCrashSafeCredsSaver(authDir, liveCreds, bufferJsonReplacer, log) {
|
|
512
|
+
const credsPath = joinPath(authDir, FS_CREDS_FILE_NAME);
|
|
513
|
+
const backupPath = joinPath(authDir, FS_CREDS_BACKUP_FILE_NAME);
|
|
514
|
+
return async () => {
|
|
515
|
+
// 1. Back up the live file only when it currently parses — never
|
|
516
|
+
// overwrite a good backup with a truncated one.
|
|
517
|
+
try {
|
|
518
|
+
if (await fileParsesAsJson(credsPath)) {
|
|
519
|
+
await copyFile(credsPath, backupPath);
|
|
520
|
+
try {
|
|
521
|
+
await chmod(backupPath, 0o600);
|
|
522
|
+
}
|
|
523
|
+
catch {
|
|
524
|
+
// chmod unsupported here — ignore.
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
catch (err) {
|
|
529
|
+
// A failed backup must not block the actual save.
|
|
530
|
+
log("WhatsApp creds backup skipped", {
|
|
531
|
+
error: err instanceof Error ? err.message : String(err),
|
|
532
|
+
});
|
|
533
|
+
}
|
|
534
|
+
// 2. Atomic write: temp file + rename.
|
|
535
|
+
const tmpPath = joinPath(authDir, `.creds.${process.pid}.${Date.now()}.tmp`);
|
|
536
|
+
try {
|
|
537
|
+
await writeFile(tmpPath, JSON.stringify(liveCreds, bufferJsonReplacer));
|
|
538
|
+
try {
|
|
539
|
+
await chmod(tmpPath, 0o600);
|
|
540
|
+
}
|
|
541
|
+
catch {
|
|
542
|
+
// chmod unsupported here — ignore.
|
|
543
|
+
}
|
|
544
|
+
await rename(tmpPath, credsPath);
|
|
545
|
+
}
|
|
546
|
+
catch (err) {
|
|
547
|
+
// Best-effort temp cleanup so a failed write doesn't litter authDir.
|
|
548
|
+
try {
|
|
549
|
+
await access(tmpPath);
|
|
550
|
+
await unlink(tmpPath);
|
|
551
|
+
}
|
|
552
|
+
catch {
|
|
553
|
+
// Temp file never created or already gone — nothing to clean.
|
|
554
|
+
}
|
|
555
|
+
throw err instanceof Error ? err : new Error(String(err));
|
|
556
|
+
}
|
|
557
|
+
};
|
|
558
|
+
}
|
|
559
|
+
export async function connectWhatsApp(args) {
|
|
560
|
+
installLibsignalConsoleFilter();
|
|
561
|
+
const baileys = await import("@whiskeysockets/baileys");
|
|
562
|
+
const makeWASocket = (baileys.default ?? baileys.makeWASocket);
|
|
563
|
+
const { DisconnectReason, fetchLatestBaileysVersion, makeCacheableSignalKeyStore, normalizeMessageContent, useMultiFileAuthState } = baileys;
|
|
564
|
+
const loggedOutCode = DisconnectReason?.loggedOut ?? 401;
|
|
565
|
+
const restartRequiredCode = DisconnectReason?.restartRequired ?? 515;
|
|
566
|
+
// Silent pino-shaped logger unless verbose — Baileys logs prolifically.
|
|
567
|
+
const level = args.verbose ? "info" : "silent";
|
|
568
|
+
const noop = () => { };
|
|
569
|
+
const baileysLogger = {
|
|
570
|
+
level,
|
|
571
|
+
trace: noop,
|
|
572
|
+
debug: noop,
|
|
573
|
+
info: noop,
|
|
574
|
+
warn: noop,
|
|
575
|
+
error: noop,
|
|
576
|
+
fatal: noop,
|
|
577
|
+
child: () => baileysLogger,
|
|
578
|
+
};
|
|
579
|
+
// Auth state — mode dispatch. Filesystem: Baileys' own multi-file dir
|
|
580
|
+
// (~900 small files under the channel state dir). Convex: the
|
|
581
|
+
// whatsappAuthCreds/whatsappAuthKeys tables via useConvexAuthState — no
|
|
582
|
+
// auth files on disk; key material is sealed before it leaves the
|
|
583
|
+
// process; pre-hydrated in one query so Signal-path key reads never pay
|
|
584
|
+
// a network round-trip.
|
|
585
|
+
const rctxForAuth = tryGetRuntimeContext();
|
|
586
|
+
// One accountId for the whole connection: the auth-state load, the
|
|
587
|
+
// LID-reverse mirror lookups, and (convex) the close() flush all key off
|
|
588
|
+
// it. Hardcoding "default" downstream silently breaks any non-default
|
|
589
|
+
// WhatsApp account.
|
|
590
|
+
const connectionAccountId = args.accountId ?? "default";
|
|
591
|
+
let state;
|
|
592
|
+
let saveCreds;
|
|
593
|
+
// Convex-mode: the auth-state queues key writes write-behind. Capture its
|
|
594
|
+
// flush so close() can drain it — otherwise a fresh pair's keys can be
|
|
595
|
+
// lost when the link command exits right after a successful connect.
|
|
596
|
+
let convexAuthFlush;
|
|
597
|
+
if (rctxForAuth?.mode === "convex") {
|
|
598
|
+
const convexAuth = await useConvexAuthState(rctxForAuth.store, connectionAccountId, {
|
|
599
|
+
initAuthCreds: baileys.initAuthCreds,
|
|
600
|
+
BufferJSON: baileys.BufferJSON,
|
|
601
|
+
proto: baileys.proto,
|
|
602
|
+
});
|
|
603
|
+
state = convexAuth.state;
|
|
604
|
+
saveCreds = convexAuth.saveCreds;
|
|
605
|
+
convexAuthFlush = convexAuth.flush;
|
|
606
|
+
}
|
|
607
|
+
else {
|
|
608
|
+
// Recover a half-written creds.json from its backup BEFORE Baileys loads
|
|
609
|
+
// the auth state — otherwise a truncated file parses as null and Baileys
|
|
610
|
+
// mints a fresh identity, forcing a QR re-pair.
|
|
611
|
+
await restoreFsCredsFromBackupIfNeeded(args.authDir, args.log);
|
|
612
|
+
const multiFile = await useMultiFileAuthState(args.authDir);
|
|
613
|
+
state = multiFile.state;
|
|
614
|
+
// Replace Baileys' raw (non-atomic, no-backup) saveCreds with a crash-safe
|
|
615
|
+
// wrapper. Baileys' saveCreds writes only creds.json, so owning that one
|
|
616
|
+
// write fully closes the durability gap. state.creds is the live object
|
|
617
|
+
// Baileys mutates, so the wrapper always serializes the current creds.
|
|
618
|
+
saveCreds = makeFsCrashSafeCredsSaver(args.authDir, state.creds, baileys.BufferJSON.replacer, args.log);
|
|
619
|
+
}
|
|
620
|
+
const { version } = await fetchLatestBaileysVersion();
|
|
621
|
+
let sock = null;
|
|
622
|
+
let closed = false;
|
|
623
|
+
let reconnectAttempts = 0;
|
|
624
|
+
let reconnectTimer = null;
|
|
625
|
+
// Inbound dedupe: WhatsApp re-delivers the same msg.key.id after a
|
|
626
|
+
// reconnect; without this, the agent runs the LLM (and bills) twice and
|
|
627
|
+
// posts the reply twice. Per-connection lifetime.
|
|
628
|
+
const inboundDedupe = createDedupeCache({ maxEntries: 5_000, ttlMs: 60 * 60 * 1_000 });
|
|
629
|
+
// Outbound id tracking — every successful send records `result.key.id` so
|
|
630
|
+
// the inbound `fromMe` echo (WhatsApp mirrors our own sends back through
|
|
631
|
+
// `messages.upsert`) can be distinguished from a genuine self-chat. Without
|
|
632
|
+
// this we'd have to blanket-drop `fromMe`, which silences the operator
|
|
633
|
+
// DMing themselves (selfChat). 20-min TTL — long enough to survive a
|
|
634
|
+
// slow reconnect, short enough to bound memory on a chatty account.
|
|
635
|
+
const outboundDedupe = createDedupeCache({ maxEntries: 5_000, ttlMs: 20 * 60 * 1_000 });
|
|
636
|
+
/**
|
|
637
|
+
* Compose the outbound-dedupe key from the destination jid + the WhatsApp
|
|
638
|
+
* `msg.key.id`. WAMIDs are statistically unique, but defence-in-depth: if
|
|
639
|
+
* a future Baileys build ever reuses short ids across chats, an id-only
|
|
640
|
+
* key would collide and Brigade would mis-classify a real inbound from
|
|
641
|
+
* one chat as an echo of an outbound from another. Conversation-scoped
|
|
642
|
+
* keys close that window with no real cost.
|
|
643
|
+
*/
|
|
644
|
+
const outboundKey = (conversationId, messageId) => `${conversationId}:${messageId}`;
|
|
645
|
+
const recordOutboundId = (conversationId, id) => {
|
|
646
|
+
if (id)
|
|
647
|
+
outboundDedupe.remember(outboundKey(conversationId, id));
|
|
648
|
+
};
|
|
649
|
+
// Track the last QR we surfaced so a Baileys QR refresh (same string) doesn't
|
|
650
|
+
// flood the operator's terminal with duplicate prints. Only NEW QRs reach
|
|
651
|
+
// `args.onQr`.
|
|
652
|
+
let lastQr = null;
|
|
653
|
+
// Pending creds writes are tracked so a reconnect (notably the 515 that
|
|
654
|
+
// follows first-link) can wait for them to flush before rebuilding.
|
|
655
|
+
let pendingCredsSave = Promise.resolve();
|
|
656
|
+
// Epoch ms of the most recent `connection: "open"` event. Inbound messages
|
|
657
|
+
// older than `connectedAtMs - PAIRING_GRACE_MS` are treated as queued-since-
|
|
658
|
+
// last-restart history — the access-control gate uses this to suppress
|
|
659
|
+
// pairing-challenge replies to historical DMs (otherwise every stranger
|
|
660
|
+
// who messaged Brigade since the last shutdown gets a code in a burst
|
|
661
|
+
// the moment the gateway reconnects).
|
|
662
|
+
let connectedAtMs = null;
|
|
663
|
+
// How long a "healthy" session must run before its next disconnect is
|
|
664
|
+
// treated as a fresh flap rather than another retry inside an existing
|
|
665
|
+
// failure sequence. Without this guard a link that ran fine for 2 hours
|
|
666
|
+
// then blipped would consume all 12 reconnect attempts in a few minutes;
|
|
667
|
+
// every flap mid-cycle would count as one more retry against a budget
|
|
668
|
+
// that should have been considered fresh.
|
|
669
|
+
const LONG_SESSION_RESET_MS = 60_000;
|
|
670
|
+
// Watchdog state. Two clocks:
|
|
671
|
+
// `lastInboundAt` — bumped on ANY notify frame (incl. status@broadcast).
|
|
672
|
+
// Coarse "transport seeing traffic" signal; kept for telemetry + back-
|
|
673
|
+
// compat with consumers that may already read it.
|
|
674
|
+
// `lastActivityAt` — bumped ONLY after per-message filtering rejects the
|
|
675
|
+
// broadcast / dedupe / LID-unresolvable cases, so the watchdog wakes
|
|
676
|
+
// up when REAL DM/group inbound stops flowing — not when story updates
|
|
677
|
+
// happen to keep the socket warm.
|
|
678
|
+
// The watchdog reads `lastActivityAt`. Disabled in linkMode (one-shot).
|
|
679
|
+
let lastInboundAt = Date.now();
|
|
680
|
+
let lastActivityAt = Date.now();
|
|
681
|
+
let watchdogTimer = null;
|
|
682
|
+
// Periodic outbound presence ping — keeps WhatsApp's server convinced the
|
|
683
|
+
// device is online even during long idle windows. Armed when the link
|
|
684
|
+
// opens, cleared on teardown.
|
|
685
|
+
let presencePingTimer = null;
|
|
686
|
+
// Cold-start presence nudge timers — extra presence-updates fired in the
|
|
687
|
+
// first ~30s after each `connection.open` to convince WhatsApp's server
|
|
688
|
+
// the device is genuinely ready and trigger immediate queue flush.
|
|
689
|
+
// Cleared on teardown AND cancelled the moment real conversational
|
|
690
|
+
// traffic starts flowing (no need to keep nagging once we know the
|
|
691
|
+
// queue is open).
|
|
692
|
+
let coldStartNudgeTimers = [];
|
|
693
|
+
const clearColdStartNudges = () => {
|
|
694
|
+
for (const t of coldStartNudgeTimers)
|
|
695
|
+
clearTimeout(t);
|
|
696
|
+
coldStartNudgeTimers = [];
|
|
697
|
+
};
|
|
698
|
+
// Max-session-age guard — preventively recycles the socket every N hours
|
|
699
|
+
// so accumulated Signal-state drift can't silently kill inbound delivery.
|
|
700
|
+
let sessionAgeTimer = null;
|
|
701
|
+
const WATCHDOG_CHECK_MS = 60_000;
|
|
702
|
+
const WATCHDOG_STALE_MS = 10 * 60 * 1_000;
|
|
703
|
+
// Connect-time liveness probe. As soon as the link opens we want proof that
|
|
704
|
+
// inbound is actually flowing — not just a socket that *says* "ready" while
|
|
705
|
+
// the server silently holds the queue (the "turn it on after a week and
|
|
706
|
+
// nothing arrives" failure). WhatsApp emits `receivedPendingNotifications:
|
|
707
|
+
// true` on `connection.update` once it has flushed everything that arrived
|
|
708
|
+
// while the device was away; a real inbound also counts as proof. If NEITHER
|
|
709
|
+
// happens within COLD_START_HEALTH_MS of connect, the socket is wedged, so we
|
|
710
|
+
// force ONE immediate clean reconnect to wake it — instead of waiting out the
|
|
711
|
+
// 10-minute watchdog. Bounded to MAX_COLD_START_KICKS per attempt so a
|
|
712
|
+
// legitimately slow flush of a huge backlog can't become a reconnect-storm.
|
|
713
|
+
const COLD_START_HEALTH_MS = 90_000;
|
|
714
|
+
const MAX_COLD_START_KICKS = 2;
|
|
715
|
+
let coldStartHealthTimer = null;
|
|
716
|
+
let pendingNotificationsSeen = false;
|
|
717
|
+
let coldStartKicks = 0;
|
|
718
|
+
const clearColdStartHealth = () => {
|
|
719
|
+
if (coldStartHealthTimer) {
|
|
720
|
+
clearTimeout(coldStartHealthTimer);
|
|
721
|
+
coldStartHealthTimer = null;
|
|
722
|
+
}
|
|
723
|
+
};
|
|
724
|
+
// Signal-protocol crypto errors don't reach `connection.update` — they
|
|
725
|
+
// surface as unhandled rejections from inside Baileys' async ratchet.
|
|
726
|
+
// Trap them per-connection and force a fast reconnect; the handler is
|
|
727
|
+
// idempotent (the `closed` + `linkMode` guards keep multi-account
|
|
728
|
+
// processes safe) and is removed on `close()`. The actual `process.on`
|
|
729
|
+
// registration happens at the bottom of `connectWhatsApp` once
|
|
730
|
+
// `teardownSocket` and `scheduleReconnect` have been declared.
|
|
731
|
+
const onUnhandledRejection = (reason) => {
|
|
732
|
+
if (closed || args.linkMode)
|
|
733
|
+
return;
|
|
734
|
+
if (!isWaCryptoError(reason))
|
|
735
|
+
return;
|
|
736
|
+
args.log("WhatsApp Signal-crypto error — force-reconnecting", {
|
|
737
|
+
error: String(reason?.message ?? reason ?? ""),
|
|
738
|
+
});
|
|
739
|
+
const dying = sock;
|
|
740
|
+
sock = null;
|
|
741
|
+
teardownSocket(dying);
|
|
742
|
+
reconnectAttempts = 0;
|
|
743
|
+
scheduleReconnect({ immediate: true });
|
|
744
|
+
};
|
|
745
|
+
/** Detach every listener from a socket and end it — no zombie emits. */
|
|
746
|
+
// Per-socket detach callbacks. Every listener attached inside `buildSocket`
|
|
747
|
+
// pushes its `() => emitter.off(event, handler)` here so `teardownSocket`
|
|
748
|
+
// can detach each one explicitly before falling back to the coarse
|
|
749
|
+
// `removeAllListeners()`. Explicit detach is the principled path —
|
|
750
|
+
// `removeAllListeners` would also drop any listener a future Brigade
|
|
751
|
+
// subsystem (a doctor probe, a sub-agent, an extension) might have
|
|
752
|
+
// attached to the same emitter.
|
|
753
|
+
const socketDetach = new Map();
|
|
754
|
+
const registerDetach = (s, off) => {
|
|
755
|
+
let list = socketDetach.get(s);
|
|
756
|
+
if (!list) {
|
|
757
|
+
list = [];
|
|
758
|
+
socketDetach.set(s, list);
|
|
759
|
+
}
|
|
760
|
+
list.push(off);
|
|
761
|
+
};
|
|
762
|
+
const teardownSocket = (s) => {
|
|
763
|
+
// Per-socket timers go down with the socket — a fresh `buildSocket`
|
|
764
|
+
// re-arms them in the next open handler. Clearing here keeps a
|
|
765
|
+
// reconnect from leaving zombie pings firing against a dead socket.
|
|
766
|
+
if (presencePingTimer) {
|
|
767
|
+
clearInterval(presencePingTimer);
|
|
768
|
+
presencePingTimer = null;
|
|
769
|
+
}
|
|
770
|
+
if (sessionAgeTimer) {
|
|
771
|
+
clearTimeout(sessionAgeTimer);
|
|
772
|
+
sessionAgeTimer = null;
|
|
773
|
+
}
|
|
774
|
+
clearColdStartNudges();
|
|
775
|
+
clearColdStartHealth();
|
|
776
|
+
if (!s)
|
|
777
|
+
return;
|
|
778
|
+
// Detach our own listeners explicitly first so we never drop
|
|
779
|
+
// listeners owned by callers (defense against a future cross-cutting
|
|
780
|
+
// subsystem subscribing to the same emitter).
|
|
781
|
+
const detaches = socketDetach.get(s);
|
|
782
|
+
if (detaches) {
|
|
783
|
+
for (const off of detaches) {
|
|
784
|
+
try {
|
|
785
|
+
off();
|
|
786
|
+
}
|
|
787
|
+
catch {
|
|
788
|
+
/* best-effort — keep going on the next detach */
|
|
789
|
+
}
|
|
790
|
+
}
|
|
791
|
+
socketDetach.delete(s);
|
|
792
|
+
}
|
|
793
|
+
// Belt-and-braces fallback: in case a Baileys-internal listener slipped
|
|
794
|
+
// past our register helper, the coarse removeAllListeners catches it.
|
|
795
|
+
try {
|
|
796
|
+
s.ev.removeAllListeners?.();
|
|
797
|
+
}
|
|
798
|
+
catch {
|
|
799
|
+
/* best-effort */
|
|
800
|
+
}
|
|
801
|
+
try {
|
|
802
|
+
const ws = s.ws;
|
|
803
|
+
ws?.removeAllListeners?.();
|
|
804
|
+
}
|
|
805
|
+
catch {
|
|
806
|
+
/* best-effort */
|
|
807
|
+
}
|
|
808
|
+
try {
|
|
809
|
+
s.end?.(undefined);
|
|
810
|
+
}
|
|
811
|
+
catch {
|
|
812
|
+
/* already torn down */
|
|
813
|
+
}
|
|
814
|
+
};
|
|
815
|
+
const scheduleReconnect = (opts = {}) => {
|
|
816
|
+
if (closed || reconnectTimer)
|
|
817
|
+
return;
|
|
818
|
+
if (reconnectAttempts >= RECONNECT_MAX_ATTEMPTS) {
|
|
819
|
+
args.log("WhatsApp reconnect attempts exhausted — giving up until restart", {
|
|
820
|
+
attempts: reconnectAttempts,
|
|
821
|
+
});
|
|
822
|
+
return;
|
|
823
|
+
}
|
|
824
|
+
// `immediate: true` is set by the 515 first-link recovery path — we know
|
|
825
|
+
// the creds just landed and there's no rate-limit risk reconnecting at
|
|
826
|
+
// once. Skipping the 2s backoff turns a 7-second pair into a 2-second
|
|
827
|
+
// pair and avoids a window where neither socket nor timer is anchoring
|
|
828
|
+
// the Node event loop. For drop recoveries we keep the jittered backoff.
|
|
829
|
+
const delay = opts.immediate ? 0 : backoffDelay(reconnectAttempts);
|
|
830
|
+
reconnectAttempts += 1;
|
|
831
|
+
// During linkMode the CLI is rendering a polished status; the technical
|
|
832
|
+
// "reconnecting attempt=N delayMs=…" line would clutter the link UX.
|
|
833
|
+
// Gateway mode keeps the structured log — operators want that detail.
|
|
834
|
+
if (!args.linkMode) {
|
|
835
|
+
args.log("WhatsApp reconnecting", { attempt: reconnectAttempts, delayMs: delay });
|
|
836
|
+
}
|
|
837
|
+
reconnectTimer = setTimeout(() => {
|
|
838
|
+
reconnectTimer = null;
|
|
839
|
+
if (closed)
|
|
840
|
+
return;
|
|
841
|
+
// Flush any pending creds write first (covers the 515 first-link race),
|
|
842
|
+
// then build a fresh socket on the same creds.
|
|
843
|
+
void pendingCredsSave
|
|
844
|
+
.catch(() => { })
|
|
845
|
+
.then(() => {
|
|
846
|
+
if (closed)
|
|
847
|
+
return;
|
|
848
|
+
sock = buildSocket();
|
|
849
|
+
});
|
|
850
|
+
}, delay);
|
|
851
|
+
// In gateway mode we `.unref()` so a permanently-broken link can't keep
|
|
852
|
+
// the daemon alive across shutdown. In linkMode we MUST NOT unref — the
|
|
853
|
+
// CLI's outer `await done` is the only thing holding the event loop
|
|
854
|
+
// open across the brief gap between socket teardown and rebuild; an
|
|
855
|
+
// unref'd timer plus a torn-down socket = nothing anchoring the loop,
|
|
856
|
+
// which surfaces as "Detected unsettled top-level await" and an early
|
|
857
|
+
// exit BEFORE the new socket reaches `open`.
|
|
858
|
+
if (!args.linkMode)
|
|
859
|
+
reconnectTimer.unref?.();
|
|
860
|
+
};
|
|
861
|
+
const buildSocket = () => {
|
|
862
|
+
const s = makeWASocket({
|
|
863
|
+
version,
|
|
864
|
+
// biome-ignore lint/suspicious/noExplicitAny: pino-shaped stub logger
|
|
865
|
+
logger: baileysLogger,
|
|
866
|
+
printQRInTerminal: false,
|
|
867
|
+
browser: ["Brigade", "Chrome", "1.0.0"],
|
|
868
|
+
syncFullHistory: false,
|
|
869
|
+
markOnlineOnConnect: false,
|
|
870
|
+
// Explicit timeouts + keepalive. Baileys' defaults work in
|
|
871
|
+
// well-connected environments but leave the door open to slow
|
|
872
|
+
// silent failures over flaky networks: keepalive at 25s sits
|
|
873
|
+
// under WhatsApp's typical 30s server-side idle threshold so
|
|
874
|
+
// the link gets nudged before the server marks it offline; the
|
|
875
|
+
// 60s connect/query timeouts give Baileys enough headroom on
|
|
876
|
+
// the initial handshake without dragging shutdown.
|
|
877
|
+
keepAliveIntervalMs: 25_000,
|
|
878
|
+
connectTimeoutMs: 60_000,
|
|
879
|
+
defaultQueryTimeoutMs: 60_000,
|
|
880
|
+
retryRequestDelayMs: 250,
|
|
881
|
+
qrTimeout: 60_000,
|
|
882
|
+
auth: {
|
|
883
|
+
creds: state.creds,
|
|
884
|
+
// biome-ignore lint/suspicious/noExplicitAny: pino-shaped stub logger
|
|
885
|
+
keys: makeCacheableSignalKeyStore(state.keys, baileysLogger),
|
|
886
|
+
},
|
|
887
|
+
});
|
|
888
|
+
const credsUpdateHandler = () => {
|
|
889
|
+
pendingCredsSave = Promise.resolve(saveCreds()).catch((err) => {
|
|
890
|
+
args.log("failed saving WhatsApp creds", { error: err instanceof Error ? err.message : String(err) });
|
|
891
|
+
});
|
|
892
|
+
};
|
|
893
|
+
s.ev.on("creds.update", credsUpdateHandler);
|
|
894
|
+
registerDetach(s, () => {
|
|
895
|
+
s.ev.off?.("creds.update", credsUpdateHandler);
|
|
896
|
+
});
|
|
897
|
+
const connectionUpdateHandler = (update) => {
|
|
898
|
+
// Wrap the whole handler — a throw inside a Baileys event emit would
|
|
899
|
+
// otherwise surface as an unhandled rejection and could crash the daemon.
|
|
900
|
+
try {
|
|
901
|
+
const { connection, lastDisconnect, qr } = update;
|
|
902
|
+
// Offline-queue flush signal — WhatsApp sets
|
|
903
|
+
// `receivedPendingNotifications: true` on `connection.update` once it
|
|
904
|
+
// has delivered everything that arrived while the device was away.
|
|
905
|
+
// That's positive proof inbound is flowing (not a connected-but-deaf
|
|
906
|
+
// socket), so we disarm the connect-time liveness probe and announce
|
|
907
|
+
// the catch-up — the operator sees "turned it on → immediately caught
|
|
908
|
+
// up", even after a week away.
|
|
909
|
+
if (update.receivedPendingNotifications) {
|
|
910
|
+
if (!pendingNotificationsSeen) {
|
|
911
|
+
pendingNotificationsSeen = true;
|
|
912
|
+
coldStartKicks = 0;
|
|
913
|
+
clearColdStartHealth();
|
|
914
|
+
if (!args.linkMode)
|
|
915
|
+
args.log("WhatsApp caught up — offline message queue flushed");
|
|
916
|
+
}
|
|
917
|
+
}
|
|
918
|
+
// Dedupe QR refreshes — Baileys re-emits the same string on its own
|
|
919
|
+
// polling cadence; only forward when the QR actually changed so the
|
|
920
|
+
// operator's terminal doesn't fill with identical QR codes.
|
|
921
|
+
if (qr && qr !== lastQr) {
|
|
922
|
+
lastQr = qr;
|
|
923
|
+
args.onQr?.(qr);
|
|
924
|
+
}
|
|
925
|
+
if (connection === "open") {
|
|
926
|
+
reconnectAttempts = 0; // healthy link — reset backoff
|
|
927
|
+
lastQr = null; // any future QR is genuinely a re-pair
|
|
928
|
+
const now = Date.now();
|
|
929
|
+
lastInboundAt = now; // coarse "frames flowing" reset on fresh link
|
|
930
|
+
lastActivityAt = now; // watchdog clock reset on fresh link
|
|
931
|
+
connectedAtMs = now; // anchor the pairing-grace window
|
|
932
|
+
pendingNotificationsSeen = false; // re-arm the connect-time liveness probe
|
|
933
|
+
clearColdStartHealth();
|
|
934
|
+
// Gateway mode: always log the structured event.
|
|
935
|
+
// Link mode: the CLI renders the polished success card itself,
|
|
936
|
+
// so suppress the duplicate "connected" log here.
|
|
937
|
+
if (!args.linkMode)
|
|
938
|
+
args.log("connected to WhatsApp");
|
|
939
|
+
args.onConnected?.();
|
|
940
|
+
// Tell WhatsApp's server we're online and ready for queued
|
|
941
|
+
// messages. Without this nudge the server can sit on queued
|
|
942
|
+
// inbound for hours (boot connection silent until a later
|
|
943
|
+
// reconnect happens to push the queue) — exactly the overnight
|
|
944
|
+
// "connected but no messages" failure mode. Fires on EVERY
|
|
945
|
+
// fresh `open`, not just the first connect, so watchdog-
|
|
946
|
+
// triggered reconnects also reannounce presence. `queueMicrotask`
|
|
947
|
+
// so `onConnected` callers see the connection before any
|
|
948
|
+
// outbound traffic.
|
|
949
|
+
if (!args.linkMode) {
|
|
950
|
+
queueMicrotask(() => {
|
|
951
|
+
const live = sock;
|
|
952
|
+
if (!live)
|
|
953
|
+
return;
|
|
954
|
+
void Promise.resolve()
|
|
955
|
+
.then(() => live.sendPresenceUpdate?.("available"))
|
|
956
|
+
.catch((err) => {
|
|
957
|
+
args.log("WhatsApp presence-update on open failed", {
|
|
958
|
+
error: err instanceof Error ? err.message : String(err),
|
|
959
|
+
});
|
|
960
|
+
});
|
|
961
|
+
});
|
|
962
|
+
// Cold-start nudges. The single presence-update above is
|
|
963
|
+
// often not enough to convince WhatsApp's server the device
|
|
964
|
+
// is "really" ready — there's a server-side debounce that
|
|
965
|
+
// otherwise holds the queue for ~60s before flushing. Three
|
|
966
|
+
// quick re-pings during the cold window pull that floor
|
|
967
|
+
// down to ~5-15s. Self-cancel as soon as real inbound
|
|
968
|
+
// flows (see the per-message loop). New nudges replace any
|
|
969
|
+
// stale ones from a prior `open` event in the same lifetime.
|
|
970
|
+
clearColdStartNudges();
|
|
971
|
+
for (const offset of COLD_START_NUDGES_MS) {
|
|
972
|
+
const timer = setTimeout(() => {
|
|
973
|
+
if (closed)
|
|
974
|
+
return;
|
|
975
|
+
const live = sock;
|
|
976
|
+
if (!live)
|
|
977
|
+
return;
|
|
978
|
+
void Promise.resolve()
|
|
979
|
+
.then(() => live.sendPresenceUpdate?.("available"))
|
|
980
|
+
.catch((err) => {
|
|
981
|
+
args.log("WhatsApp cold-start presence-nudge failed", {
|
|
982
|
+
offsetMs: offset,
|
|
983
|
+
error: err instanceof Error ? err.message : String(err),
|
|
984
|
+
});
|
|
985
|
+
});
|
|
986
|
+
}, offset);
|
|
987
|
+
timer.unref?.();
|
|
988
|
+
coldStartNudgeTimers.push(timer);
|
|
989
|
+
}
|
|
990
|
+
// Arm the periodic presence ping (idle keepalive nudge).
|
|
991
|
+
// Cleared by `teardownSocket` on the next reconnect / close.
|
|
992
|
+
if (presencePingTimer)
|
|
993
|
+
clearInterval(presencePingTimer);
|
|
994
|
+
const pingInterval = presencePingMs();
|
|
995
|
+
presencePingTimer = setInterval(() => {
|
|
996
|
+
if (closed)
|
|
997
|
+
return;
|
|
998
|
+
const live = sock;
|
|
999
|
+
if (!live)
|
|
1000
|
+
return;
|
|
1001
|
+
void Promise.resolve()
|
|
1002
|
+
.then(() => live.sendPresenceUpdate?.("available"))
|
|
1003
|
+
.catch((err) => {
|
|
1004
|
+
args.log("WhatsApp presence-ping failed", {
|
|
1005
|
+
error: err instanceof Error ? err.message : String(err),
|
|
1006
|
+
});
|
|
1007
|
+
});
|
|
1008
|
+
}, pingInterval);
|
|
1009
|
+
presencePingTimer.unref?.();
|
|
1010
|
+
// Arm the max-session-age recycle. After N hours we force a
|
|
1011
|
+
// clean reconnect regardless of how healthy the link looks —
|
|
1012
|
+
// preventive defense against accumulated Signal state drift.
|
|
1013
|
+
if (sessionAgeTimer)
|
|
1014
|
+
clearTimeout(sessionAgeTimer);
|
|
1015
|
+
const sessionAge = maxSessionAgeMs();
|
|
1016
|
+
sessionAgeTimer = setTimeout(() => {
|
|
1017
|
+
if (closed)
|
|
1018
|
+
return;
|
|
1019
|
+
args.log("WhatsApp forced reconnect after max session age", {
|
|
1020
|
+
maxAgeMs: sessionAge,
|
|
1021
|
+
});
|
|
1022
|
+
const dying = sock;
|
|
1023
|
+
sock = null;
|
|
1024
|
+
teardownSocket(dying);
|
|
1025
|
+
reconnectAttempts = 0; // preventive recycle isn't a failure
|
|
1026
|
+
scheduleReconnect();
|
|
1027
|
+
}, sessionAge);
|
|
1028
|
+
sessionAgeTimer.unref?.();
|
|
1029
|
+
// Arm the connect-time liveness probe (one-shot per open). If
|
|
1030
|
+
// the offline-queue flush (`receivedPendingNotifications`)
|
|
1031
|
+
// hasn't arrived AND no real inbound has flowed within
|
|
1032
|
+
// COLD_START_HEALTH_MS, the socket is connected-but-deaf — force
|
|
1033
|
+
// ONE immediate clean reconnect so a wedged link wakes up in
|
|
1034
|
+
// ~90s instead of waiting out the 10-minute watchdog. Bounded by
|
|
1035
|
+
// MAX_COLD_START_KICKS so a legitimately slow flush of a huge
|
|
1036
|
+
// backlog can't become a reconnect-storm; after that we leave it
|
|
1037
|
+
// to the steady-state watchdog.
|
|
1038
|
+
clearColdStartHealth();
|
|
1039
|
+
coldStartHealthTimer = setTimeout(() => {
|
|
1040
|
+
if (closed || !sock)
|
|
1041
|
+
return;
|
|
1042
|
+
if (pendingNotificationsSeen)
|
|
1043
|
+
return; // queue flushed / inbound flowed — healthy
|
|
1044
|
+
if (Date.now() - lastActivityAt < COLD_START_HEALTH_MS)
|
|
1045
|
+
return; // real inbound recently
|
|
1046
|
+
if (coldStartKicks >= MAX_COLD_START_KICKS) {
|
|
1047
|
+
args.log("WhatsApp liveness probe — still no inbound after retries; leaving it to the watchdog", {
|
|
1048
|
+
kicks: coldStartKicks,
|
|
1049
|
+
});
|
|
1050
|
+
return;
|
|
1051
|
+
}
|
|
1052
|
+
coldStartKicks += 1;
|
|
1053
|
+
args.log("WhatsApp liveness probe — no inbound flow after connect, forcing reconnect to wake the link", {
|
|
1054
|
+
waitedMs: COLD_START_HEALTH_MS,
|
|
1055
|
+
kick: coldStartKicks,
|
|
1056
|
+
});
|
|
1057
|
+
const dying = sock;
|
|
1058
|
+
sock = null;
|
|
1059
|
+
teardownSocket(dying);
|
|
1060
|
+
reconnectAttempts = 0; // liveness kick isn't a failure sequence
|
|
1061
|
+
scheduleReconnect({ immediate: true });
|
|
1062
|
+
}, COLD_START_HEALTH_MS);
|
|
1063
|
+
coldStartHealthTimer.unref?.();
|
|
1064
|
+
}
|
|
1065
|
+
}
|
|
1066
|
+
if (connection === "close") {
|
|
1067
|
+
const status = lastDisconnect?.error?.output
|
|
1068
|
+
?.statusCode;
|
|
1069
|
+
// Tear the dead socket down BEFORE doing anything else so its
|
|
1070
|
+
// listeners can't fire again (no leak, no duplicate inbound).
|
|
1071
|
+
teardownSocket(s);
|
|
1072
|
+
if (sock === s)
|
|
1073
|
+
sock = null;
|
|
1074
|
+
// If this socket lived for more than LONG_SESSION_RESET_MS, the
|
|
1075
|
+
// close is a fresh flap — not the continuation of a failing
|
|
1076
|
+
// reconnect sequence. Reset the attempt counter so the new
|
|
1077
|
+
// flap gets the full 12-retry budget instead of inheriting a
|
|
1078
|
+
// burned-down one from earlier in the day. Without this guard,
|
|
1079
|
+
// a single transient blip after a healthy 2-hour session can
|
|
1080
|
+
// exhaust the budget within minutes.
|
|
1081
|
+
if (connectedAtMs !== null &&
|
|
1082
|
+
Date.now() - connectedAtMs >= LONG_SESSION_RESET_MS &&
|
|
1083
|
+
reconnectAttempts > 0) {
|
|
1084
|
+
reconnectAttempts = 0;
|
|
1085
|
+
}
|
|
1086
|
+
if (status === loggedOutCode) {
|
|
1087
|
+
args.log("WhatsApp session logged out — re-link required");
|
|
1088
|
+
args.onLoggedOut?.();
|
|
1089
|
+
return; // dead creds — never reconnect
|
|
1090
|
+
}
|
|
1091
|
+
if (status === MULTI_DEVICE_CONFLICT_CODE) {
|
|
1092
|
+
// A new WhatsApp Web session opened against the same number
|
|
1093
|
+
// (another linked Brigade, a manual Web login, or the
|
|
1094
|
+
// operator scanning the QR somewhere else). Reconnecting
|
|
1095
|
+
// here would put us into a 440-conflict ping-pong with the
|
|
1096
|
+
// other session — both reconnect, both see 440, both
|
|
1097
|
+
// reconnect, forever. Treat as terminal; the operator must
|
|
1098
|
+
// resolve which session keeps the link.
|
|
1099
|
+
args.log("WhatsApp multi-device conflict — another linked Web session took over; not reconnecting");
|
|
1100
|
+
args.onLoggedOut?.();
|
|
1101
|
+
return;
|
|
1102
|
+
}
|
|
1103
|
+
if (status === restartRequiredCode) {
|
|
1104
|
+
// Expected immediately after first-link; reconnect promptly
|
|
1105
|
+
// without consuming the backoff budget. This single hop is
|
|
1106
|
+
// honored even in linkMode — it's part of the pair handshake.
|
|
1107
|
+
// During linkMode we emit a single polished progress string
|
|
1108
|
+
// instead of the technical "restart required" log; the CLI
|
|
1109
|
+
// renders it as "Finalising link…" — much friendlier than
|
|
1110
|
+
// "restart required → reconnecting" which sounds like an error.
|
|
1111
|
+
if (args.linkMode) {
|
|
1112
|
+
args.onLinkProgress?.("Finalising link…");
|
|
1113
|
+
}
|
|
1114
|
+
else {
|
|
1115
|
+
args.log("WhatsApp restart required (post-link) — reconnecting");
|
|
1116
|
+
}
|
|
1117
|
+
reconnectAttempts = 0;
|
|
1118
|
+
// Immediate reconnect — the creds-flush promise still gates
|
|
1119
|
+
// the rebuild, but there's no jittered 2s delay. Halves the
|
|
1120
|
+
// total link time and closes the unref'd-timer race window.
|
|
1121
|
+
scheduleReconnect({ immediate: true });
|
|
1122
|
+
return;
|
|
1123
|
+
}
|
|
1124
|
+
// In one-shot link mode, treat any non-515 close as a hard failure
|
|
1125
|
+
// so the link command's outer timeout / failure path can act on it.
|
|
1126
|
+
// The gateway path keeps the auto-reconnect (its job IS to stay up).
|
|
1127
|
+
if (args.linkMode) {
|
|
1128
|
+
args.log("WhatsApp connection dropped during link — aborting (linkMode)", { status });
|
|
1129
|
+
return;
|
|
1130
|
+
}
|
|
1131
|
+
scheduleReconnect();
|
|
1132
|
+
}
|
|
1133
|
+
}
|
|
1134
|
+
catch (err) {
|
|
1135
|
+
args.log("WhatsApp connection.update handler error", {
|
|
1136
|
+
error: err instanceof Error ? err.message : String(err),
|
|
1137
|
+
});
|
|
1138
|
+
}
|
|
1139
|
+
};
|
|
1140
|
+
s.ev.on("connection.update", connectionUpdateHandler);
|
|
1141
|
+
registerDetach(s, () => {
|
|
1142
|
+
s.ev.off?.("connection.update", connectionUpdateHandler);
|
|
1143
|
+
});
|
|
1144
|
+
const messagesUpsertHandler = (payload) => {
|
|
1145
|
+
// `notify` = live messages. `append` = the offline/history catch-up
|
|
1146
|
+
// batch WhatsApp delivers on (re)connect — the messages that arrived
|
|
1147
|
+
// while the device was away. We accept BOTH (mirrors the reference
|
|
1148
|
+
// codebase) so a gateway turned on after a long offline window
|
|
1149
|
+
// immediately surfaces what it missed; the per-message handler gates
|
|
1150
|
+
// `append` to RECENT entries (within APPEND_RECENT_GRACE_MS of connect)
|
|
1151
|
+
// so we catch genuinely-missed live messages without replaying the
|
|
1152
|
+
// whole backlog of old chats.
|
|
1153
|
+
if (payload.type !== "notify" && payload.type !== "append")
|
|
1154
|
+
return;
|
|
1155
|
+
const upsertType = payload.type;
|
|
1156
|
+
// Coarse "frames are flowing" clock — bumped on ANY notify, including
|
|
1157
|
+
// status broadcasts and other passthrough traffic. This proves the
|
|
1158
|
+
// transport is alive but says nothing about real inbound delivery,
|
|
1159
|
+
// so the watchdog does NOT read it. Telemetry / back-compat only.
|
|
1160
|
+
lastInboundAt = Date.now();
|
|
1161
|
+
// Process each message in its own async task so media download (a
|
|
1162
|
+
// network round-trip) doesn't block the next message's dedupe claim.
|
|
1163
|
+
for (const m of payload.messages) {
|
|
1164
|
+
void (async () => {
|
|
1165
|
+
try {
|
|
1166
|
+
const jid = m.key.remoteJid;
|
|
1167
|
+
if (!jid)
|
|
1168
|
+
return;
|
|
1169
|
+
// Status/broadcast feeds — both legacy (`status@broadcast`) and
|
|
1170
|
+
// the suffix variants (`…@status`, `…@broadcast`) — are story
|
|
1171
|
+
// updates, never DMs to react to. They must NOT bump the
|
|
1172
|
+
// watchdog clock: if a contact posts a story every few
|
|
1173
|
+
// minutes, those notifies would otherwise keep the watchdog
|
|
1174
|
+
// satisfied while real DMs were silently queued server-side.
|
|
1175
|
+
if (jid === "status@broadcast" || jid.endsWith("@status") || jid.endsWith("@broadcast"))
|
|
1176
|
+
return;
|
|
1177
|
+
// Real DM/group inbound — bump the watchdog clock. From this
|
|
1178
|
+
// point on we know we've got actual conversational traffic.
|
|
1179
|
+
lastActivityAt = Date.now();
|
|
1180
|
+
// Cancel any pending cold-start nudges — the queue is open
|
|
1181
|
+
// and flowing, no need to keep nagging the server.
|
|
1182
|
+
if (coldStartNudgeTimers.length > 0)
|
|
1183
|
+
clearColdStartNudges();
|
|
1184
|
+
// Real inbound (live OR offline catch-up) proves delivery is
|
|
1185
|
+
// flowing — disarm the connect-time liveness probe.
|
|
1186
|
+
pendingNotificationsSeen = true;
|
|
1187
|
+
clearColdStartHealth();
|
|
1188
|
+
// History/offline catch-up (`append`) — process only RECENT
|
|
1189
|
+
// entries so a reconnect after a long offline window surfaces
|
|
1190
|
+
// genuinely-missed live messages without replaying the whole
|
|
1191
|
+
// backlog of old chats. Mirrors the reference codebase's
|
|
1192
|
+
// APPEND_RECENT_GRACE_MS gate. `notify` messages are always
|
|
1193
|
+
// live and skip this check.
|
|
1194
|
+
if (upsertType === "append") {
|
|
1195
|
+
const APPEND_RECENT_GRACE_MS = 60_000;
|
|
1196
|
+
const tsRaw = m.messageTimestamp;
|
|
1197
|
+
const tsSec = typeof tsRaw === "number"
|
|
1198
|
+
? tsRaw
|
|
1199
|
+
: tsRaw && typeof tsRaw.toNumber === "function"
|
|
1200
|
+
? tsRaw.toNumber()
|
|
1201
|
+
: 0;
|
|
1202
|
+
const tsMs = tsSec > 0 ? tsSec * 1000 : 0;
|
|
1203
|
+
if (connectedAtMs !== null && tsMs < connectedAtMs - APPEND_RECENT_GRACE_MS)
|
|
1204
|
+
return;
|
|
1205
|
+
}
|
|
1206
|
+
const isGroup = jid.endsWith("@g.us");
|
|
1207
|
+
const msgId = m.key.id;
|
|
1208
|
+
// `fromMe` handling. WhatsApp surfaces TWO distinct flavours of
|
|
1209
|
+
// `fromMe: true` messages through the same `messages.upsert`
|
|
1210
|
+
// event, and they must be handled completely differently:
|
|
1211
|
+
//
|
|
1212
|
+
// (a) ECHO of an outbound Brigade just sent — `msgId` is in
|
|
1213
|
+
// `outboundDedupe` (we remembered it on send). Always
|
|
1214
|
+
// drop; it's not user input.
|
|
1215
|
+
//
|
|
1216
|
+
// (b) OPERATOR TYPED ON A LINKED DEVICE (their phone, web,
|
|
1217
|
+
// another linked Brigade) — `msgId` is fresh. This branches:
|
|
1218
|
+
//
|
|
1219
|
+
// (b1) DM to a CONTACT (chat jid ≠ operator's own phone):
|
|
1220
|
+
// the operator messaging Mom from their phone. Brigade
|
|
1221
|
+
// MUST NOT engage with this — otherwise we'd send
|
|
1222
|
+
// Mom a pairing-challenge card from the operator's
|
|
1223
|
+
// own account. Drop silently. Matches the upstream
|
|
1224
|
+
// reference's access-control.ts:136-144 "Skipping outbound DM".
|
|
1225
|
+
//
|
|
1226
|
+
// (b2) SELF-CHAT (chat jid == operator's own phone): the
|
|
1227
|
+
// "notes-to-self" use case. Flow through as normal
|
|
1228
|
+
// inbound; the bot responds.
|
|
1229
|
+
//
|
|
1230
|
+
// (b3) GROUP: fall through so policy.ts can apply the
|
|
1231
|
+
// standard group rules. The operator is NOT auto-
|
|
1232
|
+
// allowed in groups — a group the operator hasn't
|
|
1233
|
+
// opted in (via `groupAllowJids`, or by being on the
|
|
1234
|
+
// group allow-from list) is dropped with reason
|
|
1235
|
+
// `group:not-allowlisted`, even for the operator's
|
|
1236
|
+
// own messages and self-tags.
|
|
1237
|
+
if (m.key.fromMe) {
|
|
1238
|
+
// (a) — known echo of our own outbound.
|
|
1239
|
+
if (!msgId || outboundDedupe.peek(outboundKey(jid, msgId)))
|
|
1240
|
+
return;
|
|
1241
|
+
// (b1) — operator messaged a contact from a linked device.
|
|
1242
|
+
// Detect by comparing the chat jid's canonical phone to the
|
|
1243
|
+
// linked self id. Resolution gates on having BOTH — without
|
|
1244
|
+
// either, we conservatively drop (better to miss a self-
|
|
1245
|
+
// chat than to spam a contact with a pairing card).
|
|
1246
|
+
if (!isGroup) {
|
|
1247
|
+
const selfPhone = canonicalWhatsAppId(sock?.user?.id);
|
|
1248
|
+
const chatPhone = await resolveJidToE164(sock, jid, args.authDir, connectionAccountId);
|
|
1249
|
+
const isSelfChat = !!(selfPhone && chatPhone && selfPhone === chatPhone);
|
|
1250
|
+
if (!isSelfChat) {
|
|
1251
|
+
args.log("dropped operator outbound DM (fromMe, not self-chat)", {
|
|
1252
|
+
jid,
|
|
1253
|
+
msgId,
|
|
1254
|
+
});
|
|
1255
|
+
return;
|
|
1256
|
+
}
|
|
1257
|
+
}
|
|
1258
|
+
// (b2) self-chat, or (b3) group: fall through.
|
|
1259
|
+
}
|
|
1260
|
+
// Drop duplicates of the same message — WhatsApp re-delivers the
|
|
1261
|
+
// same `msg.key.id` after a reconnect; without this guard the agent
|
|
1262
|
+
// would run twice (and bill twice) per real message.
|
|
1263
|
+
if (msgId && !inboundDedupe.claim(`${jid}:${msgId}`)) {
|
|
1264
|
+
args.log("dropped duplicate inbound (already processed)", { jid, msgId });
|
|
1265
|
+
return;
|
|
1266
|
+
}
|
|
1267
|
+
const normalized = normalizeMessageContent(m.message);
|
|
1268
|
+
const text = extractText(m.message, normalizeMessageContent).trim();
|
|
1269
|
+
// Media download is DEFERRED. Only a cheap envelope probe runs
|
|
1270
|
+
// here; the actual download (bytes from WhatsApp + seal +
|
|
1271
|
+
// backend archive) happens via `resolveMedia` AFTER the
|
|
1272
|
+
// pipeline's access-control gate admits the sender. Eager
|
|
1273
|
+
// download meant any stranger in any group could push videos
|
|
1274
|
+
// into the operator's storage even though the message itself
|
|
1275
|
+
// was dropped by policy.
|
|
1276
|
+
const hasMedia = !!(normalized && msgId) && hasInboundMedia(normalized);
|
|
1277
|
+
const resolveMedia = hasMedia && normalized && msgId
|
|
1278
|
+
? () => downloadInboundMedia({
|
|
1279
|
+
content: normalized,
|
|
1280
|
+
msgId,
|
|
1281
|
+
downloadMediaMessage: baileys.downloadMediaMessage,
|
|
1282
|
+
rawMessage: m,
|
|
1283
|
+
log: args.log,
|
|
1284
|
+
})
|
|
1285
|
+
: undefined;
|
|
1286
|
+
// Drop the message entirely only if there's no text AND no media.
|
|
1287
|
+
if (!text && !hasMedia)
|
|
1288
|
+
return;
|
|
1289
|
+
// Sender resolution. For DMs the chat jid itself is the sender;
|
|
1290
|
+
// for groups the per-message `participant` carries the speaker.
|
|
1291
|
+
// We resolve to a STABLE identity that NEVER drops a usable
|
|
1292
|
+
// sender (mirrors the reference codebase): the phone number when
|
|
1293
|
+
// the LID can be mapped, otherwise the canonical `@lid` alias
|
|
1294
|
+
// itself — so a group message from a privacy-aliased member
|
|
1295
|
+
// still reaches the access-control gate instead of vanishing at
|
|
1296
|
+
// the socket layer. Only a genuinely empty/unusable jid drops.
|
|
1297
|
+
const rawParticipant = m.key.participant?.trim();
|
|
1298
|
+
const senderJid = isGroup && rawParticipant && rawParticipant.length > 0 ? rawParticipant : jid;
|
|
1299
|
+
const senderIdentity = await resolveSenderIdentity(sock, senderJid, args.authDir, connectionAccountId);
|
|
1300
|
+
if (!senderIdentity) {
|
|
1301
|
+
args.log("inbound dropped — empty/unusable sender jid", {
|
|
1302
|
+
jid,
|
|
1303
|
+
participant: rawParticipant,
|
|
1304
|
+
});
|
|
1305
|
+
return;
|
|
1306
|
+
}
|
|
1307
|
+
const fromCanonical = senderIdentity.id;
|
|
1308
|
+
const senderLid = senderIdentity.lid;
|
|
1309
|
+
// Mentions + quoted-reply context come from the normalized message;
|
|
1310
|
+
// pulled here so the manager can gate group activation cleanly and
|
|
1311
|
+
// the LLM gets the "user replied to X" context for free. Async
|
|
1312
|
+
// because LID mentions need the same resolver above.
|
|
1313
|
+
const mentions = normalized
|
|
1314
|
+
? await extractMentions(normalized, sock, args.authDir, connectionAccountId)
|
|
1315
|
+
: [];
|
|
1316
|
+
const replyTo = normalized
|
|
1317
|
+
? await extractReplyContext(normalized, sock, args.authDir, connectionAccountId)
|
|
1318
|
+
: undefined;
|
|
1319
|
+
// Baileys' `messageTimestamp` is in seconds (Long or number).
|
|
1320
|
+
// Normalize to epoch ms; the manager uses this to decide
|
|
1321
|
+
// whether a stranger's DM is "live" or "since-restart
|
|
1322
|
+
// history" for the pairing-grace window.
|
|
1323
|
+
const tsRaw = m.messageTimestamp;
|
|
1324
|
+
const tsSec = typeof tsRaw === "number"
|
|
1325
|
+
? tsRaw
|
|
1326
|
+
: tsRaw && typeof tsRaw.toNumber === "function"
|
|
1327
|
+
? tsRaw.toNumber()
|
|
1328
|
+
: undefined;
|
|
1329
|
+
args.onMessage({
|
|
1330
|
+
conversationId: jid,
|
|
1331
|
+
messageId: msgId ?? undefined,
|
|
1332
|
+
participantId: isGroup ? rawParticipant : undefined,
|
|
1333
|
+
messageTimestampMs: typeof tsSec === "number" && tsSec > 0 ? tsSec * 1000 : undefined,
|
|
1334
|
+
from: fromCanonical,
|
|
1335
|
+
senderLid,
|
|
1336
|
+
fromName: m.pushName ?? undefined,
|
|
1337
|
+
text,
|
|
1338
|
+
chatType: isGroup ? "group" : "direct",
|
|
1339
|
+
mentions: mentions.length > 0 ? mentions : undefined,
|
|
1340
|
+
replyTo,
|
|
1341
|
+
...(resolveMedia ? { resolveMedia } : {}),
|
|
1342
|
+
raw: m,
|
|
1343
|
+
});
|
|
1344
|
+
}
|
|
1345
|
+
catch (err) {
|
|
1346
|
+
args.log("failed to process inbound message", {
|
|
1347
|
+
error: err instanceof Error ? err.message : String(err),
|
|
1348
|
+
});
|
|
1349
|
+
}
|
|
1350
|
+
})();
|
|
1351
|
+
}
|
|
1352
|
+
};
|
|
1353
|
+
s.ev.on("messages.upsert", messagesUpsertHandler);
|
|
1354
|
+
registerDetach(s, () => {
|
|
1355
|
+
s.ev.off?.("messages.upsert", messagesUpsertHandler);
|
|
1356
|
+
});
|
|
1357
|
+
// Surface socket-level WS errors instead of crashing the process.
|
|
1358
|
+
const ws = s.ws;
|
|
1359
|
+
const wsErrorHandler = (err) => args.log("WhatsApp socket error", { error: String(err) });
|
|
1360
|
+
ws?.on?.("error", wsErrorHandler);
|
|
1361
|
+
registerDetach(s, () => {
|
|
1362
|
+
ws?.off?.("error", wsErrorHandler);
|
|
1363
|
+
});
|
|
1364
|
+
return s;
|
|
1365
|
+
};
|
|
1366
|
+
sock = buildSocket();
|
|
1367
|
+
// Watchdog — once-a-minute check that WhatsApp is still delivering REAL
|
|
1368
|
+
// inbound. Reads `lastActivityAt` (post-filter) so a stream of story-
|
|
1369
|
+
// broadcast notifies on an otherwise-silent link can't keep us asleep.
|
|
1370
|
+
// If we go past the stale threshold, force a reconnect so the operator
|
|
1371
|
+
// doesn't sit there wondering why nothing arrives. Disabled in linkMode
|
|
1372
|
+
// (one-shot pair, no daemon).
|
|
1373
|
+
if (!args.linkMode) {
|
|
1374
|
+
watchdogTimer = setInterval(() => {
|
|
1375
|
+
if (closed || !sock)
|
|
1376
|
+
return;
|
|
1377
|
+
const elapsed = Date.now() - lastActivityAt;
|
|
1378
|
+
if (elapsed < WATCHDOG_STALE_MS)
|
|
1379
|
+
return;
|
|
1380
|
+
args.log("WhatsApp watchdog — no inbound activity, forcing reconnect", {
|
|
1381
|
+
elapsedMs: elapsed,
|
|
1382
|
+
staleThresholdMs: WATCHDOG_STALE_MS,
|
|
1383
|
+
});
|
|
1384
|
+
const dying = sock;
|
|
1385
|
+
sock = null;
|
|
1386
|
+
teardownSocket(dying);
|
|
1387
|
+
scheduleReconnect();
|
|
1388
|
+
// Reset the clock so a flapping link doesn't trigger another forced
|
|
1389
|
+
// reconnect before the new socket has a chance to open.
|
|
1390
|
+
lastActivityAt = Date.now();
|
|
1391
|
+
lastInboundAt = Date.now();
|
|
1392
|
+
}, WATCHDOG_CHECK_MS);
|
|
1393
|
+
watchdogTimer.unref?.();
|
|
1394
|
+
}
|
|
1395
|
+
// Trap Signal-protocol crypto rejections (declared earlier in this
|
|
1396
|
+
// function; see `onUnhandledRejection`). Registered here, AFTER
|
|
1397
|
+
// `teardownSocket` and `scheduleReconnect` are in scope, and removed in
|
|
1398
|
+
// `close()` so a torn-down connection's handler doesn't survive past
|
|
1399
|
+
// the lifecycle that armed it.
|
|
1400
|
+
if (!args.linkMode) {
|
|
1401
|
+
process.on("unhandledRejection", onUnhandledRejection);
|
|
1402
|
+
}
|
|
1403
|
+
const delay = (ms) => new Promise((r) => setTimeout(r, ms).unref?.());
|
|
1404
|
+
/**
|
|
1405
|
+
* Send one chunk with retry on transient send failures. A WebSocket flap
|
|
1406
|
+
* during a reply would otherwise drop the message silently — Baileys throws
|
|
1407
|
+
* "Connection Closed" / "WS not open" until the auto-reconnect lands a
|
|
1408
|
+
* fresh socket. We back off and retry against the LIVE `sock` reference (so
|
|
1409
|
+
* a reconnect-replaced socket is used on the next attempt). Permanent
|
|
1410
|
+
* errors (e.g. "jid not registered") propagate after the first try.
|
|
1411
|
+
*/
|
|
1412
|
+
const TRANSIENT_SEND_ERROR = /closed|reset|timed?\s*out|disconnect|not\s*open|stream\s*error|ws/i;
|
|
1413
|
+
const SEND_MAX_ATTEMPTS = 3;
|
|
1414
|
+
/**
|
|
1415
|
+
* Run an outbound send against the LIVE `sock` reference with retry on
|
|
1416
|
+
* transient WS / disconnect errors. Used by text / media / reaction /
|
|
1417
|
+
* presence paths so a single reconnect mid-flight doesn't silently drop
|
|
1418
|
+
* the send. Permanent errors (e.g. "jid not registered") propagate after
|
|
1419
|
+
* the first try. `kind` is just a log tag — every line for one send shares
|
|
1420
|
+
* a correlation id so operators can grep for it.
|
|
1421
|
+
*/
|
|
1422
|
+
async function sendWithRetry(kind, send, log, extra) {
|
|
1423
|
+
const correlationId = `wa-${Date.now().toString(36)}-${Math.floor(Math.random() * 1e6).toString(36)}`;
|
|
1424
|
+
const startedAt = Date.now();
|
|
1425
|
+
let lastErr;
|
|
1426
|
+
for (let attempt = 1; attempt <= SEND_MAX_ATTEMPTS; attempt++) {
|
|
1427
|
+
const live = sock;
|
|
1428
|
+
if (live) {
|
|
1429
|
+
try {
|
|
1430
|
+
const result = await send(live);
|
|
1431
|
+
log(`WhatsApp ${kind} ok`, {
|
|
1432
|
+
correlationId,
|
|
1433
|
+
attempt,
|
|
1434
|
+
durationMs: Date.now() - startedAt,
|
|
1435
|
+
...extra,
|
|
1436
|
+
});
|
|
1437
|
+
return result;
|
|
1438
|
+
}
|
|
1439
|
+
catch (err) {
|
|
1440
|
+
lastErr = err;
|
|
1441
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
1442
|
+
if (!TRANSIENT_SEND_ERROR.test(message)) {
|
|
1443
|
+
log(`WhatsApp ${kind} permanent error`, { correlationId, attempt, error: message });
|
|
1444
|
+
throw err;
|
|
1445
|
+
}
|
|
1446
|
+
log(`WhatsApp ${kind} transient — retrying`, { correlationId, attempt, error: message });
|
|
1447
|
+
}
|
|
1448
|
+
}
|
|
1449
|
+
else {
|
|
1450
|
+
lastErr = new Error("WhatsApp socket not connected");
|
|
1451
|
+
log(`WhatsApp ${kind} paused — socket reconnecting`, { correlationId, attempt });
|
|
1452
|
+
}
|
|
1453
|
+
if (attempt < SEND_MAX_ATTEMPTS)
|
|
1454
|
+
await delay(500 * attempt);
|
|
1455
|
+
}
|
|
1456
|
+
log(`WhatsApp ${kind} failed after retries`, {
|
|
1457
|
+
correlationId,
|
|
1458
|
+
attempts: SEND_MAX_ATTEMPTS,
|
|
1459
|
+
durationMs: Date.now() - startedAt,
|
|
1460
|
+
error: lastErr instanceof Error ? lastErr.message : String(lastErr),
|
|
1461
|
+
});
|
|
1462
|
+
throw lastErr ?? new Error(`WhatsApp ${kind} failed after retries`);
|
|
1463
|
+
}
|
|
1464
|
+
/** Send a single text chunk with retry. Records the outbound id for echo-dedupe. */
|
|
1465
|
+
async function sendOneChunkWithRetry(conversationId, chunk, log) {
|
|
1466
|
+
const result = await sendWithRetry("send", async (live) => (await live.sendMessage(conversationId, { text: chunk })), log, { chunkBytes: chunk.length });
|
|
1467
|
+
// Remember the outbound message id so the inbound `fromMe` echo
|
|
1468
|
+
// can be distinguished from a genuine self-chat message (see
|
|
1469
|
+
// outboundDedupe in the upsert handler).
|
|
1470
|
+
recordOutboundId(conversationId, result?.key?.id);
|
|
1471
|
+
}
|
|
1472
|
+
return {
|
|
1473
|
+
current: () => sock,
|
|
1474
|
+
selfId: () => canonicalWhatsAppId(sock?.user?.id) || null,
|
|
1475
|
+
connectedAt: () => connectedAtMs,
|
|
1476
|
+
lastInboundAt: () => lastInboundAt,
|
|
1477
|
+
lastActivityAt: () => lastActivityAt,
|
|
1478
|
+
async sendText(conversationId, text) {
|
|
1479
|
+
// Convert agent-style markdown (**bold**, headings, tables, [links])
|
|
1480
|
+
// into WhatsApp's sparse formatting (*bold*, • bullets, "label (url)")
|
|
1481
|
+
// before splitting. Otherwise raw `**` / `|` / `###` leak into chat.
|
|
1482
|
+
const wa = markdownToWhatsApp(text);
|
|
1483
|
+
// Split long replies into WhatsApp-sized chunks (~4000 chars, fence-
|
|
1484
|
+
// aware). Each chunk goes through its own retry loop so a transient
|
|
1485
|
+
// reconnect mid-reply doesn't lose the rest of the message.
|
|
1486
|
+
const chunks = chunkText(wa);
|
|
1487
|
+
// Show "composing…" once at the start of a multi-chunk reply so the
|
|
1488
|
+
// recipient sees "typing…" while the LLM was thinking AND while we're
|
|
1489
|
+
// sending. Best-effort — failure here never breaks the send.
|
|
1490
|
+
try {
|
|
1491
|
+
await sock?.sendPresenceUpdate?.("composing", conversationId);
|
|
1492
|
+
}
|
|
1493
|
+
catch {
|
|
1494
|
+
/* presence is cosmetic */
|
|
1495
|
+
}
|
|
1496
|
+
for (let i = 0; i < chunks.length; i++) {
|
|
1497
|
+
await sendOneChunkWithRetry(conversationId, chunks[i], args.log);
|
|
1498
|
+
if (i < chunks.length - 1)
|
|
1499
|
+
await delay(150);
|
|
1500
|
+
}
|
|
1501
|
+
// Reset presence so the bot doesn't show as "typing forever".
|
|
1502
|
+
try {
|
|
1503
|
+
await sock?.sendPresenceUpdate?.("paused", conversationId);
|
|
1504
|
+
}
|
|
1505
|
+
catch {
|
|
1506
|
+
/* ignore */
|
|
1507
|
+
}
|
|
1508
|
+
},
|
|
1509
|
+
async sendMedia(conversationId, media) {
|
|
1510
|
+
// Map Brigade's media kind onto Baileys' payload shape. Caption rides
|
|
1511
|
+
// the media (a single message) so the agent doesn't have to issue two
|
|
1512
|
+
// sends; voice = audio + ptt=true with opus mime.
|
|
1513
|
+
const url = media.path; // Baileys accepts an absolute path for `url`.
|
|
1514
|
+
// SECURITY — refuse to upload a local secret/system file. media.path can be
|
|
1515
|
+
// agent/tool-supplied, so a prompt-injected "send ~/.ssh/id_rsa" (or
|
|
1516
|
+
// Brigade's own sealed auth) would otherwise exfiltrate it to the chat.
|
|
1517
|
+
const mediaGuard = validateOutboundMediaPath(url);
|
|
1518
|
+
if (!mediaGuard.ok) {
|
|
1519
|
+
args.log?.(`sendMedia blocked: ${mediaGuard.reason}`);
|
|
1520
|
+
throw new Error(`Refusing to send this file — ${mediaGuard.reason}.`);
|
|
1521
|
+
}
|
|
1522
|
+
const captionWa = media.caption ? markdownToWhatsApp(media.caption) : undefined;
|
|
1523
|
+
let payload;
|
|
1524
|
+
switch (media.kind) {
|
|
1525
|
+
case "image":
|
|
1526
|
+
payload = { image: { url }, mimetype: media.mimeType ?? "image/jpeg", caption: captionWa };
|
|
1527
|
+
break;
|
|
1528
|
+
case "video":
|
|
1529
|
+
payload = { video: { url }, mimetype: media.mimeType ?? "video/mp4", caption: captionWa };
|
|
1530
|
+
break;
|
|
1531
|
+
case "audio":
|
|
1532
|
+
payload = { audio: { url }, mimetype: media.mimeType ?? "audio/mpeg", ptt: false };
|
|
1533
|
+
break;
|
|
1534
|
+
case "voice":
|
|
1535
|
+
payload = { audio: { url }, mimetype: media.mimeType ?? "audio/ogg; codecs=opus", ptt: true };
|
|
1536
|
+
break;
|
|
1537
|
+
case "document":
|
|
1538
|
+
payload = {
|
|
1539
|
+
document: { url },
|
|
1540
|
+
mimetype: media.mimeType ?? "application/octet-stream",
|
|
1541
|
+
fileName: media.fileName,
|
|
1542
|
+
caption: captionWa,
|
|
1543
|
+
};
|
|
1544
|
+
break;
|
|
1545
|
+
case "sticker":
|
|
1546
|
+
payload = { sticker: { url }, mimetype: media.mimeType ?? "image/webp" };
|
|
1547
|
+
break;
|
|
1548
|
+
}
|
|
1549
|
+
// Same transient-retry shape as text — a reconnect mid-upload
|
|
1550
|
+
// otherwise drops the media silently. The actual Baileys upload
|
|
1551
|
+
// happens inside `live.sendMessage`; if it fails transiently we
|
|
1552
|
+
// retry against whatever socket the reconnect loop hands us next.
|
|
1553
|
+
const mediaResult = await sendWithRetry(`sendMedia(${media.kind})`, async (live) => (await live.sendMessage(conversationId, payload)), args.log);
|
|
1554
|
+
recordOutboundId(conversationId, mediaResult?.key?.id);
|
|
1555
|
+
},
|
|
1556
|
+
async react(conversationId, messageId, emoji, fromMe) {
|
|
1557
|
+
// Reactions need the original message's key (jid + id + fromMe). When
|
|
1558
|
+
// the caller only has the inbound's id (the common case), pass
|
|
1559
|
+
// fromMe=false; for clearing our own reaction, pass fromMe=true.
|
|
1560
|
+
// Wrapped in sendWithRetry so a transient reconnect mid-reaction
|
|
1561
|
+
// doesn't silently drop it (reactions are cheap; better to retry
|
|
1562
|
+
// than to leave a half-acknowledged inbound).
|
|
1563
|
+
const reactResult = await sendWithRetry("react", async (live) => (await live.sendMessage(conversationId, {
|
|
1564
|
+
react: {
|
|
1565
|
+
text: emoji, // "" clears any prior reaction
|
|
1566
|
+
key: { remoteJid: conversationId, id: messageId, fromMe: fromMe ?? false },
|
|
1567
|
+
},
|
|
1568
|
+
})), args.log);
|
|
1569
|
+
recordOutboundId(conversationId, reactResult?.key?.id);
|
|
1570
|
+
},
|
|
1571
|
+
async markRead(conversationId, messageId, participant) {
|
|
1572
|
+
// Read receipts are cosmetic — drop silently when the socket is
|
|
1573
|
+
// reconnecting or the platform refuses (e.g. account hasn't opted
|
|
1574
|
+
// into read receipts globally).
|
|
1575
|
+
try {
|
|
1576
|
+
await sock?.readMessages?.([
|
|
1577
|
+
{
|
|
1578
|
+
remoteJid: conversationId,
|
|
1579
|
+
id: messageId,
|
|
1580
|
+
...(participant ? { participant } : {}),
|
|
1581
|
+
},
|
|
1582
|
+
]);
|
|
1583
|
+
}
|
|
1584
|
+
catch {
|
|
1585
|
+
/* cosmetic */
|
|
1586
|
+
}
|
|
1587
|
+
},
|
|
1588
|
+
async setComposing(conversationId, state) {
|
|
1589
|
+
try {
|
|
1590
|
+
await sock?.sendPresenceUpdate?.(state, conversationId);
|
|
1591
|
+
}
|
|
1592
|
+
catch {
|
|
1593
|
+
/* cosmetic */
|
|
1594
|
+
}
|
|
1595
|
+
},
|
|
1596
|
+
async close() {
|
|
1597
|
+
closed = true;
|
|
1598
|
+
if (reconnectTimer) {
|
|
1599
|
+
clearTimeout(reconnectTimer);
|
|
1600
|
+
reconnectTimer = null;
|
|
1601
|
+
}
|
|
1602
|
+
if (watchdogTimer) {
|
|
1603
|
+
clearInterval(watchdogTimer);
|
|
1604
|
+
watchdogTimer = null;
|
|
1605
|
+
}
|
|
1606
|
+
clearColdStartHealth();
|
|
1607
|
+
// Remove the process-level crypto-rejection trap — otherwise a
|
|
1608
|
+
// torn-down connection's handler survives and could touch a `sock`
|
|
1609
|
+
// that's been nulled out (the `closed` guard catches that, but it's
|
|
1610
|
+
// cleaner to deregister).
|
|
1611
|
+
process.off("unhandledRejection", onUnhandledRejection);
|
|
1612
|
+
// `logout()` would invalidate creds; we want a clean disconnect that
|
|
1613
|
+
// keeps the link, so just tear the socket down. (presencePingTimer
|
|
1614
|
+
// + sessionAgeTimer are cleared inside teardownSocket.)
|
|
1615
|
+
teardownSocket(sock);
|
|
1616
|
+
sock = null;
|
|
1617
|
+
// Let a final creds write flush so the link survives a restart.
|
|
1618
|
+
await pendingCredsSave.catch(() => { });
|
|
1619
|
+
// Convex mode: drain the auth-state's write-behind key queue so a
|
|
1620
|
+
// just-completed pair (or any keys written right before close) lands
|
|
1621
|
+
// in the backend. Without this, a `brigade channels link` that exits
|
|
1622
|
+
// immediately after connect can lose the freshly-negotiated keys.
|
|
1623
|
+
if (convexAuthFlush)
|
|
1624
|
+
await convexAuthFlush().catch(() => { });
|
|
1625
|
+
},
|
|
1626
|
+
};
|
|
1627
|
+
}
|
|
1628
|
+
//# sourceMappingURL=connection.js.map
|