@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,169 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ // Copyright (C) 2026 Kindgi Inc.
3
+
4
+ //
5
+ // Provenance binding surface — types + `ProvenanceBinding` interface
6
+ // consumed by the provenance routes. Deployments plug in an
7
+ // implementation (the Kindgi runtime provides one); @kindgi/api never
8
+ // touches provenance storage directly.
9
+ //
10
+
11
+ import type { FlowId, ProvenanceId, Result, RunId, TenantId, Timestamp } from '@kindgi/types';
12
+
13
+ // ---------- domain type surface ----------
14
+
15
+ export const NODE_KINDS = [
16
+ 'input',
17
+ 'prompt',
18
+ 'retrieval',
19
+ 'tool-call',
20
+ 'tool-result',
21
+ 'model-call',
22
+ 'model-output',
23
+ 'artifact',
24
+ 'guardrail-check',
25
+ 'event',
26
+ 'policy-decision',
27
+ 'memory-read',
28
+ 'memory-write',
29
+ 'wait',
30
+ 'resume',
31
+ ] as const;
32
+
33
+ export type NodeKind = (typeof NODE_KINDS)[number];
34
+
35
+ export const EDGE_KINDS = [
36
+ 'caused-by',
37
+ 'influenced-by',
38
+ 'retrieved-from',
39
+ 'invoked',
40
+ 'produced',
41
+ 'checked-against',
42
+ 'waited-on',
43
+ 'resumed-from',
44
+ ] as const;
45
+
46
+ export type EdgeKind = (typeof EDGE_KINDS)[number];
47
+
48
+ export interface ProvenanceNode {
49
+ readonly id: string;
50
+ readonly kind: NodeKind;
51
+ readonly timestamp: Timestamp;
52
+ readonly actor?: string;
53
+ readonly contentHash?: string;
54
+ readonly contentRef?: string;
55
+ readonly modelVersion?: string;
56
+ readonly policyDecisionId?: string;
57
+ readonly attributes?: Readonly<Record<string, unknown>>;
58
+ }
59
+
60
+ export interface ProvenanceEdge {
61
+ readonly from: string;
62
+ readonly to: string;
63
+ readonly kind: EdgeKind;
64
+ }
65
+
66
+ export interface Signature {
67
+ readonly algorithm: 'ed25519';
68
+ readonly keyId: string;
69
+ readonly value: string;
70
+ readonly signedAt: Timestamp;
71
+ }
72
+
73
+ export interface Provenance {
74
+ readonly id: ProvenanceId;
75
+ readonly runId: RunId;
76
+ readonly tenantId: TenantId;
77
+ readonly version: string;
78
+ readonly createdAt: Timestamp;
79
+ readonly flowRef?: { readonly id: FlowId; readonly version: string };
80
+ readonly nodes: readonly ProvenanceNode[];
81
+ readonly edges: readonly ProvenanceEdge[];
82
+ readonly signature?: Signature;
83
+ }
84
+
85
+ // ---------- method inputs / outputs ----------
86
+
87
+ /**
88
+ * Keyset cursor for `listRecords`. Decoded shape — routes handle the
89
+ * base64 encoding envelope (`./routes/pagination.ts`). Binding consumers
90
+ * pass the decoded pair through so the binding never touches route-layer
91
+ * encoding conventions.
92
+ */
93
+ export interface ProvenanceListCursor {
94
+ readonly createdAt: string;
95
+ readonly id: string;
96
+ }
97
+
98
+ export interface ListProvenanceRecordsInput {
99
+ readonly tenantId: TenantId;
100
+ readonly limit: number;
101
+ readonly runId?: RunId;
102
+ readonly agentId?: string;
103
+ readonly createdAfter?: Date;
104
+ readonly cursor?: ProvenanceListCursor;
105
+ }
106
+
107
+ /**
108
+ * Denormalized record metadata used by `GET /v1/provenance` list. Full
109
+ * DAG (`nodes`, `edges`) is fetched only via `getByRunId` — list only
110
+ * exposes summary rows.
111
+ */
112
+ export interface ProvenanceRecordSummary {
113
+ readonly id: ProvenanceId;
114
+ readonly runId: RunId;
115
+ readonly tenantId: TenantId;
116
+ readonly version: string;
117
+ readonly createdAt: Timestamp;
118
+ readonly flowRef?: { readonly id: FlowId; readonly version: string };
119
+ readonly signed: boolean;
120
+ }
121
+
122
+ export interface ListProvenanceRecordsResult {
123
+ readonly records: readonly ProvenanceRecordSummary[];
124
+ readonly nextCursor?: ProvenanceListCursor;
125
+ }
126
+
127
+ // ---------- error shape ----------
128
+
129
+ /**
130
+ * Structural error surface returned by `ProvenanceBinding` methods.
131
+ * Implementations emit codes `provenance-not-found` + `persistence-error`
132
+ * — the routes pass them through to `statusFor()` / `toWireError()`.
133
+ */
134
+ export interface ProvenanceBindingError {
135
+ readonly code: string;
136
+ readonly message: string;
137
+ readonly [key: string]: unknown;
138
+ }
139
+
140
+ // ---------- binding ----------
141
+
142
+ /**
143
+ * Provenance data-access binding. Every method takes typed inputs and
144
+ * returns `Promise<Result<T, ProvenanceBindingError>>` — the
145
+ * implementation owns its storage client, so callers never touch
146
+ * storage directly.
147
+ */
148
+ export interface ProvenanceBinding {
149
+ /**
150
+ * List provenance records, keyset-paginated by
151
+ * `(createdAt desc, id desc)`. Optional filters narrow by run, agent
152
+ * (node actor), and creation window. Returns already-shaped
153
+ * `ProvenanceRecordSummary` rows — the binding owns the storage →
154
+ * wire projection.
155
+ *
156
+ * The result carries `nextCursor` when more records exist; the route
157
+ * derives `hasMore` from it and encodes it as the next cursor.
158
+ */
159
+ listRecords(
160
+ input: ListProvenanceRecordsInput,
161
+ ): Promise<Result<ListProvenanceRecordsResult, ProvenanceBindingError>>;
162
+
163
+ /**
164
+ * Reconstruct the full provenance DAG for a run. Returns
165
+ * `provenance-not-found` (via `code`) when no record exists for the
166
+ * tenant/run pair.
167
+ */
168
+ getByRunId(tenantId: TenantId, runId: RunId): Promise<Result<Provenance, ProvenanceBindingError>>;
169
+ }
@@ -0,0 +1,196 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ // Copyright (C) 2026 Kindgi Inc.
3
+
4
+ import type { AdapterConfig, ProviderMetadata } from '@kindgi/capabilities';
5
+ import type { Cursor, TenantId } from '@kindgi/types';
6
+
7
+ import type { CapabilityDescriptor } from './capability-binding.js';
8
+
9
+ /**
10
+ * Caller-plugged surface for the model-provider catalog — part of the
11
+ * admin control plane. Full CRUD: tenants register
12
+ * their own providers (hosted model APIs, self-hosted inference servers,
13
+ * embedding backends, sandbox-exec fleets, ...). The runtime's capability
14
+ * router consults the registered set at run time to pick a best-fit
15
+ * provider per capability requirement.
16
+ *
17
+ * `ProviderMetadata` is the **wire shape** — no secrets (API keys,
18
+ * endpoints, credentials) cross the HTTP boundary. Secrets stay inside
19
+ * the binding implementation; the wire surface returns only routing-
20
+ * relevant metadata: provider-level `id` / `region` / `attributes` /
21
+ * `capabilityKind` + `models[]` (each entry carries `name`,
22
+ * `contextWindow`, `features`, `cost`, optional `p95LatencyMs`,
23
+ * `maxOutputTokens`, `description`).
24
+ *
25
+ * Every method is tenant-scoped: callers pass `tenantId` explicitly so
26
+ * multi-tenant deployments can partition storage without exposing that
27
+ * scoping inside the API package.
28
+ *
29
+ * Cursors are opaque — the binding chooses its encoding. The API layer
30
+ * only validates round-trip as a string; it never inspects the payload.
31
+ */
32
+ export interface ProviderRegistryBinding {
33
+ /**
34
+ * Cursor-paginated list of registered providers. Optional
35
+ * `featureFilter` narrows the result to providers that self-report
36
+ * support for the given capability feature — same semantics as the
37
+ * `?feature=` query param on the route.
38
+ */
39
+ list(input: ProviderListInput): Promise<ProviderPage>;
40
+ /**
41
+ * Fetch a provider by id, or `null` when unknown. The route surfaces
42
+ * `null` as `404 provider-not-found`.
43
+ */
44
+ get(input: ProviderGetInput): Promise<ProviderMetadata | null>;
45
+ /**
46
+ * Register a provider under the given tenant. The route validates
47
+ * the wire shape via the `@kindgi/capabilities` runtime rules
48
+ * before calling — the binding receives well-formed metadata.
49
+ * Bindings MAY reject with `already-registered` when the same
50
+ * `providerId` is re-registered; the route maps that to `409`.
51
+ */
52
+ register(input: ProviderRegisterInput): Promise<ProviderRegisterOutcome>;
53
+ /**
54
+ * Remove a specific provider. Returns `{ unregistered: true }` on
55
+ * success; `{ unregistered: false }` when the id was unknown — the
56
+ * route flips the latter to `404`.
57
+ */
58
+ unregister(input: ProviderUnregisterInput): Promise<ProviderUnregisterOutcome>;
59
+ /**
60
+ * Sub-resource: return the catalog capabilities this provider
61
+ * satisfies. Returns `null` when the provider is unknown so the
62
+ * route can flip that to `404 provider-not-found`. An empty array
63
+ * is a valid answer for a known provider with no matches.
64
+ */
65
+ capabilitiesFor(
66
+ input: ProviderCapabilitiesForInput,
67
+ ): Promise<readonly CapabilityDescriptor[] | null>;
68
+ /**
69
+ * Bulk-read for the runtime bridge. Returns every
70
+ * provider registered under `tenantId` bundled with the fields the
71
+ * runtime needs to instantiate a `ModelProvider`: the routing
72
+ * metadata (`metadata`), which adapter package to invoke
73
+ * (`adapterId`), and where to resolve the API key from
74
+ * (`secretRef`, optional).
75
+ *
76
+ * Consumed by the runtime at agent-turn start; separate from `list`
77
+ * because HTTP callers of `list` see only the wire-safe metadata,
78
+ * not the plumbing fields.
79
+ */
80
+ resolveForRuntime(
81
+ input: ProviderResolveForRuntimeInput,
82
+ ): Promise<readonly ProviderRuntimeEntry[]>;
83
+ }
84
+
85
+ export interface ProviderListInput {
86
+ readonly tenantId: TenantId;
87
+ readonly limit: number;
88
+ readonly cursor?: Cursor;
89
+ /**
90
+ * Filter to providers whose `metadata.features` includes this feature
91
+ * name. Exact match, not prefix — `Feature` is a closed enum, so
92
+ * partial matches would over-match noisily.
93
+ */
94
+ readonly featureFilter?: string;
95
+ }
96
+
97
+ export interface ProviderGetInput {
98
+ readonly tenantId: TenantId;
99
+ readonly providerId: string;
100
+ }
101
+
102
+ export interface ProviderRegisterInput {
103
+ readonly tenantId: TenantId;
104
+ readonly metadata: ProviderMetadata;
105
+ /**
106
+ * Identifies which adapter package instantiates the `ModelProvider`
107
+ * at invoke time (runtime bridge). MUST reference an adapter
108
+ * previously registered for this tenant (see `AdapterRegistryBinding`)
109
+ * — implementations reject an unknown adapter at register time
110
+ * rather than at agent-invoke time.
111
+ */
112
+ readonly adapterId: string;
113
+ /**
114
+ * Optional pointer to the tenant-scoped secret carrying the
115
+ * adapter's credential. Shape: `{envName, name}`. The runtime bridge
116
+ * resolves it through the secrets binding for the calling tenant —
117
+ * tenant scoping applies at resolve time, so this ref is
118
+ * tenant-agnostic. Absent when the adapter needs no external
119
+ * credentials (dev-echo, local models).
120
+ */
121
+ readonly secretRef?: ProviderSecretRef;
122
+ /**
123
+ * The adapter's connection settings (a cloud project, a base URL):
124
+ * flat, non-secret values the adapter factory receives as `config`.
125
+ * Like `secretRef`, plumbing — stored with the provider and handed
126
+ * to the runtime, never returned by `list` / `get`.
127
+ */
128
+ readonly adapterConfig?: AdapterConfig;
129
+ }
130
+
131
+ export interface ProviderSecretRef {
132
+ readonly envName: string;
133
+ readonly name: string;
134
+ }
135
+
136
+ /**
137
+ * Runtime-side persistence view bundled for the runtime bridge.
138
+ * `list`/`get` on the binding return the wire-safe `ProviderMetadata`
139
+ * only; this shape adds the plumbing fields (`adapterId`,
140
+ * `secretRef`) the runtime needs to instantiate a `ModelProvider`.
141
+ *
142
+ * Consumed by the runtime at agent-turn start via
143
+ * `resolveForRuntime`.
144
+ */
145
+ export interface ProviderRuntimeEntry {
146
+ readonly metadata: ProviderMetadata;
147
+ readonly adapterId: string;
148
+ readonly secretRef?: ProviderSecretRef;
149
+ readonly adapterConfig?: AdapterConfig;
150
+ }
151
+
152
+ export interface ProviderResolveForRuntimeInput {
153
+ readonly tenantId: TenantId;
154
+ /**
155
+ * Optional capability-kind filter. When present, returns only
156
+ * providers whose declared `capabilityKind` matches — mirrors the
157
+ * router's own kind gate and lets the runtime bridge skip
158
+ * instantiating irrelevant providers.
159
+ */
160
+ readonly capabilityKind?: string;
161
+ }
162
+
163
+ export interface ProviderUnregisterInput {
164
+ readonly tenantId: TenantId;
165
+ readonly providerId: string;
166
+ }
167
+
168
+ export interface ProviderCapabilitiesForInput {
169
+ readonly tenantId: TenantId;
170
+ readonly providerId: string;
171
+ }
172
+
173
+ export interface ProviderPage {
174
+ readonly data: readonly ProviderMetadata[];
175
+ readonly nextCursor?: Cursor;
176
+ }
177
+
178
+ export type ProviderRegisterOutcome =
179
+ | {
180
+ readonly kind: 'ok';
181
+ readonly providerId: string;
182
+ }
183
+ | {
184
+ readonly kind: 'already-registered';
185
+ readonly providerId: string;
186
+ }
187
+ | {
188
+ readonly kind: 'invalid';
189
+ readonly providerId: string;
190
+ readonly message: string;
191
+ readonly reason?: string;
192
+ };
193
+
194
+ export type ProviderUnregisterOutcome = {
195
+ readonly unregistered: boolean;
196
+ };
@@ -0,0 +1,263 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ // Copyright (C) 2026 Kindgi Inc.
3
+
4
+ import { type SigningKeyBinding, signEd25519, verifyEd25519 } from '@kindgi/crypto';
5
+ import type { RunId, SigningKeyId, TenantId } from '@kindgi/types';
6
+
7
+ /**
8
+ * Public run tokens: short-lived, read-only tokens that let a browser
9
+ * follow specific runs (`GET /v1/runs/{runId}/progress` and its event stream) with
10
+ * nothing else allowed. The application's backend obtains one when it
11
+ * starts a run (`POST /v1/runs` returns `publicAccessToken`) or mints one
12
+ * (`POST /v1/tokens/public`), and hands it to the browser.
13
+ *
14
+ * Wire form: `kgi_pt_<base64url payload>.<base64url signature>`.
15
+ * - payload: JSON `{ v: 1, kid, tenantId, runIds, iat, exp }` (seconds);
16
+ * - signature: Ed25519 over the ASCII bytes of `kgi_pt_<base64url payload>`,
17
+ * by the key `kid` in the deployment's `SigningKeyBinding`.
18
+ *
19
+ * Stateless: nothing is stored. A token stops working when it expires;
20
+ * removing its key from the binding revokes every token signed with it.
21
+ */
22
+
23
+ export const PUBLIC_RUN_TOKEN_PREFIX = 'kgi_pt_';
24
+
25
+ /** A token's lifetime when the caller doesn't choose one: 15 minutes. */
26
+ export const DEFAULT_PUBLIC_RUN_TOKEN_TTL_SECONDS = 900;
27
+ /** The longest lifetime a token can have: 24 hours. */
28
+ export const MAX_PUBLIC_RUN_TOKEN_TTL_SECONDS = 86_400;
29
+ /** Runs one token can name. */
30
+ export const MAX_PUBLIC_RUN_TOKEN_RUNS = 50;
31
+
32
+ /** Tolerated clock difference for a token issued "in the future" (seconds). */
33
+ const CLOCK_SKEW_SECONDS = 60;
34
+ const PAYLOAD_VERSION = 1;
35
+
36
+ /** How a deployment issues and checks public run tokens. */
37
+ export interface PublicRunTokenConfig {
38
+ /** Key store holding the Ed25519 signing key(s). */
39
+ readonly signingKey: SigningKeyBinding;
40
+ /**
41
+ * The key new tokens are signed with. Tokens signed with another key in
42
+ * the binding stay valid until they expire, so keys rotate by adding
43
+ * the new key, switching `keyId`, and removing the old key a day later.
44
+ */
45
+ readonly keyId: SigningKeyId;
46
+ /** Default lifetime; {@link DEFAULT_PUBLIC_RUN_TOKEN_TTL_SECONDS} when absent. */
47
+ readonly defaultTtlSeconds?: number;
48
+ /** Longest lifetime a mint may ask for; at most {@link MAX_PUBLIC_RUN_TOKEN_TTL_SECONDS}. */
49
+ readonly maxTtlSeconds?: number;
50
+ /**
51
+ * Browser origins (e.g. `https://app.example.com`) allowed to call the
52
+ * routes a public run token can use, cross-origin. Absent or empty: no
53
+ * CORS headers are sent.
54
+ */
55
+ readonly allowedOrigins?: readonly string[];
56
+ }
57
+
58
+ /** What a verified token grants. */
59
+ export interface PublicRunTokenClaims {
60
+ readonly keyId: SigningKeyId;
61
+ readonly tenantId: TenantId;
62
+ /** The runs the token may read; their descendants are readable too. */
63
+ readonly runIds: readonly RunId[];
64
+ readonly issuedAt: Date;
65
+ readonly expiresAt: Date;
66
+ }
67
+
68
+ export interface MintPublicRunTokenInput {
69
+ readonly signingKey: SigningKeyBinding;
70
+ readonly keyId: SigningKeyId;
71
+ readonly tenantId: TenantId;
72
+ readonly runIds: readonly RunId[];
73
+ readonly ttlSeconds: number;
74
+ /** Clock in milliseconds; default `Date.now`. */
75
+ readonly now?: () => number;
76
+ }
77
+
78
+ export type MintPublicRunTokenResult =
79
+ | { readonly kind: 'ok'; readonly token: string; readonly expiresAt: Date }
80
+ | {
81
+ readonly kind: 'err';
82
+ readonly reason: 'unknown-key' | 'invalid-input';
83
+ readonly message: string;
84
+ };
85
+
86
+ export type VerifyPublicRunTokenFailure = 'malformed' | 'unknown-key' | 'bad-signature' | 'expired';
87
+
88
+ export type VerifyPublicRunTokenResult =
89
+ | { readonly kind: 'ok'; readonly claims: PublicRunTokenClaims }
90
+ | { readonly kind: 'err'; readonly reason: VerifyPublicRunTokenFailure };
91
+
92
+ interface Payload {
93
+ readonly v: number;
94
+ readonly kid: string;
95
+ readonly tenantId: string;
96
+ readonly runIds: readonly string[];
97
+ readonly iat: number;
98
+ readonly exp: number;
99
+ }
100
+
101
+ /** Sign a token for `runIds` in `tenantId`, valid for `ttlSeconds`. */
102
+ export function mintPublicRunToken(input: MintPublicRunTokenInput): MintPublicRunTokenResult {
103
+ if (
104
+ input.runIds.length === 0 ||
105
+ input.runIds.length > MAX_PUBLIC_RUN_TOKEN_RUNS ||
106
+ !Number.isInteger(input.ttlSeconds) ||
107
+ input.ttlSeconds <= 0 ||
108
+ input.ttlSeconds > MAX_PUBLIC_RUN_TOKEN_TTL_SECONDS
109
+ ) {
110
+ return {
111
+ kind: 'err',
112
+ reason: 'invalid-input',
113
+ message: `a token names 1–${MAX_PUBLIC_RUN_TOKEN_RUNS} runs and lives 1–${MAX_PUBLIC_RUN_TOKEN_TTL_SECONDS} seconds`,
114
+ };
115
+ }
116
+ const privateKey = ed25519Key(input.signingKey, input.keyId, 'private');
117
+ if (privateKey === null) {
118
+ return {
119
+ kind: 'err',
120
+ reason: 'unknown-key',
121
+ message: `no Ed25519 signing key "${input.keyId as unknown as string}" in the binding`,
122
+ };
123
+ }
124
+ const iat = Math.floor((input.now ?? Date.now)() / 1000);
125
+ const payload: Payload = {
126
+ v: PAYLOAD_VERSION,
127
+ kid: input.keyId as unknown as string,
128
+ tenantId: input.tenantId as unknown as string,
129
+ runIds: input.runIds.map((id) => id as unknown as string),
130
+ iat,
131
+ exp: iat + input.ttlSeconds,
132
+ };
133
+ const signed = `${PUBLIC_RUN_TOKEN_PREFIX}${Buffer.from(JSON.stringify(payload)).toString('base64url')}`;
134
+ const signature = signEd25519(privateKey, Buffer.from(signed, 'ascii'));
135
+ if (signature.kind === 'err') {
136
+ return { kind: 'err', reason: 'unknown-key', message: signature.error.message };
137
+ }
138
+ return {
139
+ kind: 'ok',
140
+ token: `${signed}.${Buffer.from(signature.value).toString('base64url')}`,
141
+ expiresAt: new Date(payload.exp * 1000),
142
+ };
143
+ }
144
+
145
+ /** Check a token's form, signature and lifetime. Never throws. */
146
+ export function verifyPublicRunToken(
147
+ token: string,
148
+ options: { readonly signingKey: SigningKeyBinding; readonly now?: () => number },
149
+ ): VerifyPublicRunTokenResult {
150
+ if (!token.startsWith(PUBLIC_RUN_TOKEN_PREFIX)) return fail('malformed');
151
+ const dot = token.lastIndexOf('.');
152
+ if (dot <= PUBLIC_RUN_TOKEN_PREFIX.length) return fail('malformed');
153
+ const signed = token.slice(0, dot);
154
+ const payloadPart = signed.slice(PUBLIC_RUN_TOKEN_PREFIX.length);
155
+ const signaturePart = token.slice(dot + 1);
156
+ if (!BASE64URL.test(payloadPart) || !BASE64URL.test(signaturePart)) return fail('malformed');
157
+
158
+ const payload = parsePayload(payloadPart);
159
+ if (payload === null) return fail('malformed');
160
+
161
+ const keyId = payload.kid as SigningKeyId;
162
+ const publicKey = ed25519Key(options.signingKey, keyId, 'public');
163
+ if (publicKey === null) return fail('unknown-key');
164
+ const verified = verifyEd25519(
165
+ publicKey,
166
+ Buffer.from(signed, 'ascii'),
167
+ Buffer.from(signaturePart, 'base64url'),
168
+ );
169
+ if (verified.kind === 'err' || !verified.value) return fail('bad-signature');
170
+
171
+ const now = Math.floor((options.now ?? Date.now)() / 1000);
172
+ if (now >= payload.exp || payload.iat > now + CLOCK_SKEW_SECONDS) return fail('expired');
173
+
174
+ return {
175
+ kind: 'ok',
176
+ claims: {
177
+ keyId,
178
+ tenantId: payload.tenantId as TenantId,
179
+ runIds: payload.runIds as readonly RunId[],
180
+ issuedAt: new Date(payload.iat * 1000),
181
+ expiresAt: new Date(payload.exp * 1000),
182
+ },
183
+ };
184
+ }
185
+
186
+ /**
187
+ * Check a deployment's configuration at startup: the signing key exists
188
+ * and is Ed25519, and the lifetimes are in range. Returns the effective
189
+ * lifetimes; throws on a misconfiguration so the server fails to start.
190
+ */
191
+ export function resolvePublicRunTokenConfig(config: PublicRunTokenConfig): {
192
+ readonly defaultTtlSeconds: number;
193
+ readonly maxTtlSeconds: number;
194
+ } {
195
+ if (ed25519Key(config.signingKey, config.keyId, 'private') === null) {
196
+ throw new Error(
197
+ `publicRunTokens: no Ed25519 key "${config.keyId as unknown as string}" with a private key in signingKey`,
198
+ );
199
+ }
200
+ const maxTtlSeconds = config.maxTtlSeconds ?? MAX_PUBLIC_RUN_TOKEN_TTL_SECONDS;
201
+ const defaultTtlSeconds = config.defaultTtlSeconds ?? DEFAULT_PUBLIC_RUN_TOKEN_TTL_SECONDS;
202
+ if (
203
+ !Number.isInteger(maxTtlSeconds) ||
204
+ maxTtlSeconds <= 0 ||
205
+ maxTtlSeconds > MAX_PUBLIC_RUN_TOKEN_TTL_SECONDS
206
+ ) {
207
+ throw new Error(
208
+ `publicRunTokens.maxTtlSeconds must be an integer in 1–${MAX_PUBLIC_RUN_TOKEN_TTL_SECONDS}`,
209
+ );
210
+ }
211
+ if (
212
+ !Number.isInteger(defaultTtlSeconds) ||
213
+ defaultTtlSeconds <= 0 ||
214
+ defaultTtlSeconds > maxTtlSeconds
215
+ ) {
216
+ throw new Error('publicRunTokens.defaultTtlSeconds must be an integer in 1–maxTtlSeconds');
217
+ }
218
+ return { defaultTtlSeconds, maxTtlSeconds };
219
+ }
220
+
221
+ const BASE64URL = /^[A-Za-z0-9_-]+$/;
222
+
223
+ function fail(reason: VerifyPublicRunTokenFailure): VerifyPublicRunTokenResult {
224
+ return { kind: 'err', reason };
225
+ }
226
+
227
+ /** The key's bytes when the binding holds it as an Ed25519 key; else `null`. */
228
+ function ed25519Key(
229
+ binding: SigningKeyBinding,
230
+ keyId: SigningKeyId,
231
+ side: 'public' | 'private',
232
+ ): Uint8Array | null {
233
+ const descriptor = binding.listKeys().find((key) => key.keyId === keyId);
234
+ if (descriptor === undefined || descriptor.algorithm !== 'ed25519') return null;
235
+ return side === 'public' ? binding.getPublicKey(keyId) : binding.getPrivateKey(keyId);
236
+ }
237
+
238
+ function parsePayload(encoded: string): Payload | null {
239
+ let value: unknown;
240
+ try {
241
+ value = JSON.parse(Buffer.from(encoded, 'base64url').toString('utf-8'));
242
+ } catch {
243
+ return null;
244
+ }
245
+ if (value === null || typeof value !== 'object' || Array.isArray(value)) return null;
246
+ const p = value as Record<string, unknown>;
247
+ const runIds = p.runIds;
248
+ const valid =
249
+ p.v === PAYLOAD_VERSION &&
250
+ typeof p.kid === 'string' &&
251
+ p.kid.length > 0 &&
252
+ typeof p.tenantId === 'string' &&
253
+ p.tenantId.length > 0 &&
254
+ Array.isArray(runIds) &&
255
+ runIds.length > 0 &&
256
+ runIds.length <= MAX_PUBLIC_RUN_TOKEN_RUNS &&
257
+ runIds.every((id) => typeof id === 'string' && id.length > 0) &&
258
+ Number.isInteger(p.iat) &&
259
+ Number.isInteger(p.exp) &&
260
+ (p.exp as number) > (p.iat as number) &&
261
+ (p.exp as number) - (p.iat as number) <= MAX_PUBLIC_RUN_TOKEN_TTL_SECONDS;
262
+ return valid ? (p as unknown as Payload) : null;
263
+ }
@@ -0,0 +1,78 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ // Copyright (C) 2026 Kindgi Inc.
3
+
4
+ import type { RetentionDomain } from '@kindgi/policy-contract';
5
+ import type { TenantId } from '@kindgi/types';
6
+
7
+ /**
8
+ * Caller-plugged surface for the retention pipeline — the API routes
9
+ * (`/v1/retention/scheduled`, `/v1/retention/sweep`,
10
+ * `/v1/retention/sweep/:domain`) call this binding; the Kindgi runtime
11
+ * provides an implementation backed by its retention executor.
12
+ *
13
+ * Wire shape is deliberately kept minimal — the deep types (candidates,
14
+ * per-domain entries, missing-adapter marker) live in the runtime. The
15
+ * api package keeps a leaner projection here so the route body is easy
16
+ * to reason about.
17
+ */
18
+ export interface RetentionBinding {
19
+ /**
20
+ * Enumerate tombstoned rows across every domain with an adapter
21
+ * registered. `pastGraceOnly = false` returns both in-grace and
22
+ * past-grace candidates — the "Scheduled for deletion" view uses
23
+ * that. `true` returns only rows the sweeper would purge right now.
24
+ */
25
+ scheduled(input: RetentionScheduledInput): Promise<RetentionScheduledPage>;
26
+
27
+ /**
28
+ * Trigger a sweep across every domain (or `domain` if provided).
29
+ * Idempotent — a second call after a successful sweep returns
30
+ * `purged: 0` per domain.
31
+ */
32
+ sweep(input: RetentionSweepInput): Promise<RetentionSweepResult>;
33
+ }
34
+
35
+ export interface RetentionScheduledInput {
36
+ readonly tenantId: TenantId;
37
+ readonly domain?: RetentionDomain;
38
+ readonly limit: number;
39
+ readonly pastGraceOnly?: boolean;
40
+ readonly now?: Date;
41
+ }
42
+
43
+ export interface RetentionScheduledItem {
44
+ readonly domain: RetentionDomain;
45
+ readonly id: string;
46
+ readonly unregisteredAt: string;
47
+ readonly purgeAt: string;
48
+ readonly pastGrace: boolean;
49
+ readonly policyId: string;
50
+ readonly policyVersion: string;
51
+ readonly graceSeconds: number;
52
+ }
53
+
54
+ export interface RetentionScheduledPage {
55
+ readonly data: readonly RetentionScheduledItem[];
56
+ /** Domains a retention policy exists for but no adapter is wired in this deployment. */
57
+ readonly domainsMissingAdapter: readonly RetentionDomain[];
58
+ /** Domains that have an adapter but no matching policy — tombstones sit forever. */
59
+ readonly unpolicedDomains: readonly RetentionDomain[];
60
+ }
61
+
62
+ export interface RetentionSweepInput {
63
+ readonly tenantId: TenantId;
64
+ readonly domain?: RetentionDomain;
65
+ readonly maxPerDomain?: number;
66
+ readonly now?: Date;
67
+ }
68
+
69
+ export interface RetentionSweepResult {
70
+ readonly perDomain: readonly {
71
+ readonly domain: RetentionDomain;
72
+ readonly purged: number;
73
+ readonly remaining: number;
74
+ readonly policyId?: string;
75
+ readonly missingAdapter?: true;
76
+ }[];
77
+ readonly totalPurged: number;
78
+ }