@vellumai/assistant 0.11.9 → 0.11.10-dev.202609091114.7b6342c
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/ARCHITECTURE.md +2 -2
- package/Dockerfile +6 -12
- package/docs/architecture/memory.md +17 -9
- package/docs/guardian-request-flow.md +7 -4
- package/docs/runbook-trusted-contacts.md +13 -2
- package/node_modules/@vellumai/ces-client/node_modules/@vellumai/service-contracts/package.json +3 -1
- package/node_modules/@vellumai/ces-client/node_modules/@vellumai/service-contracts/src/__tests__/plan-credit.test.ts +51 -0
- package/node_modules/@vellumai/ces-client/node_modules/@vellumai/service-contracts/src/__tests__/secret-detection.test.ts +2 -0
- package/node_modules/@vellumai/ces-client/node_modules/@vellumai/service-contracts/src/desktop-presence.ts +11 -0
- package/node_modules/@vellumai/ces-client/node_modules/@vellumai/service-contracts/src/index.ts +1 -0
- package/node_modules/@vellumai/ces-client/node_modules/@vellumai/service-contracts/src/plan-credit.ts +66 -0
- package/node_modules/@vellumai/ces-client/node_modules/@vellumai/service-contracts/src/secret-detection.ts +7 -0
- package/node_modules/@vellumai/gateway-client/node_modules/@vellumai/service-contracts/package.json +3 -1
- package/node_modules/@vellumai/gateway-client/node_modules/@vellumai/service-contracts/src/__tests__/plan-credit.test.ts +51 -0
- package/node_modules/@vellumai/gateway-client/node_modules/@vellumai/service-contracts/src/__tests__/secret-detection.test.ts +2 -0
- package/node_modules/@vellumai/gateway-client/node_modules/@vellumai/service-contracts/src/desktop-presence.ts +11 -0
- package/node_modules/@vellumai/gateway-client/node_modules/@vellumai/service-contracts/src/index.ts +1 -0
- package/node_modules/@vellumai/gateway-client/node_modules/@vellumai/service-contracts/src/plan-credit.ts +66 -0
- package/node_modules/@vellumai/gateway-client/node_modules/@vellumai/service-contracts/src/secret-detection.ts +7 -0
- package/node_modules/@vellumai/gateway-client/src/gateway-ipc-contracts.ts +72 -0
- package/node_modules/@vellumai/service-contracts/package.json +3 -1
- package/node_modules/@vellumai/service-contracts/src/__tests__/plan-credit.test.ts +51 -0
- package/node_modules/@vellumai/service-contracts/src/__tests__/secret-detection.test.ts +2 -0
- package/node_modules/@vellumai/service-contracts/src/desktop-presence.ts +11 -0
- package/node_modules/@vellumai/service-contracts/src/index.ts +1 -0
- package/node_modules/@vellumai/service-contracts/src/plan-credit.ts +66 -0
- package/node_modules/@vellumai/service-contracts/src/secret-detection.ts +7 -0
- package/openapi.yaml +729 -63
- package/package.json +1 -1
- package/src/__tests__/agent-loop-mutable-latest-user-message.test.ts +19 -21
- package/src/__tests__/assistant-event-hub-machine-name.test.ts +40 -0
- package/src/__tests__/assistant-event-hub.test.ts +45 -0
- package/src/__tests__/cli-memory-v2-reembed-skills.test.ts +0 -1
- package/src/__tests__/compactor-assistant-tail-preview.test.ts +111 -0
- package/src/__tests__/compactor-tail-resolution.test.ts +116 -0
- package/src/__tests__/computer-use-native-history.test.ts +30 -0
- package/src/__tests__/computer-use-window-schema.test.ts +24 -0
- package/src/__tests__/config-get-vision-flag.test.ts +36 -0
- package/src/__tests__/config-loader-validation-reset-notice.test.ts +47 -15
- package/src/__tests__/context-search-conversations-source.test.ts +27 -5
- package/src/__tests__/conversation-agent-loop-overflow.test.ts +189 -195
- package/src/__tests__/conversation-agent-loop.test.ts +690 -50
- package/src/__tests__/conversation-fork-crud.test.ts +132 -45
- package/src/__tests__/conversation-fork-retrospective.test.ts +9 -7
- package/src/__tests__/conversation-lifecycle.test.ts +684 -10
- package/src/__tests__/conversation-pairing.test.ts +10 -9
- package/src/__tests__/conversation-runtime-assembly.test.ts +288 -1
- package/src/__tests__/conversation-surfaces-history-restored-completion.test.ts +21 -4
- package/src/__tests__/conversation-surfaces-point-at-budget.test.ts +150 -0
- package/src/__tests__/conversation-surfaces-point-at-capability.test.ts +161 -0
- package/src/__tests__/copy-composer-tc-templates.test.ts +2 -2
- package/src/__tests__/credential-security-invariants.test.ts +1 -0
- package/src/__tests__/delivered-post-record.test.ts +107 -0
- package/src/__tests__/guardian-action-service-scope.test.ts +53 -0
- package/src/__tests__/guardian-question-mode.test.ts +88 -138
- package/src/__tests__/headless-browser-mode.test.ts +63 -13
- package/src/__tests__/heartbeat-disk-pressure.test.ts +2 -0
- package/src/__tests__/heartbeat-service.test.ts +118 -27
- package/src/__tests__/host-cu-proxy.test.ts +159 -1
- package/src/__tests__/host-proxy-interface.test.ts +15 -0
- package/src/__tests__/host-proxy-preactivation.test.ts +61 -0
- package/src/__tests__/injector-chain.test.ts +3 -3
- package/src/__tests__/injector-registry-order-guard.test.ts +1 -1
- package/src/__tests__/injector-v3-suppression.test.ts +587 -45
- package/src/__tests__/llm-schema.test.ts +70 -2
- package/src/__tests__/logger.test.ts +33 -32
- package/src/__tests__/mcp-config-secret-boundary.test.ts +2 -0
- package/src/__tests__/memory-config-file-parity.test.ts +18 -0
- package/src/__tests__/memory-retrieval-hook.test.ts +53 -3
- package/src/__tests__/messages-read-boundary-guard.test.ts +0 -1
- package/src/__tests__/messaging-send-tool.test.ts +251 -128
- package/src/__tests__/messaging-shared.test.ts +19 -0
- package/src/__tests__/notification-decision-fallback.test.ts +98 -76
- package/src/__tests__/notification-decision-strategy.test.ts +10 -38
- package/src/__tests__/notification-events-source-context-probe.test.ts +211 -0
- package/src/__tests__/openai-responses-prompt-cache.test.ts +7 -2
- package/src/__tests__/openai-responses-provider.test.ts +42 -0
- package/src/__tests__/outlook-messaging-provider.test.ts +9 -0
- package/src/__tests__/platform-callback-registration.test.ts +162 -3
- package/src/__tests__/plugin-api-webhook-url.test.ts +66 -4
- package/src/__tests__/plugin-import-boundary-guard.test.ts +1 -0
- package/src/__tests__/pricing.test.ts +29 -0
- package/src/__tests__/prompt-cache-cross-turn-stability.test.ts +63 -3
- package/src/__tests__/scheduler-result-notification.test.ts +209 -0
- package/src/__tests__/strip-memory-injections.test.ts +75 -27
- package/src/__tests__/tool-approval-seed-content-blocks.test.ts +4 -13
- package/src/acp/auto-install.test.ts +35 -1
- package/src/acp/resolve-agent.test.ts +3 -3
- package/src/agent/loop.ts +116 -45
- package/src/api/constants/personality-sliders.test.ts +21 -0
- package/src/api/constants/personality-sliders.ts +64 -0
- package/src/api/events/contact-record-request.ts +16 -4
- package/src/api/events/contact-request.ts +10 -1
- package/src/api/index.ts +12 -0
- package/src/api/responses/memory-v3-selection-log.ts +64 -13
- package/src/api/surfaces.ts +6 -5
- package/src/background-wake/next-wake.test.ts +13 -0
- package/src/background-wake/next-wake.ts +4 -2
- package/src/calls/__tests__/voice-session-bridge.test.ts +166 -0
- package/src/calls/__tests__/voice-turn-sight-hold.test.ts +301 -0
- package/src/calls/voice-session-bridge.ts +162 -1
- package/src/calls/voice-triage-escalate.ts +1 -1
- package/src/channels/types.ts +14 -0
- package/src/cli/__tests__/catalog-search-help.test.ts +1 -0
- package/src/cli/__tests__/contacts-address-prompt-cli.test.ts +701 -0
- package/src/cli/__tests__/contacts-record-prompt-cli.test.ts +276 -15
- package/src/cli/__tests__/roadmap-cli.test.ts +313 -0
- package/src/cli/__tests__/run-assistant-command.ts +59 -20
- package/src/cli/commands/__tests__/conversations-slack.test.ts +12 -0
- package/src/cli/commands/__tests__/plugins-search.test.ts +81 -0
- package/src/cli/commands/config.help.ts +3 -1
- package/src/cli/commands/contacts.help.ts +179 -12
- package/src/cli/commands/contacts.ts +442 -47
- package/src/cli/commands/memory/worker.ts +1 -1
- package/src/cli/commands/platform/__tests__/credits-format.test.ts +152 -0
- package/src/cli/commands/platform/__tests__/credits.test.ts +20 -0
- package/src/cli/commands/platform/credits-format.ts +108 -0
- package/src/cli/commands/platform/index.help.ts +33 -11
- package/src/cli/commands/platform/index.ts +7 -18
- package/src/cli/commands/plugins.help.ts +4 -1
- package/src/cli/commands/plugins.ts +2 -1
- package/src/cli/commands/roadmap.help.ts +171 -0
- package/src/cli/commands/roadmap.ts +358 -0
- package/src/cli/index.help.ts +2 -0
- package/src/cli/lib/__tests__/cli-output.test.ts +5 -0
- package/src/cli/lib/cli-output.ts +6 -6
- package/src/cli/program.ts +2 -0
- package/src/config/__tests__/webhook-routing.test.ts +42 -0
- package/src/config/acp-defaults.test.ts +3 -3
- package/src/config/acp-defaults.ts +5 -5
- package/src/config/bundled-skills/acp/SKILL.md +8 -11
- package/src/config/bundled-skills/computer-use/SKILL.md +21 -0
- package/src/config/bundled-skills/computer-use/TOOLS.json +6 -0
- package/src/config/bundled-skills/contacts/SKILL.md +61 -11
- package/src/config/bundled-skills/messaging/SKILL.md +2 -0
- package/src/config/bundled-skills/messaging/TOOLS.json +4 -4
- package/src/config/bundled-skills/messaging/tools/messaging-send.ts +160 -36
- package/src/config/bundled-skills/messaging/tools/shared.ts +6 -0
- package/src/config/bundled-skills/schedule/SKILL.md +10 -2
- package/src/config/bundled-skills/screen-annotation/SKILL.md +80 -0
- package/src/config/bundled-skills/screen-annotation/TOOLS.json +73 -0
- package/src/config/bundled-skills/screen-annotation/tools/screen-annotation.test.ts +74 -0
- package/src/config/bundled-skills/screen-annotation/tools/screen-clear-marks.ts +33 -0
- package/src/config/bundled-skills/screen-annotation/tools/screen-point-at.ts +25 -0
- package/src/config/env-registry.ts +2 -0
- package/src/config/feature-flag-registry.json +39 -7
- package/src/config/input-modalities.test.ts +71 -0
- package/src/config/input-modalities.ts +95 -0
- package/src/config/loader.ts +2 -0
- package/src/config/schemas/__tests__/memory-v3.test.ts +58 -15
- package/src/config/schemas/heartbeat.ts +3 -3
- package/src/config/schemas/llm.ts +47 -10
- package/src/config/schemas/memory-storage.test.ts +39 -0
- package/src/config/schemas/memory-storage.ts +21 -0
- package/src/config/schemas/memory-v3.ts +73 -46
- package/src/config/schemas/services.ts +18 -0
- package/src/config/webhook-routing.ts +12 -2
- package/src/context/compactor.ts +12 -13
- package/src/context/strip-injections.ts +29 -25
- package/src/context/token-estimator.ts +2 -2
- package/src/daemon/__tests__/embedding-reconcile.test.ts +77 -0
- package/src/daemon/__tests__/lifecycle-embedding-reconcile.test.ts +3 -0
- package/src/daemon/__tests__/turn-actor.test.ts +68 -0
- package/src/daemon/conversation-agent-loop-handlers.ts +152 -22
- package/src/daemon/conversation-agent-loop.ts +19 -3
- package/src/daemon/conversation-messaging.ts +3 -2
- package/src/daemon/conversation-runtime-assembly.ts +191 -69
- package/src/daemon/conversation-surfaces.ts +32 -62
- package/src/daemon/conversation.ts +153 -46
- package/src/daemon/embedding-reconcile.ts +64 -1
- package/src/daemon/handlers/config-embeddings.ts +31 -0
- package/src/daemon/host-cu-proxy.ts +66 -50
- package/src/daemon/host-cu-target.ts +139 -0
- package/src/daemon/host-proxy-preactivation.ts +29 -1
- package/src/daemon/mcp-reload-service.ts +6 -0
- package/src/daemon/providers-setup.ts +5 -26
- package/src/daemon/trust-context.ts +1 -1
- package/src/daemon/turn-actor.ts +46 -0
- package/src/heartbeat/heartbeat-service.ts +72 -13
- package/src/inbound/platform-callback-registration.ts +77 -11
- package/src/inbound/pod-webhook-claim.ts +35 -0
- package/src/inbound/velay-webhooks-gate.ts +20 -0
- package/src/ipc/gateway-client.ts +91 -0
- package/src/live-voice/__tests__/live-voice-photo.test.ts +174 -0
- package/src/live-voice/__tests__/live-voice-session-guardian.test.ts +127 -0
- package/src/live-voice/__tests__/live-voice-session-telemetry.test.ts +42 -2
- package/src/live-voice/__tests__/live-voice-sight-frame.test.ts +81 -0
- package/src/live-voice/__tests__/protocol.test.ts +67 -0
- package/src/live-voice/live-voice-connection.ts +14 -1
- package/src/live-voice/live-voice-photo.ts +109 -4
- package/src/live-voice/live-voice-session-manager.ts +10 -1
- package/src/live-voice/live-voice-session.ts +196 -31
- package/src/live-voice/protocol.ts +134 -1
- package/src/mcp/__tests__/reload-signal-emission.test.ts +54 -0
- package/src/mcp/__tests__/reload-signal.test.ts +57 -0
- package/src/mcp/__tests__/startup.test.ts +150 -0
- package/src/mcp/reload-signal.ts +50 -0
- package/src/mcp/startup.ts +101 -0
- package/src/messaging/providers/outlook/adapter.ts +2 -13
- package/src/messaging/providers/outlook/client.ts +13 -1
- package/src/messaging/providers/outlook/types.ts +3 -0
- package/src/messaging/providers/telegram-bot/adapter.ts +9 -2
- package/src/messaging/providers/telegram-bot/client.ts +8 -2
- package/src/messaging/providers/whatsapp/adapter.ts +9 -2
- package/src/messaging/providers/whatsapp/client.ts +8 -2
- package/src/notifications/AGENTS.md +5 -0
- package/src/notifications/README.md +21 -7
- package/src/notifications/__tests__/assistant-reply-producer.test.ts +3 -10
- package/src/notifications/__tests__/background-failure-signal.test.ts +96 -0
- package/src/notifications/__tests__/broadcaster.test.ts +171 -7
- package/src/notifications/__tests__/decision-engine.test.ts +79 -6
- package/src/notifications/__tests__/edit-notification.test.ts +59 -0
- package/src/notifications/__tests__/resolve-visible-in-source.test.ts +96 -0
- package/src/notifications/__tests__/schedule-result-producer.test.ts +397 -0
- package/src/notifications/access-request-copy.ts +5 -5
- package/src/notifications/approval-card-data.ts +29 -13
- package/src/notifications/assistant-reply-producer.ts +0 -4
- package/src/notifications/background-failure-signal.ts +13 -1
- package/src/notifications/broadcaster.ts +65 -2
- package/src/notifications/conversation-pairing.ts +263 -155
- package/src/notifications/copy-composer.ts +38 -22
- package/src/notifications/decision-engine.ts +89 -61
- package/src/notifications/delivered-post-record.ts +81 -0
- package/src/notifications/deliveries-store.ts +8 -1
- package/src/notifications/edit-notification.ts +16 -0
- package/src/notifications/events-store.ts +68 -2
- package/src/notifications/guardian-question-mode.ts +24 -232
- package/src/notifications/home-feed-side-effect.ts +1 -0
- package/src/notifications/notification-utils.ts +13 -5
- package/src/notifications/resolve-visible-in-source.ts +56 -0
- package/src/notifications/schedule-result-producer.ts +275 -0
- package/src/notifications/signal.ts +5 -0
- package/src/oauth/__tests__/seed-providers-managed.test.ts +82 -0
- package/src/oauth/seed-providers.ts +201 -3
- package/src/onboarding/onboarding-events-store.ts +14 -8
- package/src/persistence/conversation-crud.ts +68 -19
- package/src/persistence/embeddings/embedding-backend.test.ts +162 -0
- package/src/persistence/embeddings/embedding-backend.ts +148 -11
- package/src/persistence/embeddings/embedding-gemini.test.ts +328 -9
- package/src/persistence/embeddings/embedding-gemini.ts +211 -27
- package/src/persistence/embeddings/embedding-openai.test.ts +113 -0
- package/src/persistence/embeddings/embedding-openai.ts +55 -4
- package/src/persistence/embeddings/embedding-types.test.ts +24 -0
- package/src/persistence/embeddings/embedding-types.ts +25 -1
- package/src/persistence/job-utils.ts +6 -2
- package/src/persistence/message-metadata.ts +20 -0
- package/src/persistence/migrations/283-memory-v3-selections-message-id-and-sections.ts +2 -1
- package/src/persistence/migrations/376-notification-deliveries-canonical-message-id.ts +37 -0
- package/src/persistence/schema/memory-injection.ts +31 -9
- package/src/persistence/schema/notifications.ts +8 -0
- package/src/persistence/steps.ts +2 -0
- package/src/plugin-api/index.ts +2 -1
- package/src/plugin-api/vision-support.test.ts +81 -0
- package/src/plugin-api/vision-support.ts +57 -10
- package/src/plugin-api/webhook-url.ts +18 -4
- package/src/plugins/AGENTS.md +1 -1
- package/src/plugins/defaults/channel/injectors.ts +3 -1
- package/src/plugins/defaults/injector-order.ts +2 -2
- package/src/plugins/defaults/memory/AGENTS.md +263 -30
- package/src/plugins/defaults/memory/__tests__/conversation-memory-orphan-sweep.test.ts +4 -0
- package/src/plugins/defaults/memory/__tests__/conversation-memory-purge.test.ts +6 -0
- package/src/plugins/defaults/memory/__tests__/db-memory-attach.test.ts +9 -3
- package/src/plugins/defaults/memory/__tests__/memory-log-stores-degraded.test.ts +3 -7
- package/src/plugins/defaults/memory/__tests__/relocated-memory-test-rows.ts +18 -0
- package/src/plugins/defaults/memory/context-search/sources/conversations.ts +16 -2
- package/src/plugins/defaults/memory/conversation-memory-purge.ts +2 -0
- package/src/plugins/defaults/memory/fork-conversation-memory.ts +13 -13
- package/src/plugins/defaults/memory/graph/__tests__/conversation-graph-memory-v2-routing.test.ts +19 -12
- package/src/plugins/defaults/memory/graph/conversation-graph-memory.ts +17 -15
- package/src/plugins/defaults/memory/graph-topology/build-memory-graph.ts +1 -1
- package/src/plugins/defaults/memory/hooks/__tests__/post-compact.test.ts +121 -0
- package/src/plugins/defaults/memory/hooks/init.ts +10 -0
- package/src/plugins/defaults/memory/hooks/injection-metadata.ts +100 -0
- package/src/plugins/defaults/memory/hooks/post-compact.ts +19 -7
- package/src/plugins/defaults/memory/hooks/user-prompt-submit.ts +11 -83
- package/src/plugins/defaults/memory/injectors.ts +4 -4
- package/src/plugins/defaults/memory/job-handlers.ts +4 -1
- package/src/plugins/defaults/memory/jobs/__tests__/embed-concept-page.test.ts +1 -0
- package/src/plugins/defaults/memory/jobs/embed-concept-page.ts +11 -3
- package/src/plugins/defaults/memory/memory-db.ts +4 -0
- package/src/plugins/defaults/memory/memory-marker.ts +28 -17
- package/src/plugins/defaults/memory/src/__tests__/memory-v2-simulate-route.test.ts +0 -1
- package/src/plugins/defaults/memory/src/__tests__/memory-worker-routes.test.ts +20 -0
- package/src/plugins/defaults/memory/src/memory-item-routes.test.ts +0 -1
- package/src/plugins/defaults/memory/src/memory-worker-routes.ts +3 -1
- package/src/plugins/defaults/memory/substrate/__tests__/cli-command-store.test.ts +1 -1
- package/src/plugins/defaults/memory/substrate/__tests__/consolidation-job.test.ts +66 -0
- package/src/plugins/defaults/memory/substrate/__tests__/injected-block-slugs.test.ts +345 -0
- package/src/plugins/defaults/memory/substrate/__tests__/page-index.test.ts +0 -1
- package/src/plugins/defaults/memory/substrate/__tests__/prompts-consolidation.test.ts +170 -1
- package/src/plugins/defaults/memory/substrate/__tests__/reembed-job.test.ts +1 -0
- package/src/plugins/defaults/memory/substrate/capability-slugs.ts +53 -0
- package/src/plugins/defaults/memory/substrate/cli-command-store.ts +4 -18
- package/src/plugins/defaults/memory/substrate/consolidation-job.ts +40 -1
- package/src/plugins/defaults/memory/substrate/ingest.ts +11 -9
- package/src/plugins/defaults/memory/substrate/injected-block-slugs.ts +426 -42
- package/src/plugins/defaults/memory/substrate/page-index.ts +5 -4
- package/src/plugins/defaults/memory/substrate/prompts/consolidation.ts +127 -14
- package/src/plugins/defaults/memory/substrate/skill-store.ts +1 -18
- package/src/plugins/defaults/memory/v2/__tests__/backfill-jobs.test.ts +1 -0
- package/src/plugins/defaults/memory/v2/__tests__/injection.test.ts +2 -8
- package/src/plugins/defaults/memory/v2/__tests__/router.test.ts +0 -1
- package/src/plugins/defaults/memory/v2/injection.ts +4 -4
- package/src/plugins/defaults/memory/v3/__tests__/capabilities.test.ts +16 -0
- package/src/plugins/defaults/memory/v3/__tests__/carry-integration.test.ts +1004 -319
- package/src/plugins/defaults/memory/v3/__tests__/dense.test.ts +227 -4
- package/src/plugins/defaults/memory/v3/__tests__/injection.test.ts +836 -263
- package/src/plugins/defaults/memory/v3/__tests__/live-integration.test.ts +65 -38
- package/src/plugins/defaults/memory/v3/__tests__/maintain-job.test.ts +354 -3
- package/src/plugins/defaults/memory/v3/__tests__/orchestrate.test.ts +688 -104
- package/src/plugins/defaults/memory/v3/__tests__/overlong-sections.test.ts +109 -0
- package/src/plugins/defaults/memory/v3/__tests__/page-content.test.ts +144 -0
- package/src/plugins/defaults/memory/v3/__tests__/plugin-schema.test.ts +534 -0
- package/src/plugins/defaults/memory/v3/__tests__/pool-log-store.test.ts +449 -0
- package/src/plugins/defaults/memory/v3/__tests__/pool-select.test.ts +265 -27
- package/src/plugins/defaults/memory/v3/__tests__/render-injection.test.ts +34 -117
- package/src/plugins/defaults/memory/v3/__tests__/section-dense-store.test.ts +491 -4
- package/src/plugins/defaults/memory/v3/__tests__/section-needle.test.ts +124 -1
- package/src/plugins/defaults/memory/v3/__tests__/sections.test.ts +264 -4
- package/src/plugins/defaults/memory/v3/__tests__/selection-log-store.test.ts +560 -22
- package/src/plugins/defaults/memory/v3/__tests__/shadow-integration.test.ts +40 -33
- package/src/plugins/defaults/memory/v3/__tests__/shadow-plugin.test.ts +718 -63
- package/src/plugins/defaults/memory/v3/__tests__/types.test.ts +83 -2
- package/src/plugins/defaults/memory/v3/candidate-match.ts +1 -1
- package/src/plugins/defaults/memory/v3/capabilities.ts +90 -14
- package/src/plugins/defaults/memory/v3/card.test.ts +15 -16
- package/src/plugins/defaults/memory/v3/card.ts +16 -15
- package/src/plugins/defaults/memory/v3/dense.ts +10 -0
- package/src/plugins/defaults/memory/v3/ever-injected-store.test.ts +643 -140
- package/src/plugins/defaults/memory/v3/ever-injected-store.ts +462 -212
- package/src/plugins/defaults/memory/v3/hot-set.test.ts +2 -2
- package/src/plugins/defaults/memory/v3/injector.ts +366 -278
- package/src/plugins/defaults/memory/v3/learned-edges.test.ts +2 -2
- package/src/plugins/defaults/memory/v3/maintain-job.ts +299 -73
- package/src/plugins/defaults/memory/v3/orchestrate.ts +327 -214
- package/src/plugins/defaults/memory/v3/overlong-sections.ts +83 -0
- package/src/plugins/defaults/memory/v3/page-content.ts +72 -92
- package/src/plugins/defaults/memory/v3/plugin-schema.ts +346 -0
- package/src/plugins/defaults/memory/v3/pool-log-store.ts +291 -0
- package/src/plugins/defaults/memory/v3/pool-select.test.ts +2 -2
- package/src/plugins/defaults/memory/v3/pool-select.ts +160 -60
- package/src/plugins/defaults/memory/v3/prune.test.ts +1042 -329
- package/src/plugins/defaults/memory/v3/prune.ts +433 -270
- package/src/plugins/defaults/memory/v3/rare-term-lane.test.ts +269 -0
- package/src/plugins/defaults/memory/v3/rare-term-lane.ts +141 -0
- package/src/plugins/defaults/memory/v3/render-injection.ts +43 -82
- package/src/plugins/defaults/memory/v3/section-dense-store.ts +316 -28
- package/src/plugins/defaults/memory/v3/section-needle.ts +145 -11
- package/src/plugins/defaults/memory/v3/sections.ts +103 -16
- package/src/plugins/defaults/memory/v3/selection-log-store.ts +243 -78
- package/src/plugins/defaults/memory/v3/shadow-plugin.ts +189 -68
- package/src/plugins/defaults/memory/v3/tuning-profile.ts +6 -0
- package/src/plugins/defaults/memory/v3/types.ts +169 -23
- package/src/plugins/defaults/memory/v3-eval/__tests__/eval-packets.test.ts +21 -4
- package/src/plugins/defaults/memory/v3-eval/eval-packets.ts +77 -26
- package/src/plugins/types.ts +14 -0
- package/src/providers/__tests__/connection-model-compat.test.ts +1 -0
- package/src/providers/__tests__/provider-secret-catalog.test.ts +4 -0
- package/src/providers/__tests__/xml-tool-call-salvage.test.ts +172 -0
- package/src/providers/inline-audio-support.test.ts +34 -0
- package/src/providers/inline-audio-support.ts +27 -0
- package/src/providers/model-catalog.ts +102 -0
- package/src/providers/openai/__tests__/chat-completions-extra-body.test.ts +51 -0
- package/src/providers/openai/__tests__/chat-completions-provider-xml-salvage.test.ts +291 -0
- package/src/providers/openai/chat-completions-provider.ts +114 -14
- package/src/providers/openai/codex-models.ts +1 -0
- package/src/providers/openai/responses-provider.ts +65 -15
- package/src/providers/opencode/client.test.ts +24 -0
- package/src/providers/opencode/client.ts +6 -1
- package/src/providers/provider-secret-catalog.ts +11 -1
- package/src/providers/retry.ts +6 -0
- package/src/providers/vellum/client.ts +14 -1
- package/src/providers/vellum/personality-directions.test.ts +163 -0
- package/src/providers/vellum/personality-directions.ts +120 -0
- package/src/providers/xml-tool-call-salvage.ts +212 -0
- package/src/runtime/AGENTS.md +7 -2
- package/src/runtime/__tests__/background-job-runner.test.ts +115 -0
- package/src/runtime/__tests__/guardian-form-registry.test.ts +0 -32
- package/src/runtime/__tests__/host-observe.test.ts +44 -0
- package/src/runtime/assistant-event-hub.ts +14 -9
- package/src/runtime/auth/__tests__/guard-tests.test.ts +1 -4
- package/src/runtime/auth/__tests__/route-policy.test.ts +65 -0
- package/src/runtime/auth/same-actor.ts +4 -3
- package/src/runtime/background-job-runner.ts +10 -0
- package/src/runtime/channel-reply-delivery.ts +1 -162
- package/src/runtime/guardian-action-service.ts +20 -1
- package/src/runtime/host-observe.ts +56 -6
- package/src/runtime/http-server.ts +35 -0
- package/src/runtime/outbound-post-reconciliation.ts +183 -0
- package/src/runtime/routes/__tests__/contact-address-prompt-route.test.ts +231 -0
- package/src/runtime/routes/__tests__/contact-record-prompt-route.test.ts +59 -3
- package/src/runtime/routes/__tests__/guardian-form-routes.test.ts +85 -0
- package/src/runtime/routes/__tests__/heartbeat-routes.test.ts +24 -0
- package/src/runtime/routes/__tests__/platform-credits-routes.test.ts +239 -0
- package/src/runtime/routes/__tests__/roadmap-routes.test.ts +469 -0
- package/src/runtime/routes/__tests__/watch-routes.test.ts +70 -1
- package/src/runtime/routes/__tests__/webhook-routes.test.ts +83 -0
- package/src/runtime/routes/contact-prompt-routes.ts +177 -28
- package/src/runtime/routes/conversation-query-routes.ts +53 -11
- package/src/runtime/routes/events-routes.ts +13 -3
- package/src/runtime/routes/guardian-action-routes.ts +7 -0
- package/src/runtime/routes/guardian-form-routes.ts +6 -4
- package/src/runtime/routes/heartbeat-routes.ts +41 -53
- package/src/runtime/routes/index.ts +2 -2
- package/src/runtime/routes/integrations/a2a.ts +12 -3
- package/src/runtime/routes/integrations/vercel.ts +13 -3
- package/src/runtime/routes/platform-routes.ts +175 -23
- package/src/runtime/routes/roadmap-routes.ts +744 -0
- package/src/runtime/routes/watch-routes.ts +50 -0
- package/src/runtime/routes/webhook-routes.ts +24 -2
- package/src/runtime/web-presence.ts +13 -9
- package/src/schedule/__tests__/schedule-timezone.test.ts +21 -3
- package/src/schedule/__tests__/worker-mcp-tools.test.ts +88 -0
- package/src/schedule/schedule-timezone.ts +25 -0
- package/src/schedule/scheduler.ts +19 -0
- package/src/schedule/worker.ts +119 -2
- package/src/telemetry/__tests__/live-voice-funnel.test.ts +32 -0
- package/src/telemetry/live-voice-funnel.ts +33 -0
- package/src/tools/acp/list-agents.test.ts +1 -1
- package/src/tools/browser/__tests__/browser-status.test.ts +3 -0
- package/src/tools/browser/browser-execution.ts +117 -53
- package/src/tools/browser/browser-status-constants.ts +6 -6
- package/src/tools/capability-offer.test.ts +87 -0
- package/src/tools/capability-offer.ts +93 -0
- package/src/tools/computer-use/definitions.ts +6 -0
- package/src/tools/computer-use/skill-proxy-bridge.ts +10 -0
- package/src/tools/terminal/safe-env.ts +2 -0
- package/src/watch/__tests__/watch-retro.test.ts +11 -10
- package/src/watch/__tests__/watch-session-manager.test.ts +75 -1
- package/src/watch/watch-retro.ts +10 -9
- package/src/watch/watch-session-manager.ts +17 -0
- package/src/runtime/routes/__tests__/sight-frame-routes.test.ts +0 -487
- package/src/runtime/routes/sight-frame-routes.ts +0 -136
|
@@ -19,22 +19,24 @@
|
|
|
19
19
|
// shared Qdrant client; the read side (`dense.ts`) reuses that client to query
|
|
20
20
|
// this collection.
|
|
21
21
|
|
|
22
|
-
import { createHash } from "node:crypto";
|
|
23
|
-
|
|
24
22
|
import { QdrantClient as QdrantRestClient } from "@qdrant/js-client-rest";
|
|
25
23
|
import { v5 as uuidv5 } from "uuid";
|
|
26
24
|
|
|
27
25
|
import type { AssistantConfig } from "../../../../config/types.js";
|
|
28
|
-
import { deleteMemoryCheckpoint } from "../../../../persistence/checkpoints.js";
|
|
29
26
|
import {
|
|
30
|
-
|
|
27
|
+
deleteMemoryCheckpoint,
|
|
28
|
+
getMemoryCheckpoint,
|
|
29
|
+
setMemoryCheckpoint,
|
|
30
|
+
} from "../../../../persistence/checkpoints.js";
|
|
31
|
+
import {
|
|
32
|
+
durableEmbeddingCacheExtras,
|
|
31
33
|
getMemoryBackendStatus,
|
|
32
34
|
} from "../../../../persistence/embeddings/embedding-backend.js";
|
|
33
35
|
import {
|
|
34
36
|
readEmbeddingCache,
|
|
35
37
|
writeEmbeddingCache,
|
|
36
38
|
} from "../../../../persistence/embeddings/embedding-cache.js";
|
|
37
|
-
import {
|
|
39
|
+
import { embeddingContentHashWithExtras } from "../../../../persistence/embeddings/embedding-types.js";
|
|
38
40
|
import { embedWithBackend, resolveQdrantUrl } from "../embeddings.js";
|
|
39
41
|
import { getLogger } from "../logging.js";
|
|
40
42
|
import { memoryDbOrNull } from "../memory-db.js";
|
|
@@ -59,6 +61,274 @@ export const SECTION_COLLECTION = "memory_v3_sections";
|
|
|
59
61
|
export const MAINTAIN_EMBED_HIGH_WATER_KEY =
|
|
60
62
|
"memory_v3_maintain:sections_embedded_through_ms";
|
|
61
63
|
|
|
64
|
+
/**
|
|
65
|
+
* Checkpoint key of the section chunker version the stored vectors were built
|
|
66
|
+
* with, and the current version. Point ids derive from `(article, ordinal)`
|
|
67
|
+
* and the dense lane resolves hits by ordinal against the in-memory index, so
|
|
68
|
+
* a chunker change that moves chunk text or ordinals (version 2: the body
|
|
69
|
+
* budget that keeps the head line on every chunk) leaves a collection built
|
|
70
|
+
* by the previous chunker pointing at the wrong sections until every page is
|
|
71
|
+
* re-embedded. {@link ensureSectionChunkerVersion} forces that rebuild once
|
|
72
|
+
* per version change through the same high-water reset a recreated
|
|
73
|
+
* collection uses.
|
|
74
|
+
*/
|
|
75
|
+
export const SECTION_CHUNKER_VERSION_KEY =
|
|
76
|
+
"memory_v3_maintain:section_chunker_version";
|
|
77
|
+
export const SECTION_CHUNKER_VERSION = 2;
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Checkpoint key marking a rebuild that a chunker version change forced and
|
|
81
|
+
* that no clean full re-embed pass has completed since: written by
|
|
82
|
+
* {@link ensureSectionChunkerVersion} before it resets the high-water, so an
|
|
83
|
+
* interruption between the two writes leaves the marker in place and the
|
|
84
|
+
* next check finishes the transition, and cleared by
|
|
85
|
+
* {@link commitSectionEmbedHighWater}. While it is set the stored points were
|
|
86
|
+
* built by the previous chunker, so their ordinals can name the wrong section
|
|
87
|
+
* of the current index and the dense lane serves no hits
|
|
88
|
+
* ({@link sectionDenseReadsHeld}); the maintain pass it names re-embeds every
|
|
89
|
+
* page and every capability row the store holds before its commit clears the
|
|
90
|
+
* marker. Persisted rather than held in process state so a restart between
|
|
91
|
+
* the reset and the rebuild keeps holding reads.
|
|
92
|
+
*/
|
|
93
|
+
export const SECTION_REBUILD_PENDING_KEY =
|
|
94
|
+
"memory_v3_maintain:section_rebuild_pending";
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Compare the recorded chunker version with the current one before an embed
|
|
98
|
+
* pass, and report whether the section store awaits a chunker rebuild. On a
|
|
99
|
+
* mismatch against a store holding vectors built by another chunker (see
|
|
100
|
+
* {@link sectionStoreHoldsStaleVectors}): mark the rebuild pending, then
|
|
101
|
+
* clear the embed high-water (so the next maintain pass re-embeds every page
|
|
102
|
+
* and prunes stale points through its usual paths), record the current
|
|
103
|
+
* version, and log once. The marker is written first because it is the only
|
|
104
|
+
* signal that survives the high-water reset: a crash or failed write between
|
|
105
|
+
* the two leaves the hold in place and the next check finishes the
|
|
106
|
+
* transition, where the reverse order would leave a store that reads as a
|
|
107
|
+
* fresh install with stale points still in it. On a mismatch against an empty
|
|
108
|
+
* store (a fresh install) only the version is recorded. On a match nothing is
|
|
109
|
+
* written. Returns whether a rebuild is pending after the check: one this
|
|
110
|
+
* call forced, or one an earlier check marked that no clean pass has
|
|
111
|
+
* committed since. Called at dense lane init, by the maintain job, and by the
|
|
112
|
+
* one-time backfill, whichever runs first, so the version is on record before
|
|
113
|
+
* any pass commits a high-water, and retried from the dense read path while
|
|
114
|
+
* a lane init's check has not completed ({@link settleSectionDenseReadHold}).
|
|
115
|
+
*/
|
|
116
|
+
export async function ensureSectionChunkerVersion(): Promise<boolean> {
|
|
117
|
+
const recorded = getMemoryCheckpoint(SECTION_CHUNKER_VERSION_KEY);
|
|
118
|
+
if (recorded === String(SECTION_CHUNKER_VERSION)) {
|
|
119
|
+
return getMemoryCheckpoint(SECTION_REBUILD_PENDING_KEY) !== null;
|
|
120
|
+
}
|
|
121
|
+
const stale = await sectionStoreHoldsStaleVectors();
|
|
122
|
+
if (stale) {
|
|
123
|
+
setMemoryCheckpoint(SECTION_REBUILD_PENDING_KEY, "1");
|
|
124
|
+
deleteMemoryCheckpoint(MAINTAIN_EMBED_HIGH_WATER_KEY);
|
|
125
|
+
log.info(
|
|
126
|
+
{ recorded, current: SECTION_CHUNKER_VERSION },
|
|
127
|
+
"memory-v3 section chunker version changed: the next maintain pass rebuilds the section dense store from every page",
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
setMemoryCheckpoint(
|
|
131
|
+
SECTION_CHUNKER_VERSION_KEY,
|
|
132
|
+
String(SECTION_CHUNKER_VERSION),
|
|
133
|
+
);
|
|
134
|
+
return stale;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Whether a store whose recorded chunker version is absent or differs from
|
|
139
|
+
* the current one holds vectors built by another chunker. True when an embed
|
|
140
|
+
* high-water is on record (a pass committed vectors), when a rebuild is
|
|
141
|
+
* already pending (an earlier transition was interrupted before the version
|
|
142
|
+
* was recorded), or, with neither on record, when the collection holds any
|
|
143
|
+
* point (an install whose passes never committed cleanly). An empty
|
|
144
|
+
* collection is a fresh install with nothing to rebuild. The collection probe
|
|
145
|
+
* throws when Qdrant is unreachable, so the check completes only once the
|
|
146
|
+
* store can be read.
|
|
147
|
+
*/
|
|
148
|
+
async function sectionStoreHoldsStaleVectors(): Promise<boolean> {
|
|
149
|
+
if (getMemoryCheckpoint(MAINTAIN_EMBED_HIGH_WATER_KEY) !== null) {
|
|
150
|
+
return true;
|
|
151
|
+
}
|
|
152
|
+
if (getMemoryCheckpoint(SECTION_REBUILD_PENDING_KEY) !== null) {
|
|
153
|
+
return true;
|
|
154
|
+
}
|
|
155
|
+
const result = await getSectionDenseClient().scroll(SECTION_COLLECTION, {
|
|
156
|
+
limit: 1,
|
|
157
|
+
with_payload: false,
|
|
158
|
+
with_vector: false,
|
|
159
|
+
});
|
|
160
|
+
return result.points.length > 0;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Why this process holds dense reads: `rebuild` while the durable marker
|
|
165
|
+
* says the store awaits a chunker rebuild; `indeterminate` while the version
|
|
166
|
+
* check has not completed (its last run threw: a collection probe against an
|
|
167
|
+
* unreachable Qdrant, a checkpoint the ledger could not serve), so whether
|
|
168
|
+
* the stored ordinals are safe is unknown; `open` when nothing holds them.
|
|
169
|
+
*/
|
|
170
|
+
type SectionDenseReadHold = "open" | "rebuild" | "indeterminate";
|
|
171
|
+
|
|
172
|
+
let _hold: SectionDenseReadHold = "open";
|
|
173
|
+
|
|
174
|
+
/** Epoch ms of the version check whose failure last left the hold
|
|
175
|
+
* indeterminate; the retry waits {@link SECTION_VERSION_CHECK_RETRY_MS}
|
|
176
|
+
* from it. */
|
|
177
|
+
let _checkFailedAt = 0;
|
|
178
|
+
|
|
179
|
+
/** The retried check in flight, shared by the dense reads that overlap it. */
|
|
180
|
+
let _retry: Promise<boolean> | null = null;
|
|
181
|
+
|
|
182
|
+
/** Registered at lane init: kicks the rebuild pass when a check first
|
|
183
|
+
* reports a rebuild pending in this process. */
|
|
184
|
+
let _onRebuildPending: (() => void) | undefined;
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* How long after a failed version check the dense read path waits before
|
|
188
|
+
* retrying it, so an outage draws one collection probe a minute rather than
|
|
189
|
+
* one per read.
|
|
190
|
+
*/
|
|
191
|
+
const SECTION_VERSION_CHECK_RETRY_MS = 60_000;
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Hold dense reads while the section store awaits its chunker rebuild, or
|
|
195
|
+
* while whether it does cannot be determined. Run at dense lane init, before
|
|
196
|
+
* the lanes are handed out: compares the chunker version on record
|
|
197
|
+
* ({@link ensureSectionChunkerVersion}, which marks the rebuild pending and
|
|
198
|
+
* resets the high-water on a mismatch, and reports a marker an earlier check
|
|
199
|
+
* left), so a restart between a reset and the rebuild resumes the hold. A
|
|
200
|
+
* check that reports a rebuild pending holds reads until the rebuild's
|
|
201
|
+
* commit and calls `onRebuildPending`, the caller's cue to kick the rebuild
|
|
202
|
+
* pass. A check that throws holds reads as indeterminate: nothing on record
|
|
203
|
+
* proves the stored ordinals safe (the failed probe may be the one that
|
|
204
|
+
* would have found them stale), so the dense read path retries the check
|
|
205
|
+
* ({@link settleSectionDenseReadHold}) until one completes, and a retried
|
|
206
|
+
* check that reports the rebuild calls `onRebuildPending` the same way.
|
|
207
|
+
* Returns whether this call started a hold; a hold already in place, or none
|
|
208
|
+
* needed, returns false.
|
|
209
|
+
*/
|
|
210
|
+
export async function holdSectionDenseReadsUntilRebuilt(
|
|
211
|
+
onRebuildPending?: () => void,
|
|
212
|
+
): Promise<boolean> {
|
|
213
|
+
if (_hold !== "open") {
|
|
214
|
+
return false;
|
|
215
|
+
}
|
|
216
|
+
_onRebuildPending = onRebuildPending;
|
|
217
|
+
return applySectionChunkerVersionCheck();
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* Run the version check and move the hold to what it reports: `rebuild`
|
|
222
|
+
* (kicking the rebuild pass) when one is pending, `indeterminate` when the
|
|
223
|
+
* check throws, `open` when nothing is pending. Returns whether reads are
|
|
224
|
+
* held afterwards.
|
|
225
|
+
*/
|
|
226
|
+
async function applySectionChunkerVersionCheck(): Promise<boolean> {
|
|
227
|
+
let pending: boolean;
|
|
228
|
+
try {
|
|
229
|
+
pending = await ensureSectionChunkerVersion();
|
|
230
|
+
} catch (err) {
|
|
231
|
+
_hold = "indeterminate";
|
|
232
|
+
_checkFailedAt = Date.now();
|
|
233
|
+
log.warn(
|
|
234
|
+
{
|
|
235
|
+
err: err instanceof Error ? err.message : String(err),
|
|
236
|
+
retryAfterMs: SECTION_VERSION_CHECK_RETRY_MS,
|
|
237
|
+
},
|
|
238
|
+
"memory-v3 section chunker version check failed; dense reads held until a retried check completes",
|
|
239
|
+
);
|
|
240
|
+
return true;
|
|
241
|
+
}
|
|
242
|
+
if (!pending) {
|
|
243
|
+
releaseSectionDenseReadHold();
|
|
244
|
+
return false;
|
|
245
|
+
}
|
|
246
|
+
_hold = "rebuild";
|
|
247
|
+
log.warn(
|
|
248
|
+
{ current: SECTION_CHUNKER_VERSION },
|
|
249
|
+
"memory-v3 section store awaits its chunker rebuild: the dense lane serves no hits until the rebuild pass completes",
|
|
250
|
+
);
|
|
251
|
+
_onRebuildPending?.();
|
|
252
|
+
return true;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* Whether the dense lane must serve no hits, the fast path of every dense
|
|
257
|
+
* read. A hold for a rebuild on record re-reads the durable marker, so the
|
|
258
|
+
* read that finds it cleared (the rebuild completed in another process)
|
|
259
|
+
* releases the hold, and a marker that cannot be read keeps holding. An
|
|
260
|
+
* indeterminate hold stays until a retried check completes
|
|
261
|
+
* ({@link settleSectionDenseReadHold}), never on the marker's absence, which
|
|
262
|
+
* is exactly what the failed check left unproven.
|
|
263
|
+
*/
|
|
264
|
+
export function sectionDenseReadsHeld(): boolean {
|
|
265
|
+
if (_hold === "open") {
|
|
266
|
+
return false;
|
|
267
|
+
}
|
|
268
|
+
if (_hold === "indeterminate") {
|
|
269
|
+
return true;
|
|
270
|
+
}
|
|
271
|
+
try {
|
|
272
|
+
if (getMemoryCheckpoint(SECTION_REBUILD_PENDING_KEY) !== null) {
|
|
273
|
+
return true;
|
|
274
|
+
}
|
|
275
|
+
} catch {
|
|
276
|
+
return true;
|
|
277
|
+
}
|
|
278
|
+
releaseSectionDenseReadHold();
|
|
279
|
+
return false;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* The slow path behind {@link sectionDenseReadsHeld}, for a dense read that
|
|
284
|
+
* found reads held: an indeterminate hold whose retry cooldown has elapsed
|
|
285
|
+
* runs the version check again (one check at a time, shared by the reads
|
|
286
|
+
* that overlap it), and the check that completes moves the hold to the
|
|
287
|
+
* rebuild it reports or releases it. Resolves to whether reads are still
|
|
288
|
+
* held.
|
|
289
|
+
*/
|
|
290
|
+
export async function settleSectionDenseReadHold(): Promise<boolean> {
|
|
291
|
+
if (_hold !== "indeterminate") {
|
|
292
|
+
return sectionDenseReadsHeld();
|
|
293
|
+
}
|
|
294
|
+
if (Date.now() - _checkFailedAt < SECTION_VERSION_CHECK_RETRY_MS) {
|
|
295
|
+
return true;
|
|
296
|
+
}
|
|
297
|
+
if (!_retry) {
|
|
298
|
+
_retry = applySectionChunkerVersionCheck().finally(() => {
|
|
299
|
+
_retry = null;
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
return _retry;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
function releaseSectionDenseReadHold(): void {
|
|
306
|
+
if (_hold === "open") {
|
|
307
|
+
return;
|
|
308
|
+
}
|
|
309
|
+
const released = _hold;
|
|
310
|
+
_hold = "open";
|
|
311
|
+
log.info(
|
|
312
|
+
released === "rebuild"
|
|
313
|
+
? "memory-v3 section store rebuilt for the current chunker: dense reads resume"
|
|
314
|
+
: "memory-v3 section chunker version check completed with no rebuild pending: dense reads resume",
|
|
315
|
+
);
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
/**
|
|
319
|
+
* Record the epoch-ms high-water of a re-embed pass that completed with zero
|
|
320
|
+
* failures, the point from which the maintain job and the backfill advance
|
|
321
|
+
* the mark. A pass that started with the mark absent, which is what a forced
|
|
322
|
+
* chunker rebuild leaves behind, re-embedded every page (and, with the
|
|
323
|
+
* rebuild marked pending, every capability row the store held), so the same
|
|
324
|
+
* commit clears the pending marker and releases this process's read hold.
|
|
325
|
+
*/
|
|
326
|
+
export function commitSectionEmbedHighWater(highWaterMs: number): void {
|
|
327
|
+
setMemoryCheckpoint(MAINTAIN_EMBED_HIGH_WATER_KEY, String(highWaterMs));
|
|
328
|
+
deleteMemoryCheckpoint(SECTION_REBUILD_PENDING_KEY);
|
|
329
|
+
releaseSectionDenseReadHold();
|
|
330
|
+
}
|
|
331
|
+
|
|
62
332
|
/**
|
|
63
333
|
* Stable UUIDv5 namespace used to derive a deterministic Qdrant point ID from a
|
|
64
334
|
* section's `(article, ordinal)` pair. The namespace itself is an arbitrary
|
|
@@ -242,24 +512,6 @@ function sectionCacheId(article: string, ordinal: number): string {
|
|
|
242
512
|
return `${article}#${ordinal}`;
|
|
243
513
|
}
|
|
244
514
|
|
|
245
|
-
/**
|
|
246
|
-
* Content hash a section's cached vector is keyed by. Folds the provider's
|
|
247
|
-
* embedding-option extras (Gemini task type / output dimensions) into the base
|
|
248
|
-
* text hash, so changing an option that alters the vector for identical text is
|
|
249
|
-
* a cache miss that re-embeds. With no extras the bare text hash is returned
|
|
250
|
-
* unchanged, keeping existing rows valid for non-Gemini and default-Gemini
|
|
251
|
-
* configs.
|
|
252
|
-
*/
|
|
253
|
-
function sectionContentHash(text: string, extras: string[]): string {
|
|
254
|
-
const base = embeddingInputContentHash({ type: "text", text });
|
|
255
|
-
if (extras.length === 0) {
|
|
256
|
-
return base;
|
|
257
|
-
}
|
|
258
|
-
return createHash("sha256")
|
|
259
|
-
.update(`${base}\0${extras.join("\0")}`)
|
|
260
|
-
.digest("hex");
|
|
261
|
-
}
|
|
262
|
-
|
|
263
515
|
/**
|
|
264
516
|
* Embed each section's `text` and upsert one point per section, keyed by a
|
|
265
517
|
* deterministic `(article, ordinal)`-derived ID. Stable IDs mean re-upserting
|
|
@@ -313,6 +565,36 @@ export async function upsertSections(
|
|
|
313
565
|
});
|
|
314
566
|
}
|
|
315
567
|
|
|
568
|
+
/**
|
|
569
|
+
* Sections per backend call when warming the cache: the vectors of one call
|
|
570
|
+
* are held in memory until its cache rows are written, so this bounds that
|
|
571
|
+
* footprint (a few megabytes at 3,072 dimensions) while a call still spans
|
|
572
|
+
* many pages.
|
|
573
|
+
*/
|
|
574
|
+
export const WARM_SECTIONS_PER_CALL = 200;
|
|
575
|
+
|
|
576
|
+
/**
|
|
577
|
+
* Warm the `memory_embeddings` cache for `sections` across pages, in backend
|
|
578
|
+
* calls of at most {@link WARM_SECTIONS_PER_CALL} sections (every miss in a
|
|
579
|
+
* call embeds in one batched request), so the per-page `upsertSections` calls
|
|
580
|
+
* that follow serve from the cache and make no backend round trip. Without
|
|
581
|
+
* the warm-up a corpus rebuild pays one backend call per page. The vectors
|
|
582
|
+
* are not returned: the cache rows are the product, keyed exactly as the
|
|
583
|
+
* per-page path keys them, and each call's vectors are released once its rows
|
|
584
|
+
* are written. An empty `sections` array is a no-op.
|
|
585
|
+
*/
|
|
586
|
+
export async function warmSectionEmbeddings(
|
|
587
|
+
config: AssistantConfig,
|
|
588
|
+
sections: Section[],
|
|
589
|
+
): Promise<void> {
|
|
590
|
+
for (let i = 0; i < sections.length; i += WARM_SECTIONS_PER_CALL) {
|
|
591
|
+
await embedSectionsCached(
|
|
592
|
+
config,
|
|
593
|
+
sections.slice(i, i + WARM_SECTIONS_PER_CALL),
|
|
594
|
+
);
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
|
|
316
598
|
/**
|
|
317
599
|
* Resolve a dense vector per section, reusing cached vectors for sections whose
|
|
318
600
|
* `text` is unchanged and embedding only the misses in a single batched backend
|
|
@@ -339,11 +621,13 @@ async function embedSectionsCached(
|
|
|
339
621
|
const status = await getMemoryBackendStatus(config);
|
|
340
622
|
const mem = memoryDbOrNull("embedSectionsCached");
|
|
341
623
|
|
|
342
|
-
//
|
|
343
|
-
//
|
|
344
|
-
//
|
|
345
|
-
const extras = status.provider
|
|
346
|
-
const hashes = sections.map((s) =>
|
|
624
|
+
// Fold provider extras that change the vector for identical text (Gemini
|
|
625
|
+
// task type / dimensions, custom endpoint URL / dimensions) into the
|
|
626
|
+
// durable cache identity. Other backends keep the bare text hash.
|
|
627
|
+
const extras = durableEmbeddingCacheExtras(config, status.provider);
|
|
628
|
+
const hashes = sections.map((s) =>
|
|
629
|
+
embeddingContentHashWithExtras({ type: "text", text: s.text }, extras),
|
|
630
|
+
);
|
|
347
631
|
|
|
348
632
|
const result: Array<number[] | undefined> = new Array(sections.length);
|
|
349
633
|
const missIndices: number[] = [];
|
|
@@ -491,4 +775,8 @@ export async function listSectionArticles(
|
|
|
491
775
|
export function _resetSectionDenseStoreForTests(): void {
|
|
492
776
|
_client = null;
|
|
493
777
|
_collectionReady = false;
|
|
778
|
+
_hold = "open";
|
|
779
|
+
_checkFailedAt = 0;
|
|
780
|
+
_retry = null;
|
|
781
|
+
_onRebuildPending = undefined;
|
|
494
782
|
}
|
|
@@ -2,9 +2,10 @@ import type { SectionIndex, Slug } from "./types.js";
|
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Section-grain "needle" lane for memory-v3 retrieval: a lexical BM25F search
|
|
5
|
-
* over a {@link SectionIndex}. Each section is a tiny two-field document
|
|
6
|
-
* weighted `head` line (`${lastSlugSegment}
|
|
7
|
-
* `
|
|
5
|
+
* over a {@link SectionIndex}. Each section is a tiny two-field document, a
|
|
6
|
+
* weighted `head` line (`${lastSlugSegment} - ${title}`, the title capped, as
|
|
7
|
+
* `sectionHeadLine` in `sections.ts` renders it) and the remaining `body`
|
|
8
|
+
* text, so a literal term in a heading outranks the same term buried in
|
|
8
9
|
* prose. Scoring happens at section grain; results are deduped to distinct
|
|
9
10
|
* articles, each tagged with its best-scoring section.
|
|
10
11
|
*
|
|
@@ -33,6 +34,13 @@ export interface SectionNeedleScoredHit {
|
|
|
33
34
|
score: number;
|
|
34
35
|
}
|
|
35
36
|
|
|
37
|
+
/** A single-term hit: a section index (into `SectionIndex.sections`) and the
|
|
38
|
+
* term's own BM25F contribution to that section. */
|
|
39
|
+
interface SectionTermHit {
|
|
40
|
+
doc: number;
|
|
41
|
+
score: number;
|
|
42
|
+
}
|
|
43
|
+
|
|
36
44
|
export interface SectionNeedle {
|
|
37
45
|
/**
|
|
38
46
|
* Returns up to `k` distinct articles ranked by BM25F score (descending),
|
|
@@ -59,16 +67,72 @@ export interface SectionNeedle {
|
|
|
59
67
|
* entity keys (hub words like "vellum" fall below the floor).
|
|
60
68
|
*/
|
|
61
69
|
idf(term: string): number;
|
|
70
|
+
/**
|
|
71
|
+
* The query terms contributing the most BM25F score to the section at
|
|
72
|
+
* `doc` (an index into `SectionIndex.sections`), best first, at most `n`;
|
|
73
|
+
* ties break by term. Empty when no query term occurs in that section.
|
|
74
|
+
* Feeds the keyword-in-context finder snippets in `pool-select.ts`.
|
|
75
|
+
*/
|
|
76
|
+
topTerms(doc: number, queryText: string, n: number): string[];
|
|
77
|
+
/**
|
|
78
|
+
* Document frequency of a single unigram: the number of sections it occurs
|
|
79
|
+
* in (head or body), 0 when the corpus does not hold it. A bigram term is
|
|
80
|
+
* never a single-term signal and reads 0. Feeds the rare-term lane
|
|
81
|
+
* (`rare-term-lane.ts`), which keys on terms rare enough that the sections
|
|
82
|
+
* they occur in are near-certain matches on their own.
|
|
83
|
+
*/
|
|
84
|
+
df(term: string): number;
|
|
85
|
+
/**
|
|
86
|
+
* The top `k` sections for a single unigram by its own BM25F contribution,
|
|
87
|
+
* score descending with ties broken by `(article, ordinal)`. Empty for a
|
|
88
|
+
* term the corpus does not hold, for a bigram term, and for `k <= 0`.
|
|
89
|
+
*/
|
|
90
|
+
scoreTerm(term: string, k: number): SectionTermHit[];
|
|
62
91
|
}
|
|
63
92
|
|
|
64
|
-
/**
|
|
65
|
-
|
|
93
|
+
/** The characters of a needle token; the tokenizer splits on any other. */
|
|
94
|
+
const TOKEN_CHARS = "a-z0-9";
|
|
95
|
+
const NON_TOKEN_RUN = new RegExp(`[^${TOKEN_CHARS}]+`);
|
|
96
|
+
/** The shape of a needle term: a unigram of token characters, or a bigram
|
|
97
|
+
* of two joined by `_`. */
|
|
98
|
+
const TERM_SHAPE = new RegExp(`^[${TOKEN_CHARS}]+(?:_[${TOKEN_CHARS}]+)*$`);
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* The needle's unigram tokenizer: lowercase, split on non-token characters,
|
|
102
|
+
* drop empties. Shared with the rare-term lane so a message is tokenized
|
|
103
|
+
* exactly as the corpus was indexed.
|
|
104
|
+
*/
|
|
105
|
+
export function tokenizeUnigrams(text: string): string[] {
|
|
66
106
|
return text
|
|
67
107
|
.toLowerCase()
|
|
68
|
-
.split(
|
|
108
|
+
.split(NON_TOKEN_RUN)
|
|
69
109
|
.filter((token) => token.length > 0);
|
|
70
110
|
}
|
|
71
111
|
|
|
112
|
+
/**
|
|
113
|
+
* The span of the first whole-token occurrence of a needle `term` in `text`,
|
|
114
|
+
* or `undefined`. The term matches case-insensitively at token boundaries,
|
|
115
|
+
* with a bigram's halves separated by any run of non-token characters, so
|
|
116
|
+
* the occurrence found is one the tokenizer would have indexed. Feeds the
|
|
117
|
+
* keyword-in-context snippets in `pool-select.ts`.
|
|
118
|
+
*/
|
|
119
|
+
export function findTerm(
|
|
120
|
+
text: string,
|
|
121
|
+
term: string,
|
|
122
|
+
): { start: number; end: number } | undefined {
|
|
123
|
+
if (!TERM_SHAPE.test(term)) {
|
|
124
|
+
return undefined;
|
|
125
|
+
}
|
|
126
|
+
const halves = term.split("_").join(`[^${TOKEN_CHARS}]+`);
|
|
127
|
+
const match = new RegExp(
|
|
128
|
+
`(?<![${TOKEN_CHARS}])${halves}(?![${TOKEN_CHARS}])`,
|
|
129
|
+
"i",
|
|
130
|
+
).exec(text);
|
|
131
|
+
return match
|
|
132
|
+
? { start: match.index, end: match.index + match[0].length }
|
|
133
|
+
: undefined;
|
|
134
|
+
}
|
|
135
|
+
|
|
72
136
|
/** Unigrams plus adjacent-token bigrams (`a_b`), matching the harness. */
|
|
73
137
|
function tokenize(text: string): string[] {
|
|
74
138
|
const unigrams = tokenizeUnigrams(text);
|
|
@@ -144,6 +208,23 @@ export function buildSectionNeedle(index: SectionIndex): SectionNeedle {
|
|
|
144
208
|
return idfFromDf(postings.get(term)?.length ?? 0);
|
|
145
209
|
}
|
|
146
210
|
|
|
211
|
+
/** A bigram term (`a_b`) is never eligible as a single-term signal. */
|
|
212
|
+
function isUnigram(term: string): boolean {
|
|
213
|
+
return !term.includes("_");
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
function df(term: string): number {
|
|
217
|
+
return isUnigram(term) ? (postings.get(term)?.length ?? 0) : 0;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/** One term's BM25F contribution to section `doc`. */
|
|
221
|
+
function termScore(doc: number, weightedTf: number, termIdf: number): number {
|
|
222
|
+
const norm = weightedTf * (k1 + 1);
|
|
223
|
+
const denom =
|
|
224
|
+
weightedTf + k1 * (1 - b + b * (docLengths[doc]! / avgDocLength));
|
|
225
|
+
return termIdf * (norm / denom);
|
|
226
|
+
}
|
|
227
|
+
|
|
147
228
|
/** BM25F score per section for the given query terms. */
|
|
148
229
|
function scoreSections(queryTerms: Set<string>): Map<number, number> {
|
|
149
230
|
const scores = new Map<number, number>();
|
|
@@ -160,16 +241,69 @@ export function buildSectionNeedle(index: SectionIndex): SectionNeedle {
|
|
|
160
241
|
const termIdf = idfFromDf(list.length);
|
|
161
242
|
|
|
162
243
|
for (const { doc, weightedTf } of list) {
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
244
|
+
scores.set(
|
|
245
|
+
doc,
|
|
246
|
+
(scores.get(doc) ?? 0) + termScore(doc, weightedTf, termIdf),
|
|
247
|
+
);
|
|
167
248
|
}
|
|
168
249
|
}
|
|
169
250
|
|
|
170
251
|
return scores;
|
|
171
252
|
}
|
|
172
253
|
|
|
254
|
+
/** The posting of `doc` in `list`, or `undefined` when the term is absent
|
|
255
|
+
* from that section. Sections are indexed in ascending order, so every
|
|
256
|
+
* postings list is sorted by `doc` and a binary search finds it. */
|
|
257
|
+
function postingFor(list: Posting[], doc: number): Posting | undefined {
|
|
258
|
+
let lo = 0;
|
|
259
|
+
let hi = list.length - 1;
|
|
260
|
+
while (lo <= hi) {
|
|
261
|
+
const mid = (lo + hi) >>> 1;
|
|
262
|
+
const posting = list[mid]!;
|
|
263
|
+
if (posting.doc === doc) {
|
|
264
|
+
return posting;
|
|
265
|
+
}
|
|
266
|
+
if (posting.doc < doc) {
|
|
267
|
+
lo = mid + 1;
|
|
268
|
+
} else {
|
|
269
|
+
hi = mid - 1;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
return undefined;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
function topTerms(doc: number, queryText: string, n: number): string[] {
|
|
276
|
+
if (n <= 0 || doc < 0 || doc >= docCount) {
|
|
277
|
+
return [];
|
|
278
|
+
}
|
|
279
|
+
const contributions: Array<{ term: string; score: number }> = [];
|
|
280
|
+
for (const term of new Set(tokenize(queryText))) {
|
|
281
|
+
const list = postings.get(term);
|
|
282
|
+
const posting = list ? postingFor(list, doc) : undefined;
|
|
283
|
+
if (list && posting) {
|
|
284
|
+
contributions.push({
|
|
285
|
+
term,
|
|
286
|
+
score: termScore(doc, posting.weightedTf, idfFromDf(list.length)),
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
contributions.sort(
|
|
291
|
+
(a, c) => c.score - a.score || a.term.localeCompare(c.term),
|
|
292
|
+
);
|
|
293
|
+
return contributions.slice(0, n).map((c) => c.term);
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
function scoreTerm(term: string, k: number): SectionTermHit[] {
|
|
297
|
+
if (k <= 0 || !isUnigram(term)) {
|
|
298
|
+
return [];
|
|
299
|
+
}
|
|
300
|
+
const scores = scoreSections(new Set([term]));
|
|
301
|
+
return [...scores.keys()]
|
|
302
|
+
.sort((a, c) => rankSection(a, c, scores))
|
|
303
|
+
.slice(0, k)
|
|
304
|
+
.map((doc) => ({ doc, score: scores.get(doc)! }));
|
|
305
|
+
}
|
|
306
|
+
|
|
173
307
|
/** Deterministic order: score desc, then (article, ordinal) asc. */
|
|
174
308
|
function rankSection(
|
|
175
309
|
a: number,
|
|
@@ -249,5 +383,5 @@ export function buildSectionNeedle(index: SectionIndex): SectionNeedle {
|
|
|
249
383
|
return best;
|
|
250
384
|
}
|
|
251
385
|
|
|
252
|
-
return { query, queryScored, bestSection, idf };
|
|
386
|
+
return { query, queryScored, bestSection, idf, topTerms, df, scoreTerm };
|
|
253
387
|
}
|