@kindgi/api 0.1.4 → 0.1.5-rc.0

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 (507) hide show
  1. package/dist/agent-binding.d.ts +13 -0
  2. package/dist/agent-binding.d.ts.map +1 -1
  3. package/dist/agent-pins.d.ts.map +1 -1
  4. package/dist/agent-pins.js +18 -2
  5. package/dist/agent-pins.js.map +1 -1
  6. package/dist/app.d.ts +110 -17
  7. package/dist/app.d.ts.map +1 -1
  8. package/dist/app.js +163 -35
  9. package/dist/app.js.map +1 -1
  10. package/dist/block-publish.d.ts +56 -0
  11. package/dist/block-publish.d.ts.map +1 -0
  12. package/dist/block-publish.js +132 -0
  13. package/dist/block-publish.js.map +1 -0
  14. package/dist/caller.d.ts +24 -0
  15. package/dist/caller.d.ts.map +1 -0
  16. package/dist/caller.js +47 -0
  17. package/dist/caller.js.map +1 -0
  18. package/dist/capability-binding.d.ts +11 -0
  19. package/dist/capability-binding.d.ts.map +1 -1
  20. package/dist/derive-agent-version.d.ts +7 -0
  21. package/dist/derive-agent-version.d.ts.map +1 -1
  22. package/dist/derive-agent-version.js +4 -0
  23. package/dist/derive-agent-version.js.map +1 -1
  24. package/dist/errors.d.ts.map +1 -1
  25. package/dist/errors.js +73 -7
  26. package/dist/errors.js.map +1 -1
  27. package/dist/eval-case-binding.d.ts +16 -4
  28. package/dist/eval-case-binding.d.ts.map +1 -1
  29. package/dist/eval-run-binding.d.ts +31 -0
  30. package/dist/eval-run-binding.d.ts.map +1 -1
  31. package/dist/eval-run-dispatcher.d.ts +7 -0
  32. package/dist/eval-run-dispatcher.d.ts.map +1 -1
  33. package/dist/eval-run-dispatcher.js.map +1 -1
  34. package/dist/eval-sample.d.ts +11 -0
  35. package/dist/eval-sample.d.ts.map +1 -0
  36. package/dist/eval-sample.js +34 -0
  37. package/dist/eval-sample.js.map +1 -0
  38. package/dist/eval-suite-binding.d.ts +13 -0
  39. package/dist/eval-suite-binding.d.ts.map +1 -1
  40. package/dist/eval-suite-binding.js.map +1 -1
  41. package/dist/flow-binding.d.ts +18 -0
  42. package/dist/flow-binding.d.ts.map +1 -1
  43. package/dist/flow-pins.d.ts.map +1 -1
  44. package/dist/flow-pins.js +18 -2
  45. package/dist/flow-pins.js.map +1 -1
  46. package/dist/gate.d.ts.map +1 -1
  47. package/dist/gate.js +25 -0
  48. package/dist/gate.js.map +1 -1
  49. package/dist/handler-binding.d.ts +32 -0
  50. package/dist/handler-binding.d.ts.map +1 -1
  51. package/dist/hitl-binding.d.ts +23 -0
  52. package/dist/hitl-binding.d.ts.map +1 -1
  53. package/dist/identity-directory-binding.d.ts +82 -4
  54. package/dist/identity-directory-binding.d.ts.map +1 -1
  55. package/dist/identity-provider-binding.d.ts +197 -17
  56. package/dist/identity-provider-binding.d.ts.map +1 -1
  57. package/dist/improvement-pass-binding.d.ts +196 -0
  58. package/dist/improvement-pass-binding.d.ts.map +1 -0
  59. package/dist/improvement-pass-binding.js +9 -0
  60. package/dist/improvement-pass-binding.js.map +1 -0
  61. package/dist/index.d.ts +35 -17
  62. package/dist/index.d.ts.map +1 -1
  63. package/dist/index.js +11 -3
  64. package/dist/index.js.map +1 -1
  65. package/dist/judged-dispatcher.d.ts +25 -4
  66. package/dist/judged-dispatcher.d.ts.map +1 -1
  67. package/dist/judged-dispatcher.js +43 -6
  68. package/dist/judged-dispatcher.js.map +1 -1
  69. package/dist/judgment-binding.d.ts +25 -1
  70. package/dist/judgment-binding.d.ts.map +1 -1
  71. package/dist/mcp-endpoint-binding.d.ts +7 -0
  72. package/dist/mcp-endpoint-binding.d.ts.map +1 -1
  73. package/dist/memory-binding.d.ts +124 -17
  74. package/dist/memory-binding.d.ts.map +1 -1
  75. package/dist/memory-erasure-binding.d.ts +145 -0
  76. package/dist/memory-erasure-binding.d.ts.map +1 -0
  77. package/dist/memory-erasure-binding.js +4 -0
  78. package/dist/memory-erasure-binding.js.map +1 -0
  79. package/dist/middleware/auth.d.ts +66 -13
  80. package/dist/middleware/auth.d.ts.map +1 -1
  81. package/dist/middleware/auth.js +150 -50
  82. package/dist/middleware/auth.js.map +1 -1
  83. package/dist/middleware/authorize.d.ts +6 -0
  84. package/dist/middleware/authorize.d.ts.map +1 -1
  85. package/dist/middleware/authorize.js +113 -4
  86. package/dist/middleware/authorize.js.map +1 -1
  87. package/dist/middleware/error-mapper.d.ts +5 -0
  88. package/dist/middleware/error-mapper.d.ts.map +1 -1
  89. package/dist/middleware/error-mapper.js +14 -1
  90. package/dist/middleware/error-mapper.js.map +1 -1
  91. package/dist/middleware/idempotency.d.ts +70 -5
  92. package/dist/middleware/idempotency.d.ts.map +1 -1
  93. package/dist/middleware/idempotency.js +174 -41
  94. package/dist/middleware/idempotency.js.map +1 -1
  95. package/dist/middleware/key-project.d.ts +17 -0
  96. package/dist/middleware/key-project.d.ts.map +1 -0
  97. package/dist/middleware/key-project.js +75 -0
  98. package/dist/middleware/key-project.js.map +1 -0
  99. package/dist/middleware/principal.d.ts.map +1 -1
  100. package/dist/middleware/principal.js +9 -5
  101. package/dist/middleware/principal.js.map +1 -1
  102. package/dist/middleware/project-ref.d.ts.map +1 -1
  103. package/dist/middleware/project-ref.js +3 -0
  104. package/dist/middleware/project-ref.js.map +1 -1
  105. package/dist/openapi/generate.d.ts.map +1 -1
  106. package/dist/openapi/generate.js +5 -2
  107. package/dist/openapi/generate.js.map +1 -1
  108. package/dist/openapi/operations.d.ts.map +1 -1
  109. package/dist/openapi/operations.js +918 -139
  110. package/dist/openapi/operations.js.map +1 -1
  111. package/dist/openapi/schemas.d.ts +90 -13
  112. package/dist/openapi/schemas.d.ts.map +1 -1
  113. package/dist/openapi/schemas.js +2081 -359
  114. package/dist/openapi/schemas.js.map +1 -1
  115. package/dist/person-grants-binding.d.ts +77 -0
  116. package/dist/person-grants-binding.d.ts.map +1 -0
  117. package/dist/person-grants-binding.js +4 -0
  118. package/dist/person-grants-binding.js.map +1 -0
  119. package/dist/proposal-service.d.ts +121 -0
  120. package/dist/proposal-service.d.ts.map +1 -0
  121. package/dist/proposal-service.js +447 -0
  122. package/dist/proposal-service.js.map +1 -0
  123. package/dist/proposal-status.d.ts +60 -0
  124. package/dist/proposal-status.d.ts.map +1 -0
  125. package/dist/proposal-status.js +109 -0
  126. package/dist/proposal-status.js.map +1 -0
  127. package/dist/provider-binding.d.ts +10 -0
  128. package/dist/provider-binding.d.ts.map +1 -1
  129. package/dist/publish-refused.d.ts +18 -3
  130. package/dist/publish-refused.d.ts.map +1 -1
  131. package/dist/publish-refused.js +18 -3
  132. package/dist/publish-refused.js.map +1 -1
  133. package/dist/routes/adapters.d.ts +2 -1
  134. package/dist/routes/adapters.d.ts.map +1 -1
  135. package/dist/routes/adapters.js +3 -1
  136. package/dist/routes/adapters.js.map +1 -1
  137. package/dist/routes/agent-releases.d.ts +55 -3
  138. package/dist/routes/agent-releases.d.ts.map +1 -1
  139. package/dist/routes/agent-releases.js +85 -55
  140. package/dist/routes/agent-releases.js.map +1 -1
  141. package/dist/routes/agents.d.ts +12 -1
  142. package/dist/routes/agents.d.ts.map +1 -1
  143. package/dist/routes/agents.js +100 -2
  144. package/dist/routes/agents.js.map +1 -1
  145. package/dist/routes/approvals.d.ts +15 -3
  146. package/dist/routes/approvals.d.ts.map +1 -1
  147. package/dist/routes/approvals.js +133 -122
  148. package/dist/routes/approvals.js.map +1 -1
  149. package/dist/routes/artifacts.d.ts +25 -3
  150. package/dist/routes/artifacts.d.ts.map +1 -1
  151. package/dist/routes/artifacts.js +116 -7
  152. package/dist/routes/artifacts.js.map +1 -1
  153. package/dist/routes/auth.d.ts +25 -1
  154. package/dist/routes/auth.d.ts.map +1 -1
  155. package/dist/routes/auth.js +655 -281
  156. package/dist/routes/auth.js.map +1 -1
  157. package/dist/routes/blocks.d.ts.map +1 -1
  158. package/dist/routes/blocks.js +2 -42
  159. package/dist/routes/blocks.js.map +1 -1
  160. package/dist/routes/capabilities.d.ts +2 -1
  161. package/dist/routes/capabilities.d.ts.map +1 -1
  162. package/dist/routes/capabilities.js +6 -1
  163. package/dist/routes/capabilities.js.map +1 -1
  164. package/dist/routes/compliance.d.ts +9 -10
  165. package/dist/routes/compliance.d.ts.map +1 -1
  166. package/dist/routes/compliance.js +42 -61
  167. package/dist/routes/compliance.js.map +1 -1
  168. package/dist/routes/conversations.d.ts +8 -1
  169. package/dist/routes/conversations.d.ts.map +1 -1
  170. package/dist/routes/conversations.js +87 -8
  171. package/dist/routes/conversations.js.map +1 -1
  172. package/dist/routes/cost.d.ts +7 -1
  173. package/dist/routes/cost.d.ts.map +1 -1
  174. package/dist/routes/cost.js +22 -3
  175. package/dist/routes/cost.js.map +1 -1
  176. package/dist/routes/denied.d.ts +11 -0
  177. package/dist/routes/denied.d.ts.map +1 -0
  178. package/dist/routes/denied.js +17 -0
  179. package/dist/routes/denied.js.map +1 -0
  180. package/dist/routes/deployments.d.ts +2 -1
  181. package/dist/routes/deployments.d.ts.map +1 -1
  182. package/dist/routes/deployments.js +44 -12
  183. package/dist/routes/deployments.js.map +1 -1
  184. package/dist/routes/eval-comparison.d.ts.map +1 -1
  185. package/dist/routes/eval-comparison.js +69 -1
  186. package/dist/routes/eval-comparison.js.map +1 -1
  187. package/dist/routes/eval-overrides.d.ts +18 -0
  188. package/dist/routes/eval-overrides.d.ts.map +1 -0
  189. package/dist/routes/eval-overrides.js +81 -0
  190. package/dist/routes/eval-overrides.js.map +1 -0
  191. package/dist/routes/eval-runs.d.ts +10 -1
  192. package/dist/routes/eval-runs.d.ts.map +1 -1
  193. package/dist/routes/eval-runs.js +63 -7
  194. package/dist/routes/eval-runs.js.map +1 -1
  195. package/dist/routes/eval-suites.d.ts.map +1 -1
  196. package/dist/routes/eval-suites.js +20 -1
  197. package/dist/routes/eval-suites.js.map +1 -1
  198. package/dist/routes/event-triggers.d.ts +5 -1
  199. package/dist/routes/event-triggers.d.ts.map +1 -1
  200. package/dist/routes/event-triggers.js +26 -3
  201. package/dist/routes/event-triggers.js.map +1 -1
  202. package/dist/routes/export-signing-keys.d.ts +12 -0
  203. package/dist/routes/export-signing-keys.d.ts.map +1 -0
  204. package/dist/routes/export-signing-keys.js +24 -0
  205. package/dist/routes/export-signing-keys.js.map +1 -0
  206. package/dist/routes/flows.d.ts.map +1 -1
  207. package/dist/routes/flows.js +9 -1
  208. package/dist/routes/flows.js.map +1 -1
  209. package/dist/routes/gate-policies.d.ts +4 -1
  210. package/dist/routes/gate-policies.d.ts.map +1 -1
  211. package/dist/routes/gate-policies.js +29 -5
  212. package/dist/routes/gate-policies.js.map +1 -1
  213. package/dist/routes/guardrails.d.ts +16 -14
  214. package/dist/routes/guardrails.d.ts.map +1 -1
  215. package/dist/routes/guardrails.js +39 -3
  216. package/dist/routes/guardrails.js.map +1 -1
  217. package/dist/routes/identity.d.ts +20 -4
  218. package/dist/routes/identity.d.ts.map +1 -1
  219. package/dist/routes/identity.js +246 -6
  220. package/dist/routes/identity.js.map +1 -1
  221. package/dist/routes/improvement-passes.d.ts +52 -0
  222. package/dist/routes/improvement-passes.d.ts.map +1 -0
  223. package/dist/routes/improvement-passes.js +449 -0
  224. package/dist/routes/improvement-passes.js.map +1 -0
  225. package/dist/routes/judged-suites.d.ts +50 -0
  226. package/dist/routes/judged-suites.d.ts.map +1 -1
  227. package/dist/routes/judged-suites.js +66 -27
  228. package/dist/routes/judged-suites.js.map +1 -1
  229. package/dist/routes/judgment-context.d.ts +18 -2
  230. package/dist/routes/judgment-context.d.ts.map +1 -1
  231. package/dist/routes/judgment-context.js +63 -5
  232. package/dist/routes/judgment-context.js.map +1 -1
  233. package/dist/routes/judgment-flow-context.d.ts.map +1 -1
  234. package/dist/routes/judgment-flow-context.js +14 -2
  235. package/dist/routes/judgment-flow-context.js.map +1 -1
  236. package/dist/routes/judgments.d.ts.map +1 -1
  237. package/dist/routes/judgments.js +8 -1
  238. package/dist/routes/judgments.js.map +1 -1
  239. package/dist/routes/mcp.d.ts.map +1 -1
  240. package/dist/routes/mcp.js +26 -1
  241. package/dist/routes/mcp.js.map +1 -1
  242. package/dist/routes/memory-access.d.ts +43 -0
  243. package/dist/routes/memory-access.d.ts.map +1 -0
  244. package/dist/routes/memory-access.js +129 -0
  245. package/dist/routes/memory-access.js.map +1 -0
  246. package/dist/routes/memory-erasures.d.ts +25 -0
  247. package/dist/routes/memory-erasures.d.ts.map +1 -0
  248. package/dist/routes/memory-erasures.js +214 -0
  249. package/dist/routes/memory-erasures.js.map +1 -0
  250. package/dist/routes/memory-parse.d.ts +38 -0
  251. package/dist/routes/memory-parse.d.ts.map +1 -0
  252. package/dist/routes/memory-parse.js +199 -0
  253. package/dist/routes/memory-parse.js.map +1 -0
  254. package/dist/routes/memory.d.ts +9 -4
  255. package/dist/routes/memory.d.ts.map +1 -1
  256. package/dist/routes/memory.js +226 -234
  257. package/dist/routes/memory.js.map +1 -1
  258. package/dist/routes/observations.d.ts +4 -1
  259. package/dist/routes/observations.d.ts.map +1 -1
  260. package/dist/routes/observations.js +8 -2
  261. package/dist/routes/observations.js.map +1 -1
  262. package/dist/routes/pagination.d.ts +7 -0
  263. package/dist/routes/pagination.d.ts.map +1 -1
  264. package/dist/routes/pagination.js +10 -0
  265. package/dist/routes/pagination.js.map +1 -1
  266. package/dist/routes/policies.d.ts +2 -1
  267. package/dist/routes/policies.d.ts.map +1 -1
  268. package/dist/routes/policies.js +3 -1
  269. package/dist/routes/policies.js.map +1 -1
  270. package/dist/routes/project-mismatch.d.ts +22 -0
  271. package/dist/routes/project-mismatch.d.ts.map +1 -0
  272. package/dist/routes/project-mismatch.js +34 -0
  273. package/dist/routes/project-mismatch.js.map +1 -0
  274. package/dist/routes/projects.d.ts +15 -4
  275. package/dist/routes/projects.d.ts.map +1 -1
  276. package/dist/routes/projects.js +100 -9
  277. package/dist/routes/projects.js.map +1 -1
  278. package/dist/routes/proposals.d.ts +25 -17
  279. package/dist/routes/proposals.d.ts.map +1 -1
  280. package/dist/routes/proposals.js +340 -507
  281. package/dist/routes/proposals.js.map +1 -1
  282. package/dist/routes/provenance.d.ts +17 -3
  283. package/dist/routes/provenance.d.ts.map +1 -1
  284. package/dist/routes/provenance.js +79 -103
  285. package/dist/routes/provenance.js.map +1 -1
  286. package/dist/routes/providers.d.ts +17 -1
  287. package/dist/routes/providers.d.ts.map +1 -1
  288. package/dist/routes/providers.js +110 -3
  289. package/dist/routes/providers.js.map +1 -1
  290. package/dist/routes/public-run-tokens.d.ts.map +1 -1
  291. package/dist/routes/public-run-tokens.js +3 -0
  292. package/dist/routes/public-run-tokens.js.map +1 -1
  293. package/dist/routes/runs.d.ts +10 -0
  294. package/dist/routes/runs.d.ts.map +1 -1
  295. package/dist/routes/runs.js +92 -42
  296. package/dist/routes/runs.js.map +1 -1
  297. package/dist/routes/schedules.d.ts +21 -13
  298. package/dist/routes/schedules.d.ts.map +1 -1
  299. package/dist/routes/schedules.js +416 -55
  300. package/dist/routes/schedules.js.map +1 -1
  301. package/dist/routes/segments.d.ts +2 -0
  302. package/dist/routes/segments.d.ts.map +1 -1
  303. package/dist/routes/segments.js +5 -0
  304. package/dist/routes/segments.js.map +1 -1
  305. package/dist/routes/service-accounts.d.ts +17 -0
  306. package/dist/routes/service-accounts.d.ts.map +1 -0
  307. package/dist/routes/service-accounts.js +212 -0
  308. package/dist/routes/service-accounts.js.map +1 -0
  309. package/dist/routes/sign-in-options.d.ts +50 -0
  310. package/dist/routes/sign-in-options.d.ts.map +1 -0
  311. package/dist/routes/sign-in-options.js +98 -0
  312. package/dist/routes/sign-in-options.js.map +1 -0
  313. package/dist/routes/signing-keys.d.ts +2 -1
  314. package/dist/routes/signing-keys.d.ts.map +1 -1
  315. package/dist/routes/signing-keys.js +3 -1
  316. package/dist/routes/signing-keys.js.map +1 -1
  317. package/dist/routes/tenant-access.d.ts +13 -0
  318. package/dist/routes/tenant-access.d.ts.map +1 -0
  319. package/dist/routes/tenant-access.js +26 -0
  320. package/dist/routes/tenant-access.js.map +1 -0
  321. package/dist/routes/tenant.d.ts.map +1 -1
  322. package/dist/routes/tenant.js +4 -0
  323. package/dist/routes/tenant.js.map +1 -1
  324. package/dist/routes/token-sign-in.d.ts +36 -0
  325. package/dist/routes/token-sign-in.d.ts.map +1 -0
  326. package/dist/routes/token-sign-in.js +101 -0
  327. package/dist/routes/token-sign-in.js.map +1 -0
  328. package/dist/routes/tokens.d.ts +15 -5
  329. package/dist/routes/tokens.d.ts.map +1 -1
  330. package/dist/routes/tokens.js +162 -43
  331. package/dist/routes/tokens.js.map +1 -1
  332. package/dist/routes/tools.d.ts.map +1 -1
  333. package/dist/routes/tools.js +9 -1
  334. package/dist/routes/tools.js.map +1 -1
  335. package/dist/routes/trigger-access.d.ts +29 -0
  336. package/dist/routes/trigger-access.d.ts.map +1 -0
  337. package/dist/routes/trigger-access.js +33 -0
  338. package/dist/routes/trigger-access.js.map +1 -0
  339. package/dist/routes/webhook-endpoints.d.ts +2 -1
  340. package/dist/routes/webhook-endpoints.d.ts.map +1 -1
  341. package/dist/routes/webhook-endpoints.js +11 -3
  342. package/dist/routes/webhook-endpoints.js.map +1 -1
  343. package/dist/routes/webhooks.d.ts +5 -1
  344. package/dist/routes/webhooks.d.ts.map +1 -1
  345. package/dist/routes/webhooks.js +25 -2
  346. package/dist/routes/webhooks.js.map +1 -1
  347. package/dist/run-failure.d.ts +21 -0
  348. package/dist/run-failure.d.ts.map +1 -0
  349. package/dist/run-failure.js +29 -0
  350. package/dist/run-failure.js.map +1 -0
  351. package/dist/service-account-binding.d.ts +108 -0
  352. package/dist/service-account-binding.d.ts.map +1 -0
  353. package/dist/service-account-binding.js +4 -0
  354. package/dist/service-account-binding.js.map +1 -0
  355. package/dist/session-store-binding.d.ts +61 -13
  356. package/dist/session-store-binding.d.ts.map +1 -1
  357. package/dist/signed-export.d.ts +89 -0
  358. package/dist/signed-export.d.ts.map +1 -0
  359. package/dist/signed-export.js +149 -0
  360. package/dist/signed-export.js.map +1 -0
  361. package/dist/supervisor-binding.d.ts +186 -413
  362. package/dist/supervisor-binding.d.ts.map +1 -1
  363. package/dist/testing/app-bindings.d.ts +33 -0
  364. package/dist/testing/app-bindings.d.ts.map +1 -0
  365. package/dist/testing/app-bindings.js +112 -0
  366. package/dist/testing/app-bindings.js.map +1 -0
  367. package/dist/testing/index.d.ts +11 -0
  368. package/dist/testing/index.d.ts.map +1 -0
  369. package/dist/testing/index.js +13 -0
  370. package/dist/testing/index.js.map +1 -0
  371. package/dist/testing/stub-binding.d.ts +34 -0
  372. package/dist/testing/stub-binding.d.ts.map +1 -0
  373. package/dist/testing/stub-binding.js +42 -0
  374. package/dist/testing/stub-binding.js.map +1 -0
  375. package/dist/testing/trigger-registry.d.ts +21 -0
  376. package/dist/testing/trigger-registry.d.ts.map +1 -0
  377. package/dist/testing/trigger-registry.js +206 -0
  378. package/dist/testing/trigger-registry.js.map +1 -0
  379. package/dist/token-admin.d.ts +46 -8
  380. package/dist/token-admin.d.ts.map +1 -1
  381. package/dist/token-admin.js.map +1 -1
  382. package/dist/tool-binding.d.ts +13 -0
  383. package/dist/tool-binding.d.ts.map +1 -1
  384. package/dist/trigger-binding.d.ts +2 -2
  385. package/dist/trigger-binding.d.ts.map +1 -1
  386. package/dist/trigger-binding.js +1 -1
  387. package/dist/trigger-binding.js.map +1 -1
  388. package/dist/types.d.ts +16 -0
  389. package/dist/types.d.ts.map +1 -1
  390. package/dist/webhook-endpoint-binding.d.ts +19 -3
  391. package/dist/webhook-endpoint-binding.d.ts.map +1 -1
  392. package/dist/webhook-endpoint-binding.js +1 -1
  393. package/dist/webhook-endpoint-binding.js.map +1 -1
  394. package/openapi.json +15385 -8788
  395. package/package.json +26 -22
  396. package/src/agent-binding.ts +14 -0
  397. package/src/agent-pins.ts +18 -2
  398. package/src/app.ts +366 -80
  399. package/src/block-publish.ts +181 -0
  400. package/src/caller.ts +62 -0
  401. package/src/capability-binding.ts +12 -0
  402. package/src/derive-agent-version.ts +9 -1
  403. package/src/errors.ts +73 -7
  404. package/src/eval-case-binding.ts +17 -1
  405. package/src/eval-run-binding.ts +31 -0
  406. package/src/eval-run-dispatcher.ts +7 -0
  407. package/src/eval-sample.ts +42 -0
  408. package/src/eval-suite-binding.ts +14 -0
  409. package/src/flow-binding.ts +19 -0
  410. package/src/flow-pins.ts +18 -2
  411. package/src/gate.ts +26 -0
  412. package/src/handler-binding.ts +36 -1
  413. package/src/hitl-binding.ts +24 -0
  414. package/src/identity-directory-binding.ts +85 -4
  415. package/src/identity-provider-binding.ts +216 -21
  416. package/src/improvement-pass-binding.ts +193 -0
  417. package/src/index.ts +153 -31
  418. package/src/judged-dispatcher.ts +78 -11
  419. package/src/judgment-binding.ts +25 -1
  420. package/src/mcp-endpoint-binding.ts +7 -0
  421. package/src/memory-binding.ts +121 -17
  422. package/src/memory-erasure-binding.ts +156 -0
  423. package/src/middleware/auth.ts +228 -62
  424. package/src/middleware/authorize.ts +139 -3
  425. package/src/middleware/error-mapper.ts +15 -1
  426. package/src/middleware/idempotency.ts +230 -43
  427. package/src/middleware/key-project.ts +86 -0
  428. package/src/middleware/principal.ts +9 -5
  429. package/src/middleware/project-ref.ts +3 -0
  430. package/src/openapi/generate.ts +11 -2
  431. package/src/openapi/operations.ts +1059 -142
  432. package/src/openapi/schemas.ts +2387 -469
  433. package/src/person-grants-binding.ts +76 -0
  434. package/src/proposal-service.ts +640 -0
  435. package/src/proposal-status.ts +176 -0
  436. package/src/provider-binding.ts +10 -0
  437. package/src/publish-refused.ts +38 -9
  438. package/src/routes/adapters.ts +4 -0
  439. package/src/routes/agent-releases.ts +121 -69
  440. package/src/routes/agents.ts +128 -1
  441. package/src/routes/approvals.ts +164 -154
  442. package/src/routes/artifacts.ts +181 -11
  443. package/src/routes/auth.ts +804 -336
  444. package/src/routes/blocks.ts +2 -53
  445. package/src/routes/capabilities.ts +10 -1
  446. package/src/routes/compliance.ts +60 -99
  447. package/src/routes/conversations.ts +101 -7
  448. package/src/routes/cost.ts +32 -3
  449. package/src/routes/denied.ts +28 -0
  450. package/src/routes/deployments.ts +62 -16
  451. package/src/routes/eval-comparison.ts +81 -2
  452. package/src/routes/eval-overrides.ts +108 -0
  453. package/src/routes/eval-runs.ts +86 -6
  454. package/src/routes/eval-suites.ts +25 -1
  455. package/src/routes/event-triggers.ts +27 -3
  456. package/src/routes/export-signing-keys.ts +31 -0
  457. package/src/routes/flows.ts +12 -1
  458. package/src/routes/gate-policies.ts +37 -6
  459. package/src/routes/guardrails.ts +61 -2
  460. package/src/routes/identity.ts +328 -10
  461. package/src/routes/improvement-passes.ts +541 -0
  462. package/src/routes/judged-suites.ts +113 -43
  463. package/src/routes/judgment-context.ts +76 -5
  464. package/src/routes/judgment-flow-context.ts +16 -2
  465. package/src/routes/judgments.ts +17 -3
  466. package/src/routes/mcp.ts +29 -1
  467. package/src/routes/memory-access.ts +179 -0
  468. package/src/routes/memory-erasures.ts +240 -0
  469. package/src/routes/memory-parse.ts +250 -0
  470. package/src/routes/memory.ts +244 -286
  471. package/src/routes/observations.ts +15 -2
  472. package/src/routes/pagination.ts +12 -0
  473. package/src/routes/policies.ts +7 -1
  474. package/src/routes/project-mismatch.ts +56 -0
  475. package/src/routes/projects.ts +107 -13
  476. package/src/routes/proposals.ts +370 -611
  477. package/src/routes/provenance.ts +99 -133
  478. package/src/routes/providers.ts +142 -3
  479. package/src/routes/public-run-tokens.ts +3 -0
  480. package/src/routes/runs.ts +119 -39
  481. package/src/routes/schedules.ts +472 -60
  482. package/src/routes/segments.ts +11 -0
  483. package/src/routes/service-accounts.ts +262 -0
  484. package/src/routes/sign-in-options.ts +168 -0
  485. package/src/routes/signing-keys.ts +7 -1
  486. package/src/routes/tenant-access.ts +37 -0
  487. package/src/routes/tenant.ts +6 -0
  488. package/src/routes/token-sign-in.ts +161 -0
  489. package/src/routes/tokens.ts +172 -46
  490. package/src/routes/tools.ts +12 -1
  491. package/src/routes/trigger-access.ts +72 -0
  492. package/src/routes/webhook-endpoints.ts +15 -3
  493. package/src/routes/webhooks.ts +26 -2
  494. package/src/run-failure.ts +42 -0
  495. package/src/service-account-binding.ts +113 -0
  496. package/src/session-store-binding.ts +65 -13
  497. package/src/signed-export.ts +250 -0
  498. package/src/supervisor-binding.ts +169 -409
  499. package/src/testing/app-bindings.ts +142 -0
  500. package/src/testing/index.ts +21 -0
  501. package/src/testing/stub-binding.ts +53 -0
  502. package/src/testing/trigger-registry.ts +259 -0
  503. package/src/token-admin.ts +40 -8
  504. package/src/tool-binding.ts +14 -0
  505. package/src/trigger-binding.ts +8 -1
  506. package/src/types.ts +16 -0
  507. package/src/webhook-endpoint-binding.ts +18 -3
