@xopcai/xopc 0.0.332 → 0.0.334
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/dist/assets/{auth-DocRzRlS.js → auth-Cjj5SuoT.js} +49 -39
- package/dist/browser-ext/dist/background.js +1 -1
- package/dist/browser-ext/dist/sidepanel.html +1 -1
- package/dist/browser-ext/dist/sidepanel.js +240 -36
- package/dist/browser-ext/manifest.json +1 -1
- package/dist/extensions/telegram/xopc.extension.json +1 -1
- package/dist/gateway/static/root/assets/{agent-avatar-dicebear-C2wg3xC_.js → agent-avatar-dicebear-B73q7mlz.js} +1 -1
- package/dist/gateway/static/root/assets/agent-defaults-settings-panel-B9L2YIXz.js +1 -0
- package/dist/gateway/static/root/assets/{agent-plugin-dialog-BeNnu1Ts.js → agent-plugin-dialog-COOjsvea.js} +1 -1
- package/dist/gateway/static/root/assets/agents-CCj1JnLu.js +70 -0
- package/dist/gateway/static/root/assets/agents-admin-api-Cuqi5xZn.js +2 -0
- package/dist/gateway/static/root/assets/{app-link-C6gA5Nck.js → app-link-DRL0YnPs.js} +1 -1
- package/dist/gateway/static/root/assets/{app-management-settings-panel-etFSkfzl.js → app-management-settings-panel-CckioKud.js} +1 -1
- package/dist/gateway/static/root/assets/{appearance-settings-DKmU2VAP.js → appearance-settings-DDiPIr_Q.js} +1 -1
- package/dist/gateway/static/root/assets/apps-page-Azqy8vfo.js +1 -0
- package/dist/gateway/static/root/assets/{archive-plugin-D0z_Fr2G.js → archive-plugin-Dtyr0RhX.js} +1 -1
- package/dist/gateway/static/root/assets/attachment-load-qjPpQzYY.js +1 -0
- package/dist/gateway/static/root/assets/attachment-utils-core-BIOUBrpT.js +1 -0
- package/dist/gateway/static/root/assets/{automations-page-B7_C-p66.js → automations-page-g3SrFkTC.js} +1 -1
- package/dist/gateway/static/root/assets/automations-workspace-B0nW2nZD.js +7 -0
- package/dist/gateway/static/root/assets/binary-plugins-BwKQVxsU.js +2 -0
- package/dist/gateway/static/root/assets/{block-editor-ChWW8Z9L.js → block-editor-DD9d5pCt.js} +29 -29
- package/dist/gateway/static/root/assets/{browser-automation-inputs-C5s1yHOu.js → browser-automation-inputs-D2gNdS3e.js} +1 -1
- package/dist/gateway/static/root/assets/{browser-automations-page-BV00BXRb.js → browser-automations-page-BKqqJR7P.js} +2 -2
- package/dist/gateway/static/root/assets/{browser-settings-page-xwTmuZjS.js → browser-settings-page-BZH9bZbk.js} +2 -2
- package/dist/gateway/static/root/assets/capabilities-CHk4RZl4.js +1 -0
- package/dist/gateway/static/root/assets/capabilities-page-CfWaVH-6.js +2 -0
- package/dist/gateway/static/root/assets/capabilities-settings-panel-C5FcWsSe.js +8 -0
- package/dist/gateway/static/root/assets/capability-header-actions-Bd66yEOa.js +1 -0
- package/dist/gateway/static/root/assets/channels-DIU5Gq4o.js +1 -0
- package/dist/gateway/static/root/assets/{chat-terminal-dock-C41mXCAi.js → chat-terminal-dock-B0nPDJyj.js} +2 -2
- package/dist/gateway/static/root/assets/{computer-settings-page-BJkqok2G.js → computer-settings-page-D7PxxaoG.js} +1 -1
- package/dist/gateway/static/root/assets/{connector-service-page-BKCZMmwm.js → connector-service-page-BZH4SeQg.js} +1 -1
- package/dist/gateway/static/root/assets/connectors-page-BC81R_fz.js +2 -0
- package/dist/gateway/static/root/assets/{turn-outcome-D0SnyZ3Z.js → constants-Co2_smKQ.js} +1 -1
- package/dist/gateway/static/root/assets/date-picker-CDEVYjXI.js +1 -0
- package/dist/gateway/static/root/assets/{dependency-picker-CqADAHZp.js → dependency-picker-AInmpSwC.js} +1 -1
- package/dist/gateway/static/root/assets/{desktop-pet-Bab-iWED.js → desktop-pet-Sjgnlq8M.js} +1 -1
- package/dist/gateway/static/root/assets/{desktop-pet-settings-BqgzLOdi.js → desktop-pet-settings-BWn0rrhr.js} +1 -1
- package/dist/gateway/static/root/assets/{device-pairing-wizard-DFg7FDPf.js → device-pairing-wizard-BtW837_d.js} +1 -1
- package/dist/gateway/static/root/assets/{directory-picker-path-field-hqJ9sFCR.js → directory-picker-path-field-2CpmDx_D.js} +1 -1
- package/dist/gateway/static/root/assets/dist-CKkafhaS.js +1 -0
- package/dist/gateway/static/root/assets/dist-io9jFpN72.js +1 -0
- package/dist/gateway/static/root/assets/{extension-debug-page-DX3PFhRE.js → extension-debug-page-WWJFj9Z5.js} +1 -1
- package/dist/gateway/static/root/assets/{extension-page-DkREdHLs.js → extension-page-DL00dFRr.js} +1 -1
- package/dist/gateway/static/root/assets/{extension-settings-page-wF-HNTM-.js → extension-settings-page-CN-agjPk.js} +1 -1
- package/dist/gateway/static/root/assets/{files-BK6enEvD.js → files-Bw4SBGdM.js} +1 -1
- package/dist/gateway/static/root/assets/{gateway-config-swr-cR-tz7-Q.js → gateway-config-swr-CgIjCxM8.js} +1 -1
- package/dist/gateway/static/root/assets/gateway-realtime-Ciq4c7KT.js +1 -0
- package/dist/gateway/static/root/assets/gateway-realtime-store-BHeHN26R.js +1 -0
- package/dist/gateway/static/root/assets/gateway-settings-4oD6fhAm.js +1 -0
- package/dist/gateway/static/root/assets/{gateway-startup-retry-6jLRcQsu.js → gateway-startup-retry-i-1lTrwY.js} +1 -1
- package/dist/gateway/static/root/assets/home-page-nEpyJUBY.js +1 -0
- package/dist/gateway/static/root/assets/{image-generation-api-CSSkwsyC.js → image-generation-api-gilc-u7M.js} +1 -1
- package/dist/gateway/static/root/assets/{imports-page-B80Cv043.js → imports-page-BivdeiQ5.js} +1 -1
- package/dist/gateway/static/root/assets/index-BioG1pRD.js +106 -0
- package/dist/gateway/static/root/assets/index-DbLEkdNg.css +1 -0
- package/dist/gateway/static/root/assets/{keyboard-shortcuts-settings-BgoFaTwv.js → keyboard-shortcuts-settings-B_8AJTFr.js} +1 -1
- package/dist/gateway/static/root/assets/local-app-workbench-page-CRtZQrmz.js +1 -0
- package/dist/gateway/static/root/assets/{local-apps-page-HO6OQlQT.js → local-apps-page-DclxpoqR.js} +1 -1
- package/dist/gateway/static/root/assets/{local-apps-Bpja8nC6.js → local-apps-yys1VChX.js} +1 -1
- package/dist/gateway/static/root/assets/local-session-drafts-DkolHmyp.js +1 -0
- package/dist/gateway/static/root/assets/{locale-store-wNXWkWu5.js → locale-store-BY30D6tg.js} +1 -1
- package/dist/gateway/static/root/assets/logs-page-DX8TxkRl.js +2 -0
- package/dist/gateway/static/root/assets/management-settings-5WFufZ4g.js +1 -0
- package/dist/gateway/static/root/assets/{markdown-view-DlT9KqwF.js → markdown-view-DYJnwlDr.js} +1 -1
- package/dist/gateway/static/root/assets/media-plugins-DlJDvwLK.js +1 -0
- package/dist/gateway/static/root/assets/messages-_6IXbP2u.js +3 -0
- package/dist/gateway/static/root/assets/note-detail-panel-GF5Q9Fqy.js +5 -0
- package/dist/gateway/static/root/assets/notes-page-E8o4_Ty9.js +8 -0
- package/dist/gateway/static/root/assets/page-context-capture-button-CiCmfRTw.js +1 -0
- package/dist/gateway/static/root/assets/{page-tabs-vqI30Yrg.js → page-tabs-Cwp3fGVM.js} +1 -1
- package/dist/gateway/static/root/assets/popover-select-0p9PIHRy.js +1 -0
- package/dist/gateway/static/root/assets/{preview-open-alternatives-B-mwPBJW.js → preview-open-alternatives-DJ5xqGeu.js} +1 -1
- package/dist/gateway/static/root/assets/{product-delivery-bv3z8Xkh.js → product-delivery-BAks11S4.js} +1 -1
- package/dist/gateway/static/root/assets/{product-open-page-D--sj_uN.js → product-open-page-CcGwNePw.js} +1 -1
- package/dist/gateway/static/root/assets/project-detail-page-6hhRBkmC.js +1 -0
- package/dist/gateway/static/root/assets/projects-page-DUOzRaFI.js +1 -0
- package/dist/gateway/static/root/assets/{registry-api-BIpltJ47.js → registry-api-BvVx0G1o.js} +1 -1
- package/dist/gateway/static/root/assets/remote-access-hub-BWpWUXiE.js +1 -0
- package/dist/gateway/static/root/assets/{runtime-tools-settings-panel-CAnb0PNY.js → runtime-tools-settings-panel-C6eDCNHz.js} +2 -2
- package/dist/gateway/static/root/assets/scenes-page-pF7Lmqnk.js +2 -0
- package/dist/gateway/static/root/assets/{schema-form-BKj6wIMb.js → schema-form-D8W8q_ez.js} +1 -1
- package/dist/gateway/static/root/assets/{schemas-88fK3zzl.js → schemas-CObaziC7.js} +3 -3
- package/dist/gateway/static/root/assets/session-api-BAyUr97V.js +1 -0
- package/dist/gateway/static/root/assets/session-manager-BAy2sR2Q.js +16 -0
- package/dist/gateway/static/root/assets/sessions-page-BDKDqqf9.js +1 -0
- package/dist/gateway/static/root/assets/settings-advanced-gate-C9cJWlAq.js +1 -0
- package/dist/gateway/static/root/assets/{settings-form-section-78ycUHfv.js → settings-form-section-B0cAj0nq.js} +1 -1
- package/dist/gateway/static/root/assets/{settings-page-BOdxIVzo.js → settings-page-DZVVTFxs.js} +1 -1
- package/dist/gateway/static/root/assets/setup-status-panel-DZCPVx9c.js +1 -0
- package/dist/gateway/static/root/assets/share-preview-page-BkPNyV8c.js +2 -0
- package/dist/gateway/static/root/assets/shares-settings-Bqlv5JBi.js +1 -0
- package/dist/gateway/static/root/assets/{skill-api-CiBGQ0Jg.js → skill-api-C0dufzQC.js} +1 -1
- package/dist/gateway/static/root/assets/skill-reload-api-3JF2OTBz.js +1 -0
- package/dist/gateway/static/root/assets/skills-page-DB4lR4om.js +2 -0
- package/dist/gateway/static/root/assets/{system-settings-panel-CyJUeREH.js → system-settings-panel-xjrlhdUz.js} +1 -1
- package/dist/gateway/static/root/assets/task-detail-page-CB6M7wSs.js +1 -0
- package/dist/gateway/static/root/assets/{tasks-CDR_RVbQ.js → tasks-QQJXsiER.js} +1 -1
- package/dist/gateway/static/root/assets/{tunnel-api-Day9zhKi.js → tunnel-api--68MQEWM.js} +1 -1
- package/dist/gateway/static/root/assets/usage-page-OLZ00eqD.js +1 -0
- package/dist/gateway/static/root/assets/{use-autosave-Bj9hC6ML.js → use-autosave-DsnHYpTv.js} +1 -1
- package/dist/gateway/static/root/assets/user-model-page-CoePFpHD.js +2 -0
- package/dist/gateway/static/root/assets/{voice-api-key-field-fWRD6B8r.js → voice-api-key-field-CvIXutQp.js} +1 -1
- package/dist/gateway/static/root/assets/{voice-config-api-ujEySjyc.js → voice-config-api-Bwy3Al3J.js} +1 -1
- package/dist/gateway/static/root/assets/{work-discovery-overlay-CnxdvIk8.js → work-discovery-overlay-By5_7MLR.js} +1 -1
- package/dist/gateway/static/root/assets/{workflow-run-setup-panel-DlWNN1VA.js → workflow-run-setup-panel-HSMDxDXV.js} +2 -2
- package/dist/gateway/static/root/assets/workflows-page-DElQ47Da.js +6 -0
- package/dist/gateway/static/root/index.html +27 -21
- package/dist/package.js +1 -1
- package/dist/packages/gateway-contract/src/automations.js +44 -14
- package/dist/packages/gateway-contract/src/capabilities.js +120 -10
- package/dist/packages/gateway-contract/src/index.js +8 -2
- package/dist/packages/gateway-contract/src/scenes.js +7 -6
- package/dist/packages/gateway-contract/src/session-command-rejection.js +19 -0
- package/dist/packages/gateway-contract/src/session-input-command.js +109 -0
- package/dist/packages/gateway-contract/src/sessions.js +2 -7
- package/dist/packages/gateway-contract/src/usage.js +6 -0
- package/dist/src/agent/agent-manager.js +15 -9
- package/dist/src/agent/background-review/run-background-review.js +8 -3
- package/dist/src/agent/bootstrap/filter-bootstrap-files.js +1 -1
- package/dist/src/agent/embedded/model-runtime.js +1 -1
- package/dist/src/agent/embedded/run-for-session.js +1 -1
- package/dist/src/agent/embedded/run-turn.js +7 -1
- package/dist/src/agent/external-tools/endpoint-provider.js +2 -2
- package/dist/src/agent/external-tools/gateway-tools.d.ts +2 -1
- package/dist/src/agent/external-tools/gateway-tools.js +45 -11
- package/dist/src/agent/external-tools/index.js +1 -1
- package/dist/src/agent/image/tool-model-config.js +2 -2
- package/dist/src/agent/image/understanding/pi-ai-provider.js +1 -1
- package/dist/src/agent/memory/compaction.js +4 -0
- package/dist/src/agent/service/btw-query.js +8 -2
- package/dist/src/agent/service/process-direct-streaming.js +4 -2
- package/dist/src/agent/service.js +5 -5
- package/dist/src/agent/session/session-inspector.js +1 -1
- package/dist/src/agent/skills/filesystem-watcher.js +1 -1
- package/dist/src/agent/skills/hub-pull.js +2 -2
- package/dist/src/agent/skills/marketplace/adapters/store/adapter.js +1 -1
- package/dist/src/agent/skills/marketplace/adapters/store/store-api-client.js +1 -1
- package/dist/src/agent/tasks/task-judge-service.js +7 -3
- package/dist/src/agent/tool-manuals/xopc-use.d.ts +1 -1
- package/dist/src/agent/tool-manuals/xopc-use.js +5 -4
- package/dist/src/agent/tools/automation-tool.d.ts +4 -1
- package/dist/src/agent/tools/automation-tool.js +42 -4
- package/dist/src/agent/tools/session-search-tool.js +1 -1
- package/dist/src/agent/tools/web-extract.js +1 -1
- package/dist/src/agent/tools/xopc-use-tool.js +50 -9
- package/dist/src/agent-catalog/capabilities.js +2 -2
- package/dist/src/ai-assist/text-assist.js +6 -2
- package/dist/src/auth/credentials.js +1 -1
- package/dist/src/auth/oauth-provider-lock.js +1 -1
- package/dist/src/auth/sync-provider-auth.js +1 -1
- package/dist/src/automations/api/routes.js +65 -0
- package/dist/src/automations/capabilities/drafts.js +1 -1
- package/dist/src/automations/capabilities/read.js +24 -0
- package/dist/src/automations/capabilities/write.d.ts +52 -14
- package/dist/src/automations/capabilities/write.js +52 -3
- package/dist/src/automations/delivery/delivery-router.d.ts +50 -0
- package/dist/src/automations/delivery/delivery-router.js +318 -0
- package/dist/src/automations/delivery/index.d.ts +1 -0
- package/dist/src/automations/delivery/index.js +2 -0
- package/dist/src/automations/domain/defaults.d.ts +0 -1
- package/dist/src/automations/domain/defaults.js +1 -1
- package/dist/src/automations/domain/index.js +2 -2
- package/dist/src/automations/domain/types.d.ts +158 -7
- package/dist/src/automations/domain/validation.d.ts +104 -22
- package/dist/src/automations/domain/validation.js +66 -13
- package/dist/src/automations/draft/automation-draft-prompt.js +3 -4
- package/dist/src/automations/draft/automation-draft-service.js +6 -0
- package/dist/src/automations/draft/automation-draft-validator.d.ts +22 -3
- package/dist/src/automations/draft/automation-draft-validator.js +4 -4
- package/dist/src/automations/events/event-catalog.d.ts +14 -0
- package/dist/src/automations/events/event-catalog.js +117 -0
- package/dist/src/automations/events/event-dispatcher.d.ts +27 -0
- package/dist/src/automations/events/event-dispatcher.js +140 -0
- package/dist/src/automations/events/event-repository.d.ts +59 -0
- package/dist/src/automations/events/event-repository.js +361 -0
- package/dist/src/automations/events/index.d.ts +3 -0
- package/dist/src/automations/events/index.js +4 -0
- package/dist/src/automations/index.d.ts +3 -1
- package/dist/src/automations/index.js +9 -3
- package/dist/src/automations/service/action-executor.d.ts +20 -1
- package/dist/src/automations/service/action-executor.js +80 -40
- package/dist/src/automations/service/automation-service.d.ts +21 -4
- package/dist/src/automations/service/automation-service.js +150 -100
- package/dist/src/automations/storage/automation-repository.js +4 -5
- package/dist/src/automations/storage/automation-run-repository.d.ts +1 -0
- package/dist/src/automations/storage/automation-run-repository.js +26 -1
- package/dist/src/automations/storage/index.js +2 -2
- package/dist/src/automations/webhook-secrets.d.ts +1 -0
- package/dist/src/automations/webhook-secrets.js +16 -0
- package/dist/src/bootstrap/application-state.js +1 -1
- package/dist/src/capabilities/runtime/dispatcher.js +1 -1
- package/dist/src/capabilities/runtime/product.js +1 -1
- package/dist/src/capabilities/store-connector.d.ts +17 -1
- package/dist/src/capabilities/store-connector.js +69 -3
- package/dist/src/channels/attachments/voice-stt-webchat.js +1 -1
- package/dist/src/chat-commands/agent-edit.js +1 -1
- package/dist/src/chat-commands/builtins/config.js +1 -1
- package/dist/src/cli/commands/agent.js +1 -1
- package/dist/src/cli/commands/agents.js +1 -1
- package/dist/src/cli/commands/connectors.js +4 -3
- package/dist/src/cli/commands/doctor/checks/automation-integrity.d.ts +2 -0
- package/dist/src/cli/commands/doctor/checks/automation-integrity.js +55 -0
- package/dist/src/cli/commands/doctor/checks/database-relations.d.ts +2 -0
- package/dist/src/cli/commands/doctor/checks/database-relations.js +81 -0
- package/dist/src/cli/commands/doctor/checks/database-schema.js +1 -1
- package/dist/src/cli/commands/doctor/checks/provider-auth.js +2 -2
- package/dist/src/cli/commands/doctor/flow.js +5 -1
- package/dist/src/cli/commands/extension-marketplace.js +1 -1
- package/dist/src/cli/commands/models.js +1 -1
- package/dist/src/cli/commands/onboard/model.js +2 -2
- package/dist/src/cli/commands/skills.js +1 -1
- package/dist/src/cli/utils/init-workspace-core.js +1 -1
- package/dist/src/computer/runtime.js +1 -1
- package/dist/src/config/index.js +5 -5
- package/dist/src/config/loader.js +2 -2
- package/dist/src/config/models-json.js +1 -1
- package/dist/src/config/schema.js +1 -1
- package/dist/src/connectors/approval-resume.js +1 -1
- package/dist/src/connectors/cli/authorization.d.ts +1 -1
- package/dist/src/connectors/cli/store.d.ts +1 -1
- package/dist/src/connectors/cli/store.js +1 -1
- package/dist/src/connectors/composio-backends.js +14 -4
- package/dist/src/connectors/composio-managed-events.d.ts +5 -2
- package/dist/src/connectors/composio-managed-events.js +4 -1
- package/dist/src/connectors/connection-candidates.js +53 -15
- package/dist/src/connectors/connection-capabilities.js +5 -1
- package/dist/src/connectors/connection-recovery-service.d.ts +2 -1
- package/dist/src/connectors/connection-recovery-service.js +89 -4
- package/dist/src/discussions/analyzer.js +4 -4
- package/dist/src/execution-environments/local-worktree-manager.js +10 -1
- package/dist/src/execution-environments/session-environment-service.d.ts +3 -0
- package/dist/src/execution-environments/session-environment-service.js +28 -4
- package/dist/src/extensions/agent-plugins/validation.js +1 -1
- package/dist/src/extensions/update.js +1 -1
- package/dist/src/gateway/agent-builtin-tools.d.ts +1 -1
- package/dist/src/gateway/agents-admin.js +2 -2
- package/dist/src/gateway/file-path-classifier.js +1 -1
- package/dist/src/gateway/home-intelligence-automation-reconciler.js +4 -1
- package/dist/src/gateway/hono/lib/config-payload.js +1 -1
- package/dist/src/gateway/hono/routes/agent-stream.js +6 -2
- package/dist/src/gateway/hono/routes/browser-session.js +4 -2
- package/dist/src/gateway/hono/routes/capabilities.js +1 -1
- package/dist/src/gateway/hono/routes/commands-skills.js +9 -2
- package/dist/src/gateway/hono/routes/config-patch/misc.js +2 -2
- package/dist/src/gateway/hono/routes/connection-waits.js +3 -2
- package/dist/src/gateway/hono/routes/files.js +3 -0
- package/dist/src/gateway/hono/routes/lazy-bundles.js +14 -1
- package/dist/src/gateway/hono/routes/models.js +17 -1
- package/dist/src/gateway/hono/routes/notes.js +2 -4
- package/dist/src/gateway/hono/routes/projects.js +2 -2
- package/dist/src/gateway/hono/routes/public-gateway.js +93 -3
- package/dist/src/gateway/hono/routes/scenes.js +57 -41
- package/dist/src/gateway/hono/routes/session-command-handler.d.ts +5 -0
- package/dist/src/gateway/hono/routes/session-command-handler.js +189 -0
- package/dist/src/gateway/hono/routes/session-input-handler.d.ts +14 -2
- package/dist/src/gateway/hono/routes/session-input-handler.js +2 -2
- package/dist/src/gateway/hono/routes/sessions.js +15 -168
- package/dist/src/gateway/hono/routes/tasks.js +1 -1
- package/dist/src/gateway/hono/routes/tui.js +2 -1
- package/dist/src/gateway/hono/routes/usage.d.ts +3 -0
- package/dist/src/gateway/hono/routes/usage.js +61 -0
- package/dist/src/gateway/hono/routes/voice.js +10 -1
- package/dist/src/gateway/image-generation-setup.js +2 -2
- package/dist/src/gateway/lock.js +1 -1
- package/dist/src/gateway/memory-maintenance-automation-reconciler.js +5 -2
- package/dist/src/gateway/resolve-webchat-session-key.d.ts +1 -1
- package/dist/src/gateway/resolve-webchat-session-key.js +2 -2
- package/dist/src/gateway/scenes/host.js +27 -14
- package/dist/src/gateway/scenes/slackThreadSource.d.ts +2 -2
- package/dist/src/gateway/security/gateway-scopes.js +1 -0
- package/dist/src/gateway/service/active-execution.d.ts +19 -0
- package/dist/src/gateway/service/active-execution.js +16 -0
- package/dist/src/gateway/service/agent-runner.d.ts +4 -0
- package/dist/src/gateway/service/agent-runner.js +19 -1
- package/dist/src/gateway/service/marketplace-service.js +2 -2
- package/dist/src/gateway/service/run-gateway-agent.d.ts +2 -0
- package/dist/src/gateway/service/run-gateway-agent.js +10 -2
- package/dist/src/gateway/service/session-command-service.d.ts +34 -0
- package/dist/src/gateway/service/session-command-service.js +81 -0
- package/dist/src/gateway/service/session-input-coordinator.d.ts +21 -0
- package/dist/src/gateway/service/session-input-coordinator.js +41 -0
- package/dist/src/gateway/service/session-preparation-worker.d.ts +15 -0
- package/dist/src/gateway/service/session-preparation-worker.js +125 -0
- package/dist/src/gateway/service/sessions-api.d.ts +13 -0
- package/dist/src/gateway/service/sessions-api.js +23 -0
- package/dist/src/gateway/service.d.ts +30 -3
- package/dist/src/gateway/service.js +89 -79
- package/dist/src/gateway/side-chat/promotion-service.js +0 -1
- package/dist/src/gateway/side-chat/run-service.js +10 -7
- package/dist/src/gateway/xopc-cloud-capability-setup.js +1 -1
- package/dist/src/home-intelligence/generator.js +5 -2
- package/dist/src/infra/domain-outbox-dispatcher.d.ts +0 -3
- package/dist/src/infra/domain-outbox-dispatcher.js +15 -7
- package/dist/src/local-apps/service.js +2 -2
- package/dist/src/mcp/channel-bridge.js +12 -2
- package/dist/src/notes/capabilities/read.js +2 -2
- package/dist/src/notes/service.d.ts +4 -1
- package/dist/src/notes/service.js +13 -11
- package/dist/src/projects/project-service.js +1 -2
- package/dist/src/projects/project-skill-service.js +2 -2
- package/dist/src/providers/auth-runtime/resolve-auth.js +1 -1
- package/dist/src/providers/index.js +2 -2
- package/dist/src/providers/model-call.d.ts +3 -2
- package/dist/src/providers/model-call.js +30 -5
- package/dist/src/providers/model-catalog-persistence.js +1 -1
- package/dist/src/providers/register-runtime-providers.js +1 -1
- package/dist/src/scenes/activationAdapter.d.ts +19 -0
- package/dist/src/scenes/activationAdapter.js +1 -0
- package/dist/src/scenes/agentExecutor.js +3 -10
- package/dist/src/scenes/contracts.d.ts +3 -9
- package/dist/src/scenes/contracts.js +1 -0
- package/dist/src/scenes/execution.d.ts +9 -3
- package/dist/src/scenes/execution.js +12 -11
- package/dist/src/scenes/httpServices.d.ts +5 -2
- package/dist/src/scenes/mailContext.d.ts +4 -0
- package/dist/src/scenes/mailContext.js +9 -0
- package/dist/src/scenes/maintenance.js +1 -5
- package/dist/src/scenes/metrics.d.ts +0 -6
- package/dist/src/scenes/metrics.js +0 -11
- package/dist/src/scenes/registry.d.ts +11 -0
- package/dist/src/scenes/registry.js +28 -0
- package/dist/src/scenes/repository.d.ts +6 -3
- package/dist/src/scenes/repository.js +43 -5
- package/dist/src/scenes/service.d.ts +2 -1
- package/dist/src/scenes/service.js +9 -7
- package/dist/src/scenes/taskFollowUp/contracts.d.ts +37 -7
- package/dist/src/scenes/taskFollowUp/contracts.js +36 -17
- package/dist/src/scenes/taskFollowUp/service.d.ts +35 -7
- package/dist/src/scenes/taskFollowUp/service.js +86 -28
- package/dist/src/scenes/templates.d.ts +2 -2
- package/dist/src/scenes/userNotes.d.ts +3 -0
- package/dist/src/scenes/userNotes.js +6 -0
- package/dist/src/session/client-history.d.ts +3 -0
- package/dist/src/session/client-history.js +10 -5
- package/dist/src/session/manager.d.ts +1 -0
- package/dist/src/session/resolve-session.js +4 -3
- package/dist/src/session/session-title.js +1 -1
- package/dist/src/session/store.d.ts +1 -0
- package/dist/src/session/store.js +3 -3
- package/dist/src/storage/sqlite/ai-usage-repository.d.ts +137 -0
- package/dist/src/storage/sqlite/ai-usage-repository.js +175 -0
- package/dist/src/storage/sqlite/connector-account-repository.js +7 -5
- package/dist/src/storage/sqlite/connector-repository.js +36 -34
- 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/209_automation_event_hub.sql +48 -0
- package/dist/src/storage/sqlite/migrations/210_remove_legacy_automation_timeout.sql +14 -0
- package/dist/src/storage/sqlite/migrations/211_automation_result_deliveries.sql +16 -0
- package/dist/src/storage/sqlite/migrations/212_automation_delivery_policy.sql +30 -0
- package/dist/src/storage/sqlite/migrations/213_automation_reliability_contract.sql +188 -0
- package/dist/src/storage/sqlite/migrations/214_ai_usage_ledger.sql +41 -0
- package/dist/src/storage/sqlite/migrations/215_scene_execution_adapters.sql +6 -0
- package/dist/src/storage/sqlite/migrations/216_remove_scene_model_usage.sql +1 -0
- package/dist/src/storage/sqlite/migrations/217_remove_legacy_memory_tables.sql +4 -0
- package/dist/src/storage/sqlite/migrations/218_core_relation_indexes.sql +26 -0
- package/dist/src/storage/sqlite/migrations/219_json_contracts.sql +123 -0
- package/dist/src/storage/sqlite/migrations/220_normalize_timestamps.sql +339 -0
- package/dist/src/storage/sqlite/migrations/221_ai_usage_retention_index.sql +2 -0
- package/dist/src/storage/sqlite/migrations/222_session_config_authority.sql +13 -0
- package/dist/src/storage/sqlite/migrations/223_session_creation_receipts.sql +59 -0
- package/dist/src/storage/sqlite/migrations/runner.d.ts +1 -1
- package/dist/src/storage/sqlite/migrations/runner.js +4 -4
- package/dist/src/storage/sqlite/row-mappers.d.ts +3 -7
- package/dist/src/storage/sqlite/row-mappers.js +6 -6
- package/dist/src/storage/sqlite/scenes-schema.d.ts +1 -1
- package/dist/src/storage/sqlite/scenes-schema.js +0 -1
- package/dist/src/storage/sqlite/schema.js +1 -1
- package/dist/src/storage/sqlite/schema.sql +0 -52
- package/dist/src/storage/sqlite/schemas/scenes.sql +0 -7
- package/dist/src/storage/sqlite/session-creation-repository.d.ts +50 -0
- package/dist/src/storage/sqlite/session-creation-repository.js +166 -0
- package/dist/src/storage/sqlite/session-input-repository.d.ts +12 -2
- package/dist/src/storage/sqlite/session-input-repository.js +25 -2
- package/dist/src/storage/sqlite/session-read-repository.d.ts +1 -1
- package/dist/src/storage/sqlite/session-read-repository.js +0 -1
- package/dist/src/storage/sqlite/session-repository.d.ts +0 -4
- package/dist/src/storage/sqlite/session-repository.js +8 -18
- package/dist/src/storage/sqlite/timestamps.d.ts +4 -0
- package/dist/src/storage/sqlite/timestamps.js +20 -0
- package/dist/src/storage/sqlite/transcript-repository.d.ts +1 -0
- package/dist/src/storage/sqlite/transcript-repository.js +23 -15
- package/dist/src/storage/sqlite/user-trust-repository.js +4 -2
- package/dist/src/tasks/capabilities/read.js +2 -2
- package/dist/src/tasks/capabilities/write.d.ts +1 -1
- package/dist/src/tasks/home-query-service.js +3 -3
- package/dist/src/tasks/task-contract-planner.js +1 -1
- package/dist/src/tui/backends/embedded-backend.d.ts +5 -0
- package/dist/src/tui/backends/embedded-backend.js +266 -20
- package/dist/src/tui/backends/embedded-drafts.d.ts +22 -0
- package/dist/src/tui/backends/embedded-drafts.js +53 -0
- package/dist/src/tui/backends/gateway-realtime-backend.d.ts +10 -0
- package/dist/src/tui/backends/gateway-realtime-backend.js +214 -33
- package/dist/src/tui/tui-backend.d.ts +1 -1
- package/dist/src/tui/tui-chat-input-state.d.ts +1 -0
- package/dist/src/tui/tui-commands.js +1 -1
- package/dist/src/tui/tui-session-format.js +0 -1
- package/dist/src/tui/tui-startup-resources.d.ts +1 -0
- package/dist/src/tui/tui-startup-resources.js +2 -2
- package/dist/src/tui/tui-types.d.ts +0 -1
- package/dist/src/tui/tui.js +69 -29
- package/dist/src/usage/cost.d.ts +4 -0
- package/dist/src/usage/cost.js +28 -0
- package/dist/src/usage/recorder.d.ts +13 -0
- package/dist/src/usage/recorder.js +117 -0
- package/dist/src/usage/scenario-registry.d.ts +8 -0
- package/dist/src/usage/scenario-registry.js +117 -0
- package/dist/src/usage/types.d.ts +55 -0
- package/dist/src/usage/types.js +1 -0
- package/dist/src/voice/realtime/persona-context.js +1 -1
- package/dist/src/voice/tts/summarize.js +1 -1
- package/dist/src/work-discovery/analyzer.js +2 -2
- package/dist/src/work-discovery/investigator.js +1 -1
- package/dist/src/work-discovery/service.js +3 -6
- package/dist/src/workflows/service/workflow-run-service.js +16 -3
- package/package.json +3 -3
- package/dist/gateway/static/root/assets/agent-defaults-settings-panel-Se1Z72VG.js +0 -1
- package/dist/gateway/static/root/assets/agents-udIitwV8.js +0 -70
- package/dist/gateway/static/root/assets/apps-page-DVNySL58.js +0 -1
- package/dist/gateway/static/root/assets/attachment-load-DNCDbeOX.js +0 -1
- package/dist/gateway/static/root/assets/automations-workspace-BMgJvdcv.js +0 -7
- package/dist/gateway/static/root/assets/binary-plugins-BYn2hScX.js +0 -2
- package/dist/gateway/static/root/assets/capabilities-CHA-sTAZ.js +0 -1
- package/dist/gateway/static/root/assets/capabilities-page-v0WkhV5o.js +0 -2
- package/dist/gateway/static/root/assets/capabilities-settings-panel-DefBGjhV.js +0 -8
- package/dist/gateway/static/root/assets/capability-header-actions-vmx35sbu.js +0 -1
- package/dist/gateway/static/root/assets/channels-Eo4ONF5X.js +0 -1
- package/dist/gateway/static/root/assets/connectors-page-DZYgogQw.js +0 -2
- package/dist/gateway/static/root/assets/conversation-identity-Cw0n9uzK.js +0 -1
- package/dist/gateway/static/root/assets/date-picker-CrOV4Ynd.js +0 -1
- package/dist/gateway/static/root/assets/dist-3h6cXXhT.js +0 -1
- package/dist/gateway/static/root/assets/dist-Che_jiQF.js +0 -1
- package/dist/gateway/static/root/assets/gateway-settings-Du-Dos9O.js +0 -1
- package/dist/gateway/static/root/assets/home-page-D7YoMHq4.js +0 -1
- package/dist/gateway/static/root/assets/index-BEw0xrde.css +0 -1
- package/dist/gateway/static/root/assets/index-DalslRUx.js +0 -121
- package/dist/gateway/static/root/assets/local-app-workbench-page-BKL5UZAj.js +0 -1
- package/dist/gateway/static/root/assets/logs-page-CjzR9Rpj.js +0 -2
- package/dist/gateway/static/root/assets/management-settings-Dk_gTJb9.js +0 -1
- package/dist/gateway/static/root/assets/media-plugins-Dlj6TD3M.js +0 -1
- package/dist/gateway/static/root/assets/messages-fmf0dnr4.js +0 -3
- package/dist/gateway/static/root/assets/note-detail-panel-BebJPjjk.js +0 -5
- package/dist/gateway/static/root/assets/notes-page-CmS_hvz8.js +0 -8
- package/dist/gateway/static/root/assets/page-context-capture-button-BArPtqp5.js +0 -1
- package/dist/gateway/static/root/assets/popover-select-DcsFzD_i.js +0 -1
- package/dist/gateway/static/root/assets/project-detail-page-BFUdtWXF.js +0 -1
- package/dist/gateway/static/root/assets/projects-page-DBsBwAQ6.js +0 -1
- package/dist/gateway/static/root/assets/remote-access-hub-BurdDY0m.js +0 -1
- package/dist/gateway/static/root/assets/scenes-page-Cj8xtr5t.js +0 -2
- package/dist/gateway/static/root/assets/sessions-page-BCsjgkCs.js +0 -1
- package/dist/gateway/static/root/assets/settings-advanced-gate-BLL7csOJ.js +0 -1
- package/dist/gateway/static/root/assets/setup-status-panel-CbKHBjrU.js +0 -1
- package/dist/gateway/static/root/assets/share-preview-page-DyLfktib.js +0 -2
- package/dist/gateway/static/root/assets/shares-settings-BzvSNouj.js +0 -1
- package/dist/gateway/static/root/assets/skill-reload-api-BHnru0F5.js +0 -1
- package/dist/gateway/static/root/assets/skills-page-C35VKjhb.js +0 -2
- package/dist/gateway/static/root/assets/task-detail-page-Bd1_Fguk.js +0 -1
- package/dist/gateway/static/root/assets/user-model-page-DuYzuR1T.js +0 -2
- package/dist/gateway/static/root/assets/workflows-page-B45YDiEw.js +0 -6
- package/dist/src/automations/product-events.d.ts +0 -5
- package/dist/src/automations/product-events.js +0 -19
- package/dist/src/tui/tui-empty-session-cleanup.d.ts +0 -9
- package/dist/src/tui/tui-empty-session-cleanup.js +0 -19
- /package/dist/gateway/static/root/assets/{dist-CI_fqRk-.js → dist-CI_fqRk-2.js} +0 -0
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { type SessionCreation, type SessionInputCommand, type SessionMaterializeCommand, type SessionPreparationState } from '@xopcai/gateway-contract';
|
|
2
|
+
import type { SessionAgentConfig } from '../../session/config-types.js';
|
|
3
|
+
import { insertSessionInput } from './session-input-repository.js';
|
|
4
|
+
export declare class SessionCommandError extends Error {
|
|
5
|
+
readonly code: 'IDEMPOTENCY_CONFLICT' | 'CONVERSATION_EXISTS' | 'SESSION_DELETED' | 'FORBIDDEN' | 'SESSION_CHANGED' | 'CONFIG_CHANGED' | 'NOT_FOUND' | 'BAD_REQUEST' | 'SESSION_BUSY' | 'QUEUE_FULL';
|
|
6
|
+
constructor(code: 'IDEMPOTENCY_CONFLICT' | 'CONVERSATION_EXISTS' | 'SESSION_DELETED' | 'FORBIDDEN' | 'SESSION_CHANGED' | 'CONFIG_CHANGED' | 'NOT_FOUND' | 'BAD_REQUEST' | 'SESSION_BUSY' | 'QUEUE_FULL', message: string);
|
|
7
|
+
}
|
|
8
|
+
export type SessionInputReceipt = {
|
|
9
|
+
conversationId: string;
|
|
10
|
+
clientMessageId: string;
|
|
11
|
+
principalId: string;
|
|
12
|
+
requestHash: string;
|
|
13
|
+
inputId: string | null;
|
|
14
|
+
transcriptId: string;
|
|
15
|
+
acceptedAt: number;
|
|
16
|
+
};
|
|
17
|
+
export type SessionPreparation = {
|
|
18
|
+
conversationId: string;
|
|
19
|
+
operationId: string;
|
|
20
|
+
creation: SessionCreation;
|
|
21
|
+
state: SessionPreparationState;
|
|
22
|
+
environmentId: string;
|
|
23
|
+
baseCommit: string | null;
|
|
24
|
+
revision: number;
|
|
25
|
+
leaseUntil: number;
|
|
26
|
+
lastError: string | null;
|
|
27
|
+
};
|
|
28
|
+
export declare function sessionCommandHash(command: SessionInputCommand | SessionMaterializeCommand): string;
|
|
29
|
+
export declare function isConversationDeleted(conversationId: string): boolean;
|
|
30
|
+
export declare function getSessionInputReceipt(conversationId: string, clientMessageId: string, principalId: string): SessionInputReceipt | undefined;
|
|
31
|
+
export declare function matchSessionInputReceipt(conversationId: string, clientMessageId: string, principalId: string, hash: string): SessionInputReceipt | undefined;
|
|
32
|
+
export declare function getSessionPreparation(conversationId: string): SessionPreparation | undefined;
|
|
33
|
+
/** Commit the identity, configuration, input and replay receipt together. All preparation happens before entry. */
|
|
34
|
+
export declare function acceptSessionCommand(input: {
|
|
35
|
+
conversationId: string;
|
|
36
|
+
principalId: string;
|
|
37
|
+
command: SessionInputCommand | SessionMaterializeCommand;
|
|
38
|
+
preparedInput?: Omit<Parameters<typeof insertSessionInput>[0], 'conversationId' | 'id' | 'clientMessageId' | 'expectedTranscriptId'>;
|
|
39
|
+
config?: SessionAgentConfig;
|
|
40
|
+
sourceChannel?: 'webchat' | 'tui';
|
|
41
|
+
attachProject?: (conversationId: string, projectId: string) => void;
|
|
42
|
+
}): SessionInputReceipt;
|
|
43
|
+
export declare function claimSessionPreparation(conversationId: string, now?: number): SessionPreparation | undefined;
|
|
44
|
+
export declare function finishSessionPreparation(operation: SessionPreparation, error?: string): boolean;
|
|
45
|
+
export declare function pendingSessionPreparations(): string[];
|
|
46
|
+
export declare function retrySessionPreparation(conversationId: string, principalId: string, input: {
|
|
47
|
+
operationId: string;
|
|
48
|
+
expectedRevision: number;
|
|
49
|
+
idempotencyKey: string;
|
|
50
|
+
}): SessionPreparation;
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import { getSqliteDatabase, init_transaction, runSqliteWriteTransaction } from "./transaction.js";
|
|
2
|
+
import { sessionCommandIdentity } from "../../../packages/gateway-contract/src/session-input-command.js";
|
|
3
|
+
import { init_src } from "../../../packages/gateway-contract/src/index.js";
|
|
4
|
+
import { init_session_input_repository, insertSessionInput } from "./session-input-repository.js";
|
|
5
|
+
import { init_clarification_wait_repository, supersedeActiveClarification } from "./clarification-wait-repository.js";
|
|
6
|
+
import { init_connection_wait_repository, invalidateConnectionResumeIntent } from "./connection-wait-repository.js";
|
|
7
|
+
import { getSessionMetadata } from "./session-read-repository.js";
|
|
8
|
+
import { init_session_repository } from "./session-repository.js";
|
|
9
|
+
import { init_config_repository, setSessionConfig } from "./config-repository.js";
|
|
10
|
+
import { createConversation, init_conversation_repository } from "./conversation-repository.js";
|
|
11
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
12
|
+
//#region src/storage/sqlite/session-creation-repository.ts
|
|
13
|
+
init_src();
|
|
14
|
+
init_conversation_repository();
|
|
15
|
+
init_config_repository();
|
|
16
|
+
init_session_repository();
|
|
17
|
+
init_session_input_repository();
|
|
18
|
+
init_connection_wait_repository();
|
|
19
|
+
init_clarification_wait_repository();
|
|
20
|
+
init_transaction();
|
|
21
|
+
var SessionCommandError = class extends Error {
|
|
22
|
+
constructor(code, message) {
|
|
23
|
+
super(message);
|
|
24
|
+
this.code = code;
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
function sessionCommandHash(command) {
|
|
28
|
+
return createHash("sha256").update(sessionCommandIdentity(command)).digest("hex");
|
|
29
|
+
}
|
|
30
|
+
function isConversationDeleted(conversationId) {
|
|
31
|
+
return Boolean(getSqliteDatabase().prepare("SELECT 1 FROM session_tombstones WHERE conversation_id=?").get(conversationId));
|
|
32
|
+
}
|
|
33
|
+
function getSessionInputReceipt(conversationId, clientMessageId, principalId) {
|
|
34
|
+
const row = getSqliteDatabase().prepare(`SELECT conversation_id AS conversationId, client_message_id AS clientMessageId,
|
|
35
|
+
principal_id AS principalId, request_hash AS requestHash, input_id AS inputId,
|
|
36
|
+
transcript_id AS transcriptId, accepted_at AS acceptedAt FROM session_input_receipts
|
|
37
|
+
WHERE conversation_id=? AND client_message_id=?`).get(conversationId, clientMessageId);
|
|
38
|
+
if (row && row.principalId !== principalId) throw new SessionCommandError("FORBIDDEN", "Input belongs to another principal");
|
|
39
|
+
return row;
|
|
40
|
+
}
|
|
41
|
+
function matchSessionInputReceipt(conversationId, clientMessageId, principalId, hash) {
|
|
42
|
+
const receipt = getSessionInputReceipt(conversationId, clientMessageId, principalId);
|
|
43
|
+
if (receipt && receipt.requestHash !== hash) throw new SessionCommandError("IDEMPOTENCY_CONFLICT", "Input identity was reused with different content");
|
|
44
|
+
if (isConversationDeleted(conversationId)) throw new SessionCommandError("SESSION_DELETED", "Conversation was deleted");
|
|
45
|
+
return receipt;
|
|
46
|
+
}
|
|
47
|
+
function getSessionPreparation(conversationId) {
|
|
48
|
+
const row = getSqliteDatabase().prepare(`SELECT conversation_id AS conversationId, operation_id AS operationId,
|
|
49
|
+
creation_json AS creationJson, state, environment_id AS environmentId, base_commit AS baseCommit,
|
|
50
|
+
revision, lease_until AS leaseUntil, last_error AS lastError FROM session_preparations WHERE conversation_id=?`).get(conversationId);
|
|
51
|
+
if (!row) return void 0;
|
|
52
|
+
const { creationJson, ...rest } = row;
|
|
53
|
+
return {
|
|
54
|
+
...rest,
|
|
55
|
+
creation: JSON.parse(creationJson)
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
/** Commit the identity, configuration, input and replay receipt together. All preparation happens before entry. */
|
|
59
|
+
function acceptSessionCommand(input) {
|
|
60
|
+
return runSqliteWriteTransaction((db) => {
|
|
61
|
+
const { conversationId, command, principalId } = input;
|
|
62
|
+
const clientMessageId = "commandId" in command ? command.commandId : command.clientMessageId;
|
|
63
|
+
const requestHash = sessionCommandHash(command);
|
|
64
|
+
const existing = matchSessionInputReceipt(conversationId, clientMessageId, principalId, requestHash);
|
|
65
|
+
if (existing) return existing;
|
|
66
|
+
if ("input" in command !== Boolean(input.preparedInput)) throw new SessionCommandError("BAD_REQUEST", "Prepared input is required for input commands only");
|
|
67
|
+
const pending = db.prepare(`SELECT count(*) AS count FROM session_inputs WHERE conversation_id=?
|
|
68
|
+
AND status IN ('queued','running','injecting','interrupted')`).get(conversationId);
|
|
69
|
+
if (input.preparedInput && pending.count >= 10) throw new SessionCommandError("QUEUE_FULL", "Input queue is full");
|
|
70
|
+
const creation = "creation" in command ? command.creation : void 0;
|
|
71
|
+
let session = getSessionMetadata(conversationId);
|
|
72
|
+
if (creation) {
|
|
73
|
+
if (session) throw new SessionCommandError("CONVERSATION_EXISTS", "Conversation already exists");
|
|
74
|
+
session = createConversation({
|
|
75
|
+
agentId: creation.agentId,
|
|
76
|
+
sourceChannel: input.sourceChannel ?? "webchat",
|
|
77
|
+
sourceChatId: conversationId,
|
|
78
|
+
sessionType: "chat",
|
|
79
|
+
hiddenFromSessionList: !input.preparedInput,
|
|
80
|
+
routing: {
|
|
81
|
+
agentId: creation.agentId,
|
|
82
|
+
source: input.sourceChannel ?? "webchat",
|
|
83
|
+
accountId: "default",
|
|
84
|
+
peerKind: "direct",
|
|
85
|
+
peerId: conversationId
|
|
86
|
+
}
|
|
87
|
+
}, "", conversationId);
|
|
88
|
+
setSessionConfig(conversationId, input.config ?? {
|
|
89
|
+
modelOverride: creation.model,
|
|
90
|
+
fixedModel: true,
|
|
91
|
+
thinkingLevel: creation.thinkingLevel,
|
|
92
|
+
userContextMode: creation.temporary ? "temporary" : "enabled"
|
|
93
|
+
}, "");
|
|
94
|
+
if (creation.projectId) {
|
|
95
|
+
if (!input.attachProject) throw new Error("Project attachment is required");
|
|
96
|
+
input.attachProject(conversationId, creation.projectId);
|
|
97
|
+
}
|
|
98
|
+
if (creation.execution) db.prepare(`INSERT INTO session_preparations
|
|
99
|
+
(conversation_id,operation_id,creation_json,state,environment_id,created_at,updated_at)
|
|
100
|
+
VALUES (?,?,?,'preparing',?,?,?)`).run(conversationId, randomUUID(), JSON.stringify(creation), randomUUID(), Date.now(), Date.now());
|
|
101
|
+
} else {
|
|
102
|
+
if (!session) throw new SessionCommandError("NOT_FOUND", "Conversation not found");
|
|
103
|
+
if (!("kind" in command) || command.kind !== "append" || command.expectedTranscriptId !== session.transcriptId) throw new SessionCommandError("SESSION_CHANGED", "Conversation transcript changed");
|
|
104
|
+
if ((db.prepare("SELECT updated_at FROM session_config WHERE conversation_id=?").get(conversationId)?.updated_at ?? 0) !== command.configVersion) throw new SessionCommandError("CONFIG_CHANGED", "Model configuration changed");
|
|
105
|
+
}
|
|
106
|
+
const transcriptId = session.transcriptId;
|
|
107
|
+
const inputId = input.preparedInput ? randomUUID() : null;
|
|
108
|
+
if (input.preparedInput && inputId) insertSessionInput({
|
|
109
|
+
...input.preparedInput,
|
|
110
|
+
conversationId,
|
|
111
|
+
id: inputId,
|
|
112
|
+
clientMessageId,
|
|
113
|
+
expectedTranscriptId: transcriptId
|
|
114
|
+
});
|
|
115
|
+
if (inputId) {
|
|
116
|
+
invalidateConnectionResumeIntent(conversationId);
|
|
117
|
+
supersedeActiveClarification(conversationId);
|
|
118
|
+
}
|
|
119
|
+
const receipt = {
|
|
120
|
+
conversationId,
|
|
121
|
+
clientMessageId,
|
|
122
|
+
principalId,
|
|
123
|
+
requestHash,
|
|
124
|
+
inputId,
|
|
125
|
+
transcriptId,
|
|
126
|
+
acceptedAt: Date.now()
|
|
127
|
+
};
|
|
128
|
+
db.prepare(`INSERT INTO session_input_receipts
|
|
129
|
+
(conversation_id,client_message_id,principal_id,request_hash,input_id,transcript_id,accepted_at)
|
|
130
|
+
VALUES (?,?,?,?,?,?,?)`).run(conversationId, clientMessageId, principalId, requestHash, inputId, transcriptId, receipt.acceptedAt);
|
|
131
|
+
return receipt;
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
function claimSessionPreparation(conversationId, now = Date.now()) {
|
|
135
|
+
return runSqliteWriteTransaction((db) => {
|
|
136
|
+
return db.prepare(`UPDATE session_preparations SET lease_until=?,revision=revision+1,updated_at=?
|
|
137
|
+
WHERE conversation_id=? AND state='preparing' AND lease_until<=?`).run(now + 6e4, now, conversationId, now).changes ? getSessionPreparation(conversationId) : void 0;
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
function finishSessionPreparation(operation, error) {
|
|
141
|
+
return runSqliteWriteTransaction((db) => Boolean(db.prepare(`UPDATE session_preparations
|
|
142
|
+
SET state=?,last_error=?,lease_until=0,revision=revision+1,updated_at=?
|
|
143
|
+
WHERE conversation_id=? AND operation_id=? AND revision=? AND state='preparing'`).run(error ? "preparation_failed" : "ready", error ?? null, Date.now(), operation.conversationId, operation.operationId, operation.revision).changes));
|
|
144
|
+
}
|
|
145
|
+
function pendingSessionPreparations() {
|
|
146
|
+
return getSqliteDatabase().prepare("SELECT conversation_id FROM session_preparations WHERE state='preparing' AND lease_until<=?").all(Date.now()).map((row) => row.conversation_id);
|
|
147
|
+
}
|
|
148
|
+
function retrySessionPreparation(conversationId, principalId, input) {
|
|
149
|
+
return runSqliteWriteTransaction((db) => {
|
|
150
|
+
if (isConversationDeleted(conversationId)) throw new SessionCommandError("SESSION_DELETED", "Conversation was deleted");
|
|
151
|
+
const operation = getSessionPreparation(conversationId);
|
|
152
|
+
if (!operation) throw new SessionCommandError("NOT_FOUND", "Preparation not found");
|
|
153
|
+
if (db.prepare("SELECT principal_id FROM session_input_receipts WHERE conversation_id=? ORDER BY accepted_at LIMIT 1").get(conversationId)?.principal_id !== principalId) throw new SessionCommandError("FORBIDDEN", "Preparation belongs to another principal");
|
|
154
|
+
const previous = db.prepare("SELECT * FROM session_preparation_retries WHERE conversation_id=? AND idempotency_key=?").get(conversationId, input.idempotencyKey);
|
|
155
|
+
if (previous) {
|
|
156
|
+
if (previous.operation_id !== input.operationId || previous.expected_revision !== input.expectedRevision || previous.principal_id !== principalId) throw new SessionCommandError("IDEMPOTENCY_CONFLICT", "Retry identity was reused");
|
|
157
|
+
return operation;
|
|
158
|
+
}
|
|
159
|
+
if (!db.prepare(`UPDATE session_preparations SET state='preparing', revision=revision+1,
|
|
160
|
+
lease_until=0,last_error=NULL,updated_at=? WHERE conversation_id=? AND operation_id=? AND revision=? AND state='preparation_failed'`).run(Date.now(), conversationId, input.operationId, input.expectedRevision).changes) throw new SessionCommandError("SESSION_CHANGED", "Preparation state changed");
|
|
161
|
+
db.prepare("INSERT INTO session_preparation_retries VALUES (?,?,?,?,?)").run(conversationId, input.idempotencyKey, input.operationId, input.expectedRevision, principalId);
|
|
162
|
+
return getSessionPreparation(conversationId);
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
//#endregion
|
|
166
|
+
export { SessionCommandError, acceptSessionCommand, claimSessionPreparation, finishSessionPreparation, getSessionInputReceipt, getSessionPreparation, isConversationDeleted, matchSessionInputReceipt, pendingSessionPreparations, retrySessionPreparation, sessionCommandHash };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { getSqliteDatabase } from './transaction.js';
|
|
2
2
|
import { type TurnOrigin } from '@xopcai/endpoint-tools-protocol';
|
|
3
|
+
import type { SessionPreparationView } from '@xopcai/gateway-contract';
|
|
3
4
|
import type { AgentSourceContext, SourceContextRefSummary } from '../../agent/source-context/types.js';
|
|
4
5
|
export type SessionInputDelivery = 'next' | 'steer';
|
|
5
6
|
export type SessionInputStatus = 'queued' | 'running' | 'injecting' | 'completed' | 'cancelled' | 'failed' | 'interrupted' | 'suspended';
|
|
@@ -38,6 +39,7 @@ export type SessionInput = {
|
|
|
38
39
|
updatedAtMs: number;
|
|
39
40
|
};
|
|
40
41
|
export type SessionInputState = {
|
|
42
|
+
preparation?: SessionPreparationView;
|
|
41
43
|
conversationId: string;
|
|
42
44
|
revision: number;
|
|
43
45
|
activeRunId?: string;
|
|
@@ -51,6 +53,14 @@ export declare function listActiveSessionInputRuns(): Array<{
|
|
|
51
53
|
conversationId: string;
|
|
52
54
|
runId: string;
|
|
53
55
|
}>;
|
|
56
|
+
/** Durable active runs with the claimed input metadata needed by runtime policy surfaces. */
|
|
57
|
+
export declare function listActiveSessionInputExecutions(): Array<{
|
|
58
|
+
conversationId: string;
|
|
59
|
+
runId: string;
|
|
60
|
+
origin: TurnOrigin;
|
|
61
|
+
taskRunId?: string;
|
|
62
|
+
startedAt: number;
|
|
63
|
+
}>;
|
|
54
64
|
export declare function findSessionInput(conversationId: string, clientMessageId: string): SessionInput | undefined;
|
|
55
65
|
export declare function getSessionInputById(conversationId: string, id: string): SessionInput | undefined;
|
|
56
66
|
export declare class SessionInstanceChangedError extends Error {
|
|
@@ -75,8 +85,8 @@ export declare function insertSessionInput(input: {
|
|
|
75
85
|
origin: TurnOrigin;
|
|
76
86
|
targetRunId?: string;
|
|
77
87
|
}): SessionInput;
|
|
78
|
-
export declare function claimNextSessionInput(conversationId: string, runId: string): SessionInput | undefined;
|
|
79
|
-
export declare function finishSessionInputRun(conversationId: string, runId: string, status: 'completed' | 'failed' | 'cancelled' | 'suspended', error?: string): boolean;
|
|
88
|
+
export declare function claimNextSessionInput(conversationId: string, runId: string, expectedInputId?: string): SessionInput | undefined;
|
|
89
|
+
export declare function finishSessionInputRun(conversationId: string, runId: string, status: 'completed' | 'failed' | 'cancelled' | 'suspended' | 'interrupted', error?: string): boolean;
|
|
80
90
|
export declare function setSessionInputStatus(id: string, status: SessionInputStatus, patch?: {
|
|
81
91
|
effectiveDelivery?: SessionInputDelivery;
|
|
82
92
|
targetRunId?: string | null;
|
|
@@ -42,12 +42,14 @@ function bumpSessionInputRevision(db, conversationId) {
|
|
|
42
42
|
}
|
|
43
43
|
function getSessionInputState(conversationId) {
|
|
44
44
|
const db = getSqliteDatabase();
|
|
45
|
+
const preparation = db.prepare("SELECT operation_id AS operationId, revision, state, last_error AS lastError FROM session_preparations WHERE conversation_id=?").get(conversationId);
|
|
45
46
|
const runtime = db.prepare(`SELECT revision, active_run_id, active_input_id
|
|
46
47
|
FROM session_input_runtime WHERE conversation_id = ?`).get(conversationId);
|
|
47
48
|
const rows = db.prepare(`${SELECT_INPUTS} WHERE conversation_id = ? AND status IN
|
|
48
49
|
('queued','running','injecting','interrupted') ORDER BY position, created_at_ms, id`).all(conversationId);
|
|
49
50
|
return {
|
|
50
51
|
conversationId,
|
|
52
|
+
...preparation ? { preparation } : {},
|
|
51
53
|
revision: runtime?.revision ?? 0,
|
|
52
54
|
activeRunId: runtime?.active_run_id ?? void 0,
|
|
53
55
|
activeInputId: runtime?.active_input_id ?? void 0,
|
|
@@ -65,6 +67,23 @@ function listActiveSessionInputRuns() {
|
|
|
65
67
|
runId: row.active_run_id
|
|
66
68
|
}));
|
|
67
69
|
}
|
|
70
|
+
/** Durable active runs with the claimed input metadata needed by runtime policy surfaces. */
|
|
71
|
+
function listActiveSessionInputExecutions() {
|
|
72
|
+
return getSqliteDatabase().prepare(`SELECT runtime.conversation_id, runtime.active_run_id,
|
|
73
|
+
input.origin_json, input.task_run_id, input.updated_at_ms
|
|
74
|
+
FROM session_input_runtime runtime
|
|
75
|
+
LEFT JOIN session_inputs input ON input.id = runtime.active_input_id
|
|
76
|
+
WHERE runtime.active_run_id IS NOT NULL`).all().map((row) => ({
|
|
77
|
+
conversationId: row.conversation_id,
|
|
78
|
+
runId: row.active_run_id,
|
|
79
|
+
origin: row.origin_json ? turnOriginSchema.parse(JSON.parse(row.origin_json)) : {
|
|
80
|
+
type: "system",
|
|
81
|
+
source: "internal"
|
|
82
|
+
},
|
|
83
|
+
...row.task_run_id ? { taskRunId: row.task_run_id } : {},
|
|
84
|
+
startedAt: row.updated_at_ms ?? Date.now()
|
|
85
|
+
}));
|
|
86
|
+
}
|
|
68
87
|
function findSessionInput(conversationId, clientMessageId) {
|
|
69
88
|
const row = getSqliteDatabase().prepare(`${SELECT_INPUTS} WHERE conversation_id = ? AND client_message_id = ?`).get(conversationId, clientMessageId);
|
|
70
89
|
return row ? mapInput(row) : void 0;
|
|
@@ -90,8 +109,11 @@ function insertSessionInput(input) {
|
|
|
90
109
|
return mapInput(db.prepare(`${SELECT_INPUTS} WHERE id = ?`).get(input.id));
|
|
91
110
|
});
|
|
92
111
|
}
|
|
93
|
-
function claimNextSessionInput(conversationId, runId) {
|
|
112
|
+
function claimNextSessionInput(conversationId, runId, expectedInputId) {
|
|
94
113
|
return runSqliteWriteTransaction((db) => {
|
|
114
|
+
const preparation = db.prepare("SELECT state FROM session_preparations WHERE conversation_id=?").get(conversationId);
|
|
115
|
+
if (preparation && preparation.state !== "ready") return void 0;
|
|
116
|
+
if (db.prepare("SELECT 1 FROM session_tombstones WHERE conversation_id=?").get(conversationId)) return void 0;
|
|
95
117
|
ensureRuntime(db, conversationId);
|
|
96
118
|
if (db.prepare(`SELECT active_run_id FROM session_input_runtime WHERE conversation_id = ?`).get(conversationId).active_run_id) return void 0;
|
|
97
119
|
if (db.prepare(`UPDATE session_inputs SET status = 'interrupted', error = 'Session changed before delivery',
|
|
@@ -100,6 +122,7 @@ function claimNextSessionInput(conversationId, runId) {
|
|
|
100
122
|
const row = db.prepare(`${SELECT_INPUTS} WHERE conversation_id = ? AND effective_delivery = 'next'
|
|
101
123
|
AND status = 'queued' ORDER BY position, created_at_ms, id LIMIT 1`).get(conversationId);
|
|
102
124
|
if (!row) return void 0;
|
|
125
|
+
if (expectedInputId && row.id !== expectedInputId) return void 0;
|
|
103
126
|
const now = Date.now();
|
|
104
127
|
db.prepare(`UPDATE session_inputs SET status = 'running', run_id = ?, version = version + 1,
|
|
105
128
|
updated_at_ms = ? WHERE id = ?`).run(runId, now, row.id);
|
|
@@ -188,4 +211,4 @@ var init_session_input_repository = __esmMin((() => {
|
|
|
188
211
|
}));
|
|
189
212
|
//#endregion
|
|
190
213
|
init_session_input_repository();
|
|
191
|
-
export { SessionInstanceChangedError, bumpSessionInputRevision, cancelQueuedSessionInput, claimNextSessionInput, findSessionInput, finishSessionInputRun, getSessionInputById, getSessionInputState, init_session_input_repository, insertSessionInput, listActiveSessionInputRuns, mutateQueuedSessionInput, recoverSessionInputState, setSessionInputStatus };
|
|
214
|
+
export { SessionInstanceChangedError, bumpSessionInputRevision, cancelQueuedSessionInput, claimNextSessionInput, findSessionInput, finishSessionInputRun, getSessionInputById, getSessionInputState, init_session_input_repository, insertSessionInput, listActiveSessionInputExecutions, listActiveSessionInputRuns, mutateQueuedSessionInput, recoverSessionInputState, setSessionInputStatus };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { DatabaseSync } from 'node:sqlite';
|
|
2
2
|
import type { SessionMetadata } from '../../session/types.js';
|
|
3
3
|
import { type SessionRow } from './row-mappers.js';
|
|
4
|
-
export declare const SESSION_COLUMNS = "\n s.conversation_id, s.agent_id, s.active_transcript_id, s.status, s.name, s.tags_json,\n s.created_at, s.updated_at, s.last_accessed_at, s.session_started_at, s.last_interaction_at,\n s.source_channel, s.source_chat_id, s.session_type, s.hidden_from_session_list,\n s.parent_conversation_id, s.workflow_run_id, s.workflow_definition_id, s.workflow_agent_id, s.workflow_agent_label,\n s.project_id, s.routing_json, s.custom_data_json,\n s.message_count, s.estimated_tokens, s.compacted_count,\n s.last_flushed_at, s.flush_count,\n
|
|
4
|
+
export declare const SESSION_COLUMNS = "\n s.conversation_id, s.agent_id, s.active_transcript_id, s.status, s.name, s.tags_json,\n s.created_at, s.updated_at, s.last_accessed_at, s.session_started_at, s.last_interaction_at,\n s.source_channel, s.source_chat_id, s.session_type, s.hidden_from_session_list,\n s.parent_conversation_id, s.workflow_run_id, s.workflow_definition_id, s.workflow_agent_id, s.workflow_agent_label,\n s.project_id, s.routing_json, s.custom_data_json,\n s.message_count, s.estimated_tokens, s.compacted_count,\n s.last_flushed_at, s.flush_count,\n t.cwd AS cwd\n";
|
|
5
5
|
export declare const SESSION_FROM_JOIN = "\n FROM sessions s\n LEFT JOIN transcripts t ON t.transcript_id = s.active_transcript_id\n";
|
|
6
6
|
export declare function readSessionRow(db: DatabaseSync, conversationId: string): SessionRow | undefined;
|
|
7
7
|
/** Read metadata without importing session lifecycle operations. */
|
|
@@ -22,7 +22,6 @@ var init_session_read_repository = __esmMin((() => {
|
|
|
22
22
|
s.project_id, s.routing_json, s.custom_data_json,
|
|
23
23
|
s.message_count, s.estimated_tokens, s.compacted_count,
|
|
24
24
|
s.last_flushed_at, s.flush_count,
|
|
25
|
-
s.thinking_level, s.verbose_level,
|
|
26
25
|
t.cwd AS cwd
|
|
27
26
|
`;
|
|
28
27
|
SESSION_FROM_JOIN = `
|
|
@@ -21,10 +21,6 @@ export declare function resetSessionRecord(conversationId: string, cwd: string):
|
|
|
21
21
|
} | null;
|
|
22
22
|
export declare function deleteSessionRecord(conversationId: string): boolean;
|
|
23
23
|
export declare function listSessionsByAgent(agentId: string): SessionMetadata[];
|
|
24
|
-
export declare function getSessionPersistedLevels(conversationId: string): {
|
|
25
|
-
thinkingLevel: string | null;
|
|
26
|
-
verboseLevel: string | null;
|
|
27
|
-
} | null;
|
|
28
24
|
export declare function findConversationIdByTranscriptId(transcriptId: string): string | null;
|
|
29
25
|
export declare function getGlobalSessionStats(): ReturnType<typeof buildGlobalSessionStats>;
|
|
30
26
|
export declare function resolveSessionAgentId(conversationId: string): string;
|
|
@@ -4,6 +4,7 @@ import { validateConversationId, validateTranscriptId } from "../../../packages/
|
|
|
4
4
|
import { init_src } from "../../../packages/gateway-contract/src/index.js";
|
|
5
5
|
import { init_session_instance_repository, readCurrentTranscriptId } from "./session-instance-repository.js";
|
|
6
6
|
import { buildDefaultSessionMetadata, init_session_metadata } from "./session-metadata.js";
|
|
7
|
+
import { init_timestamps, optionalTimestampToMs } from "./timestamps.js";
|
|
7
8
|
import { buildGlobalSessionStats, init_row_mappers, metadataToSessionInsert, sessionRowToMetadata } from "./row-mappers.js";
|
|
8
9
|
import { cancelConnectionObjective, init_connection_wait_repository } from "./connection-wait-repository.js";
|
|
9
10
|
import { init_changes, notifyUserContextChange } from "../../user-context/changes.js";
|
|
@@ -21,17 +22,15 @@ function insertSessionAndTranscript(db, conversationId, transcriptId, cwd, metad
|
|
|
21
22
|
parent_conversation_id, workflow_run_id, workflow_definition_id, workflow_agent_id, workflow_agent_label,
|
|
22
23
|
project_id, routing_json, custom_data_json,
|
|
23
24
|
message_count, estimated_tokens, compacted_count,
|
|
24
|
-
last_flushed_at, flush_count
|
|
25
|
-
thinking_level, verbose_level
|
|
25
|
+
last_flushed_at, flush_count
|
|
26
26
|
) VALUES (
|
|
27
27
|
?, ?, ?, ?, ?,
|
|
28
28
|
?, ?, ?, ?, ?,
|
|
29
29
|
?, ?, ?, ?,
|
|
30
30
|
?, ?, ?, ?, ?,
|
|
31
31
|
?, ?, ?,
|
|
32
|
-
?, ?, ?, ?, ?,
|
|
33
|
-
|
|
34
|
-
)`).run(row.conversationId, row.agentId, row.transcriptId, row.status, row.name, row.tagsJson, row.createdAt, row.updatedAt, row.lastAccessedAt, row.sessionStartedAt, row.lastInteractionAt, row.sourceChannel, row.sourceChatId, row.sessionType, row.hiddenFromSessionList, row.parentConversationId, row.workflowRunId, row.workflowDefinitionId, row.workflowAgentId, row.workflowAgentLabel, row.projectId, row.routingJson, row.customDataJson, row.messageCount, row.estimatedTokens, row.compactedCount, row.lastFlushedAt, row.flushCount, row.thinkingLevel, row.verboseLevel);
|
|
32
|
+
?, ?, ?, ?, ?, ?
|
|
33
|
+
)`).run(row.conversationId, row.agentId, row.transcriptId, row.status, row.name, row.tagsJson, row.createdAt, row.updatedAt, row.lastAccessedAt, row.sessionStartedAt, row.lastInteractionAt, row.sourceChannel, row.sourceChatId, row.sessionType, row.hiddenFromSessionList, row.parentConversationId, row.workflowRunId, row.workflowDefinitionId, row.workflowAgentId, row.workflowAgentLabel, row.projectId, row.routingJson, row.customDataJson, row.messageCount, row.estimatedTokens, row.compactedCount, row.lastFlushedAt, row.flushCount);
|
|
35
34
|
const now = Date.now();
|
|
36
35
|
db.prepare(`INSERT INTO transcripts (transcript_id, conversation_id, status, created_at, cwd)
|
|
37
36
|
VALUES (?, ?, 'active', ?, ?)`).run(transcriptId, conversationId, now, cwd);
|
|
@@ -224,10 +223,8 @@ function patchSessionMetadata(conversationId, updates) {
|
|
|
224
223
|
estimated_tokens = ?,
|
|
225
224
|
compacted_count = ?,
|
|
226
225
|
last_flushed_at = ?,
|
|
227
|
-
flush_count =
|
|
228
|
-
|
|
229
|
-
verbose_level = ?
|
|
230
|
-
WHERE conversation_id = ?`).run(merged.status, merged.name ?? null, JSON.stringify(merged.tags ?? []), Date.parse(merged.updatedAt) || now, Date.parse(merged.lastAccessedAt) || now, merged.sessionStartedAt ? Date.parse(merged.sessionStartedAt) : existing.session_started_at, merged.lastInteractionAt ? Date.parse(merged.lastInteractionAt) : existing.last_interaction_at, merged.sourceChannel, merged.sourceChatId, merged.sessionType, merged.hiddenFromSessionList ? 1 : 0, merged.parentConversationId ?? null, merged.workflowRunId ?? null, merged.workflowDefinitionId ?? null, merged.workflowAgentId ?? null, merged.workflowAgentLabel ?? null, merged.projectId ?? null, merged.routing ? JSON.stringify(merged.routing) : null, merged.customData ? JSON.stringify(merged.customData) : null, merged.messageCount, merged.estimatedTokens, merged.compactedCount, merged.lastFlushedAt ?? null, merged.flushCount ?? 0, existing.thinking_level, existing.verbose_level, conversationId);
|
|
226
|
+
flush_count = ?
|
|
227
|
+
WHERE conversation_id = ?`).run(merged.status, merged.name ?? null, JSON.stringify(merged.tags ?? []), Date.parse(merged.updatedAt) || now, Date.parse(merged.lastAccessedAt) || now, merged.sessionStartedAt ? Date.parse(merged.sessionStartedAt) : existing.session_started_at, merged.lastInteractionAt ? Date.parse(merged.lastInteractionAt) : existing.last_interaction_at, merged.sourceChannel, merged.sourceChatId, merged.sessionType, merged.hiddenFromSessionList ? 1 : 0, merged.parentConversationId ?? null, merged.workflowRunId ?? null, merged.workflowDefinitionId ?? null, merged.workflowAgentId ?? null, merged.workflowAgentLabel ?? null, merged.projectId ?? null, merged.routing ? JSON.stringify(merged.routing) : null, merged.customData ? JSON.stringify(merged.customData) : null, merged.messageCount, merged.estimatedTokens, merged.compactedCount, optionalTimestampToMs(merged.lastFlushedAt), merged.flushCount ?? 0, conversationId);
|
|
231
228
|
const row = readSessionRow(db, conversationId);
|
|
232
229
|
if (!row) throw new Error(`Session not found after patch: ${conversationId}`);
|
|
233
230
|
return sessionRowToMetadata(conversationId, row);
|
|
@@ -308,14 +305,6 @@ function listSessionsByAgent(agentId) {
|
|
|
308
305
|
WHERE s.agent_id = ?
|
|
309
306
|
ORDER BY s.updated_at DESC`).all(agentId.toLowerCase()).map((row) => sessionRowToMetadata(row.conversation_id, row));
|
|
310
307
|
}
|
|
311
|
-
function getSessionPersistedLevels(conversationId) {
|
|
312
|
-
const row = getSqliteDatabase().prepare(`SELECT thinking_level, verbose_level FROM sessions WHERE conversation_id = ?`).get(conversationId);
|
|
313
|
-
if (!row) return null;
|
|
314
|
-
return {
|
|
315
|
-
thinkingLevel: row.thinking_level,
|
|
316
|
-
verboseLevel: row.verbose_level
|
|
317
|
-
};
|
|
318
|
-
}
|
|
319
308
|
function findConversationIdByTranscriptId(transcriptId) {
|
|
320
309
|
return getSqliteDatabase().prepare(`SELECT conversation_id FROM sessions WHERE active_transcript_id = ?`).get(transcriptId)?.conversation_id ?? null;
|
|
321
310
|
}
|
|
@@ -335,6 +324,7 @@ var init_session_repository = __esmMin((() => {
|
|
|
335
324
|
init_session_metadata();
|
|
336
325
|
init_session_instance_repository();
|
|
337
326
|
init_row_mappers();
|
|
327
|
+
init_timestamps();
|
|
338
328
|
init_transaction();
|
|
339
329
|
init_session_identity_sql();
|
|
340
330
|
init_fts();
|
|
@@ -342,4 +332,4 @@ var init_session_repository = __esmMin((() => {
|
|
|
342
332
|
}));
|
|
343
333
|
//#endregion
|
|
344
334
|
init_session_repository();
|
|
345
|
-
export { deleteSessionRecord, ensureSessionInTransaction, ensureSessionRecord, findConversationIdByTranscriptId, getCurrentTranscriptId, getGlobalSessionStats, getSessionMetadata,
|
|
335
|
+
export { deleteSessionRecord, ensureSessionInTransaction, ensureSessionRecord, findConversationIdByTranscriptId, getCurrentTranscriptId, getGlobalSessionStats, getSessionMetadata, incrementSessionStatsOnAppend, init_session_repository, listSessionMetadata, listSessionsByAgent, patchSessionMetadata, readCurrentTranscriptId, resetSessionRecord, resolveSessionAgentId, updateSessionStats };
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare function timestampToMs(value: string): number;
|
|
2
|
+
export declare function optionalTimestampToMs(value: string | undefined): number | null;
|
|
3
|
+
export declare function timestampToIso(value: number): string;
|
|
4
|
+
export declare function optionalTimestampToIso(value: number | null): string | undefined;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { __esmMin } from "../../../_virtual/_rolldown/runtime.js";
|
|
2
|
+
//#region src/storage/sqlite/timestamps.ts
|
|
3
|
+
function timestampToMs(value) {
|
|
4
|
+
const timestamp = Date.parse(value);
|
|
5
|
+
if (!Number.isFinite(timestamp)) throw new Error(`Invalid ISO timestamp: ${value}`);
|
|
6
|
+
return timestamp;
|
|
7
|
+
}
|
|
8
|
+
function optionalTimestampToMs(value) {
|
|
9
|
+
return value === void 0 ? null : timestampToMs(value);
|
|
10
|
+
}
|
|
11
|
+
function timestampToIso(value) {
|
|
12
|
+
return new Date(value).toISOString();
|
|
13
|
+
}
|
|
14
|
+
function optionalTimestampToIso(value) {
|
|
15
|
+
return value === null ? void 0 : timestampToIso(value);
|
|
16
|
+
}
|
|
17
|
+
var init_timestamps = __esmMin((() => {}));
|
|
18
|
+
//#endregion
|
|
19
|
+
init_timestamps();
|
|
20
|
+
export { init_timestamps, optionalTimestampToIso, optionalTimestampToMs, timestampToIso, timestampToMs };
|
|
@@ -52,6 +52,7 @@ export declare function paginateTranscriptMessages(conversationId: string, optio
|
|
|
52
52
|
total: number;
|
|
53
53
|
startSeq: number;
|
|
54
54
|
endSeq: number;
|
|
55
|
+
revision: number;
|
|
55
56
|
};
|
|
56
57
|
export declare function listCompactionBoundaries(conversationId: string): CompactionBoundarySummary[];
|
|
57
58
|
export declare function restoreBeforeCompactionBoundary(conversationId: string, compactionId: string): void;
|
|
@@ -50,24 +50,27 @@ function withSessionInputContextMetadata(db, conversationId, row) {
|
|
|
50
50
|
const turnId = typeof message.turnId === "string" ? message.turnId.trim() : "";
|
|
51
51
|
if (!turnId) return row;
|
|
52
52
|
const metadata = message.metadata && typeof message.metadata === "object" && !Array.isArray(message.metadata) ? message.metadata : {};
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
WHERE conversation_id = ? AND run_id = ? AND context_refs_json IS NOT NULL
|
|
53
|
+
const input = db.prepare(`SELECT client_message_id, context_refs_json FROM session_inputs
|
|
54
|
+
WHERE conversation_id = ? AND run_id = ?
|
|
56
55
|
LIMIT 1`).get(conversationId, turnId);
|
|
57
56
|
if (!input) return row;
|
|
57
|
+
let sourceContexts = metadata.sourceContexts;
|
|
58
58
|
try {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
metadata: {
|
|
64
|
-
...metadata,
|
|
65
|
-
sourceContexts
|
|
66
|
-
}
|
|
67
|
-
};
|
|
59
|
+
if ((!Array.isArray(sourceContexts) || sourceContexts.length === 0) && input.context_refs_json) {
|
|
60
|
+
const parsed = JSON.parse(input.context_refs_json);
|
|
61
|
+
if (Array.isArray(parsed) && parsed.length > 0) sourceContexts = parsed;
|
|
62
|
+
}
|
|
68
63
|
} catch {
|
|
69
|
-
|
|
64
|
+
sourceContexts = metadata.sourceContexts;
|
|
70
65
|
}
|
|
66
|
+
return {
|
|
67
|
+
...message,
|
|
68
|
+
metadata: {
|
|
69
|
+
...metadata,
|
|
70
|
+
clientMessageId: input.client_message_id,
|
|
71
|
+
...Array.isArray(sourceContexts) && sourceContexts.length > 0 ? { sourceContexts } : {}
|
|
72
|
+
}
|
|
73
|
+
};
|
|
71
74
|
}
|
|
72
75
|
function appendTranscriptEntry(conversationId, row, opts) {
|
|
73
76
|
if (isRuntimeOnlyTranscriptMessage(row)) throw new Error("Runtime-only messages cannot be persisted in a session transcript");
|
|
@@ -281,7 +284,8 @@ function paginateTranscriptMessages(conversationId, options = {}) {
|
|
|
281
284
|
messages: [],
|
|
282
285
|
total: 0,
|
|
283
286
|
startSeq: 0,
|
|
284
|
-
endSeq: 0
|
|
287
|
+
endSeq: 0,
|
|
288
|
+
revision: 0
|
|
285
289
|
};
|
|
286
290
|
const db = getSqliteDatabase();
|
|
287
291
|
const kinds = options.includeContext ? ["message", "context"] : ["message"];
|
|
@@ -293,6 +297,9 @@ function paginateTranscriptMessages(conversationId, options = {}) {
|
|
|
293
297
|
FROM transcript_entries e
|
|
294
298
|
JOIN transcripts t ON t.transcript_id = e.transcript_id
|
|
295
299
|
WHERE ${transcriptWhere} AND e.entry_kind IN (${kindPlaceholders})`).get(transcriptArg, ...kinds).total;
|
|
300
|
+
const revisionRow = db.prepare(`SELECT COALESCE(MAX(seq), 0) AS revision
|
|
301
|
+
FROM transcript_entries
|
|
302
|
+
WHERE transcript_id = ? AND entry_kind IN (${kindPlaceholders})`).get(transcriptId, ...kinds);
|
|
296
303
|
const limit = Math.min(200, Math.max(1, Math.trunc(options.limit ?? 50)));
|
|
297
304
|
const offset = Math.max(0, Math.trunc(options.offset ?? 0));
|
|
298
305
|
let rows;
|
|
@@ -324,7 +331,8 @@ function paginateTranscriptMessages(conversationId, options = {}) {
|
|
|
324
331
|
messages: buildSessionContextForLlm(storedRows),
|
|
325
332
|
total,
|
|
326
333
|
startSeq: rows[0]?.seq ?? 0,
|
|
327
|
-
endSeq: rows[rows.length - 1]?.seq ?? 0
|
|
334
|
+
endSeq: rows[rows.length - 1]?.seq ?? 0,
|
|
335
|
+
revision: revisionRow.revision
|
|
328
336
|
};
|
|
329
337
|
}
|
|
330
338
|
function listCompactionBoundaries(conversationId) {
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { __esmMin } from "../../../_virtual/_rolldown/runtime.js";
|
|
2
2
|
import { getSqliteDatabase, init_transaction, runSqliteWriteTransaction } from "./transaction.js";
|
|
3
|
+
import { init_timestamps, timestampToIso } from "./timestamps.js";
|
|
3
4
|
import { DEFAULT_USER_TRUST_LEVEL, init_trust_policy, isUserTrustLevel } from "../../user-context/trust-policy.js";
|
|
4
5
|
//#region src/storage/sqlite/user-trust-repository.ts
|
|
5
6
|
function fromRow(row) {
|
|
6
7
|
return {
|
|
7
8
|
principalId: row.principal_id,
|
|
8
9
|
defaultActionLevel: isUserTrustLevel(row.default_action_level) ? row.default_action_level : DEFAULT_USER_TRUST_LEVEL,
|
|
9
|
-
updatedAt: row.updated_at
|
|
10
|
+
updatedAt: timestampToIso(row.updated_at)
|
|
10
11
|
};
|
|
11
12
|
}
|
|
12
13
|
function getUserTrustPolicy(principalId = "local-owner") {
|
|
@@ -17,7 +18,7 @@ function getUserTrustPolicy(principalId = "local-owner") {
|
|
|
17
18
|
};
|
|
18
19
|
}
|
|
19
20
|
function setUserTrustPolicy(defaultActionLevel, principalId = "local-owner") {
|
|
20
|
-
const updatedAt =
|
|
21
|
+
const updatedAt = Date.now();
|
|
21
22
|
return runSqliteWriteTransaction((db) => {
|
|
22
23
|
db.prepare(`
|
|
23
24
|
INSERT INTO user_trust_policies (principal_id, default_action_level, updated_at)
|
|
@@ -31,6 +32,7 @@ function setUserTrustPolicy(defaultActionLevel, principalId = "local-owner") {
|
|
|
31
32
|
}
|
|
32
33
|
var init_user_trust_repository = __esmMin((() => {
|
|
33
34
|
init_trust_policy();
|
|
35
|
+
init_timestamps();
|
|
34
36
|
init_transaction();
|
|
35
37
|
}));
|
|
36
38
|
//#endregion
|
|
@@ -2,10 +2,10 @@ import { ProductReadContracts } from "../../../packages/gateway-contract/src/cap
|
|
|
2
2
|
import { init_src } from "../../../packages/gateway-contract/src/index.js";
|
|
3
3
|
import { TaskRepository, init_task_repository } from "../task-repository.js";
|
|
4
4
|
import { TaskRunRepository, init_task_run_repository } from "../task-run-repository.js";
|
|
5
|
-
import { TaskConversationRepository } from "../task-conversation-repository.js";
|
|
6
|
-
import { TaskReadModelProjector } from "../task-read-model-projector.js";
|
|
7
5
|
import { CapabilityError } from "../../capabilities/runtime/errors.js";
|
|
8
6
|
import { defineReadCapability } from "../../capabilities/runtime/dispatcher.js";
|
|
7
|
+
import { TaskConversationRepository } from "../task-conversation-repository.js";
|
|
8
|
+
import { TaskReadModelProjector } from "../task-read-model-projector.js";
|
|
9
9
|
import { TaskContextRepository } from "../task-context-repository.js";
|
|
10
10
|
import { TaskDependencyService } from "../task-dependency-service.js";
|
|
11
11
|
import { TaskValueMetricsService } from "../task-value-metrics-service.js";
|
|
@@ -101,8 +101,8 @@ export declare const TaskMutationOutputSchema: z.ZodDiscriminatedUnion<[z.ZodObj
|
|
|
101
101
|
ok: z.ZodLiteral<false>;
|
|
102
102
|
reason: z.ZodEnum<{
|
|
103
103
|
blocked: "blocked";
|
|
104
|
-
not_found: "not_found";
|
|
105
104
|
conflict: "conflict";
|
|
105
|
+
not_found: "not_found";
|
|
106
106
|
invalid_transition: "invalid_transition";
|
|
107
107
|
}>;
|
|
108
108
|
model: z.ZodOptional<z.ZodObject<{
|
|
@@ -51,7 +51,7 @@ function toHomeAutomation(automation) {
|
|
|
51
51
|
};
|
|
52
52
|
}
|
|
53
53
|
function effectiveAutomationTimeoutSeconds(run, automation) {
|
|
54
|
-
return ("timeoutSeconds" in run.actionSnapshot ? run.actionSnapshot.timeoutSeconds : void 0) ?? automation?.reliability?.
|
|
54
|
+
return ("timeoutSeconds" in run.actionSnapshot ? run.actionSnapshot.timeoutSeconds : void 0) ?? automation?.reliability?.executionTimeoutSeconds ?? 1800;
|
|
55
55
|
}
|
|
56
56
|
function attentionDetail(kind, status, locale, timeoutSeconds) {
|
|
57
57
|
const isChinese = locale?.toLowerCase().startsWith("zh") ?? false;
|
|
@@ -327,7 +327,7 @@ var HomeQueryService = class {
|
|
|
327
327
|
const projectsById = new Map(projects.items.map((project) => [project.id, project]));
|
|
328
328
|
const activeWorkflowRuns = workflowRuns.filter((run) => run.status === "queued" || run.status === "running").map(toHomeWorkflowRun);
|
|
329
329
|
const failedWorkflowRuns = workflowRuns.filter((run) => run.status === "failed" || run.status === "timeout").slice(0, 5).map(toHomeWorkflowRun);
|
|
330
|
-
const upcomingAutomations = automations.filter((automation) => automation.notificationPolicy !== "none").map(toHomeAutomation).filter((automation) => Boolean(automation)).sort((a, b) => Date.parse(a.nextRunAt) - Date.parse(b.nextRunAt));
|
|
330
|
+
const upcomingAutomations = automations.filter((automation) => automation.delivery.notificationPolicy !== "none").map(toHomeAutomation).filter((automation) => Boolean(automation)).sort((a, b) => Date.parse(a.nextRunAt) - Date.parse(b.nextRunAt));
|
|
331
331
|
const latestAutomationRuns = [...automationRuns].sort((left, right) => right.createdAtMs - left.createdAtMs).filter((run, index, all) => all.findIndex((candidate) => candidate.automationId === run.automationId) === index);
|
|
332
332
|
const automationsById = new Map(automations.map((automation) => [automation.id, automation]));
|
|
333
333
|
const decisionCandidates = [...activeTasks.map((task) => decisionFromTask(this.#projector.project(task), task.projectId ? projectsById.get(task.projectId)?.name : void 0, locale)).filter((item) => Boolean(item)), ...connectorApprovals.filter((approval) => Date.parse(approval.expiresAt) > nowMs).map((approval) => ({
|
|
@@ -354,7 +354,7 @@ var HomeQueryService = class {
|
|
|
354
354
|
href: `/workflows?runId=${encodeURIComponent(run.id)}`,
|
|
355
355
|
updatedAt: run.completedAtMs ?? run.startedAtMs ?? run.createdAtMs,
|
|
356
356
|
conversationId: run.conversationId
|
|
357
|
-
})), ...latestAutomationRuns.filter((run) => run.status === "failed" || run.status === "timeout").filter((run) => automationsById.get(run.automationId)?.notificationPolicy !== "none").filter((run) => !isHomeAttentionAcknowledged("automation_run", run.id)).map((run) => ({
|
|
357
|
+
})), ...latestAutomationRuns.filter((run) => run.status === "failed" || run.status === "timeout").filter((run) => automationsById.get(run.automationId)?.delivery.notificationPolicy !== "none").filter((run) => !isHomeAttentionAcknowledged("automation_run", run.id)).map((run) => ({
|
|
358
358
|
id: `automation_run:${run.id}`,
|
|
359
359
|
kind: "automation_run",
|
|
360
360
|
runId: run.id,
|
|
@@ -69,7 +69,7 @@ var ModelTaskContractPlanner = class {
|
|
|
69
69
|
apiKey: await resolveModelCallApiKey(model),
|
|
70
70
|
maxTokens: 2e3,
|
|
71
71
|
temperature: 0
|
|
72
|
-
})).content));
|
|
72
|
+
}, void 0, { operation: "task.plan_contract" })).content));
|
|
73
73
|
return planned ? {
|
|
74
74
|
...planned,
|
|
75
75
|
objective: fallback.objective
|