@vibesdotdev/runnable 0.0.0-stage → 1.0.0-rc.1

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 (675) hide show
  1. package/LICENSE +18 -0
  2. package/README.md +4 -2
  3. package/dist/artifact-data.d.ts +8 -0
  4. package/dist/artifact-data.d.ts.map +1 -0
  5. package/dist/artifact-data.js +12 -0
  6. package/dist/artifact-data.js.map +1 -0
  7. package/dist/change-source.d.ts +54 -0
  8. package/dist/change-source.d.ts.map +1 -0
  9. package/dist/change-source.js +37 -0
  10. package/dist/change-source.js.map +1 -0
  11. package/dist/client/client.d.ts +1002 -0
  12. package/dist/client/client.d.ts.map +1 -0
  13. package/dist/client/client.js +148 -0
  14. package/dist/client/client.js.map +1 -0
  15. package/dist/client/execution/failure.d.ts +3 -0
  16. package/dist/client/execution/failure.d.ts.map +1 -0
  17. package/dist/client/execution/failure.js +20 -0
  18. package/dist/client/execution/failure.js.map +1 -0
  19. package/dist/client/execution/finalize.d.ts +81 -0
  20. package/dist/client/execution/finalize.d.ts.map +1 -0
  21. package/dist/client/execution/finalize.js +71 -0
  22. package/dist/client/execution/finalize.js.map +1 -0
  23. package/dist/client/execution/memo.d.ts +25 -0
  24. package/dist/client/execution/memo.d.ts.map +1 -0
  25. package/dist/client/execution/memo.js +56 -0
  26. package/dist/client/execution/memo.js.map +1 -0
  27. package/dist/client/execution/native-admission.d.ts +7 -0
  28. package/dist/client/execution/native-admission.d.ts.map +1 -0
  29. package/dist/client/execution/native-admission.js +22 -0
  30. package/dist/client/execution/native-admission.js.map +1 -0
  31. package/dist/client/execution/prepare-input.d.ts +19 -0
  32. package/dist/client/execution/prepare-input.d.ts.map +1 -0
  33. package/dist/client/execution/prepare-input.js +27 -0
  34. package/dist/client/execution/prepare-input.js.map +1 -0
  35. package/dist/client/execution/prepare-record.d.ts +271 -0
  36. package/dist/client/execution/prepare-record.d.ts.map +1 -0
  37. package/dist/client/execution/prepare-record.js +115 -0
  38. package/dist/client/execution/prepare-record.js.map +1 -0
  39. package/dist/client/execution/produce.d.ts +44 -0
  40. package/dist/client/execution/produce.d.ts.map +1 -0
  41. package/dist/client/execution/produce.js +78 -0
  42. package/dist/client/execution/produce.js.map +1 -0
  43. package/dist/client/execution/recorded.d.ts +28 -0
  44. package/dist/client/execution/recorded.d.ts.map +1 -0
  45. package/dist/client/execution/recorded.js +74 -0
  46. package/dist/client/execution/recorded.js.map +1 -0
  47. package/dist/client/execution/selection.d.ts +19 -0
  48. package/dist/client/execution/selection.d.ts.map +1 -0
  49. package/dist/client/execution/selection.js +38 -0
  50. package/dist/client/execution/selection.js.map +1 -0
  51. package/dist/client/native/completion.d.ts +19 -0
  52. package/dist/client/native/completion.d.ts.map +1 -0
  53. package/dist/client/native/completion.js +158 -0
  54. package/dist/client/native/completion.js.map +1 -0
  55. package/dist/client/native/controls.d.ts +18 -0
  56. package/dist/client/native/controls.d.ts.map +1 -0
  57. package/dist/client/native/controls.js +69 -0
  58. package/dist/client/native/controls.js.map +1 -0
  59. package/dist/client/native/owner.d.ts +36 -0
  60. package/dist/client/native/owner.d.ts.map +1 -0
  61. package/dist/client/native/owner.js +111 -0
  62. package/dist/client/native/owner.js.map +1 -0
  63. package/dist/client/native/supervision.d.ts +12 -0
  64. package/dist/client/native/supervision.d.ts.map +1 -0
  65. package/dist/client/native/supervision.js +56 -0
  66. package/dist/client/native/supervision.js.map +1 -0
  67. package/dist/client/records/authority.d.ts +20 -0
  68. package/dist/client/records/authority.d.ts.map +1 -0
  69. package/dist/client/records/authority.js +186 -0
  70. package/dist/client/records/authority.js.map +1 -0
  71. package/dist/client/records/identity.d.ts +4 -0
  72. package/dist/client/records/identity.d.ts.map +1 -0
  73. package/dist/client/records/identity.js +7 -0
  74. package/dist/client/records/identity.js.map +1 -0
  75. package/dist/client/records/input-admission.d.ts +5 -0
  76. package/dist/client/records/input-admission.d.ts.map +1 -0
  77. package/dist/client/records/input-admission.js +26 -0
  78. package/dist/client/records/input-admission.js.map +1 -0
  79. package/dist/client/records/owner.d.ts +254 -0
  80. package/dist/client/records/owner.d.ts.map +1 -0
  81. package/dist/client/records/owner.js +127 -0
  82. package/dist/client/records/owner.js.map +1 -0
  83. package/dist/client/records/query.d.ts +11 -0
  84. package/dist/client/records/query.d.ts.map +1 -0
  85. package/dist/client/records/query.js +60 -0
  86. package/dist/client/records/query.js.map +1 -0
  87. package/dist/client/records/recording.d.ts +9 -0
  88. package/dist/client/records/recording.d.ts.map +1 -0
  89. package/dist/client/records/recording.js +160 -0
  90. package/dist/client/records/recording.js.map +1 -0
  91. package/dist/client/resolve.d.ts +10 -0
  92. package/dist/client/resolve.d.ts.map +1 -0
  93. package/dist/client/resolve.js +33 -0
  94. package/dist/client/resolve.js.map +1 -0
  95. package/dist/client/tracking/artifact-data.d.ts +8 -0
  96. package/dist/client/tracking/artifact-data.d.ts.map +1 -0
  97. package/dist/client/tracking/artifact-data.js +12 -0
  98. package/dist/client/tracking/artifact-data.js.map +1 -0
  99. package/dist/client/tracking/client.d.ts +20 -0
  100. package/dist/client/tracking/client.d.ts.map +1 -0
  101. package/dist/client/tracking/client.js +187 -0
  102. package/dist/client/tracking/client.js.map +1 -0
  103. package/dist/client/tracking/panel-bindings.d.ts +8 -0
  104. package/dist/client/tracking/panel-bindings.d.ts.map +1 -0
  105. package/dist/client/tracking/panel-bindings.js +81 -0
  106. package/dist/client/tracking/panel-bindings.js.map +1 -0
  107. package/dist/client/tracking/panels.d.ts +62 -0
  108. package/dist/client/tracking/panels.d.ts.map +1 -0
  109. package/dist/client/tracking/panels.js +56 -0
  110. package/dist/client/tracking/panels.js.map +1 -0
  111. package/dist/client/tracking/projection.d.ts +17 -0
  112. package/dist/client/tracking/projection.d.ts.map +1 -0
  113. package/dist/client/tracking/projection.js +100 -0
  114. package/dist/client/tracking/projection.js.map +1 -0
  115. package/dist/client/tracking/watch.d.ts +10 -0
  116. package/dist/client/tracking/watch.d.ts.map +1 -0
  117. package/dist/client/tracking/watch.js +128 -0
  118. package/dist/client/tracking/watch.js.map +1 -0
  119. package/dist/client/transport.d.ts +14 -0
  120. package/dist/client/transport.d.ts.map +1 -0
  121. package/dist/client/transport.js +52 -0
  122. package/dist/client/transport.js.map +1 -0
  123. package/dist/client.d.ts +460 -0
  124. package/dist/client.d.ts.map +1 -0
  125. package/dist/client.js +1181 -0
  126. package/dist/client.js.map +1 -0
  127. package/dist/context.d.ts +14 -0
  128. package/dist/context.d.ts.map +1 -0
  129. package/dist/context.js +98 -0
  130. package/dist/context.js.map +1 -0
  131. package/dist/docs/runnable.context.docs.descriptor.d.ts +4 -0
  132. package/dist/docs/runnable.context.docs.descriptor.d.ts.map +1 -0
  133. package/dist/docs/runnable.context.docs.descriptor.js +419 -0
  134. package/dist/docs/runnable.context.docs.descriptor.js.map +1 -0
  135. package/dist/docs/runnable.graphs.docs.descriptor.d.ts +4 -0
  136. package/dist/docs/runnable.graphs.docs.descriptor.d.ts.map +1 -0
  137. package/dist/docs/runnable.graphs.docs.descriptor.js +51 -0
  138. package/dist/docs/runnable.graphs.docs.descriptor.js.map +1 -0
  139. package/dist/docs/runnable.nodes.docs.descriptor.d.ts +4 -0
  140. package/dist/docs/runnable.nodes.docs.descriptor.d.ts.map +1 -0
  141. package/dist/docs/runnable.nodes.docs.descriptor.js +327 -0
  142. package/dist/docs/runnable.nodes.docs.descriptor.js.map +1 -0
  143. package/dist/event-broker.d.ts +54 -0
  144. package/dist/event-broker.d.ts.map +1 -0
  145. package/dist/event-broker.js +157 -0
  146. package/dist/event-broker.js.map +1 -0
  147. package/dist/events.d.ts +16 -0
  148. package/dist/events.d.ts.map +1 -0
  149. package/dist/events.js +144 -0
  150. package/dist/events.js.map +1 -0
  151. package/dist/execution.contract.d.ts +10 -0
  152. package/dist/execution.contract.d.ts.map +1 -0
  153. package/dist/execution.contract.js +30 -0
  154. package/dist/execution.contract.js.map +1 -0
  155. package/dist/execution.d.ts +24 -0
  156. package/dist/execution.d.ts.map +1 -0
  157. package/dist/execution.js +172 -0
  158. package/dist/execution.js.map +1 -0
  159. package/dist/execution.telemetry.descriptor.d.ts +4 -0
  160. package/dist/execution.telemetry.descriptor.d.ts.map +1 -0
  161. package/dist/execution.telemetry.descriptor.js +6 -0
  162. package/dist/execution.telemetry.descriptor.js.map +1 -0
  163. package/dist/host.d.ts +95 -0
  164. package/dist/host.d.ts.map +1 -0
  165. package/dist/host.js +12 -0
  166. package/dist/host.js.map +1 -0
  167. package/dist/identity.d.ts +3 -0
  168. package/dist/identity.d.ts.map +1 -0
  169. package/dist/identity.js +6 -0
  170. package/dist/identity.js.map +1 -0
  171. package/dist/index.d.ts +32 -0
  172. package/dist/index.d.ts.map +1 -0
  173. package/dist/index.js +24 -0
  174. package/dist/index.js.map +1 -0
  175. package/dist/input-admission.d.ts +5 -0
  176. package/dist/input-admission.d.ts.map +1 -0
  177. package/dist/input-admission.js +43 -0
  178. package/dist/input-admission.js.map +1 -0
  179. package/dist/invocation.d.ts +17 -0
  180. package/dist/invocation.d.ts.map +1 -0
  181. package/dist/invocation.js +32 -0
  182. package/dist/invocation.js.map +1 -0
  183. package/dist/issues.d.ts +4 -0
  184. package/dist/issues.d.ts.map +1 -0
  185. package/dist/issues.js +5 -0
  186. package/dist/issues.js.map +1 -0
  187. package/dist/json-field.d.ts +4 -0
  188. package/dist/json-field.d.ts.map +1 -0
  189. package/dist/json-field.js +16 -0
  190. package/dist/json-field.js.map +1 -0
  191. package/dist/kinds/config.d.ts +3 -0
  192. package/dist/kinds/config.d.ts.map +1 -0
  193. package/dist/kinds/config.js +14 -0
  194. package/dist/kinds/config.js.map +1 -0
  195. package/dist/kinds/ingest-mapping.d.ts +3 -0
  196. package/dist/kinds/ingest-mapping.d.ts.map +1 -0
  197. package/dist/kinds/ingest-mapping.js +30 -0
  198. package/dist/kinds/ingest-mapping.js.map +1 -0
  199. package/dist/kinds/result.d.ts +3 -0
  200. package/dist/kinds/result.d.ts.map +1 -0
  201. package/dist/kinds/result.js +14 -0
  202. package/dist/kinds/result.js.map +1 -0
  203. package/dist/kinds/runnable.d.ts +3 -0
  204. package/dist/kinds/runnable.d.ts.map +1 -0
  205. package/dist/kinds/runnable.js +19 -0
  206. package/dist/kinds/runnable.js.map +1 -0
  207. package/dist/kinds/telemetry.d.ts +3 -0
  208. package/dist/kinds/telemetry.d.ts.map +1 -0
  209. package/dist/kinds/telemetry.js +14 -0
  210. package/dist/kinds/telemetry.js.map +1 -0
  211. package/dist/kinds/type.d.ts +3 -0
  212. package/dist/kinds/type.d.ts.map +1 -0
  213. package/dist/kinds/type.js +14 -0
  214. package/dist/kinds/type.js.map +1 -0
  215. package/dist/kinds/visualization.d.ts +3 -0
  216. package/dist/kinds/visualization.d.ts.map +1 -0
  217. package/dist/kinds/visualization.js +14 -0
  218. package/dist/kinds/visualization.js.map +1 -0
  219. package/dist/metrics/runnable.metrics.descriptor.d.ts +16 -0
  220. package/dist/metrics/runnable.metrics.descriptor.d.ts.map +1 -0
  221. package/dist/metrics/runnable.metrics.descriptor.js +16 -0
  222. package/dist/metrics/runnable.metrics.descriptor.js.map +1 -0
  223. package/dist/metrics/runnable.metrics.impl.d.ts +13 -0
  224. package/dist/metrics/runnable.metrics.impl.d.ts.map +1 -0
  225. package/dist/metrics/runnable.metrics.impl.js +60 -0
  226. package/dist/metrics/runnable.metrics.impl.js.map +1 -0
  227. package/dist/panels.d.ts +31 -0
  228. package/dist/panels.d.ts.map +1 -0
  229. package/dist/panels.js +58 -0
  230. package/dist/panels.js.map +1 -0
  231. package/dist/plugin.d.ts +3 -0
  232. package/dist/plugin.d.ts.map +1 -0
  233. package/dist/plugin.js +71 -0
  234. package/dist/plugin.js.map +1 -0
  235. package/dist/projection.d.ts +26 -0
  236. package/dist/projection.d.ts.map +1 -0
  237. package/dist/projection.js +100 -0
  238. package/dist/projection.js.map +1 -0
  239. package/dist/recording.d.ts +9 -0
  240. package/dist/recording.d.ts.map +1 -0
  241. package/dist/recording.js +121 -0
  242. package/dist/recording.js.map +1 -0
  243. package/dist/records/authority.d.ts +20 -0
  244. package/dist/records/authority.d.ts.map +1 -0
  245. package/dist/records/authority.js +142 -0
  246. package/dist/records/authority.js.map +1 -0
  247. package/dist/records/query.d.ts +11 -0
  248. package/dist/records/query.d.ts.map +1 -0
  249. package/dist/records/query.js +60 -0
  250. package/dist/records/query.js.map +1 -0
  251. package/dist/runnable.cloud.plugin.d.ts +3 -0
  252. package/dist/runnable.cloud.plugin.d.ts.map +1 -0
  253. package/dist/runnable.cloud.plugin.js +3 -0
  254. package/dist/runnable.cloud.plugin.js.map +1 -0
  255. package/dist/runnable.consumer.plugin.d.ts +15 -0
  256. package/dist/runnable.consumer.plugin.d.ts.map +1 -0
  257. package/dist/runnable.consumer.plugin.js +15 -0
  258. package/dist/runnable.consumer.plugin.js.map +1 -0
  259. package/dist/runnable.plugin.d.ts +3 -0
  260. package/dist/runnable.plugin.d.ts.map +1 -0
  261. package/dist/runnable.plugin.js +3 -0
  262. package/dist/runnable.plugin.js.map +1 -0
  263. package/dist/runner.d.ts +13 -0
  264. package/dist/runner.d.ts.map +1 -0
  265. package/dist/runner.js +151 -0
  266. package/dist/runner.js.map +1 -0
  267. package/dist/runtime/change-source.d.ts +39 -0
  268. package/dist/runtime/change-source.d.ts.map +1 -0
  269. package/dist/runtime/change-source.js +36 -0
  270. package/dist/runtime/change-source.js.map +1 -0
  271. package/dist/runtime/event-broker.d.ts +41 -0
  272. package/dist/runtime/event-broker.d.ts.map +1 -0
  273. package/dist/runtime/event-broker.js +157 -0
  274. package/dist/runtime/event-broker.js.map +1 -0
  275. package/dist/runtime/events.d.ts +16 -0
  276. package/dist/runtime/events.d.ts.map +1 -0
  277. package/dist/runtime/events.js +144 -0
  278. package/dist/runtime/events.js.map +1 -0
  279. package/dist/runtime/execution/contract.d.ts +10 -0
  280. package/dist/runtime/execution/contract.d.ts.map +1 -0
  281. package/dist/runtime/execution/contract.js +30 -0
  282. package/dist/runtime/execution/contract.js.map +1 -0
  283. package/dist/runtime/execution/exit.d.ts +5 -0
  284. package/dist/runtime/execution/exit.d.ts.map +1 -0
  285. package/dist/runtime/execution/exit.js +39 -0
  286. package/dist/runtime/execution/exit.js.map +1 -0
  287. package/dist/runtime/execution/index.d.ts +23 -0
  288. package/dist/runtime/execution/index.d.ts.map +1 -0
  289. package/dist/runtime/execution/index.js +136 -0
  290. package/dist/runtime/execution/index.js.map +1 -0
  291. package/dist/runtime/host.d.ts +60 -0
  292. package/dist/runtime/host.d.ts.map +1 -0
  293. package/dist/runtime/host.js +13 -0
  294. package/dist/runtime/host.js.map +1 -0
  295. package/dist/runtime/invocation.d.ts +10 -0
  296. package/dist/runtime/invocation.d.ts.map +1 -0
  297. package/dist/runtime/invocation.js +27 -0
  298. package/dist/runtime/invocation.js.map +1 -0
  299. package/dist/runtime/plugins/plugin.d.ts +3 -0
  300. package/dist/runtime/plugins/plugin.d.ts.map +1 -0
  301. package/dist/runtime/plugins/plugin.js +69 -0
  302. package/dist/runtime/plugins/plugin.js.map +1 -0
  303. package/dist/runtime/plugins/runnable.cloud.plugin.d.ts +3 -0
  304. package/dist/runtime/plugins/runnable.cloud.plugin.d.ts.map +1 -0
  305. package/dist/runtime/plugins/runnable.cloud.plugin.js +3 -0
  306. package/dist/runtime/plugins/runnable.cloud.plugin.js.map +1 -0
  307. package/dist/runtime/plugins/runnable.consumer.plugin.d.ts +15 -0
  308. package/dist/runtime/plugins/runnable.consumer.plugin.d.ts.map +1 -0
  309. package/dist/runtime/plugins/runnable.consumer.plugin.js +15 -0
  310. package/dist/runtime/plugins/runnable.consumer.plugin.js.map +1 -0
  311. package/dist/runtime/plugins/runnable.metrics.plugin.d.ts +4 -0
  312. package/dist/runtime/plugins/runnable.metrics.plugin.d.ts.map +1 -0
  313. package/dist/runtime/plugins/runnable.metrics.plugin.js +13 -0
  314. package/dist/runtime/plugins/runnable.metrics.plugin.js.map +1 -0
  315. package/dist/runtime/plugins/runnable.plugin.d.ts +3 -0
  316. package/dist/runtime/plugins/runnable.plugin.d.ts.map +1 -0
  317. package/dist/runtime/plugins/runnable.plugin.js +3 -0
  318. package/dist/runtime/plugins/runnable.plugin.js.map +1 -0
  319. package/dist/runtime/runner.d.ts +13 -0
  320. package/dist/runtime/runner.d.ts.map +1 -0
  321. package/dist/runtime/runner.js +154 -0
  322. package/dist/runtime/runner.js.map +1 -0
  323. package/dist/runtime/state/index.d.ts +4 -0
  324. package/dist/runtime/state/index.d.ts.map +1 -0
  325. package/dist/runtime/state/index.js +4 -0
  326. package/dist/runtime/state/index.js.map +1 -0
  327. package/dist/runtime/state/manager.d.ts +20 -0
  328. package/dist/runtime/state/manager.d.ts.map +1 -0
  329. package/dist/runtime/state/manager.js +135 -0
  330. package/dist/runtime/state/manager.js.map +1 -0
  331. package/dist/runtime/state/snapshot.d.ts +10 -0
  332. package/dist/runtime/state/snapshot.d.ts.map +1 -0
  333. package/dist/runtime/state/snapshot.js +59 -0
  334. package/dist/runtime/state/snapshot.js.map +1 -0
  335. package/dist/runtime/state/time-series.d.ts +36 -0
  336. package/dist/runtime/state/time-series.d.ts.map +1 -0
  337. package/dist/runtime/state/time-series.js +151 -0
  338. package/dist/runtime/state/time-series.js.map +1 -0
  339. package/dist/schemas/context.d.ts +64 -0
  340. package/dist/schemas/context.d.ts.map +1 -0
  341. package/dist/schemas/context.js +37 -0
  342. package/dist/schemas/context.js.map +1 -0
  343. package/dist/schemas/contracts/events.d.ts +33 -0
  344. package/dist/schemas/contracts/events.d.ts.map +1 -0
  345. package/dist/schemas/contracts/events.js +5 -0
  346. package/dist/schemas/contracts/events.js.map +1 -0
  347. package/dist/schemas/contracts/execution.d.ts +211 -0
  348. package/dist/schemas/contracts/execution.d.ts.map +1 -0
  349. package/dist/schemas/contracts/execution.js +40 -0
  350. package/dist/schemas/contracts/execution.js.map +1 -0
  351. package/dist/schemas/contracts/host.d.ts +37 -0
  352. package/dist/schemas/contracts/host.d.ts.map +1 -0
  353. package/dist/schemas/contracts/host.js +2 -0
  354. package/dist/schemas/contracts/host.js.map +1 -0
  355. package/dist/schemas/contracts/index.d.ts +77 -0
  356. package/dist/schemas/contracts/index.d.ts.map +1 -0
  357. package/dist/schemas/contracts/index.js +28 -0
  358. package/dist/schemas/contracts/index.js.map +1 -0
  359. package/dist/schemas/contracts/invocation.d.ts +9 -0
  360. package/dist/schemas/contracts/invocation.d.ts.map +1 -0
  361. package/dist/schemas/contracts/invocation.js +8 -0
  362. package/dist/schemas/contracts/invocation.js.map +1 -0
  363. package/dist/schemas/contracts/runner.d.ts +61 -0
  364. package/dist/schemas/contracts/runner.d.ts.map +1 -0
  365. package/dist/schemas/contracts/runner.js +3 -0
  366. package/dist/schemas/contracts/runner.js.map +1 -0
  367. package/dist/schemas/contracts/state.d.ts +147 -0
  368. package/dist/schemas/contracts/state.d.ts.map +1 -0
  369. package/dist/schemas/contracts/state.js +16 -0
  370. package/dist/schemas/contracts/state.js.map +1 -0
  371. package/dist/schemas/contracts/storage.d.ts +231 -0
  372. package/dist/schemas/contracts/storage.d.ts.map +1 -0
  373. package/dist/schemas/contracts/storage.js +39 -0
  374. package/dist/schemas/contracts/storage.js.map +1 -0
  375. package/dist/schemas/contracts/test-scenario.d.ts +60 -0
  376. package/dist/schemas/contracts/test-scenario.d.ts.map +1 -0
  377. package/dist/schemas/contracts/test-scenario.js +2 -0
  378. package/dist/schemas/contracts/test-scenario.js.map +1 -0
  379. package/dist/schemas/contracts/watch.d.ts +49 -0
  380. package/dist/schemas/contracts/watch.d.ts.map +1 -0
  381. package/dist/schemas/contracts/watch.js +2 -0
  382. package/dist/schemas/contracts/watch.js.map +1 -0
  383. package/dist/schemas/contracts.d.ts +192 -0
  384. package/dist/schemas/contracts.d.ts.map +1 -0
  385. package/dist/schemas/contracts.js +38 -0
  386. package/dist/schemas/contracts.js.map +1 -0
  387. package/dist/schemas/description.d.ts +68 -0
  388. package/dist/schemas/description.d.ts.map +1 -0
  389. package/dist/schemas/description.js +12 -0
  390. package/dist/schemas/description.js.map +1 -0
  391. package/dist/schemas/descriptors.d.ts +429 -0
  392. package/dist/schemas/descriptors.d.ts.map +1 -0
  393. package/dist/schemas/descriptors.js +125 -0
  394. package/dist/schemas/descriptors.js.map +1 -0
  395. package/dist/schemas/events.d.ts +359 -0
  396. package/dist/schemas/events.d.ts.map +1 -0
  397. package/dist/schemas/events.js +109 -0
  398. package/dist/schemas/events.js.map +1 -0
  399. package/dist/schemas/index.d.ts +12 -0
  400. package/dist/schemas/index.d.ts.map +1 -0
  401. package/dist/schemas/index.js +12 -0
  402. package/dist/schemas/index.js.map +1 -0
  403. package/dist/schemas/issues.d.ts +142 -0
  404. package/dist/schemas/issues.d.ts.map +1 -0
  405. package/dist/schemas/issues.js +44 -0
  406. package/dist/schemas/issues.js.map +1 -0
  407. package/dist/schemas/outcome.d.ts +111 -0
  408. package/dist/schemas/outcome.d.ts.map +1 -0
  409. package/dist/schemas/outcome.js +32 -0
  410. package/dist/schemas/outcome.js.map +1 -0
  411. package/dist/schemas/panels.d.ts +164 -0
  412. package/dist/schemas/panels.d.ts.map +1 -0
  413. package/dist/schemas/panels.js +25 -0
  414. package/dist/schemas/panels.js.map +1 -0
  415. package/dist/schemas/projection.d.ts +301 -0
  416. package/dist/schemas/projection.d.ts.map +1 -0
  417. package/dist/schemas/projection.js +64 -0
  418. package/dist/schemas/projection.js.map +1 -0
  419. package/dist/schemas/runs.d.ts +2428 -0
  420. package/dist/schemas/runs.d.ts.map +1 -0
  421. package/dist/schemas/runs.js +163 -0
  422. package/dist/schemas/runs.js.map +1 -0
  423. package/dist/schemas/writes.d.ts +103 -0
  424. package/dist/schemas/writes.d.ts.map +1 -0
  425. package/dist/schemas/writes.js +28 -0
  426. package/dist/schemas/writes.js.map +1 -0
  427. package/dist/state.d.ts +175 -0
  428. package/dist/state.d.ts.map +1 -0
  429. package/dist/state.js +356 -0
  430. package/dist/state.js.map +1 -0
  431. package/dist/storage/context-sql.d.ts +9 -0
  432. package/dist/storage/context-sql.d.ts.map +1 -0
  433. package/dist/storage/context-sql.js +77 -0
  434. package/dist/storage/context-sql.js.map +1 -0
  435. package/dist/storage/local/catalog.d.ts +62 -0
  436. package/dist/storage/local/catalog.d.ts.map +1 -0
  437. package/dist/storage/local/catalog.js +88 -0
  438. package/dist/storage/local/catalog.js.map +1 -0
  439. package/dist/storage/local/descriptors.d.ts +8 -0
  440. package/dist/storage/local/descriptors.d.ts.map +1 -0
  441. package/dist/storage/local/descriptors.js +32 -0
  442. package/dist/storage/local/descriptors.js.map +1 -0
  443. package/dist/storage/local/host.d.ts +5 -0
  444. package/dist/storage/local/host.d.ts.map +1 -0
  445. package/dist/storage/local/host.js +100 -0
  446. package/dist/storage/local/host.js.map +1 -0
  447. package/dist/storage/local/index.d.ts +4 -0
  448. package/dist/storage/local/index.d.ts.map +1 -0
  449. package/dist/storage/local/index.js +22 -0
  450. package/dist/storage/local/index.js.map +1 -0
  451. package/dist/storage/local/refusal.d.ts +2 -0
  452. package/dist/storage/local/refusal.d.ts.map +1 -0
  453. package/dist/storage/local/refusal.js +7 -0
  454. package/dist/storage/local/refusal.js.map +1 -0
  455. package/dist/storage/local/state-host.d.ts +5 -0
  456. package/dist/storage/local/state-host.d.ts.map +1 -0
  457. package/dist/storage/local/state-host.js +149 -0
  458. package/dist/storage/local/state-host.js.map +1 -0
  459. package/dist/storage/local/telemetry.d.ts +19 -0
  460. package/dist/storage/local/telemetry.d.ts.map +1 -0
  461. package/dist/storage/local/telemetry.js +52 -0
  462. package/dist/storage/local/telemetry.js.map +1 -0
  463. package/dist/storage/local.d.ts +3 -0
  464. package/dist/storage/local.d.ts.map +1 -0
  465. package/dist/storage/local.js +408 -0
  466. package/dist/storage/local.js.map +1 -0
  467. package/dist/storage/plugin.d.ts +7 -0
  468. package/dist/storage/plugin.d.ts.map +1 -0
  469. package/dist/storage/plugin.js +116 -0
  470. package/dist/storage/plugin.js.map +1 -0
  471. package/dist/storage/records.d.ts +8 -0
  472. package/dist/storage/records.d.ts.map +1 -0
  473. package/dist/storage/records.js +68 -0
  474. package/dist/storage/records.js.map +1 -0
  475. package/dist/svelte/components/ArtifactList.svelte +198 -0
  476. package/dist/svelte/components/ArtifactList.svelte.d.ts +10 -0
  477. package/dist/svelte/components/ArtifactList.svelte.d.ts.map +1 -0
  478. package/dist/svelte/components/ArtifactPreview.svelte +19 -0
  479. package/dist/svelte/components/ArtifactPreview.svelte.d.ts +8 -0
  480. package/dist/svelte/components/ArtifactPreview.svelte.d.ts.map +1 -0
  481. package/dist/svelte/components/FleetRuns.svelte +50 -0
  482. package/dist/svelte/components/FleetRuns.svelte.d.ts +8 -0
  483. package/dist/svelte/components/FleetRuns.svelte.d.ts.map +1 -0
  484. package/dist/svelte/components/LogViewer.svelte +98 -0
  485. package/dist/svelte/components/LogViewer.svelte.d.ts +13 -0
  486. package/dist/svelte/components/LogViewer.svelte.d.ts.map +1 -0
  487. package/dist/svelte/components/MetricCard.svelte +176 -0
  488. package/dist/svelte/components/MetricCard.svelte.d.ts +5 -0
  489. package/dist/svelte/components/MetricCard.svelte.d.ts.map +1 -0
  490. package/dist/svelte/components/RunActivity.svelte +32 -0
  491. package/dist/svelte/components/RunActivity.svelte.d.ts +13 -0
  492. package/dist/svelte/components/RunActivity.svelte.d.ts.map +1 -0
  493. package/dist/svelte/components/RunBrowser.svelte +86 -0
  494. package/dist/svelte/components/RunBrowser.svelte.d.ts +13 -0
  495. package/dist/svelte/components/RunBrowser.svelte.d.ts.map +1 -0
  496. package/dist/svelte/components/RunComparison.svelte +76 -0
  497. package/dist/svelte/components/RunComparison.svelte.d.ts +12 -0
  498. package/dist/svelte/components/RunComparison.svelte.d.ts.map +1 -0
  499. package/dist/svelte/components/RunContext.svelte +29 -0
  500. package/dist/svelte/components/RunContext.svelte.d.ts +10 -0
  501. package/dist/svelte/components/RunContext.svelte.d.ts.map +1 -0
  502. package/dist/svelte/components/RunEvidence.svelte +30 -0
  503. package/dist/svelte/components/RunEvidence.svelte.d.ts +8 -0
  504. package/dist/svelte/components/RunEvidence.svelte.d.ts.map +1 -0
  505. package/dist/svelte/components/RunIssues.svelte +114 -0
  506. package/dist/svelte/components/RunIssues.svelte.d.ts +12 -0
  507. package/dist/svelte/components/RunIssues.svelte.d.ts.map +1 -0
  508. package/dist/svelte/components/RunObservation.svelte +32 -0
  509. package/dist/svelte/components/RunObservation.svelte.d.ts +12 -0
  510. package/dist/svelte/components/RunObservation.svelte.d.ts.map +1 -0
  511. package/dist/svelte/components/RunOutcomeBadge.svelte +11 -0
  512. package/dist/svelte/components/RunOutcomeBadge.svelte.d.ts +8 -0
  513. package/dist/svelte/components/RunOutcomeBadge.svelte.d.ts.map +1 -0
  514. package/dist/svelte/components/RunPanels.svelte +64 -0
  515. package/dist/svelte/components/RunPanels.svelte.d.ts +15 -0
  516. package/dist/svelte/components/RunPanels.svelte.d.ts.map +1 -0
  517. package/dist/svelte/components/RunStatusBadge.svelte +38 -0
  518. package/dist/svelte/components/RunStatusBadge.svelte.d.ts +9 -0
  519. package/dist/svelte/components/RunStatusBadge.svelte.d.ts.map +1 -0
  520. package/dist/svelte/components/RunSummary.svelte +42 -0
  521. package/dist/svelte/components/RunSummary.svelte.d.ts +11 -0
  522. package/dist/svelte/components/RunSummary.svelte.d.ts.map +1 -0
  523. package/dist/svelte/components/RunsView.svelte +162 -0
  524. package/dist/svelte/components/RunsView.svelte.d.ts +17 -0
  525. package/dist/svelte/components/RunsView.svelte.d.ts.map +1 -0
  526. package/dist/svelte/components/TypePicker.svelte +337 -0
  527. package/dist/svelte/components/TypePicker.svelte.d.ts +12 -0
  528. package/dist/svelte/components/TypePicker.svelte.d.ts.map +1 -0
  529. package/dist/svelte/components/records/RunDetail.svelte +214 -0
  530. package/dist/svelte/components/records/RunDetail.svelte.d.ts +20 -0
  531. package/dist/svelte/components/records/RunDetail.svelte.d.ts.map +1 -0
  532. package/dist/svelte/components/records/RunList.svelte +190 -0
  533. package/dist/svelte/components/records/RunList.svelte.d.ts +14 -0
  534. package/dist/svelte/components/records/RunList.svelte.d.ts.map +1 -0
  535. package/dist/svelte/components/records/RunTree.svelte +186 -0
  536. package/dist/svelte/components/records/RunTree.svelte.d.ts +5 -0
  537. package/dist/svelte/components/records/RunTree.svelte.d.ts.map +1 -0
  538. package/dist/svelte/components/records/tree-navigation.d.ts +3 -0
  539. package/dist/svelte/components/records/tree-navigation.d.ts.map +1 -0
  540. package/dist/svelte/components/records/tree-navigation.js +29 -0
  541. package/dist/svelte/components/records/tree-projection.d.ts +16 -0
  542. package/dist/svelte/components/records/tree-projection.d.ts.map +1 -0
  543. package/dist/svelte/components/records/tree-projection.js +134 -0
  544. package/dist/svelte/index.d.ts +27 -0
  545. package/dist/svelte/index.d.ts.map +1 -0
  546. package/dist/svelte/index.js +22 -0
  547. package/dist/svelte/lib/artifact-blob.d.ts +2 -0
  548. package/dist/svelte/lib/artifact-blob.d.ts.map +1 -0
  549. package/dist/svelte/lib/artifact-blob.js +1 -0
  550. package/dist/svelte/lib/run-investigation.d.ts +17 -0
  551. package/dist/svelte/lib/run-investigation.d.ts.map +1 -0
  552. package/dist/svelte/lib/run-investigation.js +44 -0
  553. package/dist/svelte/lib/run-issues.d.ts +34 -0
  554. package/dist/svelte/lib/run-issues.d.ts.map +1 -0
  555. package/dist/svelte/lib/run-issues.js +59 -0
  556. package/dist/svelte/lib/run-presentation.d.ts +16 -0
  557. package/dist/svelte/lib/run-presentation.d.ts.map +1 -0
  558. package/dist/svelte/lib/run-presentation.js +69 -0
  559. package/dist/svelte/lib/run-tree.d.ts +22 -0
  560. package/dist/svelte/lib/run-tree.d.ts.map +1 -0
  561. package/dist/svelte/lib/run-tree.js +93 -0
  562. package/dist/svelte/lib/status.d.ts +19 -0
  563. package/dist/svelte/lib/status.d.ts.map +1 -0
  564. package/dist/svelte/lib/status.js +122 -0
  565. package/dist/svelte/query-form.d.ts +50 -0
  566. package/dist/svelte/query-form.d.ts.map +1 -0
  567. package/dist/svelte/query-form.js +19 -0
  568. package/dist/svelte/runs/data.svelte.d.ts +678 -0
  569. package/dist/svelte/runs/data.svelte.d.ts.map +1 -0
  570. package/dist/svelte/runs/data.svelte.js +28 -0
  571. package/dist/svelte/runs/opening.d.ts +8 -0
  572. package/dist/svelte/runs/opening.d.ts.map +1 -0
  573. package/dist/svelte/runs/opening.js +110 -0
  574. package/dist/svelte/runs/query.d.ts +3 -0
  575. package/dist/svelte/runs/query.d.ts.map +1 -0
  576. package/dist/svelte/runs/query.js +16 -0
  577. package/dist/svelte/runs/selection.d.ts +3 -0
  578. package/dist/svelte/runs/selection.d.ts.map +1 -0
  579. package/dist/svelte/runs/selection.js +42 -0
  580. package/dist/svelte/runs/shutdown.d.ts +9 -0
  581. package/dist/svelte/runs/shutdown.d.ts.map +1 -0
  582. package/dist/svelte/runs/shutdown.js +104 -0
  583. package/dist/svelte/runs.store.svelte.d.ts +427 -0
  584. package/dist/svelte/runs.store.svelte.d.ts.map +1 -0
  585. package/dist/svelte/runs.store.svelte.js +90 -0
  586. package/dist/svelte/styles.css +16 -0
  587. package/dist/svelte/types.d.ts +29 -0
  588. package/dist/svelte/types.d.ts.map +1 -0
  589. package/dist/svelte/types.js +1 -0
  590. package/dist/svelte/viz/DescriptorPanel.svelte +104 -0
  591. package/dist/svelte/viz/DescriptorPanel.svelte.d.ts +18 -0
  592. package/dist/svelte/viz/DescriptorPanel.svelte.d.ts.map +1 -0
  593. package/dist/svelte/viz/crystal/Crystal3D.svelte +137 -0
  594. package/dist/svelte/viz/crystal/Crystal3D.svelte.d.ts +12 -0
  595. package/dist/svelte/viz/crystal/Crystal3D.svelte.d.ts.map +1 -0
  596. package/dist/svelte/viz/crystal/Crystal3DControls.svelte +253 -0
  597. package/dist/svelte/viz/crystal/Crystal3DControls.svelte.d.ts +18 -0
  598. package/dist/svelte/viz/crystal/Crystal3DControls.svelte.d.ts.map +1 -0
  599. package/dist/svelte/viz/crystal/Crystal3DRenderer.svelte +941 -0
  600. package/dist/svelte/viz/crystal/Crystal3DRenderer.svelte.d.ts +16 -0
  601. package/dist/svelte/viz/crystal/Crystal3DRenderer.svelte.d.ts.map +1 -0
  602. package/dist/svelte/viz/crystal/Crystal3DStats.svelte +110 -0
  603. package/dist/svelte/viz/crystal/Crystal3DStats.svelte.d.ts +12 -0
  604. package/dist/svelte/viz/crystal/Crystal3DStats.svelte.d.ts.map +1 -0
  605. package/dist/svelte/viz/crystal/LatticePanel.svelte +230 -0
  606. package/dist/svelte/viz/crystal/LatticePanel.svelte.d.ts +13 -0
  607. package/dist/svelte/viz/crystal/LatticePanel.svelte.d.ts.map +1 -0
  608. package/dist/svelte/viz/crystal/index.d.ts +8 -0
  609. package/dist/svelte/viz/crystal/index.d.ts.map +1 -0
  610. package/dist/svelte/viz/crystal/index.js +6 -0
  611. package/dist/svelte/viz/crystal/types.d.ts +59 -0
  612. package/dist/svelte/viz/crystal/types.d.ts.map +1 -0
  613. package/dist/svelte/viz/crystal/types.js +27 -0
  614. package/dist/svelte/viz/index.d.ts +18 -0
  615. package/dist/svelte/viz/index.d.ts.map +1 -0
  616. package/dist/svelte/viz/index.js +16 -0
  617. package/dist/svelte/viz/mfd/MFDArcGauge.svelte +59 -0
  618. package/dist/svelte/viz/mfd/MFDArcGauge.svelte.d.ts +21 -0
  619. package/dist/svelte/viz/mfd/MFDArcGauge.svelte.d.ts.map +1 -0
  620. package/dist/svelte/viz/mfd/MFDBarMeter.svelte +58 -0
  621. package/dist/svelte/viz/mfd/MFDBarMeter.svelte.d.ts +21 -0
  622. package/dist/svelte/viz/mfd/MFDBarMeter.svelte.d.ts.map +1 -0
  623. package/dist/svelte/viz/mfd/MFDHexMatrix.svelte +58 -0
  624. package/dist/svelte/viz/mfd/MFDHexMatrix.svelte.d.ts +21 -0
  625. package/dist/svelte/viz/mfd/MFDHexMatrix.svelte.d.ts.map +1 -0
  626. package/dist/svelte/viz/mfd/MFDPanel.svelte +372 -0
  627. package/dist/svelte/viz/mfd/MFDPanel.svelte.d.ts +19 -0
  628. package/dist/svelte/viz/mfd/MFDPanel.svelte.d.ts.map +1 -0
  629. package/dist/svelte/viz/mfd/MFDScope.svelte +59 -0
  630. package/dist/svelte/viz/mfd/MFDScope.svelte.d.ts +21 -0
  631. package/dist/svelte/viz/mfd/MFDScope.svelte.d.ts.map +1 -0
  632. package/dist/svelte/viz/mfd/MFDStatusGrid.svelte +65 -0
  633. package/dist/svelte/viz/mfd/MFDStatusGrid.svelte.d.ts +25 -0
  634. package/dist/svelte/viz/mfd/MFDStatusGrid.svelte.d.ts.map +1 -0
  635. package/dist/svelte/viz/mfd/grid.d.ts +37 -0
  636. package/dist/svelte/viz/mfd/grid.d.ts.map +1 -0
  637. package/dist/svelte/viz/mfd/grid.js +51 -0
  638. package/dist/svelte/viz/mfd/palette.d.ts +22 -0
  639. package/dist/svelte/viz/mfd/palette.d.ts.map +1 -0
  640. package/dist/svelte/viz/mfd/palette.js +105 -0
  641. package/dist/svelte/viz/mfd/pipeline/store.svelte.d.ts +42 -0
  642. package/dist/svelte/viz/mfd/pipeline/store.svelte.d.ts.map +1 -0
  643. package/dist/svelte/viz/mfd/pipeline/store.svelte.js +115 -0
  644. package/dist/svelte/viz/mfd/renderer/context.d.ts +47 -0
  645. package/dist/svelte/viz/mfd/renderer/context.d.ts.map +1 -0
  646. package/dist/svelte/viz/mfd/renderer/context.js +272 -0
  647. package/dist/svelte/viz/mfd/renderer/pipeline.d.ts +32 -0
  648. package/dist/svelte/viz/mfd/renderer/pipeline.d.ts.map +1 -0
  649. package/dist/svelte/viz/mfd/renderer/pipeline.js +188 -0
  650. package/dist/svelte/viz/mfd/renderer/shaders.d.ts +35 -0
  651. package/dist/svelte/viz/mfd/renderer/shaders.d.ts.map +1 -0
  652. package/dist/svelte/viz/mfd/renderer/shaders.js +837 -0
  653. package/dist/svelte/viz/mfd/types.d.ts +88 -0
  654. package/dist/svelte/viz/mfd/types.d.ts.map +1 -0
  655. package/dist/svelte/viz/mfd/types.js +31 -0
  656. package/dist/svelte/viz/registry.d.ts +36 -0
  657. package/dist/svelte/viz/registry.d.ts.map +1 -0
  658. package/dist/svelte/viz/registry.js +74 -0
  659. package/dist/test-scenario/test-scenario-emitter.d.ts +35 -0
  660. package/dist/test-scenario/test-scenario-emitter.d.ts.map +1 -0
  661. package/dist/test-scenario/test-scenario-emitter.js +64 -0
  662. package/dist/test-scenario/test-scenario-emitter.js.map +1 -0
  663. package/dist/test-scenario/test-scenario.plugin.d.ts +11 -0
  664. package/dist/test-scenario/test-scenario.plugin.d.ts.map +1 -0
  665. package/dist/test-scenario/test-scenario.plugin.js +19 -0
  666. package/dist/test-scenario/test-scenario.plugin.js.map +1 -0
  667. package/dist/test-scenario/test-scenario.type.descriptor.d.ts +12 -0
  668. package/dist/test-scenario/test-scenario.type.descriptor.d.ts.map +1 -0
  669. package/dist/test-scenario/test-scenario.type.descriptor.js +21 -0
  670. package/dist/test-scenario/test-scenario.type.descriptor.js.map +1 -0
  671. package/dist/watch.d.ts +13 -0
  672. package/dist/watch.d.ts.map +1 -0
  673. package/dist/watch.js +127 -0
  674. package/dist/watch.js.map +1 -0
  675. package/package.json +355 -4
