@xopcai/xopc 0.0.248 → 0.0.249
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/dist/browser-ext/manifest.json +1 -1
- package/dist/extensions/telegram/xopc.extension.json +1 -1
- package/dist/gateway/static/root/assets/{activity-store-etpmyV7S.js → activity-store-B759R_qf.js} +1 -1
- package/dist/gateway/static/root/assets/{agent-avatar-dicebear-BmKxSM1k.js → agent-avatar-dicebear-BUu7EnwM.js} +1 -1
- package/dist/gateway/static/root/assets/agent-defaults-settings-panel-C1rXNUAG.js +1 -0
- package/dist/gateway/static/root/assets/agents-DK9HjHO0.js +1 -0
- package/dist/gateway/static/root/assets/{api-B0-hLuZ1.js → api-Cg0v7Lpn.js} +1 -1
- package/dist/gateway/static/root/assets/app-management-settings-panel-C9DkCW_d.js +1 -0
- package/dist/gateway/static/root/assets/appearance-settings-CFggS95Y.js +1 -0
- package/dist/gateway/static/root/assets/apps-page-jOvT-fzU.js +1 -0
- package/dist/gateway/static/root/assets/{archive-plugin-BnMSgZvR.js → archive-plugin-BQrilVVv.js} +1 -1
- package/dist/gateway/static/root/assets/{attachment-load-CejsQMev.js → attachment-load-BG0BliqV.js} +1 -1
- package/dist/gateway/static/root/assets/{automations-page-RC8EyoAf.js → automations-page-Bo4RiTkh.js} +1 -1
- package/dist/gateway/static/root/assets/automations-workspace-BKjKTlW8.js +6 -0
- package/dist/gateway/static/root/assets/{binary-plugins-DGjppLSG.js → binary-plugins-BCnyNU0C.js} +1 -1
- package/dist/gateway/static/root/assets/{block-editor-CWdP4bUc.js → block-editor-Db8DlVvg.js} +50 -50
- package/dist/gateway/static/root/assets/browser-settings-page-Dzq18pO1.js +8 -0
- package/dist/gateway/static/root/assets/{browser-workflow-inputs-BQ1Ilw_o.js → browser-workflow-inputs-C71vfl0b.js} +1 -1
- package/dist/gateway/static/root/assets/{browser-workflows-page-CJh4NyxT.js → browser-workflows-page-vvmSYKsO.js} +2 -2
- package/dist/gateway/static/root/assets/capabilities-settings-panel-DW4SBQf4.js +7 -0
- package/dist/gateway/static/root/assets/channels-settings-57OGuewD.js +1 -0
- package/dist/gateway/static/root/assets/{channels-status-swr-Ohhee4vm.js → channels-status-swr-CKyV3jY5.js} +1 -1
- package/dist/gateway/static/root/assets/{chat-terminal-dock-BOtoKTK3.js → chat-terminal-dock-B1Xd6OFB.js} +2 -2
- package/dist/gateway/static/root/assets/connectors-page-CT_I3kbR.js +2 -0
- package/dist/gateway/static/root/assets/{cron-expression-DTj1V3Sw.js → cron-expression-D-F9vjtE.js} +1 -1
- package/dist/gateway/static/root/assets/{date-picker-Yr6OCvGL.js → date-picker-B2OoYvic.js} +1 -1
- package/dist/gateway/static/root/assets/dependency-picker-BiGx9Sbj.js +1 -0
- package/dist/gateway/static/root/assets/{desktop-pet-DbGzggPF.js → desktop-pet-BNMRqipe.js} +1 -1
- package/dist/gateway/static/root/assets/desktop-pet-settings-DeYbIV7A.js +1 -0
- package/dist/gateway/static/root/assets/{extension-debug-page-DgTtk4KC.js → extension-debug-page-COyn05ub.js} +1 -1
- package/dist/gateway/static/root/assets/{extension-page-DtQeiP6f.js → extension-page-oH43chS2.js} +1 -1
- package/dist/gateway/static/root/assets/extension-settings-page-BMO59994.js +1 -0
- package/dist/gateway/static/root/assets/gateway-config-api-cimpViGk.js +1 -0
- package/dist/gateway/static/root/assets/{gateway-config-swr-DXuXtU1w.js → gateway-config-swr-BGdHwT4e.js} +1 -1
- package/dist/gateway/static/root/assets/gateway-settings-BHJtnSic.js +1 -0
- package/dist/gateway/static/root/assets/{gateway-startup-retry-CzBzglzQ.js → gateway-startup-retry-CuaM3b4c.js} +1 -1
- package/dist/gateway/static/root/assets/heartbeat-settings-DNhrZHqx.js +1 -0
- package/dist/gateway/static/root/assets/home-page-BiHwiBnQ.js +1 -0
- package/dist/gateway/static/root/assets/{image-generation-api-TIgsn04n.js → image-generation-api-D7duj7Uj.js} +1 -1
- package/dist/gateway/static/root/assets/index-DGeGmj4k.css +2 -0
- package/dist/gateway/static/root/assets/index-aBs0EfQB.js +72 -0
- package/dist/gateway/static/root/assets/{keyboard-shortcuts-settings-wsWuoa8p.js → keyboard-shortcuts-settings-D8Zw_lYd.js} +1 -1
- package/dist/gateway/static/root/assets/{local-app-workbench-page-CpyvYyrb.js → local-app-workbench-page-eBFVWmtH.js} +2 -2
- package/dist/gateway/static/root/assets/{local-apps-page-CXrbrGo8.js → local-apps-page-CvPDPRwb.js} +1 -1
- package/dist/gateway/static/root/assets/{locale-store-BJFLQY8O.js → locale-store-zEL8bkwx.js} +1 -1
- package/dist/gateway/static/root/assets/logs-page-ClvcWlL6.js +2 -0
- package/dist/gateway/static/root/assets/{management-settings-BdJZFR7U.js → management-settings-D8moh99U.js} +1 -1
- package/dist/gateway/static/root/assets/{markdown-split-NK3ACVG2.js → markdown-split-D7V3j0vE.js} +1 -1
- package/dist/gateway/static/root/assets/{markdown-view-DTF9v1gg.js → markdown-view-DGRN-8wP.js} +1 -1
- package/dist/gateway/static/root/assets/{media-plugins-F0jcUxyl.js → media-plugins-BLaE5b1Y.js} +1 -1
- package/dist/gateway/static/root/assets/messages-W5P19VTF.js +11 -0
- package/dist/gateway/static/root/assets/mobile-pairing-wizard-DiVDuCxl.js +1 -0
- package/dist/gateway/static/root/assets/note-detail-panel-CEEvR-fV.js +5 -0
- package/dist/gateway/static/root/assets/notes-page-BLqgXNCx.js +8 -0
- package/dist/gateway/static/root/assets/page-tabs-BFMGjA60.js +1 -0
- package/dist/gateway/static/root/assets/preview-open-alternatives-DNEWZN7H.js +1 -0
- package/dist/gateway/static/root/assets/{product-open-page-CxGGlWA8.js → product-open-page-Co5u7asH.js} +1 -1
- package/dist/gateway/static/root/assets/project-detail-page-CIiFJ5tk.js +1 -0
- package/dist/gateway/static/root/assets/projects-page-B3UF-Pfm.js +1 -0
- package/dist/gateway/static/root/assets/{registry-api-CIsNlSBi.js → registry-api-Cg92zSod.js} +1 -1
- package/dist/gateway/static/root/assets/remote-access-hub-BUtpkJPG.js +1 -0
- package/dist/gateway/static/root/assets/{runtime-tools-settings-panel-YkjhiQfA.js → runtime-tools-settings-panel-C0ByNmlV.js} +2 -2
- package/dist/gateway/static/root/assets/{schema-form-oFGf3G3s.js → schema-form-Dq_VQpuY.js} +1 -1
- package/dist/gateway/static/root/assets/sessions-page-UgJmG-V4.js +1 -0
- package/dist/gateway/static/root/assets/settings-advanced-gate-DDCzpdkl.js +1 -0
- package/dist/gateway/static/root/assets/settings-form-section-CZu6FX4k.js +1 -0
- package/dist/gateway/static/root/assets/{settings-page-C7VWs0IT.js → settings-page-S8ekeUZd.js} +1 -1
- package/dist/gateway/static/root/assets/setup-status-panel-BdVmwXMv.js +1 -0
- package/dist/gateway/static/root/assets/{share-preview-page-t5oz18rh.js → share-preview-page-D2fEidbn.js} +1 -1
- package/dist/gateway/static/root/assets/shares-settings-BdsqnCYj.js +1 -0
- package/dist/gateway/static/root/assets/skill-reload-api-ghzAQKna.js +1 -0
- package/dist/gateway/static/root/assets/skills-page-AYiPlgZE.js +2 -0
- package/dist/gateway/static/root/assets/{skills-page.utils-DEDTYs2W.js → skills-page.utils-DGzl-ib-.js} +1 -1
- package/dist/gateway/static/root/assets/system-settings-panel-5Xd5mIiR.js +1 -0
- package/dist/gateway/static/root/assets/task-detail-page-BQAUaCDD.js +1 -0
- package/dist/gateway/static/root/assets/{theme-store-O597U8q_.js → theme-store-ZVClZKQ0.js} +1 -1
- package/dist/gateway/static/root/assets/tunnel-api-CdZN1Jin.js +1 -0
- package/dist/gateway/static/root/assets/{use-autosave-B5eUJ6Zq.js → use-autosave-czRI0NBc.js} +1 -1
- package/dist/gateway/static/root/assets/user-model-page-W3GTm6nA.js +2 -0
- package/dist/gateway/static/root/assets/{voice-api-key-field-CMKSwz4C.js → voice-api-key-field-8YEvA3cU.js} +1 -1
- package/dist/gateway/static/root/assets/{voice-config-api-q7B6fOFB.js → voice-config-api-CopF64lY.js} +1 -1
- package/dist/gateway/static/root/assets/work-discovery-overlay-keLtqYYJ.js +1 -0
- package/dist/gateway/static/root/assets/{workflow-run-setup-panel-DZmvLZjb.js → workflow-run-setup-panel-Dy5WgYMO.js} +2 -2
- package/dist/gateway/static/root/assets/workflows-page-BbAV3h7n.js +5 -0
- package/dist/gateway/static/root/index.html +10 -26
- package/dist/package.js +1 -1
- package/dist/src/agent/agent-instance-gateway.d.ts +2 -2
- package/dist/src/agent/agent-manager.d.ts +4 -4
- package/dist/src/agent/agent-manager.js +31 -15
- package/dist/src/agent/background-review/coordinator.d.ts +2 -4
- package/dist/src/agent/background-review/coordinator.js +5 -30
- package/dist/src/agent/background-review/prompts.d.ts +4 -2
- package/dist/src/agent/background-review/prompts.js +24 -19
- package/dist/src/agent/background-review/run-background-review.d.ts +6 -7
- package/dist/src/agent/background-review/run-background-review.js +47 -41
- package/dist/src/agent/background-review/settings.d.ts +0 -1
- package/dist/src/agent/background-review/settings.js +6 -7
- package/dist/src/agent/context/audit.d.ts +36 -0
- package/dist/src/agent/context/audit.js +97 -0
- package/dist/src/agent/context/coordinator.d.ts +26 -0
- package/dist/src/agent/context/coordinator.js +72 -0
- package/dist/src/agent/context/execution-context.d.ts +54 -0
- package/dist/src/agent/context/execution-context.js +147 -0
- package/dist/src/agent/context/execution-scope.js +1 -1
- package/dist/src/agent/context/prepend.d.ts +2 -0
- package/dist/src/agent/context/prepend.js +28 -0
- package/dist/src/agent/context/project-context.d.ts +3 -3
- package/dist/src/agent/context/project-context.js +26 -23
- package/dist/src/agent/embedded/index.js +1 -1
- package/dist/src/agent/embedded/run-for-session.js +1 -0
- package/dist/src/agent/embedded/run-turn.js +22 -2
- package/dist/src/agent/embedded/types.d.ts +1 -25
- package/dist/src/agent/external-tools/composio-provider.js +87 -92
- package/dist/src/agent/external-tools/gateway-tools.d.ts +4 -1
- package/dist/src/agent/external-tools/gateway-tools.js +153 -41
- package/dist/src/agent/external-tools/index.js +1 -1
- package/dist/src/agent/external-tools/search-error.d.ts +12 -0
- package/dist/src/agent/external-tools/search-error.js +29 -0
- package/dist/src/agent/external-tools/service.d.ts +4 -0
- package/dist/src/agent/external-tools/service.js +22 -2
- package/dist/src/agent/memory/compaction-policy.js +1 -1
- package/dist/src/agent/memory/compaction-promotion.js +45 -77
- package/dist/src/agent/memory/create-memory-manager.js +1 -3
- package/dist/src/agent/memory/index.d.ts +0 -5
- package/dist/src/agent/memory/index.js +2 -5
- package/dist/src/agent/memory/manager.d.ts +0 -16
- package/dist/src/agent/memory/manager.js +11 -40
- package/dist/src/agent/memory/memory-config.js +1 -1
- package/dist/src/agent/memory/runtime.d.ts +2 -2
- package/dist/src/agent/memory/runtime.js +9 -19
- package/dist/src/agent/memory/types.d.ts +1 -1
- package/dist/src/agent/orchestration/agent-orchestrator.js +13 -21
- package/dist/src/agent/prompt/sections/memory-skills.js +25 -36
- package/dist/src/agent/prompt/sections/tooling.js +10 -4
- package/dist/src/agent/prompt/service-prompt-builder.js +4 -3
- package/dist/src/agent/service/direct-turn-helpers.js +6 -23
- package/dist/src/agent/service/process-direct-streaming.js +5 -3
- package/dist/src/agent/service.js +4 -3
- package/dist/src/agent/tasks/task-judge-service.js +1 -1
- package/dist/src/agent/tools/clarify-tool.d.ts +1 -0
- package/dist/src/agent/tools/delegate-tool.js +5 -2
- package/dist/src/agent/tools/factory.js +36 -19
- package/dist/src/agent/tools/index.d.ts +3 -2
- package/dist/src/agent/tools/index.js +4 -3
- package/dist/src/agent/tools/knowledge-memory-tool.d.ts +9 -0
- package/dist/src/agent/tools/knowledge-memory-tool.js +129 -0
- package/dist/src/agent/tools/{dreaming-tool.d.ts → memory-maintenance-tool.d.ts} +2 -2
- package/dist/src/agent/tools/memory-maintenance-tool.js +31 -0
- package/dist/src/agent/tools/user-context-tool.d.ts +8 -0
- package/dist/src/agent/tools/user-context-tool.js +81 -0
- package/dist/src/agent/tools/xopc-use-tool.js +2 -2
- package/dist/src/chat-commands/builtins/understanding.js +24 -6
- package/dist/src/cli/commands/connectors.js +1 -1
- package/dist/src/cli/commands/doctor/checks/database-schema.js +1 -1
- package/dist/src/config/schema.d.ts +68 -75
- package/dist/src/config/schema.js +29 -18
- package/dist/src/config/web-patch.d.ts +1 -1
- package/dist/src/connectors/auth-provider-registry.js +1 -1
- package/dist/src/connectors/composio-managed-client.js +6 -2
- package/dist/src/connectors/connected-source-ingestion.js +1 -1
- package/dist/src/connectors/connected-source-understanding.d.ts +1 -3
- package/dist/src/connectors/connected-source-understanding.js +86 -99
- package/dist/src/connectors/connection-candidates.d.ts +11 -0
- package/dist/src/connectors/connection-candidates.js +58 -0
- package/dist/src/connectors/connection-capabilities.d.ts +4 -0
- package/dist/src/connectors/connection-capabilities.js +37 -0
- package/dist/src/connectors/connection-recovery-service.d.ts +42 -0
- package/dist/src/connectors/connection-recovery-service.js +396 -0
- package/dist/src/connectors/health.js +1 -1
- package/dist/src/connectors/learning-coordinator.d.ts +0 -2
- package/dist/src/connectors/learning-coordinator.js +6 -7
- package/dist/src/connectors/principal.d.ts +5 -0
- package/dist/src/connectors/principal.js +18 -0
- package/dist/src/gateway/agent-builtin-tools.d.ts +28 -10
- package/dist/src/gateway/agent-builtin-tools.js +30 -9
- package/dist/src/gateway/chat-stream/mapper.js +1 -28
- package/dist/src/gateway/chat-stream/protocol.d.ts +2 -24
- package/dist/src/gateway/clarify-bridge.d.ts +4 -0
- package/dist/src/gateway/clarify-bridge.js +9 -4
- package/dist/src/gateway/heartbeat/service.js +1 -1
- package/dist/src/gateway/hono/lib/config-payload.d.ts +52 -30
- package/dist/src/gateway/hono/lib/config-payload.js +4 -4
- package/dist/src/gateway/hono/middleware/auth.js +1 -2
- package/dist/src/gateway/hono/routes/capabilities.js +1 -1
- package/dist/src/gateway/hono/routes/config-patch/misc.d.ts +1 -1
- package/dist/src/gateway/hono/routes/config-patch/misc.js +72 -28
- package/dist/src/gateway/hono/routes/connection-waits.d.ts +3 -0
- package/dist/src/gateway/hono/routes/connection-waits.js +58 -0
- package/dist/src/gateway/hono/routes/connectors.js +7 -15
- package/dist/src/gateway/hono/routes/context-sources.d.ts +4 -0
- package/dist/src/gateway/hono/routes/context-sources.js +159 -0
- package/dist/src/gateway/hono/routes/index.js +4 -2
- package/dist/src/gateway/hono/routes/lazy-bundles.js +9 -4
- package/dist/src/gateway/hono/routes/mcp.js +1 -1
- package/dist/src/gateway/hono/routes/notes.js +22 -7
- package/dist/src/gateway/hono/routes/projects.js +36 -44
- package/dist/src/gateway/hono/routes/session-input-handler.d.ts +15 -1
- package/dist/src/gateway/hono/routes/side-chats.js +13 -2
- package/dist/src/gateway/hono/routes/tasks.js +2 -2
- package/dist/src/gateway/hono/routes/user-model.d.ts +3 -0
- package/dist/src/gateway/hono/routes/user-model.js +480 -0
- package/dist/src/gateway/memory-maintenance-automation-reconciler.d.ts +11 -0
- package/dist/src/gateway/memory-maintenance-automation-reconciler.js +72 -0
- package/dist/src/gateway/service/agent-runner.d.ts +9 -1
- package/dist/src/gateway/service/agent-runner.js +25 -1
- package/dist/src/gateway/service/config-coordinator.d.ts +2 -2
- package/dist/src/gateway/service/config-coordinator.js +4 -4
- package/dist/src/gateway/service/run-gateway-agent.d.ts +1 -0
- package/dist/src/gateway/service/run-gateway-agent.js +18 -14
- package/dist/src/gateway/service/session-input-coordinator.d.ts +3 -0
- package/dist/src/gateway/service/session-input-coordinator.js +12 -2
- package/dist/src/gateway/service.d.ts +3 -1
- package/dist/src/gateway/service.js +45 -14
- package/dist/src/gateway/side-chat/manager.d.ts +16 -3
- package/dist/src/gateway/side-chat/manager.js +117 -28
- package/dist/src/gateway/side-chat/run-service.d.ts +2 -0
- package/dist/src/gateway/side-chat/run-service.js +28 -5
- package/dist/src/gateway/side-chat/types.d.ts +9 -1
- package/dist/src/heartbeat/index.js +1 -1
- package/dist/src/knowledge/connected-knowledge-pipeline.d.ts +0 -2
- package/dist/src/knowledge/connected-knowledge-pipeline.js +46 -217
- package/dist/src/knowledge-memory/domain.d.ts +35 -0
- package/dist/src/knowledge-memory/index.d.ts +2 -0
- package/dist/src/knowledge-memory/index.js +2 -0
- package/dist/src/knowledge-memory/repository.d.ts +45 -0
- package/dist/src/knowledge-memory/repository.js +154 -0
- package/dist/src/memory-maintenance/index.d.ts +2 -0
- package/dist/src/memory-maintenance/index.js +3 -0
- package/dist/src/memory-maintenance/schedule.d.ts +13 -0
- package/dist/src/memory-maintenance/schedule.js +51 -0
- package/dist/src/memory-maintenance/service.d.ts +28 -0
- package/dist/src/memory-maintenance/service.js +216 -0
- package/dist/src/notes/service.d.ts +1 -0
- package/dist/src/notes/service.js +7 -1
- package/dist/src/notes/types.d.ts +16 -0
- package/dist/src/proactive/execution/context.d.ts +2 -2
- package/dist/src/proactive/execution/context.js +16 -11
- package/dist/src/proactive/index.d.ts +1 -1
- package/dist/src/proactive/index.js +2 -2
- package/dist/src/projects/index.d.ts +1 -1
- package/dist/src/projects/index.js +2 -2
- package/dist/src/projects/knowledge-bind.d.ts +1 -0
- package/dist/src/projects/knowledge-bind.js +15 -0
- package/dist/src/projects/project-loop.d.ts +3 -3
- package/dist/src/projects/project-loop.js +4 -4
- package/dist/src/projects/project-store.js +2 -1
- package/dist/src/realtime/runtime.js +1 -0
- package/dist/src/runtime-tools/manager.js +1 -1
- package/dist/src/storage/sqlite/collaboration-rule-repository.d.ts +17 -0
- package/dist/src/storage/sqlite/collaboration-rule-repository.js +54 -0
- package/dist/src/storage/sqlite/connection-wait-repository.d.ts +30 -0
- package/dist/src/storage/sqlite/connection-wait-repository.js +338 -0
- package/dist/src/storage/sqlite/connector-account-repository.js +1 -1
- package/dist/src/storage/sqlite/context-evidence-repository.d.ts +24 -0
- package/dist/src/storage/sqlite/context-evidence-repository.js +52 -0
- package/dist/src/storage/sqlite/index.d.ts +3 -5
- package/dist/src/storage/sqlite/index.js +4 -6
- package/dist/src/storage/sqlite/knowledge-repository.d.ts +0 -19
- package/dist/src/storage/sqlite/knowledge-repository.js +1 -90
- package/dist/src/storage/sqlite/migrations/148_user_model_foundation.sql +554 -0
- package/dist/src/storage/sqlite/migrations/149_separate_source_index_from_memory.sql +18 -0
- package/dist/src/storage/sqlite/migrations/150_session_connection_waits.sql +47 -0
- package/dist/src/storage/sqlite/migrations/runner.d.ts +1 -1
- package/dist/src/storage/sqlite/migrations/runner.js +3 -3
- package/dist/src/storage/sqlite/migrations/runner.ts +1 -1
- package/dist/src/storage/sqlite/notes-repository.d.ts +2 -1
- package/dist/src/storage/sqlite/notes-repository.js +37 -3
- package/dist/src/storage/sqlite/schema.js +1 -1
- package/dist/src/storage/sqlite/session-input-repository.d.ts +14 -2
- package/dist/src/storage/sqlite/session-input-repository.js +16 -13
- package/dist/src/storage/sqlite/session-repository.js +4 -1
- package/dist/src/storage/sqlite/transcript-repository.js +1 -1
- package/dist/src/tasks/index.js +2 -2
- package/dist/src/tasks/project-operating-view-service.js +1 -1
- package/dist/src/tasks/task-application-service.js +6 -1
- package/dist/src/tasks/task-context-assembler.js +1 -1
- package/dist/src/tasks/task-context-repository.d.ts +0 -1
- package/dist/src/tasks/task-context-repository.js +1 -1
- package/dist/src/tasks/task-deletion-service.js +1 -1
- package/dist/src/tasks/task-handoff-service.js +1 -1
- package/dist/src/tasks/task-read-model-projector.js +1 -1
- package/dist/src/tasks/task-run-coordinator.js +1 -1
- package/dist/src/tasks/task-run-dispatcher.js +1 -1
- package/dist/src/tasks/task-run-repository.js +1 -0
- package/dist/src/tasks/task-signal-service.js +1 -1
- package/dist/src/tui/tool-summary.js +2 -1
- package/dist/src/tui/tui-startup-resources.js +1 -1
- package/dist/src/user-context/changes.d.ts +1 -1
- package/dist/src/user-context/config.d.ts +135 -153
- package/dist/src/user-context/config.js +94 -99
- package/dist/src/user-context/relationship-continuity.d.ts +2 -2
- package/dist/src/user-context/relationship-continuity.js +34 -24
- package/dist/src/user-context/sources/activity-clustering.d.ts +9 -3
- package/dist/src/user-context/sources/index.js +2 -2
- package/dist/src/user-context/sources/repository.d.ts +1 -21
- package/dist/src/user-context/sources/repository.js +1 -183
- package/dist/src/user-context/sources/types.d.ts +0 -23
- package/dist/src/user-model/capture/executor.d.ts +40 -0
- package/dist/src/user-model/capture/executor.js +134 -0
- package/dist/src/user-model/capture/index.d.ts +2 -0
- package/dist/src/user-model/capture/index.js +3 -0
- package/dist/src/user-model/capture/semantic.d.ts +21 -0
- package/dist/src/user-model/capture/semantic.js +197 -0
- package/dist/src/user-model/domain.d.ts +93 -0
- package/dist/src/user-model/domain.js +33 -0
- package/dist/src/user-model/goals.d.ts +58 -0
- package/dist/src/user-model/goals.js +89 -0
- package/dist/src/user-model/importance.d.ts +11 -0
- package/dist/src/user-model/importance.js +17 -0
- package/dist/src/user-model/index.d.ts +5 -0
- package/dist/src/user-model/index.js +6 -0
- package/dist/src/user-model/repository.d.ts +23 -0
- package/dist/src/user-model/repository.js +268 -0
- package/dist/src/user-model/temporal.d.ts +10 -0
- package/dist/src/user-model/temporal.js +44 -0
- package/dist/src/voice/realtime/memory-context.d.ts +7 -2
- package/dist/src/voice/realtime/memory-context.js +39 -51
- package/dist/src/work-discovery/service.d.ts +3 -14
- package/dist/src/work-discovery/service.js +138 -99
- package/dist/src/work-discovery/types.d.ts +3 -3
- package/dist/src/workflows/service/workflow-run-service.js +1 -1
- package/dist/src/workflows/service/workflow-session-bridge.js +12 -20
- package/package.json +1 -1
- package/dist/gateway/static/root/assets/agent-defaults-settings-panel-CUXApfcE.js +0 -1
- package/dist/gateway/static/root/assets/agents-DNq_GKuc.js +0 -1
- package/dist/gateway/static/root/assets/app-management-settings-panel-qfwAgyhQ.js +0 -1
- package/dist/gateway/static/root/assets/appearance-settings-DqQVUpCC.js +0 -1
- package/dist/gateway/static/root/assets/apps-page-dwIqYmXk.js +0 -1
- package/dist/gateway/static/root/assets/automations-workspace-SkdcSZ0i.js +0 -6
- package/dist/gateway/static/root/assets/browser-settings-page-CKCa6TvG.js +0 -8
- package/dist/gateway/static/root/assets/capabilities-settings-panel-DSp--zIZ.js +0 -7
- package/dist/gateway/static/root/assets/channels-settings-CMd2dDrI.js +0 -1
- package/dist/gateway/static/root/assets/cloud-C4-yfnnk.js +0 -1
- package/dist/gateway/static/root/assets/connectors-page-udWs5Kdm.js +0 -2
- package/dist/gateway/static/root/assets/dependency-picker-DpN3XZg9.js +0 -1
- package/dist/gateway/static/root/assets/desktop-pet-settings-DinCToZh.js +0 -1
- package/dist/gateway/static/root/assets/ellipsis-0k4rZLoy.js +0 -1
- package/dist/gateway/static/root/assets/extension-settings-page-DcguCgsH.js +0 -1
- package/dist/gateway/static/root/assets/eye-CABVeTq0.js +0 -1
- package/dist/gateway/static/root/assets/eye-off-DEAzt3g1.js +0 -1
- package/dist/gateway/static/root/assets/folder-open-CyzJ19I9.js +0 -1
- package/dist/gateway/static/root/assets/form-field-width-DJw_jULe.js +0 -1
- package/dist/gateway/static/root/assets/gateway-config-api-Br7lSf6H.js +0 -1
- package/dist/gateway/static/root/assets/gateway-settings-CdPoDMuj.js +0 -1
- package/dist/gateway/static/root/assets/heartbeat-settings-DHk1hawP.js +0 -1
- package/dist/gateway/static/root/assets/home-page-YGipe_W6.js +0 -1
- package/dist/gateway/static/root/assets/index-D5TQQpeb.js +0 -71
- package/dist/gateway/static/root/assets/index-DReBaaTX.css +0 -2
- package/dist/gateway/static/root/assets/interaction-BmQogeqz.js +0 -1
- package/dist/gateway/static/root/assets/is-masked-secret-DOkL5b_X.js +0 -1
- package/dist/gateway/static/root/assets/link-2-D_ZKYUW7.js +0 -1
- package/dist/gateway/static/root/assets/local-context-graph-BjUf7fQ9.js +0 -1
- package/dist/gateway/static/root/assets/logs-page-CXKy6E_l.js +0 -2
- package/dist/gateway/static/root/assets/message-square-plus-XP0tGdlV.js +0 -1
- package/dist/gateway/static/root/assets/messages-CHNYp8EQ.js +0 -3
- package/dist/gateway/static/root/assets/minimize-2-DtOGrlpo.js +0 -1
- package/dist/gateway/static/root/assets/mobile-pairing-wizard-3NKCniSp.js +0 -1
- package/dist/gateway/static/root/assets/models-hub-cache-nCfkBN8M.js +0 -1
- package/dist/gateway/static/root/assets/notes-page-DuqLahi6.js +0 -1
- package/dist/gateway/static/root/assets/notes-workbench-C7j9EdQk.js +0 -5
- package/dist/gateway/static/root/assets/oauth-api-8lP_qJpq.js +0 -1
- package/dist/gateway/static/root/assets/oauth-authorization-window-Cdolr2wE.js +0 -1
- package/dist/gateway/static/root/assets/page-tabs-BaEQMYm_.js +0 -1
- package/dist/gateway/static/root/assets/pencil-DmIY3Oa-.js +0 -1
- package/dist/gateway/static/root/assets/preview-open-alternatives-CsNVTKC0.js +0 -1
- package/dist/gateway/static/root/assets/project-detail-page-CfebYVX0.js +0 -1
- package/dist/gateway/static/root/assets/projects-page-48GvzSVa.js +0 -1
- package/dist/gateway/static/root/assets/remote-access-hub-64xj_s2m.js +0 -1
- package/dist/gateway/static/root/assets/rotate-cw-LIg3Am9S.js +0 -1
- package/dist/gateway/static/root/assets/search-DA7gz22f.js +0 -1
- package/dist/gateway/static/root/assets/sessions-page-CcwcdRN8.js +0 -1
- package/dist/gateway/static/root/assets/settings-advanced-gate-BaN84CyW.js +0 -1
- package/dist/gateway/static/root/assets/settings-form-section-DjWzRk4z.js +0 -1
- package/dist/gateway/static/root/assets/setup-status-panel-DVVOCNbr.js +0 -1
- package/dist/gateway/static/root/assets/shares-settings-DUYbYLi7.js +0 -1
- package/dist/gateway/static/root/assets/skill-reload-api-BGyD0gB9.js +0 -1
- package/dist/gateway/static/root/assets/skills-page-CjF8DTsN.js +0 -2
- package/dist/gateway/static/root/assets/system-settings-panel-BSYuRgFI.js +0 -1
- package/dist/gateway/static/root/assets/task-detail-page-YZYSTJH7.js +0 -1
- package/dist/gateway/static/root/assets/tunnel-api-FKUi9wDL.js +0 -1
- package/dist/gateway/static/root/assets/user-context-page-BCyiduKd.js +0 -2
- package/dist/gateway/static/root/assets/work-discovery-overlay-jhT2EzeH.js +0 -1
- package/dist/gateway/static/root/assets/workflows-page-DQC0TpMa.js +0 -5
- package/dist/src/agent/memory/builtin-provider.d.ts +0 -37
- package/dist/src/agent/memory/builtin-provider.js +0 -225
- package/dist/src/agent/memory/context/types.d.ts +0 -40
- package/dist/src/agent/memory/understanding/quality.d.ts +0 -8
- package/dist/src/agent/memory/understanding/quality.js +0 -18
- package/dist/src/agent/memory/understanding/service.d.ts +0 -19
- package/dist/src/agent/memory/understanding/service.js +0 -209
- package/dist/src/agent/memory/understanding/types.d.ts +0 -34
- package/dist/src/agent/memory/understanding/types.js +0 -1
- package/dist/src/agent/memory/user-context-coordinator.d.ts +0 -23
- package/dist/src/agent/memory/user-context-coordinator.js +0 -113
- package/dist/src/agent/tools/dreaming-tool.js +0 -37
- package/dist/src/agent/tools/memory-tool.d.ts +0 -9
- package/dist/src/agent/tools/memory-tool.js +0 -119
- package/dist/src/gateway/dreaming-automation-reconciler.d.ts +0 -11
- package/dist/src/gateway/dreaming-automation-reconciler.js +0 -63
- package/dist/src/gateway/hono/routes/understanding-sources.d.ts +0 -21
- package/dist/src/gateway/hono/routes/understanding-sources.js +0 -387
- package/dist/src/gateway/hono/routes/you.d.ts +0 -3
- package/dist/src/gateway/hono/routes/you.js +0 -457
- package/dist/src/projects/memory-bind.d.ts +0 -1
- package/dist/src/projects/memory-bind.js +0 -14
- package/dist/src/storage/sqlite/context-consolidation-repository.d.ts +0 -37
- package/dist/src/storage/sqlite/context-consolidation-repository.js +0 -64
- package/dist/src/storage/sqlite/memory-records-repository.d.ts +0 -217
- package/dist/src/storage/sqlite/memory-records-repository.js +0 -715
- package/dist/src/storage/sqlite/remote-context-repository.d.ts +0 -3
- package/dist/src/storage/sqlite/remote-context-repository.js +0 -40
- package/dist/src/storage/sqlite/understanding-focus-exclusions.d.ts +0 -2
- package/dist/src/storage/sqlite/understanding-focus-exclusions.js +0 -24
- package/dist/src/storage/sqlite/user-context-quality-repository.d.ts +0 -49
- package/dist/src/storage/sqlite/user-context-quality-repository.js +0 -118
- package/dist/src/storage/sqlite/user-context-repository.d.ts +0 -85
- package/dist/src/storage/sqlite/user-context-repository.js +0 -535
- package/dist/src/user-context/automatic-context.d.ts +0 -17
- package/dist/src/user-context/automatic-context.js +0 -85
- package/dist/src/user-context/consolidation.d.ts +0 -27
- package/dist/src/user-context/consolidation.js +0 -187
- package/dist/src/user-context/context-objects.d.ts +0 -17
- package/dist/src/user-context/context-objects.js +0 -99
- package/dist/src/user-context/evaluation/harness.d.ts +0 -13
- package/dist/src/user-context/evaluation/harness.js +0 -31
- package/dist/src/user-context/extraction/executor.d.ts +0 -22
- package/dist/src/user-context/extraction/executor.js +0 -142
- package/dist/src/user-context/extraction/repair.d.ts +0 -19
- package/dist/src/user-context/extraction/repair.js +0 -71
- package/dist/src/user-context/extraction/semantic.d.ts +0 -18
- package/dist/src/user-context/extraction/semantic.js +0 -148
- package/dist/src/user-context/focus-lifecycle.d.ts +0 -2
- package/dist/src/user-context/focus-lifecycle.js +0 -26
- package/dist/src/user-context/manual-understanding.d.ts +0 -12
- package/dist/src/user-context/manual-understanding.js +0 -37
- package/dist/src/user-context/planner.d.ts +0 -17
- package/dist/src/user-context/planner.js +0 -465
- package/dist/src/user-context/relationships/indexer.d.ts +0 -13
- package/dist/src/user-context/relationships/indexer.js +0 -185
- package/dist/src/user-context/relationships/service.d.ts +0 -22
- package/dist/src/user-context/relationships/service.js +0 -50
- package/dist/src/user-context/retriever.d.ts +0 -15
- package/dist/src/user-context/retriever.js +0 -124
- package/dist/src/user-context/scope.d.ts +0 -7
- package/dist/src/user-context/scope.js +0 -9
- package/dist/src/user-context/selection-policy.d.ts +0 -20
- package/dist/src/user-context/selection-policy.js +0 -33
- package/dist/src/user-context/understanding.d.ts +0 -15
- package/dist/src/user-context/understanding.js +0 -24
- package/dist/src/user-context/understandingQuality.d.ts +0 -5
- package/dist/src/user-context/understandingQuality.js +0 -48
- /package/dist/src/{agent/memory/context/types.js → knowledge-memory/domain.js} +0 -0
|
@@ -1,715 +0,0 @@
|
|
|
1
|
-
import { getSqliteDatabase, runSqliteWriteTransaction } from "./transaction.js";
|
|
2
|
-
import { buildFts5SearchQuery } from "./fts.js";
|
|
3
|
-
import { LOCAL_USER_ID } from "../../user-context/owner.js";
|
|
4
|
-
import { fuseRankedCandidates } from "../../retrieval/candidateFusion.js";
|
|
5
|
-
import { normalizeRetrievalText, retrievalLexicalSimilarity } from "../../retrieval/textFeatures.js";
|
|
6
|
-
import { buildRetrievalQueryProfile } from "../../retrieval/queryProfile.js";
|
|
7
|
-
import { listMemoryEvidence, listMemoryEvidenceForRecords, replaceMemoryEvidenceForRecord } from "./knowledge-repository.js";
|
|
8
|
-
import { randomUUID } from "node:crypto";
|
|
9
|
-
//#region src/storage/sqlite/memory-records-repository.ts
|
|
10
|
-
function memoryFeedbackAdjustment(summary) {
|
|
11
|
-
if (!summary || summary.total < 3) return 0;
|
|
12
|
-
const helpfulRate = (summary.helpful + 1) / (summary.total + 2);
|
|
13
|
-
const relevancePenalty = summary.irrelevant >= 3 ? .05 : 0;
|
|
14
|
-
return Math.max(-.1, Math.min(.05, (helpfulRate - .5) * .1 - relevancePenalty));
|
|
15
|
-
}
|
|
16
|
-
function parseStringArray(json) {
|
|
17
|
-
try {
|
|
18
|
-
const parsed = JSON.parse(json);
|
|
19
|
-
return Array.isArray(parsed) ? parsed.filter((v) => typeof v === "string") : [];
|
|
20
|
-
} catch {
|
|
21
|
-
return [];
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
function memoryFeedbackRowToPayload(row) {
|
|
25
|
-
return {
|
|
26
|
-
feedbackId: row.feedback_id,
|
|
27
|
-
traceId: row.trace_id,
|
|
28
|
-
turnId: row.turn_id,
|
|
29
|
-
level: row.level,
|
|
30
|
-
...row.record_id ? { recordId: row.record_id } : {},
|
|
31
|
-
rating: row.rating,
|
|
32
|
-
...row.score != null ? { score: row.score } : {},
|
|
33
|
-
...row.reason_code ? { reasonCode: row.reason_code } : {},
|
|
34
|
-
...row.note ? { note: row.note } : {},
|
|
35
|
-
source: row.source,
|
|
36
|
-
createdAt: new Date(row.created_at).toISOString(),
|
|
37
|
-
updatedAt: new Date(row.updated_at).toISOString()
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
function listFeedbackForTrace(traceId) {
|
|
41
|
-
return getSqliteDatabase().prepare(`SELECT * FROM memory_feedback WHERE trace_id = ? ORDER BY level, updated_at DESC`).all(traceId).map(memoryFeedbackRowToPayload);
|
|
42
|
-
}
|
|
43
|
-
function memoryTraceRowToPayload(row) {
|
|
44
|
-
return {
|
|
45
|
-
traceId: row.trace_id,
|
|
46
|
-
...row.session_key ? { sessionKey: row.session_key } : {},
|
|
47
|
-
...row.turn_id ? { turnId: row.turn_id } : {},
|
|
48
|
-
phase: row.phase,
|
|
49
|
-
providerId: row.provider_id,
|
|
50
|
-
request: parseJsonValue(row.request_json, {}),
|
|
51
|
-
...row.result_count != null ? { resultCount: row.result_count } : {},
|
|
52
|
-
selectedRecordIds: parseStringArray(row.selected_record_ids_json),
|
|
53
|
-
...row.skipped_reason ? { skippedReason: row.skipped_reason } : {},
|
|
54
|
-
...row.error ? { error: row.error } : {},
|
|
55
|
-
feedback: listFeedbackForTrace(row.trace_id),
|
|
56
|
-
durationMs: row.duration_ms,
|
|
57
|
-
createdAt: new Date(row.created_at).toISOString()
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
function parseOptionalTimestamp(value) {
|
|
61
|
-
if (!value?.trim()) return null;
|
|
62
|
-
const parsed = Date.parse(value);
|
|
63
|
-
return Number.isFinite(parsed) ? parsed : null;
|
|
64
|
-
}
|
|
65
|
-
function timestampToIso(value) {
|
|
66
|
-
return value == null ? void 0 : new Date(value).toISOString();
|
|
67
|
-
}
|
|
68
|
-
function parseSource(json) {
|
|
69
|
-
try {
|
|
70
|
-
const parsed = JSON.parse(json);
|
|
71
|
-
return parsed && typeof parsed === "object" ? parsed : {};
|
|
72
|
-
} catch {
|
|
73
|
-
return {};
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
function rowToRecord(row, evidence = []) {
|
|
77
|
-
return {
|
|
78
|
-
id: row.record_id,
|
|
79
|
-
providerId: row.provider_id,
|
|
80
|
-
kind: row.kind,
|
|
81
|
-
status: row.status,
|
|
82
|
-
...row.canonical_key ? { canonicalKey: row.canonical_key } : {},
|
|
83
|
-
scope: {
|
|
84
|
-
userId: row.user_id,
|
|
85
|
-
...row.workspace_id ? { workspaceId: row.workspace_id } : {},
|
|
86
|
-
...row.session_key ? { sessionKey: row.session_key } : {},
|
|
87
|
-
...row.project_id ? { projectId: row.project_id } : {}
|
|
88
|
-
},
|
|
89
|
-
provenance: {
|
|
90
|
-
sourceAgentId: row.source_agent_id,
|
|
91
|
-
originClass: row.origin_class,
|
|
92
|
-
sessionKind: row.session_kind,
|
|
93
|
-
observedAt: new Date(row.observed_at).toISOString(),
|
|
94
|
-
...row.source_session_id ? { sourceSessionId: row.source_session_id } : {},
|
|
95
|
-
...row.source_turn_id ? { sourceTurnId: row.source_turn_id } : {},
|
|
96
|
-
...row.supersedes_key ? { supersedesKey: row.supersedes_key } : {},
|
|
97
|
-
derivedFromRecalledContext: row.derived_from_recalled_context === 1
|
|
98
|
-
},
|
|
99
|
-
content: row.content,
|
|
100
|
-
source: parseSource(row.source_json),
|
|
101
|
-
...row.confidence != null ? { confidence: row.confidence } : {},
|
|
102
|
-
sensitivity: row.sensitivity,
|
|
103
|
-
explicitness: row.explicitness,
|
|
104
|
-
durability: row.durability,
|
|
105
|
-
importance: row.importance,
|
|
106
|
-
disclosurePolicy: row.disclosure_policy,
|
|
107
|
-
evidence,
|
|
108
|
-
...timestampToIso(row.valid_from) ? { validFrom: timestampToIso(row.valid_from) } : {},
|
|
109
|
-
...timestampToIso(row.valid_to) ? { validTo: timestampToIso(row.valid_to) } : {},
|
|
110
|
-
...timestampToIso(row.review_after) ? { reviewAfter: timestampToIso(row.review_after) } : {},
|
|
111
|
-
...timestampToIso(row.expires_at) ? { expiresAt: timestampToIso(row.expires_at) } : {},
|
|
112
|
-
...row.supersedes_record_id ? { supersedesRecordId: row.supersedes_record_id } : {},
|
|
113
|
-
...row.conflict_group_id ? { conflictGroupId: row.conflict_group_id } : {},
|
|
114
|
-
createdAt: new Date(row.created_at).toISOString(),
|
|
115
|
-
updatedAt: new Date(row.updated_at).toISOString(),
|
|
116
|
-
tags: parseStringArray(row.tags_json)
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
function rowsToRecords(rows) {
|
|
120
|
-
const evidenceByRecord = listMemoryEvidenceForRecords(rows.map((row) => row.record_id));
|
|
121
|
-
return rows.map((row) => rowToRecord(row, evidenceByRecord.get(row.record_id) ?? []));
|
|
122
|
-
}
|
|
123
|
-
function upsertMemoryRecordFts(db, row) {
|
|
124
|
-
db.prepare(`DELETE FROM memory_records_fts WHERE record_id = ?`).run(row.id);
|
|
125
|
-
if (!row.content.trim()) return;
|
|
126
|
-
db.prepare(`INSERT INTO memory_records_fts (
|
|
127
|
-
content, record_id, provider_id, kind, user_id, source_agent_id, workspace_id
|
|
128
|
-
) VALUES (?, ?, ?, ?, ?, ?, ?)`).run(row.content, row.id, row.providerId, row.kind, row.userId ?? "local-owner", row.sourceAgentId, row.workspaceId ?? null);
|
|
129
|
-
}
|
|
130
|
-
function upsertMemoryRecord(input) {
|
|
131
|
-
const id = input.id ?? randomUUID();
|
|
132
|
-
const now = input.nowMs ?? Date.now();
|
|
133
|
-
const status = input.status ?? "active";
|
|
134
|
-
const sensitivity = input.sensitivity ?? "normal";
|
|
135
|
-
const explicitness = input.explicitness ?? "inferred";
|
|
136
|
-
const durability = input.durability ?? "durable";
|
|
137
|
-
const importance = Math.max(0, Math.min(1, input.importance ?? .5));
|
|
138
|
-
const disclosurePolicy = input.disclosurePolicy ?? "referenceable";
|
|
139
|
-
const validFrom = parseOptionalTimestamp(input.validFrom);
|
|
140
|
-
const validTo = parseOptionalTimestamp(input.validTo);
|
|
141
|
-
const reviewAfter = parseOptionalTimestamp(input.reviewAfter);
|
|
142
|
-
const expiresAt = parseOptionalTimestamp(input.expiresAt);
|
|
143
|
-
const observedAt = parseOptionalTimestamp(input.observedAt) ?? now;
|
|
144
|
-
const originClass = input.originClass ?? "untrusted";
|
|
145
|
-
const sessionKind = input.sessionKind ?? "unknown";
|
|
146
|
-
const source = {
|
|
147
|
-
...input.source ?? {},
|
|
148
|
-
provider: input.source?.provider ?? input.providerId
|
|
149
|
-
};
|
|
150
|
-
runSqliteWriteTransaction((db) => {
|
|
151
|
-
db.prepare(`INSERT INTO memory_records (
|
|
152
|
-
record_id, provider_id, kind, user_id, source_agent_id, workspace_id, session_key, project_id,
|
|
153
|
-
content, source_json, confidence, tags_json, status, sensitivity,
|
|
154
|
-
canonical_key, explicitness, durability, importance,
|
|
155
|
-
disclosure_policy, valid_from, valid_to, review_after, expires_at,
|
|
156
|
-
supersedes_record_id, conflict_group_id,
|
|
157
|
-
origin_class, session_kind, observed_at, source_session_id, source_turn_id,
|
|
158
|
-
supersedes_key, derived_from_recalled_context, created_at, updated_at
|
|
159
|
-
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
160
|
-
ON CONFLICT(record_id) DO UPDATE SET
|
|
161
|
-
provider_id = excluded.provider_id,
|
|
162
|
-
kind = excluded.kind,
|
|
163
|
-
user_id = excluded.user_id,
|
|
164
|
-
source_agent_id = excluded.source_agent_id,
|
|
165
|
-
workspace_id = excluded.workspace_id,
|
|
166
|
-
session_key = excluded.session_key,
|
|
167
|
-
project_id = excluded.project_id,
|
|
168
|
-
content = excluded.content,
|
|
169
|
-
source_json = excluded.source_json,
|
|
170
|
-
confidence = excluded.confidence,
|
|
171
|
-
tags_json = excluded.tags_json,
|
|
172
|
-
status = excluded.status,
|
|
173
|
-
sensitivity = excluded.sensitivity,
|
|
174
|
-
canonical_key = excluded.canonical_key,
|
|
175
|
-
explicitness = excluded.explicitness,
|
|
176
|
-
durability = excluded.durability,
|
|
177
|
-
importance = excluded.importance,
|
|
178
|
-
disclosure_policy = excluded.disclosure_policy,
|
|
179
|
-
valid_from = excluded.valid_from,
|
|
180
|
-
valid_to = excluded.valid_to,
|
|
181
|
-
review_after = excluded.review_after,
|
|
182
|
-
expires_at = excluded.expires_at,
|
|
183
|
-
supersedes_record_id = excluded.supersedes_record_id,
|
|
184
|
-
conflict_group_id = excluded.conflict_group_id,
|
|
185
|
-
origin_class = excluded.origin_class,
|
|
186
|
-
session_kind = excluded.session_kind,
|
|
187
|
-
observed_at = excluded.observed_at,
|
|
188
|
-
source_session_id = excluded.source_session_id,
|
|
189
|
-
source_turn_id = excluded.source_turn_id,
|
|
190
|
-
supersedes_key = excluded.supersedes_key,
|
|
191
|
-
derived_from_recalled_context = excluded.derived_from_recalled_context,
|
|
192
|
-
updated_at = excluded.updated_at`).run(id, input.providerId, input.kind, input.userId ?? "local-owner", input.sourceAgentId, input.workspaceId ?? null, input.sessionKey ?? null, input.projectId ?? null, input.content, JSON.stringify(source), input.confidence ?? null, JSON.stringify(input.tags ?? []), status, sensitivity, input.canonicalKey ?? null, explicitness, durability, importance, disclosurePolicy, validFrom, validTo, reviewAfter, expiresAt, input.supersedesRecordId ?? null, input.conflictGroupId ?? null, originClass, sessionKind, observedAt, input.sourceSessionId ?? null, input.sourceTurnId ?? null, input.supersedesKey ?? null, input.derivedFromRecalledContext ? 1 : 0, now, now);
|
|
193
|
-
upsertMemoryRecordFts(db, {
|
|
194
|
-
...input,
|
|
195
|
-
id
|
|
196
|
-
});
|
|
197
|
-
if (input.evidence) replaceMemoryEvidenceForRecord(db, id, input.evidence, now);
|
|
198
|
-
if (input.supersedesRecordId && input.supersedesRecordId !== id) {
|
|
199
|
-
if (db.prepare(`SELECT 1 FROM memory_records WHERE record_id = ?`).get(input.supersedesRecordId)) {
|
|
200
|
-
db.prepare(`INSERT INTO memory_relations (
|
|
201
|
-
relation_id, from_record_id, relation_type, to_record_id,
|
|
202
|
-
confidence, valid_from, valid_to, created_at, updated_at
|
|
203
|
-
) VALUES (?, ?, 'supersedes', ?, ?, ?, NULL, ?, ?)
|
|
204
|
-
ON CONFLICT(from_record_id, relation_type, to_record_id) DO UPDATE SET
|
|
205
|
-
confidence = excluded.confidence,
|
|
206
|
-
valid_from = excluded.valid_from,
|
|
207
|
-
valid_to = NULL,
|
|
208
|
-
updated_at = excluded.updated_at`).run(randomUUID(), id, input.supersedesRecordId, input.confidence ?? 1, validFrom ?? now, now, now);
|
|
209
|
-
if (status === "active") db.prepare(`UPDATE memory_records
|
|
210
|
-
SET status = 'archived', valid_to = COALESCE(valid_to, ?), updated_at = ?
|
|
211
|
-
WHERE record_id = ? AND status IN ('active', 'needs_review', 'stale')`).run(now, now, input.supersedesRecordId);
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
});
|
|
215
|
-
const storedEvidence = input.evidence ?? listMemoryEvidence(id);
|
|
216
|
-
return {
|
|
217
|
-
id,
|
|
218
|
-
providerId: input.providerId,
|
|
219
|
-
kind: input.kind,
|
|
220
|
-
status,
|
|
221
|
-
...input.canonicalKey ? { canonicalKey: input.canonicalKey } : {},
|
|
222
|
-
scope: {
|
|
223
|
-
userId: input.userId ?? "local-owner",
|
|
224
|
-
...input.workspaceId ? { workspaceId: input.workspaceId } : {},
|
|
225
|
-
...input.sessionKey ? { sessionKey: input.sessionKey } : {},
|
|
226
|
-
...input.projectId ? { projectId: input.projectId } : {}
|
|
227
|
-
},
|
|
228
|
-
provenance: {
|
|
229
|
-
sourceAgentId: input.sourceAgentId,
|
|
230
|
-
originClass,
|
|
231
|
-
sessionKind,
|
|
232
|
-
observedAt: new Date(observedAt).toISOString(),
|
|
233
|
-
...input.sourceSessionId ? { sourceSessionId: input.sourceSessionId } : {},
|
|
234
|
-
...input.sourceTurnId ? { sourceTurnId: input.sourceTurnId } : {},
|
|
235
|
-
...input.supersedesKey ? { supersedesKey: input.supersedesKey } : {},
|
|
236
|
-
derivedFromRecalledContext: input.derivedFromRecalledContext ?? false
|
|
237
|
-
},
|
|
238
|
-
content: input.content,
|
|
239
|
-
source,
|
|
240
|
-
...input.confidence != null ? { confidence: input.confidence } : {},
|
|
241
|
-
sensitivity,
|
|
242
|
-
explicitness,
|
|
243
|
-
durability,
|
|
244
|
-
importance,
|
|
245
|
-
disclosurePolicy,
|
|
246
|
-
evidence: storedEvidence,
|
|
247
|
-
...validFrom != null ? { validFrom: new Date(validFrom).toISOString() } : {},
|
|
248
|
-
...validTo != null ? { validTo: new Date(validTo).toISOString() } : {},
|
|
249
|
-
...reviewAfter != null ? { reviewAfter: new Date(reviewAfter).toISOString() } : {},
|
|
250
|
-
...expiresAt != null ? { expiresAt: new Date(expiresAt).toISOString() } : {},
|
|
251
|
-
...input.supersedesRecordId ? { supersedesRecordId: input.supersedesRecordId } : {},
|
|
252
|
-
...input.conflictGroupId ? { conflictGroupId: input.conflictGroupId } : {},
|
|
253
|
-
createdAt: new Date(now).toISOString(),
|
|
254
|
-
updatedAt: new Date(now).toISOString(),
|
|
255
|
-
tags: input.tags ?? []
|
|
256
|
-
};
|
|
257
|
-
}
|
|
258
|
-
function getMemoryRecord(recordId) {
|
|
259
|
-
const row = getSqliteDatabase().prepare(`SELECT * FROM memory_records WHERE record_id = ?`).get(recordId);
|
|
260
|
-
return row ? rowToRecord(row, listMemoryEvidence(recordId)) : null;
|
|
261
|
-
}
|
|
262
|
-
function hasUnresolvedMemoryConflict(conflictGroupId) {
|
|
263
|
-
if (!conflictGroupId.trim()) return false;
|
|
264
|
-
const row = getSqliteDatabase().prepare(`
|
|
265
|
-
SELECT COUNT(*) AS count
|
|
266
|
-
FROM memory_records
|
|
267
|
-
WHERE conflict_group_id = ?
|
|
268
|
-
AND status IN ('active', 'candidate', 'needs_review', 'stale')
|
|
269
|
-
`).get(conflictGroupId);
|
|
270
|
-
return Number(row.count) > 1;
|
|
271
|
-
}
|
|
272
|
-
function listMemoryRecords(options = {}) {
|
|
273
|
-
const where = [];
|
|
274
|
-
const params = [];
|
|
275
|
-
if (options.providerId) {
|
|
276
|
-
where.push("provider_id = ?");
|
|
277
|
-
params.push(options.providerId);
|
|
278
|
-
}
|
|
279
|
-
if (options.userId) {
|
|
280
|
-
where.push("user_id = ?");
|
|
281
|
-
params.push(options.userId);
|
|
282
|
-
}
|
|
283
|
-
if (options.sourceAgentId) {
|
|
284
|
-
where.push("source_agent_id = ?");
|
|
285
|
-
params.push(options.sourceAgentId);
|
|
286
|
-
}
|
|
287
|
-
if (options.workspaceId) {
|
|
288
|
-
where.push("workspace_id = ?");
|
|
289
|
-
params.push(options.workspaceId);
|
|
290
|
-
}
|
|
291
|
-
if (options.visibleToWorkspaceId) {
|
|
292
|
-
where.push("(workspace_id IS NULL OR workspace_id = ?)");
|
|
293
|
-
params.push(options.visibleToWorkspaceId);
|
|
294
|
-
} else if (options.unscopedWorkspaceOnly) where.push("workspace_id IS NULL");
|
|
295
|
-
if (options.projectId) {
|
|
296
|
-
where.push("project_id = ?");
|
|
297
|
-
params.push(options.projectId);
|
|
298
|
-
}
|
|
299
|
-
if (options.visibleToSessionKey) {
|
|
300
|
-
where.push("(session_key IS NULL OR session_key = ?)");
|
|
301
|
-
params.push(options.visibleToSessionKey);
|
|
302
|
-
} else if (options.unscopedSessionOnly) where.push("session_key IS NULL");
|
|
303
|
-
if (options.visibleToProjectId) {
|
|
304
|
-
where.push("(project_id IS NULL OR project_id = ?)");
|
|
305
|
-
params.push(options.visibleToProjectId);
|
|
306
|
-
} else if (options.unscopedProjectOnly) where.push("project_id IS NULL");
|
|
307
|
-
if (options.kind) {
|
|
308
|
-
where.push("kind = ?");
|
|
309
|
-
params.push(options.kind);
|
|
310
|
-
}
|
|
311
|
-
if (options.status) {
|
|
312
|
-
where.push("status = ?");
|
|
313
|
-
params.push(options.status);
|
|
314
|
-
}
|
|
315
|
-
if (options.canonicalKey) {
|
|
316
|
-
where.push("canonical_key = ?");
|
|
317
|
-
params.push(options.canonicalKey);
|
|
318
|
-
}
|
|
319
|
-
const limit = Math.max(1, Math.min(500, options.limit ?? 100));
|
|
320
|
-
const offset = Math.max(0, options.offset ?? 0);
|
|
321
|
-
return rowsToRecords(getSqliteDatabase().prepare(`SELECT * FROM memory_records
|
|
322
|
-
${where.length > 0 ? `WHERE ${where.join(" AND ")}` : ""}
|
|
323
|
-
ORDER BY updated_at DESC
|
|
324
|
-
LIMIT ? OFFSET ?`).all(...params, limit, offset));
|
|
325
|
-
}
|
|
326
|
-
function searchMemoryRecords(options) {
|
|
327
|
-
const profile = buildRetrievalQueryProfile(options.query, {
|
|
328
|
-
...options.visibleToSessionKey ? { sessionKey: options.visibleToSessionKey } : {},
|
|
329
|
-
...options.visibleToWorkspaceId ?? options.workspaceId ? { workspaceId: options.visibleToWorkspaceId ?? options.workspaceId } : {},
|
|
330
|
-
...options.visibleToProjectId ?? options.projectId ? { projectId: options.visibleToProjectId ?? options.projectId } : {}
|
|
331
|
-
});
|
|
332
|
-
const query = buildFts5SearchQuery(profile.normalized);
|
|
333
|
-
if (!query) return [];
|
|
334
|
-
const filters = ["memory_records_fts MATCH ?"];
|
|
335
|
-
const params = [query];
|
|
336
|
-
if (options.userId) {
|
|
337
|
-
filters.push("f.user_id = ?");
|
|
338
|
-
params.push(options.userId);
|
|
339
|
-
}
|
|
340
|
-
if (options.sourceAgentId) {
|
|
341
|
-
filters.push("f.source_agent_id = ?");
|
|
342
|
-
params.push(options.sourceAgentId);
|
|
343
|
-
}
|
|
344
|
-
if (options.workspaceId) {
|
|
345
|
-
filters.push("f.workspace_id = ?");
|
|
346
|
-
params.push(options.workspaceId);
|
|
347
|
-
}
|
|
348
|
-
if (options.visibleToWorkspaceId) {
|
|
349
|
-
filters.push("(r.workspace_id IS NULL OR r.workspace_id = ?)");
|
|
350
|
-
params.push(options.visibleToWorkspaceId);
|
|
351
|
-
} else if (options.unscopedWorkspaceOnly) filters.push("r.workspace_id IS NULL");
|
|
352
|
-
if (options.projectId) {
|
|
353
|
-
filters.push("r.project_id = ?");
|
|
354
|
-
params.push(options.projectId);
|
|
355
|
-
}
|
|
356
|
-
if (options.visibleToSessionKey) {
|
|
357
|
-
filters.push("(r.session_key IS NULL OR r.session_key = ?)");
|
|
358
|
-
params.push(options.visibleToSessionKey);
|
|
359
|
-
} else if (options.unscopedSessionOnly) filters.push("r.session_key IS NULL");
|
|
360
|
-
if (options.visibleToProjectId) {
|
|
361
|
-
filters.push("(r.project_id IS NULL OR r.project_id = ?)");
|
|
362
|
-
params.push(options.visibleToProjectId);
|
|
363
|
-
} else if (options.unscopedProjectOnly) filters.push("r.project_id IS NULL");
|
|
364
|
-
if (options.providerId) {
|
|
365
|
-
filters.push("f.provider_id = ?");
|
|
366
|
-
params.push(options.providerId);
|
|
367
|
-
}
|
|
368
|
-
if (options.kinds && options.kinds.length > 0) {
|
|
369
|
-
filters.push(`f.kind IN (${options.kinds.map(() => "?").join(", ")})`);
|
|
370
|
-
params.push(...options.kinds);
|
|
371
|
-
}
|
|
372
|
-
if (options.trustedOnly) {
|
|
373
|
-
filters.push(`r.origin_class IN ('owner', 'agent')`);
|
|
374
|
-
filters.push("r.derived_from_recalled_context = 0");
|
|
375
|
-
}
|
|
376
|
-
const statuses = options.statuses && options.statuses.length > 0 ? options.statuses : ["active"];
|
|
377
|
-
filters.push(`r.status IN (${statuses.map(() => "?").join(", ")})`);
|
|
378
|
-
params.push(...statuses);
|
|
379
|
-
const maxResults = Math.max(1, Math.min(50, options.maxResults ?? 5));
|
|
380
|
-
const minScore = options.minScore ?? 0;
|
|
381
|
-
const candidateLimit = Math.max(50, Math.min(200, maxResults * 10));
|
|
382
|
-
const rows = getSqliteDatabase().prepare(`SELECT
|
|
383
|
-
r.*,
|
|
384
|
-
bm25(memory_records_fts) AS rank
|
|
385
|
-
FROM memory_records_fts f
|
|
386
|
-
JOIN memory_records r ON r.record_id = f.record_id
|
|
387
|
-
WHERE ${filters.join(" AND ")}
|
|
388
|
-
ORDER BY rank
|
|
389
|
-
LIMIT ?`).all(...params, candidateLimit);
|
|
390
|
-
const candidateRecords = listMemoryRecords({
|
|
391
|
-
providerId: options.providerId,
|
|
392
|
-
userId: options.userId,
|
|
393
|
-
sourceAgentId: options.sourceAgentId,
|
|
394
|
-
workspaceId: options.workspaceId,
|
|
395
|
-
projectId: options.projectId,
|
|
396
|
-
visibleToSessionKey: options.visibleToSessionKey,
|
|
397
|
-
unscopedSessionOnly: options.unscopedSessionOnly,
|
|
398
|
-
visibleToProjectId: options.visibleToProjectId,
|
|
399
|
-
unscopedProjectOnly: options.unscopedProjectOnly,
|
|
400
|
-
visibleToWorkspaceId: options.visibleToWorkspaceId,
|
|
401
|
-
unscopedWorkspaceOnly: options.unscopedWorkspaceOnly,
|
|
402
|
-
limit: 500
|
|
403
|
-
}).filter((record) => statuses.includes(record.status ?? "active") && (!options.kinds?.length || options.kinds.includes(record.kind))).filter((record) => !options.trustedOnly || (record.provenance.originClass === "owner" || record.provenance.originClass === "agent") && !record.provenance.derivedFromRecalledContext);
|
|
404
|
-
const candidateById = new Map(candidateRecords.map((record) => [record.id, record]));
|
|
405
|
-
const missingRows = rows.filter((row) => !candidateById.has(row.record_id));
|
|
406
|
-
const missingEvidence = listMemoryEvidenceForRecords(missingRows.map((row) => row.record_id));
|
|
407
|
-
const recordById = new Map(candidateRecords.map((record) => [record.id, record]));
|
|
408
|
-
for (const row of missingRows) recordById.set(row.record_id, rowToRecord(row, missingEvidence.get(row.record_id) ?? []));
|
|
409
|
-
const lexical = candidateRecords.map((record) => ({
|
|
410
|
-
id: record.id,
|
|
411
|
-
score: retrievalLexicalSimilarity(profile.normalized, record.content)
|
|
412
|
-
})).filter((result) => result.score > 0).sort((left, right) => right.score - left.score).slice(0, candidateLimit);
|
|
413
|
-
const fused = fuseRankedCandidates([
|
|
414
|
-
{
|
|
415
|
-
weight: 1.4,
|
|
416
|
-
ids: (profile.identifiers.length ? candidateRecords.map((record) => {
|
|
417
|
-
const content = normalizeRetrievalText(record.content);
|
|
418
|
-
return {
|
|
419
|
-
id: record.id,
|
|
420
|
-
matches: profile.identifiers.filter((identifier) => content.includes(identifier)).length
|
|
421
|
-
};
|
|
422
|
-
}).filter((result) => result.matches > 0).sort((left, right) => right.matches - left.matches).slice(0, candidateLimit) : []).map((result) => result.id)
|
|
423
|
-
},
|
|
424
|
-
{
|
|
425
|
-
weight: 1,
|
|
426
|
-
ids: rows.map((row) => row.record_id)
|
|
427
|
-
},
|
|
428
|
-
{
|
|
429
|
-
weight: .8,
|
|
430
|
-
ids: lexical.map((result) => result.id)
|
|
431
|
-
}
|
|
432
|
-
]);
|
|
433
|
-
const feedback = new Map(summarizeMemoryRecallFeedback({ limit: 1e3 }).map((summary) => [summary.recordId, summary]));
|
|
434
|
-
return [...fused.entries()].map(([id, fusionScore]) => {
|
|
435
|
-
const record = recordById.get(id);
|
|
436
|
-
if (!record) return null;
|
|
437
|
-
const kindBonus = profile.intentKinds.includes(record.kind) ? .08 : 0;
|
|
438
|
-
const authorityBonus = record.explicitness === "explicit" ? .03 : 0;
|
|
439
|
-
return {
|
|
440
|
-
record,
|
|
441
|
-
score: Math.max(0, Math.min(1, fusionScore * .85 + kindBonus + authorityBonus + record.importance * .04 + memoryFeedbackAdjustment(feedback.get(record.id)))),
|
|
442
|
-
snippet: record.content,
|
|
443
|
-
citation: {
|
|
444
|
-
providerId: record.providerId,
|
|
445
|
-
recordId: record.id,
|
|
446
|
-
path: record.source.path,
|
|
447
|
-
lineStart: record.source.lineStart,
|
|
448
|
-
lineEnd: record.source.lineEnd,
|
|
449
|
-
createdAt: record.createdAt
|
|
450
|
-
}
|
|
451
|
-
};
|
|
452
|
-
}).filter((result) => Boolean(result)).filter((result) => result.score >= minScore).sort((left, right) => right.score - left.score).slice(0, maxResults);
|
|
453
|
-
}
|
|
454
|
-
function deleteMemoryRecord(recordId) {
|
|
455
|
-
return runSqliteWriteTransaction((db) => {
|
|
456
|
-
db.prepare(`DELETE FROM memory_records_fts WHERE record_id = ?`).run(recordId);
|
|
457
|
-
return db.prepare(`DELETE FROM memory_records WHERE record_id = ?`).run(recordId).changes > 0;
|
|
458
|
-
});
|
|
459
|
-
}
|
|
460
|
-
function countMemoryRecordsBySourceInstanceId(sourceInstanceId) {
|
|
461
|
-
const row = getSqliteDatabase().prepare(`SELECT COUNT(*) AS count FROM memory_records
|
|
462
|
-
WHERE json_extract(source_json, '$.sourceInstanceId') = ?`).get(sourceInstanceId);
|
|
463
|
-
return Number(row.count);
|
|
464
|
-
}
|
|
465
|
-
function deleteMemoryRecordsBySourceInstanceId(sourceInstanceId) {
|
|
466
|
-
return runSqliteWriteTransaction((db) => {
|
|
467
|
-
const recordIds = db.prepare(`SELECT record_id FROM memory_records
|
|
468
|
-
WHERE json_extract(source_json, '$.sourceInstanceId') = ?`).all(sourceInstanceId).map((row) => row.record_id);
|
|
469
|
-
if (!recordIds.length) return 0;
|
|
470
|
-
const removeFts = db.prepare("DELETE FROM memory_records_fts WHERE record_id = ?");
|
|
471
|
-
const removeRecord = db.prepare("DELETE FROM memory_records WHERE record_id = ?");
|
|
472
|
-
let deleted = 0;
|
|
473
|
-
for (const recordId of recordIds) {
|
|
474
|
-
removeFts.run(recordId);
|
|
475
|
-
deleted += Number(removeRecord.run(recordId).changes);
|
|
476
|
-
}
|
|
477
|
-
return deleted;
|
|
478
|
-
});
|
|
479
|
-
}
|
|
480
|
-
/** Change lifecycle status without reconstructing or weakening the record's provenance. */
|
|
481
|
-
function setMemoryRecordStatus(recordId, status, nowMs = Date.now()) {
|
|
482
|
-
return runSqliteWriteTransaction((db) => {
|
|
483
|
-
return db.prepare(`UPDATE memory_records SET status = ?, updated_at = ? WHERE record_id = ?`).run(status, nowMs, recordId).changes > 0;
|
|
484
|
-
});
|
|
485
|
-
}
|
|
486
|
-
function markMemoryRecordsConflicted(recordIds, conflictGroupId) {
|
|
487
|
-
const ids = [...new Set(recordIds.filter(Boolean))];
|
|
488
|
-
if (!ids.length || !conflictGroupId.trim()) return 0;
|
|
489
|
-
return runSqliteWriteTransaction((db) => {
|
|
490
|
-
const now = Date.now();
|
|
491
|
-
const update = db.prepare(`
|
|
492
|
-
UPDATE memory_records
|
|
493
|
-
SET conflict_group_id = ?, status = 'needs_review', review_after = ?, updated_at = ?
|
|
494
|
-
WHERE record_id = ? AND status IN ('active', 'candidate', 'needs_review', 'stale')
|
|
495
|
-
`);
|
|
496
|
-
let changed = 0;
|
|
497
|
-
for (const id of ids) changed += Number(update.run(conflictGroupId, now, now, id).changes);
|
|
498
|
-
return changed;
|
|
499
|
-
});
|
|
500
|
-
}
|
|
501
|
-
function appendMemorySignal(input) {
|
|
502
|
-
const id = randomUUID();
|
|
503
|
-
const now = input.nowMs ?? Date.now();
|
|
504
|
-
runSqliteWriteTransaction((db) => {
|
|
505
|
-
db.prepare(`INSERT INTO memory_signals (
|
|
506
|
-
signal_id, source, record_id, provider_id, user_id, source_agent_id, workspace_id,
|
|
507
|
-
session_key, score, content, metadata_json, created_at
|
|
508
|
-
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`).run(id, input.signal.source, input.signal.recordId ?? null, input.providerId ?? null, input.userId ?? "local-owner", input.sourceAgentId ?? null, input.workspaceId ?? null, input.sessionKey ?? null, input.signal.score ?? null, input.signal.content ?? null, JSON.stringify(input.signal.metadata ?? {}), now);
|
|
509
|
-
if (input.signal.recordId) db.prepare(`UPDATE memory_records
|
|
510
|
-
SET recall_count = recall_count + 1, last_recalled_at = ?, updated_at = MAX(updated_at, ?)
|
|
511
|
-
WHERE record_id = ?`).run(now, now, input.signal.recordId);
|
|
512
|
-
});
|
|
513
|
-
return id;
|
|
514
|
-
}
|
|
515
|
-
function listMemorySignals(options = {}) {
|
|
516
|
-
const where = [];
|
|
517
|
-
const params = [];
|
|
518
|
-
if (options.recordId) {
|
|
519
|
-
where.push("record_id = ?");
|
|
520
|
-
params.push(options.recordId);
|
|
521
|
-
}
|
|
522
|
-
if (options.providerId) {
|
|
523
|
-
where.push("provider_id = ?");
|
|
524
|
-
params.push(options.providerId);
|
|
525
|
-
}
|
|
526
|
-
if (options.userId) {
|
|
527
|
-
where.push("user_id = ?");
|
|
528
|
-
params.push(options.userId);
|
|
529
|
-
}
|
|
530
|
-
if (options.sourceAgentId) {
|
|
531
|
-
where.push("source_agent_id = ?");
|
|
532
|
-
params.push(options.sourceAgentId);
|
|
533
|
-
}
|
|
534
|
-
if (options.workspaceId) {
|
|
535
|
-
where.push("workspace_id = ?");
|
|
536
|
-
params.push(options.workspaceId);
|
|
537
|
-
}
|
|
538
|
-
const limit = Math.max(1, Math.min(500, options.limit ?? 100));
|
|
539
|
-
return getSqliteDatabase().prepare(`SELECT * FROM memory_signals
|
|
540
|
-
${where.length > 0 ? `WHERE ${where.join(" AND ")}` : ""}
|
|
541
|
-
ORDER BY created_at DESC
|
|
542
|
-
LIMIT ?`).all(...params, limit).map((row) => {
|
|
543
|
-
let metadata = {};
|
|
544
|
-
try {
|
|
545
|
-
const parsed = JSON.parse(row.metadata_json);
|
|
546
|
-
if (parsed && typeof parsed === "object") metadata = parsed;
|
|
547
|
-
} catch {
|
|
548
|
-
metadata = {};
|
|
549
|
-
}
|
|
550
|
-
return {
|
|
551
|
-
signalId: row.signal_id,
|
|
552
|
-
source: row.source,
|
|
553
|
-
...row.record_id ? { recordId: row.record_id } : {},
|
|
554
|
-
...row.provider_id ? { providerId: row.provider_id } : {},
|
|
555
|
-
userId: row.user_id,
|
|
556
|
-
...row.source_agent_id ? { sourceAgentId: row.source_agent_id } : {},
|
|
557
|
-
...row.workspace_id ? { workspaceId: row.workspace_id } : {},
|
|
558
|
-
...row.session_key ? { sessionKey: row.session_key } : {},
|
|
559
|
-
...row.score != null ? { score: row.score } : {},
|
|
560
|
-
...row.content ? { content: row.content } : {},
|
|
561
|
-
metadata,
|
|
562
|
-
createdAt: new Date(row.created_at).toISOString()
|
|
563
|
-
};
|
|
564
|
-
});
|
|
565
|
-
}
|
|
566
|
-
function getMemoryProviderState(providerId, scopeKey) {
|
|
567
|
-
const row = getSqliteDatabase().prepare(`SELECT state_json FROM memory_provider_state WHERE provider_id = ? AND scope_key = ?`).get(providerId, scopeKey);
|
|
568
|
-
if (!row) return null;
|
|
569
|
-
try {
|
|
570
|
-
return JSON.parse(row.state_json);
|
|
571
|
-
} catch {
|
|
572
|
-
return null;
|
|
573
|
-
}
|
|
574
|
-
}
|
|
575
|
-
function setMemoryProviderState(providerId, scopeKey, state) {
|
|
576
|
-
const now = Date.now();
|
|
577
|
-
runSqliteWriteTransaction((db) => {
|
|
578
|
-
db.prepare(`INSERT INTO memory_provider_state (provider_id, scope_key, state_json, updated_at)
|
|
579
|
-
VALUES (?, ?, ?, ?)
|
|
580
|
-
ON CONFLICT(provider_id, scope_key) DO UPDATE SET
|
|
581
|
-
state_json = excluded.state_json,
|
|
582
|
-
updated_at = excluded.updated_at`).run(providerId, scopeKey, JSON.stringify(state ?? null), now);
|
|
583
|
-
});
|
|
584
|
-
}
|
|
585
|
-
function appendMemoryTraceEvent(input) {
|
|
586
|
-
const id = input.traceId ?? randomUUID();
|
|
587
|
-
const now = input.nowMs ?? Date.now();
|
|
588
|
-
runSqliteWriteTransaction((db) => {
|
|
589
|
-
db.prepare(`INSERT INTO memory_trace_events (
|
|
590
|
-
trace_id, session_key, turn_id, phase, provider_id, request_json,
|
|
591
|
-
result_count, selected_record_ids_json, skipped_reason, error, duration_ms, created_at,
|
|
592
|
-
user_id, source_agent_id
|
|
593
|
-
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`).run(id, input.sessionKey ?? null, input.turnId ?? null, input.phase, input.providerId, JSON.stringify(input.request ?? {}), input.resultCount ?? null, JSON.stringify(input.selectedRecordIds ?? []), input.skippedReason ?? null, input.error ?? null, Math.max(0, Math.floor(input.durationMs ?? 0)), now, LOCAL_USER_ID, input.sourceAgentId ?? null);
|
|
594
|
-
});
|
|
595
|
-
return id;
|
|
596
|
-
}
|
|
597
|
-
function listMemoryTraceEvents(options = {}) {
|
|
598
|
-
const where = [];
|
|
599
|
-
const params = [];
|
|
600
|
-
if (options.providerId) {
|
|
601
|
-
where.push("provider_id = ?");
|
|
602
|
-
params.push(options.providerId);
|
|
603
|
-
}
|
|
604
|
-
where.push("user_id = ?");
|
|
605
|
-
params.push(options.userId ?? "local-owner");
|
|
606
|
-
if (options.sourceAgentId) {
|
|
607
|
-
where.push("source_agent_id = ?");
|
|
608
|
-
params.push(options.sourceAgentId);
|
|
609
|
-
}
|
|
610
|
-
if (options.sessionKey) {
|
|
611
|
-
where.push("session_key = ?");
|
|
612
|
-
params.push(options.sessionKey);
|
|
613
|
-
}
|
|
614
|
-
if (options.phase) {
|
|
615
|
-
where.push("phase = ?");
|
|
616
|
-
params.push(options.phase);
|
|
617
|
-
}
|
|
618
|
-
const limit = Math.max(1, Math.min(500, options.limit ?? 100));
|
|
619
|
-
return getSqliteDatabase().prepare(`SELECT * FROM memory_trace_events
|
|
620
|
-
${where.length > 0 ? `WHERE ${where.join(" AND ")}` : ""}
|
|
621
|
-
ORDER BY created_at DESC
|
|
622
|
-
LIMIT ?`).all(...params, limit).map(memoryTraceRowToPayload);
|
|
623
|
-
}
|
|
624
|
-
function setMemoryTurnFeedback(input) {
|
|
625
|
-
const turnId = input.turnId.trim();
|
|
626
|
-
if (!turnId) return null;
|
|
627
|
-
const trace = getSqliteDatabase().prepare(`SELECT * FROM memory_trace_events WHERE turn_id = ? AND phase = 'inject'`).get(turnId);
|
|
628
|
-
if (!trace) return null;
|
|
629
|
-
const nowMs = input.nowMs ?? Date.now();
|
|
630
|
-
const source = input.source ?? "user";
|
|
631
|
-
const selected = new Set(parseStringArray(trace.selected_record_ids_json));
|
|
632
|
-
const records = (input.records ?? []).filter((item) => selected.has(item.recordId));
|
|
633
|
-
runSqliteWriteTransaction((db) => {
|
|
634
|
-
const upsert = db.prepare(`INSERT INTO memory_feedback (
|
|
635
|
-
feedback_id, trace_id, turn_id, record_id, level, rating, score,
|
|
636
|
-
reason_code, note, source, created_at, updated_at
|
|
637
|
-
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
638
|
-
ON CONFLICT DO UPDATE SET rating = excluded.rating, score = excluded.score,
|
|
639
|
-
reason_code = excluded.reason_code, note = excluded.note, updated_at = excluded.updated_at`);
|
|
640
|
-
upsert.run(randomUUID(), trace.trace_id, turnId, null, "response", input.rating, typeof input.score === "number" ? Math.max(-1, Math.min(1, input.score)) : null, input.reasonCode?.trim().slice(0, 200) || null, input.note?.trim().slice(0, 2e3) || null, source, nowMs, nowMs);
|
|
641
|
-
for (const item of records) {
|
|
642
|
-
upsert.run(randomUUID(), trace.trace_id, turnId, item.recordId, "record", item.rating, null, item.reasonCode?.trim().slice(0, 200) || null, item.note?.trim().slice(0, 2e3) || null, source, nowMs, nowMs);
|
|
643
|
-
if (item.rating === "incorrect" || item.rating === "sensitive") db.prepare("UPDATE memory_records SET status = 'needs_review', updated_at = ? WHERE record_id = ?").run(nowMs, item.recordId);
|
|
644
|
-
else if (item.rating === "outdated") db.prepare("UPDATE memory_records SET status = 'stale', updated_at = ? WHERE record_id = ?").run(nowMs, item.recordId);
|
|
645
|
-
}
|
|
646
|
-
});
|
|
647
|
-
return memoryTraceRowToPayload(trace);
|
|
648
|
-
}
|
|
649
|
-
function getMemoryTurnFeedback(turnId) {
|
|
650
|
-
const normalized = turnId.trim();
|
|
651
|
-
if (!normalized) return null;
|
|
652
|
-
const trace = getSqliteDatabase().prepare(`SELECT * FROM memory_trace_events WHERE turn_id = ? AND phase = 'inject'`).get(normalized);
|
|
653
|
-
return trace ? memoryTraceRowToPayload(trace) : null;
|
|
654
|
-
}
|
|
655
|
-
function summarizeMemoryRecallFeedback(options = {}) {
|
|
656
|
-
const where = ["phase IN (?, ?)"];
|
|
657
|
-
const params = ["search", "inject"];
|
|
658
|
-
if (options.providerId) {
|
|
659
|
-
where.push("provider_id = ?");
|
|
660
|
-
params.push(options.providerId);
|
|
661
|
-
}
|
|
662
|
-
where.push("user_id = ?");
|
|
663
|
-
params.push(LOCAL_USER_ID);
|
|
664
|
-
if (options.sourceAgentId) {
|
|
665
|
-
where.push("source_agent_id = ?");
|
|
666
|
-
params.push(options.sourceAgentId);
|
|
667
|
-
}
|
|
668
|
-
if (options.sessionKey) {
|
|
669
|
-
where.push("session_key = ?");
|
|
670
|
-
params.push(options.sessionKey);
|
|
671
|
-
}
|
|
672
|
-
const limit = Math.max(1, Math.min(5e3, options.limit ?? 1e3));
|
|
673
|
-
const rows = getSqliteDatabase().prepare(`SELECT feedback.* FROM memory_feedback AS feedback
|
|
674
|
-
JOIN memory_trace_events AS trace ON trace.trace_id = feedback.trace_id
|
|
675
|
-
WHERE feedback.level = 'record' AND ${where.map((clause) => `trace.${clause}`).join(" AND ")}
|
|
676
|
-
ORDER BY feedback.updated_at DESC LIMIT ?`).all(...params, limit);
|
|
677
|
-
const summaries = /* @__PURE__ */ new Map();
|
|
678
|
-
for (const row of rows) {
|
|
679
|
-
const recordId = row.record_id;
|
|
680
|
-
if (!recordId || options.recordId && recordId !== options.recordId) continue;
|
|
681
|
-
const current = summaries.get(recordId) ?? {
|
|
682
|
-
recordId,
|
|
683
|
-
helpful: 0,
|
|
684
|
-
notHelpful: 0,
|
|
685
|
-
mixed: 0,
|
|
686
|
-
irrelevant: 0,
|
|
687
|
-
total: 0,
|
|
688
|
-
averageScore: null,
|
|
689
|
-
scoreTotal: 0,
|
|
690
|
-
scoreCount: 0
|
|
691
|
-
};
|
|
692
|
-
if (row.rating === "helpful") current.helpful += 1;
|
|
693
|
-
if (row.rating === "not_helpful" || row.rating === "incorrect" || row.rating === "outdated" || row.rating === "sensitive") current.notHelpful += 1;
|
|
694
|
-
if (row.rating === "mixed") current.mixed += 1;
|
|
695
|
-
if (row.rating === "irrelevant") current.irrelevant += 1;
|
|
696
|
-
current.total += 1;
|
|
697
|
-
if (typeof row.score === "number") {
|
|
698
|
-
current.scoreTotal += row.score;
|
|
699
|
-
current.scoreCount += 1;
|
|
700
|
-
current.averageScore = current.scoreTotal / current.scoreCount;
|
|
701
|
-
}
|
|
702
|
-
current.lastFeedbackAt ??= new Date(row.updated_at).toISOString();
|
|
703
|
-
summaries.set(recordId, current);
|
|
704
|
-
}
|
|
705
|
-
return [...summaries.values()].map(({ scoreTotal: _scoreTotal, scoreCount: _scoreCount, ...summary }) => summary).sort((a, b) => b.total - a.total);
|
|
706
|
-
}
|
|
707
|
-
function parseJsonValue(json, fallback) {
|
|
708
|
-
try {
|
|
709
|
-
return JSON.parse(json);
|
|
710
|
-
} catch {
|
|
711
|
-
return fallback;
|
|
712
|
-
}
|
|
713
|
-
}
|
|
714
|
-
//#endregion
|
|
715
|
-
export { appendMemorySignal, appendMemoryTraceEvent, countMemoryRecordsBySourceInstanceId, deleteMemoryRecord, deleteMemoryRecordsBySourceInstanceId, getMemoryProviderState, getMemoryRecord, getMemoryTurnFeedback, hasUnresolvedMemoryConflict, listMemoryRecords, listMemorySignals, listMemoryTraceEvents, markMemoryRecordsConflicted, searchMemoryRecords, setMemoryProviderState, setMemoryRecordStatus, setMemoryTurnFeedback, summarizeMemoryRecallFeedback, upsertMemoryRecord };
|