@xopcai/xopc 0.0.227 → 0.0.229
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser-ext/manifest.json +1 -1
- package/dist/extensions/telegram/xopc.extension.json +1 -1
- package/dist/gateway/static/root/assets/{activity-store-BevwE16n.js → activity-store-M0nAY5XB.js} +1 -1
- package/dist/gateway/static/root/assets/{agent-avatar-dicebear-BggVQrEZ.js → agent-avatar-dicebear-CsFAJTIN.js} +1 -1
- package/dist/gateway/static/root/assets/agents-DA4b6_0C.js +68 -0
- package/dist/gateway/static/root/assets/{api-Bx_BpIt8.js → api-BywYxpaS.js} +1 -1
- package/dist/gateway/static/root/assets/{app-management-settings-panel-BtKP9n2r.js → app-management-settings-panel-7KcMWuah.js} +1 -1
- package/dist/gateway/static/root/assets/{appearance-settings-BoH2NAUX.js → appearance-settings-Cqlw7Fif.js} +1 -1
- package/dist/gateway/static/root/assets/apps-page-CsnhdGZ2.js +1 -0
- package/dist/gateway/static/root/assets/{archive-plugin-DnceUyxm.js → archive-plugin-7_DXaMTP.js} +1 -1
- package/dist/gateway/static/root/assets/{attachment-load-Bh8_9gkr.js → attachment-load-q4pDpqkF.js} +1 -1
- package/dist/gateway/static/root/assets/{automations-page-ZKeAAVxD.js → automations-page-BuTqjKGX.js} +1 -1
- package/dist/gateway/static/root/assets/automations-workspace-CD0E2ThS.js +6 -0
- package/dist/gateway/static/root/assets/{binary-plugins-Cy9er6w-.js → binary-plugins-DUce1Bsc.js} +1 -1
- package/dist/gateway/static/root/assets/{block-editor-Cc0wWvNX.js → block-editor-D8Ejp-QR.js} +3 -3
- package/dist/gateway/static/root/assets/browser-settings-page-CY1k3MMd.js +8 -0
- package/dist/gateway/static/root/assets/{browser-workflow-inputs-BS7rpLLl.js → browser-workflow-inputs-8NC2qDRF.js} +1 -1
- package/dist/gateway/static/root/assets/{browser-workflows-page-BdBVUZXm.js → browser-workflows-page-BDvZbR9v.js} +2 -2
- package/dist/gateway/static/root/assets/capabilities-settings-panel-D1VfotHQ.js +7 -0
- package/dist/gateway/static/root/assets/{capability-presets-api-D1Lqz0Tt.js → capability-presets-api-o0y9WgAI.js} +1 -1
- package/dist/gateway/static/root/assets/capability-presets-settings-panel-DXHqRLpU.js +3 -0
- package/dist/gateway/static/root/assets/{channel-recipient-api-CGuEl-l2.js → channel-recipient-api-C5ABr73b.js} +1 -1
- package/dist/gateway/static/root/assets/channels-settings-DrFL57M_.js +1 -0
- package/dist/gateway/static/root/assets/channels-status-swr-38FsOnR0.js +1 -0
- package/dist/gateway/static/root/assets/{chat-terminal-dock-CdX_7aQh.js → chat-terminal-dock-h1CKexNz.js} +2 -2
- package/dist/gateway/static/root/assets/connectors-page-DUAyfFCF.js +2 -0
- package/dist/gateway/static/root/assets/{cron-expression-BnSQc4Ek.js → cron-expression-DlaQQOId.js} +1 -1
- package/dist/gateway/static/root/assets/{date-picker-BbuG7zQ_.js → date-picker-8R1sXJKb.js} +1 -1
- package/dist/gateway/static/root/assets/{dependency-picker-snZeqOmG.js → dependency-picker-CWur0821.js} +1 -1
- package/dist/gateway/static/root/assets/{desktop-pet-DJQ8JoR1.js → desktop-pet-Knl-zNDU.js} +1 -1
- package/dist/gateway/static/root/assets/{desktop-pet-settings-B9txsRtv.js → desktop-pet-settings-CAQMLVtd.js} +1 -1
- package/dist/gateway/static/root/assets/{directory-picker-path-field-D7WKWkNB.js → directory-picker-path-field-Caaz4Rw5.js} +1 -1
- package/dist/gateway/static/root/assets/{extension-debug-page-D_7cOCj2.js → extension-debug-page-B965Mc15.js} +1 -1
- package/dist/gateway/static/root/assets/{extension-page-Bwu47iUb.js → extension-page-C0UnkBi5.js} +1 -1
- package/dist/gateway/static/root/assets/{extension-settings-page-Dwg4dSZM.js → extension-settings-page-BUSIAZCR.js} +1 -1
- package/dist/gateway/static/root/assets/{gateway-config-api-jURUSte_.js → gateway-config-api-DkH0eEgy.js} +1 -1
- package/dist/gateway/static/root/assets/{gateway-config-swr-6SQXF1yR.js → gateway-config-swr-BWGjnmDl.js} +1 -1
- package/dist/gateway/static/root/assets/{gateway-settings-UklJOMLX.js → gateway-settings-BBgLDm6I.js} +1 -1
- package/dist/gateway/static/root/assets/{gateway-startup-retry-DqWaxyvZ.js → gateway-startup-retry-B_zrtccP.js} +1 -1
- package/dist/gateway/static/root/assets/{heartbeat-settings-Djs_nduD.js → heartbeat-settings-BtEHVXWD.js} +1 -1
- package/dist/gateway/static/root/assets/home-page-5SU2TNJj.js +1 -0
- package/dist/gateway/static/root/assets/{image-generation-api-Bxmt6LEr.js → image-generation-api-YKP2me5Z.js} +1 -1
- package/dist/gateway/static/root/assets/index-BNWhgmjs.js +70 -0
- package/dist/gateway/static/root/assets/index-D_hrEKXM.css +2 -0
- package/dist/gateway/static/root/assets/{keyboard-shortcuts-settings-ByVsCH3d.js → keyboard-shortcuts-settings-CsRz8NrS.js} +1 -1
- package/dist/gateway/static/root/assets/local-app-workbench-page-DYPEUgpP.js +2 -0
- package/dist/gateway/static/root/assets/{local-apps-page-D19R-xsz.js → local-apps-page-CTBNUG4a.js} +1 -1
- package/dist/gateway/static/root/assets/{locale-store-Ci1Qi0Q-.js → locale-store-CXhjfe4q.js} +1 -1
- package/dist/gateway/static/root/assets/logs-page-B0P7rG2B.js +2 -0
- package/dist/gateway/static/root/assets/{management-settings-G0y7zmfY.js → management-settings-YqUAEwQo.js} +1 -1
- package/dist/gateway/static/root/assets/{markdown-split-B69d2HWt.js → markdown-split-dxpSCXb8.js} +1 -1
- package/dist/gateway/static/root/assets/{markdown-view-DD_PgVue.css → markdown-view-CLzTdVLW.css} +1 -1
- package/dist/gateway/static/root/assets/markdown-view-DvM5PWEH.js +201 -0
- package/dist/gateway/static/root/assets/{media-plugins-6TWEQgN_.js → media-plugins-CJ00i1Lg.js} +1 -1
- package/dist/gateway/static/root/assets/messages-BMdD0LWk.js +3 -0
- package/dist/gateway/static/root/assets/{notes-api-DLsnnZCS.js → notes-api-BFsOGYkd.js} +1 -1
- package/dist/gateway/static/root/assets/{notes-page-CkRJJKDm.js → notes-page-DEnbnkIt.js} +1 -1
- package/dist/gateway/static/root/assets/notes-workbench-DmVYu_Oc.js +4 -0
- package/dist/gateway/static/root/assets/{product-open-page-HxArIvoN.js → product-open-page-BHxo9U95.js} +1 -1
- package/dist/gateway/static/root/assets/project-detail-page-DV2nGmsq.js +1 -0
- package/dist/gateway/static/root/assets/projects-page-BNIFwFfc.js +1 -0
- package/dist/gateway/static/root/assets/{registry-api-lEar5FOV.js → registry-api-BFZrVYfy.js} +1 -1
- package/dist/gateway/static/root/assets/remote-access-hub-DLXqKiA_.js +1 -0
- package/dist/gateway/static/root/assets/{runtime-tools-settings-panel-Bf03UNGD.js → runtime-tools-settings-panel-BpQ2GI-0.js} +1 -1
- package/dist/gateway/static/root/assets/{schema-form-CIXMBgx5.js → schema-form-HE1G26Lx.js} +1 -1
- package/dist/gateway/static/root/assets/sessions-page-DWaXf_25.js +1 -0
- package/dist/gateway/static/root/assets/settings-advanced-gate-JFCbnCL2.js +1 -0
- package/dist/gateway/static/root/assets/{settings-form-section-DgdB26mE.js → settings-form-section-CXAn0Xhy.js} +1 -1
- package/dist/gateway/static/root/assets/{settings-loading-skeleton-efk5W6lG.js → settings-loading-skeleton-DsFu7Bcv.js} +1 -1
- package/dist/gateway/static/root/assets/{settings-page-BHVf4gEP.js → settings-page-C4iib9nO.js} +1 -1
- package/dist/gateway/static/root/assets/{setup-status-panel-WK0dGNMv.js → setup-status-panel-BA83Wr1d.js} +1 -1
- package/dist/gateway/static/root/assets/{share-preview-page-Cod-w2qm.js → share-preview-page-BOGl3s6M.js} +1 -1
- package/dist/gateway/static/root/assets/{shares-settings-CUqQ31gt.js → shares-settings-Q2MdGaBi.js} +1 -1
- package/dist/gateway/static/root/assets/skill-reload-api-cFtfVeFU.js +1 -0
- package/dist/gateway/static/root/assets/{skills-page-DwCcipqK.js → skills-page-CdaFtNw9.js} +1 -1
- package/dist/gateway/static/root/assets/{skills-page.utils-3WSbtl3S.js → skills-page.utils-DYaAddUL.js} +1 -1
- package/dist/gateway/static/root/assets/{system-settings-panel-C5VxqC_s.js → system-settings-panel-Co7gilRd.js} +1 -1
- package/dist/gateway/static/root/assets/task-detail-page-5B1pswu8.js +1 -0
- package/dist/gateway/static/root/assets/{theme-store-Dd89g_ki.js → theme-store-DOdCjyuw.js} +1 -1
- package/dist/gateway/static/root/assets/{use-autosave-CeV8VJh2.js → use-autosave-DnnZtMpA.js} +1 -1
- package/dist/gateway/static/root/assets/user-context-page-Dr1FKjXv.js +1 -0
- package/dist/gateway/static/root/assets/{voice-api-key-field-EmJ-8aZu.js → voice-api-key-field-wetUpi3i.js} +1 -1
- package/dist/gateway/static/root/assets/{work-discovery-overlay-zsk6E3Mi.js → work-discovery-overlay-tbTWASJJ.js} +1 -1
- package/dist/gateway/static/root/assets/workflow-run-setup-panel-Dy0fDs8w.js +3 -0
- package/dist/gateway/static/root/assets/workflows-page-IVP3GSkI.js +5 -0
- package/dist/gateway/static/root/index.html +12 -12
- package/dist/gateway/static/root/notification-sw.js +1 -1
- package/dist/package.js +1 -1
- package/dist/packages/gateway-contract/src/notifications.js +56 -0
- package/dist/packages/gateway-contract/src/turn-outcome.js +114 -0
- package/dist/src/agent/agent-instance-gateway.d.ts +1 -1
- package/dist/src/agent/agent-manager.d.ts +1 -1
- package/dist/src/agent/agent-manager.js +18 -3
- package/dist/src/agent/background-review/prompts.d.ts +8 -2
- package/dist/src/agent/background-review/prompts.js +25 -12
- package/dist/src/agent/background-review/run-background-review.d.ts +7 -2
- package/dist/src/agent/background-review/run-background-review.js +175 -160
- package/dist/src/agent/lifecycle/timeout-wrapper.d.ts +1 -0
- package/dist/src/agent/lifecycle/timeout-wrapper.js +7 -6
- package/dist/src/agent/mcp/mcp-transport-config.d.ts +1 -1
- package/dist/src/agent/mcp/mcp-transport-config.js +1 -1
- package/dist/src/agent/memory/index.d.ts +1 -1
- package/dist/src/agent/memory/index.js +2 -2
- package/dist/src/agent/memory/manager.d.ts +1 -11
- package/dist/src/agent/memory/manager.js +0 -16
- package/dist/src/agent/memory/understanding/service.d.ts +0 -11
- package/dist/src/agent/memory/understanding/service.js +7 -173
- package/dist/src/agent/memory/user-context-coordinator.d.ts +1 -3
- package/dist/src/agent/memory/user-context-coordinator.js +3 -66
- package/dist/src/agent/orchestration/agent-orchestrator.js +1 -1
- package/dist/src/agent/orchestration/run-agent-turn-with-timeout.d.ts +2 -2
- package/dist/src/agent/orchestration/run-agent-turn-with-timeout.js +4 -4
- package/dist/src/agent/service/direct-turn-helpers.js +1 -1
- package/dist/src/agent/tools/create-share-tool.js +14 -1
- package/dist/src/agent/tools/exec-command.js +3 -3
- package/dist/src/agent/tools/execute-code-tool.js +1 -1
- package/dist/src/agent/tools/executor.js +2 -2
- package/dist/src/agent/tools/image-generate-tool.js +12 -0
- package/dist/src/agent/tools/send-media.js +11 -0
- package/dist/src/agent/tools/xopc-use-tool.js +1 -1
- package/dist/src/cli/command-loaders.js +1 -0
- package/dist/src/cli/command-manifest.js +4 -0
- package/dist/src/cli/commands/doctor/checks/database-schema.js +1 -1
- package/dist/src/cli/commands/history.d.ts +1 -0
- package/dist/src/cli/commands/history.js +50 -0
- package/dist/src/config/agent-profile.js +1 -1
- package/dist/src/config/schema.d.ts +4 -0
- package/dist/src/config/schema.js +1 -0
- package/dist/src/connectors/connected-source-understanding.js +35 -21
- package/dist/src/connectors/learning-coordinator.js +1 -42
- package/dist/src/gateway/agents-admin.js +1 -1
- package/dist/src/gateway/chat-stream/mapper.d.ts +2 -0
- package/dist/src/gateway/chat-stream/mapper.js +5 -0
- package/dist/src/gateway/chat-stream/protocol.d.ts +3 -2
- package/dist/src/gateway/chat-stream/turn-outcome-collector.d.ts +16 -0
- package/dist/src/gateway/chat-stream/turn-outcome-collector.js +111 -0
- package/dist/src/gateway/hono/lib/static-ui.js +7 -5
- package/dist/src/gateway/hono/routes/index.js +2 -0
- package/dist/src/gateway/hono/routes/mobile.js +18 -40
- package/dist/src/gateway/hono/routes/notifications.d.ts +3 -0
- package/dist/src/gateway/hono/routes/notifications.js +45 -0
- package/dist/src/gateway/hono/routes/sessions.js +31 -0
- package/dist/src/gateway/hono/routes/tasks.js +1 -1
- package/dist/src/gateway/hono/routes/understanding-sources.js +4 -1
- package/dist/src/gateway/hono/routes/you.js +29 -11
- package/dist/src/gateway/service/agent-runner.js +6 -2
- package/dist/src/gateway/service/run-gateway-agent.js +58 -2
- package/dist/src/gateway/service/sessions-api.d.ts +6 -0
- package/dist/src/gateway/service/sessions-api.js +60 -3
- package/dist/src/gateway/service.d.ts +2 -2
- package/dist/src/gateway/service.js +8 -7
- package/dist/src/history/ctx/exporter.d.ts +14 -0
- package/dist/src/history/ctx/exporter.js +99 -0
- package/dist/src/history/ctx/format.d.ts +25 -0
- package/dist/src/history/ctx/format.js +282 -0
- package/dist/src/knowledge/index.d.ts +0 -1
- package/dist/src/knowledge/index.js +1 -2
- package/dist/src/media/session-references.d.ts +6 -0
- package/dist/src/media/session-references.js +24 -3
- package/dist/src/notifications/device-store.d.ts +16 -0
- package/dist/src/notifications/device-store.js +96 -0
- package/dist/src/notifications/planner.d.ts +6 -0
- package/dist/src/notifications/planner.js +160 -0
- package/dist/src/notifications/service.d.ts +18 -0
- package/dist/src/notifications/service.js +184 -0
- package/dist/src/notifications/store.d.ts +53 -0
- package/dist/src/notifications/store.js +184 -0
- package/dist/src/notifications/types.d.ts +29 -0
- package/dist/src/notifications/types.js +14 -0
- package/dist/src/session/client-history.d.ts +3 -1
- package/dist/src/session/client-history.js +13 -0
- package/dist/src/session/index.d.ts +1 -1
- package/dist/src/session/manager.d.ts +1 -0
- package/dist/src/session/manager.js +6 -0
- package/dist/src/session/store.d.ts +15 -0
- package/dist/src/session/store.js +58 -0
- package/dist/src/storage/sqlite/index.d.ts +2 -2
- package/dist/src/storage/sqlite/index.js +3 -3
- package/dist/src/storage/sqlite/migrations/136_product_notifications.sql +79 -0
- package/dist/src/storage/sqlite/migrations/137_understanding_status_audit.sql +71 -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/session-input-repository.d.ts +5 -0
- package/dist/src/storage/sqlite/session-input-repository.js +9 -1
- package/dist/src/storage/sqlite/user-context-repository.d.ts +16 -4
- package/dist/src/storage/sqlite/user-context-repository.js +56 -12
- package/dist/src/tasks/index.js +2 -2
- package/dist/src/tasks/task-application-service.js +42 -6
- package/dist/src/tasks/task-change-events.d.ts +9 -0
- package/dist/src/tasks/task-change-events.js +17 -1
- package/dist/src/tasks/task-outbox-dispatcher.js +5 -1
- package/dist/src/tasks/task-run-dispatcher.js +4 -2
- package/dist/src/tasks/task-run-repository.js +13 -0
- package/dist/src/user-context/config.d.ts +8 -0
- package/dist/src/user-context/config.js +3 -0
- package/dist/src/user-context/consolidation.js +16 -4
- package/dist/src/user-context/extraction/executor.d.ts +22 -0
- package/dist/src/user-context/extraction/executor.js +142 -0
- package/dist/src/user-context/extraction/registry.d.ts +1 -1
- package/dist/src/user-context/extraction/registry.js +5 -34
- package/dist/src/user-context/extraction/repair.js +4 -1
- package/dist/src/user-context/extraction/semantic.d.ts +18 -0
- package/dist/src/user-context/extraction/semantic.js +148 -0
- package/dist/src/user-context/understandingQuality.js +4 -0
- package/dist/src/work-discovery/analyzer.js +9 -4
- package/dist/src/work-discovery/service.d.ts +1 -0
- package/dist/src/work-discovery/service.js +5 -4
- package/dist/src/work-discovery/types.d.ts +1 -0
- package/package.json +14 -8
- package/dist/gateway/static/root/assets/agents-TJpjRHnr.js +0 -68
- package/dist/gateway/static/root/assets/apps-page-CZ4Da51l.js +0 -1
- package/dist/gateway/static/root/assets/automations-workspace-2Y00PvJU.js +0 -6
- package/dist/gateway/static/root/assets/browser-settings-page-CbJD27_j.js +0 -8
- package/dist/gateway/static/root/assets/capabilities-settings-panel-Dv8y6OuP.js +0 -7
- package/dist/gateway/static/root/assets/capability-presets-settings-panel-TZmjzWzt.js +0 -3
- package/dist/gateway/static/root/assets/channels-settings-g-68dutA.js +0 -1
- package/dist/gateway/static/root/assets/channels-status-swr-D7KsAeWh.js +0 -1
- package/dist/gateway/static/root/assets/connectors-page-DXA0rAvQ.js +0 -2
- package/dist/gateway/static/root/assets/home-page-i6bXCHdo.js +0 -1
- package/dist/gateway/static/root/assets/index-BBBE89vm.css +0 -2
- package/dist/gateway/static/root/assets/index-BsD5wygl.js +0 -74
- package/dist/gateway/static/root/assets/local-app-workbench-page-BCKEDMlP.js +0 -2
- package/dist/gateway/static/root/assets/logs-page-Cy9YQK7j.js +0 -2
- package/dist/gateway/static/root/assets/markdown-view-CBM-v2ph.js +0 -69
- package/dist/gateway/static/root/assets/mermaid-render-BbqDc_LQ.js +0 -134
- package/dist/gateway/static/root/assets/messages-CtOJwGW3.js +0 -3
- package/dist/gateway/static/root/assets/notes-workbench-B10T3hGX.js +0 -4
- package/dist/gateway/static/root/assets/project-detail-page-DsqRlgsy.js +0 -1
- package/dist/gateway/static/root/assets/projects-page-Bu2PN8OK.js +0 -1
- package/dist/gateway/static/root/assets/remote-access-hub-CXACdJ2f.js +0 -1
- package/dist/gateway/static/root/assets/sessions-page-CS2knWDT.js +0 -1
- package/dist/gateway/static/root/assets/settings-advanced-gate-ByFGk0q_.js +0 -1
- package/dist/gateway/static/root/assets/skill-reload-api-DweAPjI8.js +0 -1
- package/dist/gateway/static/root/assets/task-detail-page-DEj-BFMP.js +0 -1
- package/dist/gateway/static/root/assets/user-context-page-f7yh7aD5.js +0 -1
- package/dist/gateway/static/root/assets/workflow-run-setup-panel-CBAYvm3G.js +0 -3
- package/dist/gateway/static/root/assets/workflows-page-BN0JmHrG.js +0 -5
- package/dist/src/agent/memory/understanding/correction.d.ts +0 -3
- package/dist/src/agent/memory/understanding/correction.js +0 -39
- package/dist/src/knowledge/connected-understanding-pipeline.d.ts +0 -17
- package/dist/src/knowledge/connected-understanding-pipeline.js +0 -278
- package/dist/src/mobile/notification-service.d.ts +0 -9
- package/dist/src/mobile/notification-service.js +0 -156
- package/dist/src/mobile/notification-store.d.ts +0 -28
- package/dist/src/mobile/notification-store.js +0 -132
- package/dist/src/mobile/notification-types.d.ts +0 -37
- package/dist/src/mobile/notification-types.js +0 -9
|
@@ -1,27 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getContextExtractionRun } from "../../../storage/sqlite/context-extraction-repository.js";
|
|
2
2
|
import { closeTemporalAssertions, createTemporalAssertion, linkContextObjects } from "../../../storage/sqlite/context-relation-repository.js";
|
|
3
3
|
import { closeUnderstandingValidity, createContextEvidence, createUnderstanding, getUnderstanding, isUnderstandingSuppressed, linkUnderstandingEvidence, listUnderstandings, setUnderstandingStatus } from "../../../storage/sqlite/user-context-repository.js";
|
|
4
4
|
import "../../../storage/sqlite/index.js";
|
|
5
|
-
import {
|
|
6
|
-
import { claimRegisteredExtraction, extractionInputHash, getRegisteredExtractorDefinition } from "../../../user-context/extraction/registry.js";
|
|
5
|
+
import { getRegisteredExtractorDefinition } from "../../../user-context/extraction/registry.js";
|
|
7
6
|
import { canonicalUnderstandingKey, findContradictoryUnderstanding, findDuplicateUnderstanding } from "../../../user-context/understanding.js";
|
|
8
7
|
import { inferMemorySensitivity, redactSensitiveMemoryText } from "../sensitivity.js";
|
|
9
8
|
//#region src/agent/memory/understanding/service.ts
|
|
10
9
|
const MAX_CANDIDATE_CHARS = 600;
|
|
11
|
-
const EXPLICIT_PATTERNS = [
|
|
12
|
-
/\b(?:please\s+)?remember(?:\s+that)?\s+(.+)/i,
|
|
13
|
-
/\bkeep\s+in\s+mind(?:\s+that)?\s+(.+)/i,
|
|
14
|
-
/(?:请)?记住[::\s]*(.+)/
|
|
15
|
-
];
|
|
16
|
-
const HIGH_SIGNAL_PATTERNS = [
|
|
17
|
-
/(?:从现在起|今后|以后)(?:都)?(?:请)?[::\s]*(.+)/,
|
|
18
|
-
/下次(?:请)?[::\s]*(.+)/,
|
|
19
|
-
/(?:默认|每次|每回)(?:都)?(?:请)?[::\s]*(.+)/,
|
|
20
|
-
/((?:我|本人)(?:一直|通常|一般|更)?(?:喜欢|偏好|习惯|希望|不希望|不喜欢).+)/,
|
|
21
|
-
/\b(?:from now on|going forward|next time|by default|whenever)\b[,:\s]*(.+)/i,
|
|
22
|
-
/(\bi\s+(?:always|usually|generally)\s+(?:prefer|like|want|need|avoid)\b.+)/i,
|
|
23
|
-
/(\bi\s+(?:prefer|like|want|need)\s+.+\s+(?:every time|by default|going forward)\b.*)/i
|
|
24
|
-
];
|
|
25
10
|
const SENSITIVITY_RANK = {
|
|
26
11
|
normal: 0,
|
|
27
12
|
personal: 1,
|
|
@@ -40,50 +25,6 @@ function candidateTime(value) {
|
|
|
40
25
|
const parsed = Date.parse(value);
|
|
41
26
|
return Number.isFinite(parsed) ? parsed : void 0;
|
|
42
27
|
}
|
|
43
|
-
function inferKind(content) {
|
|
44
|
-
if (/\b(don't|do not|never|avoid)\b/i.test(content) || /不要|不用|无需|别再|禁止|底线/.test(content)) return "boundary";
|
|
45
|
-
if (/\b(prefer|preference|like)\b/i.test(content) || /喜欢|偏好|习惯/.test(content)) return "preference";
|
|
46
|
-
if (/\b(project|repo|codebase|workspace)\b/i.test(content) || /项目|仓库|代码库/.test(content)) return "project_context";
|
|
47
|
-
if (/\b(goal|plan|deadline)\b/i.test(content) || /目标|计划|截止/.test(content)) return "long_term_goal";
|
|
48
|
-
if (/\b(next time|lesson|failed|error)\b/i.test(content) || /教训|失败|错误/.test(content)) return "task_lesson";
|
|
49
|
-
if (/习惯|每周|每天|usually|routine/i.test(content)) return "routine";
|
|
50
|
-
return "current_state";
|
|
51
|
-
}
|
|
52
|
-
function extractExplicitUnderstandingCandidates(userContent) {
|
|
53
|
-
const correction = extractExplicitUnderstandingCorrectionContent(userContent);
|
|
54
|
-
const matched = correction ?? userContent.split(/\r?\n/).map((line) => line.trim()).filter(Boolean).flatMap((line) => EXPLICIT_PATTERNS.map((pattern) => pattern.exec(line)?.[1] ?? "")).map(normalizeContent).find((content) => content.length >= 8);
|
|
55
|
-
if (!matched) return [];
|
|
56
|
-
const content = normalizeContent(matched);
|
|
57
|
-
const kind = inferKind(content);
|
|
58
|
-
return [{
|
|
59
|
-
kind,
|
|
60
|
-
content,
|
|
61
|
-
canonicalKey: canonicalUnderstandingKey(kind, content),
|
|
62
|
-
confidence: correction ? .98 : .95,
|
|
63
|
-
importance: kind === "boundary" ? .9 : .8,
|
|
64
|
-
explicitness: "explicit",
|
|
65
|
-
durability: "durable",
|
|
66
|
-
sensitivity: inferMemorySensitivity(content),
|
|
67
|
-
disclosurePolicy: kind === "boundary" ? "silent" : "referenceable"
|
|
68
|
-
}];
|
|
69
|
-
}
|
|
70
|
-
function extractHighSignalUnderstandingCandidates(userContent) {
|
|
71
|
-
if (extractExplicitUnderstandingCorrectionContent(userContent)) return [];
|
|
72
|
-
const matched = userContent.split(/\r?\n/).map((line) => line.trim()).filter(Boolean).flatMap((line) => HIGH_SIGNAL_PATTERNS.map((pattern) => pattern.exec(line)?.[1] ?? "")).map(normalizeContent).find((content) => content.length >= 6);
|
|
73
|
-
if (!matched) return [];
|
|
74
|
-
const kind = inferKind(matched);
|
|
75
|
-
return [{
|
|
76
|
-
kind,
|
|
77
|
-
content: matched,
|
|
78
|
-
canonicalKey: canonicalUnderstandingKey(kind, matched),
|
|
79
|
-
confidence: .85,
|
|
80
|
-
importance: kind === "boundary" ? .9 : .75,
|
|
81
|
-
explicitness: "observed",
|
|
82
|
-
durability: "durable",
|
|
83
|
-
sensitivity: inferMemorySensitivity(matched),
|
|
84
|
-
disclosurePolicy: kind === "boundary" ? "silent" : "referenceable"
|
|
85
|
-
}];
|
|
86
|
-
}
|
|
87
28
|
function scopeForCandidate(candidate, context) {
|
|
88
29
|
if (candidate.durability === "ephemeral" && context.sessionKey) return {
|
|
89
30
|
type: "session",
|
|
@@ -100,116 +41,6 @@ function scopeForCandidate(candidate, context) {
|
|
|
100
41
|
return { type: "global" };
|
|
101
42
|
}
|
|
102
43
|
var UserUnderstandingService = class {
|
|
103
|
-
async reviewTurn(params) {
|
|
104
|
-
params.assistantContent;
|
|
105
|
-
const explicitCandidates = extractExplicitUnderstandingCandidates(params.userContent);
|
|
106
|
-
const candidates = explicitCandidates.length > 0 ? explicitCandidates : extractHighSignalUnderstandingCandidates(params.userContent);
|
|
107
|
-
const turnRef = params.turnId ?? `untracked-${extractionInputHash(params.userContent).slice(0, 16)}`;
|
|
108
|
-
const extraction = claimRegisteredExtraction({
|
|
109
|
-
extractorId: explicitCandidates.length > 0 ? "explicit-command" : "deterministic-signal",
|
|
110
|
-
sourceRef: params.sessionKey ? `session:${params.sessionKey}:turn:${turnRef}` : `turn:${turnRef}`,
|
|
111
|
-
contentForHash: params.userContent,
|
|
112
|
-
processingPolicy: "local_only",
|
|
113
|
-
destination: "deterministic"
|
|
114
|
-
});
|
|
115
|
-
if (!extraction.shouldExecute) {
|
|
116
|
-
const previous = listContextExtractionOutputs(extraction.run.id);
|
|
117
|
-
return {
|
|
118
|
-
proposed: candidates.length,
|
|
119
|
-
created: 0,
|
|
120
|
-
deduplicated: previous.filter((output) => output.outcome !== "rejected").length,
|
|
121
|
-
rejected: previous.filter((output) => output.outcome === "rejected").length,
|
|
122
|
-
createdRecords: []
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
if (candidates.length === 0) {
|
|
126
|
-
finishContextExtractionRun({
|
|
127
|
-
runId: extraction.run.id,
|
|
128
|
-
status: "completed",
|
|
129
|
-
outputs: []
|
|
130
|
-
});
|
|
131
|
-
return {
|
|
132
|
-
proposed: 0,
|
|
133
|
-
created: 0,
|
|
134
|
-
deduplicated: 0,
|
|
135
|
-
rejected: 0,
|
|
136
|
-
createdRecords: []
|
|
137
|
-
};
|
|
138
|
-
}
|
|
139
|
-
const safeCandidates = candidates.filter((candidate) => {
|
|
140
|
-
const content = normalizeContent(candidate.content);
|
|
141
|
-
const sensitivity = effectiveSensitivity(candidate.sensitivity, content);
|
|
142
|
-
return sensitivity !== "secret" && sensitivity !== "regulated";
|
|
143
|
-
});
|
|
144
|
-
if (!safeCandidates.length) {
|
|
145
|
-
finishContextExtractionRun({
|
|
146
|
-
runId: extraction.run.id,
|
|
147
|
-
status: "completed",
|
|
148
|
-
outputs: candidates.map((candidate) => ({
|
|
149
|
-
candidateKey: candidate.canonicalKey ?? canonicalUnderstandingKey(candidate.kind, candidate.content),
|
|
150
|
-
outcome: "rejected"
|
|
151
|
-
}))
|
|
152
|
-
});
|
|
153
|
-
return {
|
|
154
|
-
proposed: candidates.length,
|
|
155
|
-
created: 0,
|
|
156
|
-
deduplicated: 0,
|
|
157
|
-
rejected: candidates.length,
|
|
158
|
-
createdRecords: []
|
|
159
|
-
};
|
|
160
|
-
}
|
|
161
|
-
const evidence = createContextEvidence({
|
|
162
|
-
sourceType: "conversation",
|
|
163
|
-
sourceRef: params.sessionKey ? `session:${params.sessionKey}:turn:${turnRef}` : `turn:${turnRef}`,
|
|
164
|
-
sourceRunId: extraction.run.id,
|
|
165
|
-
...params.sessionKey ? { sessionId: params.sessionKey } : {},
|
|
166
|
-
turnId: turnRef,
|
|
167
|
-
contentHash: extractionInputHash(params.userContent),
|
|
168
|
-
retentionPolicy: "derived_only",
|
|
169
|
-
processingPolicy: "local_only",
|
|
170
|
-
extractorId: extraction.run.extractorId,
|
|
171
|
-
extractorVersion: extraction.run.extractorVersion,
|
|
172
|
-
redactedExcerpt: redactSensitiveMemoryText(safeCandidates.map((candidate) => candidate.content).join("\n")).slice(0, MAX_CANDIDATE_CHARS),
|
|
173
|
-
trustLevel: "owner",
|
|
174
|
-
observedAt: Date.now()
|
|
175
|
-
});
|
|
176
|
-
let result;
|
|
177
|
-
try {
|
|
178
|
-
result = await this.applyCandidates(safeCandidates, {
|
|
179
|
-
sessionKey: params.sessionKey,
|
|
180
|
-
workspaceId: params.workspaceId,
|
|
181
|
-
projectId: params.projectId,
|
|
182
|
-
evidenceIds: [evidence.id],
|
|
183
|
-
reviewSource: "turn",
|
|
184
|
-
supersedesRecordIds: params.correctionTargetRecordIds,
|
|
185
|
-
extractionRunId: extraction.run.id
|
|
186
|
-
});
|
|
187
|
-
} catch (error) {
|
|
188
|
-
finishContextExtractionRun({
|
|
189
|
-
runId: extraction.run.id,
|
|
190
|
-
status: "failed",
|
|
191
|
-
errorCode: "write_failed"
|
|
192
|
-
});
|
|
193
|
-
throw error;
|
|
194
|
-
}
|
|
195
|
-
finishContextExtractionRun({
|
|
196
|
-
runId: extraction.run.id,
|
|
197
|
-
status: "completed",
|
|
198
|
-
outputs: result.writeOutputs?.map((output) => ({
|
|
199
|
-
candidateKey: output.candidateKey,
|
|
200
|
-
objectType: output.objectId ? "understanding" : void 0,
|
|
201
|
-
objectId: output.objectId,
|
|
202
|
-
versionId: output.versionId,
|
|
203
|
-
outcome: output.outcome
|
|
204
|
-
})) ?? []
|
|
205
|
-
});
|
|
206
|
-
return {
|
|
207
|
-
...result,
|
|
208
|
-
proposed: candidates.length,
|
|
209
|
-
rejected: result.rejected + candidates.length - safeCandidates.length,
|
|
210
|
-
sourceItemId: evidence.id
|
|
211
|
-
};
|
|
212
|
-
}
|
|
213
44
|
async applyCandidates(candidates, context) {
|
|
214
45
|
let created = 0;
|
|
215
46
|
let deduplicated = 0;
|
|
@@ -332,7 +163,10 @@ var UserUnderstandingService = class {
|
|
|
332
163
|
objectId: supersededId,
|
|
333
164
|
validTo: closedAt
|
|
334
165
|
});
|
|
335
|
-
setUnderstandingStatus(supersededId, "archived"
|
|
166
|
+
setUnderstandingStatus(supersededId, "archived", {
|
|
167
|
+
actorType: "user",
|
|
168
|
+
source: "semantic-memory-superseded"
|
|
169
|
+
});
|
|
336
170
|
}
|
|
337
171
|
const assertionType = record.kind === "current_state" ? "current_state" : record.kind === "routine" ? "routine" : record.kind === "relationship" ? "relationship" : record.kind === "project_context" ? "project_status" : void 0;
|
|
338
172
|
if (assertionType) createTemporalAssertion({
|
|
@@ -372,4 +206,4 @@ var UserUnderstandingService = class {
|
|
|
372
206
|
}
|
|
373
207
|
};
|
|
374
208
|
//#endregion
|
|
375
|
-
export { UserUnderstandingService
|
|
209
|
+
export { UserUnderstandingService };
|
|
@@ -5,7 +5,6 @@ import type { MemoryManager } from './manager.js';
|
|
|
5
5
|
export interface UserContextCoordinatorOptions {
|
|
6
6
|
getConfig: () => Config | undefined;
|
|
7
7
|
isEnabledForSession: (sessionKey: string) => boolean;
|
|
8
|
-
getAgentIdForSession: (sessionKey: string) => string;
|
|
9
8
|
getWorkspaceIdForSession?: (sessionKey: string) => string;
|
|
10
9
|
getProjectIdForSession?: (sessionKey: string) => string | undefined;
|
|
11
10
|
getMemoryManagerForSession: (sessionKey: string) => MemoryManager;
|
|
@@ -15,11 +14,10 @@ export declare class UserContextCoordinator {
|
|
|
15
14
|
private readonly options;
|
|
16
15
|
private readonly userTurn;
|
|
17
16
|
private readonly lastTurnId;
|
|
18
|
-
private readonly correctionTargets;
|
|
19
17
|
private readonly planner;
|
|
20
18
|
constructor(options: UserContextCoordinatorOptions);
|
|
21
19
|
forgetSession(sessionKey: string): void;
|
|
22
20
|
clear(): void;
|
|
23
21
|
prepare(userMessage: AgentMessage, sessionKey: string, turnId: string): Promise<UserContextPlan>;
|
|
24
|
-
afterTurn(sessionKey: string, userPlainText: string): Promise<
|
|
22
|
+
afterTurn(sessionKey: string, userPlainText: string): Promise<void>;
|
|
25
23
|
}
|
|
@@ -1,19 +1,12 @@
|
|
|
1
|
-
import { createLogger } from "../../utils/logger/index.js";
|
|
2
|
-
import { init_logger } from "../../utils/logger.js";
|
|
3
|
-
import { getTurnPersonalization, recordContextFeedback, setUnderstandingStatus } from "../../storage/sqlite/user-context-repository.js";
|
|
4
|
-
import "../../storage/sqlite/index.js";
|
|
5
1
|
import { init_session_key, parseSessionKey } from "../../routing/session-key.js";
|
|
6
2
|
import { assembleTaskContext } from "../../tasks/task-context-assembler.js";
|
|
7
3
|
import { shouldPlanUserContextThisTurn } from "./memory-config.js";
|
|
8
4
|
import { UserContextPlanner, prependAgentContext } from "../../user-context/planner.js";
|
|
9
|
-
import { isExplicitUnderstandingCorrection } from "./understanding/correction.js";
|
|
10
5
|
import { extractAgentUserPlainText } from "./user-message-text.js";
|
|
11
6
|
import { consumeTurnMemoryProvenance, markTurnRecalledContext } from "./turn-provenance.js";
|
|
12
7
|
import { planTrustedRecall } from "./trusted-recall.js";
|
|
13
8
|
//#region src/agent/memory/user-context-coordinator.ts
|
|
14
9
|
init_session_key();
|
|
15
|
-
init_logger();
|
|
16
|
-
const log = createLogger("UserContextCoordinator");
|
|
17
10
|
function isPrivateSession(sessionKey) {
|
|
18
11
|
const parsed = parseSessionKey(sessionKey);
|
|
19
12
|
return !parsed || parsed.peerKind === "direct";
|
|
@@ -21,7 +14,6 @@ function isPrivateSession(sessionKey) {
|
|
|
21
14
|
var UserContextCoordinator = class {
|
|
22
15
|
userTurn = /* @__PURE__ */ new Map();
|
|
23
16
|
lastTurnId = /* @__PURE__ */ new Map();
|
|
24
|
-
correctionTargets = /* @__PURE__ */ new Map();
|
|
25
17
|
planner = new UserContextPlanner();
|
|
26
18
|
constructor(options) {
|
|
27
19
|
this.options = options;
|
|
@@ -29,12 +21,10 @@ var UserContextCoordinator = class {
|
|
|
29
21
|
forgetSession(sessionKey) {
|
|
30
22
|
this.userTurn.delete(sessionKey);
|
|
31
23
|
this.lastTurnId.delete(sessionKey);
|
|
32
|
-
this.correctionTargets.delete(sessionKey);
|
|
33
24
|
}
|
|
34
25
|
clear() {
|
|
35
26
|
this.userTurn.clear();
|
|
36
27
|
this.lastTurnId.clear();
|
|
37
|
-
this.correctionTargets.clear();
|
|
38
28
|
}
|
|
39
29
|
async prepare(userMessage, sessionKey, turnId) {
|
|
40
30
|
const empty = () => ({
|
|
@@ -50,37 +40,9 @@ var UserContextCoordinator = class {
|
|
|
50
40
|
if (!this.options.isEnabledForSession(sessionKey)) return empty();
|
|
51
41
|
const config = this.options.getConfig();
|
|
52
42
|
if (!isPrivateSession(sessionKey)) return empty();
|
|
53
|
-
const
|
|
54
|
-
const taskContext = assembleTaskContext(sessionKey, userQuery);
|
|
43
|
+
const taskContext = assembleTaskContext(sessionKey, extractAgentUserPlainText(userMessage));
|
|
55
44
|
const query = taskContext.retrievalQuery;
|
|
56
|
-
const previousTurnId = this.lastTurnId.get(sessionKey);
|
|
57
45
|
this.lastTurnId.set(sessionKey, turnId);
|
|
58
|
-
this.correctionTargets.delete(sessionKey);
|
|
59
|
-
let excludedRecordIds;
|
|
60
|
-
if (previousTurnId && isExplicitUnderstandingCorrection(userQuery)) try {
|
|
61
|
-
const personalization = getTurnPersonalization(previousTurnId);
|
|
62
|
-
const selectedIds = personalization?.items.filter((item) => item.objectType === "understanding" && item.decision === "selected").map((item) => item.objectId) ?? [];
|
|
63
|
-
if (personalization && selectedIds.length) {
|
|
64
|
-
for (const recordId of selectedIds) {
|
|
65
|
-
recordContextFeedback({
|
|
66
|
-
turnId: previousTurnId,
|
|
67
|
-
runId: personalization.runId,
|
|
68
|
-
objectType: "understanding",
|
|
69
|
-
objectId: recordId,
|
|
70
|
-
rating: "wrong",
|
|
71
|
-
reason: "detected_explicit_user_correction"
|
|
72
|
-
});
|
|
73
|
-
setUnderstandingStatus(recordId, "needs_review");
|
|
74
|
-
}
|
|
75
|
-
this.correctionTargets.set(sessionKey, selectedIds);
|
|
76
|
-
excludedRecordIds = selectedIds;
|
|
77
|
-
}
|
|
78
|
-
} catch (err) {
|
|
79
|
-
log.debug({
|
|
80
|
-
err,
|
|
81
|
-
sessionKey
|
|
82
|
-
}, "Understanding correction feedback was not persisted");
|
|
83
|
-
}
|
|
84
46
|
const turn = (this.userTurn.get(sessionKey) ?? 0) + 1;
|
|
85
47
|
this.userTurn.set(sessionKey, turn);
|
|
86
48
|
if (!shouldPlanUserContextThisTurn(config, turn)) return empty();
|
|
@@ -92,7 +54,6 @@ var UserContextCoordinator = class {
|
|
|
92
54
|
turnId,
|
|
93
55
|
query,
|
|
94
56
|
userMessage,
|
|
95
|
-
excludedRecordIds,
|
|
96
57
|
allocation: taskContext.allocation
|
|
97
58
|
});
|
|
98
59
|
const totalChars = taskContext.allocation.maxChars;
|
|
@@ -134,36 +95,12 @@ var UserContextCoordinator = class {
|
|
|
134
95
|
};
|
|
135
96
|
}
|
|
136
97
|
async afterTurn(sessionKey, userPlainText) {
|
|
137
|
-
if (!this.options.isEnabledForSession(sessionKey)) return
|
|
98
|
+
if (!this.options.isEnabledForSession(sessionKey)) return;
|
|
138
99
|
const memoryManager = this.options.getMemoryManagerForSession(sessionKey);
|
|
139
100
|
const assistantContent = this.options.getLastAssistantContent(sessionKey) ?? "";
|
|
140
|
-
if (!isPrivateSession(sessionKey)) return
|
|
141
|
-
const correctionTargetRecordIds = this.correctionTargets.get(sessionKey);
|
|
101
|
+
if (!isPrivateSession(sessionKey)) return;
|
|
142
102
|
const turnId = this.lastTurnId.get(sessionKey);
|
|
143
103
|
const provenance = turnId ? consumeTurnMemoryProvenance(sessionKey, turnId) : void 0;
|
|
144
|
-
this.correctionTargets.delete(sessionKey);
|
|
145
|
-
try {
|
|
146
|
-
const review = await memoryManager.captureTurnUnderstanding(userPlainText, assistantContent, {
|
|
147
|
-
agentId: this.options.getAgentIdForSession(sessionKey),
|
|
148
|
-
sessionId: sessionKey,
|
|
149
|
-
turnId,
|
|
150
|
-
workspaceId: this.options.getWorkspaceIdForSession?.(sessionKey),
|
|
151
|
-
projectId: this.options.getProjectIdForSession?.(sessionKey),
|
|
152
|
-
correctionTargetRecordIds
|
|
153
|
-
});
|
|
154
|
-
memoryManager.syncProvidersForTurn(userPlainText, assistantContent, {
|
|
155
|
-
sessionId: sessionKey,
|
|
156
|
-
turnId,
|
|
157
|
-
provenance
|
|
158
|
-
});
|
|
159
|
-
memoryManager.queuePrefetchAll(userPlainText, { sessionId: sessionKey });
|
|
160
|
-
return review;
|
|
161
|
-
} catch (err) {
|
|
162
|
-
log.warn({
|
|
163
|
-
err,
|
|
164
|
-
sessionKey
|
|
165
|
-
}, "Turn understanding capture failed");
|
|
166
|
-
}
|
|
167
104
|
memoryManager.syncProvidersForTurn(userPlainText, assistantContent, {
|
|
168
105
|
sessionId: sessionKey,
|
|
169
106
|
turnId,
|
|
@@ -110,7 +110,7 @@ var AgentOrchestrator = class {
|
|
|
110
110
|
clearPendingTranscriptUserMessage(sessionKey, userMessage);
|
|
111
111
|
}
|
|
112
112
|
})();
|
|
113
|
-
const understandingReview = await this.agentManager.afterAgentTurn(sessionKey, userPlainForMemory);
|
|
113
|
+
const understandingReview = await this.agentManager.afterAgentTurn(sessionKey, userPlainForMemory, turnId);
|
|
114
114
|
if (understandingReview?.createdRecords.length) {
|
|
115
115
|
const captured = understandingReview.createdRecords.filter((record) => record.status === "active");
|
|
116
116
|
const candidates = understandingReview.createdRecords.filter((record) => record.status === "candidate");
|
|
@@ -6,9 +6,9 @@ import type { Agent } from '@earendil-works/pi-agent-core';
|
|
|
6
6
|
import type { Config } from '../../config/schema.js';
|
|
7
7
|
/** Minimum per-turn timeout (1 minute). */
|
|
8
8
|
export declare const MIN_AGENT_TURN_TIMEOUT_MS = 60000;
|
|
9
|
-
/** Maximum per-turn timeout (
|
|
9
|
+
/** Maximum configurable per-turn timeout (24 hours). */
|
|
10
10
|
export declare const MAX_AGENT_TURN_TIMEOUT_MS: number;
|
|
11
|
-
/** Default per-turn timeout (
|
|
11
|
+
/** Default per-turn timeout (4 hours). */
|
|
12
12
|
export declare const DEFAULT_AGENT_TURN_TIMEOUT_MS: number;
|
|
13
13
|
export declare const DEFAULT_AGENT_ABORT_GRACE_MS = 5000;
|
|
14
14
|
export declare class AgentTurnUnsettledError extends Error {
|
|
@@ -2,10 +2,10 @@ import { resolveEffectiveAgentManifestForSession } from "../../config/agent-prof
|
|
|
2
2
|
//#region src/agent/orchestration/run-agent-turn-with-timeout.ts
|
|
3
3
|
/** Minimum per-turn timeout (1 minute). */
|
|
4
4
|
const MIN_AGENT_TURN_TIMEOUT_MS = 6e4;
|
|
5
|
-
/** Maximum per-turn timeout (
|
|
6
|
-
const MAX_AGENT_TURN_TIMEOUT_MS =
|
|
7
|
-
/** Default per-turn timeout (
|
|
8
|
-
const DEFAULT_AGENT_TURN_TIMEOUT_MS =
|
|
5
|
+
/** Maximum configurable per-turn timeout (24 hours). */
|
|
6
|
+
const MAX_AGENT_TURN_TIMEOUT_MS = 1440 * 60 * 1e3;
|
|
7
|
+
/** Default per-turn timeout (4 hours). */
|
|
8
|
+
const DEFAULT_AGENT_TURN_TIMEOUT_MS = 14400 * 1e3;
|
|
9
9
|
const DEFAULT_AGENT_ABORT_GRACE_MS = 5e3;
|
|
10
10
|
var AgentTurnUnsettledError = class extends Error {
|
|
11
11
|
constructor(timeoutMs, abortGraceMs) {
|
|
@@ -116,7 +116,7 @@ async function runDirectAgentTurn(deps, input) {
|
|
|
116
116
|
beforeTurn: () => deps.agentManager.beginBackgroundReviewUserTurn(input.sessionKey),
|
|
117
117
|
onEvent: input.onEvent
|
|
118
118
|
});
|
|
119
|
-
const understandingReview = await deps.agentManager.afterAgentTurn(input.sessionKey, userPlain);
|
|
119
|
+
const understandingReview = await deps.agentManager.afterAgentTurn(input.sessionKey, userPlain, turnId);
|
|
120
120
|
if (understandingReview?.createdRecords.length) {
|
|
121
121
|
const captured = understandingReview.createdRecords.filter((record) => record.status === "active");
|
|
122
122
|
const candidates = understandingReview.createdRecords.filter((record) => record.status === "candidate");
|
|
@@ -226,7 +226,20 @@ function successResult(locale, payload) {
|
|
|
226
226
|
isPublic: payload.reachability === "public"
|
|
227
227
|
}).filter(Boolean).join("\n")
|
|
228
228
|
}],
|
|
229
|
-
details:
|
|
229
|
+
details: {
|
|
230
|
+
...payload,
|
|
231
|
+
artifacts: [{
|
|
232
|
+
artifactId: `share:${String(payload.shareUrl ?? "")}`,
|
|
233
|
+
title: String(payload.title ?? "Shared result"),
|
|
234
|
+
kind: payload.kind === "site" ? "site" : payload.kind === "zip" ? "archive" : "file",
|
|
235
|
+
availability: "available",
|
|
236
|
+
location: "artifact_store",
|
|
237
|
+
capabilities: payload.kind === "site" ? ["preview", "share"] : ["download", "share"],
|
|
238
|
+
shareUrl: String(payload.shareUrl ?? ""),
|
|
239
|
+
...typeof payload.thumbnailUrl === "string" ? { thumbnailUrl: payload.thumbnailUrl } : {},
|
|
240
|
+
...typeof payload.expiresAt === "string" ? { expiresAt: payload.expiresAt } : {}
|
|
241
|
+
}]
|
|
242
|
+
}
|
|
230
243
|
};
|
|
231
244
|
}
|
|
232
245
|
function errorResult(locale, message) {
|
|
@@ -4,14 +4,14 @@ import { resolve } from "node:path";
|
|
|
4
4
|
import { spawn } from "node:child_process";
|
|
5
5
|
import { Type } from "@sinclair/typebox";
|
|
6
6
|
//#region src/agent/tools/exec-command.ts
|
|
7
|
-
const MAX_COMMAND_TIMEOUT_MS =
|
|
8
|
-
const DEFAULT_TIMEOUT_MS =
|
|
7
|
+
const MAX_COMMAND_TIMEOUT_MS = 14400 * 1e3;
|
|
8
|
+
const DEFAULT_TIMEOUT_MS = 1800 * 1e3;
|
|
9
9
|
const DEFAULT_MAX_OUTPUT_CHARS = 5e4;
|
|
10
10
|
const STREAM_DELTA_MAX_CHARS = 16e3;
|
|
11
11
|
const ExecCommandSchema = Type.Object({
|
|
12
12
|
cmd: Type.String({ description: "Shell command to execute." }),
|
|
13
13
|
cwd: Type.Optional(Type.String({ description: "Working directory. Relative paths are resolved under the agent workspace." })),
|
|
14
|
-
timeoutMs: Type.Optional(Type.Number({ description: "Command timeout in milliseconds. Defaults to
|
|
14
|
+
timeoutMs: Type.Optional(Type.Number({ description: "Command timeout in milliseconds. Defaults to 1800000 (30m) and is capped at 14400000 (4h)." })),
|
|
15
15
|
maxOutputChars: Type.Optional(Type.Number({ description: "Maximum characters returned to the model. UI streaming still receives output deltas." }))
|
|
16
16
|
});
|
|
17
17
|
function clampTimeoutMs(raw) {
|
|
@@ -12,7 +12,7 @@ const MAX_TIMEOUT_SEC = 14400;
|
|
|
12
12
|
const ExecuteCodeSchema = Type.Object({
|
|
13
13
|
code: Type.String({ description: "JavaScript to run. Exposed as `tools` (async functions) and `console`:\n await tools.web_search(query, count?)\n await tools.web_fetch(url, maxChars?)\n await tools.read_file(path, limit?)\n await tools.write_file(path, content)\n await tools.grep(pattern, { path?, glob?, ignoreCase?, literal?, context?, limit? })\n await tools.find(pattern, { path?, limit? })\n await tools.exec_command(cmd, cwd?)\n\nUse console.log() for output; combined stdout/stderr is returned." }),
|
|
14
14
|
timeout: Type.Optional(Type.Number({
|
|
15
|
-
description: "Execution timeout in seconds (default:
|
|
15
|
+
description: "Execution timeout in seconds (default: 1800 = 30m, max: 14400 = 4h)",
|
|
16
16
|
default: DEFAULT_TIMEOUT_SEC
|
|
17
17
|
}))
|
|
18
18
|
});
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { createLogger } from "../../utils/logger/index.js";
|
|
2
2
|
import { init_logger } from "../../utils/logger.js";
|
|
3
|
-
import { TimeoutError, executeWithTimeout } from "../lifecycle/timeout-wrapper.js";
|
|
3
|
+
import { DEFAULT_TOOL_EXECUTION_TIMEOUT_MS, TimeoutError, executeWithTimeout } from "../lifecycle/timeout-wrapper.js";
|
|
4
4
|
import { withRetry } from "../../infra/retry.js";
|
|
5
5
|
import { ToolConcurrencyController, resolveToolLockMode } from "./concurrency.js";
|
|
6
6
|
//#region src/agent/tools/executor.ts
|
|
7
7
|
init_logger();
|
|
8
8
|
const log = createLogger("ToolExecutor");
|
|
9
9
|
const DEFAULT_CONFIG = {
|
|
10
|
-
defaultTimeoutMs:
|
|
10
|
+
defaultTimeoutMs: DEFAULT_TOOL_EXECUTION_TIMEOUT_MS,
|
|
11
11
|
maxRetries: 2,
|
|
12
12
|
retryDelayMs: 1e3,
|
|
13
13
|
enableTimeout: true,
|
|
@@ -296,6 +296,18 @@ function createImageGenerateTool(options) {
|
|
|
296
296
|
paths,
|
|
297
297
|
workspaceRelativePaths,
|
|
298
298
|
media,
|
|
299
|
+
artifacts: media.map((item, index) => ({
|
|
300
|
+
artifactId: item.id,
|
|
301
|
+
title: item.name,
|
|
302
|
+
kind: "image",
|
|
303
|
+
mimeType: item.mimeType,
|
|
304
|
+
sizeBytes: item.size,
|
|
305
|
+
availability: "available",
|
|
306
|
+
location: "artifact_store",
|
|
307
|
+
capabilities: ["preview", "download"],
|
|
308
|
+
uri: item.uri,
|
|
309
|
+
workspaceRelativePath: workspaceRelativePaths[index]
|
|
310
|
+
})),
|
|
299
311
|
attempts: result.attempts,
|
|
300
312
|
...result.normalization ? { normalization: result.normalization } : {},
|
|
301
313
|
...result.ignoredOverrides.length > 0 ? { ignoredOverrides: result.ignoredOverrides } : {},
|
|
@@ -64,6 +64,17 @@ function createSendMediaTool(workspace, bus, getContext) {
|
|
|
64
64
|
}],
|
|
65
65
|
details: {
|
|
66
66
|
media: [media],
|
|
67
|
+
artifacts: [{
|
|
68
|
+
artifactId: media.id,
|
|
69
|
+
title: media.name,
|
|
70
|
+
kind: media.type === "photo" ? "image" : media.type === "video" ? "video" : media.type === "audio" ? "audio" : media.mimeType === "application/pdf" ? "pdf" : "file",
|
|
71
|
+
mimeType: media.mimeType,
|
|
72
|
+
sizeBytes: media.size,
|
|
73
|
+
availability: "available",
|
|
74
|
+
location: "artifact_store",
|
|
75
|
+
capabilities: ["preview", "download"],
|
|
76
|
+
uri: media.uri
|
|
77
|
+
}],
|
|
67
78
|
...p.caption ? { caption: p.caption } : {}
|
|
68
79
|
}
|
|
69
80
|
};
|
|
@@ -6,6 +6,7 @@ import { ObjectLinkService } from "../../activity/service.js";
|
|
|
6
6
|
import "../../activity/index.js";
|
|
7
7
|
import { getDefaultAgentId, init_resolve_route } from "../../routing/resolve-route.js";
|
|
8
8
|
import { TaskRepository } from "../../tasks/task-repository.js";
|
|
9
|
+
import { enqueueTaskChangedEvent } from "../../tasks/task-change-events.js";
|
|
9
10
|
import { TaskRunRepository } from "../../tasks/task-run-repository.js";
|
|
10
11
|
import { TaskReadModelProjector } from "../../tasks/task-read-model-projector.js";
|
|
11
12
|
import { TaskCommandSchema, TaskContextInputSchema } from "../../../packages/gateway-contract/src/tasks.js";
|
|
@@ -15,7 +16,6 @@ import "../../automations/index.js";
|
|
|
15
16
|
import { isValidProjectAgentId, normalizeProjectAgentId, resolveProjectAgentId } from "../../projects/project-agent.js";
|
|
16
17
|
import "../../projects/index.js";
|
|
17
18
|
import { TaskContextRepository } from "../../tasks/task-context-repository.js";
|
|
18
|
-
import { enqueueTaskChangedEvent } from "../../tasks/task-change-events.js";
|
|
19
19
|
import { TaskDependencyError, TaskDependencyService } from "../../tasks/task-dependency-service.js";
|
|
20
20
|
import { TaskApplicationService } from "../../tasks/task-application-service.js";
|
|
21
21
|
import { defineTaskContract } from "../../tasks/task-contract-definition.js";
|
|
@@ -11,6 +11,7 @@ const REGISTRY_COMMAND_MODULES = {
|
|
|
11
11
|
tui: () => import("./commands/tui.js"),
|
|
12
12
|
resume: () => import("./commands/resume.js"),
|
|
13
13
|
gateway: () => import("./commands/gateway.js"),
|
|
14
|
+
history: () => import("./commands/history.js"),
|
|
14
15
|
session: () => import("./commands/session.js"),
|
|
15
16
|
project: () => import("./commands/project.js"),
|
|
16
17
|
config: () => import("./commands/config.js"),
|
|
@@ -67,6 +67,10 @@ const ROOT_HELP_COMMANDS = [
|
|
|
67
67
|
name: "gateway [options]",
|
|
68
68
|
description: "Start the xopc gateway server"
|
|
69
69
|
},
|
|
70
|
+
{
|
|
71
|
+
name: "history",
|
|
72
|
+
description: "Export XOPC session history for external tools"
|
|
73
|
+
},
|
|
70
74
|
{
|
|
71
75
|
name: "session",
|
|
72
76
|
description: "Session management commands"
|
|
@@ -52,7 +52,7 @@ async function checkDatabaseSchema(ctx) {
|
|
|
52
52
|
id: "database-schema",
|
|
53
53
|
label: "Database schema",
|
|
54
54
|
status: "pass",
|
|
55
|
-
message: `SQLite schema v${status.dbVersion} (current release
|
|
55
|
+
message: `SQLite schema v${status.dbVersion} (current release v137).`,
|
|
56
56
|
hints: []
|
|
57
57
|
};
|
|
58
58
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { requireXopcDatabase } from "../../storage/sqlite/connection.js";
|
|
2
|
+
import "../../storage/sqlite/index.js";
|
|
3
|
+
import { formatExamples, register } from "../registry.js";
|
|
4
|
+
import { exportCtxHistory } from "../../history/ctx/exporter.js";
|
|
5
|
+
import { Command } from "commander";
|
|
6
|
+
//#region src/cli/commands/history.ts
|
|
7
|
+
async function runCtxExport(options) {
|
|
8
|
+
try {
|
|
9
|
+
const { db } = requireXopcDatabase();
|
|
10
|
+
const result = await exportCtxHistory(db, { outputDir: options.outputDir });
|
|
11
|
+
const importCommand = `ctx import --history-source-manifest ${result.manifestPath}`;
|
|
12
|
+
if (options.json) {
|
|
13
|
+
console.log(JSON.stringify({
|
|
14
|
+
...result,
|
|
15
|
+
importCommand
|
|
16
|
+
}, null, 2));
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
const action = result.changed ? "Exported" : "Already up to date";
|
|
20
|
+
console.log(`${action}: ${result.sessionCount} sessions, ${result.eventCount} events`);
|
|
21
|
+
console.log(`History: ${result.historyPath}`);
|
|
22
|
+
console.log(`Manifest: ${result.manifestPath}`);
|
|
23
|
+
console.log(`\nRegister or refresh it in ctx:\n ${importCommand}`);
|
|
24
|
+
} catch (error) {
|
|
25
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
26
|
+
console.error(`Failed to export history for ctx: ${message}`);
|
|
27
|
+
process.exit(1);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
function createHistoryCommand(_ctx) {
|
|
31
|
+
const command = new Command("history").description("Export XOPC session history for external tools").addHelpText("after", formatExamples([
|
|
32
|
+
"xopc history export ctx",
|
|
33
|
+
"xopc history export ctx --output-dir ./xopc-ctx-history",
|
|
34
|
+
"xopc history export ctx --json"
|
|
35
|
+
]));
|
|
36
|
+
command.command("export").description("Export session history").command("ctx").description("Export a provider-owned ctx-history-jsonl-v2 source").option("--output-dir <path>", "Output directory (default: <xopc-state>/exports/ctx)").option("--json", "Output the result as JSON").action(runCtxExport);
|
|
37
|
+
return command;
|
|
38
|
+
}
|
|
39
|
+
register({
|
|
40
|
+
id: "history",
|
|
41
|
+
name: "history",
|
|
42
|
+
description: "Export XOPC session history for external tools",
|
|
43
|
+
factory: createHistoryCommand,
|
|
44
|
+
metadata: {
|
|
45
|
+
category: "utility",
|
|
46
|
+
examples: ["xopc history export ctx"]
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
//#endregion
|
|
50
|
+
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { init_agent_scope, normalizeAgentId, resolveAgentWorkspaceDir } from "../agent/agent-scope.js";
|
|
1
2
|
import { resolveEffectiveAgentManifest } from "../agent-manifest/resolver.js";
|
|
2
3
|
import "../agent-manifest/index.js";
|
|
3
|
-
import { init_agent_scope, normalizeAgentId, resolveAgentWorkspaceDir } from "../agent/agent-scope.js";
|
|
4
4
|
import { init_session_key, parseSessionKey } from "../routing/session-key.js";
|
|
5
5
|
import { agentExists, getDefaultAgentId, init_resolve_route } from "../routing/resolve-route.js";
|
|
6
6
|
//#region src/config/agent-profile.ts
|
|
@@ -1572,6 +1572,10 @@ export declare const ConfigSchema: z.ZodDefault<z.ZodObject<{
|
|
|
1572
1572
|
}, z.core.$strict>>;
|
|
1573
1573
|
understanding: z.ZodDefault<z.ZodObject<{
|
|
1574
1574
|
enabled: z.ZodDefault<z.ZodBoolean>;
|
|
1575
|
+
processingPolicy: z.ZodDefault<z.ZodEnum<{
|
|
1576
|
+
local_only: "local_only";
|
|
1577
|
+
remote_allowed: "remote_allowed";
|
|
1578
|
+
}>>;
|
|
1575
1579
|
adaptiveCadence: z.ZodDefault<z.ZodBoolean>;
|
|
1576
1580
|
reviewIntervalTurns: z.ZodDefault<z.ZodNumber>;
|
|
1577
1581
|
maxHistoryMessages: z.ZodDefault<z.ZodNumber>;
|
|
@@ -1059,6 +1059,7 @@ workDiscoveryOnboarding: z.boolean().default(true) }).strict().default({ workDis
|
|
|
1059
1059
|
},
|
|
1060
1060
|
understanding: {
|
|
1061
1061
|
enabled: true,
|
|
1062
|
+
processingPolicy: "remote_allowed",
|
|
1062
1063
|
adaptiveCadence: true,
|
|
1063
1064
|
reviewIntervalTurns: 10,
|
|
1064
1065
|
maxHistoryMessages: 80,
|