@nylorun/runtime 0.13.0-beta → 0.15.0-beta

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 (309) hide show
  1. package/CHANGELOG.md +434 -0
  2. package/README.md +137 -41
  3. package/dist/adapters/execution/restate.d.ts +7 -2
  4. package/dist/adapters/execution/restate.js +40 -10
  5. package/dist/adapters/replication/pgoutput.d.ts +21 -0
  6. package/dist/adapters/replication/pgoutput.js +170 -0
  7. package/dist/adapters/streams/s2.js +37 -20
  8. package/dist/admin-openapi.json +570 -0
  9. package/dist/api/a2a/card.d.ts +15 -0
  10. package/dist/api/a2a/card.js +24 -0
  11. package/dist/api/a2a/endpoint.d.ts +8 -0
  12. package/dist/api/a2a/endpoint.js +81 -0
  13. package/dist/api/a2a/protocol.d.ts +144 -0
  14. package/dist/api/a2a/protocol.js +188 -0
  15. package/dist/api/a2a/routes.d.ts +19 -0
  16. package/dist/api/a2a/routes.js +289 -0
  17. package/dist/api/a2a/tasks.d.ts +50 -0
  18. package/dist/api/a2a/tasks.js +186 -0
  19. package/dist/api/ag-ui/endpoint.d.ts +8 -0
  20. package/dist/api/ag-ui/endpoint.js +126 -0
  21. package/dist/api/ag-ui/history.d.ts +7 -0
  22. package/dist/api/ag-ui/history.js +60 -0
  23. package/dist/api/ag-ui/routes.d.ts +32 -0
  24. package/dist/api/ag-ui/routes.js +305 -0
  25. package/dist/api/ag-ui/session-id.d.ts +1 -0
  26. package/dist/api/ag-ui/session-id.js +12 -0
  27. package/dist/api/ag-ui/sse.d.ts +9 -0
  28. package/dist/api/ag-ui/sse.js +7 -0
  29. package/dist/api/ag-ui/translate.d.ts +38 -0
  30. package/dist/api/ag-ui/translate.js +222 -0
  31. package/dist/api/components.d.ts +8065 -0
  32. package/dist/api/components.js +82 -0
  33. package/dist/api/gate/keys.d.ts +14 -0
  34. package/dist/api/gate/keys.js +59 -0
  35. package/dist/api/gate/routes.d.ts +34 -0
  36. package/dist/api/gate/routes.js +235 -0
  37. package/dist/api/http/app.d.ts +18 -0
  38. package/dist/api/http/app.js +58 -0
  39. package/dist/api/http/body.d.ts +4 -0
  40. package/dist/api/http/body.js +37 -0
  41. package/dist/api/http/define.d.ts +39 -0
  42. package/dist/api/http/define.js +122 -0
  43. package/dist/api/http/respond.d.ts +9 -0
  44. package/dist/api/http/respond.js +44 -0
  45. package/dist/api/http/routes/access.d.ts +24 -0
  46. package/dist/api/http/routes/access.js +266 -0
  47. package/dist/api/http/routes/actions.d.ts +8 -0
  48. package/dist/api/http/routes/actions.js +76 -0
  49. package/dist/api/http/routes/endpoints.d.ts +7 -0
  50. package/dist/api/http/routes/endpoints.js +100 -0
  51. package/dist/api/http/routes/sessions.d.ts +3 -0
  52. package/dist/api/http/routes/sessions.js +205 -0
  53. package/dist/api/http/routes/tenant.d.ts +11 -0
  54. package/dist/api/http/routes/tenant.js +244 -0
  55. package/dist/api/http/routes/vaults.d.ts +8 -0
  56. package/dist/api/http/routes/vaults.js +167 -0
  57. package/dist/api/openapi.d.ts +19 -0
  58. package/dist/api/openapi.js +137 -0
  59. package/dist/api/route.d.ts +12 -0
  60. package/dist/api/route.js +4 -0
  61. package/dist/core/bearer.d.ts +8 -0
  62. package/dist/core/bearer.js +11 -0
  63. package/dist/core/flow-host.d.ts +7 -15
  64. package/dist/core/flow-host.js +16 -41
  65. package/dist/core/sandbox-routes.d.ts +12 -7
  66. package/dist/core/sandbox-routes.js +24 -25
  67. package/dist/execution/memory.d.ts +8 -5
  68. package/dist/execution/memory.js +33 -13
  69. package/dist/execution/types.d.ts +38 -6
  70. package/dist/execution/types.js +12 -3
  71. package/dist/gates/contract.d.ts +51 -0
  72. package/dist/gates/contract.js +37 -0
  73. package/dist/gates/handler.d.ts +21 -0
  74. package/dist/gates/handler.js +55 -0
  75. package/dist/gates/http-client.d.ts +12 -0
  76. package/dist/gates/http-client.js +160 -0
  77. package/dist/gates/in-process.d.ts +32 -0
  78. package/dist/gates/in-process.js +42 -0
  79. package/dist/gates/inflight.d.ts +39 -0
  80. package/dist/gates/inflight.js +70 -0
  81. package/dist/gates/mcp-handler.d.ts +35 -0
  82. package/dist/gates/mcp-handler.js +142 -0
  83. package/dist/gates/meter.d.ts +24 -0
  84. package/dist/gates/meter.js +165 -0
  85. package/dist/gates/model-gate.d.ts +45 -0
  86. package/dist/gates/model-gate.js +1 -0
  87. package/dist/gates/tenant-vaults.d.ts +64 -0
  88. package/dist/gates/tenant-vaults.js +94 -0
  89. package/dist/gates/tool-calls.d.ts +51 -0
  90. package/dist/gates/tool-calls.js +64 -0
  91. package/dist/gates/tool-client.d.ts +12 -0
  92. package/dist/gates/tool-client.js +201 -0
  93. package/dist/gates/tool-contract.d.ts +116 -0
  94. package/dist/gates/tool-contract.js +64 -0
  95. package/dist/gates/tool-gate.d.ts +45 -0
  96. package/dist/gates/tool-gate.js +10 -0
  97. package/dist/host/admin-api.d.ts +23 -0
  98. package/dist/host/admin-api.js +74 -0
  99. package/dist/host/app.d.ts +34 -0
  100. package/dist/host/app.js +181 -0
  101. package/dist/host/config-for.d.ts +3 -1
  102. package/dist/host/config-for.js +3 -2
  103. package/dist/host/config.d.ts +11 -0
  104. package/dist/host/cors.d.ts +27 -0
  105. package/dist/host/cors.js +64 -0
  106. package/dist/host/create-host.d.ts +36 -8
  107. package/dist/host/create-host.js +161 -330
  108. package/dist/host/execution.d.ts +20 -18
  109. package/dist/host/execution.js +2 -2
  110. package/dist/host/gates.d.ts +58 -0
  111. package/dist/host/gates.js +127 -0
  112. package/dist/host/http.d.ts +20 -4
  113. package/dist/host/http.js +81 -23
  114. package/dist/host/index.d.ts +1 -1
  115. package/dist/host/main.js +189 -58
  116. package/dist/host/stack-config.d.ts +91 -19
  117. package/dist/host/stack-config.js +246 -17
  118. package/dist/infra/database.d.ts +2 -2
  119. package/dist/infra/execution.d.ts +5 -5
  120. package/dist/infra/execution.js +8 -6
  121. package/dist/infra/index.d.ts +1 -1
  122. package/dist/infra/workers.d.ts +17 -17
  123. package/dist/infra/workers.js +9 -9
  124. package/dist/keys/client.d.ts +9 -0
  125. package/dist/keys/client.js +70 -0
  126. package/dist/keys/contract.d.ts +24 -0
  127. package/dist/keys/contract.js +12 -0
  128. package/dist/keys/keys.d.ts +41 -0
  129. package/dist/keys/keys.js +50 -0
  130. package/dist/mcp/connect.d.ts +43 -3
  131. package/dist/mcp/connect.js +12 -5
  132. package/dist/mcp/pool.d.ts +39 -3
  133. package/dist/mcp/pool.js +74 -11
  134. package/dist/model/catalog.d.ts +2 -10
  135. package/dist/model/classify.d.ts +13 -0
  136. package/dist/model/classify.js +61 -0
  137. package/dist/model/models.d.ts +10 -1
  138. package/dist/model/models.js +14 -6
  139. package/dist/model/pi-model.d.ts +17 -2
  140. package/dist/model/pi-model.js +366 -222
  141. package/dist/openapi.json +25889 -0
  142. package/dist/record/append.d.ts +51 -0
  143. package/dist/record/append.js +20 -0
  144. package/dist/record/envelope.d.ts +19 -0
  145. package/dist/record/envelope.js +49 -0
  146. package/dist/record/index.d.ts +11 -0
  147. package/dist/record/index.js +11 -0
  148. package/dist/sandbox/manager.d.ts +13 -1
  149. package/dist/sandbox/manager.js +8 -11
  150. package/dist/sandbox/resolve.d.ts +33 -0
  151. package/dist/sandbox/resolve.js +81 -0
  152. package/dist/sandbox/session-sandbox.d.ts +11 -0
  153. package/dist/sandbox/session-sandbox.js +51 -0
  154. package/dist/sandbox/share.d.ts +14 -2
  155. package/dist/sandbox/share.js +33 -3
  156. package/dist/sandbox/tenant-config.d.ts +37 -0
  157. package/dist/sandbox/tenant-config.js +51 -0
  158. package/dist/sandbox/tools.d.ts +7 -9
  159. package/dist/sandbox/tools.js +11 -3
  160. package/dist/sandbox/types.d.ts +8 -2
  161. package/dist/store/postgres/connect.d.ts +25 -9
  162. package/dist/store/postgres/connect.js +27 -10
  163. package/dist/store/postgres/db.d.ts +16 -0
  164. package/dist/store/postgres/db.js +28 -0
  165. package/dist/store/postgres/drizzle/0000_foundation.sql +22 -0
  166. package/dist/store/postgres/drizzle/0001_baseline.sql +255 -0
  167. package/dist/store/postgres/drizzle/0002_stream_relay.sql +4 -0
  168. package/dist/store/postgres/drizzle/0003_tool_crossings.sql +9 -0
  169. package/dist/store/postgres/drizzle/meta/_journal.json +34 -0
  170. package/dist/store/postgres/migrate.d.ts +68 -0
  171. package/dist/store/postgres/migrate.js +183 -0
  172. package/dist/store/postgres/record-writer.d.ts +4 -0
  173. package/dist/store/postgres/record-writer.js +34 -0
  174. package/dist/store/postgres/record.d.ts +5 -0
  175. package/dist/store/postgres/record.js +60 -0
  176. package/dist/store/postgres/schema.d.ts +3096 -0
  177. package/dist/store/postgres/schema.js +363 -0
  178. package/dist/store/postgres/store.d.ts +2 -4
  179. package/dist/store/postgres/store.js +590 -434
  180. package/dist/store/postgres/tenant.d.ts +56 -0
  181. package/dist/store/postgres/tenant.js +154 -0
  182. package/dist/store/types.d.ts +183 -132
  183. package/dist/store/types.js +0 -1
  184. package/dist/streams/basin.d.ts +18 -1
  185. package/dist/streams/basin.js +34 -2
  186. package/dist/streams/control.d.ts +18 -0
  187. package/dist/streams/control.js +33 -0
  188. package/dist/streams/memory.d.ts +3 -1
  189. package/dist/streams/memory.js +14 -8
  190. package/dist/streams/relay/core.d.ts +35 -0
  191. package/dist/streams/relay/core.js +366 -0
  192. package/dist/streams/relay/types.d.ts +78 -0
  193. package/dist/streams/relay/types.js +8 -0
  194. package/dist/streams/types.d.ts +71 -36
  195. package/dist/streams/types.js +18 -53
  196. package/dist/tenant/access-policy.d.ts +30 -0
  197. package/dist/tenant/access-policy.js +52 -0
  198. package/dist/tenant/actions.d.ts +10 -149
  199. package/dist/tenant/actions.js +5 -167
  200. package/dist/tenant/advance.d.ts +7 -2
  201. package/dist/tenant/advance.js +125 -14
  202. package/dist/tenant/auth.d.ts +19 -17
  203. package/dist/tenant/auth.js +90 -93
  204. package/dist/tenant/browser.d.ts +15 -0
  205. package/dist/tenant/browser.js +39 -0
  206. package/dist/tenant/cause.d.ts +25 -0
  207. package/dist/tenant/cause.js +45 -0
  208. package/dist/tenant/commands.d.ts +18 -2
  209. package/dist/tenant/commands.js +111 -115
  210. package/dist/tenant/context.d.ts +101 -21
  211. package/dist/tenant/context.js +14 -10
  212. package/dist/tenant/delivery-token.d.ts +41 -0
  213. package/dist/tenant/delivery-token.js +104 -0
  214. package/dist/tenant/delivery.d.ts +62 -0
  215. package/dist/tenant/delivery.js +481 -0
  216. package/dist/tenant/effects.d.ts +20 -1
  217. package/dist/tenant/effects.js +159 -42
  218. package/dist/tenant/endpoints.d.ts +67 -0
  219. package/dist/tenant/endpoints.js +90 -0
  220. package/dist/tenant/ephemeral.d.ts +22 -7
  221. package/dist/tenant/ephemeral.js +83 -125
  222. package/dist/tenant/history.d.ts +64 -0
  223. package/dist/tenant/history.js +120 -0
  224. package/dist/tenant/http.d.ts +8 -9
  225. package/dist/tenant/http.js +13 -27
  226. package/dist/tenant/jwt.d.ts +16 -0
  227. package/dist/tenant/jwt.js +50 -0
  228. package/dist/tenant/model-setting.d.ts +2 -2
  229. package/dist/tenant/module.d.ts +17 -28
  230. package/dist/tenant/module.js +133 -279
  231. package/dist/tenant/outbound.d.ts +44 -0
  232. package/dist/tenant/outbound.js +127 -0
  233. package/dist/tenant/paths.d.ts +11 -16
  234. package/dist/tenant/paths.js +24 -68
  235. package/dist/tenant/pool.d.ts +1 -3
  236. package/dist/tenant/pool.js +1 -19
  237. package/dist/tenant/principals.d.ts +23 -11
  238. package/dist/tenant/principals.js +61 -49
  239. package/dist/tenant/reset.d.ts +0 -4
  240. package/dist/tenant/reset.js +0 -5
  241. package/dist/tenant/runtime.d.ts +28 -20
  242. package/dist/tenant/runtime.js +95 -64
  243. package/dist/tenant/scheduler.d.ts +10 -3
  244. package/dist/tenant/scheduler.js +9 -5
  245. package/dist/tenant/session-streams.d.ts +127 -0
  246. package/dist/tenant/session-streams.js +404 -0
  247. package/dist/tenant/sessions.d.ts +28 -4
  248. package/dist/tenant/sessions.js +118 -24
  249. package/dist/tenant/signing-keys.d.ts +55 -0
  250. package/dist/tenant/signing-keys.js +172 -0
  251. package/dist/tenant/slim.d.ts +8 -0
  252. package/dist/tenant/slim.js +21 -0
  253. package/dist/tenant/status.d.ts +3 -3
  254. package/dist/tenant/status.js +20 -13
  255. package/dist/tenant/store-pg.d.ts +9 -6
  256. package/dist/tenant/store-pg.js +60 -125
  257. package/dist/tenant/streams.d.ts +62 -85
  258. package/dist/tenant/streams.js +143 -226
  259. package/dist/tenant/subject-limits.d.ts +16 -0
  260. package/dist/tenant/subject-limits.js +45 -0
  261. package/dist/tenant/sweep.d.ts +1 -10
  262. package/dist/tenant/sweep.js +29 -69
  263. package/dist/tenant/tokens.d.ts +14 -0
  264. package/dist/tenant/tokens.js +180 -0
  265. package/dist/tenant/transcript.d.ts +48 -5
  266. package/dist/tenant/transcript.js +58 -1
  267. package/dist/tenant/types.d.ts +69 -98
  268. package/dist/tenant/types.js +4 -15
  269. package/dist/tenant/worker.d.ts +3 -1
  270. package/dist/tenant/worker.js +13 -7
  271. package/dist/vault/host-model.d.ts +31 -0
  272. package/dist/vault/host-model.js +57 -0
  273. package/dist/vault/service.d.ts +44 -17
  274. package/dist/vault/service.js +126 -121
  275. package/dist/version.d.ts +1 -1
  276. package/dist/version.js +1 -1
  277. package/package.json +25 -9
  278. package/dist/core/executors.d.ts +0 -44
  279. package/dist/core/executors.js +0 -95
  280. package/dist/store/memory.d.ts +0 -57
  281. package/dist/store/memory.js +0 -645
  282. package/dist/store/postgres/migrations/001_initial.d.ts +0 -27
  283. package/dist/store/postgres/migrations/001_initial.js +0 -196
  284. package/dist/store/postgres/migrations/002_session_owner.d.ts +0 -6
  285. package/dist/store/postgres/migrations/002_session_owner.js +0 -13
  286. package/dist/store/postgres/migrations/index.d.ts +0 -49
  287. package/dist/store/postgres/migrations/index.js +0 -76
  288. package/dist/store/postgres/names.d.ts +0 -11
  289. package/dist/store/postgres/names.js +0 -42
  290. package/dist/store/postgres/tenants.d.ts +0 -90
  291. package/dist/store/postgres/tenants.js +0 -214
  292. package/dist/streams/relay.d.ts +0 -37
  293. package/dist/streams/relay.js +0 -254
  294. package/dist/tenant/envelope.d.ts +0 -7
  295. package/dist/tenant/envelope.js +0 -22
  296. package/dist/tenant/live.d.ts +0 -92
  297. package/dist/tenant/live.js +0 -290
  298. package/dist/tenant/quarantine-error.d.ts +0 -6
  299. package/dist/tenant/quarantine-error.js +0 -9
  300. package/dist/tenant/quarantine.d.ts +0 -27
  301. package/dist/tenant/quarantine.js +0 -72
  302. package/dist/tenant/routes-tenant.d.ts +0 -12
  303. package/dist/tenant/routes-tenant.js +0 -137
  304. package/dist/tenant/routes.d.ts +0 -9
  305. package/dist/tenant/routes.js +0 -151
  306. package/dist/tenant/store-memory.d.ts +0 -16
  307. package/dist/tenant/store-memory.js +0 -111
  308. /package/dist/{store → record}/cursor.d.ts +0 -0
  309. /package/dist/{store → record}/cursor.js +0 -0