@@ -1,25 +1,60 @@
1
1
  // SPDX-License-Identifier: Apache-2.0
2
2
  // Copyright (C) 2026 Kindgi Inc.
3
3
  import { Hono } from 'hono';
4
+ import { ref } from '@kindgi/authz';
4
5
  import { statusFor, toWireError } from '../errors.js';
6
+ import { SCHEDULE_DEFAULTS, } from '../trigger-binding.js';
7
+ import { parseImproveScheduleInput } from './improvement-passes.js';
8
+ import { liveScopeToWire, parseLiveScopeBody } from './live-scope-wire.js';
5
9
  import { clampLimit } from './pagination.js';
10
+ import { UUID_RE } from './uuid-param.js';
6
11
  /**
7
- * Schedules — cron-kind triggers.
12
+ * Schedules: cron-kind triggers that start a run of an agent or a flow.
8
13
  *
9
- * Seven routes, all soft-delete-shaped per framework convention:
10
- * - POST /v1/schedules (register)
11
- * - GET /v1/schedules (list, cursor-paginated)
12
- * - GET /v1/schedules/:triggerId (get)
13
- * - PATCH /v1/schedules/:triggerId (update cron/label/flowVersion)
14
- * - POST /v1/schedules/:triggerId/pause
15
- * - POST /v1/schedules/:triggerId/resume
16
- * - POST /v1/schedules/:triggerId/unregister (tombstone — GC per policy)
14
+ * POST /v1/schedules register
15
+ * GET /v1/schedules list (cursor-paginated)
16
+ * GET /v1/schedules/:triggerId[?upcoming=N] get, with its next N occurrences
17
+ * PATCH /v1/schedules/:triggerId update
18
+ * POST /v1/schedules/:triggerId/pause | resume | unregister
19
+ * GET /v1/schedules/:triggerId/fires its fire history, newest first
20
+ * POST /v1/schedules/:triggerId/run-now fire it now, outside the schedule
21
+ * POST /v1/schedules/:triggerId/owner the caller becomes the owner
17
22
  *
18
- * The `triggerId` URL param is the trigger's id; the response body
19
- * aliases it as `scheduleId` for a friendlier client surface.
23
+ * A schedule's runs act as its owner (whoever registered it, until an
24
+ * admin takes it over), checked again at every fire. With an authorizer:
25
+ * reads need `read` on the schedule's project, changes `write`, taking
26
+ * ownership `admin`, and registering or retargeting also needs `execute`
27
+ * on what it runs, as starting that run does. The `triggerId` is aliased
28
+ * as `scheduleId` in bodies.
20
29
  */
