@xopcai/xopc 0.0.248 → 0.0.250
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-DfBjTSo9.js} +1 -1
- package/dist/gateway/static/root/assets/{agent-avatar-dicebear-BmKxSM1k.js → agent-avatar-dicebear-BN6FJXkJ.js} +1 -1
- package/dist/gateway/static/root/assets/agent-defaults-settings-panel-C7rZH1A2.js +1 -0
- package/dist/gateway/static/root/assets/agents-CgGaoo4z.js +1 -0
- package/dist/gateway/static/root/assets/{api-B0-hLuZ1.js → api-zxpcJfgj.js} +1 -1
- package/dist/gateway/static/root/assets/app-management-settings-panel-D2gMshuS.js +1 -0
- package/dist/gateway/static/root/assets/appearance-settings-wMu0jSKx.js +1 -0
- package/dist/gateway/static/root/assets/apps-page-KF1Gnv36.js +1 -0
- package/dist/gateway/static/root/assets/{archive-plugin-BnMSgZvR.js → archive-plugin-u6EE3JV8.js} +1 -1
- package/dist/gateway/static/root/assets/{attachment-load-CejsQMev.js → attachment-load-DbJurnv-.js} +1 -1
- package/dist/gateway/static/root/assets/{automations-page-RC8EyoAf.js → automations-page-Ew_e5HDn.js} +1 -1
- package/dist/gateway/static/root/assets/automations-workspace-Ch-ldu35.js +6 -0
- package/dist/gateway/static/root/assets/{binary-plugins-DGjppLSG.js → binary-plugins-DtDFNfPM.js} +1 -1
- package/dist/gateway/static/root/assets/{block-editor-CWdP4bUc.js → block-editor-CnAwmabq.js} +44 -44
- package/dist/gateway/static/root/assets/browser-settings-page-DtVhsHJW.js +8 -0
- package/dist/gateway/static/root/assets/{browser-workflow-inputs-BQ1Ilw_o.js → browser-workflow-inputs-BX1-uM9L.js} +1 -1
- package/dist/gateway/static/root/assets/{browser-workflows-page-CJh4NyxT.js → browser-workflows-page-CcbUOWDF.js} +2 -2
- package/dist/gateway/static/root/assets/capabilities-settings-panel--sXeylhe.js +7 -0
- package/dist/gateway/static/root/assets/channels-settings-AXSBDujZ.js +1 -0
- package/dist/gateway/static/root/assets/{channels-status-swr-Ohhee4vm.js → channels-status-swr-CX-yWwLD.js} +1 -1
- package/dist/gateway/static/root/assets/{chat-terminal-dock-BOtoKTK3.js → chat-terminal-dock-CryTDNdD.js} +2 -2
- package/dist/gateway/static/root/assets/connectors-page-HBHUWohz.js +2 -0
- package/dist/gateway/static/root/assets/{cron-expression-DTj1V3Sw.js → cron-expression-ji5aWrjG.js} +1 -1
- package/dist/gateway/static/root/assets/{date-picker-Yr6OCvGL.js → date-picker-Dro_w3eX.js} +1 -1
- package/dist/gateway/static/root/assets/dependency-picker-Ce19KKnX.js +1 -0
- package/dist/gateway/static/root/assets/{desktop-pet-DbGzggPF.js → desktop-pet-DsSi-3uZ.js} +1 -1
- package/dist/gateway/static/root/assets/desktop-pet-settings-8WQ4woJy.js +1 -0
- package/dist/gateway/static/root/assets/{extension-debug-page-DgTtk4KC.js → extension-debug-page-CgvEBfLZ.js} +1 -1
- package/dist/gateway/static/root/assets/{extension-page-DtQeiP6f.js → extension-page-DkznBbMj.js} +1 -1
- package/dist/gateway/static/root/assets/extension-settings-page-BOjhchK2.js +1 -0
- package/dist/gateway/static/root/assets/files-BArWTfr7.js +1 -0
- package/dist/gateway/static/root/assets/gateway-config-api-OEruhhX3.js +1 -0
- package/dist/gateway/static/root/assets/{gateway-config-swr-DXuXtU1w.js → gateway-config-swr-CMNbl0FZ.js} +1 -1
- package/dist/gateway/static/root/assets/gateway-settings-BgH3A0LO.js +1 -0
- package/dist/gateway/static/root/assets/{gateway-startup-retry-CzBzglzQ.js → gateway-startup-retry-CR7Xg8As.js} +1 -1
- package/dist/gateway/static/root/assets/heartbeat-settings-C97naDkO.js +1 -0
- package/dist/gateway/static/root/assets/home-page-BBKKme4G.js +1 -0
- package/dist/gateway/static/root/assets/{image-generation-api-TIgsn04n.js → image-generation-api-C5mn73ca.js} +1 -1
- package/dist/gateway/static/root/assets/index-BcaF-dgQ.js +72 -0
- package/dist/gateway/static/root/assets/index-DAryGvZ7.css +2 -0
- package/dist/gateway/static/root/assets/{keyboard-shortcuts-settings-wsWuoa8p.js → keyboard-shortcuts-settings-BYhfzsqe.js} +1 -1
- package/dist/gateway/static/root/assets/local-app-workbench-page-DNncc2tn.js +2 -0
- package/dist/gateway/static/root/assets/{local-apps-page-CXrbrGo8.js → local-apps-page-vBlknU7C.js} +1 -1
- package/dist/gateway/static/root/assets/{locale-store-BJFLQY8O.js → locale-store-CF4erhjB.js} +1 -1
- package/dist/gateway/static/root/assets/logs-page-CizZInrT.js +2 -0
- package/dist/gateway/static/root/assets/{management-settings-BdJZFR7U.js → management-settings-Dnx6mSNe.js} +1 -1
- package/dist/gateway/static/root/assets/{markdown-split-NK3ACVG2.js → markdown-split-DtBtcHWi.js} +1 -1
- package/dist/gateway/static/root/assets/{markdown-view-DTF9v1gg.js → markdown-view-CQvzsE24.js} +1 -1
- package/dist/gateway/static/root/assets/{media-plugins-F0jcUxyl.js → media-plugins-DrMYeHe7.js} +1 -1
- package/dist/gateway/static/root/assets/messages-Cf5hpZE6.js +3 -0
- package/dist/gateway/static/root/assets/mobile-pairing-wizard-AKgGy3Kx.js +1 -0
- package/dist/gateway/static/root/assets/note-detail-panel-Bw3jD9Jf.js +5 -0
- package/dist/gateway/static/root/assets/notes-page-Dpqq7Z-J.js +8 -0
- package/dist/gateway/static/root/assets/page-tabs-CX9T71by.js +1 -0
- package/dist/gateway/static/root/assets/preview-open-alternatives-DvEHoimN.js +1 -0
- package/dist/gateway/static/root/assets/{product-open-page-CxGGlWA8.js → product-open-page-COcr_NUJ.js} +1 -1
- package/dist/gateway/static/root/assets/project-detail-page-BuT6MCTs.js +1 -0
- package/dist/gateway/static/root/assets/projects-page-DXWMxOjf.js +1 -0
- package/dist/gateway/static/root/assets/{registry-api-CIsNlSBi.js → registry-api-BsRBlji7.js} +1 -1
- package/dist/gateway/static/root/assets/remote-access-hub-7rBCUWzZ.js +1 -0
- package/dist/gateway/static/root/assets/{runtime-tools-settings-panel-YkjhiQfA.js → runtime-tools-settings-panel-CQ13P-mS.js} +2 -2
- package/dist/gateway/static/root/assets/{schema-form-oFGf3G3s.js → schema-form-BUVyTpZj.js} +1 -1
- package/dist/gateway/static/root/assets/sessions-page-gmEOYNb4.js +1 -0
- package/dist/gateway/static/root/assets/settings-advanced-gate-DYYoJcl7.js +1 -0
- package/dist/gateway/static/root/assets/settings-form-section-DVY-8_B9.js +1 -0
- package/dist/gateway/static/root/assets/{settings-page-C7VWs0IT.js → settings-page-CdiVYyTl.js} +1 -1
- package/dist/gateway/static/root/assets/setup-status-panel-BhenBnUj.js +1 -0
- package/dist/gateway/static/root/assets/{share-preview-page-t5oz18rh.js → share-preview-page-C88YLKm4.js} +1 -1
- package/dist/gateway/static/root/assets/shares-settings-Dq7xIj0_.js +1 -0
- package/dist/gateway/static/root/assets/skill-reload-api-MDI9Lz6z.js +1 -0
- package/dist/gateway/static/root/assets/skills-page-DLir1nM0.js +2 -0
- package/dist/gateway/static/root/assets/{skills-page.utils-DEDTYs2W.js → skills-page.utils-BMZAfS3G.js} +1 -1
- package/dist/gateway/static/root/assets/system-settings-panel-BM8ivYan.js +1 -0
- package/dist/gateway/static/root/assets/task-detail-page-P0_RldWv.js +1 -0
- package/dist/gateway/static/root/assets/{theme-store-O597U8q_.js → theme-store-BOgkc_9D.js} +1 -1
- package/dist/gateway/static/root/assets/tunnel-api-DemxChjo.js +1 -0
- package/dist/gateway/static/root/assets/{use-autosave-B5eUJ6Zq.js → use-autosave-CV3Ui5hu.js} +1 -1
- package/dist/gateway/static/root/assets/user-model-page-CxfnoRVn.js +2 -0
- package/dist/gateway/static/root/assets/{voice-api-key-field-CMKSwz4C.js → voice-api-key-field-CUoCi4Sq.js} +1 -1
- package/dist/gateway/static/root/assets/{voice-config-api-q7B6fOFB.js → voice-config-api-C-ryeIxj.js} +1 -1
- package/dist/gateway/static/root/assets/work-discovery-overlay-BhDlkCMB.js +1 -0
- package/dist/gateway/static/root/assets/{workflow-run-setup-panel-DZmvLZjb.js → workflow-run-setup-panel-D8CcPc_C.js} +2 -2
- package/dist/gateway/static/root/assets/workflows-page-Bxn2Dc16.js +5 -0
- package/dist/gateway/static/root/index.html +11 -27
- package/dist/package.js +1 -1
- package/dist/packages/gateway-contract/src/user-message-display.js +18 -0
- package/dist/src/agent/agent-instance-gateway.d.ts +3 -3
- package/dist/src/agent/agent-manager.d.ts +13 -13
- package/dist/src/agent/agent-manager.js +76 -42
- 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 +33 -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 +38 -0
- package/dist/src/agent/context/audit.js +123 -0
- package/dist/src/agent/context/coordinator.d.ts +31 -0
- package/dist/src/agent/context/coordinator.js +73 -0
- package/dist/src/agent/context/execution-context.d.ts +13 -0
- package/dist/src/agent/context/execution-context.js +211 -0
- package/dist/src/agent/context/execution-context.types.d.ts +50 -0
- package/dist/src/agent/context/execution-scope.d.ts +5 -1
- package/dist/src/agent/context/execution-scope.js +6 -2
- 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 +6 -3
- package/dist/src/agent/context/project-context.js +28 -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.d.ts +1 -0
- package/dist/src/agent/external-tools/index.js +2 -1
- package/dist/src/agent/external-tools/memory-provider.d.ts +1 -0
- package/dist/src/agent/external-tools/memory-provider.js +1 -0
- 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/inbound/attachment-pipeline.js +5 -1
- package/dist/src/agent/memory/compaction-policy.js +1 -1
- package/dist/src/agent/memory/compaction-promotion.d.ts +1 -0
- package/dist/src/agent/memory/compaction-promotion.js +52 -79
- package/dist/src/agent/memory/create-memory-manager.js +1 -3
- package/dist/src/agent/memory/index.d.ts +1 -6
- package/dist/src/agent/memory/index.js +3 -6
- 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.d.ts +0 -5
- package/dist/src/agent/memory/memory-config.js +2 -9
- 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/orchestration/context-overflow.js +1 -0
- 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.d.ts +2 -2
- package/dist/src/agent/service/direct-turn-helpers.js +8 -25
- package/dist/src/agent/service/process-direct-streaming.js +8 -7
- 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.d.ts +1 -0
- package/dist/src/agent/tools/factory.js +68 -21
- 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 +15 -0
- package/dist/src/agent/tools/knowledge-memory-tool.js +184 -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/session-search-tool.d.ts +1 -0
- package/dist/src/agent/tools/session-search-tool.js +7 -0
- package/dist/src/agent/tools/user-context-tool.d.ts +10 -0
- package/dist/src/agent/tools/user-context-tool.js +98 -0
- package/dist/src/agent/tools/xopc-use-tool.js +2 -2
- package/dist/src/automations/service/automation-service.d.ts +2 -1
- package/dist/src/automations/service/automation-service.js +6 -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 +43 -0
- package/dist/src/connectors/connection-recovery-service.js +420 -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/files/file-service.js +4 -1
- 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 +24 -18
- 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/files.js +23 -2
- 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 +3 -3
- 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/security/gateway-scopes.js +2 -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 +52 -17
- 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 +36 -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 +48 -0
- package/dist/src/knowledge-memory/repository.js +168 -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/notifications/planner.js +7 -3
- package/dist/src/proactive/actions/service.d.ts +0 -1
- package/dist/src/proactive/actions/service.js +1 -10
- package/dist/src/proactive/execution/context.d.ts +8 -10
- package/dist/src/proactive/execution/context.js +93 -42
- package/dist/src/proactive/execution/insight.d.ts +4 -1
- package/dist/src/proactive/execution/insight.js +5 -2
- package/dist/src/proactive/execution/repository.d.ts +1 -0
- package/dist/src/proactive/execution/repository.js +9 -1
- package/dist/src/proactive/execution/types.d.ts +0 -1
- package/dist/src/proactive/execution/worker.js +7 -5
- package/dist/src/proactive/inbox/repository.js +8 -2
- package/dist/src/proactive/inbox/service.js +2 -2
- package/dist/src/proactive/inbox/types.d.ts +1 -0
- package/dist/src/proactive/inbox/worker.d.ts +1 -0
- package/dist/src/proactive/inbox/worker.js +7 -0
- package/dist/src/proactive/index.d.ts +2 -1
- package/dist/src/proactive/index.js +3 -2
- package/dist/src/proactive/maintenance.d.ts +4 -0
- package/dist/src/proactive/maintenance.js +21 -0
- package/dist/src/proactive/scenarios/repository.d.ts +1 -1
- package/dist/src/proactive/scenarios/repository.js +10 -3
- package/dist/src/proactive/scenarios/types.d.ts +7 -0
- package/dist/src/proactive/service.d.ts +7 -0
- package/dist/src/proactive/service.js +17 -1
- 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-service.d.ts +2 -1
- package/dist/src/projects/project-service.js +3 -2
- 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/session/index.js +1 -1
- package/dist/src/session/store.js +5 -2
- package/dist/src/storage/sqlite/collaboration-rule-repository.d.ts +19 -0
- package/dist/src/storage/sqlite/collaboration-rule-repository.js +54 -0
- package/dist/src/storage/sqlite/config-repository.js +1 -1
- 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 +6 -8
- 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/151_proactive_scope_cleanup.sql +6 -0
- package/dist/src/storage/sqlite/migrations/152_proactive_scenario_contract.sql +140 -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/row-mappers.js +2 -2
- 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 +17 -14
- package/dist/src/storage/sqlite/session-instance-repository.d.ts +2 -0
- package/dist/src/storage/sqlite/session-instance-repository.js +6 -0
- package/dist/src/storage/sqlite/session-repository.d.ts +1 -1
- package/dist/src/storage/sqlite/session-repository.js +7 -6
- package/dist/src/storage/sqlite/transcript-repository.js +3 -2
- package/dist/src/tasks/home-query-service.js +35 -13
- package/dist/src/tasks/index.js +2 -2
- package/dist/src/tasks/project-monitoring-service.d.ts +2 -0
- package/dist/src/tasks/project-monitoring-service.js +4 -1
- 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/backends/embedded-backend.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/access-policy.d.ts +11 -0
- package/dist/src/user-context/access-policy.js +26 -0
- 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 +50 -0
- package/dist/src/user-model/capture/executor.js +230 -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 +39 -0
- package/dist/src/user-model/capture/semantic.js +263 -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 +62 -0
- package/dist/src/user-model/goals.js +91 -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 +3 -3
- 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/files-D6vf3S30.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-app-workbench-page-CpyvYyrb.js +0 -2
- 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/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 → context/execution-context.types.js} +0 -0
- /package/dist/src/{agent/memory/understanding/types.js → knowledge-memory/domain.js} +0 -0
|
@@ -1,34 +1,48 @@
|
|
|
1
|
-
import { USER_FACING_UNDERSTANDING_WRITING_GUIDANCE } from "../../user-context/understanding-writing.js";
|
|
2
1
|
//#region src/agent/background-review/prompts.ts
|
|
3
|
-
const
|
|
4
|
-
function
|
|
5
|
-
const targets = options.availableTargets?.length ? `\
|
|
2
|
+
const USER_MODEL_INTERPRETER_SYSTEM_PROMPT = `You are xopc's user-model interpreter. You do not chat with the user and cannot write storage. Distinguish explicit memory commands, corrections, forgetting, durable user assertions, durable goals, collaboration rules, and ordinary task requests. Return strict JSON only. Assistant text is never evidence about the user.`;
|
|
3
|
+
function buildUserModelInterpreterPrompt(options) {
|
|
4
|
+
const targets = options.availableTargets?.length ? `\nThese assertion IDs may be targeted for confirm, correction, or forgetting:\n${options.availableTargets.map((item) => `- ${item.id}: ${item.statement}`).join("\n")}` : "\nNo existing assertion IDs are available to target.";
|
|
6
5
|
return `Interpret the evidence-tagged conversation above for ${options.mode === "turn" ? "the latest user turn" : "durable transcript synthesis"}.
|
|
7
6
|
|
|
8
|
-
|
|
9
|
-
{
|
|
7
|
+
Evidence time: ${options.evidenceTimestamp}
|
|
8
|
+
User timezone: ${options.timezone}
|
|
10
9
|
|
|
11
|
-
|
|
10
|
+
Return exactly this top-level shape:
|
|
11
|
+
{"intent":"none","candidates":[],"goals":[],"collaborationRules":[],"targetAssertionIds":[],"abstentionReason":"..."}
|
|
12
12
|
|
|
13
13
|
Candidate shape:
|
|
14
|
-
{"
|
|
14
|
+
{"subject":{"type":"user","id":"self"},"predicate":"preference.response.detail","cardinality":"single","scope":{"type":"global"},"kind":"preference","value":"concise","normalizedValue":"concise","statement":"The user prefers concise answers.","authority":"user_observed","confidence":0.9,"declaredImportance":0.8,"inferredImportance":0.6,"consequence":"medium","actionability":1,"volatility":"stable","sensitivity":"normal","disclosurePolicy":"referenceable","applicability":{"operation":"response"},"temporalResolution":"exact","evidence":[{"ref":"entry-id","quote":"exact quote"}],"selfContained":true,"unresolvedReferences":[]}
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
Goal shape:
|
|
17
|
+
{"title":"Ship Atlas","desiredOutcome":"Atlas is released with all acceptance checks passing.","scope":{"type":"project","id":"exact-project-id"},"declaredImportance":0.9,"targetAt":"2026-09-30T18:00:00+08:00","evidence":[{"ref":"entry-id","quote":"exact quote"}],"selfContained":true,"unresolvedReferences":[]}
|
|
18
|
+
|
|
19
|
+
Collaboration rule shape:
|
|
20
|
+
{"category":"communication","priority":10,"scope":{"type":"global"},"conditions":{"enforcementLevel":"prompt"},"statement":"Keep status updates concise.","evidence":[{"ref":"entry-id","quote":"exact quote"}],"selfContained":true,"unresolvedReferences":[]}
|
|
21
|
+
|
|
22
|
+
Allowed intents: remember, query, confirm, correct, forget, user_assertion, task, none.
|
|
23
|
+
Allowed subject types: user, person, goal, project, topic.
|
|
24
|
+
Allowed kinds: identity, preference, value, routine, capability, relationship, current_state, derived_insight.
|
|
25
|
+
Allowed scopes: global without id; agent, workspace, project, or session with the exact supplied id.
|
|
17
26
|
|
|
18
27
|
Rules:
|
|
19
|
-
- A question
|
|
20
|
-
- A request to create, summarize, update, investigate, or track
|
|
21
|
-
- Every candidate needs an exact quote from
|
|
22
|
-
- Extract zero to eight independent candidates
|
|
23
|
-
-
|
|
24
|
-
-
|
|
28
|
+
- A question about what is remembered uses query and creates no candidate.
|
|
29
|
+
- A request to create, summarize, update, investigate, or track work uses task, not a user assertion.
|
|
30
|
+
- Every candidate needs an exact quote from a user message. Assistant messages can resolve context but are never evidence.
|
|
31
|
+
- Extract zero to eight independent candidates. Each candidate represents one stable predicate and one value.
|
|
32
|
+
- Extract a goal only when the user explicitly describes a durable desired outcome, not a one-off task request.
|
|
33
|
+
- Extract a collaboration rule only when the user explicitly states an ongoing way the assistant should communicate, execute, or respect a boundary.
|
|
34
|
+
- Use only prompt enforcement for inferred collaboration rules. Never invent tool gates or deny effects.
|
|
35
|
+
- predicate is a stable language-neutral lowercase identifier. The value is excluded from predicate identity.
|
|
36
|
+
- Preserve importance stated by the user in declaredImportance; estimate inferredImportance separately.
|
|
37
|
+
- Use current_state or event volatility only with a bounded validTo. If relative time cannot be resolved, use temporalResolution=unresolved and omit resolved time fields.
|
|
38
|
+
- Resolve relative time using the evidence time and timezone. Put ISO 8601 timestamps with offsets in validFrom, validTo, and reviewAt.
|
|
39
|
+
- For an explicit correction, set correctionOfAssertionId on the replacement candidate.
|
|
40
|
+
- Set selfContained=false and list unresolvedReferences for unresolved pronouns or references.
|
|
25
41
|
- Omit temporary reactions and one-off task instructions.
|
|
26
42
|
- Never include passwords, credentials, regulated identifiers, or speculative diagnoses.
|
|
27
|
-
-
|
|
43
|
+
- In transcript mode, use system_inferred unless a quoted user message is itself an explicit memory command.
|
|
28
44
|
- If evidence is insufficient, return candidates=[] and explain abstentionReason.
|
|
29
|
-
|
|
30
|
-
${USER_FACING_UNDERSTANDING_WRITING_GUIDANCE}
|
|
31
45
|
${targets}`;
|
|
32
46
|
}
|
|
33
47
|
//#endregion
|
|
34
|
-
export {
|
|
48
|
+
export { USER_MODEL_INTERPRETER_SYSTEM_PROMPT, buildUserModelInterpreterPrompt };
|
|
@@ -1,19 +1,18 @@
|
|
|
1
1
|
import { Agent } from '@earendil-works/pi-agent-core';
|
|
2
2
|
import type { Config } from '../../config/schema.js';
|
|
3
|
-
import type
|
|
4
|
-
import type { UnderstandingReviewResult } from '../memory/understanding/types.js';
|
|
3
|
+
import { type UserModelCaptureResult } from '../../user-model/capture/index.js';
|
|
5
4
|
import type { BackgroundReviewSettings } from './settings.js';
|
|
6
|
-
export interface
|
|
5
|
+
export interface RunUserModelReviewParams {
|
|
7
6
|
sessionKey: string;
|
|
8
7
|
mainAgent: Agent;
|
|
9
8
|
settings: BackgroundReviewSettings;
|
|
10
|
-
|
|
9
|
+
workspaceId: string;
|
|
11
10
|
getConfig: () => Config | undefined;
|
|
12
11
|
}
|
|
13
|
-
export interface
|
|
12
|
+
export interface RunTurnUserModelCaptureParams extends Omit<RunUserModelReviewParams, 'settings'> {
|
|
14
13
|
turnId: string;
|
|
15
14
|
userText: string;
|
|
16
15
|
maxHistoryMessages?: number;
|
|
17
16
|
}
|
|
18
|
-
export declare function
|
|
19
|
-
export declare function
|
|
17
|
+
export declare function runTurnUserModelCapture(params: RunTurnUserModelCaptureParams): Promise<UserModelCaptureResult>;
|
|
18
|
+
export declare function runBackgroundUserModelReview(params: RunUserModelReviewParams): Promise<void>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createLogger } from "../../utils/logger/index.js";
|
|
2
2
|
import { init_logger } from "../../utils/logger.js";
|
|
3
3
|
import { finishContextExtractionRun } from "../../storage/sqlite/context-extraction-repository.js";
|
|
4
|
-
import {
|
|
4
|
+
import { getSessionMetadata } from "../../storage/sqlite/session-repository.js";
|
|
5
5
|
import { loadCompactionSourceSnapshot } from "../../storage/sqlite/transcript-repository.js";
|
|
6
6
|
import "../../storage/sqlite/index.js";
|
|
7
7
|
import { extractProfileAgentId } from "../../config/agent-profile.js";
|
|
@@ -9,20 +9,22 @@ import { init_sync_provider_auth, resolveProviderApiKeySync } from "../../auth/s
|
|
|
9
9
|
import { getApiKeySync, init_providers, resolveModel } from "../../providers/index.js";
|
|
10
10
|
import { createExtensionAwareStreamFn } from "../../providers/extension-stream-bridge.js";
|
|
11
11
|
import { extractTextContent } from "../context/workspace.js";
|
|
12
|
+
import { listUserAssertions } from "../../user-model/repository.js";
|
|
12
13
|
import { readAgentMessageContent } from "../memory/agent-message-access.js";
|
|
13
14
|
import { isAssistantTurnAborted, isAssistantTurnFailed } from "../orchestration/llm-turn-retry.js";
|
|
14
15
|
import { resolveAgentTurnTimeoutMs, runAgentTurnWithTimeout } from "../orchestration/run-agent-turn-with-timeout.js";
|
|
15
|
-
import { claimRegisteredExtraction } from "../../user-context/extraction/registry.js";
|
|
16
16
|
import { resolveModelIntentRef } from "../../config/agent-model-intents.js";
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
17
|
+
import { claimRegisteredExtraction } from "../../user-context/extraction/registry.js";
|
|
18
|
+
import { emptyUserModelCaptureResult, executeUserModelInterpretation } from "../../user-model/capture/executor.js";
|
|
19
|
+
import { parseUserModelInterpretation } from "../../user-model/capture/semantic.js";
|
|
20
|
+
import "../../user-model/capture/index.js";
|
|
21
|
+
import { USER_MODEL_INTERPRETER_SYSTEM_PROMPT, buildUserModelInterpreterPrompt } from "./prompts.js";
|
|
20
22
|
import { Agent } from "@earendil-works/pi-agent-core";
|
|
21
23
|
//#region src/agent/background-review/run-background-review.ts
|
|
22
24
|
init_sync_provider_auth();
|
|
23
25
|
init_providers();
|
|
24
26
|
init_logger();
|
|
25
|
-
const log = createLogger("
|
|
27
|
+
const log = createLogger("UserModelInterpreter");
|
|
26
28
|
function isReviewMessage(value) {
|
|
27
29
|
if (!value || typeof value !== "object") return false;
|
|
28
30
|
const role = value.role;
|
|
@@ -91,7 +93,7 @@ function isLocalModel(model) {
|
|
|
91
93
|
}
|
|
92
94
|
function resolveInterpreterRuntime(params) {
|
|
93
95
|
const config = params.getConfig();
|
|
94
|
-
const processingPolicy = config?.userContext.
|
|
96
|
+
const processingPolicy = config?.userContext.userModel.processingPolicy ?? "remote_allowed";
|
|
95
97
|
let model;
|
|
96
98
|
if (config) {
|
|
97
99
|
const agentId = extractProfileAgentId(params.sessionKey, config);
|
|
@@ -124,7 +126,7 @@ function resolveInterpreterRuntime(params) {
|
|
|
124
126
|
async function interpret(params) {
|
|
125
127
|
const reviewAgent = new Agent({
|
|
126
128
|
initialState: {
|
|
127
|
-
systemPrompt:
|
|
129
|
+
systemPrompt: USER_MODEL_INTERPRETER_SYSTEM_PROMPT,
|
|
128
130
|
model: params.model,
|
|
129
131
|
thinkingLevel: "off",
|
|
130
132
|
tools: [],
|
|
@@ -136,11 +138,14 @@ async function interpret(params) {
|
|
|
136
138
|
reviewAgent.state.messages = params.evidence.map(tagMessage);
|
|
137
139
|
try {
|
|
138
140
|
await runAgentTurnWithTimeout(reviewAgent, async () => {
|
|
141
|
+
const timezone = params.getConfig()?.userContext.userModel.maintenance.timezone ?? Intl.DateTimeFormat().resolvedOptions().timeZone ?? "UTC";
|
|
139
142
|
await reviewAgent.prompt({
|
|
140
143
|
role: "user",
|
|
141
|
-
content:
|
|
144
|
+
content: buildUserModelInterpreterPrompt({
|
|
142
145
|
mode: params.mode,
|
|
143
|
-
availableTargets: params.availableTargets
|
|
146
|
+
availableTargets: params.availableTargets,
|
|
147
|
+
evidenceTimestamp: new Date(params.evidence.at(-1)?.createdAt ?? Date.now()).toISOString(),
|
|
148
|
+
timezone
|
|
144
149
|
}),
|
|
145
150
|
timestamp: Date.now()
|
|
146
151
|
});
|
|
@@ -156,11 +161,11 @@ async function interpret(params) {
|
|
|
156
161
|
return null;
|
|
157
162
|
}
|
|
158
163
|
if (isAssistantTurnAborted(reviewAgent) || isAssistantTurnFailed(reviewAgent)) return null;
|
|
159
|
-
return
|
|
164
|
+
return parseUserModelInterpretation(lastAssistantText(reviewAgent), params.evidence, params.availableTargets.map((item) => item.id));
|
|
160
165
|
}
|
|
161
166
|
async function executeReview(params) {
|
|
162
167
|
const runtime = resolveInterpreterRuntime(params);
|
|
163
|
-
if (!runtime) return
|
|
168
|
+
if (!runtime) return emptyUserModelCaptureResult();
|
|
164
169
|
const extraction = claimRegisteredExtraction({
|
|
165
170
|
extractorId: params.extractorId,
|
|
166
171
|
sourceRef: params.sourceRef,
|
|
@@ -168,7 +173,7 @@ async function executeReview(params) {
|
|
|
168
173
|
processingPolicy: runtime.processingPolicy,
|
|
169
174
|
destination: runtime.destination
|
|
170
175
|
});
|
|
171
|
-
if (!extraction.shouldExecute) return
|
|
176
|
+
if (!extraction.shouldExecute) return emptyUserModelCaptureResult();
|
|
172
177
|
const interpretation = await interpret({
|
|
173
178
|
...params,
|
|
174
179
|
model: runtime.model
|
|
@@ -179,32 +184,36 @@ async function executeReview(params) {
|
|
|
179
184
|
status: "failed",
|
|
180
185
|
errorCode: "model_or_schema_failed"
|
|
181
186
|
});
|
|
182
|
-
return
|
|
187
|
+
return emptyUserModelCaptureResult();
|
|
183
188
|
}
|
|
184
189
|
try {
|
|
185
|
-
const
|
|
190
|
+
const config = params.getConfig();
|
|
191
|
+
const agentId = config ? extractProfileAgentId(params.sessionKey, config) : "main";
|
|
192
|
+
const write = config?.userContext.userModel.writePolicy ?? "deny";
|
|
193
|
+
const result = executeUserModelInterpretation({
|
|
186
194
|
interpretation,
|
|
187
195
|
evidence: params.evidence,
|
|
188
196
|
extractionRunId: extraction.run.id,
|
|
189
197
|
extractorId: params.extractorId,
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
198
|
+
scopeContext: {
|
|
199
|
+
sessionId: params.sessionKey,
|
|
200
|
+
agentId,
|
|
201
|
+
workspaceId: params.workspaceId,
|
|
202
|
+
...getSessionMetadata(params.sessionKey)?.projectId ? { projectId: getSessionMetadata(params.sessionKey).projectId } : {}
|
|
203
|
+
},
|
|
204
|
+
policy: {
|
|
205
|
+
write,
|
|
206
|
+
sensitiveWrite: config?.userContext.userModel.sensitiveWritePolicy ?? "confirm",
|
|
207
|
+
processing: runtime.processingPolicy
|
|
208
|
+
},
|
|
209
|
+
...params.turnId ? { turnId: params.turnId } : {}
|
|
196
210
|
});
|
|
197
211
|
finishContextExtractionRun({
|
|
198
212
|
runId: extraction.run.id,
|
|
199
213
|
status: "completed",
|
|
200
|
-
outputs: result.
|
|
214
|
+
outputs: result.outputs.map((output) => ({
|
|
201
215
|
candidateKey: output.candidateKey,
|
|
202
|
-
|
|
203
|
-
objectType: "understanding",
|
|
204
|
-
objectId: output.objectId
|
|
205
|
-
} : {},
|
|
206
|
-
...output.versionId ? { versionId: output.versionId } : {},
|
|
207
|
-
outcome: output.outcome
|
|
216
|
+
outcome: output.outcome === "deduplicated" ? "deduplicated" : output.outcome === "rejected" ? "rejected" : "created"
|
|
208
217
|
}))
|
|
209
218
|
});
|
|
210
219
|
return result;
|
|
@@ -217,20 +226,17 @@ async function executeReview(params) {
|
|
|
217
226
|
throw err;
|
|
218
227
|
}
|
|
219
228
|
}
|
|
220
|
-
async function
|
|
229
|
+
async function runTurnUserModelCapture(params) {
|
|
221
230
|
const evidence = loadEvidenceMessages(params.sessionKey, params.maxHistoryMessages ?? 12);
|
|
222
|
-
if (!evidence.length) return
|
|
223
|
-
const availableTargets =
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
statement: item.content
|
|
228
|
-
}];
|
|
229
|
-
}) ?? [];
|
|
231
|
+
if (!evidence.length) return emptyUserModelCaptureResult();
|
|
232
|
+
const availableTargets = listUserAssertions({ limit: 200 }).map((item) => ({
|
|
233
|
+
id: item.id,
|
|
234
|
+
statement: item.statement
|
|
235
|
+
}));
|
|
230
236
|
return executeReview({
|
|
231
237
|
sessionKey: params.sessionKey,
|
|
232
238
|
mainAgent: params.mainAgent,
|
|
233
|
-
|
|
239
|
+
workspaceId: params.workspaceId,
|
|
234
240
|
getConfig: params.getConfig,
|
|
235
241
|
evidence,
|
|
236
242
|
mode: "turn",
|
|
@@ -242,7 +248,7 @@ async function runTurnUnderstandingReview(params) {
|
|
|
242
248
|
turnId: params.turnId
|
|
243
249
|
});
|
|
244
250
|
}
|
|
245
|
-
async function
|
|
251
|
+
async function runBackgroundUserModelReview(params) {
|
|
246
252
|
const evidence = loadEvidenceMessages(params.sessionKey, params.settings.maxHistoryMessages);
|
|
247
253
|
if (!evidence.length) return;
|
|
248
254
|
const first = evidence[0];
|
|
@@ -250,7 +256,7 @@ async function runBackgroundReviewTurn(params) {
|
|
|
250
256
|
await executeReview({
|
|
251
257
|
sessionKey: params.sessionKey,
|
|
252
258
|
mainAgent: params.mainAgent,
|
|
253
|
-
|
|
259
|
+
workspaceId: params.workspaceId,
|
|
254
260
|
getConfig: params.getConfig,
|
|
255
261
|
evidence,
|
|
256
262
|
mode: "transcript",
|
|
@@ -262,4 +268,4 @@ async function runBackgroundReviewTurn(params) {
|
|
|
262
268
|
});
|
|
263
269
|
}
|
|
264
270
|
//#endregion
|
|
265
|
-
export {
|
|
271
|
+
export { runBackgroundUserModelReview, runTurnUserModelCapture };
|
|
@@ -1,20 +1,19 @@
|
|
|
1
1
|
//#region src/agent/background-review/settings.ts
|
|
2
2
|
const DEFAULT_SETTINGS = {
|
|
3
3
|
enabled: false,
|
|
4
|
-
adaptiveCadence: true,
|
|
5
4
|
reviewIntervalTurns: 10,
|
|
6
5
|
maxHistoryMessages: 80,
|
|
7
6
|
maxDurationMs: 12e4
|
|
8
7
|
};
|
|
9
8
|
function resolveBackgroundReviewSettings(config) {
|
|
10
9
|
if (!config) return DEFAULT_SETTINGS;
|
|
11
|
-
const
|
|
10
|
+
const userModel = config.userContext.userModel;
|
|
11
|
+
const extraction = userModel.extraction;
|
|
12
12
|
return {
|
|
13
|
-
enabled: config.userContext.enabled &&
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
maxDurationMs: understanding.maxDurationMs
|
|
13
|
+
enabled: config.userContext.enabled && userModel.enabled,
|
|
14
|
+
reviewIntervalTurns: extraction.reviewIntervalTurns,
|
|
15
|
+
maxHistoryMessages: extraction.maxHistoryMessages,
|
|
16
|
+
maxDurationMs: extraction.maxDurationMs
|
|
18
17
|
};
|
|
19
18
|
}
|
|
20
19
|
//#endregion
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { ExecutionContext } from './execution-context.types.js';
|
|
2
|
+
export interface ExecutionContextBudget {
|
|
3
|
+
maxAssertions: number;
|
|
4
|
+
maxKnowledge: number;
|
|
5
|
+
maxChars: number;
|
|
6
|
+
}
|
|
7
|
+
export interface ExecutionContextAudit {
|
|
8
|
+
runId: string;
|
|
9
|
+
principalId: string;
|
|
10
|
+
turnId: string;
|
|
11
|
+
sessionId: string;
|
|
12
|
+
queryHash: string;
|
|
13
|
+
asOf: number;
|
|
14
|
+
budget: ExecutionContextBudget;
|
|
15
|
+
metrics: Record<string, number>;
|
|
16
|
+
items: Array<{
|
|
17
|
+
objectType: 'rule' | 'assertion' | 'goal' | 'priority' | 'knowledge';
|
|
18
|
+
objectId: string;
|
|
19
|
+
score?: number;
|
|
20
|
+
reasons: string[];
|
|
21
|
+
included: boolean;
|
|
22
|
+
}>;
|
|
23
|
+
createdAt: number;
|
|
24
|
+
}
|
|
25
|
+
export declare function recordExecutionContext(context: ExecutionContext, input: {
|
|
26
|
+
turnId: string;
|
|
27
|
+
sessionId: string;
|
|
28
|
+
budget: ExecutionContextBudget;
|
|
29
|
+
renderedChars: number;
|
|
30
|
+
includedContext?: ExecutionContext;
|
|
31
|
+
}): void;
|
|
32
|
+
export declare function getExecutionContextAudit(turnId: string): ExecutionContextAudit | undefined;
|
|
33
|
+
export declare function recordExecutionContextFeedback(input: {
|
|
34
|
+
turnId: string;
|
|
35
|
+
rating: 'helpful' | 'irrelevant';
|
|
36
|
+
reason?: string;
|
|
37
|
+
}): boolean;
|
|
38
|
+
export declare function getExecutionContextFeedbackScores(): Map<string, number>;
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { getSqliteDatabase, runSqliteWriteTransaction } from "../../storage/sqlite/transaction.js";
|
|
2
|
+
import { createHash } from "node:crypto";
|
|
3
|
+
//#region src/agent/context/audit.ts
|
|
4
|
+
function recordExecutionContext(context, input) {
|
|
5
|
+
const createdAt = Date.now();
|
|
6
|
+
const included = /* @__PURE__ */ new Set();
|
|
7
|
+
const selected = input.includedContext ?? context;
|
|
8
|
+
for (const item of selected.rules) included.add(`rule:${item.id}`);
|
|
9
|
+
for (const item of selected.assertions) included.add(`assertion:${item.assertion.id}`);
|
|
10
|
+
for (const item of selected.goals) included.add(`goal:${item.id}`);
|
|
11
|
+
for (const item of selected.priorities) included.add(`priority:${item.id}`);
|
|
12
|
+
for (const item of selected.knowledge) included.add(`knowledge:${item.id}`);
|
|
13
|
+
const items = [
|
|
14
|
+
...context.rules.map((item) => ({
|
|
15
|
+
objectType: "rule",
|
|
16
|
+
objectId: item.id,
|
|
17
|
+
reasons: [`${item.enforcementLevel}_rule`],
|
|
18
|
+
included: included.has(`rule:${item.id}`)
|
|
19
|
+
})),
|
|
20
|
+
...context.assertions.map((item) => ({
|
|
21
|
+
objectType: "assertion",
|
|
22
|
+
objectId: item.assertion.id,
|
|
23
|
+
score: item.score,
|
|
24
|
+
reasons: item.reasons,
|
|
25
|
+
included: included.has(`assertion:${item.assertion.id}`)
|
|
26
|
+
})),
|
|
27
|
+
...context.goals.map((item) => ({
|
|
28
|
+
objectType: "goal",
|
|
29
|
+
objectId: item.id,
|
|
30
|
+
reasons: ["active_goal"],
|
|
31
|
+
included: included.has(`goal:${item.id}`)
|
|
32
|
+
})),
|
|
33
|
+
...context.priorities.map((item) => ({
|
|
34
|
+
objectType: "priority",
|
|
35
|
+
objectId: item.id,
|
|
36
|
+
score: item.urgency,
|
|
37
|
+
reasons: [`${item.rank}_priority`],
|
|
38
|
+
included: included.has(`priority:${item.id}`)
|
|
39
|
+
})),
|
|
40
|
+
...context.knowledge.map((item) => ({
|
|
41
|
+
objectType: "knowledge",
|
|
42
|
+
objectId: item.id,
|
|
43
|
+
score: item.importance,
|
|
44
|
+
reasons: ["task_relevant_knowledge"],
|
|
45
|
+
included: included.has(`knowledge:${item.id}`)
|
|
46
|
+
}))
|
|
47
|
+
];
|
|
48
|
+
const metrics = {
|
|
49
|
+
rules: context.rules.length,
|
|
50
|
+
assertions: context.assertions.length,
|
|
51
|
+
goals: context.goals.length,
|
|
52
|
+
priorities: context.priorities.length,
|
|
53
|
+
knowledge: context.knowledge.length,
|
|
54
|
+
includedRules: selected.rules.length,
|
|
55
|
+
includedAssertions: selected.assertions.length,
|
|
56
|
+
includedGoals: selected.goals.length,
|
|
57
|
+
includedPriorities: selected.priorities.length,
|
|
58
|
+
includedKnowledge: selected.knowledge.length,
|
|
59
|
+
renderedChars: input.renderedChars
|
|
60
|
+
};
|
|
61
|
+
runSqliteWriteTransaction((db) => {
|
|
62
|
+
if (db.prepare("SELECT 1 FROM execution_context_runs WHERE turn_id = ?").get(input.turnId)) return;
|
|
63
|
+
db.prepare(`INSERT INTO execution_context_runs (
|
|
64
|
+
run_id, principal_id, turn_id, session_id, query_hash, as_of,
|
|
65
|
+
budget_json, metrics_json, created_at
|
|
66
|
+
) VALUES (?, 'local-owner', ?, ?, ?, ?, ?, ?, ?)`).run(context.traceId, input.turnId, input.sessionId, createHash("sha256").update(context.query).digest("hex"), context.asOf, JSON.stringify(input.budget), JSON.stringify(metrics), createdAt);
|
|
67
|
+
const insert = db.prepare(`INSERT INTO execution_context_items (
|
|
68
|
+
run_id, object_type, object_id, score, reasons_json, included, created_at
|
|
69
|
+
) VALUES (?, ?, ?, ?, ?, ?, ?)`);
|
|
70
|
+
for (const item of items) insert.run(context.traceId, item.objectType, item.objectId, item.score ?? null, JSON.stringify(item.reasons), item.included ? 1 : 0, createdAt);
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
function getExecutionContextAudit(turnId) {
|
|
74
|
+
const db = getSqliteDatabase();
|
|
75
|
+
const run = db.prepare("SELECT * FROM execution_context_runs WHERE turn_id = ?").get(turnId);
|
|
76
|
+
if (!run) return void 0;
|
|
77
|
+
const rows = db.prepare(`SELECT object_type, object_id, score, reasons_json, included
|
|
78
|
+
FROM execution_context_items WHERE run_id = ? ORDER BY rowid`).all(run.run_id);
|
|
79
|
+
return {
|
|
80
|
+
runId: run.run_id,
|
|
81
|
+
principalId: run.principal_id,
|
|
82
|
+
turnId: run.turn_id,
|
|
83
|
+
sessionId: run.session_id,
|
|
84
|
+
queryHash: run.query_hash,
|
|
85
|
+
asOf: run.as_of,
|
|
86
|
+
budget: JSON.parse(run.budget_json),
|
|
87
|
+
metrics: JSON.parse(run.metrics_json),
|
|
88
|
+
items: rows.map((row) => ({
|
|
89
|
+
objectType: row.object_type,
|
|
90
|
+
objectId: row.object_id,
|
|
91
|
+
...row.score === null ? {} : { score: row.score },
|
|
92
|
+
reasons: JSON.parse(row.reasons_json),
|
|
93
|
+
included: row.included === 1
|
|
94
|
+
})),
|
|
95
|
+
createdAt: run.created_at
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
function recordExecutionContextFeedback(input) {
|
|
99
|
+
const now = Date.now();
|
|
100
|
+
const result = getSqliteDatabase().prepare(`INSERT INTO execution_context_feedback (
|
|
101
|
+
turn_id, rating, reason, created_at, updated_at
|
|
102
|
+
) SELECT ?, ?, ?, ?, ? WHERE EXISTS (
|
|
103
|
+
SELECT 1 FROM execution_context_runs WHERE turn_id = ?
|
|
104
|
+
) ON CONFLICT(turn_id) DO UPDATE SET
|
|
105
|
+
rating = excluded.rating, reason = excluded.reason, updated_at = excluded.updated_at`).run(input.turnId, input.rating, input.reason ?? null, now, now, input.turnId);
|
|
106
|
+
return Number(result.changes) > 0;
|
|
107
|
+
}
|
|
108
|
+
function getExecutionContextFeedbackScores() {
|
|
109
|
+
const rows = getSqliteDatabase().prepare(`SELECT i.object_type, i.object_id,
|
|
110
|
+
COUNT(*) AS samples,
|
|
111
|
+
SUM(CASE f.rating WHEN 'helpful' THEN 1 ELSE -1 END) AS balance
|
|
112
|
+
FROM execution_context_items i
|
|
113
|
+
JOIN execution_context_runs r ON r.run_id = i.run_id
|
|
114
|
+
JOIN (
|
|
115
|
+
SELECT turn_id, rating FROM execution_context_feedback
|
|
116
|
+
ORDER BY updated_at DESC LIMIT 500
|
|
117
|
+
) f ON f.turn_id = r.turn_id
|
|
118
|
+
WHERE i.included = 1
|
|
119
|
+
GROUP BY i.object_type, i.object_id`).all();
|
|
120
|
+
return new Map(rows.flatMap((row) => row.samples < 2 ? [] : [[`${row.object_type}:${row.object_id}`, Math.max(-.1, Math.min(.1, row.balance / row.samples * .1))]]));
|
|
121
|
+
}
|
|
122
|
+
//#endregion
|
|
123
|
+
export { getExecutionContextAudit, getExecutionContextFeedbackScores, recordExecutionContext, recordExecutionContextFeedback };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { AgentMessage } from '@earendil-works/pi-agent-core';
|
|
2
|
+
import type { Config } from '../../config/schema.js';
|
|
3
|
+
import type { KnowledgeSource } from '../../knowledge-memory/index.js';
|
|
4
|
+
import { type ExecutionContext } from './execution-context.js';
|
|
5
|
+
export interface ExecutionContextPlan {
|
|
6
|
+
traceId: string;
|
|
7
|
+
modelMessage: AgentMessage;
|
|
8
|
+
executionContext?: ExecutionContext;
|
|
9
|
+
estimatedTokens: number;
|
|
10
|
+
contextChars: number;
|
|
11
|
+
contextItemCount: number;
|
|
12
|
+
}
|
|
13
|
+
export interface ExecutionContextCoordinatorOptions {
|
|
14
|
+
getConfig: () => Config | undefined;
|
|
15
|
+
getAccessForSession: (sessionKey: string) => {
|
|
16
|
+
userModel: boolean;
|
|
17
|
+
knowledge: boolean;
|
|
18
|
+
knowledgeSources: readonly KnowledgeSource[];
|
|
19
|
+
};
|
|
20
|
+
getWorkspaceIdForSession: (sessionKey: string) => string;
|
|
21
|
+
getProjectIdForSession: (sessionKey: string) => string | undefined;
|
|
22
|
+
}
|
|
23
|
+
export declare class ExecutionContextCoordinator {
|
|
24
|
+
private readonly options;
|
|
25
|
+
private readonly currentBySession;
|
|
26
|
+
constructor(options: ExecutionContextCoordinatorOptions);
|
|
27
|
+
forgetSession(sessionKey: string): void;
|
|
28
|
+
clear(): void;
|
|
29
|
+
getCurrent(sessionKey: string): ExecutionContext | undefined;
|
|
30
|
+
prepare(userMessage: AgentMessage, sessionKey: string, turnId: string): Promise<ExecutionContextPlan>;
|
|
31
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { extractProfileAgentId } from "../../config/agent-profile.js";
|
|
2
|
+
import { assembleTaskContext } from "../../tasks/task-context-assembler.js";
|
|
3
|
+
import { recordExecutionContext } from "./audit.js";
|
|
4
|
+
import { prependAgentContext } from "./prepend.js";
|
|
5
|
+
import { extractAgentUserPlainText } from "../memory/user-message-text.js";
|
|
6
|
+
import { buildExecutionContext, fitExecutionContextToChars } from "./execution-context.js";
|
|
7
|
+
//#region src/agent/context/coordinator.ts
|
|
8
|
+
var ExecutionContextCoordinator = class {
|
|
9
|
+
currentBySession = /* @__PURE__ */ new Map();
|
|
10
|
+
constructor(options) {
|
|
11
|
+
this.options = options;
|
|
12
|
+
}
|
|
13
|
+
forgetSession(sessionKey) {
|
|
14
|
+
this.currentBySession.delete(sessionKey);
|
|
15
|
+
}
|
|
16
|
+
clear() {
|
|
17
|
+
this.currentBySession.clear();
|
|
18
|
+
}
|
|
19
|
+
getCurrent(sessionKey) {
|
|
20
|
+
return this.currentBySession.get(sessionKey);
|
|
21
|
+
}
|
|
22
|
+
async prepare(userMessage, sessionKey, turnId) {
|
|
23
|
+
const empty = () => ({
|
|
24
|
+
traceId: "",
|
|
25
|
+
modelMessage: userMessage,
|
|
26
|
+
estimatedTokens: 0,
|
|
27
|
+
contextChars: 0,
|
|
28
|
+
contextItemCount: 0
|
|
29
|
+
});
|
|
30
|
+
const config = this.options.getConfig();
|
|
31
|
+
const access = this.options.getAccessForSession(sessionKey);
|
|
32
|
+
if (!config || !config.userContext.contextPlanning.enabled || !access.userModel && !access.knowledge) return empty();
|
|
33
|
+
const task = assembleTaskContext(sessionKey, extractAgentUserPlainText(userMessage));
|
|
34
|
+
const context = buildExecutionContext({
|
|
35
|
+
query: task.retrievalQuery,
|
|
36
|
+
agentId: extractProfileAgentId(sessionKey, config),
|
|
37
|
+
workspaceId: this.options.getWorkspaceIdForSession(sessionKey),
|
|
38
|
+
projectId: this.options.getProjectIdForSession(sessionKey),
|
|
39
|
+
sessionId: sessionKey,
|
|
40
|
+
maxAssertions: Math.min(config.userContext.contextPlanning.maxAssertions, task.allocation.maxResults),
|
|
41
|
+
maxKnowledge: Math.min(config.userContext.contextPlanning.maxKnowledge, task.allocation.maxResults),
|
|
42
|
+
includeUserModel: access.userModel,
|
|
43
|
+
includeKnowledge: access.knowledge,
|
|
44
|
+
knowledgeSources: access.knowledgeSources
|
|
45
|
+
});
|
|
46
|
+
this.currentBySession.set(sessionKey, context);
|
|
47
|
+
const maxChars = Math.min(config.userContext.contextPlanning.maxChars, task.allocation.maxChars);
|
|
48
|
+
const fitted = fitExecutionContextToChars(context, maxChars);
|
|
49
|
+
const rendered = fitted.rendered;
|
|
50
|
+
const contextItemCount = fitted.context.rules.length + fitted.context.assertions.length + fitted.context.goals.length + fitted.context.priorities.length + fitted.context.knowledge.length;
|
|
51
|
+
recordExecutionContext(context, {
|
|
52
|
+
turnId,
|
|
53
|
+
sessionId: sessionKey,
|
|
54
|
+
budget: {
|
|
55
|
+
maxAssertions: Math.min(config.userContext.contextPlanning.maxAssertions, task.allocation.maxResults),
|
|
56
|
+
maxKnowledge: Math.min(config.userContext.contextPlanning.maxKnowledge, task.allocation.maxResults),
|
|
57
|
+
maxChars
|
|
58
|
+
},
|
|
59
|
+
renderedChars: rendered.length,
|
|
60
|
+
includedContext: fitted.context
|
|
61
|
+
});
|
|
62
|
+
return {
|
|
63
|
+
traceId: context.traceId,
|
|
64
|
+
modelMessage: prependAgentContext(userMessage, rendered),
|
|
65
|
+
executionContext: context,
|
|
66
|
+
estimatedTokens: Math.ceil(rendered.length / 4),
|
|
67
|
+
contextChars: rendered.length,
|
|
68
|
+
contextItemCount
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
//#endregion
|
|
73
|
+
export { ExecutionContextCoordinator };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ExecutionContext, ExecutionContextRequest, ExecutionRule } from './execution-context.types.js';
|
|
2
|
+
export type { ExecutionContext, ExecutionContextRequest, ExecutionGoal, ExecutionPriority, ExecutionRule, RankedExecutionAssertion, RuleEnforcementLevel, } from './execution-context.types.js';
|
|
3
|
+
export declare function buildExecutionContext(request: ExecutionContextRequest): ExecutionContext;
|
|
4
|
+
export declare function renderExecutionContext(context: ExecutionContext): string;
|
|
5
|
+
export declare function fitExecutionContextToChars(context: ExecutionContext, maxChars: number): {
|
|
6
|
+
context: ExecutionContext;
|
|
7
|
+
rendered: string;
|
|
8
|
+
};
|
|
9
|
+
export declare function evaluateToolGate(context: ExecutionContext, operation: string): {
|
|
10
|
+
allowed: boolean;
|
|
11
|
+
rule?: ExecutionRule;
|
|
12
|
+
reason?: string;
|
|
13
|
+
};
|