@@ -5,12 +5,12 @@
5
5
  *
6
6
  * ## Layout
7
7
  *
8
- * - One basin per Tenant, named by `tenantBasinName` (`streams/basin.ts`):
9
- * `<basinPrefix>tn-<ulid>` for a Tenant id `tn_<ulid>`.
10
- * - The basin is created with `createStreamOnAppend`, so `sessions/<id>/<incarnation>`,
11
- * `tenant/work` and `tenant/control` come into existence on their first
12
- * append. Its default stream config sets infinite retention, which session
13
- * streams keep; the work and control streams are created with a one-day
8
+ * - One basin per Tenant basin generation, named by `tenantBasinName` (`streams/basin.ts`):
9
+ * `<basinPrefix>tn-<ulid>` for a Tenant id `tn_<ulid>`, `…-<g base36>` for generation g.
10
+ * - The basin is created with `createStreamOnAppend` and `createStreamOnRead`, so
11
+ * `sessions/<id>` and `tenant/control` come into existence on first use. Its
12
+ * default stream config sets infinite retention, which session streams
13
+ * keep; the control stream is created with a one-day
14
14
  * age-based retention instead (signals are latency hints, not history).
15
15
  * - Bodies are JSON text in string records. Record timestamps are S2 arrival
16
16
  * times.