21
- export function schedulesRouter(binding) {
30
+ export function schedulesRouter(binding, authorizer,
31
+ /** The tenant's Default project: where a schedule that names no project goes. */
32
+ projects) {
22
33
  const r = new Hono();
34
+ /** Nothing, when allowed; else the authorizer's own 403. */
35
+ async function denied(c, action, resource) {
36
+ if (authorizer === undefined)
37
+ return undefined;
38
+ let allowed = false;
39
+ const answer = await authorizer.authorize(action, async () => resource)(c, async () => {
40
+ allowed = true;
41
+ });
42
+ return allowed ? undefined : answer;
43
+ }
44
+ /** The schedule, if it is one (another kind's id is not found here), and the caller may `action` it. */
45
+ async function scheduleFor(c, action) {
46
+ const requestId = c.get('requestId');
47
+ const tenantId = c.get('tenantId');
48
+ const triggerId = c.req.param('triggerId');
49
+ const rec = UUID_RE.test(triggerId) ? await binding.get({ tenantId, triggerId }) : null;
50
+ if (rec === null || rec.kind !== 'cron') {
51
+ return { kind: 'err', response: notFound(c, requestId, triggerId) };
52
+ }
53
+ const refused = await denied(c, action, ref('project', rec.projectId));
54
+ if (refused !== undefined)
55
+ return { kind: 'err', response: refused };
56
+ return { kind: 'ok', value: rec };
57
+ }
23
58
  // ---------- POST / (register) ----------
24
59
  r.post('/', async (c) => {
25
60
  const requestId = c.get('requestId');
@@ -28,26 +63,51 @@ export function schedulesRouter(binding) {
28
63
  if (parsed.kind === 'err')
29
64
  return parsed.response;
30
65
  const body = parsed.value;
31
- const flowId = requireString(body, 'flowId');
32
- const flowVersion = requireString(body, 'flowVersion');
33
- const cronExpression = requireString(body.config, 'config.cronExpression');
34
- if (flowId.kind === 'err')
35
- return bad(c, requestId, flowId.message);
36
- if (flowVersion.kind === 'err')
37
- return bad(c, requestId, flowVersion.message);
66
+ const target = parseTarget(body);
67
+ if (target.kind === 'err')
68
+ return bad(c, requestId, target.message);
69
+ const cronExpression = requireString(body, 'config.cronExpression');
38
70
  if (cronExpression.kind === 'err')
39
71
  return bad(c, requestId, cronExpression.message);
72
+ const policy = parsePolicy(body);
73
+ if (policy.kind === 'err')
74
+ return bad(c, requestId, policy.message);
75
+ const projectId = body.projectId;
76
+ if (projectId !== undefined && (typeof projectId !== 'string' || !UUID_RE.test(projectId))) {
77
+ return bad(c, requestId, '`projectId` must be a project id (a UUID)');
78
+ }
40
79
  const rawConfig = (body.config ?? {});
80
+ const input = targetInput(target.value, rawConfig.input);
81
+ if (input.kind === 'err')
82
+ return bad(c, requestId, input.message);
83
+ // A schedule that names no project goes in its improve scope's
84
+ // project, else the tenant's Default project: checked and stored as
85
+ // that project. With no Default to find, the registry picks it, and
86
+ // only a tenant admin may.
87
+ const project = projectId ??
88
+ scopeProjectOf(target.value) ??
89
+ (await projects?.getDefault(tenantId))?.id;
90
+ const scopeProblem = improveScopeProblem(target.value, project);
91
+ if (scopeProblem !== undefined)
92
+ return bad(c, requestId, scopeProblem);
93
+ const refused = (project === undefined
94
+ ? await denied(c, 'admin', ref('tenant', tenantId))
95
+ : await denied(c, 'write', ref('project', project))) ??
96
+ (await denied(c, ...targetAccess(target.value)));
97
+ if (refused !== undefined)
98
+ return refused;
41
99
  const registerInput = {
42
100
  kind: 'cron',
43
101
  tenantId,
44
- flowId: flowId.value,
45
- flowVersion: flowVersion.value,
102
+ target: target.value,
103
+ ...(project !== undefined && { projectId: project }),
104
+ owner: ownerOf(c),
46
105
  config: {
47
106
  cronExpression: cronExpression.value,
48
107
  ...(typeof rawConfig.timezone === 'string' && { timezone: rawConfig.timezone }),
49
- ...('input' in rawConfig && { input: rawConfig.input }),
108
+ ...(input.input !== undefined && { input: input.input }),
50
109
  },
110
+ ...policy.value,
51
111
  ...(typeof body.label === 'string' && body.label.length > 0 && { label: body.label }),
52
112
  };
53
113
  const result = await binding.register(registerInput);
@@ -59,6 +119,10 @@ export function schedulesRouter(binding) {
59
119
  return c.json(serializeSchedule(result.value));
60
120
  });
61
121
  // ---------- GET / (list) ----------
122
+ // The tenant's schedules, then only those whose project the caller may
123
+ // read (`read` on it, as reading one schedule needs): a schedule's input
124
+ // and target are its project's. The page and its cursor are the
125
+ // tenant's, so a page can hold fewer than `limit` rows and still have more.
62
126
  r.get('/', async (c) => {
63
127
  const tenantId = c.get('tenantId');
64
128
  const limit = clampLimit(c.req.query('limit'));
@@ -74,8 +138,12 @@ export function schedulesRouter(binding) {
74
138
  ...(cursorRaw !== undefined && cursorRaw.length > 0 && { cursor: cursorRaw }),
75
139
  ...(statusFilter !== undefined && { status: statusFilter }),
76
140
  });
141
+ const rows = page.data;
142
+ const visible = authorizer === undefined
143
+ ? rows
144
+ : await authorizer.filterByCan(c, 'read', rows, (rec) => ref('project', rec.projectId));
77
145
  return c.json({
78
- data: page.data.map((row) => serializeSchedule(row)),
146
+ data: visible.map((row) => serializeSchedule(row)),
79
147
  hasMore: page.nextCursor !== undefined,
80
148
  ...(page.nextCursor !== undefined && { nextCursor: page.nextCursor }),
81
149
  });
@@ -83,22 +151,53 @@ export function schedulesRouter(binding) {
83
151
  // ---------- GET /:triggerId (get) ----------
84
152
  r.get('/:triggerId', async (c) => {
85
153
  const requestId = c.get('requestId');
86
- const tenantId = c.get('tenantId');
87
- const triggerId = c.req.param('triggerId');
88
- const rec = await binding.get({ tenantId, triggerId });
89
- if (rec === null || rec.kind !== 'cron')
90
- return notFound(c, requestId, triggerId);
91
- return c.json(serializeSchedule(rec));
154
+ const upcomingRaw = c.req.query('upcoming');
155
+ const upcoming = upcomingRaw === undefined ? undefined : Number(upcomingRaw);
156
+ if (upcoming !== undefined && (!Number.isInteger(upcoming) || upcoming < 1 || upcoming > 20)) {
157
+ return bad(c, requestId, '`upcoming` must be a whole number from 1 to 20');
158
+ }
159
+ const found = await scheduleFor(c, 'read');
160
+ if (found.kind === 'err')
161
+ return found.response;
162
+ if (upcoming === undefined)
163
+ return c.json(serializeSchedule(found.value));
164
+ const rec = await binding.get({
165
+ tenantId: c.get('tenantId'),
166
+ triggerId: found.value.triggerId,
167
+ upcoming,
168
+ });
169
+ return c.json(serializeSchedule((rec ?? found.value)));
92
170
  });
93
171
  // ---------- PATCH /:triggerId (update) ----------
94
172
  r.patch('/:triggerId', async (c) => {
95
173
  const requestId = c.get('requestId');
96
174
  const tenantId = c.get('tenantId');
97
- const triggerId = c.req.param('triggerId');
98
175
  const parsed = await parseJsonObject(c, requestId);
99
176
  if (parsed.kind === 'err')
100
177
  return parsed.response;
101
178
  const body = parsed.value;
179
+ const retarget = 'flowId' in body ||
180
+ 'agentId' in body ||
181
+ 'flowVersion' in body ||
182
+ 'agentVersion' in body ||
183
+ 'improve' in body;
184
+ const target = retarget ? parseTarget(body) : undefined;
185
+ if (target?.kind === 'err')
186
+ return bad(c, requestId, target.message);
187
+ const policy = parsePolicy(body);
188
+ if (policy.kind === 'err')
189
+ return bad(c, requestId, policy.message);
190
+ const found = await scheduleFor(c, 'write');
191
+ if (found.kind === 'err')
192
+ return found.response;
193
+ if (target !== undefined) {
194
+ const scopeProblem = improveScopeProblem(target.value, found.value.projectId);
195
+ if (scopeProblem !== undefined)
196
+ return bad(c, requestId, scopeProblem);
197
+ const refused = await denied(c, ...targetAccess(target.value));
198
+ if (refused !== undefined)
199
+ return refused;
200
+ }
102
201
  const patchConfig = body.config;
103
202
  const cfg = {};
104
203
  if (patchConfig !== undefined) {
@@ -109,13 +208,22 @@ export function schedulesRouter(binding) {
109
208
  if ('input' in patchConfig)
110
209
  cfg.input = patchConfig.input;
111
210
  }
211
+ if (target !== undefined || 'input' in cfg) {
212
+ const input = targetInput(target?.value ?? found.value.target, 'input' in cfg ? cfg.input : found.value.config.input);
213
+ if (input.kind === 'err')
214
+ return bad(c, requestId, input.message);
215
+ if (input.input !== undefined)
216
+ cfg.input = input.input;
217
+ }
218
+ const triggerId = found.value.triggerId;
112
219
  const updateInput = {
113
220
  kind: 'cron',
114
221
  tenantId,
115
222
  triggerId,
116
223
  ...(Object.keys(cfg).length > 0 && { config: cfg }),
224
+ ...(target !== undefined && { target: target.value }),
225
+ ...policy.value,
117
226
  ...('label' in body && { label: body.label === null ? null : body.label }),
118
- ...(typeof body.flowVersion === 'string' && { flowVersion: body.flowVersion }),
119
227
  };
120
228
  const result = await binding.update(updateInput);
121
229
  if (result.kind === 'err') {
@@ -128,58 +236,304 @@ export function schedulesRouter(binding) {
128
236
  }
129
237
  return c.json(serializeSchedule(result.value));
130
238
  });
131
- // ---------- POST /:triggerId/pause ----------
132
- r.post('/:triggerId/pause', async (c) => {
239
+ // ---------- POST /:triggerId/pause | resume ----------
240
+ for (const verb of ['pause', 'resume']) {
241
+ r.post(`/:triggerId/${verb}`, async (c) => {
242
+ const requestId = c.get('requestId');
243
+ const found = await scheduleFor(c, 'write');
244
+ if (found.kind === 'err')
245
+ return found.response;
246
+ const { tenantId, triggerId } = found.value;
247
+ const result = await binding[verb]({ tenantId, triggerId });
248
+ if (result.kind === 'err')
249
+ return lifecycleError(c, requestId, result.error, triggerId);
250
+ return c.json(serializeSchedule(result.value));
251
+ });
252
+ }
253
+ // ---------- POST /:triggerId/unregister (soft delete) ----------
254
+ r.post('/:triggerId/unregister', async (c) => {
255
+ const found = await scheduleFor(c, 'write');
256
+ if (found.kind === 'err')
257
+ return found.response;
258
+ const { tenantId, triggerId } = found.value;
259
+ const outcome = await binding.unregister({ tenantId, triggerId });
260
+ return c.json({
261
+ scheduleId: triggerId,
262
+ unregistered: outcome.unregistered,
263
+ });
264
+ });
265
+ // ---------- GET /:triggerId/fires (history) ----------
266
+ r.get('/:triggerId/fires', async (c) => {
133
267
  const requestId = c.get('requestId');
134
- const tenantId = c.get('tenantId');
135
- const triggerId = c.req.param('triggerId');
136
- const result = await binding.pause({ tenantId, triggerId });
268
+ const found = await scheduleFor(c, 'read');
269
+ if (found.kind === 'err')
270
+ return found.response;
271
+ if (binding.listFires === undefined)
272
+ return unsupported(c, requestId, 'fire history');
273
+ const cursorRaw = c.req.query('cursor');
274
+ const page = await binding.listFires({
275
+ tenantId: found.value.tenantId,
276
+ triggerId: found.value.triggerId,
277
+ limit: clampLimit(c.req.query('limit')),
278
+ ...(cursorRaw !== undefined && cursorRaw.length > 0 && { cursor: cursorRaw }),
279
+ });
280
+ return c.json({
281
+ data: page.data.map(serializeFire),
282
+ hasMore: page.nextCursor !== undefined,
283
+ ...(page.nextCursor !== undefined && { nextCursor: page.nextCursor }),
284
+ });
285
+ });
286
+ // ---------- POST /:triggerId/run-now ----------
287
+ r.post('/:triggerId/run-now', async (c) => {
288
+ const requestId = c.get('requestId');
289
+ const found = await scheduleFor(c, 'write');
290
+ if (found.kind === 'err')
291
+ return found.response;
292
+ if (binding.fireNow === undefined)
293
+ return unsupported(c, requestId, 'run-now');
294
+ const { tenantId, triggerId } = found.value;
295
+ const result = await binding.fireNow({ tenantId, triggerId });
137
296
  if (result.kind === 'err')
138
297
  return lifecycleError(c, requestId, result.error, triggerId);
139
- return c.json(serializeSchedule(result.value));
298
+ c.status(202);
299
+ return c.json(serializeFire(result.value));
140
300
  });
141
- // ---------- POST /:triggerId/resume ----------
142
- r.post('/:triggerId/resume', async (c) => {
301
+ // ---------- POST /:triggerId/owner (take ownership) ----------
302
+ r.post('/:triggerId/owner', async (c) => {
143
303
  const requestId = c.get('requestId');
144
- const tenantId = c.get('tenantId');
145
- const triggerId = c.req.param('triggerId');
146
- const result = await binding.resume({ tenantId, triggerId });
304
+ const found = await scheduleFor(c, 'admin');
305
+ if (found.kind === 'err')
306
+ return found.response;
307
+ if (binding.setOwner === undefined)
308
+ return unsupported(c, requestId, 'changing the owner');
309
+ const refused = await denied(c, ...targetAccess(found.value.target));
310
+ if (refused !== undefined)
311
+ return refused;
312
+ const { tenantId, triggerId } = found.value;
313
+ const result = await binding.setOwner({ tenantId, triggerId, owner: ownerOf(c) });
147
314
  if (result.kind === 'err')
148
315
  return lifecycleError(c, requestId, result.error, triggerId);
149
316
  return c.json(serializeSchedule(result.value));
150
317
  });
151
- // ---------- POST /:triggerId/unregister (soft delete) ----------
152
- r.post('/:triggerId/unregister', async (c) => {
153
- const tenantId = c.get('tenantId');
154
- const triggerId = c.req.param('triggerId');
155
- const outcome = await binding.unregister({ tenantId, triggerId });
156
- return c.json({
157
- scheduleId: triggerId,
158
- unregistered: outcome.unregistered,
159
- });
160
- });
161
318
  return r;
162
319
  }
163
320
  // -----------------------------------------------------------------------
164
321
  // Shared helpers (co-located to keep each router self-contained).
165
322
  // -----------------------------------------------------------------------
323
+ /** A target on the wire: `flowId` + `flowVersion`, `agentId` (+ `agentVersion`), or `improve`. */
324
+ function targetFields(target) {
325
+ switch (target.kind) {
326
+ case 'flow':
327
+ return { flowId: target.flowId, flowVersion: target.flowVersion };
328
+ case 'agent':
329
+ return {
330
+ agentId: target.agentId,
331
+ ...(target.agentVersion !== undefined && { agentVersion: target.agentVersion }),
332
+ };
333
+ case 'improve':
334
+ return { improve: { agentId: target.agentId, scope: liveScopeToWire(target.scope) } };
335
+ }
336
+ }
166
337
  function serializeSchedule(r) {
167
338
  return {
168
339
  scheduleId: r.triggerId,
169
340
  triggerId: r.triggerId,
170
- flowId: r.flowId,
171
- flowVersion: r.flowVersion,
341
+ ...targetFields(r.target),
342
+ projectId: r.projectId,
343
+ owner: { kind: r.owner.kind, id: r.owner.id },
172
344
  cronExpression: r.config.cronExpression,
173
345
  ...(r.config.timezone !== undefined && { timezone: r.config.timezone }),
174
346
  ...(r.config.input !== undefined && { input: r.config.input }),
347
+ catchUp: r.catchUp,
348
+ overlap: r.overlap,
349
+ startingDeadlineSeconds: r.startingDeadlineSeconds,
175
350
  label: r.label,
176
351
  status: r.status,
352
+ ...(r.statusReason !== undefined && { statusReason: r.statusReason }),
177
353
  nextFireAt: r.nextFireAt,
354
+ ...(r.upcoming !== undefined && { upcoming: r.upcoming }),
178
355
  lastFiredAt: r.lastFiredAt,
179
356
  createdAt: r.createdAt,
180
357
  updatedAt: r.updatedAt,
181
358
  };
182
359
  }
360
+ function serializeFire(f) {
361
+ return {
362
+ fireId: f.fireId,
363
+ scheduleId: f.triggerId,
364
+ triggerId: f.triggerId,
365
+ ...(f.scheduledFor !== undefined && { scheduledFor: f.scheduledFor }),
366
+ firedAt: f.firedAt,
367
+ outcome: f.outcome,
368
+ ...(f.runId !== undefined && { runId: f.runId }),
369
+ ...(f.passId !== undefined && { passId: f.passId }),
370
+ ...(f.detail !== undefined && { detail: f.detail }),
371
+ ...(f.missedCount !== undefined && { missedCount: f.missedCount }),
372
+ ...(f.manual === true && { manual: true }),
373
+ };
374
+ }
375
+ /**
376
+ * What firing the target needs, as starting it by hand does: `execute` on
377
+ * the agent or flow a run starts; `publish` on the agent an improvement
378
+ * pass works on (as `POST /v1/proposals/improve`).
379
+ */
380
+ function targetAccess(target) {
381
+ switch (target.kind) {
382
+ case 'flow':
383
+ return ['execute', ref('flow', target.flowId)];
384
+ case 'agent':
385
+ return ['execute', ref('agent', target.agentId)];
386
+ case 'improve':
387
+ return ['publish', ref('agent', target.agentId)];
388
+ }
389
+ }
390
+ /** Who a schedule's runs act as: the request's principal. */
391
+ function ownerOf(c) {
392
+ const actor = c.get('principal')?.actor;
393
+ if (actor === undefined)
394
+ return { kind: 'service', id: 'unknown' };
395
+ return { kind: actor.kind === 'user' ? 'user' : 'service', id: actor.id };
396
+ }
397
+ /** `flowId` + `flowVersion`, `agentId` (+ `agentVersion`), or `improve`: exactly one target. */
398
+ function parseTarget(body) {
399
+ const { flowId, flowVersion, agentId, agentVersion, improve } = body;
400
+ const named = (v) => typeof v === 'string' && v.length > 0;
401
+ if ([named(flowId), named(agentId), improve !== undefined].filter(Boolean).length !== 1) {
402
+ return {
403
+ kind: 'err',
404
+ message: 'Name what the schedule runs: `flowId` (with `flowVersion`), `agentId`, or `improve` ({ agentId, scope }), one of them',
405
+ };
406
+ }
407
+ if (improve !== undefined)
408
+ return parseImproveTarget(improve, flowVersion, agentVersion);
409
+ if (named(flowId)) {
410
+ if (!named(flowVersion))
411
+ return { kind: 'err', message: '`flowVersion` is required with `flowId`' };
412
+ if (agentVersion !== undefined) {
413
+ return { kind: 'err', message: '`agentVersion` goes with `agentId`, not `flowId`' };
414
+ }
415
+ return {
416
+ kind: 'ok',
417
+ value: { kind: 'flow', flowId: flowId, flowVersion: flowVersion },
418
+ };
419
+ }
420
+ if (flowVersion !== undefined) {
421
+ return { kind: 'err', message: '`flowVersion` goes with `flowId`, not `agentId`' };
422
+ }
423
+ if (agentVersion !== undefined && !named(agentVersion)) {
424
+ return { kind: 'err', message: '`agentVersion` must be a version (semver)' };
425
+ }
426
+ return {
427
+ kind: 'ok',
428
+ value: {
429
+ kind: 'agent',
430
+ agentId: agentId,
431
+ ...(agentVersion !== undefined && { agentVersion: agentVersion }),
432
+ },
433
+ };
434
+ }
435
+ /** An improve scope's project, when it names one. */
436
+ function scopeProjectOf(target) {
437
+ if (target.kind !== 'improve')
438
+ return undefined;
439
+ const { scope } = target;
440
+ return scope.kind === 'project' || scope.kind === 'segment'
441
+ ? scope.projectId
442
+ : undefined;
443
+ }
444
+ /**
445
+ * A pass's evidence must cover the scope it changes: an improve schedule
446
+ * learns from its project's runs (for a segment scope, that segment's),
447
+ * so its scope is the schedule's own project or a segment of it. The
448
+ * tenant and an org span projects: going wider stays a promotion by hand,
449
+ * through that scope's gate.
450
+ */
451
+ function improveScopeProblem(target, project) {
452
+ if (target.kind !== 'improve')
453
+ return undefined;
454
+ if (target.scope.kind === 'tenant' || target.scope.kind === 'org') {
455
+ return `An improve schedule's scope is a project or a segment of it, not the ${target.scope.kind === 'org' ? 'org' : 'tenant'}: a pass's evidence must cover the scope it changes, and it learns from one project's runs. Use the project (or a segment) scope; promote to the ${target.scope.kind === 'org' ? 'org' : 'tenant'} by hand after review.`;
456
+ }
457
+ const own = scopeProjectOf(target);
458
+ if (own !== undefined && project !== undefined && own !== project) {
459
+ return "An improve schedule's scope must be in the schedule's project (`projectId`): it learns from that project's runs";
460
+ }
461
+ return undefined;
462
+ }
463
+ function parseImproveTarget(improve, flowVersion, agentVersion) {
464
+ const shape = 'An improve schedule names `improve: { agentId, scope }`: the agent its passes work on, and the live scope they propose for';
465
+ if (flowVersion !== undefined || agentVersion !== undefined) {
466
+ return {
467
+ kind: 'err',
468
+ message: `${shape}; \`flowVersion\` and \`agentVersion\` don't go with it`,
469
+ };
470
+ }
471
+ const o = typeof improve === 'object' && improve !== null && !Array.isArray(improve)
472
+ ? improve
473
+ : undefined;
474
+ if (o === undefined ||
475
+ Object.keys(o).some((k) => k !== 'agentId' && k !== 'scope') ||
476
+ typeof o.agentId !== 'string' ||
477
+ o.agentId.length === 0) {
478
+ return { kind: 'err', message: shape };
479
+ }
480
+ const scope = parseLiveScopeBody(o.scope);
481
+ if (scope.kind === 'err')
482
+ return { kind: 'err', message: `\`improve.scope\`: ${scope.message}` };
483
+ return { kind: 'ok', value: { kind: 'improve', agentId: o.agentId, scope: scope.scope } };
484
+ }
485
+ /**
486
+ * The input a target's fires get, or why it can't be: an agent's run takes
487
+ * the agent payload, so an agent schedule's input must carry the message
488
+ * each run sends (without it every fire would be refused); an improve
489
+ * schedule's input is its pass options, kept with the defaults applied; a
490
+ * flow's input is the flow's own.
491
+ */
492
+ function targetInput(target, input) {
493
+ if (target.kind === 'improve') {
494
+ const parsed = parseImproveScheduleInput(input);
495
+ return parsed.kind === 'ok' ? { kind: 'ok', input: parsed.input } : parsed;
496
+ }
497
+ if (target.kind === 'flow')
498
+ return { kind: 'ok', ...(input !== undefined && { input }) };
499
+ const message = typeof input === 'object' && input !== null
500
+ ? input.userMessage
501
+ : undefined;
502
+ if (typeof message === 'string' && message.length > 0)
503
+ return { kind: 'ok', input };
504
+ return {
505
+ kind: 'err',
506
+ message: 'An agent schedule needs `config.input.userMessage`: the message each run sends the agent (`{ userMessage, parameters? }`)',
507
+ };
508
+ }
509
+ /** `catchUp`, `overlap` and `startingDeadlineSeconds`, each optional. */
510
+ function parsePolicy(body) {
511
+ const { catchUp, overlap, startingDeadlineSeconds } = body;
512
+ if (catchUp !== undefined && catchUp !== 'latest' && catchUp !== 'skip') {
513
+ return { kind: 'err', message: '`catchUp` must be `latest` or `skip`' };
514
+ }
515
+ if (overlap !== undefined && overlap !== 'skip' && overlap !== 'allow') {
516
+ return { kind: 'err', message: '`overlap` must be `skip` or `allow`' };
517
+ }
518
+ if (startingDeadlineSeconds !== undefined &&
519
+ (typeof startingDeadlineSeconds !== 'number' ||
520
+ !Number.isInteger(startingDeadlineSeconds) ||
521
+ startingDeadlineSeconds < 1 ||
522
+ startingDeadlineSeconds > 86_400)) {
523
+ return {
524
+ kind: 'err',
525
+ message: `\`startingDeadlineSeconds\` must be a whole number of seconds from 1 to 86400 (default ${SCHEDULE_DEFAULTS.startingDeadlineSeconds})`,
526
+ };
527
+ }
528
+ return {
529
+ kind: 'ok',
530
+ value: {
531
+ ...(catchUp !== undefined && { catchUp }),
532
+ ...(overlap !== undefined && { overlap }),
533
+ ...(startingDeadlineSeconds !== undefined && { startingDeadlineSeconds }),
534
+ },
535
+ };
536
+ }
183
537
  async function parseJsonObject(c, requestId) {
184
538
  let body;
185
539
  try {
@@ -219,11 +573,18 @@ function bad(c, requestId, message) {
219
573
  c.status(statusFor('bad-input'));
220
574
  return c.json(toWireError({ code: 'bad-input', message }, requestId));
221
575
  }
576
+ function unsupported(c, requestId, what) {
577
+ c.status(statusFor('trigger-operation-unsupported'));
578
+ return c.json(toWireError({
579
+ code: 'trigger-operation-unsupported',
580
+ message: `This deployment's schedules don't support ${what} yet.`,
581
+ }, requestId));
582
+ }
222
583
  function notFound(c, requestId, triggerId) {
223
584
  c.status(statusFor('trigger-not-found'));
224
585
  return c.json(toWireError({
225
586
  code: 'trigger-not-found',
226
- message: `No trigger with id "${triggerId}"`,
587
+ message: `No schedule with id "${triggerId}"`,
227
588
  triggerId: triggerId,
228
589
  }, requestId));
229
590
  }