@xopcai/xopc 0.0.188 → 0.0.190
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -4
- package/README.zh-CN.md +0 -3
- package/dist/browser-ext/manifest.json +1 -1
- package/dist/extensions/telegram/xopc.extension.json +1 -1
- package/dist/gateway/static/root/assets/{activity-store--QoUGhiS.js → activity-store-DstnJCS5.js} +1 -1
- package/dist/gateway/static/root/assets/{agent-avatar-dicebear-B0yweLNQ.js → agent-avatar-dicebear-9vAbkroX.js} +1 -1
- package/dist/gateway/static/root/assets/agents-D1t4SfMQ.js +68 -0
- package/dist/gateway/static/root/assets/{api-5laWqfiE.js → api-BTL9kayv.js} +1 -1
- package/dist/gateway/static/root/assets/{app-management-settings-panel-BXJ8Jiv_.js → app-management-settings-panel-DkFeIdBf.js} +1 -1
- package/dist/gateway/static/root/assets/{appearance-settings-DG9n9D1M.js → appearance-settings-Bxs8Fpaj.js} +1 -1
- package/dist/gateway/static/root/assets/apps-page-Cgrgu5OW.js +1 -0
- package/dist/gateway/static/root/assets/{archive-plugin-Ceh5qrZf.js → archive-plugin-Ch2RmLCC.js} +1 -1
- package/dist/gateway/static/root/assets/{attachment-load-jFW7uYf7.js → attachment-load-BhMQM_Ky.js} +1 -1
- package/dist/gateway/static/root/assets/automations-page-CtJxstKh.js +6 -0
- package/dist/gateway/static/root/assets/{binary-plugins-XDlkI1r4.js → binary-plugins-D6CqlymH.js} +1 -1
- package/dist/gateway/static/root/assets/{block-editor-kyKc2IhE.js → block-editor-ClL6HEg9.js} +56 -56
- package/dist/gateway/static/root/assets/browser-settings-page-DW99iDmD.js +8 -0
- package/dist/gateway/static/root/assets/{browser-workflow-inputs-BJa5Iz_v.js → browser-workflow-inputs-BYy48VhN.js} +1 -1
- package/dist/gateway/static/root/assets/{browser-workflows-page-CTQQOsn5.js → browser-workflows-page-zgLibuMH.js} +2 -2
- package/dist/gateway/static/root/assets/capabilities-settings-panel-CHUrT9EB.js +7 -0
- package/dist/gateway/static/root/assets/capability-presets-api-BB8t4Ja7.js +1 -0
- package/dist/gateway/static/root/assets/capability-presets-settings-panel-Cycrv0YV.js +1 -0
- package/dist/gateway/static/root/assets/{channel-recipient-api-BgIkWq01.js → channel-recipient-api-BThDGiO3.js} +1 -1
- package/dist/gateway/static/root/assets/channels-settings-V96gPUAU.js +1 -0
- package/dist/gateway/static/root/assets/channels-status-swr-Cz7SAAkm.js +1 -0
- package/dist/gateway/static/root/assets/connectors-api-DS9ED-EL.js +1 -0
- package/dist/gateway/static/root/assets/connectors-page-BhlyQoQI.js +2 -0
- package/dist/gateway/static/root/assets/cron-expression-CkgsvhtW.js +2 -0
- package/dist/gateway/static/root/assets/{desktop-pet-CSwd00CV.js → desktop-pet-Cv8rGhYW.js} +1 -1
- package/dist/gateway/static/root/assets/{desktop-pet-settings-CuNQvHGu.js → desktop-pet-settings-CIeJdwfV.js} +1 -1
- package/dist/gateway/static/root/assets/{directory-picker-path-field-ct0n5Rje.js → directory-picker-path-field-D8jXEiAY.js} +1 -1
- package/dist/gateway/static/root/assets/{extension-debug-page-BeRBuMUU.js → extension-debug-page-CCZ9u6TZ.js} +1 -1
- package/dist/gateway/static/root/assets/{extension-page-DbK-Cwao.js → extension-page-CV36ILRG.js} +1 -1
- package/dist/gateway/static/root/assets/extension-settings-page-IyQrSILY.js +1 -0
- package/dist/gateway/static/root/assets/{gateway-config-api-CC7EvEFp.js → gateway-config-api-D4_r5iJM.js} +1 -1
- package/dist/gateway/static/root/assets/gateway-settings-CYlntpBH.js +1 -0
- package/dist/gateway/static/root/assets/{gateway-startup-retry-B2DmdlwO.js → gateway-startup-retry-EO9mKvzE.js} +1 -1
- package/dist/gateway/static/root/assets/heartbeat-settings-D4SyWob8.js +1 -0
- package/dist/gateway/static/root/assets/home-page-B2Kagoh8.js +3 -0
- package/dist/gateway/static/root/assets/{image-generation-api-GMTaS6eI.js → image-generation-api-Bu7PyVSh.js} +1 -1
- package/dist/gateway/static/root/assets/index-CYT5DOzr.js +150 -0
- package/dist/gateway/static/root/assets/index-D6e3tPL-.css +1 -0
- package/dist/gateway/static/root/assets/{keyboard-shortcuts-settings-DhGYddbI.js → keyboard-shortcuts-settings-BMhCuVBZ.js} +1 -1
- package/dist/gateway/static/root/assets/local-app-workbench-page-BHYbFjqy.js +2 -0
- package/dist/gateway/static/root/assets/{local-apps-page-CmnrBmWi.js → local-apps-page-ijIe7_y2.js} +1 -1
- package/dist/gateway/static/root/assets/locale-store-deR2zRaE.js +1 -0
- package/dist/gateway/static/root/assets/logs-page-IIn8Tess.js +2 -0
- package/dist/gateway/static/root/assets/management-settings--V_fovKD.js +1 -0
- package/dist/gateway/static/root/assets/{markdown-split-CZaBPOVn.js → markdown-split-Dt9-in6W.js} +1 -1
- package/dist/gateway/static/root/assets/{media-plugins-CiKvSgCv.js → media-plugins-B3pj_iO0.js} +1 -1
- package/dist/gateway/static/root/assets/messages-B4XqB8I6.js +3 -0
- package/dist/gateway/static/root/assets/{notes-page-Bisbzqlz.js → notes-page-DZ366lIT.js} +1 -1
- package/dist/gateway/static/root/assets/notes-workbench-S2sBVOLw.js +4 -0
- package/dist/gateway/static/root/assets/{page-tabs-BxlwhAbH.js → page-tabs-C5ge434C.js} +1 -1
- package/dist/gateway/static/root/assets/{preview-open-alternatives-RM8wXxfT.js → preview-open-alternatives-BFa9DgSV.js} +1 -1
- package/dist/gateway/static/root/assets/product-delivery-tRr-7IxY.js +1 -0
- package/dist/gateway/static/root/assets/{product-open-page-DdBlibek.js → product-open-page-Dc9CcWdu.js} +1 -1
- package/dist/gateway/static/root/assets/project-detail-page-BilzoCJ7.js +1 -0
- package/dist/gateway/static/root/assets/projects-page-BoQUyacP.js +1 -0
- package/dist/gateway/static/root/assets/remote-access-hub-DUyUaCRF.js +1 -0
- package/dist/gateway/static/root/assets/{schema-form-BDKbpmXv.js → schema-form-B84DckWe.js} +1 -1
- package/dist/gateway/static/root/assets/{schemas-C6onAggk.js → schemas-zIBW3wiV.js} +1 -1
- package/dist/gateway/static/root/assets/sessions-page-Dzxlq1F0.js +1 -0
- package/dist/gateway/static/root/assets/settings-advanced-gate-TzwlZxU6.js +1 -0
- package/dist/gateway/static/root/assets/settings-form-section-Dp9itvdy.js +1 -0
- package/dist/gateway/static/root/assets/{settings-loading-skeleton-DgIp8_S6.js → settings-loading-skeleton-CCtlhoy7.js} +1 -1
- package/dist/gateway/static/root/assets/settings-page-DQmMKf8r.js +1 -0
- package/dist/gateway/static/root/assets/{settings-page-layout-97LmwrzC.js → settings-page-layout-EQIOJa_L.js} +1 -1
- package/dist/gateway/static/root/assets/setup-status-panel-Cwi-SPja.js +1 -0
- package/dist/gateway/static/root/assets/{share-preview-page-BH7i3g1S.js → share-preview-page-C4_B2jvf.js} +1 -1
- package/dist/gateway/static/root/assets/shares-settings-CkyuGlZK.js +1 -0
- package/dist/gateway/static/root/assets/skill-reload-api-BJCePQK5.js +1 -0
- package/dist/gateway/static/root/assets/skills-page-BYWLfmJi.js +2 -0
- package/dist/gateway/static/root/assets/{skills-page.utils-s-a5WV9j.js → skills-page.utils-Jhm24i4h.js} +1 -1
- package/dist/gateway/static/root/assets/{system-settings-panel-BxjeMT5k.js → system-settings-panel-Dpx2ags2.js} +1 -1
- package/dist/gateway/static/root/assets/{task-detail-page-BahycnfW.js → task-detail-page-DLAdxI6e.js} +1 -1
- package/dist/gateway/static/root/assets/{theme-store-BRxdsmic.js → theme-store-DnBOcGXi.js} +1 -1
- package/dist/gateway/static/root/assets/{typed-models-lib-39MjwPSq.js → typed-models-lib-DULmTHUB.js} +1 -1
- package/dist/gateway/static/root/assets/use-autosave-BrjVk5VH.js +1 -0
- package/dist/gateway/static/root/assets/user-context-page-9AAFpGAL.js +1 -0
- package/dist/gateway/static/root/assets/{voice-api-key-field-XU-7sBSg.js → voice-api-key-field-BISTPfq_.js} +1 -1
- package/dist/gateway/static/root/assets/{work-discovery-overlay-CJqu8UHq.js → work-discovery-overlay-Wr-uF7VA.js} +1 -1
- package/dist/gateway/static/root/assets/work-discovery-page-BWds95sL.js +1 -0
- package/dist/gateway/static/root/assets/{workflow-run-setup-panel-DXtg8Qxl.js → workflow-run-setup-panel-DHqHP8_6.js} +2 -2
- package/dist/gateway/static/root/assets/workflows-page-0b4_DFHr.js +11 -0
- package/dist/gateway/static/root/index.html +9 -9
- package/dist/package.js +1 -1
- package/dist/packages/endpoint-tools-protocol/src/index.js +184 -0
- package/dist/packages/gateway-contract/src/tool-activity.js +0 -36
- package/dist/packages/realtime-client/src/index.js +256 -0
- package/dist/packages/realtime-protocol/src/index.js +88 -0
- package/dist/src/agent/agent-manager.d.ts +1 -1
- package/dist/src/agent/agent-manager.js +7 -13
- package/dist/src/agent/background-review/coordinator.js +1 -1
- package/dist/src/agent/background-review/prompts.d.ts +1 -1
- package/dist/src/agent/background-review/prompts.js +3 -1
- package/dist/src/agent/background-review/run-background-review.d.ts +2 -0
- package/dist/src/agent/background-review/run-background-review.js +10 -9
- package/dist/src/agent/bootstrap/bootstrap-cache.d.ts +0 -1
- package/dist/src/agent/bootstrap/bootstrap-cache.js +3 -4
- package/dist/src/agent/bootstrap/bootstrap-files.d.ts +0 -4
- package/dist/src/agent/bootstrap/bootstrap-files.js +3 -4
- package/dist/src/agent/bootstrap/filter-bootstrap-files.js +1 -4
- package/dist/src/agent/bootstrap/load-bootstrap-files.d.ts +0 -1
- package/dist/src/agent/bootstrap/load-bootstrap-files.js +1 -14
- package/dist/src/agent/bootstrap/types.d.ts +1 -1
- package/dist/src/agent/client-error-format.d.ts +1 -1
- package/dist/src/agent/client-error-format.js +1 -1
- package/dist/src/agent/context/workspace-templates/SOUL.md +1 -1
- package/dist/src/agent/external-tools/endpoint-provider.d.ts +17 -0
- package/dist/src/agent/external-tools/endpoint-provider.js +93 -0
- package/dist/src/agent/external-tools/gateway-tools.js +1 -1
- package/dist/src/agent/external-tools/index.d.ts +4 -5
- package/dist/src/agent/external-tools/index.js +8 -2
- package/dist/src/agent/external-tools/types.d.ts +8 -1
- package/dist/src/agent/external-tools/types.js +2 -1
- package/dist/src/agent/inbound/inbound-loop.js +4 -0
- package/dist/src/agent/inbound/turn-dispatcher.d.ts +9 -8
- package/dist/src/agent/inbound/turn-dispatcher.js +13 -11
- package/dist/src/agent/memory/builtin-provider.d.ts +2 -4
- package/dist/src/agent/memory/builtin-provider.js +35 -15
- package/dist/src/agent/memory/context/types.d.ts +3 -1
- package/dist/src/agent/memory/create-memory-manager.js +2 -0
- package/dist/src/agent/memory/index.d.ts +1 -1
- package/dist/src/agent/memory/index.js +1 -1
- package/dist/src/agent/memory/manager.d.ts +9 -1
- package/dist/src/agent/memory/manager.js +39 -9
- package/dist/src/agent/memory/memory-config.d.ts +1 -1
- package/dist/src/agent/memory/memory-config.js +1 -1
- package/dist/src/agent/memory/source-origin.js +0 -2
- package/dist/src/agent/memory/types.d.ts +5 -1
- package/dist/src/agent/memory/understanding/service.d.ts +10 -10
- package/dist/src/agent/memory/understanding/service.js +108 -176
- package/dist/src/agent/memory/understanding/types.d.ts +7 -8
- package/dist/src/agent/memory/user-context-coordinator.d.ts +2 -1
- package/dist/src/agent/memory/user-context-coordinator.js +27 -41
- package/dist/src/agent/messaging/command-handler.d.ts +2 -2
- package/dist/src/agent/messaging/command-handler.js +3 -3
- package/dist/src/agent/orchestration/agent-orchestrator.js +4 -7
- package/dist/src/agent/prompt/sections/memory-skills.js +4 -4
- package/dist/src/agent/prompt/sections/tooling.js +0 -10
- package/dist/src/agent/prompt/service-prompt-builder.d.ts +0 -1
- package/dist/src/agent/prompt/service-prompt-builder.js +4 -33
- package/dist/src/agent/prompt/system-prompt.js +1 -2
- package/dist/src/agent/service/async-queue.d.ts +1 -1
- package/dist/src/agent/service/async-queue.js +1 -1
- package/dist/src/agent/service/direct-turn-helpers.d.ts +1 -1
- package/dist/src/agent/service/direct-turn-helpers.js +2 -2
- package/dist/src/agent/service/process-direct-one-shot.d.ts +3 -1
- package/dist/src/agent/service/process-direct-one-shot.js +1 -1
- package/dist/src/agent/service/process-direct-streaming.d.ts +7 -5
- package/dist/src/agent/service/process-direct-streaming.js +5 -5
- package/dist/src/agent/service.d.ts +2 -3
- package/dist/src/agent/service.js +10 -21
- package/dist/src/agent/service.types.d.ts +2 -0
- package/dist/src/agent/session/index.d.ts +1 -1
- package/dist/src/agent/session/session-context.d.ts +2 -0
- package/dist/src/agent/session/session-context.js +4 -0
- package/dist/src/agent/session/session-state-bag.d.ts +4 -4
- package/dist/src/agent/session/session-state-bag.js +1 -1
- package/dist/src/agent/skills/marketplace/adapters/clawhub/adapter.js +1 -1
- package/dist/src/agent/streaming/reasoning-visibility.d.ts +6 -0
- package/dist/src/agent/streaming/{reasoning-visibility-sse.js → reasoning-visibility.js} +3 -6
- package/dist/src/agent/tools/dreaming-tool.d.ts +0 -2
- package/dist/src/agent/tools/dreaming-tool.js +13 -38
- package/dist/src/agent/tools/factory.d.ts +4 -3
- package/dist/src/agent/tools/factory.js +2 -10
- package/dist/src/agent/tools/index.d.ts +0 -1
- package/dist/src/agent/tools/index.js +1 -2
- package/dist/src/agent/tools/memory-tool.js +1 -1
- package/dist/src/agent/workspace-runtime/registry.d.ts +3 -5
- package/dist/src/agent/workspace-runtime/registry.js +2 -15
- package/dist/src/agent-manifest/schema.d.ts +17 -17
- package/dist/src/agent-runtime/index.js +1 -1
- package/dist/src/agent-runtime/memory-runtime.d.ts +2 -2
- package/dist/src/agent-runtime/runtime-profile.js +1 -1
- package/dist/src/automations/domain/types.d.ts +2 -1
- package/dist/src/automations/domain/validation.d.ts +29 -29
- package/dist/src/automations/draft/automation-draft-validator.d.ts +3 -3
- package/dist/src/automations/service/action-executor.js +4 -1
- package/dist/src/channels/pairing/pairing-challenge.d.ts +1 -1
- package/dist/src/channels/pairing/pairing-challenge.js +1 -1
- package/dist/src/chat-commands/builtins/understanding.js +2 -5
- package/dist/src/cli/commands/agent/stream-renderer.js +4 -1
- package/dist/src/cli/commands/doctor/checks/database-schema.js +1 -1
- package/dist/src/cli/commands/extension-marketplace.js +1 -1
- package/dist/src/cli/commands/init.js +3 -22
- package/dist/src/cli/templates.js +1 -1
- package/dist/src/config/index.js +3 -3
- package/dist/src/config/paths.d.ts +0 -5
- package/dist/src/config/paths.js +2 -11
- package/dist/src/config/rules.js +0 -5
- package/dist/src/config/schema.d.ts +27 -122
- package/dist/src/config/schema.js +9 -42
- package/dist/src/config/web-patch.js +0 -1
- package/dist/src/connectors/learning-coordinator.js +75 -3
- package/dist/src/endpoint-tools/auth.d.ts +20 -0
- package/dist/src/endpoint-tools/auth.js +51 -0
- package/dist/src/endpoint-tools/index.d.ts +5 -0
- package/dist/src/endpoint-tools/index.js +6 -0
- package/dist/src/endpoint-tools/invocation-service.d.ts +68 -0
- package/dist/src/endpoint-tools/invocation-service.js +190 -0
- package/dist/src/endpoint-tools/policy.d.ts +10 -0
- package/dist/src/endpoint-tools/policy.js +18 -0
- package/dist/src/endpoint-tools/registry.d.ts +45 -0
- package/dist/src/endpoint-tools/registry.js +121 -0
- package/dist/src/endpoint-tools/runtime.d.ts +23 -0
- package/dist/src/endpoint-tools/runtime.js +86 -0
- package/dist/src/endpoint-tools/upload-service.d.ts +41 -0
- package/dist/src/endpoint-tools/upload-service.js +103 -0
- package/dist/src/extensions/types/hooks.d.ts +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/agent-builtin-tools.js +0 -5
- package/dist/src/gateway/agents-admin.d.ts +0 -7
- package/dist/src/gateway/agents-admin.js +3 -32
- package/dist/src/gateway/chat-stream/protocol.d.ts +0 -1
- package/dist/src/gateway/clarify-bridge.d.ts +5 -4
- package/dist/src/gateway/clarify-bridge.js +3 -4
- package/dist/src/gateway/dreaming-automation-reconciler.d.ts +3 -3
- package/dist/src/gateway/dreaming-automation-reconciler.js +48 -88
- package/dist/src/gateway/heartbeat/service.js +4 -1
- package/dist/src/gateway/hono/app.js +1 -5
- package/dist/src/gateway/hono/index.d.ts +0 -1
- package/dist/src/gateway/hono/index.js +1 -2
- package/dist/src/gateway/hono/lib/config-payload.d.ts +20 -9
- package/dist/src/gateway/hono/lib/config-payload.js +3 -2
- package/dist/src/gateway/hono/middleware/auth.js +3 -5
- package/dist/src/gateway/hono/oauth-async.d.ts +1 -0
- package/dist/src/gateway/hono/oauth-async.js +17 -2
- package/dist/src/gateway/hono/routes/agent-stream.js +49 -6
- package/dist/src/gateway/hono/routes/agents.js +1 -33
- package/dist/src/gateway/hono/routes/auth-registry-extensions.js +1 -1
- package/dist/src/gateway/hono/routes/config-patch/gateway.d.ts +2 -2
- package/dist/src/gateway/hono/routes/config-patch/gateway.js +0 -19
- package/dist/src/gateway/hono/routes/config-patch/misc.js +17 -1
- package/dist/src/gateway/hono/routes/connectors.js +13 -12
- package/dist/src/gateway/hono/routes/deps.d.ts +0 -2
- package/dist/src/gateway/hono/routes/endpoint-tools.d.ts +3 -0
- package/dist/src/gateway/hono/routes/endpoint-tools.js +196 -0
- package/dist/src/gateway/hono/routes/index.js +6 -2
- package/dist/src/gateway/hono/routes/lazy-bundles.js +1 -5
- package/dist/src/gateway/hono/routes/logs.js +0 -4
- package/dist/src/gateway/hono/routes/public-gateway.js +2 -2
- package/dist/src/gateway/hono/routes/realtime.d.ts +3 -0
- package/dist/src/gateway/hono/routes/realtime.js +35 -0
- package/dist/src/gateway/hono/routes/status.js +0 -7
- package/dist/src/gateway/hono/routes/understanding-sources.d.ts +3 -0
- package/dist/src/gateway/hono/routes/understanding-sources.js +203 -0
- package/dist/src/gateway/hono/routes/work-discovery.d.ts +2 -0
- package/dist/src/gateway/hono/routes/work-discovery.js +3 -134
- package/dist/src/gateway/hono/routes/workflows.js +1 -1
- package/dist/src/gateway/hono/routes/you.d.ts +0 -31
- package/dist/src/gateway/hono/routes/you.js +230 -1161
- package/dist/src/gateway/index.d.ts +1 -1
- package/dist/src/gateway/index.js +1 -2
- package/dist/src/gateway/protocol.d.ts +1 -7
- package/dist/src/gateway/security/index.js +1 -1
- package/dist/src/gateway/security/operator-scopes.js +1 -1
- package/dist/src/gateway/server.js +4 -4
- package/dist/src/gateway/service/agent-runner.d.ts +11 -9
- package/dist/src/gateway/service/agent-runner.js +18 -18
- package/dist/src/gateway/service/config-coordinator.d.ts +3 -3
- package/dist/src/gateway/service/run-gateway-agent.d.ts +4 -3
- package/dist/src/gateway/service/run-gateway-agent.js +15 -17
- package/dist/src/gateway/service/session-input-coordinator.d.ts +3 -0
- package/dist/src/gateway/service/session-input-coordinator.js +4 -2
- package/dist/src/gateway/service/types.d.ts +0 -5
- package/dist/src/gateway/service.d.ts +7 -6
- package/dist/src/gateway/service.js +43 -26
- package/dist/src/infra/update-runner.js +1 -1
- package/dist/src/knowledge/connected-knowledge-pipeline.js +1 -1
- package/dist/src/knowledge/connected-understanding-pipeline.d.ts +2 -4
- package/dist/src/knowledge/connected-understanding-pipeline.js +31 -81
- package/dist/src/knowledge/index.js +2 -2
- package/dist/src/knowledge/people-graph.d.ts +22 -25
- package/dist/src/knowledge/people-graph.js +76 -43
- package/dist/src/mcp/channel-bridge.d.ts +6 -9
- package/dist/src/mcp/channel-bridge.js +48 -76
- package/dist/src/mcp/channel-server.js +2 -6
- package/dist/src/proactive/execution/context.js +8 -13
- package/dist/src/realtime/broker.d.ts +31 -0
- package/dist/src/realtime/broker.js +114 -0
- package/dist/src/realtime/runtime.d.ts +20 -0
- package/dist/src/realtime/runtime.js +263 -0
- package/dist/src/realtime/tickets.d.ts +15 -0
- package/dist/src/realtime/tickets.js +38 -0
- package/dist/src/realtime/writer.d.ts +15 -0
- package/dist/src/realtime/writer.js +78 -0
- package/dist/src/share/share-config.js +0 -1
- package/dist/src/share/site-share-config.js +0 -1
- package/dist/src/storage/sqlite/connector-account-repository.js +0 -1
- package/dist/src/storage/sqlite/context-consolidation-repository.d.ts +37 -0
- package/dist/src/storage/sqlite/context-consolidation-repository.js +64 -0
- package/dist/src/storage/sqlite/endpoint-principal-repository.d.ts +17 -0
- package/dist/src/storage/sqlite/endpoint-principal-repository.js +54 -0
- package/dist/src/storage/sqlite/endpoint-tool-invocation-repository.d.ts +25 -0
- package/dist/src/storage/sqlite/endpoint-tool-invocation-repository.js +42 -0
- package/dist/src/storage/sqlite/fts.d.ts +2 -0
- package/dist/src/storage/sqlite/fts.js +29 -1
- package/dist/src/storage/sqlite/index.d.ts +6 -6
- package/dist/src/storage/sqlite/index.js +7 -7
- package/dist/src/storage/sqlite/knowledge-repository.d.ts +9 -2
- package/dist/src/storage/sqlite/knowledge-repository.js +58 -10
- package/dist/src/storage/sqlite/memory-records-repository.d.ts +7 -56
- package/dist/src/storage/sqlite/memory-records-repository.js +68 -218
- package/dist/src/storage/sqlite/migrations/109_endpoint_principals.sql +14 -0
- package/dist/src/storage/sqlite/migrations/110_session_input_origin.sql +43 -0
- package/dist/src/storage/sqlite/migrations/111_endpoint_tool_invocations.sql +18 -0
- package/dist/src/storage/sqlite/migrations/112_endpoint_instance_bindings.sql +8 -0
- package/dist/src/storage/sqlite/migrations/113_memory_evidence_single_source.sql +54 -0
- package/dist/src/storage/sqlite/migrations/114_user_context_domain.sql +193 -0
- package/dist/src/storage/sqlite/migrations/115_remove_legacy_user_context.sql +6 -0
- package/dist/src/storage/sqlite/migrations/116_structured_context_consolidation.sql +38 -0
- package/dist/src/storage/sqlite/migrations/117_unified_understanding_sources.sql +110 -0
- package/dist/src/storage/sqlite/migrations/runner.d.ts +1 -1
- package/dist/src/storage/sqlite/migrations/runner.js +3 -3
- package/dist/src/storage/sqlite/migrations/runner.ts +1 -1
- package/dist/src/storage/sqlite/schema.js +1 -1
- package/dist/src/storage/sqlite/schema.sql +0 -20
- package/dist/src/storage/sqlite/session-input-repository.d.ts +3 -0
- package/dist/src/storage/sqlite/session-input-repository.js +5 -3
- package/dist/src/storage/sqlite/user-context-quality-repository.d.ts +34 -0
- package/dist/src/storage/sqlite/user-context-quality-repository.js +74 -0
- package/dist/src/storage/sqlite/user-context-repository.d.ts +64 -0
- package/dist/src/storage/sqlite/user-context-repository.js +383 -0
- package/dist/src/tasks/home-query-service.d.ts +1 -1
- package/dist/src/tui/backends/embedded-backend.js +5 -2
- package/dist/src/tui/backends/{gateway-sse-backend.d.ts → gateway-realtime-backend.d.ts} +13 -10
- package/dist/src/tui/backends/{gateway-sse-backend.js → gateway-realtime-backend.js} +114 -151
- package/dist/src/tui/tool-summary.js +1 -7
- package/dist/src/tui/tui-agent-events.d.ts +0 -1
- package/dist/src/tui/tui-agent-events.js +2 -15
- package/dist/src/tui/tui-backend.d.ts +4 -4
- package/dist/src/tui/tui-run-state.js +0 -4
- package/dist/src/tui/tui-startup-resources.js +1 -2
- package/dist/src/tui/tui-types.d.ts +2 -9
- package/dist/src/tui/tui-types.js +0 -1
- package/dist/src/tui/tui.js +5 -5
- package/dist/src/tunnel/gateway-lifecycle.d.ts +1 -1
- package/dist/src/tunnel/gateway-lifecycle.js +1 -1
- package/dist/src/user-context/config.d.ts +17 -210
- package/dist/src/user-context/config.js +19 -85
- package/dist/src/user-context/consolidation.d.ts +26 -0
- package/dist/src/user-context/consolidation.js +115 -0
- package/dist/src/user-context/domain.d.ts +75 -0
- package/dist/src/user-context/domain.js +4 -0
- package/dist/src/user-context/manual-understanding.d.ts +7 -14
- package/dist/src/user-context/manual-understanding.js +19 -49
- package/dist/src/{agent/memory/context → user-context}/planner.d.ts +5 -6
- package/dist/src/user-context/planner.js +311 -0
- package/dist/src/user-context/relationship-continuity.d.ts +3 -6
- package/dist/src/user-context/relationship-continuity.js +39 -32
- package/dist/src/user-context/sources/catalog.d.ts +2 -0
- package/dist/src/user-context/sources/catalog.js +149 -0
- package/dist/src/user-context/sources/index.d.ts +3 -0
- package/dist/src/user-context/sources/index.js +3 -0
- package/dist/src/user-context/sources/repository.d.ts +40 -0
- package/dist/src/user-context/sources/repository.js +164 -0
- package/dist/src/user-context/sources/types.d.ts +83 -0
- package/dist/src/user-context/understandingQuality.d.ts +5 -0
- package/dist/src/user-context/understandingQuality.js +44 -0
- package/dist/src/utils/logger/log-stream.d.ts +3 -10
- package/dist/src/utils/logger/log-stream.js +2 -73
- package/dist/src/utils/logger/pino-record.d.ts +1 -1
- package/dist/src/utils/logger/streams.js +1 -1
- package/dist/src/work-discovery/analyzer.d.ts +4 -3
- package/dist/src/work-discovery/analyzer.js +21 -16
- package/dist/src/work-discovery/incremental-repository.js +42 -40
- package/dist/src/work-discovery/index.js +3 -3
- package/dist/src/work-discovery/service.d.ts +7 -7
- package/dist/src/work-discovery/service.js +241 -190
- package/dist/src/work-discovery/source-repository.js +42 -53
- package/dist/src/work-discovery/types.d.ts +2 -14
- package/package.json +5 -7
- package/dist/gateway/static/root/assets/agents-C6OV-gMm.js +0 -2
- package/dist/gateway/static/root/assets/apps-page-Ci14lDeO.js +0 -1
- package/dist/gateway/static/root/assets/automations-page-Q1xmb4Rh.js +0 -6
- package/dist/gateway/static/root/assets/browser-settings-page-DbowrHXD.js +0 -8
- package/dist/gateway/static/root/assets/capabilities-settings-panel-DoZPFdKF.js +0 -7
- package/dist/gateway/static/root/assets/capability-presets-api-Dn-7MMEo.js +0 -1
- package/dist/gateway/static/root/assets/capability-presets-settings-panel-Bt8Hnx0h.js +0 -1
- package/dist/gateway/static/root/assets/channels-settings-Bpsebsru.js +0 -1
- package/dist/gateway/static/root/assets/channels-status-swr-DFmdYRE5.js +0 -1
- package/dist/gateway/static/root/assets/connector-logo-TRr9ybf6.js +0 -1
- package/dist/gateway/static/root/assets/connectors-page-Tg5kl22i.js +0 -2
- package/dist/gateway/static/root/assets/cron-expression-B3B1eqnr.js +0 -2
- package/dist/gateway/static/root/assets/extension-settings-page-C9ag5tb5.js +0 -1
- package/dist/gateway/static/root/assets/gateway-settings-9g8uIry9.js +0 -1
- package/dist/gateway/static/root/assets/heartbeat-settings-fl1oC_-5.js +0 -1
- package/dist/gateway/static/root/assets/home-page-Bao9jq_z.js +0 -3
- package/dist/gateway/static/root/assets/index-Cl5n1f_U.css +0 -1
- package/dist/gateway/static/root/assets/index-OJgiMh07.js +0 -223
- package/dist/gateway/static/root/assets/local-app-workbench-page-B69NvtvH.js +0 -2
- package/dist/gateway/static/root/assets/locale-store-D6hs74o5.js +0 -1
- package/dist/gateway/static/root/assets/logs-page-Cq3cABqg.js +0 -7
- package/dist/gateway/static/root/assets/messages-D02NNLCZ.js +0 -3
- package/dist/gateway/static/root/assets/notes-workbench-BOZfJFhE.js +0 -4
- package/dist/gateway/static/root/assets/product-delivery-C8JbSj5Y.js +0 -1
- package/dist/gateway/static/root/assets/project-detail-page-TSKFb2tN.js +0 -1
- package/dist/gateway/static/root/assets/projects-page-BokeBrTT.js +0 -1
- package/dist/gateway/static/root/assets/remote-access-hub-C56anxCX.js +0 -1
- package/dist/gateway/static/root/assets/segmented-styles-BL8oLBEp.js +0 -1
- package/dist/gateway/static/root/assets/sessions-page-C7TQADrD.js +0 -1
- package/dist/gateway/static/root/assets/settings-advanced-gate-BDOPKeAX.js +0 -1
- package/dist/gateway/static/root/assets/settings-form-section-zxo5ZGOu.js +0 -1
- package/dist/gateway/static/root/assets/settings-page-BUPSIa9P.js +0 -1
- package/dist/gateway/static/root/assets/setup-status-panel-BRg766eW.js +0 -1
- package/dist/gateway/static/root/assets/shares-settings-DhEAviQ_.js +0 -1
- package/dist/gateway/static/root/assets/skill-reload-api-Ct7AV8ls.js +0 -1
- package/dist/gateway/static/root/assets/skills-page-DoVuprZm.js +0 -2
- package/dist/gateway/static/root/assets/time-picker-BGk_Tbsj.js +0 -1
- package/dist/gateway/static/root/assets/use-save-bar-registration-5aVSjTjO.js +0 -1
- package/dist/gateway/static/root/assets/user-context-page-B9K41qmy.js +0 -1
- package/dist/gateway/static/root/assets/work-discovery-page-BBVnRHju.js +0 -1
- package/dist/gateway/static/root/assets/workflows-page-Bs_tYfst.js +0 -11
- package/dist/src/agent/code-intelligence/binary.d.ts +0 -15
- package/dist/src/agent/code-intelligence/binary.js +0 -372
- package/dist/src/agent/code-intelligence/index.d.ts +0 -4
- package/dist/src/agent/code-intelligence/index.js +0 -4
- package/dist/src/agent/code-intelligence/runtime.d.ts +0 -34
- package/dist/src/agent/code-intelligence/runtime.js +0 -280
- package/dist/src/agent/code-intelligence/tool-gating.d.ts +0 -5
- package/dist/src/agent/code-intelligence/tool-gating.js +0 -6
- package/dist/src/agent/code-intelligence/tools.d.ts +0 -6
- package/dist/src/agent/code-intelligence/tools.js +0 -266
- package/dist/src/agent/code-intelligence/types.d.ts +0 -22
- package/dist/src/agent/memory/context/planner.js +0 -286
- package/dist/src/agent/memory/dreaming/config.d.ts +0 -48
- package/dist/src/agent/memory/dreaming/config.js +0 -98
- package/dist/src/agent/memory/dreaming/constants.d.ts +0 -12
- package/dist/src/agent/memory/dreaming/constants.js +0 -18
- package/dist/src/agent/memory/dreaming/deep-promotion.d.ts +0 -19
- package/dist/src/agent/memory/dreaming/deep-promotion.js +0 -152
- package/dist/src/agent/memory/dreaming/light-sweep.d.ts +0 -16
- package/dist/src/agent/memory/dreaming/light-sweep.js +0 -115
- package/dist/src/agent/memory/dreaming/preview.d.ts +0 -23
- package/dist/src/agent/memory/dreaming/preview.js +0 -52
- package/dist/src/agent/memory/dreaming/promotion-lifecycle.d.ts +0 -16
- package/dist/src/agent/memory/dreaming/promotion-lifecycle.js +0 -44
- package/dist/src/agent/memory/dreaming/rem-patterns.d.ts +0 -19
- package/dist/src/agent/memory/dreaming/rem-patterns.js +0 -150
- package/dist/src/agent/memory/dreaming/runner.d.ts +0 -10
- package/dist/src/agent/memory/dreaming/runner.js +0 -78
- package/dist/src/agent/memory/dreaming/schedule.d.ts +0 -23
- package/dist/src/agent/memory/dreaming/schedule.js +0 -38
- package/dist/src/agent/memory/dreaming/scope.d.ts +0 -11
- package/dist/src/agent/memory/dreaming/scope.js +0 -33
- package/dist/src/agent/memory/dreaming/utils.d.ts +0 -3
- package/dist/src/agent/memory/dreaming/utils.js +0 -31
- package/dist/src/agent/streaming/reasoning-visibility-sse.d.ts +0 -15
- package/dist/src/gateway/agent-run-relay.d.ts +0 -19
- package/dist/src/gateway/agent-run-relay.js +0 -169
- package/dist/src/gateway/hono/routes/memory.d.ts +0 -3
- package/dist/src/gateway/hono/routes/memory.js +0 -460
- package/dist/src/gateway/hono/sse.d.ts +0 -53
- package/dist/src/gateway/hono/sse.js +0 -207
- package/dist/src/gateway/service/sse-hub.d.ts +0 -10
- package/dist/src/gateway/service/sse-hub.js +0 -53
- package/dist/src/storage/sqlite/dreaming-repository.d.ts +0 -61
- package/dist/src/storage/sqlite/dreaming-repository.js +0 -88
- package/dist/src/storage/sqlite/memory-readiness-repository.d.ts +0 -7
- package/dist/src/storage/sqlite/memory-readiness-repository.js +0 -30
- package/dist/src/storage/sqlite/memory-reference-consent-repository.d.ts +0 -27
- package/dist/src/storage/sqlite/memory-reference-consent-repository.js +0 -107
- package/dist/src/storage/sqlite/user-claims-repository.d.ts +0 -101
- package/dist/src/storage/sqlite/user-claims-repository.js +0 -241
- package/dist/src/storage/sqlite/user-profile-setup-repository.d.ts +0 -3
- package/dist/src/storage/sqlite/user-profile-setup-repository.js +0 -32
- package/dist/src/tui/sse-consumer.d.ts +0 -15
- package/dist/src/tui/sse-consumer.js +0 -73
- package/dist/src/user-context/context-compiler.d.ts +0 -27
- package/dist/src/user-context/context-compiler.js +0 -48
- package/dist/src/user-context/import.d.ts +0 -12
- package/dist/src/user-context/import.js +0 -51
- package/dist/src/user-context/memory-episode-evaluator.d.ts +0 -32
- package/dist/src/user-context/memory-episode-evaluator.js +0 -35
- package/dist/src/user-context/memory-readiness.d.ts +0 -33
- package/dist/src/user-context/memory-readiness.js +0 -41
- package/dist/src/user-context/memory-use-audit.d.ts +0 -10
- package/dist/src/user-context/memory-use-audit.js +0 -26
- package/dist/src/user-context/personal-playbook.d.ts +0 -11
- package/dist/src/user-context/personal-playbook.js +0 -41
- package/dist/src/user-context/profile.d.ts +0 -37
- package/dist/src/user-context/profile.js +0 -163
- package/dist/src/user-context/projection.d.ts +0 -120
- package/dist/src/user-context/projection.js +0 -262
- package/dist/src/user-context/source-recommendations.d.ts +0 -13
- package/dist/src/user-context/source-recommendations.js +0 -85
- /package/dist/src/{agent/code-intelligence → user-context/sources}/types.js +0 -0
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
import { createLogger } from "../utils/logger/index.js";
|
|
2
|
+
import { init_logger } from "../utils/logger.js";
|
|
3
|
+
import { REALTIME_HEARTBEAT_INTERVAL_MS, REALTIME_HEARTBEAT_TIMEOUT_MS, REALTIME_HELLO_TIMEOUT_MS, REALTIME_MAX_CLIENT_FRAME_BYTES, parseClientRealtimeJsonFrame, parseClientRealtimeMessage } from "../../packages/realtime-protocol/src/index.js";
|
|
4
|
+
import { createPreauthConnectionBudget } from "../gateway/security/preauth-connection-budget.js";
|
|
5
|
+
import { RealtimeBroker } from "./broker.js";
|
|
6
|
+
import { RealtimeTicketStore } from "./tickets.js";
|
|
7
|
+
import { RealtimeSocketWriter } from "./writer.js";
|
|
8
|
+
import { createRequire } from "node:module";
|
|
9
|
+
import crypto from "node:crypto";
|
|
10
|
+
//#region src/realtime/runtime.ts
|
|
11
|
+
init_logger();
|
|
12
|
+
const log = createLogger("Realtime");
|
|
13
|
+
const { WebSocketServer } = createRequire(import.meta.url)("ws");
|
|
14
|
+
const REALTIME_WS_PATH = "/api/realtime/v1/ws";
|
|
15
|
+
const MAX_MESSAGE_CLOCK_SKEW_MS = 6e4;
|
|
16
|
+
const MAX_SUBSCRIPTIONS = 100;
|
|
17
|
+
const MAX_CONNECTIONS = 100;
|
|
18
|
+
function serverMessage(kind, payload) {
|
|
19
|
+
return {
|
|
20
|
+
protocolVersion: 1,
|
|
21
|
+
messageId: crypto.randomUUID(),
|
|
22
|
+
kind,
|
|
23
|
+
sentAt: Date.now(),
|
|
24
|
+
payload
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
function isAuthorizedTopic(topic) {
|
|
28
|
+
return topic === "gateway" || topic === "sessions" || topic === "logs" || topic.startsWith("session:") && topic.length > 8 || topic.startsWith("run:") && topic.length > 4 || topic.startsWith("workflow:") && topic.length > 9;
|
|
29
|
+
}
|
|
30
|
+
var RealtimeRuntime = class {
|
|
31
|
+
broker = new RealtimeBroker(void 0, (error, topic) => {
|
|
32
|
+
log.warn({
|
|
33
|
+
err: error,
|
|
34
|
+
topic
|
|
35
|
+
}, "Realtime subscriber failed");
|
|
36
|
+
});
|
|
37
|
+
tickets = new RealtimeTicketStore();
|
|
38
|
+
preauthBudget = createPreauthConnectionBudget();
|
|
39
|
+
wss = new WebSocketServer({
|
|
40
|
+
noServer: true,
|
|
41
|
+
maxPayload: REALTIME_MAX_CLIENT_FRAME_BYTES,
|
|
42
|
+
perMessageDeflate: false
|
|
43
|
+
});
|
|
44
|
+
topicCleanupTimers = /* @__PURE__ */ new Map();
|
|
45
|
+
closed = false;
|
|
46
|
+
constructor(endpointTools) {
|
|
47
|
+
this.endpointTools = endpointTools;
|
|
48
|
+
this.wss.on("connection", (socket, request) => this.handleConnection(socket, request));
|
|
49
|
+
this.wss.on("error", (err) => log.error({ err }, "Realtime WebSocket server failed"));
|
|
50
|
+
}
|
|
51
|
+
handleUpgrade(req, socket, head) {
|
|
52
|
+
if (new URL(req.url ?? "/", "http://gateway.local").pathname !== REALTIME_WS_PATH) return false;
|
|
53
|
+
if (this.closed) {
|
|
54
|
+
socket.destroy();
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
if (this.wss.clients.size >= MAX_CONNECTIONS) {
|
|
58
|
+
socket.destroy();
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
const clientIp = req.socket.remoteAddress;
|
|
62
|
+
if (!this.preauthBudget.acquire(clientIp)) {
|
|
63
|
+
socket.destroy();
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
try {
|
|
67
|
+
this.wss.handleUpgrade(req, socket, head, (ws) => {
|
|
68
|
+
this.wss.emit("connection", ws, req);
|
|
69
|
+
});
|
|
70
|
+
} catch (error) {
|
|
71
|
+
this.preauthBudget.release(clientIp);
|
|
72
|
+
throw error;
|
|
73
|
+
}
|
|
74
|
+
return true;
|
|
75
|
+
}
|
|
76
|
+
close() {
|
|
77
|
+
if (this.closed) return;
|
|
78
|
+
this.closed = true;
|
|
79
|
+
for (const client of this.wss.clients) client.close(1001, "Gateway stopping");
|
|
80
|
+
for (const timer of this.topicCleanupTimers.values()) clearTimeout(timer);
|
|
81
|
+
this.topicCleanupTimers.clear();
|
|
82
|
+
this.wss.close();
|
|
83
|
+
}
|
|
84
|
+
completeTopic(topic, ttlMs = 5 * 6e4) {
|
|
85
|
+
const existing = this.topicCleanupTimers.get(topic);
|
|
86
|
+
if (existing) clearTimeout(existing);
|
|
87
|
+
this.topicCleanupTimers.set(topic, setTimeout(() => {
|
|
88
|
+
this.topicCleanupTimers.delete(topic);
|
|
89
|
+
this.broker.removeTopic(topic);
|
|
90
|
+
}, ttlMs));
|
|
91
|
+
}
|
|
92
|
+
handleConnection(socket, request) {
|
|
93
|
+
const clientIp = request.socket.remoteAddress;
|
|
94
|
+
const writer = new RealtimeSocketWriter(socket);
|
|
95
|
+
const subscriptions = /* @__PURE__ */ new Map();
|
|
96
|
+
let authenticated = false;
|
|
97
|
+
let lastSeenAt = Date.now();
|
|
98
|
+
let connectionId;
|
|
99
|
+
let endpointId;
|
|
100
|
+
let budgetHeld = true;
|
|
101
|
+
const releaseBudget = () => {
|
|
102
|
+
if (!budgetHeld) return;
|
|
103
|
+
budgetHeld = false;
|
|
104
|
+
this.preauthBudget.release(clientIp);
|
|
105
|
+
};
|
|
106
|
+
const helloTimer = setTimeout(() => socket.close(4401, "Realtime hello timeout"), REALTIME_HELLO_TIMEOUT_MS);
|
|
107
|
+
const heartbeatTimer = setInterval(() => {
|
|
108
|
+
if (Date.now() - lastSeenAt > 45e3) socket.close(4408, "Realtime heartbeat timeout");
|
|
109
|
+
}, REALTIME_HEARTBEAT_INTERVAL_MS);
|
|
110
|
+
const sendError = (code, message) => {
|
|
111
|
+
writer.enqueue(serverMessage("realtime.error", {
|
|
112
|
+
code,
|
|
113
|
+
message
|
|
114
|
+
}), "critical");
|
|
115
|
+
};
|
|
116
|
+
const subscribe = (requested) => {
|
|
117
|
+
const authorized = requested.filter((item) => {
|
|
118
|
+
if (isAuthorizedTopic(item.topic)) return true;
|
|
119
|
+
sendError("FORBIDDEN_TOPIC", `Topic is not available: ${item.topic}`);
|
|
120
|
+
return false;
|
|
121
|
+
});
|
|
122
|
+
if (new Set([...subscriptions.keys(), ...authorized.map((item) => item.topic)]).size > MAX_SUBSCRIPTIONS) {
|
|
123
|
+
sendError("TOO_MANY_SUBSCRIPTIONS", `At most ${MAX_SUBSCRIPTIONS} topics may be subscribed`);
|
|
124
|
+
return false;
|
|
125
|
+
}
|
|
126
|
+
for (const item of authorized) {
|
|
127
|
+
if (item.topic.startsWith("run:") && item.afterSeq !== void 0 && !this.broker.hasTopic(item.topic)) {
|
|
128
|
+
writer.enqueue(serverMessage("realtime.gap", {
|
|
129
|
+
topic: item.topic,
|
|
130
|
+
requestedSeq: item.afterSeq,
|
|
131
|
+
earliestSeq: 1,
|
|
132
|
+
recoverable: false
|
|
133
|
+
}));
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
subscriptions.get(item.topic)?.unsubscribe();
|
|
137
|
+
const handle = this.broker.subscribe(item.topic, item.afterSeq, (event) => {
|
|
138
|
+
writer.enqueue(event);
|
|
139
|
+
});
|
|
140
|
+
subscriptions.set(item.topic, handle);
|
|
141
|
+
writer.enqueue(serverMessage("realtime.subscribed", {
|
|
142
|
+
topic: item.topic,
|
|
143
|
+
cursor: handle.cursor
|
|
144
|
+
}), "critical");
|
|
145
|
+
for (const message of handle.initial) writer.enqueue(message);
|
|
146
|
+
}
|
|
147
|
+
return true;
|
|
148
|
+
};
|
|
149
|
+
socket.on("message", (data, isBinary) => {
|
|
150
|
+
if (isBinary) {
|
|
151
|
+
socket.close(4400, "Binary realtime frames are not supported");
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
let message;
|
|
155
|
+
try {
|
|
156
|
+
message = parseClientRealtimeMessage(parseClientRealtimeJsonFrame(this.rawDataToText(data)));
|
|
157
|
+
if (Math.abs(Date.now() - message.sentAt) > MAX_MESSAGE_CLOCK_SKEW_MS) throw new Error("Realtime message timestamp is outside the allowed window");
|
|
158
|
+
} catch (error) {
|
|
159
|
+
log.warn({ err: error }, "Realtime client sent an invalid frame");
|
|
160
|
+
socket.close(4400, "Invalid realtime protocol frame");
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
lastSeenAt = Date.now();
|
|
164
|
+
if (!authenticated) {
|
|
165
|
+
if (message.kind !== "realtime.hello") {
|
|
166
|
+
socket.close(4401, "First realtime message must be hello");
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
const claim = this.tickets.consume(message.payload.ticket, message.payload.clientId, message.payload.clientKind);
|
|
170
|
+
if (!claim) {
|
|
171
|
+
socket.close(4401, "Realtime authentication failed");
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
authenticated = true;
|
|
175
|
+
connectionId = crypto.randomUUID();
|
|
176
|
+
let endpointReady;
|
|
177
|
+
if (message.payload.endpoint) {
|
|
178
|
+
if (!this.endpointTools || message.payload.endpoint.kind !== message.payload.clientKind) {
|
|
179
|
+
socket.close(4401, "Realtime endpoint identity is invalid");
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
const transport = {
|
|
183
|
+
get readyState() {
|
|
184
|
+
return socket.readyState;
|
|
185
|
+
},
|
|
186
|
+
send: (data) => {
|
|
187
|
+
writer.enqueue(serverMessage("endpoint.message", JSON.parse(data)), "critical");
|
|
188
|
+
},
|
|
189
|
+
close: (code, reason) => socket.close(code, reason)
|
|
190
|
+
};
|
|
191
|
+
try {
|
|
192
|
+
const registration = this.endpointTools.connect(message.payload.endpoint, connectionId, transport);
|
|
193
|
+
endpointId = message.payload.endpoint.endpointId;
|
|
194
|
+
endpointReady = {
|
|
195
|
+
endpointId,
|
|
196
|
+
turnToken: registration.turnToken
|
|
197
|
+
};
|
|
198
|
+
} catch (error) {
|
|
199
|
+
log.warn({
|
|
200
|
+
err: error,
|
|
201
|
+
principalId: message.payload.endpoint.principalId
|
|
202
|
+
}, "Realtime endpoint authentication failed");
|
|
203
|
+
socket.close(4401, "Realtime endpoint authentication failed");
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
clearTimeout(helloTimer);
|
|
208
|
+
releaseBudget();
|
|
209
|
+
writer.enqueue(serverMessage("realtime.ready", {
|
|
210
|
+
connectionId,
|
|
211
|
+
heartbeatIntervalMs: REALTIME_HEARTBEAT_INTERVAL_MS,
|
|
212
|
+
heartbeatTimeoutMs: REALTIME_HEARTBEAT_TIMEOUT_MS,
|
|
213
|
+
...endpointReady ? { endpoint: endpointReady } : {}
|
|
214
|
+
}), "critical");
|
|
215
|
+
subscribe(message.payload.subscriptions);
|
|
216
|
+
log.info({
|
|
217
|
+
connectionId,
|
|
218
|
+
clientId: claim.clientId,
|
|
219
|
+
clientKind: claim.clientKind
|
|
220
|
+
}, "Realtime client connected");
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
if (message.kind === "realtime.hello") socket.close(4400, "Realtime hello may only be sent once");
|
|
224
|
+
else if (message.kind === "realtime.subscribe") subscribe(message.payload.subscriptions);
|
|
225
|
+
else if (message.kind === "realtime.unsubscribe") for (const topic of message.payload.topics) {
|
|
226
|
+
subscriptions.get(topic)?.unsubscribe();
|
|
227
|
+
subscriptions.delete(topic);
|
|
228
|
+
}
|
|
229
|
+
else if (message.kind === "realtime.ping") {
|
|
230
|
+
if (endpointId && connectionId) this.endpointTools?.touch(endpointId, connectionId);
|
|
231
|
+
writer.enqueue(serverMessage("realtime.pong", {}), "critical");
|
|
232
|
+
} else if (!endpointId || !connectionId || !this.endpointTools) sendError("ENDPOINT_NOT_REGISTERED", "Endpoint messages require an endpoint identity");
|
|
233
|
+
else try {
|
|
234
|
+
this.endpointTools.handleMessage(endpointId, connectionId, message.payload);
|
|
235
|
+
} catch (error) {
|
|
236
|
+
log.warn({
|
|
237
|
+
err: error,
|
|
238
|
+
endpointId,
|
|
239
|
+
connectionId
|
|
240
|
+
}, "Realtime endpoint message failed");
|
|
241
|
+
socket.close(4400, "Invalid endpoint message");
|
|
242
|
+
}
|
|
243
|
+
});
|
|
244
|
+
socket.on("close", () => {
|
|
245
|
+
clearTimeout(helloTimer);
|
|
246
|
+
clearInterval(heartbeatTimer);
|
|
247
|
+
releaseBudget();
|
|
248
|
+
writer.close();
|
|
249
|
+
for (const handle of subscriptions.values()) handle.unsubscribe();
|
|
250
|
+
subscriptions.clear();
|
|
251
|
+
if (endpointId && connectionId) this.endpointTools?.remove(endpointId, connectionId);
|
|
252
|
+
if (connectionId) log.info({ connectionId }, "Realtime client disconnected");
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
rawDataToText(data) {
|
|
256
|
+
if (typeof data === "string") return data;
|
|
257
|
+
if (Array.isArray(data)) return Buffer.concat(data).toString("utf8");
|
|
258
|
+
if (data instanceof ArrayBuffer) return Buffer.from(data).toString("utf8");
|
|
259
|
+
return data.toString("utf8");
|
|
260
|
+
}
|
|
261
|
+
};
|
|
262
|
+
//#endregion
|
|
263
|
+
export { RealtimeRuntime };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { RealtimeClientKind } from '@xopcai/realtime-protocol';
|
|
2
|
+
export interface RealtimeTicketClaim {
|
|
3
|
+
clientId: string;
|
|
4
|
+
clientKind: RealtimeClientKind;
|
|
5
|
+
expiresAt: number;
|
|
6
|
+
}
|
|
7
|
+
export interface IssuedRealtimeTicket extends RealtimeTicketClaim {
|
|
8
|
+
ticket: string;
|
|
9
|
+
}
|
|
10
|
+
export declare class RealtimeTicketStore {
|
|
11
|
+
private readonly claims;
|
|
12
|
+
issue(clientId: string, clientKind: RealtimeClientKind, now?: number): IssuedRealtimeTicket;
|
|
13
|
+
consume(ticket: string, clientId: string, clientKind: RealtimeClientKind, now?: number): RealtimeTicketClaim | undefined;
|
|
14
|
+
private prune;
|
|
15
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import crypto from "node:crypto";
|
|
2
|
+
//#region src/realtime/tickets.ts
|
|
3
|
+
const TICKET_TTL_MS = 3e4;
|
|
4
|
+
const MAX_OUTSTANDING_TICKETS = 1e3;
|
|
5
|
+
function ticketKey(ticket) {
|
|
6
|
+
return crypto.createHash("sha256").update(ticket).digest("hex");
|
|
7
|
+
}
|
|
8
|
+
var RealtimeTicketStore = class {
|
|
9
|
+
claims = /* @__PURE__ */ new Map();
|
|
10
|
+
issue(clientId, clientKind, now = Date.now()) {
|
|
11
|
+
this.prune(now);
|
|
12
|
+
if (this.claims.size >= MAX_OUTSTANDING_TICKETS) throw new Error("Too many outstanding realtime tickets");
|
|
13
|
+
const ticket = crypto.randomBytes(32).toString("base64url");
|
|
14
|
+
const claim = {
|
|
15
|
+
clientId,
|
|
16
|
+
clientKind,
|
|
17
|
+
expiresAt: now + TICKET_TTL_MS
|
|
18
|
+
};
|
|
19
|
+
this.claims.set(ticketKey(ticket), claim);
|
|
20
|
+
return {
|
|
21
|
+
ticket,
|
|
22
|
+
...claim
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
consume(ticket, clientId, clientKind, now = Date.now()) {
|
|
26
|
+
const key = ticketKey(ticket);
|
|
27
|
+
const claim = this.claims.get(key);
|
|
28
|
+
this.claims.delete(key);
|
|
29
|
+
if (!claim || claim.expiresAt < now) return void 0;
|
|
30
|
+
if (claim.clientId !== clientId || claim.clientKind !== clientKind) return void 0;
|
|
31
|
+
return claim;
|
|
32
|
+
}
|
|
33
|
+
prune(now) {
|
|
34
|
+
for (const [key, claim] of this.claims) if (claim.expiresAt < now) this.claims.delete(key);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
//#endregion
|
|
38
|
+
export { RealtimeTicketStore };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ServerRealtimeMessage } from '@xopcai/realtime-protocol';
|
|
2
|
+
import type { WebSocket } from 'ws';
|
|
3
|
+
export declare class RealtimeSocketWriter {
|
|
4
|
+
private readonly socket;
|
|
5
|
+
private readonly critical;
|
|
6
|
+
private readonly normal;
|
|
7
|
+
private queuedBytes;
|
|
8
|
+
private sending;
|
|
9
|
+
private closed;
|
|
10
|
+
private retryTimer?;
|
|
11
|
+
constructor(socket: WebSocket);
|
|
12
|
+
enqueue(message: ServerRealtimeMessage, priority?: 'critical' | 'normal'): boolean;
|
|
13
|
+
close(): void;
|
|
14
|
+
private flush;
|
|
15
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
//#region src/realtime/writer.ts
|
|
2
|
+
const SOFT_BUFFERED_BYTES = 512 * 1024;
|
|
3
|
+
const HARD_BUFFERED_BYTES = 4 * 1024 * 1024;
|
|
4
|
+
const MAX_QUEUED_BYTES = 2 * 1024 * 1024;
|
|
5
|
+
var RealtimeSocketWriter = class {
|
|
6
|
+
critical = [];
|
|
7
|
+
normal = [];
|
|
8
|
+
queuedBytes = 0;
|
|
9
|
+
sending = false;
|
|
10
|
+
closed = false;
|
|
11
|
+
retryTimer;
|
|
12
|
+
constructor(socket) {
|
|
13
|
+
this.socket = socket;
|
|
14
|
+
}
|
|
15
|
+
enqueue(message, priority = "normal") {
|
|
16
|
+
if (this.closed || this.socket.readyState !== 1) return false;
|
|
17
|
+
let data;
|
|
18
|
+
try {
|
|
19
|
+
data = JSON.stringify(message);
|
|
20
|
+
} catch {
|
|
21
|
+
this.socket.close(1011, "Realtime message serialization failed");
|
|
22
|
+
this.close();
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
const item = {
|
|
26
|
+
data,
|
|
27
|
+
bytes: Buffer.byteLength(data)
|
|
28
|
+
};
|
|
29
|
+
if (this.queuedBytes + item.bytes > MAX_QUEUED_BYTES) {
|
|
30
|
+
this.socket.close(4413, "Realtime client is too slow");
|
|
31
|
+
this.close();
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
this.queuedBytes += item.bytes;
|
|
35
|
+
(priority === "critical" ? this.critical : this.normal).push(item);
|
|
36
|
+
this.flush();
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
close() {
|
|
40
|
+
if (this.closed) return;
|
|
41
|
+
this.closed = true;
|
|
42
|
+
if (this.retryTimer) clearTimeout(this.retryTimer);
|
|
43
|
+
this.retryTimer = void 0;
|
|
44
|
+
this.critical.length = 0;
|
|
45
|
+
this.normal.length = 0;
|
|
46
|
+
this.queuedBytes = 0;
|
|
47
|
+
}
|
|
48
|
+
flush() {
|
|
49
|
+
if (this.closed || this.sending || this.socket.readyState !== 1) return;
|
|
50
|
+
if (this.socket.bufferedAmount > HARD_BUFFERED_BYTES) {
|
|
51
|
+
this.socket.close(4413, "Realtime client is too slow");
|
|
52
|
+
this.close();
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
if (this.socket.bufferedAmount > SOFT_BUFFERED_BYTES) {
|
|
56
|
+
if (!this.retryTimer) this.retryTimer = setTimeout(() => {
|
|
57
|
+
this.retryTimer = void 0;
|
|
58
|
+
this.flush();
|
|
59
|
+
}, 10);
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
const item = this.critical.shift() ?? this.normal.shift();
|
|
63
|
+
if (!item) return;
|
|
64
|
+
this.sending = true;
|
|
65
|
+
this.socket.send(item.data, (error) => {
|
|
66
|
+
this.sending = false;
|
|
67
|
+
this.queuedBytes -= item.bytes;
|
|
68
|
+
if (error) {
|
|
69
|
+
this.socket.close(1011, "Realtime delivery failed");
|
|
70
|
+
this.close();
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
this.flush();
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
//#endregion
|
|
78
|
+
export { RealtimeSocketWriter };
|
|
@@ -36,7 +36,6 @@ function mergeAccountSourceData(db, connectorId, sourceAccountId, targetAccountI
|
|
|
36
36
|
db.prepare("UPDATE knowledge_source_items SET source_instance_id = ? WHERE source_instance_id = ?").run(targetId, sourceId);
|
|
37
37
|
db.prepare("UPDATE knowledge_sync_runs SET source_instance_id = ? WHERE source_instance_id = ?").run(targetId, sourceId);
|
|
38
38
|
db.prepare("UPDATE knowledge_source_changes SET source_instance_id = ? WHERE source_instance_id = ?").run(targetId, sourceId);
|
|
39
|
-
db.prepare("UPDATE user_claim_evidence SET source_instance_id = ? WHERE source_instance_id = ?").run(targetId, sourceId);
|
|
40
39
|
db.prepare(`
|
|
41
40
|
DELETE FROM knowledge_collection_state AS source
|
|
42
41
|
WHERE source.source_instance_id = ?
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export type ContextConsolidationRun = {
|
|
2
|
+
runId: string;
|
|
3
|
+
triggerKind: 'schedule' | 'manual';
|
|
4
|
+
status: 'running' | 'completed' | 'failed';
|
|
5
|
+
reason?: string;
|
|
6
|
+
metrics: Record<string, unknown>;
|
|
7
|
+
startedAt: number;
|
|
8
|
+
completedAt?: number;
|
|
9
|
+
};
|
|
10
|
+
export type ContextConsolidationDecision = {
|
|
11
|
+
id: string;
|
|
12
|
+
runId: string;
|
|
13
|
+
understandingId?: string;
|
|
14
|
+
action: 'needs_review' | 'stale';
|
|
15
|
+
reasonCode: string;
|
|
16
|
+
evidenceCount: number;
|
|
17
|
+
createdAt: number;
|
|
18
|
+
};
|
|
19
|
+
export declare function startContextConsolidationRun(triggerKind: ContextConsolidationRun['triggerKind'], now?: number): ContextConsolidationRun;
|
|
20
|
+
export declare function finishContextConsolidationRun(input: {
|
|
21
|
+
runId: string;
|
|
22
|
+
ok: boolean;
|
|
23
|
+
reason: string;
|
|
24
|
+
metrics: Record<string, unknown>;
|
|
25
|
+
now?: number;
|
|
26
|
+
}): ContextConsolidationRun | undefined;
|
|
27
|
+
export declare function recordContextConsolidationDecision(input: {
|
|
28
|
+
runId: string;
|
|
29
|
+
understandingId: string;
|
|
30
|
+
action: ContextConsolidationDecision['action'];
|
|
31
|
+
reasonCode: string;
|
|
32
|
+
evidenceCount: number;
|
|
33
|
+
now?: number;
|
|
34
|
+
}): ContextConsolidationDecision;
|
|
35
|
+
export declare function getContextConsolidationRun(runId: string): ContextConsolidationRun | undefined;
|
|
36
|
+
export declare function listContextConsolidationRuns(limit?: number): ContextConsolidationRun[];
|
|
37
|
+
export declare function listContextConsolidationDecisions(runId: string): ContextConsolidationDecision[];
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { getSqliteDatabase } from "./transaction.js";
|
|
2
|
+
import { randomUUID } from "node:crypto";
|
|
3
|
+
//#region src/storage/sqlite/context-consolidation-repository.ts
|
|
4
|
+
function parseJson(value) {
|
|
5
|
+
try {
|
|
6
|
+
const parsed = JSON.parse(value);
|
|
7
|
+
return parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : {};
|
|
8
|
+
} catch {
|
|
9
|
+
return {};
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
function runFromRow(row) {
|
|
13
|
+
return {
|
|
14
|
+
runId: row.run_id,
|
|
15
|
+
triggerKind: row.trigger_kind,
|
|
16
|
+
status: row.status,
|
|
17
|
+
...row.reason ? { reason: row.reason } : {},
|
|
18
|
+
metrics: parseJson(row.metrics_json),
|
|
19
|
+
startedAt: row.started_at,
|
|
20
|
+
...row.completed_at == null ? {} : { completedAt: row.completed_at }
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
function startContextConsolidationRun(triggerKind, now = Date.now()) {
|
|
24
|
+
const runId = randomUUID();
|
|
25
|
+
getSqliteDatabase().prepare(`INSERT INTO context_consolidation_runs (
|
|
26
|
+
run_id, trigger_kind, status, started_at
|
|
27
|
+
) VALUES (?, ?, 'running', ?)`).run(runId, triggerKind, now);
|
|
28
|
+
return getContextConsolidationRun(runId);
|
|
29
|
+
}
|
|
30
|
+
function finishContextConsolidationRun(input) {
|
|
31
|
+
getSqliteDatabase().prepare(`UPDATE context_consolidation_runs
|
|
32
|
+
SET status = ?, reason = ?, metrics_json = ?, completed_at = ? WHERE run_id = ?`).run(input.ok ? "completed" : "failed", input.reason, JSON.stringify(input.metrics), input.now ?? Date.now(), input.runId);
|
|
33
|
+
return getContextConsolidationRun(input.runId);
|
|
34
|
+
}
|
|
35
|
+
function recordContextConsolidationDecision(input) {
|
|
36
|
+
const id = randomUUID();
|
|
37
|
+
getSqliteDatabase().prepare(`INSERT INTO context_consolidation_decisions (
|
|
38
|
+
decision_id, run_id, understanding_id, action, reason_code, evidence_count, created_at
|
|
39
|
+
) VALUES (?, ?, ?, ?, ?, ?, ?)`).run(id, input.runId, input.understandingId, input.action, input.reasonCode, input.evidenceCount, input.now ?? Date.now());
|
|
40
|
+
return listContextConsolidationDecisions(input.runId).find((item) => item.id === id);
|
|
41
|
+
}
|
|
42
|
+
function getContextConsolidationRun(runId) {
|
|
43
|
+
const row = getSqliteDatabase().prepare("SELECT * FROM context_consolidation_runs WHERE run_id = ?").get(runId);
|
|
44
|
+
return row ? runFromRow(row) : void 0;
|
|
45
|
+
}
|
|
46
|
+
function listContextConsolidationRuns(limit = 20) {
|
|
47
|
+
const safeLimit = Math.max(1, Math.min(200, limit));
|
|
48
|
+
return getSqliteDatabase().prepare(`SELECT * FROM context_consolidation_runs
|
|
49
|
+
ORDER BY started_at DESC LIMIT ?`).all(safeLimit).map(runFromRow);
|
|
50
|
+
}
|
|
51
|
+
function listContextConsolidationDecisions(runId) {
|
|
52
|
+
return getSqliteDatabase().prepare(`SELECT * FROM context_consolidation_decisions
|
|
53
|
+
WHERE run_id = ? ORDER BY created_at, decision_id`).all(runId).map((row) => ({
|
|
54
|
+
id: row.decision_id,
|
|
55
|
+
runId: row.run_id,
|
|
56
|
+
...row.understanding_id ? { understandingId: row.understanding_id } : {},
|
|
57
|
+
action: row.action,
|
|
58
|
+
reasonCode: row.reason_code,
|
|
59
|
+
evidenceCount: row.evidence_count,
|
|
60
|
+
createdAt: row.created_at
|
|
61
|
+
}));
|
|
62
|
+
}
|
|
63
|
+
//#endregion
|
|
64
|
+
export { finishContextConsolidationRun, getContextConsolidationRun, listContextConsolidationDecisions, listContextConsolidationRuns, recordContextConsolidationDecision, startContextConsolidationRun };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { EndpointKind } from '@xopcai/endpoint-tools-protocol';
|
|
2
|
+
export interface EndpointPrincipal {
|
|
3
|
+
id: string;
|
|
4
|
+
kind: EndpointKind;
|
|
5
|
+
displayName: string;
|
|
6
|
+
platform: string;
|
|
7
|
+
publicKey: string;
|
|
8
|
+
createdAt: number;
|
|
9
|
+
lastSeenAt?: number;
|
|
10
|
+
revokedAt?: number;
|
|
11
|
+
}
|
|
12
|
+
export declare function createEndpointPrincipal(principal: Omit<EndpointPrincipal, 'createdAt' | 'lastSeenAt' | 'revokedAt'>): EndpointPrincipal;
|
|
13
|
+
export declare function getEndpointPrincipal(id: string): EndpointPrincipal | undefined;
|
|
14
|
+
export declare function listEndpointPrincipals(): EndpointPrincipal[];
|
|
15
|
+
export declare function touchEndpointPrincipal(id: string, seenAt?: number): void;
|
|
16
|
+
export declare function bindEndpointPrincipal(endpointId: string, principalId: string, boundAt?: number): boolean;
|
|
17
|
+
export declare function revokeEndpointPrincipal(id: string, revokedAt?: number): boolean;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { getSqliteDatabase, runSqliteWriteTransaction } from "./transaction.js";
|
|
2
|
+
//#region src/storage/sqlite/endpoint-principal-repository.ts
|
|
3
|
+
function fromRow(row) {
|
|
4
|
+
return {
|
|
5
|
+
id: row.id,
|
|
6
|
+
kind: row.kind,
|
|
7
|
+
displayName: row.display_name,
|
|
8
|
+
platform: row.platform,
|
|
9
|
+
publicKey: row.public_key,
|
|
10
|
+
createdAt: row.created_at,
|
|
11
|
+
...row.last_seen_at === null ? {} : { lastSeenAt: row.last_seen_at },
|
|
12
|
+
...row.revoked_at === null ? {} : { revokedAt: row.revoked_at }
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
function createEndpointPrincipal(principal) {
|
|
16
|
+
const createdAt = Date.now();
|
|
17
|
+
runSqliteWriteTransaction((db) => {
|
|
18
|
+
db.prepare(`
|
|
19
|
+
INSERT INTO endpoint_principals (
|
|
20
|
+
id, kind, display_name, platform, public_key, created_at
|
|
21
|
+
) VALUES (?, ?, ?, ?, ?, ?)
|
|
22
|
+
`).run(principal.id, principal.kind, principal.displayName, principal.platform, principal.publicKey, createdAt);
|
|
23
|
+
});
|
|
24
|
+
return {
|
|
25
|
+
...principal,
|
|
26
|
+
createdAt
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
function getEndpointPrincipal(id) {
|
|
30
|
+
const row = getSqliteDatabase().prepare("SELECT * FROM endpoint_principals WHERE id = ?").get(id);
|
|
31
|
+
return row ? fromRow(row) : void 0;
|
|
32
|
+
}
|
|
33
|
+
function listEndpointPrincipals() {
|
|
34
|
+
return getSqliteDatabase().prepare("SELECT * FROM endpoint_principals ORDER BY created_at DESC").all().map(fromRow);
|
|
35
|
+
}
|
|
36
|
+
function touchEndpointPrincipal(id, seenAt = Date.now()) {
|
|
37
|
+
getSqliteDatabase().prepare("UPDATE endpoint_principals SET last_seen_at = ? WHERE id = ? AND revoked_at IS NULL").run(seenAt, id);
|
|
38
|
+
}
|
|
39
|
+
function bindEndpointPrincipal(endpointId, principalId, boundAt = Date.now()) {
|
|
40
|
+
return runSqliteWriteTransaction((db) => {
|
|
41
|
+
db.prepare(`
|
|
42
|
+
INSERT OR IGNORE INTO endpoint_instance_bindings (endpoint_id, principal_id, bound_at)
|
|
43
|
+
VALUES (?, ?, ?)
|
|
44
|
+
`).run(endpointId, principalId, boundAt);
|
|
45
|
+
return db.prepare(`
|
|
46
|
+
SELECT principal_id FROM endpoint_instance_bindings WHERE endpoint_id = ?
|
|
47
|
+
`).get(endpointId)?.principal_id === principalId;
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
function revokeEndpointPrincipal(id, revokedAt = Date.now()) {
|
|
51
|
+
return getSqliteDatabase().prepare("UPDATE endpoint_principals SET revoked_at = ? WHERE id = ? AND revoked_at IS NULL").run(revokedAt, id).changes > 0;
|
|
52
|
+
}
|
|
53
|
+
//#endregion
|
|
54
|
+
export { bindEndpointPrincipal, createEndpointPrincipal, getEndpointPrincipal, listEndpointPrincipals, revokeEndpointPrincipal, touchEndpointPrincipal };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { EndpointEffect, EndpointToolErrorCode } from '@xopcai/endpoint-tools-protocol';
|
|
2
|
+
export interface EndpointToolInvocationAudit {
|
|
3
|
+
id: string;
|
|
4
|
+
principalId: string;
|
|
5
|
+
endpointId: string;
|
|
6
|
+
toolCallId: string;
|
|
7
|
+
toolName: string;
|
|
8
|
+
effect: EndpointEffect;
|
|
9
|
+
confirmationRequired: boolean;
|
|
10
|
+
argumentsSha256: string;
|
|
11
|
+
status: 'running' | 'succeeded' | 'failed';
|
|
12
|
+
errorCode?: EndpointToolErrorCode;
|
|
13
|
+
errorMessage?: string;
|
|
14
|
+
startedAt: number;
|
|
15
|
+
completedAt?: number;
|
|
16
|
+
}
|
|
17
|
+
export declare function startEndpointToolInvocationAudit(audit: Omit<EndpointToolInvocationAudit, 'status' | 'completedAt' | 'errorCode' | 'errorMessage'>): void;
|
|
18
|
+
export declare function finishEndpointToolInvocationAudit(params: {
|
|
19
|
+
id: string;
|
|
20
|
+
status: 'succeeded' | 'failed';
|
|
21
|
+
errorCode?: EndpointToolErrorCode;
|
|
22
|
+
errorMessage?: string;
|
|
23
|
+
completedAt?: number;
|
|
24
|
+
}): void;
|
|
25
|
+
export declare function listEndpointToolInvocationAudits(limit?: number): EndpointToolInvocationAudit[];
|