@@ -27,7 +27,7 @@
27
27
  * explicit `{ infinite: {} }` retention to keep session history; this adapter
28
28
  * sets it as the basin default, and s2-lite honours it (a new stream reports
29
29
  * `infinite`). A `streamConfig` sent with an append that creates the stream
30
- * is honoured too (used for the work and control streams). `deleteOnEmpty`
30
+ * is honoured too (used for the control stream). `deleteOnEmpty`
31
31
  * defaults to disabled (`minAgeSecs: 0`).
32
32
  * - **Stream deletion** is immediate for our purposes: right after `DELETE`,
33
33
  * `checkTail` and reads return 404 `stream_not_found` (new read sessions
@@ -58,9 +58,9 @@
58
58
  * use the SDK's HTTP/2 (s2s) transport, which s2-lite serves over cleartext.
59
59
  */
60
60
  import { AppendInput, AppendRecord, RangeNotSatisfiableError, S2, S2Error, SeqNumMismatchError, } from "@s2-dev/streamstore";
61
- import { tenantBasinName, validateBasinPrefix } from "../../streams/basin.js";
62
- import { CONTROL_STREAM, WORK_STREAM, } from "../../streams/types.js";
63
- /** Retention of the work and control signal streams. */
61
+ import { parseBasin, tenantBasinName, validateBasinPrefix } from "../../streams/basin.js";
62
+ import { CONTROL_STREAM, } from "../../streams/types.js";
63
+ /** Retention of the control signal stream. */
64
64
  const SIGNAL_RETENTION_SECS = 24 * 60 * 60;
65
65
  /** Records per unary read while reading history. */
66
66
  const HISTORY_PAGE = 1000;
@@ -99,7 +99,7 @@ class S2Streams {
99
99
  return AppendRecord.string({ body });
100
100
  }), {
101
101
  ...(options.matchSeq !== undefined ? { matchSeqNum: options.matchSeq } : {}),
102
- ...(stream === WORK_STREAM || stream === CONTROL_STREAM
102
+ ...(stream === CONTROL_STREAM
103
103
  ? { streamConfig: { retentionPolicy: { ageSecs: SIGNAL_RETENTION_SECS } } }
104
104
  : {}),
105
105
  });
