@xopcai/xopc 0.0.94 → 0.0.96
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/feishu/src/outbound/media-load.js +1 -1
- package/dist/extensions/feishu/src/workflow-progress.js +1 -1
- package/dist/extensions/telegram/src/plugin.js +1 -1
- package/dist/extensions/telegram/src/routing-integration.js +2 -2
- package/dist/extensions/telegram/src/workflow-progress.js +1 -1
- package/dist/extensions/telegram/xopc.extension.json +1 -1
- package/dist/extensions/weixin/src/api/api.js +2 -2
- package/dist/extensions/weixin/src/auth/accounts.js +1 -1
- package/dist/extensions/weixin/src/cdn/upload.js +1 -1
- package/dist/extensions/weixin/src/media/data-url.js +1 -1
- package/dist/extensions/weixin/src/messaging/debug-mode.js +1 -1
- package/dist/extensions/weixin/src/messaging/inbound.js +1 -1
- package/dist/extensions/weixin/src/messaging/process-message.js +1 -1
- package/dist/extensions/weixin/src/plugin.js +1 -1
- package/dist/extensions/weixin/src/storage/sync-buf.js +1 -1
- package/dist/extensions/weixin/src/workflow-progress.js +1 -1
- package/dist/gateway/static/root/assets/{agents-OqhbJkMf.js → agents-DmIuSaOE.js} +3 -3
- package/dist/gateway/static/root/assets/{apps-page-OHXW9XP8.js → apps-page-DFcHBxLw.js} +1 -1
- package/dist/gateway/static/root/assets/{channels-settings-4N2R-jof.js → channels-settings-DDUf55C5.js} +1 -1
- package/dist/gateway/static/root/assets/{channels-status-swr-Bv6f9kDq.js → channels-status-swr-BxF-_nzD.js} +1 -1
- package/dist/gateway/static/root/assets/{cron-api-BtaQaHJq.js → cron-api-DylQtnb_.js} +1 -1
- package/dist/gateway/static/root/assets/{cron-page-Dah32HJK.js → cron-page-BO0d9Pf-.js} +1 -1
- package/dist/gateway/static/root/assets/{dist-BJfD9Qvs.js → dist-BskF0qDS.js} +1 -1
- package/dist/gateway/static/root/assets/{extension-debug-page-DnYuMzmH.js → extension-debug-page-BcZdTdjJ.js} +1 -1
- package/dist/gateway/static/root/assets/{extension-page-CJfc-6XV.js → extension-page-D2iuDa1D.js} +1 -1
- package/dist/gateway/static/root/assets/{extension-settings-page-BxdfYQMG.js → extension-settings-page-BKpQCgLc.js} +1 -1
- package/dist/gateway/static/root/assets/{fetch-B0aeeY0q.js → fetch-CtNDpjij.js} +1 -1
- package/dist/gateway/static/root/assets/{field-primitives-DOLHwowi.js → field-primitives-2PekrGZF.js} +1 -1
- package/dist/gateway/static/root/assets/{heartbeat-config-api-Bj2INAf5.js → heartbeat-config-api-D3D7SW8A.js} +1 -1
- package/dist/gateway/static/root/assets/index-BvEhL9RQ.css +1 -0
- package/dist/gateway/static/root/assets/{index-DuQ1XPoA.js → index-Db9fd_X4.js} +74 -74
- package/dist/gateway/static/root/assets/{logs-page-AsOgLNJE.js → logs-page-B3I1a26m.js} +1 -1
- package/dist/gateway/static/root/assets/{note-detail-page-24J4mVP-.js → note-detail-page-BOizhtJ8.js} +54 -53
- package/dist/gateway/static/root/assets/{note-detail-page-B91pLkEI.css → note-detail-page-D4ZIVQbk.css} +1 -1
- package/dist/gateway/static/root/assets/{note-time-JBszYV3s.js → note-time-CjUGtqKr.js} +1 -1
- package/dist/gateway/static/root/assets/notes-page-BB8-I0Of.js +1 -0
- package/dist/gateway/static/root/assets/{sessions-page-DX9huWsA.js → sessions-page-BcH-1K9i.js} +1 -1
- package/dist/gateway/static/root/assets/{settings-advanced-gate-DWvhsTuz.js → settings-advanced-gate-Czn8nnjN.js} +2 -2
- package/dist/gateway/static/root/assets/{settings-form-section-CxMjaMiy.js → settings-form-section-ZZWDwgVe.js} +1 -1
- package/dist/gateway/static/root/assets/settings-page-BX8c_zrN.js +3 -0
- package/dist/gateway/static/root/assets/share-preview-page-Ch3_6Qah.js +2 -0
- package/dist/gateway/static/root/assets/{skills-page-CGKGKfwe.js → skills-page-WO0bbJ54.js} +1 -1
- package/dist/gateway/static/root/assets/{theme-store-Cg_SuBw0.js → theme-store-XxRFRZDX.js} +1 -1
- package/dist/gateway/static/root/assets/url-6zpynn1R.js +3 -0
- package/dist/gateway/static/root/assets/{utils-BmlcxR2j.js → utils-uTYKh54l.js} +1 -1
- package/dist/gateway/static/root/assets/{voice-api-key-field-DaGm2N4J.js → voice-api-key-field-BIAYHRs-.js} +1 -1
- package/dist/gateway/static/root/assets/{workflow-page.utils-D0vsIGHD.js → workflow-page.utils-BbWhqD36.js} +1 -1
- package/dist/gateway/static/root/assets/{workflows-page-BFCrD3nw.js → workflows-page-D4RIF7E1.js} +2 -2
- package/dist/gateway/static/root/index.html +5 -5
- package/dist/package.js +1 -1
- package/dist/src/agent/agent-manager.js +15 -9
- package/dist/src/agent/agent-manager.js.map +1 -1
- package/dist/src/agent/agent-scope.d.ts +0 -1
- package/dist/src/agent/agent-scope.js +2 -5
- package/dist/src/agent/agent-scope.js.map +1 -1
- package/dist/src/agent/bootstrap/bootstrap-cache.d.ts +3 -0
- package/dist/src/agent/bootstrap/bootstrap-cache.js +13 -3
- package/dist/src/agent/bootstrap/bootstrap-cache.js.map +1 -1
- package/dist/src/agent/bootstrap/bootstrap-files.d.ts +6 -0
- package/dist/src/agent/bootstrap/bootstrap-files.js +35 -12
- package/dist/src/agent/bootstrap/bootstrap-files.js.map +1 -1
- package/dist/src/agent/bootstrap/load-bootstrap-files.d.ts +5 -2
- package/dist/src/agent/bootstrap/load-bootstrap-files.js +12 -3
- package/dist/src/agent/bootstrap/load-bootstrap-files.js.map +1 -1
- package/dist/src/agent/context/workspace-seed.js +8 -4
- package/dist/src/agent/context/workspace-seed.js.map +1 -1
- package/dist/src/agent/context/workspace-state.d.ts +52 -0
- package/dist/src/agent/context/workspace-state.js +101 -0
- package/dist/src/agent/context/workspace-state.js.map +1 -0
- package/dist/src/agent/embedded/index.d.ts +2 -2
- package/dist/src/agent/embedded/index.js +3 -3
- package/dist/src/agent/embedded/run-turn.js +0 -3
- package/dist/src/agent/embedded/run-turn.js.map +1 -1
- package/dist/src/agent/embedded/session-manager-init.d.ts +0 -17
- package/dist/src/agent/embedded/session-manager-init.js +1 -36
- package/dist/src/agent/embedded/session-manager-init.js.map +1 -1
- package/dist/src/agent/embedded/session-runner.d.ts +3 -12
- package/dist/src/agent/embedded/session-runner.js +12 -26
- package/dist/src/agent/embedded/session-runner.js.map +1 -1
- package/dist/src/agent/embedded/session-tool-result-guard.js +2 -4
- package/dist/src/agent/embedded/session-tool-result-guard.js.map +1 -1
- package/dist/src/agent/embedded/sqlite-hydrating-session-manager.d.ts +10 -0
- package/dist/src/agent/embedded/sqlite-hydrating-session-manager.js +34 -0
- package/dist/src/agent/embedded/sqlite-hydrating-session-manager.js.map +1 -0
- package/dist/src/agent/goals/goal-run-store.js +4 -4
- package/dist/src/agent/goals/persistent-goal-service.js +8 -15
- package/dist/src/agent/goals/persistent-goal-service.js.map +1 -1
- package/dist/src/agent/goals/post-turn.js +2 -2
- package/dist/src/agent/image/load-image-media.js +2 -2
- package/dist/src/agent/ipc/bus.js +1 -1
- package/dist/src/agent/ipc/inbox.js +2 -2
- package/dist/src/agent/ipc/socket.js +1 -1
- package/dist/src/agent/mcp/bundle-mcp-materialize.js +1 -1
- package/dist/src/agent/mcp/bundle-mcp-runtime.js +2 -2
- package/dist/src/agent/mcp/mcp-transport-config.js +1 -1
- package/dist/src/agent/mcp/mcp-transport.js +1 -1
- package/dist/src/agent/memory/builtin-memory-store.js +1 -1
- package/dist/src/agent/memory/dreaming/deep-promotion.js +1 -1
- package/dist/src/agent/memory/dreaming/events.js +1 -1
- package/dist/src/agent/memory/dreaming/last-run.js +1 -1
- package/dist/src/agent/memory/dreaming/light-sweep.js +1 -1
- package/dist/src/agent/memory/dreaming/preview.js +1 -1
- package/dist/src/agent/memory/dreaming/rem-patterns.js +1 -1
- package/dist/src/agent/memory/dreaming/short-term-store.js +1 -1
- package/dist/src/agent/memory/dreaming/utils.js +1 -1
- package/dist/src/agent/memory/plugin-discovery.js +1 -1
- package/dist/src/agent/models/manager.js +1 -1
- package/dist/src/agent/prompt/memory/index.d.ts +1 -0
- package/dist/src/agent/prompt/memory/index.js +34 -80
- package/dist/src/agent/prompt/memory/index.js.map +1 -1
- package/dist/src/agent/prompt/service-prompt-builder.js +2 -2
- package/dist/src/agent/reply/post-compaction-context.js +1 -1
- package/dist/src/agent/reply/workspace-boundary-read.js +1 -1
- package/dist/src/agent/sandbox/path-policy.js +2 -2
- package/dist/src/agent/service/build-direct-message-content.js +1 -1
- package/dist/src/agent/service/process-direct-one-shot.js +8 -17
- package/dist/src/agent/service/process-direct-one-shot.js.map +1 -1
- package/dist/src/agent/service/process-direct-streaming.js +14 -23
- package/dist/src/agent/service/process-direct-streaming.js.map +1 -1
- package/dist/src/agent/service.js +7 -11
- package/dist/src/agent/service.js.map +1 -1
- package/dist/src/agent/session/session-inspector.js +1 -1
- package/dist/src/agent/skills/config.js +1 -1
- package/dist/src/agent/skills/hub-hash.js +2 -2
- package/dist/src/agent/skills/hub-lock.js +1 -1
- package/dist/src/agent/skills/hub-pull.js +3 -3
- package/dist/src/agent/skills/index.js +1 -1
- package/dist/src/agent/skills/managed-store.js +1 -1
- package/dist/src/agent/skills/scanner.js +1 -1
- package/dist/src/agent/skills/skill-manage-ops.js +1 -1
- package/dist/src/agent/skills/skill-manager.js +1 -1
- package/dist/src/agent/tools/dreaming-tool.js +1 -1
- package/dist/src/agent/tools/factory.js +1 -1
- package/dist/src/agent/tools/image-generate-tool.js +1 -1
- package/dist/src/agent/tools/index.d.ts +0 -1
- package/dist/src/agent/tools/index.js +1 -2
- package/dist/src/agent/tools/send-media.js +1 -1
- package/dist/src/agent/tools/session-search-tool.d.ts +0 -1
- package/dist/src/agent/tools/session-search-tool.js +11 -6
- package/dist/src/agent/tools/session-search-tool.js.map +1 -1
- package/dist/src/agent/tools/skill-manage-tool.js +1 -1
- package/dist/src/agent/tools/workflow-tool.js +1 -1
- package/dist/src/agent/tools/write.js +1 -1
- package/dist/src/agent/workflow/catalog.js +1 -1
- package/dist/src/auth/credentials.js +3 -3
- package/dist/src/auth/profiles/store.js +1 -1
- package/dist/src/auth/sync-provider-auth.js +1 -1
- package/dist/src/browser/cache-dir-policy.js +1 -1
- package/dist/src/browser/cdp-local-launcher.js +2 -2
- package/dist/src/browser/providers/browser-ext-install.js +4 -4
- package/dist/src/browser/providers/cloakbrowser.js +4 -4
- package/dist/src/browser/providers/playwright-doctor.js +1 -1
- package/dist/src/browser/stealth.js +1 -1
- package/dist/src/channels/attachments/inbound-persist.js +1 -1
- package/dist/src/channels/attachments/outbound-tts-persist.js +1 -1
- package/dist/src/channels/outbound/persist-store.js +1 -1
- package/dist/src/channels/pairing/allow-from-file.js +1 -1
- package/dist/src/channels/pairing/pairing-store.js +2 -2
- package/dist/src/chat-commands/agent-edit.js +2 -2
- package/dist/src/chat-commands/builtins/config.js +2 -2
- package/dist/src/chat-commands/context.js +1 -1
- package/dist/src/cli/commands/config.js +1 -1
- package/dist/src/cli/commands/doctor/checks/config-health.js +1 -1
- package/dist/src/cli/commands/doctor/checks/provider-auth.js +1 -1
- package/dist/src/cli/commands/doctor/checks/session-integrity.js +32 -95
- package/dist/src/cli/commands/doctor/checks/session-integrity.js.map +1 -1
- package/dist/src/cli/commands/doctor/checks/state-integrity.js +1 -1
- package/dist/src/cli/commands/doctor/checks/workspace-status.js +1 -1
- package/dist/src/cli/commands/extension-dev.js +1 -1
- package/dist/src/cli/commands/extension-marketplace.js +1 -1
- package/dist/src/cli/commands/extension-pack.js +1 -1
- package/dist/src/cli/commands/gateway/logs.js +1 -1
- package/dist/src/cli/commands/image.js +1 -1
- package/dist/src/cli/commands/init.js +5 -7
- package/dist/src/cli/commands/init.js.map +1 -1
- package/dist/src/cli/commands/onboard.js +1 -1
- package/dist/src/cli/utils/init-workspace-core.js +2 -2
- package/dist/src/commands/agents.config.js +1 -1
- package/dist/src/config/agent-profile.js +1 -1
- package/dist/src/config/gateway-bind.js +1 -1
- package/dist/src/config/index.js +7 -8
- package/dist/src/config/index.js.map +1 -1
- package/dist/src/config/loader.js +2 -2
- package/dist/src/config/models-json.js +2 -2
- package/dist/src/config/paths-state.d.ts +3 -0
- package/dist/src/config/paths-state.js +7 -3
- package/dist/src/config/paths-state.js.map +1 -1
- package/dist/src/config/paths.d.ts +5 -35
- package/dist/src/config/paths.js +6 -50
- package/dist/src/config/paths.js.map +1 -1
- package/dist/src/config/profile.js +2 -2
- package/dist/src/config/schema.d.ts +15 -0
- package/dist/src/config/schema.js +11 -0
- package/dist/src/config/schema.js.map +1 -1
- package/dist/src/config/workspace-path.js +1 -1
- package/dist/src/cron/execution-types.d.ts +42 -0
- package/dist/src/cron/executor.js +2 -2
- package/dist/src/cron/persistence.js +1 -1
- package/dist/src/cron/run-log-store.d.ts +4 -8
- package/dist/src/cron/run-log-store.js +26 -78
- package/dist/src/cron/run-log-store.js.map +1 -1
- package/dist/src/cron/service.d.ts +3 -3
- package/dist/src/cron/service.js +2 -2
- package/dist/src/cron/service.js.map +1 -1
- package/dist/src/cron/types.d.ts +1 -42
- package/dist/src/daemon/constants.js +1 -1
- package/dist/src/daemon/install-plan.js +2 -2
- package/dist/src/daemon/launchd.js +2 -2
- package/dist/src/daemon/schtasks.js +2 -2
- package/dist/src/daemon/systemd.js +2 -2
- package/dist/src/extensions/bundle-mcp.js +1 -1
- package/dist/src/extensions/discover-extensions.js +1 -1
- package/dist/src/extensions/health.js +1 -1
- package/dist/src/extensions/loader.js +1 -1
- package/dist/src/extensions/lockfile.js +2 -2
- package/dist/src/extensions/update.js +1 -1
- package/dist/src/gateway/agents-admin.js +8 -3
- package/dist/src/gateway/agents-admin.js.map +1 -1
- package/dist/src/gateway/file-path-classifier.d.ts +0 -1
- package/dist/src/gateway/file-path-classifier.js +2 -8
- package/dist/src/gateway/file-path-classifier.js.map +1 -1
- package/dist/src/gateway/heartbeat/service.js +1 -1
- package/dist/src/gateway/hono/lib/config-payload.js +1 -1
- package/dist/src/gateway/hono/lib/extension-store.js +2 -2
- package/dist/src/gateway/hono/lib/static-ui.js +2 -2
- package/dist/src/gateway/hono/oauth.js +1 -1
- package/dist/src/gateway/hono/routes/agents.js +1 -1
- package/dist/src/gateway/hono/routes/auth-registry-extensions.js +1 -1
- package/dist/src/gateway/hono/routes/config-patch/misc.js +1 -1
- package/dist/src/gateway/hono/routes/dreaming.js +1 -1
- package/dist/src/gateway/hono/routes/host-fs.js +2 -2
- package/dist/src/gateway/hono/routes/models.js +1 -1
- package/dist/src/gateway/hono/routes/shares.js +1 -1
- package/dist/src/gateway/hono/routes/workspace.js +2 -2
- package/dist/src/gateway/lock.js +3 -3
- package/dist/src/gateway/ports.js +1 -1
- package/dist/src/gateway/service/agent-runner.js +2 -2
- package/dist/src/gateway/service/marketplace-service.js +2 -2
- package/dist/src/gateway/service.js +5 -1
- package/dist/src/gateway/service.js.map +1 -1
- package/dist/src/gateway/session-reset-service.d.ts +1 -1
- package/dist/src/gateway/session-reset-service.js +1 -1
- package/dist/src/gateway/session-reset-service.js.map +1 -1
- package/dist/src/gateway/workspace-fs-file-list.js +1 -1
- package/dist/src/heartbeat/index.js +1 -1
- package/dist/src/infra/brew.js +1 -1
- package/dist/src/infra/node-sqlite.d.ts +1 -0
- package/dist/src/infra/node-sqlite.js +17 -0
- package/dist/src/infra/node-sqlite.js.map +1 -0
- package/dist/src/infra/package-json.js +1 -1
- package/dist/src/infra/package-update-steps.js +1 -1
- package/dist/src/infra/path-env.js +2 -2
- package/dist/src/infra/restart.js +2 -2
- package/dist/src/infra/sqlite-errors.d.ts +1 -0
- package/dist/src/infra/sqlite-errors.js +77 -0
- package/dist/src/infra/sqlite-errors.js.map +1 -0
- package/dist/src/infra/stable-node-path.js +1 -1
- package/dist/src/infra/unhandled-rejections.d.ts +1 -0
- package/dist/src/infra/unhandled-rejections.js +25 -0
- package/dist/src/infra/unhandled-rejections.js.map +1 -0
- package/dist/src/infra/update-check.js +1 -1
- package/dist/src/infra/update-global.js +1 -1
- package/dist/src/infra/update-lock.js +3 -3
- package/dist/src/infra/update-runner.js +1 -1
- package/dist/src/infra/update-startup.js +2 -2
- package/dist/src/infra/warning-filter.d.ts +7 -0
- package/dist/src/infra/warning-filter.js +59 -0
- package/dist/src/infra/warning-filter.js.map +1 -0
- package/dist/src/infra/write-file-atomic.js +2 -2
- package/dist/src/notes/store.d.ts +3 -9
- package/dist/src/notes/store.js +22 -196
- package/dist/src/notes/store.js.map +1 -1
- package/dist/src/providers/auth-runtime/auth-profile-store.js +1 -1
- package/dist/src/providers/index.js +2 -2
- package/dist/src/providers/model-registry.js +1 -1
- package/dist/src/session/config-store.d.ts +6 -75
- package/dist/src/session/config-store.js +38 -144
- package/dist/src/session/config-store.js.map +1 -1
- package/dist/src/session/config-types.d.ts +15 -0
- package/dist/src/session/config-types.js +1 -0
- package/dist/src/session/index.d.ts +1 -3
- package/dist/src/session/index.js +3 -5
- package/dist/src/session/init-session-turn.d.ts +0 -6
- package/dist/src/session/init-session-turn.js +18 -18
- package/dist/src/session/init-session-turn.js.map +1 -1
- package/dist/src/session/lifecycle-timestamps.d.ts +5 -2
- package/dist/src/session/lifecycle-timestamps.js.map +1 -1
- package/dist/src/session/{parity/load-jsonl-entries.js → load-jsonl-entries.js} +1 -1
- package/dist/src/session/load-jsonl-entries.js.map +1 -0
- package/dist/src/session/manager.d.ts +5 -3
- package/dist/src/session/manager.js +1 -5
- package/dist/src/session/manager.js.map +1 -1
- package/dist/src/session/resolve-session.d.ts +3 -6
- package/dist/src/session/resolve-session.js +26 -31
- package/dist/src/session/resolve-session.js.map +1 -1
- package/dist/src/session/session-context-for-llm.js +5 -1
- package/dist/src/session/session-context-for-llm.js.map +1 -1
- package/dist/src/session/session-id.js +12 -0
- package/dist/src/session/session-id.js.map +1 -0
- package/dist/src/session/session-title.js +2 -2
- package/dist/src/session/session-workspace.d.ts +1 -1
- package/dist/src/session/session-workspace.js.map +1 -1
- package/dist/src/session/store.d.ts +14 -63
- package/dist/src/session/store.js +172 -847
- package/dist/src/session/store.js.map +1 -1
- package/dist/src/session/stored-rows-to-file-entries.d.ts +11 -0
- package/dist/src/session/stored-rows-to-file-entries.js +95 -0
- package/dist/src/session/stored-rows-to-file-entries.js.map +1 -0
- package/dist/src/session/transcript-events.d.ts +1 -2
- package/dist/src/session/transcript-events.js +5 -12
- package/dist/src/session/transcript-events.js.map +1 -1
- package/dist/src/session/transcript-format.d.ts +1 -1
- package/dist/src/session/transcript-format.js.map +1 -1
- package/dist/src/session/transcript-stats.d.ts +1 -0
- package/dist/src/session/transcript-stats.js +10 -0
- package/dist/src/session/transcript-stats.js.map +1 -0
- package/dist/src/share/share-auto.js +2 -2
- package/dist/src/share/share-store.js +3 -3
- package/dist/src/share/share-thumbnail.js +2 -2
- package/dist/src/share/share-zip.js +1 -1
- package/dist/src/share/site-share-store.js +3 -3
- package/dist/src/share/site-static-serve.js +1 -1
- package/dist/src/storage/sqlite/config-repository.d.ts +6 -0
- package/dist/src/storage/sqlite/config-repository.js +56 -0
- package/dist/src/storage/sqlite/config-repository.js.map +1 -0
- package/dist/src/storage/sqlite/connection.d.ts +38 -0
- package/dist/src/storage/sqlite/connection.js +258 -0
- package/dist/src/storage/sqlite/connection.js.map +1 -0
- package/dist/src/storage/sqlite/cron-run-repository.d.ts +5 -0
- package/dist/src/storage/sqlite/cron-run-repository.js +97 -0
- package/dist/src/storage/sqlite/cron-run-repository.js.map +1 -0
- package/dist/src/storage/sqlite/fts.d.ts +2 -0
- package/dist/src/storage/sqlite/fts.js +11 -0
- package/dist/src/storage/sqlite/fts.js.map +1 -0
- package/dist/src/storage/sqlite/index.d.ts +12 -0
- package/dist/src/storage/sqlite/index.js +13 -0
- package/dist/src/storage/sqlite/memory-index-repository.d.ts +18 -0
- package/dist/src/storage/sqlite/memory-index-repository.js +132 -0
- package/dist/src/storage/sqlite/memory-index-repository.js.map +1 -0
- package/dist/src/storage/sqlite/notes-repository.d.ts +11 -0
- package/dist/src/storage/sqlite/notes-repository.js +191 -0
- package/dist/src/storage/sqlite/notes-repository.js.map +1 -0
- package/dist/src/storage/sqlite/paths.d.ts +1 -0
- package/dist/src/storage/sqlite/paths.js +7 -0
- package/dist/src/storage/sqlite/paths.js.map +1 -0
- package/dist/src/storage/sqlite/row-mappers.d.ts +82 -0
- package/dist/src/storage/sqlite/row-mappers.js +164 -0
- package/dist/src/storage/sqlite/row-mappers.js.map +1 -0
- package/dist/src/storage/sqlite/schema.d.ts +5 -0
- package/dist/src/storage/sqlite/schema.js +43 -0
- package/dist/src/storage/sqlite/schema.js.map +1 -0
- package/dist/src/storage/sqlite/schema.sql +195 -0
- package/dist/src/storage/sqlite/session-metadata.d.ts +8 -0
- package/dist/src/storage/sqlite/session-metadata.js +83 -0
- package/dist/src/storage/sqlite/session-metadata.js.map +1 -0
- package/dist/src/storage/sqlite/session-repository.d.ts +29 -0
- package/dist/src/storage/sqlite/session-repository.js +268 -0
- package/dist/src/storage/sqlite/session-repository.js.map +1 -0
- package/dist/src/storage/sqlite/transaction.d.ts +11 -0
- package/dist/src/storage/sqlite/transaction.js +115 -0
- package/dist/src/storage/sqlite/transaction.js.map +1 -0
- package/dist/src/storage/sqlite/transcript-repository.d.ts +34 -0
- package/dist/src/storage/sqlite/transcript-repository.js +241 -0
- package/dist/src/storage/sqlite/transcript-repository.js.map +1 -0
- package/dist/src/tui/clipboard-image.js +3 -3
- package/dist/src/tui/theme-manager.js +1 -1
- package/dist/src/tui/tui-keybindings-file.js +1 -1
- package/dist/src/tui/tui-scoped-models.js +2 -2
- package/dist/src/tui/tui-settings.js +1 -1
- package/dist/src/tui/tui.js +3 -3
- package/dist/src/tunnel/frpc-binary.js +3 -3
- package/dist/src/tunnel/frpc-config.js +1 -1
- package/dist/src/tunnel/frpc-extract.js +1 -1
- package/dist/src/tunnel/tunnel-state.js +1 -1
- package/dist/src/utils/logger/audit.js +1 -1
- package/dist/src/utils/logger/log-store.js +1 -1
- package/dist/src/utils/logger/rotation.js +1 -1
- package/dist/src/voice/tts/audio.js +1 -1
- package/dist/src/voice/tts/providers/edge-speech.js +2 -2
- package/dist/src/workflows/service/workflow-session-bridge.js +41 -64
- package/dist/src/workflows/service/workflow-session-bridge.js.map +1 -1
- package/dist/src/workflows/store/event-store.js +1 -1
- package/dist/src/workflows/store/run-store.js +1 -1
- package/package.json +3 -3
- package/dist/gateway/static/root/assets/index-Bj_l8QDp.css +0 -1
- package/dist/gateway/static/root/assets/notes-page-BApAirFB.js +0 -1
- package/dist/gateway/static/root/assets/settings-page-4VmUTzQs.js +0 -3
- package/dist/gateway/static/root/assets/share-preview-page-IX0TJvRd.js +0 -2
- package/dist/gateway/static/root/assets/url-BHHmdJYc.js +0 -3
- package/dist/src/agent/embedded/session-manager-cache.d.ts +0 -19
- package/dist/src/agent/embedded/session-manager-cache.js +0 -48
- package/dist/src/agent/embedded/session-manager-cache.js.map +0 -1
- package/dist/src/session/parity/artifacts.d.ts +0 -16
- package/dist/src/session/parity/artifacts.js +0 -80
- package/dist/src/session/parity/artifacts.js.map +0 -1
- package/dist/src/session/parity/jsonl-transcript-io.d.ts +0 -54
- package/dist/src/session/parity/jsonl-transcript-io.js +0 -236
- package/dist/src/session/parity/jsonl-transcript-io.js.map +0 -1
- package/dist/src/session/parity/load-jsonl-entries.js.map +0 -1
- package/dist/src/session/parity/session-id.js +0 -18
- package/dist/src/session/parity/session-id.js.map +0 -1
- package/dist/src/session/parity/sessions-json-cache.d.ts +0 -14
- package/dist/src/session/parity/sessions-json-cache.js +0 -98
- package/dist/src/session/parity/sessions-json-cache.js.map +0 -1
- package/dist/src/session/parity/sessions-json-file-read.d.ts +0 -6
- package/dist/src/session/parity/sessions-json-file-read.js +0 -19
- package/dist/src/session/parity/sessions-json-file-read.js.map +0 -1
- package/dist/src/session/parity/sessions-json-file.d.ts +0 -11
- package/dist/src/session/parity/sessions-json-file.js +0 -52
- package/dist/src/session/parity/sessions-json-file.js.map +0 -1
- package/dist/src/session/parity/sessions-json-patch.d.ts +0 -14
- package/dist/src/session/parity/sessions-json-patch.js +0 -40
- package/dist/src/session/parity/sessions-json-patch.js.map +0 -1
- package/dist/src/session/parity/transcript-file-lock.d.ts +0 -22
- package/dist/src/session/parity/transcript-file-lock.js +0 -142
- package/dist/src/session/parity/transcript-file-lock.js.map +0 -1
- package/dist/src/session/parity/transcript-pagination.d.ts +0 -29
- package/dist/src/session/parity/transcript-pagination.js +0 -132
- package/dist/src/session/parity/transcript-pagination.js.map +0 -1
- package/dist/src/session/parity/transcript-paths.d.ts +0 -13
- package/dist/src/session/parity/transcript-paths.js +0 -64
- package/dist/src/session/parity/transcript-paths.js.map +0 -1
- package/dist/src/session/parity/xopc-session-disk-entry.d.ts +0 -22
- package/dist/src/session/search-index-cache.d.ts +0 -6
- package/dist/src/session/search-index-cache.js +0 -44
- package/dist/src/session/search-index-cache.js.map +0 -1
- package/dist/src/session/search-index.d.ts +0 -20
- package/dist/src/session/search-index.js +0 -124
- package/dist/src/session/search-index.js.map +0 -1
- /package/dist/src/{session/parity/xopc-session-disk-entry.js → cron/execution-types.js} +0 -0
- /package/dist/src/session/{parity/load-jsonl-entries.d.ts → load-jsonl-entries.d.ts} +0 -0
- /package/dist/src/session/{parity/session-id.d.ts → session-id.d.ts} +0 -0
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
import { getSqliteDatabase, runSqliteWriteTransaction } from "./transaction.js";
|
|
2
|
+
import { buildSessionContextForLlm } from "../../session/session-context-for-llm.js";
|
|
3
|
+
import { classifyStoredRow, estimateTokensFromMessages, extractFtsContent, transcriptEntryRowToStoredRow } from "./row-mappers.js";
|
|
4
|
+
import { getCurrentTranscriptId, readCurrentTranscriptId } from "./session-repository.js";
|
|
5
|
+
import { randomUUID } from "node:crypto";
|
|
6
|
+
//#region src/storage/sqlite/transcript-repository.ts
|
|
7
|
+
const MAX_CHECKPOINTS_PER_TRANSCRIPT = 15;
|
|
8
|
+
function nextSeq(db, transcriptId) {
|
|
9
|
+
return (db.prepare(`SELECT COALESCE(MAX(seq), 0) AS max_seq FROM transcript_entries WHERE transcript_id = ?`).get(transcriptId).max_seq ?? 0) + 1;
|
|
10
|
+
}
|
|
11
|
+
function insertEntry(db, params) {
|
|
12
|
+
const { entryKind, role } = classifyStoredRow(params.row);
|
|
13
|
+
const entryId = params.entryId ?? randomUUID();
|
|
14
|
+
const seq = nextSeq(db, params.transcriptId);
|
|
15
|
+
const createdAt = params.createdAt ?? Date.now();
|
|
16
|
+
const payloadJson = JSON.stringify(params.row);
|
|
17
|
+
db.prepare(`INSERT INTO transcript_entries (entry_id, transcript_id, seq, entry_kind, role, payload_json, created_at)
|
|
18
|
+
VALUES (?, ?, ?, ?, ?, ?, ?)`).run(entryId, params.transcriptId, seq, entryKind, role, payloadJson, createdAt);
|
|
19
|
+
const content = extractFtsContent(params.row);
|
|
20
|
+
if (content.trim()) db.prepare(`INSERT INTO transcript_fts (content, session_key, transcript_id, entry_id)
|
|
21
|
+
VALUES (?, ?, ?, ?)`).run(content, params.sessionKey, params.transcriptId, entryId);
|
|
22
|
+
return {
|
|
23
|
+
entry_id: entryId,
|
|
24
|
+
transcript_id: params.transcriptId,
|
|
25
|
+
seq,
|
|
26
|
+
entry_kind: entryKind,
|
|
27
|
+
role,
|
|
28
|
+
payload_json: payloadJson,
|
|
29
|
+
created_at: createdAt
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
function appendTranscriptEntry(sessionKey, row, opts) {
|
|
33
|
+
return runSqliteWriteTransaction((db) => {
|
|
34
|
+
const transcriptId = opts?.transcriptId ?? readCurrentTranscriptId(db, sessionKey);
|
|
35
|
+
if (!transcriptId) throw new Error(`Session not found: ${sessionKey}`);
|
|
36
|
+
const inserted = insertEntry(db, {
|
|
37
|
+
transcriptId,
|
|
38
|
+
sessionKey,
|
|
39
|
+
row
|
|
40
|
+
});
|
|
41
|
+
if (classifyStoredRow(row).entryKind === "message") {
|
|
42
|
+
const tokenDelta = opts?.tokenDelta ?? 0;
|
|
43
|
+
const now = Date.now();
|
|
44
|
+
db.prepare(`UPDATE sessions SET
|
|
45
|
+
message_count = message_count + 1,
|
|
46
|
+
estimated_tokens = estimated_tokens + ?,
|
|
47
|
+
updated_at = ?,
|
|
48
|
+
last_accessed_at = ?,
|
|
49
|
+
last_interaction_at = ?
|
|
50
|
+
WHERE session_key = ?`).run(tokenDelta, now, now, now, sessionKey);
|
|
51
|
+
}
|
|
52
|
+
return inserted;
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
function loadTranscriptRowsForSession(sessionKey) {
|
|
56
|
+
const transcriptId = getCurrentTranscriptId(sessionKey);
|
|
57
|
+
if (!transcriptId) return [];
|
|
58
|
+
return loadTranscriptRows(transcriptId);
|
|
59
|
+
}
|
|
60
|
+
function loadTranscriptRows(transcriptId) {
|
|
61
|
+
return getSqliteDatabase().prepare(`SELECT entry_id, transcript_id, seq, entry_kind, role, payload_json, created_at
|
|
62
|
+
FROM transcript_entries
|
|
63
|
+
WHERE transcript_id = ?
|
|
64
|
+
ORDER BY seq ASC`).all(transcriptId).map(transcriptEntryRowToStoredRow);
|
|
65
|
+
}
|
|
66
|
+
function loadLlmMessagesForSession(sessionKey) {
|
|
67
|
+
return buildSessionContextForLlm(loadTranscriptRowsForSession(sessionKey));
|
|
68
|
+
}
|
|
69
|
+
function replaceTranscriptRows(sessionKey, rows, opts) {
|
|
70
|
+
runSqliteWriteTransaction((db) => {
|
|
71
|
+
const transcriptId = readCurrentTranscriptId(db, sessionKey);
|
|
72
|
+
if (!transcriptId) throw new Error(`Session not found: ${sessionKey}`);
|
|
73
|
+
db.prepare(`DELETE FROM transcript_fts WHERE transcript_id = ?`).run(transcriptId);
|
|
74
|
+
db.prepare(`DELETE FROM transcript_entries WHERE transcript_id = ?`).run(transcriptId);
|
|
75
|
+
const toWrite = [...rows];
|
|
76
|
+
if (opts?.appendCompaction) toWrite.push({
|
|
77
|
+
type: "compaction",
|
|
78
|
+
...opts.appendCompaction
|
|
79
|
+
});
|
|
80
|
+
for (const row of toWrite) insertEntry(db, {
|
|
81
|
+
transcriptId,
|
|
82
|
+
sessionKey,
|
|
83
|
+
row
|
|
84
|
+
});
|
|
85
|
+
const llm = buildSessionContextForLlm(toWrite);
|
|
86
|
+
const now = Date.now();
|
|
87
|
+
db.prepare(`UPDATE sessions SET
|
|
88
|
+
message_count = ?,
|
|
89
|
+
estimated_tokens = ?,
|
|
90
|
+
updated_at = ?,
|
|
91
|
+
last_accessed_at = ?,
|
|
92
|
+
last_interaction_at = ?
|
|
93
|
+
WHERE session_key = ?`).run(llm.length, estimateTokensFromMessages(llm), now, now, now, sessionKey);
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
function loadCheckpointRows(sessionKey, checkpointId) {
|
|
97
|
+
const db = getSqliteDatabase();
|
|
98
|
+
if (!db.prepare(`SELECT checkpoint_id FROM compaction_checkpoints
|
|
99
|
+
WHERE session_key = ? AND checkpoint_id = ?`).get(sessionKey, checkpointId)) return [];
|
|
100
|
+
return db.prepare(`SELECT payload_json FROM checkpoint_entries
|
|
101
|
+
WHERE checkpoint_id = ?
|
|
102
|
+
ORDER BY seq ASC`).all(checkpointId).map((entry) => JSON.parse(entry.payload_json));
|
|
103
|
+
}
|
|
104
|
+
function paginateTranscriptMessages(sessionKey, options = {}) {
|
|
105
|
+
const transcriptId = getCurrentTranscriptId(sessionKey);
|
|
106
|
+
if (!transcriptId) return {
|
|
107
|
+
rows: [],
|
|
108
|
+
messages: [],
|
|
109
|
+
total: 0,
|
|
110
|
+
startSeq: 0,
|
|
111
|
+
endSeq: 0
|
|
112
|
+
};
|
|
113
|
+
const db = getSqliteDatabase();
|
|
114
|
+
const kinds = options.includeContext ? ["message", "context"] : ["message"];
|
|
115
|
+
const kindPlaceholders = kinds.map(() => "?").join(", ");
|
|
116
|
+
const total = db.prepare(`SELECT COUNT(*) AS total FROM transcript_entries
|
|
117
|
+
WHERE transcript_id = ? AND entry_kind IN (${kindPlaceholders})`).get(transcriptId, ...kinds).total;
|
|
118
|
+
const limit = Math.min(200, Math.max(1, Math.trunc(options.limit ?? 50)));
|
|
119
|
+
const offset = Math.max(0, Math.trunc(options.offset ?? 0));
|
|
120
|
+
let rows;
|
|
121
|
+
if (options.beforeEndIndex !== void 0 && Number.isFinite(options.beforeEndIndex)) {
|
|
122
|
+
const endExclusive = Math.min(total, Math.max(0, Math.trunc(options.beforeEndIndex)));
|
|
123
|
+
const startInclusive = Math.max(0, endExclusive - limit);
|
|
124
|
+
rows = db.prepare(`SELECT entry_id, transcript_id, seq, entry_kind, role, payload_json, created_at
|
|
125
|
+
FROM (
|
|
126
|
+
SELECT entry_id, transcript_id, seq, entry_kind, role, payload_json, created_at,
|
|
127
|
+
ROW_NUMBER() OVER (ORDER BY seq ASC) - 1 AS idx
|
|
128
|
+
FROM transcript_entries
|
|
129
|
+
WHERE transcript_id = ? AND entry_kind IN (${kindPlaceholders})
|
|
130
|
+
)
|
|
131
|
+
WHERE idx >= ? AND idx < ?
|
|
132
|
+
ORDER BY seq ASC`).all(transcriptId, ...kinds, startInclusive, endExclusive);
|
|
133
|
+
} else if (options.beforeSeq !== void 0 && Number.isFinite(options.beforeSeq)) {
|
|
134
|
+
rows = db.prepare(`SELECT entry_id, transcript_id, seq, entry_kind, role, payload_json, created_at
|
|
135
|
+
FROM transcript_entries
|
|
136
|
+
WHERE transcript_id = ? AND entry_kind IN (${kindPlaceholders}) AND seq < ?
|
|
137
|
+
ORDER BY seq DESC
|
|
138
|
+
LIMIT ?`).all(transcriptId, ...kinds, options.beforeSeq, limit);
|
|
139
|
+
rows.reverse();
|
|
140
|
+
} else {
|
|
141
|
+
rows = db.prepare(`SELECT entry_id, transcript_id, seq, entry_kind, role, payload_json, created_at
|
|
142
|
+
FROM transcript_entries
|
|
143
|
+
WHERE transcript_id = ? AND entry_kind IN (${kindPlaceholders})
|
|
144
|
+
ORDER BY seq DESC
|
|
145
|
+
LIMIT ? OFFSET ?`).all(transcriptId, ...kinds, limit, offset);
|
|
146
|
+
rows.reverse();
|
|
147
|
+
}
|
|
148
|
+
const storedRows = rows.map(transcriptEntryRowToStoredRow);
|
|
149
|
+
return {
|
|
150
|
+
rows: storedRows,
|
|
151
|
+
messages: buildSessionContextForLlm(storedRows),
|
|
152
|
+
total,
|
|
153
|
+
startSeq: rows[0]?.seq ?? 0,
|
|
154
|
+
endSeq: rows[rows.length - 1]?.seq ?? 0
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
function captureCompactionCheckpoint(sessionKey) {
|
|
158
|
+
return runSqliteWriteTransaction((db) => {
|
|
159
|
+
const transcriptId = readCurrentTranscriptId(db, sessionKey);
|
|
160
|
+
if (!transcriptId) return null;
|
|
161
|
+
const entries = db.prepare(`SELECT entry_id, transcript_id, seq, entry_kind, role, payload_json, created_at
|
|
162
|
+
FROM transcript_entries WHERE transcript_id = ? ORDER BY seq ASC`).all(transcriptId);
|
|
163
|
+
if (entries.length === 0) return null;
|
|
164
|
+
const checkpointId = randomUUID();
|
|
165
|
+
const now = Date.now();
|
|
166
|
+
const messageCount = entries.filter((e) => e.entry_kind === "message").length;
|
|
167
|
+
const sizeBytes = entries.reduce((sum, e) => sum + e.payload_json.length, 0);
|
|
168
|
+
db.prepare(`INSERT INTO compaction_checkpoints
|
|
169
|
+
(checkpoint_id, transcript_id, session_key, created_at, message_count, size_bytes)
|
|
170
|
+
VALUES (?, ?, ?, ?, ?, ?)`).run(checkpointId, transcriptId, sessionKey, now, messageCount, sizeBytes);
|
|
171
|
+
const insertCheckpointEntry = db.prepare(`INSERT INTO checkpoint_entries (checkpoint_id, seq, entry_kind, role, payload_json)
|
|
172
|
+
VALUES (?, ?, ?, ?, ?)`);
|
|
173
|
+
for (const entry of entries) insertCheckpointEntry.run(checkpointId, entry.seq, entry.entry_kind, entry.role, entry.payload_json);
|
|
174
|
+
pruneCompactionCheckpoints(db, transcriptId);
|
|
175
|
+
return checkpointId;
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
function pruneCompactionCheckpoints(db, transcriptId) {
|
|
179
|
+
const rows = db.prepare(`SELECT checkpoint_id FROM compaction_checkpoints
|
|
180
|
+
WHERE transcript_id = ?
|
|
181
|
+
ORDER BY created_at ASC`).all(transcriptId);
|
|
182
|
+
if (rows.length <= MAX_CHECKPOINTS_PER_TRANSCRIPT) return;
|
|
183
|
+
const toDelete = rows.slice(0, rows.length - MAX_CHECKPOINTS_PER_TRANSCRIPT);
|
|
184
|
+
const del = db.prepare(`DELETE FROM compaction_checkpoints WHERE checkpoint_id = ?`);
|
|
185
|
+
for (const row of toDelete) del.run(row.checkpoint_id);
|
|
186
|
+
}
|
|
187
|
+
function listCompactionCheckpoints(sessionKey) {
|
|
188
|
+
return getSqliteDatabase().prepare(`SELECT checkpoint_id, created_at, message_count, size_bytes
|
|
189
|
+
FROM compaction_checkpoints
|
|
190
|
+
WHERE session_key = ?
|
|
191
|
+
ORDER BY created_at DESC`).all(sessionKey).map((row) => ({
|
|
192
|
+
id: row.checkpoint_id,
|
|
193
|
+
sizeBytes: row.size_bytes,
|
|
194
|
+
modifiedAt: new Date(row.created_at).toISOString()
|
|
195
|
+
}));
|
|
196
|
+
}
|
|
197
|
+
function getCompactionCheckpointDetail(sessionKey, checkpointId) {
|
|
198
|
+
const row = getSqliteDatabase().prepare(`SELECT checkpoint_id, created_at, message_count, size_bytes
|
|
199
|
+
FROM compaction_checkpoints
|
|
200
|
+
WHERE session_key = ? AND checkpoint_id = ?`).get(sessionKey, checkpointId);
|
|
201
|
+
if (!row) return null;
|
|
202
|
+
return {
|
|
203
|
+
id: row.checkpoint_id,
|
|
204
|
+
sizeBytes: row.size_bytes,
|
|
205
|
+
modifiedAt: new Date(row.created_at).toISOString(),
|
|
206
|
+
messageCount: row.message_count
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
function restoreCompactionCheckpoint(sessionKey, checkpointId) {
|
|
210
|
+
runSqliteWriteTransaction((db) => {
|
|
211
|
+
const transcriptId = readCurrentTranscriptId(db, sessionKey);
|
|
212
|
+
if (!transcriptId) throw new Error(`Session not found: ${sessionKey}`);
|
|
213
|
+
if (!db.prepare(`SELECT checkpoint_id FROM compaction_checkpoints
|
|
214
|
+
WHERE session_key = ? AND checkpoint_id = ?`).get(sessionKey, checkpointId)) throw new Error(`Checkpoint not found: ${checkpointId}`);
|
|
215
|
+
const entries = db.prepare(`SELECT seq, entry_kind, role, payload_json
|
|
216
|
+
FROM checkpoint_entries
|
|
217
|
+
WHERE checkpoint_id = ?
|
|
218
|
+
ORDER BY seq ASC`).all(checkpointId);
|
|
219
|
+
db.prepare(`DELETE FROM transcript_fts WHERE transcript_id = ?`).run(transcriptId);
|
|
220
|
+
db.prepare(`DELETE FROM transcript_entries WHERE transcript_id = ?`).run(transcriptId);
|
|
221
|
+
for (const entry of entries) insertEntry(db, {
|
|
222
|
+
transcriptId,
|
|
223
|
+
sessionKey,
|
|
224
|
+
row: JSON.parse(entry.payload_json),
|
|
225
|
+
createdAt: Date.now()
|
|
226
|
+
});
|
|
227
|
+
const llm = buildSessionContextForLlm(entries.map((e) => JSON.parse(e.payload_json)));
|
|
228
|
+
const now = Date.now();
|
|
229
|
+
db.prepare(`UPDATE sessions SET
|
|
230
|
+
message_count = ?,
|
|
231
|
+
estimated_tokens = ?,
|
|
232
|
+
updated_at = ?,
|
|
233
|
+
last_accessed_at = ?,
|
|
234
|
+
last_interaction_at = ?
|
|
235
|
+
WHERE session_key = ?`).run(llm.length, estimateTokensFromMessages(llm), now, now, now, sessionKey);
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
//#endregion
|
|
239
|
+
export { appendTranscriptEntry, captureCompactionCheckpoint, getCompactionCheckpointDetail, listCompactionCheckpoints, loadCheckpointRows, loadLlmMessagesForSession, loadTranscriptRows, loadTranscriptRowsForSession, paginateTranscriptMessages, replaceTranscriptRows, restoreCompactionCheckpoint };
|
|
240
|
+
|
|
241
|
+
//# sourceMappingURL=transcript-repository.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transcript-repository.js","names":[],"sources":["../../../../src/storage/sqlite/transcript-repository.ts"],"sourcesContent":["import { randomUUID } from 'node:crypto';\nimport type { DatabaseSync } from 'node:sqlite';\n\nimport type { AgentMessage } from '@earendil-works/pi-agent-core';\n\nimport type { CompactionCheckpointDetail, CompactionCheckpointSummary } from '../../session/types.js';\nimport type { TranscriptCompactionRecord } from '../../session/transcript-format.js';\nimport {\n buildSessionContextForLlm,\n type TranscriptStoredRow,\n} from '../../session/session-context-for-llm.js';\nimport {\n classifyStoredRow,\n estimateTokensFromMessages,\n extractFtsContent,\n transcriptEntryRowToStoredRow,\n type TranscriptEntryRow,\n} from './row-mappers.js';\nimport { getCurrentTranscriptId, readCurrentTranscriptId } from './session-repository.js';\nimport { getSqliteDatabase, runSqliteWriteTransaction } from './transaction.js';\n\nconst MAX_CHECKPOINTS_PER_TRANSCRIPT = 15;\n\nfunction nextSeq(db: DatabaseSync, transcriptId: string): number {\n const row = db\n .prepare(`SELECT COALESCE(MAX(seq), 0) AS max_seq FROM transcript_entries WHERE transcript_id = ?`)\n .get(transcriptId) as { max_seq: number };\n return (row.max_seq ?? 0) + 1;\n}\n\nfunction insertEntry(\n db: DatabaseSync,\n params: {\n transcriptId: string;\n sessionKey: string;\n row: TranscriptStoredRow;\n entryId?: string;\n createdAt?: number;\n },\n): TranscriptEntryRow {\n const { entryKind, role } = classifyStoredRow(params.row);\n const entryId = params.entryId ?? randomUUID();\n const seq = nextSeq(db, params.transcriptId);\n const createdAt = params.createdAt ?? Date.now();\n const payloadJson = JSON.stringify(params.row);\n\n db.prepare(\n `INSERT INTO transcript_entries (entry_id, transcript_id, seq, entry_kind, role, payload_json, created_at)\n VALUES (?, ?, ?, ?, ?, ?, ?)`,\n ).run(entryId, params.transcriptId, seq, entryKind, role, payloadJson, createdAt);\n\n const content = extractFtsContent(params.row);\n if (content.trim()) {\n db.prepare(\n `INSERT INTO transcript_fts (content, session_key, transcript_id, entry_id)\n VALUES (?, ?, ?, ?)`,\n ).run(content, params.sessionKey, params.transcriptId, entryId);\n }\n\n return {\n entry_id: entryId,\n transcript_id: params.transcriptId,\n seq,\n entry_kind: entryKind,\n role,\n payload_json: payloadJson,\n created_at: createdAt,\n };\n}\n\nexport function appendTranscriptEntry(\n sessionKey: string,\n row: TranscriptStoredRow,\n opts?: { transcriptId?: string; tokenDelta?: number },\n): TranscriptEntryRow {\n return runSqliteWriteTransaction((db) => {\n const transcriptId = opts?.transcriptId ?? readCurrentTranscriptId(db, sessionKey);\n if (!transcriptId) {\n throw new Error(`Session not found: ${sessionKey}`);\n }\n const inserted = insertEntry(db, { transcriptId, sessionKey, row });\n if (classifyStoredRow(row).entryKind === 'message') {\n const tokenDelta = opts?.tokenDelta ?? 0;\n const now = Date.now();\n db.prepare(\n `UPDATE sessions SET\n message_count = message_count + 1,\n estimated_tokens = estimated_tokens + ?,\n updated_at = ?,\n last_accessed_at = ?,\n last_interaction_at = ?\n WHERE session_key = ?`,\n ).run(tokenDelta, now, now, now, sessionKey);\n }\n return inserted;\n });\n}\n\nexport function loadTranscriptRowsForSession(sessionKey: string): TranscriptStoredRow[] {\n const transcriptId = getCurrentTranscriptId(sessionKey);\n if (!transcriptId) {\n return [];\n }\n return loadTranscriptRows(transcriptId);\n}\n\nexport function loadTranscriptRows(transcriptId: string): TranscriptStoredRow[] {\n const db = getSqliteDatabase();\n const rows = db\n .prepare(\n `SELECT entry_id, transcript_id, seq, entry_kind, role, payload_json, created_at\n FROM transcript_entries\n WHERE transcript_id = ?\n ORDER BY seq ASC`,\n )\n .all(transcriptId) as TranscriptEntryRow[];\n return rows.map(transcriptEntryRowToStoredRow);\n}\n\nexport function loadLlmMessagesForSession(sessionKey: string): AgentMessage[] {\n const rows = loadTranscriptRowsForSession(sessionKey);\n return buildSessionContextForLlm(rows);\n}\n\nexport function replaceTranscriptRows(\n sessionKey: string,\n rows: TranscriptStoredRow[],\n opts?: { appendCompaction?: TranscriptCompactionRecord },\n): void {\n runSqliteWriteTransaction((db) => {\n const transcriptId = readCurrentTranscriptId(db, sessionKey);\n if (!transcriptId) {\n throw new Error(`Session not found: ${sessionKey}`);\n }\n\n db.prepare(`DELETE FROM transcript_fts WHERE transcript_id = ?`).run(transcriptId);\n db.prepare(`DELETE FROM transcript_entries WHERE transcript_id = ?`).run(transcriptId);\n\n const toWrite = [...rows];\n if (opts?.appendCompaction) {\n toWrite.push({\n type: 'compaction',\n ...opts.appendCompaction,\n } as unknown as TranscriptStoredRow);\n }\n\n for (const row of toWrite) {\n insertEntry(db, { transcriptId, sessionKey, row });\n }\n\n const llm = buildSessionContextForLlm(toWrite);\n const now = Date.now();\n db.prepare(\n `UPDATE sessions SET\n message_count = ?,\n estimated_tokens = ?,\n updated_at = ?,\n last_accessed_at = ?,\n last_interaction_at = ?\n WHERE session_key = ?`,\n ).run(llm.length, estimateTokensFromMessages(llm), now, now, now, sessionKey);\n });\n}\n\nexport function loadCheckpointRows(sessionKey: string, checkpointId: string): TranscriptStoredRow[] {\n const db = getSqliteDatabase();\n const checkpoint = db\n .prepare(\n `SELECT checkpoint_id FROM compaction_checkpoints\n WHERE session_key = ? AND checkpoint_id = ?`,\n )\n .get(sessionKey, checkpointId) as { checkpoint_id: string } | undefined;\n if (!checkpoint) {\n return [];\n }\n const entries = db\n .prepare(\n `SELECT payload_json FROM checkpoint_entries\n WHERE checkpoint_id = ?\n ORDER BY seq ASC`,\n )\n .all(checkpointId) as Array<{ payload_json: string }>;\n return entries.map((entry) => JSON.parse(entry.payload_json) as TranscriptStoredRow);\n}\n\nexport function paginateTranscriptMessages(\n sessionKey: string,\n options: {\n offset?: number;\n limit?: number;\n beforeSeq?: number;\n /** 0-based exclusive end index (legacy cursor from gateway UI). */\n beforeEndIndex?: number;\n includeContext?: boolean;\n } = {},\n): {\n rows: TranscriptStoredRow[];\n messages: AgentMessage[];\n total: number;\n startSeq: number;\n endSeq: number;\n} {\n const transcriptId = getCurrentTranscriptId(sessionKey);\n if (!transcriptId) {\n return { rows: [], messages: [], total: 0, startSeq: 0, endSeq: 0 };\n }\n\n const db = getSqliteDatabase();\n const kinds = options.includeContext ? ['message', 'context'] : ['message'];\n const kindPlaceholders = kinds.map(() => '?').join(', ');\n\n const countRow = db\n .prepare(\n `SELECT COUNT(*) AS total FROM transcript_entries\n WHERE transcript_id = ? AND entry_kind IN (${kindPlaceholders})`,\n )\n .get(transcriptId, ...kinds) as { total: number };\n const total = countRow.total;\n\n const limit = Math.min(200, Math.max(1, Math.trunc(options.limit ?? 50)));\n const offset = Math.max(0, Math.trunc(options.offset ?? 0));\n\n let rows: TranscriptEntryRow[];\n if (options.beforeEndIndex !== undefined && Number.isFinite(options.beforeEndIndex)) {\n const endExclusive = Math.min(total, Math.max(0, Math.trunc(options.beforeEndIndex)));\n const startInclusive = Math.max(0, endExclusive - limit);\n rows = db\n .prepare(\n `SELECT entry_id, transcript_id, seq, entry_kind, role, payload_json, created_at\n FROM (\n SELECT entry_id, transcript_id, seq, entry_kind, role, payload_json, created_at,\n ROW_NUMBER() OVER (ORDER BY seq ASC) - 1 AS idx\n FROM transcript_entries\n WHERE transcript_id = ? AND entry_kind IN (${kindPlaceholders})\n )\n WHERE idx >= ? AND idx < ?\n ORDER BY seq ASC`,\n )\n .all(transcriptId, ...kinds, startInclusive, endExclusive) as TranscriptEntryRow[];\n } else if (options.beforeSeq !== undefined && Number.isFinite(options.beforeSeq)) {\n rows = db\n .prepare(\n `SELECT entry_id, transcript_id, seq, entry_kind, role, payload_json, created_at\n FROM transcript_entries\n WHERE transcript_id = ? AND entry_kind IN (${kindPlaceholders}) AND seq < ?\n ORDER BY seq DESC\n LIMIT ?`,\n )\n .all(transcriptId, ...kinds, options.beforeSeq, limit) as TranscriptEntryRow[];\n rows.reverse();\n } else {\n rows = db\n .prepare(\n `SELECT entry_id, transcript_id, seq, entry_kind, role, payload_json, created_at\n FROM transcript_entries\n WHERE transcript_id = ? AND entry_kind IN (${kindPlaceholders})\n ORDER BY seq DESC\n LIMIT ? OFFSET ?`,\n )\n .all(transcriptId, ...kinds, limit, offset) as TranscriptEntryRow[];\n rows.reverse();\n }\n\n const storedRows = rows.map(transcriptEntryRowToStoredRow);\n const messages = buildSessionContextForLlm(storedRows);\n const startSeq = rows[0]?.seq ?? 0;\n const endSeq = rows[rows.length - 1]?.seq ?? 0;\n return { rows: storedRows, messages, total, startSeq, endSeq };\n}\n\nexport function captureCompactionCheckpoint(sessionKey: string): string | null {\n return runSqliteWriteTransaction((db) => {\n const transcriptId = readCurrentTranscriptId(db, sessionKey);\n if (!transcriptId) {\n return null;\n }\n\n const entries = db\n .prepare(\n `SELECT entry_id, transcript_id, seq, entry_kind, role, payload_json, created_at\n FROM transcript_entries WHERE transcript_id = ? ORDER BY seq ASC`,\n )\n .all(transcriptId) as TranscriptEntryRow[];\n if (entries.length === 0) {\n return null;\n }\n\n const checkpointId = randomUUID();\n const now = Date.now();\n const messageCount = entries.filter((e) => e.entry_kind === 'message').length;\n const sizeBytes = entries.reduce((sum, e) => sum + e.payload_json.length, 0);\n\n db.prepare(\n `INSERT INTO compaction_checkpoints\n (checkpoint_id, transcript_id, session_key, created_at, message_count, size_bytes)\n VALUES (?, ?, ?, ?, ?, ?)`,\n ).run(checkpointId, transcriptId, sessionKey, now, messageCount, sizeBytes);\n\n const insertCheckpointEntry = db.prepare(\n `INSERT INTO checkpoint_entries (checkpoint_id, seq, entry_kind, role, payload_json)\n VALUES (?, ?, ?, ?, ?)`,\n );\n for (const entry of entries) {\n insertCheckpointEntry.run(\n checkpointId,\n entry.seq,\n entry.entry_kind,\n entry.role,\n entry.payload_json,\n );\n }\n\n pruneCompactionCheckpoints(db, transcriptId);\n return checkpointId;\n });\n}\n\nfunction pruneCompactionCheckpoints(db: DatabaseSync, transcriptId: string): void {\n const rows = db\n .prepare(\n `SELECT checkpoint_id FROM compaction_checkpoints\n WHERE transcript_id = ?\n ORDER BY created_at ASC`,\n )\n .all(transcriptId) as Array<{ checkpoint_id: string }>;\n if (rows.length <= MAX_CHECKPOINTS_PER_TRANSCRIPT) {\n return;\n }\n const toDelete = rows.slice(0, rows.length - MAX_CHECKPOINTS_PER_TRANSCRIPT);\n const del = db.prepare(`DELETE FROM compaction_checkpoints WHERE checkpoint_id = ?`);\n for (const row of toDelete) {\n del.run(row.checkpoint_id);\n }\n}\n\nexport function listCompactionCheckpoints(sessionKey: string): CompactionCheckpointSummary[] {\n const db = getSqliteDatabase();\n const rows = db\n .prepare(\n `SELECT checkpoint_id, created_at, message_count, size_bytes\n FROM compaction_checkpoints\n WHERE session_key = ?\n ORDER BY created_at DESC`,\n )\n .all(sessionKey) as Array<{\n checkpoint_id: string;\n created_at: number;\n message_count: number;\n size_bytes: number;\n }>;\n\n return rows.map((row) => ({\n id: row.checkpoint_id,\n sizeBytes: row.size_bytes,\n modifiedAt: new Date(row.created_at).toISOString(),\n }));\n}\n\nexport function getCompactionCheckpointDetail(\n sessionKey: string,\n checkpointId: string,\n): CompactionCheckpointDetail | null {\n const db = getSqliteDatabase();\n const row = db\n .prepare(\n `SELECT checkpoint_id, created_at, message_count, size_bytes\n FROM compaction_checkpoints\n WHERE session_key = ? AND checkpoint_id = ?`,\n )\n .get(sessionKey, checkpointId) as\n | {\n checkpoint_id: string;\n created_at: number;\n message_count: number;\n size_bytes: number;\n }\n | undefined;\n if (!row) {\n return null;\n }\n return {\n id: row.checkpoint_id,\n sizeBytes: row.size_bytes,\n modifiedAt: new Date(row.created_at).toISOString(),\n messageCount: row.message_count,\n };\n}\n\nexport function restoreCompactionCheckpoint(sessionKey: string, checkpointId: string): void {\n runSqliteWriteTransaction((db) => {\n const transcriptId = readCurrentTranscriptId(db, sessionKey);\n if (!transcriptId) {\n throw new Error(`Session not found: ${sessionKey}`);\n }\n\n const checkpoint = db\n .prepare(\n `SELECT checkpoint_id FROM compaction_checkpoints\n WHERE session_key = ? AND checkpoint_id = ?`,\n )\n .get(sessionKey, checkpointId) as { checkpoint_id: string } | undefined;\n if (!checkpoint) {\n throw new Error(`Checkpoint not found: ${checkpointId}`);\n }\n\n const entries = db\n .prepare(\n `SELECT seq, entry_kind, role, payload_json\n FROM checkpoint_entries\n WHERE checkpoint_id = ?\n ORDER BY seq ASC`,\n )\n .all(checkpointId) as Array<{\n seq: number;\n entry_kind: string;\n role: string | null;\n payload_json: string;\n }>;\n\n db.prepare(`DELETE FROM transcript_fts WHERE transcript_id = ?`).run(transcriptId);\n db.prepare(`DELETE FROM transcript_entries WHERE transcript_id = ?`).run(transcriptId);\n\n for (const entry of entries) {\n const payload = JSON.parse(entry.payload_json) as TranscriptStoredRow;\n insertEntry(db, {\n transcriptId,\n sessionKey,\n row: payload,\n createdAt: Date.now(),\n });\n }\n\n const llm = buildSessionContextForLlm(entries.map((e) => JSON.parse(e.payload_json) as TranscriptStoredRow));\n const now = Date.now();\n db.prepare(\n `UPDATE sessions SET\n message_count = ?,\n estimated_tokens = ?,\n updated_at = ?,\n last_accessed_at = ?,\n last_interaction_at = ?\n WHERE session_key = ?`,\n ).run(llm.length, estimateTokensFromMessages(llm), now, now, now, sessionKey);\n });\n}\n"],"mappings":";;;;;;AAqBA,MAAM,iCAAiC;AAEvC,SAAS,QAAQ,IAAkB,cAA8B;AAI/D,SAHY,GACT,QAAQ,0FAA0F,CAClG,IAAI,aACI,CAAC,WAAW,KAAK;;AAG9B,SAAS,YACP,IACA,QAOoB;CACpB,MAAM,EAAE,WAAW,SAAS,kBAAkB,OAAO,IAAI;CACzD,MAAM,UAAU,OAAO,WAAW,YAAY;CAC9C,MAAM,MAAM,QAAQ,IAAI,OAAO,aAAa;CAC5C,MAAM,YAAY,OAAO,aAAa,KAAK,KAAK;CAChD,MAAM,cAAc,KAAK,UAAU,OAAO,IAAI;AAE9C,IAAG,QACD;mCAED,CAAC,IAAI,SAAS,OAAO,cAAc,KAAK,WAAW,MAAM,aAAa,UAAU;CAEjF,MAAM,UAAU,kBAAkB,OAAO,IAAI;AAC7C,KAAI,QAAQ,MAAM,CAChB,IAAG,QACD;4BAED,CAAC,IAAI,SAAS,OAAO,YAAY,OAAO,cAAc,QAAQ;AAGjE,QAAO;EACL,UAAU;EACV,eAAe,OAAO;EACtB;EACA,YAAY;EACZ;EACA,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MAAM,EAAE,aAAa,CAAwB,CAAC;EAC5G,MAAM,MAAM,KAAK,KAAK;AACtB,KAAG,QACD;;;;;;6BAOD,CAAC,IAAI,IAAI,QAAQ,2BAA2B,IAAI,EAAE,KAAK,KAAK,KAAK,WAAW;GAC7E"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { tmpdir } from "node:os";
|
|
2
|
-
import { join } from "node:path";
|
|
3
|
-
import { readFileSync, unlinkSync, writeFileSync } from "node:fs";
|
|
4
1
|
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { readFileSync, unlinkSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { tmpdir } from "node:os";
|
|
5
5
|
import { spawnSync } from "node:child_process";
|
|
6
6
|
//#region src/tui/clipboard-image.ts
|
|
7
7
|
const SUPPORTED_IMAGE_MIME_TYPES = [
|
|
@@ -2,8 +2,8 @@ import { resolveStateDir } from "../config/paths-state.js";
|
|
|
2
2
|
import { init_paths } from "../config/paths.js";
|
|
3
3
|
import { palette } from "./theme/dark.js";
|
|
4
4
|
import { palette as palette$1 } from "./theme/light.js";
|
|
5
|
-
import { join } from "node:path";
|
|
6
5
|
import { existsSync, readFileSync, readdirSync } from "node:fs";
|
|
6
|
+
import { join } from "node:path";
|
|
7
7
|
import chalk from "chalk";
|
|
8
8
|
//#region src/tui/theme-manager.ts
|
|
9
9
|
init_paths();
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { resolveStateDir } from "../config/paths-state.js";
|
|
2
2
|
import { init_paths } from "../config/paths.js";
|
|
3
3
|
import { XOPC_TUI_KEYBINDINGS } from "./xopc-tui-keybindings.js";
|
|
4
|
-
import { join } from "node:path";
|
|
5
4
|
import { existsSync, readFileSync } from "node:fs";
|
|
5
|
+
import { join } from "node:path";
|
|
6
6
|
import { KeybindingsManager } from "@earendil-works/pi-tui";
|
|
7
7
|
//#region src/tui/tui-keybindings-file.ts
|
|
8
8
|
init_paths();
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { homedir } from "node:os";
|
|
2
|
-
import { join } from "node:path";
|
|
3
1
|
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { homedir } from "node:os";
|
|
4
4
|
//#region src/tui/tui-scoped-models.ts
|
|
5
5
|
const STORE_PATH = join(homedir(), ".xopc", "tui-scoped-models.json");
|
|
6
6
|
function normalizeWorkspaceKey(cwd) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { resolveStateDir } from "../config/paths-state.js";
|
|
2
2
|
import { init_paths } from "../config/paths.js";
|
|
3
|
-
import { join } from "node:path";
|
|
4
3
|
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
4
|
+
import { join } from "node:path";
|
|
5
5
|
//#region src/tui/tui-settings.ts
|
|
6
6
|
init_paths();
|
|
7
7
|
const DEFAULT_TUI_SETTINGS = {
|
package/dist/src/tui/tui.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { version } from "../../package.js";
|
|
2
|
+
import { loadConfig } from "../config/loader.js";
|
|
2
3
|
import { parseAgentSessionKey } from "../routing/session-key-utils.js";
|
|
3
4
|
import { init_agent_session_key } from "../routing/agent-session-key.js";
|
|
4
|
-
import { loadConfig } from "../config/loader.js";
|
|
5
5
|
import "../config/index.js";
|
|
6
6
|
import { resolveTuiSessionKey, resolveTuiStartupSessionKey } from "../routing/resolve-tui-session-key.js";
|
|
7
7
|
import { saveClipboardImageToTempFile } from "./clipboard-image.js";
|
|
@@ -31,9 +31,9 @@ import { TuiBottomBar } from "./components/tui-bottom-bar.js";
|
|
|
31
31
|
import { TuiHeader } from "./components/tui-header.js";
|
|
32
32
|
import { loadExtensionsForTuiLocalMode } from "./extension-host/load-extensions.js";
|
|
33
33
|
import { createTuiExtensionRuntime } from "./extension-host/runtime.js";
|
|
34
|
-
import { tmpdir } from "node:os";
|
|
35
|
-
import { join } from "node:path";
|
|
36
34
|
import { mkdtempSync, readFileSync, unlinkSync, writeFileSync } from "node:fs";
|
|
35
|
+
import { join } from "node:path";
|
|
36
|
+
import { tmpdir } from "node:os";
|
|
37
37
|
import { spawnSync } from "node:child_process";
|
|
38
38
|
import { Container, Loader, ProcessTerminal, TUI, setKeybindings } from "@earendil-works/pi-tui";
|
|
39
39
|
//#region src/tui/tui.ts
|
|
@@ -2,10 +2,10 @@ import { createLogger } from "../utils/logger/index.js";
|
|
|
2
2
|
import { init_logger } from "../utils/logger.js";
|
|
3
3
|
import { init_paths, resolveBinDir } from "../config/paths.js";
|
|
4
4
|
import { extractFrpcFromReleaseArchive, frpcReleaseArchiveExtension, nodePlatformForFrpTarget } from "./frpc-extract.js";
|
|
5
|
-
import { tmpdir } from "node:os";
|
|
6
|
-
import { join } from "node:path";
|
|
7
|
-
import { chmodSync, createWriteStream, existsSync, mkdirSync, rmSync } from "node:fs";
|
|
8
5
|
import { randomBytes } from "node:crypto";
|
|
6
|
+
import { chmodSync, createWriteStream, existsSync, mkdirSync, rmSync } from "node:fs";
|
|
7
|
+
import { join } from "node:path";
|
|
8
|
+
import { tmpdir } from "node:os";
|
|
9
9
|
import { Readable } from "node:stream";
|
|
10
10
|
import { pipeline } from "node:stream/promises";
|
|
11
11
|
//#region src/tunnel/frpc-binary.ts
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { resolveStateDir } from "../config/paths-state.js";
|
|
2
2
|
import { init_paths } from "../config/paths.js";
|
|
3
|
-
import { join } from "node:path";
|
|
4
3
|
import { mkdirSync, writeFileSync } from "node:fs";
|
|
4
|
+
import { join } from "node:path";
|
|
5
5
|
//#region src/tunnel/frpc-config.ts
|
|
6
6
|
init_paths();
|
|
7
7
|
function resolveFrpcConfigPath(tunnelId) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createLogger } from "../utils/logger/index.js";
|
|
2
2
|
import { init_logger } from "../utils/logger.js";
|
|
3
|
-
import { dirname, join } from "node:path";
|
|
4
3
|
import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
4
|
+
import { dirname, join } from "node:path";
|
|
5
5
|
import { spawn } from "node:child_process";
|
|
6
6
|
import AdmZip from "adm-zip";
|
|
7
7
|
import { gunzipSync } from "node:zlib";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { resolveStateDir } from "../config/paths-state.js";
|
|
2
2
|
import { init_paths } from "../config/paths.js";
|
|
3
|
-
import { join } from "node:path";
|
|
4
3
|
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
4
|
+
import { join } from "node:path";
|
|
5
5
|
//#region src/tunnel/tunnel-state.ts
|
|
6
6
|
init_paths();
|
|
7
7
|
const TUNNEL_STATE_FILE = "tunnel.json";
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { __esmMin } from "../../../_virtual/_rolldown/runtime.js";
|
|
2
2
|
import { getLogDir, init_config } from "./config.js";
|
|
3
|
+
import { appendFile } from "fs/promises";
|
|
3
4
|
import path from "path";
|
|
4
5
|
import { existsSync, mkdirSync } from "fs";
|
|
5
|
-
import { appendFile } from "fs/promises";
|
|
6
6
|
//#region src/utils/logger/audit.ts
|
|
7
7
|
/**
|
|
8
8
|
* Audit Log
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { init_pino_record, logEntrySearchText, pinoRecordToLogEntry } from "./pino-record.js";
|
|
2
|
+
import { readFile } from "fs/promises";
|
|
2
3
|
import { basename, join } from "path";
|
|
3
4
|
import { createReadStream, existsSync, mkdirSync, readdirSync, statSync } from "fs";
|
|
4
5
|
import { Readable } from "stream";
|
|
5
|
-
import { readFile } from "fs/promises";
|
|
6
6
|
import { gunzip } from "zlib";
|
|
7
7
|
import { promisify } from "util";
|
|
8
8
|
import { createInterface } from "readline";
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { __esmMin } from "../../../_virtual/_rolldown/runtime.js";
|
|
2
2
|
import { config, getLogDir, init_config } from "./config.js";
|
|
3
|
+
import { writeFile } from "fs/promises";
|
|
3
4
|
import { join } from "path";
|
|
4
5
|
import { readFileSync, readdirSync, statSync, unlinkSync } from "fs";
|
|
5
|
-
import { writeFile } from "fs/promises";
|
|
6
6
|
import { gzip } from "zlib";
|
|
7
7
|
import { promisify } from "util";
|
|
8
8
|
//#region src/utils/logger/rotation.ts
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createLogger } from "../../utils/logger/index.js";
|
|
2
2
|
import { init_logger } from "../../utils/logger.js";
|
|
3
|
-
import { join } from "path";
|
|
4
3
|
import { unlink, writeFile } from "fs/promises";
|
|
4
|
+
import { join } from "path";
|
|
5
5
|
import { spawn } from "child_process";
|
|
6
6
|
import { tmpdir } from "os";
|
|
7
7
|
//#region src/voice/tts/audio.ts
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { createLogger } from "../../../utils/logger/index.js";
|
|
2
2
|
import { init_logger } from "../../../utils/logger.js";
|
|
3
3
|
import { registerSpeechProvider } from "../speech-registry.js";
|
|
4
|
-
import { tmpdir } from "node:os";
|
|
5
|
-
import path from "node:path";
|
|
6
4
|
import { mkdtempSync, readFileSync, rmSync } from "node:fs";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import { tmpdir } from "node:os";
|
|
7
7
|
//#region src/voice/tts/providers/edge-speech.ts
|
|
8
8
|
/**
|
|
9
9
|
* Edge TTS provider — wraps the `node-edge-tts` package. Requires no API key
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import "../../session/types.js";
|
|
2
2
|
import { renderWorkflowText } from "../../agent/workflow/snapshot.js";
|
|
3
3
|
import { isTerminalWorkflowRunStatus } from "../domain/run.js";
|
|
4
4
|
import "../domain/index.js";
|
|
5
5
|
import { runViewToSnapshot } from "./run-view-to-snapshot.js";
|
|
6
|
-
import "../../session/types.js";
|
|
7
6
|
import { buildWorkflowRunSessionKey } from "./workflow-session-key.js";
|
|
8
7
|
import { randomUUID } from "node:crypto";
|
|
9
8
|
//#region src/workflows/service/workflow-session-bridge.ts
|
|
@@ -31,19 +30,13 @@ var WorkflowSessionBridge = class {
|
|
|
31
30
|
...params.parentSessionKey ? { parentSessionKey: params.parentSessionKey } : {}
|
|
32
31
|
}
|
|
33
32
|
});
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
content: [{
|
|
42
|
-
type: "text",
|
|
43
|
-
text: goalText
|
|
44
|
-
}],
|
|
45
|
-
timestamp: Date.now()
|
|
46
|
-
}
|
|
33
|
+
await store.appendTranscriptMessage(sessionKey, {
|
|
34
|
+
role: "user",
|
|
35
|
+
content: [{
|
|
36
|
+
type: "text",
|
|
37
|
+
text: goalText
|
|
38
|
+
}],
|
|
39
|
+
timestamp: Date.now()
|
|
47
40
|
});
|
|
48
41
|
if (params.parentSessionKey?.trim()) await this.writeParentRunLink({
|
|
49
42
|
parentSessionKey: params.parentSessionKey.trim(),
|
|
@@ -78,7 +71,6 @@ var WorkflowSessionBridge = class {
|
|
|
78
71
|
}
|
|
79
72
|
async persistTerminalTranscript(sessionKey, view) {
|
|
80
73
|
const store = this.gateway.sessionIndexInstance.getStore();
|
|
81
|
-
const { absPath } = await store.resolveTranscriptPath(sessionKey);
|
|
82
74
|
const snapshot = runViewToSnapshot(view);
|
|
83
75
|
const toolCallId = randomUUID();
|
|
84
76
|
const envelope = {
|
|
@@ -89,60 +81,45 @@ var WorkflowSessionBridge = class {
|
|
|
89
81
|
details: snapshot
|
|
90
82
|
};
|
|
91
83
|
const isError = view.run.status === "failed" || view.run.status === "timeout";
|
|
92
|
-
await
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
name: "workflow",
|
|
102
|
-
arguments: { name: view.run.definitionId }
|
|
103
|
-
}],
|
|
104
|
-
timestamp: Date.now()
|
|
105
|
-
}
|
|
84
|
+
await store.appendTranscriptMessage(sessionKey, {
|
|
85
|
+
role: "assistant",
|
|
86
|
+
content: [{
|
|
87
|
+
type: "toolCall",
|
|
88
|
+
id: toolCallId,
|
|
89
|
+
name: "workflow",
|
|
90
|
+
arguments: { name: view.run.definitionId }
|
|
91
|
+
}],
|
|
92
|
+
timestamp: Date.now()
|
|
106
93
|
});
|
|
107
|
-
await
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
}],
|
|
118
|
-
details: snapshot,
|
|
119
|
-
isError,
|
|
120
|
-
timestamp: Date.now()
|
|
121
|
-
}
|
|
94
|
+
await store.appendTranscriptMessage(sessionKey, {
|
|
95
|
+
role: "toolResult",
|
|
96
|
+
toolCallId,
|
|
97
|
+
content: [{
|
|
98
|
+
type: "text",
|
|
99
|
+
text: JSON.stringify(envelope)
|
|
100
|
+
}],
|
|
101
|
+
details: snapshot,
|
|
102
|
+
isError,
|
|
103
|
+
timestamp: Date.now()
|
|
122
104
|
});
|
|
123
105
|
await store.updateMetadata(sessionKey, { status: "active" });
|
|
124
106
|
}
|
|
125
107
|
async writeParentRunLink(params) {
|
|
126
|
-
const
|
|
108
|
+
const store = this.gateway.sessionIndexInstance.getStore();
|
|
127
109
|
const text = formatParentRunLinkText(params);
|
|
128
|
-
await
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
kind:
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
goal: params.goal,
|
|
142
|
-
status: params.status
|
|
143
|
-
},
|
|
144
|
-
createdAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
145
|
-
}
|
|
110
|
+
await store.appendTranscriptContextEntry(params.parentSessionKey, {
|
|
111
|
+
kind: "context",
|
|
112
|
+
id: `workflow-run-link:${params.runId}`,
|
|
113
|
+
text,
|
|
114
|
+
data: {
|
|
115
|
+
kind: WORKFLOW_RUN_LINK_CONTEXT_KIND,
|
|
116
|
+
runId: params.runId,
|
|
117
|
+
workflowSessionKey: params.workflowSessionKey,
|
|
118
|
+
definitionId: params.definitionId,
|
|
119
|
+
goal: params.goal,
|
|
120
|
+
status: params.status
|
|
121
|
+
},
|
|
122
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
146
123
|
});
|
|
147
124
|
}
|
|
148
125
|
};
|