@otium-team/negotium 0.0.0-stage → 0.23.13
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/LICENSE +202 -0
- package/README.md +329 -2
- package/bin/codex-sdk-window-hide.mjs +40 -0
- package/bin/negotium.mjs +22 -0
- package/dist/agent-helpers.js +23090 -0
- package/dist/agent-helpers.js.map +171 -0
- package/dist/background-bash.js +535 -0
- package/dist/background-bash.js.map +16 -0
- package/dist/browser-runtime.js +2334 -0
- package/dist/browser-runtime.js.map +35 -0
- package/dist/canonical-mcp-bridge.js +13 -0
- package/dist/canonical-mcp-bridge.js.map +9 -0
- package/dist/chunk-22kg3fsw.js +79 -0
- package/dist/chunk-22kg3fsw.js.map +9 -0
- package/dist/chunk-d4j77adx.js +336 -0
- package/dist/chunk-d4j77adx.js.map +13 -0
- package/dist/chunk-mk9x18jn.js +172 -0
- package/dist/chunk-mk9x18jn.js.map +12 -0
- package/dist/chunk-qd0vtfm2.js +3923 -0
- package/dist/chunk-qd0vtfm2.js.map +47 -0
- package/dist/chunk-wf7ny8eq.js +206 -0
- package/dist/chunk-wf7ny8eq.js.map +10 -0
- package/dist/chunk-ww8a4ej4.js +54 -0
- package/dist/chunk-ww8a4ej4.js.map +10 -0
- package/dist/cron.js +1 -0
- package/dist/hosted-agent.js +5982 -0
- package/dist/hosted-agent.js.map +62 -0
- package/dist/main.js +60229 -0
- package/dist/main.js.map +340 -0
- package/dist/mcp-catalog.js +39 -0
- package/dist/mcp-catalog.js.map +10 -0
- package/dist/mcp-factories.js +25767 -0
- package/dist/mcp-factories.js.map +181 -0
- package/dist/mcp-servers.js +50 -0
- package/dist/mcp-servers.js.map +10 -0
- package/dist/media.js +570 -0
- package/dist/media.js.map +15 -0
- package/dist/outbox.js +354 -0
- package/dist/outbox.js.map +15 -0
- package/dist/platform-runtime.js +73 -0
- package/dist/platform-runtime.js.map +12 -0
- package/dist/prompts.js +892 -0
- package/dist/prompts.js.map +15 -0
- package/dist/query-runtime.js +1071 -0
- package/dist/query-runtime.js.map +26 -0
- package/dist/registry.js +335 -0
- package/dist/registry.js.map +14 -0
- package/dist/rollout.js +57 -0
- package/dist/rollout.js.map +10 -0
- package/dist/runtime/cron/background-sessions.ts +119 -0
- package/dist/runtime/cron/context.ts +123 -0
- package/dist/runtime/cron/host.ts +67 -0
- package/dist/runtime/cron/index.ts +95 -0
- package/dist/runtime/cron/mcp-server.ts +556 -0
- package/dist/runtime/cron/module.ts +174 -0
- package/dist/runtime/cron/package.json +6 -0
- package/dist/runtime/cron/schedule.ts +211 -0
- package/dist/runtime/cron/scheduler.ts +444 -0
- package/dist/runtime/cron/scripts.ts +203 -0
- package/dist/runtime/cron/store.ts +1163 -0
- package/dist/runtime/cron/summarize.ts +115 -0
- package/dist/runtime/package.json +6 -0
- package/dist/runtime/scripts/faster-whisper-wrapper.py +87 -0
- package/dist/runtime/src/agents/api-topic-agent-switch.ts +179 -0
- package/dist/runtime/src/agents/archiver.ts +677 -0
- package/dist/runtime/src/agents/auth-check.ts +156 -0
- package/dist/runtime/src/agents/claude-notices.ts +130 -0
- package/dist/runtime/src/agents/claude-provider.ts +941 -0
- package/dist/runtime/src/agents/claude-registry.ts +117 -0
- package/dist/runtime/src/agents/claude-runtime-inspection.ts +43 -0
- package/dist/runtime/src/agents/codex-app-server.ts +138 -0
- package/dist/runtime/src/agents/codex-native-multi-agent.ts +360 -0
- package/dist/runtime/src/agents/codex-provider.ts +1193 -0
- package/dist/runtime/src/agents/codex-registry.ts +116 -0
- package/dist/runtime/src/agents/codex-tier-resolver.ts +74 -0
- package/dist/runtime/src/agents/codex-tree-kill.ts +54 -0
- package/dist/runtime/src/agents/codex-tree-manager.ts +230 -0
- package/dist/runtime/src/agents/codex-vault-hook-bridge.ts +240 -0
- package/dist/runtime/src/agents/codex-vault-hook.mjs +50 -0
- package/dist/runtime/src/agents/codex-windows-wrapper.ts +174 -0
- package/dist/runtime/src/agents/compaction-support.ts +75 -0
- package/dist/runtime/src/agents/compaction-tool-projection.ts +125 -0
- package/dist/runtime/src/agents/contracts.ts +75 -0
- package/dist/runtime/src/agents/deep-map.ts +13 -0
- package/dist/runtime/src/agents/execution-host.ts +118 -0
- package/dist/runtime/src/agents/explicit-agent-switch.ts +106 -0
- package/dist/runtime/src/agents/fixtures/claude-attachments.jsonl +2 -0
- package/dist/runtime/src/agents/fixtures/codex-shell.jsonl +5 -0
- package/dist/runtime/src/agents/fork.ts +100 -0
- package/dist/runtime/src/agents/hosted-agent.ts +78 -0
- package/dist/runtime/src/agents/idle-archiver.ts +225 -0
- package/dist/runtime/src/agents/idle-compact.ts +225 -0
- package/dist/runtime/src/agents/index.ts +225 -0
- package/dist/runtime/src/agents/maestro-provider.ts +246 -0
- package/dist/runtime/src/agents/maestro-registry.ts +189 -0
- package/dist/runtime/src/agents/mcp-tools/ask-user.ts +653 -0
- package/dist/runtime/src/agents/mcp-tools/common.ts +23 -0
- package/dist/runtime/src/agents/mcp-tools/inline-assets.ts +203 -0
- package/dist/runtime/src/agents/mcp-tools/publish-html.ts +183 -0
- package/dist/runtime/src/agents/mcp-tools/request-vault.ts +684 -0
- package/dist/runtime/src/agents/mcp-tools/self-config.ts +353 -0
- package/dist/runtime/src/agents/mcp-tools/spawn-subagent.ts +1349 -0
- package/dist/runtime/src/agents/mcp-tools/visual-compat.ts +18 -0
- package/dist/runtime/src/agents/mcp-tools/visuals.ts +60 -0
- package/dist/runtime/src/agents/memory-archive-policy.ts +54 -0
- package/dist/runtime/src/agents/model-catalog.ts +439 -0
- package/dist/runtime/src/agents/public-helpers.ts +149 -0
- package/dist/runtime/src/agents/registry.ts +35 -0
- package/dist/runtime/src/agents/rollout/claude.ts +336 -0
- package/dist/runtime/src/agents/rollout/codex.ts +910 -0
- package/dist/runtime/src/agents/rollout/index.ts +26 -0
- package/dist/runtime/src/agents/rollout/shared.ts +293 -0
- package/dist/runtime/src/agents/self-config-core.ts +704 -0
- package/dist/runtime/src/agents/task-events.ts +59 -0
- package/dist/runtime/src/agents/tool-format.ts +613 -0
- package/dist/runtime/src/agents/topic-agent-switch.ts +189 -0
- package/dist/runtime/src/agents/topic-cleanup.ts +285 -0
- package/dist/runtime/src/agents/vault-tool-policy.ts +36 -0
- package/dist/runtime/src/application/execute-external-user-turn.ts +23 -0
- package/dist/runtime/src/application/submit-runtime-gateway-turn.ts +484 -0
- package/dist/runtime/src/application/submit-user-message.ts +60 -0
- package/dist/runtime/src/application/switch-topic-effort.ts +48 -0
- package/dist/runtime/src/application/switch-topic-model.ts +79 -0
- package/dist/runtime/src/application/topic-service.ts +190 -0
- package/dist/runtime/src/application/turn-follow-ups.ts +291 -0
- package/dist/runtime/src/application/vault-command.ts +170 -0
- package/dist/runtime/src/bus.ts +409 -0
- package/dist/runtime/src/config-public.ts +2 -0
- package/dist/runtime/src/cron-host.ts +33 -0
- package/dist/runtime/src/cron-mcp-host.ts +5 -0
- package/dist/runtime/src/identifiers.ts +49 -0
- package/dist/runtime/src/index.ts +573 -0
- package/dist/runtime/src/mcp/agent-health-server.ts +8 -0
- package/dist/runtime/src/mcp/canonical-bridge-config.ts +84 -0
- package/dist/runtime/src/mcp/canonical-proxy-server.ts +308 -0
- package/dist/runtime/src/mcp/compaction-log-server.ts +25 -0
- package/dist/runtime/src/mcp/decision-server.ts +21 -0
- package/dist/runtime/src/mcp/dm-ipc.ts +60 -0
- package/dist/runtime/src/mcp/factories/agent-health.ts +394 -0
- package/dist/runtime/src/mcp/factories/compaction-log.ts +135 -0
- package/dist/runtime/src/mcp/factories/decision.ts +186 -0
- package/dist/runtime/src/mcp/factories/index.ts +73 -0
- package/dist/runtime/src/mcp/factories/session-comm.ts +184 -0
- package/dist/runtime/src/mcp/factories/session-history.ts +103 -0
- package/dist/runtime/src/mcp/factories/stdio-protection.ts +24 -0
- package/dist/runtime/src/mcp/factories/system-health.ts +259 -0
- package/dist/runtime/src/mcp/factories/task.ts +185 -0
- package/dist/runtime/src/mcp/factories/token-stats.ts +145 -0
- package/dist/runtime/src/mcp/factories/vault.ts +32 -0
- package/dist/runtime/src/mcp/mcp-helpers.ts +40 -0
- package/dist/runtime/src/mcp/peer-bridge.ts +119 -0
- package/dist/runtime/src/mcp/runtime-spec.ts +473 -0
- package/dist/runtime/src/mcp/session-comm/actor-policy.ts +160 -0
- package/dist/runtime/src/mcp/session-comm/bridge-ipc-config.ts +27 -0
- package/dist/runtime/src/mcp/session-comm/context.ts +113 -0
- package/dist/runtime/src/mcp/session-comm/default-host.ts +723 -0
- package/dist/runtime/src/mcp/session-comm/history-target.ts +89 -0
- package/dist/runtime/src/mcp/session-comm/history-tools.ts +113 -0
- package/dist/runtime/src/mcp/session-comm/hub-remote-session.ts +553 -0
- package/dist/runtime/src/mcp/session-comm/limits.ts +8 -0
- package/dist/runtime/src/mcp/session-comm/peer-forward.ts +251 -0
- package/dist/runtime/src/mcp/session-comm/runtime.ts +128 -0
- package/dist/runtime/src/mcp/session-comm/server.ts +1036 -0
- package/dist/runtime/src/mcp/session-comm/tell-permissions.ts +79 -0
- package/dist/runtime/src/mcp/session-comm/topic-catalog.ts +155 -0
- package/dist/runtime/src/mcp/session-comm/topic-config.ts +137 -0
- package/dist/runtime/src/mcp/session-comm/topics.ts +313 -0
- package/dist/runtime/src/mcp/session-history-limits.ts +36 -0
- package/dist/runtime/src/mcp/session-history-reader.ts +359 -0
- package/dist/runtime/src/mcp/session-history-server.ts +19 -0
- package/dist/runtime/src/mcp/stdio-protect.ts +7 -0
- package/dist/runtime/src/mcp/system-health-server.ts +5 -0
- package/dist/runtime/src/mcp/task-server.ts +17 -0
- package/dist/runtime/src/mcp/token-stats-server.ts +10 -0
- package/dist/runtime/src/mcp/vault-server.ts +12 -0
- package/dist/runtime/src/mcp/wiki-search-index.ts +359 -0
- package/dist/runtime/src/mcp/wiki-server.ts +2386 -0
- package/dist/runtime/src/mcp-runtime-host.ts +81 -0
- package/dist/runtime/src/media/file-events.ts +33 -0
- package/dist/runtime/src/media/text-extractor.ts +334 -0
- package/dist/runtime/src/media/video.ts +92 -0
- package/dist/runtime/src/node-host.ts +211 -0
- package/dist/runtime/src/outbox/coalescing-runner.ts +157 -0
- package/dist/runtime/src/outbox/file-ops.ts +267 -0
- package/dist/runtime/src/outbox/index.ts +26 -0
- package/dist/runtime/src/outbox/utils.ts +74 -0
- package/dist/runtime/src/platform/background-bash/context.ts +9 -0
- package/dist/runtime/src/platform/background-bash/manager.ts +292 -0
- package/dist/runtime/src/platform/background-bash/output-buffer.ts +323 -0
- package/dist/runtime/src/platform/config-helpers.ts +47 -0
- package/dist/runtime/src/platform/config.ts +618 -0
- package/dist/runtime/src/platform/constants.ts +30 -0
- package/dist/runtime/src/platform/debug-users.ts +14 -0
- package/dist/runtime/src/platform/delay.ts +1 -0
- package/dist/runtime/src/platform/error.ts +9 -0
- package/dist/runtime/src/platform/file-utils.ts +35 -0
- package/dist/runtime/src/platform/ipc.ts +55 -0
- package/dist/runtime/src/platform/jsonl.ts +277 -0
- package/dist/runtime/src/platform/lifecycle.ts +176 -0
- package/dist/runtime/src/platform/log-rotation.ts +45 -0
- package/dist/runtime/src/platform/logger.ts +42 -0
- package/dist/runtime/src/platform/maestro-bootstrap-env.ts +3 -0
- package/dist/runtime/src/platform/mcp-catalog-policy.ts +63 -0
- package/dist/runtime/src/platform/mcp-config.ts +1329 -0
- package/dist/runtime/src/platform/memoize-import.ts +26 -0
- package/dist/runtime/src/platform/modules.ts +145 -0
- package/dist/runtime/src/platform/node-plugins.ts +46 -0
- package/dist/runtime/src/platform/paths.ts +62 -0
- package/dist/runtime/src/platform/playwright/browser-processes.ts +300 -0
- package/dist/runtime/src/platform/playwright/capability.ts +5 -0
- package/dist/runtime/src/platform/playwright/headed-launch.ts +61 -0
- package/dist/runtime/src/platform/playwright/manager-utils.ts +128 -0
- package/dist/runtime/src/platform/playwright/manager.ts +1502 -0
- package/dist/runtime/src/platform/playwright/mcp-transport.ts +35 -0
- package/dist/runtime/src/platform/playwright/profile-management.ts +33 -0
- package/dist/runtime/src/platform/playwright/public-runtime.ts +52 -0
- package/dist/runtime/src/platform/playwright/transport-probe.ts +89 -0
- package/dist/runtime/src/platform/playwright/vault-broker.ts +261 -0
- package/dist/runtime/src/platform/public-runtime.ts +18 -0
- package/dist/runtime/src/prompts/agents/wiki-archiver.md +194 -0
- package/dist/runtime/src/prompts/builders.ts +696 -0
- package/dist/runtime/src/prompts/sessions/_shared-tools.md +38 -0
- package/dist/runtime/src/prompts/sessions/channel-system.md +13 -0
- package/dist/runtime/src/prompts/sessions/manager-system.md +34 -0
- package/dist/runtime/src/prompts/sessions/surfaces/cli.md +6 -0
- package/dist/runtime/src/prompts/sessions/surfaces/otium-manager.md +18 -0
- package/dist/runtime/src/prompts/sessions/surfaces/otium.md +6 -0
- package/dist/runtime/src/prompts/sessions/surfaces/telegram.md +5 -0
- package/dist/runtime/src/prompts/sessions/surfaces/terminal.md +6 -0
- package/dist/runtime/src/prompts/sessions/topic-system.md +9 -0
- package/dist/runtime/src/prompts/sessions/visual-design.md +38 -0
- package/dist/runtime/src/query/active-rooms.ts +514 -0
- package/dist/runtime/src/query/index.ts +23 -0
- package/dist/runtime/src/query/public-runtime.ts +28 -0
- package/dist/runtime/src/query/room-query-registry.ts +217 -0
- package/dist/runtime/src/query/session-inbox-cleanup.ts +45 -0
- package/dist/runtime/src/query/session-inbox-path.ts +42 -0
- package/dist/runtime/src/query/state.ts +116 -0
- package/dist/runtime/src/query/types.ts +8 -0
- package/dist/runtime/src/runtime/actor-topic-reach.ts +123 -0
- package/dist/runtime/src/runtime/actor-topic-scope.ts +255 -0
- package/dist/runtime/src/runtime/ask-callbacks.ts +217 -0
- package/dist/runtime/src/runtime/attachments.ts +149 -0
- package/dist/runtime/src/runtime/background-session-policy.ts +1 -0
- package/dist/runtime/src/runtime/background-sessions.ts +288 -0
- package/dist/runtime/src/runtime/bashrs-completions.ts +350 -0
- package/dist/runtime/src/runtime/channel-context.ts +115 -0
- package/dist/runtime/src/runtime/context-warning.ts +131 -0
- package/dist/runtime/src/runtime/cron-sessions.ts +35 -0
- package/dist/runtime/src/runtime/delivery-ack.ts +112 -0
- package/dist/runtime/src/runtime/errors.ts +70 -0
- package/dist/runtime/src/runtime/event-heartbeat.ts +77 -0
- package/dist/runtime/src/runtime/file-hooks.ts +81 -0
- package/dist/runtime/src/runtime/footer.ts +23 -0
- package/dist/runtime/src/runtime/gateway-capabilities.ts +22 -0
- package/dist/runtime/src/runtime/inbox.ts +1307 -0
- package/dist/runtime/src/runtime/playwright-turn-abort.ts +59 -0
- package/dist/runtime/src/runtime/public-helpers.ts +78 -0
- package/dist/runtime/src/runtime/remote-session-grant.ts +221 -0
- package/dist/runtime/src/runtime/remote-session-inbox.ts +943 -0
- package/dist/runtime/src/runtime/remote-session-reply-outbox.ts +168 -0
- package/dist/runtime/src/runtime/task-format.ts +18 -0
- package/dist/runtime/src/runtime/tasks.ts +53 -0
- package/dist/runtime/src/runtime/thread-context.ts +123 -0
- package/dist/runtime/src/runtime/thread-read.ts +67 -0
- package/dist/runtime/src/runtime/topic-config.ts +29 -0
- package/dist/runtime/src/runtime/turn-event-stream.ts +1051 -0
- package/dist/runtime/src/runtime/turn-runner.ts +2311 -0
- package/dist/runtime/src/runtime/turn-session.ts +116 -0
- package/dist/runtime/src/runtime/usage-alert.ts +51 -0
- package/dist/runtime/src/runtime/user-turn-envelope.ts +94 -0
- package/dist/runtime/src/runtime/visual-html.ts +175 -0
- package/dist/runtime/src/runtime/visual-store.ts +480 -0
- package/dist/runtime/src/runtime/visuals.ts +209 -0
- package/dist/runtime/src/runtime-gateway.ts +1045 -0
- package/dist/runtime/src/security/sanitize.ts +27 -0
- package/dist/runtime/src/security/sensitive-path.ts +41 -0
- package/dist/runtime/src/storage/activity-log.ts +167 -0
- package/dist/runtime/src/storage/api-messages.ts +766 -0
- package/dist/runtime/src/storage/api-topic-brief.ts +134 -0
- package/dist/runtime/src/storage/api-topic-config.ts +197 -0
- package/dist/runtime/src/storage/api-topics.ts +1647 -0
- package/dist/runtime/src/storage/app-settings.ts +50 -0
- package/dist/runtime/src/storage/ask-user-gates.ts +359 -0
- package/dist/runtime/src/storage/browser-profiles.ts +186 -0
- package/dist/runtime/src/storage/conversation-migration.ts +180 -0
- package/dist/runtime/src/storage/conversations.ts +377 -0
- package/dist/runtime/src/storage/decisions.ts +231 -0
- package/dist/runtime/src/storage/forum/agent-settings.ts +20 -0
- package/dist/runtime/src/storage/forum/index.ts +4 -0
- package/dist/runtime/src/storage/forum/repository.ts +283 -0
- package/dist/runtime/src/storage/forum/schema.ts +314 -0
- package/dist/runtime/src/storage/forum-db.ts +4 -0
- package/dist/runtime/src/storage/remote-session.ts +1028 -0
- package/dist/runtime/src/storage/runtime-events.ts +209 -0
- package/dist/runtime/src/storage/runtime-follow-ups.ts +212 -0
- package/dist/runtime/src/storage/runtime-gateway-submissions.ts +132 -0
- package/dist/runtime/src/storage/runtime-leases.ts +190 -0
- package/dist/runtime/src/storage/runtime-process-leases.ts +288 -0
- package/dist/runtime/src/storage/runtime-topic-state.ts +181 -0
- package/dist/runtime/src/storage/runtime-turn-requests.ts +846 -0
- package/dist/runtime/src/storage/self-schedules.ts +306 -0
- package/dist/runtime/src/storage/session-asks.ts +468 -0
- package/dist/runtime/src/storage/session-inbox-signal.ts +76 -0
- package/dist/runtime/src/storage/session-inbox.ts +161 -0
- package/dist/runtime/src/storage/sqlite.ts +154 -0
- package/dist/runtime/src/storage/storage-contract.ts +54 -0
- package/dist/runtime/src/storage/storage-host.ts +336 -0
- package/dist/runtime/src/storage/storage-public-host.ts +16 -0
- package/dist/runtime/src/storage/storage-public.ts +66 -0
- package/dist/runtime/src/storage/tasks.ts +172 -0
- package/dist/runtime/src/storage/token-stats.ts +432 -0
- package/dist/runtime/src/storage/topic-archive-state.ts +226 -0
- package/dist/runtime/src/storage/topic-archive.ts +169 -0
- package/dist/runtime/src/storage/topic-host-mcp-grants.ts +54 -0
- package/dist/runtime/src/storage/topic-link-records.ts +1085 -0
- package/dist/runtime/src/storage/topic-settings.ts +67 -0
- package/dist/runtime/src/storage/topic-tool-capabilities.ts +89 -0
- package/dist/runtime/src/storage/topic-transcript.ts +98 -0
- package/dist/runtime/src/storage/vault-crypto-core.ts +65 -0
- package/dist/runtime/src/storage/vault-crypto.ts +31 -0
- package/dist/runtime/src/storage/vault-public.ts +27 -0
- package/dist/runtime/src/storage/vault-request-gates.ts +359 -0
- package/dist/runtime/src/storage/vault.ts +388 -0
- package/dist/runtime/src/storage/wiki-summary-names.ts +52 -0
- package/dist/runtime/src/storage/wiki.ts +90 -0
- package/dist/runtime/src/topics/claim-abort.ts +190 -0
- package/dist/runtime/src/topics/create.ts +192 -0
- package/dist/runtime/src/topics/derive.ts +600 -0
- package/dist/runtime/src/topics/lifecycle.ts +425 -0
- package/dist/runtime/src/topics/links.ts +7 -0
- package/dist/runtime/src/topics/personal-general.ts +91 -0
- package/dist/runtime/src/topics/session.ts +1041 -0
- package/dist/runtime/src/topics/update.ts +287 -0
- package/dist/runtime/src/types/api.ts +591 -0
- package/dist/runtime/src/types.ts +418 -0
- package/dist/runtime/src/version.ts +1 -0
- package/dist/runtime/tsconfig.json +13 -0
- package/dist/runtime-gateway.js +514 -0
- package/dist/runtime-gateway.js.map +10 -0
- package/dist/runtime-helpers.js +1792 -0
- package/dist/runtime-helpers.js.map +40 -0
- package/dist/sqlite.js +66 -0
- package/dist/sqlite.js.map +10 -0
- package/dist/storage.js +5223 -0
- package/dist/storage.js.map +47 -0
- package/dist/types/apps/negotium/src/mcp-servers.d.ts +20 -0
- package/dist/types/packages/core/src/agents/api-topic-agent-switch.d.ts +38 -0
- package/dist/types/packages/core/src/agents/archiver.d.ts +87 -0
- package/dist/types/packages/core/src/agents/auth-check.d.ts +19 -0
- package/dist/types/packages/core/src/agents/claude-notices.d.ts +15 -0
- package/dist/types/packages/core/src/agents/claude-provider.d.ts +25 -0
- package/dist/types/packages/core/src/agents/claude-registry.d.ts +3 -0
- package/dist/types/packages/core/src/agents/claude-runtime-inspection.d.ts +9 -0
- package/dist/types/packages/core/src/agents/codex-app-server.d.ts +13 -0
- package/dist/types/packages/core/src/agents/codex-native-multi-agent.d.ts +20 -0
- package/dist/types/packages/core/src/agents/codex-provider.d.ts +64 -0
- package/dist/types/packages/core/src/agents/codex-registry.d.ts +3 -0
- package/dist/types/packages/core/src/agents/codex-tier-resolver.d.ts +10 -0
- package/dist/types/packages/core/src/agents/codex-tree-kill.d.ts +13 -0
- package/dist/types/packages/core/src/agents/codex-tree-manager.d.ts +28 -0
- package/dist/types/packages/core/src/agents/codex-vault-hook-bridge.d.ts +28 -0
- package/dist/types/packages/core/src/agents/codex-windows-wrapper.d.ts +30 -0
- package/dist/types/packages/core/src/agents/compaction-support.d.ts +5 -0
- package/dist/types/packages/core/src/agents/compaction-tool-projection.d.ts +9 -0
- package/dist/types/packages/core/src/agents/contracts.d.ts +68 -0
- package/dist/types/packages/core/src/agents/deep-map.d.ts +2 -0
- package/dist/types/packages/core/src/agents/execution-host.d.ts +33 -0
- package/dist/types/packages/core/src/agents/explicit-agent-switch.d.ts +26 -0
- package/dist/types/packages/core/src/agents/fork.d.ts +50 -0
- package/dist/types/packages/core/src/agents/hosted-agent.d.ts +15 -0
- package/dist/types/packages/core/src/agents/idle-archiver.d.ts +35 -0
- package/dist/types/packages/core/src/agents/idle-compact.d.ts +37 -0
- package/dist/types/packages/core/src/agents/index.d.ts +8 -0
- package/dist/types/packages/core/src/agents/maestro-provider.d.ts +75 -0
- package/dist/types/packages/core/src/agents/maestro-registry.d.ts +3 -0
- package/dist/types/packages/core/src/agents/mcp-tools/ask-user.d.ts +147 -0
- package/dist/types/packages/core/src/agents/mcp-tools/common.d.ts +14 -0
- package/dist/types/packages/core/src/agents/mcp-tools/inline-assets.d.ts +24 -0
- package/dist/types/packages/core/src/agents/mcp-tools/publish-html.d.ts +18 -0
- package/dist/types/packages/core/src/agents/mcp-tools/request-vault.d.ts +124 -0
- package/dist/types/packages/core/src/agents/mcp-tools/self-config.d.ts +45 -0
- package/dist/types/packages/core/src/agents/mcp-tools/spawn-subagent.d.ts +148 -0
- package/dist/types/packages/core/src/agents/mcp-tools/visual-compat.d.ts +55 -0
- package/dist/types/packages/core/src/agents/mcp-tools/visuals.d.ts +70 -0
- package/dist/types/packages/core/src/agents/memory-archive-policy.d.ts +24 -0
- package/dist/types/packages/core/src/agents/model-catalog.d.ts +132 -0
- package/dist/types/packages/core/src/agents/public-helpers.d.ts +17 -0
- package/dist/types/packages/core/src/agents/registry.d.ts +5 -0
- package/dist/types/packages/core/src/agents/rollout/claude.d.ts +77 -0
- package/dist/types/packages/core/src/agents/rollout/codex.d.ts +119 -0
- package/dist/types/packages/core/src/agents/rollout/index.d.ts +6 -0
- package/dist/types/packages/core/src/agents/rollout/shared.d.ts +56 -0
- package/dist/types/packages/core/src/agents/self-config-core.d.ts +199 -0
- package/dist/types/packages/core/src/agents/task-events.d.ts +19 -0
- package/dist/types/packages/core/src/agents/tool-format.d.ts +25 -0
- package/dist/types/packages/core/src/agents/topic-cleanup.d.ts +83 -0
- package/dist/types/packages/core/src/agents/vault-tool-policy.d.ts +2 -0
- package/dist/types/packages/core/src/bus.d.ts +141 -0
- package/dist/types/packages/core/src/identifiers.d.ts +27 -0
- package/dist/types/packages/core/src/mcp/canonical-bridge-config.d.ts +21 -0
- package/dist/types/packages/core/src/mcp/factories/agent-health.d.ts +5 -0
- package/dist/types/packages/core/src/mcp/factories/compaction-log.d.ts +8 -0
- package/dist/types/packages/core/src/mcp/factories/decision.d.ts +18 -0
- package/dist/types/packages/core/src/mcp/factories/index.d.ts +13 -0
- package/dist/types/packages/core/src/mcp/factories/session-comm.d.ts +38 -0
- package/dist/types/packages/core/src/mcp/factories/session-history.d.ts +11 -0
- package/dist/types/packages/core/src/mcp/factories/stdio-protection.d.ts +10 -0
- package/dist/types/packages/core/src/mcp/factories/system-health.d.ts +37 -0
- package/dist/types/packages/core/src/mcp/factories/task.d.ts +13 -0
- package/dist/types/packages/core/src/mcp/factories/token-stats.d.ts +20 -0
- package/dist/types/packages/core/src/mcp/factories/vault.d.ts +9 -0
- package/dist/types/packages/core/src/mcp/mcp-helpers.d.ts +26 -0
- package/dist/types/packages/core/src/mcp/peer-bridge.d.ts +92 -0
- package/dist/types/packages/core/src/mcp/runtime-spec.d.ts +147 -0
- package/dist/types/packages/core/src/mcp/session-comm/actor-policy.d.ts +120 -0
- package/dist/types/packages/core/src/mcp/session-comm/bridge-ipc-config.d.ts +6 -0
- package/dist/types/packages/core/src/mcp/session-comm/context.d.ts +44 -0
- package/dist/types/packages/core/src/mcp/session-comm/history-tools.d.ts +31 -0
- package/dist/types/packages/core/src/mcp/session-comm/hub-remote-session.d.ts +149 -0
- package/dist/types/packages/core/src/mcp/session-comm/limits.d.ts +8 -0
- package/dist/types/packages/core/src/mcp/session-comm/peer-forward.d.ts +85 -0
- package/dist/types/packages/core/src/mcp/session-comm/tell-permissions.d.ts +29 -0
- package/dist/types/packages/core/src/mcp/session-comm/topic-catalog.d.ts +59 -0
- package/dist/types/packages/core/src/mcp/session-history-limits.d.ts +20 -0
- package/dist/types/packages/core/src/mcp/session-history-reader.d.ts +35 -0
- package/dist/types/packages/core/src/mcp/wiki-search-index.d.ts +59 -0
- package/dist/types/packages/core/src/mcp/wiki-server.d.ts +53 -0
- package/dist/types/packages/core/src/media/file-events.d.ts +14 -0
- package/dist/types/packages/core/src/media/text-extractor.d.ts +34 -0
- package/dist/types/packages/core/src/outbox/coalescing-runner.d.ts +68 -0
- package/dist/types/packages/core/src/outbox/file-ops.d.ts +79 -0
- package/dist/types/packages/core/src/outbox/index.d.ts +3 -0
- package/dist/types/packages/core/src/outbox/utils.d.ts +16 -0
- package/dist/types/packages/core/src/platform/background-bash/context.d.ts +1 -0
- package/dist/types/packages/core/src/platform/background-bash/manager.d.ts +34 -0
- package/dist/types/packages/core/src/platform/config-helpers.d.ts +20 -0
- package/dist/types/packages/core/src/platform/config.d.ts +178 -0
- package/dist/types/packages/core/src/platform/constants.d.ts +20 -0
- package/dist/types/packages/core/src/platform/delay.d.ts +1 -0
- package/dist/types/packages/core/src/platform/error.d.ts +6 -0
- package/dist/types/packages/core/src/platform/file-utils.d.ts +16 -0
- package/dist/types/packages/core/src/platform/ipc.d.ts +32 -0
- package/dist/types/packages/core/src/platform/jsonl.d.ts +46 -0
- package/dist/types/packages/core/src/platform/lifecycle.d.ts +40 -0
- package/dist/types/packages/core/src/platform/logger.d.ts +20 -0
- package/dist/types/packages/core/src/platform/maestro-bootstrap-env.d.ts +0 -0
- package/dist/types/packages/core/src/platform/mcp-catalog-policy.d.ts +73 -0
- package/dist/types/packages/core/src/platform/mcp-config.d.ts +286 -0
- package/dist/types/packages/core/src/platform/memoize-import.d.ts +15 -0
- package/dist/types/packages/core/src/platform/paths.d.ts +18 -0
- package/dist/types/packages/core/src/platform/playwright/browser-processes.d.ts +60 -0
- package/dist/types/packages/core/src/platform/playwright/capability.d.ts +1 -0
- package/dist/types/packages/core/src/platform/playwright/headed-launch.d.ts +13 -0
- package/dist/types/packages/core/src/platform/playwright/manager-utils.d.ts +34 -0
- package/dist/types/packages/core/src/platform/playwright/manager.d.ts +194 -0
- package/dist/types/packages/core/src/platform/playwright/mcp-transport.d.ts +4 -0
- package/dist/types/packages/core/src/platform/playwright/profile-management.d.ts +8 -0
- package/dist/types/packages/core/src/platform/playwright/public-runtime.d.ts +6 -0
- package/dist/types/packages/core/src/platform/playwright/transport-probe.d.ts +13 -0
- package/dist/types/packages/core/src/platform/playwright/vault-broker.d.ts +6 -0
- package/dist/types/packages/core/src/platform/public-runtime.d.ts +3 -0
- package/dist/types/packages/core/src/prompts/builders.d.ts +78 -0
- package/dist/types/packages/core/src/query/active-rooms.d.ts +240 -0
- package/dist/types/packages/core/src/query/public-runtime.d.ts +4 -0
- package/dist/types/packages/core/src/query/room-query-registry.d.ts +71 -0
- package/dist/types/packages/core/src/query/session-inbox-cleanup.d.ts +5 -0
- package/dist/types/packages/core/src/query/session-inbox-path.d.ts +8 -0
- package/dist/types/packages/core/src/query/state.d.ts +25 -0
- package/dist/types/packages/core/src/query/types.d.ts +6 -0
- package/dist/types/packages/core/src/runtime/actor-topic-reach.d.ts +63 -0
- package/dist/types/packages/core/src/runtime/actor-topic-scope.d.ts +127 -0
- package/dist/types/packages/core/src/runtime/ask-callbacks.d.ts +53 -0
- package/dist/types/packages/core/src/runtime/attachments.d.ts +36 -0
- package/dist/types/packages/core/src/runtime/background-session-policy.d.ts +1 -0
- package/dist/types/packages/core/src/runtime/background-sessions.d.ts +27 -0
- package/dist/types/packages/core/src/runtime/bashrs-completions.d.ts +50 -0
- package/dist/types/packages/core/src/runtime/channel-context.d.ts +13 -0
- package/dist/types/packages/core/src/runtime/context-warning.d.ts +46 -0
- package/dist/types/packages/core/src/runtime/cron-sessions.d.ts +9 -0
- package/dist/types/packages/core/src/runtime/errors.d.ts +6 -0
- package/dist/types/packages/core/src/runtime/event-heartbeat.d.ts +17 -0
- package/dist/types/packages/core/src/runtime/file-hooks.d.ts +38 -0
- package/dist/types/packages/core/src/runtime/playwright-turn-abort.d.ts +12 -0
- package/dist/types/packages/core/src/runtime/public-helpers.d.ts +17 -0
- package/dist/types/packages/core/src/runtime/remote-session-grant.d.ts +91 -0
- package/dist/types/packages/core/src/runtime/remote-session-inbox.d.ts +206 -0
- package/dist/types/packages/core/src/runtime/remote-session-reply-outbox.d.ts +37 -0
- package/dist/types/packages/core/src/runtime/task-format.d.ts +4 -0
- package/dist/types/packages/core/src/runtime/tasks.d.ts +3 -0
- package/dist/types/packages/core/src/runtime/thread-context.d.ts +62 -0
- package/dist/types/packages/core/src/runtime/topic-config.d.ts +24 -0
- package/dist/types/packages/core/src/runtime/turn-event-stream.d.ts +47 -0
- package/dist/types/packages/core/src/runtime/turn-runner.d.ts +284 -0
- package/dist/types/packages/core/src/runtime/turn-session.d.ts +49 -0
- package/dist/types/packages/core/src/runtime/usage-alert.d.ts +11 -0
- package/dist/types/packages/core/src/runtime/user-turn-envelope.d.ts +37 -0
- package/dist/types/packages/core/src/runtime/visual-html.d.ts +13 -0
- package/dist/types/packages/core/src/runtime/visual-store.d.ts +71 -0
- package/dist/types/packages/core/src/runtime/visuals.d.ts +33 -0
- package/dist/types/packages/core/src/runtime-gateway.d.ts +282 -0
- package/dist/types/packages/core/src/security/sanitize.d.ts +16 -0
- package/dist/types/packages/core/src/security/sensitive-path.d.ts +1 -0
- package/dist/types/packages/core/src/storage/activity-log.d.ts +25 -0
- package/dist/types/packages/core/src/storage/api-messages.d.ts +156 -0
- package/dist/types/packages/core/src/storage/api-topic-brief.d.ts +39 -0
- package/dist/types/packages/core/src/storage/api-topic-config.d.ts +23 -0
- package/dist/types/packages/core/src/storage/api-topics.d.ts +274 -0
- package/dist/types/packages/core/src/storage/app-settings.d.ts +4 -0
- package/dist/types/packages/core/src/storage/ask-user-gates.d.ts +65 -0
- package/dist/types/packages/core/src/storage/browser-profiles.d.ts +31 -0
- package/dist/types/packages/core/src/storage/conversations.d.ts +149 -0
- package/dist/types/packages/core/src/storage/decisions.d.ts +45 -0
- package/dist/types/packages/core/src/storage/forum/agent-settings.d.ts +3 -0
- package/dist/types/packages/core/src/storage/forum/index.d.ts +4 -0
- package/dist/types/packages/core/src/storage/forum/repository.d.ts +42 -0
- package/dist/types/packages/core/src/storage/forum/schema.d.ts +38 -0
- package/dist/types/packages/core/src/storage/forum-db.d.ts +2 -0
- package/dist/types/packages/core/src/storage/remote-session.d.ts +318 -0
- package/dist/types/packages/core/src/storage/runtime-events.d.ts +33 -0
- package/dist/types/packages/core/src/storage/runtime-leases.d.ts +27 -0
- package/dist/types/packages/core/src/storage/runtime-process-leases.d.ts +47 -0
- package/dist/types/packages/core/src/storage/runtime-topic-state.d.ts +39 -0
- package/dist/types/packages/core/src/storage/runtime-turn-requests.d.ts +163 -0
- package/dist/types/packages/core/src/storage/self-schedules.d.ts +54 -0
- package/dist/types/packages/core/src/storage/session-asks.d.ts +78 -0
- package/dist/types/packages/core/src/storage/session-inbox-signal.d.ts +35 -0
- package/dist/types/packages/core/src/storage/session-inbox.d.ts +36 -0
- package/dist/types/packages/core/src/storage/sqlite.d.ts +20 -0
- package/dist/types/packages/core/src/storage/storage-contract.d.ts +46 -0
- package/dist/types/packages/core/src/storage/storage-host.d.ts +41 -0
- package/dist/types/packages/core/src/storage/storage-public-host.d.ts +7 -0
- package/dist/types/packages/core/src/storage/storage-public.d.ts +45 -0
- package/dist/types/packages/core/src/storage/tasks.d.ts +49 -0
- package/dist/types/packages/core/src/storage/token-stats.d.ts +69 -0
- package/dist/types/packages/core/src/storage/topic-archive-state.d.ts +33 -0
- package/dist/types/packages/core/src/storage/topic-archive.d.ts +42 -0
- package/dist/types/packages/core/src/storage/topic-host-mcp-grants.d.ts +5 -0
- package/dist/types/packages/core/src/storage/topic-link-records.d.ts +281 -0
- package/dist/types/packages/core/src/storage/topic-settings.d.ts +19 -0
- package/dist/types/packages/core/src/storage/topic-tool-capabilities.d.ts +37 -0
- package/dist/types/packages/core/src/storage/topic-transcript.d.ts +38 -0
- package/dist/types/packages/core/src/storage/vault-crypto-core.d.ts +6 -0
- package/dist/types/packages/core/src/storage/vault-crypto.d.ts +12 -0
- package/dist/types/packages/core/src/storage/vault-public.d.ts +3 -0
- package/dist/types/packages/core/src/storage/vault-request-gates.d.ts +69 -0
- package/dist/types/packages/core/src/storage/vault.d.ts +49 -0
- package/dist/types/packages/core/src/storage/wiki-summary-names.d.ts +13 -0
- package/dist/types/packages/core/src/storage/wiki.d.ts +15 -0
- package/dist/types/packages/core/src/topics/derive.d.ts +83 -0
- package/dist/types/packages/core/src/topics/lifecycle.d.ts +75 -0
- package/dist/types/packages/core/src/topics/links.d.ts +2 -0
- package/dist/types/packages/core/src/topics/personal-general.d.ts +15 -0
- package/dist/types/packages/core/src/topics/session.d.ts +70 -0
- package/dist/types/packages/core/src/types/api.d.ts +551 -0
- package/dist/types/packages/core/src/types.d.ts +405 -0
- package/dist/types/packages/core/src/version.d.ts +1 -0
- package/dist/types/packages/module-cron/src/background-sessions.d.ts +2 -0
- package/dist/types/packages/module-cron/src/context.d.ts +15 -0
- package/dist/types/packages/module-cron/src/host.d.ts +23 -0
- package/dist/types/packages/module-cron/src/index.d.ts +14 -0
- package/dist/types/packages/module-cron/src/module.d.ts +13 -0
- package/dist/types/packages/module-cron/src/schedule.d.ts +23 -0
- package/dist/types/packages/module-cron/src/scheduler.d.ts +46 -0
- package/dist/types/packages/module-cron/src/scripts.d.ts +29 -0
- package/dist/types/packages/module-cron/src/store.d.ts +152 -0
- package/dist/types/packages/module-cron/src/summarize.d.ts +4 -0
- package/dist/vault.js +848 -0
- package/dist/vault.js.map +18 -0
- package/install-bash-rs.mjs +90 -0
- package/install-browser-rs.mjs +83 -0
- package/package.json +171 -4
|
@@ -0,0 +1,484 @@
|
|
|
1
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
2
|
+
import { hostMcpGrantRefusal, isReservedRuntimeMcpServerName } from "#platform/mcp-config";
|
|
3
|
+
import { abortRoom, getRoomQuery } from "#query/active-rooms";
|
|
4
|
+
import { AbortReason } from "#query/types";
|
|
5
|
+
import { stampActorTopicScope } from "#runtime/actor-topic-scope";
|
|
6
|
+
import { resolveAttachmentByFileId } from "#runtime/file-hooks";
|
|
7
|
+
import { describeQuotedAuthor } from "#runtime/thread-context";
|
|
8
|
+
import {
|
|
9
|
+
renderUserTurnBatch,
|
|
10
|
+
renderUserTurnPrompt,
|
|
11
|
+
type UserTurnEnvelope,
|
|
12
|
+
type UserTurnReplyContext,
|
|
13
|
+
} from "#runtime/user-turn-envelope";
|
|
14
|
+
import { type HostMcpServerSpec, parseHostMcpServers } from "#runtime-gateway";
|
|
15
|
+
import { appendApiMessage, getApiMessage } from "#storage/api-messages";
|
|
16
|
+
import { getTopicSessionId } from "#storage/api-topics";
|
|
17
|
+
import { db } from "#storage/forum-db";
|
|
18
|
+
import { appendRuntimeEvent } from "#storage/runtime-events";
|
|
19
|
+
import {
|
|
20
|
+
backfillRuntimeGatewaySubmissionPayloadHash,
|
|
21
|
+
findRuntimeGatewaySubmission,
|
|
22
|
+
type RuntimeGatewaySubmission,
|
|
23
|
+
recordRuntimeGatewaySubmission,
|
|
24
|
+
} from "#storage/runtime-gateway-submissions";
|
|
25
|
+
import { getRuntimeTopicEpoch } from "#storage/runtime-topic-state";
|
|
26
|
+
import {
|
|
27
|
+
enqueueRuntimeUserTurnRequest,
|
|
28
|
+
getActiveRuntimeUserTurnRequest,
|
|
29
|
+
mergeRuntimeUserTurnRequest,
|
|
30
|
+
} from "#storage/runtime-turn-requests";
|
|
31
|
+
import { recordTopicHostMcpGrant } from "#storage/topic-host-mcp-grants";
|
|
32
|
+
import { isTopicClaimAbortFenced, isTopicClaimAbortFenceError } from "#storage/topic-link-records";
|
|
33
|
+
import { recordTopicToolCapabilities } from "#storage/topic-tool-capabilities";
|
|
34
|
+
import type { ActorTopicScope, RemoteSessionGrant } from "#types";
|
|
35
|
+
import type { MessageDto, TopicDto } from "#types/api";
|
|
36
|
+
|
|
37
|
+
export interface SubmitRuntimeGatewayTurnParams {
|
|
38
|
+
topic: TopicDto;
|
|
39
|
+
/** Canonical execution principal, normally `local`. */
|
|
40
|
+
userId: string;
|
|
41
|
+
/** Authenticated upstream author retained independently from execution. */
|
|
42
|
+
actorUserId?: string;
|
|
43
|
+
/** Host-asserted rooms the author may reach on this node; absent = current room only. */
|
|
44
|
+
actorTopicScope?: ActorTopicScope;
|
|
45
|
+
/** Hub-issued per-turn authority for remote session-comm; absent = fail-closed. */
|
|
46
|
+
remoteSession?: RemoteSessionGrant;
|
|
47
|
+
actorLabel?: string;
|
|
48
|
+
/** Topic owner's credential namespace. */
|
|
49
|
+
vaultUserId?: string;
|
|
50
|
+
/** Adapter provenance recorded on the canonical message. */
|
|
51
|
+
sourceAdapter?: string;
|
|
52
|
+
text: string;
|
|
53
|
+
clientMessageId: string;
|
|
54
|
+
requestId?: string;
|
|
55
|
+
allowAutoContinue?: boolean;
|
|
56
|
+
/**
|
|
57
|
+
* Whether this message should also run the AI. Defaults to true.
|
|
58
|
+
*
|
|
59
|
+
* A host whose room has the AI removed, or set to mention-only, still needs
|
|
60
|
+
* the message in the canonical transcript — otherwise Terminal and Telegram
|
|
61
|
+
* see a room with holes in it. `false` records the message and acknowledges
|
|
62
|
+
* it exactly as usual, and only declines to queue the turn.
|
|
63
|
+
*/
|
|
64
|
+
respond?: boolean;
|
|
65
|
+
/**
|
|
66
|
+
* What a new message does while a turn from the same person is running.
|
|
67
|
+
* `true` (default): abort it and resume with the merged batch (steer).
|
|
68
|
+
* `false`: leave the running turn alone and queue this message behind it.
|
|
69
|
+
*/
|
|
70
|
+
steer?: boolean;
|
|
71
|
+
/**
|
|
72
|
+
* Deliver into the same person's running turn, read after the step it is on,
|
|
73
|
+
* and the work goes on (Codex-style steer; wins over `steer`). Only a turn
|
|
74
|
+
* this process runs on a provider that takes live input can; otherwise the
|
|
75
|
+
* message waits in the queue as with `steer: false`. Either way it is queued
|
|
76
|
+
* first, so a delivered message the turn does not read still runs next.
|
|
77
|
+
*/
|
|
78
|
+
inject?: boolean;
|
|
79
|
+
/**
|
|
80
|
+
* Run as a turn of its own: never folded into a queued request or into the
|
|
81
|
+
* running one. A held follow-up goes out this way (`turn-follow-ups`).
|
|
82
|
+
*/
|
|
83
|
+
ownTurn?: boolean;
|
|
84
|
+
/** Hide both the injected prompt and provider output from the visible topic. */
|
|
85
|
+
silent?: boolean;
|
|
86
|
+
/** Answer inside this thread instead of the room's main flow (S-13). */
|
|
87
|
+
threadRootId?: string;
|
|
88
|
+
/**
|
|
89
|
+
* Inline quote-reply target — a pointer at one earlier message from the
|
|
90
|
+
* room's main flow.
|
|
91
|
+
*
|
|
92
|
+
* Deliberately not folded into `threadRootId`. The canonical schema keeps the
|
|
93
|
+
* two apart (`api-messages.ts`: `parent_id` is the quote, `thread_root_id` is
|
|
94
|
+
* thread membership) and the difference is observable: `listApiMessages`
|
|
95
|
+
* excludes anything carrying a thread root, so treating a quote as a thread
|
|
96
|
+
* reply would delete it from the channel it was posted in.
|
|
97
|
+
*/
|
|
98
|
+
parentId?: string;
|
|
99
|
+
/** Host-uploaded file ids already staged in this node's file store. */
|
|
100
|
+
attachments?: string[];
|
|
101
|
+
/**
|
|
102
|
+
* Capability minted by the calling adapter, forwarded to the turn's runtime
|
|
103
|
+
* MCP. Default-deny: a host that never says `true` gets no `show_*` tools,
|
|
104
|
+
* which is correct for a gateway with no visual surface to render into.
|
|
105
|
+
*/
|
|
106
|
+
visualTools?: boolean;
|
|
107
|
+
/** Capability minted by the calling adapter. Default-deny, like `visualTools`. */
|
|
108
|
+
fileDeliveryTools?: boolean;
|
|
109
|
+
/** Host-owned remote MCP servers granted to this manager topic. */
|
|
110
|
+
hostMcpServers?: Record<string, HostMcpServerSpec>;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export interface SubmitRuntimeGatewayTurnResult extends RuntimeGatewaySubmission {
|
|
114
|
+
message: MessageDto;
|
|
115
|
+
deduplicated: boolean;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function duplicateResult(
|
|
119
|
+
submission: RuntimeGatewaySubmission,
|
|
120
|
+
params: SubmitRuntimeGatewayTurnParams,
|
|
121
|
+
requestId: string,
|
|
122
|
+
actorUserId: string,
|
|
123
|
+
payloadHash: string,
|
|
124
|
+
): SubmitRuntimeGatewayTurnResult {
|
|
125
|
+
const sourceAdapter = params.sourceAdapter?.trim() || "runtime-gateway";
|
|
126
|
+
const message =
|
|
127
|
+
getApiMessage(submission.topicId, submission.messageId) ??
|
|
128
|
+
(params.silent
|
|
129
|
+
? {
|
|
130
|
+
id: submission.messageId,
|
|
131
|
+
topicId: params.topic.id,
|
|
132
|
+
authorId: actorUserId,
|
|
133
|
+
authorName: params.actorLabel,
|
|
134
|
+
sourceAdapter,
|
|
135
|
+
sourceMessageId: params.clientMessageId,
|
|
136
|
+
text: params.text,
|
|
137
|
+
createdAt: submission.createdAt,
|
|
138
|
+
}
|
|
139
|
+
: null);
|
|
140
|
+
if (!message) throw new Error("gateway submission references a missing canonical message");
|
|
141
|
+
if (submission.payloadHash && submission.payloadHash !== payloadHash) {
|
|
142
|
+
throw new RuntimeGatewayIdempotencyConflictError();
|
|
143
|
+
}
|
|
144
|
+
if (
|
|
145
|
+
// `MessageDto.authorName` is never persisted — `api_messages` has no
|
|
146
|
+
// `author_name` column, so a message fetched back from storage always
|
|
147
|
+
// has `authorName: undefined`. Comparing it here would either always
|
|
148
|
+
// fail (once `actorLabel` is set) or always pass (once it's cleared);
|
|
149
|
+
// it is dropped in favor of the fields that actually round-trip.
|
|
150
|
+
(!submission.payloadHash &&
|
|
151
|
+
(message.authorId !== actorUserId || message.text !== params.text)) ||
|
|
152
|
+
submission.clientMessageId !== params.clientMessageId ||
|
|
153
|
+
submission.requestId !== requestId ||
|
|
154
|
+
submission.topicId !== params.topic.id ||
|
|
155
|
+
submission.userId !== params.userId
|
|
156
|
+
) {
|
|
157
|
+
throw new RuntimeGatewayIdempotencyConflictError();
|
|
158
|
+
}
|
|
159
|
+
if (!submission.payloadHash) {
|
|
160
|
+
// Pre-0.2.5 rows never recorded `actorLabel`/`vaultUserId`/
|
|
161
|
+
// `allowAutoContinue` anywhere retrievable, so this replay could not
|
|
162
|
+
// actually be checked against them above. Adopt this call's hash as
|
|
163
|
+
// canonical for the key now, so any *later* replay with a different
|
|
164
|
+
// actor label, Vault, or auto-continue flag is caught instead of
|
|
165
|
+
// silently reusing this ACK forever.
|
|
166
|
+
backfillRuntimeGatewaySubmissionPayloadHash(submission.clientMessageId, payloadHash);
|
|
167
|
+
}
|
|
168
|
+
return {
|
|
169
|
+
...submission,
|
|
170
|
+
payloadHash: submission.payloadHash ?? payloadHash,
|
|
171
|
+
message,
|
|
172
|
+
deduplicated: true,
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function gatewayPayloadHash(
|
|
177
|
+
params: SubmitRuntimeGatewayTurnParams,
|
|
178
|
+
requestId: string,
|
|
179
|
+
actorUserId: string,
|
|
180
|
+
): string {
|
|
181
|
+
return createHash("sha256")
|
|
182
|
+
.update(
|
|
183
|
+
JSON.stringify([
|
|
184
|
+
params.topic.id,
|
|
185
|
+
params.userId,
|
|
186
|
+
actorUserId,
|
|
187
|
+
params.actorLabel ?? null,
|
|
188
|
+
params.vaultUserId ?? null,
|
|
189
|
+
params.text,
|
|
190
|
+
params.clientMessageId,
|
|
191
|
+
requestId,
|
|
192
|
+
params.allowAutoContinue ?? true,
|
|
193
|
+
// Whether the message ran the AI is part of the turn's identity, not a
|
|
194
|
+
// presentation detail: replaying the same key with `respond` flipped
|
|
195
|
+
// would otherwise reuse the silent ACK and never queue the turn (or
|
|
196
|
+
// vice versa), with nothing to tell the caller it was ignored.
|
|
197
|
+
params.respond ?? true,
|
|
198
|
+
params.silent ?? false,
|
|
199
|
+
// Part of the identity of the turn: the same key asked in the channel
|
|
200
|
+
// and in a thread are different turns, and replaying one as the other
|
|
201
|
+
// would answer in the wrong place.
|
|
202
|
+
params.threadRootId ?? null,
|
|
203
|
+
// Same reasoning as the thread root: which message this quotes is part
|
|
204
|
+
// of what the turn says, so a replay that changes it is a new turn.
|
|
205
|
+
params.parentId ?? null,
|
|
206
|
+
params.attachments ?? [],
|
|
207
|
+
// Adapter capabilities are deliberately absent. They are properties of the caller, not the message,
|
|
208
|
+
// and predate this field in persisted payload hashes. Hashing them would
|
|
209
|
+
// turn an adapter upgrade into a 409 for keys already in flight.
|
|
210
|
+
]),
|
|
211
|
+
)
|
|
212
|
+
.digest("hex");
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Durable ingress for an authenticated external gateway. It deliberately
|
|
217
|
+
* reuses the canonical message table and existing durable turn worker rather
|
|
218
|
+
* than starting a second execution path.
|
|
219
|
+
*/
|
|
220
|
+
/**
|
|
221
|
+
* The supplied idempotency key already identifies a different turn.
|
|
222
|
+
*
|
|
223
|
+
* A distinct type rather than a plain `Error` because the control plane maps
|
|
224
|
+
* this to 409, and it must not be confused with a *missing* `clientMessageId`,
|
|
225
|
+
* which is a malformed request (400).
|
|
226
|
+
*/
|
|
227
|
+
export class RuntimeGatewayIdempotencyConflictError extends Error {
|
|
228
|
+
constructor(message = "clientMessageId or requestId is already bound to another turn") {
|
|
229
|
+
super(message);
|
|
230
|
+
this.name = "RuntimeGatewayIdempotencyConflictError";
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* The topic is being deleted by a host create-claim abort (topic-link PR7):
|
|
236
|
+
* the message is refused, not stored. Mapped to 409 `topic_unavailable`; a
|
|
237
|
+
* retry after the abort settles either succeeds (the delete failed or was
|
|
238
|
+
* vetoed) or finds the topic gone.
|
|
239
|
+
*/
|
|
240
|
+
export class RuntimeGatewayTopicUnavailableError extends Error {
|
|
241
|
+
readonly code = "topic_unavailable";
|
|
242
|
+
|
|
243
|
+
constructor(message = "the topic is being deleted and accepts no messages") {
|
|
244
|
+
super(message);
|
|
245
|
+
this.name = "RuntimeGatewayTopicUnavailableError";
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
export function submitRuntimeGatewayTurn(
|
|
250
|
+
params: SubmitRuntimeGatewayTurnParams,
|
|
251
|
+
): SubmitRuntimeGatewayTurnResult {
|
|
252
|
+
const hostMcpServers = parseHostMcpServers(params.hostMcpServers);
|
|
253
|
+
const grantRefusal =
|
|
254
|
+
hostMcpServers === undefined
|
|
255
|
+
? null
|
|
256
|
+
: hostMcpGrantRefusal(params.topic, Object.keys(hostMcpServers));
|
|
257
|
+
if (grantRefusal) throw new TypeError(grantRefusal);
|
|
258
|
+
const conflictingHostMcpName = Object.keys(hostMcpServers ?? {}).find(
|
|
259
|
+
isReservedRuntimeMcpServerName,
|
|
260
|
+
);
|
|
261
|
+
if (conflictingHostMcpName) {
|
|
262
|
+
throw new TypeError(
|
|
263
|
+
`host MCP server name conflicts with node catalog: ${conflictingHostMcpName}`,
|
|
264
|
+
);
|
|
265
|
+
}
|
|
266
|
+
const requestId = params.requestId ?? params.clientMessageId;
|
|
267
|
+
const actorUserId = params.actorUserId ?? params.userId;
|
|
268
|
+
const sourceAdapter = params.sourceAdapter?.trim() || "runtime-gateway";
|
|
269
|
+
const respond = params.respond ?? true;
|
|
270
|
+
const payloadHash = gatewayPayloadHash(params, requestId, actorUserId);
|
|
271
|
+
const existing = findRuntimeGatewaySubmission(params.clientMessageId, requestId);
|
|
272
|
+
if (existing) {
|
|
273
|
+
return duplicateResult(existing, params, requestId, actorUserId, payloadHash);
|
|
274
|
+
}
|
|
275
|
+
// Refused before anything is recorded. The same fence is enforced again,
|
|
276
|
+
// atomically, by the `api_messages` trigger inside the transaction below.
|
|
277
|
+
if (isTopicClaimAbortFenced(params.topic.id)) throw new RuntimeGatewayTopicUnavailableError();
|
|
278
|
+
|
|
279
|
+
// Remember what this adapter grants for the room, so the turns that never
|
|
280
|
+
// see an adapter — tell/ask, cron, auto-continue, subagent reports — inherit
|
|
281
|
+
// it instead of silently running without the tools.
|
|
282
|
+
recordTopicToolCapabilities(params.topic.id, {
|
|
283
|
+
visualTools: params.visualTools === true,
|
|
284
|
+
fileDeliveryTools: params.fileDeliveryTools === true,
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
// Name the thread for the model. The quote is read from this node's own
|
|
288
|
+
// store rather than accepted from the host: the host is trusted to say
|
|
289
|
+
// *which* message is being answered, not to say what it contained.
|
|
290
|
+
const quotedId = params.threadRootId ?? params.parentId;
|
|
291
|
+
const quoted = quotedId ? getApiMessage(params.topic.id, quotedId) : undefined;
|
|
292
|
+
const quotedFields =
|
|
293
|
+
quoted && !quoted.deleted
|
|
294
|
+
? { label: describeQuotedAuthor(quoted), text: quoted.text }
|
|
295
|
+
: undefined;
|
|
296
|
+
const replyTo: UserTurnReplyContext | undefined = params.threadRootId
|
|
297
|
+
? { kind: "thread", rootId: params.threadRootId, ...quotedFields }
|
|
298
|
+
: params.parentId
|
|
299
|
+
? { kind: "quote", ...quotedFields }
|
|
300
|
+
: undefined;
|
|
301
|
+
|
|
302
|
+
const createdAt = new Date().toISOString();
|
|
303
|
+
const attachments = params.attachments?.map(resolveAttachmentByFileId);
|
|
304
|
+
if (attachments?.some((attachment) => !attachment)) {
|
|
305
|
+
throw new Error("gateway attachment could not be resolved");
|
|
306
|
+
}
|
|
307
|
+
const message: MessageDto = {
|
|
308
|
+
id: randomUUID(),
|
|
309
|
+
topicId: params.topic.id,
|
|
310
|
+
authorId: actorUserId,
|
|
311
|
+
authorName: params.actorLabel,
|
|
312
|
+
sourceAdapter,
|
|
313
|
+
sourceMessageId: params.clientMessageId,
|
|
314
|
+
text: params.text,
|
|
315
|
+
...(attachments?.length
|
|
316
|
+
? { attachments: attachments as NonNullable<MessageDto["attachments"]> }
|
|
317
|
+
: {}),
|
|
318
|
+
...(params.threadRootId ? { threadRootId: params.threadRootId } : {}),
|
|
319
|
+
...(params.parentId ? { parentId: params.parentId } : {}),
|
|
320
|
+
createdAt,
|
|
321
|
+
};
|
|
322
|
+
const submission: RuntimeGatewaySubmission = {
|
|
323
|
+
clientMessageId: params.clientMessageId,
|
|
324
|
+
requestId,
|
|
325
|
+
topicId: params.topic.id,
|
|
326
|
+
messageId: message.id,
|
|
327
|
+
userId: params.userId,
|
|
328
|
+
createdAt,
|
|
329
|
+
ackCursor: 0,
|
|
330
|
+
messageCursor: 0,
|
|
331
|
+
payloadHash,
|
|
332
|
+
};
|
|
333
|
+
|
|
334
|
+
// Whether this message steers (aborts and resumes) the turn a worker holds
|
|
335
|
+
// right now. Decided by what the merge actually absorbed, so it cannot drift
|
|
336
|
+
// from the merge rule: the active request folds into the new batch only when
|
|
337
|
+
// the same person is speaking (a different person, or a turn whose actor was
|
|
338
|
+
// never recorded, stays a separate queue entry), and only a folded turn has
|
|
339
|
+
// a replacement batch to resume from after the abort.
|
|
340
|
+
let steersActiveTurn = false;
|
|
341
|
+
let delivery: "injected" | "queued" | "steered" | "started" | undefined;
|
|
342
|
+
try {
|
|
343
|
+
db.transaction(() => {
|
|
344
|
+
if (!params.silent) appendApiMessage(message, { notify: false });
|
|
345
|
+
// The only thing `respond: false` skips. Everything else — the canonical
|
|
346
|
+
// message, the accepted event, the idempotency record — still happens, so
|
|
347
|
+
// a silent message is indistinguishable from a normal one everywhere
|
|
348
|
+
// except that no turn is queued for it.
|
|
349
|
+
if (respond) {
|
|
350
|
+
const active = getActiveRuntimeUserTurnRequest(params.topic.id);
|
|
351
|
+
const envelope: UserTurnEnvelope = {
|
|
352
|
+
prompt: params.text,
|
|
353
|
+
actorUserId,
|
|
354
|
+
...(params.actorLabel ? { actorLabel: params.actorLabel } : {}),
|
|
355
|
+
...(params.attachments?.length ? { attachments: params.attachments } : {}),
|
|
356
|
+
...(replyTo ? { replyTo } : {}),
|
|
357
|
+
};
|
|
358
|
+
// The running turn this message can be read inside: the same person's,
|
|
359
|
+
// in the same flow, run by this process on a provider that takes live
|
|
360
|
+
// input. Attachments wait for a turn of their own.
|
|
361
|
+
const live =
|
|
362
|
+
params.inject === true && active && !params.silent && !params.attachments?.length
|
|
363
|
+
? getRoomQuery(params.topic.id)
|
|
364
|
+
: undefined;
|
|
365
|
+
const injectInto =
|
|
366
|
+
live?.deliverMidTurn &&
|
|
367
|
+
live.queryId === active?.runningQueryId &&
|
|
368
|
+
active?.execution?.actorUserId === actorUserId &&
|
|
369
|
+
active?.execution?.threadRootId === params.threadRootId
|
|
370
|
+
? live.deliverMidTurn
|
|
371
|
+
: undefined;
|
|
372
|
+
const queued = {
|
|
373
|
+
topicId: params.topic.id,
|
|
374
|
+
userId: params.userId,
|
|
375
|
+
userMessages: [envelope],
|
|
376
|
+
allowAutoContinue: params.allowAutoContinue ?? true,
|
|
377
|
+
requestId,
|
|
378
|
+
topicEpoch: getRuntimeTopicEpoch(params.topic.id),
|
|
379
|
+
execution: {
|
|
380
|
+
sessionId: getTopicSessionId(params.topic.id),
|
|
381
|
+
sessionIdSpecified: true,
|
|
382
|
+
conversationPrompts: [params.text],
|
|
383
|
+
loggedUserMessageCount: 0,
|
|
384
|
+
vaultUserId: params.vaultUserId,
|
|
385
|
+
actorUserId,
|
|
386
|
+
// Stamped on arrival: the assertion is believed for a bounded
|
|
387
|
+
// window from here (`isActorTopicScopeFresh`), not for the MCP
|
|
388
|
+
// token's lifetime.
|
|
389
|
+
...(params.actorTopicScope
|
|
390
|
+
? { actorTopicScope: stampActorTopicScope(params.actorTopicScope) }
|
|
391
|
+
: {}),
|
|
392
|
+
// Like the assertion: describes the caller's authority for this
|
|
393
|
+
// turn, rides the durable row, and is outside the idempotency hash.
|
|
394
|
+
...(params.remoteSession ? { remoteSession: params.remoteSession } : {}),
|
|
395
|
+
silent: params.silent === true,
|
|
396
|
+
// The adapter's capability grant has to ride the durable request:
|
|
397
|
+
// the turn worker builds the runtime MCP from `execution`, so a
|
|
398
|
+
// flag left here undefined is what makes `show_html` and friends
|
|
399
|
+
// absent from a mapped room's turn.
|
|
400
|
+
visualTools: params.visualTools,
|
|
401
|
+
fileDeliveryTools: params.fileDeliveryTools,
|
|
402
|
+
...(params.threadRootId ? { threadRootId: params.threadRootId } : {}),
|
|
403
|
+
},
|
|
404
|
+
};
|
|
405
|
+
if (injectInto?.({ id: message.id, text: renderUserTurnPrompt(envelope) }, requestId)) {
|
|
406
|
+
// Queued all the same, as its own row that is never folded into
|
|
407
|
+
// another: once the running turn reads the message exactly this row
|
|
408
|
+
// is dropped, and if the turn ends without reading it, it runs next.
|
|
409
|
+
enqueueRuntimeUserTurnRequest({
|
|
410
|
+
...queued,
|
|
411
|
+
prompt: renderUserTurnBatch([envelope]),
|
|
412
|
+
execution: { ...queued.execution, deliveredMidTurn: true },
|
|
413
|
+
supersedeExisting: false,
|
|
414
|
+
});
|
|
415
|
+
delivery = "injected";
|
|
416
|
+
} else if (params.ownTurn === true) {
|
|
417
|
+
enqueueRuntimeUserTurnRequest({
|
|
418
|
+
...queued,
|
|
419
|
+
prompt: renderUserTurnBatch([envelope]),
|
|
420
|
+
...(params.attachments?.length ? { attachments: params.attachments } : {}),
|
|
421
|
+
execution: { ...queued.execution, ownTurn: true },
|
|
422
|
+
supersedeExisting: false,
|
|
423
|
+
});
|
|
424
|
+
delivery = active ? "queued" : "started";
|
|
425
|
+
} else {
|
|
426
|
+
const merged = mergeRuntimeUserTurnRequest({
|
|
427
|
+
...queued,
|
|
428
|
+
...((params.steer === false || params.inject === true) && active
|
|
429
|
+
? { keepRequestIds: [active.requestId] }
|
|
430
|
+
: {}),
|
|
431
|
+
});
|
|
432
|
+
steersActiveTurn =
|
|
433
|
+
active !== null && merged.supersededRequestIds.includes(active.requestId);
|
|
434
|
+
delivery = steersActiveTurn ? "steered" : active ? "queued" : "started";
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
if (hostMcpServers !== undefined) {
|
|
438
|
+
recordTopicHostMcpGrant(params.topic.id, hostMcpServers);
|
|
439
|
+
}
|
|
440
|
+
const acceptedEvent = appendRuntimeEvent("runtime-gateway-ingress", {
|
|
441
|
+
type: "ai-status",
|
|
442
|
+
topicId: params.topic.id,
|
|
443
|
+
payload: {
|
|
444
|
+
kind: "turn_accepted",
|
|
445
|
+
requestId,
|
|
446
|
+
clientMessageId: params.clientMessageId,
|
|
447
|
+
messageId: message.id,
|
|
448
|
+
...(delivery ? { delivery } : {}),
|
|
449
|
+
},
|
|
450
|
+
});
|
|
451
|
+
const messageEvent = params.silent
|
|
452
|
+
? null
|
|
453
|
+
: appendRuntimeEvent("runtime-gateway-ingress", {
|
|
454
|
+
type: "message",
|
|
455
|
+
topicId: params.topic.id,
|
|
456
|
+
payload: message,
|
|
457
|
+
});
|
|
458
|
+
submission.ackCursor = acceptedEvent.seq;
|
|
459
|
+
submission.messageCursor = messageEvent?.seq ?? 0;
|
|
460
|
+
recordRuntimeGatewaySubmission(submission);
|
|
461
|
+
})();
|
|
462
|
+
} catch (error) {
|
|
463
|
+
const raced = findRuntimeGatewaySubmission(params.clientMessageId, requestId);
|
|
464
|
+
if (raced) return duplicateResult(raced, params, requestId, actorUserId, payloadHash);
|
|
465
|
+
if (isTopicClaimAbortFenceError(error)) throw new RuntimeGatewayTopicUnavailableError();
|
|
466
|
+
throw new Error("failed to persist gateway turn idempotency record");
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
// A new message from the *same* person steers the active topic turn. The
|
|
470
|
+
// durable replacement is committed first; `abortRoom` stops the provider at
|
|
471
|
+
// once when this process holds the turn (and still flags the lease so an
|
|
472
|
+
// owner in another process sees it on its next heartbeat), and the worker
|
|
473
|
+
// resumes the merged batch after unwind.
|
|
474
|
+
//
|
|
475
|
+
// That resume is the whole reason the abort is safe, so it is conditional on
|
|
476
|
+
// the merge having absorbed the active turn: with `respond: false` there is
|
|
477
|
+
// no replacement batch, and when another person (or a turn whose actor is
|
|
478
|
+
// unknown) is being answered, that answer is left to finish — the new
|
|
479
|
+
// request waits its turn in the queue and runs with its own actor and
|
|
480
|
+
// assertion.
|
|
481
|
+
if (steersActiveTurn) abortRoom(params.topic.id, AbortReason.Internal);
|
|
482
|
+
|
|
483
|
+
return { ...submission, message, deduplicated: false };
|
|
484
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { runtimeBus } from "#bus";
|
|
3
|
+
import { type StartAiTurnParams, startAiTurn } from "#runtime/turn-runner";
|
|
4
|
+
import { appendApiMessage } from "#storage/api-messages";
|
|
5
|
+
import { recordTopicToolCapabilities } from "#storage/topic-tool-capabilities";
|
|
6
|
+
import type { MessageDto, TopicDto } from "#types/api";
|
|
7
|
+
|
|
8
|
+
export interface SubmitUserMessageParams {
|
|
9
|
+
topic: TopicDto;
|
|
10
|
+
userId: string;
|
|
11
|
+
text: string;
|
|
12
|
+
sourceAdapter?: string;
|
|
13
|
+
allowAutoContinue?: boolean;
|
|
14
|
+
/** Adapter capability: only Otium should enable visual panel tools. */
|
|
15
|
+
visualTools?: boolean;
|
|
16
|
+
/** Adapter capability: Otium and Telegram may enable file delivery. */
|
|
17
|
+
fileDeliveryTools?: boolean;
|
|
18
|
+
onDispatched?: (queryId: string) => void;
|
|
19
|
+
/** Override used by remote hosts and deterministic tests. */
|
|
20
|
+
startTurn?: (params: StartAiTurnParams) => string | null;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface SubmitUserMessageResult {
|
|
24
|
+
message: MessageDto;
|
|
25
|
+
queryId: string | null;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Canonical local-user submission flow. Persistence and publication happen
|
|
30
|
+
* before dispatch so every channel observes the same message even when the AI
|
|
31
|
+
* turn is rejected or deferred.
|
|
32
|
+
*/
|
|
33
|
+
export function submitUserMessage(params: SubmitUserMessageParams): SubmitUserMessageResult {
|
|
34
|
+
// Same reason as the gateway path: record what this adapter grants so the
|
|
35
|
+
// room's adapter-less turns (tell/ask, cron, auto-continue) inherit it.
|
|
36
|
+
recordTopicToolCapabilities(params.topic.id, {
|
|
37
|
+
visualTools: params.visualTools === true,
|
|
38
|
+
fileDeliveryTools: params.fileDeliveryTools === true,
|
|
39
|
+
});
|
|
40
|
+
const message: MessageDto = {
|
|
41
|
+
id: randomUUID(),
|
|
42
|
+
topicId: params.topic.id,
|
|
43
|
+
authorId: params.userId,
|
|
44
|
+
...(params.sourceAdapter ? { sourceAdapter: params.sourceAdapter } : {}),
|
|
45
|
+
text: params.text,
|
|
46
|
+
createdAt: new Date().toISOString(),
|
|
47
|
+
};
|
|
48
|
+
appendApiMessage(message);
|
|
49
|
+
runtimeBus().broadcastMessage(params.topic.id, message);
|
|
50
|
+
const queryId = (params.startTurn ?? startAiTurn)({
|
|
51
|
+
topic: params.topic,
|
|
52
|
+
userId: params.userId,
|
|
53
|
+
prompt: params.text,
|
|
54
|
+
allowAutoContinue: params.allowAutoContinue ?? true,
|
|
55
|
+
visualTools: params.visualTools === true,
|
|
56
|
+
fileDeliveryTools: params.fileDeliveryTools === true,
|
|
57
|
+
onDispatched: params.onDispatched,
|
|
58
|
+
});
|
|
59
|
+
return { message, queryId };
|
|
60
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { getRegistry } from "#agents/registry";
|
|
2
|
+
import { WsHub } from "#bus";
|
|
3
|
+
import { getApiTopicConfig, setApiTopicConfig } from "#storage/api-topic-config";
|
|
4
|
+
import { getTopic } from "#storage/api-topics";
|
|
5
|
+
import type { EffortLevel } from "#types";
|
|
6
|
+
|
|
7
|
+
export type SwitchTopicEffortResult =
|
|
8
|
+
| { ok: true; effort: EffortLevel; text: string }
|
|
9
|
+
| { ok: false; error: string };
|
|
10
|
+
|
|
11
|
+
export interface SwitchTopicEffortParams {
|
|
12
|
+
topicId: string;
|
|
13
|
+
userId: string;
|
|
14
|
+
effort: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** Apply and user-lock one reasoning effort without resetting the topic session. */
|
|
18
|
+
export function switchTopicEffort(params: SwitchTopicEffortParams): SwitchTopicEffortResult {
|
|
19
|
+
const topic = getTopic(params.topicId);
|
|
20
|
+
if (!topic) return { ok: false, error: "Topic not found" };
|
|
21
|
+
const owner = topic.participants.some(
|
|
22
|
+
(participant) => participant.userId === params.userId && participant.role === "owner",
|
|
23
|
+
);
|
|
24
|
+
if (!owner) return { ok: false, error: "Only topic owners can change the effort" };
|
|
25
|
+
if (!topic.agent) return { ok: false, error: "This topic has no AI effort" };
|
|
26
|
+
|
|
27
|
+
const registry = getRegistry(topic.agent);
|
|
28
|
+
const effort = registry.validEfforts.find((candidate) => candidate === params.effort);
|
|
29
|
+
if (!effort) {
|
|
30
|
+
return {
|
|
31
|
+
ok: false,
|
|
32
|
+
error: `Unknown effort: ${String(params.effort).trim() || "(empty)"}`,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const currentConfig = getApiTopicConfig(topic.id) ?? {};
|
|
37
|
+
setApiTopicConfig(topic.id, {
|
|
38
|
+
...currentConfig,
|
|
39
|
+
effort,
|
|
40
|
+
effortLocked: true,
|
|
41
|
+
});
|
|
42
|
+
WsHub.get().broadcastTopicUpdated(topic.id);
|
|
43
|
+
return {
|
|
44
|
+
ok: true,
|
|
45
|
+
effort,
|
|
46
|
+
text: `Effort set to '${effort}'. Applies from the next turn.`,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { switchApiTopicAgent } from "#agents/api-topic-agent-switch";
|
|
2
|
+
import { checkAgentModelAuth } from "#agents/auth-check";
|
|
3
|
+
import { selectableModel } from "#agents/model-catalog";
|
|
4
|
+
import { WsHub } from "#bus";
|
|
5
|
+
import { resolveTopicWorkspaceDir } from "#platform/config";
|
|
6
|
+
import { getApiTopicConfig, setApiTopicConfig } from "#storage/api-topic-config";
|
|
7
|
+
import { getTopic } from "#storage/api-topics";
|
|
8
|
+
|
|
9
|
+
export type SwitchTopicModelResult =
|
|
10
|
+
| { ok: true; model: string; text: string }
|
|
11
|
+
| { ok: false; error: string };
|
|
12
|
+
|
|
13
|
+
export interface SwitchTopicModelParams {
|
|
14
|
+
topicId: string;
|
|
15
|
+
userId: string;
|
|
16
|
+
model: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Apply one user-selected model to a topic. The model token determines its
|
|
21
|
+
* runtime owner internally, so channel adapters never implement or expose a
|
|
22
|
+
* separate agent picker. Cross-runtime switches preserve portable history via
|
|
23
|
+
* the same rollout bridge used by the topic-config MCP tools.
|
|
24
|
+
*/
|
|
25
|
+
export function switchTopicModel(params: SwitchTopicModelParams): SwitchTopicModelResult {
|
|
26
|
+
const topic = getTopic(params.topicId);
|
|
27
|
+
if (!topic) return { ok: false, error: "Topic not found" };
|
|
28
|
+
const owner = topic.participants.some(
|
|
29
|
+
(participant) => participant.userId === params.userId && participant.role === "owner",
|
|
30
|
+
);
|
|
31
|
+
if (!owner) return { ok: false, error: "Only topic owners can change the model" };
|
|
32
|
+
if (!topic.agent) return { ok: false, error: "This topic has no AI model" };
|
|
33
|
+
|
|
34
|
+
const target = selectableModel(params.model);
|
|
35
|
+
if (!target) return { ok: false, error: `Unknown model: ${params.model.trim() || "(empty)"}` };
|
|
36
|
+
const auth = checkAgentModelAuth(target.agent, target.model, undefined, params.userId);
|
|
37
|
+
if (!auth.ok) return { ok: false, error: auth.error };
|
|
38
|
+
|
|
39
|
+
const currentAgent = topic.agent;
|
|
40
|
+
const currentConfig = getApiTopicConfig(topic.id) ?? {};
|
|
41
|
+
const nextConfig = {
|
|
42
|
+
...currentConfig,
|
|
43
|
+
model: target.model,
|
|
44
|
+
effort: undefined,
|
|
45
|
+
agentLocked: true,
|
|
46
|
+
modelLocked: true,
|
|
47
|
+
effortLocked: undefined,
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
if (currentAgent !== target.agent) {
|
|
51
|
+
const switched = switchApiTopicAgent({
|
|
52
|
+
topicId: topic.id,
|
|
53
|
+
topicTitle: topic.title,
|
|
54
|
+
userId: params.userId,
|
|
55
|
+
fromAgent: currentAgent,
|
|
56
|
+
agent: target.agent,
|
|
57
|
+
cwd: resolveTopicWorkspaceDir(topic.id),
|
|
58
|
+
config: nextConfig,
|
|
59
|
+
defaultModel: topic.defaultModel,
|
|
60
|
+
defaultEffort: topic.defaultEffort,
|
|
61
|
+
reason: "user-model-switch",
|
|
62
|
+
});
|
|
63
|
+
if (!switched.ok) return { ok: false, error: switched.error };
|
|
64
|
+
} else {
|
|
65
|
+
setApiTopicConfig(topic.id, nextConfig);
|
|
66
|
+
// A provider session is not owned by one model. Codex, Claude, and Maestro
|
|
67
|
+
// all accept the selected model when resuming, so keep the durable resume
|
|
68
|
+
// key and let the next turn continue the same rollout with the new model.
|
|
69
|
+
// Clearing it here silently discarded native tool/history structure and
|
|
70
|
+
// made an ordinary model change look like `/new`.
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
WsHub.get().broadcastTopicUpdated(topic.id);
|
|
74
|
+
return {
|
|
75
|
+
ok: true,
|
|
76
|
+
model: target.model,
|
|
77
|
+
text: `Model set to '${target.model}'. Applies from the next turn.`,
|
|
78
|
+
};
|
|
79
|
+
}
|