@kindgi/api 0.0.0-bootstrap.0 → 0.1.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 (505) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +216 -1
  3. package/dist/adapter-binding.d.ts +177 -0
  4. package/dist/adapter-binding.d.ts.map +1 -0
  5. package/dist/adapter-binding.js +12 -0
  6. package/dist/adapter-binding.js.map +1 -0
  7. package/dist/agent-binding.d.ts +207 -0
  8. package/dist/agent-binding.d.ts.map +1 -0
  9. package/dist/agent-binding.js +4 -0
  10. package/dist/agent-binding.js.map +1 -0
  11. package/dist/app.d.ts +770 -0
  12. package/dist/app.d.ts.map +1 -0
  13. package/dist/app.js +396 -0
  14. package/dist/app.js.map +1 -0
  15. package/dist/capability-binding.d.ts +76 -0
  16. package/dist/capability-binding.d.ts.map +1 -0
  17. package/dist/capability-binding.js +4 -0
  18. package/dist/capability-binding.js.map +1 -0
  19. package/dist/cost-binding.d.ts +175 -0
  20. package/dist/cost-binding.d.ts.map +1 -0
  21. package/dist/cost-binding.js +13 -0
  22. package/dist/cost-binding.js.map +1 -0
  23. package/dist/deployment-binding.d.ts +201 -0
  24. package/dist/deployment-binding.d.ts.map +1 -0
  25. package/dist/deployment-binding.js +4 -0
  26. package/dist/deployment-binding.js.map +1 -0
  27. package/dist/env-binding.d.ts +132 -0
  28. package/dist/env-binding.d.ts.map +1 -0
  29. package/dist/env-binding.js +4 -0
  30. package/dist/env-binding.js.map +1 -0
  31. package/dist/errors.d.ts +37 -0
  32. package/dist/errors.d.ts.map +1 -0
  33. package/dist/errors.js +264 -0
  34. package/dist/errors.js.map +1 -0
  35. package/dist/eval-run-binding.d.ts +196 -0
  36. package/dist/eval-run-binding.d.ts.map +1 -0
  37. package/dist/eval-run-binding.js +16 -0
  38. package/dist/eval-run-binding.js.map +1 -0
  39. package/dist/eval-run-dispatcher.d.ts +131 -0
  40. package/dist/eval-run-dispatcher.d.ts.map +1 -0
  41. package/dist/eval-run-dispatcher.js +368 -0
  42. package/dist/eval-run-dispatcher.js.map +1 -0
  43. package/dist/eval-suite-binding.d.ts +227 -0
  44. package/dist/eval-suite-binding.d.ts.map +1 -0
  45. package/dist/eval-suite-binding.js +24 -0
  46. package/dist/eval-suite-binding.js.map +1 -0
  47. package/dist/event-bus-binding.d.ts +107 -0
  48. package/dist/event-bus-binding.d.ts.map +1 -0
  49. package/dist/event-bus-binding.js +5 -0
  50. package/dist/event-bus-binding.js.map +1 -0
  51. package/dist/flow-binding.d.ts +194 -0
  52. package/dist/flow-binding.d.ts.map +1 -0
  53. package/dist/flow-binding.js +4 -0
  54. package/dist/flow-binding.js.map +1 -0
  55. package/dist/guardrail-binding.d.ts +138 -0
  56. package/dist/guardrail-binding.d.ts.map +1 -0
  57. package/dist/guardrail-binding.js +4 -0
  58. package/dist/guardrail-binding.js.map +1 -0
  59. package/dist/handler-binding.d.ts +126 -0
  60. package/dist/handler-binding.d.ts.map +1 -0
  61. package/dist/handler-binding.js +4 -0
  62. package/dist/handler-binding.js.map +1 -0
  63. package/dist/hitl-binding.d.ts +115 -0
  64. package/dist/hitl-binding.d.ts.map +1 -0
  65. package/dist/hitl-binding.js +4 -0
  66. package/dist/hitl-binding.js.map +1 -0
  67. package/dist/identity-directory-binding.d.ts +116 -0
  68. package/dist/identity-directory-binding.d.ts.map +1 -0
  69. package/dist/identity-directory-binding.js +4 -0
  70. package/dist/identity-directory-binding.js.map +1 -0
  71. package/dist/identity-provider-binding.d.ts +184 -0
  72. package/dist/identity-provider-binding.d.ts.map +1 -0
  73. package/dist/identity-provider-binding.js +4 -0
  74. package/dist/identity-provider-binding.js.map +1 -0
  75. package/dist/image-registry-binding.d.ts +165 -0
  76. package/dist/image-registry-binding.d.ts.map +1 -0
  77. package/dist/image-registry-binding.js +4 -0
  78. package/dist/image-registry-binding.js.map +1 -0
  79. package/dist/index.d.ts +72 -0
  80. package/dist/index.d.ts.map +1 -0
  81. package/dist/index.js +26 -0
  82. package/dist/index.js.map +1 -0
  83. package/dist/key-management-binding.d.ts +101 -0
  84. package/dist/key-management-binding.d.ts.map +1 -0
  85. package/dist/key-management-binding.js +4 -0
  86. package/dist/key-management-binding.js.map +1 -0
  87. package/dist/mcp-endpoint-binding.d.ts +312 -0
  88. package/dist/mcp-endpoint-binding.d.ts.map +1 -0
  89. package/dist/mcp-endpoint-binding.js +12 -0
  90. package/dist/mcp-endpoint-binding.js.map +1 -0
  91. package/dist/memory-binding.d.ts +209 -0
  92. package/dist/memory-binding.d.ts.map +1 -0
  93. package/dist/memory-binding.js +4 -0
  94. package/dist/memory-binding.js.map +1 -0
  95. package/dist/middleware/auth.d.ts +168 -0
  96. package/dist/middleware/auth.d.ts.map +1 -0
  97. package/dist/middleware/auth.js +247 -0
  98. package/dist/middleware/auth.js.map +1 -0
  99. package/dist/middleware/authorize.d.ts +26 -0
  100. package/dist/middleware/authorize.d.ts.map +1 -0
  101. package/dist/middleware/authorize.js +65 -0
  102. package/dist/middleware/authorize.js.map +1 -0
  103. package/dist/middleware/error-mapper.d.ts +13 -0
  104. package/dist/middleware/error-mapper.d.ts.map +1 -0
  105. package/dist/middleware/error-mapper.js +32 -0
  106. package/dist/middleware/error-mapper.js.map +1 -0
  107. package/dist/middleware/idempotency.d.ts +43 -0
  108. package/dist/middleware/idempotency.d.ts.map +1 -0
  109. package/dist/middleware/idempotency.js +118 -0
  110. package/dist/middleware/idempotency.js.map +1 -0
  111. package/dist/middleware/principal.d.ts +4 -0
  112. package/dist/middleware/principal.d.ts.map +1 -0
  113. package/dist/middleware/principal.js +42 -0
  114. package/dist/middleware/principal.js.map +1 -0
  115. package/dist/middleware/public-run-routes.d.ts +16 -0
  116. package/dist/middleware/public-run-routes.d.ts.map +1 -0
  117. package/dist/middleware/public-run-routes.js +43 -0
  118. package/dist/middleware/public-run-routes.js.map +1 -0
  119. package/dist/middleware/request-id.d.ts +14 -0
  120. package/dist/middleware/request-id.d.ts.map +1 -0
  121. package/dist/middleware/request-id.js +24 -0
  122. package/dist/middleware/request-id.js.map +1 -0
  123. package/dist/middleware/sigv4-verify.d.ts +64 -0
  124. package/dist/middleware/sigv4-verify.d.ts.map +1 -0
  125. package/dist/middleware/sigv4-verify.js +286 -0
  126. package/dist/middleware/sigv4-verify.js.map +1 -0
  127. package/dist/middleware/sigv4.d.ts +25 -0
  128. package/dist/middleware/sigv4.d.ts.map +1 -0
  129. package/dist/middleware/sigv4.js +120 -0
  130. package/dist/middleware/sigv4.js.map +1 -0
  131. package/dist/openapi/generate.d.ts +15 -0
  132. package/dist/openapi/generate.d.ts.map +1 -0
  133. package/dist/openapi/generate.js +241 -0
  134. package/dist/openapi/generate.js.map +1 -0
  135. package/dist/openapi/operations.d.ts +70 -0
  136. package/dist/openapi/operations.d.ts.map +1 -0
  137. package/dist/openapi/operations.js +5051 -0
  138. package/dist/openapi/operations.js.map +1 -0
  139. package/dist/openapi/schemas.d.ts +590 -0
  140. package/dist/openapi/schemas.d.ts.map +1 -0
  141. package/dist/openapi/schemas.js +5820 -0
  142. package/dist/openapi/schemas.js.map +1 -0
  143. package/dist/provenance-binding.d.ts +116 -0
  144. package/dist/provenance-binding.d.ts.map +1 -0
  145. package/dist/provenance-binding.js +31 -0
  146. package/dist/provenance-binding.js.map +1 -0
  147. package/dist/provider-binding.d.ts +174 -0
  148. package/dist/provider-binding.d.ts.map +1 -0
  149. package/dist/provider-binding.js +4 -0
  150. package/dist/provider-binding.js.map +1 -0
  151. package/dist/public-run-token.d.ts +97 -0
  152. package/dist/public-run-token.d.ts.map +1 -0
  153. package/dist/public-run-token.js +167 -0
  154. package/dist/public-run-token.js.map +1 -0
  155. package/dist/retention-binding.d.ts +69 -0
  156. package/dist/retention-binding.d.ts.map +1 -0
  157. package/dist/retention-binding.js +4 -0
  158. package/dist/retention-binding.js.map +1 -0
  159. package/dist/reviewer-binding.d.ts +84 -0
  160. package/dist/reviewer-binding.d.ts.map +1 -0
  161. package/dist/reviewer-binding.js +4 -0
  162. package/dist/reviewer-binding.js.map +1 -0
  163. package/dist/rotation-status-store.d.ts +96 -0
  164. package/dist/rotation-status-store.d.ts.map +1 -0
  165. package/dist/rotation-status-store.js +106 -0
  166. package/dist/rotation-status-store.js.map +1 -0
  167. package/dist/routes/adapters.d.ts +29 -0
  168. package/dist/routes/adapters.d.ts.map +1 -0
  169. package/dist/routes/adapters.js +230 -0
  170. package/dist/routes/adapters.js.map +1 -0
  171. package/dist/routes/agents.d.ts +17 -0
  172. package/dist/routes/agents.d.ts.map +1 -0
  173. package/dist/routes/agents.js +342 -0
  174. package/dist/routes/agents.js.map +1 -0
  175. package/dist/routes/approvals.d.ts +37 -0
  176. package/dist/routes/approvals.d.ts.map +1 -0
  177. package/dist/routes/approvals.js +551 -0
  178. package/dist/routes/approvals.js.map +1 -0
  179. package/dist/routes/artifacts.d.ts +25 -0
  180. package/dist/routes/artifacts.d.ts.map +1 -0
  181. package/dist/routes/artifacts.js +265 -0
  182. package/dist/routes/artifacts.js.map +1 -0
  183. package/dist/routes/audit.d.ts +6 -0
  184. package/dist/routes/audit.d.ts.map +1 -0
  185. package/dist/routes/audit.js +162 -0
  186. package/dist/routes/audit.js.map +1 -0
  187. package/dist/routes/auth.d.ts +47 -0
  188. package/dist/routes/auth.d.ts.map +1 -0
  189. package/dist/routes/auth.js +630 -0
  190. package/dist/routes/auth.js.map +1 -0
  191. package/dist/routes/capabilities.d.ts +14 -0
  192. package/dist/routes/capabilities.d.ts.map +1 -0
  193. package/dist/routes/capabilities.js +62 -0
  194. package/dist/routes/capabilities.js.map +1 -0
  195. package/dist/routes/compliance.d.ts +37 -0
  196. package/dist/routes/compliance.d.ts.map +1 -0
  197. package/dist/routes/compliance.js +321 -0
  198. package/dist/routes/compliance.js.map +1 -0
  199. package/dist/routes/conversations.d.ts +13 -0
  200. package/dist/routes/conversations.d.ts.map +1 -0
  201. package/dist/routes/conversations.js +295 -0
  202. package/dist/routes/conversations.js.map +1 -0
  203. package/dist/routes/cost.d.ts +24 -0
  204. package/dist/routes/cost.d.ts.map +1 -0
  205. package/dist/routes/cost.js +243 -0
  206. package/dist/routes/cost.js.map +1 -0
  207. package/dist/routes/deployments.d.ts +122 -0
  208. package/dist/routes/deployments.d.ts.map +1 -0
  209. package/dist/routes/deployments.js +1036 -0
  210. package/dist/routes/deployments.js.map +1 -0
  211. package/dist/routes/env.d.ts +62 -0
  212. package/dist/routes/env.d.ts.map +1 -0
  213. package/dist/routes/env.js +311 -0
  214. package/dist/routes/env.js.map +1 -0
  215. package/dist/routes/eval-runs.d.ts +28 -0
  216. package/dist/routes/eval-runs.d.ts.map +1 -0
  217. package/dist/routes/eval-runs.js +479 -0
  218. package/dist/routes/eval-runs.js.map +1 -0
  219. package/dist/routes/eval-suites.d.ts +24 -0
  220. package/dist/routes/eval-suites.d.ts.map +1 -0
  221. package/dist/routes/eval-suites.js +381 -0
  222. package/dist/routes/eval-suites.js.map +1 -0
  223. package/dist/routes/event-triggers.d.ts +12 -0
  224. package/dist/routes/event-triggers.d.ts.map +1 -0
  225. package/dist/routes/event-triggers.js +218 -0
  226. package/dist/routes/event-triggers.js.map +1 -0
  227. package/dist/routes/flows.d.ts +23 -0
  228. package/dist/routes/flows.d.ts.map +1 -0
  229. package/dist/routes/flows.js +344 -0
  230. package/dist/routes/flows.js.map +1 -0
  231. package/dist/routes/guardrails.d.ts +33 -0
  232. package/dist/routes/guardrails.d.ts.map +1 -0
  233. package/dist/routes/guardrails.js +236 -0
  234. package/dist/routes/guardrails.js.map +1 -0
  235. package/dist/routes/identity.d.ts +39 -0
  236. package/dist/routes/identity.d.ts.map +1 -0
  237. package/dist/routes/identity.js +138 -0
  238. package/dist/routes/identity.js.map +1 -0
  239. package/dist/routes/mcp.d.ts +23 -0
  240. package/dist/routes/mcp.d.ts.map +1 -0
  241. package/dist/routes/mcp.js +727 -0
  242. package/dist/routes/mcp.js.map +1 -0
  243. package/dist/routes/memory.d.ts +16 -0
  244. package/dist/routes/memory.d.ts.map +1 -0
  245. package/dist/routes/memory.js +353 -0
  246. package/dist/routes/memory.js.map +1 -0
  247. package/dist/routes/observations.d.ts +19 -0
  248. package/dist/routes/observations.d.ts.map +1 -0
  249. package/dist/routes/observations.js +135 -0
  250. package/dist/routes/observations.js.map +1 -0
  251. package/dist/routes/orgs.d.ts +24 -0
  252. package/dist/routes/orgs.d.ts.map +1 -0
  253. package/dist/routes/orgs.js +208 -0
  254. package/dist/routes/orgs.js.map +1 -0
  255. package/dist/routes/pagination.d.ts +18 -0
  256. package/dist/routes/pagination.d.ts.map +1 -0
  257. package/dist/routes/pagination.js +35 -0
  258. package/dist/routes/pagination.js.map +1 -0
  259. package/dist/routes/policies.d.ts +23 -0
  260. package/dist/routes/policies.d.ts.map +1 -0
  261. package/dist/routes/policies.js +314 -0
  262. package/dist/routes/policies.js.map +1 -0
  263. package/dist/routes/projects.d.ts +45 -0
  264. package/dist/routes/projects.d.ts.map +1 -0
  265. package/dist/routes/projects.js +485 -0
  266. package/dist/routes/projects.js.map +1 -0
  267. package/dist/routes/proposals.d.ts +24 -0
  268. package/dist/routes/proposals.d.ts.map +1 -0
  269. package/dist/routes/proposals.js +581 -0
  270. package/dist/routes/proposals.js.map +1 -0
  271. package/dist/routes/provenance.d.ts +34 -0
  272. package/dist/routes/provenance.d.ts.map +1 -0
  273. package/dist/routes/provenance.js +274 -0
  274. package/dist/routes/provenance.js.map +1 -0
  275. package/dist/routes/providers.d.ts +32 -0
  276. package/dist/routes/providers.d.ts.map +1 -0
  277. package/dist/routes/providers.js +490 -0
  278. package/dist/routes/providers.js.map +1 -0
  279. package/dist/routes/public-run-tokens.d.ts +17 -0
  280. package/dist/routes/public-run-tokens.d.ts.map +1 -0
  281. package/dist/routes/public-run-tokens.js +69 -0
  282. package/dist/routes/public-run-tokens.js.map +1 -0
  283. package/dist/routes/retention.d.ts +19 -0
  284. package/dist/routes/retention.d.ts.map +1 -0
  285. package/dist/routes/retention.js +152 -0
  286. package/dist/routes/retention.js.map +1 -0
  287. package/dist/routes/reviewers.d.ts +5 -0
  288. package/dist/routes/reviewers.d.ts.map +1 -0
  289. package/dist/routes/reviewers.js +161 -0
  290. package/dist/routes/reviewers.js.map +1 -0
  291. package/dist/routes/runs.d.ts +34 -0
  292. package/dist/routes/runs.d.ts.map +1 -0
  293. package/dist/routes/runs.js +773 -0
  294. package/dist/routes/runs.js.map +1 -0
  295. package/dist/routes/s3.d.ts +31 -0
  296. package/dist/routes/s3.d.ts.map +1 -0
  297. package/dist/routes/s3.js +433 -0
  298. package/dist/routes/s3.js.map +1 -0
  299. package/dist/routes/schedules.d.ts +20 -0
  300. package/dist/routes/schedules.d.ts.map +1 -0
  301. package/dist/routes/schedules.js +234 -0
  302. package/dist/routes/schedules.js.map +1 -0
  303. package/dist/routes/scope-params.d.ts +57 -0
  304. package/dist/routes/scope-params.d.ts.map +1 -0
  305. package/dist/routes/scope-params.js +105 -0
  306. package/dist/routes/scope-params.js.map +1 -0
  307. package/dist/routes/secret-ref.d.ts +20 -0
  308. package/dist/routes/secret-ref.d.ts.map +1 -0
  309. package/dist/routes/secret-ref.js +42 -0
  310. package/dist/routes/secret-ref.js.map +1 -0
  311. package/dist/routes/secrets.d.ts +53 -0
  312. package/dist/routes/secrets.d.ts.map +1 -0
  313. package/dist/routes/secrets.js +715 -0
  314. package/dist/routes/secrets.js.map +1 -0
  315. package/dist/routes/signing-keys.d.ts +23 -0
  316. package/dist/routes/signing-keys.d.ts.map +1 -0
  317. package/dist/routes/signing-keys.js +212 -0
  318. package/dist/routes/signing-keys.js.map +1 -0
  319. package/dist/routes/sse.d.ts +58 -0
  320. package/dist/routes/sse.d.ts.map +1 -0
  321. package/dist/routes/sse.js +92 -0
  322. package/dist/routes/sse.js.map +1 -0
  323. package/dist/routes/teams.d.ts +30 -0
  324. package/dist/routes/teams.d.ts.map +1 -0
  325. package/dist/routes/teams.js +443 -0
  326. package/dist/routes/teams.js.map +1 -0
  327. package/dist/routes/tenant.d.ts +57 -0
  328. package/dist/routes/tenant.d.ts.map +1 -0
  329. package/dist/routes/tenant.js +352 -0
  330. package/dist/routes/tenant.js.map +1 -0
  331. package/dist/routes/tokens.d.ts +14 -0
  332. package/dist/routes/tokens.d.ts.map +1 -0
  333. package/dist/routes/tokens.js +231 -0
  334. package/dist/routes/tokens.js.map +1 -0
  335. package/dist/routes/tools.d.ts +33 -0
  336. package/dist/routes/tools.d.ts.map +1 -0
  337. package/dist/routes/tools.js +380 -0
  338. package/dist/routes/tools.js.map +1 -0
  339. package/dist/routes/webhook-endpoints.d.ts +10 -0
  340. package/dist/routes/webhook-endpoints.d.ts.map +1 -0
  341. package/dist/routes/webhook-endpoints.js +407 -0
  342. package/dist/routes/webhook-endpoints.js.map +1 -0
  343. package/dist/routes/webhooks.d.ts +21 -0
  344. package/dist/routes/webhooks.d.ts.map +1 -0
  345. package/dist/routes/webhooks.js +228 -0
  346. package/dist/routes/webhooks.js.map +1 -0
  347. package/dist/s3-credential-binding.d.ts +54 -0
  348. package/dist/s3-credential-binding.d.ts.map +1 -0
  349. package/dist/s3-credential-binding.js +4 -0
  350. package/dist/s3-credential-binding.js.map +1 -0
  351. package/dist/secrets-binding.d.ts +281 -0
  352. package/dist/secrets-binding.d.ts.map +1 -0
  353. package/dist/secrets-binding.js +10 -0
  354. package/dist/secrets-binding.js.map +1 -0
  355. package/dist/secrets-provider-binding.d.ts +164 -0
  356. package/dist/secrets-provider-binding.d.ts.map +1 -0
  357. package/dist/secrets-provider-binding.js +4 -0
  358. package/dist/secrets-provider-binding.js.map +1 -0
  359. package/dist/session-store-binding.d.ts +148 -0
  360. package/dist/session-store-binding.d.ts.map +1 -0
  361. package/dist/session-store-binding.js +4 -0
  362. package/dist/session-store-binding.js.map +1 -0
  363. package/dist/signing-key-binding.d.ts +210 -0
  364. package/dist/signing-key-binding.d.ts.map +1 -0
  365. package/dist/signing-key-binding.js +4 -0
  366. package/dist/signing-key-binding.js.map +1 -0
  367. package/dist/state-store-binding.d.ts +53 -0
  368. package/dist/state-store-binding.d.ts.map +1 -0
  369. package/dist/state-store-binding.js +38 -0
  370. package/dist/state-store-binding.js.map +1 -0
  371. package/dist/supervisor-binding.d.ts +526 -0
  372. package/dist/supervisor-binding.d.ts.map +1 -0
  373. package/dist/supervisor-binding.js +4 -0
  374. package/dist/supervisor-binding.js.map +1 -0
  375. package/dist/tenant-host-access.d.ts +41 -0
  376. package/dist/tenant-host-access.d.ts.map +1 -0
  377. package/dist/tenant-host-access.js +42 -0
  378. package/dist/tenant-host-access.js.map +1 -0
  379. package/dist/token-admin.d.ts +99 -0
  380. package/dist/token-admin.d.ts.map +1 -0
  381. package/dist/token-admin.js +4 -0
  382. package/dist/token-admin.js.map +1 -0
  383. package/dist/tool-binding.d.ts +247 -0
  384. package/dist/tool-binding.d.ts.map +1 -0
  385. package/dist/tool-binding.js +4 -0
  386. package/dist/tool-binding.js.map +1 -0
  387. package/dist/trigger-binding.d.ts +13 -0
  388. package/dist/trigger-binding.d.ts.map +1 -0
  389. package/dist/trigger-binding.js +4 -0
  390. package/dist/trigger-binding.js.map +1 -0
  391. package/dist/types.d.ts +71 -0
  392. package/dist/types.d.ts.map +1 -0
  393. package/dist/types.js +4 -0
  394. package/dist/types.js.map +1 -0
  395. package/dist/webhook-endpoint-binding.d.ts +230 -0
  396. package/dist/webhook-endpoint-binding.d.ts.map +1 -0
  397. package/dist/webhook-endpoint-binding.js +12 -0
  398. package/dist/webhook-endpoint-binding.js.map +1 -0
  399. package/dist/xml.d.ts +79 -0
  400. package/dist/xml.d.ts.map +1 -0
  401. package/dist/xml.js +115 -0
  402. package/dist/xml.js.map +1 -0
  403. package/openapi.json +29659 -0
  404. package/package.json +76 -4
  405. package/scripts/emit-openapi.mjs +44 -0
  406. package/src/adapter-binding.ts +204 -0
  407. package/src/agent-binding.ts +231 -0
  408. package/src/app.ts +1285 -0
  409. package/src/capability-binding.ts +83 -0
  410. package/src/cost-binding.ts +213 -0
  411. package/src/deployment-binding.ts +225 -0
  412. package/src/env-binding.ts +140 -0
  413. package/src/errors.ts +291 -0
  414. package/src/eval-run-binding.ts +209 -0
  415. package/src/eval-run-dispatcher.ts +497 -0
  416. package/src/eval-suite-binding.ts +257 -0
  417. package/src/event-bus-binding.ts +127 -0
  418. package/src/flow-binding.ts +213 -0
  419. package/src/guardrail-binding.ts +151 -0
  420. package/src/handler-binding.ts +132 -0
  421. package/src/hitl-binding.ts +172 -0
  422. package/src/identity-directory-binding.ts +128 -0
  423. package/src/identity-provider-binding.ts +203 -0
  424. package/src/image-registry-binding.ts +193 -0
  425. package/src/index.ts +606 -0
  426. package/src/key-management-binding.ts +91 -0
  427. package/src/mcp-endpoint-binding.ts +311 -0
  428. package/src/memory-binding.ts +239 -0
  429. package/src/middleware/auth.ts +437 -0
  430. package/src/middleware/authorize.ts +125 -0
  431. package/src/middleware/error-mapper.ts +37 -0
  432. package/src/middleware/idempotency.ts +160 -0
  433. package/src/middleware/principal.ts +64 -0
  434. package/src/middleware/public-run-routes.ts +50 -0
  435. package/src/middleware/request-id.ts +28 -0
  436. package/src/middleware/sigv4-verify.ts +374 -0
  437. package/src/middleware/sigv4.ts +165 -0
  438. package/src/openapi/generate.ts +307 -0
  439. package/src/openapi/operations.ts +5445 -0
  440. package/src/openapi/schemas.ts +6363 -0
  441. package/src/provenance-binding.ts +169 -0
  442. package/src/provider-binding.ts +196 -0
  443. package/src/public-run-token.ts +263 -0
  444. package/src/retention-binding.ts +78 -0
  445. package/src/reviewer-binding.ts +99 -0
  446. package/src/rotation-status-store.ts +209 -0
  447. package/src/routes/adapters.ts +319 -0
  448. package/src/routes/agents.ts +424 -0
  449. package/src/routes/approvals.ts +759 -0
  450. package/src/routes/artifacts.ts +317 -0
  451. package/src/routes/audit.ts +219 -0
  452. package/src/routes/auth.ts +806 -0
  453. package/src/routes/capabilities.ts +79 -0
  454. package/src/routes/compliance.ts +482 -0
  455. package/src/routes/conversations.ts +369 -0
  456. package/src/routes/cost.ts +327 -0
  457. package/src/routes/deployments.ts +1493 -0
  458. package/src/routes/env.ts +429 -0
  459. package/src/routes/eval-runs.ts +631 -0
  460. package/src/routes/eval-suites.ts +490 -0
  461. package/src/routes/event-triggers.ts +283 -0
  462. package/src/routes/flows.ts +423 -0
  463. package/src/routes/guardrails.ts +320 -0
  464. package/src/routes/identity.ts +203 -0
  465. package/src/routes/mcp.ts +940 -0
  466. package/src/routes/memory.ts +430 -0
  467. package/src/routes/observations.ts +175 -0
  468. package/src/routes/orgs.ts +273 -0
  469. package/src/routes/pagination.ts +51 -0
  470. package/src/routes/policies.ts +413 -0
  471. package/src/routes/projects.ts +634 -0
  472. package/src/routes/proposals.ts +719 -0
  473. package/src/routes/provenance.ts +406 -0
  474. package/src/routes/providers.ts +624 -0
  475. package/src/routes/public-run-tokens.ts +104 -0
  476. package/src/routes/retention.ts +193 -0
  477. package/src/routes/reviewers.ts +209 -0
  478. package/src/routes/runs.ts +981 -0
  479. package/src/routes/s3.ts +519 -0
  480. package/src/routes/schedules.ts +300 -0
  481. package/src/routes/scope-params.ts +133 -0
  482. package/src/routes/secret-ref.ts +52 -0
  483. package/src/routes/secrets.ts +975 -0
  484. package/src/routes/signing-keys.ts +259 -0
  485. package/src/routes/sse.ts +148 -0
  486. package/src/routes/teams.ts +584 -0
  487. package/src/routes/tenant.ts +530 -0
  488. package/src/routes/tokens.ts +285 -0
  489. package/src/routes/tools.ts +491 -0
  490. package/src/routes/webhook-endpoints.ts +534 -0
  491. package/src/routes/webhooks.ts +296 -0
  492. package/src/s3-credential-binding.ts +58 -0
  493. package/src/secrets-binding.ts +308 -0
  494. package/src/secrets-provider-binding.ts +167 -0
  495. package/src/session-store-binding.ts +163 -0
  496. package/src/signing-key-binding.ts +235 -0
  497. package/src/state-store-binding.ts +84 -0
  498. package/src/supervisor-binding.ts +554 -0
  499. package/src/tenant-host-access.ts +62 -0
  500. package/src/token-admin.ts +104 -0
  501. package/src/tool-binding.ts +274 -0
  502. package/src/trigger-binding.ts +38 -0
  503. package/src/types.ts +74 -0
  504. package/src/webhook-endpoint-binding.ts +246 -0
  505. package/src/xml.ts +196 -0
