@xopcai/xopc 0.0.189 → 0.0.190
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/README.md +0 -3
- package/README.zh-CN.md +0 -3
- 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-DTFKTPs8.js → activity-store-DstnJCS5.js} +1 -1
- package/dist/gateway/static/root/assets/{agent-avatar-dicebear-DqO25Qe5.js → agent-avatar-dicebear-9vAbkroX.js} +1 -1
- package/dist/gateway/static/root/assets/agents-D1t4SfMQ.js +68 -0
- package/dist/gateway/static/root/assets/{api-DWeXfwVU.js → api-BTL9kayv.js} +1 -1
- package/dist/gateway/static/root/assets/{app-management-settings-panel-BRpV8PXG.js → app-management-settings-panel-DkFeIdBf.js} +1 -1
- package/dist/gateway/static/root/assets/{appearance-settings-3ntKM9nQ.js → appearance-settings-Bxs8Fpaj.js} +1 -1
- package/dist/gateway/static/root/assets/apps-page-Cgrgu5OW.js +1 -0
- package/dist/gateway/static/root/assets/{archive-plugin-Df7Ycj_7.js → archive-plugin-Ch2RmLCC.js} +1 -1
- package/dist/gateway/static/root/assets/{attachment-load-UHgfZYtj.js → attachment-load-BhMQM_Ky.js} +1 -1
- package/dist/gateway/static/root/assets/automations-page-CtJxstKh.js +6 -0
- package/dist/gateway/static/root/assets/{binary-plugins-BJah99wE.js → binary-plugins-D6CqlymH.js} +1 -1
- package/dist/gateway/static/root/assets/{block-editor-DNlY5KqF.js → block-editor-ClL6HEg9.js} +48 -48
- package/dist/gateway/static/root/assets/browser-settings-page-DW99iDmD.js +8 -0
- package/dist/gateway/static/root/assets/{browser-workflow-inputs-vyUfdzAd.js → browser-workflow-inputs-BYy48VhN.js} +1 -1
- package/dist/gateway/static/root/assets/{browser-workflows-page-C1cKZjx-.js → browser-workflows-page-zgLibuMH.js} +2 -2
- package/dist/gateway/static/root/assets/capabilities-settings-panel-CHUrT9EB.js +7 -0
- package/dist/gateway/static/root/assets/capability-presets-api-BB8t4Ja7.js +1 -0
- package/dist/gateway/static/root/assets/capability-presets-settings-panel-Cycrv0YV.js +1 -0
- package/dist/gateway/static/root/assets/{channel-recipient-api-BGG2kpJB.js → channel-recipient-api-BThDGiO3.js} +1 -1
- package/dist/gateway/static/root/assets/channels-settings-V96gPUAU.js +1 -0
- package/dist/gateway/static/root/assets/channels-status-swr-Cz7SAAkm.js +1 -0
- package/dist/gateway/static/root/assets/connectors-api-DS9ED-EL.js +1 -0
- package/dist/gateway/static/root/assets/connectors-page-BhlyQoQI.js +2 -0
- package/dist/gateway/static/root/assets/cron-expression-CkgsvhtW.js +2 -0
- package/dist/gateway/static/root/assets/{desktop-pet-BUuBEJuP.js → desktop-pet-Cv8rGhYW.js} +1 -1
- package/dist/gateway/static/root/assets/{desktop-pet-settings-BGfVIJM3.js → desktop-pet-settings-CIeJdwfV.js} +1 -1
- package/dist/gateway/static/root/assets/{directory-picker-path-field-DrQFfHH_.js → directory-picker-path-field-D8jXEiAY.js} +1 -1
- package/dist/gateway/static/root/assets/{extension-debug-page-CEnIFOX-.js → extension-debug-page-CCZ9u6TZ.js} +1 -1
- package/dist/gateway/static/root/assets/{extension-page-CCqHbexs.js → extension-page-CV36ILRG.js} +1 -1
- package/dist/gateway/static/root/assets/extension-settings-page-IyQrSILY.js +1 -0
- package/dist/gateway/static/root/assets/{gateway-config-api-CgUE2Ii1.js → gateway-config-api-D4_r5iJM.js} +1 -1
- package/dist/gateway/static/root/assets/gateway-settings-CYlntpBH.js +1 -0
- package/dist/gateway/static/root/assets/{gateway-startup-retry-DxhKNiCF.js → gateway-startup-retry-EO9mKvzE.js} +1 -1
- package/dist/gateway/static/root/assets/heartbeat-settings-D4SyWob8.js +1 -0
- package/dist/gateway/static/root/assets/home-page-B2Kagoh8.js +3 -0
- package/dist/gateway/static/root/assets/{image-generation-api-DCFdc-HD.js → image-generation-api-Bu7PyVSh.js} +1 -1
- package/dist/gateway/static/root/assets/index-CYT5DOzr.js +150 -0
- package/dist/gateway/static/root/assets/index-D6e3tPL-.css +1 -0
- package/dist/gateway/static/root/assets/{keyboard-shortcuts-settings-Bf2VLtXW.js → keyboard-shortcuts-settings-BMhCuVBZ.js} +1 -1
- package/dist/gateway/static/root/assets/local-app-workbench-page-BHYbFjqy.js +2 -0
- package/dist/gateway/static/root/assets/{local-apps-page-Ca1RuI13.js → local-apps-page-ijIe7_y2.js} +1 -1
- package/dist/gateway/static/root/assets/locale-store-deR2zRaE.js +1 -0
- package/dist/gateway/static/root/assets/logs-page-IIn8Tess.js +2 -0
- package/dist/gateway/static/root/assets/{management-settings-B3Eop1zn.js → management-settings--V_fovKD.js} +1 -1
- package/dist/gateway/static/root/assets/{markdown-split-BGOYjgnM.js → markdown-split-Dt9-in6W.js} +1 -1
- package/dist/gateway/static/root/assets/{media-plugins-CT0txyM4.js → media-plugins-B3pj_iO0.js} +1 -1
- package/dist/gateway/static/root/assets/messages-B4XqB8I6.js +3 -0
- package/dist/gateway/static/root/assets/{notes-page-DfKgAe78.js → notes-page-DZ366lIT.js} +1 -1
- package/dist/gateway/static/root/assets/notes-workbench-S2sBVOLw.js +4 -0
- package/dist/gateway/static/root/assets/{page-tabs-DNrbCgmC.js → page-tabs-C5ge434C.js} +1 -1
- package/dist/gateway/static/root/assets/{preview-open-alternatives-BTqViDOR.js → preview-open-alternatives-BFa9DgSV.js} +1 -1
- package/dist/gateway/static/root/assets/{product-open-page-C_2L4_Iu.js → product-open-page-Dc9CcWdu.js} +1 -1
- package/dist/gateway/static/root/assets/project-detail-page-BilzoCJ7.js +1 -0
- package/dist/gateway/static/root/assets/projects-page-BoQUyacP.js +1 -0
- package/dist/gateway/static/root/assets/remote-access-hub-DUyUaCRF.js +1 -0
- package/dist/gateway/static/root/assets/{schema-form-BFLfkDGG.js → schema-form-B84DckWe.js} +1 -1
- package/dist/gateway/static/root/assets/sessions-page-Dzxlq1F0.js +1 -0
- package/dist/gateway/static/root/assets/settings-advanced-gate-TzwlZxU6.js +1 -0
- package/dist/gateway/static/root/assets/settings-form-section-Dp9itvdy.js +1 -0
- package/dist/gateway/static/root/assets/{settings-loading-skeleton-C9a-EbTZ.js → settings-loading-skeleton-CCtlhoy7.js} +1 -1
- package/dist/gateway/static/root/assets/{settings-page-DI9qDH5x.js → settings-page-DQmMKf8r.js} +1 -1
- package/dist/gateway/static/root/assets/{settings-page-layout-D-LWQdI5.js → settings-page-layout-EQIOJa_L.js} +1 -1
- package/dist/gateway/static/root/assets/{setup-status-panel-CJwmPvgs.js → setup-status-panel-Cwi-SPja.js} +1 -1
- package/dist/gateway/static/root/assets/{share-preview-page-BKSMG9r5.js → share-preview-page-C4_B2jvf.js} +1 -1
- package/dist/gateway/static/root/assets/shares-settings-CkyuGlZK.js +1 -0
- package/dist/gateway/static/root/assets/skill-reload-api-BJCePQK5.js +1 -0
- package/dist/gateway/static/root/assets/skills-page-BYWLfmJi.js +2 -0
- package/dist/gateway/static/root/assets/{skills-page.utils-zsz2HIlZ.js → skills-page.utils-Jhm24i4h.js} +1 -1
- package/dist/gateway/static/root/assets/{system-settings-panel-IWNDBI1O.js → system-settings-panel-Dpx2ags2.js} +1 -1
- package/dist/gateway/static/root/assets/{task-detail-page-CgtK02kP.js → task-detail-page-DLAdxI6e.js} +1 -1
- package/dist/gateway/static/root/assets/{theme-store-BkJe7UDo.js → theme-store-DnBOcGXi.js} +1 -1
- package/dist/gateway/static/root/assets/{typed-models-lib-C07LGthO.js → typed-models-lib-DULmTHUB.js} +1 -1
- package/dist/gateway/static/root/assets/use-autosave-BrjVk5VH.js +1 -0
- package/dist/gateway/static/root/assets/user-context-page-9AAFpGAL.js +1 -0
- package/dist/gateway/static/root/assets/{voice-api-key-field-Boue1D46.js → voice-api-key-field-BISTPfq_.js} +1 -1
- package/dist/gateway/static/root/assets/{work-discovery-overlay-bbmvCmc8.js → work-discovery-overlay-Wr-uF7VA.js} +1 -1
- package/dist/gateway/static/root/assets/work-discovery-page-BWds95sL.js +1 -0
- package/dist/gateway/static/root/assets/{workflow-run-setup-panel-DlHv-GZC.js → workflow-run-setup-panel-DHqHP8_6.js} +2 -2
- package/dist/gateway/static/root/assets/workflows-page-0b4_DFHr.js +11 -0
- package/dist/gateway/static/root/index.html +7 -7
- package/dist/package.js +1 -1
- package/dist/packages/gateway-contract/src/tool-activity.js +0 -36
- package/dist/packages/realtime-client/src/index.js +105 -48
- package/dist/packages/realtime-protocol/src/index.js +6 -1
- package/dist/src/agent/agent-manager.d.ts +0 -1
- package/dist/src/agent/agent-manager.js +6 -13
- package/dist/src/agent/background-review/coordinator.js +1 -1
- package/dist/src/agent/background-review/run-background-review.js +5 -7
- package/dist/src/agent/bootstrap/bootstrap-cache.d.ts +0 -1
- package/dist/src/agent/bootstrap/bootstrap-cache.js +3 -4
- package/dist/src/agent/bootstrap/bootstrap-files.d.ts +0 -4
- package/dist/src/agent/bootstrap/bootstrap-files.js +3 -4
- package/dist/src/agent/bootstrap/filter-bootstrap-files.js +1 -4
- package/dist/src/agent/bootstrap/load-bootstrap-files.d.ts +0 -1
- package/dist/src/agent/bootstrap/load-bootstrap-files.js +1 -14
- package/dist/src/agent/bootstrap/types.d.ts +1 -1
- package/dist/src/agent/context/workspace-templates/SOUL.md +1 -1
- package/dist/src/agent/memory/builtin-provider.d.ts +2 -4
- package/dist/src/agent/memory/builtin-provider.js +35 -15
- package/dist/src/agent/memory/context/types.d.ts +3 -1
- package/dist/src/agent/memory/create-memory-manager.js +2 -0
- package/dist/src/agent/memory/index.d.ts +1 -1
- package/dist/src/agent/memory/index.js +1 -1
- package/dist/src/agent/memory/manager.d.ts +9 -1
- package/dist/src/agent/memory/manager.js +39 -9
- package/dist/src/agent/memory/memory-config.d.ts +1 -1
- package/dist/src/agent/memory/memory-config.js +1 -1
- package/dist/src/agent/memory/source-origin.js +0 -2
- package/dist/src/agent/memory/types.d.ts +5 -1
- package/dist/src/agent/memory/understanding/service.d.ts +10 -10
- package/dist/src/agent/memory/understanding/service.js +108 -176
- package/dist/src/agent/memory/understanding/types.d.ts +7 -8
- package/dist/src/agent/memory/user-context-coordinator.d.ts +2 -1
- package/dist/src/agent/memory/user-context-coordinator.js +27 -41
- package/dist/src/agent/orchestration/agent-orchestrator.js +4 -7
- package/dist/src/agent/prompt/sections/memory-skills.js +4 -4
- package/dist/src/agent/prompt/sections/tooling.js +0 -10
- package/dist/src/agent/prompt/service-prompt-builder.d.ts +0 -1
- package/dist/src/agent/prompt/service-prompt-builder.js +4 -33
- package/dist/src/agent/prompt/system-prompt.js +1 -2
- package/dist/src/agent/service/direct-turn-helpers.js +1 -1
- package/dist/src/agent/service.d.ts +1 -2
- package/dist/src/agent/service.js +4 -17
- package/dist/src/agent/skills/marketplace/adapters/clawhub/adapter.js +1 -1
- package/dist/src/agent/tools/dreaming-tool.d.ts +0 -2
- package/dist/src/agent/tools/dreaming-tool.js +13 -38
- package/dist/src/agent/tools/factory.d.ts +0 -3
- package/dist/src/agent/tools/factory.js +1 -10
- package/dist/src/agent/tools/index.d.ts +0 -1
- package/dist/src/agent/tools/index.js +1 -2
- package/dist/src/agent/tools/memory-tool.js +1 -1
- package/dist/src/agent/workspace-runtime/registry.d.ts +3 -5
- package/dist/src/agent/workspace-runtime/registry.js +2 -15
- package/dist/src/agent-manifest/schema.d.ts +17 -17
- package/dist/src/agent-runtime/index.js +1 -1
- package/dist/src/agent-runtime/memory-runtime.d.ts +2 -2
- package/dist/src/agent-runtime/runtime-profile.js +1 -1
- package/dist/src/automations/domain/validation.d.ts +28 -28
- package/dist/src/automations/draft/automation-draft-validator.d.ts +3 -3
- package/dist/src/chat-commands/builtins/understanding.js +2 -5
- package/dist/src/cli/commands/doctor/checks/database-schema.js +1 -1
- package/dist/src/cli/commands/init.js +3 -22
- package/dist/src/cli/templates.js +1 -1
- package/dist/src/config/index.js +3 -3
- package/dist/src/config/paths.d.ts +0 -5
- package/dist/src/config/paths.js +2 -11
- package/dist/src/config/schema.d.ts +24 -117
- package/dist/src/config/schema.js +9 -39
- package/dist/src/connectors/learning-coordinator.js +75 -3
- package/dist/src/gateway/agent-builtin-tools.d.ts +1 -1
- package/dist/src/gateway/agent-builtin-tools.js +0 -5
- package/dist/src/gateway/agents-admin.d.ts +0 -7
- package/dist/src/gateway/agents-admin.js +3 -32
- package/dist/src/gateway/dreaming-automation-reconciler.d.ts +3 -3
- package/dist/src/gateway/dreaming-automation-reconciler.js +48 -88
- package/dist/src/gateway/hono/lib/config-payload.d.ts +19 -7
- package/dist/src/gateway/hono/lib/config-payload.js +3 -1
- package/dist/src/gateway/hono/oauth-async.d.ts +1 -0
- package/dist/src/gateway/hono/oauth-async.js +17 -2
- package/dist/src/gateway/hono/routes/agents.js +1 -33
- package/dist/src/gateway/hono/routes/config-patch/misc.js +17 -1
- package/dist/src/gateway/hono/routes/connectors.js +13 -12
- package/dist/src/gateway/hono/routes/index.js +2 -2
- package/dist/src/gateway/hono/routes/lazy-bundles.js +1 -5
- package/dist/src/gateway/hono/routes/status.js +0 -7
- package/dist/src/gateway/hono/routes/understanding-sources.d.ts +3 -0
- package/dist/src/gateway/hono/routes/understanding-sources.js +203 -0
- package/dist/src/gateway/hono/routes/work-discovery.d.ts +2 -0
- package/dist/src/gateway/hono/routes/work-discovery.js +3 -134
- package/dist/src/gateway/hono/routes/you.d.ts +0 -22
- package/dist/src/gateway/hono/routes/you.js +234 -1118
- package/dist/src/gateway/service/config-coordinator.d.ts +1 -1
- package/dist/src/gateway/service/run-gateway-agent.js +2 -4
- package/dist/src/knowledge/connected-knowledge-pipeline.js +1 -1
- package/dist/src/knowledge/connected-understanding-pipeline.d.ts +2 -4
- package/dist/src/knowledge/connected-understanding-pipeline.js +31 -81
- package/dist/src/knowledge/index.js +2 -2
- package/dist/src/knowledge/people-graph.d.ts +22 -25
- package/dist/src/knowledge/people-graph.js +76 -43
- package/dist/src/proactive/execution/context.js +8 -13
- package/dist/src/realtime/broker.d.ts +1 -0
- package/dist/src/realtime/broker.js +19 -2
- package/dist/src/realtime/runtime.js +6 -1
- package/dist/src/storage/sqlite/connector-account-repository.js +0 -1
- package/dist/src/storage/sqlite/context-consolidation-repository.d.ts +37 -0
- package/dist/src/storage/sqlite/context-consolidation-repository.js +64 -0
- package/dist/src/storage/sqlite/fts.d.ts +2 -0
- package/dist/src/storage/sqlite/fts.js +29 -1
- package/dist/src/storage/sqlite/index.d.ts +4 -6
- package/dist/src/storage/sqlite/index.js +5 -7
- package/dist/src/storage/sqlite/knowledge-repository.d.ts +9 -2
- package/dist/src/storage/sqlite/knowledge-repository.js +58 -10
- package/dist/src/storage/sqlite/memory-records-repository.d.ts +7 -56
- package/dist/src/storage/sqlite/memory-records-repository.js +68 -218
- package/dist/src/storage/sqlite/migrations/113_memory_evidence_single_source.sql +54 -0
- package/dist/src/storage/sqlite/migrations/114_user_context_domain.sql +193 -0
- package/dist/src/storage/sqlite/migrations/115_remove_legacy_user_context.sql +6 -0
- package/dist/src/storage/sqlite/migrations/116_structured_context_consolidation.sql +38 -0
- package/dist/src/storage/sqlite/migrations/117_unified_understanding_sources.sql +110 -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/schema.js +1 -1
- package/dist/src/storage/sqlite/schema.sql +0 -20
- package/dist/src/storage/sqlite/user-context-quality-repository.d.ts +34 -0
- package/dist/src/storage/sqlite/user-context-quality-repository.js +74 -0
- package/dist/src/storage/sqlite/user-context-repository.d.ts +64 -0
- package/dist/src/storage/sqlite/user-context-repository.js +383 -0
- package/dist/src/tui/tool-summary.js +1 -7
- package/dist/src/tui/tui-startup-resources.js +1 -2
- package/dist/src/user-context/config.d.ts +17 -210
- package/dist/src/user-context/config.js +19 -85
- package/dist/src/user-context/consolidation.d.ts +26 -0
- package/dist/src/user-context/consolidation.js +115 -0
- package/dist/src/user-context/domain.d.ts +75 -0
- package/dist/src/user-context/domain.js +4 -0
- package/dist/src/user-context/manual-understanding.d.ts +7 -14
- package/dist/src/user-context/manual-understanding.js +19 -54
- package/dist/src/{agent/memory/context → user-context}/planner.d.ts +5 -6
- package/dist/src/user-context/planner.js +311 -0
- package/dist/src/user-context/relationship-continuity.d.ts +3 -6
- package/dist/src/user-context/relationship-continuity.js +39 -32
- package/dist/src/user-context/sources/catalog.d.ts +2 -0
- package/dist/src/user-context/sources/catalog.js +149 -0
- package/dist/src/user-context/sources/index.d.ts +3 -0
- package/dist/src/user-context/sources/index.js +3 -0
- package/dist/src/user-context/sources/repository.d.ts +40 -0
- package/dist/src/user-context/sources/repository.js +164 -0
- package/dist/src/user-context/sources/types.d.ts +83 -0
- package/dist/src/work-discovery/analyzer.d.ts +4 -3
- package/dist/src/work-discovery/analyzer.js +21 -16
- package/dist/src/work-discovery/incremental-repository.js +42 -40
- package/dist/src/work-discovery/index.js +3 -3
- package/dist/src/work-discovery/service.d.ts +7 -7
- package/dist/src/work-discovery/service.js +241 -190
- package/dist/src/work-discovery/source-repository.js +42 -53
- package/dist/src/work-discovery/types.d.ts +2 -14
- package/package.json +3 -8
- package/dist/gateway/static/root/assets/agents-BvdqdER9.js +0 -2
- package/dist/gateway/static/root/assets/apps-page-nKLsfy6C.js +0 -1
- package/dist/gateway/static/root/assets/automations-page-Dh5bdZiN.js +0 -6
- package/dist/gateway/static/root/assets/browser-settings-page-CRJ_nAuh.js +0 -8
- package/dist/gateway/static/root/assets/capabilities-settings-panel-DeQR5BZt.js +0 -7
- package/dist/gateway/static/root/assets/capability-presets-api-D7tkhDMv.js +0 -1
- package/dist/gateway/static/root/assets/capability-presets-settings-panel-D7uK3q1p.js +0 -1
- package/dist/gateway/static/root/assets/channels-settings-Bw6Dniyq.js +0 -1
- package/dist/gateway/static/root/assets/channels-status-swr-BrUTz4uU.js +0 -1
- package/dist/gateway/static/root/assets/connector-logo-8YU53RUT.js +0 -1
- package/dist/gateway/static/root/assets/connectors-page-k9tMiOL5.js +0 -2
- package/dist/gateway/static/root/assets/cron-expression-B3B1eqnr.js +0 -2
- package/dist/gateway/static/root/assets/extension-settings-page-DEZw_7zN.js +0 -1
- package/dist/gateway/static/root/assets/gateway-settings-Dg8qCiIp.js +0 -1
- package/dist/gateway/static/root/assets/heartbeat-settings-27tRzDEo.js +0 -1
- package/dist/gateway/static/root/assets/home-page-VA511kMr.js +0 -3
- package/dist/gateway/static/root/assets/index-BvR-i-m6.js +0 -216
- package/dist/gateway/static/root/assets/index-zybP34zk.css +0 -1
- package/dist/gateway/static/root/assets/local-app-workbench-page-CaJq4-wV.js +0 -2
- package/dist/gateway/static/root/assets/locale-store-DUW5YE3R.js +0 -1
- package/dist/gateway/static/root/assets/logs-page-BLTCg69e.js +0 -2
- package/dist/gateway/static/root/assets/messages-CMjnbdbn.js +0 -3
- package/dist/gateway/static/root/assets/notes-workbench-Bp1w9UM1.js +0 -4
- package/dist/gateway/static/root/assets/project-detail-page-CZmbPDQN.js +0 -1
- package/dist/gateway/static/root/assets/projects-page-D5pzqfm5.js +0 -1
- package/dist/gateway/static/root/assets/remote-access-hub-CC-XhVGI.js +0 -1
- package/dist/gateway/static/root/assets/segmented-styles-BL8oLBEp.js +0 -1
- package/dist/gateway/static/root/assets/sessions-page-B2eTLVDV.js +0 -1
- package/dist/gateway/static/root/assets/settings-advanced-gate-CRuZ_bl0.js +0 -1
- package/dist/gateway/static/root/assets/settings-form-section-C4GXGeA4.js +0 -1
- package/dist/gateway/static/root/assets/shares-settings-YzSDS4G_.js +0 -1
- package/dist/gateway/static/root/assets/skill-reload-api-CwOo8zZk.js +0 -1
- package/dist/gateway/static/root/assets/skills-page-xd1cgSGN.js +0 -2
- package/dist/gateway/static/root/assets/time-picker-CstQ___Y.js +0 -1
- package/dist/gateway/static/root/assets/use-save-bar-registration-CQYE0l6z.js +0 -1
- package/dist/gateway/static/root/assets/user-context-page-BnQAWS_B.js +0 -1
- package/dist/gateway/static/root/assets/work-discovery-page-CAszL1y8.js +0 -1
- package/dist/gateway/static/root/assets/workflows-page-DxGzo3-x.js +0 -11
- package/dist/src/agent/code-intelligence/binary.d.ts +0 -15
- package/dist/src/agent/code-intelligence/binary.js +0 -372
- package/dist/src/agent/code-intelligence/index.d.ts +0 -4
- package/dist/src/agent/code-intelligence/index.js +0 -4
- package/dist/src/agent/code-intelligence/runtime.d.ts +0 -34
- package/dist/src/agent/code-intelligence/runtime.js +0 -280
- package/dist/src/agent/code-intelligence/tool-gating.d.ts +0 -5
- package/dist/src/agent/code-intelligence/tool-gating.js +0 -6
- package/dist/src/agent/code-intelligence/tools.d.ts +0 -6
- package/dist/src/agent/code-intelligence/tools.js +0 -266
- package/dist/src/agent/code-intelligence/types.d.ts +0 -22
- package/dist/src/agent/memory/context/planner.js +0 -286
- package/dist/src/agent/memory/dreaming/config.d.ts +0 -48
- package/dist/src/agent/memory/dreaming/config.js +0 -98
- package/dist/src/agent/memory/dreaming/constants.d.ts +0 -12
- package/dist/src/agent/memory/dreaming/constants.js +0 -18
- package/dist/src/agent/memory/dreaming/deep-promotion.d.ts +0 -19
- package/dist/src/agent/memory/dreaming/deep-promotion.js +0 -152
- package/dist/src/agent/memory/dreaming/light-sweep.d.ts +0 -16
- package/dist/src/agent/memory/dreaming/light-sweep.js +0 -115
- package/dist/src/agent/memory/dreaming/preview.d.ts +0 -23
- package/dist/src/agent/memory/dreaming/preview.js +0 -52
- package/dist/src/agent/memory/dreaming/promotion-lifecycle.d.ts +0 -16
- package/dist/src/agent/memory/dreaming/promotion-lifecycle.js +0 -44
- package/dist/src/agent/memory/dreaming/rem-patterns.d.ts +0 -19
- package/dist/src/agent/memory/dreaming/rem-patterns.js +0 -150
- package/dist/src/agent/memory/dreaming/runner.d.ts +0 -10
- package/dist/src/agent/memory/dreaming/runner.js +0 -78
- package/dist/src/agent/memory/dreaming/schedule.d.ts +0 -23
- package/dist/src/agent/memory/dreaming/schedule.js +0 -38
- package/dist/src/agent/memory/dreaming/scope.d.ts +0 -11
- package/dist/src/agent/memory/dreaming/scope.js +0 -33
- package/dist/src/agent/memory/dreaming/utils.d.ts +0 -3
- package/dist/src/agent/memory/dreaming/utils.js +0 -31
- package/dist/src/gateway/hono/routes/memory.d.ts +0 -3
- package/dist/src/gateway/hono/routes/memory.js +0 -460
- package/dist/src/storage/sqlite/dreaming-repository.d.ts +0 -61
- package/dist/src/storage/sqlite/dreaming-repository.js +0 -88
- package/dist/src/storage/sqlite/memory-readiness-repository.d.ts +0 -7
- package/dist/src/storage/sqlite/memory-readiness-repository.js +0 -30
- package/dist/src/storage/sqlite/memory-reference-consent-repository.d.ts +0 -27
- package/dist/src/storage/sqlite/memory-reference-consent-repository.js +0 -107
- package/dist/src/storage/sqlite/user-claims-repository.d.ts +0 -101
- package/dist/src/storage/sqlite/user-claims-repository.js +0 -241
- package/dist/src/storage/sqlite/user-profile-setup-repository.d.ts +0 -3
- package/dist/src/storage/sqlite/user-profile-setup-repository.js +0 -32
- package/dist/src/user-context/actionableInsights.d.ts +0 -14
- package/dist/src/user-context/actionableInsights.js +0 -34
- package/dist/src/user-context/context-compiler.d.ts +0 -27
- package/dist/src/user-context/context-compiler.js +0 -48
- package/dist/src/user-context/import.d.ts +0 -12
- package/dist/src/user-context/import.js +0 -51
- package/dist/src/user-context/memory-episode-evaluator.d.ts +0 -32
- package/dist/src/user-context/memory-episode-evaluator.js +0 -35
- package/dist/src/user-context/memory-readiness.d.ts +0 -33
- package/dist/src/user-context/memory-readiness.js +0 -41
- package/dist/src/user-context/memory-use-audit.d.ts +0 -10
- package/dist/src/user-context/memory-use-audit.js +0 -26
- package/dist/src/user-context/personal-playbook.d.ts +0 -11
- package/dist/src/user-context/personal-playbook.js +0 -41
- package/dist/src/user-context/profile.d.ts +0 -37
- package/dist/src/user-context/profile.js +0 -163
- package/dist/src/user-context/projection.d.ts +0 -120
- package/dist/src/user-context/projection.js +0 -262
- package/dist/src/user-context/source-recommendations.d.ts +0 -13
- package/dist/src/user-context/source-recommendations.js +0 -85
- /package/dist/src/{agent/code-intelligence → user-context/sources}/types.js +0 -0
|
@@ -1,1167 +1,283 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { getUserClaim, linkUserClaimMemoryRecord, listUserClaimEvidence, listUserClaimStatsBySource, listUserClaims, removeUserClaimEvidenceForSource, setUserClaimDecision } from "../../../storage/sqlite/user-claims-repository.js";
|
|
4
|
-
import { listConnectorLearningJobs } from "../../../storage/sqlite/connector-learning-repository.js";
|
|
5
|
-
import { setInteractionState } from "../../../storage/sqlite/interaction-state-repository.js";
|
|
6
|
-
import { getRelationshipSettings, updateRelationshipSettings } from "../../../storage/sqlite/relationship-settings-repository.js";
|
|
7
|
-
import { deleteMemoryRecord, getMemoryRecord, getMemoryTurnFeedback, listMemoryRecords, listMemorySignals, setMemoryTurnFeedback, upsertMemoryRecord } from "../../../storage/sqlite/memory-records-repository.js";
|
|
8
|
-
import { listKnowledgeSourceItems, listKnowledgeSyncRuns } from "../../../storage/sqlite/knowledge-repository.js";
|
|
9
|
-
import { listConnectorConnections } from "../../../storage/sqlite/connector-repository.js";
|
|
10
|
-
import { getConnectorAccount } from "../../../storage/sqlite/connector-account-repository.js";
|
|
11
|
-
import { USER_TRUST_LEVELS, isUserTrustLevel } from "../../../user-context/trust-policy.js";
|
|
12
|
-
import { getUserTrustPolicy, setUserTrustPolicy } from "../../../storage/sqlite/user-trust-repository.js";
|
|
13
|
-
import { decideMemoryReferenceConsent, listMemoryReferenceConsents, revokeMemoryReferenceConsent } from "../../../storage/sqlite/memory-reference-consent-repository.js";
|
|
14
|
-
import { getUserProfilePromptState, setUserProfilePromptState } from "../../../storage/sqlite/user-profile-setup-repository.js";
|
|
1
|
+
import { listContextConsolidationRuns } from "../../../storage/sqlite/context-consolidation-repository.js";
|
|
2
|
+
import { createCollaborationRule, createUnderstanding, decideContextConsent, deleteCollaborationRule, deleteUnderstanding, getCollaborationRule, getTurnPersonalization, getUnderstanding, getUserProfile, listCollaborationRules, listUnderstandingEvidence, listUnderstandings, recordContextFeedback, rejectUnderstanding, reviseCollaborationRule, reviseUnderstanding, setCollaborationRuleStatus, setUnderstandingStatus, updateUserProfile } from "../../../storage/sqlite/user-context-repository.js";
|
|
15
3
|
import "../../../storage/sqlite/index.js";
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
import { TaskRepository } from "../../../tasks/task-repository.js";
|
|
19
|
-
import { revokeComposioConnection } from "../../../connectors/composio.js";
|
|
20
|
-
import { listConnectorCatalog } from "../../../connectors/catalog.js";
|
|
21
|
-
import { nextDreamingRunTimes } from "../../../agent/memory/dreaming/schedule.js";
|
|
22
|
-
import { resolveDreamingSettings } from "../../../agent/memory/dreaming/config.js";
|
|
23
|
-
import { readUserProfileFile, writeUserProfileFile } from "../../agents-admin.js";
|
|
24
|
-
import { TaskContextRepository } from "../../../tasks/task-context-repository.js";
|
|
25
|
-
import "../../../tasks/index.js";
|
|
26
|
-
import { nextMemoryReviewAt } from "../../../agent/memory/lifecycle.js";
|
|
27
|
-
import { isUserContextMemoryKind, isUserContextRecord, projectPersonalContextSources, projectUserContextRecord, recordsDerivedFromPersonalContextSource } from "../../../user-context/projection.js";
|
|
28
|
-
import { PERSONAL_PLAYBOOK_DISABLED_TAG, PERSONAL_PLAYBOOK_ORDER_PREFIX, PERSONAL_PLAYBOOK_RULE_TAG, patchPersonalPlaybookContextTags, personalPlaybookContext } from "../../../user-context/personal-playbook.js";
|
|
29
|
-
import { INSIGHT_ACCEPTED_TAG, INSIGHT_DISMISSED_TAG, USER_CONFIRMED_MEMORY_TAG, buildActionableInsightSuggestions } from "../../../user-context/actionableInsights.js";
|
|
30
|
-
import { createManualUnderstanding } from "../../../user-context/manual-understanding.js";
|
|
31
|
-
import { resolveDreamingAgentScope } from "../../../agent/memory/dreaming/scope.js";
|
|
32
|
-
import { runDreamingPhase } from "../../../agent/memory/dreaming/runner.js";
|
|
33
|
-
import { listConnectorInstances } from "../../../connectors/instances.js";
|
|
34
|
-
import { uninstallConnector } from "../../../connectors/install.js";
|
|
35
|
-
import { renderUserClaim } from "../../../knowledge/connected-understanding-pipeline.js";
|
|
36
|
-
import { prepareUserContextImport } from "../../../user-context/import.js";
|
|
37
|
-
import { buildUserProfileSetup, parseUserProfileMarkdown, patchUserProfileMarkdown } from "../../../user-context/profile.js";
|
|
38
|
-
import { buildTaskSourceRecommendations } from "../../../user-context/source-recommendations.js";
|
|
4
|
+
import { userInfo } from "node:os";
|
|
5
|
+
import { createHash } from "node:crypto";
|
|
39
6
|
//#region src/gateway/hono/routes/you.ts
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
"
|
|
7
|
+
const UNDERSTANDING_KINDS = new Set([
|
|
8
|
+
"preference",
|
|
9
|
+
"boundary",
|
|
10
|
+
"relationship",
|
|
11
|
+
"routine",
|
|
12
|
+
"current_state",
|
|
13
|
+
"long_term_goal",
|
|
14
|
+
"project_context",
|
|
15
|
+
"task_lesson",
|
|
16
|
+
"derived_insight"
|
|
46
17
|
]);
|
|
47
|
-
const
|
|
48
|
-
"helpful",
|
|
49
|
-
"not_helpful",
|
|
50
|
-
"mixed",
|
|
51
|
-
"irrelevant",
|
|
52
|
-
"incorrect",
|
|
53
|
-
"outdated",
|
|
54
|
-
"sensitive"
|
|
55
|
-
]);
|
|
56
|
-
const PLAYBOOK_IDS = [
|
|
57
|
-
"communication",
|
|
58
|
-
"execution",
|
|
59
|
-
"routines"
|
|
60
|
-
];
|
|
61
|
-
const PLAYBOOK_SUPPORT_NEEDS = new Set([
|
|
62
|
-
"listen",
|
|
63
|
-
"clarify",
|
|
64
|
-
"advise",
|
|
65
|
-
"act",
|
|
66
|
-
"unknown"
|
|
67
|
-
]);
|
|
68
|
-
const PROFILE_FIELD_LIMITS = {
|
|
69
|
-
callName: 80,
|
|
70
|
-
pronouns: 80,
|
|
71
|
-
timezone: 100,
|
|
72
|
-
notes: 5e3
|
|
73
|
-
};
|
|
74
|
-
const PROFILE_PROMPT_SNOOZE_MS = 10080 * 60 * 1e3;
|
|
75
|
-
const ALL_MEMORY_STATUSES = [
|
|
18
|
+
const UNDERSTANDING_STATUSES = new Set([
|
|
76
19
|
"candidate",
|
|
77
20
|
"active",
|
|
78
21
|
"needs_review",
|
|
79
22
|
"stale",
|
|
80
23
|
"archived",
|
|
81
24
|
"rejected"
|
|
82
|
-
];
|
|
83
|
-
const MEMORY_SENSITIVITIES = new Set([
|
|
84
|
-
"normal",
|
|
85
|
-
"personal",
|
|
86
|
-
"secret",
|
|
87
|
-
"regulated"
|
|
88
25
|
]);
|
|
89
|
-
const
|
|
90
|
-
"
|
|
91
|
-
"
|
|
92
|
-
"
|
|
26
|
+
const RULE_CATEGORIES = new Set([
|
|
27
|
+
"communication",
|
|
28
|
+
"execution",
|
|
29
|
+
"boundary",
|
|
30
|
+
"routine",
|
|
31
|
+
"proactive"
|
|
93
32
|
]);
|
|
94
|
-
const
|
|
95
|
-
"
|
|
96
|
-
"
|
|
97
|
-
"
|
|
33
|
+
const RULE_STATUSES = new Set([
|
|
34
|
+
"active",
|
|
35
|
+
"disabled",
|
|
36
|
+
"archived"
|
|
98
37
|
]);
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
});
|
|
109
|
-
records.push(...page);
|
|
110
|
-
if (page.length < 500) break;
|
|
111
|
-
offset += page.length;
|
|
112
|
-
}
|
|
113
|
-
return records;
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
function projectReferenceConsent(consent, record) {
|
|
117
|
-
return {
|
|
118
|
-
id: consent.id,
|
|
119
|
-
recordId: consent.recordId,
|
|
120
|
-
sessionKey: consent.sessionKey,
|
|
121
|
-
purpose: consent.purpose,
|
|
122
|
-
statement: record.content,
|
|
123
|
-
sourceName: record.source.provider ?? "local",
|
|
124
|
-
status: consent.status,
|
|
125
|
-
grantScope: consent.grantScope,
|
|
126
|
-
expiresAt: consent.expiresAt,
|
|
127
|
-
createdAt: consent.createdAt,
|
|
128
|
-
updatedAt: consent.updatedAt
|
|
129
|
-
};
|
|
38
|
+
const FEEDBACK_RATINGS = new Set([
|
|
39
|
+
"helpful",
|
|
40
|
+
"irrelevant",
|
|
41
|
+
"wrong",
|
|
42
|
+
"stale",
|
|
43
|
+
"sensitive"
|
|
44
|
+
]);
|
|
45
|
+
function asRecord(value) {
|
|
46
|
+
return value && typeof value === "object" && !Array.isArray(value) ? value : void 0;
|
|
130
47
|
}
|
|
131
|
-
function
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
group.push(record);
|
|
137
|
-
groups.set(record.conflictGroupId, group);
|
|
48
|
+
async function readBody(c) {
|
|
49
|
+
try {
|
|
50
|
+
return asRecord(await c.req.json());
|
|
51
|
+
} catch {
|
|
52
|
+
return;
|
|
138
53
|
}
|
|
139
|
-
return [...groups.entries()].filter(([, group]) => group.length > 1 && group.some((record) => VISIBLE_STATUSES.has(record.status))).map(([id, group]) => ({
|
|
140
|
-
id,
|
|
141
|
-
records: group.sort((left, right) => Date.parse(right.updatedAt) - Date.parse(left.updatedAt)).map((record) => ({
|
|
142
|
-
...projectUserContextRecord(record),
|
|
143
|
-
storedStatus: record.status
|
|
144
|
-
})),
|
|
145
|
-
unresolved: group.filter((record) => VISIBLE_STATUSES.has(record.status)).length > 1
|
|
146
|
-
}));
|
|
147
|
-
}
|
|
148
|
-
async function readProfileBundle(config) {
|
|
149
|
-
const result = await readUserProfileFile();
|
|
150
|
-
const profileContent = result.ok ? result.data.content : "";
|
|
151
|
-
const profile = parseUserProfileMarkdown(profileContent);
|
|
152
|
-
return {
|
|
153
|
-
profileContent,
|
|
154
|
-
profile,
|
|
155
|
-
profileSetup: buildUserProfileSetup({
|
|
156
|
-
profile,
|
|
157
|
-
promptState: getUserProfilePromptState(),
|
|
158
|
-
config
|
|
159
|
-
})
|
|
160
|
-
};
|
|
161
54
|
}
|
|
162
|
-
function
|
|
163
|
-
if (
|
|
164
|
-
const
|
|
165
|
-
|
|
166
|
-
for (const field of Object.keys(PROFILE_FIELD_LIMITS)) {
|
|
167
|
-
if (!(field in record)) continue;
|
|
168
|
-
if (typeof record[field] !== "string") return { error: `${field} must be a string` };
|
|
169
|
-
const value = record[field].trim();
|
|
170
|
-
if (value.length > PROFILE_FIELD_LIMITS[field]) return { error: `${field} is too long` };
|
|
171
|
-
patch[field] = value;
|
|
172
|
-
}
|
|
173
|
-
return Object.keys(patch).length > 0 ? { patch } : { error: "No profile fields provided" };
|
|
55
|
+
function nonEmptyString(value, max = 2e3) {
|
|
56
|
+
if (typeof value !== "string") return void 0;
|
|
57
|
+
const result = value.trim();
|
|
58
|
+
return result && result.length <= max ? result : void 0;
|
|
174
59
|
}
|
|
175
|
-
function
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
if (
|
|
179
|
-
if (
|
|
60
|
+
function scopeFrom(value) {
|
|
61
|
+
const raw = asRecord(value);
|
|
62
|
+
const type = raw?.type;
|
|
63
|
+
if (type !== "global" && type !== "workspace" && type !== "project" && type !== "session") return void 0;
|
|
64
|
+
if (type === "global") return { type };
|
|
65
|
+
const id = nonEmptyString(raw.id, 500);
|
|
66
|
+
return id ? {
|
|
67
|
+
type,
|
|
68
|
+
id
|
|
69
|
+
} : void 0;
|
|
180
70
|
}
|
|
181
|
-
function
|
|
182
|
-
const
|
|
183
|
-
|
|
184
|
-
return Number.isFinite(parsed) ? parsed : 1e3;
|
|
71
|
+
function canonicalKey(kind, statement) {
|
|
72
|
+
const normalized = statement.toLocaleLowerCase().replace(/[^\p{L}\p{N}]+/gu, " ").trim();
|
|
73
|
+
return `${kind}:${createHash("sha256").update(normalized).digest("hex").slice(0, 20)}`;
|
|
185
74
|
}
|
|
186
|
-
function
|
|
187
|
-
|
|
188
|
-
if (patch.enabled === true) tags = tags.filter((tag) => tag !== PERSONAL_PLAYBOOK_DISABLED_TAG);
|
|
189
|
-
if (patch.enabled === false) tags.push(PERSONAL_PLAYBOOK_DISABLED_TAG);
|
|
190
|
-
if (patch.order !== void 0) tags.push(`${PERSONAL_PLAYBOOK_ORDER_PREFIX}${patch.order}`);
|
|
191
|
-
return [...new Set(tags)];
|
|
75
|
+
function sameScope(left, right) {
|
|
76
|
+
return left.type === right.type && left.id === right.id;
|
|
192
77
|
}
|
|
193
|
-
function
|
|
194
|
-
if (value
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
context.channel = input.channel === null ? void 0 : String(input.channel);
|
|
201
|
-
}
|
|
202
|
-
if ("supportNeed" in input) {
|
|
203
|
-
if (input.supportNeed !== null && !PLAYBOOK_SUPPORT_NEEDS.has(String(input.supportNeed))) return { error: "context.supportNeed is invalid" };
|
|
204
|
-
context.supportNeed = input.supportNeed === null ? void 0 : input.supportNeed;
|
|
78
|
+
function validTimezone(value) {
|
|
79
|
+
if (!value) return true;
|
|
80
|
+
try {
|
|
81
|
+
new Intl.DateTimeFormat("en", { timeZone: value }).format();
|
|
82
|
+
return true;
|
|
83
|
+
} catch {
|
|
84
|
+
return false;
|
|
205
85
|
}
|
|
206
|
-
return { context };
|
|
207
|
-
}
|
|
208
|
-
function buildPersonalPlaybooks(records) {
|
|
209
|
-
return PLAYBOOK_IDS.map((id) => {
|
|
210
|
-
const rules = records.filter((record) => record.status === "active" && playbookForRecord(record) === id).sort((left, right) => playbookRuleOrder(left) - playbookRuleOrder(right) || left.updatedAt.localeCompare(right.updatedAt));
|
|
211
|
-
return {
|
|
212
|
-
id,
|
|
213
|
-
enabled: rules.some((record) => !record.tags?.includes(PERSONAL_PLAYBOOK_DISABLED_TAG)),
|
|
214
|
-
rules: rules.map((record) => ({
|
|
215
|
-
id: record.id,
|
|
216
|
-
statement: record.content,
|
|
217
|
-
origin: record.explicitness,
|
|
218
|
-
enabled: !record.tags?.includes(PERSONAL_PLAYBOOK_DISABLED_TAG),
|
|
219
|
-
order: playbookRuleOrder(record),
|
|
220
|
-
context: personalPlaybookContext(record),
|
|
221
|
-
versions: playbookVersionChain(records, record.id).map((version) => ({
|
|
222
|
-
id: version.id,
|
|
223
|
-
statement: version.content,
|
|
224
|
-
updatedAt: version.updatedAt,
|
|
225
|
-
current: version.id === record.id
|
|
226
|
-
}))
|
|
227
|
-
})),
|
|
228
|
-
updatedAt: rules.map((record) => record.updatedAt).sort().at(-1)
|
|
229
|
-
};
|
|
230
|
-
});
|
|
231
|
-
}
|
|
232
|
-
function buildRoutineAutomationDraftHref(record) {
|
|
233
|
-
return `/automations?${new URLSearchParams({
|
|
234
|
-
draft: record.content,
|
|
235
|
-
autogenerate: "1",
|
|
236
|
-
insight: record.id
|
|
237
|
-
}).toString()}`;
|
|
238
|
-
}
|
|
239
|
-
function selectedAgentId(config) {
|
|
240
|
-
return resolveDefaultAgentId(config);
|
|
241
|
-
}
|
|
242
|
-
function editableRecord(recordId) {
|
|
243
|
-
const record = getMemoryRecord(recordId);
|
|
244
|
-
if (!record || !VISIBLE_STATUSES.has(record.status) || !isUserContextRecord(record)) return null;
|
|
245
|
-
return record;
|
|
246
86
|
}
|
|
247
|
-
function
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
confidence: record.confidence,
|
|
259
|
-
tags: record.tags,
|
|
260
|
-
status: record.status,
|
|
261
|
-
sensitivity: record.sensitivity,
|
|
262
|
-
canonicalKey: record.canonicalKey,
|
|
263
|
-
explicitness: record.explicitness,
|
|
264
|
-
durability: record.durability,
|
|
265
|
-
importance: record.importance,
|
|
266
|
-
disclosurePolicy: record.disclosurePolicy,
|
|
267
|
-
evidence: record.evidence,
|
|
268
|
-
reviewAfter: record.reviewAfter,
|
|
269
|
-
expiresAt: record.expiresAt,
|
|
270
|
-
validFrom: record.validFrom,
|
|
271
|
-
validTo: record.validTo,
|
|
272
|
-
supersedesRecordId: record.supersedesRecordId,
|
|
273
|
-
conflictGroupId: record.conflictGroupId
|
|
274
|
-
};
|
|
275
|
-
}
|
|
276
|
-
function preserveRecord(record, patch) {
|
|
277
|
-
return upsertMemoryRecord({
|
|
278
|
-
...memoryRecordInput(record),
|
|
279
|
-
...patch,
|
|
280
|
-
id: record.id
|
|
281
|
-
});
|
|
282
|
-
}
|
|
283
|
-
function playbookVersionChain(records, recordId) {
|
|
284
|
-
const relatedIds = new Set([recordId]);
|
|
285
|
-
let previousSize = 0;
|
|
286
|
-
while (previousSize !== relatedIds.size) {
|
|
287
|
-
previousSize = relatedIds.size;
|
|
288
|
-
for (const record of records) {
|
|
289
|
-
if (!record.supersedesRecordId) continue;
|
|
290
|
-
if (relatedIds.has(record.id) || relatedIds.has(record.supersedesRecordId)) {
|
|
291
|
-
relatedIds.add(record.id);
|
|
292
|
-
relatedIds.add(record.supersedesRecordId);
|
|
293
|
-
}
|
|
294
|
-
}
|
|
87
|
+
function machineCallName() {
|
|
88
|
+
try {
|
|
89
|
+
const username = userInfo().username.trim();
|
|
90
|
+
return [
|
|
91
|
+
"root",
|
|
92
|
+
"admin",
|
|
93
|
+
"administrator",
|
|
94
|
+
"user"
|
|
95
|
+
].includes(username.toLocaleLowerCase()) ? "" : username.slice(0, 100);
|
|
96
|
+
} catch {
|
|
97
|
+
return "";
|
|
295
98
|
}
|
|
296
|
-
return records.filter((record) => relatedIds.has(record.id) && playbookForRecord(record) !== void 0).sort((left, right) => Date.parse(right.updatedAt) - Date.parse(left.updatedAt));
|
|
297
|
-
}
|
|
298
|
-
function versionPlaybookRule(record, patch) {
|
|
299
|
-
return upsertMemoryRecord({
|
|
300
|
-
...memoryRecordInput(record),
|
|
301
|
-
...patch,
|
|
302
|
-
status: "active",
|
|
303
|
-
supersedesRecordId: record.id,
|
|
304
|
-
source: {
|
|
305
|
-
provider: "local",
|
|
306
|
-
path: "you://playbook/version"
|
|
307
|
-
}
|
|
308
|
-
});
|
|
309
99
|
}
|
|
310
100
|
function registerYouRoutes(authenticated, deps) {
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
const
|
|
320
|
-
const sourceDefinitions = listConnectorCatalog();
|
|
321
|
-
const sourceInstances = listConnectorInstances(config);
|
|
322
|
-
const sources = projectPersonalContextSources(sourceDefinitions, sourceInstances, {
|
|
323
|
-
sourceItems: listKnowledgeSourceItems({ limit: 500 }),
|
|
324
|
-
syncRuns: listKnowledgeSyncRuns({ limit: 500 }),
|
|
325
|
-
connections: listConnectorConnections({ principalId: "local-owner" }),
|
|
326
|
-
learningJobs: listConnectorLearningJobs({ limit: 500 }),
|
|
327
|
-
claimStatsBySource: listUserClaimStatsBySource()
|
|
328
|
-
});
|
|
329
|
-
const openTasks = new TaskRepository().list({ limit: 500 }).filter((task) => task.delegateAgentId === agentId && task.phase !== "closed");
|
|
330
|
-
const activeTasks = openTasks.slice(0, 20).map((task) => {
|
|
331
|
-
return {
|
|
332
|
-
id: task.id,
|
|
333
|
-
title: task.title,
|
|
334
|
-
body: task.body
|
|
335
|
-
};
|
|
336
|
-
});
|
|
337
|
-
return c.json({
|
|
338
|
-
scope: {
|
|
339
|
-
profile: "global",
|
|
340
|
-
memory: "global",
|
|
341
|
-
trust: "global"
|
|
342
|
-
},
|
|
343
|
-
...profileBundle,
|
|
344
|
-
understanding: records.map(projectUserContextRecord),
|
|
345
|
-
connectedClaims: listUserClaims({
|
|
346
|
-
agentId,
|
|
347
|
-
limit: 100
|
|
348
|
-
}).map((claim) => ({
|
|
349
|
-
...claim,
|
|
350
|
-
evidence: listUserClaimEvidence(claim.id)
|
|
351
|
-
})),
|
|
352
|
-
consentRequests: consents.filter((consent) => consent.status === "pending").flatMap((consent) => {
|
|
353
|
-
const record = recordById.get(consent.recordId);
|
|
354
|
-
return record ? [projectReferenceConsent(consent, record)] : [];
|
|
355
|
-
}),
|
|
356
|
-
referenceGrants: consents.filter((consent) => consent.status === "granted" && (!consent.expiresAt || Date.parse(consent.expiresAt) > Date.now())).flatMap((consent) => {
|
|
357
|
-
const record = recordById.get(consent.recordId);
|
|
358
|
-
return record ? [projectReferenceConsent(consent, record)] : [];
|
|
359
|
-
}),
|
|
360
|
-
conflictGroups: buildConflictGroups(allUserContextRecords),
|
|
361
|
-
insights: buildActionableInsightSuggestions(records, openTasks.map((task) => [task.title, task.body].filter(Boolean).join("\n"))).map((insight) => ({
|
|
362
|
-
...insight,
|
|
363
|
-
delegateAgentId: agentId
|
|
364
|
-
})),
|
|
365
|
-
playbooks: buildPersonalPlaybooks(allUserContextRecords),
|
|
366
|
-
sources,
|
|
367
|
-
sourceRecommendations: buildTaskSourceRecommendations(sourceDefinitions, new Set(sourceInstances.map((instance) => instance.connectorId)), activeTasks),
|
|
368
|
-
controls: {
|
|
369
|
-
mode: config.userContext.memory.mode,
|
|
370
|
-
sensitiveWritePolicy: config.userContext.privacy.sensitiveWritePolicy
|
|
371
|
-
},
|
|
372
|
-
relationship: getRelationshipSettings(),
|
|
373
|
-
trust: {
|
|
374
|
-
defaultActionLevel: trustPolicy.defaultActionLevel,
|
|
375
|
-
levels: USER_TRUST_LEVELS,
|
|
376
|
-
autoRequiresExplicitOptIn: true
|
|
377
|
-
}
|
|
378
|
-
});
|
|
379
|
-
});
|
|
380
|
-
authenticated.get("/api/you/feedback/:turnId", (c) => {
|
|
381
|
-
const trace = getMemoryTurnFeedback(c.req.param("turnId"));
|
|
382
|
-
if (!trace) return c.json({ error: "Turn context not found" }, 404);
|
|
383
|
-
const personalContext = trace.selectedRecordIds.map((id) => getMemoryRecord(id)).filter((record) => Boolean(record) && isUserContextRecord(record)).map(projectUserContextRecord);
|
|
384
|
-
return c.json({
|
|
385
|
-
trace,
|
|
386
|
-
personalContext
|
|
387
|
-
});
|
|
388
|
-
});
|
|
389
|
-
authenticated.put("/api/you/feedback/:turnId", deps.strictRateLimitMiddleware, async (c) => {
|
|
390
|
-
const body = await c.req.json().catch(() => null);
|
|
391
|
-
if (!body || typeof body !== "object" || Array.isArray(body)) return c.json({ error: "Invalid feedback" }, 400);
|
|
392
|
-
const input = body;
|
|
393
|
-
if (typeof input.rating !== "string" || !FEEDBACK_RATINGS.has(input.rating)) return c.json({ error: "Invalid rating" }, 400);
|
|
394
|
-
const records = Array.isArray(input.records) ? input.records.flatMap((value) => {
|
|
395
|
-
if (!value || typeof value !== "object" || Array.isArray(value)) return [];
|
|
396
|
-
const item = value;
|
|
397
|
-
if (typeof item.recordId !== "string" || typeof item.rating !== "string" || !FEEDBACK_RATINGS.has(item.rating)) return [];
|
|
398
|
-
return [{
|
|
399
|
-
recordId: item.recordId,
|
|
400
|
-
rating: item.rating,
|
|
401
|
-
...typeof item.reasonCode === "string" ? { reasonCode: item.reasonCode } : {},
|
|
402
|
-
...typeof item.note === "string" ? { note: item.note } : {}
|
|
403
|
-
}];
|
|
404
|
-
}) : void 0;
|
|
405
|
-
const trace = setMemoryTurnFeedback({
|
|
406
|
-
turnId: c.req.param("turnId"),
|
|
407
|
-
rating: input.rating,
|
|
408
|
-
source: "user",
|
|
409
|
-
...typeof input.score === "number" ? { score: input.score } : {},
|
|
410
|
-
...typeof input.reasonCode === "string" ? { reasonCode: input.reasonCode } : {},
|
|
411
|
-
...typeof input.note === "string" ? { note: input.note } : {},
|
|
412
|
-
...records ? { records } : {}
|
|
413
|
-
});
|
|
414
|
-
if (!trace) return c.json({ error: "Turn context not found" }, 404);
|
|
415
|
-
if (trace.sessionKey && input.rating === "not_helpful" && input.reasonCode === "tone_mismatch") setInteractionState({
|
|
416
|
-
sessionKey: trace.sessionKey,
|
|
417
|
-
signal: {
|
|
418
|
-
supportNeed: "unknown",
|
|
419
|
-
confidence: 1,
|
|
420
|
-
source: "explicit",
|
|
421
|
-
repairStatus: "needed",
|
|
422
|
-
repairReason: "tone_mismatch"
|
|
423
|
-
}
|
|
424
|
-
});
|
|
425
|
-
const personalContext = trace.selectedRecordIds.map((id) => getMemoryRecord(id)).filter((record) => Boolean(record) && isUserContextRecord(record)).map(projectUserContextRecord);
|
|
426
|
-
return c.json({
|
|
427
|
-
trace,
|
|
428
|
-
personalContext
|
|
429
|
-
});
|
|
430
|
-
});
|
|
431
|
-
authenticated.get("/api/you/dreaming", (c) => {
|
|
432
|
-
const config = deps.service.currentConfig;
|
|
433
|
-
const scope = resolveDreamingAgentScope(config);
|
|
434
|
-
const settings = resolveDreamingSettings(config);
|
|
435
|
-
const signals = listMemorySignals({
|
|
436
|
-
workspaceId: scope.workspaceDir,
|
|
437
|
-
limit: 500
|
|
438
|
-
});
|
|
439
|
-
return c.json({
|
|
440
|
-
agentId: scope.agentId,
|
|
441
|
-
settings,
|
|
442
|
-
config: {
|
|
443
|
-
...scope.config,
|
|
444
|
-
phases: {
|
|
445
|
-
light: {
|
|
446
|
-
...scope.config.phases.light,
|
|
447
|
-
nextRunsAt: nextDreamingRunTimes(scope.config.phases.light.schedule, scope.config.timezone)
|
|
448
|
-
},
|
|
449
|
-
deep: {
|
|
450
|
-
...scope.config.phases.deep,
|
|
451
|
-
nextRunsAt: nextDreamingRunTimes(scope.config.phases.deep.schedule, scope.config.timezone)
|
|
452
|
-
},
|
|
453
|
-
rem: {
|
|
454
|
-
...scope.config.phases.rem,
|
|
455
|
-
nextRunsAt: nextDreamingRunTimes(scope.config.phases.rem.schedule, scope.config.timezone)
|
|
456
|
-
}
|
|
457
|
-
}
|
|
458
|
-
},
|
|
459
|
-
readiness: scope.readiness,
|
|
460
|
-
runs: listDreamingRuns({
|
|
461
|
-
agentId: scope.agentId,
|
|
462
|
-
limit: 50
|
|
463
|
-
}),
|
|
464
|
-
signalCount: signals.filter((signal) => signal.source === "dreaming").length
|
|
465
|
-
});
|
|
466
|
-
});
|
|
467
|
-
authenticated.put("/api/you/dreaming", deps.strictRateLimitMiddleware, async (c) => {
|
|
468
|
-
const config = deps.service.currentConfig;
|
|
469
|
-
const body = await c.req.json().catch(() => ({}));
|
|
470
|
-
const settings = DreamingSettingsSchema.safeParse(body);
|
|
471
|
-
if (!settings.success) return c.json({ error: settings.error.issues[0]?.message ?? "Invalid Dreaming settings" }, 400);
|
|
472
|
-
const currentPhases = config.userContext.dreaming.phases ?? {};
|
|
473
|
-
const parsed = UserContextConfigSchema.safeParse({
|
|
474
|
-
...config.userContext,
|
|
475
|
-
dreaming: {
|
|
476
|
-
...config.userContext.dreaming,
|
|
477
|
-
mode: settings.data.mode,
|
|
478
|
-
timezone: settings.data.timezone,
|
|
479
|
-
phases: {
|
|
480
|
-
light: {
|
|
481
|
-
...currentPhases.light,
|
|
482
|
-
...settings.data.phases.light
|
|
483
|
-
},
|
|
484
|
-
deep: {
|
|
485
|
-
...currentPhases.deep,
|
|
486
|
-
...settings.data.phases.deep
|
|
487
|
-
},
|
|
488
|
-
rem: {
|
|
489
|
-
...currentPhases.rem,
|
|
490
|
-
...settings.data.phases.rem
|
|
491
|
-
}
|
|
492
|
-
}
|
|
493
|
-
}
|
|
494
|
-
});
|
|
495
|
-
if (!parsed.success) return c.json({ error: parsed.error.issues[0]?.message ?? "Invalid Dreaming settings" }, 400);
|
|
496
|
-
const saved = await deps.service.saveConfig({
|
|
497
|
-
...config,
|
|
498
|
-
userContext: parsed.data
|
|
499
|
-
});
|
|
500
|
-
if (!saved.saved) return c.json({ error: saved.error ?? "save failed" }, 500);
|
|
501
|
-
const savedConfig = deps.service.currentConfig;
|
|
502
|
-
return c.json({ settings: resolveDreamingSettings(savedConfig) });
|
|
503
|
-
});
|
|
504
|
-
authenticated.get("/api/you/readiness", (c) => {
|
|
505
|
-
return c.json(resolveDreamingAgentScope(deps.service.currentConfig).readiness);
|
|
506
|
-
});
|
|
507
|
-
authenticated.post("/api/you/dreaming/runs", deps.strictRateLimitMiddleware, async (c) => {
|
|
508
|
-
const body = await c.req.json().catch(() => ({}));
|
|
509
|
-
const phase = body.phase === "light" || body.phase === "deep" || body.phase === "rem" ? body.phase : "deep";
|
|
510
|
-
try {
|
|
511
|
-
const result = await runDreamingPhase({
|
|
512
|
-
config: deps.service.currentConfig,
|
|
513
|
-
phase,
|
|
514
|
-
triggerKind: "manual"
|
|
515
|
-
});
|
|
516
|
-
return c.json(result);
|
|
517
|
-
} catch (error) {
|
|
518
|
-
return c.json({ error: error instanceof Error ? error.message : String(error) }, 400);
|
|
519
|
-
}
|
|
520
|
-
});
|
|
521
|
-
authenticated.get("/api/you/dreaming/runs/:runId", (c) => {
|
|
522
|
-
const scope = resolveDreamingAgentScope(deps.service.currentConfig);
|
|
523
|
-
const run = getDreamingRun(c.req.param("runId"));
|
|
524
|
-
if (!run || run.agentId !== scope.agentId || run.workspaceId !== scope.workspaceDir) return c.json({ error: "Dreaming run not found" }, 404);
|
|
101
|
+
const write = deps.strictRateLimitMiddleware;
|
|
102
|
+
authenticated.get("/api/you", (c) => c.json({
|
|
103
|
+
profile: getUserProfile(),
|
|
104
|
+
understandings: listUnderstandings(),
|
|
105
|
+
rules: listCollaborationRules(),
|
|
106
|
+
consolidation: { lastRun: listContextConsolidationRuns(1)[0] ?? null }
|
|
107
|
+
}));
|
|
108
|
+
authenticated.get("/api/you/profile", (c) => {
|
|
109
|
+
const profile = getUserProfile();
|
|
525
110
|
return c.json({
|
|
526
|
-
|
|
527
|
-
|
|
111
|
+
profile,
|
|
112
|
+
suggestedCallName: profile.callName || machineCallName()
|
|
528
113
|
});
|
|
529
114
|
});
|
|
530
|
-
authenticated.patch("/api/you/
|
|
531
|
-
const body = await c
|
|
532
|
-
if (!body
|
|
533
|
-
const input = body;
|
|
115
|
+
authenticated.patch("/api/you/profile", write, async (c) => {
|
|
116
|
+
const body = await readBody(c);
|
|
117
|
+
if (!body) return c.json({ error: "Invalid JSON" }, 400);
|
|
534
118
|
const patch = {};
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
if (typeof
|
|
546
|
-
patch
|
|
547
|
-
}
|
|
548
|
-
for (const field of ["quietStart", "quietEnd"]) {
|
|
549
|
-
if (!(field in input)) continue;
|
|
550
|
-
const value = input[field];
|
|
551
|
-
if (value !== null && (typeof value !== "string" || !/^([01]\d|2[0-3]):[0-5]\d$/.test(value))) return c.json({ error: `${field} must use HH:mm` }, 400);
|
|
552
|
-
patch[field] = value === null ? void 0 : String(value);
|
|
119
|
+
for (const field of [
|
|
120
|
+
"callName",
|
|
121
|
+
"role",
|
|
122
|
+
"primaryGoal",
|
|
123
|
+
"pronouns",
|
|
124
|
+
"timezone",
|
|
125
|
+
"locale"
|
|
126
|
+
]) {
|
|
127
|
+
if (body[field] === void 0) continue;
|
|
128
|
+
const max = field === "primaryGoal" ? 500 : field === "role" ? 300 : 100;
|
|
129
|
+
if (typeof body[field] !== "string" || body[field].length > max) return c.json({ error: `${field} must be a string of at most ${max} characters` }, 400);
|
|
130
|
+
patch[field] = body[field].trim();
|
|
553
131
|
}
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
if (!
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
if (Object.keys(patch).length === 0) return c.json({ error: "No relationship settings provided" }, 400);
|
|
560
|
-
return c.json({
|
|
561
|
-
ok: true,
|
|
562
|
-
relationship: updateRelationshipSettings(patch)
|
|
563
|
-
});
|
|
564
|
-
});
|
|
565
|
-
authenticated.patch("/api/you/claims/:id", deps.strictRateLimitMiddleware, async (c) => {
|
|
566
|
-
const body = await c.req.json().catch(() => ({}));
|
|
567
|
-
const action = body.action === "confirm" || body.action === "reject" ? body.action : void 0;
|
|
568
|
-
if (!action) return c.json({ error: "Action must be confirm or reject" }, 400);
|
|
569
|
-
const claim = runSqliteWriteTransaction(() => {
|
|
570
|
-
const updated = setUserClaimDecision(c.req.param("id"), action === "confirm" ? "confirmed" : "rejected");
|
|
571
|
-
if (!updated) return updated;
|
|
572
|
-
const existing = updated.memoryRecordId ? getMemoryRecord(updated.memoryRecordId) : void 0;
|
|
573
|
-
if (existing) preserveRecord(existing, {
|
|
574
|
-
status: action === "confirm" ? "active" : "rejected",
|
|
575
|
-
...action === "confirm" ? { reviewAfter: nextMemoryReviewAt(existing) } : {}
|
|
576
|
-
});
|
|
577
|
-
else if (action === "confirm") {
|
|
578
|
-
const candidate = renderUserClaim(updated);
|
|
579
|
-
const evidence = listUserClaimEvidence(updated.id);
|
|
580
|
-
const record = upsertMemoryRecord({
|
|
581
|
-
providerId: "local",
|
|
582
|
-
kind: candidate.kind,
|
|
583
|
-
sourceAgentId: updated.agentId,
|
|
584
|
-
content: candidate.content,
|
|
585
|
-
canonicalKey: candidate.canonicalKey,
|
|
586
|
-
source: { provider: "connected-sources" },
|
|
587
|
-
confidence: 1,
|
|
588
|
-
status: "active",
|
|
589
|
-
sensitivity: candidate.sensitivity,
|
|
590
|
-
explicitness: "explicit",
|
|
591
|
-
durability: candidate.durability,
|
|
592
|
-
importance: candidate.importance,
|
|
593
|
-
disclosurePolicy: candidate.disclosurePolicy,
|
|
594
|
-
tags: [...new Set([
|
|
595
|
-
"user-understanding",
|
|
596
|
-
...candidate.tags ?? [],
|
|
597
|
-
USER_CONFIRMED_MEMORY_TAG
|
|
598
|
-
])],
|
|
599
|
-
evidence: evidence.map((item) => ({
|
|
600
|
-
sourceItemId: item.sourceItemId,
|
|
601
|
-
relation: item.relation === "contradicts" ? "contradicts" : "supports",
|
|
602
|
-
observedAt: item.observedAt,
|
|
603
|
-
confidence: updated.confidence
|
|
604
|
-
})),
|
|
605
|
-
reviewAfter: nextMemoryReviewAt({
|
|
606
|
-
durability: candidate.durability,
|
|
607
|
-
explicitness: "explicit"
|
|
608
|
-
})
|
|
609
|
-
});
|
|
610
|
-
linkUserClaimMemoryRecord(updated.id, record.id);
|
|
611
|
-
}
|
|
612
|
-
return getUserClaim(updated.id);
|
|
613
|
-
});
|
|
614
|
-
if (!claim) return c.json({ error: "Connected claim not found" }, 404);
|
|
615
|
-
return c.json({
|
|
616
|
-
ok: true,
|
|
617
|
-
claim: {
|
|
618
|
-
...claim,
|
|
619
|
-
evidence: listUserClaimEvidence(claim.id)
|
|
620
|
-
}
|
|
621
|
-
});
|
|
622
|
-
});
|
|
623
|
-
authenticated.get("/api/you/profile", async (c) => {
|
|
624
|
-
return c.json(await readProfileBundle(deps.service.currentConfig));
|
|
625
|
-
});
|
|
626
|
-
authenticated.get("/api/you/export", async (c) => {
|
|
627
|
-
const config = deps.service.currentConfig;
|
|
628
|
-
const profileBundle = await readProfileBundle(config);
|
|
629
|
-
const understanding = listAllUserContextRecords(ALL_MEMORY_STATUSES).filter(isUserContextRecord).map((record) => ({
|
|
630
|
-
statement: record.content,
|
|
631
|
-
kind: record.kind,
|
|
632
|
-
status: record.status,
|
|
633
|
-
sensitivity: record.sensitivity ?? "normal",
|
|
634
|
-
durability: record.durability,
|
|
635
|
-
disclosurePolicy: record.disclosurePolicy,
|
|
636
|
-
sourceName: record.source.provider ?? "local",
|
|
637
|
-
updatedAt: record.updatedAt
|
|
638
|
-
}));
|
|
639
|
-
return c.json({
|
|
640
|
-
version: 2,
|
|
641
|
-
exportedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
642
|
-
profile: profileBundle.profile,
|
|
643
|
-
understanding
|
|
644
|
-
});
|
|
645
|
-
});
|
|
646
|
-
authenticated.post("/api/you/import", deps.strictRateLimitMiddleware, async (c) => {
|
|
647
|
-
const body = await c.req.json().catch(() => null);
|
|
648
|
-
if (!body || typeof body !== "object" || Array.isArray(body) || body.version !== 2 || !Array.isArray(body.understanding)) return c.json({ error: "Invalid About You export" }, 400);
|
|
649
|
-
if (body.understanding.length > 500) return c.json({ error: "Import is limited to 500 understandings" }, 400);
|
|
650
|
-
const config = deps.service.currentConfig;
|
|
651
|
-
const agentId = selectedAgentId(config);
|
|
652
|
-
const existingStatements = listAllUserContextRecords(ALL_MEMORY_STATUSES).filter(isUserContextRecord).map((record) => record.content);
|
|
653
|
-
const { imports, skippedCount } = prepareUserContextImport(body.understanding, existingStatements);
|
|
654
|
-
runSqliteWriteTransaction(() => {
|
|
655
|
-
for (const item of imports) upsertMemoryRecord({
|
|
656
|
-
providerId: "local",
|
|
657
|
-
kind: item.kind,
|
|
658
|
-
sourceAgentId: agentId,
|
|
659
|
-
content: item.statement,
|
|
660
|
-
source: {
|
|
661
|
-
provider: "local",
|
|
662
|
-
path: "import://about-you"
|
|
663
|
-
},
|
|
664
|
-
confidence: 1,
|
|
665
|
-
tags: ["user-understanding", "user-import"],
|
|
666
|
-
status: "candidate",
|
|
667
|
-
sensitivity: item.sensitivity,
|
|
668
|
-
explicitness: "explicit",
|
|
669
|
-
durability: item.durability,
|
|
670
|
-
importance: .7,
|
|
671
|
-
disclosurePolicy: item.disclosurePolicy
|
|
672
|
-
});
|
|
673
|
-
});
|
|
674
|
-
return c.json({
|
|
675
|
-
ok: true,
|
|
676
|
-
importedCount: imports.length,
|
|
677
|
-
skippedCount
|
|
678
|
-
});
|
|
679
|
-
});
|
|
680
|
-
authenticated.post("/api/you/understanding", deps.strictRateLimitMiddleware, async (c) => {
|
|
681
|
-
const body = await c.req.json().catch(() => ({}));
|
|
682
|
-
const content = typeof body.content === "string" ? body.content.trim() : "";
|
|
683
|
-
const kind = isUserContextMemoryKind(body.kind) ? body.kind : void 0;
|
|
684
|
-
if (!content || content.length > 5e3) return c.json({ error: "Understanding content must be 1-5000 characters" }, 400);
|
|
685
|
-
if (!kind) return c.json({ error: "A valid user understanding kind is required" }, 400);
|
|
686
|
-
const scope = body.scope === "session" ? {
|
|
687
|
-
type: "session",
|
|
688
|
-
sessionKey: typeof body.sessionKey === "string" ? body.sessionKey.trim() : ""
|
|
689
|
-
} : body.scope === void 0 || body.scope === "global" ? { type: "global" } : null;
|
|
690
|
-
if (!scope || scope.type === "session" && !scope.sessionKey) return c.json({ error: "scope must be global or a session with sessionKey" }, 400);
|
|
691
|
-
const sensitivity = MEMORY_SENSITIVITIES.has(body.sensitivity) ? body.sensitivity : "normal";
|
|
692
|
-
const durability = MEMORY_DURABILITIES.has(body.durability) ? body.durability : "durable";
|
|
693
|
-
const disclosurePolicy = MEMORY_DISCLOSURE_POLICIES.has(body.disclosurePolicy) ? body.disclosurePolicy : "referenceable";
|
|
694
|
-
const config = deps.service.currentConfig;
|
|
695
|
-
const result = createManualUnderstanding({
|
|
696
|
-
agentId: selectedAgentId(config),
|
|
697
|
-
content,
|
|
698
|
-
kind,
|
|
699
|
-
scope,
|
|
700
|
-
sensitivity,
|
|
701
|
-
durability,
|
|
702
|
-
disclosurePolicy
|
|
703
|
-
});
|
|
704
|
-
if (!result.created) return c.json({
|
|
705
|
-
error: "This understanding already exists in the selected scope",
|
|
706
|
-
understanding: projectUserContextRecord(result.record)
|
|
707
|
-
}, 409);
|
|
708
|
-
return c.json({ understanding: projectUserContextRecord(result.record) }, 201);
|
|
709
|
-
});
|
|
710
|
-
authenticated.get("/api/you/understanding/:id/history", (c) => {
|
|
711
|
-
const all = listAllUserContextRecords(ALL_MEMORY_STATUSES).filter(isUserContextRecord);
|
|
712
|
-
const target = all.find((record) => record.id === c.req.param("id"));
|
|
713
|
-
if (!target) return c.json({ error: "Understanding not found" }, 404);
|
|
714
|
-
const relatedIds = new Set([target.id]);
|
|
715
|
-
let changed = true;
|
|
716
|
-
while (changed) {
|
|
717
|
-
changed = false;
|
|
718
|
-
for (const record of all) if (record.supersedesRecordId && relatedIds.has(record.supersedesRecordId) || record.supersedesRecordId && relatedIds.has(record.id)) {
|
|
719
|
-
if (!relatedIds.has(record.id)) {
|
|
720
|
-
relatedIds.add(record.id);
|
|
721
|
-
changed = true;
|
|
722
|
-
}
|
|
723
|
-
if (record.supersedesRecordId && !relatedIds.has(record.supersedesRecordId)) {
|
|
724
|
-
relatedIds.add(record.supersedesRecordId);
|
|
725
|
-
changed = true;
|
|
726
|
-
}
|
|
727
|
-
}
|
|
132
|
+
if (body.accessibility !== void 0) {
|
|
133
|
+
const accessibility = asRecord(body.accessibility);
|
|
134
|
+
if (!accessibility) return c.json({ error: "accessibility must be an object" }, 400);
|
|
135
|
+
if (JSON.stringify(accessibility).length > 1e4) return c.json({ error: "accessibility is too large" }, 400);
|
|
136
|
+
patch.accessibility = accessibility;
|
|
728
137
|
}
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
const
|
|
737
|
-
|
|
738
|
-
const
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
if (!record) continue;
|
|
745
|
-
if (action === "forget") deleteMemoryRecord(id);
|
|
746
|
-
else preserveRecord(record, {
|
|
747
|
-
status: action === "confirm" ? "active" : "rejected",
|
|
748
|
-
...action === "confirm" ? {
|
|
749
|
-
reviewAfter: nextMemoryReviewAt(record),
|
|
750
|
-
tags: [...new Set([...record.tags ?? [], USER_CONFIRMED_MEMORY_TAG])]
|
|
751
|
-
} : {}
|
|
752
|
-
});
|
|
753
|
-
updatedCount += 1;
|
|
754
|
-
}
|
|
755
|
-
});
|
|
756
|
-
return c.json({
|
|
757
|
-
ok: true,
|
|
758
|
-
updatedCount
|
|
759
|
-
});
|
|
760
|
-
});
|
|
761
|
-
authenticated.post("/api/you/conflicts/:id/resolve", deps.strictRateLimitMiddleware, async (c) => {
|
|
762
|
-
const body = await c.req.json().catch(() => ({}));
|
|
763
|
-
const winnerId = typeof body.winnerId === "string" ? body.winnerId : "";
|
|
764
|
-
const group = listAllUserContextRecords(ALL_MEMORY_STATUSES).filter(isUserContextRecord).filter((record) => record.conflictGroupId === c.req.param("id"));
|
|
765
|
-
const winner = group.find((record) => record.id === winnerId && VISIBLE_STATUSES.has(record.status));
|
|
766
|
-
if (group.length < 2 || !winner) return c.json({ error: "Conflict group or winner not found" }, 404);
|
|
767
|
-
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
768
|
-
runSqliteWriteTransaction(() => {
|
|
769
|
-
for (const record of group) preserveRecord(record, record.id === winnerId ? {
|
|
770
|
-
status: "active",
|
|
771
|
-
reviewAfter: nextMemoryReviewAt(record),
|
|
772
|
-
tags: [...new Set([...record.tags ?? [], USER_CONFIRMED_MEMORY_TAG])]
|
|
773
|
-
} : {
|
|
774
|
-
status: "archived",
|
|
775
|
-
validTo: record.validTo ?? now
|
|
776
|
-
});
|
|
777
|
-
});
|
|
778
|
-
return c.json({
|
|
779
|
-
ok: true,
|
|
780
|
-
understanding: projectUserContextRecord(getMemoryRecord(winnerId))
|
|
781
|
-
});
|
|
782
|
-
});
|
|
783
|
-
authenticated.patch("/api/you/profile", deps.strictRateLimitMiddleware, async (c) => {
|
|
784
|
-
const config = deps.service.currentConfig;
|
|
785
|
-
const parsed = parseProfilePatch(await c.req.json().catch(() => null));
|
|
786
|
-
if ("error" in parsed) return c.json({ error: parsed.error }, 400);
|
|
787
|
-
const current = await readUserProfileFile();
|
|
788
|
-
const saved = await writeUserProfileFile(patchUserProfileMarkdown(current.ok ? current.data.content : "", parsed.patch));
|
|
789
|
-
if (saved.ok === false) return c.json({ error: saved.error }, saved.status ?? 500);
|
|
790
|
-
if (parsed.patch.callName !== void 0) setUserProfilePromptState({ state: "active" });
|
|
791
|
-
deps.service.refreshUserProfileContext();
|
|
792
|
-
return c.json(await readProfileBundle(config));
|
|
793
|
-
});
|
|
794
|
-
authenticated.post("/api/you/profile-prompt", deps.strictRateLimitMiddleware, async (c) => {
|
|
795
|
-
const body = await c.req.json().catch(() => ({}));
|
|
796
|
-
const action = typeof body.action === "string" ? body.action : "";
|
|
797
|
-
if (action !== "snooze" && action !== "reset") return c.json({ error: "Action must be snooze or reset" }, 400);
|
|
798
|
-
const config = deps.service.currentConfig;
|
|
799
|
-
const current = await readProfileBundle(config);
|
|
800
|
-
const suggestionHash = current.profileSetup.callNameSuggestion?.id;
|
|
801
|
-
const promptState = action === "snooze" ? setUserProfilePromptState({
|
|
802
|
-
state: "snoozed",
|
|
803
|
-
suggestionHash,
|
|
804
|
-
snoozedUntil: new Date(Date.now() + PROFILE_PROMPT_SNOOZE_MS).toISOString()
|
|
805
|
-
}) : setUserProfilePromptState({
|
|
806
|
-
state: "active",
|
|
807
|
-
suggestionHash
|
|
808
|
-
});
|
|
809
|
-
return c.json({ profileSetup: buildUserProfileSetup({
|
|
810
|
-
profile: current.profile,
|
|
811
|
-
promptState,
|
|
812
|
-
config
|
|
813
|
-
}) });
|
|
814
|
-
});
|
|
815
|
-
authenticated.patch("/api/you/trust", deps.strictRateLimitMiddleware, async (c) => {
|
|
816
|
-
const body = await c.req.json().catch(() => ({}));
|
|
817
|
-
if (!isUserTrustLevel(body.defaultActionLevel)) return c.json({ error: "Invalid default action level" }, 400);
|
|
818
|
-
const policy = setUserTrustPolicy(body.defaultActionLevel);
|
|
819
|
-
deps.service.refreshActionTrustPolicy();
|
|
820
|
-
return c.json({ trust: {
|
|
821
|
-
defaultActionLevel: policy.defaultActionLevel,
|
|
822
|
-
levels: USER_TRUST_LEVELS,
|
|
823
|
-
autoRequiresExplicitOptIn: true
|
|
824
|
-
} });
|
|
825
|
-
});
|
|
826
|
-
authenticated.patch("/api/you/playbooks/:id", deps.strictRateLimitMiddleware, async (c) => {
|
|
827
|
-
const id = c.req.param("id");
|
|
828
|
-
if (!PLAYBOOK_IDS.includes(id)) return c.json({ error: "Playbook not found" }, 404);
|
|
829
|
-
const enabled = (await c.req.json().catch(() => ({}))).enabled;
|
|
830
|
-
if (typeof enabled !== "boolean") return c.json({ error: "enabled must be a boolean" }, 400);
|
|
831
|
-
const active = listMemoryRecords({
|
|
832
|
-
status: "active",
|
|
833
|
-
limit: 500
|
|
834
|
-
}).filter(isUserContextRecord).filter((record) => playbookForRecord(record) === id);
|
|
835
|
-
runSqliteWriteTransaction(() => {
|
|
836
|
-
for (const record of active) versionPlaybookRule(record, { tags: patchPlaybookRuleTags(record, { enabled }) });
|
|
837
|
-
});
|
|
838
|
-
const current = active.map((record) => ({
|
|
839
|
-
...record,
|
|
840
|
-
tags: patchPlaybookRuleTags(record, { enabled })
|
|
841
|
-
}));
|
|
842
|
-
return c.json({
|
|
843
|
-
ok: true,
|
|
844
|
-
playbook: buildPersonalPlaybooks(current).find((playbook) => playbook.id === id)
|
|
845
|
-
});
|
|
846
|
-
});
|
|
847
|
-
authenticated.post("/api/you/playbooks/:id/rules", deps.strictRateLimitMiddleware, async (c) => {
|
|
848
|
-
const id = c.req.param("id");
|
|
849
|
-
if (!PLAYBOOK_IDS.includes(id)) return c.json({ error: "Playbook not found" }, 404);
|
|
850
|
-
const body = await c.req.json().catch(() => ({}));
|
|
851
|
-
const statement = typeof body.statement === "string" ? body.statement.trim() : "";
|
|
852
|
-
if (!statement || statement.length > 5e3) return c.json({ error: "Rule statement is required" }, 400);
|
|
853
|
-
const parsedContext = parsePlaybookContext(body.context);
|
|
854
|
-
if ("error" in parsedContext) return c.json({ error: parsedContext.error }, 400);
|
|
855
|
-
const record = upsertMemoryRecord({
|
|
856
|
-
providerId: "local",
|
|
857
|
-
kind: id === "communication" ? "preference" : id === "execution" ? "task_lesson" : "routine",
|
|
858
|
-
sourceAgentId: selectedAgentId(deps.service.currentConfig),
|
|
859
|
-
content: statement,
|
|
860
|
-
source: {
|
|
861
|
-
provider: "local",
|
|
862
|
-
path: "you://playbook"
|
|
863
|
-
},
|
|
864
|
-
confidence: 1,
|
|
865
|
-
tags: patchPersonalPlaybookContextTags([
|
|
866
|
-
"user-understanding",
|
|
867
|
-
PERSONAL_PLAYBOOK_RULE_TAG,
|
|
868
|
-
`${PERSONAL_PLAYBOOK_ORDER_PREFIX}${Number.isInteger(body.order) ? body.order : 1e3}`
|
|
869
|
-
], parsedContext.context),
|
|
138
|
+
if (patch.timezone !== void 0 && !validTimezone(patch.timezone)) return c.json({ error: "timezone must be a valid IANA time zone" }, 400);
|
|
139
|
+
return c.json({ profile: updateUserProfile(patch) });
|
|
140
|
+
});
|
|
141
|
+
authenticated.post("/api/you/understandings", write, async (c) => {
|
|
142
|
+
const body = await readBody(c);
|
|
143
|
+
const statement = nonEmptyString(body?.statement);
|
|
144
|
+
const kind = body?.kind;
|
|
145
|
+
const scope = scopeFrom(body?.scope ?? { type: "global" });
|
|
146
|
+
if (!statement || !UNDERSTANDING_KINDS.has(kind) || !scope) return c.json({ error: "Valid statement, kind, and scope are required" }, 400);
|
|
147
|
+
const typedKind = kind;
|
|
148
|
+
const key = canonicalKey(typedKind, statement);
|
|
149
|
+
if (listUnderstandings().some((item) => item.canonicalKey === key && sameScope(item.scope, scope) && item.status !== "archived" && item.status !== "rejected")) return c.json({ error: "This understanding already exists" }, 409);
|
|
150
|
+
const understanding = createUnderstanding({
|
|
151
|
+
kind: typedKind,
|
|
152
|
+
canonicalKey: key,
|
|
870
153
|
status: "active",
|
|
871
|
-
|
|
154
|
+
scope,
|
|
872
155
|
explicitness: "explicit",
|
|
873
|
-
durability:
|
|
874
|
-
|
|
875
|
-
disclosurePolicy: "referenceable"
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
}, 201);
|
|
881
|
-
});
|
|
882
|
-
authenticated.patch("/api/you/playbooks/:id/rules/:recordId", deps.strictRateLimitMiddleware, async (c) => {
|
|
883
|
-
const id = c.req.param("id");
|
|
884
|
-
const record = editableRecord(c.req.param("recordId"));
|
|
885
|
-
if (!PLAYBOOK_IDS.includes(id) || !record || playbookForRecord(record) !== id) return c.json({ error: "Playbook rule not found" }, 404);
|
|
886
|
-
const body = await c.req.json().catch(() => ({}));
|
|
887
|
-
const content = body.statement === void 0 ? record.content : typeof body.statement === "string" ? body.statement.trim() : "";
|
|
888
|
-
if (!content || content.length > 5e3) return c.json({ error: "Rule statement is required" }, 400);
|
|
889
|
-
if (body.enabled !== void 0 && typeof body.enabled !== "boolean") return c.json({ error: "enabled must be boolean" }, 400);
|
|
890
|
-
if (body.order !== void 0 && (!Number.isInteger(body.order) || body.order < 0 || body.order > 1e4)) return c.json({ error: "order must be an integer between 0 and 10000" }, 400);
|
|
891
|
-
const parsedContext = parsePlaybookContext(body.context);
|
|
892
|
-
if ("error" in parsedContext) return c.json({ error: parsedContext.error }, 400);
|
|
893
|
-
const updated = versionPlaybookRule(record, {
|
|
894
|
-
content,
|
|
895
|
-
tags: patchPersonalPlaybookContextTags(patchPlaybookRuleTags(record, {
|
|
896
|
-
enabled: body.enabled,
|
|
897
|
-
order: body.order
|
|
898
|
-
}), parsedContext.context),
|
|
899
|
-
explicitness: body.statement === void 0 ? record.explicitness : "explicit"
|
|
900
|
-
});
|
|
901
|
-
return c.json({
|
|
902
|
-
ok: true,
|
|
903
|
-
rule: buildPersonalPlaybooks([updated]).find((playbook) => playbook.id === id)?.rules[0]
|
|
156
|
+
durability: "durable",
|
|
157
|
+
sensitivity: "normal",
|
|
158
|
+
disclosurePolicy: typedKind === "boundary" ? "silent" : "referenceable",
|
|
159
|
+
confidence: 1,
|
|
160
|
+
statement,
|
|
161
|
+
createdBy: "user",
|
|
162
|
+
changeReason: "Created by user"
|
|
904
163
|
});
|
|
164
|
+
return c.json({ understanding }, 201);
|
|
905
165
|
});
|
|
906
|
-
authenticated.
|
|
907
|
-
const
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
preserveRecord(record, {
|
|
911
|
-
status: "archived",
|
|
912
|
-
validTo: (/* @__PURE__ */ new Date()).toISOString()
|
|
913
|
-
});
|
|
914
|
-
return c.json({ ok: true });
|
|
166
|
+
authenticated.get("/api/you/understandings/:id/evidence", (c) => {
|
|
167
|
+
const understanding = getUnderstanding(c.req.param("id"));
|
|
168
|
+
if (!understanding) return c.json({ error: "Understanding not found" }, 404);
|
|
169
|
+
return c.json({ evidence: listUnderstandingEvidence(understanding.id) });
|
|
915
170
|
});
|
|
916
|
-
authenticated.
|
|
171
|
+
authenticated.patch("/api/you/understandings/:id", write, async (c) => {
|
|
917
172
|
const id = c.req.param("id");
|
|
918
|
-
|
|
919
|
-
if (!
|
|
920
|
-
const body = await c
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
ok: true,
|
|
933
|
-
rule: buildPersonalPlaybooks([...all, rolledBack]).find((playbook) => playbook.id === id)?.rules.find((rule) => rule.id === rolledBack.id)
|
|
934
|
-
});
|
|
935
|
-
});
|
|
936
|
-
authenticated.post("/api/you/insights/:id/apply", deps.strictRateLimitMiddleware, async (c) => {
|
|
937
|
-
const config = deps.service.currentConfig;
|
|
938
|
-
const existing = editableRecord(c.req.param("id"));
|
|
939
|
-
const suggestion = existing ? buildActionableInsightSuggestions([existing], [])[0] : void 0;
|
|
940
|
-
if (!existing || !suggestion) return c.json({ error: "Insight not found" }, 404);
|
|
941
|
-
if (suggestion.action === "start_progress") return c.json({ error: "Progress insights must be reviewed as task drafts" }, 400);
|
|
942
|
-
if (existing.kind === "routine") {
|
|
943
|
-
preserveRecord(existing, { tags: [...new Set([...existing.tags ?? [], INSIGHT_ACCEPTED_TAG])] });
|
|
944
|
-
return c.json({
|
|
945
|
-
ok: true,
|
|
946
|
-
status: "drafting",
|
|
947
|
-
href: buildRoutineAutomationDraftHref(existing)
|
|
173
|
+
let understanding = getUnderstanding(id);
|
|
174
|
+
if (!understanding) return c.json({ error: "Understanding not found" }, 404);
|
|
175
|
+
const body = await readBody(c);
|
|
176
|
+
if (!body) return c.json({ error: "Invalid JSON" }, 400);
|
|
177
|
+
if (body.statement !== void 0) {
|
|
178
|
+
const statement = nonEmptyString(body.statement);
|
|
179
|
+
if (!statement) return c.json({ error: "statement must be 1-2000 characters" }, 400);
|
|
180
|
+
const key = canonicalKey(understanding.kind, statement);
|
|
181
|
+
if (listUnderstandings().some((item) => item.id !== id && item.canonicalKey === key && sameScope(item.scope, understanding.scope) && item.status !== "archived" && item.status !== "rejected")) return c.json({ error: "This understanding already exists" }, 409);
|
|
182
|
+
understanding = reviseUnderstanding(id, statement, {
|
|
183
|
+
canonicalKey: key,
|
|
184
|
+
explicitness: "explicit",
|
|
185
|
+
confidence: 1,
|
|
186
|
+
changeReason: "Edited by user"
|
|
948
187
|
});
|
|
949
188
|
}
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
return c.json({
|
|
976
|
-
ok: true,
|
|
977
|
-
status: "saved"
|
|
978
|
-
});
|
|
979
|
-
});
|
|
980
|
-
authenticated.delete("/api/you/insights/:id", deps.strictRateLimitMiddleware, (c) => {
|
|
981
|
-
const existing = editableRecord(c.req.param("id"));
|
|
982
|
-
const suggestion = existing ? buildActionableInsightSuggestions([existing], [])[0] : void 0;
|
|
983
|
-
if (!existing || !suggestion) return c.json({ error: "Insight not found" }, 404);
|
|
984
|
-
preserveRecord(existing, { tags: [...new Set([...existing.tags ?? [], INSIGHT_DISMISSED_TAG])] });
|
|
985
|
-
return c.json({
|
|
986
|
-
ok: true,
|
|
987
|
-
status: "dismissed"
|
|
988
|
-
});
|
|
989
|
-
});
|
|
990
|
-
authenticated.post("/api/you/insights/:id/complete", deps.strictRateLimitMiddleware, async (c) => {
|
|
991
|
-
const existing = editableRecord(c.req.param("id"));
|
|
992
|
-
const suggestion = existing ? buildActionableInsightSuggestions([existing], [])[0] : void 0;
|
|
993
|
-
if (!existing || suggestion?.action !== "start_progress") return c.json({ error: "Insight not found" }, 404);
|
|
994
|
-
const body = await c.req.json().catch(() => ({}));
|
|
995
|
-
const taskId = typeof body.taskId === "string" ? body.taskId.trim() : "";
|
|
996
|
-
const task = taskId ? new TaskRepository().get(taskId) : null;
|
|
997
|
-
const linked = task && new TaskContextRepository().list(task.id).some((edge) => edge.targetKind === "memory" && edge.targetId === existing.id);
|
|
998
|
-
if (!task || !linked) return c.json({ error: "A linked task draft is required" }, 400);
|
|
999
|
-
preserveRecord(existing, { tags: [...new Set([...existing.tags ?? [], INSIGHT_ACCEPTED_TAG])] });
|
|
1000
|
-
return c.json({
|
|
1001
|
-
ok: true,
|
|
1002
|
-
status: "saved",
|
|
1003
|
-
taskId: task.id
|
|
189
|
+
if (body.status !== void 0) {
|
|
190
|
+
if (!UNDERSTANDING_STATUSES.has(body.status)) return c.json({ error: "Invalid status" }, 400);
|
|
191
|
+
understanding = body.status === "rejected" ? rejectUnderstanding(id, nonEmptyString(body.reason, 500) ?? "Rejected by user") : setUnderstandingStatus(id, body.status, body.status === "active" ? {
|
|
192
|
+
explicitness: "explicit",
|
|
193
|
+
confidence: 1
|
|
194
|
+
} : void 0);
|
|
195
|
+
}
|
|
196
|
+
return c.json({ understanding });
|
|
197
|
+
});
|
|
198
|
+
authenticated.delete("/api/you/understandings/:id", write, (c) => deleteUnderstanding(c.req.param("id")) ? c.json({ ok: true }) : c.json({ error: "Understanding not found" }, 404));
|
|
199
|
+
authenticated.post("/api/you/rules", write, async (c) => {
|
|
200
|
+
const body = await readBody(c);
|
|
201
|
+
const statement = nonEmptyString(body?.statement);
|
|
202
|
+
const category = body?.category;
|
|
203
|
+
const scope = scopeFrom(body?.scope ?? { type: "global" });
|
|
204
|
+
if (!statement || !RULE_CATEGORIES.has(category) || !scope) return c.json({ error: "Valid statement, category, and scope are required" }, 400);
|
|
205
|
+
const priority = typeof body?.priority === "number" && Number.isInteger(body.priority) ? Math.max(0, Math.min(100, body.priority)) : 50;
|
|
206
|
+
const conditions = body?.conditions === void 0 ? {} : asRecord(body.conditions);
|
|
207
|
+
if (!conditions) return c.json({ error: "conditions must be an object" }, 400);
|
|
208
|
+
const rule = createCollaborationRule({
|
|
209
|
+
category,
|
|
210
|
+
priority,
|
|
211
|
+
scope,
|
|
212
|
+
conditions,
|
|
213
|
+
statement
|
|
1004
214
|
});
|
|
215
|
+
return c.json({ rule }, 201);
|
|
1005
216
|
});
|
|
1006
|
-
authenticated.patch("/api/you/
|
|
1007
|
-
const
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
},
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
}
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
217
|
+
authenticated.patch("/api/you/rules/:id", write, async (c) => {
|
|
218
|
+
const id = c.req.param("id");
|
|
219
|
+
let rule = getCollaborationRule(id);
|
|
220
|
+
if (!rule) return c.json({ error: "Collaboration rule not found" }, 404);
|
|
221
|
+
const body = await readBody(c);
|
|
222
|
+
if (!body) return c.json({ error: "Invalid JSON" }, 400);
|
|
223
|
+
if (body.statement !== void 0) {
|
|
224
|
+
const statement = nonEmptyString(body.statement);
|
|
225
|
+
if (!statement) return c.json({ error: "statement must be 1-2000 characters" }, 400);
|
|
226
|
+
rule = reviseCollaborationRule(id, statement);
|
|
227
|
+
}
|
|
228
|
+
if (body.status !== void 0) {
|
|
229
|
+
if (!RULE_STATUSES.has(body.status)) return c.json({ error: "Invalid status" }, 400);
|
|
230
|
+
rule = setCollaborationRuleStatus(id, body.status);
|
|
231
|
+
}
|
|
232
|
+
return c.json({ rule });
|
|
233
|
+
});
|
|
234
|
+
authenticated.delete("/api/you/rules/:id", write, (c) => deleteCollaborationRule(c.req.param("id")) ? c.json({ ok: true }) : c.json({ error: "Collaboration rule not found" }, 404));
|
|
235
|
+
authenticated.get("/api/you/turns/:turnId/personalization", (c) => {
|
|
236
|
+
const personalization = getTurnPersonalization(c.req.param("turnId"));
|
|
237
|
+
return personalization ? c.json({ personalization }) : c.json({ error: "Personalization run not found" }, 404);
|
|
238
|
+
});
|
|
239
|
+
authenticated.post("/api/you/turns/:turnId/feedback", write, async (c) => {
|
|
240
|
+
const turnId = c.req.param("turnId");
|
|
241
|
+
const run = getTurnPersonalization(turnId);
|
|
242
|
+
if (!run) return c.json({ error: "Personalization run not found" }, 404);
|
|
243
|
+
const body = await readBody(c);
|
|
244
|
+
if (!body || !FEEDBACK_RATINGS.has(String(body.rating))) return c.json({ error: "Invalid feedback rating" }, 400);
|
|
245
|
+
const objectType = body.objectType;
|
|
246
|
+
const objectId = body.objectId;
|
|
247
|
+
if (objectType === void 0 !== (objectId === void 0) || objectType !== void 0 && ![
|
|
248
|
+
"profile",
|
|
249
|
+
"rule",
|
|
250
|
+
"understanding"
|
|
251
|
+
].includes(String(objectType)) || objectId !== void 0 && typeof objectId !== "string") return c.json({ error: "objectType and objectId must be valid and provided together" }, 400);
|
|
252
|
+
if (objectType !== void 0 && !run.items.some((item) => item.objectType === objectType && item.objectId === objectId)) return c.json({ error: "The context object was not part of this turn" }, 400);
|
|
253
|
+
const rating = body.rating;
|
|
254
|
+
recordContextFeedback({
|
|
255
|
+
turnId,
|
|
256
|
+
runId: run.runId,
|
|
257
|
+
rating,
|
|
258
|
+
...objectType ? {
|
|
259
|
+
objectType,
|
|
260
|
+
objectId
|
|
261
|
+
} : {},
|
|
262
|
+
...typeof body.reason === "string" ? { reason: body.reason.slice(0, 500) } : {}
|
|
263
|
+
});
|
|
264
|
+
if (objectType === "understanding" && typeof objectId === "string") {
|
|
265
|
+
if (rating === "wrong") rejectUnderstanding(objectId, "Marked wrong from turn feedback");
|
|
266
|
+
if (rating === "stale") setUnderstandingStatus(objectId, "stale");
|
|
267
|
+
if (rating === "sensitive") setUnderstandingStatus(objectId, "needs_review");
|
|
268
|
+
}
|
|
269
|
+
return c.json({ ok: true });
|
|
1031
270
|
});
|
|
1032
|
-
authenticated.patch("/api/you/consents/:id",
|
|
1033
|
-
const
|
|
1034
|
-
const decision = typeof body.decision === "string" ? body.decision : "";
|
|
271
|
+
authenticated.patch("/api/you/consents/:id", write, async (c) => {
|
|
272
|
+
const decision = (await readBody(c))?.decision;
|
|
1035
273
|
if (![
|
|
1036
274
|
"once",
|
|
1037
275
|
"session",
|
|
1038
276
|
"always",
|
|
1039
277
|
"deny"
|
|
1040
|
-
].includes(decision)) return c.json({ error: "
|
|
1041
|
-
|
|
1042
|
-
if (!consent) return c.json({ error: "Pending consent not found" }, 404);
|
|
1043
|
-
return c.json({
|
|
1044
|
-
ok: true,
|
|
1045
|
-
consent
|
|
1046
|
-
});
|
|
1047
|
-
});
|
|
1048
|
-
authenticated.delete("/api/you/consents/:id", deps.strictRateLimitMiddleware, (c) => {
|
|
1049
|
-
const consent = revokeMemoryReferenceConsent(c.req.param("id"));
|
|
1050
|
-
if (!consent) return c.json({ error: "Active reference grant not found" }, 404);
|
|
1051
|
-
return c.json({
|
|
1052
|
-
ok: true,
|
|
1053
|
-
consent
|
|
1054
|
-
});
|
|
1055
|
-
});
|
|
1056
|
-
authenticated.delete("/api/you/sources/:instanceId", deps.strictRateLimitMiddleware, async (c) => {
|
|
1057
|
-
const config = deps.service.currentConfig;
|
|
1058
|
-
const instanceId = c.req.param("instanceId");
|
|
1059
|
-
const installedInstances = listConnectorInstances(config);
|
|
1060
|
-
const account = getConnectorAccount(instanceId);
|
|
1061
|
-
const accountConnections = account ? listConnectorConnections({
|
|
1062
|
-
principalId: account.principalId,
|
|
1063
|
-
connectorId: account.connectorId
|
|
1064
|
-
}).filter((connection) => connection.accountId === account.id) : [];
|
|
1065
|
-
const instance = installedInstances.find((item) => item.instanceId === instanceId);
|
|
1066
|
-
const connectorId = account?.connectorId ?? instance?.connectorId;
|
|
1067
|
-
const definition = connectorId ? listConnectorCatalog().find((item) => item.id === connectorId) : void 0;
|
|
1068
|
-
if (!instance && !account || !definition || !definition.capabilities.some((capability) => capability === "context" || capability === "memory_source")) return c.json({ error: "Personal context source not found" }, 404);
|
|
1069
|
-
const body = await c.req.json().catch(() => ({}));
|
|
1070
|
-
const understandingPolicy = body.understandingPolicy === "keep" || body.understandingPolicy === "delete" ? body.understandingPolicy : void 0;
|
|
1071
|
-
if (!understandingPolicy) return c.json({ error: "understandingPolicy must be keep or delete" }, 400);
|
|
1072
|
-
try {
|
|
1073
|
-
if (account) for (const connection of accountConnections.filter((candidate) => candidate.status !== "revoked")) await revokeComposioConnection(connection.id);
|
|
1074
|
-
else if (instance) {
|
|
1075
|
-
uninstallConnector(config, instance.instanceId);
|
|
1076
|
-
const saved = await deps.service.saveConfig(config);
|
|
1077
|
-
if (!saved.saved) return c.json({ error: saved.error ?? "save failed" }, 500);
|
|
1078
|
-
}
|
|
1079
|
-
} catch (error) {
|
|
1080
|
-
return c.json({ error: error instanceof Error ? error.message : String(error) }, 400);
|
|
1081
|
-
}
|
|
1082
|
-
let deletedUnderstandingCount = 0;
|
|
1083
|
-
let deletedClaimCount = 0;
|
|
1084
|
-
if (understandingPolicy === "delete") {
|
|
1085
|
-
const sourceInstanceId = account ? `composio:${account.connectorId}:${account.id}` : instanceId;
|
|
1086
|
-
const targets = recordsDerivedFromPersonalContextSource(listAllUserContextRecords(ALL_MEMORY_STATUSES), sourceInstanceId);
|
|
1087
|
-
runSqliteWriteTransaction(() => {
|
|
1088
|
-
const claimRemoval = removeUserClaimEvidenceForSource(sourceInstanceId);
|
|
1089
|
-
deletedClaimCount = claimRemoval.deletedClaimCount;
|
|
1090
|
-
const retainedMemoryIds = new Set(claimRemoval.retainedClaims.map((claim) => claim.memoryRecordId));
|
|
1091
|
-
const deleteIds = new Set([...claimRemoval.deletedMemoryRecordIds, ...targets.filter((record) => !retainedMemoryIds.has(record.id)).map((record) => record.id)]);
|
|
1092
|
-
for (const recordId of deleteIds) deleteMemoryRecord(recordId);
|
|
1093
|
-
for (const retained of claimRemoval.retainedClaims) {
|
|
1094
|
-
if (retained.state === "active") continue;
|
|
1095
|
-
const record = getMemoryRecord(retained.memoryRecordId);
|
|
1096
|
-
if (record) preserveRecord(record, { status: retained.state === "rejected" ? "rejected" : "stale" });
|
|
1097
|
-
}
|
|
1098
|
-
deletedUnderstandingCount = deleteIds.size;
|
|
1099
|
-
});
|
|
1100
|
-
}
|
|
1101
|
-
return c.json({
|
|
1102
|
-
ok: true,
|
|
1103
|
-
deletedUnderstandingCount,
|
|
1104
|
-
deletedClaimCount
|
|
1105
|
-
});
|
|
1106
|
-
});
|
|
1107
|
-
authenticated.patch("/api/you/understanding/:id", deps.strictRateLimitMiddleware, async (c) => {
|
|
1108
|
-
const existing = editableRecord(c.req.param("id"));
|
|
1109
|
-
if (!existing) return c.json({ error: "Understanding not found" }, 404);
|
|
1110
|
-
const body = await c.req.json().catch(() => ({}));
|
|
1111
|
-
const action = typeof body.action === "string" ? body.action : "";
|
|
1112
|
-
if (action === "confirm") return c.json({ understanding: projectUserContextRecord(preserveRecord(existing, {
|
|
1113
|
-
status: "active",
|
|
1114
|
-
reviewAfter: nextMemoryReviewAt(existing),
|
|
1115
|
-
tags: [...new Set([...existing.tags ?? [], USER_CONFIRMED_MEMORY_TAG])]
|
|
1116
|
-
})) });
|
|
1117
|
-
if (action === "reject") return c.json({ understanding: projectUserContextRecord(preserveRecord(existing, { status: "rejected" })) });
|
|
1118
|
-
if (action === "update") {
|
|
1119
|
-
const content = typeof body.content === "string" ? body.content.trim() : "";
|
|
1120
|
-
if (!content) return c.json({ error: "Updated understanding cannot be empty" }, 400);
|
|
1121
|
-
const replacement = upsertMemoryRecord({
|
|
1122
|
-
providerId: "local",
|
|
1123
|
-
kind: existing.kind,
|
|
1124
|
-
sourceAgentId: existing.provenance.sourceAgentId,
|
|
1125
|
-
workspaceId: existing.scope.workspaceId,
|
|
1126
|
-
sessionKey: existing.scope.sessionKey,
|
|
1127
|
-
projectId: existing.scope.projectId,
|
|
1128
|
-
content,
|
|
1129
|
-
source: { provider: "local" },
|
|
1130
|
-
confidence: 1,
|
|
1131
|
-
tags: [...new Set([
|
|
1132
|
-
...existing.tags ?? [],
|
|
1133
|
-
"user-understanding",
|
|
1134
|
-
"explicit-user-correction",
|
|
1135
|
-
USER_CONFIRMED_MEMORY_TAG
|
|
1136
|
-
])],
|
|
1137
|
-
status: "active",
|
|
1138
|
-
sensitivity: existing.sensitivity,
|
|
1139
|
-
explicitness: "explicit",
|
|
1140
|
-
durability: existing.durability,
|
|
1141
|
-
importance: Math.max(existing.importance, .8),
|
|
1142
|
-
disclosurePolicy: existing.disclosurePolicy,
|
|
1143
|
-
evidence: existing.evidence,
|
|
1144
|
-
reviewAfter: nextMemoryReviewAt({
|
|
1145
|
-
durability: existing.durability,
|
|
1146
|
-
explicitness: "explicit"
|
|
1147
|
-
}),
|
|
1148
|
-
supersedesRecordId: existing.id,
|
|
1149
|
-
conflictGroupId: existing.conflictGroupId
|
|
1150
|
-
});
|
|
1151
|
-
preserveRecord(existing, {
|
|
1152
|
-
status: "archived",
|
|
1153
|
-
validTo: (/* @__PURE__ */ new Date()).toISOString()
|
|
1154
|
-
});
|
|
1155
|
-
return c.json({ understanding: projectUserContextRecord(replacement) });
|
|
1156
|
-
}
|
|
1157
|
-
return c.json({ error: "Action must be confirm, reject, or update" }, 400);
|
|
1158
|
-
});
|
|
1159
|
-
authenticated.delete("/api/you/understanding/:id", deps.strictRateLimitMiddleware, (c) => {
|
|
1160
|
-
const existing = editableRecord(c.req.param("id"));
|
|
1161
|
-
if (!existing) return c.json({ error: "Understanding not found" }, 404);
|
|
1162
|
-
deleteMemoryRecord(existing.id);
|
|
1163
|
-
return c.json({ ok: true });
|
|
278
|
+
].includes(String(decision))) return c.json({ error: "Invalid consent decision" }, 400);
|
|
279
|
+
return decideContextConsent(c.req.param("id"), decision) ? c.json({ ok: true }) : c.json({ error: "Consent request not found" }, 404);
|
|
1164
280
|
});
|
|
1165
281
|
}
|
|
1166
282
|
//#endregion
|
|
1167
|
-
export {
|
|
283
|
+
export { registerYouRoutes };
|