@xopcai/xopc 0.0.247 → 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/src/update-offset-store.js +17 -54
- package/dist/extensions/telegram/xopc.extension.json +1 -1
- package/dist/extensions/weixin/src/auth/accounts.js +3 -5
- package/dist/extensions/weixin/src/monitor/monitor.js +3 -5
- package/dist/extensions/weixin/src/storage/sync-buf.d.ts +3 -6
- package/dist/extensions/weixin/src/storage/sync-buf.js +9 -22
- package/dist/gateway/static/root/assets/{activity-store-BlxqErph.js → activity-store-B759R_qf.js} +1 -1
- package/dist/gateway/static/root/assets/{agent-avatar-dicebear-DmaFeojS.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-BbXzyQMj.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-DD2SweEH.js → archive-plugin-BQrilVVv.js} +1 -1
- package/dist/gateway/static/root/assets/{attachment-load-BG82bNBQ.js → attachment-load-BG0BliqV.js} +1 -1
- package/dist/gateway/static/root/assets/{automations-page-CqBZ89He.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-B6LKm5Zv.js → binary-plugins-BCnyNU0C.js} +1 -1
- package/dist/gateway/static/root/assets/{block-editor-BJKvGVXd.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-BAAc151l.js → browser-workflow-inputs-C71vfl0b.js} +1 -1
- package/dist/gateway/static/root/assets/{browser-workflows-page-DoE4Uuns.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-CCBCtLDg.js → channels-status-swr-CKyV3jY5.js} +1 -1
- package/dist/gateway/static/root/assets/{chat-terminal-dock-BsRWnz7M.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-DdCgsH2c.js → cron-expression-D-F9vjtE.js} +1 -1
- package/dist/gateway/static/root/assets/{date-picker-dt37Lt8e.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-Nw_Pgkk3.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-BHSst0WN.js → extension-debug-page-COyn05ub.js} +1 -1
- package/dist/gateway/static/root/assets/{extension-page-DXbL4cQZ.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-826dipyU.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-DyvcAIMm.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-D7cyfks6.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-EY4cu-6W.js → keyboard-shortcuts-settings-D8Zw_lYd.js} +1 -1
- package/dist/gateway/static/root/assets/local-app-workbench-page-eBFVWmtH.js +2 -0
- package/dist/gateway/static/root/assets/{local-apps-page-Dh7OxX0S.js → local-apps-page-CvPDPRwb.js} +1 -1
- package/dist/gateway/static/root/assets/{locale-store-CBoCuIMx.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-ZjiL3A-S.js → management-settings-D8moh99U.js} +1 -1
- package/dist/gateway/static/root/assets/{markdown-split-B4BxkTpU.js → markdown-split-D7V3j0vE.js} +1 -1
- package/dist/gateway/static/root/assets/{markdown-view-BXsHghJd.js → markdown-view-DGRN-8wP.js} +1 -1
- package/dist/gateway/static/root/assets/{media-plugins-D15XBiEo.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-CAJeUXeU.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-BhGKnvLP.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-BhKcyEId.js → runtime-tools-settings-panel-C0ByNmlV.js} +2 -2
- package/dist/gateway/static/root/assets/{schema-form-L0s7RWCi.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-CTKoztlF.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-CiiLLz5A.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-CwRekJSJ.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-hybK3oC9.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-DX5YZ3Nn.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-ocnZbAyi.js → voice-api-key-field-8YEvA3cU.js} +1 -1
- package/dist/gateway/static/root/assets/{voice-config-api-CBbiF1T3.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-DaErGvxO.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/commands/command-registry.d.ts +1 -0
- package/dist/src/agent/commands/command-registry.js +12 -22
- 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/ipc/inbox.d.ts +8 -31
- package/dist/src/agent/ipc/inbox.js +64 -133
- 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-one-shot.js +15 -10
- 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/agent/workflow/catalog.d.ts +1 -8
- package/dist/src/agent/workflow/catalog.js +44 -102
- package/dist/src/agent/workflow/index.d.ts +1 -1
- package/dist/src/agent/workflow/index.js +2 -2
- package/dist/src/automations/domain/types.d.ts +1 -0
- package/dist/src/automations/service/action-executor.js +2 -2
- package/dist/src/automations/service/automation-service.js +2 -2
- package/dist/src/channels/manager.d.ts +1 -1
- package/dist/src/channels/manager.js +2 -2
- package/dist/src/channels/outbound/persist-store.d.ts +2 -8
- package/dist/src/channels/outbound/persist-store.js +11 -38
- package/dist/src/channels/outbound-sender.d.ts +1 -1
- package/dist/src/channels/outbound-sender.js +2 -2
- package/dist/src/chat-commands/builtins/understanding.js +24 -6
- 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 +31 -20
- package/dist/src/config/web-patch.d.ts +1 -1
- package/dist/src/connectors/composio-managed-client.js +6 -2
- package/dist/src/connectors/composio-triggers.d.ts +2 -2
- package/dist/src/connectors/composio-triggers.js +8 -15
- 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/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/automation-agent-session.js +3 -0
- 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/lib/extension-store.js +8 -25
- package/dist/src/gateway/hono/middleware/auth.js +1 -2
- 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 +4 -12
- 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/notes.js +22 -7
- package/dist/src/gateway/hono/routes/projects.js +37 -45
- 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/hono/routes/workflows.js +2 -2
- 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 +49 -19
- 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/index.d.ts +1 -1
- package/dist/src/notes/index.js +2 -2
- package/dist/src/notes/paths.d.ts +0 -3
- package/dist/src/notes/paths.js +1 -10
- package/dist/src/notes/service.d.ts +1 -1
- package/dist/src/notes/service.js +7 -4
- package/dist/src/notes/store.d.ts +0 -2
- package/dist/src/notes/store.js +33 -80
- 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/share/hosted-session-share.d.ts +1 -4
- package/dist/src/share/hosted-session-share.js +14 -47
- package/dist/src/share/share-auto.d.ts +1 -1
- package/dist/src/share/share-auto.js +2 -2
- package/dist/src/share/share-store.d.ts +2 -7
- package/dist/src/share/share-store.js +153 -195
- package/dist/src/share/share-types.d.ts +0 -4
- package/dist/src/share/site-share-store.d.ts +3 -8
- package/dist/src/share/site-share-store.js +94 -153
- package/dist/src/share/site-share-types.d.ts +0 -4
- 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/connection.d.ts +1 -2
- package/dist/src/storage/sqlite/connection.js +50 -47
- 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/durable-queue.d.ts +16 -0
- package/dist/src/storage/sqlite/durable-queue.js +52 -0
- package/dist/src/storage/sqlite/durable-state.d.ts +16 -0
- package/dist/src/storage/sqlite/durable-state.js +43 -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/146_understanding_focus_exclusions.sql +9 -0
- package/dist/src/storage/sqlite/migrations/147_durable_application_state.sql +39 -0
- 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-scoped-models.js +9 -6
- 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/agentEngine.js +63 -18
- package/dist/src/voice/realtime/conversationTurn.d.ts +20 -0
- package/dist/src/voice/realtime/conversationTurn.js +83 -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/voice/realtime/omniEngine.js +72 -18
- 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/authoring/workflow-draft-store.d.ts +1 -5
- package/dist/src/workflows/authoring/workflow-draft-store.js +23 -43
- package/dist/src/workflows/index.js +2 -2
- package/dist/src/workflows/service/workflow-run-service.js +1 -1
- package/dist/src/workflows/service/workflow-session-bridge.js +12 -20
- package/dist/src/workflows/store/event-store.d.ts +1 -2
- package/dist/src/workflows/store/event-store.js +19 -64
- package/dist/src/workflows/store/paths.d.ts +0 -2
- package/dist/src/workflows/store/paths.js +1 -7
- package/dist/src/workflows/store/run-store.d.ts +0 -1
- package/dist/src/workflows/store/run-store.js +1 -24
- package/package.json +3 -3
- package/dist/gateway/static/root/assets/agent-defaults-settings-panel-eG49pM-z.js +0 -1
- package/dist/gateway/static/root/assets/agents-CZwf1mgZ.js +0 -1
- package/dist/gateway/static/root/assets/app-management-settings-panel-BODskFTb.js +0 -1
- package/dist/gateway/static/root/assets/appearance-settings-DeaVvaYZ.js +0 -1
- package/dist/gateway/static/root/assets/apps-page-BZG3BK7f.js +0 -1
- package/dist/gateway/static/root/assets/automations-workspace-CB7Yl2_B.js +0 -6
- package/dist/gateway/static/root/assets/browser-settings-page-Bu42Ljfw.js +0 -8
- package/dist/gateway/static/root/assets/capabilities-settings-panel-Cg7zCxEH.js +0 -7
- package/dist/gateway/static/root/assets/channels-settings-EDTZ8P3y.js +0 -1
- package/dist/gateway/static/root/assets/cloud-C4-yfnnk.js +0 -1
- package/dist/gateway/static/root/assets/connectors-page-kh7PEkSS.js +0 -2
- package/dist/gateway/static/root/assets/dependency-picker-oi7cdv2C.js +0 -1
- package/dist/gateway/static/root/assets/desktop-pet-settings-D9OO-exo.js +0 -1
- package/dist/gateway/static/root/assets/ellipsis-0k4rZLoy.js +0 -1
- package/dist/gateway/static/root/assets/extension-settings-page-FTD7nE8v.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-c-8ENciH.js +0 -1
- package/dist/gateway/static/root/assets/gateway-settings-BxvyTRl0.js +0 -1
- package/dist/gateway/static/root/assets/heartbeat-settings-C1S2Ccui.js +0 -1
- package/dist/gateway/static/root/assets/home-page-Bqx-SMWV.js +0 -1
- package/dist/gateway/static/root/assets/index-Cif1_3Jx.js +0 -71
- package/dist/gateway/static/root/assets/index-Dbh5SXyV.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-app-workbench-page-sDdw7Y3Q.js +0 -2
- package/dist/gateway/static/root/assets/logs-page-DUsxXdDp.js +0 -2
- package/dist/gateway/static/root/assets/message-square-plus-XP0tGdlV.js +0 -1
- package/dist/gateway/static/root/assets/messages-BbdwoxVo.js +0 -3
- package/dist/gateway/static/root/assets/minimize-2-DtOGrlpo.js +0 -1
- package/dist/gateway/static/root/assets/mobile-pairing-wizard-Dv87XewB.js +0 -1
- package/dist/gateway/static/root/assets/models-hub-cache-88f4fzYS.js +0 -1
- package/dist/gateway/static/root/assets/notes-page-DOe0lOcQ.js +0 -1
- package/dist/gateway/static/root/assets/notes-workbench-Cy0oYbWP.js +0 -4
- package/dist/gateway/static/root/assets/oauth-api-BjSUDIgq.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-fgD1xc4O.js +0 -1
- package/dist/gateway/static/root/assets/projects-page-CiTiEcOc.js +0 -1
- package/dist/gateway/static/root/assets/remote-access-hub-Dc0GrNSp.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-BPOW3yaM.js +0 -1
- package/dist/gateway/static/root/assets/settings-advanced-gate-Bz4s9BBY.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-rllj-j7k.js +0 -1
- package/dist/gateway/static/root/assets/shares-settings-DMj7onCX.js +0 -1
- package/dist/gateway/static/root/assets/skill-reload-api-DRB366nS.js +0 -1
- package/dist/gateway/static/root/assets/skills-page-cBT9jCof.js +0 -2
- package/dist/gateway/static/root/assets/system-settings-panel-Byrk4DQy.js +0 -1
- package/dist/gateway/static/root/assets/task-detail-page-CheX3zmK.js +0 -1
- package/dist/gateway/static/root/assets/tunnel-api-jKzujxFU.js +0 -1
- package/dist/gateway/static/root/assets/user-context-page-CWy3Pqtk.js +0 -1
- package/dist/gateway/static/root/assets/work-discovery-overlay-DE4_YpDn.js +0 -1
- package/dist/gateway/static/root/assets/workflows-page-y4O9-BTf.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 -443
- 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/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
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
import { createLogger } from "../../utils/logger/index.js";
|
|
2
|
+
import { init_logger } from "../../utils/logger.js";
|
|
3
|
+
import { isXopcDatabaseOpen } from "./connection.js";
|
|
4
|
+
import { getSqliteDatabase, runSqliteWriteTransaction } from "./transaction.js";
|
|
5
|
+
import { TaskRunRepository } from "../../tasks/task-run-repository.js";
|
|
6
|
+
import { readCurrentSessionId } from "./session-repository.js";
|
|
7
|
+
import { bumpSessionInputRevision, getSessionInputById, getSessionInputState, insertSessionInput, setSessionInputStatus } from "./session-input-repository.js";
|
|
8
|
+
import { randomUUID } from "node:crypto";
|
|
9
|
+
import { EventEmitter } from "node:events";
|
|
10
|
+
//#region src/storage/sqlite/connection-wait-repository.ts
|
|
11
|
+
init_logger();
|
|
12
|
+
const log = createLogger("Connectors:Wait");
|
|
13
|
+
const events = new EventEmitter();
|
|
14
|
+
function onConnectionWaitChanged(listener) {
|
|
15
|
+
events.on("changed", listener);
|
|
16
|
+
return () => {
|
|
17
|
+
events.off("changed", listener);
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
function publishConnectionWait(sessionKey) {
|
|
21
|
+
events.emit("changed", sessionKey);
|
|
22
|
+
}
|
|
23
|
+
function getConnectionWait(id) {
|
|
24
|
+
if (!isXopcDatabaseOpen()) return void 0;
|
|
25
|
+
const row = getSqliteDatabase().prepare("SELECT data_json FROM session_connection_waits WHERE id = ?").get(id);
|
|
26
|
+
return row ? JSON.parse(row.data_json) : void 0;
|
|
27
|
+
}
|
|
28
|
+
function getActiveConnectionWait(sessionKey) {
|
|
29
|
+
if (!isXopcDatabaseOpen()) return void 0;
|
|
30
|
+
const db = getSqliteDatabase();
|
|
31
|
+
const row = db.prepare(`SELECT data_json FROM session_connection_waits WHERE session_key = ? AND session_id = ?
|
|
32
|
+
AND status IN ('open','queued')`).get(sessionKey, readCurrentSessionId(db, sessionKey) ?? "");
|
|
33
|
+
return row ? JSON.parse(row.data_json) : void 0;
|
|
34
|
+
}
|
|
35
|
+
function isConnectionSuspended(sessionKey, runId) {
|
|
36
|
+
const wait = getActiveConnectionWait(sessionKey);
|
|
37
|
+
return Boolean(wait && wait.originRunId === runId);
|
|
38
|
+
}
|
|
39
|
+
function updateConnectionWait(wait, expectedVersion) {
|
|
40
|
+
return runSqliteWriteTransaction((db) => {
|
|
41
|
+
if (readCurrentSessionId(db, wait.sessionKey) !== wait.sessionId) throw new Error("SESSION_CHANGED");
|
|
42
|
+
const next = {
|
|
43
|
+
...wait,
|
|
44
|
+
version: expectedVersion + 1,
|
|
45
|
+
updatedAt: Date.now()
|
|
46
|
+
};
|
|
47
|
+
if (!db.prepare(`UPDATE session_connection_waits SET status = ?, version = ?, data_json = ? WHERE id = ? AND version = ?`).run(next.status, next.version, JSON.stringify(next), next.id, expectedVersion).changes) throw new Error("WAIT_CHANGED");
|
|
48
|
+
bumpSessionInputRevision(db, wait.sessionKey);
|
|
49
|
+
return next;
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
function requireSessionConnection(input) {
|
|
53
|
+
return runSqliteWriteTransaction((db) => {
|
|
54
|
+
const sessionId = readCurrentSessionId(db, input.sessionKey);
|
|
55
|
+
const runtime = getSessionInputState(input.sessionKey);
|
|
56
|
+
const origin = runtime.activeInputId ? getSessionInputById(input.sessionKey, runtime.activeInputId) : void 0;
|
|
57
|
+
if (!sessionId || !origin || !runtime.activeRunId) throw new Error("Connection recovery requires a queued chat execution.");
|
|
58
|
+
const resumed = origin.payload ? getConnectionWait(origin.payload.waitId) : void 0;
|
|
59
|
+
if (resumed?.resolution === "skipped") return { status: "skipped" };
|
|
60
|
+
const active = getActiveConnectionWait(input.sessionKey);
|
|
61
|
+
if (active) {
|
|
62
|
+
if (active.originInputId !== origin.id && active.objectiveId !== resumed?.objectiveId) return {
|
|
63
|
+
status: "objective_conflict",
|
|
64
|
+
waitId: active.id
|
|
65
|
+
};
|
|
66
|
+
const needs = new Map(active.needs.map((need) => [need.key, need]));
|
|
67
|
+
for (const need of input.needs) {
|
|
68
|
+
const previous = needs.get(need.key);
|
|
69
|
+
needs.set(need.key, previous ? {
|
|
70
|
+
...previous,
|
|
71
|
+
capabilities: [...new Set([...previous.capabilities, ...need.capabilities])]
|
|
72
|
+
} : need);
|
|
73
|
+
}
|
|
74
|
+
if (JSON.stringify([...needs.values()]) !== JSON.stringify(active.needs)) updateConnectionWait({
|
|
75
|
+
...active,
|
|
76
|
+
needs: [...needs.values()]
|
|
77
|
+
}, active.version);
|
|
78
|
+
return {
|
|
79
|
+
status: "connection_required",
|
|
80
|
+
waitId: active.id
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
const lastEntry = db.prepare("SELECT entry_id FROM transcript_entries WHERE session_id = ? ORDER BY seq DESC LIMIT 1").get(sessionId);
|
|
84
|
+
const wait = {
|
|
85
|
+
...input,
|
|
86
|
+
needs: [...new Map(input.needs.map((need) => [need.key, need])).values()],
|
|
87
|
+
id: randomUUID(),
|
|
88
|
+
sessionId,
|
|
89
|
+
objectiveId: resumed?.objectiveId ?? origin.id,
|
|
90
|
+
objectiveRevision: (resumed?.objectiveRevision ?? 0) + 1,
|
|
91
|
+
objectiveUpdatedAt: resumed?.objectiveUpdatedAt ?? origin.createdAtMs,
|
|
92
|
+
originInputId: origin.id,
|
|
93
|
+
originRunId: runtime.activeRunId,
|
|
94
|
+
taskRunId: origin.taskRunId,
|
|
95
|
+
checkpoint: {
|
|
96
|
+
entryId: lastEntry?.entry_id,
|
|
97
|
+
completedSteps: input.checkpoint?.completedSteps ?? [],
|
|
98
|
+
pendingSteps: input.checkpoint?.pendingSteps ?? [input.summary],
|
|
99
|
+
timeRange: input.checkpoint?.timeRange ?? resumed?.checkpoint.timeRange
|
|
100
|
+
},
|
|
101
|
+
summary: resumed?.summary ?? origin.content,
|
|
102
|
+
status: "open",
|
|
103
|
+
version: 1,
|
|
104
|
+
createdAt: Date.now(),
|
|
105
|
+
updatedAt: Date.now()
|
|
106
|
+
};
|
|
107
|
+
db.prepare(`INSERT INTO session_connection_waits(id,principal_id,session_key,session_id,status,version,data_json) VALUES (?,?,?,?,?,?,?)`).run(wait.id, wait.principalId, wait.sessionKey, wait.sessionId, wait.status, wait.version, JSON.stringify(wait));
|
|
108
|
+
if (wait.taskRunId) {
|
|
109
|
+
const runs = new TaskRunRepository();
|
|
110
|
+
const run = runs.get(wait.taskRunId);
|
|
111
|
+
if (run) {
|
|
112
|
+
runs.createWait({
|
|
113
|
+
taskId: run.taskId,
|
|
114
|
+
taskRunId: run.id,
|
|
115
|
+
kind: "user_input",
|
|
116
|
+
reason: input.summary,
|
|
117
|
+
condition: {
|
|
118
|
+
type: "connection",
|
|
119
|
+
connectionWaitId: wait.id
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
runs.setStatus({
|
|
123
|
+
runId: run.id,
|
|
124
|
+
expectedVersion: run.version,
|
|
125
|
+
from: [run.status],
|
|
126
|
+
to: "waiting",
|
|
127
|
+
actor: { kind: "system" }
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
bumpSessionInputRevision(db, wait.sessionKey);
|
|
132
|
+
log.info({
|
|
133
|
+
sessionKey: wait.sessionKey,
|
|
134
|
+
waitId: wait.id,
|
|
135
|
+
objectiveRevision: wait.objectiveRevision,
|
|
136
|
+
runId: wait.originRunId,
|
|
137
|
+
phase: "waiting"
|
|
138
|
+
}, "Connection requirement saved");
|
|
139
|
+
return {
|
|
140
|
+
status: "connection_required",
|
|
141
|
+
waitId: wait.id
|
|
142
|
+
};
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
/** The input and the wait transition commit together, using the existing queue's unique key. */
|
|
146
|
+
function queueConnectionResolution(wait, resolution) {
|
|
147
|
+
return runSqliteWriteTransaction(() => {
|
|
148
|
+
const current = getConnectionWait(wait.id);
|
|
149
|
+
if (!current || current.version !== wait.version || current.status !== "open") throw new Error("WAIT_CHANGED");
|
|
150
|
+
const origin = getSessionInputById(wait.sessionKey, wait.originInputId);
|
|
151
|
+
if (!origin) throw new Error("Original input is unavailable.");
|
|
152
|
+
const input = insertSessionInput({
|
|
153
|
+
id: randomUUID(),
|
|
154
|
+
sessionKey: wait.sessionKey,
|
|
155
|
+
expectedSessionId: wait.sessionId,
|
|
156
|
+
clientMessageId: `connection:${wait.id}:${wait.objectiveRevision}:${resolution}`,
|
|
157
|
+
requestedDelivery: "next",
|
|
158
|
+
effectiveDelivery: "next",
|
|
159
|
+
status: "queued",
|
|
160
|
+
content: resolution === "skipped" ? `The user skipped the requested connection. Continue this objective using only available information: ${wait.summary}. Do not request these connections again or claim to have read their data.` : `Recovery checkpoint: ${JSON.stringify(wait.checkpoint)}. The user chose to continue the request originally made at ${new Date(wait.objectiveUpdatedAt).toISOString()}: ${wait.summary}. Interpret relative dates against that original request time, unless the user explicitly changed them. The connection requirement has been checked. Search and describe tools again before using them. Use the explicitly selected account. Do not repeat already completed actions.`,
|
|
161
|
+
origin: {
|
|
162
|
+
type: "system",
|
|
163
|
+
source: "internal"
|
|
164
|
+
},
|
|
165
|
+
thinking: origin.thinking,
|
|
166
|
+
contextRefs: origin.contextRefs,
|
|
167
|
+
contextSnapshots: origin.contextSnapshots,
|
|
168
|
+
kind: "connection_resume",
|
|
169
|
+
taskRunId: wait.taskRunId,
|
|
170
|
+
payload: {
|
|
171
|
+
waitId: wait.id,
|
|
172
|
+
objectiveRevision: wait.objectiveRevision,
|
|
173
|
+
resolution
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
return updateConnectionWait({
|
|
177
|
+
...wait,
|
|
178
|
+
status: "queued",
|
|
179
|
+
resolution,
|
|
180
|
+
queuedInputId: input.id
|
|
181
|
+
}, wait.version);
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
function consumeConnectionResume(input) {
|
|
185
|
+
if (input.kind !== "connection_resume") return true;
|
|
186
|
+
return runSqliteWriteTransaction(() => {
|
|
187
|
+
const wait = input.payload ? getConnectionWait(input.payload.waitId) : void 0;
|
|
188
|
+
if (!wait || wait.status !== "queued" || wait.queuedInputId !== input.id || wait.objectiveRevision !== input.payload?.objectiveRevision) return false;
|
|
189
|
+
if (readCurrentSessionId(getSqliteDatabase(), input.sessionKey) !== wait.sessionId) return false;
|
|
190
|
+
if (wait.taskRunId) {
|
|
191
|
+
const runs = new TaskRunRepository();
|
|
192
|
+
const run = runs.get(wait.taskRunId);
|
|
193
|
+
if (!run || run.status !== "waiting") return false;
|
|
194
|
+
const taskWaits = runs.listActiveWaits(run.taskId);
|
|
195
|
+
if (taskWaits.some((item) => item.taskRunId === run.id && item.condition.connectionWaitId !== wait.id)) {
|
|
196
|
+
updateConnectionWait({
|
|
197
|
+
...wait,
|
|
198
|
+
status: "open",
|
|
199
|
+
intent: void 0,
|
|
200
|
+
queuedInputId: void 0,
|
|
201
|
+
objectiveRevision: wait.objectiveRevision + 1
|
|
202
|
+
}, wait.version);
|
|
203
|
+
return false;
|
|
204
|
+
}
|
|
205
|
+
for (const taskWait of taskWaits) if (taskWait.condition.connectionWaitId === wait.id) runs.resolveWait({
|
|
206
|
+
waitId: taskWait.id,
|
|
207
|
+
actor: { kind: "system" },
|
|
208
|
+
resolution: { connectionWaitId: wait.id }
|
|
209
|
+
});
|
|
210
|
+
runs.setStatus({
|
|
211
|
+
runId: run.id,
|
|
212
|
+
expectedVersion: run.version,
|
|
213
|
+
from: ["waiting"],
|
|
214
|
+
to: "running",
|
|
215
|
+
actor: { kind: "system" }
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
updateConnectionWait({
|
|
219
|
+
...wait,
|
|
220
|
+
status: "closed"
|
|
221
|
+
}, wait.version);
|
|
222
|
+
return true;
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
function connectionBindings(sessionKey) {
|
|
226
|
+
if (!isXopcDatabaseOpen()) return [];
|
|
227
|
+
const state = getSessionInputState(sessionKey);
|
|
228
|
+
const input = state.activeInputId ? getSessionInputById(sessionKey, state.activeInputId) : void 0;
|
|
229
|
+
return input?.payload ? getConnectionWait(input.payload.waitId)?.needs ?? [] : [];
|
|
230
|
+
}
|
|
231
|
+
function connectionBinding(sessionKey, connectorId) {
|
|
232
|
+
const matches = connectionBindings(sessionKey).filter((need) => need.connectorId === connectorId);
|
|
233
|
+
return matches.length === 1 ? matches[0].connectionId : void 0;
|
|
234
|
+
}
|
|
235
|
+
/** New input wins over an outstanding auto-resume intent, including an already queued resume. */
|
|
236
|
+
function invalidateConnectionResumeIntent(sessionKey) {
|
|
237
|
+
const wait = getActiveConnectionWait(sessionKey);
|
|
238
|
+
if (!wait) return;
|
|
239
|
+
runSqliteWriteTransaction(() => {
|
|
240
|
+
if (wait.queuedInputId) setSessionInputStatus(wait.queuedInputId, "cancelled");
|
|
241
|
+
updateConnectionWait({
|
|
242
|
+
...wait,
|
|
243
|
+
status: "open",
|
|
244
|
+
intent: void 0,
|
|
245
|
+
queuedInputId: void 0,
|
|
246
|
+
objectiveRevision: wait.objectiveRevision + 1,
|
|
247
|
+
scopeConfirmedAt: void 0,
|
|
248
|
+
reviewRequired: true
|
|
249
|
+
}, wait.version);
|
|
250
|
+
});
|
|
251
|
+
publishConnectionWait(sessionKey);
|
|
252
|
+
}
|
|
253
|
+
function reviseCurrentConnectionObjective(sessionKey, summary) {
|
|
254
|
+
const wait = getActiveConnectionWait(sessionKey);
|
|
255
|
+
if (!wait) throw new Error("No connection objective is waiting.");
|
|
256
|
+
if (!summary) {
|
|
257
|
+
cancelConnectionObjective(sessionKey);
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
runSqliteWriteTransaction(() => {
|
|
261
|
+
if (wait.queuedInputId) setSessionInputStatus(wait.queuedInputId, "cancelled");
|
|
262
|
+
updateConnectionWait({
|
|
263
|
+
...wait,
|
|
264
|
+
summary,
|
|
265
|
+
objectiveUpdatedAt: Date.now(),
|
|
266
|
+
checkpoint: {
|
|
267
|
+
...wait.checkpoint,
|
|
268
|
+
pendingSteps: [summary],
|
|
269
|
+
timeRange: void 0
|
|
270
|
+
},
|
|
271
|
+
status: "open",
|
|
272
|
+
resolution: void 0,
|
|
273
|
+
intent: void 0,
|
|
274
|
+
queuedInputId: void 0,
|
|
275
|
+
scopeConfirmedAt: void 0,
|
|
276
|
+
reviewRequired: true,
|
|
277
|
+
objectiveRevision: wait.objectiveRevision + 1
|
|
278
|
+
}, wait.version);
|
|
279
|
+
});
|
|
280
|
+
publishConnectionWait(sessionKey);
|
|
281
|
+
}
|
|
282
|
+
function cancelConnectionObjective(sessionKey) {
|
|
283
|
+
const wait = getActiveConnectionWait(sessionKey);
|
|
284
|
+
if (!wait) return;
|
|
285
|
+
runSqliteWriteTransaction(() => {
|
|
286
|
+
if (wait.queuedInputId) setSessionInputStatus(wait.queuedInputId, "cancelled");
|
|
287
|
+
if (wait.taskRunId) {
|
|
288
|
+
const runs = new TaskRunRepository();
|
|
289
|
+
const run = runs.get(wait.taskRunId);
|
|
290
|
+
if (run?.status === "waiting") {
|
|
291
|
+
for (const taskWait of runs.listActiveWaits(run.taskId)) if (taskWait.condition.connectionWaitId === wait.id) runs.resolveWait({
|
|
292
|
+
waitId: taskWait.id,
|
|
293
|
+
actor: { kind: "system" },
|
|
294
|
+
resolution: { cancelled: true }
|
|
295
|
+
});
|
|
296
|
+
runs.finalize({
|
|
297
|
+
runId: run.id,
|
|
298
|
+
expectedVersion: run.version,
|
|
299
|
+
receipt: {
|
|
300
|
+
status: "cancelled",
|
|
301
|
+
summary: "Connection objective cancelled",
|
|
302
|
+
changes: [],
|
|
303
|
+
evidence: [],
|
|
304
|
+
verification: {
|
|
305
|
+
status: "unverified",
|
|
306
|
+
checks: []
|
|
307
|
+
},
|
|
308
|
+
remainingWork: [],
|
|
309
|
+
needsUser: false,
|
|
310
|
+
completionVerdict: "not_achieved"
|
|
311
|
+
}
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
updateConnectionWait({
|
|
316
|
+
...wait,
|
|
317
|
+
status: "closed",
|
|
318
|
+
resolution: "cancelled",
|
|
319
|
+
intent: void 0
|
|
320
|
+
}, wait.version);
|
|
321
|
+
});
|
|
322
|
+
publishConnectionWait(sessionKey);
|
|
323
|
+
}
|
|
324
|
+
function getConnectionResumeInput(sessionKey, runId) {
|
|
325
|
+
if (!isXopcDatabaseOpen()) return void 0;
|
|
326
|
+
const state = getSessionInputState(sessionKey);
|
|
327
|
+
if (state.activeRunId !== runId || !state.activeInputId) return void 0;
|
|
328
|
+
const input = getSessionInputById(sessionKey, state.activeInputId);
|
|
329
|
+
return input?.kind === "connection_resume" ? input : void 0;
|
|
330
|
+
}
|
|
331
|
+
function listConnectionWaitsToCheck() {
|
|
332
|
+
if (!isXopcDatabaseOpen()) return [];
|
|
333
|
+
return getSqliteDatabase().prepare(`SELECT wait.data_json FROM session_connection_waits wait
|
|
334
|
+
JOIN sessions session ON session.session_id = wait.session_id
|
|
335
|
+
WHERE wait.status = 'open'`).all().map((row) => JSON.parse(row.data_json)).filter((wait) => wait.principalId === "local-owner" && wait.intent && wait.intent.validUntil > Date.now());
|
|
336
|
+
}
|
|
337
|
+
//#endregion
|
|
338
|
+
export { cancelConnectionObjective, connectionBinding, connectionBindings, consumeConnectionResume, getActiveConnectionWait, getConnectionResumeInput, getConnectionWait, invalidateConnectionResumeIntent, isConnectionSuspended, listConnectionWaitsToCheck, onConnectionWaitChanged, publishConnectionWait, queueConnectionResolution, requireSessionConnection, reviseCurrentConnectionObjective, updateConnectionWait };
|
|
@@ -10,8 +10,7 @@ export type SqliteConnectionPragmaOptions = {
|
|
|
10
10
|
checkpointMode?: SqliteWalCheckpointMode;
|
|
11
11
|
busyTimeoutMs?: number;
|
|
12
12
|
foreignKeys?: boolean;
|
|
13
|
-
synchronous?: 'NORMAL';
|
|
14
|
-
databasePath?: string;
|
|
13
|
+
synchronous?: 'NORMAL' | 'FULL';
|
|
15
14
|
onCheckpointError?: (error: unknown) => void;
|
|
16
15
|
};
|
|
17
16
|
export type XopcDatabase = {
|
|
@@ -88,44 +88,38 @@ function isPathWithinMount(targetPath, mountPoint) {
|
|
|
88
88
|
const resolvedMountPoint = path.resolve(mountPoint);
|
|
89
89
|
return resolvedTarget === resolvedMountPoint || resolvedMountPoint === path.parse(resolvedMountPoint).root || resolvedTarget.startsWith(`${resolvedMountPoint}${path.sep}`);
|
|
90
90
|
}
|
|
91
|
-
function
|
|
92
|
-
|
|
91
|
+
function isNetworkMountType(fsType) {
|
|
92
|
+
const type = fsType.toLowerCase();
|
|
93
|
+
return type.startsWith("nfs") || [
|
|
94
|
+
"cifs",
|
|
95
|
+
"smbfs",
|
|
96
|
+
"smb3",
|
|
97
|
+
"fuse.sshfs"
|
|
98
|
+
].includes(type);
|
|
93
99
|
}
|
|
94
|
-
function
|
|
100
|
+
function isNetworkMountEntryPath(targetPath) {
|
|
95
101
|
const mountEntry = readMountEntries().filter((entry) => isPathWithinMount(targetPath, entry.mountPoint)).toSorted((a, b) => b.mountPoint.length - a.mountPoint.length)[0];
|
|
96
|
-
return mountEntry ?
|
|
102
|
+
return mountEntry ? isNetworkMountType(mountEntry.fsType) : false;
|
|
97
103
|
}
|
|
98
|
-
function
|
|
99
|
-
if (typeof fs.statfsSync !== "function") return
|
|
104
|
+
function isNetworkBackedPath(targetPath) {
|
|
105
|
+
if (typeof fs.statfsSync !== "function") return isNetworkMountEntryPath(targetPath);
|
|
100
106
|
const checkedPath = findExistingVolumePath(targetPath);
|
|
101
107
|
if (!checkedPath) return false;
|
|
102
108
|
try {
|
|
103
|
-
if (
|
|
109
|
+
if ([
|
|
110
|
+
LINUX_NFS_SUPER_MAGIC,
|
|
111
|
+
4283649346,
|
|
112
|
+
4266872130,
|
|
113
|
+
20859
|
|
114
|
+
].includes(fs.statfsSync(checkedPath).type >>> 0)) return true;
|
|
104
115
|
} catch {
|
|
105
|
-
return
|
|
116
|
+
return isNetworkMountEntryPath(checkedPath);
|
|
106
117
|
}
|
|
107
|
-
return
|
|
108
|
-
}
|
|
109
|
-
function readJournalModeResult(row) {
|
|
110
|
-
if (!row || typeof row !== "object") return null;
|
|
111
|
-
const record = row;
|
|
112
|
-
const value = record.journal_mode ?? Object.values(record)[0];
|
|
113
|
-
return typeof value === "string" ? value.toLowerCase() : null;
|
|
114
|
-
}
|
|
115
|
-
function requireRollbackJournalMode(db, dbPath) {
|
|
116
|
-
const mode = readJournalModeResult(db.prepare("PRAGMA journal_mode = DELETE;").get());
|
|
117
|
-
if (mode !== "delete") throw new Error(`xopc.db at ${dbPath} is on an NFS-backed volume but SQLite kept journal_mode=${mode ?? "unknown"}. WAL mode is unsafe on NFS. Move ~/.xopc to a local filesystem, or set XOPC_STATE_DIR to a local path.`);
|
|
118
|
+
return isNetworkMountEntryPath(checkedPath);
|
|
118
119
|
}
|
|
119
120
|
function configureSqliteConnectionPragmas(db, options = {}) {
|
|
120
121
|
const busyTimeoutMs = options.busyTimeoutMs ?? XOPC_SQLITE_BUSY_TIMEOUT_MS;
|
|
121
122
|
db.exec(`PRAGMA busy_timeout = ${normalizeNonNegativeInteger(busyTimeoutMs, "busyTimeoutMs")};`);
|
|
122
|
-
if (options.databasePath && isNfsBackedPath(options.databasePath)) {
|
|
123
|
-
requireRollbackJournalMode(db, options.databasePath);
|
|
124
|
-
return {
|
|
125
|
-
checkpoint: () => true,
|
|
126
|
-
close: () => true
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
123
|
db.exec("PRAGMA journal_mode = WAL;");
|
|
130
124
|
const autoCheckpointPages = normalizeNonNegativeInteger(options.autoCheckpointPages ?? 1e3, "autoCheckpointPages");
|
|
131
125
|
db.exec(`PRAGMA wal_autocheckpoint = ${autoCheckpointPages};`);
|
|
@@ -136,8 +130,7 @@ function configureSqliteConnectionPragmas(db, options = {}) {
|
|
|
136
130
|
const checkpointIntervalMs = normalizeNonNegativeInteger(options.checkpointIntervalMs ?? 1800 * 1e3, "checkpointIntervalMs");
|
|
137
131
|
const runCheckpoint = (mode) => {
|
|
138
132
|
try {
|
|
139
|
-
db.
|
|
140
|
-
return true;
|
|
133
|
+
return db.prepare(`PRAGMA wal_checkpoint(${mode});`).get().busy === 0;
|
|
141
134
|
} catch (error) {
|
|
142
135
|
options.onCheckpointError?.(error);
|
|
143
136
|
return false;
|
|
@@ -174,29 +167,39 @@ function ensureDatabasePermissions(pathname) {
|
|
|
174
167
|
}
|
|
175
168
|
function openDatabaseAtPath(pathname) {
|
|
176
169
|
installSqliteTransientRejectionHandler();
|
|
170
|
+
if (pathname !== ":memory:" && isNetworkBackedPath(pathname)) throw new Error("SQLite requires a local filesystem; run the Gateway on the NAS instead of opening a network-mounted database.");
|
|
177
171
|
ensureDatabasePermissions(pathname);
|
|
178
172
|
const { DatabaseSync } = requireNodeSqlite();
|
|
179
173
|
const db = new DatabaseSync(pathname);
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
174
|
+
let walMaintenance;
|
|
175
|
+
try {
|
|
176
|
+
walMaintenance = configureSqliteConnectionPragmas(db, {
|
|
177
|
+
synchronous: "FULL",
|
|
178
|
+
foreignKeys: true,
|
|
179
|
+
onCheckpointError: (error) => {
|
|
180
|
+
const em = error instanceof Error ? error.message : String(error);
|
|
181
|
+
log.warn({
|
|
182
|
+
err: error instanceof Error ? error : void 0,
|
|
183
|
+
errorMessage: em
|
|
184
|
+
}, `SQLite WAL checkpoint failed: ${em}`);
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
ensureXopcDatabaseSchema(db, { databasePath: pathname });
|
|
188
|
+
ensureDatabasePermissions(pathname);
|
|
189
|
+
log.info({ path: pathname }, "Opened xopc SQLite database");
|
|
190
|
+
return {
|
|
191
|
+
db,
|
|
192
|
+
path: pathname,
|
|
193
|
+
walMaintenance
|
|
194
|
+
};
|
|
195
|
+
} catch (error) {
|
|
196
|
+
try {
|
|
197
|
+
walMaintenance?.close();
|
|
198
|
+
} finally {
|
|
199
|
+
db.close();
|
|
190
200
|
}
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
ensureDatabasePermissions(pathname);
|
|
194
|
-
log.info({ path: pathname }, "Opened xopc SQLite database");
|
|
195
|
-
return {
|
|
196
|
-
db,
|
|
197
|
-
path: pathname,
|
|
198
|
-
walMaintenance
|
|
199
|
-
};
|
|
201
|
+
throw error;
|
|
202
|
+
}
|
|
200
203
|
}
|
|
201
204
|
function openXopcDatabase(options = {}) {
|
|
202
205
|
const env = options.env ?? process.env;
|
|
@@ -59,7 +59,7 @@ function mergeAccountSourceData(db, connectorId, sourceAccountId, targetAccountI
|
|
|
59
59
|
`).run(targetId, sourceId);
|
|
60
60
|
db.prepare("DELETE FROM knowledge_consumer_watermarks WHERE source_instance_id = ?").run(sourceId);
|
|
61
61
|
db.prepare(`
|
|
62
|
-
UPDATE
|
|
62
|
+
UPDATE knowledge_items
|
|
63
63
|
SET source_json = json_set(source_json, '$.sourceInstanceId', ?)
|
|
64
64
|
WHERE json_extract(source_json, '$.sourceInstanceId') = ?
|
|
65
65
|
`).run(targetId, sourceId);
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export interface ContextEvidence {
|
|
2
|
+
id: string;
|
|
3
|
+
sourceType: 'conversation' | 'connector' | 'user' | 'runtime';
|
|
4
|
+
sourceInstanceId?: string;
|
|
5
|
+
sourceRef: string;
|
|
6
|
+
sourceRunId?: string;
|
|
7
|
+
sourceItemId?: string;
|
|
8
|
+
sessionId?: string;
|
|
9
|
+
turnId?: string;
|
|
10
|
+
messageId?: string;
|
|
11
|
+
contentHash?: string;
|
|
12
|
+
retentionPolicy?: string;
|
|
13
|
+
processingPolicy?: 'local_only' | 'remote_allowed';
|
|
14
|
+
extractorId?: string;
|
|
15
|
+
extractorVersion?: string;
|
|
16
|
+
redactedExcerpt?: string;
|
|
17
|
+
trustLevel: 'owner' | 'trusted' | 'untrusted';
|
|
18
|
+
observedAt: number;
|
|
19
|
+
ingestedAt: number;
|
|
20
|
+
createdAt: number;
|
|
21
|
+
}
|
|
22
|
+
export declare function createContextEvidence(input: Omit<ContextEvidence, 'id' | 'ingestedAt' | 'createdAt'> & {
|
|
23
|
+
ingestedAt?: number;
|
|
24
|
+
}, principalId?: string): ContextEvidence;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { getSqliteDatabase } from "./transaction.js";
|
|
2
|
+
import { USER_MODEL_PRINCIPAL_ID } from "../../user-model/domain.js";
|
|
3
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
4
|
+
//#region src/storage/sqlite/context-evidence-repository.ts
|
|
5
|
+
function fromRow(row) {
|
|
6
|
+
return {
|
|
7
|
+
id: row.evidence_id,
|
|
8
|
+
sourceType: row.source_type,
|
|
9
|
+
...row.source_instance_id ? { sourceInstanceId: row.source_instance_id } : {},
|
|
10
|
+
sourceRef: row.source_ref,
|
|
11
|
+
...row.source_run_id ? { sourceRunId: row.source_run_id } : {},
|
|
12
|
+
...row.source_item_id ? { sourceItemId: row.source_item_id } : {},
|
|
13
|
+
...row.session_id ? { sessionId: row.session_id } : {},
|
|
14
|
+
...row.turn_id ? { turnId: row.turn_id } : {},
|
|
15
|
+
...row.message_id ? { messageId: row.message_id } : {},
|
|
16
|
+
...row.content_hash ? { contentHash: row.content_hash } : {},
|
|
17
|
+
...row.retention_policy ? { retentionPolicy: row.retention_policy } : {},
|
|
18
|
+
...row.processing_policy ? { processingPolicy: row.processing_policy } : {},
|
|
19
|
+
...row.extractor_id ? { extractorId: row.extractor_id } : {},
|
|
20
|
+
...row.extractor_version ? { extractorVersion: row.extractor_version } : {},
|
|
21
|
+
...row.redacted_excerpt ? { redactedExcerpt: row.redacted_excerpt } : {},
|
|
22
|
+
trustLevel: row.trust_level,
|
|
23
|
+
observedAt: row.observed_at,
|
|
24
|
+
ingestedAt: row.ingested_at ?? row.created_at,
|
|
25
|
+
createdAt: row.created_at
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
function createContextEvidence(input, principalId = USER_MODEL_PRINCIPAL_ID) {
|
|
29
|
+
const db = getSqliteDatabase();
|
|
30
|
+
const existing = db.prepare(`SELECT * FROM context_evidence WHERE principal_id = ?
|
|
31
|
+
AND source_type = ? AND COALESCE(source_instance_id, '') = COALESCE(?, '') AND source_ref = ?`).get(principalId, input.sourceType, input.sourceInstanceId ?? null, input.sourceRef);
|
|
32
|
+
const contentHash = input.contentHash ?? (input.redactedExcerpt ? createHash("sha256").update(input.redactedExcerpt).digest("hex") : void 0);
|
|
33
|
+
if (existing) {
|
|
34
|
+
db.prepare(`UPDATE context_evidence SET
|
|
35
|
+
source_run_id = ?, source_item_id = ?, session_id = ?, turn_id = ?, message_id = ?,
|
|
36
|
+
content_hash = ?, retention_policy = ?, processing_policy = ?, extractor_id = ?,
|
|
37
|
+
extractor_version = ?, redacted_excerpt = ?, trust_level = ?, observed_at = ?, ingested_at = ?
|
|
38
|
+
WHERE evidence_id = ?`).run(input.sourceRunId ?? null, input.sourceItemId ?? null, input.sessionId ?? null, input.turnId ?? null, input.messageId ?? null, contentHash ?? null, input.retentionPolicy ?? null, input.processingPolicy ?? null, input.extractorId ?? null, input.extractorVersion ?? null, input.redactedExcerpt ?? null, input.trustLevel, input.observedAt, input.ingestedAt ?? Date.now(), existing.evidence_id);
|
|
39
|
+
return fromRow(db.prepare("SELECT * FROM context_evidence WHERE evidence_id = ?").get(existing.evidence_id));
|
|
40
|
+
}
|
|
41
|
+
const createdAt = Date.now();
|
|
42
|
+
const id = randomUUID();
|
|
43
|
+
db.prepare(`INSERT INTO context_evidence (
|
|
44
|
+
evidence_id, principal_id, source_type, source_instance_id, source_ref, source_run_id,
|
|
45
|
+
source_item_id, session_id, turn_id, message_id, content_hash, retention_policy,
|
|
46
|
+
processing_policy, extractor_id, extractor_version, redacted_excerpt, trust_level,
|
|
47
|
+
observed_at, ingested_at, created_at
|
|
48
|
+
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`).run(id, principalId, input.sourceType, input.sourceInstanceId ?? null, input.sourceRef, input.sourceRunId ?? null, input.sourceItemId ?? null, input.sessionId ?? null, input.turnId ?? null, input.messageId ?? null, contentHash ?? null, input.retentionPolicy ?? null, input.processingPolicy ?? null, input.extractorId ?? null, input.extractorVersion ?? null, input.redactedExcerpt ?? null, input.trustLevel, input.observedAt, input.ingestedAt ?? createdAt, createdAt);
|
|
49
|
+
return fromRow(db.prepare("SELECT * FROM context_evidence WHERE evidence_id = ?").get(id));
|
|
50
|
+
}
|
|
51
|
+
//#endregion
|
|
52
|
+
export { createContextEvidence };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare class DurableQueue<T> {
|
|
2
|
+
readonly queue: string;
|
|
3
|
+
readonly scope: string;
|
|
4
|
+
constructor(queue: string, scope: string);
|
|
5
|
+
enqueue(id: string, payload: T, now?: number): void;
|
|
6
|
+
pending(limit?: number): T[];
|
|
7
|
+
delete(id: string): void;
|
|
8
|
+
claim(leaseMs: number): {
|
|
9
|
+
id: string;
|
|
10
|
+
payload: T;
|
|
11
|
+
token: string;
|
|
12
|
+
} | null;
|
|
13
|
+
renew(id: string, token: string, leaseMs: number): boolean;
|
|
14
|
+
finish(id: string, token: string, success: boolean): void;
|
|
15
|
+
clearProcessed(olderThanMs?: number): number;
|
|
16
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { requireXopcDatabase } from "./connection.js";
|
|
2
|
+
import { runSqliteWriteTransaction } from "./transaction.js";
|
|
3
|
+
import { randomUUID } from "node:crypto";
|
|
4
|
+
//#region src/storage/sqlite/durable-queue.ts
|
|
5
|
+
var DurableQueue = class {
|
|
6
|
+
constructor(queue, scope) {
|
|
7
|
+
this.queue = queue;
|
|
8
|
+
this.scope = scope;
|
|
9
|
+
}
|
|
10
|
+
enqueue(id, payload, now = Date.now()) {
|
|
11
|
+
requireXopcDatabase().db.prepare(`INSERT INTO durable_messages(queue, scope, id, payload, enqueued_at)
|
|
12
|
+
VALUES (?, ?, ?, ?, ?) ON CONFLICT(queue, scope, id) DO NOTHING`).run(this.queue, this.scope, id, JSON.stringify(payload), now);
|
|
13
|
+
}
|
|
14
|
+
pending(limit = 2147483647) {
|
|
15
|
+
return requireXopcDatabase().db.prepare(`SELECT payload FROM durable_messages
|
|
16
|
+
WHERE queue = ? AND scope = ? AND processed_at IS NULL ORDER BY sequence LIMIT ?`).all(this.queue, this.scope, Math.max(0, Math.floor(limit))).map((row) => JSON.parse(row.payload));
|
|
17
|
+
}
|
|
18
|
+
delete(id) {
|
|
19
|
+
requireXopcDatabase().db.prepare("DELETE FROM durable_messages WHERE queue = ? AND scope = ? AND id = ?").run(this.queue, this.scope, id);
|
|
20
|
+
}
|
|
21
|
+
claim(leaseMs) {
|
|
22
|
+
requireXopcDatabase();
|
|
23
|
+
return runSqliteWriteTransaction((db) => {
|
|
24
|
+
const now = Date.now();
|
|
25
|
+
const row = db.prepare(`SELECT id, payload FROM durable_messages
|
|
26
|
+
WHERE queue = ? AND scope = ? AND processed_at IS NULL AND (lease_until IS NULL OR lease_until <= ?)
|
|
27
|
+
ORDER BY sequence LIMIT 1`).get(this.queue, this.scope, now);
|
|
28
|
+
if (!row) return null;
|
|
29
|
+
const token = randomUUID();
|
|
30
|
+
db.prepare("UPDATE durable_messages SET lease_token = ?, lease_until = ? WHERE queue = ? AND scope = ? AND id = ?").run(token, now + leaseMs, this.queue, this.scope, row.id);
|
|
31
|
+
return {
|
|
32
|
+
id: row.id,
|
|
33
|
+
payload: JSON.parse(row.payload),
|
|
34
|
+
token
|
|
35
|
+
};
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
renew(id, token, leaseMs) {
|
|
39
|
+
return requireXopcDatabase().db.prepare(`UPDATE durable_messages SET lease_until = ?
|
|
40
|
+
WHERE queue = ? AND scope = ? AND id = ? AND lease_token = ? AND processed_at IS NULL`).run(Date.now() + leaseMs, this.queue, this.scope, id, token).changes > 0;
|
|
41
|
+
}
|
|
42
|
+
finish(id, token, success) {
|
|
43
|
+
requireXopcDatabase().db.prepare(`UPDATE durable_messages SET processed_at = ?, lease_token = NULL, lease_until = NULL
|
|
44
|
+
WHERE queue = ? AND scope = ? AND id = ? AND lease_token = ?`).run(success ? Date.now() : null, this.queue, this.scope, id, token);
|
|
45
|
+
}
|
|
46
|
+
clearProcessed(olderThanMs) {
|
|
47
|
+
return Number(requireXopcDatabase().db.prepare(`DELETE FROM durable_messages
|
|
48
|
+
WHERE queue = ? AND scope = ? AND processed_at IS NOT NULL AND processed_at <= ?`).run(this.queue, this.scope, Date.now() - (olderThanMs ?? 0)).changes);
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
//#endregion
|
|
52
|
+
export { DurableQueue };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** Small namespaced extension/runtime documents. Domain histories use dedicated tables. */
|
|
2
|
+
export declare class DurableState<T> {
|
|
3
|
+
readonly namespace: string;
|
|
4
|
+
readonly scope: string;
|
|
5
|
+
constructor(namespace: string, scope?: string);
|
|
6
|
+
get(key: string): T | undefined;
|
|
7
|
+
set(key: string, value: T): void;
|
|
8
|
+
delete(key: string): boolean;
|
|
9
|
+
entries(): Array<[string, T]>;
|
|
10
|
+
[Symbol.iterator](): Iterator<[string, T]>;
|
|
11
|
+
values(limit?: number, newestFirst?: boolean): T[];
|
|
12
|
+
update<R>(key: string, operation: (value: T | undefined) => {
|
|
13
|
+
value: T | undefined;
|
|
14
|
+
result: R;
|
|
15
|
+
}): R;
|
|
16
|
+
}
|