@vertesia/common 1.5.0-dev.20260722.120446Z → 1.5.0-dev.20260804.124748Z

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 (522) hide show
  1. package/lib/access-control-values.d.ts +98 -0
  2. package/lib/access-control-values.d.ts.map +1 -0
  3. package/lib/access-control-values.js +101 -0
  4. package/lib/access-control-values.js.map +1 -0
  5. package/lib/access-control.d.ts +22 -119
  6. package/lib/access-control.d.ts.map +1 -1
  7. package/lib/access-control.js +6 -78
  8. package/lib/access-control.js.map +1 -1
  9. package/lib/account-values.d.ts +53 -0
  10. package/lib/account-values.d.ts.map +1 -0
  11. package/lib/account-values.js +91 -0
  12. package/lib/account-values.js.map +1 -0
  13. package/lib/analytics.d.ts +12 -38
  14. package/lib/analytics.d.ts.map +1 -1
  15. package/lib/api-schemas/access-control.d.ts +215 -0
  16. package/lib/api-schemas/access-control.d.ts.map +1 -0
  17. package/lib/api-schemas/access-control.js +165 -0
  18. package/lib/api-schemas/access-control.js.map +1 -0
  19. package/lib/api-schemas/account.d.ts +101 -0
  20. package/lib/api-schemas/account.d.ts.map +1 -0
  21. package/lib/api-schemas/account.js +136 -0
  22. package/lib/api-schemas/account.js.map +1 -0
  23. package/lib/api-schemas/adapter.d.ts +80 -0
  24. package/lib/api-schemas/adapter.d.ts.map +1 -0
  25. package/lib/api-schemas/adapter.js +726 -0
  26. package/lib/api-schemas/adapter.js.map +1 -0
  27. package/lib/api-schemas/agent-runs.d.ts +3781 -0
  28. package/lib/api-schemas/agent-runs.d.ts.map +1 -0
  29. package/lib/api-schemas/agent-runs.js +991 -0
  30. package/lib/api-schemas/agent-runs.js.map +1 -0
  31. package/lib/api-schemas/analytics.d.ts +86 -0
  32. package/lib/api-schemas/analytics.d.ts.map +1 -0
  33. package/lib/api-schemas/analytics.js +58 -0
  34. package/lib/api-schemas/analytics.js.map +1 -0
  35. package/lib/api-schemas/apikey.d.ts +231 -0
  36. package/lib/api-schemas/apikey.d.ts.map +1 -0
  37. package/lib/api-schemas/apikey.js +172 -0
  38. package/lib/api-schemas/apikey.js.map +1 -0
  39. package/lib/api-schemas/app-lifecycle.d.ts +1114 -0
  40. package/lib/api-schemas/app-lifecycle.d.ts.map +1 -0
  41. package/lib/api-schemas/app-lifecycle.js +750 -0
  42. package/lib/api-schemas/app-lifecycle.js.map +1 -0
  43. package/lib/api-schemas/app-runtime.d.ts +9056 -0
  44. package/lib/api-schemas/app-runtime.d.ts.map +1 -0
  45. package/lib/api-schemas/app-runtime.js +782 -0
  46. package/lib/api-schemas/app-runtime.js.map +1 -0
  47. package/lib/api-schemas/apps.d.ts +247 -0
  48. package/lib/api-schemas/apps.d.ts.map +1 -0
  49. package/lib/api-schemas/apps.js +366 -0
  50. package/lib/api-schemas/apps.js.map +1 -0
  51. package/lib/api-schemas/audit-trail.d.ts +465 -0
  52. package/lib/api-schemas/audit-trail.d.ts.map +1 -0
  53. package/lib/api-schemas/audit-trail.js +218 -0
  54. package/lib/api-schemas/audit-trail.js.map +1 -0
  55. package/lib/api-schemas/bulk-operation.d.ts +104 -0
  56. package/lib/api-schemas/bulk-operation.d.ts.map +1 -0
  57. package/lib/api-schemas/bulk-operation.js +66 -0
  58. package/lib/api-schemas/bulk-operation.js.map +1 -0
  59. package/lib/api-schemas/commands.d.ts +50 -0
  60. package/lib/api-schemas/commands.d.ts.map +1 -0
  61. package/lib/api-schemas/commands.js +58 -0
  62. package/lib/api-schemas/commands.js.map +1 -0
  63. package/lib/api-schemas/content.d.ts +3561 -0
  64. package/lib/api-schemas/content.d.ts.map +1 -0
  65. package/lib/api-schemas/content.js +842 -0
  66. package/lib/api-schemas/content.js.map +1 -0
  67. package/lib/api-schemas/cost-analytics.d.ts +300 -0
  68. package/lib/api-schemas/cost-analytics.d.ts.map +1 -0
  69. package/lib/api-schemas/cost-analytics.js +218 -0
  70. package/lib/api-schemas/cost-analytics.js.map +1 -0
  71. package/lib/api-schemas/dashboard.d.ts +408 -0
  72. package/lib/api-schemas/dashboard.d.ts.map +1 -0
  73. package/lib/api-schemas/dashboard.js +311 -0
  74. package/lib/api-schemas/dashboard.js.map +1 -0
  75. package/lib/api-schemas/data-store.d.ts +1650 -0
  76. package/lib/api-schemas/data-store.d.ts.map +1 -0
  77. package/lib/api-schemas/data-store.js +504 -0
  78. package/lib/api-schemas/data-store.js.map +1 -0
  79. package/lib/api-schemas/document-processing.d.ts +1501 -0
  80. package/lib/api-schemas/document-processing.d.ts.map +1 -0
  81. package/lib/api-schemas/document-processing.js +312 -0
  82. package/lib/api-schemas/document-processing.js.map +1 -0
  83. package/lib/api-schemas/embeddings.d.ts +184 -0
  84. package/lib/api-schemas/embeddings.d.ts.map +1 -0
  85. package/lib/api-schemas/embeddings.js +102 -0
  86. package/lib/api-schemas/embeddings.js.map +1 -0
  87. package/lib/api-schemas/environment.d.ts +412 -0
  88. package/lib/api-schemas/environment.d.ts.map +1 -0
  89. package/lib/api-schemas/environment.js +170 -0
  90. package/lib/api-schemas/environment.js.map +1 -0
  91. package/lib/api-schemas/events.d.ts +4880 -0
  92. package/lib/api-schemas/events.d.ts.map +1 -0
  93. package/lib/api-schemas/events.js +832 -0
  94. package/lib/api-schemas/events.js.map +1 -0
  95. package/lib/api-schemas/files.d.ts +107 -0
  96. package/lib/api-schemas/files.d.ts.map +1 -0
  97. package/lib/api-schemas/files.js +137 -0
  98. package/lib/api-schemas/files.js.map +1 -0
  99. package/lib/api-schemas/group.d.ts +122 -0
  100. package/lib/api-schemas/group.d.ts.map +1 -0
  101. package/lib/api-schemas/group.js +142 -0
  102. package/lib/api-schemas/group.js.map +1 -0
  103. package/lib/api-schemas/index.d.ts +36 -0
  104. package/lib/api-schemas/index.d.ts.map +1 -0
  105. package/lib/api-schemas/index.js +36 -0
  106. package/lib/api-schemas/index.js.map +1 -0
  107. package/lib/api-schemas/indexing.d.ts +144 -0
  108. package/lib/api-schemas/indexing.d.ts.map +1 -0
  109. package/lib/api-schemas/indexing.js +217 -0
  110. package/lib/api-schemas/indexing.js.map +1 -0
  111. package/lib/api-schemas/integrations.d.ts +269 -0
  112. package/lib/api-schemas/integrations.d.ts.map +1 -0
  113. package/lib/api-schemas/integrations.js +335 -0
  114. package/lib/api-schemas/integrations.js.map +1 -0
  115. package/lib/api-schemas/interaction.d.ts +22454 -0
  116. package/lib/api-schemas/interaction.d.ts.map +1 -0
  117. package/lib/api-schemas/interaction.js +2065 -0
  118. package/lib/api-schemas/interaction.js.map +1 -0
  119. package/lib/api-schemas/invites.d.ts +162 -0
  120. package/lib/api-schemas/invites.d.ts.map +1 -0
  121. package/lib/api-schemas/invites.js +106 -0
  122. package/lib/api-schemas/invites.js.map +1 -0
  123. package/lib/api-schemas/oauth-server.d.ts +415 -0
  124. package/lib/api-schemas/oauth-server.d.ts.map +1 -0
  125. package/lib/api-schemas/oauth-server.js +193 -0
  126. package/lib/api-schemas/oauth-server.js.map +1 -0
  127. package/lib/api-schemas/oauth.d.ts +150 -0
  128. package/lib/api-schemas/oauth.d.ts.map +1 -0
  129. package/lib/api-schemas/oauth.js +148 -0
  130. package/lib/api-schemas/oauth.js.map +1 -0
  131. package/lib/api-schemas/parameters.d.ts +64 -0
  132. package/lib/api-schemas/parameters.d.ts.map +1 -0
  133. package/lib/api-schemas/parameters.js +246 -0
  134. package/lib/api-schemas/parameters.js.map +1 -0
  135. package/lib/api-schemas/process.d.ts +499 -0
  136. package/lib/api-schemas/process.d.ts.map +1 -0
  137. package/lib/api-schemas/process.js +817 -0
  138. package/lib/api-schemas/process.js.map +1 -0
  139. package/lib/api-schemas/project-configuration.d.ts +4900 -0
  140. package/lib/api-schemas/project-configuration.d.ts.map +1 -0
  141. package/lib/api-schemas/project-configuration.js +425 -0
  142. package/lib/api-schemas/project-configuration.js.map +1 -0
  143. package/lib/api-schemas/project.d.ts +7247 -0
  144. package/lib/api-schemas/project.d.ts.map +1 -0
  145. package/lib/api-schemas/project.js +185 -0
  146. package/lib/api-schemas/project.js.map +1 -0
  147. package/lib/api-schemas/prompt.d.ts +70 -0
  148. package/lib/api-schemas/prompt.d.ts.map +1 -0
  149. package/lib/api-schemas/prompt.js +77 -0
  150. package/lib/api-schemas/prompt.js.map +1 -0
  151. package/lib/api-schemas/quota.d.ts +90 -0
  152. package/lib/api-schemas/quota.d.ts.map +1 -0
  153. package/lib/api-schemas/quota.js +95 -0
  154. package/lib/api-schemas/quota.js.map +1 -0
  155. package/lib/api-schemas/registry.d.ts +97458 -0
  156. package/lib/api-schemas/registry.d.ts.map +1 -0
  157. package/lib/api-schemas/registry.js +2586 -0
  158. package/lib/api-schemas/registry.js.map +1 -0
  159. package/lib/api-schemas/schema-primitives.d.ts +5 -0
  160. package/lib/api-schemas/schema-primitives.d.ts.map +1 -0
  161. package/lib/api-schemas/schema-primitives.js +11 -0
  162. package/lib/api-schemas/schema-primitives.js.map +1 -0
  163. package/lib/api-schemas/secrets.d.ts +497 -0
  164. package/lib/api-schemas/secrets.d.ts.map +1 -0
  165. package/lib/api-schemas/secrets.js +298 -0
  166. package/lib/api-schemas/secrets.js.map +1 -0
  167. package/lib/api-schemas/store.d.ts +22140 -0
  168. package/lib/api-schemas/store.d.ts.map +1 -0
  169. package/lib/api-schemas/store.js +557 -0
  170. package/lib/api-schemas/store.js.map +1 -0
  171. package/lib/api-schemas/sts.d.ts +156 -0
  172. package/lib/api-schemas/sts.d.ts.map +1 -0
  173. package/lib/api-schemas/sts.js +96 -0
  174. package/lib/api-schemas/sts.js.map +1 -0
  175. package/lib/api-schemas/task.d.ts +215 -0
  176. package/lib/api-schemas/task.d.ts.map +1 -0
  177. package/lib/api-schemas/task.js +95 -0
  178. package/lib/api-schemas/task.js.map +1 -0
  179. package/lib/api-schemas/tools.d.ts +111 -0
  180. package/lib/api-schemas/tools.d.ts.map +1 -0
  181. package/lib/api-schemas/tools.js +122 -0
  182. package/lib/api-schemas/tools.js.map +1 -0
  183. package/lib/api-schemas/user.d.ts +208 -0
  184. package/lib/api-schemas/user.d.ts.map +1 -0
  185. package/lib/api-schemas/user.js +180 -0
  186. package/lib/api-schemas/user.js.map +1 -0
  187. package/lib/api-schemas/view-execution.d.ts +3163 -0
  188. package/lib/api-schemas/view-execution.d.ts.map +1 -0
  189. package/lib/api-schemas/view-execution.js +172 -0
  190. package/lib/api-schemas/view-execution.js.map +1 -0
  191. package/lib/api-schemas/views.d.ts +5990 -0
  192. package/lib/api-schemas/views.d.ts.map +1 -0
  193. package/lib/api-schemas/views.js +396 -0
  194. package/lib/api-schemas/views.js.map +1 -0
  195. package/lib/api-schemas/workflow-runs.d.ts +2209 -0
  196. package/lib/api-schemas/workflow-runs.d.ts.map +1 -0
  197. package/lib/api-schemas/workflow-runs.js +589 -0
  198. package/lib/api-schemas/workflow-runs.js.map +1 -0
  199. package/lib/apikey-values.d.ts +10 -0
  200. package/lib/apikey-values.d.ts.map +1 -0
  201. package/lib/apikey-values.js +11 -0
  202. package/lib/apikey-values.js.map +1 -0
  203. package/lib/apikey.d.ts +37 -36
  204. package/lib/apikey.d.ts.map +1 -1
  205. package/lib/apikey.js +5 -4
  206. package/lib/apikey.js.map +1 -1
  207. package/lib/apps.d.ts +116 -1121
  208. package/lib/apps.d.ts.map +1 -1
  209. package/lib/apps.js.map +1 -1
  210. package/lib/ask-user.d.ts +8 -1
  211. package/lib/ask-user.d.ts.map +1 -1
  212. package/lib/audit-trail.d.ts +17 -128
  213. package/lib/audit-trail.d.ts.map +1 -1
  214. package/lib/audit-trail.js.map +1 -1
  215. package/lib/browser-credentials.d.ts +11 -106
  216. package/lib/browser-credentials.d.ts.map +1 -1
  217. package/lib/common.d.ts +59 -81
  218. package/lib/common.d.ts.map +1 -1
  219. package/lib/cost-analytics.d.ts +14 -167
  220. package/lib/cost-analytics.d.ts.map +1 -1
  221. package/lib/cost-analytics.js.map +1 -1
  222. package/lib/data-platform.d.ts +122 -786
  223. package/lib/data-platform.d.ts.map +1 -1
  224. package/lib/data-platform.js +41 -61
  225. package/lib/data-platform.js.map +1 -1
  226. package/lib/email.d.ts +5 -17
  227. package/lib/email.d.ts.map +1 -1
  228. package/lib/email.js +0 -3
  229. package/lib/email.js.map +1 -1
  230. package/lib/embeddings.d.ts +14 -56
  231. package/lib/embeddings.d.ts.map +1 -1
  232. package/lib/environment.d.ts +19 -113
  233. package/lib/environment.d.ts.map +1 -1
  234. package/lib/environment.js +3 -0
  235. package/lib/environment.js.map +1 -1
  236. package/lib/facets.d.ts +4 -7
  237. package/lib/facets.d.ts.map +1 -1
  238. package/lib/group.d.ts +33 -39
  239. package/lib/group.d.ts.map +1 -1
  240. package/lib/group.js +0 -1
  241. package/lib/group.js.map +1 -1
  242. package/lib/index.d.ts +7 -0
  243. package/lib/index.d.ts.map +1 -1
  244. package/lib/index.js.map +1 -1
  245. package/lib/integrations.d.ts +20 -108
  246. package/lib/integrations.d.ts.map +1 -1
  247. package/lib/integrations.js.map +1 -1
  248. package/lib/interaction-values.d.ts +11 -0
  249. package/lib/interaction-values.d.ts.map +1 -0
  250. package/lib/interaction-values.js +24 -0
  251. package/lib/interaction-values.js.map +1 -0
  252. package/lib/interaction.d.ts +116 -734
  253. package/lib/interaction.d.ts.map +1 -1
  254. package/lib/interaction.js +56 -12
  255. package/lib/interaction.js.map +1 -1
  256. package/lib/meters.d.ts +11 -7
  257. package/lib/meters.d.ts.map +1 -1
  258. package/lib/meters.js.map +1 -1
  259. package/lib/oauth-server.d.ts +33 -119
  260. package/lib/oauth-server.d.ts.map +1 -1
  261. package/lib/oauth.d.ts +14 -96
  262. package/lib/oauth.d.ts.map +1 -1
  263. package/lib/oauth.js +0 -4
  264. package/lib/oauth.js.map +1 -1
  265. package/lib/payload.d.ts +15 -38
  266. package/lib/payload.d.ts.map +1 -1
  267. package/lib/platform-event.d.ts +49 -462
  268. package/lib/platform-event.d.ts.map +1 -1
  269. package/lib/platform-event.js.map +1 -1
  270. package/lib/principal-context.d.ts +10 -15
  271. package/lib/principal-context.d.ts.map +1 -1
  272. package/lib/project-values.d.ts +24 -0
  273. package/lib/project-values.d.ts.map +1 -0
  274. package/lib/project-values.js +42 -0
  275. package/lib/project-values.js.map +1 -0
  276. package/lib/project.d.ts +55 -503
  277. package/lib/project.d.ts.map +1 -1
  278. package/lib/project.js +6 -76
  279. package/lib/project.js.map +1 -1
  280. package/lib/prompt.d.ts +20 -51
  281. package/lib/prompt.d.ts.map +1 -1
  282. package/lib/prompt.js.map +1 -1
  283. package/lib/query.d.ts +27 -88
  284. package/lib/query.d.ts.map +1 -1
  285. package/lib/rate-limiter.d.ts +19 -70
  286. package/lib/rate-limiter.d.ts.map +1 -1
  287. package/lib/rate-limiter.js +0 -3
  288. package/lib/rate-limiter.js.map +1 -1
  289. package/lib/refs.d.ts +3 -11
  290. package/lib/refs.d.ts.map +1 -1
  291. package/lib/refs.js.map +1 -1
  292. package/lib/roles/types.d.ts +14 -20
  293. package/lib/roles/types.d.ts.map +1 -1
  294. package/lib/roles/types.js +5 -9
  295. package/lib/roles/types.js.map +1 -1
  296. package/lib/runs.d.ts +6 -25
  297. package/lib/runs.d.ts.map +1 -1
  298. package/lib/secrets.d.ts +20 -105
  299. package/lib/secrets.d.ts.map +1 -1
  300. package/lib/store/agent-approval.d.ts +5 -14
  301. package/lib/store/agent-approval.d.ts.map +1 -1
  302. package/lib/store/agent-approval.js.map +1 -1
  303. package/lib/store/agent-run.d.ts +63 -342
  304. package/lib/store/agent-run.d.ts.map +1 -1
  305. package/lib/store/collections.d.ts +11 -63
  306. package/lib/store/collections.d.ts.map +1 -1
  307. package/lib/store/collections.js.map +1 -1
  308. package/lib/store/conversation-state.d.ts +63 -61
  309. package/lib/store/conversation-state.d.ts.map +1 -1
  310. package/lib/store/conversation-state.js +2 -0
  311. package/lib/store/conversation-state.js.map +1 -1
  312. package/lib/store/doc-analyzer.d.ts +9 -32
  313. package/lib/store/doc-analyzer.d.ts.map +1 -1
  314. package/lib/store/dsl-workflow.d.ts +37 -151
  315. package/lib/store/dsl-workflow.d.ts.map +1 -1
  316. package/lib/store/dsl-workflow.js.map +1 -1
  317. package/lib/store/editing-policy-schema.generated.d.ts +3 -0
  318. package/lib/store/editing-policy-schema.generated.d.ts.map +1 -0
  319. package/lib/store/editing-policy-schema.generated.js +28 -0
  320. package/lib/store/editing-policy-schema.generated.js.map +1 -0
  321. package/lib/store/grounded-extraction.d.ts +7 -104
  322. package/lib/store/grounded-extraction.d.ts.map +1 -1
  323. package/lib/store/grounded-extraction.js.map +1 -1
  324. package/lib/store/index.d.ts +2 -0
  325. package/lib/store/index.d.ts.map +1 -1
  326. package/lib/store/index.js +3 -0
  327. package/lib/store/index.js.map +1 -1
  328. package/lib/store/intake-policy-schema.generated.d.ts +3 -0
  329. package/lib/store/intake-policy-schema.generated.d.ts.map +1 -0
  330. package/lib/store/intake-policy-schema.generated.js +1425 -0
  331. package/lib/store/intake-policy-schema.generated.js.map +1 -0
  332. package/lib/store/process-schema.d.ts +80 -0
  333. package/lib/store/process-schema.d.ts.map +1 -1
  334. package/lib/store/process-schema.js +79 -0
  335. package/lib/store/process-schema.js.map +1 -1
  336. package/lib/store/process-validation.d.ts.map +1 -1
  337. package/lib/store/process-validation.js +70 -2
  338. package/lib/store/process-validation.js.map +1 -1
  339. package/lib/store/process.d.ts +36 -125
  340. package/lib/store/process.d.ts.map +1 -1
  341. package/lib/store/process.js.map +1 -1
  342. package/lib/store/rendering.d.ts +9 -64
  343. package/lib/store/rendering.d.ts.map +1 -1
  344. package/lib/store/rendering.js.map +1 -1
  345. package/lib/store/store.d.ts +98 -693
  346. package/lib/store/store.d.ts.map +1 -1
  347. package/lib/store/store.js +4 -443
  348. package/lib/store/store.js.map +1 -1
  349. package/lib/store/task.d.ts +15 -59
  350. package/lib/store/task.d.ts.map +1 -1
  351. package/lib/store/task.js +0 -3
  352. package/lib/store/task.js.map +1 -1
  353. package/lib/store/workflow.d.ts +56 -516
  354. package/lib/store/workflow.d.ts.map +1 -1
  355. package/lib/store/workflow.js +28 -11
  356. package/lib/store/workflow.js.map +1 -1
  357. package/lib/sts-token-types.d.ts +12 -66
  358. package/lib/sts-token-types.d.ts.map +1 -1
  359. package/lib/sts-token-types.js.map +1 -1
  360. package/lib/tools.d.ts +8 -100
  361. package/lib/tools.d.ts.map +1 -1
  362. package/lib/transient-tokens-values.d.ts +11 -0
  363. package/lib/transient-tokens-values.d.ts.map +1 -0
  364. package/lib/transient-tokens-values.js +12 -0
  365. package/lib/transient-tokens-values.js.map +1 -0
  366. package/lib/transient-tokens.d.ts +15 -13
  367. package/lib/transient-tokens.d.ts.map +1 -1
  368. package/lib/transient-tokens.js +5 -5
  369. package/lib/transient-tokens.js.map +1 -1
  370. package/lib/user.d.ts +54 -155
  371. package/lib/user.d.ts.map +1 -1
  372. package/lib/user.js +1 -78
  373. package/lib/user.js.map +1 -1
  374. package/lib/versions.d.ts +24 -1
  375. package/lib/versions.d.ts.map +1 -1
  376. package/lib/versions.js +23 -0
  377. package/lib/versions.js.map +1 -1
  378. package/lib/vertesia-common.js +6 -2
  379. package/lib/vertesia-common.js.map +1 -1
  380. package/lib/views-schema.d.ts +4 -4
  381. package/lib/views.d.ts +56 -312
  382. package/lib/views.d.ts.map +1 -1
  383. package/lib/views.js.map +1 -1
  384. package/package.json +14 -5
  385. package/src/access-control-values.ts +113 -0
  386. package/src/access-control.ts +33 -138
  387. package/src/account-values.ts +95 -0
  388. package/src/agent-resources.test.ts +100 -0
  389. package/src/analytics.ts +18 -42
  390. package/src/api-schemas/access-control.contract.test.ts +209 -0
  391. package/src/api-schemas/access-control.ts +208 -0
  392. package/src/api-schemas/account.contract.test.ts +318 -0
  393. package/src/api-schemas/account.ts +150 -0
  394. package/src/api-schemas/adapter-edge-cases.test.ts +480 -0
  395. package/src/api-schemas/adapter.ts +778 -0
  396. package/src/api-schemas/agent-runs.ts +1081 -0
  397. package/src/api-schemas/analytics.ts +65 -0
  398. package/src/api-schemas/apikey.contract.test.ts +270 -0
  399. package/src/api-schemas/apikey.ts +199 -0
  400. package/src/api-schemas/app-lifecycle.ts +841 -0
  401. package/src/api-schemas/app-runtime.ts +919 -0
  402. package/src/api-schemas/apps.ts +415 -0
  403. package/src/api-schemas/audit-trail.ts +243 -0
  404. package/src/api-schemas/bulk-operation.contract.test.ts +39 -0
  405. package/src/api-schemas/bulk-operation.ts +75 -0
  406. package/src/api-schemas/bundle-isolation.test.ts +80 -0
  407. package/src/api-schemas/commands.contract.test.ts +51 -0
  408. package/src/api-schemas/commands.ts +62 -0
  409. package/src/api-schemas/content.ts +939 -0
  410. package/src/api-schemas/cost-analytics.contract.test.ts +64 -0
  411. package/src/api-schemas/cost-analytics.ts +235 -0
  412. package/src/api-schemas/dashboard.contract.test.ts +127 -0
  413. package/src/api-schemas/dashboard.ts +351 -0
  414. package/src/api-schemas/data-store.contract.test.ts +91 -0
  415. package/src/api-schemas/data-store.ts +571 -0
  416. package/src/api-schemas/document-processing.contract.test.ts +76 -0
  417. package/src/api-schemas/document-processing.ts +344 -0
  418. package/src/api-schemas/embeddings.ts +113 -0
  419. package/src/api-schemas/environment.contract.test.ts +184 -0
  420. package/src/api-schemas/environment.ts +190 -0
  421. package/src/api-schemas/events.ts +921 -0
  422. package/src/api-schemas/files.ts +159 -0
  423. package/src/api-schemas/group.contract.test.ts +205 -0
  424. package/src/api-schemas/group.ts +155 -0
  425. package/src/api-schemas/index.ts +35 -0
  426. package/src/api-schemas/indexing.contract.test.ts +83 -0
  427. package/src/api-schemas/indexing.ts +234 -0
  428. package/src/api-schemas/integrations.ts +369 -0
  429. package/src/api-schemas/interaction.ts +2357 -0
  430. package/src/api-schemas/invites.contract.test.ts +268 -0
  431. package/src/api-schemas/invites.ts +127 -0
  432. package/src/api-schemas/llumiverse.contract.test.ts +108 -0
  433. package/src/api-schemas/oauth-server.ts +219 -0
  434. package/src/api-schemas/oauth.contract.test.ts +118 -0
  435. package/src/api-schemas/oauth.ts +166 -0
  436. package/src/api-schemas/parameters.test.ts +402 -0
  437. package/src/api-schemas/parameters.ts +310 -0
  438. package/src/api-schemas/process.ts +929 -0
  439. package/src/api-schemas/project-configuration.ts +478 -0
  440. package/src/api-schemas/project.contract.test.ts +365 -0
  441. package/src/api-schemas/project.ts +214 -0
  442. package/src/api-schemas/prompt.ts +88 -0
  443. package/src/api-schemas/pruning-limits.test.ts +189 -0
  444. package/src/api-schemas/quota.contract.test.ts +147 -0
  445. package/src/api-schemas/quota.ts +122 -0
  446. package/src/api-schemas/registry-groups.test.ts +91 -0
  447. package/src/api-schemas/registry.ts +3487 -0
  448. package/src/api-schemas/response-pruning.test.ts +260 -0
  449. package/src/api-schemas/schema-primitives.ts +12 -0
  450. package/src/api-schemas/secrets.ts +332 -0
  451. package/src/api-schemas/store.contract.test.ts +450 -0
  452. package/src/api-schemas/store.ts +604 -0
  453. package/src/api-schemas/sts.contract.test.ts +80 -0
  454. package/src/api-schemas/sts.ts +110 -0
  455. package/src/api-schemas/task.ts +104 -0
  456. package/src/api-schemas/tools.ts +140 -0
  457. package/src/api-schemas/user.contract.test.ts +191 -0
  458. package/src/api-schemas/user.ts +204 -0
  459. package/src/api-schemas/view-execution.ts +200 -0
  460. package/src/api-schemas/views.ts +437 -0
  461. package/src/api-schemas/workflow-runs.ts +653 -0
  462. package/src/apikey-values.ts +10 -0
  463. package/src/apikey.ts +49 -40
  464. package/src/apps.ts +249 -1179
  465. package/src/ask-user.ts +9 -1
  466. package/src/audit-trail.ts +45 -137
  467. package/src/browser-credentials.ts +21 -106
  468. package/src/common.ts +67 -78
  469. package/src/cost-analytics.ts +37 -176
  470. package/src/data-platform.ts +205 -776
  471. package/src/email.ts +5 -17
  472. package/src/embeddings.ts +22 -60
  473. package/src/environment.ts +52 -124
  474. package/src/facets.ts +4 -7
  475. package/src/group.ts +38 -42
  476. package/src/index.ts +11 -0
  477. package/src/integrations.ts +39 -129
  478. package/src/interaction-values.ts +23 -0
  479. package/src/interaction.ts +231 -841
  480. package/src/meters.ts +11 -7
  481. package/src/oauth-server.ts +58 -127
  482. package/src/oauth.ts +24 -108
  483. package/src/payload.ts +25 -40
  484. package/src/platform-event.ts +98 -484
  485. package/src/principal-context.ts +11 -15
  486. package/src/project-values.ts +41 -0
  487. package/src/project.ts +116 -588
  488. package/src/prompt.ts +34 -61
  489. package/src/query.ts +34 -93
  490. package/src/rate-limiter.ts +27 -75
  491. package/src/refs.ts +4 -11
  492. package/src/roles/types.ts +20 -20
  493. package/src/runs.ts +11 -24
  494. package/src/secrets.ts +38 -117
  495. package/src/store/agent-approval.ts +9 -14
  496. package/src/store/agent-run.ts +106 -434
  497. package/src/store/collections.ts +21 -63
  498. package/src/store/content-type-editing.test.ts +17 -0
  499. package/src/store/conversation-state.ts +78 -64
  500. package/src/store/doc-analyzer.ts +17 -33
  501. package/src/store/dsl-workflow.ts +62 -158
  502. package/src/store/editing-policy-schema.generated.ts +30 -0
  503. package/src/store/grounded-extraction.ts +13 -104
  504. package/src/store/index.ts +3 -0
  505. package/src/store/intake-policy-schema.generated.ts +1442 -0
  506. package/src/store/process-schema.test.ts +43 -0
  507. package/src/store/process-schema.ts +79 -0
  508. package/src/store/process-validation.test.ts +141 -0
  509. package/src/store/process-validation.ts +82 -2
  510. package/src/store/process.ts +70 -146
  511. package/src/store/rendering.ts +15 -64
  512. package/src/store/store.ts +197 -1182
  513. package/src/store/task.ts +25 -59
  514. package/src/store/workflow.ts +103 -554
  515. package/src/sts-token-types.ts +24 -75
  516. package/src/tools.ts +18 -97
  517. package/src/transient-tokens-values.ts +11 -0
  518. package/src/transient-tokens.ts +16 -13
  519. package/src/user.ts +74 -214
  520. package/src/versions.ts +24 -0
  521. package/src/views-schema.test.ts +9 -1
  522. package/src/views.ts +106 -329
