@aexhq/sdk 0.46.4-canary → 0.50.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 (337) hide show
  1. package/LICENSE +201 -0
  2. package/NOTICE +38 -0
  3. package/README.md +23 -31
  4. package/dist/client/aex.d.ts +33 -0
  5. package/dist/client/aex.js +98 -0
  6. package/dist/client/aex.js.map +1 -0
  7. package/dist/client/credentials.d.ts +25 -0
  8. package/dist/client/credentials.js +97 -0
  9. package/dist/client/credentials.js.map +1 -0
  10. package/dist/client/routing.d.ts +7 -0
  11. package/dist/client/routing.js +29 -0
  12. package/dist/client/routing.js.map +1 -0
  13. package/dist/downloads/download.d.ts +25 -0
  14. package/dist/downloads/download.js +53 -0
  15. package/dist/downloads/download.js.map +1 -0
  16. package/dist/generated/errors.d.ts +12 -0
  17. package/dist/generated/errors.js +81 -0
  18. package/dist/generated/errors.js.map +1 -0
  19. package/dist/generated/resources.d.ts +730 -0
  20. package/dist/generated/resources.js +606 -0
  21. package/dist/generated/resources.js.map +1 -0
  22. package/dist/generated/routes.d.ts +42 -0
  23. package/dist/generated/routes.js +2101 -0
  24. package/dist/generated/routes.js.map +1 -0
  25. package/dist/index.d.ts +20 -50
  26. package/dist/index.js +11 -62
  27. package/dist/index.js.map +1 -1
  28. package/dist/observations/stream.d.ts +1 -0
  29. package/dist/observations/stream.js +18 -0
  30. package/dist/observations/stream.js.map +1 -0
  31. package/dist/transport/errors.d.ts +60 -0
  32. package/dist/transport/errors.js +107 -0
  33. package/dist/transport/errors.js.map +1 -0
  34. package/dist/transport/pagination.d.ts +8 -0
  35. package/dist/transport/pagination.js +34 -0
  36. package/dist/transport/pagination.js.map +1 -0
  37. package/dist/transport/retry.d.ts +21 -0
  38. package/dist/transport/retry.js +37 -0
  39. package/dist/transport/retry.js.map +1 -0
  40. package/dist/transport/transport.d.ts +25 -0
  41. package/dist/transport/transport.js +28 -0
  42. package/dist/transport/transport.js.map +1 -0
  43. package/package.json +63 -30
  44. package/dist/_contracts/account-operations.d.ts +0 -101
  45. package/dist/_contracts/account-operations.js +0 -242
  46. package/dist/_contracts/account-types.d.ts +0 -461
  47. package/dist/_contracts/account-types.js +0 -1
  48. package/dist/_contracts/api-key.d.ts +0 -61
  49. package/dist/_contracts/api-key.js +0 -101
  50. package/dist/_contracts/api-routes.d.ts +0 -20
  51. package/dist/_contracts/api-routes.js +0 -109
  52. package/dist/_contracts/archive-limits.d.ts +0 -3
  53. package/dist/_contracts/archive-limits.js +0 -23
  54. package/dist/_contracts/asset-authoring.d.ts +0 -22
  55. package/dist/_contracts/asset-authoring.js +0 -106
  56. package/dist/_contracts/asset-bundle.d.ts +0 -64
  57. package/dist/_contracts/asset-bundle.js +0 -263
  58. package/dist/_contracts/asset-upload-helper.d.ts +0 -31
  59. package/dist/_contracts/asset-upload-helper.js +0 -84
  60. package/dist/_contracts/billing-admission.d.ts +0 -29
  61. package/dist/_contracts/billing-admission.js +0 -28
  62. package/dist/_contracts/bundle-manifest.d.ts +0 -89
  63. package/dist/_contracts/bundle-manifest.js +0 -158
  64. package/dist/_contracts/canonical-sha256.d.ts +0 -8
  65. package/dist/_contracts/canonical-sha256.js +0 -8
  66. package/dist/_contracts/connection-ticket.d.ts +0 -22
  67. package/dist/_contracts/connection-ticket.js +0 -54
  68. package/dist/_contracts/continuation-event.d.ts +0 -31
  69. package/dist/_contracts/continuation-event.js +0 -6
  70. package/dist/_contracts/contract-parse-error.d.ts +0 -12
  71. package/dist/_contracts/contract-parse-error.js +0 -51
  72. package/dist/_contracts/error-codes.d.ts +0 -26
  73. package/dist/_contracts/error-codes.js +0 -116
  74. package/dist/_contracts/error-factory.d.ts +0 -32
  75. package/dist/_contracts/error-factory.js +0 -174
  76. package/dist/_contracts/event-envelope.d.ts +0 -471
  77. package/dist/_contracts/event-envelope.js +0 -501
  78. package/dist/_contracts/event-stream-client.d.ts +0 -122
  79. package/dist/_contracts/event-stream-client.js +0 -445
  80. package/dist/_contracts/event-view.d.ts +0 -44
  81. package/dist/_contracts/event-view.js +0 -69
  82. package/dist/_contracts/failure-class.d.ts +0 -29
  83. package/dist/_contracts/failure-class.js +0 -73
  84. package/dist/_contracts/http.d.ts +0 -135
  85. package/dist/_contracts/http.js +0 -434
  86. package/dist/_contracts/ids.d.ts +0 -66
  87. package/dist/_contracts/ids.js +0 -119
  88. package/dist/_contracts/index.d.ts +0 -42
  89. package/dist/_contracts/index.js +0 -52
  90. package/dist/_contracts/internal.d.ts +0 -55
  91. package/dist/_contracts/internal.js +0 -113
  92. package/dist/_contracts/models.d.ts +0 -30
  93. package/dist/_contracts/models.js +0 -28
  94. package/dist/_contracts/operation-core.d.ts +0 -36
  95. package/dist/_contracts/operation-core.js +0 -70
  96. package/dist/_contracts/operations.d.ts +0 -218
  97. package/dist/_contracts/operations.js +0 -1496
  98. package/dist/_contracts/otlp-projection.d.ts +0 -78
  99. package/dist/_contracts/otlp-projection.js +0 -171
  100. package/dist/_contracts/post-hook.d.ts +0 -31
  101. package/dist/_contracts/post-hook.js +0 -61
  102. package/dist/_contracts/provider-fault.d.ts +0 -34
  103. package/dist/_contracts/provider-fault.js +0 -68
  104. package/dist/_contracts/retry-core.d.ts +0 -29
  105. package/dist/_contracts/retry-core.js +0 -79
  106. package/dist/_contracts/runner-event.d.ts +0 -117
  107. package/dist/_contracts/runner-event.js +0 -172
  108. package/dist/_contracts/runtime-kind.d.ts +0 -60
  109. package/dist/_contracts/runtime-kind.js +0 -70
  110. package/dist/_contracts/runtime-manifest.d.ts +0 -121
  111. package/dist/_contracts/runtime-manifest.js +0 -83
  112. package/dist/_contracts/runtime-security-profile.d.ts +0 -26
  113. package/dist/_contracts/runtime-security-profile.js +0 -73
  114. package/dist/_contracts/runtime-sizes.d.ts +0 -104
  115. package/dist/_contracts/runtime-sizes.js +0 -111
  116. package/dist/_contracts/runtime-types.d.ts +0 -618
  117. package/dist/_contracts/runtime-types.js +0 -58
  118. package/dist/_contracts/schemas/asset-bundle.d.ts +0 -70
  119. package/dist/_contracts/schemas/asset-bundle.js +0 -107
  120. package/dist/_contracts/schemas/asset-ref.d.ts +0 -61
  121. package/dist/_contracts/schemas/asset-ref.js +0 -118
  122. package/dist/_contracts/schemas/bundle-manifest.d.ts +0 -66
  123. package/dist/_contracts/schemas/bundle-manifest.js +0 -77
  124. package/dist/_contracts/schemas/index.d.ts +0 -32
  125. package/dist/_contracts/schemas/index.js +0 -30
  126. package/dist/_contracts/schemas/mcp-server.d.ts +0 -99
  127. package/dist/_contracts/schemas/mcp-server.js +0 -209
  128. package/dist/_contracts/schemas/models.d.ts +0 -29
  129. package/dist/_contracts/schemas/models.js +0 -51
  130. package/dist/_contracts/schemas/numeric.d.ts +0 -18
  131. package/dist/_contracts/schemas/numeric.js +0 -28
  132. package/dist/_contracts/schemas/post-hook.d.ts +0 -45
  133. package/dist/_contracts/schemas/post-hook.js +0 -68
  134. package/dist/_contracts/schemas/response-assets.d.ts +0 -75
  135. package/dist/_contracts/schemas/response-assets.js +0 -81
  136. package/dist/_contracts/schemas/response-billing.d.ts +0 -208
  137. package/dist/_contracts/schemas/response-billing.js +0 -139
  138. package/dist/_contracts/schemas/response-common.d.ts +0 -132
  139. package/dist/_contracts/schemas/response-common.js +0 -162
  140. package/dist/_contracts/schemas/response-identity.d.ts +0 -648
  141. package/dist/_contracts/schemas/response-identity.js +0 -131
  142. package/dist/_contracts/schemas/response-mcp-servers.d.ts +0 -51
  143. package/dist/_contracts/schemas/response-mcp-servers.js +0 -32
  144. package/dist/_contracts/schemas/response-secrets.d.ts +0 -50
  145. package/dist/_contracts/schemas/response-secrets.js +0 -32
  146. package/dist/_contracts/schemas/response-sessions-internal.d.ts +0 -200
  147. package/dist/_contracts/schemas/response-sessions-internal.js +0 -142
  148. package/dist/_contracts/schemas/response-sessions.d.ts +0 -1598
  149. package/dist/_contracts/schemas/response-sessions.js +0 -377
  150. package/dist/_contracts/schemas/response-webhooks.d.ts +0 -76
  151. package/dist/_contracts/schemas/response-webhooks.js +0 -42
  152. package/dist/_contracts/schemas/response-workspace.d.ts +0 -225
  153. package/dist/_contracts/schemas/response-workspace.js +0 -99
  154. package/dist/_contracts/schemas/runtime-kind.d.ts +0 -31
  155. package/dist/_contracts/schemas/runtime-kind.js +0 -29
  156. package/dist/_contracts/schemas/runtime-security-profile.d.ts +0 -28
  157. package/dist/_contracts/schemas/runtime-security-profile.js +0 -26
  158. package/dist/_contracts/schemas/runtime-sizes.d.ts +0 -70
  159. package/dist/_contracts/schemas/runtime-sizes.js +0 -127
  160. package/dist/_contracts/schemas/session-limits.d.ts +0 -34
  161. package/dist/_contracts/schemas/session-limits.js +0 -39
  162. package/dist/_contracts/schemas/session-machine.d.ts +0 -23
  163. package/dist/_contracts/schemas/session-machine.js +0 -24
  164. package/dist/_contracts/schemas/session-request-config.d.ts +0 -58
  165. package/dist/_contracts/schemas/session-request-config.js +0 -134
  166. package/dist/_contracts/schemas/session-webhook.d.ts +0 -11
  167. package/dist/_contracts/schemas/session-webhook.js +0 -38
  168. package/dist/_contracts/schemas/side-effect-audit.d.ts +0 -98
  169. package/dist/_contracts/schemas/side-effect-audit.js +0 -102
  170. package/dist/_contracts/schemas/submission-assets.d.ts +0 -117
  171. package/dist/_contracts/schemas/submission-assets.js +0 -147
  172. package/dist/_contracts/schemas/submission-body.d.ts +0 -251
  173. package/dist/_contracts/schemas/submission-body.js +0 -378
  174. package/dist/_contracts/schemas/submission-environment.d.ts +0 -79
  175. package/dist/_contracts/schemas/submission-environment.js +0 -179
  176. package/dist/_contracts/schemas/submission-request.d.ts +0 -158
  177. package/dist/_contracts/schemas/submission-request.js +0 -49
  178. package/dist/_contracts/schemas/submission-secrets.d.ts +0 -47
  179. package/dist/_contracts/schemas/submission-secrets.js +0 -108
  180. package/dist/_contracts/schemas/wire.d.ts +0 -118
  181. package/dist/_contracts/schemas/wire.js +0 -171
  182. package/dist/_contracts/schemas/workspace-resources.d.ts +0 -50
  183. package/dist/_contracts/schemas/workspace-resources.js +0 -87
  184. package/dist/_contracts/sdk-errors.d.ts +0 -212
  185. package/dist/_contracts/sdk-errors.js +0 -313
  186. package/dist/_contracts/sdk-secrets.d.ts +0 -67
  187. package/dist/_contracts/sdk-secrets.js +0 -427
  188. package/dist/_contracts/session-archive.d.ts +0 -16
  189. package/dist/_contracts/session-archive.js +0 -92
  190. package/dist/_contracts/session-artifacts.d.ts +0 -189
  191. package/dist/_contracts/session-artifacts.js +0 -264
  192. package/dist/_contracts/session-config.d.ts +0 -373
  193. package/dist/_contracts/session-config.js +0 -562
  194. package/dist/_contracts/session-cost-types.d.ts +0 -211
  195. package/dist/_contracts/session-cost-types.js +0 -69
  196. package/dist/_contracts/session-cost.d.ts +0 -8
  197. package/dist/_contracts/session-cost.js +0 -582
  198. package/dist/_contracts/session-custody.d.ts +0 -165
  199. package/dist/_contracts/session-custody.js +0 -345
  200. package/dist/_contracts/session-file-query.d.ts +0 -14
  201. package/dist/_contracts/session-file-query.js +0 -178
  202. package/dist/_contracts/session-record.d.ts +0 -112
  203. package/dist/_contracts/session-record.js +0 -165
  204. package/dist/_contracts/session-retention.d.ts +0 -201
  205. package/dist/_contracts/session-retention.js +0 -450
  206. package/dist/_contracts/side-effect-audit.d.ts +0 -126
  207. package/dist/_contracts/side-effect-audit.js +0 -520
  208. package/dist/_contracts/sse.d.ts +0 -74
  209. package/dist/_contracts/sse.js +0 -227
  210. package/dist/_contracts/stable.d.ts +0 -45
  211. package/dist/_contracts/stable.js +0 -62
  212. package/dist/_contracts/status.d.ts +0 -25
  213. package/dist/_contracts/status.js +0 -57
  214. package/dist/_contracts/submission-limits.d.ts +0 -61
  215. package/dist/_contracts/submission-limits.js +0 -60
  216. package/dist/_contracts/submission.d.ts +0 -547
  217. package/dist/_contracts/submission.js +0 -812
  218. package/dist/_contracts/suggest.d.ts +0 -15
  219. package/dist/_contracts/suggest.js +0 -53
  220. package/dist/_contracts/testing/response-bindings.d.ts +0 -45
  221. package/dist/_contracts/testing/response-bindings.js +0 -256
  222. package/dist/_contracts/testing/wire-conformance-entry.d.ts +0 -10
  223. package/dist/_contracts/testing/wire-conformance-entry.js +0 -8
  224. package/dist/_contracts/testing/wire-conformance.d.ts +0 -169
  225. package/dist/_contracts/testing/wire-conformance.js +0 -276
  226. package/dist/_contracts/turn-trace.d.ts +0 -28
  227. package/dist/_contracts/turn-trace.js +0 -1
  228. package/dist/_contracts/unknown-field-error.d.ts +0 -13
  229. package/dist/_contracts/unknown-field-error.js +0 -21
  230. package/dist/_contracts/value-guards.d.ts +0 -20
  231. package/dist/_contracts/value-guards.js +0 -34
  232. package/dist/_contracts/webhook-verify.d.ts +0 -34
  233. package/dist/_contracts/webhook-verify.js +0 -93
  234. package/dist/_contracts/wire-observer.d.ts +0 -49
  235. package/dist/_contracts/wire-observer.js +0 -34
  236. package/dist/_contracts/workflow-status.d.ts +0 -7
  237. package/dist/_contracts/workflow-status.js +0 -43
  238. package/dist/_contracts/workspace-resources.d.ts +0 -98
  239. package/dist/_contracts/workspace-resources.js +0 -39
  240. package/dist/archive-limits.d.ts +0 -1
  241. package/dist/archive-limits.js +0 -2
  242. package/dist/archive-limits.js.map +0 -1
  243. package/dist/asset-upload.d.ts +0 -47
  244. package/dist/asset-upload.js +0 -269
  245. package/dist/asset-upload.js.map +0 -1
  246. package/dist/bundle.d.ts +0 -9
  247. package/dist/bundle.js +0 -20
  248. package/dist/bundle.js.map +0 -1
  249. package/dist/canonical-zip.d.ts +0 -68
  250. package/dist/canonical-zip.js +0 -355
  251. package/dist/canonical-zip.js.map +0 -1
  252. package/dist/cli.mjs +0 -12048
  253. package/dist/cli.mjs.sha256 +0 -1
  254. package/dist/client-types.d.ts +0 -192
  255. package/dist/client-types.js +0 -2
  256. package/dist/client-types.js.map +0 -1
  257. package/dist/client.d.ts +0 -464
  258. package/dist/client.js +0 -1207
  259. package/dist/client.js.map +0 -1
  260. package/dist/event-projection.d.ts +0 -22
  261. package/dist/event-projection.js +0 -380
  262. package/dist/event-projection.js.map +0 -1
  263. package/dist/fetch-archive.d.ts +0 -16
  264. package/dist/fetch-archive.js +0 -252
  265. package/dist/fetch-archive.js.map +0 -1
  266. package/dist/file.d.ts +0 -96
  267. package/dist/file.js +0 -272
  268. package/dist/file.js.map +0 -1
  269. package/dist/instructions.d.ts +0 -20
  270. package/dist/instructions.js +0 -40
  271. package/dist/instructions.js.map +0 -1
  272. package/dist/legacy-session-provider-fault.d.ts +0 -7
  273. package/dist/legacy-session-provider-fault.js +0 -38
  274. package/dist/legacy-session-provider-fault.js.map +0 -1
  275. package/dist/mcp-server.d.ts +0 -84
  276. package/dist/mcp-server.js +0 -117
  277. package/dist/mcp-server.js.map +0 -1
  278. package/dist/node-fs.d.ts +0 -29
  279. package/dist/node-fs.js +0 -19
  280. package/dist/node-fs.js.map +0 -1
  281. package/dist/node-walk.d.ts +0 -69
  282. package/dist/node-walk.js +0 -151
  283. package/dist/node-walk.js.map +0 -1
  284. package/dist/path-basename.d.ts +0 -5
  285. package/dist/path-basename.js +0 -9
  286. package/dist/path-basename.js.map +0 -1
  287. package/dist/retry.d.ts +0 -70
  288. package/dist/retry.js +0 -155
  289. package/dist/retry.js.map +0 -1
  290. package/dist/secret.d.ts +0 -65
  291. package/dist/secret.js +0 -110
  292. package/dist/secret.js.map +0 -1
  293. package/dist/session-validate.d.ts +0 -100
  294. package/dist/session-validate.js +0 -303
  295. package/dist/session-validate.js.map +0 -1
  296. package/dist/skill.d.ts +0 -99
  297. package/dist/skill.js +0 -169
  298. package/dist/skill.js.map +0 -1
  299. package/dist/submission-wire.d.ts +0 -13
  300. package/dist/submission-wire.js +0 -69
  301. package/dist/submission-wire.js.map +0 -1
  302. package/dist/tool.d.ts +0 -41
  303. package/dist/tool.js +0 -76
  304. package/dist/tool.js.map +0 -1
  305. package/dist/version.d.ts +0 -9
  306. package/dist/version.js +0 -10
  307. package/dist/version.js.map +0 -1
  308. package/docs/authentication.md +0 -125
  309. package/docs/billing.md +0 -164
  310. package/docs/cleanup.md +0 -27
  311. package/docs/concepts/agent-tools.md +0 -47
  312. package/docs/concepts/composition.md +0 -60
  313. package/docs/concepts/providers-and-runtimes.md +0 -121
  314. package/docs/concepts/sessions.md +0 -51
  315. package/docs/concepts/subagents.md +0 -35
  316. package/docs/credentials.md +0 -116
  317. package/docs/defaults.md +0 -51
  318. package/docs/errors.md +0 -258
  319. package/docs/events.md +0 -143
  320. package/docs/files.md +0 -130
  321. package/docs/limits-and-quotas.md +0 -114
  322. package/docs/limits.md +0 -51
  323. package/docs/mcp.md +0 -47
  324. package/docs/networking.md +0 -114
  325. package/docs/provider-runtime-capabilities.md +0 -32
  326. package/docs/public-surface.json +0 -73
  327. package/docs/quickstart.md +0 -135
  328. package/docs/release.md +0 -44
  329. package/docs/retries.md +0 -108
  330. package/docs/secrets.md +0 -141
  331. package/docs/session-config.md +0 -51
  332. package/docs/session-record.md +0 -58
  333. package/docs/skills.md +0 -65
  334. package/docs/telemetry.md +0 -66
  335. package/docs/testing.md +0 -35
  336. package/docs/vision-skills.md +0 -94
  337. package/docs/webhooks.md +0 -143
