@poolzin/pool-bot 2026.2.17 → 2026.2.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +25 -0
- package/dist/agents/agent-scope.js +4 -0
- package/dist/agents/announce-idempotency.js +14 -0
- package/dist/agents/auth-profiles.resolve-auth-profile-order.fixtures.js +23 -0
- package/dist/agents/bash-tools.exec-runtime.js +438 -0
- package/dist/agents/bash-tools.shared.js +6 -0
- package/dist/agents/cli-runner/reliability.js +61 -0
- package/dist/agents/cli-watchdog-defaults.js +11 -0
- package/dist/agents/command-poll-backoff.js +63 -0
- package/dist/agents/current-time.js +16 -0
- package/dist/agents/model-alias-lines.js +18 -0
- package/dist/agents/model-auth-label.js +61 -0
- package/dist/agents/models-config.e2e-harness.js +115 -0
- package/dist/agents/ollama-stream.js +11 -3
- package/dist/agents/openclaw-tools.js +135 -0
- package/dist/agents/pi-auth-json.js +118 -0
- package/dist/agents/pi-embedded-runner/run.overflow-compaction.mocks.shared.js +147 -0
- package/dist/agents/pi-embedded-subscribe.e2e-harness.js +90 -0
- package/dist/agents/pi-embedded-subscribe.handlers.compaction.js +63 -0
- package/dist/agents/pi-embedded-subscribe.handlers.tools.media.test-helpers.js +30 -0
- package/dist/agents/pi-extensions/session-manager-runtime-registry.js +23 -0
- package/dist/agents/pi-tools.js +2 -0
- package/dist/agents/queued-file-writer.js +22 -0
- package/dist/agents/sandbox/docker.js +133 -40
- package/dist/agents/sandbox/fs-bridge.js +146 -0
- package/dist/agents/sandbox/fs-paths.js +205 -0
- package/dist/agents/sandbox/hash.js +4 -0
- package/dist/agents/sandbox-paths.js +3 -0
- package/dist/agents/session-dirs.js +20 -0
- package/dist/agents/skills/filter.js +24 -0
- package/dist/agents/skills/tools-dir.js +9 -0
- package/dist/agents/skills-install-download.js +290 -0
- package/dist/agents/skills-install-output.js +30 -0
- package/dist/agents/skills-install.download-test-utils.js +36 -0
- package/dist/agents/skills.e2e-test-helpers.js +13 -0
- package/dist/agents/subagent-announce-queue.js +59 -15
- package/dist/agents/subagent-depth.js +137 -0
- package/dist/agents/subagent-registry.js +448 -96
- package/dist/agents/subagent-spawn.js +262 -0
- package/dist/agents/test-helpers/fast-tool-stubs.js +18 -0
- package/dist/agents/test-helpers/host-sandbox-fs-bridge.js +74 -0
- package/dist/agents/tool-display-common.js +782 -0
- package/dist/agents/tools/image-tool.js +1 -1
- package/dist/agents/tools/sessions-access.js +178 -0
- package/dist/agents/tools/sessions-resolution.js +206 -0
- package/dist/agents/tools/subagents-tool.js +616 -0
- package/dist/agents/workspace-dir.js +18 -0
- package/dist/agents/workspace-dirs.js +14 -0
- package/dist/agents/workspace.js +70 -0
- package/dist/auto-reply/heartbeat-reply-payload.js +18 -0
- package/dist/auto-reply/reply/commands-export-session.js +163 -0
- package/dist/auto-reply/reply/commands-mesh.js +245 -0
- package/dist/auto-reply/reply/commands-setunset.js +28 -0
- package/dist/auto-reply/reply/commands-slash-parse.js +31 -0
- package/dist/auto-reply/reply/commands-system-prompt.js +117 -0
- package/dist/auto-reply/reply/directive-handling.levels.js +17 -0
- package/dist/auto-reply/reply/directive-handling.params.js +1 -0
- package/dist/auto-reply/reply/directive-parsing.js +36 -0
- package/dist/auto-reply/reply/dispatcher-registry.js +43 -0
- package/dist/auto-reply/reply/elevated-unavailable.js +20 -0
- package/dist/auto-reply/reply/reply-delivery.js +92 -0
- package/dist/auto-reply/reply/session-reset-prompt.js +1 -0
- package/dist/auto-reply/reply/session-run-accounting.js +33 -0
- package/dist/auto-reply/reply.directive.directive-behavior.e2e-harness.js +115 -0
- package/dist/auto-reply/reply.directive.directive-behavior.e2e-mocks.js +12 -0
- package/dist/browser/bridge-auth-registry.js +26 -0
- package/dist/browser/client-actions-url.js +10 -0
- package/dist/browser/control-auth.js +73 -0
- package/dist/browser/csrf.js +64 -0
- package/dist/browser/http-auth.js +52 -0
- package/dist/browser/paths.js +37 -0
- package/dist/browser/proxy-files.js +32 -0
- package/dist/browser/pw-ai-state.js +7 -0
- package/dist/browser/resolved-config-refresh.js +42 -0
- package/dist/browser/routes/path-output.js +1 -0
- package/dist/browser/server-context.chrome-test-harness.js +20 -0
- package/dist/browser/server-middleware.js +31 -0
- package/dist/browser/test-port.js +16 -0
- package/dist/build-info.json +3 -3
- package/dist/canvas-host/file-resolver.js +43 -0
- package/dist/channels/account-summary.js +19 -0
- package/dist/channels/draft-stream-loop.js +77 -0
- package/dist/channels/plugins/account-helpers.js +26 -0
- package/dist/channels/telegram/allow-from.js +10 -0
- package/dist/cli/browser-cli-resize.js +22 -0
- package/dist/cli/browser-cli-shared.js +8 -0
- package/dist/cli/clawbot-cli.js +5 -0
- package/dist/cli/completion-cli.js +566 -0
- package/dist/cli/config-cli.js +63 -5
- package/dist/cli/daemon-cli/lifecycle-core.js +256 -0
- package/dist/cli/daemon-cli/register-service-commands.js +60 -0
- package/dist/cli/daemon-cli-compat.js +80 -0
- package/dist/cli/nodes-cli/pairing-render.js +26 -0
- package/dist/cli/program/action-reparse.js +17 -0
- package/dist/cli/program/command-registry.js +17 -0
- package/dist/cli/program/program-context.js +8 -0
- package/dist/cli/program/register.subclis.js +7 -0
- package/dist/cli/program/routes.js +233 -0
- package/dist/cli/qr-cli.js +132 -0
- package/dist/cli/requirements-test-fixtures.js +17 -0
- package/dist/cli/respawn-policy.js +4 -0
- package/dist/cli/shared/parse-port.js +18 -0
- package/dist/cli/skills-cli.format.js +241 -0
- package/dist/cli/update-cli/progress.js +121 -0
- package/dist/cli/update-cli/restart-helper.js +108 -0
- package/dist/cli/update-cli/shared.js +196 -0
- package/dist/cli/update-cli/status.js +97 -0
- package/dist/cli/update-cli/suppress-deprecations.js +17 -0
- package/dist/cli/update-cli/update-command.js +506 -0
- package/dist/cli/update-cli/wizard.js +130 -0
- package/dist/cli/update-cli.js +3 -9
- package/dist/cli/windows-argv.js +69 -0
- package/dist/commands/auth-choice-legacy.js +20 -0
- package/dist/commands/auth-choice.apply-helpers.js +8 -0
- package/dist/commands/channel-test-helpers.js +19 -0
- package/dist/commands/cleanup-plan.js +10 -0
- package/dist/commands/cleanup-utils.js +7 -0
- package/dist/commands/config-validation.js +15 -0
- package/dist/commands/doctor-completion.js +112 -0
- package/dist/commands/doctor-memory-search.js +119 -0
- package/dist/commands/doctor-session-locks.js +73 -0
- package/dist/commands/doctor.e2e-harness.js +364 -0
- package/dist/commands/gateway-presence.js +19 -0
- package/dist/commands/model-default.js +35 -0
- package/dist/commands/models/fallbacks-shared.js +102 -0
- package/dist/commands/models/shared.js +24 -0
- package/dist/commands/onboard-auth.config-gateways.js +64 -0
- package/dist/commands/onboard-auth.config-litellm.js +45 -0
- package/dist/commands/onboard-auth.config-shared.js +116 -0
- package/dist/commands/onboard-config.js +16 -0
- package/dist/commands/onboard-non-interactive.test-helpers.js +31 -0
- package/dist/commands/onboard-provider-auth-flags.js +136 -0
- package/dist/commands/openai-codex-oauth.js +40 -0
- package/dist/commands/test-runtime-config-helpers.js +21 -0
- package/dist/commands/test-wizard-helpers.js +68 -0
- package/dist/commands/vllm-setup.js +66 -0
- package/dist/compat/legacy-names.js +2 -0
- package/dist/config/backup-rotation.js +19 -0
- package/dist/config/env-preserve.js +122 -0
- package/dist/config/includes-scan.js +78 -0
- package/dist/config/plugins-allowlist.js +13 -0
- package/dist/config/schema.help.js +256 -0
- package/dist/config/schema.hints.js +189 -0
- package/dist/config/schema.irc.js +20 -0
- package/dist/config/schema.labels.js +317 -0
- package/dist/config/sessions/delivery-info.js +40 -0
- package/dist/config/types.irc.js +1 -0
- package/dist/config/zod-schema.agent-model.js +10 -0
- package/dist/config/zod-schema.allowdeny.js +35 -0
- package/dist/config/zod-schema.sensitive.js +4 -0
- package/dist/control-ui/assets/index-HRr1grwl.js.map +1 -1
- package/dist/cron/isolated-agent/skills-snapshot.js +26 -0
- package/dist/cron/isolated-agent/subagent-followup.js +127 -0
- package/dist/cron/isolated-agent.mocks.js +12 -0
- package/dist/cron/isolated-agent.test-setup.js +22 -0
- package/dist/cron/legacy-delivery.js +43 -0
- package/dist/cron/webhook-url.js +22 -0
- package/dist/daemon/arg-split.js +40 -0
- package/dist/daemon/exec-file.js +23 -0
- package/dist/daemon/output.js +6 -0
- package/dist/daemon/runtime-format.js +31 -0
- package/dist/daemon/schtasks-exec.js +4 -0
- package/dist/daemon/service-audit.js +22 -0
- package/dist/discord/client.js +41 -0
- package/dist/discord/components-registry.js +57 -0
- package/dist/discord/components.js +816 -0
- package/dist/discord/guilds.js +12 -0
- package/dist/discord/monitor/gateway-plugin.js +48 -0
- package/dist/discord/monitor/presence.js +30 -0
- package/dist/discord/send.components.js +115 -0
- package/dist/discord/send.shared.js +4 -0
- package/dist/discord/ui.js +26 -0
- package/dist/discord/voice-message.js +254 -0
- package/dist/gateway/agent-event-assistant-text.js +5 -0
- package/dist/gateway/agent-prompt.js +33 -0
- package/dist/gateway/auth-rate-limit.js +136 -0
- package/dist/gateway/channel-health-monitor.js +114 -0
- package/dist/gateway/control-ui-contract.js +1 -0
- package/dist/gateway/control-ui-csp.js +15 -0
- package/dist/gateway/gateway-config-prompts.shared.js +25 -0
- package/dist/gateway/http-auth-helpers.js +18 -0
- package/dist/gateway/http-common.js +18 -0
- package/dist/gateway/http-endpoint-helpers.js +27 -0
- package/dist/gateway/node-invoke-sanitize.js +11 -0
- package/dist/gateway/node-invoke-system-run-approval.js +205 -0
- package/dist/gateway/probe-auth.js +21 -0
- package/dist/gateway/protocol/index.js +7 -2
- package/dist/gateway/protocol/schema/mesh.js +54 -0
- package/dist/gateway/protocol/schema/protocol-schemas.js +7 -0
- package/dist/gateway/protocol/schema.js +1 -0
- package/dist/gateway/server/ws-connection/auth-messages.js +54 -0
- package/dist/gateway/server-channels.js +11 -0
- package/dist/gateway/server-methods/attachment-normalize.js +16 -0
- package/dist/gateway/server-methods/base-hash.js +8 -0
- package/dist/gateway/server-methods/mesh.js +700 -0
- package/dist/gateway/server-methods/nodes.handlers.invoke-result.js +55 -0
- package/dist/gateway/server-methods/restart-request.js +13 -0
- package/dist/gateway/server-methods/validation.js +8 -0
- package/dist/gateway/server.agent.gateway-server-agent.mocks.js +35 -0
- package/dist/gateway/server.e2e-registry-helpers.js +1 -0
- package/dist/gateway/server.e2e-ws-harness.js +20 -0
- package/dist/gateway/test-helpers.js +2 -0
- package/dist/gateway/test-helpers.server.js +3 -1
- package/dist/gateway/test-http-response.js +12 -0
- package/dist/gateway/test-openai-responses-model.js +20 -0
- package/dist/gateway/test-temp-config.js +30 -0
- package/dist/gateway/test-with-server.js +32 -0
- package/dist/hooks/bundled/bootstrap-extra-files/handler.js +46 -0
- package/dist/imessage/monitor/abort-handler.js +23 -0
- package/dist/imessage/monitor/inbound-processing.js +346 -0
- package/dist/imessage/monitor/parse-notification.js +64 -0
- package/dist/imessage/target-parsing-helpers.js +92 -0
- package/dist/infra/archive.js +244 -20
- package/dist/infra/detect-package-manager.js +26 -0
- package/dist/infra/exec-approvals-allowlist.js +257 -0
- package/dist/infra/exec-approvals-analysis.js +770 -0
- package/dist/infra/exec-approvals.js +13 -0
- package/dist/infra/file-lock.js +1 -0
- package/dist/infra/gemini-auth.js +39 -0
- package/dist/infra/heartbeat-active-hours.js +85 -0
- package/dist/infra/heartbeat-events-filter.js +50 -0
- package/dist/infra/heartbeat-runner.test-utils.js +39 -0
- package/dist/infra/http-body.js +265 -0
- package/dist/infra/install-package-dir.js +50 -0
- package/dist/infra/install-safe-path.js +49 -0
- package/dist/infra/json-files.js +49 -0
- package/dist/infra/jsonl-socket.js +52 -0
- package/dist/infra/map-size.js +14 -0
- package/dist/infra/net/hostname.js +7 -0
- package/dist/infra/npm-registry-spec.js +39 -0
- package/dist/infra/openclaw-root.js +109 -0
- package/dist/infra/outbound/delivery-queue.js +214 -0
- package/dist/infra/outbound/identity.js +23 -0
- package/dist/infra/outbound/message-action-params.js +307 -0
- package/dist/infra/outbound/tool-payload.js +21 -0
- package/dist/infra/package-json.js +23 -0
- package/dist/infra/pairing-files.js +19 -0
- package/dist/infra/pairing-token.js +9 -0
- package/dist/infra/path-prepend.js +51 -0
- package/dist/infra/process-respawn.js +49 -0
- package/dist/infra/runtime-status.js +16 -0
- package/dist/infra/session-cost-usage.types.js +1 -0
- package/dist/infra/session-maintenance-warning.js +89 -0
- package/dist/infra/system-run-command.js +78 -0
- package/dist/infra/tmp-openclaw-dir.js +81 -0
- package/dist/infra/tmp-poolbot-dir.js +2 -0
- package/dist/infra/update-channels.js +19 -0
- package/dist/line/actions.js +45 -0
- package/dist/line/channel-access-token.js +9 -0
- package/dist/line/flex-templates/basic-cards.js +332 -0
- package/dist/line/flex-templates/common.js +18 -0
- package/dist/line/flex-templates/media-control-cards.js +453 -0
- package/dist/line/flex-templates/message.js +10 -0
- package/dist/line/flex-templates/schedule-cards.js +399 -0
- package/dist/line/flex-templates/types.js +1 -0
- package/dist/line/webhook-node.js +100 -0
- package/dist/line/webhook-utils.js +11 -0
- package/dist/logging/timestamps.js +14 -0
- package/dist/markdown/whatsapp.js +62 -0
- package/dist/media/base64.js +34 -0
- package/dist/media/local-roots.js +32 -0
- package/dist/media/outbound-attachment.js +10 -0
- package/dist/media/read-response-with-limit.js +41 -0
- package/dist/media/sniff-mime-from-base64.js +19 -0
- package/dist/media-understanding/audio-preflight.js +67 -0
- package/dist/media-understanding/fs.js +13 -0
- package/dist/media-understanding/output-extract.js +26 -0
- package/dist/media-understanding/providers/audio.test-helpers.js +34 -0
- package/dist/media-understanding/providers/google/inline-data.js +64 -0
- package/dist/media-understanding/providers/shared.js +7 -0
- package/dist/media-understanding/runner.entries.js +459 -0
- package/dist/memory/batch-error-utils.js +11 -0
- package/dist/memory/batch-http.js +27 -0
- package/dist/memory/batch-output.js +29 -0
- package/dist/memory/batch-runner.js +22 -0
- package/dist/memory/batch-upload.js +23 -0
- package/dist/memory/batch-utils.js +26 -0
- package/dist/memory/embeddings-debug.js +11 -0
- package/dist/memory/embeddings-remote-client.js +22 -0
- package/dist/memory/embeddings-remote-fetch.js +14 -0
- package/dist/memory/manager-embedding-ops.js +616 -0
- package/dist/memory/manager-sync-ops.js +953 -0
- package/dist/memory/qmd-manager.js +1061 -0
- package/dist/memory/qmd-query-parser.js +107 -0
- package/dist/memory/qmd-scope.js +93 -0
- package/dist/memory/search-manager.js +0 -1
- package/dist/memory/sync-index.js +21 -0
- package/dist/memory/sync-progress.js +22 -0
- package/dist/memory/sync-stale.js +30 -0
- package/dist/memory/test-embeddings-mock.js +16 -0
- package/dist/memory/test-manager-helpers.js +14 -0
- package/dist/memory/test-runtime-mocks.js +11 -0
- package/dist/node-host/invoke-browser.js +177 -0
- package/dist/node-host/invoke.js +685 -0
- package/dist/pairing/setup-code.js +285 -0
- package/dist/plugin-sdk/account-id.js +1 -0
- package/dist/plugin-sdk/agent-media-payload.js +13 -0
- package/dist/plugin-sdk/allow-from.js +47 -0
- package/dist/plugin-sdk/command-auth.js +23 -0
- package/dist/plugin-sdk/config-paths.js +9 -0
- package/dist/plugin-sdk/file-lock.js +116 -0
- package/dist/plugin-sdk/json-store.js +31 -0
- package/dist/plugin-sdk/onboarding.js +28 -0
- package/dist/plugin-sdk/provider-auth-result.js +29 -0
- package/dist/plugin-sdk/slack-message-actions.js +133 -0
- package/dist/plugin-sdk/status-helpers.js +35 -0
- package/dist/plugin-sdk/text-chunking.js +31 -0
- package/dist/plugin-sdk/tool-send.js +12 -0
- package/dist/plugin-sdk/webhook-path.js +27 -0
- package/dist/plugin-sdk/webhook-targets.js +34 -0
- package/dist/plugins/hooks.test-helpers.js +21 -0
- package/dist/plugins/uninstall.js +171 -0
- package/dist/process/supervisor/adapters/child.js +143 -0
- package/dist/process/supervisor/adapters/env.js +13 -0
- package/dist/process/supervisor/adapters/pty.js +148 -0
- package/dist/process/supervisor/index.js +10 -0
- package/dist/process/supervisor/registry.js +117 -0
- package/dist/process/supervisor/supervisor.js +244 -0
- package/dist/process/supervisor/types.js +1 -0
- package/dist/providers/google-shared.test-helpers.js +75 -0
- package/dist/security/audit-channel.js +419 -0
- package/dist/security/audit-tool-policy.js +1 -0
- package/dist/security/scan-paths.js +12 -0
- package/dist/sessions/input-provenance.js +55 -0
- package/dist/sessions/session-key-utils.js +7 -0
- package/dist/shared/chat-content.js +31 -0
- package/dist/shared/chat-envelope.js +45 -0
- package/dist/shared/config-eval.js +117 -0
- package/dist/shared/device-auth.js +16 -0
- package/dist/shared/entry-metadata.js +9 -0
- package/dist/shared/entry-status.js +25 -0
- package/dist/shared/frontmatter.js +98 -0
- package/dist/shared/model-param-b.js +19 -0
- package/dist/shared/net/ipv4.js +17 -0
- package/dist/shared/node-match.js +53 -0
- package/dist/shared/requirements.js +128 -0
- package/dist/shared/subagents-format.js +84 -0
- package/dist/shared/usage-aggregates.js +28 -0
- package/dist/signal/monitor/mentions.js +45 -0
- package/dist/signal/rpc-context.js +19 -0
- package/dist/slack/blocks-fallback.js +76 -0
- package/dist/slack/blocks-input.js +40 -0
- package/dist/slack/draft-stream.js +106 -0
- package/dist/slack/message-actions.js +51 -0
- package/dist/slack/modal-metadata.js +32 -0
- package/dist/slack/monitor/events/interactions.js +462 -0
- package/dist/slack/monitor/room-context.js +17 -0
- package/dist/slack/stream-mode.js +41 -0
- package/dist/telegram/bot-native-command-menu.js +64 -0
- package/dist/telegram/bot.media.e2e-harness.js +81 -0
- package/dist/telegram/button-types.js +1 -0
- package/dist/telegram/group-access.js +65 -0
- package/dist/telegram/outbound-params.js +21 -0
- package/dist/telegram/poll-vote-cache.js +21 -0
- package/dist/terminal/health-style.js +36 -0
- package/dist/test-utils/chunk-test-helpers.js +21 -0
- package/dist/test-utils/env.js +72 -0
- package/dist/test-utils/exec-assertions.js +12 -0
- package/dist/test-utils/imessage-test-plugin.js +54 -0
- package/dist/test-utils/mock-http-response.js +17 -0
- package/dist/test-utils/vitest-mock-fn.js +1 -0
- package/dist/tts/tts-core.js +550 -0
- package/dist/utils/chunk-items.js +10 -0
- package/dist/utils/reaction-level.js +52 -0
- package/dist/utils/safe-json.js +22 -0
- package/dist/utils/with-timeout.js +14 -0
- package/dist/web/media.js +17 -5
- package/dist/whatsapp/resolve-outbound-target.js +42 -0
- package/dist/wizard/onboarding.completion.js +74 -0
- package/extensions/bluebubbles/src/account-resolve.ts +29 -0
- package/extensions/bluebubbles/src/monitor-normalize.ts +796 -0
- package/extensions/bluebubbles/src/monitor-processing.ts +1007 -0
- package/extensions/bluebubbles/src/monitor-reply-cache.ts +185 -0
- package/extensions/bluebubbles/src/monitor-shared.ts +51 -0
- package/extensions/bluebubbles/src/multipart.ts +32 -0
- package/extensions/bluebubbles/src/send-helpers.ts +53 -0
- package/extensions/bluebubbles/src/test-harness.ts +50 -0
- package/extensions/bluebubbles/src/test-mocks.ts +11 -0
- package/extensions/device-pair/index.ts +554 -0
- package/extensions/device-pair/poolbot.plugin.json +20 -0
- package/extensions/discord/src/channel.js +366 -0
- package/extensions/discord/src/runtime.js +10 -0
- package/extensions/feishu/index.ts +63 -0
- package/extensions/feishu/package.json +37 -0
- package/extensions/feishu/poolbot.plugin.json +10 -0
- package/extensions/feishu/skills/feishu-doc/SKILL.md +105 -0
- package/extensions/feishu/skills/feishu-doc/references/block-types.md +103 -0
- package/extensions/feishu/skills/feishu-drive/SKILL.md +97 -0
- package/extensions/feishu/skills/feishu-perm/SKILL.md +119 -0
- package/extensions/feishu/skills/feishu-wiki/SKILL.md +111 -0
- package/extensions/feishu/src/accounts.ts +114 -0
- package/extensions/feishu/src/bitable.ts +739 -0
- package/extensions/feishu/src/bot.ts +965 -0
- package/extensions/feishu/src/channel.ts +351 -0
- package/extensions/feishu/src/client.ts +118 -0
- package/extensions/feishu/src/config-schema.ts +206 -0
- package/extensions/feishu/src/dedup.ts +33 -0
- package/extensions/feishu/src/directory.ts +177 -0
- package/extensions/feishu/src/doc-schema.ts +47 -0
- package/extensions/feishu/src/docx.ts +536 -0
- package/extensions/feishu/src/drive-schema.ts +46 -0
- package/extensions/feishu/src/drive.ts +227 -0
- package/extensions/feishu/src/dynamic-agent.ts +131 -0
- package/extensions/feishu/src/media.ts +449 -0
- package/extensions/feishu/src/mention.ts +126 -0
- package/extensions/feishu/src/monitor.ts +330 -0
- package/extensions/feishu/src/onboarding.ts +359 -0
- package/extensions/feishu/src/outbound.ts +55 -0
- package/extensions/feishu/src/perm-schema.ts +52 -0
- package/extensions/feishu/src/perm.ts +173 -0
- package/extensions/feishu/src/policy.ts +84 -0
- package/extensions/feishu/src/probe.ts +44 -0
- package/extensions/feishu/src/reactions.ts +160 -0
- package/extensions/feishu/src/reply-dispatcher.ts +239 -0
- package/extensions/feishu/src/runtime.ts +14 -0
- package/extensions/feishu/src/send-result.ts +29 -0
- package/extensions/feishu/src/send.ts +335 -0
- package/extensions/feishu/src/streaming-card.ts +223 -0
- package/extensions/feishu/src/targets.ts +78 -0
- package/extensions/feishu/src/tools-config.ts +21 -0
- package/extensions/feishu/src/types.ts +81 -0
- package/extensions/feishu/src/typing.ts +80 -0
- package/extensions/feishu/src/wiki-schema.ts +55 -0
- package/extensions/feishu/src/wiki.ts +232 -0
- package/extensions/imessage/src/channel.js +253 -0
- package/extensions/imessage/src/runtime.js +10 -0
- package/extensions/irc/index.ts +17 -0
- package/extensions/irc/package.json +14 -0
- package/extensions/irc/poolbot.plugin.json +9 -0
- package/extensions/irc/src/accounts.ts +268 -0
- package/extensions/irc/src/channel.ts +367 -0
- package/extensions/irc/src/client.ts +439 -0
- package/extensions/irc/src/config-schema.ts +97 -0
- package/extensions/irc/src/connect-options.ts +30 -0
- package/extensions/irc/src/control-chars.ts +22 -0
- package/extensions/irc/src/inbound.ts +334 -0
- package/extensions/irc/src/monitor.ts +147 -0
- package/extensions/irc/src/normalize.ts +117 -0
- package/extensions/irc/src/onboarding.ts +479 -0
- package/extensions/irc/src/policy.ts +157 -0
- package/extensions/irc/src/probe.ts +53 -0
- package/extensions/irc/src/protocol.ts +169 -0
- package/extensions/irc/src/runtime.ts +14 -0
- package/extensions/irc/src/send.ts +88 -0
- package/extensions/irc/src/types.ts +93 -0
- package/extensions/matrix/src/matrix/client-bootstrap.ts +39 -0
- package/extensions/mattermost/src/mattermost/monitor-onchar.ts +25 -0
- package/extensions/mattermost/src/mattermost/monitor-websocket.ts +221 -0
- package/extensions/mattermost/src/mattermost/reactions.ts +130 -0
- package/extensions/mattermost/src/mattermost/reconnect.ts +103 -0
- package/extensions/minimax-portal-auth/README.md +33 -0
- package/extensions/minimax-portal-auth/index.ts +161 -0
- package/extensions/minimax-portal-auth/oauth.ts +247 -0
- package/extensions/minimax-portal-auth/package.json +15 -0
- package/extensions/minimax-portal-auth/poolbot.plugin.json +9 -0
- package/extensions/msteams/src/file-lock.ts +1 -0
- package/extensions/msteams/src/graph.ts +92 -0
- package/extensions/msteams/src/mentions.ts +114 -0
- package/extensions/msteams/src/test-runtime.ts +16 -0
- package/extensions/openai-codex-auth/README.md +82 -0
- package/extensions/openai-codex-auth/index.ts +177 -0
- package/extensions/openai-codex-auth/package.json +15 -0
- package/extensions/openai-codex-auth/poolbot.plugin.json +9 -0
- package/extensions/phone-control/index.ts +421 -0
- package/extensions/phone-control/poolbot.plugin.json +10 -0
- package/extensions/shared/resolve-target-test-helpers.ts +66 -0
- package/extensions/signal/src/channel.js +273 -0
- package/extensions/signal/src/runtime.js +10 -0
- package/extensions/slack/src/channel.js +489 -0
- package/extensions/slack/src/runtime.js +10 -0
- package/extensions/talk-voice/index.ts +150 -0
- package/extensions/talk-voice/poolbot.plugin.json +10 -0
- package/extensions/telegram/src/channel.js +424 -0
- package/extensions/telegram/src/runtime.js +10 -0
- package/extensions/thread-ownership/index.ts +133 -0
- package/extensions/thread-ownership/poolbot.plugin.json +28 -0
- package/extensions/tlon/src/account-fields.ts +25 -0
- package/extensions/tlon/src/urbit/base-url.ts +57 -0
- package/extensions/tlon/src/urbit/channel-client.ts +157 -0
- package/extensions/tlon/src/urbit/channel-ops.ts +164 -0
- package/extensions/tlon/src/urbit/context.ts +47 -0
- package/extensions/tlon/src/urbit/errors.ts +51 -0
- package/extensions/tlon/src/urbit/fetch.ts +39 -0
- package/extensions/twitch/src/test-fixtures.ts +30 -0
- package/extensions/voice-call/src/allowlist.ts +19 -0
- package/extensions/whatsapp/src/channel.js +429 -0
- package/extensions/whatsapp/src/runtime.js +10 -0
- package/package.json +1 -1
|
@@ -0,0 +1,616 @@
|
|
|
1
|
+
import fs from "node:fs/promises";
|
|
2
|
+
import { createSubsystemLogger } from "../logging/subsystem.js";
|
|
3
|
+
import { runGeminiEmbeddingBatches } from "./batch-gemini.js";
|
|
4
|
+
import { OPENAI_BATCH_ENDPOINT, runOpenAiEmbeddingBatches, } from "./batch-openai.js";
|
|
5
|
+
import { runVoyageEmbeddingBatches } from "./batch-voyage.js";
|
|
6
|
+
import { enforceEmbeddingMaxInputTokens } from "./embedding-chunk-limits.js";
|
|
7
|
+
import { estimateUtf8Bytes } from "./embedding-input-limits.js";
|
|
8
|
+
import { chunkMarkdown, hashText, parseEmbedding, remapChunkLines, } from "./internal.js";
|
|
9
|
+
import { MemoryManagerSyncOps } from "./manager-sync-ops.js";
|
|
10
|
+
const VECTOR_TABLE = "chunks_vec";
|
|
11
|
+
const FTS_TABLE = "chunks_fts";
|
|
12
|
+
const EMBEDDING_CACHE_TABLE = "embedding_cache";
|
|
13
|
+
const EMBEDDING_BATCH_MAX_TOKENS = 8000;
|
|
14
|
+
const EMBEDDING_INDEX_CONCURRENCY = 4;
|
|
15
|
+
const EMBEDDING_RETRY_MAX_ATTEMPTS = 3;
|
|
16
|
+
const EMBEDDING_RETRY_BASE_DELAY_MS = 500;
|
|
17
|
+
const EMBEDDING_RETRY_MAX_DELAY_MS = 8000;
|
|
18
|
+
const BATCH_FAILURE_LIMIT = 2;
|
|
19
|
+
const EMBEDDING_QUERY_TIMEOUT_REMOTE_MS = 60_000;
|
|
20
|
+
const EMBEDDING_QUERY_TIMEOUT_LOCAL_MS = 5 * 60_000;
|
|
21
|
+
const EMBEDDING_BATCH_TIMEOUT_REMOTE_MS = 2 * 60_000;
|
|
22
|
+
const EMBEDDING_BATCH_TIMEOUT_LOCAL_MS = 10 * 60_000;
|
|
23
|
+
const vectorToBlob = (embedding) => Buffer.from(new Float32Array(embedding).buffer);
|
|
24
|
+
const log = createSubsystemLogger("memory");
|
|
25
|
+
export class MemoryManagerEmbeddingOps extends MemoryManagerSyncOps {
|
|
26
|
+
buildEmbeddingBatches(chunks) {
|
|
27
|
+
const batches = [];
|
|
28
|
+
let current = [];
|
|
29
|
+
let currentTokens = 0;
|
|
30
|
+
for (const chunk of chunks) {
|
|
31
|
+
const estimate = estimateUtf8Bytes(chunk.text);
|
|
32
|
+
const wouldExceed = current.length > 0 && currentTokens + estimate > EMBEDDING_BATCH_MAX_TOKENS;
|
|
33
|
+
if (wouldExceed) {
|
|
34
|
+
batches.push(current);
|
|
35
|
+
current = [];
|
|
36
|
+
currentTokens = 0;
|
|
37
|
+
}
|
|
38
|
+
if (current.length === 0 && estimate > EMBEDDING_BATCH_MAX_TOKENS) {
|
|
39
|
+
batches.push([chunk]);
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
current.push(chunk);
|
|
43
|
+
currentTokens += estimate;
|
|
44
|
+
}
|
|
45
|
+
if (current.length > 0) {
|
|
46
|
+
batches.push(current);
|
|
47
|
+
}
|
|
48
|
+
return batches;
|
|
49
|
+
}
|
|
50
|
+
loadEmbeddingCache(hashes) {
|
|
51
|
+
if (!this.cache.enabled || !this.provider) {
|
|
52
|
+
return new Map();
|
|
53
|
+
}
|
|
54
|
+
if (hashes.length === 0) {
|
|
55
|
+
return new Map();
|
|
56
|
+
}
|
|
57
|
+
const unique = [];
|
|
58
|
+
const seen = new Set();
|
|
59
|
+
for (const hash of hashes) {
|
|
60
|
+
if (!hash) {
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
if (seen.has(hash)) {
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
seen.add(hash);
|
|
67
|
+
unique.push(hash);
|
|
68
|
+
}
|
|
69
|
+
if (unique.length === 0) {
|
|
70
|
+
return new Map();
|
|
71
|
+
}
|
|
72
|
+
const out = new Map();
|
|
73
|
+
const baseParams = [this.provider.id, this.provider.model, this.providerKey];
|
|
74
|
+
const batchSize = 400;
|
|
75
|
+
for (let start = 0; start < unique.length; start += batchSize) {
|
|
76
|
+
const batch = unique.slice(start, start + batchSize);
|
|
77
|
+
const placeholders = batch.map(() => "?").join(", ");
|
|
78
|
+
const rows = this.db
|
|
79
|
+
.prepare(`SELECT hash, embedding FROM ${EMBEDDING_CACHE_TABLE}\n` +
|
|
80
|
+
` WHERE provider = ? AND model = ? AND provider_key = ? AND hash IN (${placeholders})`)
|
|
81
|
+
.all(...baseParams, ...batch);
|
|
82
|
+
for (const row of rows) {
|
|
83
|
+
out.set(row.hash, parseEmbedding(row.embedding));
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return out;
|
|
87
|
+
}
|
|
88
|
+
upsertEmbeddingCache(entries) {
|
|
89
|
+
if (!this.cache.enabled || !this.provider) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
if (entries.length === 0) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
const now = Date.now();
|
|
96
|
+
const stmt = this.db.prepare(`INSERT INTO ${EMBEDDING_CACHE_TABLE} (provider, model, provider_key, hash, embedding, dims, updated_at)\n` +
|
|
97
|
+
` VALUES (?, ?, ?, ?, ?, ?, ?)\n` +
|
|
98
|
+
` ON CONFLICT(provider, model, provider_key, hash) DO UPDATE SET\n` +
|
|
99
|
+
` embedding=excluded.embedding,\n` +
|
|
100
|
+
` dims=excluded.dims,\n` +
|
|
101
|
+
` updated_at=excluded.updated_at`);
|
|
102
|
+
for (const entry of entries) {
|
|
103
|
+
const embedding = entry.embedding ?? [];
|
|
104
|
+
stmt.run(this.provider.id, this.provider.model, this.providerKey, entry.hash, JSON.stringify(embedding), embedding.length, now);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
pruneEmbeddingCacheIfNeeded() {
|
|
108
|
+
if (!this.cache.enabled) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
const max = this.cache.maxEntries;
|
|
112
|
+
if (!max || max <= 0) {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
const row = this.db.prepare(`SELECT COUNT(*) as c FROM ${EMBEDDING_CACHE_TABLE}`).get();
|
|
116
|
+
const count = row?.c ?? 0;
|
|
117
|
+
if (count <= max) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
const excess = count - max;
|
|
121
|
+
this.db
|
|
122
|
+
.prepare(`DELETE FROM ${EMBEDDING_CACHE_TABLE}\n` +
|
|
123
|
+
` WHERE rowid IN (\n` +
|
|
124
|
+
` SELECT rowid FROM ${EMBEDDING_CACHE_TABLE}\n` +
|
|
125
|
+
` ORDER BY updated_at ASC\n` +
|
|
126
|
+
` LIMIT ?\n` +
|
|
127
|
+
` )`)
|
|
128
|
+
.run(excess);
|
|
129
|
+
}
|
|
130
|
+
async embedChunksInBatches(chunks) {
|
|
131
|
+
if (chunks.length === 0) {
|
|
132
|
+
return [];
|
|
133
|
+
}
|
|
134
|
+
const { embeddings, missing } = this.collectCachedEmbeddings(chunks);
|
|
135
|
+
if (missing.length === 0) {
|
|
136
|
+
return embeddings;
|
|
137
|
+
}
|
|
138
|
+
const missingChunks = missing.map((m) => m.chunk);
|
|
139
|
+
const batches = this.buildEmbeddingBatches(missingChunks);
|
|
140
|
+
const toCache = [];
|
|
141
|
+
let cursor = 0;
|
|
142
|
+
for (const batch of batches) {
|
|
143
|
+
const batchEmbeddings = await this.embedBatchWithRetry(batch.map((chunk) => chunk.text));
|
|
144
|
+
for (let i = 0; i < batch.length; i += 1) {
|
|
145
|
+
const item = missing[cursor + i];
|
|
146
|
+
const embedding = batchEmbeddings[i] ?? [];
|
|
147
|
+
if (item) {
|
|
148
|
+
embeddings[item.index] = embedding;
|
|
149
|
+
toCache.push({ hash: item.chunk.hash, embedding });
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
cursor += batch.length;
|
|
153
|
+
}
|
|
154
|
+
this.upsertEmbeddingCache(toCache);
|
|
155
|
+
return embeddings;
|
|
156
|
+
}
|
|
157
|
+
computeProviderKey() {
|
|
158
|
+
// FTS-only mode: no provider, use a constant key
|
|
159
|
+
if (!this.provider) {
|
|
160
|
+
return hashText(JSON.stringify({ provider: "none", model: "fts-only" }));
|
|
161
|
+
}
|
|
162
|
+
if (this.provider.id === "openai" && this.openAi) {
|
|
163
|
+
const entries = Object.entries(this.openAi.headers)
|
|
164
|
+
.filter(([key]) => key.toLowerCase() !== "authorization")
|
|
165
|
+
.toSorted(([a], [b]) => a.localeCompare(b))
|
|
166
|
+
.map(([key, value]) => [key, value]);
|
|
167
|
+
return hashText(JSON.stringify({
|
|
168
|
+
provider: "openai",
|
|
169
|
+
baseUrl: this.openAi.baseUrl,
|
|
170
|
+
model: this.openAi.model,
|
|
171
|
+
headers: entries,
|
|
172
|
+
}));
|
|
173
|
+
}
|
|
174
|
+
if (this.provider.id === "gemini" && this.gemini) {
|
|
175
|
+
const entries = Object.entries(this.gemini.headers)
|
|
176
|
+
.filter(([key]) => {
|
|
177
|
+
const lower = key.toLowerCase();
|
|
178
|
+
return lower !== "authorization" && lower !== "x-goog-api-key";
|
|
179
|
+
})
|
|
180
|
+
.toSorted(([a], [b]) => a.localeCompare(b))
|
|
181
|
+
.map(([key, value]) => [key, value]);
|
|
182
|
+
return hashText(JSON.stringify({
|
|
183
|
+
provider: "gemini",
|
|
184
|
+
baseUrl: this.gemini.baseUrl,
|
|
185
|
+
model: this.gemini.model,
|
|
186
|
+
headers: entries,
|
|
187
|
+
}));
|
|
188
|
+
}
|
|
189
|
+
return hashText(JSON.stringify({ provider: this.provider.id, model: this.provider.model }));
|
|
190
|
+
}
|
|
191
|
+
async embedChunksWithBatch(chunks, entry, source) {
|
|
192
|
+
if (!this.provider) {
|
|
193
|
+
return this.embedChunksInBatches(chunks);
|
|
194
|
+
}
|
|
195
|
+
if (this.provider.id === "openai" && this.openAi) {
|
|
196
|
+
return this.embedChunksWithOpenAiBatch(chunks, entry, source);
|
|
197
|
+
}
|
|
198
|
+
if (this.provider.id === "gemini" && this.gemini) {
|
|
199
|
+
return this.embedChunksWithGeminiBatch(chunks, entry, source);
|
|
200
|
+
}
|
|
201
|
+
if (this.provider.id === "voyage" && this.voyage) {
|
|
202
|
+
return this.embedChunksWithVoyageBatch(chunks, entry, source);
|
|
203
|
+
}
|
|
204
|
+
return this.embedChunksInBatches(chunks);
|
|
205
|
+
}
|
|
206
|
+
collectCachedEmbeddings(chunks) {
|
|
207
|
+
const cached = this.loadEmbeddingCache(chunks.map((chunk) => chunk.hash));
|
|
208
|
+
const embeddings = Array.from({ length: chunks.length }, () => []);
|
|
209
|
+
const missing = [];
|
|
210
|
+
for (let i = 0; i < chunks.length; i += 1) {
|
|
211
|
+
const chunk = chunks[i];
|
|
212
|
+
const hit = chunk?.hash ? cached.get(chunk.hash) : undefined;
|
|
213
|
+
if (hit && hit.length > 0) {
|
|
214
|
+
embeddings[i] = hit;
|
|
215
|
+
}
|
|
216
|
+
else if (chunk) {
|
|
217
|
+
missing.push({ index: i, chunk });
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
return { embeddings, missing };
|
|
221
|
+
}
|
|
222
|
+
buildBatchCustomId(params) {
|
|
223
|
+
return hashText(`${params.source}:${params.entry.path}:${params.chunk.startLine}:${params.chunk.endLine}:${params.chunk.hash}:${params.index}`);
|
|
224
|
+
}
|
|
225
|
+
buildBatchRequests(params) {
|
|
226
|
+
const requests = [];
|
|
227
|
+
const mapping = new Map();
|
|
228
|
+
for (const item of params.missing) {
|
|
229
|
+
const chunk = item.chunk;
|
|
230
|
+
const customId = this.buildBatchCustomId({
|
|
231
|
+
source: params.source,
|
|
232
|
+
entry: params.entry,
|
|
233
|
+
chunk,
|
|
234
|
+
index: item.index,
|
|
235
|
+
});
|
|
236
|
+
mapping.set(customId, { index: item.index, hash: chunk.hash });
|
|
237
|
+
const built = params.build(chunk);
|
|
238
|
+
requests.push({ custom_id: customId, ...built });
|
|
239
|
+
}
|
|
240
|
+
return { requests, mapping };
|
|
241
|
+
}
|
|
242
|
+
applyBatchEmbeddings(params) {
|
|
243
|
+
const toCache = [];
|
|
244
|
+
for (const [customId, embedding] of params.byCustomId.entries()) {
|
|
245
|
+
const mapped = params.mapping.get(customId);
|
|
246
|
+
if (!mapped) {
|
|
247
|
+
continue;
|
|
248
|
+
}
|
|
249
|
+
params.embeddings[mapped.index] = embedding;
|
|
250
|
+
toCache.push({ hash: mapped.hash, embedding });
|
|
251
|
+
}
|
|
252
|
+
this.upsertEmbeddingCache(toCache);
|
|
253
|
+
}
|
|
254
|
+
buildEmbeddingBatchRunnerOptions(params) {
|
|
255
|
+
const { requests, chunks, source } = params;
|
|
256
|
+
return {
|
|
257
|
+
agentId: this.agentId,
|
|
258
|
+
requests,
|
|
259
|
+
wait: this.batch.wait,
|
|
260
|
+
concurrency: this.batch.concurrency,
|
|
261
|
+
pollIntervalMs: this.batch.pollIntervalMs,
|
|
262
|
+
timeoutMs: this.batch.timeoutMs,
|
|
263
|
+
debug: (message, data) => log.debug(message, data ? { ...data, source, chunks: chunks.length } : { source, chunks: chunks.length }),
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
async embedChunksWithVoyageBatch(chunks, entry, source) {
|
|
267
|
+
const voyage = this.voyage;
|
|
268
|
+
if (!voyage) {
|
|
269
|
+
return this.embedChunksInBatches(chunks);
|
|
270
|
+
}
|
|
271
|
+
if (chunks.length === 0) {
|
|
272
|
+
return [];
|
|
273
|
+
}
|
|
274
|
+
const { embeddings, missing } = this.collectCachedEmbeddings(chunks);
|
|
275
|
+
if (missing.length === 0) {
|
|
276
|
+
return embeddings;
|
|
277
|
+
}
|
|
278
|
+
const { requests, mapping } = this.buildBatchRequests({
|
|
279
|
+
missing,
|
|
280
|
+
entry,
|
|
281
|
+
source,
|
|
282
|
+
build: (chunk) => ({
|
|
283
|
+
body: { input: chunk.text },
|
|
284
|
+
}),
|
|
285
|
+
});
|
|
286
|
+
const runnerOptions = this.buildEmbeddingBatchRunnerOptions({ requests, chunks, source });
|
|
287
|
+
const batchResult = await this.runBatchWithFallback({
|
|
288
|
+
provider: "voyage",
|
|
289
|
+
run: async () => await runVoyageEmbeddingBatches({
|
|
290
|
+
client: voyage,
|
|
291
|
+
...runnerOptions,
|
|
292
|
+
}),
|
|
293
|
+
fallback: async () => await this.embedChunksInBatches(chunks),
|
|
294
|
+
});
|
|
295
|
+
if (Array.isArray(batchResult)) {
|
|
296
|
+
return batchResult;
|
|
297
|
+
}
|
|
298
|
+
this.applyBatchEmbeddings({ byCustomId: batchResult, mapping, embeddings });
|
|
299
|
+
return embeddings;
|
|
300
|
+
}
|
|
301
|
+
async embedChunksWithOpenAiBatch(chunks, entry, source) {
|
|
302
|
+
const openAi = this.openAi;
|
|
303
|
+
if (!openAi) {
|
|
304
|
+
return this.embedChunksInBatches(chunks);
|
|
305
|
+
}
|
|
306
|
+
if (chunks.length === 0) {
|
|
307
|
+
return [];
|
|
308
|
+
}
|
|
309
|
+
const { embeddings, missing } = this.collectCachedEmbeddings(chunks);
|
|
310
|
+
if (missing.length === 0) {
|
|
311
|
+
return embeddings;
|
|
312
|
+
}
|
|
313
|
+
const { requests, mapping } = this.buildBatchRequests({
|
|
314
|
+
missing,
|
|
315
|
+
entry,
|
|
316
|
+
source,
|
|
317
|
+
build: (chunk) => ({
|
|
318
|
+
method: "POST",
|
|
319
|
+
url: OPENAI_BATCH_ENDPOINT,
|
|
320
|
+
body: {
|
|
321
|
+
model: this.openAi?.model ?? this.provider?.model ?? "text-embedding-3-small",
|
|
322
|
+
input: chunk.text,
|
|
323
|
+
},
|
|
324
|
+
}),
|
|
325
|
+
});
|
|
326
|
+
const runnerOptions = this.buildEmbeddingBatchRunnerOptions({ requests, chunks, source });
|
|
327
|
+
const batchResult = await this.runBatchWithFallback({
|
|
328
|
+
provider: "openai",
|
|
329
|
+
run: async () => await runOpenAiEmbeddingBatches({
|
|
330
|
+
openAi,
|
|
331
|
+
...runnerOptions,
|
|
332
|
+
}),
|
|
333
|
+
fallback: async () => await this.embedChunksInBatches(chunks),
|
|
334
|
+
});
|
|
335
|
+
if (Array.isArray(batchResult)) {
|
|
336
|
+
return batchResult;
|
|
337
|
+
}
|
|
338
|
+
this.applyBatchEmbeddings({ byCustomId: batchResult, mapping, embeddings });
|
|
339
|
+
return embeddings;
|
|
340
|
+
}
|
|
341
|
+
async embedChunksWithGeminiBatch(chunks, entry, source) {
|
|
342
|
+
const gemini = this.gemini;
|
|
343
|
+
if (!gemini) {
|
|
344
|
+
return this.embedChunksInBatches(chunks);
|
|
345
|
+
}
|
|
346
|
+
if (chunks.length === 0) {
|
|
347
|
+
return [];
|
|
348
|
+
}
|
|
349
|
+
const { embeddings, missing } = this.collectCachedEmbeddings(chunks);
|
|
350
|
+
if (missing.length === 0) {
|
|
351
|
+
return embeddings;
|
|
352
|
+
}
|
|
353
|
+
const { requests, mapping } = this.buildBatchRequests({
|
|
354
|
+
missing,
|
|
355
|
+
entry,
|
|
356
|
+
source,
|
|
357
|
+
build: (chunk) => ({
|
|
358
|
+
content: { parts: [{ text: chunk.text }] },
|
|
359
|
+
taskType: "RETRIEVAL_DOCUMENT",
|
|
360
|
+
}),
|
|
361
|
+
});
|
|
362
|
+
const runnerOptions = this.buildEmbeddingBatchRunnerOptions({ requests, chunks, source });
|
|
363
|
+
const batchResult = await this.runBatchWithFallback({
|
|
364
|
+
provider: "gemini",
|
|
365
|
+
run: async () => await runGeminiEmbeddingBatches({
|
|
366
|
+
gemini,
|
|
367
|
+
...runnerOptions,
|
|
368
|
+
}),
|
|
369
|
+
fallback: async () => await this.embedChunksInBatches(chunks),
|
|
370
|
+
});
|
|
371
|
+
if (Array.isArray(batchResult)) {
|
|
372
|
+
return batchResult;
|
|
373
|
+
}
|
|
374
|
+
this.applyBatchEmbeddings({ byCustomId: batchResult, mapping, embeddings });
|
|
375
|
+
return embeddings;
|
|
376
|
+
}
|
|
377
|
+
async embedBatchWithRetry(texts) {
|
|
378
|
+
if (texts.length === 0) {
|
|
379
|
+
return [];
|
|
380
|
+
}
|
|
381
|
+
if (!this.provider) {
|
|
382
|
+
throw new Error("Cannot embed batch in FTS-only mode (no embedding provider)");
|
|
383
|
+
}
|
|
384
|
+
let attempt = 0;
|
|
385
|
+
let delayMs = EMBEDDING_RETRY_BASE_DELAY_MS;
|
|
386
|
+
while (true) {
|
|
387
|
+
try {
|
|
388
|
+
const timeoutMs = this.resolveEmbeddingTimeout("batch");
|
|
389
|
+
log.debug("memory embeddings: batch start", {
|
|
390
|
+
provider: this.provider.id,
|
|
391
|
+
items: texts.length,
|
|
392
|
+
timeoutMs,
|
|
393
|
+
});
|
|
394
|
+
return await this.withTimeout(this.provider.embedBatch(texts), timeoutMs, `memory embeddings batch timed out after ${Math.round(timeoutMs / 1000)}s`);
|
|
395
|
+
}
|
|
396
|
+
catch (err) {
|
|
397
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
398
|
+
if (!this.isRetryableEmbeddingError(message) || attempt >= EMBEDDING_RETRY_MAX_ATTEMPTS) {
|
|
399
|
+
throw err;
|
|
400
|
+
}
|
|
401
|
+
const waitMs = Math.min(EMBEDDING_RETRY_MAX_DELAY_MS, Math.round(delayMs * (1 + Math.random() * 0.2)));
|
|
402
|
+
log.warn(`memory embeddings rate limited; retrying in ${waitMs}ms`);
|
|
403
|
+
await new Promise((resolve) => setTimeout(resolve, waitMs));
|
|
404
|
+
delayMs *= 2;
|
|
405
|
+
attempt += 1;
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
isRetryableEmbeddingError(message) {
|
|
410
|
+
return /(rate[_ ]limit|too many requests|429|resource has been exhausted|5\d\d|cloudflare)/i.test(message);
|
|
411
|
+
}
|
|
412
|
+
resolveEmbeddingTimeout(kind) {
|
|
413
|
+
const isLocal = this.provider?.id === "local";
|
|
414
|
+
if (kind === "query") {
|
|
415
|
+
return isLocal ? EMBEDDING_QUERY_TIMEOUT_LOCAL_MS : EMBEDDING_QUERY_TIMEOUT_REMOTE_MS;
|
|
416
|
+
}
|
|
417
|
+
return isLocal ? EMBEDDING_BATCH_TIMEOUT_LOCAL_MS : EMBEDDING_BATCH_TIMEOUT_REMOTE_MS;
|
|
418
|
+
}
|
|
419
|
+
async embedQueryWithTimeout(text) {
|
|
420
|
+
if (!this.provider) {
|
|
421
|
+
throw new Error("Cannot embed query in FTS-only mode (no embedding provider)");
|
|
422
|
+
}
|
|
423
|
+
const timeoutMs = this.resolveEmbeddingTimeout("query");
|
|
424
|
+
log.debug("memory embeddings: query start", { provider: this.provider.id, timeoutMs });
|
|
425
|
+
return await this.withTimeout(this.provider.embedQuery(text), timeoutMs, `memory embeddings query timed out after ${Math.round(timeoutMs / 1000)}s`);
|
|
426
|
+
}
|
|
427
|
+
async withTimeout(promise, timeoutMs, message) {
|
|
428
|
+
if (!Number.isFinite(timeoutMs) || timeoutMs <= 0) {
|
|
429
|
+
return await promise;
|
|
430
|
+
}
|
|
431
|
+
let timer = null;
|
|
432
|
+
const timeoutPromise = new Promise((_, reject) => {
|
|
433
|
+
timer = setTimeout(() => reject(new Error(message)), timeoutMs);
|
|
434
|
+
});
|
|
435
|
+
try {
|
|
436
|
+
return (await Promise.race([promise, timeoutPromise]));
|
|
437
|
+
}
|
|
438
|
+
finally {
|
|
439
|
+
if (timer) {
|
|
440
|
+
clearTimeout(timer);
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
async withBatchFailureLock(fn) {
|
|
445
|
+
let release;
|
|
446
|
+
const wait = this.batchFailureLock;
|
|
447
|
+
this.batchFailureLock = new Promise((resolve) => {
|
|
448
|
+
release = resolve;
|
|
449
|
+
});
|
|
450
|
+
await wait;
|
|
451
|
+
try {
|
|
452
|
+
return await fn();
|
|
453
|
+
}
|
|
454
|
+
finally {
|
|
455
|
+
release();
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
async resetBatchFailureCount() {
|
|
459
|
+
await this.withBatchFailureLock(async () => {
|
|
460
|
+
if (this.batchFailureCount > 0) {
|
|
461
|
+
log.debug("memory embeddings: batch recovered; resetting failure count");
|
|
462
|
+
}
|
|
463
|
+
this.batchFailureCount = 0;
|
|
464
|
+
this.batchFailureLastError = undefined;
|
|
465
|
+
this.batchFailureLastProvider = undefined;
|
|
466
|
+
});
|
|
467
|
+
}
|
|
468
|
+
async recordBatchFailure(params) {
|
|
469
|
+
return await this.withBatchFailureLock(async () => {
|
|
470
|
+
if (!this.batch.enabled) {
|
|
471
|
+
return { disabled: true, count: this.batchFailureCount };
|
|
472
|
+
}
|
|
473
|
+
const increment = params.forceDisable
|
|
474
|
+
? BATCH_FAILURE_LIMIT
|
|
475
|
+
: Math.max(1, params.attempts ?? 1);
|
|
476
|
+
this.batchFailureCount += increment;
|
|
477
|
+
this.batchFailureLastError = params.message;
|
|
478
|
+
this.batchFailureLastProvider = params.provider;
|
|
479
|
+
const disabled = params.forceDisable || this.batchFailureCount >= BATCH_FAILURE_LIMIT;
|
|
480
|
+
if (disabled) {
|
|
481
|
+
this.batch.enabled = false;
|
|
482
|
+
}
|
|
483
|
+
return { disabled, count: this.batchFailureCount };
|
|
484
|
+
});
|
|
485
|
+
}
|
|
486
|
+
isBatchTimeoutError(message) {
|
|
487
|
+
return /timed out|timeout/i.test(message);
|
|
488
|
+
}
|
|
489
|
+
async runBatchWithTimeoutRetry(params) {
|
|
490
|
+
try {
|
|
491
|
+
return await params.run();
|
|
492
|
+
}
|
|
493
|
+
catch (err) {
|
|
494
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
495
|
+
if (this.isBatchTimeoutError(message)) {
|
|
496
|
+
log.warn(`memory embeddings: ${params.provider} batch timed out; retrying once`);
|
|
497
|
+
try {
|
|
498
|
+
return await params.run();
|
|
499
|
+
}
|
|
500
|
+
catch (retryErr) {
|
|
501
|
+
retryErr.batchAttempts = 2;
|
|
502
|
+
throw retryErr;
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
throw err;
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
async runBatchWithFallback(params) {
|
|
509
|
+
if (!this.batch.enabled) {
|
|
510
|
+
return await params.fallback();
|
|
511
|
+
}
|
|
512
|
+
try {
|
|
513
|
+
const result = await this.runBatchWithTimeoutRetry({
|
|
514
|
+
provider: params.provider,
|
|
515
|
+
run: params.run,
|
|
516
|
+
});
|
|
517
|
+
await this.resetBatchFailureCount();
|
|
518
|
+
return result;
|
|
519
|
+
}
|
|
520
|
+
catch (err) {
|
|
521
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
522
|
+
const attempts = err.batchAttempts ?? 1;
|
|
523
|
+
const forceDisable = /asyncBatchEmbedContent not available/i.test(message);
|
|
524
|
+
const failure = await this.recordBatchFailure({
|
|
525
|
+
provider: params.provider,
|
|
526
|
+
message,
|
|
527
|
+
attempts,
|
|
528
|
+
forceDisable,
|
|
529
|
+
});
|
|
530
|
+
const suffix = failure.disabled ? "disabling batch" : "keeping batch enabled";
|
|
531
|
+
log.warn(`memory embeddings: ${params.provider} batch failed (${failure.count}/${BATCH_FAILURE_LIMIT}); ${suffix}; falling back to non-batch embeddings: ${message}`);
|
|
532
|
+
return await params.fallback();
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
getIndexConcurrency() {
|
|
536
|
+
return this.batch.enabled ? this.batch.concurrency : EMBEDDING_INDEX_CONCURRENCY;
|
|
537
|
+
}
|
|
538
|
+
async indexFile(entry, options) {
|
|
539
|
+
// FTS-only mode: skip indexing if no provider
|
|
540
|
+
if (!this.provider) {
|
|
541
|
+
log.debug("Skipping embedding indexing in FTS-only mode", {
|
|
542
|
+
path: entry.path,
|
|
543
|
+
source: options.source,
|
|
544
|
+
});
|
|
545
|
+
return;
|
|
546
|
+
}
|
|
547
|
+
const content = options.content ?? (await fs.readFile(entry.absPath, "utf-8"));
|
|
548
|
+
const chunks = enforceEmbeddingMaxInputTokens(this.provider, chunkMarkdown(content, this.settings.chunking).filter((chunk) => chunk.text.trim().length > 0));
|
|
549
|
+
if (options.source === "sessions" && "lineMap" in entry) {
|
|
550
|
+
remapChunkLines(chunks, entry.lineMap);
|
|
551
|
+
}
|
|
552
|
+
const embeddings = this.batch.enabled
|
|
553
|
+
? await this.embedChunksWithBatch(chunks, entry, options.source)
|
|
554
|
+
: await this.embedChunksInBatches(chunks);
|
|
555
|
+
const sample = embeddings.find((embedding) => embedding.length > 0);
|
|
556
|
+
const vectorReady = sample ? await this.ensureVectorReady(sample.length) : false;
|
|
557
|
+
const now = Date.now();
|
|
558
|
+
if (vectorReady) {
|
|
559
|
+
try {
|
|
560
|
+
this.db
|
|
561
|
+
.prepare(`DELETE FROM ${VECTOR_TABLE} WHERE id IN (SELECT id FROM chunks WHERE path = ? AND source = ?)`)
|
|
562
|
+
.run(entry.path, options.source);
|
|
563
|
+
}
|
|
564
|
+
catch { }
|
|
565
|
+
}
|
|
566
|
+
if (this.fts.enabled && this.fts.available) {
|
|
567
|
+
try {
|
|
568
|
+
this.db
|
|
569
|
+
.prepare(`DELETE FROM ${FTS_TABLE} WHERE path = ? AND source = ? AND model = ?`)
|
|
570
|
+
.run(entry.path, options.source, this.provider.model);
|
|
571
|
+
}
|
|
572
|
+
catch { }
|
|
573
|
+
}
|
|
574
|
+
this.db
|
|
575
|
+
.prepare(`DELETE FROM chunks WHERE path = ? AND source = ?`)
|
|
576
|
+
.run(entry.path, options.source);
|
|
577
|
+
for (let i = 0; i < chunks.length; i++) {
|
|
578
|
+
const chunk = chunks[i];
|
|
579
|
+
const embedding = embeddings[i] ?? [];
|
|
580
|
+
const id = hashText(`${options.source}:${entry.path}:${chunk.startLine}:${chunk.endLine}:${chunk.hash}:${this.provider.model}`);
|
|
581
|
+
this.db
|
|
582
|
+
.prepare(`INSERT INTO chunks (id, path, source, start_line, end_line, hash, model, text, embedding, updated_at)
|
|
583
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
584
|
+
ON CONFLICT(id) DO UPDATE SET
|
|
585
|
+
hash=excluded.hash,
|
|
586
|
+
model=excluded.model,
|
|
587
|
+
text=excluded.text,
|
|
588
|
+
embedding=excluded.embedding,
|
|
589
|
+
updated_at=excluded.updated_at`)
|
|
590
|
+
.run(id, entry.path, options.source, chunk.startLine, chunk.endLine, chunk.hash, this.provider.model, chunk.text, JSON.stringify(embedding), now);
|
|
591
|
+
if (vectorReady && embedding.length > 0) {
|
|
592
|
+
try {
|
|
593
|
+
this.db.prepare(`DELETE FROM ${VECTOR_TABLE} WHERE id = ?`).run(id);
|
|
594
|
+
}
|
|
595
|
+
catch { }
|
|
596
|
+
this.db
|
|
597
|
+
.prepare(`INSERT INTO ${VECTOR_TABLE} (id, embedding) VALUES (?, ?)`)
|
|
598
|
+
.run(id, vectorToBlob(embedding));
|
|
599
|
+
}
|
|
600
|
+
if (this.fts.enabled && this.fts.available) {
|
|
601
|
+
this.db
|
|
602
|
+
.prepare(`INSERT INTO ${FTS_TABLE} (text, id, path, source, model, start_line, end_line)\n` +
|
|
603
|
+
` VALUES (?, ?, ?, ?, ?, ?, ?)`)
|
|
604
|
+
.run(chunk.text, id, entry.path, options.source, this.provider.model, chunk.startLine, chunk.endLine);
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
this.db
|
|
608
|
+
.prepare(`INSERT INTO files (path, source, hash, mtime, size) VALUES (?, ?, ?, ?, ?)
|
|
609
|
+
ON CONFLICT(path) DO UPDATE SET
|
|
610
|
+
source=excluded.source,
|
|
611
|
+
hash=excluded.hash,
|
|
612
|
+
mtime=excluded.mtime,
|
|
613
|
+
size=excluded.size`)
|
|
614
|
+
.run(entry.path, options.source, entry.hash, entry.mtimeMs, entry.size);
|
|
615
|
+
}
|
|
616
|
+
}
|