@@ -0,0 +1,778 @@
1
+ /**
2
+ * Library-neutral JSON Schema -> OpenAPI 3.1 `components.schemas` adapter.
3
+ *
4
+ * Input is plain JSON Schema, so this works for any authoring library. It normalizes the three
5
+ * ways a schema library expresses a named reference into the one form OpenAPI needs:
6
+ *
7
+ * - zod `$defs` + `{"$ref": "#/$defs/X"}` (and `{"$ref": "#"}` for self-recursion)
8
+ * - typebox a nested subschema carrying `$id` (hoisted here, per the same contract)
9
+ * - either a bare `{"$ref": "X"}` id pointer
10
+ *
11
+ * All three become `{"$ref": "#/components/schemas/X"}` with the target hoisted into components,
12
+ * so the pointer that is published is byte-identical to the pointer AJV compiles. That identity
13
+ * is the whole point: the spec cannot drift from the enforced contract because they are the same
14
+ * object.
15
+ *
16
+ * The input is never mutated.
17
+ */
18
+
19
+ export type JsonObject = Record<string, unknown>;
20
+
21
+ /** How a component treats properties it does not declare. */
22
+ export type AdditionalPropertiesPolicy = 'open' | 'closed';
23
+
24
+ export interface AdapterOptions {
25
+ /**
26
+ * Components that reject undeclared properties. Everything else is left open — omitting the
27
+ * keyword entirely, so extras are accepted and RETAINED. Existing endpoints must stay open:
28
+ * they currently cast the payload without validating, so rejecting extras would be a breaking
29
+ * API change. Only new endpoints should opt in to 'closed'.
30
+ */
31
+ strictComponents?: ReadonlySet<string>;
32
+ /**
33
+ * Already-published components that roots may reference without redefining. They participate in
34
+ * reference resolution and discriminator synthesis, but are not copied into the returned map or
35
+ * subjected to this adaptation pass.
36
+ */
37
+ referenceComponents?: Readonly<Record<string, JsonObject>>;
38
+ }
39
+
40
+ export class SchemaAdapterError extends Error {}
41
+
42
+ const REF = '$ref';
43
+ const COMPONENT_PREFIX = '#/components/schemas/';
44
+
45
+ function isPlainObject(value: unknown): value is JsonObject {
46
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
47
+ }
48
+
49
+ /** Resolve any of the supported reference spellings to a component name. */
50
+ function refTargetName(ref: string, rootName: string): string {
51
+ if (ref === '#') return rootName;
52
+ if (ref.startsWith('#/$defs/')) return ref.slice('#/$defs/'.length);
53
+ if (ref.startsWith('#/definitions/')) return ref.slice('#/definitions/'.length);
54
+ if (ref.startsWith(COMPONENT_PREFIX)) return ref.slice(COMPONENT_PREFIX.length);
55
+ if (ref.startsWith('#')) {
56
+ throw new SchemaAdapterError(
57
+ `Unsupported internal pointer '${ref}' in component '${rootName}'. Only '#', '#/$defs/*' ` +
58
+ `and '#/components/schemas/*' can be hoisted to OpenAPI components.`,
59
+ );
60
+ }
61
+ return ref;
62
+ }
63
+
64
+ function componentRef(name: string): JsonObject {
65
+ return { [REF]: `${COMPONENT_PREFIX}${name}` };
66
+ }
67
+
68
+ /**
69
+ * Adds `discriminator` to a union whose members are all component references and which share a
70
+ * required single-valued property. Generated Java/Go clients need this to pick a concrete
71
+ * subtype; without it they fall back to a loose map or fail to deserialize.
72
+ *
73
+ * The property must be REQUIRED in every branch — OpenAPI treats a discriminator as always
74
+ * present, so promoting an optional property would publish a contract the schema does not
75
+ * guarantee.
76
+ */
77
+ function synthesizeDiscriminator(node: JsonObject, ctx: HoistContext): void {
78
+ const members = node.oneOf ?? node.anyOf;
79
+ if (!Array.isArray(members) || members.length < 2 || node.discriminator) return;
80
+
81
+ const targets: { name: string; schema: JsonObject }[] = [];
82
+ for (const member of members) {
83
+ if (!isPlainObject(member) || typeof member[REF] !== 'string') return;
84
+ const name = (member[REF] as string).slice(COMPONENT_PREFIX.length);
85
+ // Hoisted components shadow the already-published ones, which is what a root redefining a
86
+ // reference component means. Looked up rather than merged into one map: this runs for every
87
+ // union node, and building a 1000-entry object per node was most of the adaptation's cost.
88
+ const schema = ctx.components[name] ?? ctx.referenceComponents[name];
89
+ if (!schema) return;
90
+ targets.push({ name, schema });
91
+ }
92
+
93
+ const candidates = new Map<string, Record<string, string>>();
94
+ const disqualified = new Set<string>();
95
+ for (const { name, schema } of targets) {
96
+ const properties = isPlainObject(schema.properties) ? schema.properties : undefined;
97
+ if (!properties) return;
98
+ const required = Array.isArray(schema.required) ? schema.required : [];
99
+ for (const [key, value] of Object.entries(properties)) {
100
+ if (!isPlainObject(value)) continue;
101
+ if (!required.includes(key)) {
102
+ disqualified.add(key);
103
+ continue;
104
+ }
105
+ const literal =
106
+ typeof value.const === 'string'
107
+ ? value.const
108
+ : Array.isArray(value.enum) && value.enum.length === 1 && typeof value.enum[0] === 'string'
109
+ ? value.enum[0]
110
+ : undefined;
111
+ if (literal === undefined) continue;
112
+ const mapping = candidates.get(key) ?? {};
113
+ // Two members claiming the same literal means it does not discriminate.
114
+ if (mapping[literal]) {
115
+ disqualified.add(key);
116
+ continue;
117
+ }
118
+ mapping[literal] = `${COMPONENT_PREFIX}${name}`;
119
+ candidates.set(key, mapping);
120
+ }
121
+ }
122
+
123
+ for (const [propertyName, mapping] of candidates) {
124
+ if (disqualified.has(propertyName)) continue;
125
+ if (Object.keys(mapping).length !== targets.length) continue;
126
+ node.discriminator = { propertyName, mapping };
127
+ // OpenAPI requires oneOf for a discriminated union; anyOf is not enough for codegen.
128
+ if (node.anyOf && !node.oneOf) {
129
+ node.oneOf = node.anyOf;
130
+ delete node.anyOf;
131
+ }
132
+ // Restated on the union itself, matching what the OpenAPI scanner emits for the unions it
133
+ // derives. Both are already true of every branch, so validation is unchanged — but a
134
+ // generated Java/Go client reads the union node, not the branches, and needs to be told
135
+ // the value is an object whose discriminator is always present.
136
+ node.type = 'object';
137
+ const required = Array.isArray(node.required)
138
+ ? node.required.filter((item): item is string => typeof item === 'string')
139
+ : [];
140
+ node.required = [...new Set([...required, propertyName])];
141
+ return;
142
+ }
143
+ }
144
+
145
+ /**
146
+ * Definition entries in an order that lets a discriminator be synthesized.
147
+ *
148
+ * A union's `discriminator` is read off its MEMBERS, so a union hoisted before them registers
149
+ * without one. That is invisible until the same union is registered twice — once as a root, where
150
+ * Zod happens to emit its members first, and once inside a component that references it, where it
151
+ * does not — at which point the two shapes disagree and `register` reports a conflict on a
152
+ * component nobody wrote twice.
153
+ *
154
+ * A discriminated union's branches are objects, never unions themselves, so hoisting non-unions
155
+ * first is enough to make the result independent of the order Zod emitted `$defs` in.
156
+ */
157
+ function inHoistOrder(block: JsonObject): [string, unknown][] {
158
+ const entries = Object.entries(block);
159
+ const isUnion = (schema: unknown) =>
160
+ isPlainObject(schema) && (Array.isArray(schema.oneOf) || Array.isArray(schema.anyOf));
161
+ return [...entries.filter(([, schema]) => !isUnion(schema)), ...entries.filter(([, schema]) => isUnion(schema))];
162
+ }
163
+
164
+ interface HoistContext {
165
+ components: Record<string, JsonObject>;
166
+ referenceComponents: Readonly<Record<string, JsonObject>>;
167
+ rootName: string;
168
+ /** Component name -> serialized shape, for detecting conflicting definitions. */
169
+ seen: Map<string, string>;
170
+ /** Names reserved while their definition is still being walked (recursion guard). */
171
+ pending: Set<string>;
172
+ }
173
+
174
+ function walk(value: unknown, ctx: HoistContext, isRoot: boolean): unknown {
175
+ if (Array.isArray(value)) return value.map((item) => walk(item, ctx, false));
176
+ if (!isPlainObject(value)) return value;
177
+
178
+ const { $schema: _schema, $id, $defs, definitions, ...rest } = value;
179
+
180
+ // A nested $id opens a new reference scope: `{"$ref": "#"}` inside it means *this* schema,
181
+ // not the enclosing root.
182
+ const scopeName = typeof $id === 'string' && !isRoot ? $id : ctx.rootName;
183
+ const previousRoot = ctx.rootName;
184
+ ctx.rootName = scopeName;
185
+ try {
186
+ // Hoist sibling definition blocks first so members can reference each other — and before the
187
+ // `$ref` branch below, which returns without descending. A node that is ONLY a reference can
188
+ // still carry the definitions that reference points at: that is exactly the shape Zod emits
189
+ // for an alias schema adapted on its own, and skipping its `$defs` left the reference dangling.
190
+ for (const block of [$defs, definitions]) {
191
+ if (!isPlainObject(block)) continue;
192
+ for (const [name, schema] of inHoistOrder(block)) {
193
+ hoist(name, schema, ctx);
194
+ }
195
+ }
196
+
197
+ if (typeof rest[REF] === 'string') {
198
+ const rewritten = componentRef(refTargetName(rest[REF] as string, ctx.rootName));
199
+ // In 2020-12 a reference may carry sibling keywords and annotations; keep them.
200
+ const siblings = Object.entries(rest).filter(([key]) => key !== REF);
201
+ if (siblings.length === 0) return rewritten;
202
+ const out: JsonObject = {};
203
+ for (const [key, child] of siblings) out[key] = walk(child, ctx, false);
204
+ return { ...out, ...rewritten };
205
+ }
206
+
207
+ const out: JsonObject = {};
208
+ for (const [key, child] of Object.entries(rest)) {
209
+ // An empty `properties` map constrains nothing, and Zod emits one for the catchall-only
210
+ // object that a `Record<string, T>` index signature has to be written as — `z.record`
211
+ // additionally emits a `propertyNames`, which the TypeScript-derived generator never did.
212
+ // Dropping it is what lets such a component be byte-identical to its derived counterpart.
213
+ if (key === 'properties' && isPlainObject(child) && Object.keys(child).length === 0) continue;
214
+ // `properties` keys are user data, not schema keywords — never treat them as refs.
215
+ out[key] =
216
+ key === 'properties' && isPlainObject(child)
217
+ ? Object.fromEntries(Object.entries(child).map(([p, s]) => [p, walk(s, ctx, false)]))
218
+ : walk(child, ctx, false);
219
+ }
220
+
221
+ synthesizeDiscriminator(out, ctx);
222
+
223
+ // A nested schema carrying its own $id is a named component: hoist it and leave a reference.
224
+ if (typeof $id === 'string' && !isRoot) {
225
+ register($id, out, ctx);
226
+ return componentRef($id);
227
+ }
228
+ return out;
229
+ } finally {
230
+ ctx.rootName = previousRoot;
231
+ }
232
+ }
233
+
234
+ function register(name: string, schema: JsonObject, ctx: HoistContext): void {
235
+ const fingerprint = JSON.stringify(schema);
236
+ const previous = ctx.seen.get(name);
237
+ if (previous !== undefined && previous !== fingerprint) {
238
+ throw new SchemaAdapterError(
239
+ `Component '${name}' is defined twice with different shapes (seen while adapting ` +
240
+ `'${ctx.rootName}'). Component names must be globally unique.`,
241
+ );
242
+ }
243
+ ctx.seen.set(name, fingerprint);
244
+ ctx.components[name] = schema;
245
+ }
246
+
247
+ function hoist(name: string, schema: unknown, ctx: HoistContext): void {
248
+ if (!isPlainObject(schema)) return;
249
+ // Already being walked higher up the stack — the reference will resolve once it lands.
250
+ if (ctx.pending.has(name)) return;
251
+ ctx.pending.add(name);
252
+ const previousRoot = ctx.rootName;
253
+ // A `$defs` entry does NOT open a new reference scope — only an `$id` does. `{"$ref": "#"}`
254
+ // inside one still points at the DOCUMENT root, so the enclosing root name has to stay in place.
255
+ // Naming the entry here instead was invisible until the first recursive schema: Zod writes
256
+ // `JSONSchemaProperties.additionalProperties` as a bare `#`, meaning the enclosing `JSONSchema`,
257
+ // and rewriting it to `JSONSchemaProperties` turned a property map into a map of property maps.
258
+ if (typeof schema.$id === 'string') ctx.rootName = schema.$id;
259
+ try {
260
+ // Every root carries its own inlined copy of the whole `$defs` closure it reaches, so a shared
261
+ // definition arrives here once per referencing root — 7069 times for 671 names on the full
262
+ // registry. The repeats are what feed `register`'s shape comparison, and they cannot be short-
263
+ // circuited on the INPUT: two copies of the same definition are not textually equal, because a
264
+ // `$ref` inside one is spelled relative to whichever root inlined it. Only the walked form is
265
+ // comparable, so every copy is walked.
266
+ register(name, walk(schema, ctx, true) as JsonObject, ctx);
267
+ } finally {
268
+ ctx.rootName = previousRoot;
269
+ ctx.pending.delete(name);
270
+ }
271
+ }
272
+
273
+ /** Every `$ref` must land on a component that exists, or the spec ships a dangling pointer. */
274
+ function assertReferencesResolve(
275
+ components: Readonly<Record<string, JsonObject>>,
276
+ referenceComponents: Readonly<Record<string, JsonObject>>,
277
+ ): void {
278
+ const visit = (node: unknown, owner: string): void => {
279
+ if (Array.isArray(node)) {
280
+ for (const item of node) visit(item, owner);
281
+ return;
282
+ }
283
+ if (!isPlainObject(node)) return;
284
+ const ref = node[REF];
285
+ if (typeof ref === 'string') {
286
+ const name = ref.startsWith(COMPONENT_PREFIX) ? ref.slice(COMPONENT_PREFIX.length) : undefined;
287
+ if (name === undefined || (!components[name] && !referenceComponents[name])) {
288
+ throw new SchemaAdapterError(
289
+ `Component '${owner}' references '${ref}', which is not a known component.`,
290
+ );
291
+ }
292
+ }
293
+ for (const child of Object.values(node)) visit(child, owner);
294
+ };
295
+ for (const [name, schema] of Object.entries(components)) visit(schema, name);
296
+ }
297
+
298
+ /**
299
+ * Converts a map of named JSON Schemas into OpenAPI `components.schemas`.
300
+ *
301
+ * @param roots component name -> plain JSON Schema
302
+ */
303
+ export function toOpenApiComponents(
304
+ roots: Readonly<Record<string, unknown>>,
305
+ options: AdapterOptions = {},
306
+ ): Record<string, JsonObject> {
307
+ const ctx: HoistContext = {
308
+ components: {},
309
+ referenceComponents: options.referenceComponents ?? {},
310
+ rootName: '',
311
+ seen: new Map(),
312
+ pending: new Set(),
313
+ };
314
+ for (const [name, schema] of Object.entries(roots)) {
315
+ if (!isPlainObject(schema)) {
316
+ throw new SchemaAdapterError(`Component '${name}' is not an object schema.`);
317
+ }
318
+ ctx.rootName = name;
319
+ register(name, walk(structuredClone(schema), ctx, true) as JsonObject, ctx);
320
+ }
321
+
322
+ const strict = options.strictComponents;
323
+ if (strict) {
324
+ for (const name of strict) {
325
+ const schema = ctx.components[name];
326
+ if (!schema) {
327
+ throw new SchemaAdapterError(`Cannot apply a strict policy to unknown component '${name}'.`);
328
+ }
329
+ closeObjects(schema);
330
+ }
331
+ }
332
+ for (const [name, schema] of Object.entries(ctx.components)) {
333
+ if (strict?.has(name)) continue;
334
+ // Open the component by removing an inherited `false`. A `true` or a subschema is a
335
+ // deliberate constraint on the extras (e.g. a Record<string, string> value type) and must
336
+ // survive — deleting it would silently widen the contract to accept anything.
337
+ if (schema.additionalProperties === false) delete schema.additionalProperties;
338
+ // The one subschema that is NOT a constraint: `{}` accepts every extra, which is exactly what
339
+ // an absent `additionalProperties` means. Zod emits it for `looseObject`, and the
340
+ // TypeScript-derived generator emits nothing for the index signature that models the same
341
+ // thing, so dropping it is what lets an intentionally-open component be byte-identical to its
342
+ // derived counterpart. Unlike the `false` above, this changes no meaning at all.
343
+ if (isPlainObject(schema.additionalProperties) && Object.keys(schema.additionalProperties).length === 0) {
344
+ delete schema.additionalProperties;
345
+ }
346
+ }
347
+
348
+ for (const schema of Object.values(ctx.components)) {
349
+ normalizeOpenMaps(schema);
350
+ }
351
+
352
+ for (const schema of Object.values(ctx.components)) {
353
+ moveDescriptionsLast(schema);
354
+ }
355
+
356
+ assertReferencesResolve(ctx.components, ctx.referenceComponents);
357
+ return ctx.components;
358
+ }
359
+
360
+ /**
361
+ * Visits every SUBSCHEMA of a node, and nothing else.
362
+ *
363
+ * The distinction is load-bearing rather than pedantic: `properties` is a map from property NAME to
364
+ * subschema, so its keys are user data. A generic "walk every object" pass would treat a property
365
+ * literally named `description` — which `Project`, `ICreateProjectPayload` and three other published
366
+ * components have — as the `description` keyword, and reordering it would change the published
367
+ * property order. Enumerating the structural keywords is what makes that impossible.
368
+ */
369
+ function eachSubschema(node: JsonObject, visit: (child: JsonObject) => void): void {
370
+ for (const keyword of ['items', 'additionalProperties', 'propertyNames', 'contains', 'not', 'if', 'then', 'else']) {
371
+ const child = node[keyword];
372
+ if (isPlainObject(child)) visit(child);
373
+ }
374
+ for (const keyword of ['properties', 'patternProperties', '$defs', 'definitions', 'dependentSchemas']) {
375
+ const map = node[keyword];
376
+ if (!isPlainObject(map)) continue;
377
+ for (const child of Object.values(map)) {
378
+ if (isPlainObject(child)) visit(child);
379
+ }
380
+ }
381
+ for (const keyword of ['anyOf', 'oneOf', 'allOf', 'prefixItems']) {
382
+ const list = node[keyword];
383
+ if (!Array.isArray(list)) continue;
384
+ for (const child of list) {
385
+ if (isPlainObject(child)) visit(child);
386
+ }
387
+ }
388
+ }
389
+
390
+ /**
391
+ * Spells an unconstrained map the way the document already spelled it, everywhere below a component
392
+ * root.
393
+ *
394
+ * Zod writes a `Record<string, T>` with an unconstrained value as `additionalProperties: {}` plus
395
+ * `propertyNames: {type: 'string'}`. Neither constrains anything — the empty schema accepts every
396
+ * value, and a JSON object's keys are strings by definition — so both are equivalent to what the
397
+ * TypeScript-derived generator emitted, which was `additionalProperties: true` and no
398
+ * `propertyNames` at all.
399
+ *
400
+ * Equivalent to a validator, but NOT to a code generator: openapi-generator renders the two
401
+ * `additionalProperties` spellings as different Go types (`map[string]interface{}` against
402
+ * `map[string]*interface{}`), so publishing the Zod spelling silently changed the generated Go
403
+ * client's map element type at 109 sites. That is a source break for SDK consumers bought for
404
+ * nothing, which is why the published form is normalized rather than left as emitted.
405
+ *
406
+ * Runs after the component-root pass above, which DELETES a root's empty `additionalProperties`
407
+ * outright. Roots therefore never reach here still carrying one, and the two rules do not fight.
408
+ */
409
+ function normalizeOpenMaps(node: JsonObject): void {
410
+ if (isPlainObject(node.additionalProperties) && Object.keys(node.additionalProperties).length === 0) {
411
+ node.additionalProperties = true;
412
+ }
413
+ // `{type: 'string'}` is the only no-op form; a pattern or a length bound is a real constraint on
414
+ // the keys and has to survive.
415
+ const names = node.propertyNames;
416
+ if (isPlainObject(names) && (Object.keys(names).length === 0 || isOnlyStringType(names))) {
417
+ delete node.propertyNames;
418
+ }
419
+ eachSubschema(node, normalizeOpenMaps);
420
+ }
421
+
422
+ function isOnlyStringType(schema: JsonObject): boolean {
423
+ const keys = Object.keys(schema);
424
+ return keys.length === 1 && keys[0] === 'type' && schema.type === 'string';
425
+ }
426
+
427
+ /**
428
+ * Closes a strict component and every anonymous object inside it.
429
+ *
430
+ * Strictness is declared per component, but an object nested inline in one is not a component — it has
431
+ * no name to list — so without this it stayed open while its parent closed. The TypeScript-derived
432
+ * generator closed every object it emitted, so the document already publishes those inline objects
433
+ * closed, and leaving them open would loosen the published contract.
434
+ *
435
+ * An existing `additionalProperties` is never overwritten: `true` or a subschema is a deliberate
436
+ * statement about the extras — a `Record<string, string>` value type, say — and replacing it with
437
+ * `false` would reject data the schema explicitly allows. A nested `$ref` is left alone too; it points
438
+ * at another component, which is governed by its own listing.
439
+ */
440
+ function closeObjects(node: JsonObject): void {
441
+ if (typeof node[REF] !== 'string' && node.type === 'object' && node.additionalProperties === undefined) {
442
+ node.additionalProperties = false;
443
+ }
444
+ eachSubschema(node, closeObjects);
445
+ }
446
+
447
+ /**
448
+ * Puts `description` last on every subschema, which is where the published document has it.
449
+ *
450
+ * Key order carries no meaning to consumers, but stable ordering keeps generated artifacts readable.
451
+ * The scanner's TypeScript-derived output puts `description` last, while Zod emits it wherever
452
+ * `.meta()` happened to land, and
453
+ * the strict policy above appends `additionalProperties` after that, so without this pass a described
454
+ * `$ref` property emitted `{description, $ref}` against the document's `{$ref, description}` and every
455
+ * closed component with a description emitted `{description, additionalProperties}`.
456
+ */
457
+ function moveDescriptionsLast(node: JsonObject): void {
458
+ eachSubschema(node, moveDescriptionsLast);
459
+ if (!('description' in node)) return;
460
+ const keys = Object.keys(node);
461
+ if (keys[keys.length - 1] === 'description') return;
462
+ const { description } = node;
463
+ delete node.description;
464
+ node.description = description;
465
+ }
466
+
467
+ /**
468
+ * Sibling keywords next to a `$ref` that compose conjunctively in a way pruning can honour: both
469
+ * schemas' declared properties count as declared, and required is the union.
470
+ */
471
+ const COMPOSABLE_SIBLINGS = new Set(['properties', 'required']);
472
+
473
+ /** Siblings that annotate rather than constrain, so they cannot affect which fields survive. */
474
+ const ANNOTATION_SIBLINGS = new Set([
475
+ 'title',
476
+ 'description',
477
+ 'deprecated',
478
+ 'examples',
479
+ 'example',
480
+ 'default',
481
+ 'readOnly',
482
+ 'writeOnly',
483
+ 'format',
484
+ '$comment',
485
+ ]);
486
+
487
+ /**
488
+ * Applicator keywords whose interaction with pruning is not sound to guess.
489
+ *
490
+ * `patternProperties` and `dependentSchemas` declare fields that are absent from `properties`, so
491
+ * pruning would delete legitimate data. `prefixItems` gives array positions their own schemas,
492
+ * which the single-`items` path would apply wrongly. `not`/`if` are conditional, and `allOf`
493
+ * needs the union of every branch's properties.
494
+ */
495
+ const UNSUPPORTED_APPLICATORS = [
496
+ 'allOf',
497
+ 'patternProperties',
498
+ 'prefixItems',
499
+ 'dependentSchemas',
500
+ 'unevaluatedProperties',
501
+ 'not',
502
+ 'if',
503
+ ];
504
+
505
+ /** Sibling keywords beside a `$ref` that cannot be composed safely. */
506
+ function unsupportedSiblings(schema: JsonObject): string[] {
507
+ return Object.keys(schema).filter(
508
+ (key) => key !== REF && !COMPOSABLE_SIBLINGS.has(key) && !ANNOTATION_SIBLINGS.has(key),
509
+ );
510
+ }
511
+
512
+ type Resolution = { schema: JsonObject } | { reason: string };
513
+
514
+ /**
515
+ * Fully resolves a reference chain, composing the sibling keywords that can be composed.
516
+ *
517
+ * Follows references until a non-reference schema is reached. A component whose body is itself a
518
+ * `$ref` — or one carrying `properties` beside a `$ref` — is an alias, and stopping after one hop
519
+ * would hand the caller a node that still has a `$ref`. Pruning would then read that node's own
520
+ * `properties` as the whole shape and drop everything the target declares, while
521
+ * {@link findUnprunablePaths} kept recursing and reported nothing wrong. Both paths call this, so
522
+ * they always see the same terminal schema.
523
+ *
524
+ * In JSON Schema 2020-12 a `$ref` and its siblings apply CONJUNCTIVELY — both must hold. Merging
525
+ * by overwriting would be wrong in the widening direction: a sibling `additionalProperties: true`
526
+ * beside a closed target does not open it. Rather than reimplement intersection semantics (whose
527
+ * `additionalProperties` interaction is famously counterintuitive), anything beyond a union of
528
+ * `properties`/`required` and pure annotations is declined — the caller then passes the value
529
+ * through untouched.
530
+ *
531
+ * Returns a reason instead of a schema when a target is unknown, a link carries siblings that
532
+ * cannot be composed, or the chain cycles.
533
+ */
534
+ function resolveChain(schema: JsonObject, components: Readonly<Record<string, JsonObject>>): Resolution {
535
+ let current = schema;
536
+ const visited = new Set<string>();
537
+ // Sibling contributions accumulated along the chain, applied to the terminal schema.
538
+ const extraProperties: JsonObject = {};
539
+ const extraRequired: string[] = [];
540
+
541
+ while (typeof current[REF] === 'string') {
542
+ const unsupported = unsupportedSiblings(current);
543
+ if (unsupported.length > 0) {
544
+ return { reason: `$ref with unsupported sibling: ${unsupported.sort().join(', ')}` };
545
+ }
546
+ const name = (current[REF] as string).slice(COMPONENT_PREFIX.length);
547
+ // An alias cycle has no terminal schema to prune against.
548
+ if (visited.has(name)) return { reason: 'circular $ref' };
549
+ visited.add(name);
550
+
551
+ const properties = current.properties;
552
+ if (isPlainObject(properties)) Object.assign(extraProperties, properties);
553
+ if (Array.isArray(current.required)) extraRequired.push(...(current.required as string[]));
554
+
555
+ const target = components[name];
556
+ if (!target) return { reason: 'unresolved $ref' };
557
+ current = target;
558
+ }
559
+
560
+ if (Object.keys(extraProperties).length === 0 && extraRequired.length === 0) return { schema: current };
561
+
562
+ const merged: JsonObject = { ...current };
563
+ merged.properties = { ...(isPlainObject(current.properties) ? current.properties : {}), ...extraProperties };
564
+ if (extraRequired.length > 0) {
565
+ const existing = Array.isArray(current.required) ? (current.required as string[]) : [];
566
+ merged.required = [...new Set([...existing, ...extraRequired])];
567
+ }
568
+ return { schema: merged };
569
+ }
570
+
571
+ /**
572
+ * {@link resolveChain} for callers that only need to know whether resolution succeeded.
573
+ *
574
+ * Exported so parameter normalization follows the same reference semantics as pruning rather than
575
+ * carrying a second, subtly different resolver. A query parameter typed by a hoisted enum is reached
576
+ * through exactly the chain walked here, so what the normalizer coerces towards and what the spec
577
+ * publishes are read off the same node.
578
+ */
579
+ export function resolveSchemaRef(
580
+ schema: JsonObject,
581
+ components: Readonly<Record<string, JsonObject>>,
582
+ ): JsonObject | undefined {
583
+ const resolution = resolveChain(schema, components);
584
+ return 'schema' in resolution ? resolution.schema : undefined;
585
+ }
586
+
587
+ function resolve(schema: JsonObject, components: Readonly<Record<string, JsonObject>>): JsonObject | undefined {
588
+ return resolveSchemaRef(schema, components);
589
+ }
590
+
591
+ /**
592
+ * Whether a subschema could describe an object, i.e. whether pruning it would do anything.
593
+ * References are resolved first — a `$ref` to a scalar enum is not object-bearing, and treating
594
+ * every reference as one makes scalar unions look ambiguous when they are not.
595
+ */
596
+ function couldHoldProperties(node: unknown, components: Readonly<Record<string, JsonObject>>): boolean {
597
+ if (!isPlainObject(node)) return false;
598
+ const resolved = typeof node[REF] === 'string' ? resolve(node, components) : node;
599
+ // An unresolvable reference is opaque, so assume the worst.
600
+ if (!resolved) return true;
601
+ return (
602
+ resolved.type === 'object' ||
603
+ isPlainObject(resolved.properties) ||
604
+ resolved.additionalProperties !== undefined ||
605
+ resolved.patternProperties !== undefined ||
606
+ resolved.allOf !== undefined ||
607
+ resolved.oneOf !== undefined ||
608
+ resolved.anyOf !== undefined
609
+ );
610
+ }
611
+
612
+ /**
613
+ * Why this node cannot be narrowed, or undefined if it can.
614
+ *
615
+ * Shared by {@link pruneToSchema} and {@link findUnprunablePaths} so the pruner and the report of
616
+ * its own limitations cannot drift apart.
617
+ */
618
+ function unprunableReason(node: JsonObject, components: Readonly<Record<string, JsonObject>>): string | undefined {
619
+ for (const keyword of UNSUPPORTED_APPLICATORS) {
620
+ if (node[keyword] !== undefined) return keyword;
621
+ }
622
+ const branches = node.oneOf ?? node.anyOf;
623
+ if (Array.isArray(branches)) {
624
+ // A union of scalars (a nullable enum, say) has no properties to narrow, so an absent
625
+ // discriminator costs nothing.
626
+ if (!branches.some((branch) => couldHoldProperties(branch, components))) return undefined;
627
+ if (!isPlainObject(node.discriminator)) return 'union without discriminator';
628
+ }
629
+ return undefined;
630
+ }
631
+
632
+ /**
633
+ * Reports the paths within a component where {@link pruneToSchema} cannot narrow. Values at those
634
+ * paths pass through untouched, extras included.
635
+ *
636
+ * An empty report means every path is structurally prunable FOR SCHEMA-CONFORMING INPUT. It is not
637
+ * a guarantee about arbitrary payloads: a discriminated union whose discriminator carries a value
638
+ * with no mapping entry still passes through, because no branch describes it. Treat an empty
639
+ * report as "no structural gaps", not as "nothing can escape".
640
+ */
641
+ export function findUnprunablePaths(schema: JsonObject, components: Readonly<Record<string, JsonObject>>): string[] {
642
+ const found: string[] = [];
643
+ const visiting = new Set<string>();
644
+
645
+ const visit = (node: JsonObject, path: string): void => {
646
+ const ref = node[REF];
647
+ if (typeof ref === 'string') {
648
+ const name = ref.slice(COMPONENT_PREFIX.length);
649
+ if (visiting.has(name)) return; // cycle — already accounted for
650
+ // The same resolution the pruner performs, chain included, so a defect in an alias
651
+ // hop is reported here rather than discovered when a response comes back malformed.
652
+ const resolution = resolveChain(node, components);
653
+ if ('reason' in resolution) {
654
+ found.push(`${path} (${resolution.reason})`);
655
+ return;
656
+ }
657
+ visiting.add(name);
658
+ visit(resolution.schema, path);
659
+ visiting.delete(name);
660
+ return;
661
+ }
662
+
663
+ const reason = unprunableReason(node, components);
664
+ if (reason) {
665
+ found.push(`${path} (${reason})`);
666
+ return;
667
+ }
668
+
669
+ const branches = node.oneOf ?? node.anyOf;
670
+ if (Array.isArray(branches)) {
671
+ if (!branches.some((branch) => couldHoldProperties(branch, components))) return;
672
+ for (const [index, branch] of branches.entries()) {
673
+ if (isPlainObject(branch)) visit(branch, `${path}/${index}`);
674
+ }
675
+ return;
676
+ }
677
+
678
+ if (isPlainObject(node.properties)) {
679
+ for (const [key, child] of Object.entries(node.properties)) {
680
+ if (isPlainObject(child)) visit(child, `${path}/${key}`);
681
+ }
682
+ }
683
+ // A map's values are pruned through this subschema, so its limitations count too.
684
+ if (isPlainObject(node.additionalProperties) && Object.keys(node.additionalProperties).length > 0) {
685
+ visit(node.additionalProperties, `${path}{}`);
686
+ }
687
+ if (isPlainObject(node.items)) visit(node.items, `${path}[]`);
688
+ };
689
+
690
+ visit(schema, '');
691
+ return found;
692
+ }
693
+
694
+ /**
695
+ * Whether an object schema describes a fixed shape (prunable) or a freeform map (must be left
696
+ * alone).
697
+ *
698
+ * The distinction is what makes this safe. AJV's `removeAdditional: 'all'` strips keys from
699
+ * freeform objects too — that is how `launch_workstream`'s `data` was silently emptied and
700
+ * `sys:AppDeveloper` lost `user_prompt` (see `packages/workflows/src/tools/validation.ts`).
701
+ * `Account.feature_flags` is exactly such a map: `{additionalProperties: {}}` with no
702
+ * `properties`. Pruning it would delete every operator flag.
703
+ */
704
+ function declaresFixedShape(schema: JsonObject): boolean {
705
+ const additional = schema.additionalProperties;
706
+ if (additional === false) return true;
707
+ // Explicitly extensible (`true` or a subschema) — the extras are part of the contract.
708
+ if (additional !== undefined) return false;
709
+ return isPlainObject(schema.properties);
710
+ }
711
+
712
+ /**
713
+ * Best-effort narrowing of a response payload to the properties its published schema declares.
714
+ *
715
+ * NOT A SECURITY BOUNDARY. Where the schema is ambiguous — an `allOf` intersection, a union with
716
+ * no discriminator, a discriminator value with no mapping entry, or an unresolvable `$ref` — the
717
+ * value passes through UNTOUCHED, extras included. Losing data is worse than guessing, so the
718
+ * pruner declines rather than improvises. Anything that must never reach a client (secrets,
719
+ * internal identifiers) still needs an explicit response mapper or a request/response type split;
720
+ * this must not be relied on to remove it. {@link findUnprunablePaths} reports where a given
721
+ * component falls into those gaps.
722
+ *
723
+ * Responses are pruned rather than rejected: a document carrying an undocumented field is the
724
+ * server's problem, not the caller's, and failing would turn drift into a 500.
725
+ *
726
+ * The input is never mutated.
727
+ */
728
+ export function pruneToSchema(
729
+ value: unknown,
730
+ schema: JsonObject,
731
+ components: Readonly<Record<string, JsonObject>>,
732
+ ): unknown {
733
+ const resolved = resolve(schema, components);
734
+ if (!resolved) return value;
735
+ // Declines on any shape whose narrowing would be a guess. Shared with findUnprunablePaths so
736
+ // the report always describes what the pruner actually does.
737
+ if (unprunableReason(resolved, components)) return value;
738
+
739
+ const branches = resolved.oneOf ?? resolved.anyOf;
740
+ if (Array.isArray(branches)) {
741
+ const discriminator = resolved.discriminator;
742
+ if (!isPlainObject(discriminator) || !isPlainObject(value)) return value;
743
+ const key = discriminator.propertyName;
744
+ const mapping = discriminator.mapping;
745
+ if (typeof key !== 'string' || !isPlainObject(mapping)) return value;
746
+ const target = mapping[String(value[key])];
747
+ if (typeof target !== 'string') return value;
748
+ return pruneToSchema(value, { [REF]: target }, components);
749
+ }
750
+
751
+ if (Array.isArray(value)) {
752
+ const items = resolved.items;
753
+ if (!isPlainObject(items)) return value;
754
+ return value.map((item) => pruneToSchema(item, items, components));
755
+ }
756
+
757
+ if (!isPlainObject(value)) return value;
758
+
759
+ const properties = isPlainObject(resolved.properties) ? resolved.properties : undefined;
760
+ const additional = resolved.additionalProperties;
761
+ const fixed = declaresFixedShape(resolved);
762
+
763
+ const out: JsonObject = {};
764
+ for (const [key, child] of Object.entries(value)) {
765
+ const propertySchema = properties?.[key];
766
+ if (isPlainObject(propertySchema)) {
767
+ out[key] = pruneToSchema(child, propertySchema, components);
768
+ continue;
769
+ }
770
+ if (fixed) continue; // undeclared on a fixed shape — drop it
771
+ // Freeform: keep the value, narrowing it only if a subschema describes the extras.
772
+ out[key] =
773
+ isPlainObject(additional) && Object.keys(additional).length > 0
774
+ ? pruneToSchema(child, additional, components)
775
+ : child;
776
+ }
777
+ return out;
778
+ }