@@ -1,208 +0,0 @@
1
- /**
2
- * Response schemas for the `billing.*` and `adminBilling.*` families.
3
- *
4
- * Both `BillingSummary` and `BillingLedgerEntry` USED to carry
5
- * `[key: string]: unknown` — an explicit "additive server fields pass through"
6
- * promise. That promise is what made two real gaps invisible (`BillingSummary`
7
- * omitting `accountType`, `BillingLedgerEntry` omitting `workspaceId`), and it
8
- * is exactly what a strict response schema exists to stop being invisible. Both
9
- * signatures are now gone from the types as well, and both interfaces declare
10
- * every field the server sends.
11
- *
12
- * One gap remains, resolved in favour of the server (a schema that fails every
13
- * real response is not a gate): `workspaceId` on a ledger entry and on the three
14
- * admin routes is a RAW id, not the public `wsp_<hex>` form `whoami` and the
15
- * MCP-server records carry, so it is validated as a plain string.
16
- *
17
- * `createdAt` on a ledger entry is NOT ISO-8601: it is selected raw, so it
18
- * arrives as the Data API's `"YYYY-MM-DD HH:MM:SS"` text. It is validated as a
19
- * non-empty string, deliberately, and the inconsistency is reported rather than
20
- * encoded as if intended. `resetAt` and `blocked.at` ARE ISO-8601 — they are
21
- * constructed, not selected. `pastDueAt`, the third timestamp that used to sit
22
- * here, went with the plan catalog.
23
- */
24
- import * as z from "zod/mini";
25
- /**
26
- * One free monthly allowance row inside `GET /billing`.
27
- *
28
- * `dimension`, `unit` and `label` are validated as non-empty strings rather than
29
- * as enums on purpose: the dimensions a free allowance is denominated in are
30
- * hosted billing policy, and pinning them here would put a second copy of that
31
- * policy in the public package — the exact duplication the prepaid model was
32
- * built to remove. The SHAPE is what this schema is for.
33
- *
34
- * `approximateTokens` rides only on the USD-denominated token allowance, and
35
- * only when there is usage to infer a model from.
36
- */
37
- export declare const BillingAllowanceSchema: z.ZodMiniObject<{
38
- dimension: z.ZodMiniString<string>;
39
- quota: z.ZodMiniNumber<number>;
40
- used: z.ZodMiniNumber<number>;
41
- remaining: z.ZodMiniNumber<number>;
42
- unit: z.ZodMiniString<string>;
43
- label: z.ZodMiniString<string>;
44
- resetAt: z.ZodMiniString<string>;
45
- approximateTokens: z.ZodMiniOptional<z.ZodMiniObject<{
46
- model: z.ZodMiniString<string>;
47
- tokens: z.ZodMiniNumber<number>;
48
- }, z.core.$strict>>;
49
- }, z.core.$strict>;
50
- /** Auto-recharge settings plus the two guards a top-up form has to respect. */
51
- export declare const BillingAutoTopupSchema: z.ZodMiniObject<{
52
- enabled: z.ZodMiniBoolean<boolean>;
53
- thresholdUsd: z.ZodMiniNumber<number>;
54
- amountUsd: z.ZodMiniNumber<number>;
55
- minimumAmountUsd: z.ZodMiniNumber<number>;
56
- maxPerDay: z.ZodMiniNumber<number>;
57
- }, z.core.$strict>;
58
- /**
59
- * `GET /billing`.
60
- *
61
- * `planKey`, `subscriptionStatus` and `pastDueAt` are GONE with the catalog they
62
- * described; a strict schema still expecting them fails C4 against the current
63
- * server. What replaces them is the prepaid surface: the period, the
64
- * card-derived `admissionState`, the allowance rows, the auto-recharge block,
65
- * the saved card, and any live block.
66
- */
67
- export declare const BillingSummaryResponseSchema: z.ZodMiniObject<{
68
- balanceUsd: z.ZodMiniNumber<number>;
69
- monthSpendUsd: z.ZodMiniNumber<number>;
70
- spendCapUsd: z.ZodMiniNumber<number>;
71
- period: z.ZodMiniString<string>;
72
- admissionState: z.ZodMiniEnum<{
73
- free: "free";
74
- carded_manual: "carded_manual";
75
- carded_auto: "carded_auto";
76
- }>;
77
- accountType: z.ZodMiniEnum<{
78
- standard: "standard";
79
- internal: "internal";
80
- }>;
81
- paymentMethodStatus: z.ZodMiniEnum<{
82
- none: "none";
83
- active: "active";
84
- }>;
85
- autoTopupEnabled: z.ZodMiniBoolean<boolean>;
86
- blocked: z.ZodMiniNullable<z.ZodMiniObject<{
87
- at: z.ZodMiniString<string>;
88
- reason: z.ZodMiniString<string>;
89
- }, z.core.$strict>>;
90
- paymentMethod: z.ZodMiniObject<{
91
- present: z.ZodMiniBoolean<boolean>;
92
- brand: z.ZodMiniNullable<z.ZodMiniString<string>>;
93
- last4: z.ZodMiniNullable<z.ZodMiniString<string>>;
94
- }, z.core.$strict>;
95
- autoTopup: z.ZodMiniObject<{
96
- enabled: z.ZodMiniBoolean<boolean>;
97
- thresholdUsd: z.ZodMiniNumber<number>;
98
- amountUsd: z.ZodMiniNumber<number>;
99
- minimumAmountUsd: z.ZodMiniNumber<number>;
100
- maxPerDay: z.ZodMiniNumber<number>;
101
- }, z.core.$strict>;
102
- allowances: z.ZodMiniArray<z.ZodMiniObject<{
103
- dimension: z.ZodMiniString<string>;
104
- quota: z.ZodMiniNumber<number>;
105
- used: z.ZodMiniNumber<number>;
106
- remaining: z.ZodMiniNumber<number>;
107
- unit: z.ZodMiniString<string>;
108
- label: z.ZodMiniString<string>;
109
- resetAt: z.ZodMiniString<string>;
110
- approximateTokens: z.ZodMiniOptional<z.ZodMiniObject<{
111
- model: z.ZodMiniString<string>;
112
- tokens: z.ZodMiniNumber<number>;
113
- }, z.core.$strict>>;
114
- }, z.core.$strict>>;
115
- }, z.core.$strict>;
116
- /** `PATCH /billing/autotopup` echoes exactly the stored settings. */
117
- export declare const BillingAutoTopupResponseSchema: z.ZodMiniObject<{
118
- autoTopup: z.ZodMiniObject<{
119
- enabled: z.ZodMiniBoolean<boolean>;
120
- thresholdUsd: z.ZodMiniNumber<number>;
121
- amountUsd: z.ZodMiniNumber<number>;
122
- minimumAmountUsd: z.ZodMiniNumber<number>;
123
- maxPerDay: z.ZodMiniNumber<number>;
124
- }, z.core.$strict>;
125
- }, z.core.$strict>;
126
- /**
127
- * One row of `GET /billing/statements`.
128
- *
129
- * Only ISSUED periods are listed. A month whose statement did not reconcile is
130
- * withheld rather than rendered on demand, so an absent period is a statement
131
- * that was never issued — not one this read failed to find.
132
- *
133
- * `issuedAt` IS ISO-8601: the handler formats it, unlike the raw ledger
134
- * `createdAt` above.
135
- */
136
- export declare const BillingStatementSummarySchema: z.ZodMiniObject<{
137
- period: z.ZodMiniString<string>;
138
- issuedAt: z.ZodMiniString<string>;
139
- openingBalanceUsd: z.ZodMiniNumber<number>;
140
- creditsPurchasedUsd: z.ZodMiniNumber<number>;
141
- usageUsd: z.ZodMiniNumber<number>;
142
- adjustmentsUsd: z.ZodMiniNumber<number>;
143
- closingBalanceUsd: z.ZodMiniNumber<number>;
144
- }, z.core.$strict>;
145
- export declare const BillingStatementListResponseSchema: z.ZodMiniObject<{
146
- statements: z.ZodMiniArray<z.ZodMiniObject<{
147
- period: z.ZodMiniString<string>;
148
- issuedAt: z.ZodMiniString<string>;
149
- openingBalanceUsd: z.ZodMiniNumber<number>;
150
- creditsPurchasedUsd: z.ZodMiniNumber<number>;
151
- usageUsd: z.ZodMiniNumber<number>;
152
- adjustmentsUsd: z.ZodMiniNumber<number>;
153
- closingBalanceUsd: z.ZodMiniNumber<number>;
154
- }, z.core.$strict>>;
155
- }, z.core.$strict>;
156
- export declare const BillingLedgerEntrySchema: z.ZodMiniObject<{
157
- id: z.ZodMiniString<string>;
158
- entryType: z.ZodMiniString<string>;
159
- amountUsd: z.ZodMiniNumber<number>;
160
- currency: z.ZodMiniString<string>;
161
- sessionId: z.ZodMiniNullable<z.ZodMiniString<string>>;
162
- workspaceId: z.ZodMiniNullable<z.ZodMiniString<string>>;
163
- description: z.ZodMiniNullable<z.ZodMiniString<string>>;
164
- createdBy: z.ZodMiniString<string>;
165
- createdAt: z.ZodMiniString<string>;
166
- }, z.core.$strict>;
167
- export declare const BillingLedgerResponseSchema: z.ZodMiniObject<{
168
- entries: z.ZodMiniArray<z.ZodMiniObject<{
169
- id: z.ZodMiniString<string>;
170
- entryType: z.ZodMiniString<string>;
171
- amountUsd: z.ZodMiniNumber<number>;
172
- currency: z.ZodMiniString<string>;
173
- sessionId: z.ZodMiniNullable<z.ZodMiniString<string>>;
174
- workspaceId: z.ZodMiniNullable<z.ZodMiniString<string>>;
175
- description: z.ZodMiniNullable<z.ZodMiniString<string>>;
176
- createdBy: z.ZodMiniString<string>;
177
- createdAt: z.ZodMiniString<string>;
178
- }, z.core.$strict>>;
179
- }, z.core.$strict>;
180
- /** `POST /billing/topup/checkout` and `POST /billing/portal` both answer exactly `{ url }`. */
181
- export declare const BillingHostedSessionResponseSchema: z.ZodMiniObject<{
182
- url: z.ZodMiniString<string>;
183
- }, z.core.$strict>;
184
- export declare const AdminBillingTopupResponseSchema: z.ZodMiniObject<{
185
- ok: z.ZodMiniLiteral<true>;
186
- workspaceId: z.ZodMiniString<string>;
187
- orgId: z.ZodMiniString<string>;
188
- amountUsd: z.ZodMiniNumber<number>;
189
- inserted: z.ZodMiniBoolean<boolean>;
190
- balanceUsd: z.ZodMiniNumber<number>;
191
- }, z.core.$strict>;
192
- export declare const AdminBillingPaymentMethodResponseSchema: z.ZodMiniObject<{
193
- ok: z.ZodMiniLiteral<true>;
194
- workspaceId: z.ZodMiniString<string>;
195
- paymentMethodStatus: z.ZodMiniEnum<{
196
- none: "none";
197
- active: "active";
198
- }>;
199
- }, z.core.$strict>;
200
- export declare const AdminBillingAccountTypeResponseSchema: z.ZodMiniObject<{
201
- ok: z.ZodMiniLiteral<true>;
202
- workspaceId: z.ZodMiniString<string>;
203
- accountType: z.ZodMiniEnum<{
204
- standard: "standard";
205
- internal: "internal";
206
- }>;
207
- }, z.core.$strict>;
208
- export type BillingSummaryResponse = z.infer<typeof BillingSummaryResponseSchema>;
@@ -1,139 +0,0 @@
1
- /**
2
- * Response schemas for the `billing.*` and `adminBilling.*` families.
3
- *
4
- * Both `BillingSummary` and `BillingLedgerEntry` USED to carry
5
- * `[key: string]: unknown` — an explicit "additive server fields pass through"
6
- * promise. That promise is what made two real gaps invisible (`BillingSummary`
7
- * omitting `accountType`, `BillingLedgerEntry` omitting `workspaceId`), and it
8
- * is exactly what a strict response schema exists to stop being invisible. Both
9
- * signatures are now gone from the types as well, and both interfaces declare
10
- * every field the server sends.
11
- *
12
- * One gap remains, resolved in favour of the server (a schema that fails every
13
- * real response is not a gate): `workspaceId` on a ledger entry and on the three
14
- * admin routes is a RAW id, not the public `wsp_<hex>` form `whoami` and the
15
- * MCP-server records carry, so it is validated as a plain string.
16
- *
17
- * `createdAt` on a ledger entry is NOT ISO-8601: it is selected raw, so it
18
- * arrives as the Data API's `"YYYY-MM-DD HH:MM:SS"` text. It is validated as a
19
- * non-empty string, deliberately, and the inconsistency is reported rather than
20
- * encoded as if intended. `resetAt` and `blocked.at` ARE ISO-8601 — they are
21
- * constructed, not selected. `pastDueAt`, the third timestamp that used to sit
22
- * here, went with the plan catalog.
23
- */
24
- import * as z from "zod/mini";
25
- import { BILLING_ADMISSION_STATES } from "../billing-admission.js";
26
- import { describeResponse, responseObject, wireBoolean, wireEnum, wireLiteral, wireNonEmptyString, wireNumber, wireString, wireTimestamp } from "./response-common.js";
27
- /**
28
- * One free monthly allowance row inside `GET /billing`.
29
- *
30
- * `dimension`, `unit` and `label` are validated as non-empty strings rather than
31
- * as enums on purpose: the dimensions a free allowance is denominated in are
32
- * hosted billing policy, and pinning them here would put a second copy of that
33
- * policy in the public package — the exact duplication the prepaid model was
34
- * built to remove. The SHAPE is what this schema is for.
35
- *
36
- * `approximateTokens` rides only on the USD-denominated token allowance, and
37
- * only when there is usage to infer a model from.
38
- */
39
- export const BillingAllowanceSchema = describeResponse("BillingAllowance", "One free monthly allowance: quota, consumption and the instant it resets.", responseObject({
40
- dimension: wireNonEmptyString,
41
- quota: wireNumber,
42
- used: wireNumber,
43
- remaining: wireNumber,
44
- unit: wireNonEmptyString,
45
- label: wireNonEmptyString,
46
- resetAt: wireTimestamp,
47
- approximateTokens: z.optional(responseObject({ model: wireNonEmptyString, tokens: wireNumber }))
48
- }));
49
- /** Auto-recharge settings plus the two guards a top-up form has to respect. */
50
- export const BillingAutoTopupSchema = describeResponse("BillingAutoTopup", "Auto-recharge settings, the minimum accepted top-up and the daily recharge cap.", responseObject({
51
- enabled: wireBoolean,
52
- thresholdUsd: wireNumber,
53
- amountUsd: wireNumber,
54
- minimumAmountUsd: wireNumber,
55
- maxPerDay: wireNumber
56
- }));
57
- /**
58
- * `GET /billing`.
59
- *
60
- * `planKey`, `subscriptionStatus` and `pastDueAt` are GONE with the catalog they
61
- * described; a strict schema still expecting them fails C4 against the current
62
- * server. What replaces them is the prepaid surface: the period, the
63
- * card-derived `admissionState`, the allowance rows, the auto-recharge block,
64
- * the saved card, and any live block.
65
- */
66
- export const BillingSummaryResponseSchema = describeResponse("BillingSummaryResponse", "Workspace billing summary: prepaid balance, month-to-date spend, cap, free allowances and card state.", responseObject({
67
- balanceUsd: wireNumber,
68
- monthSpendUsd: wireNumber,
69
- spendCapUsd: wireNumber,
70
- period: wireNonEmptyString,
71
- admissionState: wireEnum(BILLING_ADMISSION_STATES),
72
- accountType: wireEnum(["standard", "internal"]),
73
- paymentMethodStatus: wireEnum(["none", "active"]),
74
- autoTopupEnabled: wireBoolean,
75
- blocked: z.nullable(responseObject({ at: wireTimestamp, reason: wireNonEmptyString })),
76
- paymentMethod: responseObject({
77
- present: wireBoolean,
78
- brand: z.nullable(wireString),
79
- last4: z.nullable(wireString)
80
- }),
81
- autoTopup: BillingAutoTopupSchema,
82
- allowances: z.array(BillingAllowanceSchema)
83
- }));
84
- /** `PATCH /billing/autotopup` echoes exactly the stored settings. */
85
- export const BillingAutoTopupResponseSchema = describeResponse("BillingAutoTopupResponse", "The stored auto-recharge settings after the update.", responseObject({ autoTopup: BillingAutoTopupSchema }));
86
- /**
87
- * One row of `GET /billing/statements`.
88
- *
89
- * Only ISSUED periods are listed. A month whose statement did not reconcile is
90
- * withheld rather than rendered on demand, so an absent period is a statement
91
- * that was never issued — not one this read failed to find.
92
- *
93
- * `issuedAt` IS ISO-8601: the handler formats it, unlike the raw ledger
94
- * `createdAt` above.
95
- */
96
- export const BillingStatementSummarySchema = describeResponse("BillingStatementSummary", "One issued monthly statement: the period, when it was issued, and the five " +
97
- "figures that reconcile opening balance to closing.", responseObject({
98
- period: wireNonEmptyString,
99
- issuedAt: wireTimestamp,
100
- openingBalanceUsd: wireNumber,
101
- creditsPurchasedUsd: wireNumber,
102
- usageUsd: wireNumber,
103
- adjustmentsUsd: wireNumber,
104
- closingBalanceUsd: wireNumber
105
- }));
106
- export const BillingStatementListResponseSchema = describeResponse("BillingStatementListResponse", "The months a customer can download, newest first. Bounded server-side; not cursor-paged.", responseObject({ statements: z.array(BillingStatementSummarySchema) }));
107
- export const BillingLedgerEntrySchema = describeResponse("BillingLedgerEntry", "One signed credit-ledger row. Top-ups are positive, run charges negative.", responseObject({
108
- id: wireNonEmptyString,
109
- entryType: wireNonEmptyString,
110
- amountUsd: wireNumber,
111
- currency: wireNonEmptyString,
112
- sessionId: z.nullable(wireString),
113
- workspaceId: z.nullable(wireString),
114
- description: z.nullable(wireString),
115
- createdBy: wireString,
116
- createdAt: wireNonEmptyString
117
- }));
118
- export const BillingLedgerResponseSchema = describeResponse("BillingLedgerResponse", "Recent credit-ledger rows, newest first. Bounded by `limit`; not cursor-paged.", responseObject({ entries: z.array(BillingLedgerEntrySchema) }));
119
- /** `POST /billing/topup/checkout` and `POST /billing/portal` both answer exactly `{ url }`. */
120
- export const BillingHostedSessionResponseSchema = describeResponse("BillingHostedSessionResponse", "A hosted checkout or billing-portal session. The client should open `url`.", responseObject({ url: wireNonEmptyString }));
121
- export const AdminBillingTopupResponseSchema = describeResponse("AdminBillingTopupResponse", "Operator credit grant. `inserted` is false on an idempotent replay; " +
122
- "`balanceUsd` is the authoritative post-state either way.", responseObject({
123
- ok: wireLiteral(true),
124
- workspaceId: wireNonEmptyString,
125
- orgId: wireNonEmptyString,
126
- amountUsd: wireNumber,
127
- inserted: wireBoolean,
128
- balanceUsd: wireNumber
129
- }));
130
- export const AdminBillingPaymentMethodResponseSchema = describeResponse("AdminBillingPaymentMethodResponse", "Operator payment-method override, echoing the applied status.", responseObject({
131
- ok: wireLiteral(true),
132
- workspaceId: wireNonEmptyString,
133
- paymentMethodStatus: wireEnum(["none", "active"])
134
- }));
135
- export const AdminBillingAccountTypeResponseSchema = describeResponse("AdminBillingAccountTypeResponse", "Operator account-type override, echoing the applied type.", responseObject({
136
- ok: wireLiteral(true),
137
- workspaceId: wireNonEmptyString,
138
- accountType: wireEnum(["standard", "internal"])
139
- }));
@@ -1,132 +0,0 @@
1
- /**
2
- * Shared machinery for the RESPONSE half of the wire contract (C4 / P3).
3
- *
4
- * The request schemas answer "what may a caller send". These answer "what did
5
- * the server actually send", and they are checked against real bytes by
6
- * {@link import("../testing/wire-conformance.js").installWireConformance} rather
7
- * than by anything on the request path. That is the whole value: it is the one
8
- * gate in the contract pipeline that observes reality instead of comparing two
9
- * of our own artefacts to each other.
10
- *
11
- * Three rules the modules in this family follow:
12
- *
13
- * 1. **Strict.** Every response object is a {@link responseObject}, i.e. a
14
- * `z.strictObject`. A field the server added and we never declared FAILS the
15
- * suite. That generalises what `parseWhoAmI` did by hand for three removed
16
- * fields (`caps`, `tokenId`, `tokenName`) to the whole surface. Several of
17
- * our own declared types used to carry `[key: string]: unknown` — an explicit
18
- * "additive server fields pass through" promise — and these schemas
19
- * deliberately did not honour it. They no longer have to: an index signature
20
- * makes EVERY undeclared field structurally legal, which is how
21
- * `BillingSummary` came to omit two fields the server always sends without
22
- * anything being able to notice. The signatures are gone from the types too.
23
- * 2. **No `.transform()`.** `z.toJSONSchema(s, { io: "output" })` throws on any
24
- * transform, which would make the response half of the generated spec
25
- * ungenerable. Schemas validate; `normalize*()` functions transform.
26
- * 3. **`zod/mini` only**, like every other module in this directory.
27
- */
28
- import * as z from "zod/mini";
29
- /**
30
- * Metadata registry for response schemas.
31
- *
32
- * Deliberately NOT `z.globalRegistry`. The OpenAPI generator converts
33
- * `OPENAPI_SCHEMA_REGISTRY`, and that constant *is* `z.globalRegistry` — so
34
- * registering a response schema there would silently add a component to
35
- * `openapi/data-plane.json`, break the committed-spec freshness gate (C3), and
36
- * do it as a side effect of merely importing this file. Response schemas are not
37
- * referenced by any generated operation yet (`scripts/openapi/generate.ts` still
38
- * emits `"2XX": { description: "Success." }`), so an entry there would be an
39
- * unreferenced component describing nothing.
40
- *
41
- * When the generator learns to declare responses, this registry is what it
42
- * converts — the ids below are already the component names.
43
- */
44
- export declare const responseSchemaRegistry: z.core.$ZodRegistry<{
45
- readonly id: string;
46
- readonly description: string;
47
- }, z.core.$ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>;
48
- /**
49
- * A strict response object.
50
- *
51
- * Paths are resolved against the ROOT of the parse rather than anchored on a
52
- * fixed name, so a nested object reports its real position
53
- * (`response.session.currentRun.phase`) instead of doubling a segment — the trap
54
- * the port measured and `08-refined-plan.md` records.
55
- */
56
- export declare function responseObject<Shape extends z.core.$ZodLooseShape>(shape: Shape): z.ZodMiniObject<Shape, z.core.$strict>;
57
- /**
58
- * Attach the component id and prose a spec consumer needs.
59
- *
60
- * `.meta()` does not exist on `zod/mini` schemas; `.register()` is the mini
61
- * equivalent and is what every metadata instruction in the plan documents means.
62
- */
63
- export declare function describeResponse<Schema extends z.core.$ZodType>(id: string, description: string, schema: Schema): Schema;
64
- export declare const wireString: z.ZodMiniString<string>;
65
- /**
66
- * A string the hand-written parsers already required to be non-empty (ids,
67
- * statuses, timestamps). Asserting less than the client already asserts would
68
- * make C4 weaker than the code it is meant to backstop.
69
- */
70
- export declare const wireNonEmptyString: z.ZodMiniString<string>;
71
- /** A finite number. `z.number()` already rejects `NaN` and `±Infinity` (measured). */
72
- export declare const wireNumber: z.ZodMiniNumber<number>;
73
- export declare const wireNonNegativeNumber: z.ZodMiniNumber<number>;
74
- export declare const wireInteger: z.ZodMiniNumberFormat;
75
- export declare const wireNonNegativeInteger: z.ZodMiniNumberFormat;
76
- export declare const wirePositiveInteger: z.ZodMiniNumberFormat;
77
- export declare const wireBoolean: z.ZodMiniBoolean<boolean>;
78
- /** An ISO-8601 timestamp, judged the way the parsers judge one: `Date.parse` succeeds. */
79
- export declare const wireTimestamp: z.ZodMiniString<string>;
80
- /** A closed vocabulary. The message names the accepted values, as the parsers do. */
81
- export declare function wireEnum<const Values extends readonly [string, ...string[]]>(values: Values): z.ZodMiniEnum<{ [k_1 in Values[number]]: k_1; } extends infer T ? { [k in keyof T]: { [k_1 in Values[number]]: k_1; }[k]; } : never>;
82
- /** A literal the server always sends verbatim (`ok: true`, `kind: "file"`). */
83
- export declare function wireLiteral<const Value extends string | number | boolean>(value: Value): z.ZodMiniLiteral<Value>;
84
- /**
85
- * The empty JSON body an HTTP 204 becomes by the time the harness sees it.
86
- *
87
- * `HttpClient.request` reads the body as text and returns `{}` for a zero-length
88
- * one, so a 204 arrives at the observer as an empty object. Declaring it as a
89
- * strict empty object is a real assertion — a route that starts returning
90
- * content fails.
91
- */
92
- export declare const NoContentResponseSchema: z.ZodMiniObject<{}, z.core.$strict>;
93
- /**
94
- * The error envelope EVERY operation declares — and, until now, the only
95
- * declared response nothing ever checked.
96
- *
97
- * `scripts/openapi/generate.ts` gives all 68 operations a `default` response of
98
- * `#/components/schemas/ApiErrorEnvelope`. C4 could not see it, because
99
- * `HttpClient.request` threw on a non-2xx *before* reporting to the wire
100
- * observer, so the harness only ever met 2xx bodies. Both halves move together:
101
- * the report now happens ahead of the throw, and this is what the reported body
102
- * is checked against.
103
- *
104
- * ## Why this one is NOT a `responseObject`
105
- *
106
- * Every other schema in this family is strict, deliberately — an undeclared
107
- * field should fail the suite. The generated component declares
108
- * `additionalProperties: true`, and it is right to: the envelope is a BASE that
109
- * individual codes extend. `session_busy` adds the session's current `status`,
110
- * `rate_limited` adds `retryAfterMs`, `content_deleted` adds `sessionId` /
111
- * `purgedAt` / `deletedBy`, an auth failure adds `requiredScope` —
112
- * `error-factory.ts` reads every one of them. Declaring this strict would fail
113
- * the suite on error bodies our own client is built to consume, which is
114
- * inventing a contract rather than checking one.
115
- *
116
- * ## What it therefore does assert
117
- *
118
- * That a non-2xx JSON body carries the two fields the spec marks required — a
119
- * stable machine-readable `error` code and a human `message` — and that
120
- * `requestId`, when present, is a string. That is a real assertion about the
121
- * wire, not a tautology: the lambda's `finalizeApiResponse` only defaults a
122
- * `message` for codes present in its `API_ERROR_MESSAGES` table, and only
123
- * rewrites a body that already carries an `error` or a `code`. A rejection
124
- * produced anywhere other than a route handler — an API-Gateway-native 403, say
125
- * — carries neither and surfaces here as a violation. That is a FINDING about
126
- * the declared contract; do not loosen this schema to make such a body pass.
127
- */
128
- export declare const ApiErrorEnvelopeSchema: z.ZodMiniObject<{
129
- error: z.ZodMiniString<string>;
130
- message: z.ZodMiniString<string>;
131
- requestId: z.ZodMiniOptional<z.ZodMiniString<string>>;
132
- }, z.core.$loose>;
@@ -1,162 +0,0 @@
1
- /**
2
- * Shared machinery for the RESPONSE half of the wire contract (C4 / P3).
3
- *
4
- * The request schemas answer "what may a caller send". These answer "what did
5
- * the server actually send", and they are checked against real bytes by
6
- * {@link import("../testing/wire-conformance.js").installWireConformance} rather
7
- * than by anything on the request path. That is the whole value: it is the one
8
- * gate in the contract pipeline that observes reality instead of comparing two
9
- * of our own artefacts to each other.
10
- *
11
- * Three rules the modules in this family follow:
12
- *
13
- * 1. **Strict.** Every response object is a {@link responseObject}, i.e. a
14
- * `z.strictObject`. A field the server added and we never declared FAILS the
15
- * suite. That generalises what `parseWhoAmI` did by hand for three removed
16
- * fields (`caps`, `tokenId`, `tokenName`) to the whole surface. Several of
17
- * our own declared types used to carry `[key: string]: unknown` — an explicit
18
- * "additive server fields pass through" promise — and these schemas
19
- * deliberately did not honour it. They no longer have to: an index signature
20
- * makes EVERY undeclared field structurally legal, which is how
21
- * `BillingSummary` came to omit two fields the server always sends without
22
- * anything being able to notice. The signatures are gone from the types too.
23
- * 2. **No `.transform()`.** `z.toJSONSchema(s, { io: "output" })` throws on any
24
- * transform, which would make the response half of the generated spec
25
- * ungenerable. Schemas validate; `normalize*()` functions transform.
26
- * 3. **`zod/mini` only**, like every other module in this directory.
27
- */
28
- import * as z from "zod/mini";
29
- import { wireObject, wirePath } from "./wire.js";
30
- /**
31
- * Metadata registry for response schemas.
32
- *
33
- * Deliberately NOT `z.globalRegistry`. The OpenAPI generator converts
34
- * `OPENAPI_SCHEMA_REGISTRY`, and that constant *is* `z.globalRegistry` — so
35
- * registering a response schema there would silently add a component to
36
- * `openapi/data-plane.json`, break the committed-spec freshness gate (C3), and
37
- * do it as a side effect of merely importing this file. Response schemas are not
38
- * referenced by any generated operation yet (`scripts/openapi/generate.ts` still
39
- * emits `"2XX": { description: "Success." }`), so an entry there would be an
40
- * unreferenced component describing nothing.
41
- *
42
- * When the generator learns to declare responses, this registry is what it
43
- * converts — the ids below are already the component names.
44
- */
45
- export const responseSchemaRegistry = z.registry();
46
- /** Render the position of an issue as a wire path rooted at the response body. */
47
- function responsePath(issuePath) {
48
- return wirePath("response", issuePath);
49
- }
50
- function expected(description) {
51
- return (issue) => `${responsePath(issue.path ?? [])} must be ${description}`;
52
- }
53
- /**
54
- * A strict response object.
55
- *
56
- * Paths are resolved against the ROOT of the parse rather than anchored on a
57
- * fixed name, so a nested object reports its real position
58
- * (`response.session.currentRun.phase`) instead of doubling a segment — the trap
59
- * the port measured and `08-refined-plan.md` records.
60
- */
61
- export function responseObject(shape) {
62
- return wireObject(responsePath, shape, {
63
- notObject: (path) => `${path} must be an object`,
64
- unknownKey: (path, key, permitted) => `${path}.${key} is not a declared response field; declared: ${permitted.join(", ")}`
65
- });
66
- }
67
- /**
68
- * Attach the component id and prose a spec consumer needs.
69
- *
70
- * `.meta()` does not exist on `zod/mini` schemas; `.register()` is the mini
71
- * equivalent and is what every metadata instruction in the plan documents means.
72
- */
73
- export function describeResponse(id, description, schema) {
74
- responseSchemaRegistry.add(schema, { id, description });
75
- return schema;
76
- }
77
- // ===========================================================================
78
- // Field primitives
79
- //
80
- // One instance each, shared across every response shape. Zod schemas are
81
- // immutable, and the message is derived from the issue's own path, so a single
82
- // `wireString` reports `response.session.id must be a string` in one object and
83
- // `response.entries[3].currency must be a string` in another.
84
- // ===========================================================================
85
- export const wireString = z.string({ error: expected("a string") });
86
- /**
87
- * A string the hand-written parsers already required to be non-empty (ids,
88
- * statuses, timestamps). Asserting less than the client already asserts would
89
- * make C4 weaker than the code it is meant to backstop.
90
- */
91
- export const wireNonEmptyString = z.string({ error: expected("a non-empty string") }).check(z.refine((value) => value.length > 0, { error: expected("a non-empty string") }));
92
- /** A finite number. `z.number()` already rejects `NaN` and `±Infinity` (measured). */
93
- export const wireNumber = z.number({ error: expected("a finite number") });
94
- export const wireNonNegativeNumber = z.number({ error: expected("a non-negative finite number") }).check(z.refine((value) => value >= 0, { error: expected("a non-negative finite number") }));
95
- export const wireInteger = z.int({ error: expected("a safe integer") });
96
- export const wireNonNegativeInteger = z.int({ error: expected("a non-negative safe integer") }).check(z.refine((value) => value >= 0, { error: expected("a non-negative safe integer") }));
97
- export const wirePositiveInteger = z.int({ error: expected("a positive safe integer") }).check(z.refine((value) => value >= 1, { error: expected("a positive safe integer") }));
98
- export const wireBoolean = z.boolean({ error: expected("a boolean") });
99
- /** An ISO-8601 timestamp, judged the way the parsers judge one: `Date.parse` succeeds. */
100
- export const wireTimestamp = z.string({ error: expected("an ISO-8601 timestamp") }).check(z.refine((value) => Number.isFinite(Date.parse(value)), {
101
- error: expected("an ISO-8601 timestamp")
102
- }));
103
- /** A closed vocabulary. The message names the accepted values, as the parsers do. */
104
- export function wireEnum(values) {
105
- return z.enum(values, { error: expected(`one of: ${values.join(", ")}`) });
106
- }
107
- /** A literal the server always sends verbatim (`ok: true`, `kind: "file"`). */
108
- export function wireLiteral(value) {
109
- return z.literal(value, { error: expected(JSON.stringify(value)) });
110
- }
111
- /**
112
- * The empty JSON body an HTTP 204 becomes by the time the harness sees it.
113
- *
114
- * `HttpClient.request` reads the body as text and returns `{}` for a zero-length
115
- * one, so a 204 arrives at the observer as an empty object. Declaring it as a
116
- * strict empty object is a real assertion — a route that starts returning
117
- * content fails.
118
- */
119
- export const NoContentResponseSchema = describeResponse("NoContentResponse", "An HTTP 204 with no body. `HttpClient` renders a zero-length body as `{}`, " +
120
- "so the assertion is that the route sends nothing at all.", responseObject({}));
121
- /**
122
- * The error envelope EVERY operation declares — and, until now, the only
123
- * declared response nothing ever checked.
124
- *
125
- * `scripts/openapi/generate.ts` gives all 68 operations a `default` response of
126
- * `#/components/schemas/ApiErrorEnvelope`. C4 could not see it, because
127
- * `HttpClient.request` threw on a non-2xx *before* reporting to the wire
128
- * observer, so the harness only ever met 2xx bodies. Both halves move together:
129
- * the report now happens ahead of the throw, and this is what the reported body
130
- * is checked against.
131
- *
132
- * ## Why this one is NOT a `responseObject`
133
- *
134
- * Every other schema in this family is strict, deliberately — an undeclared
135
- * field should fail the suite. The generated component declares
136
- * `additionalProperties: true`, and it is right to: the envelope is a BASE that
137
- * individual codes extend. `session_busy` adds the session's current `status`,
138
- * `rate_limited` adds `retryAfterMs`, `content_deleted` adds `sessionId` /
139
- * `purgedAt` / `deletedBy`, an auth failure adds `requiredScope` —
140
- * `error-factory.ts` reads every one of them. Declaring this strict would fail
141
- * the suite on error bodies our own client is built to consume, which is
142
- * inventing a contract rather than checking one.
143
- *
144
- * ## What it therefore does assert
145
- *
146
- * That a non-2xx JSON body carries the two fields the spec marks required — a
147
- * stable machine-readable `error` code and a human `message` — and that
148
- * `requestId`, when present, is a string. That is a real assertion about the
149
- * wire, not a tautology: the lambda's `finalizeApiResponse` only defaults a
150
- * `message` for codes present in its `API_ERROR_MESSAGES` table, and only
151
- * rewrites a body that already carries an `error` or a `code`. A rejection
152
- * produced anywhere other than a route handler — an API-Gateway-native 403, say
153
- * — carries neither and surfaces here as a violation. That is a FINDING about
154
- * the declared contract; do not loosen this schema to make such a body pass.
155
- */
156
- export const ApiErrorEnvelopeSchema = describeResponse("ApiErrorEnvelope", "The body every non-2xx response carries: a stable `error` code, a human " +
157
- "`message`, and the `requestId` to quote in a support request. Open by " +
158
- "design — individual codes extend it with their own fields.", z.looseObject({
159
- error: wireNonEmptyString,
160
- message: wireString,
161
- requestId: z.optional(wireString)
162
- }, { error: (issue) => `${responsePath(issue.path ?? [])} must be an object` }));