@xopcai/xopc 0.0.249 → 0.0.251
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-B759R_qf.js → activity-store-DfBjTSo9.js} +1 -1
- package/dist/gateway/static/root/assets/{agent-avatar-dicebear-BUu7EnwM.js → agent-avatar-dicebear-Bo_dmLv8.js} +1 -1
- package/dist/gateway/static/root/assets/agent-defaults-settings-panel-kILWelNb.js +1 -0
- package/dist/gateway/static/root/assets/{agents-DK9HjHO0.js → agents-yuUn8n-f.js} +1 -1
- package/dist/gateway/static/root/assets/{api-Cg0v7Lpn.js → api-zxpcJfgj.js} +1 -1
- package/dist/gateway/static/root/assets/{app-management-settings-panel-C9DkCW_d.js → app-management-settings-panel-Cz56nrVF.js} +1 -1
- package/dist/gateway/static/root/assets/{appearance-settings-CFggS95Y.js → appearance-settings-DxSws5U4.js} +1 -1
- package/dist/gateway/static/root/assets/apps-page-BnizTdgs.js +1 -0
- package/dist/gateway/static/root/assets/{archive-plugin-BQrilVVv.js → archive-plugin-7k15-hqo.js} +1 -1
- package/dist/gateway/static/root/assets/{attachment-load-BG0BliqV.js → attachment-load-B-SFpjd9.js} +1 -1
- package/dist/gateway/static/root/assets/{automations-page-Bo4RiTkh.js → automations-page-Qy36j19q.js} +1 -1
- package/dist/gateway/static/root/assets/automations-workspace-CZRKqSqY.js +6 -0
- package/dist/gateway/static/root/assets/{binary-plugins-BCnyNU0C.js → binary-plugins-CPOZQt8F.js} +1 -1
- package/dist/gateway/static/root/assets/{block-editor-Db8DlVvg.js → block-editor-DhvVlIp9.js} +4 -4
- package/dist/gateway/static/root/assets/browser-settings-page-pN5LbChY.js +8 -0
- package/dist/gateway/static/root/assets/{browser-workflow-inputs-C71vfl0b.js → browser-workflow-inputs-BX1-uM9L.js} +1 -1
- package/dist/gateway/static/root/assets/{browser-workflows-page-vvmSYKsO.js → browser-workflows-page-C65MI57t.js} +2 -2
- package/dist/gateway/static/root/assets/capabilities-settings-panel-CJw2e16J.js +7 -0
- package/dist/gateway/static/root/assets/channels-settings-CRgjb4Ck.js +1 -0
- package/dist/gateway/static/root/assets/{channels-status-swr-CKyV3jY5.js → channels-status-swr-CX-yWwLD.js} +1 -1
- package/dist/gateway/static/root/assets/{chat-terminal-dock-B1Xd6OFB.js → chat-terminal-dock-1PJoxRuV.js} +2 -2
- package/dist/gateway/static/root/assets/connectors-page-Dcpdy06y.js +2 -0
- package/dist/gateway/static/root/assets/{cron-expression-D-F9vjtE.js → cron-expression-CBCc6zFA.js} +1 -1
- package/dist/gateway/static/root/assets/{date-picker-B2OoYvic.js → date-picker-u8K5Kt_N.js} +1 -1
- package/dist/gateway/static/root/assets/{dependency-picker-BiGx9Sbj.js → dependency-picker-y_i_cnpz.js} +1 -1
- package/dist/gateway/static/root/assets/{desktop-pet-BNMRqipe.js → desktop-pet-DyL0JxLm.js} +1 -1
- package/dist/gateway/static/root/assets/{desktop-pet-settings-DeYbIV7A.js → desktop-pet-settings-d2d_IsyP.js} +1 -1
- package/dist/gateway/static/root/assets/{extension-debug-page-COyn05ub.js → extension-debug-page-DqIBKJwl.js} +1 -1
- package/dist/gateway/static/root/assets/{extension-page-oH43chS2.js → extension-page-DUW1xxj2.js} +1 -1
- package/dist/gateway/static/root/assets/{extension-settings-page-BMO59994.js → extension-settings-page-BHY9qaNw.js} +1 -1
- package/dist/gateway/static/root/assets/files-BArWTfr7.js +1 -0
- package/dist/gateway/static/root/assets/{gateway-config-api-cimpViGk.js → gateway-config-api-e3BRcgDx.js} +1 -1
- package/dist/gateway/static/root/assets/{gateway-config-swr-BGdHwT4e.js → gateway-config-swr-CMNbl0FZ.js} +1 -1
- package/dist/gateway/static/root/assets/{gateway-settings-BHJtnSic.js → gateway-settings-Cheo0Rkc.js} +1 -1
- package/dist/gateway/static/root/assets/{gateway-startup-retry-CuaM3b4c.js → gateway-startup-retry-CR7Xg8As.js} +1 -1
- package/dist/gateway/static/root/assets/{heartbeat-settings-DNhrZHqx.js → heartbeat-settings-7CD9iPR7.js} +1 -1
- package/dist/gateway/static/root/assets/home-page-DVrTRqNc.js +1 -0
- package/dist/gateway/static/root/assets/{image-generation-api-D7duj7Uj.js → image-generation-api-C5mn73ca.js} +1 -1
- package/dist/gateway/static/root/assets/{index-DGeGmj4k.css → index-B7CX4Qob.css} +1 -1
- package/dist/gateway/static/root/assets/index-BHrpyJ4t.js +72 -0
- package/dist/gateway/static/root/assets/{keyboard-shortcuts-settings-D8Zw_lYd.js → keyboard-shortcuts-settings-BtlqMleF.js} +1 -1
- package/dist/gateway/static/root/assets/languages-5WaOu0Lf.js +2 -0
- package/dist/gateway/static/root/assets/local-app-workbench-page-BjxfkjxE.js +2 -0
- package/dist/gateway/static/root/assets/{local-apps-page-CvPDPRwb.js → local-apps-page-B7xqQe2s.js} +1 -1
- package/dist/gateway/static/root/assets/{locale-store-zEL8bkwx.js → locale-store-CF4erhjB.js} +1 -1
- package/dist/gateway/static/root/assets/logs-page-kACaPZKL.js +2 -0
- package/dist/gateway/static/root/assets/{management-settings-D8moh99U.js → management-settings-A432siER.js} +1 -1
- package/dist/gateway/static/root/assets/markdown-editor-BjMTIM-m.js +1 -0
- package/dist/gateway/static/root/assets/{markdown-view-DGRN-8wP.js → markdown-view-CQvzsE24.js} +1 -1
- package/dist/gateway/static/root/assets/{media-plugins-BLaE5b1Y.js → media-plugins-CpvYiauZ.js} +1 -1
- package/dist/gateway/static/root/assets/messages-Cf5hpZE6.js +3 -0
- package/dist/gateway/static/root/assets/{mobile-pairing-wizard-DiVDuCxl.js → mobile-pairing-wizard-DyjVGngO.js} +1 -1
- package/dist/gateway/static/root/assets/note-detail-panel-CUd8O4K7.js +5 -0
- package/dist/gateway/static/root/assets/notes-page-BLQwd39W.js +8 -0
- package/dist/gateway/static/root/assets/{page-tabs-BFMGjA60.js → page-tabs-B3FKzjR6.js} +1 -1
- package/dist/gateway/static/root/assets/{preview-open-alternatives-DNEWZN7H.js → preview-open-alternatives-DnjrwAHD.js} +1 -1
- package/dist/gateway/static/root/assets/{product-open-page-Co5u7asH.js → product-open-page-COcr_NUJ.js} +1 -1
- package/dist/gateway/static/root/assets/project-detail-page-NttW338u.js +1 -0
- package/dist/gateway/static/root/assets/projects-page-BzH8pjEz.js +1 -0
- package/dist/gateway/static/root/assets/{registry-api-Cg92zSod.js → registry-api-BsRBlji7.js} +1 -1
- package/dist/gateway/static/root/assets/remote-access-hub-BxpjSDnL.js +1 -0
- package/dist/gateway/static/root/assets/{runtime-tools-settings-panel-C0ByNmlV.js → runtime-tools-settings-panel-LO4wZ_dO.js} +1 -1
- package/dist/gateway/static/root/assets/{schema-form-Dq_VQpuY.js → schema-form-crcj4-Pm.js} +1 -1
- package/dist/gateway/static/root/assets/sessions-page-BLMaibOb.js +1 -0
- package/dist/gateway/static/root/assets/settings-advanced-gate-BRvvKhoH.js +1 -0
- package/dist/gateway/static/root/assets/{settings-form-section-CZu6FX4k.js → settings-form-section-Bl4MvTmq.js} +1 -1
- package/dist/gateway/static/root/assets/{settings-page-S8ekeUZd.js → settings-page-DplrjZ6x.js} +1 -1
- package/dist/gateway/static/root/assets/{setup-status-panel-BdVmwXMv.js → setup-status-panel-DTOsxQC1.js} +1 -1
- package/dist/gateway/static/root/assets/{share-preview-page-D2fEidbn.js → share-preview-page-CJP1kURj.js} +1 -1
- package/dist/gateway/static/root/assets/shares-settings-CemgzEi4.js +1 -0
- package/dist/gateway/static/root/assets/skill-reload-api-BWYanBlQ.js +1 -0
- package/dist/gateway/static/root/assets/{skills-page-AYiPlgZE.js → skills-page-DsjcKg9Q.js} +1 -1
- package/dist/gateway/static/root/assets/{skills-page.utils-DGzl-ib-.js → skills-page.utils-D6gWBbvy.js} +1 -1
- package/dist/gateway/static/root/assets/source-workspace-editor-CVWzt0oT.js +1 -0
- package/dist/gateway/static/root/assets/{system-settings-panel-5Xd5mIiR.js → system-settings-panel-_eCXfqCo.js} +1 -1
- package/dist/gateway/static/root/assets/{task-detail-page-BQAUaCDD.js → task-detail-page-D0Z_K5JT.js} +1 -1
- package/dist/gateway/static/root/assets/{theme-store-ZVClZKQ0.js → theme-store-BOgkc_9D.js} +1 -1
- package/dist/gateway/static/root/assets/{tunnel-api-CdZN1Jin.js → tunnel-api-W5mktxl1.js} +1 -1
- package/dist/gateway/static/root/assets/{use-autosave-czRI0NBc.js → use-autosave-Na2DYzT3.js} +1 -1
- package/dist/gateway/static/root/assets/user-model-page-B_-SNat-.js +2 -0
- package/dist/gateway/static/root/assets/{vendor-codemirror--gTq3YAI.js → vendor-codemirror-Qdcjid65.js} +1 -1
- package/dist/gateway/static/root/assets/{voice-api-key-field-8YEvA3cU.js → voice-api-key-field-OXweUxS_.js} +1 -1
- package/dist/gateway/static/root/assets/{voice-config-api-CopF64lY.js → voice-config-api-C-ryeIxj.js} +1 -1
- package/dist/gateway/static/root/assets/{work-discovery-overlay-keLtqYYJ.js → work-discovery-overlay-BqOsO47I.js} +1 -1
- package/dist/gateway/static/root/assets/{workflow-run-setup-panel-Dy5WgYMO.js → workflow-run-setup-panel-B9S_lfT1.js} +2 -2
- package/dist/gateway/static/root/assets/workflows-page-CNOT2Coo.js +5 -0
- package/dist/gateway/static/root/index.html +11 -11
- 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 +1 -1
- package/dist/src/agent/agent-manager.d.ts +9 -9
- package/dist/src/agent/agent-manager.js +50 -32
- package/dist/src/agent/background-review/prompts.d.ts +1 -1
- package/dist/src/agent/background-review/prompts.js +11 -2
- package/dist/src/agent/background-review/run-background-review.js +1 -1
- package/dist/src/agent/context/audit.d.ts +3 -1
- package/dist/src/agent/context/audit.js +32 -6
- package/dist/src/agent/context/coordinator.d.ts +6 -1
- package/dist/src/agent/context/coordinator.js +14 -13
- package/dist/src/agent/context/execution-context.d.ts +6 -47
- package/dist/src/agent/context/execution-context.js +79 -15
- package/dist/src/agent/context/execution-context.types.d.ts +50 -0
- package/dist/src/agent/context/execution-context.types.js +1 -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/project-context.d.ts +3 -0
- package/dist/src/agent/context/project-context.js +5 -3
- package/dist/src/agent/embedded/model-runtime.js +1 -1
- package/dist/src/agent/embedded/run-for-session.js +1 -1
- package/dist/src/agent/external-tools/index.d.ts +1 -0
- package/dist/src/agent/external-tools/index.js +1 -0
- 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/image/tool-model-config.js +1 -1
- package/dist/src/agent/inbound/attachment-pipeline.js +5 -1
- package/dist/src/agent/mcp/oauth/mcp-oauth-store.js +1 -1
- package/dist/src/agent/memory/compaction-promotion.d.ts +1 -0
- package/dist/src/agent/memory/compaction-promotion.js +7 -2
- package/dist/src/agent/memory/index.d.ts +1 -1
- package/dist/src/agent/memory/index.js +3 -3
- package/dist/src/agent/memory/memory-config.d.ts +0 -5
- package/dist/src/agent/memory/memory-config.js +1 -8
- package/dist/src/agent/orchestration/context-overflow.js +1 -0
- package/dist/src/agent/service/direct-turn-helpers.d.ts +2 -2
- package/dist/src/agent/service/direct-turn-helpers.js +2 -2
- package/dist/src/agent/service/process-direct-streaming.js +3 -4
- package/dist/src/agent/service.js +2 -2
- package/dist/src/agent/session/session-inspector.js +1 -1
- package/dist/src/agent/skills/hub-lock.js +1 -1
- package/dist/src/agent/tasks/task-judge-service.js +3 -3
- package/dist/src/agent/tools/factory.d.ts +1 -0
- package/dist/src/agent/tools/factory.js +37 -7
- package/dist/src/agent/tools/knowledge-memory-tool.d.ts +6 -0
- package/dist/src/agent/tools/knowledge-memory-tool.js +81 -26
- 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 +2 -0
- package/dist/src/agent/tools/user-context-tool.js +21 -4
- package/dist/src/ai-assist/text-assist.js +1 -1
- package/dist/src/auth/credentials.js +2 -2
- package/dist/src/auth/profiles/store.js +1 -1
- package/dist/src/auth/sync-provider-auth.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/browser/providers/browser-ext-install.js +1 -1
- package/dist/src/cli/commands/doctor/checks/database-schema.js +1 -1
- package/dist/src/cli/commands/doctor/checks/provider-auth.js +1 -1
- package/dist/src/cli/commands/models.js +1 -1
- package/dist/src/config/index.js +4 -4
- package/dist/src/config/loader.js +1 -1
- package/dist/src/config/models-json.js +1 -1
- package/dist/src/connectors/connection-recovery-service.d.ts +1 -0
- package/dist/src/connectors/connection-recovery-service.js +46 -22
- package/dist/src/extensions/lockfile.js +1 -1
- package/dist/src/files/file-service.js +142 -14
- package/dist/src/gateway/agents-admin.js +1 -1
- package/dist/src/gateway/file-path-classifier.js +1 -1
- package/dist/src/gateway/heartbeat/service.js +1 -1
- package/dist/src/gateway/hono/lib/config-payload.js +1 -1
- package/dist/src/gateway/hono/routes/connectors.js +17 -3
- package/dist/src/gateway/hono/routes/files.js +23 -2
- package/dist/src/gateway/hono/routes/models.js +1 -1
- package/dist/src/gateway/hono/routes/tasks.js +1 -1
- package/dist/src/gateway/security/gateway-scopes.js +2 -0
- package/dist/src/gateway/service/agent-runner.js +1 -1
- package/dist/src/gateway/service/config-coordinator.js +1 -1
- package/dist/src/gateway/service/run-gateway-agent.js +1 -1
- package/dist/src/gateway/service/session-input-coordinator.js +1 -1
- package/dist/src/gateway/service.js +12 -8
- package/dist/src/heartbeat/index.js +1 -1
- package/dist/src/knowledge-memory/domain.d.ts +1 -0
- package/dist/src/knowledge-memory/index.js +2 -2
- package/dist/src/knowledge-memory/repository.d.ts +4 -1
- package/dist/src/knowledge-memory/repository.js +16 -2
- 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 +6 -8
- package/dist/src/proactive/execution/context.js +78 -32
- 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 +1 -0
- package/dist/src/proactive/index.js +2 -1
- 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/project-service.d.ts +2 -1
- package/dist/src/projects/project-service.js +3 -2
- package/dist/src/providers/auth-runtime/resolve-auth.js +1 -1
- package/dist/src/providers/index.js +2 -2
- package/dist/src/providers/model-registry.js +1 -1
- package/dist/src/providers/register-runtime-providers.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 +3 -1
- package/dist/src/storage/sqlite/collaboration-rule-repository.js +1 -1
- package/dist/src/storage/sqlite/config-repository.js +1 -1
- package/dist/src/storage/sqlite/connection-wait-repository.js +2 -2
- package/dist/src/storage/sqlite/index.js +2 -2
- 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/row-mappers.js +2 -2
- package/dist/src/storage/sqlite/schema.js +1 -1
- package/dist/src/storage/sqlite/session-input-repository.js +1 -1
- 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 +3 -5
- package/dist/src/storage/sqlite/transcript-repository.js +2 -1
- package/dist/src/tasks/home-query-service.js +35 -13
- package/dist/src/tasks/project-monitoring-service.d.ts +2 -0
- package/dist/src/tasks/project-monitoring-service.js +4 -1
- package/dist/src/tui/backends/embedded-backend.js +1 -1
- package/dist/src/tui/tui-startup-resources.js +1 -1
- package/dist/src/tui/tui.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-model/capture/executor.d.ts +10 -0
- package/dist/src/user-model/capture/executor.js +99 -3
- package/dist/src/user-model/capture/semantic.d.ts +18 -0
- package/dist/src/user-model/capture/semantic.js +72 -6
- package/dist/src/user-model/goals.d.ts +4 -0
- package/dist/src/user-model/goals.js +4 -2
- package/dist/src/voice/realtime/agentEngine.js +0 -1
- package/dist/src/work-discovery/service.js +1 -1
- package/dist/src/workflows/service/workflow-run-service.js +1 -1
- package/package.json +1 -1
- package/dist/gateway/static/root/assets/agent-defaults-settings-panel-C1rXNUAG.js +0 -1
- package/dist/gateway/static/root/assets/apps-page-jOvT-fzU.js +0 -1
- package/dist/gateway/static/root/assets/automations-workspace-BKjKTlW8.js +0 -6
- package/dist/gateway/static/root/assets/browser-settings-page-Dzq18pO1.js +0 -8
- package/dist/gateway/static/root/assets/capabilities-settings-panel-DW4SBQf4.js +0 -7
- package/dist/gateway/static/root/assets/channels-settings-57OGuewD.js +0 -1
- package/dist/gateway/static/root/assets/code-editor-D4_k-6QN.js +0 -1
- package/dist/gateway/static/root/assets/connectors-page-CT_I3kbR.js +0 -2
- package/dist/gateway/static/root/assets/files-D6vf3S30.js +0 -1
- package/dist/gateway/static/root/assets/home-page-BiHwiBnQ.js +0 -1
- package/dist/gateway/static/root/assets/html-workspace-editor-C3DKAkMc.js +0 -1
- package/dist/gateway/static/root/assets/index-aBs0EfQB.js +0 -72
- package/dist/gateway/static/root/assets/local-app-workbench-page-eBFVWmtH.js +0 -2
- package/dist/gateway/static/root/assets/logs-page-ClvcWlL6.js +0 -2
- package/dist/gateway/static/root/assets/markdown-editor-nDLmA_LF.js +0 -2
- package/dist/gateway/static/root/assets/markdown-split-D7V3j0vE.js +0 -1
- package/dist/gateway/static/root/assets/messages-W5P19VTF.js +0 -11
- package/dist/gateway/static/root/assets/note-detail-panel-CEEvR-fV.js +0 -5
- package/dist/gateway/static/root/assets/notes-page-BLqgXNCx.js +0 -8
- package/dist/gateway/static/root/assets/project-detail-page-CIiFJ5tk.js +0 -1
- package/dist/gateway/static/root/assets/projects-page-B3UF-Pfm.js +0 -1
- package/dist/gateway/static/root/assets/remote-access-hub-BUtpkJPG.js +0 -1
- package/dist/gateway/static/root/assets/sessions-page-UgJmG-V4.js +0 -1
- package/dist/gateway/static/root/assets/settings-advanced-gate-DDCzpdkl.js +0 -1
- package/dist/gateway/static/root/assets/shares-settings-BdsqnCYj.js +0 -1
- package/dist/gateway/static/root/assets/skill-reload-api-ghzAQKna.js +0 -1
- package/dist/gateway/static/root/assets/user-model-page-W3GTm6nA.js +0 -2
- package/dist/gateway/static/root/assets/workflows-page-BbAV3h7n.js +0 -5
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type UserModelScope } from '../user-model/domain.js';
|
|
2
|
-
import type { KnowledgeItem, KnowledgeKind, KnowledgeOriginClass, KnowledgeRecordClass, KnowledgeStatus, KnowledgeVisibilityContext } from './domain.js';
|
|
2
|
+
import type { KnowledgeItem, KnowledgeKind, KnowledgeOriginClass, KnowledgeRecordClass, KnowledgeSource, KnowledgeStatus, KnowledgeVisibilityContext } from './domain.js';
|
|
3
3
|
export interface WriteKnowledgeInput {
|
|
4
4
|
principalId?: string;
|
|
5
5
|
kind: KnowledgeKind;
|
|
@@ -41,5 +41,8 @@ export declare function searchKnowledgeItems(input: {
|
|
|
41
41
|
principalId?: string;
|
|
42
42
|
asOf?: number;
|
|
43
43
|
recordClass?: KnowledgeRecordClass;
|
|
44
|
+
trustedOnly?: boolean;
|
|
45
|
+
sources?: readonly KnowledgeSource[];
|
|
44
46
|
limit?: number;
|
|
45
47
|
}): KnowledgeItem[];
|
|
48
|
+
export declare function knowledgeSourceAllowed(item: KnowledgeItem, sources: readonly KnowledgeSource[]): boolean;
|
|
@@ -138,6 +138,14 @@ function searchKnowledgeItems(input) {
|
|
|
138
138
|
const asOf = input.asOf ?? Date.now();
|
|
139
139
|
const limit = Math.max(1, Math.min(100, input.limit ?? 12));
|
|
140
140
|
const visible = visibilityClause(input.context);
|
|
141
|
+
const sourceParts = [];
|
|
142
|
+
const sourceValues = [];
|
|
143
|
+
if (input.sources?.includes("connector")) sourceParts.push("k.record_class = 'source_index'");
|
|
144
|
+
const memoryScopes = input.sources?.filter((source) => source !== "connector") ?? [];
|
|
145
|
+
if (memoryScopes.length) {
|
|
146
|
+
sourceParts.push(`(k.record_class = 'memory' AND k.scope_type IN (${memoryScopes.map(() => "?").join(", ")}))`);
|
|
147
|
+
sourceValues.push(...memoryScopes);
|
|
148
|
+
}
|
|
141
149
|
const fts = buildFts5SearchQuery(input.query);
|
|
142
150
|
if (!fts) return [];
|
|
143
151
|
return getSqliteDatabase().prepare(`SELECT k.*, bm25(knowledge_items_fts) AS rank
|
|
@@ -147,8 +155,14 @@ function searchKnowledgeItems(input) {
|
|
|
147
155
|
AND (k.valid_to IS NULL OR k.valid_to >= ?)
|
|
148
156
|
AND (k.expires_at IS NULL OR k.expires_at >= ?)
|
|
149
157
|
${input.recordClass ? "AND k.record_class = ?" : ""}
|
|
158
|
+
${input.trustedOnly ? "AND k.origin_class != 'untrusted'" : ""}
|
|
159
|
+
${input.sources ? `AND (${sourceParts.length ? sourceParts.join(" OR ") : "0"})` : ""}
|
|
150
160
|
AND ${visible.sql}
|
|
151
|
-
ORDER BY rank ASC, k.importance DESC, k.updated_at DESC LIMIT ?`).all(fts, principalId, asOf, asOf, asOf, ...input.recordClass ? [input.recordClass] : [], ...visible.values, limit).map(fromRow);
|
|
161
|
+
ORDER BY rank ASC, k.importance DESC, k.updated_at DESC LIMIT ?`).all(fts, principalId, asOf, asOf, asOf, ...input.recordClass ? [input.recordClass] : [], ...sourceValues, ...visible.values, limit).map(fromRow);
|
|
162
|
+
}
|
|
163
|
+
function knowledgeSourceAllowed(item, sources) {
|
|
164
|
+
if (item.recordClass === "source_index") return sources.includes("connector");
|
|
165
|
+
return item.scope.type === "session" ? sources.includes("session") : item.scope.type === "workspace" ? sources.includes("workspace") : item.scope.type === "project" ? sources.includes("project") : false;
|
|
152
166
|
}
|
|
153
167
|
//#endregion
|
|
154
|
-
export { getKnowledgeItem, listKnowledgeItems, searchKnowledgeItems, setKnowledgeStatus, writeKnowledgeItem };
|
|
168
|
+
export { getKnowledgeItem, knowledgeSourceAllowed, listKnowledgeItems, searchKnowledgeItems, setKnowledgeStatus, writeKnowledgeItem };
|
|
@@ -122,7 +122,11 @@ function automationPlan(payload) {
|
|
|
122
122
|
function proactivePlan(payload) {
|
|
123
123
|
if (!payload || typeof payload !== "object") return null;
|
|
124
124
|
const item = payload;
|
|
125
|
-
if (typeof item.id !== "string" || typeof item.
|
|
125
|
+
if (typeof item.id !== "string" || typeof item.insightId !== "string" || typeof item.insight.title !== "string") return null;
|
|
126
|
+
const requiresDecision = item.insight.attentionKind === "decision";
|
|
127
|
+
const highUrgency = item.insight.urgency === "high" || item.insight.urgency === "critical";
|
|
128
|
+
if (item.insight.attentionKind === "receipt") return null;
|
|
129
|
+
if (!requiresDecision && !highUrgency) return null;
|
|
126
130
|
const title = item.insight.title.trim().slice(0, 120);
|
|
127
131
|
const summary = typeof item.insight.summary === "string" ? item.insight.summary.trim().slice(0, 180) : "";
|
|
128
132
|
return {
|
|
@@ -133,7 +137,7 @@ function proactivePlan(payload) {
|
|
|
133
137
|
kind: "insight",
|
|
134
138
|
inboxItemId: item.id
|
|
135
139
|
},
|
|
136
|
-
priority:
|
|
140
|
+
priority: requiresDecision || highUrgency ? "high" : "normal",
|
|
137
141
|
title: {
|
|
138
142
|
en: title,
|
|
139
143
|
zh: title
|
|
@@ -144,7 +148,7 @@ function proactivePlan(payload) {
|
|
|
144
148
|
} } : {},
|
|
145
149
|
payload: {
|
|
146
150
|
inboxItemId: item.id,
|
|
147
|
-
insightId: item.
|
|
151
|
+
insightId: item.insightId
|
|
148
152
|
}
|
|
149
153
|
}
|
|
150
154
|
};
|
|
@@ -67,14 +67,5 @@ function executePendingProactiveActions(now = /* @__PURE__ */ new Date()) {
|
|
|
67
67
|
executed += 1;
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
|
-
function resolveProactiveActionDecision(inboxItemId, choice, now = /* @__PURE__ */ new Date()) {
|
|
71
|
-
const row = getSqliteDatabase().prepare(`SELECT x.insight_id, x.action_status
|
|
72
|
-
FROM proactive_inbox_items i JOIN proactive_insights x ON x.insight_id = i.insight_id
|
|
73
|
-
WHERE i.inbox_item_id = ?`).get(inboxItemId);
|
|
74
|
-
if (!row || row.action_status !== "approval_required") return;
|
|
75
|
-
getSqliteDatabase().prepare(`UPDATE proactive_insights SET action_status = ?, action_updated_at = ?
|
|
76
|
-
WHERE insight_id = ? AND action_status = 'approval_required'`).run(choice === "approve" ? "pending" : "rejected", now.toISOString(), row.insight_id);
|
|
77
|
-
if (choice === "approve") executePendingProactiveActions(now);
|
|
78
|
-
}
|
|
79
70
|
//#endregion
|
|
80
|
-
export { executePendingProactiveActions
|
|
71
|
+
export { executePendingProactiveActions };
|
|
@@ -1,44 +1,42 @@
|
|
|
1
1
|
import type { ContextProvider, ResolvedContext } from './types.js';
|
|
2
|
+
import type { ScenarioDefinition } from '../scenarios/types.js';
|
|
2
3
|
type ContextInput = Parameters<ContextProvider['collect']>[0];
|
|
3
4
|
export declare class EventBatchContextProvider implements ContextProvider {
|
|
4
5
|
readonly id = "event_batch";
|
|
5
|
-
supports(): boolean;
|
|
6
6
|
collect(input: ContextInput): Promise<ResolvedContext>;
|
|
7
7
|
}
|
|
8
8
|
export declare class ConnectedSourceContextProvider implements ContextProvider {
|
|
9
9
|
readonly id = "connected_source";
|
|
10
|
-
supports(): boolean;
|
|
11
10
|
collect(input: ContextInput): Promise<ResolvedContext>;
|
|
12
11
|
}
|
|
13
12
|
export declare class InternalObjectContextProvider implements ContextProvider {
|
|
14
13
|
readonly id = "internal_objects";
|
|
15
|
-
supports(): boolean;
|
|
16
14
|
collect(input: ContextInput): Promise<ResolvedContext>;
|
|
17
15
|
}
|
|
18
16
|
export declare class UserModelContextProvider implements ContextProvider {
|
|
19
17
|
readonly id = "user_model";
|
|
20
|
-
supports(): boolean;
|
|
21
18
|
collect(input: ContextInput): Promise<ResolvedContext>;
|
|
22
19
|
}
|
|
23
20
|
export declare class MeetingWorkspaceContextProvider implements ContextProvider {
|
|
24
21
|
readonly id = "meeting_workspace";
|
|
25
|
-
supports(scenarioKey: string): boolean;
|
|
26
22
|
collect(input: ContextInput): Promise<ResolvedContext>;
|
|
27
23
|
}
|
|
28
24
|
export declare class ProjectStateContextProvider implements ContextProvider {
|
|
29
25
|
readonly id = "project_state";
|
|
30
|
-
supports(scenarioKey: string): boolean;
|
|
31
26
|
collect(input: ContextInput): Promise<ResolvedContext>;
|
|
32
27
|
}
|
|
33
28
|
export declare class AutomationStateContextProvider implements ContextProvider {
|
|
34
29
|
readonly id = "automation_state";
|
|
35
|
-
|
|
30
|
+
collect(input: ContextInput): Promise<ResolvedContext>;
|
|
31
|
+
}
|
|
32
|
+
export declare class DiscussionContextProvider implements ContextProvider {
|
|
33
|
+
readonly id = "discussion";
|
|
36
34
|
collect(input: ContextInput): Promise<ResolvedContext>;
|
|
37
35
|
}
|
|
38
36
|
export declare class ContextProviderRegistry {
|
|
39
37
|
private readonly providers;
|
|
40
38
|
constructor(providers?: ContextProvider[]);
|
|
41
|
-
collect(
|
|
39
|
+
collect(scenario: ScenarioDefinition, input: {
|
|
42
40
|
batchId: string;
|
|
43
41
|
eventIds: string[];
|
|
44
42
|
subscriptionId: string;
|
|
@@ -3,6 +3,7 @@ import { getKnowledgeSourceItem } from "../../storage/sqlite/knowledge-repositor
|
|
|
3
3
|
import { getConnectorSyncPolicyForConnection } from "../../storage/sqlite/connector-sync-policy-repository.js";
|
|
4
4
|
import { getAssertionSlot, listUserAssertions } from "../../user-model/repository.js";
|
|
5
5
|
import "../../user-model/index.js";
|
|
6
|
+
import { getDiscussionCapture, getLatestDiscussionOrganization } from "../../discussions/repository.js";
|
|
6
7
|
import { wrapExternalContent } from "../../gateway/security/external-content.js";
|
|
7
8
|
//#region src/proactive/execution/context.ts
|
|
8
9
|
const MAX_EVENT_COUNT = 50;
|
|
@@ -39,9 +40,6 @@ function authorizedConnectedSourceItem(event, scenarioKey) {
|
|
|
39
40
|
}
|
|
40
41
|
var EventBatchContextProvider = class {
|
|
41
42
|
id = "event_batch";
|
|
42
|
-
supports() {
|
|
43
|
-
return true;
|
|
44
|
-
}
|
|
45
43
|
async collect(input) {
|
|
46
44
|
const rows = eventRows(input.eventIds).filter((row) => !row.type.startsWith("connected_source.") || Boolean(authorizedConnectedSourceItem(row, input.scenarioKey)));
|
|
47
45
|
return {
|
|
@@ -61,9 +59,6 @@ var EventBatchContextProvider = class {
|
|
|
61
59
|
};
|
|
62
60
|
var ConnectedSourceContextProvider = class {
|
|
63
61
|
id = "connected_source";
|
|
64
|
-
supports() {
|
|
65
|
-
return true;
|
|
66
|
-
}
|
|
67
62
|
async collect(input) {
|
|
68
63
|
const items = [];
|
|
69
64
|
const snapshotItems = [];
|
|
@@ -104,9 +99,6 @@ var ConnectedSourceContextProvider = class {
|
|
|
104
99
|
};
|
|
105
100
|
var InternalObjectContextProvider = class {
|
|
106
101
|
id = "internal_objects";
|
|
107
|
-
supports() {
|
|
108
|
-
return true;
|
|
109
|
-
}
|
|
110
102
|
async collect(input) {
|
|
111
103
|
const db = getSqliteDatabase();
|
|
112
104
|
const objects = [];
|
|
@@ -157,9 +149,6 @@ var InternalObjectContextProvider = class {
|
|
|
157
149
|
};
|
|
158
150
|
var UserModelContextProvider = class {
|
|
159
151
|
id = "user_model";
|
|
160
|
-
supports() {
|
|
161
|
-
return true;
|
|
162
|
-
}
|
|
163
152
|
async collect(input) {
|
|
164
153
|
const scope = eventRows(input.eventIds).at(-1);
|
|
165
154
|
if (!scope) return emptyContext();
|
|
@@ -186,9 +175,6 @@ var UserModelContextProvider = class {
|
|
|
186
175
|
};
|
|
187
176
|
var MeetingWorkspaceContextProvider = class {
|
|
188
177
|
id = "meeting_workspace";
|
|
189
|
-
supports(scenarioKey) {
|
|
190
|
-
return scenarioKey === "meeting_preparation";
|
|
191
|
-
}
|
|
192
178
|
async collect(input) {
|
|
193
179
|
const scope = eventRows(input.eventIds).at(-1);
|
|
194
180
|
if (!scope) return emptyContext();
|
|
@@ -237,16 +223,27 @@ var MeetingWorkspaceContextProvider = class {
|
|
|
237
223
|
};
|
|
238
224
|
var ProjectStateContextProvider = class {
|
|
239
225
|
id = "project_state";
|
|
240
|
-
supports(scenarioKey) {
|
|
241
|
-
return scenarioKey === "project_delivery_risk" || scenarioKey === "blocked_work";
|
|
242
|
-
}
|
|
243
226
|
async collect(input) {
|
|
244
227
|
if (!input.eventIds.length) return emptyContext();
|
|
245
228
|
const project = getSqliteDatabase().prepare(`SELECT p.* FROM proactive_events e JOIN projects p ON p.project_id = e.project_id
|
|
246
229
|
WHERE e.event_id IN (${input.eventIds.map(() => "?").join(",")}) AND e.project_id IS NOT NULL ORDER BY e.occurred_at DESC LIMIT 1`).get(...input.eventIds);
|
|
247
230
|
if (!project) return emptyContext();
|
|
248
231
|
const tasks = getSqliteDatabase().prepare(`SELECT task.task_id, task.title, task.body,
|
|
249
|
-
task.phase, task.resolution, task.priority, task.due_at, task.updated_at
|
|
232
|
+
task.phase, task.resolution, task.priority, task.due_at, task.updated_at,
|
|
233
|
+
(SELECT wait.kind FROM task_waits wait
|
|
234
|
+
WHERE wait.task_id = task.task_id AND wait.status = 'active'
|
|
235
|
+
ORDER BY wait.created_at DESC LIMIT 1) AS wait_kind,
|
|
236
|
+
(SELECT wait.reason FROM task_waits wait
|
|
237
|
+
WHERE wait.task_id = task.task_id AND wait.status = 'active'
|
|
238
|
+
ORDER BY wait.created_at DESC LIMIT 1) AS wait_reason,
|
|
239
|
+
(SELECT json_group_array(json_object(
|
|
240
|
+
'taskId', dependency.depends_on_task_id,
|
|
241
|
+
'title', upstream.title,
|
|
242
|
+
'phase', upstream.phase,
|
|
243
|
+
'resolution', upstream.resolution
|
|
244
|
+
)) FROM task_dependencies dependency
|
|
245
|
+
JOIN tasks upstream ON upstream.task_id = dependency.depends_on_task_id
|
|
246
|
+
WHERE dependency.task_id = task.task_id) AS dependencies_json
|
|
250
247
|
FROM tasks task
|
|
251
248
|
WHERE task.project_id = ? AND task.phase <> 'closed'
|
|
252
249
|
ORDER BY CASE WHEN EXISTS (
|
|
@@ -261,10 +258,14 @@ var ProjectStateContextProvider = class {
|
|
|
261
258
|
evidenceId: projectEvidenceId,
|
|
262
259
|
...project
|
|
263
260
|
},
|
|
264
|
-
activeTasks: tasks.map((task, index) =>
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
261
|
+
activeTasks: tasks.map((task, index) => {
|
|
262
|
+
const { dependencies_json: dependenciesJson, ...fields } = task;
|
|
263
|
+
return {
|
|
264
|
+
evidenceId: taskEvidenceIds[index],
|
|
265
|
+
...fields,
|
|
266
|
+
dependencies: dependenciesJson ? JSON.parse(String(dependenciesJson)) : []
|
|
267
|
+
};
|
|
268
|
+
})
|
|
268
269
|
},
|
|
269
270
|
evidenceIds: [projectEvidenceId, ...taskEvidenceIds]
|
|
270
271
|
};
|
|
@@ -272,9 +273,6 @@ var ProjectStateContextProvider = class {
|
|
|
272
273
|
};
|
|
273
274
|
var AutomationStateContextProvider = class {
|
|
274
275
|
id = "automation_state";
|
|
275
|
-
supports(scenarioKey) {
|
|
276
|
-
return scenarioKey === "automation_failure_impact";
|
|
277
|
-
}
|
|
278
276
|
async collect(input) {
|
|
279
277
|
if (!input.eventIds.length) return emptyContext();
|
|
280
278
|
const run = getSqliteDatabase().prepare(`SELECT r.* FROM proactive_events e JOIN automation_runs r ON r.run_id = e.subject_id
|
|
@@ -282,6 +280,9 @@ var AutomationStateContextProvider = class {
|
|
|
282
280
|
if (!run) return emptyContext();
|
|
283
281
|
const automation = getSqliteDatabase().prepare(`SELECT automation_id, name, description, enabled, reliability_json, state_json, project_id
|
|
284
282
|
FROM automations WHERE automation_id = ?`).get(String(run.automation_id));
|
|
283
|
+
const recentRuns = getSqliteDatabase().prepare(`SELECT run_id, status, summary, error, duration_ms, started_at, ended_at
|
|
284
|
+
FROM automation_runs WHERE automation_id = ? AND run_id <> ?
|
|
285
|
+
ORDER BY started_at DESC LIMIT 5`).all(String(run.automation_id), String(run.run_id));
|
|
285
286
|
const runEvidenceId = `automation-run:${String(run.run_id)}`;
|
|
286
287
|
return {
|
|
287
288
|
content: {
|
|
@@ -289,12 +290,50 @@ var AutomationStateContextProvider = class {
|
|
|
289
290
|
failedRun: {
|
|
290
291
|
evidenceId: runEvidenceId,
|
|
291
292
|
...run
|
|
292
|
-
}
|
|
293
|
+
},
|
|
294
|
+
recentRuns
|
|
293
295
|
},
|
|
294
296
|
evidenceIds: [runEvidenceId]
|
|
295
297
|
};
|
|
296
298
|
}
|
|
297
299
|
};
|
|
300
|
+
var DiscussionContextProvider = class {
|
|
301
|
+
id = "discussion";
|
|
302
|
+
async collect(input) {
|
|
303
|
+
const event = eventRows(input.eventIds).findLast((row) => row.subject_kind === "discussion");
|
|
304
|
+
if (!event) return emptyContext();
|
|
305
|
+
const discussion = getDiscussionCapture(event.subject_id);
|
|
306
|
+
if (!discussion || discussion.status !== "completed") return emptyContext();
|
|
307
|
+
const organization = getLatestDiscussionOrganization(discussion.id);
|
|
308
|
+
const discussionEvidenceId = `discussion:${discussion.id}`;
|
|
309
|
+
const noteEvidenceId = `note:${discussion.noteId}`;
|
|
310
|
+
return {
|
|
311
|
+
content: { discussion: {
|
|
312
|
+
evidenceId: discussionEvidenceId,
|
|
313
|
+
id: discussion.id,
|
|
314
|
+
noteId: discussion.noteId,
|
|
315
|
+
noteEvidenceId,
|
|
316
|
+
projectId: discussion.projectId,
|
|
317
|
+
title: discussion.generatedTitle,
|
|
318
|
+
transcript: boundedText(discussion.canonicalTranscript, 6e3),
|
|
319
|
+
organization: organization?.organization,
|
|
320
|
+
completedAt: discussion.completedAt
|
|
321
|
+
} },
|
|
322
|
+
snapshotContent: { discussion: {
|
|
323
|
+
evidenceId: discussionEvidenceId,
|
|
324
|
+
id: discussion.id,
|
|
325
|
+
noteId: discussion.noteId,
|
|
326
|
+
noteEvidenceId,
|
|
327
|
+
projectId: discussion.projectId,
|
|
328
|
+
transcriptSha256: discussion.canonicalTranscriptSha256,
|
|
329
|
+
organizationRevision: organization?.revision,
|
|
330
|
+
organization: organization?.organization,
|
|
331
|
+
completedAt: discussion.completedAt
|
|
332
|
+
} },
|
|
333
|
+
evidenceIds: [discussionEvidenceId, noteEvidenceId]
|
|
334
|
+
};
|
|
335
|
+
}
|
|
336
|
+
};
|
|
298
337
|
var ContextProviderRegistry = class {
|
|
299
338
|
constructor(providers = [
|
|
300
339
|
new EventBatchContextProvider(),
|
|
@@ -303,14 +342,21 @@ var ContextProviderRegistry = class {
|
|
|
303
342
|
new UserModelContextProvider(),
|
|
304
343
|
new MeetingWorkspaceContextProvider(),
|
|
305
344
|
new ProjectStateContextProvider(),
|
|
306
|
-
new AutomationStateContextProvider()
|
|
345
|
+
new AutomationStateContextProvider(),
|
|
346
|
+
new DiscussionContextProvider()
|
|
307
347
|
]) {
|
|
308
348
|
this.providers = providers;
|
|
309
349
|
}
|
|
310
|
-
async collect(
|
|
311
|
-
const
|
|
350
|
+
async collect(scenario, input) {
|
|
351
|
+
const providers = new Map(this.providers.map((provider) => [provider.id, provider]));
|
|
352
|
+
const selected = scenario.contextProviderIds.map((id) => {
|
|
353
|
+
const provider = providers.get(id);
|
|
354
|
+
if (!provider) throw new Error(`Unknown context provider: ${id}`);
|
|
355
|
+
return provider;
|
|
356
|
+
});
|
|
357
|
+
const entries = await Promise.all(selected.map(async (provider) => [provider.id, await provider.collect({
|
|
312
358
|
...input,
|
|
313
|
-
scenarioKey
|
|
359
|
+
scenarioKey: scenario.key
|
|
314
360
|
})]));
|
|
315
361
|
return {
|
|
316
362
|
content: Object.fromEntries(entries.map(([id, result]) => [id, result.content])),
|
|
@@ -320,4 +366,4 @@ var ContextProviderRegistry = class {
|
|
|
320
366
|
}
|
|
321
367
|
};
|
|
322
368
|
//#endregion
|
|
323
|
-
export { AutomationStateContextProvider, ConnectedSourceContextProvider, ContextProviderRegistry, EventBatchContextProvider, InternalObjectContextProvider, MeetingWorkspaceContextProvider, ProjectStateContextProvider, UserModelContextProvider };
|
|
369
|
+
export { AutomationStateContextProvider, ConnectedSourceContextProvider, ContextProviderRegistry, DiscussionContextProvider, EventBatchContextProvider, InternalObjectContextProvider, MeetingWorkspaceContextProvider, ProjectStateContextProvider, UserModelContextProvider };
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import type { InsightCandidate } from './types.js';
|
|
2
2
|
export declare function parseInsightCandidate(raw: string, allowedEvidenceIds: Set<string>): InsightCandidate;
|
|
3
3
|
export declare function scoreInsight(candidate: InsightCandidate): number;
|
|
4
|
-
export declare function isValuableInsight(candidate: InsightCandidate
|
|
4
|
+
export declare function isValuableInsight(candidate: InsightCandidate, policy?: {
|
|
5
|
+
minConfidence: number;
|
|
6
|
+
minScore: number;
|
|
7
|
+
}): boolean;
|
|
@@ -87,8 +87,11 @@ function scoreInsight(candidate) {
|
|
|
87
87
|
}[candidate.urgency];
|
|
88
88
|
return Math.round((candidate.confidence * .7 + urgencyWeight * .3) * 1e3) / 1e3;
|
|
89
89
|
}
|
|
90
|
-
function isValuableInsight(candidate
|
|
91
|
-
|
|
90
|
+
function isValuableInsight(candidate, policy = {
|
|
91
|
+
minConfidence: .65,
|
|
92
|
+
minScore: .6
|
|
93
|
+
}) {
|
|
94
|
+
return candidate.confidence >= policy.minConfidence && candidate.urgency !== "low" && scoreInsight(candidate) >= policy.minScore;
|
|
92
95
|
}
|
|
93
96
|
//#endregion
|
|
94
97
|
export { isValuableInsight, parseInsightCandidate, scoreInsight };
|
|
@@ -5,8 +5,16 @@ const str = (row, key) => String(row[key]);
|
|
|
5
5
|
function claimNextRun(owner, now = /* @__PURE__ */ new Date(), leaseSeconds = 120) {
|
|
6
6
|
return runSqliteWriteTransaction((db) => {
|
|
7
7
|
const nowIso = now.toISOString();
|
|
8
|
+
const dayStart = new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate())).toISOString();
|
|
8
9
|
db.prepare(`UPDATE proactive_signal_batches SET status = 'ignored', updated_at = ? WHERE status = 'ready'
|
|
9
10
|
AND subscription_id IN (SELECT subscription_id FROM proactive_scenario_subscriptions WHERE enabled = 0)`).run(nowIso);
|
|
11
|
+
db.prepare(`UPDATE proactive_signal_batches AS batch SET status = 'ignored', updated_at = ?
|
|
12
|
+
WHERE batch.status = 'ready' AND EXISTS (
|
|
13
|
+
SELECT 1 FROM proactive_scenario_versions scenario
|
|
14
|
+
WHERE scenario.scenario_key = batch.scenario_key AND scenario.version = batch.scenario_version
|
|
15
|
+
AND (SELECT COUNT(*) FROM proactive_runs run
|
|
16
|
+
WHERE run.scenario_key = batch.scenario_key AND run.started_at >= ?) >= scenario.max_runs_per_day
|
|
17
|
+
)`).run(nowIso, dayStart);
|
|
10
18
|
db.prepare(`UPDATE proactive_signal_batches SET status = 'failed_permanent', updated_at = ?
|
|
11
19
|
WHERE status = 'processing' AND batch_id IN (
|
|
12
20
|
SELECT batch_id FROM proactive_runs WHERE status = 'running' AND lease_expires_at <= ? AND attempt >= 3
|
|
@@ -80,7 +88,7 @@ function finishRun(input, now = /* @__PURE__ */ new Date()) {
|
|
|
80
88
|
input.candidate.recommendation
|
|
81
89
|
].map((value) => value.trim().toLowerCase().replace(/\s+/g, " "))].join("\n")).digest("hex") : void 0;
|
|
82
90
|
const duplicate = fingerprint ? db.prepare(`SELECT 1 FROM proactive_insights
|
|
83
|
-
WHERE subscription_id = ? AND scenario_key = ? AND content_fingerprint = ? AND created_at >= ? LIMIT 1`).get(input.run.subscriptionId, input.run.scenarioKey, fingerprint, (/* @__PURE__ */ new Date(now.getTime() - 10080 *
|
|
91
|
+
WHERE subscription_id = ? AND scenario_key = ? AND content_fingerprint = ? AND created_at >= ? LIMIT 1`).get(input.run.subscriptionId, input.run.scenarioKey, fingerprint, (/* @__PURE__ */ new Date(now.getTime() - (input.cooldownSeconds ?? 10080 * 60) * 1e3)).toISOString()) : void 0;
|
|
84
92
|
const valuable = Boolean(input.candidate) && !duplicate;
|
|
85
93
|
db.prepare(`UPDATE proactive_runs SET status = ?, raw_output = ?, model_ref = ?, lease_owner = NULL,
|
|
86
94
|
lease_expires_at = NULL, completed_at = ?, updated_at = ? WHERE run_id = ?`).run(valuable ? "completed" : "discarded", input.rawOutput.slice(0, 2e4), input.modelRef ?? null, nowIso, nowIso, input.run.id);
|
|
@@ -40,11 +40,11 @@ var ProactiveWorker = class {
|
|
|
40
40
|
const run = claimNextRun(this.owner);
|
|
41
41
|
if (!run) return;
|
|
42
42
|
try {
|
|
43
|
-
const scenario = getScenario(run.scenarioKey);
|
|
44
|
-
if (!scenario
|
|
43
|
+
const scenario = getScenario(run.scenarioKey, run.scenarioVersion);
|
|
44
|
+
if (!scenario) throw new Error("Pinned scenario version is unavailable");
|
|
45
45
|
const revision = run.promptRevisionId ? getPromptRevision(run.promptRevisionId) ?? void 0 : void 0;
|
|
46
46
|
const eventIds = eventIdsForBatch(run.batchId);
|
|
47
|
-
const context = await this.contexts.collect(
|
|
47
|
+
const context = await this.contexts.collect(scenario, {
|
|
48
48
|
batchId: run.batchId,
|
|
49
49
|
eventIds,
|
|
50
50
|
subscriptionId: run.subscriptionId
|
|
@@ -62,13 +62,15 @@ var ProactiveWorker = class {
|
|
|
62
62
|
authorizedContext: context.content
|
|
63
63
|
});
|
|
64
64
|
const candidate = parseInsightCandidate(output.text, new Set(context.evidenceIds));
|
|
65
|
-
const
|
|
65
|
+
const valueScore = scoreInsight(candidate);
|
|
66
|
+
const valuable = isValuableInsight(candidate, scenario.valuePolicy);
|
|
66
67
|
const insight = finishRun({
|
|
67
68
|
run,
|
|
68
69
|
...valuable ? {
|
|
69
70
|
candidate,
|
|
70
|
-
valueScore
|
|
71
|
+
valueScore
|
|
71
72
|
} : {},
|
|
73
|
+
cooldownSeconds: scenario.valuePolicy.cooldownSeconds,
|
|
72
74
|
rawOutput: output.text,
|
|
73
75
|
modelRef: output.modelRef
|
|
74
76
|
});
|
|
@@ -4,6 +4,7 @@ import { randomUUID } from "node:crypto";
|
|
|
4
4
|
//#region src/proactive/inbox/repository.ts
|
|
5
5
|
const s = (row, key) => String(row[key]);
|
|
6
6
|
function itemFromRow(row) {
|
|
7
|
+
const attentionKind = row.action_status === "completed" ? "receipt" : row.decision_json || row.action_status === "approval_required" ? "decision" : "information";
|
|
7
8
|
return {
|
|
8
9
|
id: s(row, "inbox_item_id"),
|
|
9
10
|
insightId: s(row, "insight_id"),
|
|
@@ -30,7 +31,8 @@ function itemFromRow(row) {
|
|
|
30
31
|
urgency: s(row, "urgency"),
|
|
31
32
|
confidence: Number(row.confidence),
|
|
32
33
|
valueScore: Number(row.value_score),
|
|
33
|
-
evidenceIds: JSON.parse(s(row, "evidence_ids_json"))
|
|
34
|
+
evidenceIds: JSON.parse(s(row, "evidence_ids_json")),
|
|
35
|
+
attentionKind
|
|
34
36
|
}
|
|
35
37
|
};
|
|
36
38
|
}
|
|
@@ -124,13 +126,17 @@ function transitionInboxItem(id, input, now = /* @__PURE__ */ new Date()) {
|
|
|
124
126
|
function recordDecision(id, choice, note = "", now = /* @__PURE__ */ new Date()) {
|
|
125
127
|
if (!choice.trim()) throw new Error("choice is required");
|
|
126
128
|
runSqliteWriteTransaction((db) => {
|
|
127
|
-
const row = db.prepare(`SELECT x.decision_json FROM proactive_inbox_items i
|
|
129
|
+
const row = db.prepare(`SELECT i.status, x.decision_json, x.action_status FROM proactive_inbox_items i
|
|
128
130
|
JOIN proactive_insights x ON x.insight_id = i.insight_id WHERE i.inbox_item_id = ?`).get(id);
|
|
129
131
|
if (!row) throw new Error("Inbox item not found");
|
|
132
|
+
if (row.status === "resolved") throw new Error("Inbox item is already resolved");
|
|
130
133
|
if (!row.decision_json) throw new Error("Inbox item does not require a decision");
|
|
131
134
|
if (!JSON.parse(row.decision_json).options.some((option) => option.id === choice.trim())) throw new Error("choice is not a valid decision option");
|
|
132
135
|
db.prepare("INSERT INTO proactive_decisions (decision_id, inbox_item_id, choice, note, created_at) VALUES (?, ?, ?, ?, ?)").run(randomUUID(), id, choice.trim().slice(0, 200), note.trim().slice(0, 2e3), now.toISOString());
|
|
133
136
|
db.prepare("UPDATE proactive_inbox_items SET status = 'resolved', resolution = ?, updated_at = ? WHERE inbox_item_id = ?").run(choice.trim().slice(0, 200), now.toISOString(), id);
|
|
137
|
+
if (row.action_status === "approval_required") db.prepare(`UPDATE proactive_insights SET action_status = ?, action_updated_at = ?
|
|
138
|
+
WHERE insight_id = (SELECT insight_id FROM proactive_inbox_items WHERE inbox_item_id = ?)
|
|
139
|
+
AND action_status = 'approval_required'`).run(choice === "approve" ? "pending" : "rejected", now.toISOString(), id);
|
|
134
140
|
});
|
|
135
141
|
return getInboxItem(id);
|
|
136
142
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { publishInstructionFeedback } from "../scenarios/repository.js";
|
|
2
|
-
import {
|
|
2
|
+
import { executePendingProactiveActions } from "../actions/service.js";
|
|
3
3
|
import { getInboxItem, getInboxSubscriptionId, listInbox, projectInsightsToInbox, recordDecision, recordFeedback, transitionInboxItem, wakeSnoozedItems } from "./repository.js";
|
|
4
4
|
//#region src/proactive/inbox/service.ts
|
|
5
5
|
var ProactiveInboxService = class {
|
|
@@ -9,7 +9,7 @@ var ProactiveInboxService = class {
|
|
|
9
9
|
feedback = recordFeedback;
|
|
10
10
|
decide(id, choice, note = "") {
|
|
11
11
|
const item = recordDecision(id, choice, note);
|
|
12
|
-
|
|
12
|
+
if (choice === "approve") executePendingProactiveActions();
|
|
13
13
|
return getInboxItem(id) ?? item;
|
|
14
14
|
}
|
|
15
15
|
instruct(id, instruction) {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { createLogger } from "../../utils/logger/index.js";
|
|
2
2
|
import { init_logger } from "../../utils/logger.js";
|
|
3
|
+
import { pruneProactiveHistory } from "../maintenance.js";
|
|
3
4
|
import { executePendingProactiveActions } from "../actions/service.js";
|
|
4
5
|
import { claimDelivery, finishDelivery, projectInsightsToInbox, recoverExpiredDeliveries, wakeSnoozedItems } from "./repository.js";
|
|
5
6
|
//#region src/proactive/inbox/worker.ts
|
|
@@ -9,6 +10,7 @@ var ProactiveInboxWorker = class {
|
|
|
9
10
|
timer;
|
|
10
11
|
running = false;
|
|
11
12
|
waiters = [];
|
|
13
|
+
lastMaintenanceAt = 0;
|
|
12
14
|
constructor(delivery, intervalMs = 3e3) {
|
|
13
15
|
this.delivery = delivery;
|
|
14
16
|
this.intervalMs = intervalMs;
|
|
@@ -28,6 +30,11 @@ var ProactiveInboxWorker = class {
|
|
|
28
30
|
if (this.running) return;
|
|
29
31
|
this.running = true;
|
|
30
32
|
try {
|
|
33
|
+
const now = Date.now();
|
|
34
|
+
if (now - this.lastMaintenanceAt >= 60 * 6e4) {
|
|
35
|
+
pruneProactiveHistory(new Date(now));
|
|
36
|
+
this.lastMaintenanceAt = now;
|
|
37
|
+
}
|
|
31
38
|
projectInsightsToInbox();
|
|
32
39
|
executePendingProactiveActions();
|
|
33
40
|
wakeSnoozedItems();
|
|
@@ -6,6 +6,7 @@ export { matchesCondition, matchScenario } from './routing/matcher.js';
|
|
|
6
6
|
export type { EventCondition, ScenarioRoute } from './routing/types.js';
|
|
7
7
|
export type { SignalBatch } from './routing/batch-repository.js';
|
|
8
8
|
export { ProactiveEventService } from './service.js';
|
|
9
|
+
export { pruneProactiveHistory } from './maintenance.js';
|
|
9
10
|
export { ProactiveScenarioService } from './scenarios/service.js';
|
|
10
11
|
export type { PromptRevision, ScenarioDefinition, ScenarioSubscription } from './scenarios/types.js';
|
|
11
12
|
export { AutomationStateContextProvider, ConnectedSourceContextProvider, ContextProviderRegistry, EventBatchContextProvider, InternalObjectContextProvider, MeetingWorkspaceContextProvider, ProjectStateContextProvider, UserModelContextProvider, } from './execution/context.js';
|
|
@@ -3,6 +3,7 @@ import { normalizeEventEnvelope } from "./events/envelope.js";
|
|
|
3
3
|
import { mapProductEventToProactive } from "./events/product-event-bridge.js";
|
|
4
4
|
import { matchScenario, matchesCondition } from "./routing/matcher.js";
|
|
5
5
|
import { ProactiveEventService } from "./service.js";
|
|
6
|
+
import { pruneProactiveHistory } from "./maintenance.js";
|
|
6
7
|
import { AutomationStateContextProvider, ConnectedSourceContextProvider, ContextProviderRegistry, EventBatchContextProvider, InternalObjectContextProvider, MeetingWorkspaceContextProvider, ProjectStateContextProvider, UserModelContextProvider } from "./execution/context.js";
|
|
7
8
|
import { ReadonlyProactiveAgentExecutor } from "./execution/agent-executor.js";
|
|
8
9
|
import { listInsights } from "./execution/repository.js";
|
|
@@ -10,4 +11,4 @@ import { ProactiveWorker } from "./execution/worker.js";
|
|
|
10
11
|
import { ProactiveTemporalWorker } from "./temporal/worker.js";
|
|
11
12
|
import { ProactiveInboxService } from "./inbox/service.js";
|
|
12
13
|
import { ProactiveInboxWorker } from "./inbox/worker.js";
|
|
13
|
-
export { AutomationStateContextProvider, ConnectedSourceContextProvider, ContextProviderRegistry, EventBatchContextProvider, InternalObjectContextProvider, MeetingWorkspaceContextProvider, ProactiveEventService, ProactiveInboxService, ProactiveInboxWorker, ProactiveScenarioService, ProactiveTemporalWorker, ProactiveWorker, ProjectStateContextProvider, ReadonlyProactiveAgentExecutor, UserModelContextProvider, listInsights, mapProductEventToProactive, matchScenario, matchesCondition, normalizeEventEnvelope };
|
|
14
|
+
export { AutomationStateContextProvider, ConnectedSourceContextProvider, ContextProviderRegistry, EventBatchContextProvider, InternalObjectContextProvider, MeetingWorkspaceContextProvider, ProactiveEventService, ProactiveInboxService, ProactiveInboxWorker, ProactiveScenarioService, ProactiveTemporalWorker, ProactiveWorker, ProjectStateContextProvider, ReadonlyProactiveAgentExecutor, UserModelContextProvider, listInsights, mapProductEventToProactive, matchScenario, matchesCondition, normalizeEventEnvelope, pruneProactiveHistory };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { runSqliteWriteTransaction } from "../storage/sqlite/transaction.js";
|
|
2
|
+
//#region src/proactive/maintenance.ts
|
|
3
|
+
const RETENTION_DAYS = 90;
|
|
4
|
+
function pruneProactiveHistory(now = /* @__PURE__ */ new Date()) {
|
|
5
|
+
const cutoff = (/* @__PURE__ */ new Date(now.getTime() - RETENTION_DAYS * 24 * 60 * 6e4)).toISOString();
|
|
6
|
+
return runSqliteWriteTransaction((db) => {
|
|
7
|
+
const batches = db.prepare(`DELETE FROM proactive_signal_batches
|
|
8
|
+
WHERE updated_at < ? AND status IN ('processed', 'ignored', 'failed_permanent', 'expired')`).run(cutoff).changes;
|
|
9
|
+
const events = db.prepare(`DELETE FROM proactive_events
|
|
10
|
+
WHERE observed_at < ? AND NOT EXISTS (
|
|
11
|
+
SELECT 1 FROM proactive_batch_events batch_event
|
|
12
|
+
WHERE batch_event.event_id = proactive_events.event_id
|
|
13
|
+
)`).run(cutoff).changes;
|
|
14
|
+
return {
|
|
15
|
+
batches: Number(batches),
|
|
16
|
+
events: Number(events)
|
|
17
|
+
};
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
//#endregion
|
|
21
|
+
export { pruneProactiveHistory };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ScenarioRoute } from '../routing/types.js';
|
|
2
2
|
import type { PromptRevision, ScenarioDefinition, ScenarioSubscription } from './types.js';
|
|
3
3
|
export declare function listScenarios(): ScenarioDefinition[];
|
|
4
|
-
export declare function getScenario(key: string): ScenarioDefinition | null;
|
|
4
|
+
export declare function getScenario(key: string, version?: number): ScenarioDefinition | null;
|
|
5
5
|
export declare function upsertSubscription(input: {
|
|
6
6
|
scenarioKey: string;
|
|
7
7
|
workspaceId: string;
|