@@ -0,0 +1,165 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ // Copyright (C) 2026 Kindgi Inc.
3
+
4
+ import { createHash } from 'node:crypto';
5
+
6
+ import type { MiddlewareHandler } from 'hono';
7
+
8
+ import type { S3CredentialBinding } from '../s3-credential-binding.js';
9
+ import type { AppEnv } from '../types.js';
10
+ import { errorXml } from '../xml.js';
11
+ import {
12
+ checkSigV4Claim,
13
+ constantTimeEqual,
14
+ parseSigV4,
15
+ verifySigV4Signature,
16
+ } from './sigv4-verify.js';
17
+
18
+ /**
19
+ * AWS SigV4 verification middleware for the `/s3/*` wire surface.
20
+ * Verifies both header-based auth (`Authorization: AWS4-HMAC-SHA256 ...`)
21
+ * and presigned URLs (`?X-Amz-Algorithm=...&X-Amz-Signature=...`). On
22
+ * success sets `tenantId`, `bucket` and `s3AccessKeyId` on the context for
23
+ * downstream route handlers.
24
+ *
25
+ * The signature is re-derived from exactly what the client signed — its
26
+ * own timestamp and only its `SignedHeaders` (see `./sigv4-verify.ts`);
27
+ * the server clock only bounds the timestamp (±15 minutes; presigned URLs
28
+ * until `X-Amz-Expires`). Order: parse → timestamp/scope → credential →
29
+ * payload hash → signature → bucket.
30
+ *
31
+ * ## S3-style errors
32
+ *
33
+ * Failures return S3 error XML (not JSON): `AccessDenied`,
34
+ * `InvalidAccessKeyId`, `SignatureDoesNotMatch`, `RequestTimeTooSkewed`,
35
+ * `XAmzContentSHA256Mismatch`, `AuthorizationQueryParametersError`,
36
+ * `InvalidRequest`.
37
+ */
38
+ export function sigv4Middleware(binding: S3CredentialBinding): MiddlewareHandler<AppEnv> {
39
+ return async (c, next) => {
40
+ const req = c.req.raw;
41
+ const method = req.method;
42
+ // Read body once so both hash + downstream reads can access it.
43
+ // The whole body is buffered — a limitation for large uploads; true
44
+ // streaming would need to pass the raw stream through after a
45
+ // header-only signature check.
46
+ const bodyBytes =
47
+ method === 'GET' || method === 'HEAD' || method === 'DELETE'
48
+ ? Buffer.alloc(0)
49
+ : Buffer.from(await req.arrayBuffer());
50
+
51
+ const url = new URL(req.url);
52
+ const request = { method, url, headers: req.headers };
53
+
54
+ const claim = parseSigV4(request);
55
+ if (claim.kind === 'err') {
56
+ return xmlError(c, claim.error.code, claim.error.message, claim.error.status);
57
+ }
58
+ const info = claim.value;
59
+ const checked = checkSigV4Claim(info, new Date());
60
+ if (checked.kind === 'err') {
61
+ return xmlError(c, checked.error.code, checked.error.message, checked.error.status);
62
+ }
63
+
64
+ const credential = await binding.resolve(info.accessKeyId);
65
+ if (credential === null) {
66
+ return xmlError(
67
+ c,
68
+ 'InvalidAccessKeyId',
69
+ `The AWS Access Key Id you provided does not exist: ${info.accessKeyId}`,
70
+ 403,
71
+ );
72
+ }
73
+ if (credential.expiresAt !== undefined && credential.expiresAt.getTime() < Date.now()) {
74
+ return xmlError(c, 'AccessDenied', 'Credential has expired', 403);
75
+ }
76
+
77
+ // ------------ payload hash verification ------------
78
+ // Header auth signs `x-amz-content-sha256`. Cross-check it against
79
+ // the actual body bytes, or an attacker could swap the body after
80
+ // signing and the signature would still verify. (Presigned URLs sign
81
+ // `UNSIGNED-PAYLOAD` by design.)
82
+ if (info.kind === 'header' && bodyBytes.length > 0) {
83
+ const declared = c.req.header('x-amz-content-sha256') ?? '';
84
+ if (declared !== 'UNSIGNED-PAYLOAD' && declared.length > 0) {
85
+ const actual = createHash('sha256').update(bodyBytes).digest('hex');
86
+ if (!constantTimeEqual(actual, declared)) {
87
+ return xmlError(
88
+ c,
89
+ 'XAmzContentSHA256Mismatch',
90
+ 'The provided x-amz-content-sha256 header does not match the SHA256 of the request body.',
91
+ 400,
92
+ );
93
+ }
94
+ }
95
+ }
96
+
97
+ // ------------ signature ------------
98
+ const verified = verifySigV4Signature(request, info, credential.secretKey);
99
+ if (verified.kind === 'err') {
100
+ return xmlError(c, verified.error.code, verified.error.message, verified.error.status);
101
+ }
102
+
103
+ // ------------ bucket authorization ------------
104
+ // Extract bucket from URL. /s3/<bucket>/<key>. The router mounts
105
+ // this middleware under /s3, so the first path segment after
106
+ // stripping the mount is the bucket.
107
+ const requestedBucket = extractBucket(url.pathname);
108
+ if (requestedBucket === null) {
109
+ return xmlError(c, 'InvalidRequest', 'Bucket path segment missing', 400);
110
+ }
111
+ if (requestedBucket !== credential.bucket) {
112
+ return xmlError(
113
+ c,
114
+ 'AccessDenied',
115
+ `Credential is not authorized for bucket "${requestedBucket}"`,
116
+ 403,
117
+ );
118
+ }
119
+
120
+ // Buffer the body onto the request for downstream handlers to
121
+ // re-consume. Hono's Context re-reads req.raw for each parse.
122
+ rebindBody(c, bodyBytes);
123
+
124
+ c.set('tenantId', credential.tenantId);
125
+ c.set('bucket', credential.bucket);
126
+ c.set('s3AccessKeyId', info.accessKeyId);
127
+ await next();
128
+ return;
129
+ };
130
+ }
131
+
132
+ function extractBucket(pathname: string): string | null {
133
+ // pathname like /s3/<bucket>/<key/with/slashes>. Middleware is
134
+ // mounted at /s3, so req.url still shows the full pathname.
135
+ const match = /^\/s3\/([^/?]+)/.exec(pathname);
136
+ return match === null ? null : (match[1] as string);
137
+ }
138
+
139
+ // -------------------- comparison + rebind helpers --------------------
140
+
141
+ function rebindBody(c: { req: { raw: Request } }, body: Buffer): void {
142
+ const original = c.req.raw;
143
+ const rebuilt = new Request(original.url, {
144
+ method: original.method,
145
+ headers: original.headers,
146
+ body: body.length > 0 ? new Uint8Array(body) : undefined,
147
+ // `duplex: 'half'` is required by undici when a body is present.
148
+ ...(body.length > 0 && { duplex: 'half' }),
149
+ } as RequestInit);
150
+ Object.defineProperty(c.req, 'raw', { value: rebuilt, configurable: true });
151
+ }
152
+
153
+ // -------------------- XML error response --------------------
154
+
155
+ async function xmlError(
156
+ c: import('hono').Context,
157
+ code: string,
158
+ message: string,
159
+ status: number,
160
+ ): Promise<Response> {
161
+ const xml = errorXml(code, message);
162
+ return c.body(xml, status as never, {
163
+ 'Content-Type': 'application/xml',
164
+ });
165
+ }
@@ -0,0 +1,307 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ // Copyright (C) 2026 Kindgi Inc.
3
+
4
+ /**
5
+ * OpenAPI 3.1 document generator. Assembles `info` + `servers` +
6
+ * `components` + `paths` + `tags` from the operation registry
7
+ * (`operations.ts`) and the schema registry (`schemas.ts`).
8
+ *
9
+ * The output is a plain JSON-serializable object — the caller decides
10
+ * how to expose it (route handler, static file, both).
11
+ */
12
+
13
+ import {
14
+ OPERATIONS,
15
+ type OperationSpec,
16
+ type ParameterSpec,
17
+ type ResponseSpec,
18
+ honoToOpenapiPath,
19
+ } from './operations.js';
20
+ import { COMPONENT_SCHEMAS, type JsonSchema } from './schemas.js';
21
+
22
+ export interface OpenApiInfo {
23
+ readonly title?: string;
24
+ readonly version?: string;
25
+ readonly description?: string;
26
+ }
27
+
28
+ export interface OpenApiServer {
29
+ readonly url: string;
30
+ readonly description?: string;
31
+ }
32
+
33
+ export interface GenerateOptions {
34
+ readonly info?: OpenApiInfo;
35
+ readonly servers?: readonly OpenApiServer[];
36
+ }
37
+
38
+ const DEFAULT_INFO: Required<OpenApiInfo> = {
39
+ title: 'Kindgi Platform API',
40
+ version: '0.1.0',
41
+ description:
42
+ 'REST + SSE API for Kindgi: runs, agents, flows, human-in-the-loop approvals and the admin control plane. Generated from the route and schema registrations in `@kindgi/api` and drift-checked against the mounted routes.',
43
+ };
44
+
45
+ const DEFAULT_SERVERS: readonly OpenApiServer[] = [
46
+ { url: '/', description: 'Same-origin — path relative to the deployment root.' },
47
+ ];
48
+
49
+ const TAG_DESCRIPTIONS: Readonly<Record<string, string>> = {
50
+ system: 'Health + spec discovery.',
51
+ runs: 'Run lifecycle (start, list, get, cancel, resume, journal, stream).',
52
+ 'signing-keys':
53
+ 'The deployment trust list: the public keys whose signatures `POST /v1/deployments` accepts. Revoked keys stay readable for audit.',
54
+ tokens:
55
+ 'API token administration (mint + revoke), and public run tokens: short-lived, read-only tokens a browser uses to follow specific runs.',
56
+ approvals: 'Human-in-the-loop review queue (role-scoped).',
57
+ observations: 'Supervisor readback of run outcomes.',
58
+ agents: 'Agent catalog (list, get, publish, unregister — caller-plugged registry).',
59
+ flows:
60
+ 'Flow catalog (list, get, publish, unregister — caller-plugged registry). Enables non-agent workflows via HTTP — publish once, execute many via `POST /v1/runs`.',
61
+ tools: 'Tool catalog (list, get, register, unregister — caller-plugged registry, metadata-only).',
62
+ guardrails:
63
+ 'Guardrail catalog (list, get, register, unregister — caller-plugged registry, metadata-only).',
64
+ conversations: 'Durable multi-turn threads (open, list, get, close, read messages).',
65
+ memory:
66
+ 'Fact catalog + retrieval (list, get, write, supersede, retrieve — caller-plugged binding wraps the memory subsystem).',
67
+ proposals:
68
+ 'Supervisor fix-proposal lifecycle (draft, dry-run, submit-review, apply, rollback, withdraw — caller-plugged binding wraps the supervisor).',
69
+ provenance:
70
+ 'Causal DAG readback + signed exports (list, get, export — signing is caller-plugged via `SigningKeyBinding`).',
71
+ artifacts:
72
+ 'Blob storage (list metadata, multipart upload, streaming download, HEAD, delete). Caller-plugged via `BlobStorageBinding` (from `@kindgi/blob-binding`).',
73
+ capabilities:
74
+ 'Capability catalog (list + get) — part of the admin control plane. Read-only over HTTP. Capabilities are framework-declared (`FEATURES` enum + `@kindgi/specs/capability.schema.json`) and deployment-extended at boot time via `CapabilityRegistryBinding`; tenants do NOT author capabilities via the API.',
75
+ providers:
76
+ 'Model-provider catalog (list, get, register, unregister, capabilities sub-resource) — part of the admin control plane. Full CRUD. `ProviderMetadata` is the wire shape; secrets never cross the wire (they live inside `ProviderRegistryBinding`). The capability router picks a best-fit provider from this set per capability requirement at run time.',
77
+ cost: 'Cost readback (list records, get record, aggregate across a required time window) — part of the admin control plane. Read-only over HTTP; records are written by the runtime usage instrumentation (agents, tools, sandboxes). Caller-plugged via `CostBinding`. Budgets are not enforced through this surface.',
78
+ adapters:
79
+ 'Unified adapter catalog (list, get, test) — part of the admin control plane. Covers every adapter kind the deployment wired: model providers, embedding providers, blob storage, sandbox providers, eval judges. Read-only + smoke-test-only over HTTP; adapter lifecycle (register / unregister / reconfigure) is a deployment concern — the runtime learns about adapters at `CreateAppInput` time. Caller-plugged via `AdapterRegistryBinding`. Config is REDACTED on the wire — no secrets crossing.',
80
+ policies:
81
+ 'Tenant policy catalog (list, get, versions, publish, unregister) — part of the admin control plane. Full versioned CRUD, mirrors `flows` 1:1. Registry-only: enforcement is out of scope. `policyKind` selects the shape of `spec` — closed enum, extended additively (`access-control`, `model-routing`, `adapter-allowlist`, `rate-limit`, `retention`, `compliance`). Runtime consumers (e.g. model routing for `model-routing`, retention sweeps for `retention`) read policies from this store and apply them at their own boundary. Caller-plugged via `PolicyRegistryBinding`.',
82
+ 'eval-suites':
83
+ 'Evaluation suite catalog (list, get, versions, publish, unregister) — part of the admin control plane. Full versioned CRUD, mirrors `policies` 1:1. Registry-only: eval-run execution + per-kind grader dispatch live on the `eval-runs` tag. `evalKind` selects the shape of `spec` — closed enum, extended additively (`accuracy`, `pairwise`, `regression`, `human-review`, `benchmark`, `custom`). Runs against these suites are started through the `eval-runs` tag. Caller-plugged via `EvalSuiteRegistryBinding`.',
84
+ 'eval-runs':
85
+ 'Eval-run data plane (start, list, get, cancel, events SSE). Dispatches an eval run against a registered suite. Dispatch is per-`EvalKind`; kinds without a registered dispatcher return `422 dispatcher-not-registered`. `result` is kind-specific opaque JSON on the wire — for `accuracy` it is `{ passCount, totalCount, meanScore, perCase[] }`. SSE events mirror run streaming: per-case progress followed by a terminal frame carrying the aggregate. Caller-plugged via `EvalRunBinding`.',
86
+ auth: 'OAuth 2.0 / OIDC identity providers + session lifecycle. Layers browser-based auth on top of the static bearer-token surface: bearer tokens continue to work byte-shape-identical; session tokens use the `kgi_sk_*` prefix so the same middleware routes both flavors. Providers are caller-plugged via `IdentityProviderBinding` (no baked-in list). Sessions persist via `SessionStoreBinding`. Code exchange is caller-supplied via `exchangeCode`. PKCE (S256) is mandatory. `clientSecretRef` is a REFERENCE — the plaintext secret never crosses the wire.',
87
+ identity:
88
+ 'Tenant-scoped identity directory (list, get, list-active-sessions, revoke-sessions, whoami) — part of the admin control plane. Caller-plugged via `IdentityDirectoryBinding` — deployments plug in their own user store (LDAP, SCIM, or bespoke). Registry-only over HTTP: the framework does NOT own user persistence. The directory is flat; groups, roles, invitations, directory sync and impersonation are not part of this surface. `primaryEmail` may be redacted per tenant policy — the routes treat it as opaque. Provider access-token / refresh-token NEVER cross the wire, even to admins.',
89
+ mcp: "MCP-endpoint catalog (list, get, register, unregister). Tenants declare the remote MCP servers (`stdio` / `http-sse` / `streamable-http`) they want the runtime to consume. The runtime discovers each endpoint's tools and registers them into `ToolRegistryBinding` under the same tenant — remote MCP tools become native Kindgi tools without a recompile. Secrets never cross the wire: `secretRef` names a secret in the deployment's store, resolved at the endpoint's tenant scope. A deployment refuses `stdio` endpoints unless `KINDGI_TENANT_HOST_ACCESS=local`. Caller-plugged via `MCPEndpointRegistryBinding`.",
90
+ deployments:
91
+ 'Signed pack deployments (register, list, get). The single wire surface that lands a signed OCI image + index.json into the platform. Register runs a six-step atomic transaction: Ed25519 signature verify over the canonical `{imageDigest, artifactVersion, indexHash, tenantId, publishedAt}` envelope, tenant-scoped trust-list check via `SigningKeyRegistryBinding`, image pullability + `/app/index.json` sha256 match via `ImageRegistryBinding`, per-primitive manifest validation, registry upserts (tools + guardrails + agents + flows), append-only deployment ledger row via `DeploymentBinding`. All-or-nothing rollback on any failure; digest-based idempotency (redeploying the same image returns the existing record). Records are immutable — rollback = re-register the previous digest.',
92
+ compliance:
93
+ 'Compliance-evidence readback + signed exports (list, get, export). Reads are a classification lens over `AuditEventBinding`; only classifier-marked `exportable` kinds appear on the wire. Signed export is caller-plugged via `SigningKeyBinding` — deployments without a signing key get `404 signing-not-configured`. Bundle envelope matches `provenance.export` + audit-bundle byte-for-byte so verifiers reuse one `verifyEd25519` wrapper across all three surfaces. Redaction happens when evidence is generated, not at the export boundary — records are stored already redacted.',
94
+ audit:
95
+ 'PDP decision audit stream (list). Every route-level authz `check()` emits one `AuditEvent` (kind `authz-decision`) via the `AuditEventBinding`; this route pages through them, tenant-scoped, with `?actorSubject=` / `?onBehalfOf=` / `?action=` / `?resource=` / `?outcome=` / `?runId=` / `?from=` / `?to=` filters. Admin@tenant only. This view is a filtered projection of the tenant audit events.',
96
+ orgs: 'Multi-tenant hierarchy — Org CRUD (list, create, get, patch, delete). Optional structural subdivision within a tenant; small tenants ignore Orgs entirely. Caller-plugged via `OrgBinding` from `@kindgi/platform`.',
97
+ teams:
98
+ 'Multi-tenant hierarchy — Team CRUD (list, create, get, patch, delete) + `TeamMembership` sub-resource (list, add, updateRole, remove). People-groups that work together on projects; users belong to many teams. Team memberships are framework-owned (no external directory sync). Membership add is idempotent on `(teamId, userId)` — role mutation goes through PATCH.',
99
+ projects:
100
+ 'Multi-tenant hierarchy — Project CRUD (list, create, get, patch, delete) + `/projects/default` shortcut + `ProjectMembership` sub-resource (list, add, updateRole, remove). Primary content scope: every content resource belongs to exactly one project. The Default project (`isDefault: true`) is auto-created per tenant at inception — exactly one per tenant, enforced at the storage layer.',
101
+ tenant:
102
+ 'Sovereignty boundary readback + tenant-scoped config (get tenant; list + upsert entries routed to the env / secrets bindings). There is no `/v1/tenants` collection — the caller\'s tenant is implicit from the bearer token. `PATCH /config` routes writes to `SecretBinding` when `sensitive: true` OR `kind: "secret"`; else to `EnvBinding`. `GET /config` merges both bindings at tenant scope; secret values are ALWAYS redacted here. The `/config` sub-routes mount when at least one of `envBinding` / `secretsBinding` is wired. Prefer `/v1/env/*` + `/v1/secrets/*` for new callers.',
103
+ env: 'Non-sensitive per-env values (`/v1/env/*`). Every route requires `envName` + `scopeKind` (+ `scopeId` for org / project); `value` is present on every read path (env is non-sensitive by definition). Writes require the `env:write` capability. Caller-plugged via `EnvBinding` (`@kindgi/env-inmemory` is an in-memory implementation for development and tests).',
104
+ 'webhook-endpoints':
105
+ 'Outbound webhooks: endpoints the platform sends signed events to (`run.finished` when a top-level run completes, fails or is cancelled), their delivery log, redelivery and a test event. Signed in the Standard Webhooks format with a secret the endpoint references by name (`secretRef`); delivered at least once, so receivers deduplicate on `webhook-id`. Event bodies are under `webhooks`. Not to be confused with `/v1/webhooks`, which are inbound triggers. Caller-plugged via `WebhookEndpointBinding`.',
106
+ secrets:
107
+ 'Sensitive per-env values (`/v1/secrets/*`). The ONLY endpoint that accepts plaintext is `POST /v1/secrets`; every other route is metadata-only (`value` NEVER returns on list / get / listVersions / getVersion — structural redaction). Rotation is discriminated: sync providers return 201 inline, async providers return 202 with a status URL + SSE events URL. Hard-revoke performs cryptographic erasure. Every mutating route is capability-gated (`secrets:write`, `secrets:rotate`, `secrets:revoke`, `secrets:revoke:hard`).',
108
+ };
109
+
110
+ export function generateOpenApiDocument(opts: GenerateOptions = {}): Record<string, unknown> {
111
+ const info: OpenApiInfo = { ...DEFAULT_INFO, ...opts.info };
112
+ const servers = opts.servers ?? DEFAULT_SERVERS;
113
+
114
+ const paths = buildPaths(OPERATIONS);
115
+ const components = {
116
+ schemas: Object.fromEntries(COMPONENT_SCHEMAS),
117
+ securitySchemes: {
118
+ bearerAuth: {
119
+ type: 'http',
120
+ scheme: 'bearer',
121
+ description:
122
+ "Bearer token minted via `POST /v1/tokens` (or the deployment's equivalent). See `docs/API-ROUTE-CONVENTIONS.md` §2.",
123
+ },
124
+ publicRunToken: {
125
+ type: 'http',
126
+ scheme: 'bearer',
127
+ bearerFormat: 'kgi_pt',
128
+ description:
129
+ 'Public run token (`kgi_pt_…`): short-lived and read-only, for a browser following specific runs. Returned by `POST /v1/runs` and minted by `POST /v1/tokens/public`. Accepted only by `GET /v1/runs/{runId}/progress` and its stream.',
130
+ },
131
+ },
132
+ };
133
+ const tags = uniqueTags(OPERATIONS).map((name) => ({
134
+ name,
135
+ ...(TAG_DESCRIPTIONS[name] !== undefined && { description: TAG_DESCRIPTIONS[name] }),
136
+ }));
137
+
138
+ return {
139
+ openapi: '3.1.0',
140
+ info,
141
+ servers,
142
+ tags,
143
+ components,
144
+ paths,
145
+ webhooks: buildOutboundWebhooks(),
146
+ };
147
+ }
148
+
149
+ /**
150
+ * The requests the platform sends to registered webhook endpoints
151
+ * (OpenAPI 3.1 `webhooks`): one entry per event type, all signed the same
152
+ * way.
153
+ */
154
+ function buildOutboundWebhooks(): Record<string, unknown> {
155
+ const signatureHeaders = [
156
+ {
157
+ name: 'webhook-id',
158
+ in: 'header',
159
+ required: true,
160
+ description: 'The event id; the same on every retry. Deduplicate on it.',
161
+ schema: { type: 'string' },
162
+ },
163
+ {
164
+ name: 'webhook-timestamp',
165
+ in: 'header',
166
+ required: true,
167
+ description: 'Unix seconds when the request was signed. Reject requests far from your clock.',
168
+ schema: { type: 'string', pattern: '^[0-9]+$' },
169
+ },
170
+ {
171
+ name: 'webhook-signature',
172
+ in: 'header',
173
+ required: true,
174
+ description:
175
+ '`v1,<base64 HMAC-SHA256 of "{webhook-id}.{webhook-timestamp}.{body}">` under the endpoint\'s secret; space-separated when two secrets sign during a rotation.',
176
+ schema: { type: 'string' },
177
+ },
178
+ ];
179
+ const event = (type: string, summary: string, schema: string): Record<string, unknown> => ({
180
+ post: {
181
+ operationId: `webhook.${type}`,
182
+ summary,
183
+ tags: ['webhook-endpoints'],
184
+ // The receiver authenticates the request by its signature
185
+ // (`webhook-signature`), not by an API credential.
186
+ security: [],
187
+ parameters: signatureHeaders,
188
+ requestBody: {
189
+ required: true,
190
+ content: { 'application/json': { schema: { $ref: `#/components/schemas/${schema}` } } },
191
+ },
192
+ responses: {
193
+ '2XX': {
194
+ description: 'Received. Any other answer, or none within 10 seconds, is retried.',
195
+ },
196
+ },
197
+ },
198
+ });
199
+ return {
200
+ 'run.finished': event(
201
+ 'run.finished',
202
+ 'A top-level run completed, failed or was cancelled',
203
+ 'RunFinishedEvent',
204
+ ),
205
+ 'webhook.test': event(
206
+ 'webhook.test',
207
+ 'A test event sent on request (`POST /v1/webhook-endpoints/{endpointId}/test`)',
208
+ 'WebhookTestEvent',
209
+ ),
210
+ };
211
+ }
212
+
213
+ // ---------------- internals ----------------
214
+
215
+ function buildPaths(ops: readonly OperationSpec[]): Record<string, Record<string, unknown>> {
216
+ const paths: Record<string, Record<string, unknown>> = {};
217
+ for (const op of ops) {
218
+ const key = op.openapiPath ?? honoToOpenapiPath(op.honoPath);
219
+ let bucket = paths[key];
220
+ if (bucket === undefined) {
221
+ bucket = {};
222
+ paths[key] = bucket;
223
+ }
224
+ if (bucket[op.method] !== undefined) {
225
+ throw new Error(`Duplicate operation for ${op.method.toUpperCase()} ${key}`);
226
+ }
227
+ bucket[op.method] = buildOperation(op);
228
+ }
229
+ return paths;
230
+ }
231
+
232
+ function buildOperation(op: OperationSpec): Record<string, unknown> {
233
+ const doc: Record<string, unknown> = {
234
+ operationId: op.operationId,
235
+ summary: op.summary,
236
+ tags: [...op.tags],
237
+ responses: buildResponses(op.responses),
238
+ };
239
+ if (op.description !== undefined) doc.description = op.description;
240
+ if (op.parameters !== undefined && op.parameters.length > 0) {
241
+ doc.parameters = op.parameters.map(buildParameter);
242
+ }
243
+ if (op.requestBody !== undefined) {
244
+ const contentType = op.requestBody.contentType ?? 'application/json';
245
+ const contentSlot: Record<string, unknown> = { schema: op.requestBody.schema };
246
+ if (op.requestBody.encoding !== undefined) {
247
+ contentSlot.encoding = op.requestBody.encoding;
248
+ }
249
+ doc.requestBody = {
250
+ required: op.requestBody.required ?? true,
251
+ ...(op.requestBody.description !== undefined && {
252
+ description: op.requestBody.description,
253
+ }),
254
+ content: {
255
+ [contentType]: contentSlot,
256
+ },
257
+ };
258
+ }
259
+ if (op.security === 'bearer') {
260
+ doc.security = [{ bearerAuth: [] }];
261
+ } else if (op.security === 'bearer-or-public-run') {
262
+ doc.security = [{ bearerAuth: [] }, { publicRunToken: [] }];
263
+ } else {
264
+ doc.security = [];
265
+ }
266
+ return doc;
267
+ }
268
+
269
+ function buildParameter(p: ParameterSpec): Record<string, unknown> {
270
+ const doc: Record<string, unknown> = {
271
+ name: p.name,
272
+ in: p.in,
273
+ schema: p.schema,
274
+ };
275
+ if (p.required !== undefined) doc.required = p.required;
276
+ else if (p.in === 'path') doc.required = true;
277
+ if (p.description !== undefined) doc.description = p.description;
278
+ return doc;
279
+ }
280
+
281
+ function buildResponses(
282
+ responses: Readonly<Record<string, ResponseSpec>>,
283
+ ): Record<string, unknown> {
284
+ const doc: Record<string, unknown> = {};
285
+ for (const [status, spec] of Object.entries(responses)) {
286
+ const entry: Record<string, unknown> = { description: spec.description };
287
+ if (spec.schema !== undefined) {
288
+ const contentType = spec.contentType ?? 'application/json';
289
+ entry.content = { [contentType]: { schema: spec.schema as JsonSchema } };
290
+ }
291
+ doc[status] = entry;
292
+ }
293
+ return doc;
294
+ }
295
+
296
+ function uniqueTags(ops: readonly OperationSpec[]): readonly string[] {
297
+ const seen = new Set<string>();
298
+ const out: string[] = [];
299
+ for (const op of ops) {
300
+ for (const t of op.tags) {
301
+ if (seen.has(t)) continue;
302
+ seen.add(t);
303
+ out.push(t);
304
+ }
305
+ }
306
+ return out;
307
+ }