@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.
Files changed (572) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +329 -2
  3. package/bin/codex-sdk-window-hide.mjs +40 -0
  4. package/bin/negotium.mjs +22 -0
  5. package/dist/agent-helpers.js +23090 -0
  6. package/dist/agent-helpers.js.map +171 -0
  7. package/dist/background-bash.js +535 -0
  8. package/dist/background-bash.js.map +16 -0
  9. package/dist/browser-runtime.js +2334 -0
  10. package/dist/browser-runtime.js.map +35 -0
  11. package/dist/canonical-mcp-bridge.js +13 -0
  12. package/dist/canonical-mcp-bridge.js.map +9 -0
  13. package/dist/chunk-22kg3fsw.js +79 -0
  14. package/dist/chunk-22kg3fsw.js.map +9 -0
  15. package/dist/chunk-d4j77adx.js +336 -0
  16. package/dist/chunk-d4j77adx.js.map +13 -0
  17. package/dist/chunk-mk9x18jn.js +172 -0
  18. package/dist/chunk-mk9x18jn.js.map +12 -0
  19. package/dist/chunk-qd0vtfm2.js +3923 -0
  20. package/dist/chunk-qd0vtfm2.js.map +47 -0
  21. package/dist/chunk-wf7ny8eq.js +206 -0
  22. package/dist/chunk-wf7ny8eq.js.map +10 -0
  23. package/dist/chunk-ww8a4ej4.js +54 -0
  24. package/dist/chunk-ww8a4ej4.js.map +10 -0
  25. package/dist/cron.js +1 -0
  26. package/dist/hosted-agent.js +5982 -0
  27. package/dist/hosted-agent.js.map +62 -0
  28. package/dist/main.js +60229 -0
  29. package/dist/main.js.map +340 -0
  30. package/dist/mcp-catalog.js +39 -0
  31. package/dist/mcp-catalog.js.map +10 -0
  32. package/dist/mcp-factories.js +25767 -0
  33. package/dist/mcp-factories.js.map +181 -0
  34. package/dist/mcp-servers.js +50 -0
  35. package/dist/mcp-servers.js.map +10 -0
  36. package/dist/media.js +570 -0
  37. package/dist/media.js.map +15 -0
  38. package/dist/outbox.js +354 -0
  39. package/dist/outbox.js.map +15 -0
  40. package/dist/platform-runtime.js +73 -0
  41. package/dist/platform-runtime.js.map +12 -0
  42. package/dist/prompts.js +892 -0
  43. package/dist/prompts.js.map +15 -0
  44. package/dist/query-runtime.js +1071 -0
  45. package/dist/query-runtime.js.map +26 -0
  46. package/dist/registry.js +335 -0
  47. package/dist/registry.js.map +14 -0
  48. package/dist/rollout.js +57 -0
  49. package/dist/rollout.js.map +10 -0
  50. package/dist/runtime/cron/background-sessions.ts +119 -0
  51. package/dist/runtime/cron/context.ts +123 -0
  52. package/dist/runtime/cron/host.ts +67 -0
  53. package/dist/runtime/cron/index.ts +95 -0
  54. package/dist/runtime/cron/mcp-server.ts +556 -0
  55. package/dist/runtime/cron/module.ts +174 -0
  56. package/dist/runtime/cron/package.json +6 -0
  57. package/dist/runtime/cron/schedule.ts +211 -0
  58. package/dist/runtime/cron/scheduler.ts +444 -0
  59. package/dist/runtime/cron/scripts.ts +203 -0
  60. package/dist/runtime/cron/store.ts +1163 -0
  61. package/dist/runtime/cron/summarize.ts +115 -0
  62. package/dist/runtime/package.json +6 -0
  63. package/dist/runtime/scripts/faster-whisper-wrapper.py +87 -0
  64. package/dist/runtime/src/agents/api-topic-agent-switch.ts +179 -0
  65. package/dist/runtime/src/agents/archiver.ts +677 -0
  66. package/dist/runtime/src/agents/auth-check.ts +156 -0
  67. package/dist/runtime/src/agents/claude-notices.ts +130 -0
  68. package/dist/runtime/src/agents/claude-provider.ts +941 -0
  69. package/dist/runtime/src/agents/claude-registry.ts +117 -0
  70. package/dist/runtime/src/agents/claude-runtime-inspection.ts +43 -0
  71. package/dist/runtime/src/agents/codex-app-server.ts +138 -0
  72. package/dist/runtime/src/agents/codex-native-multi-agent.ts +360 -0
  73. package/dist/runtime/src/agents/codex-provider.ts +1193 -0
  74. package/dist/runtime/src/agents/codex-registry.ts +116 -0
  75. package/dist/runtime/src/agents/codex-tier-resolver.ts +74 -0
  76. package/dist/runtime/src/agents/codex-tree-kill.ts +54 -0
  77. package/dist/runtime/src/agents/codex-tree-manager.ts +230 -0
  78. package/dist/runtime/src/agents/codex-vault-hook-bridge.ts +240 -0
  79. package/dist/runtime/src/agents/codex-vault-hook.mjs +50 -0
  80. package/dist/runtime/src/agents/codex-windows-wrapper.ts +174 -0
  81. package/dist/runtime/src/agents/compaction-support.ts +75 -0
  82. package/dist/runtime/src/agents/compaction-tool-projection.ts +125 -0
  83. package/dist/runtime/src/agents/contracts.ts +75 -0
  84. package/dist/runtime/src/agents/deep-map.ts +13 -0
  85. package/dist/runtime/src/agents/execution-host.ts +118 -0
  86. package/dist/runtime/src/agents/explicit-agent-switch.ts +106 -0
  87. package/dist/runtime/src/agents/fixtures/claude-attachments.jsonl +2 -0
  88. package/dist/runtime/src/agents/fixtures/codex-shell.jsonl +5 -0
  89. package/dist/runtime/src/agents/fork.ts +100 -0
  90. package/dist/runtime/src/agents/hosted-agent.ts +78 -0
  91. package/dist/runtime/src/agents/idle-archiver.ts +225 -0
  92. package/dist/runtime/src/agents/idle-compact.ts +225 -0
  93. package/dist/runtime/src/agents/index.ts +225 -0
  94. package/dist/runtime/src/agents/maestro-provider.ts +246 -0
  95. package/dist/runtime/src/agents/maestro-registry.ts +189 -0
  96. package/dist/runtime/src/agents/mcp-tools/ask-user.ts +653 -0
  97. package/dist/runtime/src/agents/mcp-tools/common.ts +23 -0
  98. package/dist/runtime/src/agents/mcp-tools/inline-assets.ts +203 -0
  99. package/dist/runtime/src/agents/mcp-tools/publish-html.ts +183 -0
  100. package/dist/runtime/src/agents/mcp-tools/request-vault.ts +684 -0
  101. package/dist/runtime/src/agents/mcp-tools/self-config.ts +353 -0
  102. package/dist/runtime/src/agents/mcp-tools/spawn-subagent.ts +1349 -0
  103. package/dist/runtime/src/agents/mcp-tools/visual-compat.ts +18 -0
  104. package/dist/runtime/src/agents/mcp-tools/visuals.ts +60 -0
  105. package/dist/runtime/src/agents/memory-archive-policy.ts +54 -0
  106. package/dist/runtime/src/agents/model-catalog.ts +439 -0
  107. package/dist/runtime/src/agents/public-helpers.ts +149 -0
  108. package/dist/runtime/src/agents/registry.ts +35 -0
  109. package/dist/runtime/src/agents/rollout/claude.ts +336 -0
  110. package/dist/runtime/src/agents/rollout/codex.ts +910 -0
  111. package/dist/runtime/src/agents/rollout/index.ts +26 -0
  112. package/dist/runtime/src/agents/rollout/shared.ts +293 -0
  113. package/dist/runtime/src/agents/self-config-core.ts +704 -0
  114. package/dist/runtime/src/agents/task-events.ts +59 -0
  115. package/dist/runtime/src/agents/tool-format.ts +613 -0
  116. package/dist/runtime/src/agents/topic-agent-switch.ts +189 -0
  117. package/dist/runtime/src/agents/topic-cleanup.ts +285 -0
  118. package/dist/runtime/src/agents/vault-tool-policy.ts +36 -0
  119. package/dist/runtime/src/application/execute-external-user-turn.ts +23 -0
  120. package/dist/runtime/src/application/submit-runtime-gateway-turn.ts +484 -0
  121. package/dist/runtime/src/application/submit-user-message.ts +60 -0
  122. package/dist/runtime/src/application/switch-topic-effort.ts +48 -0
  123. package/dist/runtime/src/application/switch-topic-model.ts +79 -0
  124. package/dist/runtime/src/application/topic-service.ts +190 -0
  125. package/dist/runtime/src/application/turn-follow-ups.ts +291 -0
  126. package/dist/runtime/src/application/vault-command.ts +170 -0
  127. package/dist/runtime/src/bus.ts +409 -0
  128. package/dist/runtime/src/config-public.ts +2 -0
  129. package/dist/runtime/src/cron-host.ts +33 -0
  130. package/dist/runtime/src/cron-mcp-host.ts +5 -0
  131. package/dist/runtime/src/identifiers.ts +49 -0
  132. package/dist/runtime/src/index.ts +573 -0
  133. package/dist/runtime/src/mcp/agent-health-server.ts +8 -0
  134. package/dist/runtime/src/mcp/canonical-bridge-config.ts +84 -0
  135. package/dist/runtime/src/mcp/canonical-proxy-server.ts +308 -0
  136. package/dist/runtime/src/mcp/compaction-log-server.ts +25 -0
  137. package/dist/runtime/src/mcp/decision-server.ts +21 -0
  138. package/dist/runtime/src/mcp/dm-ipc.ts +60 -0
  139. package/dist/runtime/src/mcp/factories/agent-health.ts +394 -0
  140. package/dist/runtime/src/mcp/factories/compaction-log.ts +135 -0
  141. package/dist/runtime/src/mcp/factories/decision.ts +186 -0
  142. package/dist/runtime/src/mcp/factories/index.ts +73 -0
  143. package/dist/runtime/src/mcp/factories/session-comm.ts +184 -0
  144. package/dist/runtime/src/mcp/factories/session-history.ts +103 -0
  145. package/dist/runtime/src/mcp/factories/stdio-protection.ts +24 -0
  146. package/dist/runtime/src/mcp/factories/system-health.ts +259 -0
  147. package/dist/runtime/src/mcp/factories/task.ts +185 -0
  148. package/dist/runtime/src/mcp/factories/token-stats.ts +145 -0
  149. package/dist/runtime/src/mcp/factories/vault.ts +32 -0
  150. package/dist/runtime/src/mcp/mcp-helpers.ts +40 -0
  151. package/dist/runtime/src/mcp/peer-bridge.ts +119 -0
  152. package/dist/runtime/src/mcp/runtime-spec.ts +473 -0
  153. package/dist/runtime/src/mcp/session-comm/actor-policy.ts +160 -0
  154. package/dist/runtime/src/mcp/session-comm/bridge-ipc-config.ts +27 -0
  155. package/dist/runtime/src/mcp/session-comm/context.ts +113 -0
  156. package/dist/runtime/src/mcp/session-comm/default-host.ts +723 -0
  157. package/dist/runtime/src/mcp/session-comm/history-target.ts +89 -0
  158. package/dist/runtime/src/mcp/session-comm/history-tools.ts +113 -0
  159. package/dist/runtime/src/mcp/session-comm/hub-remote-session.ts +553 -0
  160. package/dist/runtime/src/mcp/session-comm/limits.ts +8 -0
  161. package/dist/runtime/src/mcp/session-comm/peer-forward.ts +251 -0
  162. package/dist/runtime/src/mcp/session-comm/runtime.ts +128 -0
  163. package/dist/runtime/src/mcp/session-comm/server.ts +1036 -0
  164. package/dist/runtime/src/mcp/session-comm/tell-permissions.ts +79 -0
  165. package/dist/runtime/src/mcp/session-comm/topic-catalog.ts +155 -0
  166. package/dist/runtime/src/mcp/session-comm/topic-config.ts +137 -0
  167. package/dist/runtime/src/mcp/session-comm/topics.ts +313 -0
  168. package/dist/runtime/src/mcp/session-history-limits.ts +36 -0
  169. package/dist/runtime/src/mcp/session-history-reader.ts +359 -0
  170. package/dist/runtime/src/mcp/session-history-server.ts +19 -0
  171. package/dist/runtime/src/mcp/stdio-protect.ts +7 -0
  172. package/dist/runtime/src/mcp/system-health-server.ts +5 -0
  173. package/dist/runtime/src/mcp/task-server.ts +17 -0
  174. package/dist/runtime/src/mcp/token-stats-server.ts +10 -0
  175. package/dist/runtime/src/mcp/vault-server.ts +12 -0
  176. package/dist/runtime/src/mcp/wiki-search-index.ts +359 -0
  177. package/dist/runtime/src/mcp/wiki-server.ts +2386 -0
  178. package/dist/runtime/src/mcp-runtime-host.ts +81 -0
  179. package/dist/runtime/src/media/file-events.ts +33 -0
  180. package/dist/runtime/src/media/text-extractor.ts +334 -0
  181. package/dist/runtime/src/media/video.ts +92 -0
  182. package/dist/runtime/src/node-host.ts +211 -0
  183. package/dist/runtime/src/outbox/coalescing-runner.ts +157 -0
  184. package/dist/runtime/src/outbox/file-ops.ts +267 -0
  185. package/dist/runtime/src/outbox/index.ts +26 -0
  186. package/dist/runtime/src/outbox/utils.ts +74 -0
  187. package/dist/runtime/src/platform/background-bash/context.ts +9 -0
  188. package/dist/runtime/src/platform/background-bash/manager.ts +292 -0
  189. package/dist/runtime/src/platform/background-bash/output-buffer.ts +323 -0
  190. package/dist/runtime/src/platform/config-helpers.ts +47 -0
  191. package/dist/runtime/src/platform/config.ts +618 -0
  192. package/dist/runtime/src/platform/constants.ts +30 -0
  193. package/dist/runtime/src/platform/debug-users.ts +14 -0
  194. package/dist/runtime/src/platform/delay.ts +1 -0
  195. package/dist/runtime/src/platform/error.ts +9 -0
  196. package/dist/runtime/src/platform/file-utils.ts +35 -0
  197. package/dist/runtime/src/platform/ipc.ts +55 -0
  198. package/dist/runtime/src/platform/jsonl.ts +277 -0
  199. package/dist/runtime/src/platform/lifecycle.ts +176 -0
  200. package/dist/runtime/src/platform/log-rotation.ts +45 -0
  201. package/dist/runtime/src/platform/logger.ts +42 -0
  202. package/dist/runtime/src/platform/maestro-bootstrap-env.ts +3 -0
  203. package/dist/runtime/src/platform/mcp-catalog-policy.ts +63 -0
  204. package/dist/runtime/src/platform/mcp-config.ts +1329 -0
  205. package/dist/runtime/src/platform/memoize-import.ts +26 -0
  206. package/dist/runtime/src/platform/modules.ts +145 -0
  207. package/dist/runtime/src/platform/node-plugins.ts +46 -0
  208. package/dist/runtime/src/platform/paths.ts +62 -0
  209. package/dist/runtime/src/platform/playwright/browser-processes.ts +300 -0
  210. package/dist/runtime/src/platform/playwright/capability.ts +5 -0
  211. package/dist/runtime/src/platform/playwright/headed-launch.ts +61 -0
  212. package/dist/runtime/src/platform/playwright/manager-utils.ts +128 -0
  213. package/dist/runtime/src/platform/playwright/manager.ts +1502 -0
  214. package/dist/runtime/src/platform/playwright/mcp-transport.ts +35 -0
  215. package/dist/runtime/src/platform/playwright/profile-management.ts +33 -0
  216. package/dist/runtime/src/platform/playwright/public-runtime.ts +52 -0
  217. package/dist/runtime/src/platform/playwright/transport-probe.ts +89 -0
  218. package/dist/runtime/src/platform/playwright/vault-broker.ts +261 -0
  219. package/dist/runtime/src/platform/public-runtime.ts +18 -0
  220. package/dist/runtime/src/prompts/agents/wiki-archiver.md +194 -0
  221. package/dist/runtime/src/prompts/builders.ts +696 -0
  222. package/dist/runtime/src/prompts/sessions/_shared-tools.md +38 -0
  223. package/dist/runtime/src/prompts/sessions/channel-system.md +13 -0
  224. package/dist/runtime/src/prompts/sessions/manager-system.md +34 -0
  225. package/dist/runtime/src/prompts/sessions/surfaces/cli.md +6 -0
  226. package/dist/runtime/src/prompts/sessions/surfaces/otium-manager.md +18 -0
  227. package/dist/runtime/src/prompts/sessions/surfaces/otium.md +6 -0
  228. package/dist/runtime/src/prompts/sessions/surfaces/telegram.md +5 -0
  229. package/dist/runtime/src/prompts/sessions/surfaces/terminal.md +6 -0
  230. package/dist/runtime/src/prompts/sessions/topic-system.md +9 -0
  231. package/dist/runtime/src/prompts/sessions/visual-design.md +38 -0
  232. package/dist/runtime/src/query/active-rooms.ts +514 -0
  233. package/dist/runtime/src/query/index.ts +23 -0
  234. package/dist/runtime/src/query/public-runtime.ts +28 -0
  235. package/dist/runtime/src/query/room-query-registry.ts +217 -0
  236. package/dist/runtime/src/query/session-inbox-cleanup.ts +45 -0
  237. package/dist/runtime/src/query/session-inbox-path.ts +42 -0
  238. package/dist/runtime/src/query/state.ts +116 -0
  239. package/dist/runtime/src/query/types.ts +8 -0
  240. package/dist/runtime/src/runtime/actor-topic-reach.ts +123 -0
  241. package/dist/runtime/src/runtime/actor-topic-scope.ts +255 -0
  242. package/dist/runtime/src/runtime/ask-callbacks.ts +217 -0
  243. package/dist/runtime/src/runtime/attachments.ts +149 -0
  244. package/dist/runtime/src/runtime/background-session-policy.ts +1 -0
  245. package/dist/runtime/src/runtime/background-sessions.ts +288 -0
  246. package/dist/runtime/src/runtime/bashrs-completions.ts +350 -0
  247. package/dist/runtime/src/runtime/channel-context.ts +115 -0
  248. package/dist/runtime/src/runtime/context-warning.ts +131 -0
  249. package/dist/runtime/src/runtime/cron-sessions.ts +35 -0
  250. package/dist/runtime/src/runtime/delivery-ack.ts +112 -0
  251. package/dist/runtime/src/runtime/errors.ts +70 -0
  252. package/dist/runtime/src/runtime/event-heartbeat.ts +77 -0
  253. package/dist/runtime/src/runtime/file-hooks.ts +81 -0
  254. package/dist/runtime/src/runtime/footer.ts +23 -0
  255. package/dist/runtime/src/runtime/gateway-capabilities.ts +22 -0
  256. package/dist/runtime/src/runtime/inbox.ts +1307 -0
  257. package/dist/runtime/src/runtime/playwright-turn-abort.ts +59 -0
  258. package/dist/runtime/src/runtime/public-helpers.ts +78 -0
  259. package/dist/runtime/src/runtime/remote-session-grant.ts +221 -0
  260. package/dist/runtime/src/runtime/remote-session-inbox.ts +943 -0
  261. package/dist/runtime/src/runtime/remote-session-reply-outbox.ts +168 -0
  262. package/dist/runtime/src/runtime/task-format.ts +18 -0
  263. package/dist/runtime/src/runtime/tasks.ts +53 -0
  264. package/dist/runtime/src/runtime/thread-context.ts +123 -0
  265. package/dist/runtime/src/runtime/thread-read.ts +67 -0
  266. package/dist/runtime/src/runtime/topic-config.ts +29 -0
  267. package/dist/runtime/src/runtime/turn-event-stream.ts +1051 -0
  268. package/dist/runtime/src/runtime/turn-runner.ts +2311 -0
  269. package/dist/runtime/src/runtime/turn-session.ts +116 -0
  270. package/dist/runtime/src/runtime/usage-alert.ts +51 -0
  271. package/dist/runtime/src/runtime/user-turn-envelope.ts +94 -0
  272. package/dist/runtime/src/runtime/visual-html.ts +175 -0
  273. package/dist/runtime/src/runtime/visual-store.ts +480 -0
  274. package/dist/runtime/src/runtime/visuals.ts +209 -0
  275. package/dist/runtime/src/runtime-gateway.ts +1045 -0
  276. package/dist/runtime/src/security/sanitize.ts +27 -0
  277. package/dist/runtime/src/security/sensitive-path.ts +41 -0
  278. package/dist/runtime/src/storage/activity-log.ts +167 -0
  279. package/dist/runtime/src/storage/api-messages.ts +766 -0
  280. package/dist/runtime/src/storage/api-topic-brief.ts +134 -0
  281. package/dist/runtime/src/storage/api-topic-config.ts +197 -0
  282. package/dist/runtime/src/storage/api-topics.ts +1647 -0
  283. package/dist/runtime/src/storage/app-settings.ts +50 -0
  284. package/dist/runtime/src/storage/ask-user-gates.ts +359 -0
  285. package/dist/runtime/src/storage/browser-profiles.ts +186 -0
  286. package/dist/runtime/src/storage/conversation-migration.ts +180 -0
  287. package/dist/runtime/src/storage/conversations.ts +377 -0
  288. package/dist/runtime/src/storage/decisions.ts +231 -0
  289. package/dist/runtime/src/storage/forum/agent-settings.ts +20 -0
  290. package/dist/runtime/src/storage/forum/index.ts +4 -0
  291. package/dist/runtime/src/storage/forum/repository.ts +283 -0
  292. package/dist/runtime/src/storage/forum/schema.ts +314 -0
  293. package/dist/runtime/src/storage/forum-db.ts +4 -0
  294. package/dist/runtime/src/storage/remote-session.ts +1028 -0
  295. package/dist/runtime/src/storage/runtime-events.ts +209 -0
  296. package/dist/runtime/src/storage/runtime-follow-ups.ts +212 -0
  297. package/dist/runtime/src/storage/runtime-gateway-submissions.ts +132 -0
  298. package/dist/runtime/src/storage/runtime-leases.ts +190 -0
  299. package/dist/runtime/src/storage/runtime-process-leases.ts +288 -0
  300. package/dist/runtime/src/storage/runtime-topic-state.ts +181 -0
  301. package/dist/runtime/src/storage/runtime-turn-requests.ts +846 -0
  302. package/dist/runtime/src/storage/self-schedules.ts +306 -0
  303. package/dist/runtime/src/storage/session-asks.ts +468 -0
  304. package/dist/runtime/src/storage/session-inbox-signal.ts +76 -0
  305. package/dist/runtime/src/storage/session-inbox.ts +161 -0
  306. package/dist/runtime/src/storage/sqlite.ts +154 -0
  307. package/dist/runtime/src/storage/storage-contract.ts +54 -0
  308. package/dist/runtime/src/storage/storage-host.ts +336 -0
  309. package/dist/runtime/src/storage/storage-public-host.ts +16 -0
  310. package/dist/runtime/src/storage/storage-public.ts +66 -0
  311. package/dist/runtime/src/storage/tasks.ts +172 -0
  312. package/dist/runtime/src/storage/token-stats.ts +432 -0
  313. package/dist/runtime/src/storage/topic-archive-state.ts +226 -0
  314. package/dist/runtime/src/storage/topic-archive.ts +169 -0
  315. package/dist/runtime/src/storage/topic-host-mcp-grants.ts +54 -0
  316. package/dist/runtime/src/storage/topic-link-records.ts +1085 -0
  317. package/dist/runtime/src/storage/topic-settings.ts +67 -0
  318. package/dist/runtime/src/storage/topic-tool-capabilities.ts +89 -0
  319. package/dist/runtime/src/storage/topic-transcript.ts +98 -0
  320. package/dist/runtime/src/storage/vault-crypto-core.ts +65 -0
  321. package/dist/runtime/src/storage/vault-crypto.ts +31 -0
  322. package/dist/runtime/src/storage/vault-public.ts +27 -0
  323. package/dist/runtime/src/storage/vault-request-gates.ts +359 -0
  324. package/dist/runtime/src/storage/vault.ts +388 -0
  325. package/dist/runtime/src/storage/wiki-summary-names.ts +52 -0
  326. package/dist/runtime/src/storage/wiki.ts +90 -0
  327. package/dist/runtime/src/topics/claim-abort.ts +190 -0
  328. package/dist/runtime/src/topics/create.ts +192 -0
  329. package/dist/runtime/src/topics/derive.ts +600 -0
  330. package/dist/runtime/src/topics/lifecycle.ts +425 -0
  331. package/dist/runtime/src/topics/links.ts +7 -0
  332. package/dist/runtime/src/topics/personal-general.ts +91 -0
  333. package/dist/runtime/src/topics/session.ts +1041 -0
  334. package/dist/runtime/src/topics/update.ts +287 -0
  335. package/dist/runtime/src/types/api.ts +591 -0
  336. package/dist/runtime/src/types.ts +418 -0
  337. package/dist/runtime/src/version.ts +1 -0
  338. package/dist/runtime/tsconfig.json +13 -0
  339. package/dist/runtime-gateway.js +514 -0
  340. package/dist/runtime-gateway.js.map +10 -0
  341. package/dist/runtime-helpers.js +1792 -0
  342. package/dist/runtime-helpers.js.map +40 -0
  343. package/dist/sqlite.js +66 -0
  344. package/dist/sqlite.js.map +10 -0
  345. package/dist/storage.js +5223 -0
  346. package/dist/storage.js.map +47 -0
  347. package/dist/types/apps/negotium/src/mcp-servers.d.ts +20 -0
  348. package/dist/types/packages/core/src/agents/api-topic-agent-switch.d.ts +38 -0
  349. package/dist/types/packages/core/src/agents/archiver.d.ts +87 -0
  350. package/dist/types/packages/core/src/agents/auth-check.d.ts +19 -0
  351. package/dist/types/packages/core/src/agents/claude-notices.d.ts +15 -0
  352. package/dist/types/packages/core/src/agents/claude-provider.d.ts +25 -0
  353. package/dist/types/packages/core/src/agents/claude-registry.d.ts +3 -0
  354. package/dist/types/packages/core/src/agents/claude-runtime-inspection.d.ts +9 -0
  355. package/dist/types/packages/core/src/agents/codex-app-server.d.ts +13 -0
  356. package/dist/types/packages/core/src/agents/codex-native-multi-agent.d.ts +20 -0
  357. package/dist/types/packages/core/src/agents/codex-provider.d.ts +64 -0
  358. package/dist/types/packages/core/src/agents/codex-registry.d.ts +3 -0
  359. package/dist/types/packages/core/src/agents/codex-tier-resolver.d.ts +10 -0
  360. package/dist/types/packages/core/src/agents/codex-tree-kill.d.ts +13 -0
  361. package/dist/types/packages/core/src/agents/codex-tree-manager.d.ts +28 -0
  362. package/dist/types/packages/core/src/agents/codex-vault-hook-bridge.d.ts +28 -0
  363. package/dist/types/packages/core/src/agents/codex-windows-wrapper.d.ts +30 -0
  364. package/dist/types/packages/core/src/agents/compaction-support.d.ts +5 -0
  365. package/dist/types/packages/core/src/agents/compaction-tool-projection.d.ts +9 -0
  366. package/dist/types/packages/core/src/agents/contracts.d.ts +68 -0
  367. package/dist/types/packages/core/src/agents/deep-map.d.ts +2 -0
  368. package/dist/types/packages/core/src/agents/execution-host.d.ts +33 -0
  369. package/dist/types/packages/core/src/agents/explicit-agent-switch.d.ts +26 -0
  370. package/dist/types/packages/core/src/agents/fork.d.ts +50 -0
  371. package/dist/types/packages/core/src/agents/hosted-agent.d.ts +15 -0
  372. package/dist/types/packages/core/src/agents/idle-archiver.d.ts +35 -0
  373. package/dist/types/packages/core/src/agents/idle-compact.d.ts +37 -0
  374. package/dist/types/packages/core/src/agents/index.d.ts +8 -0
  375. package/dist/types/packages/core/src/agents/maestro-provider.d.ts +75 -0
  376. package/dist/types/packages/core/src/agents/maestro-registry.d.ts +3 -0
  377. package/dist/types/packages/core/src/agents/mcp-tools/ask-user.d.ts +147 -0
  378. package/dist/types/packages/core/src/agents/mcp-tools/common.d.ts +14 -0
  379. package/dist/types/packages/core/src/agents/mcp-tools/inline-assets.d.ts +24 -0
  380. package/dist/types/packages/core/src/agents/mcp-tools/publish-html.d.ts +18 -0
  381. package/dist/types/packages/core/src/agents/mcp-tools/request-vault.d.ts +124 -0
  382. package/dist/types/packages/core/src/agents/mcp-tools/self-config.d.ts +45 -0
  383. package/dist/types/packages/core/src/agents/mcp-tools/spawn-subagent.d.ts +148 -0
  384. package/dist/types/packages/core/src/agents/mcp-tools/visual-compat.d.ts +55 -0
  385. package/dist/types/packages/core/src/agents/mcp-tools/visuals.d.ts +70 -0
  386. package/dist/types/packages/core/src/agents/memory-archive-policy.d.ts +24 -0
  387. package/dist/types/packages/core/src/agents/model-catalog.d.ts +132 -0
  388. package/dist/types/packages/core/src/agents/public-helpers.d.ts +17 -0
  389. package/dist/types/packages/core/src/agents/registry.d.ts +5 -0
  390. package/dist/types/packages/core/src/agents/rollout/claude.d.ts +77 -0
  391. package/dist/types/packages/core/src/agents/rollout/codex.d.ts +119 -0
  392. package/dist/types/packages/core/src/agents/rollout/index.d.ts +6 -0
  393. package/dist/types/packages/core/src/agents/rollout/shared.d.ts +56 -0
  394. package/dist/types/packages/core/src/agents/self-config-core.d.ts +199 -0
  395. package/dist/types/packages/core/src/agents/task-events.d.ts +19 -0
  396. package/dist/types/packages/core/src/agents/tool-format.d.ts +25 -0
  397. package/dist/types/packages/core/src/agents/topic-cleanup.d.ts +83 -0
  398. package/dist/types/packages/core/src/agents/vault-tool-policy.d.ts +2 -0
  399. package/dist/types/packages/core/src/bus.d.ts +141 -0
  400. package/dist/types/packages/core/src/identifiers.d.ts +27 -0
  401. package/dist/types/packages/core/src/mcp/canonical-bridge-config.d.ts +21 -0
  402. package/dist/types/packages/core/src/mcp/factories/agent-health.d.ts +5 -0
  403. package/dist/types/packages/core/src/mcp/factories/compaction-log.d.ts +8 -0
  404. package/dist/types/packages/core/src/mcp/factories/decision.d.ts +18 -0
  405. package/dist/types/packages/core/src/mcp/factories/index.d.ts +13 -0
  406. package/dist/types/packages/core/src/mcp/factories/session-comm.d.ts +38 -0
  407. package/dist/types/packages/core/src/mcp/factories/session-history.d.ts +11 -0
  408. package/dist/types/packages/core/src/mcp/factories/stdio-protection.d.ts +10 -0
  409. package/dist/types/packages/core/src/mcp/factories/system-health.d.ts +37 -0
  410. package/dist/types/packages/core/src/mcp/factories/task.d.ts +13 -0
  411. package/dist/types/packages/core/src/mcp/factories/token-stats.d.ts +20 -0
  412. package/dist/types/packages/core/src/mcp/factories/vault.d.ts +9 -0
  413. package/dist/types/packages/core/src/mcp/mcp-helpers.d.ts +26 -0
  414. package/dist/types/packages/core/src/mcp/peer-bridge.d.ts +92 -0
  415. package/dist/types/packages/core/src/mcp/runtime-spec.d.ts +147 -0
  416. package/dist/types/packages/core/src/mcp/session-comm/actor-policy.d.ts +120 -0
  417. package/dist/types/packages/core/src/mcp/session-comm/bridge-ipc-config.d.ts +6 -0
  418. package/dist/types/packages/core/src/mcp/session-comm/context.d.ts +44 -0
  419. package/dist/types/packages/core/src/mcp/session-comm/history-tools.d.ts +31 -0
  420. package/dist/types/packages/core/src/mcp/session-comm/hub-remote-session.d.ts +149 -0
  421. package/dist/types/packages/core/src/mcp/session-comm/limits.d.ts +8 -0
  422. package/dist/types/packages/core/src/mcp/session-comm/peer-forward.d.ts +85 -0
  423. package/dist/types/packages/core/src/mcp/session-comm/tell-permissions.d.ts +29 -0
  424. package/dist/types/packages/core/src/mcp/session-comm/topic-catalog.d.ts +59 -0
  425. package/dist/types/packages/core/src/mcp/session-history-limits.d.ts +20 -0
  426. package/dist/types/packages/core/src/mcp/session-history-reader.d.ts +35 -0
  427. package/dist/types/packages/core/src/mcp/wiki-search-index.d.ts +59 -0
  428. package/dist/types/packages/core/src/mcp/wiki-server.d.ts +53 -0
  429. package/dist/types/packages/core/src/media/file-events.d.ts +14 -0
  430. package/dist/types/packages/core/src/media/text-extractor.d.ts +34 -0
  431. package/dist/types/packages/core/src/outbox/coalescing-runner.d.ts +68 -0
  432. package/dist/types/packages/core/src/outbox/file-ops.d.ts +79 -0
  433. package/dist/types/packages/core/src/outbox/index.d.ts +3 -0
  434. package/dist/types/packages/core/src/outbox/utils.d.ts +16 -0
  435. package/dist/types/packages/core/src/platform/background-bash/context.d.ts +1 -0
  436. package/dist/types/packages/core/src/platform/background-bash/manager.d.ts +34 -0
  437. package/dist/types/packages/core/src/platform/config-helpers.d.ts +20 -0
  438. package/dist/types/packages/core/src/platform/config.d.ts +178 -0
  439. package/dist/types/packages/core/src/platform/constants.d.ts +20 -0
  440. package/dist/types/packages/core/src/platform/delay.d.ts +1 -0
  441. package/dist/types/packages/core/src/platform/error.d.ts +6 -0
  442. package/dist/types/packages/core/src/platform/file-utils.d.ts +16 -0
  443. package/dist/types/packages/core/src/platform/ipc.d.ts +32 -0
  444. package/dist/types/packages/core/src/platform/jsonl.d.ts +46 -0
  445. package/dist/types/packages/core/src/platform/lifecycle.d.ts +40 -0
  446. package/dist/types/packages/core/src/platform/logger.d.ts +20 -0
  447. package/dist/types/packages/core/src/platform/maestro-bootstrap-env.d.ts +0 -0
  448. package/dist/types/packages/core/src/platform/mcp-catalog-policy.d.ts +73 -0
  449. package/dist/types/packages/core/src/platform/mcp-config.d.ts +286 -0
  450. package/dist/types/packages/core/src/platform/memoize-import.d.ts +15 -0
  451. package/dist/types/packages/core/src/platform/paths.d.ts +18 -0
  452. package/dist/types/packages/core/src/platform/playwright/browser-processes.d.ts +60 -0
  453. package/dist/types/packages/core/src/platform/playwright/capability.d.ts +1 -0
  454. package/dist/types/packages/core/src/platform/playwright/headed-launch.d.ts +13 -0
  455. package/dist/types/packages/core/src/platform/playwright/manager-utils.d.ts +34 -0
  456. package/dist/types/packages/core/src/platform/playwright/manager.d.ts +194 -0
  457. package/dist/types/packages/core/src/platform/playwright/mcp-transport.d.ts +4 -0
  458. package/dist/types/packages/core/src/platform/playwright/profile-management.d.ts +8 -0
  459. package/dist/types/packages/core/src/platform/playwright/public-runtime.d.ts +6 -0
  460. package/dist/types/packages/core/src/platform/playwright/transport-probe.d.ts +13 -0
  461. package/dist/types/packages/core/src/platform/playwright/vault-broker.d.ts +6 -0
  462. package/dist/types/packages/core/src/platform/public-runtime.d.ts +3 -0
  463. package/dist/types/packages/core/src/prompts/builders.d.ts +78 -0
  464. package/dist/types/packages/core/src/query/active-rooms.d.ts +240 -0
  465. package/dist/types/packages/core/src/query/public-runtime.d.ts +4 -0
  466. package/dist/types/packages/core/src/query/room-query-registry.d.ts +71 -0
  467. package/dist/types/packages/core/src/query/session-inbox-cleanup.d.ts +5 -0
  468. package/dist/types/packages/core/src/query/session-inbox-path.d.ts +8 -0
  469. package/dist/types/packages/core/src/query/state.d.ts +25 -0
  470. package/dist/types/packages/core/src/query/types.d.ts +6 -0
  471. package/dist/types/packages/core/src/runtime/actor-topic-reach.d.ts +63 -0
  472. package/dist/types/packages/core/src/runtime/actor-topic-scope.d.ts +127 -0
  473. package/dist/types/packages/core/src/runtime/ask-callbacks.d.ts +53 -0
  474. package/dist/types/packages/core/src/runtime/attachments.d.ts +36 -0
  475. package/dist/types/packages/core/src/runtime/background-session-policy.d.ts +1 -0
  476. package/dist/types/packages/core/src/runtime/background-sessions.d.ts +27 -0
  477. package/dist/types/packages/core/src/runtime/bashrs-completions.d.ts +50 -0
  478. package/dist/types/packages/core/src/runtime/channel-context.d.ts +13 -0
  479. package/dist/types/packages/core/src/runtime/context-warning.d.ts +46 -0
  480. package/dist/types/packages/core/src/runtime/cron-sessions.d.ts +9 -0
  481. package/dist/types/packages/core/src/runtime/errors.d.ts +6 -0
  482. package/dist/types/packages/core/src/runtime/event-heartbeat.d.ts +17 -0
  483. package/dist/types/packages/core/src/runtime/file-hooks.d.ts +38 -0
  484. package/dist/types/packages/core/src/runtime/playwright-turn-abort.d.ts +12 -0
  485. package/dist/types/packages/core/src/runtime/public-helpers.d.ts +17 -0
  486. package/dist/types/packages/core/src/runtime/remote-session-grant.d.ts +91 -0
  487. package/dist/types/packages/core/src/runtime/remote-session-inbox.d.ts +206 -0
  488. package/dist/types/packages/core/src/runtime/remote-session-reply-outbox.d.ts +37 -0
  489. package/dist/types/packages/core/src/runtime/task-format.d.ts +4 -0
  490. package/dist/types/packages/core/src/runtime/tasks.d.ts +3 -0
  491. package/dist/types/packages/core/src/runtime/thread-context.d.ts +62 -0
  492. package/dist/types/packages/core/src/runtime/topic-config.d.ts +24 -0
  493. package/dist/types/packages/core/src/runtime/turn-event-stream.d.ts +47 -0
  494. package/dist/types/packages/core/src/runtime/turn-runner.d.ts +284 -0
  495. package/dist/types/packages/core/src/runtime/turn-session.d.ts +49 -0
  496. package/dist/types/packages/core/src/runtime/usage-alert.d.ts +11 -0
  497. package/dist/types/packages/core/src/runtime/user-turn-envelope.d.ts +37 -0
  498. package/dist/types/packages/core/src/runtime/visual-html.d.ts +13 -0
  499. package/dist/types/packages/core/src/runtime/visual-store.d.ts +71 -0
  500. package/dist/types/packages/core/src/runtime/visuals.d.ts +33 -0
  501. package/dist/types/packages/core/src/runtime-gateway.d.ts +282 -0
  502. package/dist/types/packages/core/src/security/sanitize.d.ts +16 -0
  503. package/dist/types/packages/core/src/security/sensitive-path.d.ts +1 -0
  504. package/dist/types/packages/core/src/storage/activity-log.d.ts +25 -0
  505. package/dist/types/packages/core/src/storage/api-messages.d.ts +156 -0
  506. package/dist/types/packages/core/src/storage/api-topic-brief.d.ts +39 -0
  507. package/dist/types/packages/core/src/storage/api-topic-config.d.ts +23 -0
  508. package/dist/types/packages/core/src/storage/api-topics.d.ts +274 -0
  509. package/dist/types/packages/core/src/storage/app-settings.d.ts +4 -0
  510. package/dist/types/packages/core/src/storage/ask-user-gates.d.ts +65 -0
  511. package/dist/types/packages/core/src/storage/browser-profiles.d.ts +31 -0
  512. package/dist/types/packages/core/src/storage/conversations.d.ts +149 -0
  513. package/dist/types/packages/core/src/storage/decisions.d.ts +45 -0
  514. package/dist/types/packages/core/src/storage/forum/agent-settings.d.ts +3 -0
  515. package/dist/types/packages/core/src/storage/forum/index.d.ts +4 -0
  516. package/dist/types/packages/core/src/storage/forum/repository.d.ts +42 -0
  517. package/dist/types/packages/core/src/storage/forum/schema.d.ts +38 -0
  518. package/dist/types/packages/core/src/storage/forum-db.d.ts +2 -0
  519. package/dist/types/packages/core/src/storage/remote-session.d.ts +318 -0
  520. package/dist/types/packages/core/src/storage/runtime-events.d.ts +33 -0
  521. package/dist/types/packages/core/src/storage/runtime-leases.d.ts +27 -0
  522. package/dist/types/packages/core/src/storage/runtime-process-leases.d.ts +47 -0
  523. package/dist/types/packages/core/src/storage/runtime-topic-state.d.ts +39 -0
  524. package/dist/types/packages/core/src/storage/runtime-turn-requests.d.ts +163 -0
  525. package/dist/types/packages/core/src/storage/self-schedules.d.ts +54 -0
  526. package/dist/types/packages/core/src/storage/session-asks.d.ts +78 -0
  527. package/dist/types/packages/core/src/storage/session-inbox-signal.d.ts +35 -0
  528. package/dist/types/packages/core/src/storage/session-inbox.d.ts +36 -0
  529. package/dist/types/packages/core/src/storage/sqlite.d.ts +20 -0
  530. package/dist/types/packages/core/src/storage/storage-contract.d.ts +46 -0
  531. package/dist/types/packages/core/src/storage/storage-host.d.ts +41 -0
  532. package/dist/types/packages/core/src/storage/storage-public-host.d.ts +7 -0
  533. package/dist/types/packages/core/src/storage/storage-public.d.ts +45 -0
  534. package/dist/types/packages/core/src/storage/tasks.d.ts +49 -0
  535. package/dist/types/packages/core/src/storage/token-stats.d.ts +69 -0
  536. package/dist/types/packages/core/src/storage/topic-archive-state.d.ts +33 -0
  537. package/dist/types/packages/core/src/storage/topic-archive.d.ts +42 -0
  538. package/dist/types/packages/core/src/storage/topic-host-mcp-grants.d.ts +5 -0
  539. package/dist/types/packages/core/src/storage/topic-link-records.d.ts +281 -0
  540. package/dist/types/packages/core/src/storage/topic-settings.d.ts +19 -0
  541. package/dist/types/packages/core/src/storage/topic-tool-capabilities.d.ts +37 -0
  542. package/dist/types/packages/core/src/storage/topic-transcript.d.ts +38 -0
  543. package/dist/types/packages/core/src/storage/vault-crypto-core.d.ts +6 -0
  544. package/dist/types/packages/core/src/storage/vault-crypto.d.ts +12 -0
  545. package/dist/types/packages/core/src/storage/vault-public.d.ts +3 -0
  546. package/dist/types/packages/core/src/storage/vault-request-gates.d.ts +69 -0
  547. package/dist/types/packages/core/src/storage/vault.d.ts +49 -0
  548. package/dist/types/packages/core/src/storage/wiki-summary-names.d.ts +13 -0
  549. package/dist/types/packages/core/src/storage/wiki.d.ts +15 -0
  550. package/dist/types/packages/core/src/topics/derive.d.ts +83 -0
  551. package/dist/types/packages/core/src/topics/lifecycle.d.ts +75 -0
  552. package/dist/types/packages/core/src/topics/links.d.ts +2 -0
  553. package/dist/types/packages/core/src/topics/personal-general.d.ts +15 -0
  554. package/dist/types/packages/core/src/topics/session.d.ts +70 -0
  555. package/dist/types/packages/core/src/types/api.d.ts +551 -0
  556. package/dist/types/packages/core/src/types.d.ts +405 -0
  557. package/dist/types/packages/core/src/version.d.ts +1 -0
  558. package/dist/types/packages/module-cron/src/background-sessions.d.ts +2 -0
  559. package/dist/types/packages/module-cron/src/context.d.ts +15 -0
  560. package/dist/types/packages/module-cron/src/host.d.ts +23 -0
  561. package/dist/types/packages/module-cron/src/index.d.ts +14 -0
  562. package/dist/types/packages/module-cron/src/module.d.ts +13 -0
  563. package/dist/types/packages/module-cron/src/schedule.d.ts +23 -0
  564. package/dist/types/packages/module-cron/src/scheduler.d.ts +46 -0
  565. package/dist/types/packages/module-cron/src/scripts.d.ts +29 -0
  566. package/dist/types/packages/module-cron/src/store.d.ts +152 -0
  567. package/dist/types/packages/module-cron/src/summarize.d.ts +4 -0
  568. package/dist/vault.js +848 -0
  569. package/dist/vault.js.map +18 -0
  570. package/install-bash-rs.mjs +90 -0
  571. package/install-browser-rs.mjs +83 -0
  572. package/package.json +171 -4