package/dist/client.js ADDED
@@ -0,0 +1,1181 @@
1
+ /**
2
+ * RunnableClient — canonical `runtime/client` for the runnable module.
3
+ *
4
+ * Resolves the runnable-web ingest endpoint from a per-runtime host context,
5
+ * then defers to `createRunner()` for the actual
6
+ * batched-POST telemetry transport. Producers use:
7
+ *
8
+ * ```ts
9
+ * import { getVibesRunnableClient } from '@vibesdotdev/runnable/client';
10
+ *
11
+ * const runnable = await getVibesRunnableClient(context.runtime);
12
+ * const run = await runnable.createRun({ type: 'cgn-train', name: 'tiny-2pass' });
13
+ * await run.start({ N: 32, k: 64 });
14
+ * await run.metric('reward', 0.42);
15
+ * await run.done();
16
+ * ```
17
+ *
18
+ * The host supplies `runnable/host`; no process/global URL fallback exists.
19
+ */
20
+ import { CapabilityError, CaughtFailureSchema, captureRuntimeWorkspace, isCapabilityError, valueFreeFailure } from '@vibesdotdev/kernel';
21
+ import { getRuntimeMemoRevision } from '@vibesdotdev/kernel/memo-revision';
22
+ import { hashHex } from '@vibesdotdev/crypto/hash';
23
+ import { JsonObjectSchema, JsonValueSchema, JsonValueFromReaderSchema } from '@vibesdotdev/kernel/schemas/json';
24
+ import { RunnableDescriptorSchema, RunnableTypeDescriptorSchema, RunnableTelemetryDescriptorSchema, RunnableVisualizationDescriptorSchema } from "./schemas/descriptors.js";
25
+ import { OutcomeSchema, done } from "./schemas/outcome.js";
26
+ import { MemoIdentitySchema, RunRecordSchema, RunExecutionReferenceSchema, RunCompletedPayloadSchema, RUN_COMPLETED_EVENT, RunnableNativeExecutionSchema, RunnableNativeExecutionStateSchema, RunnableNativeObservationSchema, RUN_NATIVE_EXECUTION_METADATA_KEY, RunnableReadQuerySchema } from "./schemas/runs.js";
27
+ import { BaseRuntimeClient } from "@vibesdotdev/kernel/client";
28
+ import { canonical } from "./identity.js";
29
+ import { runEventEnvelopeSchema } from "./schemas/events.js";
30
+ import { captureRunAdmission, mergeRunEventMetadata, RUN_ADMISSION_METADATA_KEY, RUN_INPUT_ADMISSION_METADATA_KEY } from "./records/authority.js";
31
+ import { readInputAdmission } from "./input-admission.js";
32
+ import { createRunner } from "./runner.js";
33
+ import { recordRunHandle } from "./recording.js";
34
+ import { getRunnableInvocation, withRunnableInvocation } from "./invocation.js";
35
+ import { RunnableExecutionInputSchema, RunnableSpawnRequestSchema, RunnableStartInputSchema, RunnablePreparedInputSchema, RunnableControlActionSchema, RunnableControlInputSchema } from "./schemas/contracts.js";
36
+ import { RUNNABLE_HOST_CONTEXT_ID, RUNNABLE_STATE_HOST_CONTEXT_ID } from "./host.js";
37
+ import { RUNNABLE_SUPERVISOR_ID } from "./execution.contract.js";
38
+ import { RunnableSnapshotSchema, RunnableTrackedRunSchema, RunnableCatalogRunSchema, RunnableWatchProjectionSchema } from "./schemas/runs.js";
39
+ import { watchRunnableSnapshots } from "./watch.js";
40
+ import { RunnableDescriptionSchema, RunnableDescriptionSchemasSchema } from "./schemas/description.js";
41
+ import { bindRunContext, latestRunObservation, runContextBindings, runContextReferenceId } from "./context.js";
42
+ import { RunnableNativeCompletionOutboxSchema, RUN_NATIVE_COMPLETION_METADATA_KEY } from "./schemas/runs.js";
43
+ import { assertRunWrite } from "./records/authority.js";
44
+ const EVENTS_PATH = "/api/events";
45
+ export class RunnableClient extends BaseRuntimeClient {
46
+ resolvedUrl = null;
47
+ request;
48
+ directRun;
49
+ nativeObservers = new Map();
50
+ nativeFinalizers = new Map();
51
+ /** Parsed configs for record generations still being re-read. The oldest leaves. */
52
+ admittedConfigs = new Map();
53
+ constructor(descriptor = { id: "runnable", kind: "runtime/client" }, context, runtime) {
54
+ super(descriptor, context, runtime);
55
+ }
56
+ async onLoad() {
57
+ await super.onLoad();
58
+ const host = await this.runtime.context(RUNNABLE_HOST_CONTEXT_ID);
59
+ if (host.transport === 'in-process') {
60
+ this.directRun = options => host.createRun(options);
61
+ return;
62
+ }
63
+ this.request = host.request;
64
+ let url;
65
+ try {
66
+ url = new URL(host.eventsUrl);
67
+ }
68
+ catch (error) {
69
+ throw new CapabilityError('Runnable host supplied invalid eventsUrl.', 'INVALID_INPUT', { reason: 'runnable-events-url-invalid', cause: error });
70
+ }
71
+ if (url.protocol !== 'http:' && url.protocol !== 'https:') {
72
+ throw new CapabilityError('Runnable eventsUrl must use http or https.', 'INVALID_INPUT', { reason: 'runnable-events-url-protocol-invalid', details: { protocol: url.protocol } });
73
+ }
74
+ this.resolvedUrl = url.pathname !== '/'
75
+ ? url.toString()
76
+ : new URL(EVENTS_PATH, url).toString();
77
+ }
78
+ /** Resolved events URL after `load()`. Throws if not yet loaded. */
79
+ get eventsUrl() {
80
+ if (this.directRun) {
81
+ throw new CapabilityError('The selected in-process host has no HTTP event endpoint.', 'UNAVAILABLE', { reason: 'runnable-events-url-unavailable' });
82
+ }
83
+ if (!this.resolvedUrl) {
84
+ throw new CapabilityError('Runnable client is not loaded.', 'INTERNAL', { reason: 'runnable-client-not-loaded' });
85
+ }
86
+ return this.resolvedUrl;
87
+ }
88
+ /**
89
+ * Create a run-emitter handle. The mandatory `type` matches a
90
+ * registered `runnable/type` descriptor; the runtime client resolves
91
+ * the ingest URL once and passes it to the underlying runner.
92
+ */
93
+ async createRun(options) {
94
+ await this.ensureLoaded();
95
+ if (this.directRun)
96
+ return this.directRun(options);
97
+ return createRunner({ ...options, url: this.eventsUrl, lifecycle: this.runtime.lifecycle, request: this.request });
98
+ }
99
+ async start(input) {
100
+ const parsedInput = RunnableStartInputSchema.safeParse(input);
101
+ if (!parsedInput.success) {
102
+ throw new CapabilityError('Runnable start input is invalid.', 'INVALID_INPUT', {
103
+ reason: 'runnable-start-input-invalid',
104
+ retryable: false
105
+ });
106
+ }
107
+ const start = parsedInput.data;
108
+ await this.ensureLoaded();
109
+ const executorQuery = this.runtime
110
+ .query('runnable/executor')
111
+ .withId(start.typeId);
112
+ if (executorQuery.descriptors().length === 0)
113
+ return { runId: start.runId, spawned: false };
114
+ const executor = await executorQuery.resolve();
115
+ const request = await executor.execute({ runId: start.runId, config: start.config, configUnit: start.configUnit });
116
+ if (!request)
117
+ return { runId: start.runId, spawned: false };
118
+ const task = OutcomeSchema.safeParse(request);
119
+ if (task.success)
120
+ return { runId: start.runId, spawned: false, outcome: task.data };
121
+ const parsedRequest = RunnableSpawnRequestSchema.safeParse(request);
122
+ if (!parsedRequest.success) {
123
+ throw new CapabilityError('Runnable executor returned an invalid spawn request.', 'INVALID_INPUT', {
124
+ reason: 'runnable-spawn-request-invalid',
125
+ retryable: false
126
+ });
127
+ }
128
+ const supervisor = await this.supervisor();
129
+ return supervisor.spawn(start.runId, parsedRequest.data, start.ingestCredential);
130
+ }
131
+ async select(query) {
132
+ return (await this.runtime.query('runnable/runnable').enabled().descriptorsAsync())
133
+ .map((descriptor) => RunnableDescriptorSchema.parse(descriptor))
134
+ .filter((descriptor) => descriptor.roles.includes(query.role) &&
135
+ (!query.entity || !descriptor.entities || descriptor.entities.includes(query.entity)))
136
+ .sort((left, right) => left.cost - right.cost || left.id.localeCompare(right.id));
137
+ }
138
+ async run(id, input, options) {
139
+ return (await this.runRecorded(id, input, options)).outcome;
140
+ }
141
+ async runAll(query, input, options) {
142
+ const candidates = await this.select(query);
143
+ return Promise.all(candidates.map((candidate) => this.run(candidate.id, input, options)));
144
+ }
145
+ async runBest(query, input, options) {
146
+ const candidate = (await this.select(query))[0];
147
+ if (!candidate) {
148
+ throw new CapabilityError('No runnable covers the requested role and entity.', 'UNAVAILABLE', { reason: 'runnable-selection-empty' });
149
+ }
150
+ const selected = await this.selectNamed(candidate.id);
151
+ return (await this.executeRecorded(selected.descriptor, input, options, { coldStart: true, cost: selected.descriptor.cost }, selected.impl)).outcome;
152
+ }
153
+ async runRecorded(id, input, options) {
154
+ const selected = await this.selectNamed(id);
155
+ return this.executeRecorded(selected.descriptor, input, options, { named: true }, selected.impl);
156
+ }
157
+ /** Receive an already admitted native execution through this same record owner, without dispatching another job. */
158
+ async recordNativeExecution(id, input, execute, options, nativeExecution) {
159
+ const selected = await this.selectNamed(id);
160
+ if (selected.descriptor.execution !== 'native') {
161
+ throw new CapabilityError('Receiving execution must belong to a native Runnable.', 'INVALID_INPUT', { reason: 'runnable-native-admission-invalid' });
162
+ }
163
+ const owner = { execute };
164
+ if (selected.impl.prepareInput)
165
+ owner.prepareInput = selected.impl.prepareInput.bind(selected.impl);
166
+ return this.executeRecorded({ ...selected.descriptor, memo: false }, input, options, { named: true }, owner, nativeExecution);
167
+ }
168
+ /** Attach the receiving owner's receipt to the producer's certified, frozen input record. */
169
+ async recordPreparedExecution(runId, execute, nativeExecution, options) {
170
+ const receipt = RunnableNativeExecutionSchema.parse(nativeExecution);
171
+ const held = options?.held?.record.id === runId ? options.held : await this.inputAdmission(runId);
172
+ if (!held || held.admission.owner.kind !== 'runnable/runnable') {
173
+ throw new CapabilityError('Prepared native execution needs its selected owner admission.', 'PERMISSION_DENIED', { reason: 'runnable-input-admission-mismatch' });
174
+ }
175
+ assertRunWrite(held.record, captureRunAdmission(this.runtime), await this.scopeIdentity());
176
+ const selected = await this.runtime.query('runnable/runnable').withId(held.admission.owner.id).select();
177
+ if (!selected)
178
+ throw new CapabilityError('The prepared native owner is unavailable.', 'UNAVAILABLE', { reason: 'runnable-native-owner-unavailable' });
179
+ const descriptor = RunnableDescriptorSchema.parse(selected.descriptor);
180
+ if (descriptor.id !== held.record.runnableId || descriptor.execution !== 'native') {
181
+ throw new CapabilityError('The receiving owner differs from its prepared admission.', 'PERMISSION_DENIED', { reason: 'runnable-native-execution-mismatch' });
182
+ }
183
+ return this.executeRecorded({ ...descriptor, memo: false, nativeResult: receipt.result.mode }, held.record.metadata['runnable.submittedInput'] ?? null, {
184
+ signal: options?.signal, configUnit: RunnableExecutionInputSchema.shape.configUnit.parse(held.record.metadata.configUnit)
185
+ }, { named: true }, { execute }, receipt, held.record);
186
+ }
187
+ async selectNamed(id) {
188
+ const selected = await this.runtime.query('runnable/runnable').withId(id).enabled().select();
189
+ if (!selected) {
190
+ throw new CapabilityError(`Runnable '${id}' is not registered.`, 'UNAVAILABLE', { reason: 'runnable-unknown' });
191
+ }
192
+ return { descriptor: RunnableDescriptorSchema.parse(selected.descriptor), impl: selected.impl };
193
+ }
194
+ async describe(id, receive) {
195
+ const selected = await this.selectNamed(id);
196
+ const executor = selected.descriptor.execution === 'native' ? null : await this.runtime
197
+ .query('runnable/executor')
198
+ .enabled().filter(candidate => candidate.runnableType === selected.descriptor.type).select();
199
+ const described = executor
200
+ ? await executor.impl.describe?.(selected.descriptor.settings)
201
+ : await selected.impl.describe?.();
202
+ const description = RunnableDescriptionSchema.parse(JsonValueFromReaderSchema.parse({
203
+ descriptor: selected.descriptor,
204
+ ...RunnableDescriptionSchemasSchema.parse(described ?? {})
205
+ }));
206
+ if (receive)
207
+ await receive(description);
208
+ else
209
+ return description;
210
+ }
211
+ /** Validated only after the record owner's authorized by-ID read. */
212
+ async inputAdmission(runId, expectedConfig) {
213
+ const record = await this.storedRecord(runId);
214
+ if (!record)
215
+ return null;
216
+ const admission = await readInputAdmission(this.runtime, record);
217
+ if (admission && expectedConfig !== undefined && admission.configDigest !== await hashHex(this.runtime, 'sha256', canonical(expectedConfig))) {
218
+ throw new CapabilityError('Queued input differs from the owner-admitted config.', 'PERMISSION_DENIED', { reason: 'runnable-input-admission-mismatch' });
219
+ }
220
+ return admission ? { record, admission } : null;
221
+ }
222
+ /** Receiving execution must also possess the persistence owner's write authority. */
223
+ async attachInputAdmission(runId, config, jobId, known) {
224
+ if (known?.record.id === runId && known.admission.configDigest !== await hashHex(this.runtime, 'sha256', canonical(config))) {
225
+ throw new CapabilityError('Queued input differs from the owner-admitted config.', 'PERMISSION_DENIED', { reason: 'runnable-input-admission-mismatch' });
226
+ }
227
+ const held = known?.record.id === runId ? known : await this.inputAdmission(runId, config);
228
+ if (!held || held.record.ref?.jobId !== jobId) {
229
+ throw new CapabilityError(held ? 'Execution reference differs from its input admission.' : 'Execution input admission is unavailable to this owner.', 'PERMISSION_DENIED', {
230
+ reason: 'runnable-input-admission-mismatch',
231
+ details: {
232
+ runId, jobId, admissionPresent: held !== null,
233
+ admittedJobId: held?.record.ref?.jobId ?? null
234
+ }
235
+ });
236
+ }
237
+ await (await this.records()).save(held.record);
238
+ return held;
239
+ }
240
+ /** Reuse the authorized record's emitter; this does not admit another execution or start event. */
241
+ async attachHandle(runId) {
242
+ const record = await this.record(runId);
243
+ if (!record)
244
+ throw new CapabilityError('The execution record is unavailable.', 'NOT_FOUND', { reason: 'runnable-run-not-found' });
245
+ const records = await this.records();
246
+ await records.save(record);
247
+ const native = record.metadata[RUN_NATIVE_EXECUTION_METADATA_KEY] === undefined
248
+ ? undefined : RunnableNativeExecutionStateSchema.parse(record.metadata[RUN_NATIVE_EXECUTION_METADATA_KEY]);
249
+ const attempt = native?.attempts.at(-1);
250
+ if (native && (!attempt || attempt.generation !== native.generation)) {
251
+ throw new CapabilityError('Native handle has no admitted physical attempt.', 'UNAVAILABLE', { reason: 'runnable-native-attempt-unavailable' });
252
+ }
253
+ // A retained handle belongs to this admission even after another attempt starts.
254
+ const emitter = await this.createRun({ runId: record.id, type: record.runnableType, name: record.name ?? record.runnableId,
255
+ executionGeneration: native?.generation, executionAttempt: attempt?.attempt });
256
+ return recordRunHandle(emitter, record, records).handle;
257
+ }
258
+ async scopeIdentity() {
259
+ let workspace = null;
260
+ if (this.runtime.hasContext('runtime/workspace-path')) {
261
+ try {
262
+ workspace = await this.runtime.context('runtime/workspace-path');
263
+ }
264
+ catch (error) {
265
+ if (!(error instanceof Error && CapabilityError.isAbsenceOf(error, 'context', 'runtime/workspace-path')))
266
+ throw error;
267
+ }
268
+ }
269
+ // Only principal-declaring hosts call requestPrincipal; an inactive invocation is a real refusal.
270
+ // Identity contains no JWT or session credential.
271
+ const principal = this.runtime.scope.capabilities?.requestPrincipals === true ? this.runtime.requestPrincipal() : null;
272
+ let caller = null;
273
+ if (principal?.kind === 'user') {
274
+ caller = JsonValueSchema.parse({
275
+ kind: principal.kind, userId: principal.userId, orgId: principal.orgId ?? null,
276
+ projectId: principal.projectId ?? null, agentId: principal.agentPrincipal?.agentId ?? null,
277
+ agentOwner: principal.agentPrincipal?.owner ?? null,
278
+ agentKeyId: principal.agentPrincipal?.keyId ?? null,
279
+ agentScopes: [...(principal.agentPrincipal?.scopes ?? [])].sort(),
280
+ roles: [...(principal.roles ?? [])].sort(),
281
+ orgs: principal.orgs ? [...principal.orgs].sort((left, right) => left.id.localeCompare(right.id)) : [],
282
+ staff: principal.staff ?? null, isSuperuser: principal.isSuperuser ?? null
283
+ });
284
+ }
285
+ else if (principal?.kind === 'service') {
286
+ caller = JsonValueSchema.parse({
287
+ kind: principal.kind, caller: principal.caller, onBehalfOf: principal.onBehalfOf ?? null,
288
+ delegation: principal.delegation ?? null
289
+ });
290
+ }
291
+ else if (principal) {
292
+ caller = principal;
293
+ }
294
+ const invocation = captureRuntimeWorkspace(this.runtime);
295
+ const workspaceIdentity = invocation ? {
296
+ id: invocation.id ?? null,
297
+ target: invocation.target ?? null,
298
+ remoteHostId: invocation.remoteHostId ?? null,
299
+ access: invocation.access ?? null
300
+ } : null;
301
+ const scope = invocation
302
+ ? { ...this.runtime.scope, workspace: { root: invocation.root, access: invocation.access } }
303
+ : this.runtime.scope;
304
+ return canonical({ scope, workspace, ...(workspaceIdentity ? { workspaceIdentity } : {}), caller });
305
+ }
306
+ async runs(input) {
307
+ const query = RunnableReadQuerySchema.strict().parse(input);
308
+ const { status, ...ownerQuery } = query;
309
+ const host = await this.stateHost();
310
+ const rows = host.tracking ? await host.tracking.list(ownerQuery) : host.reads?.list ? await host.reads.list(ownerQuery) : null;
311
+ if (rows) {
312
+ const views = await Promise.all(rows.map(record => this.trackingView(record)));
313
+ return views.filter(record => status === undefined || record.outcome?.status === status);
314
+ }
315
+ if (query.type !== undefined || query.under !== undefined || query.host !== undefined || query.input !== undefined || query.about !== undefined) {
316
+ throw new CapabilityError('The selected Runnable host does not support scoped read queries.', 'UNAVAILABLE', { reason: 'runnable-read-query-unavailable' });
317
+ }
318
+ const records = await this.records();
319
+ const scope = await this.scopeIdentity();
320
+ const views = await Promise.all((await records.list({ ...ownerQuery, scope })).map(record => this.trackingView(record)));
321
+ return views.filter(record => status === undefined || record.outcome?.status === status);
322
+ }
323
+ /** Read by identifier through the persistence owner's actual admission boundary. */
324
+ async record(input) {
325
+ const record = await this.storedRecord(input);
326
+ if (!record)
327
+ return null;
328
+ const observation = await this.observeNative(record);
329
+ return observation ? this.nativeView(record, observation) : record;
330
+ }
331
+ /** Status is parsed every read. Config is reused while the input digest is unchanged. */
332
+ admittedConfig(id, inputDigest, config) {
333
+ const key = `${id}:${inputDigest}`;
334
+ const remembered = this.admittedConfigs.get(key);
335
+ if (remembered) {
336
+ this.admittedConfigs.delete(key);
337
+ this.admittedConfigs.set(key, remembered);
338
+ return remembered;
339
+ }
340
+ const parsed = JsonObjectSchema.parse(config);
341
+ this.admittedConfigs.set(key, parsed);
342
+ while (this.admittedConfigs.size > 64) {
343
+ const oldest = this.admittedConfigs.keys().next().value;
344
+ if (oldest === undefined)
345
+ break;
346
+ this.admittedConfigs.delete(oldest);
347
+ }
348
+ return parsed;
349
+ }
350
+ async storedRecord(input) {
351
+ const id = RunRecordSchema.shape.id.parse(input);
352
+ const host = await this.stateHost();
353
+ const raw = host.reads
354
+ ? await host.reads.get(id)
355
+ : (await (await this.records()).list({ scope: await this.scopeIdentity(), id })).find(record => record.id === id) ?? null;
356
+ if (!raw)
357
+ return null;
358
+ const shell = RunRecordSchema.omit({ config: true }).parse(raw);
359
+ return { ...shell, config: this.admittedConfig(shell.id, shell.inputDigest, raw.config) };
360
+ }
361
+ async resolveNativeOwner(owner) {
362
+ return this.runtime.query(owner.kind).withId(owner.id).resolve();
363
+ }
364
+ nativeObserverView(owner, implementation) {
365
+ if (!implementation.observe)
366
+ throw new CapabilityError('The admitted native owner cannot observe its receipt.', 'UNAVAILABLE', {
367
+ reason: 'runnable-native-observation-unavailable'
368
+ });
369
+ return {
370
+ owner,
371
+ observe: implementation.observe.bind(implementation),
372
+ subscribeObservation: implementation.subscribeObservation?.bind(implementation)
373
+ };
374
+ }
375
+ async nativeObserver(record) {
376
+ const execution = RunnableNativeExecutionStateSchema.parse(record.metadata[RUN_NATIVE_EXECUTION_METADATA_KEY]);
377
+ if (execution.observer) {
378
+ return this.nativeObserverView(execution.observer, await this.resolveNativeOwner(execution.observer));
379
+ }
380
+ const native = await this.runtime.query('runnable/runnable')
381
+ .withId(record.runnableId).enabled().select();
382
+ if (native?.impl.observe)
383
+ return this.nativeObserverView({ kind: 'runnable/runnable', id: native.descriptor.id }, native.impl);
384
+ const executor = await this.runtime.query('runnable/executor')
385
+ .enabled().filter(owner => owner.runnableType === record.runnableType).select();
386
+ if (!executor?.impl.observe)
387
+ throw new CapabilityError('The native execution owner does not provide receipt observation.', 'UNAVAILABLE', { reason: 'runnable-native-observation-unavailable' });
388
+ return this.nativeObserverView({ kind: 'runnable/executor', id: executor.descriptor.id }, executor.impl);
389
+ }
390
+ async observeNative(record) {
391
+ if (record.metadata[RUN_NATIVE_EXECUTION_METADATA_KEY] === undefined)
392
+ return null;
393
+ return RunnableNativeObservationSchema.parse(await (await this.nativeObserver(record)).observe(record));
394
+ }
395
+ /** Explicit admitted execution repair. Read APIs never call this operation. */
396
+ async reconcileNativeExecution(runId) {
397
+ const pending = this.nativeFinalizers.get(runId);
398
+ if (pending) {
399
+ const record = await this.storedRecord(runId);
400
+ if (!record)
401
+ throw new CapabilityError('Native execution record is unavailable.', 'NOT_FOUND', { reason: 'runnable-run-not-found' });
402
+ assertRunWrite(record, captureRunAdmission(this.runtime), await this.scopeIdentity());
403
+ return pending;
404
+ }
405
+ const work = this.reconcileNativeOnce(runId);
406
+ this.nativeFinalizers.set(runId, work);
407
+ try {
408
+ return await work;
409
+ }
410
+ finally {
411
+ if (this.nativeFinalizers.get(runId) === work)
412
+ this.nativeFinalizers.delete(runId);
413
+ }
414
+ }
415
+ async reconcileNativeOnce(runId) {
416
+ let record = await this.storedRecord(runId);
417
+ if (!record)
418
+ throw new CapabilityError('Native execution record is unavailable.', 'NOT_FOUND', { reason: 'runnable-run-not-found' });
419
+ assertRunWrite(record, captureRunAdmission(this.runtime), await this.scopeIdentity());
420
+ const observed = await this.observeNative(record);
421
+ if (!observed)
422
+ throw new CapabilityError('Run has no admitted native execution reference.', 'INVALID_INPUT', { reason: 'runnable-native-execution-absent' });
423
+ // The body persists its attempt evidence before the queue commits its
424
+ // receipt. Refresh that evidence after observing the terminal receipt.
425
+ record = await this.storedRecord(runId);
426
+ if (!record)
427
+ throw new CapabilityError('Native execution record is unavailable.', 'NOT_FOUND', { reason: 'runnable-run-not-found' });
428
+ assertRunWrite(record, captureRunAdmission(this.runtime), await this.scopeIdentity());
429
+ const execution = RunnableNativeExecutionStateSchema.parse(record.metadata[RUN_NATIVE_EXECUTION_METADATA_KEY]);
430
+ if (observed.terminal && execution.generation !== observed.generation) {
431
+ throw new CapabilityError('Native execution changed while its terminal receipt was being observed.', 'CONFLICT', { reason: 'runnable-native-execution-changed' });
432
+ }
433
+ const outbox = RunnableNativeCompletionOutboxSchema.parse(record.metadata[RUN_NATIVE_COMPLETION_METADATA_KEY] ?? []);
434
+ const records = await this.records();
435
+ if (observed.terminal && !outbox.some(completion => completion.receiptId === observed.receiptId)) {
436
+ if (!observed.outcome)
437
+ throw new CapabilityError('Terminal native receipt has no task outcome.', 'UNAVAILABLE', { reason: 'runnable-native-outcome-unavailable' });
438
+ const attempt = execution.attempts.at(-1);
439
+ if (!attempt || attempt.generation !== observed.generation)
440
+ throw new CapabilityError('Terminal native receipt has no admitted attempt.', 'UNAVAILABLE', { reason: 'runnable-native-attempt-unavailable' });
441
+ const view = this.nativeView(record, observed);
442
+ const eventId = `completion-${await hashHex(this.runtime, 'sha256', canonical({ runId, receipt: observed.receiptId }))}`;
443
+ outbox.push({
444
+ receiptId: observed.receiptId,
445
+ eventId, generation: observed.generation, attempt: attempt.attempt,
446
+ timestamp: observed.endedAt ?? Date.now(), delivered: false,
447
+ payload: RunCompletedPayloadSchema.parse(JsonValueFromReaderSchema.parse({ runId, occurrenceId: eventId, generation: observed.generation, attempt: attempt.attempt, runnableId: view.runnableId, status: view.status, outcome: observed.outcome, parentRunId: view.parentRunId }))
448
+ });
449
+ view.metadata[RUN_NATIVE_COMPLETION_METADATA_KEY] = JsonValueFromReaderSchema.parse(outbox);
450
+ await records.save(view);
451
+ }
452
+ for (const completion of outbox.filter(occurrence => !occurrence.delivered)) {
453
+ const emitter = await this.createRun({ runId, type: record.runnableType, name: record.name ?? record.runnableId,
454
+ executionGeneration: completion.generation, executionAttempt: completion.attempt });
455
+ await emitter.event(RUN_COMPLETED_EVENT, JsonObjectSchema.parse(completion.payload), { eventId: completion.eventId, timestamp: completion.timestamp });
456
+ await emitter.event('status', { status: completion.payload.status }, { eventId: `${completion.eventId}:status`, timestamp: completion.timestamp });
457
+ await this.runtime.hooks('runnable.run').emit('completed', completion.payload);
458
+ // Another native generation may have started while delivery waited.
459
+ // Only acknowledge this occurrence on that latest admitted snapshot.
460
+ const latest = await this.storedRecord(runId);
461
+ if (!latest)
462
+ throw new CapabilityError('Native execution record is unavailable.', 'NOT_FOUND', { reason: 'runnable-run-not-found' });
463
+ assertRunWrite(latest, captureRunAdmission(this.runtime), await this.scopeIdentity());
464
+ const pending = RunnableNativeCompletionOutboxSchema.parse(latest.metadata[RUN_NATIVE_COMPLETION_METADATA_KEY] ?? []);
465
+ const delivered = pending.find(occurrence => occurrence.receiptId === completion.receiptId);
466
+ if (!delivered || canonical({ ...delivered, delivered: false }) !== canonical({ ...completion, delivered: false })) {
467
+ throw new CapabilityError('Native completion occurrence changed during delivery.', 'CONFLICT', { reason: 'runnable-native-completion-changed' });
468
+ }
469
+ delivered.delivered = true;
470
+ latest.metadata[RUN_NATIVE_COMPLETION_METADATA_KEY] = JsonValueFromReaderSchema.parse(pending);
471
+ await records.save(latest);
472
+ }
473
+ return observed;
474
+ }
475
+ async followNativeCompletion(record) {
476
+ const execution = RunnableNativeExecutionStateSchema.parse(record.metadata[RUN_NATIVE_EXECUTION_METADATA_KEY]);
477
+ const observerId = `${record.id}:${execution.generation}`;
478
+ if (this.nativeObservers.has(observerId))
479
+ return;
480
+ const owner = await this.nativeObserver(record);
481
+ if (!owner.subscribeObservation)
482
+ throw new CapabilityError('The native execution owner cannot subscribe to its durable receipt.', 'UNAVAILABLE', { reason: 'runnable-native-subscription-unavailable' });
483
+ const subscribe = owner.subscribeObservation.bind(owner);
484
+ const invocation = this.runtime.captureInvocation();
485
+ const ready = Promise.withResolvers();
486
+ const work = this.runtime.lifecycle.own(() => invocation.run(async () => {
487
+ let changed = Promise.withResolvers();
488
+ const stop = await subscribe(record, () => changed.resolve());
489
+ try {
490
+ ready.resolve();
491
+ for (;;) {
492
+ const notified = changed.promise;
493
+ if ((await this.reconcileNativeExecution(record.id)).terminal)
494
+ return;
495
+ const signal = this.runtime.lifecycle.signal;
496
+ await new Promise(resolve => {
497
+ const cancelled = () => resolve();
498
+ if (signal.aborted)
499
+ resolve();
500
+ else
501
+ signal.addEventListener('abort', cancelled, { once: true });
502
+ void notified.then(() => {
503
+ signal.removeEventListener('abort', cancelled);
504
+ resolve();
505
+ });
506
+ });
507
+ if (signal.aborted)
508
+ return;
509
+ changed = Promise.withResolvers();
510
+ }
511
+ }
512
+ finally {
513
+ await stop();
514
+ }
515
+ }));
516
+ this.nativeObservers.set(observerId, work);
517
+ void work.catch(error => {
518
+ ready.reject(error);
519
+ const caught = CaughtFailureSchema.parse(error);
520
+ if (!(this.runtime.lifecycle.signal.aborted && isCapabilityError(caught) && caught.code === 'CANCELLED')) {
521
+ this.runtime.diagnostics.error('Native Runnable completion observation failed', { scope: 'runnable:native-completion', plugin: 'runnable', error: caught });
522
+ }
523
+ }).finally(() => this.nativeObservers.delete(observerId));
524
+ await ready.promise;
525
+ }
526
+ nativeView(record, observation) {
527
+ const view = RunRecordSchema.parse(record);
528
+ view.status = observation.status;
529
+ if (observation.progress !== undefined)
530
+ view.progress = observation.progress;
531
+ if (observation.outcome !== undefined)
532
+ view.outcome = observation.outcome;
533
+ else
534
+ delete view.outcome;
535
+ if (observation.endedAt !== undefined)
536
+ view.endedAt = observation.endedAt;
537
+ else
538
+ delete view.endedAt;
539
+ return view;
540
+ }
541
+ /** Display-only fallback for older rows, from the declared owner rather than an inferred ID. */
542
+ namedRun(run) {
543
+ if (run.name)
544
+ return run;
545
+ const declared = this.runtime.query('runnable/runnable').withId(run.runnableId).descriptors()[0];
546
+ return declared ? { ...run, name: RunnableDescriptorSchema.parse(declared).name } : run;
547
+ }
548
+ async trackingView(input) {
549
+ const record = this.namedRun(RunnableTrackedRunSchema.parse(JsonValueFromReaderSchema.parse(input)));
550
+ const binding = runContextBindings(this.runtime).find(binding => binding.runnables.includes(record.runnableId));
551
+ if (binding) {
552
+ const value = JsonValueFromReaderSchema.parse(record);
553
+ const referenceId = runContextReferenceId(value, binding);
554
+ const reference = referenceId ? await this.storedRecord(referenceId) : null;
555
+ record.context = bindRunContext(value, binding, reference ? JsonValueFromReaderSchema.parse(reference) : undefined);
556
+ }
557
+ if (record.metadata[RUN_NATIVE_EXECUTION_METADATA_KEY] === undefined)
558
+ return record;
559
+ const strict = RunRecordSchema.parse(record);
560
+ const observation = await this.observeNative(strict);
561
+ return observation ? RunnableTrackedRunSchema.parse({ ...this.nativeView(strict, observation), context: record.context }) : record;
562
+ }
563
+ /**
564
+ * List replacement. Direct children are the matched rows that name a parent
565
+ * in this same read. Persisted telemetry stays on `snapshot`.
566
+ */
567
+ async catalogSnapshots(query) {
568
+ const matched = await this.runs(query);
569
+ const children = new Map();
570
+ for (const run of matched) {
571
+ if (!run.parentRunId)
572
+ continue;
573
+ const listed = children.get(run.parentRunId);
574
+ if (listed)
575
+ listed.push(run);
576
+ else
577
+ children.set(run.parentRunId, [run]);
578
+ }
579
+ return matched.map(run => ({
580
+ run,
581
+ metrics: [],
582
+ logs: [],
583
+ artifacts: [],
584
+ children: children.get(run.id) ?? []
585
+ }));
586
+ }
587
+ /** Recorded list state is a distinct projection; full evidence and native observation stay on detail reads. */
588
+ async watchCatalog(input, listener, failureOrOptions) {
589
+ return this.runtime.runInvocation(async () => {
590
+ const query = RunnableReadQuerySchema.strict().parse(input);
591
+ const options = typeof failureOrOptions === 'function' ? { onError: failureOrOptions } : failureOrOptions ?? {};
592
+ return this.openReadWatch(query, listener, async () => {
593
+ const host = await this.stateHost();
594
+ const source = host.tracking ?? host.reads;
595
+ if (!source?.list)
596
+ throw new CapabilityError('Runnable host does not provide catalog reads.', 'UNAVAILABLE', {
597
+ reason: 'runnable-catalog-unavailable'
598
+ });
599
+ const rows = source.listCatalog
600
+ ? await source.listCatalog(query)
601
+ : await Promise.all((await source.list(query)).map(async (run) => {
602
+ const binding = runContextBindings(this.runtime).find(binding => binding.runnables.includes(run.runnableId));
603
+ const value = JsonValueFromReaderSchema.parse(run);
604
+ const referenceId = binding ? runContextReferenceId(value, binding) : undefined;
605
+ const reference = referenceId ? await this.storedRecord(referenceId) : null;
606
+ return RunnableCatalogRunSchema.parse({ ...run, ...(binding ? { context: bindRunContext(value, binding, reference ? JsonValueFromReaderSchema.parse(reference) : undefined) } : {}) });
607
+ }));
608
+ const runs = rows.map(run => this.namedRun(run));
609
+ const children = new Map();
610
+ for (const run of runs) {
611
+ if (!run.parentRunId)
612
+ continue;
613
+ const group = children.get(run.parentRunId) ?? [];
614
+ group.push(run);
615
+ children.set(run.parentRunId, group);
616
+ }
617
+ return runs.map(run => ({ run, children: children.get(run.id) ?? [] }));
618
+ }, options, 'catalog');
619
+ });
620
+ }
621
+ /** Append producer or caller evidence through this record’s admitted writer. */
622
+ async appendEvent(runId, type, payload) {
623
+ const event = runEventEnvelopeSchema.safeParse({ ...payload, type });
624
+ if (!event.success || type.startsWith('runnable.')) {
625
+ throw new CapabilityError('Caller evidence must be an extension event outside the reserved Runnable protocol.', 'INVALID_INPUT', { reason: 'runnable-caller-event-invalid' });
626
+ }
627
+ const record = await this.record(runId);
628
+ if (!record)
629
+ throw new CapabilityError('Run not found.', 'NOT_FOUND', { reason: 'runnable-run-not-found' });
630
+ assertRunWrite(record, captureRunAdmission(this.runtime), await this.scopeIdentity());
631
+ if (record.endedAt !== undefined || ['completed', 'stopped', 'error'].includes(record.status)) {
632
+ throw new CapabilityError('This execution has ended and cannot receive new events.', 'CONFLICT', { reason: 'runnable-execution-ended' });
633
+ }
634
+ const handle = await this.attachHandle(runId);
635
+ await handle.event(type, JsonObjectSchema.parse(payload));
636
+ }
637
+ /** Read the full owner snapshot, including persisted telemetry and direct children. */
638
+ async snapshot(runId) {
639
+ const host = await this.stateHost();
640
+ const run = host.tracking ? await host.tracking.get(runId) : await this.storedRecord(runId);
641
+ if (!run)
642
+ throw new CapabilityError('Run not found.', 'NOT_FOUND', { reason: 'runnable-run-not-found' });
643
+ const telemetry = host.telemetry;
644
+ if (!telemetry)
645
+ throw new CapabilityError('Runnable host does not provide persisted telemetry reads.', 'UNAVAILABLE', { reason: 'runnable-telemetry-reads-unavailable' });
646
+ const evidence = await telemetry.read(runId);
647
+ const declarations = this.runtime.query('runnable/telemetry').enabled().descriptors().map(descriptor => RunnableTelemetryDescriptorSchema.parse(descriptor));
648
+ return RunnableSnapshotSchema.parse(JsonValueFromReaderSchema.parse({ run: await this.trackingView(run), ...evidence,
649
+ children: await this.runs({ parentRunId: runId }), observation: latestRunObservation(evidence.logs, declarations) }));
650
+ }
651
+ async watch(input, listener, failureOrOptions, nativeOptions) {
652
+ return this.runtime.runInvocation(() => this.openWatch(input, listener, failureOrOptions, nativeOptions));
653
+ }
654
+ async openWatch(input, listener, failureOrOptions, nativeOptions) {
655
+ const query = RunnableReadQuerySchema.strict().parse(input);
656
+ const options = typeof failureOrOptions === 'function'
657
+ ? { ...nativeOptions, onError: failureOrOptions }
658
+ : { ...nativeOptions, ...failureOrOptions };
659
+ const projection = RunnableWatchProjectionSchema.optional().parse(options.projection) ?? 'snapshot';
660
+ let nativeJobs;
661
+ const dependencies = (snapshots) => {
662
+ // An unlisted record can enter a native status query without a persisted write.
663
+ if (query.status !== undefined || snapshots.length === 0)
664
+ return undefined;
665
+ const jobs = new Set();
666
+ for (const snapshot of snapshots) {
667
+ for (const run of [snapshot.run, ...snapshot.children]) {
668
+ const native = run.metadata[RUN_NATIVE_EXECUTION_METADATA_KEY];
669
+ const admitted = native === undefined ? undefined : RunnableNativeExecutionStateSchema.safeParse(native);
670
+ const reference = admitted === undefined ? run.ref : admitted.success ? admitted.data.reference : undefined;
671
+ if (reference?.jobId === undefined)
672
+ return undefined;
673
+ jobs.add(reference.jobId);
674
+ }
675
+ }
676
+ return jobs;
677
+ };
678
+ return this.openReadWatch(query, listener, async () => {
679
+ try {
680
+ const snapshots = projection === 'records' ? await this.catalogSnapshots(query)
681
+ : await Promise.all((await this.runs(query)).map(run => this.snapshot(run.id)));
682
+ nativeJobs = dependencies(snapshots);
683
+ return snapshots;
684
+ }
685
+ catch (cause) {
686
+ nativeJobs = undefined;
687
+ throw cause;
688
+ }
689
+ }, options, 'native', jobId => nativeJobs === undefined || nativeJobs.has(jobId));
690
+ }
691
+ async openReadWatch(query, listener, read, options, purpose = 'native', nativeJobRelevant) {
692
+ const host = await this.stateHost();
693
+ const source = host.tracking ?? host.reads;
694
+ const subscription = purpose === 'catalog' ? source?.subscribeCatalog ?? source?.subscribe : source?.subscribe;
695
+ const subscribe = subscription?.bind(source);
696
+ if (!subscribe)
697
+ throw new CapabilityError('Runnable host does not provide live tracking subscriptions.', 'UNAVAILABLE', {
698
+ reason: 'runnable-watch-unavailable'
699
+ });
700
+ const inherited = await getRunnableInvocation(this.runtime);
701
+ const signals = [this.runtime.lifecycle.signal, this.runtime.invocationSignal, inherited?.signal, options.signal]
702
+ .filter((value) => value !== undefined);
703
+ const signal = AbortSignal.any(signals);
704
+ return watchRunnableSnapshots(this.runtime, {
705
+ read,
706
+ subscribe: changed => subscribe(query, reference => {
707
+ if (!nativeJobRelevant || reference === undefined) {
708
+ changed();
709
+ return;
710
+ }
711
+ const native = RunExecutionReferenceSchema.safeParse(reference);
712
+ if (!native.success || native.data.jobId === undefined || nativeJobRelevant(native.data.jobId))
713
+ changed();
714
+ }),
715
+ failed: async (cause) => {
716
+ if (options.onError)
717
+ await options.onError(this.failureFacts(cause));
718
+ else
719
+ this.runtime.diagnostics.error('Runnable watch failed', { scope: 'runnable:watch', plugin: 'runnable', error: cause });
720
+ }
721
+ }, listener, signal);
722
+ }
723
+ /** Resolve panels from explicit producer declarations, independent of feature names. */
724
+ async visualizations(query) {
725
+ let selection;
726
+ if ('runId' in query) {
727
+ const [record] = await this.runs({ id: query.runId });
728
+ if (!record)
729
+ throw new CapabilityError('Run not found.', 'NOT_FOUND', { reason: 'runnable-run-not-found' });
730
+ selection = {
731
+ type: record.runnableType,
732
+ runnableId: record.runnableId,
733
+ reportedTelemetry: RunnableDescriptorSchema.shape.telemetry.parse(record.metadata.telemetry) ?? []
734
+ };
735
+ }
736
+ else {
737
+ selection = query;
738
+ }
739
+ const type = this.runtime.hasKind('runnable/type')
740
+ ? await this.runtime.query('runnable/type').withId(selection.type).enabled().firstDescriptorAsync()
741
+ : null;
742
+ const runnable = selection.runnableId && this.runtime.hasKind('runnable/runnable')
743
+ ? await this.runtime.query('runnable/runnable').withId(selection.runnableId).enabled().firstDescriptorAsync()
744
+ : null;
745
+ const telemetry = new Set([
746
+ ...(type ? RunnableTypeDescriptorSchema.parse(type).telemetry ?? [] : []),
747
+ ...(runnable ? RunnableDescriptorSchema.parse(runnable).telemetry ?? [] : []),
748
+ ...(selection.reportedTelemetry ?? [])
749
+ ]);
750
+ if (telemetry.size > 0) {
751
+ const declared = this.runtime.hasKind('runnable/telemetry')
752
+ ? await this.runtime.query('runnable/telemetry').enabled().filter(descriptor => telemetry.has(descriptor.id)).descriptorsAsync()
753
+ : [];
754
+ const available = new Set(declared.map(descriptor => RunnableTelemetryDescriptorSchema.parse(descriptor).id));
755
+ const missing = [...telemetry].filter(id => !available.has(id));
756
+ if (missing.length > 0) {
757
+ throw new CapabilityError('Run telemetry declarations are unavailable.', 'UNAVAILABLE', {
758
+ reason: 'runnable-telemetry-unavailable', details: { telemetry: missing }
759
+ });
760
+ }
761
+ }
762
+ if (!this.runtime.hasKind('runnable/visualization'))
763
+ return [];
764
+ return (await this.runtime.query('runnable/visualization').enabled().descriptorsAsync())
765
+ .map(descriptor => RunnableVisualizationDescriptorSchema.parse(descriptor))
766
+ .filter(descriptor => descriptor.telemetryId === '*' || telemetry.has(descriptor.telemetryId));
767
+ }
768
+ async records() {
769
+ const records = (await this.stateHost()).records;
770
+ if (!records) {
771
+ throw new CapabilityError('Runnable host does not provide durable run records.', 'UNAVAILABLE', { reason: 'runnable-records-unavailable' });
772
+ }
773
+ return records;
774
+ }
775
+ failureFacts(error) {
776
+ const caught = CaughtFailureSchema.parse(error);
777
+ const facts = valueFreeFailure(caught);
778
+ const failure = { name: facts.name, code: facts.code ?? 'ERROR', message: facts.name };
779
+ if (facts.reason !== undefined)
780
+ failure.reason = facts.reason;
781
+ if (isCapabilityError(caught)) {
782
+ failure.message = caught.message;
783
+ failure.retryable = caught.retryable;
784
+ if (caught.recoveryHint !== undefined)
785
+ failure.recoveryHint = caught.recoveryHint;
786
+ if (caught.details !== undefined)
787
+ failure.details = JsonValueSchema.parse(JSON.parse(JSON.stringify(caught.details)));
788
+ }
789
+ return failure;
790
+ }
791
+ executeRecorded(descriptor, input, options, rankReason, implementation, nativeExecution, preparedRecord) {
792
+ return this.runtime.runInvocation(() => this.executeRecordedInInvocation(descriptor, input, options, rankReason, implementation, nativeExecution, preparedRecord));
793
+ }
794
+ async executeRecordedInInvocation(descriptor, input, options, rankReason, implementation, nativeExecution, preparedRecord) {
795
+ const inherited = await getRunnableInvocation(this.runtime);
796
+ const signals = [this.runtime.invocationSignal, inherited?.signal, options?.signal].filter((value) => value !== undefined);
797
+ const signal = signals.length === 0 ? undefined : AbortSignal.any(signals);
798
+ signal?.throwIfAborted();
799
+ const submittedInput = JsonValueSchema.parse(input);
800
+ const submittedObject = JsonObjectSchema.safeParse(submittedInput);
801
+ let config = submittedObject.success ? submittedObject.data : { input: submittedInput };
802
+ const parentRunId = options?.parentRunId ?? inherited?.runId;
803
+ const completionHooks = this.runtime.hooks('runnable.run');
804
+ const records = await this.records();
805
+ const scope = await this.scopeIdentity();
806
+ const received = nativeExecution === undefined ? undefined : RunnableNativeExecutionSchema.parse(nativeExecution);
807
+ const receivedRunId = preparedRecord?.id ?? (received === undefined ? undefined : `native-${await hashHex(this.runtime, 'sha256', canonical({ scope, execution: received.id }))}`);
808
+ const previous = preparedRecord ?? (receivedRunId === undefined ? null : await this.storedRecord(receivedRunId));
809
+ if (preparedRecord && !previous)
810
+ throw new CapabilityError('The prepared native record is unavailable.', 'NOT_FOUND', { reason: 'runnable-run-not-found' });
811
+ const previousExecution = previous?.metadata[RUN_NATIVE_EXECUTION_METADATA_KEY] === undefined ? undefined : RunnableNativeExecutionStateSchema.parse(previous.metadata[RUN_NATIVE_EXECUTION_METADATA_KEY]);
812
+ const previousAdmission = previous ? await readInputAdmission(this.runtime, previous) : null;
813
+ if (previous && received) {
814
+ const sameReference = previous.ref !== undefined && previous.ref.jobId === received.reference.jobId && Object.entries(previous.ref).every(([key, value]) => received.reference[key] === value);
815
+ if (!previousAdmission || previous.runnableId !== descriptor.id || !sameReference ||
816
+ canonical(previous.metadata['runnable.submittedInput']) !== canonical(submittedInput) ||
817
+ (!previousExecution && !preparedRecord) ||
818
+ (previousExecution && (canonical(previousExecution.reference) !== canonical(received.reference) || previousExecution.id !== received.id ||
819
+ canonical(previousExecution.owner) !== canonical(received.owner) || canonical(previousExecution.result) !== canonical(received.result))) ||
820
+ (options?.configUnit !== undefined && previous.metadata.configUnit !== options.configUnit)) {
821
+ throw new CapabilityError('Native execution differs from its recorded input admission.', 'PERMISSION_DENIED', { reason: 'runnable-native-execution-mismatch' });
822
+ }
823
+ const last = previousExecution?.attempts.at(-1);
824
+ if (last && (received.generation < last.generation || (received.generation === last.generation && received.attempt < last.attempt))) {
825
+ throw new CapabilityError('Native execution attempt has already been admitted.', 'CONFLICT', { reason: 'runnable-native-execution-attempt-stale' });
826
+ }
827
+ }
828
+ const identity = options?.memoIdentity ? MemoIdentitySchema.parse(options.memoIdentity) : undefined;
829
+ let configUnit = RunnableExecutionInputSchema.shape.configUnit.parse(options?.configUnit ?? inherited?.configUnit);
830
+ const executorQuery = this.runtime.query('runnable/executor')
831
+ .enabled().filter((executor) => executor.runnableType === descriptor.type);
832
+ const selectedExecutor = descriptor.execution === 'native' ? null : await executorQuery.select();
833
+ const preparationOwner = selectedExecutor
834
+ ? { kind: 'runnable/executor', id: selectedExecutor.descriptor.id }
835
+ : { kind: 'runnable/runnable', id: descriptor.id };
836
+ let preparationContext;
837
+ let preparationFailure;
838
+ try {
839
+ const prepared = previous ? {
840
+ config: previous.config, context: previousAdmission?.context,
841
+ configUnit: RunnableExecutionInputSchema.shape.configUnit.parse(previous.metadata.configUnit)
842
+ } : selectedExecutor
843
+ ? await selectedExecutor.impl.prepareInput?.({ config, settings: descriptor.settings, configUnit }, { signal, configUnit })
844
+ : await implementation.prepareInput?.(submittedInput, { signal, configUnit });
845
+ if (prepared !== undefined) {
846
+ const admitted = RunnablePreparedInputSchema.parse(prepared);
847
+ config = admitted.config;
848
+ preparationContext = admitted.context;
849
+ configUnit = admitted.configUnit ?? configUnit;
850
+ }
851
+ signal?.throwIfAborted();
852
+ }
853
+ catch (cause) {
854
+ preparationFailure = { cause };
855
+ }
856
+ const memoUnits = options?.memoUnits === undefined ? undefined : [...new Set([...options.memoUnits, ...(configUnit === undefined ? [] : [configUnit])])];
857
+ if (identity && identity.scope !== scope) {
858
+ throw new CapabilityError('Memo identity belongs to another invocation scope.', 'INVALID_INPUT', { reason: 'runnable-memo-scope-mismatch' });
859
+ }
860
+ let runtimeRevision;
861
+ let memoDiagnostic;
862
+ if (descriptor.memo) {
863
+ if (memoUnits === undefined) {
864
+ memoDiagnostic = 'configuration-units-undeclared';
865
+ }
866
+ else {
867
+ try {
868
+ runtimeRevision = await getRuntimeMemoRevision(this.runtime, { units: memoUnits });
869
+ }
870
+ catch (error) {
871
+ const failure = CaughtFailureSchema.parse(error);
872
+ if (isCapabilityError(failure) && ['runtime-memo-revision-unavailable', 'runtime-memo-revision-unstable'].includes(failure.reason ?? '')) {
873
+ memoDiagnostic = failure.reason;
874
+ }
875
+ else {
876
+ throw error;
877
+ }
878
+ }
879
+ }
880
+ }
881
+ const inputDigest = previous?.inputDigest ?? await hashHex(this.runtime, 'sha256', canonical({ input: config, configUnit: configUnit ?? null, identity: identity ?? null, runtimeRevision: runtimeRevision ?? null }));
882
+ let reused;
883
+ if (!preparationFailure && descriptor.memo && runtimeRevision) {
884
+ reused = (await records.list({ scope, runnable: descriptor.id, inputDigest, status: 'done' }))
885
+ .map((record) => RunRecordSchema.parse(record))
886
+ .find((record) => record.outcome?.status === 'done' && record.metadata.memoEligible === true);
887
+ }
888
+ const emitter = await this.createRun({ runId: receivedRunId, type: descriptor.type, name: descriptor.name ?? descriptor.id,
889
+ executionGeneration: received?.generation, executionAttempt: received?.attempt });
890
+ const record = previous ? RunRecordSchema.parse(previous) : RunRecordSchema.parse({
891
+ id: emitter.runId, scope, status: 'running', runnableType: descriptor.type, runnableId: descriptor.id, name: descriptor.name ?? descriptor.id, config,
892
+ progress: 0, startedAt: Date.now(), metadata: { ...mergeRunEventMetadata({}, options?.metadata ?? {}), [RUN_ADMISSION_METADATA_KEY]: captureRunAdmission(this.runtime) }, inputDigest, rankReason
893
+ });
894
+ record.metadata['runnable.submittedInput'] = submittedInput;
895
+ if (!preparationFailure && !previous) {
896
+ record.metadata[RUN_INPUT_ADMISSION_METADATA_KEY] = {
897
+ version: 1, runId: record.id, runnableId: descriptor.id, inputDigest,
898
+ configDigest: await hashHex(this.runtime, 'sha256', canonical(config)), owner: preparationOwner,
899
+ ...(preparationContext === undefined ? {} : { context: preparationContext }),
900
+ ...(inherited?.runId === undefined ? {} : { enclosingRunId: inherited.runId })
901
+ };
902
+ }
903
+ if (received) {
904
+ const previousAttempts = previousExecution?.attempts ?? [];
905
+ const reentry = previousAttempts.some(attempt => attempt.generation === received.generation && attempt.attempt === received.attempt);
906
+ record.ref = { ...record.ref, ...received.reference };
907
+ record.status = 'running';
908
+ delete record.outcome;
909
+ delete record.endedAt;
910
+ record.metadata[RUN_NATIVE_EXECUTION_METADATA_KEY] = JsonObjectSchema.parse({
911
+ id: received.id, owner: received.owner, generation: received.generation, reference: received.reference, result: previousExecution?.result ?? received.result,
912
+ attempts: reentry ? previousAttempts : [...previousAttempts, { generation: received.generation, attempt: received.attempt, maxAttempts: received.maxAttempts, startedAt: Date.now() }]
913
+ });
914
+ const execution = RunnableNativeExecutionStateSchema.parse(record.metadata[RUN_NATIVE_EXECUTION_METADATA_KEY]);
915
+ execution.observer = previousExecution?.observer ?? (await this.nativeObserver(record)).owner;
916
+ record.metadata[RUN_NATIVE_EXECUTION_METADATA_KEY] = JsonObjectSchema.parse(execution);
917
+ }
918
+ if (parentRunId && !previous)
919
+ record.parentRunId = parentRunId;
920
+ if (options?.about !== undefined)
921
+ record.metadata.about = JsonValueSchema.parse(options.about);
922
+ if (configUnit !== undefined)
923
+ record.metadata.configUnit = configUnit;
924
+ if (descriptor.memo)
925
+ record.metadata.memoEligible = false;
926
+ if (memoDiagnostic)
927
+ record.metadata.memo = memoDiagnostic;
928
+ if (reused) {
929
+ record.metadata.reusedRunId = reused.id;
930
+ if (reused.ref)
931
+ record.ref = reused.ref;
932
+ if (reused.approval)
933
+ record.approval = reused.approval;
934
+ }
935
+ const recording = recordRunHandle(emitter, record, records, () => this.storedRecord(record.id));
936
+ const handle = recording.handle;
937
+ await recording.save();
938
+ if (received)
939
+ await this.followNativeCompletion(record);
940
+ let outcome;
941
+ let executionStatus = 'completed';
942
+ let producerFailure;
943
+ try {
944
+ await handle.start(config);
945
+ if (preparationFailure)
946
+ throw preparationFailure.cause;
947
+ if (memoDiagnostic)
948
+ await handle.log('info', 'Authoritative memo identity unavailable; executing without cached reuse.', { reason: memoDiagnostic });
949
+ if (reused?.outcome) {
950
+ outcome = OutcomeSchema.parse(reused.outcome);
951
+ }
952
+ else {
953
+ if (selectedExecutor) {
954
+ const executor = selectedExecutor.impl;
955
+ const result = await withRunnableInvocation(this.runtime, { runId: handle.runId, signal, configUnit }, () => executor.execute({ runId: handle.runId, config, settings: descriptor.settings, configUnit }, handle, { signal }));
956
+ const task = OutcomeSchema.safeParse(result);
957
+ if (task.success) {
958
+ outcome = task.data;
959
+ }
960
+ else {
961
+ const request = RunnableSpawnRequestSchema.parse(result);
962
+ const supervisor = await this.supervisor();
963
+ if (!supervisor.run) {
964
+ throw new CapabilityError('Runnable supervisor cannot await process completion.', 'UNAVAILABLE', { reason: 'runnable-completion-unavailable' });
965
+ }
966
+ outcome = OutcomeSchema.parse(await supervisor.run(handle.runId, request, undefined, { signal }));
967
+ }
968
+ }
969
+ else {
970
+ const result = await withRunnableInvocation(this.runtime, { runId: handle.runId, signal, configUnit }, () => implementation.execute(config, handle, { signal, configUnit }));
971
+ if (descriptor.nativeResult === 'void') {
972
+ if (result !== undefined)
973
+ throw new CapabilityError('Void runnable returned a value.', 'INVALID_INPUT', { reason: 'runnable-native-result-invalid' });
974
+ outcome = done(null);
975
+ }
976
+ else if (descriptor.nativeResult === 'outcome') {
977
+ outcome = OutcomeSchema.parse(result);
978
+ }
979
+ else {
980
+ outcome = done(JsonValueSchema.parse(result));
981
+ }
982
+ }
983
+ }
984
+ signal?.throwIfAborted();
985
+ outcome = OutcomeSchema.parse(outcome);
986
+ if (outcome.status === 'skipped' && outcome.cause.kind === 'cancelled')
987
+ executionStatus = 'stopped';
988
+ }
989
+ catch (error) {
990
+ producerFailure = { cause: error };
991
+ const failure = this.failureFacts(error);
992
+ if (signal?.aborted || failure.code === 'CANCELLED') {
993
+ executionStatus = 'stopped';
994
+ outcome = {
995
+ status: 'skipped', reason: 'Runnable invocation cancelled.',
996
+ cause: { kind: 'cancelled', provenance: JsonValueSchema.parse(failure) }
997
+ };
998
+ }
999
+ else {
1000
+ executionStatus = 'error';
1001
+ outcome = { status: 'not-done', reason: 'Runnable execution failed.', failure };
1002
+ }
1003
+ }
1004
+ let revisionRefusal;
1005
+ if (descriptor.memo && runtimeRevision && outcome.status === 'done') {
1006
+ try {
1007
+ const current = await getRuntimeMemoRevision(this.runtime, { units: memoUnits });
1008
+ record.metadata.memoEligible = canonical(current) === canonical(runtimeRevision);
1009
+ if (!record.metadata.memoEligible)
1010
+ record.metadata.memo = 'revision-changed-during-execution';
1011
+ }
1012
+ catch (error) {
1013
+ const failure = CaughtFailureSchema.parse(error);
1014
+ if (isCapabilityError(failure) && ['runtime-memo-revision-unavailable', 'runtime-memo-revision-unstable'].includes(failure.reason ?? '')) {
1015
+ record.metadata.memo = failure.reason ?? 'revision-unavailable-after-execution';
1016
+ }
1017
+ else {
1018
+ revisionRefusal = { error };
1019
+ }
1020
+ }
1021
+ }
1022
+ if (!received) {
1023
+ const attached = await recording.handoff();
1024
+ if (attached) {
1025
+ await this.followNativeCompletion(attached);
1026
+ const execution = RunnableNativeExecutionStateSchema.parse(attached.metadata[RUN_NATIVE_EXECUTION_METADATA_KEY]);
1027
+ await this.nativeObservers.get(`${record.id}:${execution.generation}`);
1028
+ const completed = await this.storedRecord(record.id);
1029
+ if (!completed?.outcome)
1030
+ throw new CapabilityError('The native execution has no completed receipt.', 'UNAVAILABLE', { reason: 'runnable-native-outcome-unavailable' });
1031
+ if (descriptor.memo) {
1032
+ completed.metadata.memoEligible = record.metadata.memoEligible ?? false;
1033
+ if (record.metadata.memo !== undefined)
1034
+ completed.metadata.memo = record.metadata.memo;
1035
+ await records.save(completed);
1036
+ }
1037
+ if (revisionRefusal)
1038
+ throw revisionRefusal.error;
1039
+ if (producerFailure && completed.status === 'completed')
1040
+ throw producerFailure.cause;
1041
+ return { runId: record.id, outcome: OutcomeSchema.parse(completed.outcome) };
1042
+ }
1043
+ }
1044
+ record.outcome = outcome;
1045
+ record.endedAt = Date.now();
1046
+ record.status = executionStatus;
1047
+ record.progress = 1;
1048
+ if (received) {
1049
+ const execution = RunnableNativeExecutionStateSchema.parse(record.metadata[RUN_NATIVE_EXECUTION_METADATA_KEY]);
1050
+ const attempt = execution.attempts.at(-1);
1051
+ attempt.endedAt = record.endedAt;
1052
+ attempt.outcome = outcome;
1053
+ record.metadata[RUN_NATIVE_EXECUTION_METADATA_KEY] = JsonObjectSchema.parse(execution);
1054
+ delete record.outcome;
1055
+ delete record.endedAt;
1056
+ record.status = 'running';
1057
+ await recording.save();
1058
+ return { runId: record.id, outcome: outcome };
1059
+ }
1060
+ await recording.save();
1061
+ const completed = RunCompletedPayloadSchema.parse({
1062
+ runId: record.id,
1063
+ runnableId: descriptor.id,
1064
+ status: record.status,
1065
+ outcome,
1066
+ parentRunId: record.parentRunId
1067
+ });
1068
+ await handle.event(RUN_COMPLETED_EVENT, completed);
1069
+ if (executionStatus === 'completed')
1070
+ await handle.done();
1071
+ else
1072
+ await handle.status(executionStatus);
1073
+ await completionHooks.emit('completed', completed);
1074
+ if (revisionRefusal)
1075
+ throw revisionRefusal.error;
1076
+ return { runId: record.id, outcome: outcome };
1077
+ }
1078
+ async hydrateState() {
1079
+ const host = await this.stateHost();
1080
+ await host.hydrateOnce();
1081
+ }
1082
+ async getState() {
1083
+ return (await this.stateHost()).state;
1084
+ }
1085
+ async executionController(record) {
1086
+ const native = record.metadata[RUN_NATIVE_EXECUTION_METADATA_KEY] === undefined
1087
+ ? undefined : RunnableNativeExecutionStateSchema.parse(record.metadata[RUN_NATIVE_EXECUTION_METADATA_KEY]);
1088
+ const owner = native?.observer ?? (await readInputAdmission(this.runtime, record))?.owner;
1089
+ return owner ? this.resolveNativeOwner(owner) : null;
1090
+ }
1091
+ async controlRecord(runId) {
1092
+ if (!this.runtime.hasContext(RUNNABLE_STATE_HOST_CONTEXT_ID))
1093
+ return null;
1094
+ const host = await this.stateHost();
1095
+ if (!host.reads && !host.records)
1096
+ return null;
1097
+ return this.storedRecord(runId);
1098
+ }
1099
+ async controls(runId) {
1100
+ const record = await this.controlRecord(runId);
1101
+ if (record) {
1102
+ const owner = await this.executionController(record);
1103
+ if (owner?.controls)
1104
+ return RunnableControlActionSchema.array().parse(await owner.controls(record));
1105
+ if (record.metadata[RUN_NATIVE_EXECUTION_METADATA_KEY] !== undefined)
1106
+ return [];
1107
+ }
1108
+ return await this.isSupervised(runId) ? ['stop', 'pause', 'resume'] : [];
1109
+ }
1110
+ async control(input) {
1111
+ const request = RunnableControlInputSchema.parse(input);
1112
+ const record = await this.controlRecord(request.runId);
1113
+ if (!record)
1114
+ return (await this.supervisor()).control(request.runId, request.action);
1115
+ assertRunWrite(record, captureRunAdmission(this.runtime), await this.scopeIdentity());
1116
+ const owner = await this.executionController(record);
1117
+ const actions = owner?.controls ? RunnableControlActionSchema.array().parse(await owner.controls(record)) : [];
1118
+ if (owner?.control && actions.includes(request.action)) {
1119
+ const { runId: _runId, ...control } = request;
1120
+ return owner.control(record, control);
1121
+ }
1122
+ if (record.metadata[RUN_NATIVE_EXECUTION_METADATA_KEY] === undefined && await this.isSupervised(request.runId)) {
1123
+ return (await this.supervisor()).control(request.runId, request.action);
1124
+ }
1125
+ throw new CapabilityError('The admitted owner does not support this Runnable control.', 'UNAVAILABLE', {
1126
+ reason: 'runnable-control-unavailable', details: { action: request.action }
1127
+ });
1128
+ }
1129
+ async isSupervised(runId) {
1130
+ return (await this.supervisor()).isSupervised(runId);
1131
+ }
1132
+ async status(runId) {
1133
+ return (await this.supervisor()).status(runId);
1134
+ }
1135
+ /**
1136
+ * The supervisor's loader is consumer-scoped, so on any other declared
1137
+ * hardware resolution fails instead of this client inventing an idle or
1138
+ * unspawned answer.
1139
+ */
1140
+ supervisor() {
1141
+ return this.runtime
1142
+ .query('runnable/supervisor')
1143
+ .withId(RUNNABLE_SUPERVISOR_ID).resolve();
1144
+ }
1145
+ stateHost() {
1146
+ return this.runtime.context(RUNNABLE_STATE_HOST_CONTEXT_ID);
1147
+ }
1148
+ }
1149
+ /**
1150
+ * The `runnable` runtime client of the runtime the caller was handed. The
1151
+ * runtime is required: there is no ambient fallback to a process-global
1152
+ * runtime (RC02, D39), and no on-demand plugin registration. A missing
1153
+ * client kind or client is refused typed.
1154
+ */
1155
+ export async function getVibesRunnableClient(runtime) {
1156
+ if (!runtime.hasKind('runtime/client')) {
1157
+ throw new CapabilityError("Runtime kind 'runtime/client' is not registered; compose the runtime-client and runnable plugins before resolving runnable.", 'UNAVAILABLE', { reason: 'runnable-client-unavailable', retryable: false });
1158
+ }
1159
+ let client;
1160
+ try {
1161
+ client = await runtime.query('runtime/client').withId('runnable').resolve();
1162
+ }
1163
+ catch (error) {
1164
+ if (error instanceof Error && CapabilityError.isAbsenceOf(error, 'runtime/client', 'runnable')) {
1165
+ throw new CapabilityError('No runtime client registered with id "runnable". Compose the runnable plugin before use.', 'UNAVAILABLE', {
1166
+ reason: 'runnable-client-unavailable',
1167
+ retryable: false
1168
+ });
1169
+ }
1170
+ throw error;
1171
+ }
1172
+ if (!client) {
1173
+ throw new CapabilityError('No runtime client registered with id "runnable". Compose the runnable plugin before use.', 'UNAVAILABLE', {
1174
+ reason: 'runnable-client-unavailable',
1175
+ retryable: false
1176
+ });
1177
+ }
1178
+ return client;
1179
+ }
1180
+ export default RunnableClient;
1181
+ //# sourceMappingURL=client.js.map