@@ -155,6 +155,9 @@ class S2Streams {
155
155
  basin,
156
156
  config: {
157
157
  createStreamOnAppend: true,
158
+ // A reader that arrives before a session's first event creates the
159
+ // stream and follows it live, instead of polling until it exists.
160
+ createStreamOnRead: true,
158
161
  defaultStreamConfig: { retentionPolicy: { infinite: {} } },
159
162
  },
160
163
  }, { signal: this.closing.signal });
@@ -171,15 +174,24 @@ class S2Streams {
171
174
  }
172
175
  }
173
176
  }
174
- async deleteTenant(tenantId) {
177
+ async deleteTenant(tenantId, options = {}) {
175
178
  this.checkOpen();
176
- try {
177
- await this.s2.basins.delete({ basin: this.basinName(tenantId) }, { signal: this.closing.signal });
178
- }
179
- catch (error) {
180
- if (!isMissing(error))
181
- throw error;
179
+ const basins = [this.basinName(tenantId)];
180
+ // Every later generation's basin too: `<basin>-<g base36>`.
181
+ if (options.allGenerations && parseBasin(tenantId).generation === 0) {
182
+ const later = new RegExp(`^${escapeRegExp(basins[0])}-[0-9a-z]{1,2}$`);
183
+ for await (const info of this.s2.basins.listAll({ prefix: `${basins[0]}-` }, { signal: this.closing.signal }))
184
+ if (later.test(info.name) && info.deletedAt == null)
185
+ basins.push(info.name);
182
186
  }
187
+ for (const basin of basins)
188
+ try {
189
+ await this.s2.basins.delete({ basin }, { signal: this.closing.signal });
190
+ }
191
+ catch (error) {
192
+ if (!isMissing(error))
193
+ throw error;
194
+ }
183
195
  }
184
196
  async deleteStream(tenantId, stream) {
185
197
  this.checkOpen();
@@ -256,7 +268,9 @@ class S2Streams {
256
268
  /**
257
269
  * Follows `stream` from `fromSeq` with S2 read sessions, reopening a session
258
270
  * from the next sequence whenever one ends or fails, until aborted, closed,
259
- * or the Tenant's basin is gone. A missing stream is polled until it exists.
271
+ * or the Tenant's basin is gone. Basins create a stream on read, so a reader
272
+ * that arrives before the first append waits on the live session instead of
273
+ * polling.
260
274
  */
261
275
  async *readLive(tenantId, stream, fromSeq, signal) {
262
276
  const aborted = anySignal(signal, this.closing.signal);
@@ -288,7 +302,7 @@ class S2Streams {
288
302
  if ((isMissing(error) || isCode(error, "stream_deletion_pending")) &&
289
303
  (await this.basinGone(tenantId, aborted)))
290
304
  return;
291
- // Stream not created yet, or S2 unreachable: retry below.
305
+ // S2 unreachable, or a stream being deleted: retry below.
292
306
  }
293
307
  await sleep(delay, aborted);
294
308
  delay = Math.min(delay * 2, RETRY_MAX_MS);
@@ -343,6 +357,9 @@ function isTransactionConflict(error) {
343
357
  function isTenantGone(error) {
344
358
  return isCode(error, "basin_not_found") || isCode(error, "basin_deletion_pending");
345
359
  }
360
+ function escapeRegExp(text) {
361
+ return text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
362
+ }
346
363
  function anySignal(...signals) {
347
364
  return AbortSignal.any(signals.filter((s) => s !== undefined));
348
365
  }
@@ -0,0 +1,570 @@
1
+ {
2
+ "openapi": "3.2.0",
3
+ "info": {
4
+ "title": "Nylorun Runtime: Admin API",
5
+ "version": "0.15.0-beta",
6
+ "description": "The Host's status, its Tenant's state and shutdown, with the admin key. Served on the operator listener when the Host has one; the public listener answers these routes with the opaque 404.",
7
+ "x-nylorun-protocol": {
8
+ "min": 4,
9
+ "max": 5,
10
+ "features": [
11
+ "runtime-tenants",
12
+ "admin-status",
13
+ "studio-principal",
14
+ "action-endpoints",
15
+ "tenant-fixture-model",
16
+ "transcript-events",
17
+ "derived-principals",
18
+ "subject-headers",
19
+ "subject-tokens",
20
+ "browser-access",
21
+ "ag-ui-endpoint",
22
+ "a2a-endpoint",
23
+ "action-endpoints"
24
+ ]
25
+ }
26
+ },
27
+ "servers": [
28
+ {
29
+ "url": "{origin}",
30
+ "description": "The operator listener: the local stack's, or where yours runs",
31
+ "variables": {
32
+ "origin": {
33
+ "default": "http://localhost:8788"
34
+ }
35
+ }
36
+ }
37
+ ],
38
+ "components": {
39
+ "securitySchemes": {
40
+ "adminKey": {
41
+ "type": "http",
42
+ "scheme": "bearer",
43
+ "description": "The Host's admin key (`host-credentials.json`). Never a Tenant bearer."
44
+ }
45
+ },
46
+ "schemas": {
47
+ "AdminStatus": {
48
+ "type": "object",
49
+ "properties": {
50
+ "service": {
51
+ "type": "string",
52
+ "minLength": 1
53
+ },
54
+ "version": {
55
+ "type": "string",
56
+ "minLength": 1
57
+ },
58
+ "protocol": {
59
+ "type": "object",
60
+ "properties": {
61
+ "min": {
62
+ "type": "integer"
63
+ },
64
+ "max": {
65
+ "type": "integer"
66
+ },
67
+ "features": {
68
+ "type": "array",
69
+ "items": {
70
+ "type": "string"
71
+ }
72
+ }
73
+ },
74
+ "required": [
75
+ "min",
76
+ "max",
77
+ "features"
78
+ ],
79
+ "additionalProperties": false
80
+ },
81
+ "tenant": {
82
+ "type": "object",
83
+ "properties": {
84
+ "id": {
85
+ "type": [
86
+ "string",
87
+ "null"
88
+ ],
89
+ "minLength": 1
90
+ },
91
+ "name": {
92
+ "type": [
93
+ "string",
94
+ "null"
95
+ ]
96
+ },
97
+ "state": {
98
+ "type": "string",
99
+ "enum": [
100
+ "open",
101
+ "unavailable"
102
+ ]
103
+ },
104
+ "envelope": {
105
+ "type": [
106
+ "object",
107
+ "null"
108
+ ],
109
+ "properties": {
110
+ "id": {
111
+ "type": "string",
112
+ "minLength": 1
113
+ },
114
+ "name": {
115
+ "type": "string",
116
+ "minLength": 1
117
+ },
118
+ "createdAt": {
119
+ "type": "string",
120
+ "minLength": 1
121
+ },
122
+ "updatedAt": {
123
+ "type": "string",
124
+ "minLength": 1
125
+ },
126
+ "schemaVersion": {
127
+ "type": "integer"
128
+ }
129
+ },
130
+ "required": [
131
+ "id",
132
+ "name",
133
+ "createdAt",
134
+ "updatedAt",
135
+ "schemaVersion"
136
+ ],
137
+ "additionalProperties": false
138
+ },
139
+ "cause": {
140
+ "type": "object",
141
+ "properties": {
142
+ "code": {
143
+ "type": "string",
144
+ "enum": [
145
+ "kek-missing",
146
+ "corrupt",
147
+ "schema-too-new",
148
+ "migration-failed",
149
+ "envelope-invalid",
150
+ "open-timeout",
151
+ "open-failed",
152
+ "database-layout-old"
153
+ ]
154
+ },
155
+ "message": {
156
+ "type": "string"
157
+ },
158
+ "repair": {
159
+ "type": "string"
160
+ }
161
+ },
162
+ "required": [
163
+ "code",
164
+ "message",
165
+ "repair"
166
+ ],
167
+ "additionalProperties": false
168
+ }
169
+ },
170
+ "required": [
171
+ "id",
172
+ "name",
173
+ "state",
174
+ "envelope"
175
+ ],
176
+ "additionalProperties": false
177
+ },
178
+ "aggregate": {
179
+ "type": "object",
180
+ "properties": {
181
+ "runningSessions": {
182
+ "type": "integer",
183
+ "minimum": 0
184
+ },
185
+ "inFlightDeliveries": {
186
+ "type": "integer",
187
+ "minimum": 0
188
+ },
189
+ "pendingActions": {
190
+ "type": "integer",
191
+ "minimum": 0
192
+ },
193
+ "uncertainEffects": {
194
+ "type": "integer",
195
+ "minimum": 0
196
+ },
197
+ "relay": {
198
+ "type": "object",
199
+ "properties": {
200
+ "active": {
201
+ "type": "boolean"
202
+ },
203
+ "pendingTxs": {
204
+ "type": "integer",
205
+ "minimum": 0
206
+ },
207
+ "pendingRows": {
208
+ "type": "integer",
209
+ "minimum": 0
210
+ },
211
+ "confirmed": {
212
+ "type": [
213
+ "string",
214
+ "null"
215
+ ]
216
+ },
217
+ "reconciliations": {
218
+ "type": "integer",
219
+ "minimum": 0
220
+ },
221
+ "lastError": {
222
+ "type": [
223
+ "string",
224
+ "null"
225
+ ]
226
+ },
227
+ "lagBytes": {
228
+ "type": "number",
229
+ "minimum": 0
230
+ }
231
+ },
232
+ "required": [
233
+ "active",
234
+ "pendingTxs",
235
+ "pendingRows",
236
+ "confirmed",
237
+ "reconciliations",
238
+ "lastError"
239
+ ],
240
+ "additionalProperties": false
241
+ }
242
+ },
243
+ "required": [
244
+ "runningSessions",
245
+ "inFlightDeliveries",
246
+ "pendingActions",
247
+ "uncertainEffects"
248
+ ],
249
+ "additionalProperties": false
250
+ },
251
+ "host": {
252
+ "type": "object",
253
+ "properties": {
254
+ "hostId": {
255
+ "type": "string",
256
+ "minLength": 1
257
+ },
258
+ "url": {
259
+ "type": "string",
260
+ "minLength": 1
261
+ },
262
+ "pid": {
263
+ "type": "integer"
264
+ }
265
+ },
266
+ "required": [
267
+ "hostId",
268
+ "url",
269
+ "pid"
270
+ ],
271
+ "additionalProperties": false
272
+ }
273
+ },
274
+ "required": [
275
+ "service",
276
+ "version",
277
+ "protocol",
278
+ "tenant",
279
+ "aggregate"
280
+ ],
281
+ "additionalProperties": false
282
+ },
283
+ "Rejected": {
284
+ "type": "object",
285
+ "properties": {
286
+ "status": {
287
+ "type": "string",
288
+ "enum": [
289
+ "rejected"
290
+ ]
291
+ },
292
+ "code": {
293
+ "type": "string",
294
+ "enum": [
295
+ "not_found",
296
+ "protocol_unsupported",
297
+ "host_rejected",
298
+ "origin_rejected",
299
+ "unsupported_media_type",
300
+ "connection_missing",
301
+ "incompatible_host",
302
+ "subject_invalid",
303
+ "scope_required",
304
+ "token_expired",
305
+ "limit_exceeded",
306
+ "request_rejected",
307
+ "invalid_request",
308
+ "subject_required",
309
+ "internal_error"
310
+ ]
311
+ },
312
+ "message": {
313
+ "type": "string"
314
+ },
315
+ "details": {},
316
+ "activeTurnId": {
317
+ "type": "string"
318
+ },
319
+ "requestId": {
320
+ "type": "string"
321
+ }
322
+ },
323
+ "required": [
324
+ "status",
325
+ "code",
326
+ "message"
327
+ ]
328
+ },
329
+ "ProtocolRejected": {
330
+ "type": "object",
331
+ "properties": {
332
+ "status": {
333
+ "type": "string",
334
+ "enum": [
335
+ "rejected"
336
+ ]
337
+ },
338
+ "code": {
339
+ "type": "string",
340
+ "enum": [
341
+ "protocol_unsupported"
342
+ ]
343
+ },
344
+ "protocol": {
345
+ "type": "object",
346
+ "properties": {
347
+ "min": {
348
+ "type": "integer"
349
+ },
350
+ "max": {
351
+ "type": "integer"
352
+ },
353
+ "features": {
354
+ "type": "array",
355
+ "items": {
356
+ "type": "string"
357
+ }
358
+ }
359
+ },
360
+ "required": [
361
+ "min",
362
+ "max",
363
+ "features"
364
+ ],
365
+ "additionalProperties": false
366
+ }
367
+ },
368
+ "required": [
369
+ "status",
370
+ "code",
371
+ "protocol"
372
+ ],
373
+ "additionalProperties": false
374
+ },
375
+ "HostShutdownResponse": {
376
+ "type": "object",
377
+ "properties": {
378
+ "status": {
379
+ "type": "string",
380
+ "enum": [
381
+ "shutting_down"
382
+ ]
383
+ }
384
+ },
385
+ "required": [
386
+ "status"
387
+ ],
388
+ "additionalProperties": false
389
+ }
390
+ },
391
+ "parameters": {}
392
+ },
393
+ "paths": {
394
+ "/v1/admin/status": {
395
+ "get": {
396
+ "summary": "Get the Host's status",
397
+ "tags": [
398
+ "Admin"
399
+ ],
400
+ "security": [
401
+ {
402
+ "adminKey": []
403
+ }
404
+ ],
405
+ "responses": {
406
+ "200": {
407
+ "description": "Version, protocol, the Tenant and the Host",
408
+ "content": {
409
+ "application/json": {
410
+ "schema": {
411
+ "$ref": "#/components/schemas/AdminStatus"
412
+ }
413
+ }
414
+ }
415
+ },
416
+ "404": {
417
+ "description": "Not found: an unknown admin key, or the public listener",
418
+ "content": {
419
+ "application/json": {
420
+ "schema": {
421
+ "$ref": "#/components/schemas/Rejected"
422
+ }
423
+ }
424
+ }
425
+ },
426
+ "426": {
427
+ "description": "`Nylorun-Protocol` missing or unsupported",
428
+ "content": {
429
+ "application/json": {
430
+ "schema": {
431
+ "$ref": "#/components/schemas/ProtocolRejected"
432
+ }
433
+ }
434
+ }
435
+ }
436
+ }
437
+ }
438
+ },
439
+ "/v1/admin/host": {
440
+ "get": {
441
+ "summary": "Get the Host's status (alias)",
442
+ "tags": [
443
+ "Admin"
444
+ ],
445
+ "security": [
446
+ {
447
+ "adminKey": []
448
+ }
449
+ ],
450
+ "responses": {
451
+ "200": {
452
+ "description": "Version, protocol, the Tenant and the Host",
453
+ "content": {
454
+ "application/json": {
455
+ "schema": {
456
+ "$ref": "#/components/schemas/AdminStatus"
457
+ }
458
+ }
459
+ }
460
+ },
461
+ "404": {
462
+ "description": "Not found: an unknown admin key, or the public listener",
463
+ "content": {
464
+ "application/json": {
465
+ "schema": {
466
+ "$ref": "#/components/schemas/Rejected"
467
+ }
468
+ }
469
+ }
470
+ },
471
+ "426": {
472
+ "description": "`Nylorun-Protocol` missing or unsupported",
473
+ "content": {
474
+ "application/json": {
475
+ "schema": {
476
+ "$ref": "#/components/schemas/ProtocolRejected"
477
+ }
478
+ }
479
+ }
480
+ }
481
+ }
482
+ }
483
+ },
484
+ "/v1/admin/host/shutdown": {
485
+ "post": {
486
+ "summary": "Shut the Host down",
487
+ "description": "Answers, then stops the Host. Served by a self-hosted Runtime only.",
488
+ "tags": [
489
+ "Admin"
490
+ ],
491
+ "security": [
492
+ {
493
+ "adminKey": []
494
+ }
495
+ ],
496
+ "responses": {
497
+ "200": {
498
+ "description": "The Host is stopping",
499
+ "content": {
500
+ "application/json": {
501
+ "schema": {
502
+ "$ref": "#/components/schemas/HostShutdownResponse"
503
+ }
504
+ }
505
+ }
506
+ },
507
+ "404": {
508
+ "description": "Not found: an unknown admin key, or the public listener",
509
+ "content": {
510
+ "application/json": {
511
+ "schema": {
512
+ "$ref": "#/components/schemas/Rejected"
513
+ }
514
+ }
515
+ }
516
+ },
517
+ "426": {
518
+ "description": "`Nylorun-Protocol` missing or unsupported",
519
+ "content": {
520
+ "application/json": {
521
+ "schema": {
522
+ "$ref": "#/components/schemas/ProtocolRejected"
523
+ }
524
+ }
525
+ }
526
+ }
527
+ }
528
+ }
529
+ },
530
+ "/v1/admin/openapi.json": {
531
+ "get": {
532
+ "summary": "Get this document",
533
+ "tags": [
534
+ "Admin"
535
+ ],
536
+ "security": [
537
+ {
538
+ "adminKey": []
539
+ }
540
+ ],
541
+ "responses": {
542
+ "200": {
543
+ "description": "The Admin API's OpenAPI document"
544
+ },
545
+ "404": {
546
+ "description": "Not found: an unknown admin key, or the public listener",
547
+ "content": {
548
+ "application/json": {
549
+ "schema": {
550
+ "$ref": "#/components/schemas/Rejected"
551
+ }
552
+ }
553
+ }
554
+ },
555
+ "426": {
556
+ "description": "`Nylorun-Protocol` missing or unsupported",
557
+ "content": {
558
+ "application/json": {
559
+ "schema": {
560
+ "$ref": "#/components/schemas/ProtocolRejected"
561
+ }
562
+ }
563
+ }
564
+ }
565
+ }
566
+ }
567
+ }
568
+ },
569
+ "webhooks": {}
570
+ }