@@ -0,0 +1,514 @@
1
+ // @bun
2
+ // ../../packages/core/src/runtime-gateway.ts
3
+ var RUNTIME_GATEWAY_VERSION = 1;
4
+ var RUNTIME_GATEWAY_CONTROL_PATH = "/api/v1/control/runtime/v1";
5
+
6
+ class RuntimeGatewayError extends Error {
7
+ kind;
8
+ status;
9
+ constructor(message, kind, status) {
10
+ super(message);
11
+ this.kind = kind;
12
+ this.status = status;
13
+ }
14
+ }
15
+ var HOST_MCP_SERVER_NAME = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
16
+ var HOST_MCP_SERVER_KEYS = new Set(["type", "url", "headers", "timeout"]);
17
+ var HTTP_HEADER_NAME = /^[!#$%&'*+.^_`|~0-9A-Za-z-]+$/;
18
+ function parseHostMcpServers(value) {
19
+ if (value === undefined)
20
+ return;
21
+ if (!value || typeof value !== "object" || Array.isArray(value)) {
22
+ throw new TypeError("hostMcpServers must be an object");
23
+ }
24
+ const parsedEntries = [];
25
+ for (const [name, raw] of Object.entries(value)) {
26
+ if (!HOST_MCP_SERVER_NAME.test(name)) {
27
+ throw new TypeError(`invalid host MCP server name: ${name}`);
28
+ }
29
+ if (!raw || typeof raw !== "object" || Array.isArray(raw)) {
30
+ throw new TypeError(`hostMcpServers.${name} must be an object`);
31
+ }
32
+ const spec = raw;
33
+ const unsupported = Object.keys(spec).find((key) => !HOST_MCP_SERVER_KEYS.has(key));
34
+ if (unsupported) {
35
+ throw new TypeError(`hostMcpServers.${name}.${unsupported} is not allowed`);
36
+ }
37
+ if (spec.type !== "sse" && spec.type !== "http") {
38
+ throw new TypeError(`hostMcpServers.${name}.type must be sse or http`);
39
+ }
40
+ if (typeof spec.url !== "string") {
41
+ throw new TypeError(`hostMcpServers.${name}.url must be a string`);
42
+ }
43
+ let url;
44
+ try {
45
+ url = new URL(spec.url);
46
+ } catch {
47
+ throw new TypeError(`hostMcpServers.${name}.url must be a valid URL`);
48
+ }
49
+ if (url.protocol !== "http:" && url.protocol !== "https:") {
50
+ throw new TypeError(`hostMcpServers.${name}.url must use http or https`);
51
+ }
52
+ let headers;
53
+ if (spec.headers !== undefined) {
54
+ if (!spec.headers || typeof spec.headers !== "object" || Array.isArray(spec.headers)) {
55
+ throw new TypeError(`hostMcpServers.${name}.headers must be an object`);
56
+ }
57
+ const headerEntries = [];
58
+ for (const [key, headerValue] of Object.entries(spec.headers)) {
59
+ if (!HTTP_HEADER_NAME.test(key) || typeof headerValue !== "string") {
60
+ throw new TypeError(`hostMcpServers.${name}.headers must contain string values`);
61
+ }
62
+ try {
63
+ new Headers([[key, headerValue]]);
64
+ } catch {
65
+ throw new TypeError(`hostMcpServers.${name}.headers contains an invalid header`);
66
+ }
67
+ headerEntries.push([key, headerValue]);
68
+ }
69
+ headers = Object.fromEntries(headerEntries);
70
+ }
71
+ if (spec.timeout !== undefined && (typeof spec.timeout !== "number" || !Number.isFinite(spec.timeout) || spec.timeout <= 0)) {
72
+ throw new TypeError(`hostMcpServers.${name}.timeout must be a positive number`);
73
+ }
74
+ parsedEntries.push([
75
+ name,
76
+ {
77
+ type: spec.type,
78
+ url: url.toString(),
79
+ ...headers ? { headers } : {},
80
+ ...spec.timeout !== undefined ? { timeout: spec.timeout } : {}
81
+ }
82
+ ]);
83
+ }
84
+ return Object.fromEntries(parsedEntries);
85
+ }
86
+ function record(value) {
87
+ return value && typeof value === "object" && !Array.isArray(value) ? value : null;
88
+ }
89
+ async function json(response) {
90
+ try {
91
+ return await response.json();
92
+ } catch {
93
+ throw new RuntimeGatewayError("Runtime Gateway returned invalid JSON", "protocol", response.status);
94
+ }
95
+ }
96
+ function validHealth(value) {
97
+ const body = record(value);
98
+ return Boolean(body?.ok === true && body.v === RUNTIME_GATEWAY_VERSION && Array.isArray(body.capabilities) && typeof body.cursor === "number");
99
+ }
100
+ function validAcknowledgedMessage(value) {
101
+ const message = record(value);
102
+ return Boolean(message && typeof message.id === "string" && typeof message.topicId === "string" && typeof message.authorId === "string" && typeof message.text === "string" && typeof message.createdAt === "string");
103
+ }
104
+ function validTurnAck(value) {
105
+ const body = record(value);
106
+ return Boolean(body?.ok === true && body.v === RUNTIME_GATEWAY_VERSION && body.accepted === true && typeof body.deduplicated === "boolean" && typeof body.requestId === "string" && typeof body.clientMessageId === "string" && typeof body.topicId === "string" && typeof body.messageId === "string" && (body.message === undefined || validAcknowledgedMessage(body.message)) && typeof body.cursor === "number");
107
+ }
108
+ function validFollowUp(value) {
109
+ const item = record(value);
110
+ return Boolean(typeof item?.id === "string" && typeof item.text === "string" && typeof item.actorUserId === "string" && Array.isArray(item.attachments) && typeof item.createdAt === "string");
111
+ }
112
+ function validFollowUpLine(value) {
113
+ const body = record(value);
114
+ return Boolean(typeof body?.topicId === "string" && Array.isArray(body.followUps) && body.followUps.every(validFollowUp) && typeof body.paused === "boolean");
115
+ }
116
+ function validHeldTurn(value) {
117
+ const body = record(value);
118
+ return Boolean(body?.ok === true && body.v === RUNTIME_GATEWAY_VERSION && body.accepted === true && body.held === true && typeof body.clientMessageId === "string" && typeof body.topicId === "string" && validFollowUp(body.followUp));
119
+ }
120
+ function validManagerTopic(value) {
121
+ const topic = record(value);
122
+ return Boolean(typeof topic?.id === "string" && typeof topic.title === "string" && topic.kind === "manager" && Array.isArray(topic.participants));
123
+ }
124
+ function validDeletedMessage(value) {
125
+ const message = record(value);
126
+ return Boolean(typeof message?.id === "string" && typeof message.topicId === "string" && typeof message.authorId === "string" && typeof message.text === "string" && message.deleted === true && typeof message.createdAt === "string");
127
+ }
128
+ function validCronJob(value) {
129
+ const job = record(value);
130
+ return Boolean(typeof job?.id === "string" && typeof job.name === "string" && typeof job.executionPrincipalUserId === "string" && typeof job.actorOwnerUserId === "string" && typeof job.topicId === "string" && typeof job.schedule === "string" && typeof job.enabled === "boolean" && typeof job.nextRunAt === "string" && typeof job.canMutate === "boolean");
131
+ }
132
+ async function* parseRuntimeGatewaySse(body) {
133
+ const reader = body.getReader();
134
+ const decoder = new TextDecoder;
135
+ let buffer = "";
136
+ let event = "message";
137
+ let id;
138
+ let data = [];
139
+ const flush = () => {
140
+ if (data.length === 0)
141
+ return null;
142
+ const raw = data.join(`
143
+ `);
144
+ data = [];
145
+ try {
146
+ return { event, id, data: JSON.parse(raw) };
147
+ } catch {
148
+ throw new RuntimeGatewayError("Runtime Gateway SSE event has invalid JSON", "protocol");
149
+ } finally {
150
+ event = "message";
151
+ id = undefined;
152
+ }
153
+ };
154
+ try {
155
+ while (true) {
156
+ const chunk = await reader.read();
157
+ if (chunk.done)
158
+ break;
159
+ buffer += decoder.decode(chunk.value, { stream: true }).replace(/\r\n/g, `
160
+ `);
161
+ let newline = buffer.indexOf(`
162
+ `);
163
+ while (newline >= 0) {
164
+ const line = buffer.slice(0, newline);
165
+ buffer = buffer.slice(newline + 1);
166
+ if (line === "") {
167
+ const parsed = flush();
168
+ if (parsed)
169
+ yield parsed;
170
+ } else if (line.startsWith("event:")) {
171
+ event = line.slice(6).trim() || "message";
172
+ } else if (line.startsWith("id:")) {
173
+ const parsed = Number.parseInt(line.slice(3).trim(), 10);
174
+ if (Number.isFinite(parsed))
175
+ id = parsed;
176
+ } else if (line.startsWith("data:")) {
177
+ data.push(line.slice(5).trimStart());
178
+ }
179
+ newline = buffer.indexOf(`
180
+ `);
181
+ }
182
+ }
183
+ buffer += decoder.decode();
184
+ if (buffer.startsWith("data:"))
185
+ data.push(buffer.slice(5).trimStart());
186
+ const parsed = flush();
187
+ if (parsed)
188
+ yield parsed;
189
+ } finally {
190
+ reader.releaseLock();
191
+ }
192
+ }
193
+
194
+ class RuntimeGatewayClient {
195
+ options;
196
+ pathPrefix;
197
+ request;
198
+ requestTimeoutMs;
199
+ compactTimeoutMs;
200
+ constructor(options) {
201
+ this.options = options;
202
+ this.pathPrefix = options.pathPrefix ?? RUNTIME_GATEWAY_CONTROL_PATH;
203
+ this.request = options.fetch ?? fetch;
204
+ this.requestTimeoutMs = options.requestTimeoutMs ?? 5000;
205
+ this.compactTimeoutMs = options.compactTimeoutMs ?? 5 * 60000;
206
+ }
207
+ endpoint(path) {
208
+ if (!this.options.baseUrl || !this.options.token) {
209
+ throw new RuntimeGatewayError("Runtime Gateway is not configured", "config");
210
+ }
211
+ return `${this.options.baseUrl.replace(/\/+$/, "")}${this.pathPrefix}${path}`;
212
+ }
213
+ async authorization() {
214
+ try {
215
+ const token = typeof this.options.token === "function" ? await this.options.token() : this.options.token;
216
+ return `Bearer ${token}`;
217
+ } catch (error) {
218
+ throw new RuntimeGatewayError(error instanceof Error ? error.message : "Runtime Gateway token resolution failed", "config");
219
+ }
220
+ }
221
+ async send(path, init, timeoutMs) {
222
+ const authorization = await this.authorization();
223
+ try {
224
+ return await this.request(this.endpoint(path), {
225
+ ...init,
226
+ headers: { authorization, ...init.headers },
227
+ signal: timeoutMs === undefined ? init.signal : AbortSignal.timeout(timeoutMs)
228
+ });
229
+ } catch (error) {
230
+ if (error instanceof DOMException && error.name === "TimeoutError") {
231
+ throw new RuntimeGatewayError("Runtime Gateway request timed out", "timeout");
232
+ }
233
+ throw new RuntimeGatewayError("Runtime Gateway request failed", "transport");
234
+ }
235
+ }
236
+ async health() {
237
+ const response = await this.send("/health", { method: "GET" }, this.requestTimeoutMs);
238
+ if (!response.ok) {
239
+ throw new RuntimeGatewayError("Runtime Gateway health request failed", "http", response.status);
240
+ }
241
+ const body = await json(response);
242
+ if (!validHealth(body)) {
243
+ throw new RuntimeGatewayError("Runtime Gateway health response is incompatible", "protocol");
244
+ }
245
+ return body;
246
+ }
247
+ async submitTurn(input) {
248
+ const response = await this.send("/turns", {
249
+ method: "POST",
250
+ headers: { "content-type": "application/json" },
251
+ body: JSON.stringify({ v: RUNTIME_GATEWAY_VERSION, ...input })
252
+ }, this.requestTimeoutMs);
253
+ if (response.status !== 202) {
254
+ throw new RuntimeGatewayError("Runtime Gateway turn was not accepted", "http", response.status);
255
+ }
256
+ const body = await json(response);
257
+ if (!validTurnAck(body)) {
258
+ throw new RuntimeGatewayError("Runtime Gateway turn acknowledgement is incompatible", "protocol");
259
+ }
260
+ return body;
261
+ }
262
+ async holdOrSubmitTurn(input) {
263
+ const response = await this.send("/turns", {
264
+ method: "POST",
265
+ headers: { "content-type": "application/json" },
266
+ body: JSON.stringify({ v: RUNTIME_GATEWAY_VERSION, ...input, hold: true })
267
+ }, this.requestTimeoutMs);
268
+ if (response.status !== 202) {
269
+ throw new RuntimeGatewayError("Runtime Gateway turn was not accepted", "http", response.status);
270
+ }
271
+ const body = await json(response);
272
+ if (validHeldTurn(body) || validTurnAck(body))
273
+ return body;
274
+ throw new RuntimeGatewayError("Runtime Gateway turn acknowledgement is incompatible", "protocol");
275
+ }
276
+ async followUps(topicId, userId) {
277
+ const response = await this.send(`/topics/${encodeURIComponent(topicId)}/follow-ups?userId=${encodeURIComponent(userId)}`, { method: "GET" }, this.requestTimeoutMs);
278
+ return this.followUpLineFrom(response, "list");
279
+ }
280
+ async editFollowUp(topicId, followUpId, actor, text) {
281
+ return this.changeFollowUp(topicId, followUpId, "", "PATCH", { ...actor, text });
282
+ }
283
+ async deleteFollowUp(topicId, followUpId, actor) {
284
+ return this.changeFollowUp(topicId, followUpId, "", "DELETE", { ...actor });
285
+ }
286
+ async moveFollowUp(topicId, followUpId, actor, toIndex) {
287
+ return this.changeFollowUp(topicId, followUpId, "/move", "POST", { ...actor, toIndex });
288
+ }
289
+ async sendFollowUpNow(topicId, followUpId, actor) {
290
+ const line = await this.changeFollowUp(topicId, followUpId, "/send", "POST", { ...actor });
291
+ return line;
292
+ }
293
+ async changeFollowUp(topicId, followUpId, suffix, method, body) {
294
+ const response = await this.send(`/topics/${encodeURIComponent(topicId)}/follow-ups/${encodeURIComponent(followUpId)}${suffix}`, {
295
+ method,
296
+ headers: { "content-type": "application/json" },
297
+ body: JSON.stringify({ v: RUNTIME_GATEWAY_VERSION, ...body })
298
+ }, this.requestTimeoutMs);
299
+ return this.followUpLineFrom(response, method === "PATCH" ? "edit" : suffix || "delete");
300
+ }
301
+ async followUpLineFrom(response, what) {
302
+ if (!response.ok) {
303
+ throw new RuntimeGatewayError(`Runtime Gateway follow-up ${what} failed`, "http", response.status);
304
+ }
305
+ const body = await json(response);
306
+ if (!validFollowUpLine(body)) {
307
+ throw new RuntimeGatewayError(`Runtime Gateway follow-up ${what} response is incompatible`, "protocol");
308
+ }
309
+ return body;
310
+ }
311
+ async deriveTopic(topicId, input) {
312
+ const response = await this.send(`/topics/${encodeURIComponent(topicId)}/derive`, {
313
+ method: "POST",
314
+ headers: { "content-type": "application/json" },
315
+ body: JSON.stringify({ v: RUNTIME_GATEWAY_VERSION, ...input })
316
+ }, this.requestTimeoutMs);
317
+ if (response.status !== 201) {
318
+ throw new RuntimeGatewayError("Runtime Gateway topic derive failed", "http", response.status);
319
+ }
320
+ const body = await json(response);
321
+ const topic = record(body)?.topic;
322
+ const topicRecord = record(topic);
323
+ if (!topicRecord || typeof topicRecord.id !== "string" || typeof topicRecord.title !== "string") {
324
+ throw new RuntimeGatewayError("Runtime Gateway topic derive response is incompatible", "protocol");
325
+ }
326
+ return topic;
327
+ }
328
+ async ensureManagerTopic(userId) {
329
+ const response = await this.send("/manager-topic", {
330
+ method: "POST",
331
+ headers: { "content-type": "application/json" },
332
+ body: JSON.stringify({ v: RUNTIME_GATEWAY_VERSION, userId })
333
+ }, this.requestTimeoutMs);
334
+ if (!response.ok) {
335
+ throw new RuntimeGatewayError("Runtime Gateway manager topic request failed", "http", response.status);
336
+ }
337
+ const body = record(await json(response));
338
+ if (body?.ok !== true || body.v !== RUNTIME_GATEWAY_VERSION || !validManagerTopic(body.topic)) {
339
+ throw new RuntimeGatewayError("Runtime Gateway manager topic response is incompatible", "protocol");
340
+ }
341
+ return body.topic;
342
+ }
343
+ async deleteMessage(topicId, messageId, actorUserId, allowAdmin = false) {
344
+ const response = await this.send(`/topics/${encodeURIComponent(topicId)}/messages/${encodeURIComponent(messageId)}`, {
345
+ method: "DELETE",
346
+ headers: { "content-type": "application/json" },
347
+ body: JSON.stringify({
348
+ v: RUNTIME_GATEWAY_VERSION,
349
+ actorUserId,
350
+ ...allowAdmin ? { allowAdmin: true } : {}
351
+ })
352
+ }, this.requestTimeoutMs);
353
+ if (!response.ok) {
354
+ throw new RuntimeGatewayError("Runtime Gateway message delete failed", "http", response.status);
355
+ }
356
+ const body = record(await json(response));
357
+ if (body?.ok !== true || body.v !== RUNTIME_GATEWAY_VERSION || !validDeletedMessage(body.message)) {
358
+ throw new RuntimeGatewayError("Runtime Gateway message delete response is incompatible", "protocol");
359
+ }
360
+ return body.message;
361
+ }
362
+ async cronRequest(path, init) {
363
+ const response = await this.send(path, init, this.requestTimeoutMs);
364
+ if (!response.ok) {
365
+ throw new RuntimeGatewayError("Runtime Gateway cron request failed", "http", response.status);
366
+ }
367
+ const body = record(await json(response));
368
+ if (body?.ok !== true || body.v !== RUNTIME_GATEWAY_VERSION) {
369
+ throw new RuntimeGatewayError("Runtime Gateway cron response is incompatible", "protocol");
370
+ }
371
+ return body;
372
+ }
373
+ async listCronScripts() {
374
+ const body = await this.cronRequest("/cron/scripts", { method: "GET" });
375
+ if (!Array.isArray(body.scripts) || !body.scripts.every((value) => typeof value === "string")) {
376
+ throw new RuntimeGatewayError("Runtime Gateway cron scripts are incompatible", "protocol");
377
+ }
378
+ return body.scripts;
379
+ }
380
+ async listCronJobs(userId, actorUserId, actorIsAdmin = false) {
381
+ const search = new URLSearchParams({
382
+ user: userId,
383
+ actorUserId,
384
+ actorIsAdmin: actorIsAdmin ? "1" : "0"
385
+ });
386
+ const body = await this.cronRequest(`/cron/jobs?${search}`, { method: "GET" });
387
+ if (!Array.isArray(body.jobs) || !body.jobs.every(validCronJob)) {
388
+ throw new RuntimeGatewayError("Runtime Gateway cron jobs are incompatible", "protocol");
389
+ }
390
+ return body.jobs;
391
+ }
392
+ async createCronJob(input) {
393
+ const body = await this.cronRequest("/cron/jobs", {
394
+ method: "POST",
395
+ headers: { "content-type": "application/json" },
396
+ body: JSON.stringify({ v: RUNTIME_GATEWAY_VERSION, ...input })
397
+ });
398
+ if (!validCronJob(body.job)) {
399
+ throw new RuntimeGatewayError("Runtime Gateway cron job is incompatible", "protocol");
400
+ }
401
+ return body.job;
402
+ }
403
+ async updateCronJob(jobId, userId, actorUserId, patch, actorIsAdmin = false) {
404
+ const body = await this.cronRequest(`/cron/jobs/${encodeURIComponent(jobId)}`, {
405
+ method: "PATCH",
406
+ headers: { "content-type": "application/json" },
407
+ body: JSON.stringify({
408
+ v: RUNTIME_GATEWAY_VERSION,
409
+ userId,
410
+ actorUserId,
411
+ actorIsAdmin,
412
+ patch
413
+ })
414
+ });
415
+ if (!validCronJob(body.job)) {
416
+ throw new RuntimeGatewayError("Runtime Gateway cron job is incompatible", "protocol");
417
+ }
418
+ return body.job;
419
+ }
420
+ async deleteCronJob(jobId, userId, actorUserId, actorIsAdmin = false) {
421
+ const search = new URLSearchParams({
422
+ user: userId,
423
+ actorUserId,
424
+ actorIsAdmin: actorIsAdmin ? "1" : "0"
425
+ });
426
+ const body = await this.cronRequest(`/cron/jobs/${encodeURIComponent(jobId)}?${search}`, {
427
+ method: "DELETE"
428
+ });
429
+ if (typeof body.deleted !== "string") {
430
+ throw new RuntimeGatewayError("Runtime Gateway cron delete is incompatible", "protocol");
431
+ }
432
+ return body.deleted;
433
+ }
434
+ async* events(after, topicId, signal) {
435
+ const search = new URLSearchParams({ after: String(Math.max(0, after)) });
436
+ if (topicId)
437
+ search.set("topicId", topicId);
438
+ const response = await this.send(`/events?${search}`, { method: "GET", signal });
439
+ if (!response.ok || !response.body) {
440
+ throw new RuntimeGatewayError("Runtime Gateway event stream failed", "http", response.status);
441
+ }
442
+ yield* parseRuntimeGatewaySse(response.body);
443
+ }
444
+ async getTopicUsage(topicId, userId) {
445
+ const response = await this.send(`/topics/${encodeURIComponent(topicId)}/usage?user=${encodeURIComponent(userId)}`, { method: "GET" }, this.requestTimeoutMs);
446
+ if (!response.ok) {
447
+ throw new RuntimeGatewayError("Runtime Gateway topic usage request failed", "http", response.status);
448
+ }
449
+ const usage = record(record(await json(response))?.usage);
450
+ const read = (key) => {
451
+ const value = usage?.[key];
452
+ return typeof value === "number" && Number.isFinite(value) ? value : 0;
453
+ };
454
+ return {
455
+ queries: read("queries"),
456
+ inputTokens: read("inputTokens"),
457
+ outputTokens: read("outputTokens"),
458
+ cacheCreationInputTokens: read("cacheCreationInputTokens"),
459
+ cacheReadInputTokens: read("cacheReadInputTokens"),
460
+ estimatedCostUsd: read("estimatedCostUsd")
461
+ };
462
+ }
463
+ async abortTurn(topicId, userId) {
464
+ const response = await this.send(`/topics/${encodeURIComponent(topicId)}/abort`, {
465
+ method: "POST",
466
+ headers: { "content-type": "application/json" },
467
+ body: JSON.stringify({ v: RUNTIME_GATEWAY_VERSION, userId })
468
+ }, this.requestTimeoutMs);
469
+ if (!response.ok) {
470
+ throw new RuntimeGatewayError("Runtime Gateway turn abort failed", "http", response.status);
471
+ }
472
+ const body = record(await json(response));
473
+ if (body?.ok !== true || body.v !== RUNTIME_GATEWAY_VERSION || typeof body.aborted !== "boolean") {
474
+ throw new RuntimeGatewayError("Runtime Gateway turn abort response is incompatible", "protocol");
475
+ }
476
+ return body.aborted;
477
+ }
478
+ async resetSession(topicId, userId, reason, actorUserId) {
479
+ return this.sessionCommand(topicId, userId, "reset", reason, actorUserId);
480
+ }
481
+ async compactSession(topicId, userId, reason, actorUserId) {
482
+ return this.sessionCommand(topicId, userId, "compact", reason, actorUserId);
483
+ }
484
+ async sessionCommand(topicId, userId, command, reason, actorUserId) {
485
+ const response = await this.send(`/topics/${encodeURIComponent(topicId)}/session/${command}`, {
486
+ method: "POST",
487
+ headers: { "content-type": "application/json" },
488
+ body: JSON.stringify({
489
+ v: RUNTIME_GATEWAY_VERSION,
490
+ userId,
491
+ ...actorUserId ? { actorUserId } : {},
492
+ ...reason ? { reason } : {}
493
+ })
494
+ }, command === "compact" ? this.compactTimeoutMs : this.requestTimeoutMs);
495
+ if (!response.ok) {
496
+ throw new RuntimeGatewayError(`Runtime Gateway session ${command} failed`, "http", response.status);
497
+ }
498
+ const body = record(await json(response));
499
+ if (body?.ok !== true || body.v !== RUNTIME_GATEWAY_VERSION) {
500
+ throw new RuntimeGatewayError(`Runtime Gateway session ${command} response is incompatible`, "protocol");
501
+ }
502
+ return typeof body.result === "string" ? body.result : undefined;
503
+ }
504
+ }
505
+ export {
506
+ RUNTIME_GATEWAY_CONTROL_PATH,
507
+ RUNTIME_GATEWAY_VERSION,
508
+ RuntimeGatewayClient,
509
+ RuntimeGatewayError,
510
+ parseHostMcpServers,
511
+ parseRuntimeGatewaySse
512
+ };
513
+
514
+ //# debugId=03FF2A0CA9E0E7D364756E2164756E21
@@ -0,0 +1,10 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../packages/core/src/runtime-gateway.ts"],
4
+ "sourcesContent": [
5
+ "import type { ActorTopicScope, RemoteSessionGrant } from \"#types\";\nimport type { AttachmentDto, MessageDto } from \"#types/api\";\n\nexport const RUNTIME_GATEWAY_VERSION = 1 as const;\nexport const RUNTIME_GATEWAY_CONTROL_PATH = \"/api/v1/control/runtime/v1\";\n\nexport type RuntimeGatewayErrorKind = \"config\" | \"timeout\" | \"transport\" | \"protocol\" | \"http\";\n\nexport class RuntimeGatewayError extends Error {\n constructor(\n message: string,\n public readonly kind: RuntimeGatewayErrorKind,\n public readonly status?: number,\n ) {\n super(message);\n }\n}\n\nexport interface RuntimeGatewayHealth {\n ok: true;\n v: typeof RUNTIME_GATEWAY_VERSION;\n nodeId?: string;\n aiName?: string;\n capabilities: string[];\n cursor: number;\n}\n\n/** Remote-only MCP transport a gateway host may grant to a manager topic. */\nexport interface HostMcpServerSpec {\n type: \"sse\" | \"http\";\n url: string;\n headers?: Record<string, string>;\n timeout?: number;\n}\n\nconst HOST_MCP_SERVER_NAME = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;\nconst HOST_MCP_SERVER_KEYS = new Set([\"type\", \"url\", \"headers\", \"timeout\"]);\nconst HTTP_HEADER_NAME = /^[!#$%&'*+.^_`|~0-9A-Za-z-]+$/;\n\n/** Keep host grants remote-only so a gateway caller cannot spawn node processes. */\nexport function parseHostMcpServers(value: unknown): Record<string, HostMcpServerSpec> | undefined {\n if (value === undefined) return undefined;\n if (!value || typeof value !== \"object\" || Array.isArray(value)) {\n throw new TypeError(\"hostMcpServers must be an object\");\n }\n const parsedEntries: Array<[string, HostMcpServerSpec]> = [];\n for (const [name, raw] of Object.entries(value)) {\n if (!HOST_MCP_SERVER_NAME.test(name)) {\n throw new TypeError(`invalid host MCP server name: ${name}`);\n }\n if (!raw || typeof raw !== \"object\" || Array.isArray(raw)) {\n throw new TypeError(`hostMcpServers.${name} must be an object`);\n }\n const spec = raw as Record<string, unknown>;\n const unsupported = Object.keys(spec).find((key) => !HOST_MCP_SERVER_KEYS.has(key));\n if (unsupported) {\n throw new TypeError(`hostMcpServers.${name}.${unsupported} is not allowed`);\n }\n if (spec.type !== \"sse\" && spec.type !== \"http\") {\n throw new TypeError(`hostMcpServers.${name}.type must be sse or http`);\n }\n if (typeof spec.url !== \"string\") {\n throw new TypeError(`hostMcpServers.${name}.url must be a string`);\n }\n let url: URL;\n try {\n url = new URL(spec.url);\n } catch {\n throw new TypeError(`hostMcpServers.${name}.url must be a valid URL`);\n }\n if (url.protocol !== \"http:\" && url.protocol !== \"https:\") {\n throw new TypeError(`hostMcpServers.${name}.url must use http or https`);\n }\n let headers: Record<string, string> | undefined;\n if (spec.headers !== undefined) {\n if (!spec.headers || typeof spec.headers !== \"object\" || Array.isArray(spec.headers)) {\n throw new TypeError(`hostMcpServers.${name}.headers must be an object`);\n }\n const headerEntries: Array<[string, string]> = [];\n for (const [key, headerValue] of Object.entries(spec.headers)) {\n if (!HTTP_HEADER_NAME.test(key) || typeof headerValue !== \"string\") {\n throw new TypeError(`hostMcpServers.${name}.headers must contain string values`);\n }\n try {\n new Headers([[key, headerValue]]);\n } catch {\n throw new TypeError(`hostMcpServers.${name}.headers contains an invalid header`);\n }\n headerEntries.push([key, headerValue]);\n }\n headers = Object.fromEntries(headerEntries);\n }\n if (\n spec.timeout !== undefined &&\n (typeof spec.timeout !== \"number\" || !Number.isFinite(spec.timeout) || spec.timeout <= 0)\n ) {\n throw new TypeError(`hostMcpServers.${name}.timeout must be a positive number`);\n }\n parsedEntries.push([\n name,\n {\n type: spec.type,\n url: url.toString(),\n ...(headers ? { headers } : {}),\n ...(spec.timeout !== undefined ? { timeout: spec.timeout } : {}),\n },\n ]);\n }\n return Object.fromEntries(parsedEntries);\n}\n\nexport interface RuntimeGatewayTurnInput {\n topicId: string;\n /** Canonical principal on the execution node. */\n userId: string;\n /** Product-side actor, when it differs from the execution principal. */\n actorUserId?: string;\n /**\n * The node topic ids `actorUserId` may reach on the receiving node, as the\n * host's membership store sees it. Omitted by hosts that predate it; the\n * node then confines the turn's cross-room tools to the current room.\n */\n actorTopicScope?: ActorTopicScope;\n /**\n * Hub-issued per-turn authority for remote (`node/topic`) session-comm:\n * `{ hubUrl, capability }`. `hubUrl` must be a loopback `http://` or any\n * `https://` origin (≤ 512 chars); `capability` an opaque `rsc1.` bearer\n * (≤ 2 KiB) the node presents back to the hub and cannot verify — it holds\n * no key. It does base64-decode the payload's `e` (expiry) for one purpose,\n * ordering grants when several requests fold into one turn\n * (`remoteSessionGrantExpiry`); that value is untrusted and takes part in no\n * security decision. Omitted\n * by hosts that predate it or have the feature off; the node then keeps\n * remote session-comm fail-closed on the `otium` surface. Malformed → 400.\n */\n remoteSession?: RemoteSessionGrant;\n actorLabel?: string;\n vaultUserId?: string;\n /** Adapter provenance recorded on the canonical message. */\n sourceAdapter?: string;\n text: string;\n clientMessageId: string;\n requestId?: string;\n allowAutoContinue?: boolean;\n threadRootId?: string;\n /** Inline quote-reply target. Mutually exclusive with `threadRootId`. */\n parentId?: string;\n respond?: boolean;\n /**\n * While a turn from the same person runs: `true` (default) aborts it and\n * resumes with the merged batch; `false` queues this message behind it.\n */\n steer?: boolean;\n /**\n * While a turn from the same person runs: deliver this message into it, read\n * after the step it is on, and the work goes on (Codex-style steer). Wins over\n * `steer`; when the turn cannot take it, the message is queued behind it. A\n * node too old for this ignores the field, so send `steer: false` with it.\n */\n inject?: boolean;\n /**\n * While the room works, hold this message as a follow-up instead of queuing\n * a turn (`turn-follow-ups` capability; use `holdOrSubmitTurn`). Held, it\n * is not in the transcript and can be edited, moved, deleted or sent now; the\n * node sends held follow-ups one per turn once the room is idle.\n */\n hold?: boolean;\n /** Run without adding the injected prompt or output to the visible transcript. */\n silent?: boolean;\n attachments?: string[];\n visualTools?: boolean;\n fileDeliveryTools?: boolean;\n /** Host-owned remote MCP servers granted to this manager topic. */\n hostMcpServers?: Record<string, HostMcpServerSpec>;\n}\n\nexport interface RuntimeGatewayTurnAcknowledgement {\n ok: true;\n v: typeof RUNTIME_GATEWAY_VERSION;\n accepted: true;\n deduplicated: boolean;\n requestId: string;\n clientMessageId: string;\n topicId: string;\n messageId: string;\n /** Canonical persisted message when the Node supports inline ACK materialization. */\n message?: MessageDto;\n cursor: number;\n}\n\n/** A message held while the room worked (`turn-follow-ups`). */\nexport interface RuntimeGatewayFollowUp {\n id: string;\n text: string;\n actorUserId: string;\n attachments: AttachmentDto[];\n createdAt: string;\n}\n\n/** A room's held follow-ups, oldest first, and whether they wait after a stop. */\nexport interface RuntimeGatewayFollowUpLine {\n topicId: string;\n followUps: RuntimeGatewayFollowUp[];\n paused: boolean;\n}\n\nexport interface RuntimeGatewayHeldTurn {\n ok: true;\n v: typeof RUNTIME_GATEWAY_VERSION;\n accepted: true;\n held: true;\n clientMessageId: string;\n topicId: string;\n followUp: RuntimeGatewayFollowUp;\n}\n\nexport interface RuntimeGatewayFollowUpActor {\n /** Canonical principal on the execution node. */\n userId: string;\n /** The person who sent it; only they may change it. Defaults to `userId`. */\n actorUserId?: string;\n}\n\nexport interface RuntimeGatewayTopicDeriveInput {\n userId: string;\n copyHistory: boolean;\n name?: string;\n}\n\nexport interface RuntimeGatewayDerivedTopic {\n id: string;\n title: string;\n kind?: string;\n agent?: string;\n defaultModel?: string;\n defaultEffort?: string;\n parentTopicId?: string;\n isFork?: boolean;\n}\n\nexport interface RuntimeGatewaySseEvent {\n id?: number;\n event: string;\n data: unknown;\n}\n\nexport interface RuntimeGatewayTopicUsage {\n queries: number;\n inputTokens: number;\n outputTokens: number;\n cacheCreationInputTokens: number;\n cacheReadInputTokens: number;\n estimatedCostUsd: number;\n}\n\nexport interface RuntimeGatewayManagerTopic {\n id: string;\n title: string;\n kind: \"manager\";\n agent?: \"claude\" | \"codex\" | \"maestro\";\n participants: Array<{ userId: string; role: \"owner\" | \"member\" }>;\n}\n\nexport interface RuntimeGatewayDeletedMessage {\n id: string;\n topicId: string;\n authorId: string;\n text: string;\n deleted: true;\n createdAt: string;\n}\n\nexport interface RuntimeGatewayCronJob {\n id: string;\n name: string;\n executionPrincipalUserId: string;\n actorOwnerUserId: string;\n topicId: string;\n source: \"prompt\" | \"script\";\n script: string | null;\n scriptExists: boolean;\n prompt: string | null;\n promptPreview: string | null;\n summary: string | null;\n schedule: string;\n timezone: string | null;\n enabled: boolean;\n agent: \"claude\" | \"codex\" | \"maestro\" | null;\n model: string | null;\n effort: string | null;\n nextRunAt: string;\n runCount: number;\n lastRun: Record<string, unknown> | null;\n createdAt: string;\n updatedAt: string;\n canMutate: boolean;\n}\n\nexport interface RuntimeGatewayCronCreateInput {\n userId: string;\n actorUserId: string;\n topicId: string;\n name: string;\n script: string;\n schedule: string;\n timezone?: string;\n agent?: \"claude\" | \"codex\" | \"maestro\";\n model?: string;\n effort?: string;\n}\n\nexport interface RuntimeGatewayCronPatch {\n name?: string;\n topicId?: string;\n script?: string;\n schedule?: string;\n timezone?: string | null;\n enabled?: boolean;\n agent?: \"claude\" | \"codex\" | \"maestro\" | null;\n model?: string | null;\n effort?: string | null;\n}\n\nexport type RuntimeGatewayToken = string | (() => string | Promise<string>);\nexport type RuntimeGatewayFetch = (\n input: string | URL | Request,\n init?: RequestInit,\n) => Promise<Response>;\n\nexport interface RuntimeGatewayClientOptions {\n baseUrl: string;\n token: RuntimeGatewayToken;\n /** Loopback control path or an authenticated relay forward prefix. */\n pathPrefix?: string;\n fetch?: RuntimeGatewayFetch;\n requestTimeoutMs?: number;\n compactTimeoutMs?: number;\n}\n\nfunction record(value: unknown): Record<string, unknown> | null {\n return value && typeof value === \"object\" && !Array.isArray(value)\n ? (value as Record<string, unknown>)\n : null;\n}\n\nasync function json(response: Response): Promise<unknown> {\n try {\n return await response.json();\n } catch {\n throw new RuntimeGatewayError(\n \"Runtime Gateway returned invalid JSON\",\n \"protocol\",\n response.status,\n );\n }\n}\n\nfunction validHealth(value: unknown): value is RuntimeGatewayHealth {\n const body = record(value);\n return Boolean(\n body?.ok === true &&\n body.v === RUNTIME_GATEWAY_VERSION &&\n Array.isArray(body.capabilities) &&\n typeof body.cursor === \"number\",\n );\n}\n\nfunction validAcknowledgedMessage(value: unknown): value is MessageDto {\n const message = record(value);\n return Boolean(\n message &&\n typeof message.id === \"string\" &&\n typeof message.topicId === \"string\" &&\n typeof message.authorId === \"string\" &&\n typeof message.text === \"string\" &&\n typeof message.createdAt === \"string\",\n );\n}\n\nfunction validTurnAck(value: unknown): value is RuntimeGatewayTurnAcknowledgement {\n const body = record(value);\n return Boolean(\n body?.ok === true &&\n body.v === RUNTIME_GATEWAY_VERSION &&\n body.accepted === true &&\n typeof body.deduplicated === \"boolean\" &&\n typeof body.requestId === \"string\" &&\n typeof body.clientMessageId === \"string\" &&\n typeof body.topicId === \"string\" &&\n typeof body.messageId === \"string\" &&\n (body.message === undefined || validAcknowledgedMessage(body.message)) &&\n typeof body.cursor === \"number\",\n );\n}\n\nfunction validFollowUp(value: unknown): value is RuntimeGatewayFollowUp {\n const item = record(value);\n return Boolean(\n typeof item?.id === \"string\" &&\n typeof item.text === \"string\" &&\n typeof item.actorUserId === \"string\" &&\n Array.isArray(item.attachments) &&\n typeof item.createdAt === \"string\",\n );\n}\n\nfunction validFollowUpLine(value: unknown): value is RuntimeGatewayFollowUpLine {\n const body = record(value);\n return Boolean(\n typeof body?.topicId === \"string\" &&\n Array.isArray(body.followUps) &&\n body.followUps.every(validFollowUp) &&\n typeof body.paused === \"boolean\",\n );\n}\n\nfunction validHeldTurn(value: unknown): value is RuntimeGatewayHeldTurn {\n const body = record(value);\n return Boolean(\n body?.ok === true &&\n body.v === RUNTIME_GATEWAY_VERSION &&\n body.accepted === true &&\n body.held === true &&\n typeof body.clientMessageId === \"string\" &&\n typeof body.topicId === \"string\" &&\n validFollowUp(body.followUp),\n );\n}\n\nfunction validManagerTopic(value: unknown): value is RuntimeGatewayManagerTopic {\n const topic = record(value);\n return Boolean(\n typeof topic?.id === \"string\" &&\n typeof topic.title === \"string\" &&\n topic.kind === \"manager\" &&\n Array.isArray(topic.participants),\n );\n}\n\nfunction validDeletedMessage(value: unknown): value is RuntimeGatewayDeletedMessage {\n const message = record(value);\n return Boolean(\n typeof message?.id === \"string\" &&\n typeof message.topicId === \"string\" &&\n typeof message.authorId === \"string\" &&\n typeof message.text === \"string\" &&\n message.deleted === true &&\n typeof message.createdAt === \"string\",\n );\n}\n\nfunction validCronJob(value: unknown): value is RuntimeGatewayCronJob {\n const job = record(value);\n return Boolean(\n typeof job?.id === \"string\" &&\n typeof job.name === \"string\" &&\n typeof job.executionPrincipalUserId === \"string\" &&\n typeof job.actorOwnerUserId === \"string\" &&\n typeof job.topicId === \"string\" &&\n typeof job.schedule === \"string\" &&\n typeof job.enabled === \"boolean\" &&\n typeof job.nextRunAt === \"string\" &&\n typeof job.canMutate === \"boolean\",\n );\n}\n\nexport async function* parseRuntimeGatewaySse(\n body: ReadableStream<Uint8Array>,\n): AsyncGenerator<RuntimeGatewaySseEvent> {\n const reader = body.getReader();\n const decoder = new TextDecoder();\n let buffer = \"\";\n let event = \"message\";\n let id: number | undefined;\n let data: string[] = [];\n const flush = (): RuntimeGatewaySseEvent | null => {\n if (data.length === 0) return null;\n const raw = data.join(\"\\n\");\n data = [];\n try {\n return { event, id, data: JSON.parse(raw) };\n } catch {\n throw new RuntimeGatewayError(\"Runtime Gateway SSE event has invalid JSON\", \"protocol\");\n } finally {\n event = \"message\";\n id = undefined;\n }\n };\n try {\n while (true) {\n const chunk = await reader.read();\n if (chunk.done) break;\n buffer += decoder.decode(chunk.value, { stream: true }).replace(/\\r\\n/g, \"\\n\");\n let newline = buffer.indexOf(\"\\n\");\n while (newline >= 0) {\n const line = buffer.slice(0, newline);\n buffer = buffer.slice(newline + 1);\n if (line === \"\") {\n const parsed = flush();\n if (parsed) yield parsed;\n } else if (line.startsWith(\"event:\")) {\n event = line.slice(6).trim() || \"message\";\n } else if (line.startsWith(\"id:\")) {\n const parsed = Number.parseInt(line.slice(3).trim(), 10);\n if (Number.isFinite(parsed)) id = parsed;\n } else if (line.startsWith(\"data:\")) {\n data.push(line.slice(5).trimStart());\n }\n newline = buffer.indexOf(\"\\n\");\n }\n }\n buffer += decoder.decode();\n if (buffer.startsWith(\"data:\")) data.push(buffer.slice(5).trimStart());\n const parsed = flush();\n if (parsed) yield parsed;\n } finally {\n reader.releaseLock();\n }\n}\n\nexport class RuntimeGatewayClient {\n private readonly pathPrefix: string;\n private readonly request: RuntimeGatewayFetch;\n private readonly requestTimeoutMs: number;\n private readonly compactTimeoutMs: number;\n\n constructor(private readonly options: RuntimeGatewayClientOptions) {\n this.pathPrefix = options.pathPrefix ?? RUNTIME_GATEWAY_CONTROL_PATH;\n this.request = options.fetch ?? fetch;\n this.requestTimeoutMs = options.requestTimeoutMs ?? 5_000;\n this.compactTimeoutMs = options.compactTimeoutMs ?? 5 * 60_000;\n }\n\n private endpoint(path: string): string {\n if (!this.options.baseUrl || !this.options.token) {\n throw new RuntimeGatewayError(\"Runtime Gateway is not configured\", \"config\");\n }\n return `${this.options.baseUrl.replace(/\\/+$/, \"\")}${this.pathPrefix}${path}`;\n }\n\n private async authorization(): Promise<string> {\n try {\n const token =\n typeof this.options.token === \"function\" ? await this.options.token() : this.options.token;\n return `Bearer ${token}`;\n } catch (error) {\n throw new RuntimeGatewayError(\n error instanceof Error ? error.message : \"Runtime Gateway token resolution failed\",\n \"config\",\n );\n }\n }\n\n private async send(path: string, init: RequestInit, timeoutMs?: number): Promise<Response> {\n const authorization = await this.authorization();\n try {\n return await this.request(this.endpoint(path), {\n ...init,\n headers: { authorization, ...init.headers },\n signal: timeoutMs === undefined ? init.signal : AbortSignal.timeout(timeoutMs),\n });\n } catch (error) {\n if (error instanceof DOMException && error.name === \"TimeoutError\") {\n throw new RuntimeGatewayError(\"Runtime Gateway request timed out\", \"timeout\");\n }\n throw new RuntimeGatewayError(\"Runtime Gateway request failed\", \"transport\");\n }\n }\n\n async health(): Promise<RuntimeGatewayHealth> {\n const response = await this.send(\"/health\", { method: \"GET\" }, this.requestTimeoutMs);\n if (!response.ok) {\n throw new RuntimeGatewayError(\n \"Runtime Gateway health request failed\",\n \"http\",\n response.status,\n );\n }\n const body = await json(response);\n if (!validHealth(body)) {\n throw new RuntimeGatewayError(\"Runtime Gateway health response is incompatible\", \"protocol\");\n }\n return body;\n }\n\n async submitTurn(input: RuntimeGatewayTurnInput): Promise<RuntimeGatewayTurnAcknowledgement> {\n const response = await this.send(\n \"/turns\",\n {\n method: \"POST\",\n headers: { \"content-type\": \"application/json\" },\n body: JSON.stringify({ v: RUNTIME_GATEWAY_VERSION, ...input }),\n },\n this.requestTimeoutMs,\n );\n if (response.status !== 202) {\n throw new RuntimeGatewayError(\n \"Runtime Gateway turn was not accepted\",\n \"http\",\n response.status,\n );\n }\n const body = await json(response);\n if (!validTurnAck(body)) {\n throw new RuntimeGatewayError(\n \"Runtime Gateway turn acknowledgement is incompatible\",\n \"protocol\",\n );\n }\n return body;\n }\n\n /**\n * `submitTurn` with `hold: true`: while the room works the node holds the\n * message as a follow-up and answers with it; otherwise it is a turn as usual.\n */\n async holdOrSubmitTurn(\n input: RuntimeGatewayTurnInput,\n ): Promise<RuntimeGatewayTurnAcknowledgement | RuntimeGatewayHeldTurn> {\n const response = await this.send(\n \"/turns\",\n {\n method: \"POST\",\n headers: { \"content-type\": \"application/json\" },\n body: JSON.stringify({ v: RUNTIME_GATEWAY_VERSION, ...input, hold: true }),\n },\n this.requestTimeoutMs,\n );\n if (response.status !== 202) {\n throw new RuntimeGatewayError(\n \"Runtime Gateway turn was not accepted\",\n \"http\",\n response.status,\n );\n }\n const body = await json(response);\n if (validHeldTurn(body) || validTurnAck(body)) return body;\n throw new RuntimeGatewayError(\n \"Runtime Gateway turn acknowledgement is incompatible\",\n \"protocol\",\n );\n }\n\n async followUps(topicId: string, userId: string): Promise<RuntimeGatewayFollowUpLine> {\n const response = await this.send(\n `/topics/${encodeURIComponent(topicId)}/follow-ups?userId=${encodeURIComponent(userId)}`,\n { method: \"GET\" },\n this.requestTimeoutMs,\n );\n return this.followUpLineFrom(response, \"list\");\n }\n\n async editFollowUp(\n topicId: string,\n followUpId: string,\n actor: RuntimeGatewayFollowUpActor,\n text: string,\n ): Promise<RuntimeGatewayFollowUpLine> {\n return this.changeFollowUp(topicId, followUpId, \"\", \"PATCH\", { ...actor, text });\n }\n\n async deleteFollowUp(\n topicId: string,\n followUpId: string,\n actor: RuntimeGatewayFollowUpActor,\n ): Promise<RuntimeGatewayFollowUpLine> {\n return this.changeFollowUp(topicId, followUpId, \"\", \"DELETE\", { ...actor });\n }\n\n async moveFollowUp(\n topicId: string,\n followUpId: string,\n actor: RuntimeGatewayFollowUpActor,\n toIndex: number,\n ): Promise<RuntimeGatewayFollowUpLine> {\n return this.changeFollowUp(topicId, followUpId, \"/move\", \"POST\", { ...actor, toIndex });\n }\n\n /** 지금 보내기: into the running turn when it can take it, else as a turn of its own. */\n async sendFollowUpNow(\n topicId: string,\n followUpId: string,\n actor: RuntimeGatewayFollowUpActor,\n ): Promise<RuntimeGatewayFollowUpLine & { sent: boolean }> {\n const line = await this.changeFollowUp(topicId, followUpId, \"/send\", \"POST\", { ...actor });\n return line as RuntimeGatewayFollowUpLine & { sent: boolean };\n }\n\n private async changeFollowUp(\n topicId: string,\n followUpId: string,\n suffix: \"\" | \"/move\" | \"/send\",\n method: \"PATCH\" | \"DELETE\" | \"POST\",\n body: Record<string, unknown>,\n ): Promise<RuntimeGatewayFollowUpLine> {\n const response = await this.send(\n `/topics/${encodeURIComponent(topicId)}/follow-ups/${encodeURIComponent(followUpId)}${suffix}`,\n {\n method,\n headers: { \"content-type\": \"application/json\" },\n body: JSON.stringify({ v: RUNTIME_GATEWAY_VERSION, ...body }),\n },\n this.requestTimeoutMs,\n );\n return this.followUpLineFrom(response, method === \"PATCH\" ? \"edit\" : suffix || \"delete\");\n }\n\n private async followUpLineFrom(\n response: Response,\n what: string,\n ): Promise<RuntimeGatewayFollowUpLine> {\n if (!response.ok) {\n throw new RuntimeGatewayError(\n `Runtime Gateway follow-up ${what} failed`,\n \"http\",\n response.status,\n );\n }\n const body = await json(response);\n if (!validFollowUpLine(body)) {\n throw new RuntimeGatewayError(\n `Runtime Gateway follow-up ${what} response is incompatible`,\n \"protocol\",\n );\n }\n return body;\n }\n\n async deriveTopic(\n topicId: string,\n input: RuntimeGatewayTopicDeriveInput,\n ): Promise<RuntimeGatewayDerivedTopic> {\n const response = await this.send(\n `/topics/${encodeURIComponent(topicId)}/derive`,\n {\n method: \"POST\",\n headers: { \"content-type\": \"application/json\" },\n body: JSON.stringify({ v: RUNTIME_GATEWAY_VERSION, ...input }),\n },\n this.requestTimeoutMs,\n );\n if (response.status !== 201) {\n throw new RuntimeGatewayError(\"Runtime Gateway topic derive failed\", \"http\", response.status);\n }\n const body = await json(response);\n const topic = record(body)?.topic;\n const topicRecord = record(topic);\n if (\n !topicRecord ||\n typeof topicRecord.id !== \"string\" ||\n typeof topicRecord.title !== \"string\"\n ) {\n throw new RuntimeGatewayError(\n \"Runtime Gateway topic derive response is incompatible\",\n \"protocol\",\n );\n }\n return topic as unknown as RuntimeGatewayDerivedTopic;\n }\n\n async ensureManagerTopic(userId: string): Promise<RuntimeGatewayManagerTopic> {\n const response = await this.send(\n \"/manager-topic\",\n {\n method: \"POST\",\n headers: { \"content-type\": \"application/json\" },\n body: JSON.stringify({ v: RUNTIME_GATEWAY_VERSION, userId }),\n },\n this.requestTimeoutMs,\n );\n if (!response.ok) {\n throw new RuntimeGatewayError(\n \"Runtime Gateway manager topic request failed\",\n \"http\",\n response.status,\n );\n }\n const body = record(await json(response));\n if (body?.ok !== true || body.v !== RUNTIME_GATEWAY_VERSION || !validManagerTopic(body.topic)) {\n throw new RuntimeGatewayError(\n \"Runtime Gateway manager topic response is incompatible\",\n \"protocol\",\n );\n }\n return body.topic;\n }\n\n async deleteMessage(\n topicId: string,\n messageId: string,\n actorUserId: string,\n allowAdmin = false,\n ): Promise<RuntimeGatewayDeletedMessage> {\n const response = await this.send(\n `/topics/${encodeURIComponent(topicId)}/messages/${encodeURIComponent(messageId)}`,\n {\n method: \"DELETE\",\n headers: { \"content-type\": \"application/json\" },\n body: JSON.stringify({\n v: RUNTIME_GATEWAY_VERSION,\n actorUserId,\n ...(allowAdmin ? { allowAdmin: true } : {}),\n }),\n },\n this.requestTimeoutMs,\n );\n if (!response.ok) {\n throw new RuntimeGatewayError(\n \"Runtime Gateway message delete failed\",\n \"http\",\n response.status,\n );\n }\n const body = record(await json(response));\n if (\n body?.ok !== true ||\n body.v !== RUNTIME_GATEWAY_VERSION ||\n !validDeletedMessage(body.message)\n ) {\n throw new RuntimeGatewayError(\n \"Runtime Gateway message delete response is incompatible\",\n \"protocol\",\n );\n }\n return body.message;\n }\n\n private async cronRequest(path: string, init: RequestInit): Promise<Record<string, unknown>> {\n const response = await this.send(path, init, this.requestTimeoutMs);\n if (!response.ok) {\n throw new RuntimeGatewayError(\"Runtime Gateway cron request failed\", \"http\", response.status);\n }\n const body = record(await json(response));\n if (body?.ok !== true || body.v !== RUNTIME_GATEWAY_VERSION) {\n throw new RuntimeGatewayError(\"Runtime Gateway cron response is incompatible\", \"protocol\");\n }\n return body;\n }\n\n async listCronScripts(): Promise<string[]> {\n const body = await this.cronRequest(\"/cron/scripts\", { method: \"GET\" });\n if (!Array.isArray(body.scripts) || !body.scripts.every((value) => typeof value === \"string\")) {\n throw new RuntimeGatewayError(\"Runtime Gateway cron scripts are incompatible\", \"protocol\");\n }\n return body.scripts;\n }\n\n async listCronJobs(\n userId: string,\n actorUserId: string,\n actorIsAdmin = false,\n ): Promise<RuntimeGatewayCronJob[]> {\n const search = new URLSearchParams({\n user: userId,\n actorUserId,\n actorIsAdmin: actorIsAdmin ? \"1\" : \"0\",\n });\n const body = await this.cronRequest(`/cron/jobs?${search}`, { method: \"GET\" });\n if (!Array.isArray(body.jobs) || !body.jobs.every(validCronJob)) {\n throw new RuntimeGatewayError(\"Runtime Gateway cron jobs are incompatible\", \"protocol\");\n }\n return body.jobs;\n }\n\n async createCronJob(input: RuntimeGatewayCronCreateInput): Promise<RuntimeGatewayCronJob> {\n const body = await this.cronRequest(\"/cron/jobs\", {\n method: \"POST\",\n headers: { \"content-type\": \"application/json\" },\n body: JSON.stringify({ v: RUNTIME_GATEWAY_VERSION, ...input }),\n });\n if (!validCronJob(body.job)) {\n throw new RuntimeGatewayError(\"Runtime Gateway cron job is incompatible\", \"protocol\");\n }\n return body.job;\n }\n\n async updateCronJob(\n jobId: string,\n userId: string,\n actorUserId: string,\n patch: RuntimeGatewayCronPatch,\n actorIsAdmin = false,\n ): Promise<RuntimeGatewayCronJob> {\n const body = await this.cronRequest(`/cron/jobs/${encodeURIComponent(jobId)}`, {\n method: \"PATCH\",\n headers: { \"content-type\": \"application/json\" },\n body: JSON.stringify({\n v: RUNTIME_GATEWAY_VERSION,\n userId,\n actorUserId,\n actorIsAdmin,\n patch,\n }),\n });\n if (!validCronJob(body.job)) {\n throw new RuntimeGatewayError(\"Runtime Gateway cron job is incompatible\", \"protocol\");\n }\n return body.job;\n }\n\n async deleteCronJob(\n jobId: string,\n userId: string,\n actorUserId: string,\n actorIsAdmin = false,\n ): Promise<string> {\n const search = new URLSearchParams({\n user: userId,\n actorUserId,\n actorIsAdmin: actorIsAdmin ? \"1\" : \"0\",\n });\n const body = await this.cronRequest(`/cron/jobs/${encodeURIComponent(jobId)}?${search}`, {\n method: \"DELETE\",\n });\n if (typeof body.deleted !== \"string\") {\n throw new RuntimeGatewayError(\"Runtime Gateway cron delete is incompatible\", \"protocol\");\n }\n return body.deleted;\n }\n\n async *events(\n after: number,\n topicId?: string,\n signal?: AbortSignal,\n ): AsyncGenerator<RuntimeGatewaySseEvent> {\n const search = new URLSearchParams({ after: String(Math.max(0, after)) });\n if (topicId) search.set(\"topicId\", topicId);\n const response = await this.send(`/events?${search}`, { method: \"GET\", signal });\n if (!response.ok || !response.body) {\n throw new RuntimeGatewayError(\"Runtime Gateway event stream failed\", \"http\", response.status);\n }\n yield* parseRuntimeGatewaySse(response.body);\n }\n\n async getTopicUsage(topicId: string, userId: string): Promise<RuntimeGatewayTopicUsage> {\n const response = await this.send(\n `/topics/${encodeURIComponent(topicId)}/usage?user=${encodeURIComponent(userId)}`,\n { method: \"GET\" },\n this.requestTimeoutMs,\n );\n if (!response.ok) {\n throw new RuntimeGatewayError(\n \"Runtime Gateway topic usage request failed\",\n \"http\",\n response.status,\n );\n }\n const usage = record(record(await json(response))?.usage);\n const read = (key: keyof RuntimeGatewayTopicUsage): number => {\n const value = usage?.[key];\n return typeof value === \"number\" && Number.isFinite(value) ? value : 0;\n };\n return {\n queries: read(\"queries\"),\n inputTokens: read(\"inputTokens\"),\n outputTokens: read(\"outputTokens\"),\n cacheCreationInputTokens: read(\"cacheCreationInputTokens\"),\n cacheReadInputTokens: read(\"cacheReadInputTokens\"),\n estimatedCostUsd: read(\"estimatedCostUsd\"),\n };\n }\n\n async abortTurn(topicId: string, userId: string): Promise<boolean> {\n const response = await this.send(\n `/topics/${encodeURIComponent(topicId)}/abort`,\n {\n method: \"POST\",\n headers: { \"content-type\": \"application/json\" },\n body: JSON.stringify({ v: RUNTIME_GATEWAY_VERSION, userId }),\n },\n this.requestTimeoutMs,\n );\n if (!response.ok) {\n throw new RuntimeGatewayError(\"Runtime Gateway turn abort failed\", \"http\", response.status);\n }\n const body = record(await json(response));\n if (\n body?.ok !== true ||\n body.v !== RUNTIME_GATEWAY_VERSION ||\n typeof body.aborted !== \"boolean\"\n ) {\n throw new RuntimeGatewayError(\n \"Runtime Gateway turn abort response is incompatible\",\n \"protocol\",\n );\n }\n return body.aborted;\n }\n\n async resetSession(\n topicId: string,\n userId: string,\n reason?: string,\n actorUserId?: string,\n ): Promise<string | undefined> {\n return this.sessionCommand(topicId, userId, \"reset\", reason, actorUserId);\n }\n\n async compactSession(\n topicId: string,\n userId: string,\n reason?: string,\n actorUserId?: string,\n ): Promise<string | undefined> {\n return this.sessionCommand(topicId, userId, \"compact\", reason, actorUserId);\n }\n\n private async sessionCommand(\n topicId: string,\n userId: string,\n command: \"reset\" | \"compact\",\n reason?: string,\n actorUserId?: string,\n ): Promise<string | undefined> {\n const response = await this.send(\n `/topics/${encodeURIComponent(topicId)}/session/${command}`,\n {\n method: \"POST\",\n headers: { \"content-type\": \"application/json\" },\n body: JSON.stringify({\n v: RUNTIME_GATEWAY_VERSION,\n userId,\n ...(actorUserId ? { actorUserId } : {}),\n ...(reason ? { reason } : {}),\n }),\n },\n command === \"compact\" ? this.compactTimeoutMs : this.requestTimeoutMs,\n );\n if (!response.ok) {\n throw new RuntimeGatewayError(\n `Runtime Gateway session ${command} failed`,\n \"http\",\n response.status,\n );\n }\n const body = record(await json(response));\n if (body?.ok !== true || body.v !== RUNTIME_GATEWAY_VERSION) {\n throw new RuntimeGatewayError(\n `Runtime Gateway session ${command} response is incompatible`,\n \"protocol\",\n );\n }\n return typeof body.result === \"string\" ? body.result : undefined;\n }\n}\n"
6
+ ],
7
+ "mappings": ";;AAGO,IAAM,0BAA0B;AAChC,IAAM,+BAA+B;AAAA;AAIrC,MAAM,4BAA4B,MAAM;AAAA,EAG3B;AAAA,EACA;AAAA,EAHlB,WAAW,CACT,SACgB,MACA,QAChB;AAAA,IACA,MAAM,OAAO;AAAA,IAHG;AAAA,IACA;AAAA;AAIpB;AAmBA,IAAM,uBAAuB;AAC7B,IAAM,uBAAuB,IAAI,IAAI,CAAC,QAAQ,OAAO,WAAW,SAAS,CAAC;AAC1E,IAAM,mBAAmB;AAGlB,SAAS,mBAAmB,CAAC,OAA+D;AAAA,EACjG,IAAI,UAAU;AAAA,IAAW;AAAA,EACzB,IAAI,CAAC,SAAS,OAAO,UAAU,YAAY,MAAM,QAAQ,KAAK,GAAG;AAAA,IAC/D,MAAM,IAAI,UAAU,kCAAkC;AAAA,EACxD;AAAA,EACA,MAAM,gBAAoD,CAAC;AAAA,EAC3D,YAAY,MAAM,QAAQ,OAAO,QAAQ,KAAK,GAAG;AAAA,IAC/C,IAAI,CAAC,qBAAqB,KAAK,IAAI,GAAG;AAAA,MACpC,MAAM,IAAI,UAAU,iCAAiC,MAAM;AAAA,IAC7D;AAAA,IACA,IAAI,CAAC,OAAO,OAAO,QAAQ,YAAY,MAAM,QAAQ,GAAG,GAAG;AAAA,MACzD,MAAM,IAAI,UAAU,kBAAkB,wBAAwB;AAAA,IAChE;AAAA,IACA,MAAM,OAAO;AAAA,IACb,MAAM,cAAc,OAAO,KAAK,IAAI,EAAE,KAAK,CAA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