@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,535 +0,0 @@
|
|
|
1
|
-
import { getSqliteDatabase, runSqliteWriteTransaction } from "./transaction.js";
|
|
2
|
-
import { USER_CONTEXT_PRINCIPAL_ID } from "../../user-context/domain.js";
|
|
3
|
-
import { notifyUserContextChange } from "../../user-context/changes.js";
|
|
4
|
-
import { retrievalQueryAuditValue } from "../../retrieval/audit.js";
|
|
5
|
-
import { buildFts5SearchQuery, fts5RankToScore } from "./fts.js";
|
|
6
|
-
import { createHash, randomUUID } from "node:crypto";
|
|
7
|
-
//#region src/storage/sqlite/user-context-repository.ts
|
|
8
|
-
function insertUnderstandingStatusEvent(db, input) {
|
|
9
|
-
db.prepare(`INSERT INTO understanding_status_events (
|
|
10
|
-
event_id, understanding_id, from_status, to_status, actor_type, source, created_at
|
|
11
|
-
) VALUES (?, ?, ?, ?, ?, ?, ?)`).run(randomUUID(), input.understandingId, input.fromStatus ?? null, input.toStatus, input.actorType, input.source, input.createdAt);
|
|
12
|
-
}
|
|
13
|
-
function evidenceFromRow(row) {
|
|
14
|
-
return {
|
|
15
|
-
id: row.evidence_id,
|
|
16
|
-
sourceType: row.source_type,
|
|
17
|
-
...row.source_instance_id ? { sourceInstanceId: row.source_instance_id } : {},
|
|
18
|
-
sourceRef: row.source_ref,
|
|
19
|
-
...row.source_run_id ? { sourceRunId: row.source_run_id } : {},
|
|
20
|
-
...row.source_item_id ? { sourceItemId: row.source_item_id } : {},
|
|
21
|
-
...row.session_id ? { sessionId: row.session_id } : {},
|
|
22
|
-
...row.turn_id ? { turnId: row.turn_id } : {},
|
|
23
|
-
...row.message_id ? { messageId: row.message_id } : {},
|
|
24
|
-
...row.content_hash ? { contentHash: row.content_hash } : {},
|
|
25
|
-
...row.retention_policy ? { retentionPolicy: row.retention_policy } : {},
|
|
26
|
-
...row.processing_policy ? { processingPolicy: row.processing_policy } : {},
|
|
27
|
-
...row.extractor_id ? { extractorId: row.extractor_id } : {},
|
|
28
|
-
...row.extractor_version ? { extractorVersion: row.extractor_version } : {},
|
|
29
|
-
...row.redacted_excerpt ? { redactedExcerpt: row.redacted_excerpt } : {},
|
|
30
|
-
trustLevel: row.trust_level,
|
|
31
|
-
observedAt: row.observed_at,
|
|
32
|
-
ingestedAt: row.ingested_at ?? row.created_at,
|
|
33
|
-
createdAt: row.created_at
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
const UNDERSTANDING_SELECT = `
|
|
37
|
-
SELECT u.*, v.statement, v.payload_json
|
|
38
|
-
FROM user_understandings u
|
|
39
|
-
JOIN user_understanding_versions v ON v.version_id = u.current_version_id
|
|
40
|
-
`;
|
|
41
|
-
function scopeFromRow(type, id) {
|
|
42
|
-
return id ? {
|
|
43
|
-
type,
|
|
44
|
-
id
|
|
45
|
-
} : { type };
|
|
46
|
-
}
|
|
47
|
-
function understandingFromRow(row) {
|
|
48
|
-
return {
|
|
49
|
-
id: row.understanding_id,
|
|
50
|
-
kind: row.kind,
|
|
51
|
-
canonicalKey: row.canonical_key,
|
|
52
|
-
status: row.status,
|
|
53
|
-
scope: scopeFromRow(row.scope_type, row.scope_id),
|
|
54
|
-
explicitness: row.explicitness,
|
|
55
|
-
durability: row.durability,
|
|
56
|
-
sensitivity: row.sensitivity,
|
|
57
|
-
disclosurePolicy: row.disclosure_policy,
|
|
58
|
-
confidence: row.confidence,
|
|
59
|
-
statement: row.statement,
|
|
60
|
-
payload: JSON.parse(row.payload_json),
|
|
61
|
-
versionId: row.current_version_id,
|
|
62
|
-
...row.valid_from === null ? {} : { validFrom: row.valid_from },
|
|
63
|
-
...row.valid_to === null ? {} : { validTo: row.valid_to },
|
|
64
|
-
...row.expires_at === null ? {} : { expiresAt: row.expires_at },
|
|
65
|
-
...row.review_at === null ? {} : { reviewAt: row.review_at },
|
|
66
|
-
...row.conflict_group_id ? { conflictGroupId: row.conflict_group_id } : {},
|
|
67
|
-
...row.supersedes_id ? { supersedesId: row.supersedes_id } : {},
|
|
68
|
-
createdAt: row.created_at,
|
|
69
|
-
updatedAt: row.updated_at
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
function ruleFromRow(row) {
|
|
73
|
-
return {
|
|
74
|
-
id: row.rule_id,
|
|
75
|
-
category: row.category,
|
|
76
|
-
status: row.status,
|
|
77
|
-
priority: row.priority,
|
|
78
|
-
scope: scopeFromRow(row.scope_type, row.scope_id),
|
|
79
|
-
conditions: JSON.parse(row.conditions_json),
|
|
80
|
-
statement: row.statement,
|
|
81
|
-
revisionId: row.current_revision_id,
|
|
82
|
-
createdAt: row.created_at,
|
|
83
|
-
updatedAt: row.updated_at
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
function getUserProfile(principalId = USER_CONTEXT_PRINCIPAL_ID) {
|
|
87
|
-
const row = getSqliteDatabase().prepare("SELECT * FROM user_profiles WHERE principal_id = ?").get(principalId);
|
|
88
|
-
if (!row) return {
|
|
89
|
-
callName: "",
|
|
90
|
-
role: "",
|
|
91
|
-
primaryGoal: "",
|
|
92
|
-
pronouns: "",
|
|
93
|
-
timezone: "",
|
|
94
|
-
locale: "",
|
|
95
|
-
accessibility: {},
|
|
96
|
-
createdAt: 0,
|
|
97
|
-
updatedAt: 0
|
|
98
|
-
};
|
|
99
|
-
return {
|
|
100
|
-
callName: row.call_name,
|
|
101
|
-
role: row.role,
|
|
102
|
-
primaryGoal: row.primary_goal,
|
|
103
|
-
pronouns: row.pronouns,
|
|
104
|
-
timezone: row.timezone,
|
|
105
|
-
locale: row.locale,
|
|
106
|
-
accessibility: JSON.parse(row.accessibility_json),
|
|
107
|
-
createdAt: row.created_at,
|
|
108
|
-
updatedAt: row.updated_at
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
|
-
function updateUserProfile(patch, principalId = USER_CONTEXT_PRINCIPAL_ID) {
|
|
112
|
-
notifyUserContextChange({
|
|
113
|
-
kind: "profile",
|
|
114
|
-
id: "profile"
|
|
115
|
-
});
|
|
116
|
-
const current = getUserProfile(principalId);
|
|
117
|
-
const now = Date.now();
|
|
118
|
-
const next = {
|
|
119
|
-
...current,
|
|
120
|
-
...patch,
|
|
121
|
-
createdAt: current.createdAt || now,
|
|
122
|
-
updatedAt: now
|
|
123
|
-
};
|
|
124
|
-
runSqliteWriteTransaction((db) => {
|
|
125
|
-
db.prepare(`
|
|
126
|
-
INSERT INTO user_profiles (
|
|
127
|
-
principal_id, call_name, role, primary_goal, pronouns, timezone, locale, accessibility_json, created_at, updated_at
|
|
128
|
-
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
129
|
-
ON CONFLICT(principal_id) DO UPDATE SET
|
|
130
|
-
call_name = excluded.call_name,
|
|
131
|
-
role = excluded.role,
|
|
132
|
-
primary_goal = excluded.primary_goal,
|
|
133
|
-
pronouns = excluded.pronouns,
|
|
134
|
-
timezone = excluded.timezone,
|
|
135
|
-
locale = excluded.locale,
|
|
136
|
-
accessibility_json = excluded.accessibility_json,
|
|
137
|
-
updated_at = excluded.updated_at
|
|
138
|
-
`).run(principalId, next.callName, next.role, next.primaryGoal, next.pronouns, next.timezone, next.locale, JSON.stringify(next.accessibility), next.createdAt, next.updatedAt);
|
|
139
|
-
});
|
|
140
|
-
return next;
|
|
141
|
-
}
|
|
142
|
-
function createUnderstanding(input, principalId = USER_CONTEXT_PRINCIPAL_ID) {
|
|
143
|
-
const id = randomUUID();
|
|
144
|
-
const versionId = randomUUID();
|
|
145
|
-
const now = Date.now();
|
|
146
|
-
runSqliteWriteTransaction((db) => {
|
|
147
|
-
db.prepare(`INSERT INTO user_understandings (
|
|
148
|
-
understanding_id, principal_id, kind, canonical_key, status, scope_type, scope_id,
|
|
149
|
-
explicitness, durability, sensitivity, disclosure_policy, confidence, valid_from,
|
|
150
|
-
valid_to, expires_at, review_at, current_version_id, conflict_group_id, supersedes_id,
|
|
151
|
-
created_at, updated_at
|
|
152
|
-
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`).run(id, principalId, input.kind, input.canonicalKey, input.status, input.scope.type, input.scope.id ?? null, input.explicitness, input.durability, input.sensitivity, input.disclosurePolicy, input.confidence, input.validFrom ?? null, input.validTo ?? null, input.expiresAt ?? null, input.reviewAt ?? null, versionId, input.conflictGroupId ?? null, input.supersedesId ?? null, now, now);
|
|
153
|
-
db.prepare(`INSERT INTO user_understanding_versions (
|
|
154
|
-
version_id, understanding_id, statement, payload_json, created_by, change_reason, created_at
|
|
155
|
-
) VALUES (?, ?, ?, ?, ?, ?, ?)`).run(versionId, id, input.statement.trim(), JSON.stringify(input.payload ?? {}), input.createdBy, input.changeReason, now);
|
|
156
|
-
db.prepare("INSERT INTO user_understanding_fts (statement, understanding_id, version_id) VALUES (?, ?, ?)").run(input.statement.trim(), id, versionId);
|
|
157
|
-
insertUnderstandingStatusEvent(db, {
|
|
158
|
-
understandingId: id,
|
|
159
|
-
toStatus: input.status,
|
|
160
|
-
actorType: input.createdBy === "user" ? "user" : "runtime",
|
|
161
|
-
source: `create:${input.changeReason}`,
|
|
162
|
-
createdAt: now
|
|
163
|
-
});
|
|
164
|
-
});
|
|
165
|
-
return getUnderstanding(id);
|
|
166
|
-
}
|
|
167
|
-
function getUnderstanding(id) {
|
|
168
|
-
const row = getSqliteDatabase().prepare(`${UNDERSTANDING_SELECT} WHERE u.understanding_id = ?`).get(id);
|
|
169
|
-
return row ? understandingFromRow(row) : void 0;
|
|
170
|
-
}
|
|
171
|
-
function listUnderstandings(statuses, principalId = USER_CONTEXT_PRINCIPAL_ID, limit) {
|
|
172
|
-
const db = getSqliteDatabase();
|
|
173
|
-
const maxRows = limit === void 0 ? -1 : Math.max(1, Math.min(500, Math.floor(limit)));
|
|
174
|
-
if (!statuses?.length) return db.prepare(`${UNDERSTANDING_SELECT} WHERE u.principal_id = ? ORDER BY u.updated_at DESC LIMIT ?`).all(principalId, maxRows).map(understandingFromRow);
|
|
175
|
-
const placeholders = statuses.map(() => "?").join(", ");
|
|
176
|
-
return db.prepare(`${UNDERSTANDING_SELECT} WHERE u.principal_id = ? AND u.status IN (${placeholders}) ORDER BY u.updated_at DESC LIMIT ?`).all(principalId, ...statuses, maxRows).map(understandingFromRow);
|
|
177
|
-
}
|
|
178
|
-
function searchActiveUnderstandings(query, limit = 50) {
|
|
179
|
-
const ftsQuery = buildFts5SearchQuery(query);
|
|
180
|
-
if (!ftsQuery) return [];
|
|
181
|
-
const boundedLimit = Math.max(1, Math.min(200, Math.floor(limit)));
|
|
182
|
-
const rows = getSqliteDatabase().prepare(`
|
|
183
|
-
SELECT u.*, v.statement, v.payload_json, bm25(user_understanding_fts) AS search_rank
|
|
184
|
-
FROM user_understanding_fts
|
|
185
|
-
JOIN user_understandings u
|
|
186
|
-
ON u.understanding_id = user_understanding_fts.understanding_id
|
|
187
|
-
JOIN user_understanding_versions v
|
|
188
|
-
ON v.version_id = u.current_version_id
|
|
189
|
-
WHERE user_understanding_fts MATCH ? AND u.principal_id = ? AND u.status = 'active'
|
|
190
|
-
ORDER BY search_rank
|
|
191
|
-
LIMIT ?
|
|
192
|
-
`).all(ftsQuery, USER_CONTEXT_PRINCIPAL_ID, boundedLimit);
|
|
193
|
-
if (!rows.length) return [];
|
|
194
|
-
const bestRank = Math.min(...rows.map((row) => row.search_rank));
|
|
195
|
-
const worstRank = Math.max(...rows.map((row) => row.search_rank));
|
|
196
|
-
return rows.map((row) => ({
|
|
197
|
-
understanding: understandingFromRow(row),
|
|
198
|
-
score: fts5RankToScore(row.search_rank, bestRank, worstRank)
|
|
199
|
-
}));
|
|
200
|
-
}
|
|
201
|
-
function reviseUnderstanding(id, statement, options) {
|
|
202
|
-
notifyUserContextChange({
|
|
203
|
-
kind: "understanding",
|
|
204
|
-
id
|
|
205
|
-
});
|
|
206
|
-
const current = getUnderstanding(id);
|
|
207
|
-
if (!current) throw new Error(`User understanding not found: ${id}`);
|
|
208
|
-
const versionId = randomUUID();
|
|
209
|
-
const now = Date.now();
|
|
210
|
-
runSqliteWriteTransaction((db) => {
|
|
211
|
-
db.prepare(`INSERT INTO user_understanding_versions (
|
|
212
|
-
version_id, understanding_id, statement, payload_json, created_by, change_reason, created_at
|
|
213
|
-
) VALUES (?, ?, ?, ?, 'user', ?, ?)`).run(versionId, id, statement.trim(), JSON.stringify(options.payload ?? current.payload), options.changeReason, now);
|
|
214
|
-
db.prepare(`UPDATE user_understandings
|
|
215
|
-
SET current_version_id = ?, canonical_key = ?, explicitness = ?, confidence = ?, updated_at = ?
|
|
216
|
-
WHERE understanding_id = ?`).run(versionId, options.canonicalKey ?? current.canonicalKey, options.explicitness ?? current.explicitness, options.confidence ?? current.confidence, now, id);
|
|
217
|
-
db.prepare("DELETE FROM user_understanding_fts WHERE understanding_id = ?").run(id);
|
|
218
|
-
db.prepare("INSERT INTO user_understanding_fts (statement, understanding_id, version_id) VALUES (?, ?, ?)").run(statement.trim(), id, versionId);
|
|
219
|
-
});
|
|
220
|
-
return getUnderstanding(id);
|
|
221
|
-
}
|
|
222
|
-
function setUnderstandingStatus(id, status, options) {
|
|
223
|
-
notifyUserContextChange({
|
|
224
|
-
kind: "understanding",
|
|
225
|
-
id
|
|
226
|
-
});
|
|
227
|
-
const current = getUnderstanding(id);
|
|
228
|
-
if (!current) throw new Error(`User understanding not found: ${id}`);
|
|
229
|
-
const now = Date.now();
|
|
230
|
-
runSqliteWriteTransaction((db) => {
|
|
231
|
-
db.prepare(`UPDATE user_understandings
|
|
232
|
-
SET status = ?,
|
|
233
|
-
explicitness = COALESCE(?, explicitness),
|
|
234
|
-
confidence = COALESCE(?, confidence),
|
|
235
|
-
updated_at = ?
|
|
236
|
-
WHERE understanding_id = ?`).run(status, options?.explicitness ?? null, options?.confidence ?? null, now, id);
|
|
237
|
-
const assertionStatus = status === "active" ? "active" : status === "archived" ? "closed" : status === "rejected" ? "rejected" : "candidate";
|
|
238
|
-
db.prepare(`UPDATE context_temporal_assertions
|
|
239
|
-
SET status = ?, updated_at = ? WHERE object_type = 'understanding' AND object_id = ?`).run(assertionStatus, now, id);
|
|
240
|
-
if (current.status !== status) insertUnderstandingStatusEvent(db, {
|
|
241
|
-
understandingId: id,
|
|
242
|
-
fromStatus: current.status,
|
|
243
|
-
toStatus: status,
|
|
244
|
-
actorType: options?.actorType ?? "runtime",
|
|
245
|
-
source: options?.source ?? "repository-status-change",
|
|
246
|
-
createdAt: now
|
|
247
|
-
});
|
|
248
|
-
});
|
|
249
|
-
const result = getUnderstanding(id);
|
|
250
|
-
if (!result) throw new Error(`User understanding not found: ${id}`);
|
|
251
|
-
return result;
|
|
252
|
-
}
|
|
253
|
-
function closeUnderstandingValidity(id, validTo = Date.now()) {
|
|
254
|
-
notifyUserContextChange({
|
|
255
|
-
kind: "understanding",
|
|
256
|
-
id
|
|
257
|
-
});
|
|
258
|
-
getSqliteDatabase().prepare(`UPDATE user_understandings SET valid_to = ?, updated_at = ?
|
|
259
|
-
WHERE understanding_id = ?`).run(validTo, validTo, id);
|
|
260
|
-
const result = getUnderstanding(id);
|
|
261
|
-
if (!result) throw new Error(`User understanding not found: ${id}`);
|
|
262
|
-
return result;
|
|
263
|
-
}
|
|
264
|
-
function rejectUnderstanding(id, reason, actorType = "runtime") {
|
|
265
|
-
notifyUserContextChange({
|
|
266
|
-
kind: "understanding",
|
|
267
|
-
id
|
|
268
|
-
});
|
|
269
|
-
const current = getUnderstanding(id);
|
|
270
|
-
if (!current) throw new Error(`User understanding not found: ${id}`);
|
|
271
|
-
const now = Date.now();
|
|
272
|
-
runSqliteWriteTransaction((db) => {
|
|
273
|
-
db.prepare("UPDATE user_understandings SET status = 'rejected', updated_at = ? WHERE understanding_id = ?").run(now, id);
|
|
274
|
-
if (current.status !== "rejected") insertUnderstandingStatusEvent(db, {
|
|
275
|
-
understandingId: id,
|
|
276
|
-
fromStatus: current.status,
|
|
277
|
-
toStatus: "rejected",
|
|
278
|
-
actorType,
|
|
279
|
-
source: reason,
|
|
280
|
-
createdAt: now
|
|
281
|
-
});
|
|
282
|
-
db.prepare(`INSERT INTO context_suppressions (
|
|
283
|
-
suppression_id, principal_id, canonical_key, scope_type, scope_id, reason, expires_at, created_at
|
|
284
|
-
) VALUES (?, ?, ?, ?, ?, ?, NULL, ?)
|
|
285
|
-
ON CONFLICT DO UPDATE SET reason = excluded.reason, expires_at = NULL`).run(randomUUID(), USER_CONTEXT_PRINCIPAL_ID, current.canonicalKey, current.scope.type, current.scope.id ?? null, reason, now);
|
|
286
|
-
});
|
|
287
|
-
return getUnderstanding(id);
|
|
288
|
-
}
|
|
289
|
-
function listUnderstandingStatusEvents(id) {
|
|
290
|
-
return getSqliteDatabase().prepare(`SELECT * FROM understanding_status_events
|
|
291
|
-
WHERE understanding_id = ? ORDER BY created_at DESC, rowid DESC`).all(id).map((row) => ({
|
|
292
|
-
id: row.event_id,
|
|
293
|
-
understandingId: row.understanding_id,
|
|
294
|
-
...row.from_status ? { fromStatus: row.from_status } : {},
|
|
295
|
-
toStatus: row.to_status,
|
|
296
|
-
actorType: row.actor_type,
|
|
297
|
-
source: row.source,
|
|
298
|
-
createdAt: row.created_at
|
|
299
|
-
}));
|
|
300
|
-
}
|
|
301
|
-
function deleteUnderstanding(id) {
|
|
302
|
-
notifyUserContextChange({
|
|
303
|
-
kind: "understanding",
|
|
304
|
-
id
|
|
305
|
-
});
|
|
306
|
-
return runSqliteWriteTransaction((db) => {
|
|
307
|
-
db.prepare("DELETE FROM user_understanding_fts WHERE understanding_id = ?").run(id);
|
|
308
|
-
return Number(db.prepare("DELETE FROM user_understandings WHERE understanding_id = ?").run(id).changes) > 0;
|
|
309
|
-
});
|
|
310
|
-
}
|
|
311
|
-
function isUnderstandingSuppressed(canonicalKey, scope, principalId = USER_CONTEXT_PRINCIPAL_ID) {
|
|
312
|
-
const row = getSqliteDatabase().prepare(`SELECT 1 FROM context_suppressions
|
|
313
|
-
WHERE principal_id = ? AND canonical_key = ? AND scope_type = ?
|
|
314
|
-
AND COALESCE(scope_id, '') = COALESCE(?, '')
|
|
315
|
-
AND (expires_at IS NULL OR expires_at > ?)`).get(principalId, canonicalKey, scope.type, scope.id ?? null, Date.now());
|
|
316
|
-
return Boolean(row);
|
|
317
|
-
}
|
|
318
|
-
function createCollaborationRule(input, principalId = USER_CONTEXT_PRINCIPAL_ID) {
|
|
319
|
-
const id = randomUUID();
|
|
320
|
-
const revisionId = randomUUID();
|
|
321
|
-
const now = Date.now();
|
|
322
|
-
runSqliteWriteTransaction((db) => {
|
|
323
|
-
db.prepare(`INSERT INTO collaboration_rules (
|
|
324
|
-
rule_id, principal_id, category, status, priority, scope_type, scope_id,
|
|
325
|
-
conditions_json, current_revision_id, created_at, updated_at
|
|
326
|
-
) VALUES (?, ?, ?, 'active', ?, ?, ?, ?, ?, ?, ?)`).run(id, principalId, input.category, input.priority, input.scope.type, input.scope.id ?? null, JSON.stringify(input.conditions), revisionId, now, now);
|
|
327
|
-
db.prepare(`INSERT INTO collaboration_rule_revisions (
|
|
328
|
-
revision_id, rule_id, statement, created_by, created_at
|
|
329
|
-
) VALUES (?, ?, ?, 'user', ?)`).run(revisionId, id, input.statement.trim(), now);
|
|
330
|
-
});
|
|
331
|
-
return getCollaborationRule(id);
|
|
332
|
-
}
|
|
333
|
-
function getCollaborationRule(id) {
|
|
334
|
-
const row = getSqliteDatabase().prepare(`SELECT r.*, v.statement FROM collaboration_rules r
|
|
335
|
-
JOIN collaboration_rule_revisions v ON v.revision_id = r.current_revision_id
|
|
336
|
-
WHERE r.rule_id = ?`).get(id);
|
|
337
|
-
return row ? ruleFromRow(row) : void 0;
|
|
338
|
-
}
|
|
339
|
-
function listCollaborationRules(principalId = USER_CONTEXT_PRINCIPAL_ID) {
|
|
340
|
-
return getSqliteDatabase().prepare(`SELECT r.*, v.statement FROM collaboration_rules r
|
|
341
|
-
JOIN collaboration_rule_revisions v ON v.revision_id = r.current_revision_id
|
|
342
|
-
WHERE r.principal_id = ? ORDER BY r.priority ASC, r.updated_at DESC`).all(principalId).map(ruleFromRow);
|
|
343
|
-
}
|
|
344
|
-
function reviseCollaborationRule(id, statement) {
|
|
345
|
-
if (!getCollaborationRule(id)) throw new Error(`Collaboration rule not found: ${id}`);
|
|
346
|
-
const revisionId = randomUUID();
|
|
347
|
-
const now = Date.now();
|
|
348
|
-
runSqliteWriteTransaction((db) => {
|
|
349
|
-
db.prepare(`INSERT INTO collaboration_rule_revisions (
|
|
350
|
-
revision_id, rule_id, statement, created_by, created_at
|
|
351
|
-
) VALUES (?, ?, ?, 'user', ?)`).run(revisionId, id, statement.trim(), now);
|
|
352
|
-
db.prepare("UPDATE collaboration_rules SET current_revision_id = ?, updated_at = ? WHERE rule_id = ?").run(revisionId, now, id);
|
|
353
|
-
});
|
|
354
|
-
return getCollaborationRule(id);
|
|
355
|
-
}
|
|
356
|
-
function setCollaborationRuleStatus(id, status) {
|
|
357
|
-
getSqliteDatabase().prepare("UPDATE collaboration_rules SET status = ?, updated_at = ? WHERE rule_id = ?").run(status, Date.now(), id);
|
|
358
|
-
const result = getCollaborationRule(id);
|
|
359
|
-
if (!result) throw new Error(`Collaboration rule not found: ${id}`);
|
|
360
|
-
return result;
|
|
361
|
-
}
|
|
362
|
-
function deleteCollaborationRule(id) {
|
|
363
|
-
return Number(getSqliteDatabase().prepare("DELETE FROM collaboration_rules WHERE rule_id = ?").run(id).changes) > 0;
|
|
364
|
-
}
|
|
365
|
-
function createContextEvidence(input, principalId = USER_CONTEXT_PRINCIPAL_ID) {
|
|
366
|
-
const existing = getSqliteDatabase().prepare(`SELECT * FROM context_evidence
|
|
367
|
-
WHERE principal_id = ? AND source_type = ?
|
|
368
|
-
AND COALESCE(source_instance_id, '') = COALESCE(?, '') AND source_ref = ?`).get(principalId, input.sourceType, input.sourceInstanceId ?? null, input.sourceRef);
|
|
369
|
-
const derivedHash = input.contentHash ?? (input.redactedExcerpt ? createHash("sha256").update(input.redactedExcerpt).digest("hex") : void 0);
|
|
370
|
-
if (existing) {
|
|
371
|
-
notifyUserContextChange({ kind: "policy" });
|
|
372
|
-
getSqliteDatabase().prepare(`UPDATE context_evidence SET
|
|
373
|
-
source_run_id = COALESCE(source_run_id, ?), source_item_id = COALESCE(source_item_id, ?),
|
|
374
|
-
session_id = COALESCE(session_id, ?), turn_id = COALESCE(turn_id, ?),
|
|
375
|
-
message_id = COALESCE(message_id, ?), content_hash = COALESCE(content_hash, ?),
|
|
376
|
-
retention_policy = COALESCE(retention_policy, ?),
|
|
377
|
-
processing_policy = CASE
|
|
378
|
-
WHEN processing_policy = 'local_only' OR ? = 'local_only' THEN 'local_only'
|
|
379
|
-
ELSE COALESCE(processing_policy, ?)
|
|
380
|
-
END,
|
|
381
|
-
extractor_id = COALESCE(extractor_id, ?), extractor_version = COALESCE(extractor_version, ?),
|
|
382
|
-
ingested_at = COALESCE(ingested_at, ?)
|
|
383
|
-
WHERE evidence_id = ?`).run(input.sourceRunId ?? null, input.sourceItemId ?? null, input.sessionId ?? null, input.turnId ?? null, input.messageId ?? null, derivedHash ?? null, input.retentionPolicy ?? null, input.processingPolicy ?? null, input.processingPolicy ?? null, input.extractorId ?? null, input.extractorVersion ?? null, input.ingestedAt ?? Date.now(), existing.evidence_id);
|
|
384
|
-
return evidenceFromRow(getSqliteDatabase().prepare("SELECT * FROM context_evidence WHERE evidence_id = ?").get(existing.evidence_id));
|
|
385
|
-
}
|
|
386
|
-
const createdAt = Date.now();
|
|
387
|
-
const evidence = {
|
|
388
|
-
...input,
|
|
389
|
-
id: randomUUID(),
|
|
390
|
-
...derivedHash ? { contentHash: derivedHash } : {},
|
|
391
|
-
ingestedAt: input.ingestedAt ?? createdAt,
|
|
392
|
-
createdAt
|
|
393
|
-
};
|
|
394
|
-
getSqliteDatabase().prepare(`INSERT INTO context_evidence (
|
|
395
|
-
evidence_id, principal_id, source_type, source_instance_id, source_ref, source_run_id,
|
|
396
|
-
source_item_id, session_id, turn_id, message_id, content_hash, retention_policy,
|
|
397
|
-
processing_policy, extractor_id, extractor_version, redacted_excerpt, trust_level,
|
|
398
|
-
observed_at, ingested_at, created_at
|
|
399
|
-
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`).run(evidence.id, principalId, evidence.sourceType, evidence.sourceInstanceId ?? null, evidence.sourceRef, evidence.sourceRunId ?? null, evidence.sourceItemId ?? null, evidence.sessionId ?? null, evidence.turnId ?? null, evidence.messageId ?? null, evidence.contentHash ?? null, evidence.retentionPolicy ?? null, evidence.processingPolicy ?? null, evidence.extractorId ?? null, evidence.extractorVersion ?? null, evidence.redactedExcerpt ?? null, evidence.trustLevel, evidence.observedAt, evidence.ingestedAt, evidence.createdAt);
|
|
400
|
-
return evidence;
|
|
401
|
-
}
|
|
402
|
-
function linkUnderstandingEvidence(versionId, evidenceId, relation, confidence) {
|
|
403
|
-
const owner = getSqliteDatabase().prepare("SELECT understanding_id AS id FROM user_understanding_versions WHERE version_id = ?").get(versionId);
|
|
404
|
-
if (owner) notifyUserContextChange({
|
|
405
|
-
kind: "understanding",
|
|
406
|
-
id: owner.id
|
|
407
|
-
});
|
|
408
|
-
getSqliteDatabase().prepare(`INSERT INTO understanding_evidence_links (
|
|
409
|
-
version_id, evidence_id, relation, confidence
|
|
410
|
-
) VALUES (?, ?, ?, ?)
|
|
411
|
-
ON CONFLICT(version_id, evidence_id, relation) DO UPDATE SET confidence = excluded.confidence`).run(versionId, evidenceId, relation, confidence);
|
|
412
|
-
}
|
|
413
|
-
function listUnderstandingEvidence(understandingId, relation) {
|
|
414
|
-
return getSqliteDatabase().prepare(`SELECT DISTINCT e.* FROM context_evidence e
|
|
415
|
-
JOIN understanding_evidence_links l ON l.evidence_id = e.evidence_id
|
|
416
|
-
JOIN user_understanding_versions v ON v.version_id = l.version_id
|
|
417
|
-
WHERE v.understanding_id = ? AND (? IS NULL OR l.relation = ?)
|
|
418
|
-
ORDER BY e.observed_at DESC`).all(understandingId, relation ?? null, relation ?? null).map(evidenceFromRow);
|
|
419
|
-
}
|
|
420
|
-
/** Latest source labels for ranking, without fetching evidence bodies per candidate. */
|
|
421
|
-
function understandingSourceBuckets(ids) {
|
|
422
|
-
if (!ids.length) return /* @__PURE__ */ new Map();
|
|
423
|
-
const rows = getSqliteDatabase().prepare(`
|
|
424
|
-
SELECT understanding_id, source_type, source_instance_id, source_ref FROM (
|
|
425
|
-
SELECT v.understanding_id, e.source_type, e.source_instance_id, e.source_ref,
|
|
426
|
-
ROW_NUMBER() OVER (PARTITION BY v.understanding_id ORDER BY e.observed_at DESC) AS rank
|
|
427
|
-
FROM context_evidence e JOIN understanding_evidence_links l ON l.evidence_id = e.evidence_id
|
|
428
|
-
JOIN user_understanding_versions v ON v.version_id = l.version_id
|
|
429
|
-
WHERE v.understanding_id IN (${ids.map(() => "?").join(",")})
|
|
430
|
-
) WHERE rank = 1
|
|
431
|
-
`).all(...ids);
|
|
432
|
-
return new Map(rows.map((row) => [row.understanding_id, `${row.source_type}:${row.source_instance_id ?? row.source_ref.split(":entry:")[0]}`]));
|
|
433
|
-
}
|
|
434
|
-
function recordContextRun(input) {
|
|
435
|
-
const auditedQuery = retrievalQueryAuditValue(input.query);
|
|
436
|
-
const existing = getSqliteDatabase().prepare("SELECT context_run_id FROM context_runs WHERE turn_id = ?").get(input.turnId);
|
|
437
|
-
const runId = existing?.context_run_id ?? randomUUID();
|
|
438
|
-
runSqliteWriteTransaction((db) => {
|
|
439
|
-
if (existing) {
|
|
440
|
-
db.prepare(`UPDATE context_runs SET principal_id = ?, session_key = ?, query = ?, budget = ?, duration_ms = ?
|
|
441
|
-
WHERE context_run_id = ?`).run(input.principalId ?? "local-owner", input.sessionKey, auditedQuery, input.budget, input.durationMs, runId);
|
|
442
|
-
db.prepare("DELETE FROM context_run_items WHERE context_run_id = ?").run(runId);
|
|
443
|
-
} else db.prepare(`INSERT INTO context_runs (
|
|
444
|
-
context_run_id, principal_id, turn_id, session_key, query, budget, duration_ms, created_at
|
|
445
|
-
) VALUES (?, ?, ?, ?, ?, ?, ?, ?)`).run(runId, input.principalId ?? "local-owner", input.turnId, input.sessionKey, auditedQuery, input.budget, input.durationMs, Date.now());
|
|
446
|
-
const insert = db.prepare(`INSERT INTO context_run_items (
|
|
447
|
-
context_run_id, object_type, object_id, version_id, decision, reason, content_snapshot,
|
|
448
|
-
source_label, origin, rank, score, injected_chars
|
|
449
|
-
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`);
|
|
450
|
-
for (const item of input.items) insert.run(runId, item.objectType, item.objectId, item.versionId ?? null, item.decision, item.reason, item.content, item.sourceLabel, item.origin, item.rank ?? null, item.score ?? null, item.injectedChars);
|
|
451
|
-
});
|
|
452
|
-
return runId;
|
|
453
|
-
}
|
|
454
|
-
function getTurnPersonalization(turnId) {
|
|
455
|
-
const db = getSqliteDatabase();
|
|
456
|
-
const run = db.prepare("SELECT context_run_id FROM context_runs WHERE turn_id = ?").get(turnId);
|
|
457
|
-
if (!run) return void 0;
|
|
458
|
-
const rows = db.prepare("SELECT * FROM context_run_items WHERE context_run_id = ? ORDER BY rank ASC, object_type ASC").all(run.context_run_id);
|
|
459
|
-
return {
|
|
460
|
-
runId: run.context_run_id,
|
|
461
|
-
items: rows.map((row) => ({
|
|
462
|
-
objectType: row.object_type,
|
|
463
|
-
objectId: row.object_id,
|
|
464
|
-
...row.version_id ? { versionId: row.version_id } : {},
|
|
465
|
-
decision: row.decision,
|
|
466
|
-
reason: row.reason,
|
|
467
|
-
content: row.content_snapshot,
|
|
468
|
-
sourceLabel: row.source_label,
|
|
469
|
-
origin: row.origin,
|
|
470
|
-
...row.rank === null ? {} : { rank: row.rank },
|
|
471
|
-
...row.score === null ? {} : { score: row.score },
|
|
472
|
-
injectedChars: row.injected_chars
|
|
473
|
-
}))
|
|
474
|
-
};
|
|
475
|
-
}
|
|
476
|
-
function recordContextFeedback(input) {
|
|
477
|
-
if (Boolean(input.objectType) !== Boolean(input.objectId)) throw new Error("objectType and objectId must be provided together");
|
|
478
|
-
getSqliteDatabase().prepare(`INSERT INTO context_feedback (
|
|
479
|
-
feedback_id, turn_id, context_run_id, object_type, object_id, rating, reason, created_at
|
|
480
|
-
) VALUES (?, ?, ?, ?, ?, ?, ?, ?)
|
|
481
|
-
ON CONFLICT DO UPDATE SET rating = excluded.rating, reason = excluded.reason, created_at = excluded.created_at`).run(randomUUID(), input.turnId, input.runId, input.objectType ?? null, input.objectId ?? null, input.rating, input.reason ?? null, Date.now());
|
|
482
|
-
}
|
|
483
|
-
function hasContextConsent(understandingId, sessionKey) {
|
|
484
|
-
const now = Date.now();
|
|
485
|
-
return Boolean(getSqliteDatabase().prepare(`SELECT 1 FROM context_consents
|
|
486
|
-
WHERE understanding_id = ? AND status = 'granted'
|
|
487
|
-
AND (grant_scope = 'always' OR session_key = ?)
|
|
488
|
-
AND (expires_at IS NULL OR expires_at > ?)
|
|
489
|
-
LIMIT 1`).get(understandingId, sessionKey, now));
|
|
490
|
-
}
|
|
491
|
-
function consumeContextConsent(understandingId, sessionKey) {
|
|
492
|
-
const db = getSqliteDatabase();
|
|
493
|
-
const now = Date.now();
|
|
494
|
-
const granted = db.prepare(`SELECT consent_id, grant_scope FROM context_consents
|
|
495
|
-
WHERE understanding_id = ? AND status = 'granted'
|
|
496
|
-
AND (grant_scope = 'always' OR session_key = ?)
|
|
497
|
-
AND (expires_at IS NULL OR expires_at > ?)
|
|
498
|
-
ORDER BY CASE grant_scope WHEN 'once' THEN 0 WHEN 'session' THEN 1 ELSE 2 END
|
|
499
|
-
LIMIT 1`).get(understandingId, sessionKey, now);
|
|
500
|
-
if (granted) {
|
|
501
|
-
if (granted.grant_scope === "once") db.prepare("UPDATE context_consents SET status = 'consumed', updated_at = ? WHERE consent_id = ?").run(now, granted.consent_id);
|
|
502
|
-
return "granted";
|
|
503
|
-
}
|
|
504
|
-
return db.prepare(`SELECT 1 FROM context_consents
|
|
505
|
-
WHERE understanding_id = ? AND session_key = ? AND status = 'denied' LIMIT 1`).get(understandingId, sessionKey) ? "denied" : "missing";
|
|
506
|
-
}
|
|
507
|
-
function ensureContextConsent(understandingId, sessionKey, purpose) {
|
|
508
|
-
const db = getSqliteDatabase();
|
|
509
|
-
const existing = db.prepare(`SELECT consent_id, purpose FROM context_consents
|
|
510
|
-
WHERE understanding_id = ? AND session_key = ? AND status = 'pending'`).get(understandingId, sessionKey);
|
|
511
|
-
if (existing) return {
|
|
512
|
-
id: existing.consent_id,
|
|
513
|
-
understandingId,
|
|
514
|
-
purpose: existing.purpose
|
|
515
|
-
};
|
|
516
|
-
const id = randomUUID();
|
|
517
|
-
const now = Date.now();
|
|
518
|
-
db.prepare(`INSERT INTO context_consents (
|
|
519
|
-
consent_id, principal_id, understanding_id, session_key, purpose, status,
|
|
520
|
-
grant_scope, expires_at, created_at, updated_at
|
|
521
|
-
) VALUES (?, ?, ?, ?, ?, 'pending', NULL, NULL, ?, ?)`).run(id, USER_CONTEXT_PRINCIPAL_ID, understandingId, sessionKey, purpose, now, now);
|
|
522
|
-
return {
|
|
523
|
-
id,
|
|
524
|
-
understandingId,
|
|
525
|
-
purpose
|
|
526
|
-
};
|
|
527
|
-
}
|
|
528
|
-
function decideContextConsent(id, decision) {
|
|
529
|
-
const expiresAt = decision === "once" ? Date.now() + 5 * 6e4 : null;
|
|
530
|
-
const result = getSqliteDatabase().prepare(`UPDATE context_consents
|
|
531
|
-
SET status = ?, grant_scope = ?, expires_at = ?, updated_at = ? WHERE consent_id = ?`).run(decision === "deny" ? "denied" : "granted", decision === "deny" ? null : decision, expiresAt, Date.now(), id);
|
|
532
|
-
return Number(result.changes) > 0;
|
|
533
|
-
}
|
|
534
|
-
//#endregion
|
|
535
|
-
export { closeUnderstandingValidity, consumeContextConsent, createCollaborationRule, createContextEvidence, createUnderstanding, decideContextConsent, deleteCollaborationRule, deleteUnderstanding, ensureContextConsent, getCollaborationRule, getTurnPersonalization, getUnderstanding, getUserProfile, hasContextConsent, isUnderstandingSuppressed, linkUnderstandingEvidence, listCollaborationRules, listUnderstandingEvidence, listUnderstandingStatusEvents, listUnderstandings, recordContextFeedback, recordContextRun, rejectUnderstanding, reviseCollaborationRule, reviseUnderstanding, searchActiveUnderstandings, setCollaborationRuleStatus, setUnderstandingStatus, understandingSourceBuckets, updateUserProfile };
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { type RemoteContextKind } from '../storage/sqlite/remote-context-repository.js';
|
|
2
|
-
import type { UserContextScopeTarget } from './scope.js';
|
|
3
|
-
export interface AutomaticContextReference {
|
|
4
|
-
kind: RemoteContextKind | 'profile';
|
|
5
|
-
id: string;
|
|
6
|
-
version: string;
|
|
7
|
-
}
|
|
8
|
-
export interface AutomaticContextSelection {
|
|
9
|
-
block: string;
|
|
10
|
-
references: AutomaticContextReference[];
|
|
11
|
-
}
|
|
12
|
-
/** Read-only background selection. Never consumes consent or starts a model turn. */
|
|
13
|
-
export declare function selectAutomaticContext(input: UserContextScopeTarget & {
|
|
14
|
-
query: string;
|
|
15
|
-
maxChars: number;
|
|
16
|
-
deadline: number;
|
|
17
|
-
}): AutomaticContextSelection;
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import { getUserProfile, listUnderstandings } from "../storage/sqlite/user-context-repository.js";
|
|
2
|
-
import { listUserFocuses } from "./sources/repository.js";
|
|
3
|
-
import { UserUnderstandingRetriever } from "./retriever.js";
|
|
4
|
-
import { allowsAutomaticDisclosure, focusRejectionReason, focusScore, rejectionReason } from "./selection-policy.js";
|
|
5
|
-
import { remoteContextEligibleIds } from "../storage/sqlite/remote-context-repository.js";
|
|
6
|
-
//#region src/user-context/automatic-context.ts
|
|
7
|
-
/** Read-only background selection. Never consumes consent or starts a model turn. */
|
|
8
|
-
function selectAutomaticContext(input) {
|
|
9
|
-
const references = [];
|
|
10
|
-
const facts = [];
|
|
11
|
-
const profile = {};
|
|
12
|
-
const render = () => JSON.stringify({ backgroundMemory: {
|
|
13
|
-
profile,
|
|
14
|
-
facts
|
|
15
|
-
} });
|
|
16
|
-
const withinDeadline = () => performance.now() < input.deadline;
|
|
17
|
-
if (input.maxChars < 128 || !withinDeadline()) return {
|
|
18
|
-
block: "",
|
|
19
|
-
references
|
|
20
|
-
};
|
|
21
|
-
const user = getUserProfile();
|
|
22
|
-
for (const key of [
|
|
23
|
-
"callName",
|
|
24
|
-
"locale",
|
|
25
|
-
"timezone",
|
|
26
|
-
"pronouns",
|
|
27
|
-
"role",
|
|
28
|
-
"primaryGoal"
|
|
29
|
-
]) {
|
|
30
|
-
if (!user[key] || user[key].length > 300) continue;
|
|
31
|
-
profile[key] = user[key];
|
|
32
|
-
if (render().length > input.maxChars) delete profile[key];
|
|
33
|
-
}
|
|
34
|
-
if (Object.keys(profile).length) references.push({
|
|
35
|
-
kind: "profile",
|
|
36
|
-
id: "profile",
|
|
37
|
-
version: JSON.stringify(user)
|
|
38
|
-
});
|
|
39
|
-
const query = input.query.trim();
|
|
40
|
-
const candidates = !withinDeadline() ? [] : query ? new UserUnderstandingRetriever().retrieve({
|
|
41
|
-
...input,
|
|
42
|
-
maxCandidates: 50
|
|
43
|
-
}) : listUnderstandings(["active"], void 0, 200).filter((item) => item.explicitness === "explicit" && ["preference", "boundary"].includes(item.kind) && item.durability === "durable").map((understanding) => ({
|
|
44
|
-
understanding,
|
|
45
|
-
score: 1
|
|
46
|
-
}));
|
|
47
|
-
const now = Date.now();
|
|
48
|
-
const eligible = candidates.filter(({ understanding: item, score }) => item.status === "active" && allowsAutomaticDisclosure(item) && !rejectionReason(item, input, now, []) && score > .25);
|
|
49
|
-
const allowed = withinDeadline() ? remoteContextEligibleIds("understanding", eligible.map(({ understanding }) => understanding.id)) : /* @__PURE__ */ new Set();
|
|
50
|
-
const append = (text, origin, reference) => {
|
|
51
|
-
if (!withinDeadline() || facts.length >= 6 || !text.trim()) return;
|
|
52
|
-
facts.push({
|
|
53
|
-
text,
|
|
54
|
-
origin
|
|
55
|
-
});
|
|
56
|
-
if (render().length > input.maxChars) {
|
|
57
|
-
facts.pop();
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
references.push(reference);
|
|
61
|
-
};
|
|
62
|
-
for (const { understanding: item } of eligible) if (allowed.has(item.id)) append(item.statement, item.explicitness, {
|
|
63
|
-
kind: "understanding",
|
|
64
|
-
id: item.id,
|
|
65
|
-
version: item.versionId
|
|
66
|
-
});
|
|
67
|
-
if (query && withinDeadline() && facts.length < 6) {
|
|
68
|
-
const focuses = listUserFocuses(["active"], 50).filter((item) => allowsAutomaticDisclosure(item) && !focusRejectionReason(item, input, now)).map((item) => ({
|
|
69
|
-
item,
|
|
70
|
-
score: focusScore(item, query, input)
|
|
71
|
-
})).filter(({ score }) => score > .25).sort((a, b) => b.score - a.score);
|
|
72
|
-
const allowedFocuses = remoteContextEligibleIds("focus", focuses.map(({ item }) => item.id));
|
|
73
|
-
for (const { item } of focuses) if (allowedFocuses.has(item.id)) append(`${item.title}: ${item.summary}`, item.explicitness, {
|
|
74
|
-
kind: "focus",
|
|
75
|
-
id: item.id,
|
|
76
|
-
version: item.versionId ?? String(item.updatedAt)
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
return {
|
|
80
|
-
block: references.length ? render() : "",
|
|
81
|
-
references
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
//#endregion
|
|
85
|
-
export { selectAutomaticContext };
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import type { Config } from '../config/schema.js';
|
|
2
|
-
import { type ContextConsolidationRun } from '../storage/sqlite/index.js';
|
|
3
|
-
export declare const USER_CONTEXT_CONSOLIDATION_TOKEN = "__xopc_user_context_consolidation__";
|
|
4
|
-
export declare const USER_CONTEXT_CONSOLIDATION_AUTOMATION_ID = "system-user-context-consolidation";
|
|
5
|
-
type ConsolidationMetrics = {
|
|
6
|
-
scanned: number;
|
|
7
|
-
needsReview: number;
|
|
8
|
-
stale: number;
|
|
9
|
-
globalCandidates: number;
|
|
10
|
-
};
|
|
11
|
-
export declare function resolveContextConsolidationConfig(config: Config): {
|
|
12
|
-
enabled: boolean;
|
|
13
|
-
timezone: string;
|
|
14
|
-
time: string;
|
|
15
|
-
minEvidenceSources: number;
|
|
16
|
-
limit: number;
|
|
17
|
-
};
|
|
18
|
-
export declare function compileContextConsolidationCron(time: string): string;
|
|
19
|
-
export declare function runContextConsolidation(input: {
|
|
20
|
-
config: Config;
|
|
21
|
-
triggerKind: 'schedule' | 'manual';
|
|
22
|
-
now?: number;
|
|
23
|
-
}): Promise<{
|
|
24
|
-
run: ContextConsolidationRun;
|
|
25
|
-
metrics: ConsolidationMetrics;
|
|
26
|
-
}>;
|
|
27
|
-
export {};
|