@xopcai/xopc 0.0.332 → 0.0.333
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser-ext/manifest.json +1 -1
- package/dist/extensions/telegram/xopc.extension.json +1 -1
- package/dist/gateway/static/root/assets/{agent-avatar-dicebear-C2wg3xC_.js → agent-avatar-dicebear-DiI2O7lC.js} +1 -1
- package/dist/gateway/static/root/assets/agent-defaults-settings-panel-CVp3J969.js +1 -0
- package/dist/gateway/static/root/assets/{agent-plugin-dialog-BeNnu1Ts.js → agent-plugin-dialog-CacyndrS.js} +1 -1
- package/dist/gateway/static/root/assets/agents-DXYZSuUV.js +70 -0
- package/dist/gateway/static/root/assets/{app-management-settings-panel-etFSkfzl.js → app-management-settings-panel-BcszTlqr.js} +1 -1
- package/dist/gateway/static/root/assets/{appearance-settings-DKmU2VAP.js → appearance-settings-B1XPe8qz.js} +1 -1
- package/dist/gateway/static/root/assets/{apps-page-DVNySL58.js → apps-page-ZqANbUZv.js} +1 -1
- package/dist/gateway/static/root/assets/{archive-plugin-D0z_Fr2G.js → archive-plugin-MjUsJcNb.js} +1 -1
- package/dist/gateway/static/root/assets/{attachment-load-DNCDbeOX.js → attachment-load-DHa-BI9a.js} +1 -1
- package/dist/gateway/static/root/assets/{automations-page-B7_C-p66.js → automations-page-Dsjivdxs.js} +1 -1
- package/dist/gateway/static/root/assets/automations-workspace-B37vs5tk.js +7 -0
- package/dist/gateway/static/root/assets/{binary-plugins-BYn2hScX.js → binary-plugins-DQYcuBHP.js} +1 -1
- package/dist/gateway/static/root/assets/{block-editor-ChWW8Z9L.js → block-editor-Bx0uXbJP.js} +3 -3
- package/dist/gateway/static/root/assets/{browser-automation-inputs-C5s1yHOu.js → browser-automation-inputs-1ZIPGDeq.js} +1 -1
- package/dist/gateway/static/root/assets/{browser-automations-page-BV00BXRb.js → browser-automations-page-CCjYipHc.js} +2 -2
- package/dist/gateway/static/root/assets/browser-settings-page-CSv4rvmx.js +3 -0
- package/dist/gateway/static/root/assets/capabilities-BnO9LV7U.js +1 -0
- package/dist/gateway/static/root/assets/{capabilities-page-v0WkhV5o.js → capabilities-page-BfvDvIY1.js} +2 -2
- package/dist/gateway/static/root/assets/capabilities-settings-panel-CoW7-ESq.js +8 -0
- package/dist/gateway/static/root/assets/{capability-header-actions-vmx35sbu.js → capability-header-actions-D_hbWRRF.js} +1 -1
- package/dist/gateway/static/root/assets/channels-BhMaRh1x.js +1 -0
- package/dist/gateway/static/root/assets/{chat-terminal-dock-C41mXCAi.js → chat-terminal-dock-Fnum_IEm.js} +1 -1
- package/dist/gateway/static/root/assets/{computer-settings-page-BJkqok2G.js → computer-settings-page-DI1zfCTA.js} +1 -1
- package/dist/gateway/static/root/assets/{connector-service-page-BKCZMmwm.js → connector-service-page-CiGDAubm.js} +1 -1
- package/dist/gateway/static/root/assets/connectors-page-Ono0Pha1.js +2 -0
- package/dist/gateway/static/root/assets/{date-picker-CrOV4Ynd.js → date-picker-D-JhzZyW.js} +1 -1
- package/dist/gateway/static/root/assets/{dependency-picker-CqADAHZp.js → dependency-picker-DpD3xaEB.js} +1 -1
- package/dist/gateway/static/root/assets/{desktop-pet-Bab-iWED.js → desktop-pet-CCoDxKqh.js} +1 -1
- package/dist/gateway/static/root/assets/{desktop-pet-settings-BqgzLOdi.js → desktop-pet-settings-GxndKfCx.js} +1 -1
- package/dist/gateway/static/root/assets/{device-pairing-wizard-DFg7FDPf.js → device-pairing-wizard-B71w3ptm.js} +1 -1
- package/dist/gateway/static/root/assets/{directory-picker-path-field-hqJ9sFCR.js → directory-picker-path-field-CUzjJvjs.js} +1 -1
- package/dist/gateway/static/root/assets/{extension-debug-page-DX3PFhRE.js → extension-debug-page-BtDY8ntX.js} +1 -1
- package/dist/gateway/static/root/assets/{extension-page-DkREdHLs.js → extension-page-D9_XF-XC.js} +1 -1
- package/dist/gateway/static/root/assets/{extension-settings-page-wF-HNTM-.js → extension-settings-page-CjhUFAaC.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-settings-Du-Dos9O.js → gateway-settings-BWaCnwT1.js} +1 -1
- 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-BTjGLngn.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-BEtq5BRU.js} +1 -1
- package/dist/gateway/static/root/assets/index-DHL16aYZ.js +121 -0
- package/dist/gateway/static/root/assets/index-N1e6PDwx.css +1 -0
- package/dist/gateway/static/root/assets/{keyboard-shortcuts-settings-BgoFaTwv.js → keyboard-shortcuts-settings-JUYY_18v.js} +1 -1
- package/dist/gateway/static/root/assets/local-app-workbench-page-uI7mtoVz.js +1 -0
- package/dist/gateway/static/root/assets/{local-apps-page-HO6OQlQT.js → local-apps-page-BlYESNqz.js} +1 -1
- package/dist/gateway/static/root/assets/{locale-store-wNXWkWu5.js → locale-store-BY30D6tg.js} +1 -1
- package/dist/gateway/static/root/assets/{logs-page-CjzR9Rpj.js → logs-page-BbLQreeN.js} +2 -2
- package/dist/gateway/static/root/assets/management-settings-c4krhYU7.js +1 -0
- package/dist/gateway/static/root/assets/{markdown-view-DlT9KqwF.js → markdown-view-BEeXMfDw.js} +1 -1
- package/dist/gateway/static/root/assets/{media-plugins-Dlj6TD3M.js → media-plugins-DEFN1I73.js} +1 -1
- package/dist/gateway/static/root/assets/messages-_6IXbP2u.js +3 -0
- package/dist/gateway/static/root/assets/note-detail-panel--09xGxyE.js +5 -0
- package/dist/gateway/static/root/assets/notes-page-DsxcVBXF.js +8 -0
- package/dist/gateway/static/root/assets/{page-context-capture-button-BArPtqp5.js → page-context-capture-button-D43aVpCj.js} +1 -1
- package/dist/gateway/static/root/assets/{page-tabs-vqI30Yrg.js → page-tabs-BhYBCqls.js} +1 -1
- package/dist/gateway/static/root/assets/{preview-open-alternatives-B-mwPBJW.js → preview-open-alternatives-CP8agNlc.js} +1 -1
- package/dist/gateway/static/root/assets/{product-open-page-D--sj_uN.js → product-open-page-CU7fRhfT.js} +1 -1
- package/dist/gateway/static/root/assets/project-detail-page-U-EdDfAW.js +1 -0
- package/dist/gateway/static/root/assets/{projects-page-DBsBwAQ6.js → projects-page-DUOKZLt7.js} +1 -1
- 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-BurdDY0m.js → remote-access-hub-fVPQe5YS.js} +1 -1
- package/dist/gateway/static/root/assets/{runtime-tools-settings-panel-CAnb0PNY.js → runtime-tools-settings-panel-Czvzsuj_.js} +2 -2
- package/dist/gateway/static/root/assets/scenes-page-C0-WHOY3.js +2 -0
- package/dist/gateway/static/root/assets/{schema-form-BKj6wIMb.js → schema-form-B9Ni5O93.js} +1 -1
- package/dist/gateway/static/root/assets/sessions-page-DdXvW09N.js +1 -0
- package/dist/gateway/static/root/assets/settings-advanced-gate-BtF83fBY.js +1 -0
- package/dist/gateway/static/root/assets/{settings-form-section-78ycUHfv.js → settings-form-section-jquf1P7n.js} +1 -1
- package/dist/gateway/static/root/assets/{settings-page-BOdxIVzo.js → settings-page-DPomsvba.js} +1 -1
- package/dist/gateway/static/root/assets/{setup-status-panel-CbKHBjrU.js → setup-status-panel-BvVlqpHf.js} +1 -1
- package/dist/gateway/static/root/assets/{share-preview-page-DyLfktib.js → share-preview-page-b9DI0N1J.js} +1 -1
- package/dist/gateway/static/root/assets/shares-settings-R_qwc4DN.js +1 -0
- package/dist/gateway/static/root/assets/{skill-api-CiBGQ0Jg.js → skill-api-Bu7-3w-L.js} +1 -1
- package/dist/gateway/static/root/assets/skill-reload-api-CNJAQ_e-.js +1 -0
- package/dist/gateway/static/root/assets/{skills-page-C35VKjhb.js → skills-page-D7XPEQu_.js} +1 -1
- package/dist/gateway/static/root/assets/{system-settings-panel-CyJUeREH.js → system-settings-panel-BwFR0Uci.js} +1 -1
- package/dist/gateway/static/root/assets/task-detail-page-PFjGW2g1.js +1 -0
- package/dist/gateway/static/root/assets/{tunnel-api-Day9zhKi.js → tunnel-api-PfucxMP3.js} +1 -1
- package/dist/gateway/static/root/assets/usage-page-t_zdQHcy.js +1 -0
- package/dist/gateway/static/root/assets/{use-autosave-Bj9hC6ML.js → use-autosave-DLyy2wHz.js} +1 -1
- package/dist/gateway/static/root/assets/user-model-page-OyfPVfB9.js +2 -0
- package/dist/gateway/static/root/assets/{voice-api-key-field-fWRD6B8r.js → voice-api-key-field-CQDY5EBK.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-CJzqJ47I.js} +1 -1
- package/dist/gateway/static/root/assets/{workflow-run-setup-panel-DlWNN1VA.js → workflow-run-setup-panel-sCOk-esV.js} +2 -2
- package/dist/gateway/static/root/assets/workflows-page-DYBGjN7C.js +6 -0
- package/dist/gateway/static/root/index.html +9 -9
- package/dist/package.js +1 -1
- package/dist/packages/gateway-contract/src/automations.js +44 -14
- package/dist/packages/gateway-contract/src/capabilities.js +106 -8
- package/dist/packages/gateway-contract/src/index.js +2 -0
- package/dist/packages/gateway-contract/src/scenes.js +7 -6
- package/dist/packages/gateway-contract/src/sessions.js +2 -1
- package/dist/packages/gateway-contract/src/usage.js +6 -0
- package/dist/src/agent/agent-manager.js +9 -3
- package/dist/src/agent/background-review/run-background-review.js +6 -1
- package/dist/src/agent/embedded/run-turn.js +7 -1
- package/dist/src/agent/external-tools/gateway-tools.d.ts +2 -1
- package/dist/src/agent/external-tools/gateway-tools.js +44 -11
- package/dist/src/agent/external-tools/index.js +1 -1
- 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.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 +4 -0
- 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 +49 -8
- package/dist/src/ai-assist/text-assist.js +5 -1
- package/dist/src/automations/api/routes.js +65 -0
- 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/capabilities/store-connector.d.ts +17 -1
- package/dist/src/capabilities/store-connector.js +69 -3
- 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/flow.js +5 -1
- package/dist/src/cli/commands/extension-marketplace.js +1 -1
- package/dist/src/cli/commands/skills.js +1 -1
- package/dist/src/connectors/approval-resume.js +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-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/extensions/update.js +1 -1
- package/dist/src/gateway/agent-builtin-tools.d.ts +1 -1
- package/dist/src/gateway/home-intelligence-automation-reconciler.js +4 -1
- package/dist/src/gateway/hono/routes/capabilities.js +1 -1
- package/dist/src/gateway/hono/routes/connection-waits.js +3 -2
- package/dist/src/gateway/hono/routes/lazy-bundles.js +14 -1
- 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/sessions.js +15 -0
- 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 +1 -1
- package/dist/src/gateway/memory-maintenance-automation-reconciler.js +5 -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 +9 -1
- 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 +6 -3
- package/dist/src/gateway/service.js +82 -85
- package/dist/src/gateway/side-chat/run-service.js +10 -7
- package/dist/src/home-intelligence/generator.js +4 -1
- package/dist/src/home-intelligence/host.js +1 -1
- 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 +1 -1
- package/dist/src/notes/service.js +2 -3
- package/dist/src/projects/project-service.js +1 -2
- package/dist/src/projects/project-skill-service.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/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 -2
- 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/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-input-repository.d.ts +8 -0
- package/dist/src/storage/sqlite/session-input-repository.js +18 -1
- 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/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/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/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/workflows/service/workflow-run-service.js +15 -2
- 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/automations-workspace-BMgJvdcv.js +0 -7
- package/dist/gateway/static/root/assets/browser-settings-page-xwTmuZjS.js +0 -3
- package/dist/gateway/static/root/assets/capabilities-CHA-sTAZ.js +0 -1
- package/dist/gateway/static/root/assets/capabilities-settings-panel-DefBGjhV.js +0 -8
- 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/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/management-settings-Dk_gTJb9.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/project-detail-page-BFUdtWXF.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/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/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
|
@@ -18,7 +18,7 @@ export declare const mailFollowUpTemplate: {
|
|
|
18
18
|
type: "schedule";
|
|
19
19
|
})[];
|
|
20
20
|
execution: {
|
|
21
|
-
kind:
|
|
21
|
+
kind: string;
|
|
22
22
|
instruction: string;
|
|
23
23
|
limits: {
|
|
24
24
|
timeoutSeconds: number;
|
|
@@ -50,7 +50,7 @@ export declare const familyPlanTemplate: {
|
|
|
50
50
|
type: "schedule";
|
|
51
51
|
})[];
|
|
52
52
|
execution: {
|
|
53
|
-
kind:
|
|
53
|
+
kind: string;
|
|
54
54
|
instruction: string;
|
|
55
55
|
limits: {
|
|
56
56
|
timeoutSeconds: number;
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import type { DatabaseSync } from 'node:sqlite';
|
|
2
2
|
import type { SceneContextProvider, SceneEvidence } from './execution.js';
|
|
3
|
+
import type { SceneActivation } from './contracts.js';
|
|
3
4
|
/** Explicit notes belong to one delegation, not an implicit family-wide data grant. */
|
|
4
5
|
export declare class SceneUserNotesProvider implements SceneContextProvider {
|
|
5
6
|
private readonly db;
|
|
6
7
|
private readonly clock;
|
|
7
8
|
readonly id = "user_notes";
|
|
8
9
|
constructor(db: DatabaseSync, clock?: () => number);
|
|
10
|
+
setupIssues(activation: SceneActivation): string[];
|
|
11
|
+
authorization(activation: SceneActivation): string[] | null;
|
|
9
12
|
read(input: Parameters<SceneContextProvider['read']>[0]): Promise<SceneEvidence[]>;
|
|
10
13
|
}
|
|
@@ -7,6 +7,12 @@ var SceneUserNotesProvider = class {
|
|
|
7
7
|
this.db = db;
|
|
8
8
|
this.clock = clock;
|
|
9
9
|
}
|
|
10
|
+
setupIssues(activation) {
|
|
11
|
+
return activation.scope.kind === "personal" ? [] : ["personal_notes_scope"];
|
|
12
|
+
}
|
|
13
|
+
authorization(activation) {
|
|
14
|
+
return activation.scope.kind === "personal" ? [] : null;
|
|
15
|
+
}
|
|
10
16
|
async read(input) {
|
|
11
17
|
input.signal.throwIfAborted();
|
|
12
18
|
if (!input.permissions.contextProviders.includes(this.id) || input.activation.scope.kind !== "personal") throw new Error("Personal notes permission is required");
|
|
@@ -14,6 +14,8 @@ export interface ClientHistoryMessage {
|
|
|
14
14
|
timestamp?: number;
|
|
15
15
|
/** Whitelisted display metadata; never includes source snapshot text. */
|
|
16
16
|
metadata?: {
|
|
17
|
+
/** Stable client-generated id used to reconcile optimistic sends exactly. */
|
|
18
|
+
clientMessageId?: string;
|
|
17
19
|
sourceContexts?: Array<{
|
|
18
20
|
refId?: string;
|
|
19
21
|
kind: 'note' | 'task' | 'file' | 'session' | 'browser_tab' | 'browser_page' | 'mcp_resource';
|
|
@@ -77,4 +79,5 @@ export declare function transcriptRowsToClientHistory(rows: TranscriptStoredRow[
|
|
|
77
79
|
limit?: number;
|
|
78
80
|
startRowNumber?: number;
|
|
79
81
|
endRowNumber?: number;
|
|
82
|
+
rowNumberOffset?: number;
|
|
80
83
|
}): ClientHistoryMessage[];
|
|
@@ -8,9 +8,13 @@ init_src();
|
|
|
8
8
|
function sourceContextDisplayMetadata(metadata) {
|
|
9
9
|
if (!metadata || typeof metadata !== "object" || Array.isArray(metadata)) return void 0;
|
|
10
10
|
const record = metadata;
|
|
11
|
+
const clientMessageId = typeof record.clientMessageId === "string" && record.clientMessageId.trim() ? record.clientMessageId : void 0;
|
|
11
12
|
const rows = record.sourceContexts;
|
|
12
13
|
const userTurnDocument = isUserTurnDocument(record.userTurnDocument) ? record.userTurnDocument : void 0;
|
|
13
|
-
if (!Array.isArray(rows)) return userTurnDocument ? {
|
|
14
|
+
if (!Array.isArray(rows)) return clientMessageId || userTurnDocument ? {
|
|
15
|
+
...clientMessageId ? { clientMessageId } : {},
|
|
16
|
+
...userTurnDocument ? { userTurnDocument } : {}
|
|
17
|
+
} : void 0;
|
|
14
18
|
const sourceContexts = rows.flatMap((value) => {
|
|
15
19
|
if (!value || typeof value !== "object" || Array.isArray(value)) return [];
|
|
16
20
|
const row = value;
|
|
@@ -29,7 +33,8 @@ function sourceContextDisplayMetadata(metadata) {
|
|
|
29
33
|
...row.kind === "file" && (row.fileKind === "file" || row.fileKind === "directory") ? { fileKind: row.fileKind } : {}
|
|
30
34
|
}];
|
|
31
35
|
});
|
|
32
|
-
return sourceContexts.length || userTurnDocument ? {
|
|
36
|
+
return clientMessageId || sourceContexts.length || userTurnDocument ? {
|
|
37
|
+
...clientMessageId ? { clientMessageId } : {},
|
|
33
38
|
...sourceContexts.length ? { sourceContexts } : {},
|
|
34
39
|
...userTurnDocument ? { userTurnDocument } : {}
|
|
35
40
|
} : void 0;
|
|
@@ -367,9 +372,9 @@ function transcriptRowsToClientHistory(rows, opts) {
|
|
|
367
372
|
const out = [];
|
|
368
373
|
const reviewTraceToolById = /* @__PURE__ */ new Map();
|
|
369
374
|
for (const [offset, row] of slice.entries()) {
|
|
370
|
-
const
|
|
371
|
-
const id = `row-${
|
|
372
|
-
const displayIndex = displayIndexByRowNumber.get(
|
|
375
|
+
const localRowNumber = startIndex + offset + 1;
|
|
376
|
+
const id = `row-${(opts?.rowNumberOffset ?? 0) + localRowNumber}`;
|
|
377
|
+
const displayIndex = displayIndexByRowNumber.get(localRowNumber);
|
|
373
378
|
if (isCompactionRow(row)) {
|
|
374
379
|
out.push({
|
|
375
380
|
id,
|
|
@@ -2,7 +2,8 @@ import { createLogger } from "../utils/logger/index.js";
|
|
|
2
2
|
import { init_logger } from "../utils/logger.js";
|
|
3
3
|
import { requireXopcDatabase } from "../storage/sqlite/connection.js";
|
|
4
4
|
import { getSessionMetadata } from "../storage/sqlite/session-read-repository.js";
|
|
5
|
-
import { findConversationIdByTranscriptId
|
|
5
|
+
import { findConversationIdByTranscriptId } from "../storage/sqlite/session-repository.js";
|
|
6
|
+
import { getSessionConfig } from "../storage/sqlite/config-repository.js";
|
|
6
7
|
import { init_sqlite } from "../storage/sqlite/index.js";
|
|
7
8
|
import { SessionConfigSchema, init_schema } from "../config/schema.js";
|
|
8
9
|
import { normalizeThinkLevel, normalizeVerboseLevel } from "../agent/transcript/thinking-types.js";
|
|
@@ -69,8 +70,8 @@ async function resolveSession(opts) {
|
|
|
69
70
|
conversationId,
|
|
70
71
|
sessionMetadata,
|
|
71
72
|
isNewSession,
|
|
72
|
-
persistedThinking: fresh && conversationId ? normalizeThinkLevel(
|
|
73
|
-
persistedVerbose: fresh && conversationId ? normalizeVerboseLevel(
|
|
73
|
+
persistedThinking: fresh && conversationId ? normalizeThinkLevel(getSessionConfig(conversationId)?.thinkingLevel) : void 0,
|
|
74
|
+
persistedVerbose: fresh && conversationId ? normalizeVerboseLevel(getSessionConfig(conversationId)?.verboseLevel) : void 0
|
|
74
75
|
};
|
|
75
76
|
}
|
|
76
77
|
//#endregion
|
|
@@ -170,7 +170,7 @@ Title:`,
|
|
|
170
170
|
maxTokens: 64,
|
|
171
171
|
temperature: .35,
|
|
172
172
|
signal
|
|
173
|
-
});
|
|
173
|
+
}, void 0, { operation: "session.generate_title" });
|
|
174
174
|
let text = "";
|
|
175
175
|
if (Array.isArray(result.content)) {
|
|
176
176
|
for (const c of result.content) if (c && typeof c === "object" && c.type === "text") text += String(c.text || "");
|
|
@@ -188,9 +188,9 @@ var SessionStore = class {
|
|
|
188
188
|
beforeIndex: hasBeforeCursor ? parsedBefore : void 0,
|
|
189
189
|
includeContext: true
|
|
190
190
|
});
|
|
191
|
-
const messages = transcriptRowsToClientHistory(page.rows);
|
|
192
191
|
const endIndex = hasBeforeCursor ? Math.min(page.total, Math.max(0, parsedBefore)) : Math.max(0, page.total - offset);
|
|
193
192
|
const startIndex = Math.max(0, endIndex - page.rows.length);
|
|
193
|
+
const messages = transcriptRowsToClientHistory(page.rows, { rowNumberOffset: startIndex });
|
|
194
194
|
const session = {
|
|
195
195
|
...metadata,
|
|
196
196
|
messages,
|
|
@@ -205,7 +205,8 @@ var SessionStore = class {
|
|
|
205
205
|
offset,
|
|
206
206
|
hasMore: hasBeforeCursor ? startIndex > 0 : offset + limit < page.total,
|
|
207
207
|
...hasBeforeCursor ? { before: String(endIndex) } : {},
|
|
208
|
-
...nextBeforeCursor ? { nextBeforeCursor } : {}
|
|
208
|
+
...nextBeforeCursor ? { nextBeforeCursor } : {},
|
|
209
|
+
revision: page.revision
|
|
209
210
|
}
|
|
210
211
|
};
|
|
211
212
|
}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import type { AiUsageEvent, AiUsageFinish } from '../../usage/types.js';
|
|
2
|
+
export declare const AI_USAGE_RETENTION_MS: number;
|
|
3
|
+
export declare function insertAiUsageEvent(event: AiUsageEvent): void;
|
|
4
|
+
export declare function finishAiUsageEvent(id: string, finish: AiUsageFinish & {
|
|
5
|
+
estimatedCostMicrousd?: number;
|
|
6
|
+
}): void;
|
|
7
|
+
export declare function markStaleAiUsageEventsUnknown(cutoffMs: number, now?: number): number;
|
|
8
|
+
export declare function pruneAiUsageEvents(cutoffMs: number): number;
|
|
9
|
+
export declare function getAiUsageEvent(id: string): Record<string, unknown> | undefined;
|
|
10
|
+
export type AiUsageQuery = {
|
|
11
|
+
from: number;
|
|
12
|
+
to: number;
|
|
13
|
+
category?: string;
|
|
14
|
+
provider?: string;
|
|
15
|
+
model?: string;
|
|
16
|
+
agentId?: string;
|
|
17
|
+
conversationId?: string;
|
|
18
|
+
};
|
|
19
|
+
export type AiUsageTotals = {
|
|
20
|
+
calls: number;
|
|
21
|
+
succeededCalls: number;
|
|
22
|
+
failedCalls: number;
|
|
23
|
+
unknownCostCalls: number;
|
|
24
|
+
inputTokens: number;
|
|
25
|
+
outputTokens: number;
|
|
26
|
+
cacheReadTokens: number;
|
|
27
|
+
cacheWriteTokens: number;
|
|
28
|
+
totalTokens: number;
|
|
29
|
+
knownCostUsd: string;
|
|
30
|
+
costCompleteness: 'complete' | 'partial' | 'unknown';
|
|
31
|
+
};
|
|
32
|
+
export declare function summarizeAiUsage(query: AiUsageQuery): {
|
|
33
|
+
totals: AiUsageTotals;
|
|
34
|
+
byCategory: Array<{
|
|
35
|
+
key: string;
|
|
36
|
+
totals: AiUsageTotals;
|
|
37
|
+
}>;
|
|
38
|
+
byModel: Array<{
|
|
39
|
+
key: string;
|
|
40
|
+
provider: string;
|
|
41
|
+
model: string;
|
|
42
|
+
totals: AiUsageTotals;
|
|
43
|
+
}>;
|
|
44
|
+
};
|
|
45
|
+
export declare function listAiUsageEvents(query: AiUsageQuery & {
|
|
46
|
+
limit?: number;
|
|
47
|
+
before?: {
|
|
48
|
+
startedAt: number;
|
|
49
|
+
id: string;
|
|
50
|
+
};
|
|
51
|
+
}): {
|
|
52
|
+
items: {
|
|
53
|
+
id: string;
|
|
54
|
+
traceId: string;
|
|
55
|
+
parentEventId: string;
|
|
56
|
+
conversationId: string;
|
|
57
|
+
runId: string;
|
|
58
|
+
agentId: string;
|
|
59
|
+
category: string;
|
|
60
|
+
operation: string;
|
|
61
|
+
trigger: string;
|
|
62
|
+
reasonKey: string;
|
|
63
|
+
provider: string;
|
|
64
|
+
model: string;
|
|
65
|
+
status: string;
|
|
66
|
+
startedAt: number;
|
|
67
|
+
finishedAt: number;
|
|
68
|
+
durationMs: number;
|
|
69
|
+
inputTokens: number;
|
|
70
|
+
outputTokens: number;
|
|
71
|
+
cacheReadTokens: number;
|
|
72
|
+
cacheWriteTokens: number;
|
|
73
|
+
reasoningTokens: number;
|
|
74
|
+
totalTokens: number;
|
|
75
|
+
estimatedCostUsd: string;
|
|
76
|
+
costSource: string;
|
|
77
|
+
pricingSnapshot: Record<string, number>;
|
|
78
|
+
errorSummary: string;
|
|
79
|
+
}[];
|
|
80
|
+
nextCursor: string;
|
|
81
|
+
};
|
|
82
|
+
export declare function getAiUsageEventView(id: string): {
|
|
83
|
+
id: string;
|
|
84
|
+
traceId: string;
|
|
85
|
+
parentEventId: string;
|
|
86
|
+
conversationId: string;
|
|
87
|
+
runId: string;
|
|
88
|
+
agentId: string;
|
|
89
|
+
category: string;
|
|
90
|
+
operation: string;
|
|
91
|
+
trigger: string;
|
|
92
|
+
reasonKey: string;
|
|
93
|
+
provider: string;
|
|
94
|
+
model: string;
|
|
95
|
+
status: string;
|
|
96
|
+
startedAt: number;
|
|
97
|
+
finishedAt: number;
|
|
98
|
+
durationMs: number;
|
|
99
|
+
inputTokens: number;
|
|
100
|
+
outputTokens: number;
|
|
101
|
+
cacheReadTokens: number;
|
|
102
|
+
cacheWriteTokens: number;
|
|
103
|
+
reasoningTokens: number;
|
|
104
|
+
totalTokens: number;
|
|
105
|
+
estimatedCostUsd: string;
|
|
106
|
+
costSource: string;
|
|
107
|
+
pricingSnapshot: Record<string, number>;
|
|
108
|
+
errorSummary: string;
|
|
109
|
+
};
|
|
110
|
+
export declare function listAiUsageTrace(traceId: string): {
|
|
111
|
+
id: string;
|
|
112
|
+
traceId: string;
|
|
113
|
+
parentEventId: string;
|
|
114
|
+
conversationId: string;
|
|
115
|
+
runId: string;
|
|
116
|
+
agentId: string;
|
|
117
|
+
category: string;
|
|
118
|
+
operation: string;
|
|
119
|
+
trigger: string;
|
|
120
|
+
reasonKey: string;
|
|
121
|
+
provider: string;
|
|
122
|
+
model: string;
|
|
123
|
+
status: string;
|
|
124
|
+
startedAt: number;
|
|
125
|
+
finishedAt: number;
|
|
126
|
+
durationMs: number;
|
|
127
|
+
inputTokens: number;
|
|
128
|
+
outputTokens: number;
|
|
129
|
+
cacheReadTokens: number;
|
|
130
|
+
cacheWriteTokens: number;
|
|
131
|
+
reasoningTokens: number;
|
|
132
|
+
totalTokens: number;
|
|
133
|
+
estimatedCostUsd: string;
|
|
134
|
+
costSource: string;
|
|
135
|
+
pricingSnapshot: Record<string, number>;
|
|
136
|
+
errorSummary: string;
|
|
137
|
+
}[];
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { getSqliteDatabase, init_transaction, runSqliteWriteTransaction } from "./transaction.js";
|
|
2
|
+
//#region src/storage/sqlite/ai-usage-repository.ts
|
|
3
|
+
init_transaction();
|
|
4
|
+
const ERROR_SUMMARY_LIMIT = 512;
|
|
5
|
+
const AI_USAGE_RETENTION_MS = 4320 * 60 * 60 * 1e3;
|
|
6
|
+
function boundedError(value) {
|
|
7
|
+
if (!value) return void 0;
|
|
8
|
+
return value.replace(/Bearer\s+[A-Za-z0-9._~+/-]+/gi, "Bearer [REDACTED]").replace(/(api[_-]?key|token|secret)\s*[=:]\s*[^\s,;]+/gi, "$1=[REDACTED]").slice(0, ERROR_SUMMARY_LIMIT);
|
|
9
|
+
}
|
|
10
|
+
function insertAiUsageEvent(event) {
|
|
11
|
+
runSqliteWriteTransaction((db) => {
|
|
12
|
+
db.prepare(`INSERT INTO ai_usage_events (
|
|
13
|
+
id, trace_id, parent_event_id, conversation_id, run_id, agent_id,
|
|
14
|
+
category, operation, trigger_kind, reason_key, provider, model, status,
|
|
15
|
+
started_at, finished_at, duration_ms, input_tokens, output_tokens,
|
|
16
|
+
cache_read_tokens, cache_write_tokens, reasoning_tokens, total_tokens,
|
|
17
|
+
estimated_cost_microusd, cost_source, pricing_snapshot_json, error_summary,
|
|
18
|
+
created_at, updated_at
|
|
19
|
+
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`).run(event.id, event.traceId, event.parentEventId ?? null, event.conversationId ?? null, event.runId ?? null, event.agentId ?? null, event.category, event.operation, event.trigger, event.reasonKey, event.provider, event.model, event.status, event.startedAt, event.finishedAt ?? null, event.durationMs ?? null, event.inputTokens ?? null, event.outputTokens ?? null, event.cacheReadTokens ?? null, event.cacheWriteTokens ?? null, event.reasoningTokens ?? null, event.totalTokens ?? null, event.estimatedCostMicrousd ?? null, event.costSource, event.pricingSnapshot ? JSON.stringify(event.pricingSnapshot) : null, boundedError(event.errorSummary) ?? null, event.startedAt, event.startedAt);
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
function finishAiUsageEvent(id, finish) {
|
|
23
|
+
const finishedAt = finish.finishedAt ?? Date.now();
|
|
24
|
+
const usage = finish.usage;
|
|
25
|
+
runSqliteWriteTransaction((db) => {
|
|
26
|
+
db.prepare(`UPDATE ai_usage_events SET
|
|
27
|
+
status = ?, finished_at = ?, duration_ms = MAX(0, ? - started_at),
|
|
28
|
+
input_tokens = ?, output_tokens = ?, cache_read_tokens = ?, cache_write_tokens = ?,
|
|
29
|
+
reasoning_tokens = ?, total_tokens = ?, estimated_cost_microusd = ?,
|
|
30
|
+
error_summary = ?, updated_at = ?
|
|
31
|
+
WHERE id = ? AND status = 'running'`).run(finish.status, finishedAt, finishedAt, usage?.input ?? null, usage?.output ?? null, usage?.cacheRead ?? null, usage?.cacheWrite ?? null, usage?.reasoning ?? null, usage?.totalTokens ?? null, finish.estimatedCostMicrousd ?? null, boundedError(finish.errorSummary) ?? null, finishedAt, id);
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
function markStaleAiUsageEventsUnknown(cutoffMs, now = Date.now()) {
|
|
35
|
+
return runSqliteWriteTransaction((db) => Number(db.prepare(`UPDATE ai_usage_events
|
|
36
|
+
SET status = 'unknown', finished_at = ?, duration_ms = MAX(0, ? - started_at), updated_at = ?
|
|
37
|
+
WHERE status = 'running' AND started_at < ?`).run(now, now, now, cutoffMs).changes));
|
|
38
|
+
}
|
|
39
|
+
function pruneAiUsageEvents(cutoffMs) {
|
|
40
|
+
return runSqliteWriteTransaction((db) => Number(db.prepare(`DELETE FROM ai_usage_events
|
|
41
|
+
WHERE status <> 'running' AND started_at < ?`).run(cutoffMs).changes));
|
|
42
|
+
}
|
|
43
|
+
function getAiUsageEvent(id) {
|
|
44
|
+
return getSqliteDatabase().prepare("SELECT * FROM ai_usage_events WHERE id = ?").get(id);
|
|
45
|
+
}
|
|
46
|
+
function queryWhere(query) {
|
|
47
|
+
const clauses = ["started_at >= ?", "started_at < ?"];
|
|
48
|
+
const values = [query.from, query.to];
|
|
49
|
+
for (const [key, column] of [
|
|
50
|
+
["category", "category"],
|
|
51
|
+
["provider", "provider"],
|
|
52
|
+
["model", "model"],
|
|
53
|
+
["agentId", "agent_id"],
|
|
54
|
+
["conversationId", "conversation_id"]
|
|
55
|
+
]) {
|
|
56
|
+
const value = query[key];
|
|
57
|
+
if (typeof value === "string" && value) {
|
|
58
|
+
clauses.push(`${column} = ?`);
|
|
59
|
+
values.push(value);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return {
|
|
63
|
+
sql: clauses.join(" AND "),
|
|
64
|
+
values
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
function usd(microusd) {
|
|
68
|
+
return (microusd / 1e6).toFixed(6).replace(/0+$/, "").replace(/\.$/, "") || "0";
|
|
69
|
+
}
|
|
70
|
+
function totalsFromRow(row) {
|
|
71
|
+
const calls = Number(row.calls ?? 0);
|
|
72
|
+
const unknownCostCalls = Number(row.unknown_cost_calls ?? 0);
|
|
73
|
+
return {
|
|
74
|
+
calls,
|
|
75
|
+
succeededCalls: Number(row.succeeded_calls ?? 0),
|
|
76
|
+
failedCalls: Number(row.failed_calls ?? 0),
|
|
77
|
+
unknownCostCalls,
|
|
78
|
+
inputTokens: Number(row.input_tokens ?? 0),
|
|
79
|
+
outputTokens: Number(row.output_tokens ?? 0),
|
|
80
|
+
cacheReadTokens: Number(row.cache_read_tokens ?? 0),
|
|
81
|
+
cacheWriteTokens: Number(row.cache_write_tokens ?? 0),
|
|
82
|
+
totalTokens: Number(row.total_tokens ?? 0),
|
|
83
|
+
knownCostUsd: usd(Number(row.known_cost_microusd ?? 0)),
|
|
84
|
+
costCompleteness: calls === 0 || unknownCostCalls === calls ? "unknown" : unknownCostCalls > 0 ? "partial" : "complete"
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
const TOTALS_SQL = `COUNT(*) AS calls,
|
|
88
|
+
SUM(CASE WHEN status = 'succeeded' THEN 1 ELSE 0 END) AS succeeded_calls,
|
|
89
|
+
SUM(CASE WHEN status IN ('failed', 'aborted', 'unknown') THEN 1 ELSE 0 END) AS failed_calls,
|
|
90
|
+
SUM(CASE WHEN cost_source <> 'local' AND estimated_cost_microusd IS NULL THEN 1 ELSE 0 END) AS unknown_cost_calls,
|
|
91
|
+
COALESCE(SUM(input_tokens), 0) AS input_tokens,
|
|
92
|
+
COALESCE(SUM(output_tokens), 0) AS output_tokens,
|
|
93
|
+
COALESCE(SUM(cache_read_tokens), 0) AS cache_read_tokens,
|
|
94
|
+
COALESCE(SUM(cache_write_tokens), 0) AS cache_write_tokens,
|
|
95
|
+
COALESCE(SUM(total_tokens), 0) AS total_tokens,
|
|
96
|
+
COALESCE(SUM(estimated_cost_microusd), 0) AS known_cost_microusd`;
|
|
97
|
+
function summarizeAiUsage(query) {
|
|
98
|
+
const { sql, values } = queryWhere(query);
|
|
99
|
+
const db = getSqliteDatabase();
|
|
100
|
+
return {
|
|
101
|
+
totals: totalsFromRow(db.prepare(`SELECT ${TOTALS_SQL} FROM ai_usage_events WHERE ${sql}`).get(...values)),
|
|
102
|
+
byCategory: db.prepare(`SELECT category AS key, ${TOTALS_SQL} FROM ai_usage_events
|
|
103
|
+
WHERE ${sql} GROUP BY category ORDER BY known_cost_microusd DESC, calls DESC`).all(...values).map((row) => ({
|
|
104
|
+
key: String(row.key),
|
|
105
|
+
totals: totalsFromRow(row)
|
|
106
|
+
})),
|
|
107
|
+
byModel: db.prepare(`SELECT provider || '/' || model AS key, provider, model, ${TOTALS_SQL}
|
|
108
|
+
FROM ai_usage_events WHERE ${sql} GROUP BY provider, model
|
|
109
|
+
ORDER BY known_cost_microusd DESC, calls DESC`).all(...values).map((row) => ({
|
|
110
|
+
key: String(row.key),
|
|
111
|
+
provider: String(row.provider),
|
|
112
|
+
model: String(row.model),
|
|
113
|
+
totals: totalsFromRow(row)
|
|
114
|
+
}))
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
function eventFromRow(row) {
|
|
118
|
+
const pricingSnapshot = typeof row.pricing_snapshot_json === "string" ? JSON.parse(row.pricing_snapshot_json) : void 0;
|
|
119
|
+
return {
|
|
120
|
+
id: String(row.id),
|
|
121
|
+
traceId: String(row.trace_id),
|
|
122
|
+
parentEventId: row.parent_event_id ? String(row.parent_event_id) : void 0,
|
|
123
|
+
conversationId: row.conversation_id ? String(row.conversation_id) : void 0,
|
|
124
|
+
runId: row.run_id ? String(row.run_id) : void 0,
|
|
125
|
+
agentId: row.agent_id ? String(row.agent_id) : void 0,
|
|
126
|
+
category: String(row.category),
|
|
127
|
+
operation: String(row.operation),
|
|
128
|
+
trigger: String(row.trigger_kind),
|
|
129
|
+
reasonKey: String(row.reason_key),
|
|
130
|
+
provider: String(row.provider),
|
|
131
|
+
model: String(row.model),
|
|
132
|
+
status: String(row.status),
|
|
133
|
+
startedAt: Number(row.started_at),
|
|
134
|
+
finishedAt: row.finished_at === null ? void 0 : Number(row.finished_at),
|
|
135
|
+
durationMs: row.duration_ms === null ? void 0 : Number(row.duration_ms),
|
|
136
|
+
inputTokens: row.input_tokens === null ? void 0 : Number(row.input_tokens),
|
|
137
|
+
outputTokens: row.output_tokens === null ? void 0 : Number(row.output_tokens),
|
|
138
|
+
cacheReadTokens: row.cache_read_tokens === null ? void 0 : Number(row.cache_read_tokens),
|
|
139
|
+
cacheWriteTokens: row.cache_write_tokens === null ? void 0 : Number(row.cache_write_tokens),
|
|
140
|
+
reasoningTokens: row.reasoning_tokens === null ? void 0 : Number(row.reasoning_tokens),
|
|
141
|
+
totalTokens: row.total_tokens === null ? void 0 : Number(row.total_tokens),
|
|
142
|
+
estimatedCostUsd: row.estimated_cost_microusd === null ? void 0 : usd(Number(row.estimated_cost_microusd)),
|
|
143
|
+
costSource: String(row.cost_source),
|
|
144
|
+
pricingSnapshot,
|
|
145
|
+
errorSummary: row.error_summary ? String(row.error_summary) : void 0
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
function listAiUsageEvents(query) {
|
|
149
|
+
const { sql, values } = queryWhere(query);
|
|
150
|
+
const clauses = [sql];
|
|
151
|
+
if (query.before) {
|
|
152
|
+
clauses.push("(started_at < ? OR (started_at = ? AND id < ?))");
|
|
153
|
+
values.push(query.before.startedAt, query.before.startedAt, query.before.id);
|
|
154
|
+
}
|
|
155
|
+
const limit = Math.min(200, Math.max(1, query.limit ?? 50));
|
|
156
|
+
const rows = getSqliteDatabase().prepare(`SELECT * FROM ai_usage_events WHERE ${clauses.join(" AND ")}
|
|
157
|
+
ORDER BY started_at DESC, id DESC LIMIT ?`).all(...values, limit + 1);
|
|
158
|
+
const hasMore = rows.length > limit;
|
|
159
|
+
const items = rows.slice(0, limit).map(eventFromRow);
|
|
160
|
+
const last = items.at(-1);
|
|
161
|
+
return {
|
|
162
|
+
items,
|
|
163
|
+
nextCursor: hasMore && last ? `${last.startedAt}:${last.id}` : void 0
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
function getAiUsageEventView(id) {
|
|
167
|
+
const row = getAiUsageEvent(id);
|
|
168
|
+
return row ? eventFromRow(row) : void 0;
|
|
169
|
+
}
|
|
170
|
+
function listAiUsageTrace(traceId) {
|
|
171
|
+
return getSqliteDatabase().prepare(`SELECT * FROM ai_usage_events WHERE trace_id = ?
|
|
172
|
+
ORDER BY started_at ASC, id ASC`).all(traceId).map(eventFromRow);
|
|
173
|
+
}
|
|
174
|
+
//#endregion
|
|
175
|
+
export { AI_USAGE_RETENTION_MS, finishAiUsageEvent, getAiUsageEvent, getAiUsageEventView, insertAiUsageEvent, listAiUsageEvents, listAiUsageTrace, markStaleAiUsageEventsUnknown, pruneAiUsageEvents, summarizeAiUsage };
|
|
@@ -1,5 +1,6 @@
|
|
|
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
|
//#region src/storage/sqlite/connector-account-repository.ts
|
|
4
5
|
function parseIdentity(value) {
|
|
5
6
|
try {
|
|
@@ -22,8 +23,8 @@ function fromRow(row) {
|
|
|
22
23
|
label: row.label ?? void 0,
|
|
23
24
|
enabled: row.enabled === 1,
|
|
24
25
|
allowedAgentIds: row.allowed_agent_ids_json === null ? null : JSON.parse(row.allowed_agent_ids_json),
|
|
25
|
-
createdAt: row.created_at,
|
|
26
|
-
updatedAt: row.updated_at
|
|
26
|
+
createdAt: timestampToIso(row.created_at),
|
|
27
|
+
updatedAt: timestampToIso(row.updated_at)
|
|
27
28
|
};
|
|
28
29
|
}
|
|
29
30
|
function mergeAccountSourceData(db, connectorId, sourceAccountId, targetAccountId) {
|
|
@@ -83,7 +84,7 @@ function updateConnectorAccount(id, patch) {
|
|
|
83
84
|
const account = getConnectorAccount(id);
|
|
84
85
|
if (!account) throw new Error("Connector account not found.");
|
|
85
86
|
getSqliteDatabase().prepare(`UPDATE connector_accounts
|
|
86
|
-
SET label = ?, enabled = ?, allowed_agent_ids_json = ?, updated_at = ? WHERE id = ?`).run(patch.label === void 0 ? account.label ?? null : patch.label.trim() || null, patch.enabled ?? account.enabled ? 1 : 0, patch.allowedAgentIds === void 0 ? account.allowedAgentIds === null ? null : JSON.stringify(account.allowedAgentIds) : patch.allowedAgentIds === null ? null : JSON.stringify([...new Set(patch.allowedAgentIds)]),
|
|
87
|
+
SET label = ?, enabled = ?, allowed_agent_ids_json = ?, updated_at = ? WHERE id = ?`).run(patch.label === void 0 ? account.label ?? null : patch.label.trim() || null, patch.enabled ?? account.enabled ? 1 : 0, patch.allowedAgentIds === void 0 ? account.allowedAgentIds === null ? null : JSON.stringify(account.allowedAgentIds) : patch.allowedAgentIds === null ? null : JSON.stringify([...new Set(patch.allowedAgentIds)]), Date.now(), id);
|
|
87
88
|
return getConnectorAccount(id);
|
|
88
89
|
}
|
|
89
90
|
function listConnectorAccounts(options = {}) {
|
|
@@ -101,7 +102,7 @@ function listConnectorAccounts(options = {}) {
|
|
|
101
102
|
return getSqliteDatabase().prepare(`SELECT * FROM connector_accounts${where} ORDER BY updated_at DESC`).all(...values).map(fromRow);
|
|
102
103
|
}
|
|
103
104
|
function refreshConnectorAccountCurrent(accountId) {
|
|
104
|
-
const now =
|
|
105
|
+
const now = Date.now();
|
|
105
106
|
runSqliteWriteTransaction((db) => {
|
|
106
107
|
const primary = db.prepare(`
|
|
107
108
|
SELECT id FROM connector_connections
|
|
@@ -119,7 +120,7 @@ function refreshConnectorAccountCurrent(accountId) {
|
|
|
119
120
|
return getConnectorAccount(accountId);
|
|
120
121
|
}
|
|
121
122
|
function reconcileConnectorAccount(input) {
|
|
122
|
-
const now =
|
|
123
|
+
const now = Date.now();
|
|
123
124
|
return getConnectorAccount(runSqliteWriteTransaction((db) => {
|
|
124
125
|
const connection = db.prepare(`SELECT c.account_id, c.connector_id, c.principal_id, a.backend_id FROM connector_connections c
|
|
125
126
|
JOIN connector_accounts a ON a.id = c.account_id WHERE c.id = ?`).get(input.connectionId);
|
|
@@ -165,6 +166,7 @@ function reconcileConnectorAccount(input) {
|
|
|
165
166
|
}));
|
|
166
167
|
}
|
|
167
168
|
var init_connector_account_repository = __esmMin((() => {
|
|
169
|
+
init_timestamps();
|
|
168
170
|
init_transaction();
|
|
169
171
|
}));
|
|
170
172
|
//#endregion
|