@otium-team/negotium 0.0.0-stage → 0.23.11
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 +23903 -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 +2336 -0
- package/dist/browser-runtime.js.map +35 -0
- package/dist/canonical-mcp-bridge.js +14 -0
- package/dist/canonical-mcp-bridge.js.map +9 -0
- package/dist/chunk-0fenxbe6.js +173 -0
- package/dist/chunk-0fenxbe6.js.map +12 -0
- package/dist/chunk-2mx7fq49.js +6 -0
- package/dist/chunk-2mx7fq49.js.map +9 -0
- package/dist/chunk-ad7kxsaq.js +202 -0
- package/dist/chunk-ad7kxsaq.js.map +9 -0
- package/dist/chunk-da9ad838.js +3927 -0
- package/dist/chunk-da9ad838.js.map +47 -0
- package/dist/chunk-f7p0h1gs.js +54 -0
- package/dist/chunk-f7p0h1gs.js.map +10 -0
- package/dist/chunk-jtv8yzy1.js +206 -0
- package/dist/chunk-jtv8yzy1.js.map +10 -0
- package/dist/chunk-mxxwx5mg.js +375 -0
- package/dist/chunk-mxxwx5mg.js.map +13 -0
- package/dist/cron.js +1 -0
- package/dist/hosted-agent.js +5919 -0
- package/dist/hosted-agent.js.map +62 -0
- package/dist/main.js +60536 -0
- package/dist/main.js.map +338 -0
- package/dist/mcp-catalog.js +39 -0
- package/dist/mcp-catalog.js.map +10 -0
- package/dist/mcp-factories.js +26572 -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 +1073 -0
- package/dist/query-runtime.js.map +26 -0
- package/dist/registry.js +336 -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 +866 -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 +420 -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 +186 -0
- package/dist/runtime/src/application/vault-command.ts +170 -0
- package/dist/runtime/src/bus.ts +403 -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 +200 -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 +508 -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 +2284 -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 +848 -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-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 +805 -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 +582 -0
- package/dist/runtime/src/types.ts +395 -0
- package/dist/runtime/src/version.ts +1 -0
- package/dist/runtime/tsconfig.json +13 -0
- package/dist/runtime-gateway.js +453 -0
- package/dist/runtime-gateway.js.map +10 -0
- package/dist/runtime-helpers.js +1794 -0
- package/dist/runtime-helpers.js.map +40 -0
- package/dist/sqlite.js +68 -0
- package/dist/sqlite.js.map +10 -0
- package/dist/storage.js +5194 -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 +138 -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 +234 -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 +224 -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 +138 -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 +546 -0
- package/dist/types/packages/core/src/types.d.ts +384 -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 +850 -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,318 @@
|
|
|
1
|
+
import { registerStorageSchemaInitializer } from "./storage-host";
|
|
2
|
+
type RemoteSessionSchemaDatabase = Parameters<Parameters<typeof registerStorageSchemaInitializer>[0]>[0];
|
|
3
|
+
/**
|
|
4
|
+
* Idempotent and all-or-nothing. A current schema is detected read-only, so a
|
|
5
|
+
* normal boot never takes the write lock. Otherwise the tables and every
|
|
6
|
+
* missing column are added in one `BEGIN IMMEDIATE`: concurrent boots
|
|
7
|
+
* serialize, and the loser re-reads the columns under the lock instead of
|
|
8
|
+
* racing an `ALTER` (which used to be swallowed together with any other
|
|
9
|
+
* error, e.g. SQLITE_BUSY, leaving a process without the column).
|
|
10
|
+
*/
|
|
11
|
+
export declare function initializeRemoteSessionSchema(database: RemoteSessionSchemaDatabase): void;
|
|
12
|
+
/** Claims older than this are forgotten; the hub never retries a call this late. */
|
|
13
|
+
export declare const REMOTE_SESSION_INBOX_CLAIM_TTL_MS: number;
|
|
14
|
+
/** A reply the hub has not acknowledged by then is dropped: the caller's pending ask has timed out. */
|
|
15
|
+
export declare const REMOTE_SESSION_REPLY_OUTBOX_TTL_MS: number;
|
|
16
|
+
/** Poll cadence of the reply outbox worker; individual rows back off (see {@link remoteSessionRetryDelayMs}). */
|
|
17
|
+
export declare const REMOTE_SESSION_REPLY_RETRY_MS = 5000;
|
|
18
|
+
/** Backoff ladder for a reply the hub did not accept: 5, 10, 20, 30 s (cap), with jitter. */
|
|
19
|
+
export declare const REMOTE_SESSION_REPLY_BACKOFF_BASE_MS = 5000;
|
|
20
|
+
export declare const REMOTE_SESSION_REPLY_BACKOFF_MAX_MS = 30000;
|
|
21
|
+
/**
|
|
22
|
+
* How long a `processing` claim is held before another delivery (a hub retry
|
|
23
|
+
* or the maintenance pass) may take it over. Longer than any single delivery
|
|
24
|
+
* attempt, so a live process is never raced by its own retry.
|
|
25
|
+
*/
|
|
26
|
+
export declare const REMOTE_SESSION_INBOX_CLAIM_LEASE_MS = 60000;
|
|
27
|
+
export type RemoteSessionInboxKind = "tell" | "ask" | "abort" | "ask-reply";
|
|
28
|
+
export type RemoteSessionInboxClaimState = "processing" | "completed";
|
|
29
|
+
/**
|
|
30
|
+
* `claimed`: this caller now holds the `processing` lease (fresh, or taken
|
|
31
|
+
* over from an expired one). `replay`: a `completed` claim with the same
|
|
32
|
+
* payload. `in_progress`: another delivery holds a live lease. `conflict`:
|
|
33
|
+
* the id is bound to a different payload/kind/room.
|
|
34
|
+
*/
|
|
35
|
+
export type RemoteSessionInboxClaimOutcome = "claimed" | "replay" | "in_progress" | "conflict";
|
|
36
|
+
/**
|
|
37
|
+
* Delay before retry number `attempts` (1-based: the first retry after the
|
|
38
|
+
* immediate attempt is `attempts = 1`): 5, 10, 20, 30 s and 30 s thereafter,
|
|
39
|
+
* each with ±20 % jitter from `random` (injectable for deterministic tests).
|
|
40
|
+
*/
|
|
41
|
+
export declare function remoteSessionRetryDelayMs(attempts: number, random?: () => number): number;
|
|
42
|
+
/**
|
|
43
|
+
* Stable digest of a value. The inbox hashes its actor-bound claim identity
|
|
44
|
+
* (`remoteSessionInboxClaimIdentity` in `#runtime/remote-session-inbox`), so
|
|
45
|
+
* a retried delivery is recognised as one only under the same principal.
|
|
46
|
+
*/
|
|
47
|
+
export declare function remoteSessionPayloadHash(payload: unknown): string;
|
|
48
|
+
export interface RemoteSessionInboxClaimRecord {
|
|
49
|
+
requestId: string;
|
|
50
|
+
kind: RemoteSessionInboxKind;
|
|
51
|
+
topicId: string;
|
|
52
|
+
payloadHash: string;
|
|
53
|
+
state: RemoteSessionInboxClaimState;
|
|
54
|
+
leaseUntil: number;
|
|
55
|
+
payload: unknown;
|
|
56
|
+
createdAt: number;
|
|
57
|
+
/** Who holds the claim right now (`null`: written before tokens existed). */
|
|
58
|
+
owner: string | null;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* `true` only when the process that holds `owner` is provably gone: our own
|
|
62
|
+
* pid under another incarnation (the pid was reused after a restart), or a
|
|
63
|
+
* pid the OS reports as nonexistent. A live process, a pid we may not signal,
|
|
64
|
+
* an unparseable or legacy (`null`) token are all "maybe alive".
|
|
65
|
+
*/
|
|
66
|
+
export declare function remoteSessionClaimOwnerIsDead(owner: string | null): boolean;
|
|
67
|
+
export interface RemoteSessionInboxClaimResult {
|
|
68
|
+
outcome: RemoteSessionInboxClaimOutcome;
|
|
69
|
+
/** Set exactly when `outcome` is `claimed`: the token release/complete must present. */
|
|
70
|
+
owner?: string;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Claim one hub delivery as `processing` under a lease. For tell/ask/abort
|
|
74
|
+
* the caller completes it in the same transaction as the enqueue; for an
|
|
75
|
+
* ask-reply it stays `processing` — with `payload` persisted — until the
|
|
76
|
+
* answer is durably in the caller's room, or is released so the hub's retry
|
|
77
|
+
* runs the delivery again.
|
|
78
|
+
*/
|
|
79
|
+
export declare function claimRemoteSessionInboxOwned(args: {
|
|
80
|
+
requestId: string;
|
|
81
|
+
kind: RemoteSessionInboxKind;
|
|
82
|
+
topicId: string;
|
|
83
|
+
payloadHash: string;
|
|
84
|
+
/** Persisted while `processing` so an interrupted delivery can be re-run. */
|
|
85
|
+
payload?: unknown;
|
|
86
|
+
now?: number;
|
|
87
|
+
leaseMs?: number;
|
|
88
|
+
/**
|
|
89
|
+
* Take over even a live lease — but only one whose owner process is
|
|
90
|
+
* provably dead ({@link remoteSessionClaimOwnerIsDead}); a live or unknown
|
|
91
|
+
* owner is still `in_progress`. Used by the startup recovery pass.
|
|
92
|
+
*/
|
|
93
|
+
force?: boolean;
|
|
94
|
+
/**
|
|
95
|
+
* The digest a node before the actor-bound hash would have stored for this
|
|
96
|
+
* delivery (payload only, no principal). A claim bearing it was written by
|
|
97
|
+
* that version: `completed` answers a replay (no side effect), `processing`
|
|
98
|
+
* is taken over and re-bound to `payloadHash`/`payload` — the caller has
|
|
99
|
+
* already verified the principal of the delivery it is re-running.
|
|
100
|
+
*/
|
|
101
|
+
legacyPayloadHash?: string;
|
|
102
|
+
}): RemoteSessionInboxClaimResult;
|
|
103
|
+
/** {@link claimRemoteSessionInboxOwned} without the token (inspection and tests). */
|
|
104
|
+
export declare function claimRemoteSessionInbox(args: Parameters<typeof claimRemoteSessionInboxOwned>[0]): RemoteSessionInboxClaimOutcome;
|
|
105
|
+
/**
|
|
106
|
+
* The delivery is durably recorded: replays may now be acknowledged.
|
|
107
|
+
* Compare-and-set on (requestId, `processing`, owner token — and the payload
|
|
108
|
+
* digest when given): `false` means
|
|
109
|
+
* the caller no longer owns the claim (taken over, completed or released by
|
|
110
|
+
* someone else) and must not record anything — run it inside the recording
|
|
111
|
+
* transaction and abort that transaction on `false`.
|
|
112
|
+
*/
|
|
113
|
+
export declare function completeRemoteSessionInboxClaim(requestId: string, owner: string, now?: number, expected?: {
|
|
114
|
+
payloadHash?: string;
|
|
115
|
+
}): boolean;
|
|
116
|
+
export declare function getRemoteSessionInboxClaim(requestId: string): RemoteSessionInboxClaimRecord | null;
|
|
117
|
+
/** `processing` claims whose lease ran out: deliveries a dead process left behind. */
|
|
118
|
+
export declare function listExpiredRemoteSessionInboxClaims(now?: number, options?: {
|
|
119
|
+
includeLive?: boolean;
|
|
120
|
+
}): RemoteSessionInboxClaimRecord[];
|
|
121
|
+
/**
|
|
122
|
+
* Hand a `processing` claim back so the hub's retry runs the delivery again.
|
|
123
|
+
*
|
|
124
|
+
* A compare-and-delete on (requestId, `processing`, owner token, payload
|
|
125
|
+
* digest and — when given — the exact lease): only the claim instance the
|
|
126
|
+
* caller holds — or, for recovery, exactly the one it read — is deleted. A claim that was meanwhile completed, or taken over by
|
|
127
|
+
* another holder (even with the same payload digest, even in another
|
|
128
|
+
* process), carries a different state or token and is never deleted: losing
|
|
129
|
+
* it would turn the hub's next retry into a 404 (an ask-reply whose answer
|
|
130
|
+
* already landed) or a second enqueue (tell/ask/abort).
|
|
131
|
+
*/
|
|
132
|
+
export declare function releaseRemoteSessionInboxClaim(requestId: string, expected: {
|
|
133
|
+
owner: string | null;
|
|
134
|
+
payloadHash: string;
|
|
135
|
+
leaseUntil?: number;
|
|
136
|
+
}): boolean;
|
|
137
|
+
export declare function purgeRemoteSessionInboxClaims(now?: number): number;
|
|
138
|
+
export interface RemoteSessionAskRecord {
|
|
139
|
+
requestId: string;
|
|
140
|
+
callerTopicId: string;
|
|
141
|
+
userId: string;
|
|
142
|
+
fromKey: string;
|
|
143
|
+
toKey: string;
|
|
144
|
+
callerThreadRootId?: string;
|
|
145
|
+
createdAt: number;
|
|
146
|
+
/** Where the outbound ask stands; see {@link RemoteSessionAskDispatchState}. */
|
|
147
|
+
dispatchState?: RemoteSessionAskDispatchState;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* One state machine for the outbound hub ask: the durable row *and* the
|
|
151
|
+
* caller's pending marker (a file) it may hold. Invariant: the row is never
|
|
152
|
+
* deleted while its marker may still exist — the marker is released first
|
|
153
|
+
* (requestId-scoped, idempotent: {@link releasePendingAsk}) and the row goes
|
|
154
|
+
* only once that succeeded, so a marker is always findable through its row.
|
|
155
|
+
*
|
|
156
|
+
* - `prepared`: row written, marker maybe; the hub has certainly not been called.
|
|
157
|
+
* - `dispatched`: the hub call is in flight (or its process died during it, or
|
|
158
|
+
* it ended "uncertain"); the hub may hold the ask. Row + marker.
|
|
159
|
+
* - `sent`: the hub acknowledged the ask. Row + marker until the reply lands
|
|
160
|
+
* (the reply path consumes both) or the TTL passes.
|
|
161
|
+
* - `abandoned`: no reply can come (the hub refused, or registration failed)
|
|
162
|
+
* but the marker could not be released yet; reconciliation retries.
|
|
163
|
+
* - `unknown`: a `dispatched` ask whose outcome nobody will learn (the hub
|
|
164
|
+
* call's grant is per-turn, so neither an idempotent resend nor a hub status
|
|
165
|
+
* query is possible after the fact). Marker released so the room can ask
|
|
166
|
+
* again; row kept so a late reply is still routed; at the TTL the caller is
|
|
167
|
+
* told no reply arrived.
|
|
168
|
+
* - `expired`: an `unknown` ask whose "no reply arrived" notice is being
|
|
169
|
+
* delivered; invisible to the reply path, removed with the notice's record.
|
|
170
|
+
*
|
|
171
|
+
* prepared ─marker─▶ dispatched ─hub ok─▶ sent ─reply/TTL─▶ ∅
|
|
172
|
+
* │ │ └─hub refused─▶ abandoned ─release─▶ ∅
|
|
173
|
+
* └─fail/grace─▶ release ─▶ ∅ (or abandoned)
|
|
174
|
+
* └─crash/uncertain + grace ─release─▶ unknown ─reply─▶ ∅
|
|
175
|
+
* └─TTL─▶ expired ─notice─▶ ∅
|
|
176
|
+
*/
|
|
177
|
+
export type RemoteSessionAskDispatchState = "prepared" | "dispatched" | "sent" | "abandoned" | "unknown" | "expired";
|
|
178
|
+
/**
|
|
179
|
+
* A `prepared` row older than this belongs to a process that died between
|
|
180
|
+
* writing it and calling the hub: prepare → marker → dispatched is
|
|
181
|
+
* synchronous, so a live one is never this old.
|
|
182
|
+
*/
|
|
183
|
+
export declare const REMOTE_SESSION_ASK_PREPARE_GRACE_MS = 60000;
|
|
184
|
+
/**
|
|
185
|
+
* A `dispatched` row older than this is not waiting on a live hub call: one
|
|
186
|
+
* `hubRemoteAsk` is bounded by 3 attempts × 15 s (+ backoff), so the caller
|
|
187
|
+
* has long since either confirmed it (`sent`) or given up on knowing.
|
|
188
|
+
*/
|
|
189
|
+
export declare const REMOTE_SESSION_ASK_DISPATCH_GRACE_MS: number;
|
|
190
|
+
/** Remember an outbound remote ask before the hub is asked to forward it. */
|
|
191
|
+
export declare function recordRemoteSessionAsk(args: Omit<RemoteSessionAskRecord, "createdAt" | "dispatchState"> & {
|
|
192
|
+
createdAt?: number;
|
|
193
|
+
/** Defaults to `sent` (an ask the hub holds); the hub-ask path passes `prepared`. */
|
|
194
|
+
dispatchState?: RemoteSessionAskDispatchState;
|
|
195
|
+
}): void;
|
|
196
|
+
/** The hub call is about to be made: from now on the hub may hold the ask. */
|
|
197
|
+
export declare function markRemoteSessionAskDispatched(requestId: string): boolean;
|
|
198
|
+
/**
|
|
199
|
+
* The hub acknowledged the ask. Best effort: a row left `dispatched` (this
|
|
200
|
+
* write failed, or the reply already consumed the row) is still correct —
|
|
201
|
+
* reconciliation merely treats it as `unknown` after the grace.
|
|
202
|
+
*/
|
|
203
|
+
export declare function markRemoteSessionAskSent(requestId: string): boolean;
|
|
204
|
+
/**
|
|
205
|
+
* Register an outbound hub ask: durable caller row (`prepared`), then the
|
|
206
|
+
* caller's pending marker, then `dispatched` — only after this returns `ok`
|
|
207
|
+
* may the hub be called. A failure retires what was written without ever
|
|
208
|
+
* orphaning the marker: the row is deleted only after `releaseMarker`
|
|
209
|
+
* confirmed the marker is gone, else it stays (`abandoned`/`prepared`) for
|
|
210
|
+
* {@link reconcileRemoteSessionAsks}. `pending` means another ask to that
|
|
211
|
+
* room is outstanding (its marker is not ours and is never touched).
|
|
212
|
+
*/
|
|
213
|
+
export declare function beginRemoteSessionAsk(args: Omit<RemoteSessionAskRecord, "createdAt" | "dispatchState"> & {
|
|
214
|
+
createMarker: () => boolean;
|
|
215
|
+
/** RequestId-scoped, idempotent: `true` once no marker of this ask remains. */
|
|
216
|
+
releaseMarker: () => boolean;
|
|
217
|
+
}): "ok" | "pending";
|
|
218
|
+
/**
|
|
219
|
+
* The hub definitively refused a `dispatched` ask (nothing was forwarded):
|
|
220
|
+
* release the marker, then drop the row — or keep it `abandoned` until the
|
|
221
|
+
* release succeeds.
|
|
222
|
+
*/
|
|
223
|
+
export declare function abandonRemoteSessionAsk(requestId: string, releaseMarker: () => boolean): void;
|
|
224
|
+
/**
|
|
225
|
+
* Durable recovery of the outbound-ask state machine; runs in the
|
|
226
|
+
* maintenance pass (at startup and then periodically). Idempotent.
|
|
227
|
+
*
|
|
228
|
+
* - `abandoned` (any age) and `prepared` past {@link REMOTE_SESSION_ASK_PREPARE_GRACE_MS}
|
|
229
|
+
* (the hub was never called): release the marker, then drop the row.
|
|
230
|
+
* - `dispatched` past {@link REMOTE_SESSION_ASK_DISPATCH_GRACE_MS} (the
|
|
231
|
+
* process died around the hub call, or the call ended uncertain): release
|
|
232
|
+
* the marker so the room can ask again, then mark the row `unknown`.
|
|
233
|
+
*
|
|
234
|
+
* A failed release leaves the row as it was, so the next pass retries; past
|
|
235
|
+
* the ask TTL the marker is stale (it no longer blocks a new ask and is
|
|
236
|
+
* swept on read), so the row moves on regardless.
|
|
237
|
+
*/
|
|
238
|
+
export declare function reconcileRemoteSessionAsks(now?: number, opts?: {
|
|
239
|
+
prepareGraceMs?: number;
|
|
240
|
+
dispatchGraceMs?: number;
|
|
241
|
+
}): {
|
|
242
|
+
removed: number;
|
|
243
|
+
unknown: number;
|
|
244
|
+
};
|
|
245
|
+
/**
|
|
246
|
+
* Asks whose caller must now be told that no reply arrived: `unknown` past
|
|
247
|
+
* the ask TTL, and `expired` ones whose notice did not land yet.
|
|
248
|
+
*/
|
|
249
|
+
export declare function listRemoteSessionAsksToExpire(now?: number): RemoteSessionAskRecord[];
|
|
250
|
+
/**
|
|
251
|
+
* `unknown` → `expired`, unless a late reply is being delivered right now
|
|
252
|
+
* (it holds an inbox claim for the same requestId): that reply wins.
|
|
253
|
+
* From here on the reply path no longer sees the row.
|
|
254
|
+
*/
|
|
255
|
+
export declare function markRemoteSessionAskExpired(requestId: string): boolean;
|
|
256
|
+
/** The "no reply arrived" notice is durable: the `expired` row goes with it. */
|
|
257
|
+
export declare function deleteExpiredRemoteSessionAsk(requestId: string): boolean;
|
|
258
|
+
/** The ask a reply may still answer (an `expired` one no longer can). */
|
|
259
|
+
export declare function getRemoteSessionAsk(requestId: string): RemoteSessionAskRecord | null;
|
|
260
|
+
export declare function deleteRemoteSessionAsk(requestId: string): boolean;
|
|
261
|
+
/** Consume the caller record exactly once: the row is gone after this returns it. */
|
|
262
|
+
export declare function takeRemoteSessionAsk(requestId: string): RemoteSessionAskRecord | null;
|
|
263
|
+
export declare function deleteRemoteSessionAsksForTopic(callerTopicId: string): number;
|
|
264
|
+
/**
|
|
265
|
+
* Forget asks past the TTL. Only states whose marker is settled go at the TTL
|
|
266
|
+
* (`sent`: the marker is stale by then); the others are walked through
|
|
267
|
+
* {@link reconcileRemoteSessionAsks} and the expiry notice first. Anything
|
|
268
|
+
* still here at twice the TTL is dropped unconditionally (a caller room that
|
|
269
|
+
* can no longer take the notice must not pin the row forever).
|
|
270
|
+
*/
|
|
271
|
+
export declare function purgeStaleRemoteSessionAsks(now?: number): number;
|
|
272
|
+
export interface RemoteSessionReplyOutboxEntry {
|
|
273
|
+
requestId: string;
|
|
274
|
+
hubUrl: string;
|
|
275
|
+
token: string;
|
|
276
|
+
kind: "reply" | "error";
|
|
277
|
+
replyText: string;
|
|
278
|
+
fromLabel: string;
|
|
279
|
+
createdAt: number;
|
|
280
|
+
attempts: number;
|
|
281
|
+
nextAttemptAt: number;
|
|
282
|
+
lastError?: string;
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* Queue an answer for the hub. One row per ask: a second answer for the same
|
|
286
|
+
* request (a retry after a partial failure) replaces the first, which is what
|
|
287
|
+
* the hub's one-shot reply token would enforce anyway.
|
|
288
|
+
*/
|
|
289
|
+
export declare function upsertRemoteSessionReplyOutbox(args: {
|
|
290
|
+
requestId: string;
|
|
291
|
+
hubUrl: string;
|
|
292
|
+
token: string;
|
|
293
|
+
kind: "reply" | "error";
|
|
294
|
+
replyText: string;
|
|
295
|
+
fromLabel: string;
|
|
296
|
+
createdAt?: number;
|
|
297
|
+
}): void;
|
|
298
|
+
export declare function listRemoteSessionReplyOutbox(args?: {
|
|
299
|
+
now?: number;
|
|
300
|
+
limit?: number;
|
|
301
|
+
due?: boolean;
|
|
302
|
+
}): RemoteSessionReplyOutboxEntry[];
|
|
303
|
+
export declare function deleteRemoteSessionReplyOutbox(requestId: string): boolean;
|
|
304
|
+
/**
|
|
305
|
+
* Record a failed attempt and schedule the next one on the backoff ladder
|
|
306
|
+
* (5, 10, 20, 30 s cap, jittered) — the immediate first attempt is
|
|
307
|
+
* `attempts = 0`, so the first deferral waits ≈5 s. `retryMs` pins the delay.
|
|
308
|
+
*/
|
|
309
|
+
export declare function deferRemoteSessionReplyOutbox(args: {
|
|
310
|
+
requestId: string;
|
|
311
|
+
error: string;
|
|
312
|
+
now?: number;
|
|
313
|
+
retryMs?: number;
|
|
314
|
+
random?: () => number;
|
|
315
|
+
}): void;
|
|
316
|
+
/** Drop answers nobody is waiting for any more. Returns what was dropped, for the log. */
|
|
317
|
+
export declare function purgeExpiredRemoteSessionReplyOutbox(now?: number): RemoteSessionReplyOutboxEntry[];
|
|
318
|
+
export {};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export declare const RUNTIME_EVENT_TYPES: readonly ["message", "message-updated", "ai-status", "topic-created", "topic-updated", "topic-deleted"];
|
|
2
|
+
export type StoredRuntimeEventType = (typeof RUNTIME_EVENT_TYPES)[number];
|
|
3
|
+
export interface StoredRuntimeEvent {
|
|
4
|
+
seq: number;
|
|
5
|
+
sourceId: string;
|
|
6
|
+
type: StoredRuntimeEventType;
|
|
7
|
+
topicId: string;
|
|
8
|
+
payload: unknown;
|
|
9
|
+
createdAt: string;
|
|
10
|
+
}
|
|
11
|
+
export declare function latestRuntimeEventSeq(): number;
|
|
12
|
+
export declare function earliestRuntimeEventSeq(): number;
|
|
13
|
+
export declare function appendRuntimeEvent(sourceId: string, event: {
|
|
14
|
+
type: StoredRuntimeEventType;
|
|
15
|
+
topicId: string;
|
|
16
|
+
payload: unknown;
|
|
17
|
+
}): StoredRuntimeEvent;
|
|
18
|
+
export declare function listRuntimeEventsAfter(seq: number, limit?: number): StoredRuntimeEvent[];
|
|
19
|
+
export declare function heartbeatRuntimeEventConsumer(consumerId: string, cursor: number, now?: number): void;
|
|
20
|
+
export interface RuntimeEventPruneOptions {
|
|
21
|
+
maxEvents?: number;
|
|
22
|
+
activeConsumerMaxAgeMs?: number;
|
|
23
|
+
now?: number;
|
|
24
|
+
}
|
|
25
|
+
export interface RuntimeEventPruneResult {
|
|
26
|
+
deleted: number;
|
|
27
|
+
cutoff: number;
|
|
28
|
+
retainedForConsumer: number | null;
|
|
29
|
+
}
|
|
30
|
+
/** Keep a soft event-count bound without deleting rows an active durable consumer has not captured. */
|
|
31
|
+
export declare function pruneRuntimeEvents(options?: RuntimeEventPruneOptions): RuntimeEventPruneResult;
|
|
32
|
+
/** Recent topic history used to hydrate a newly opened channel surface. */
|
|
33
|
+
export declare function listRecentRuntimeEventsForTopic(topicId: string, limit?: number): StoredRuntimeEvent[];
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export declare const RUNTIME_INSTANCE_ID: string;
|
|
2
|
+
export declare const TURN_LEASE_STALE_MS = 10000;
|
|
3
|
+
export interface RuntimeTurnLease {
|
|
4
|
+
topicId: string;
|
|
5
|
+
queryId: string;
|
|
6
|
+
ownerId: string;
|
|
7
|
+
origin: string;
|
|
8
|
+
startedAt: number;
|
|
9
|
+
heartbeatAt: number;
|
|
10
|
+
abortRequested: boolean;
|
|
11
|
+
abortReason?: "internal" | "external";
|
|
12
|
+
}
|
|
13
|
+
export declare function getRuntimeTurnLease(topicId: string, now?: number): RuntimeTurnLease | null;
|
|
14
|
+
export declare function listRuntimeTurnLeases(now?: number): RuntimeTurnLease[];
|
|
15
|
+
export declare function claimRuntimeTurnLease(input: {
|
|
16
|
+
topicId: string;
|
|
17
|
+
queryId: string;
|
|
18
|
+
origin: string;
|
|
19
|
+
ownerId?: string;
|
|
20
|
+
}, now?: number): boolean;
|
|
21
|
+
export declare function heartbeatRuntimeTurnLease(topicId: string, queryId: string, ownerId?: string, now?: number): {
|
|
22
|
+
owned: boolean;
|
|
23
|
+
abortRequested: boolean;
|
|
24
|
+
abortReason?: "internal" | "external";
|
|
25
|
+
};
|
|
26
|
+
export declare function requestRuntimeTurnAbort(topicId: string, reason: "internal" | "external"): boolean;
|
|
27
|
+
export declare function releaseRuntimeTurnLease(topicId: string, queryId: string, ownerId?: string): boolean;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
export declare const PROCESS_LEASE_STALE_MS = 5000;
|
|
2
|
+
export declare const PROCESS_LEASE_HEARTBEAT_MS = 1000;
|
|
3
|
+
export interface RuntimeProcessLease {
|
|
4
|
+
role: string;
|
|
5
|
+
ownerId: string;
|
|
6
|
+
pid: number;
|
|
7
|
+
startedAt: number;
|
|
8
|
+
heartbeatAt: number;
|
|
9
|
+
}
|
|
10
|
+
export interface RuntimeProcessLeaseHandle extends RuntimeProcessLease {
|
|
11
|
+
stop(): void;
|
|
12
|
+
}
|
|
13
|
+
export interface AcquireRuntimeProcessLeaseOptions {
|
|
14
|
+
ownerId?: string;
|
|
15
|
+
pid?: number;
|
|
16
|
+
now?: number;
|
|
17
|
+
staleMs?: number;
|
|
18
|
+
heartbeatMs?: number;
|
|
19
|
+
onLost?: () => void;
|
|
20
|
+
}
|
|
21
|
+
export interface WaitForRuntimeProcessLeaseOptions extends AcquireRuntimeProcessLeaseOptions {
|
|
22
|
+
waitMs?: number;
|
|
23
|
+
retryMs?: number;
|
|
24
|
+
}
|
|
25
|
+
export interface WaitForRequiredRuntimeProcessLeaseOptions extends WaitForRuntimeProcessLeaseOptions {
|
|
26
|
+
workloadName?: string;
|
|
27
|
+
}
|
|
28
|
+
export declare function isRuntimeProcessLeaseAlive(lease: RuntimeProcessLease): boolean;
|
|
29
|
+
export declare function getRuntimeProcessLease(role: string, now?: number, staleMs?: number): RuntimeProcessLease | null;
|
|
30
|
+
/** List healthy process leases, optionally restricted to one role prefix. */
|
|
31
|
+
export declare function listRuntimeProcessLeases(rolePrefix?: string, now?: number, staleMs?: number): RuntimeProcessLease[];
|
|
32
|
+
/** Remove crash leftovers without evicting a live process whose heartbeat is delayed. */
|
|
33
|
+
export declare function removeDeadRuntimeProcessLeases(rolePrefix?: string): number;
|
|
34
|
+
export declare function heartbeatRuntimeProcessLease(role: string, ownerId: string, now?: number): boolean;
|
|
35
|
+
export declare function releaseRuntimeProcessLease(role: string, ownerId: string): boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Claim one cross-process role and keep it alive with a SQLite heartbeat.
|
|
38
|
+
* A process that exits without cleanup is replaceable after `staleMs`.
|
|
39
|
+
*/
|
|
40
|
+
export declare function acquireRuntimeProcessLease(role: string, options?: AcquireRuntimeProcessLeaseOptions): RuntimeProcessLeaseHandle | null;
|
|
41
|
+
/**
|
|
42
|
+
* Wait through a graceful handoff or stale-heartbeat window instead of making
|
|
43
|
+
* process supervisors burn through their restart budget on a transient clash.
|
|
44
|
+
*/
|
|
45
|
+
export declare function waitForRuntimeProcessLease(role: string, options?: WaitForRuntimeProcessLeaseOptions): Promise<RuntimeProcessLeaseHandle | null>;
|
|
46
|
+
/** Claim a process role or report the live owner in a user-facing error. */
|
|
47
|
+
export declare function waitForRequiredRuntimeProcessLease(role: string, options?: WaitForRequiredRuntimeProcessLeaseOptions): Promise<RuntimeProcessLeaseHandle>;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export declare const TOPIC_MAINTENANCE_STALE_MS = 30000;
|
|
2
|
+
export declare const TOPIC_MAINTENANCE_HEARTBEAT_MS = 1000;
|
|
3
|
+
export interface RuntimeTopicState {
|
|
4
|
+
topicId: string;
|
|
5
|
+
epoch: number;
|
|
6
|
+
maintenance: boolean;
|
|
7
|
+
maintenanceOwner?: string;
|
|
8
|
+
heartbeatAt?: number;
|
|
9
|
+
}
|
|
10
|
+
export interface RuntimeTopicMaintenanceHandle {
|
|
11
|
+
topicId: string;
|
|
12
|
+
epoch: number;
|
|
13
|
+
ownerId: string;
|
|
14
|
+
isOwned(): boolean;
|
|
15
|
+
finish(options?: {
|
|
16
|
+
deleteState?: boolean;
|
|
17
|
+
}): void;
|
|
18
|
+
}
|
|
19
|
+
type MaintenanceReleasedListener = (topicId: string) => void;
|
|
20
|
+
/**
|
|
21
|
+
* Observe maintenance fences released by THIS process (`finish()`). Listeners
|
|
22
|
+
* run synchronously after the release and must not throw into the caller;
|
|
23
|
+
* anything that writes should defer itself out of the caller's transaction.
|
|
24
|
+
* Releases in other processes are not observed — pair with a timer.
|
|
25
|
+
*/
|
|
26
|
+
export declare function onRuntimeTopicMaintenanceReleased(listener: MaintenanceReleasedListener): () => void;
|
|
27
|
+
export declare function getRuntimeTopicState(topicId: string, now?: number): RuntimeTopicState;
|
|
28
|
+
export declare function getRuntimeTopicEpoch(topicId: string): number;
|
|
29
|
+
export declare function isRuntimeTopicMaintenance(topicId: string, now?: number): boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Advance the topic execution epoch and hold an exclusive maintenance fence.
|
|
32
|
+
* Turns from an older epoch can be identified and discarded in every process.
|
|
33
|
+
*/
|
|
34
|
+
export declare function beginRuntimeTopicMaintenance(topicId: string, options?: {
|
|
35
|
+
ownerId?: string;
|
|
36
|
+
now?: number;
|
|
37
|
+
heartbeatMs?: number;
|
|
38
|
+
}): RuntimeTopicMaintenanceHandle | null;
|
|
39
|
+
export {};
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { type UserTurnEnvelope } from "../runtime/user-turn-envelope";
|
|
2
|
+
import type { StorageDatabase } from "./storage-contract";
|
|
3
|
+
import type { ActorTopicScope, AgentKind, EffortLevel, PeerRuntimeBridgeContext, RemoteSessionGrant } from "../types";
|
|
4
|
+
/** Serializable execution details that must survive a cross-process handoff. */
|
|
5
|
+
export interface RuntimeUserTurnExecution {
|
|
6
|
+
runtimeEpoch?: number;
|
|
7
|
+
sourceRequestId?: string;
|
|
8
|
+
agentOverride?: AgentKind;
|
|
9
|
+
modelOverride?: string;
|
|
10
|
+
effortOverride?: EffortLevel;
|
|
11
|
+
sessionId?: string | null;
|
|
12
|
+
sessionIdSpecified?: boolean;
|
|
13
|
+
sessionScope?: "topic" | "isolated";
|
|
14
|
+
cwd?: string;
|
|
15
|
+
sessionName?: string;
|
|
16
|
+
sessionType?: "dm" | "forum" | "ephemeral" | "manager" | "cron";
|
|
17
|
+
visualTools?: boolean;
|
|
18
|
+
fileDeliveryTools?: boolean;
|
|
19
|
+
silent?: boolean;
|
|
20
|
+
bridgeSessionFromHistory?: boolean;
|
|
21
|
+
peerBridge?: PeerRuntimeBridgeContext;
|
|
22
|
+
from?: string;
|
|
23
|
+
/** Vault namespace for this turn, independent from the local execution principal. */
|
|
24
|
+
vaultUserId?: string;
|
|
25
|
+
/** Product actor identity, independent from the canonical execution principal. */
|
|
26
|
+
actorUserId?: string;
|
|
27
|
+
/** Host-asserted rooms the actor may reach; kept with the row so retries keep it. */
|
|
28
|
+
actorTopicScope?: ActorTopicScope;
|
|
29
|
+
/** Hub-issued per-turn remote session-comm grant; kept with the row like the assertion. */
|
|
30
|
+
remoteSession?: RemoteSessionGrant;
|
|
31
|
+
/** Newly accepted user texts not yet recorded in the unified conversation log. */
|
|
32
|
+
conversationPrompts?: string[];
|
|
33
|
+
/** Number of leading userMessages already present in the unified conversation log. */
|
|
34
|
+
loggedUserMessageCount?: number;
|
|
35
|
+
/** Native session whose provider output proves it accepted this request's user turn. */
|
|
36
|
+
providerSessionId?: string;
|
|
37
|
+
/** Request ids whose ordered messages were folded into this replacement. */
|
|
38
|
+
supersededRequestIds?: string[];
|
|
39
|
+
/**
|
|
40
|
+
* Slack-style thread this turn belongs to, when it was asked in one. Carried
|
|
41
|
+
* on the request rather than the message because it decides both where the
|
|
42
|
+
* answer goes and which pending requests may merge with it (S-13).
|
|
43
|
+
*/
|
|
44
|
+
threadRootId?: string;
|
|
45
|
+
}
|
|
46
|
+
export interface RuntimeUserTurnRequest {
|
|
47
|
+
requestId: string;
|
|
48
|
+
topicId: string;
|
|
49
|
+
userId: string;
|
|
50
|
+
prompt: string;
|
|
51
|
+
userMessages: UserTurnEnvelope[];
|
|
52
|
+
attachments?: string[];
|
|
53
|
+
allowAutoContinue: boolean;
|
|
54
|
+
execution?: RuntimeUserTurnExecution;
|
|
55
|
+
topicEpoch: number;
|
|
56
|
+
createdAt: number;
|
|
57
|
+
status: "pending" | "running";
|
|
58
|
+
claimedBy?: string;
|
|
59
|
+
claimedAt?: number;
|
|
60
|
+
runningQueryId?: string;
|
|
61
|
+
}
|
|
62
|
+
/** Apply additive upgrades and the legacy topic-primary-key rebuild to one database. */
|
|
63
|
+
export declare function ensureRuntimeUserTurnRequestsSchema(database: StorageDatabase): void;
|
|
64
|
+
export declare function enqueueRuntimeUserTurnRequest(input: {
|
|
65
|
+
topicId: string;
|
|
66
|
+
userId: string;
|
|
67
|
+
prompt: string;
|
|
68
|
+
userMessages?: UserTurnEnvelope[];
|
|
69
|
+
attachments?: string[];
|
|
70
|
+
allowAutoContinue: boolean;
|
|
71
|
+
requestId?: string;
|
|
72
|
+
execution?: RuntimeUserTurnExecution;
|
|
73
|
+
topicEpoch?: number;
|
|
74
|
+
/** Existing channel behavior supersedes queued work; gateways opt into FIFO. */
|
|
75
|
+
supersedeExisting?: boolean;
|
|
76
|
+
}): string;
|
|
77
|
+
/**
|
|
78
|
+
* Atomically fold every accepted request for a topic into one replacement.
|
|
79
|
+
* BEGIN IMMEDIATE serializes cross-process readers before they observe and
|
|
80
|
+
* replace the current rows, preventing the classic read/merge/delete race.
|
|
81
|
+
*/
|
|
82
|
+
export declare function mergeRuntimeUserTurnRequest(input: {
|
|
83
|
+
topicId: string;
|
|
84
|
+
userId: string;
|
|
85
|
+
userMessages: UserTurnEnvelope[];
|
|
86
|
+
allowAutoContinue: boolean;
|
|
87
|
+
requestId: string;
|
|
88
|
+
execution: RuntimeUserTurnExecution;
|
|
89
|
+
topicEpoch: number;
|
|
90
|
+
alreadyIncludedRequestIds?: string[];
|
|
91
|
+
/** Requests already committed to the provider's native session; keep their lineage, not prompts. */
|
|
92
|
+
omitRequestIds?: string[];
|
|
93
|
+
/**
|
|
94
|
+
* Requests that must stay standing and never be folded into this one, even
|
|
95
|
+
* for the same actor and thread. Used to queue a message behind the turn a
|
|
96
|
+
* worker is running instead of steering (aborting and replacing) it.
|
|
97
|
+
*/
|
|
98
|
+
keepRequestIds?: string[];
|
|
99
|
+
}): {
|
|
100
|
+
requestId: string;
|
|
101
|
+
supersededRequestIds: string[];
|
|
102
|
+
};
|
|
103
|
+
/**
|
|
104
|
+
* Record that provider output proves the native session contains this durable
|
|
105
|
+
* turn. A session-id event alone is insufficient: some providers publish it
|
|
106
|
+
* before appending the user prompt. This marker lets a different runtime
|
|
107
|
+
* process omit only a demonstrably committed prompt when it merges a steering
|
|
108
|
+
* message after preemption.
|
|
109
|
+
*
|
|
110
|
+
* Match only the exact request id. A late session event from a superseded turn
|
|
111
|
+
* must not mark its replacement (whose prompts have not reached the provider).
|
|
112
|
+
*/
|
|
113
|
+
export declare function markRuntimeUserTurnProviderSessionObserved(topicId: string, requestId: string, sessionId: string): boolean;
|
|
114
|
+
export declare function markRuntimeUserTurnMessagesLogged(topicId: string, requestId: string, ownerId: string, loggedUserMessages: readonly UserTurnEnvelope[]): boolean;
|
|
115
|
+
export declare function claimNextRuntimeUserTurnRequest(ownerId: string, now?: number): RuntimeUserTurnRequest | null;
|
|
116
|
+
export declare function markRuntimeUserTurnRunning(topicId: string, requestId: string, ownerId: string, queryId: string): boolean;
|
|
117
|
+
export declare function releaseRuntimeUserTurnClaim(topicId: string, requestId: string, ownerId: string): boolean;
|
|
118
|
+
export declare function completeRuntimeUserTurnRequest(topicId: string, requestId: string, ownerId: string): boolean;
|
|
119
|
+
/** Cancel work captured before a reset/delete epoch began. */
|
|
120
|
+
export declare function cancelRuntimeUserTurnRequestsBeforeEpoch(topicId: string, epoch: number): string[];
|
|
121
|
+
export declare function cancelRuntimeUserTurnRequests(topicId: string): string[];
|
|
122
|
+
/**
|
|
123
|
+
* The request a worker currently holds for `topicId` — claimed or already
|
|
124
|
+
* running — if any. This is the turn a new human message could steer; whether
|
|
125
|
+
* it may is decided by whoever folds the new message (see
|
|
126
|
+
* `submitRuntimeGatewayTurn`).
|
|
127
|
+
*/
|
|
128
|
+
export declare function getActiveRuntimeUserTurnRequest(topicId: string): RuntimeUserTurnRequest | null;
|
|
129
|
+
/**
|
|
130
|
+
* Fold the messages queued behind a running turn into it, so a steer can run
|
|
131
|
+
* them now. Same replacement `mergeRuntimeUserTurnRequest` makes for a steering
|
|
132
|
+
* message, but with no new message: the running request and the queued tail it
|
|
133
|
+
* shares an actor and thread with become one pending batch. Returns the
|
|
134
|
+
* absorbed running request's id, or null when there is nothing to fold (no
|
|
135
|
+
* running turn, nothing queued, or the queue belongs to someone else).
|
|
136
|
+
*/
|
|
137
|
+
export declare function foldQueuedIntoActiveRuntimeUserTurnRequest(topicId: string, newRequestId: string): string | null;
|
|
138
|
+
export declare function getRuntimeUserTurnRequest(topicId: string): RuntimeUserTurnRequest | null;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
export type SelfScheduleStatus = "pending" | "running";
|
|
2
|
+
export interface SelfSchedule {
|
|
3
|
+
id: string;
|
|
4
|
+
topicId: string;
|
|
5
|
+
userId: string;
|
|
6
|
+
message: string;
|
|
7
|
+
deliverAt: number;
|
|
8
|
+
createdAt: number;
|
|
9
|
+
updatedAt: number;
|
|
10
|
+
status: SelfScheduleStatus;
|
|
11
|
+
claimedBy?: string;
|
|
12
|
+
claimedAt?: number;
|
|
13
|
+
runningQueryId?: string;
|
|
14
|
+
}
|
|
15
|
+
export type CreatePendingSelfScheduleResult = {
|
|
16
|
+
ok: true;
|
|
17
|
+
schedule: SelfSchedule;
|
|
18
|
+
} | {
|
|
19
|
+
ok: false;
|
|
20
|
+
existing: SelfSchedule;
|
|
21
|
+
};
|
|
22
|
+
/** Create the topic's sole pending self-schedule without replacing an existing one. */
|
|
23
|
+
export declare function createPendingSelfSchedule(input: {
|
|
24
|
+
topicId: string;
|
|
25
|
+
userId: string;
|
|
26
|
+
message: string;
|
|
27
|
+
deliverAt: number;
|
|
28
|
+
now?: number;
|
|
29
|
+
}): CreatePendingSelfScheduleResult;
|
|
30
|
+
export declare function getPendingSelfSchedule(topicId: string): SelfSchedule | null;
|
|
31
|
+
export declare function updatePendingSelfSchedule(input: {
|
|
32
|
+
topicId: string;
|
|
33
|
+
scheduleId: string;
|
|
34
|
+
message?: string;
|
|
35
|
+
deliverAt?: number;
|
|
36
|
+
now?: number;
|
|
37
|
+
}): SelfSchedule | null;
|
|
38
|
+
export declare function cancelPendingSelfSchedule(topicId: string, scheduleId: string): boolean;
|
|
39
|
+
/**
|
|
40
|
+
* Claim one due schedule whose topic is idle. A stale running row is retryable
|
|
41
|
+
* after its process and topic lease disappear, preserving work across crashes.
|
|
42
|
+
*/
|
|
43
|
+
export declare function claimNextDueSelfSchedule(ownerId: string, now?: number): SelfSchedule | null;
|
|
44
|
+
export declare function markSelfScheduleRunning(scheduleId: string, ownerId: string, queryId: string): boolean;
|
|
45
|
+
export declare function heartbeatSelfScheduleClaim(scheduleId: string, ownerId: string, now?: number): boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Put an interrupted run back into the single pending slot. If its own turn
|
|
48
|
+
* already created a newer pending schedule, the newer explicit schedule wins.
|
|
49
|
+
*/
|
|
50
|
+
export declare function releaseSelfScheduleClaim(scheduleId: string, ownerId: string): "released" | "dropped";
|
|
51
|
+
export declare function completeSelfSchedule(scheduleId: string, ownerId?: string): boolean;
|
|
52
|
+
export declare function deleteSelfSchedulesForTopic(topicId: string): number;
|
|
53
|
+
/** Test/diagnostic helper covering pending and in-flight rows. */
|
|
54
|
+
export declare function listSelfSchedulesForTopic(topicId: string): SelfSchedule[];
|