@workerstack/clients 1.0.0-rc.28 → 1.0.0-rc.30

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 (368) hide show
  1. package/README.md +403 -21
  2. package/assets/installers/examples/github.config.ts +17 -19
  3. package/assets/installers/examples/goreleaser.config.ts +16 -18
  4. package/assets/installers/examples/raw.config.ts +13 -15
  5. package/bin/clients.js +87 -66
  6. package/bin/installgen.js +19 -10
  7. package/dist/cli.d.ts +4 -4
  8. package/dist/cli.js +18 -12
  9. package/dist/emit/cli/channels.d.ts +2 -2
  10. package/dist/emit/cli/channels.js +18 -13
  11. package/dist/emit/cli/commands.d.ts +1 -1
  12. package/dist/emit/cli/commands.js +39 -13
  13. package/dist/emit/cli/discovery.d.ts +0 -6
  14. package/dist/emit/cli/discovery.js +9 -7
  15. package/dist/emit/cli/flags.d.ts +1 -3
  16. package/dist/emit/cli/flags.js +18 -8
  17. package/dist/emit/cli/install.d.ts +0 -8
  18. package/dist/emit/cli/install.js +3 -3
  19. package/dist/emit/cli/layout.d.ts +1 -1
  20. package/dist/emit/cli/layout.js +13 -10
  21. package/dist/emit/cli/module.d.ts +6 -6
  22. package/dist/emit/cli/module.js +10 -10
  23. package/dist/emit/cli/release.d.ts +0 -11
  24. package/dist/emit/cli/release.js +4 -4
  25. package/dist/emit/cli/skills.js +8 -4
  26. package/dist/emit/csharp/errors.js +4 -4
  27. package/dist/emit/csharp/json.js +8 -8
  28. package/dist/emit/csharp/realtime.d.ts +1 -8
  29. package/dist/emit/csharp/realtime.js +26 -26
  30. package/dist/emit/csharp/sdk-answer.d.ts +10 -2
  31. package/dist/emit/csharp/sdk-answer.js +4 -4
  32. package/dist/emit/csharp/sdk-body.js +8 -6
  33. package/dist/emit/csharp/sdk-client.d.ts +3 -3
  34. package/dist/emit/csharp/sdk-client.js +2 -2
  35. package/dist/emit/csharp/sdk-csproj.d.ts +7 -9
  36. package/dist/emit/csharp/sdk-csproj.js +10 -10
  37. package/dist/emit/csharp/sdk-doc.js +1 -1
  38. package/dist/emit/csharp/sdk-method.d.ts +0 -1
  39. package/dist/emit/csharp/sdk-method.js +19 -8
  40. package/dist/emit/csharp/sdk-plan.js +0 -1
  41. package/dist/emit/csharp/sdk.js +3 -3
  42. package/dist/emit/csharp/sse.d.ts +0 -13
  43. package/dist/emit/csharp/sse.js +92 -11
  44. package/dist/emit/csharp/transport.js +9 -9
  45. package/dist/emit/csharp/types-enum.js +3 -1
  46. package/dist/emit/csharp/types-messages.d.ts +47 -0
  47. package/dist/emit/csharp/types-messages.js +172 -0
  48. package/dist/emit/csharp/types-names.js +13 -14
  49. package/dist/emit/csharp/types-record.js +3 -3
  50. package/dist/emit/csharp/types-union.d.ts +1 -1
  51. package/dist/emit/csharp/types.d.ts +0 -1
  52. package/dist/emit/csharp/types.js +3 -3
  53. package/dist/emit/csharp/ws.d.ts +0 -15
  54. package/dist/emit/csharp/ws.js +26 -5
  55. package/dist/emit/go/errors.js +1 -1
  56. package/dist/emit/go/http.js +2 -2
  57. package/dist/emit/go/module-path.js +2 -2
  58. package/dist/emit/go/sdk-answer.d.ts +24 -1
  59. package/dist/emit/go/sdk-answer.js +1 -1
  60. package/dist/emit/go/sdk-body.js +11 -7
  61. package/dist/emit/go/sdk-client.js +1 -1
  62. package/dist/emit/go/sdk-method.d.ts +3 -0
  63. package/dist/emit/go/sdk-method.js +18 -12
  64. package/dist/emit/go/sdk-mirror.js +2 -2
  65. package/dist/emit/go/sdk-opts.d.ts +0 -2
  66. package/dist/emit/go/sdk-opts.js +3 -3
  67. package/dist/emit/go/sdk.d.ts +1 -1
  68. package/dist/emit/go/sdk.js +9 -9
  69. package/dist/emit/go/sse.d.ts +2 -10
  70. package/dist/emit/go/sse.js +88 -13
  71. package/dist/emit/go/types-names.js +5 -0
  72. package/dist/emit/go/types-struct.d.ts +2 -1
  73. package/dist/emit/go/types-struct.js +1 -1
  74. package/dist/emit/go/types-union.d.ts +3 -2
  75. package/dist/emit/go/types-union.js +2 -0
  76. package/dist/emit/go/types.d.ts +6 -0
  77. package/dist/emit/go/types.js +20 -9
  78. package/dist/emit/go/ws.d.ts +4 -11
  79. package/dist/emit/go/ws.js +215 -59
  80. package/dist/emit/java/gradle.d.ts +7 -9
  81. package/dist/emit/java/gradle.js +8 -8
  82. package/dist/emit/java/json.d.ts +3 -0
  83. package/dist/emit/java/json.js +1 -1
  84. package/dist/emit/java/layout-ast.d.ts +4 -1
  85. package/dist/emit/java/layout-ast.js +1 -1
  86. package/dist/emit/java/layout-decl.js +5 -4
  87. package/dist/emit/java/layout-doc.js +13 -7
  88. package/dist/emit/java/layout-dot.js +1 -1
  89. package/dist/emit/java/layout-strings.js +4 -5
  90. package/dist/emit/java/layout-types.js +7 -5
  91. package/dist/emit/java/layout-visitor.js +4 -3
  92. package/dist/emit/java/layout.js +5 -4
  93. package/dist/emit/java/models-names.d.ts +2 -0
  94. package/dist/emit/java/models-names.js +6 -4
  95. package/dist/emit/java/models-record.d.ts +0 -1
  96. package/dist/emit/java/models-record.js +3 -3
  97. package/dist/emit/java/models-union.d.ts +13 -2
  98. package/dist/emit/java/models-union.js +12 -6
  99. package/dist/emit/java/models.d.ts +5 -1
  100. package/dist/emit/java/models.js +44 -20
  101. package/dist/emit/java/realtime.d.ts +34 -26
  102. package/dist/emit/java/realtime.js +45 -10
  103. package/dist/emit/java/sdk-client.d.ts +6 -6
  104. package/dist/emit/java/sdk-client.js +1 -1
  105. package/dist/emit/java/sdk-decl.js +2 -2
  106. package/dist/emit/java/sdk-errors.js +1 -1
  107. package/dist/emit/java/sdk-headers.js +2 -2
  108. package/dist/emit/java/sdk-mirror.js +7 -6
  109. package/dist/emit/java/sdk-models.d.ts +1 -1
  110. package/dist/emit/java/sdk-models.js +7 -7
  111. package/dist/emit/java/sdk-op.d.ts +1 -10
  112. package/dist/emit/java/sdk-op.js +9 -9
  113. package/dist/emit/java/sdk-params.d.ts +5 -5
  114. package/dist/emit/java/sdk-params.js +3 -2
  115. package/dist/emit/java/sdk-plan.js +0 -1
  116. package/dist/emit/java/sdk.d.ts +1 -1
  117. package/dist/emit/java/sdk.js +14 -13
  118. package/dist/emit/java/sse.d.ts +12 -13
  119. package/dist/emit/java/sse.js +105 -6
  120. package/dist/emit/java/ws.d.ts +48 -9
  121. package/dist/emit/java/ws.js +88 -4
  122. package/dist/emit/mcp/annotations.js +8 -4
  123. package/dist/emit/mcp/files.js +9 -9
  124. package/dist/emit/mcp/mounted.js +2 -2
  125. package/dist/emit/mcp/output-schema.d.ts +4 -2
  126. package/dist/emit/mcp/output-schema.js +58 -14
  127. package/dist/emit/mcp/registry.d.ts +0 -2
  128. package/dist/emit/mcp/registry.js +5 -4
  129. package/dist/emit/mcp/runtime.js +2 -2
  130. package/dist/emit/mcp/schema.js +22 -11
  131. package/dist/emit/mcp/server.d.ts +7 -7
  132. package/dist/emit/mcp/server.js +7 -6
  133. package/dist/emit/mcp/tools.js +7 -6
  134. package/dist/emit/python/errors.js +3 -3
  135. package/dist/emit/python/realtime.d.ts +9 -6
  136. package/dist/emit/python/realtime.js +22 -20
  137. package/dist/emit/python/sdk-answer.d.ts +8 -8
  138. package/dist/emit/python/sdk-answer.js +2 -2
  139. package/dist/emit/python/sdk-body.js +4 -5
  140. package/dist/emit/python/sdk-client.js +5 -5
  141. package/dist/emit/python/sdk-doc.js +2 -2
  142. package/dist/emit/python/sdk-method.d.ts +1 -1
  143. package/dist/emit/python/sdk-method.js +38 -11
  144. package/dist/emit/python/sdk-plan.js +0 -1
  145. package/dist/emit/python/sdk-pyproject.d.ts +0 -2
  146. package/dist/emit/python/sdk-pyproject.js +8 -8
  147. package/dist/emit/python/sdk.d.ts +1 -1
  148. package/dist/emit/python/sdk.js +28 -8
  149. package/dist/emit/python/sse.d.ts +0 -7
  150. package/dist/emit/python/sse.js +36 -6
  151. package/dist/emit/python/transport.js +4 -4
  152. package/dist/emit/python/types-dict.d.ts +2 -2
  153. package/dist/emit/python/types-dict.js +1 -1
  154. package/dist/emit/python/types-names.js +2 -2
  155. package/dist/emit/python/types-union.js +1 -1
  156. package/dist/emit/python/types.d.ts +7 -0
  157. package/dist/emit/python/types.js +23 -6
  158. package/dist/emit/python/ws.d.ts +21 -10
  159. package/dist/emit/python/ws.js +69 -3
  160. package/dist/emit/rust/errors.js +3 -3
  161. package/dist/emit/rust/http.js +4 -4
  162. package/dist/emit/rust/realtime.d.ts +7 -5
  163. package/dist/emit/rust/realtime.js +15 -18
  164. package/dist/emit/rust/sdk-body.js +8 -5
  165. package/dist/emit/rust/sdk-cargo.d.ts +16 -18
  166. package/dist/emit/rust/sdk-cargo.js +12 -12
  167. package/dist/emit/rust/sdk-client.d.ts +1 -1
  168. package/dist/emit/rust/sdk-client.js +3 -3
  169. package/dist/emit/rust/sdk-method.js +3 -3
  170. package/dist/emit/rust/sdk-opts.d.ts +2 -1
  171. package/dist/emit/rust/sdk-opts.js +2 -2
  172. package/dist/emit/rust/sdk-plan.js +0 -1
  173. package/dist/emit/rust/sdk.d.ts +1 -1
  174. package/dist/emit/rust/sdk.js +5 -5
  175. package/dist/emit/rust/sse.d.ts +11 -12
  176. package/dist/emit/rust/sse.js +54 -8
  177. package/dist/emit/rust/types-names.js +3 -3
  178. package/dist/emit/rust/types-struct.js +1 -1
  179. package/dist/emit/rust/types-union.d.ts +10 -2
  180. package/dist/emit/rust/types-union.js +4 -0
  181. package/dist/emit/rust/types.d.ts +9 -0
  182. package/dist/emit/rust/types.js +20 -12
  183. package/dist/emit/rust/ws.d.ts +22 -15
  184. package/dist/emit/rust/ws.js +60 -10
  185. package/dist/emit/shared/escape.js +17 -17
  186. package/dist/emit/shared/format.js +1 -1
  187. package/dist/emit/shared/gofmt.js +1 -1
  188. package/dist/emit/shared/lang.js +10 -10
  189. package/dist/emit/shared/literals.d.ts +5 -0
  190. package/dist/emit/shared/literals.js +8 -0
  191. package/dist/emit/shared/metadata.d.ts +0 -6
  192. package/dist/emit/shared/metadata.js +8 -7
  193. package/dist/emit/shared/ruff.js +1 -1
  194. package/dist/emit/shared/rustfmt.js +1 -1
  195. package/dist/emit/shared/type-emitter.js +37 -20
  196. package/dist/emit/shared/unknown-type.constants.d.ts +2 -0
  197. package/dist/emit/shared/unknown-type.constants.js +2 -0
  198. package/dist/emit/ts/http.d.ts +0 -2
  199. package/dist/emit/ts/http.js +4 -4
  200. package/dist/emit/ts/package.d.ts +14 -12
  201. package/dist/emit/ts/package.js +9 -8
  202. package/dist/emit/ts/route-tree.js +2 -2
  203. package/dist/emit/ts/sdk-types-preamble.d.ts +1 -1
  204. package/dist/emit/ts/sdk-types-preamble.js +6 -2
  205. package/dist/emit/ts/sdk-types.js +59 -20
  206. package/dist/emit/ts/sdk.js +6 -6
  207. package/dist/emit/ts/service-map.d.ts +10 -3
  208. package/dist/emit/ts/service-map.js +30 -2
  209. package/dist/emit/ts/tanstack-query.js +6 -6
  210. package/dist/emit/ts/type-gen.js +36 -21
  211. package/dist/emit/ts/webhooks.d.ts +0 -2
  212. package/dist/emit/ts/webhooks.js +3 -3
  213. package/dist/extract/chain.js +5 -4
  214. package/dist/extract/extract.js +5 -5
  215. package/dist/extract/serialize.d.ts +0 -2
  216. package/dist/extract/serialize.js +14 -15
  217. package/dist/extract/walk.js +15 -12
  218. package/dist/gen/args.js +9 -5
  219. package/dist/gen/formatters.js +5 -3
  220. package/dist/gen/shipped.js +2 -2
  221. package/dist/gen/targets.d.ts +2 -4
  222. package/dist/gen/targets.js +8 -4
  223. package/dist/gen/write.js +4 -2
  224. package/dist/index.js +2 -2
  225. package/dist/installers/cli.d.ts +4 -4
  226. package/dist/installers/cli.js +24 -24
  227. package/dist/installers/commands/build.d.ts +4 -4
  228. package/dist/installers/commands/build.js +2 -3
  229. package/dist/installers/commands/check.d.ts +2 -2
  230. package/dist/installers/commands/check.js +11 -10
  231. package/dist/installers/commands/init.d.ts +2 -2
  232. package/dist/installers/commands/init.js +1 -2
  233. package/dist/installers/config/define-config.d.ts +16 -16
  234. package/dist/installers/config/define-config.js +1 -1
  235. package/dist/installers/config/hooks/bun.d.ts +6 -6
  236. package/dist/installers/config/hooks/node.js +1 -1
  237. package/dist/installers/config/load.d.ts +6 -8
  238. package/dist/installers/config/load.js +7 -8
  239. package/dist/installers/config/resolve.d.ts +1 -2
  240. package/dist/installers/config/resolve.js +28 -33
  241. package/dist/installers/config/types.d.ts +6 -6
  242. package/dist/installers/config/types.js +0 -1
  243. package/dist/installers/render/quote.js +3 -5
  244. package/dist/installers/render/render.d.ts +6 -6
  245. package/dist/installers/render/render.js +26 -26
  246. package/dist/installers/ui.d.ts +4 -4
  247. package/dist/installers/ui.js +3 -3
  248. package/dist/ir/build.d.ts +3 -3
  249. package/dist/ir/build.js +12 -5
  250. package/dist/ir/load.js +9 -10
  251. package/dist/ir/model.d.ts +16 -1
  252. package/dist/ir/model.js +0 -1
  253. package/dist/ir/resolve-refs.js +2 -2
  254. package/dist/ir/resource-tree.js +2 -1
  255. package/dist/ir/route-tree-intern.js +1 -1
  256. package/dist/ir/schema.js +3 -3
  257. package/dist/ir/sdk-model.d.ts +25 -1
  258. package/dist/ir/sdk-model.js +38 -8
  259. package/dist/ir/slots.d.ts +1 -1
  260. package/dist/ir/slots.js +22 -11
  261. package/dist/ir/streams.d.ts +16 -0
  262. package/dist/ir/streams.js +40 -0
  263. package/dist/release/bootstrap.d.ts +3 -3
  264. package/dist/release/bootstrap.js +7 -7
  265. package/dist/release/bump-args.js +4 -4
  266. package/dist/release/bump-command.d.ts +1 -1
  267. package/dist/release/bump-command.js +9 -10
  268. package/dist/release/bump.d.ts +5 -4
  269. package/dist/release/bump.js +2 -2
  270. package/dist/release/cli.d.ts +4 -4
  271. package/dist/release/cli.js +4 -4
  272. package/dist/release/codegen.js +1 -1
  273. package/dist/release/digest.js +5 -7
  274. package/dist/release/git.js +5 -8
  275. package/dist/release/load.js +3 -3
  276. package/dist/release/manifest.js +9 -10
  277. package/dist/release/oasdiff.d.ts +10 -15
  278. package/dist/release/oasdiff.js +5 -6
  279. package/dist/release/registries.d.ts +0 -11
  280. package/dist/release/registries.js +17 -17
  281. package/dist/release/release-state.d.ts +16 -13
  282. package/dist/release/release-workflow.js +5 -7
  283. package/dist/release/repo-settings.d.ts +2 -1
  284. package/dist/release/spec-gate.d.ts +0 -2
  285. package/dist/release/spec-gate.js +6 -10
  286. package/dist/release/sync-command.d.ts +2 -2
  287. package/dist/release/sync-command.js +1 -1
  288. package/dist/release/sync-tree.js +9 -13
  289. package/dist/release/sync.d.ts +6 -6
  290. package/dist/release/sync.js +12 -13
  291. package/dist/release/types.d.ts +22 -22
  292. package/dist/release/types.js +0 -1
  293. package/dist/release/version-files.d.ts +3 -4
  294. package/dist/release/version-files.js +4 -5
  295. package/dist/runtime/.oxfmtrc.jsonc +8 -0
  296. package/dist/runtime/cli/socket.go +107 -13
  297. package/dist/runtime/cli/stream.go +18 -11
  298. package/dist/runtime/csharp/Adapters.cs +12 -11
  299. package/dist/runtime/csharp/Events.cs +22 -17
  300. package/dist/runtime/csharp/Realtime.cs +50 -23
  301. package/dist/runtime/csharp/RealtimeLoop.cs +1 -1
  302. package/dist/runtime/csharp/TransportSse.cs +3 -3
  303. package/dist/runtime/csharp/Ws.cs +1 -1
  304. package/dist/runtime/csharp/WsDial.cs +19 -1
  305. package/dist/runtime/csharp/WsTyped.cs +109 -0
  306. package/dist/runtime/go/realtime.go +125 -41
  307. package/dist/runtime/go/realtime_loop.go +21 -18
  308. package/dist/runtime/go/result.go +2 -1
  309. package/dist/runtime/go/sse.go +11 -0
  310. package/dist/runtime/go/stream.go +29 -13
  311. package/dist/runtime/go/transport.go +15 -21
  312. package/dist/runtime/go/transport_longpoll.go +3 -4
  313. package/dist/runtime/go/transport_sse.go +6 -6
  314. package/dist/runtime/go/ws.go +157 -61
  315. package/dist/runtime/java/EventStream.java +47 -29
  316. package/dist/runtime/java/Exchange.java +5 -5
  317. package/dist/runtime/java/Flight.java +3 -3
  318. package/dist/runtime/java/Realtime.java +45 -11
  319. package/dist/runtime/java/ResumableConnection.java +77 -32
  320. package/dist/runtime/java/Socket.java +8 -4
  321. package/dist/runtime/java/SseAdapter.java +1 -1
  322. package/dist/runtime/java/TypedWebSocket.java +81 -24
  323. package/dist/runtime/java/WsAdapter.java +4 -2
  324. package/dist/runtime/java/WsDial.java +12 -5
  325. package/dist/runtime/mcp/files.ts +1 -1
  326. package/dist/runtime/mcp/http.ts +6 -2
  327. package/dist/runtime/mcp/listen.ts +1 -1
  328. package/dist/runtime/mcp/mount.ts +2 -2
  329. package/dist/runtime/mcp/protocol.ts +1 -1
  330. package/dist/runtime/python/events.py +25 -11
  331. package/dist/runtime/python/operation.py +6 -1
  332. package/dist/runtime/python/realtime.py +47 -33
  333. package/dist/runtime/python/send_async.py +1 -0
  334. package/dist/runtime/python/transport_sse.py +2 -2
  335. package/dist/runtime/python/transport_ws.py +1 -1
  336. package/dist/runtime/python/ws.py +100 -39
  337. package/dist/runtime/rust/events.rs +64 -41
  338. package/dist/runtime/rust/realtime.rs +80 -34
  339. package/dist/runtime/rust/realtime_loop.rs +37 -12
  340. package/dist/runtime/rust/sse.rs +3 -2
  341. package/dist/runtime/rust/transport_sse.rs +1 -1
  342. package/dist/runtime/rust/transport_ws.rs +3 -2
  343. package/dist/runtime/rust/ws.rs +122 -50
  344. package/dist/runtime/ts/realtime-connection.ts +22 -0
  345. package/dist/runtime/ts/realtime-transports.ts +13 -4
  346. package/dist/runtime/ts/realtime.ts +27 -3
  347. package/dist/runtime/ts/sdk-realtime.ts +1 -1
  348. package/dist/runtime/ts/sdk-sse.ts +31 -14
  349. package/dist/runtime/ts/sdk-ws.ts +2 -1
  350. package/dist/runtime/ts/sdk.ts +9 -2
  351. package/dist/runtime/ts/sse.ts +8 -0
  352. package/dist/runtime/ts/ws.ts +88 -50
  353. package/dist/runtime/ts-tanstack-query/query.ts +0 -2
  354. package/package.json +12 -40
  355. package/dist/emit/cli/index.d.ts +0 -1
  356. package/dist/emit/cli/index.js +0 -1
  357. package/dist/emit/csharp/index.d.ts +0 -1
  358. package/dist/emit/csharp/index.js +0 -1
  359. package/dist/emit/go/index.d.ts +0 -1
  360. package/dist/emit/go/index.js +0 -1
  361. package/dist/emit/java/index.d.ts +0 -2
  362. package/dist/emit/java/index.js +0 -2
  363. package/dist/emit/mcp/index.d.ts +0 -3
  364. package/dist/emit/mcp/index.js +0 -3
  365. package/dist/emit/python/index.d.ts +0 -1
  366. package/dist/emit/python/index.js +0 -1
  367. package/dist/emit/rust/index.d.ts +0 -1
  368. package/dist/emit/rust/index.js +0 -1
@@ -1,5 +1,8 @@
1
+ import { isJsonEventData, sseEvents } from "../../ir/sdk-model.js";
2
+ import { javaString } from "../shared/escape.js";
3
+ import { javaTypeName, NameScope } from "../shared/lang.js";
4
+ import { bin, call as callOf, cond, id, lambda, lit, local, methodHeader, param, newOf, ref, returnStmt, rule, statement, typeHeader, } from "./layout.js";
1
5
  import { javaTypeOf } from "./models.js";
2
- import { bin, call as callOf, cond, methodHeader, param, newOf, ref, returnStmt, statement, } from "./layout.js";
3
6
  import { docOf } from "./sdk-decl.js";
4
7
  /** The header an SSE open resumes an event stream with. */
5
8
  export const LAST_EVENT_ID = "Last-Event-ID";
@@ -8,24 +11,120 @@ export const CURSOR = "lastEventId";
8
11
  /** Whether a declared header param is Last-Event-ID (any casing), the resume channel the cursor field carries. */
9
12
  export const isLastEventIdHeader = (name) => name.toLowerCase() === LAST_EVENT_ID.toLowerCase();
10
13
  /** F1's doc obligation: how a stream lets its connection go. */
11
- export const RELEASE = "Open it in try-with-resources: a for-each break without one keeps the connection.";
14
+ const RELEASE = "Open it in try-with-resources: a for-each break without one keeps the connection.";
12
15
  /** The SSE runtime's files: the stream, its event, the parser and the body's pump; core, with every exchange. */
13
16
  export const SSE_FILES = ["EventStream", "Pump", "Sse", "SseEvent"];
14
- /** The type an SSE op's events decode to: the declared event schema's, else `String`. */
15
- export const eventTypeOf = (op, ctx) => op.events === undefined ? "String" : javaTypeOf(op.events, { ...ctx, fieldName: "Event", parentName: op.id });
17
+ // the names a nested record never takes besides the models scope's: the types its declaration spells
18
+ const SPELLED = ["Duration", "EventStream", "Object", "SseEvent", "String", "TypeReference"];
19
+ /** A nested record's header: its data, then the event's name, id and retry. */
20
+ const recordLines = (record, data, name) => typeHeader(2, {
21
+ components: [
22
+ { name: "data", type: data },
23
+ { name: "event", type: "String" },
24
+ { name: "id", type: "String" },
25
+ { name: "retry", type: "Duration" },
26
+ ],
27
+ end: "{}",
28
+ implements: name,
29
+ kind: "record",
30
+ modifiers: ["public"],
31
+ name: record,
32
+ });
33
+ /** The record `record` built from `e` under `name`, its data `data`. */
34
+ const built = (record, data) => newOf(record, [data, "name", callOf("e", "id"), callOf("e", "retry")]);
35
+ /** The `of` arm of `nested`: its data from JSON by its type, or as sent. */
36
+ const armOf = ({ data, event, json, record }) => {
37
+ const text = callOf("e", "data");
38
+ const value = json ? callOf("EventStream", "data", [text, newOf(`TypeReference<${data}>`, [], true)]) : text;
39
+ return statement(6, rule(lit(javaString(event)), built(record, value)));
40
+ };
41
+ /**
42
+ * The nested records of `name`, one per event name (a name declared twice is its first declaration's): each data's
43
+ * type, and a record name that never shadows a type the declaration spells, one the models scope holds, `Unknown` or
44
+ * `name` itself.
45
+ */
46
+ function nestedOf(op, events, name, ctx) {
47
+ const typed = events
48
+ .filter((e, i) => events.findIndex((other) => other.name === e.name) === i)
49
+ .map(({ data, name: event }) => {
50
+ const json = isJsonEventData(data, ctx.names.resolve);
51
+ const type = json ? javaTypeOf(data, { ...ctx, fieldName: event, parentName: op.id, path: "" }) : "String";
52
+ return { data: type, event, json };
53
+ });
54
+ // a type a record's data spells would be shadowed by a nested record of its name
55
+ const spelled = typed.flatMap(({ data }) => data.split(/\W+/).filter((word) => word !== ""));
56
+ const reserved = new Set([...SPELLED, ...spelled, name, "Unknown"]);
57
+ const scope = new NameScope(reserved);
58
+ return typed.map((t) => {
59
+ const base = javaTypeName(t.event);
60
+ return { ...t, record: scope.claim(reserved.has(base) || ctx.names.has(base) ? `${base}Event` : base) };
61
+ });
62
+ }
63
+ /** `name`'s `of`: the event's name, then the record its switch builds. */
64
+ const ofLines = (name, nested) => [
65
+ docOf("The event {@code e} decoded by its name, an unnamed one {@code message}; a JSON event that does not decode throws {@link DecodeException}."),
66
+ ...methodHeader(2, { modifiers: ["static"], name: "of", params: [param("SseEvent<String>", "e")], returns: name }),
67
+ ...statement(4, local({ init: callOf("EventStream", "nameOf", ["e"]), name: "name", type: "String" })),
68
+ " return switch (name) {",
69
+ ...nested.flatMap(armOf),
70
+ ...statement(6, rule(null, built("Unknown", callOf("e", "data")))),
71
+ " };",
72
+ " }",
73
+ ];
74
+ /** `<Op>Event`, hoisted into `ctx.decls` once with its nested records and its `of`; its name. */
75
+ function namedEvents(op, events, ctx) {
76
+ const name = ctx.names.hoist(`${op.id}.events`, `${javaTypeName(op.id)}Event`);
77
+ if (ctx.decls.has(name))
78
+ return name;
79
+ // claimed before its body: what the data types hoist comes after it
80
+ ctx.decls.set(name, "");
81
+ const nested = nestedOf(op, events, name, ctx);
82
+ const records = nested.map(({ record }) => record).join(", ");
83
+ // the nested records are its permits
84
+ const header = typeHeader(0, { end: "{", kind: "interface", modifiers: ["public", "sealed"], name, permits: [] });
85
+ ctx.decls.set(name, [
86
+ docOf(`One event of ${op.id}: ${records}, or Unknown for a name the operation does not declare, its data as sent. An instanceof match reads the event's data.`, ""),
87
+ ...header,
88
+ ...nested.flatMap(({ data, record }) => [...recordLines(record, data, name), ""]),
89
+ ...recordLines("Unknown", "String", name),
90
+ "",
91
+ ...ofLines(name, nested),
92
+ "}",
93
+ ].join("\n"));
94
+ return name;
95
+ }
96
+ /**
97
+ * What an SSE op's stream yields and the decode the method hands the runtime: a named-event op's `<Op>Event` through
98
+ * its `of`; else `SseEvent<T>` through `EventStream.typed`, `T` the declared event schema's type, or `SseEvent<String>`
99
+ * as parsed for untyped or string events.
100
+ */
101
+ export function sseEventOf(op, ctx) {
102
+ const events = sseEvents(op.ir);
103
+ if (events !== undefined) {
104
+ const name = namedEvents(op, events, ctx);
105
+ return { decode: ref(name, "of"), type: name };
106
+ }
107
+ const type = op.events === undefined ? "String" : javaTypeOf(op.events, { ...ctx, fieldName: "Event", parentName: op.id });
108
+ if (type === "String")
109
+ return { decode: lambda("e", id("e")), type: "SseEvent<String>" };
110
+ return {
111
+ decode: callOf("EventStream", "typed", [newOf(`TypeReference<${type}>`, [], true)]),
112
+ type: `SseEvent<${type}>`,
113
+ };
114
+ }
16
115
  /**
17
116
  * An SSE method's lines: `op(params)` and `op(params, options)`, and `op(params, headersInto, options)` for an operation
18
117
  * with response headers, filled at the open; the shorter overloads delegate to the longest.
19
118
  */
20
119
  export function sseMethodLines(op, site, ctx) {
21
120
  const { call, constant, headers, name, params } = site;
22
- const type = eventTypeOf(op, ctx);
121
+ const { decode, type } = sseEventOf(op, ctx);
23
122
  const doc = docOf(`${op.id}: the open stream. An error status throws before any event, and no timeout bounds it after that. ${RELEASE}`);
24
123
  const signature = (args) => methodHeader(2, { modifiers: ["public"], name, params: args, returns: `EventStream<${type}>` });
25
124
  const holder = headers === null ? "null" : cond(bin("==", "headersInto", "null"), "null", ref("headersInto", "read"));
26
125
  const open = [
27
126
  ...call,
28
- ...statement(4, returnStmt(callOf("exchange", "events", [constant, "call", "options", holder, newOf(`TypeReference<${type}>`, [], true)]))),
127
+ ...statement(4, returnStmt(callOf("exchange", "events", [constant, "call", "options", holder, decode]))),
29
128
  ];
30
129
  const delegate = (args) => statement(4, returnStmt(callOf(null, name, args)));
31
130
  const longest = headers === null ? open : delegate(["params", "null", "options"]);
@@ -1,21 +1,60 @@
1
1
  /**
2
- * A WebSocket operation's method (bit 16 phase d2a, K1/K2/K3; C#'s `ws.ts`): `TypedWebSocket`, dialed by the call
3
- * through `WsDial.open` (no hook and no log), so a refused handshake throws before the method returns. The entry
4
- * sits in the gated WebSocket files, as C#'s `SocketAsync` in WsDial.cs: an SDK without a socket references none. Its
5
- * fields, `protocols` (offered in order) and `reconnectToken` (sent as `reconnect_token` after the declared query, only
6
- * when set and non-empty); a declared `reconnect_token` query folds into the token, and a param spelled like either
7
- * field claims `…2`. A socket method is the same text in either mode: it answers no Result.
2
+ * A WebSocket operation's method (bit 16 phase d2a, K1/K2/K3; C#'s `ws.ts`): `TypedWebSocket<TIn, TOut>`, dialed by
3
+ * the call through `WsDial.open` (no hook and no log), so a refused handshake throws before the method returns. An
4
+ * operation that declares its messages (D9) reads `TIn`, what the server sends, each frame as JSON, and sends `TOut`,
5
+ * what it receives, each a direction's declared type (an inline one hoisted as `<Op>Send` or `<Op>Receive`); a side it
6
+ * does not declare reads `WsMessage`, each frame as it came, or sends `JsonNode`. A keyed read side (the sealed
7
+ * interface models-union.ts declares) answers `<Read>Socket<TOut>`, one per read type, whose `on<Value>` per member
8
+ * matches inside `onMessage` and returns the socket, none for a value whose handler the socket has (message, closed,
9
+ * error); its name is claimed through the models scope after the union's wrappers, and a second value of one handler
10
+ * name is numbered. The entry sits in the gated WebSocket files, as C#'s `SocketAsync` in WsDial.cs: an SDK without a
11
+ * socket references none. Its fields, `protocols` (offered in order) and `reconnectToken` (sent as `reconnect_token`
12
+ * after the declared query, only when set and non-empty); a declared `reconnect_token` query folds into the token,
13
+ * and a param spelled like either field claims `…2`. A socket method is the same text in either mode: it answers no
14
+ * Result.
8
15
  */
9
16
  import type { SdkOp } from "../../ir/sdk-model.ts";
17
+ import type { Dispatch } from "./json.ts";
18
+ import { type Expr } from "./layout.ts";
19
+ import { type JavaTypeContext } from "./models.ts";
10
20
  /** The query param the token travels in. */
11
21
  export declare const RECONNECT_TOKEN = "reconnect_token";
12
22
  /** The socket's Params fields: the subprotocols offered, then the resume token. */
13
23
  export declare const PROTOCOLS = "protocols";
14
24
  export declare const TOKEN = "reconnectToken";
15
25
  /** Whether a declared query param is reconnect_token, the resume channel the token field carries. */
16
- export declare const isReconnectTokenQuery: (name: string) => name is "reconnect_token";
26
+ export declare const isReconnectTokenQuery: (name: string) => boolean;
17
27
  /** The WebSocket runtime's files: the socket and its parts; only an SDK with a WebSocket operation ships them. */
18
- export declare const WS_FILES: string[];
28
+ export declare const WS_FILES: readonly string[];
29
+ /**
30
+ * What a generated reader extends: its base class, the handlers the base has (a member whose `on<Value>` one of them
31
+ * names gets none), what its docs call it, and the suffix its name takes after the read type's.
32
+ */
33
+ export type Reader = {
34
+ readonly base: string;
35
+ readonly handlers: readonly string[];
36
+ readonly noun: string;
37
+ readonly suffix: string;
38
+ };
39
+ /** What a socket method answers, the frame reader it hands the dial, and the wrap of the dialed socket. */
40
+ export type WsSocket = {
41
+ readonly type: string;
42
+ readonly read: Expr;
43
+ readonly wrap: (dialed: Expr) => Expr;
44
+ };
45
+ /** The arms of `arms` that get an `on<Value>`: each but one whose handler `reader` has already. */
46
+ export declare const handledArms: (reader: Reader, arms: readonly Dispatch[]) => Dispatch[];
47
+ /**
48
+ * `<read><Suffix>`, hoisted into `ctx.decls` once per read type and reader with an `on<Value>` per arm of `arms` but
49
+ * one whose handler `reader` has; its name. The wrappers were claimed first, so a member spelled like the subclass
50
+ * keeps its wrapper and this one is numbered, and a second value of one handler name is numbered.
51
+ */
52
+ export declare function keyedReader(reader: Reader, read: string, arms: readonly Dispatch[], ctx: JavaTypeContext): string;
53
+ /**
54
+ * What `op`'s socket method answers and hands the dial: an op without messages `TypedWebSocket<WsMessage, JsonNode>`,
55
+ * its frames as they came; else each declared side's type, a keyed read side's socket wrapping the dialed one.
56
+ */
57
+ export declare function wsSocketOf(op: SdkOp, ctx: JavaTypeContext): WsSocket;
19
58
  /** What a socket method's lines need: its name and constant, its Params, and its Call's lines. */
20
59
  export type WsSite = {
21
60
  readonly name: string;
@@ -24,4 +63,4 @@ export type WsSite = {
24
63
  readonly call: readonly string[];
25
64
  };
26
65
  /** A socket method's lines: `op(params)`, delegating to `op(params, options)`, which dials. */
27
- export declare function wsMethodLines(op: SdkOp, site: WsSite): string[];
66
+ export declare function wsMethodLines(op: SdkOp, site: WsSite, ctx: JavaTypeContext): string[];
@@ -1,4 +1,7 @@
1
- import { call as callOf, methodHeader, param, returnStmt, statement } from "./layout.js";
1
+ import { NameScope } from "../shared/lang.js";
2
+ import { bin, call as callOf, exprStmt, id, ifOpen, lambda, lit, methodHeader, newOf, param, returnStmt, statement, typeHeader, } from "./layout.js";
3
+ import { JSON_NODE } from "./models-names.js";
4
+ import { declaredTypeOf, keyedArms } from "./models.js";
2
5
  import { docOf } from "./sdk-decl.js";
3
6
  /** The query param the token travels in. */
4
7
  export const RECONNECT_TOKEN = "reconnect_token";
@@ -9,12 +12,93 @@ export const TOKEN = "reconnectToken";
9
12
  export const isReconnectTokenQuery = (name) => name === RECONNECT_TOKEN;
10
13
  /** The WebSocket runtime's files: the socket and its parts; only an SDK with a WebSocket operation ships them. */
11
14
  export const WS_FILES = ["Keepalive", "Socket", "TypedWebSocket", "WsClose", "WsDial", "WsMessage"];
15
+ /** The socket's reader: its own handlers are onMessage, onClosed and onError. */
16
+ const SOCKET = {
17
+ base: "TypedWebSocket",
18
+ handlers: ["onMessage", "onClosed", "onError"],
19
+ noun: "socket",
20
+ suffix: "Socket",
21
+ };
22
+ /** The frame reader of an undeclared read side: each frame as it came. */
23
+ const asSent = () => lambda("m", id("m"));
24
+ /** One `on<Value>` of `sub`, named `name`: it matches `arm`'s wrapper inside onMessage and hands on its variant. */
25
+ const handlerLines = (reader, sub, name, { payload, wrapper }) => [
26
+ "",
27
+ docOf(`Runs {@code handler} with the variant of each ${wrapper} message, inside onMessage; this ${reader.noun}.`),
28
+ ...methodHeader(2, {
29
+ modifiers: ["public"],
30
+ name,
31
+ params: [param(`Consumer<${payload}>`, "handler")],
32
+ returns: `${sub}<TOut>`,
33
+ }),
34
+ " onMessage(",
35
+ " message -> {",
36
+ ...statement(10, ifOpen(bin("instanceof", "message", lit(`${wrapper} matched`)))),
37
+ ...statement(12, exprStmt(callOf("handler", "accept", [callOf("matched", "value")]))),
38
+ " }",
39
+ " });",
40
+ ...statement(4, returnStmt("this")),
41
+ " }",
42
+ ];
43
+ /** The arms of `arms` that get an `on<Value>`: each but one whose handler `reader` has already. */
44
+ export const handledArms = (reader, arms) => arms.filter((arm) => !reader.handlers.includes(handlerName(arm)));
45
+ // the handler an arm's first value spells
46
+ const handlerName = (arm) => `on${arm.spelled}`;
47
+ /**
48
+ * `<read><Suffix>`, hoisted into `ctx.decls` once per read type and reader with an `on<Value>` per arm of `arms` but
49
+ * one whose handler `reader` has; its name. The wrappers were claimed first, so a member spelled like the subclass
50
+ * keeps its wrapper and this one is numbered, and a second value of one handler name is numbered.
51
+ */
52
+ export function keyedReader(reader, read, arms, ctx) {
53
+ const sub = ctx.names.hoist(`${read}.${reader.noun}`, `${read}${reader.suffix}`);
54
+ if (ctx.decls.has(sub))
55
+ return sub;
56
+ const scope = new NameScope(reader.handlers);
57
+ const handlers = handledArms(reader, arms).flatMap((arm) => handlerLines(reader, sub, scope.claim(handlerName(arm)), arm));
58
+ ctx.decls.set(sub, [
59
+ docOf(`A ${reader.noun} reading ${read}: a handler per member, each matched inside onMessage.`, ""),
60
+ ...typeHeader(0, {
61
+ end: "{",
62
+ extends: `${reader.base}<${read}, TOut>`,
63
+ kind: "class",
64
+ modifiers: ["public", "final"],
65
+ name: `${sub}<TOut>`,
66
+ }),
67
+ ...methodHeader(2, { name: sub, params: [param(`${reader.base}<${read}, TOut>`, "opened")] }),
68
+ ...statement(4, exprStmt(callOf(null, "super", ["opened"]))),
69
+ " }",
70
+ ...handlers,
71
+ "}",
72
+ ].join("\n"));
73
+ return sub;
74
+ }
75
+ /** The dialed socket as it is: a socket whose read side has no members to handle. */
76
+ const AS_DIALED = (dialed) => dialed;
77
+ /**
78
+ * What `op`'s socket method answers and hands the dial: an op without messages `TypedWebSocket<WsMessage, JsonNode>`,
79
+ * its frames as they came; else each declared side's type, a keyed read side's socket wrapping the dialed one.
80
+ */
81
+ export function wsSocketOf(op, ctx) {
82
+ const messages = op.ir.messages;
83
+ const at = (fieldName) => ({ ...ctx, fieldName, parentName: op.id, path: "" });
84
+ const write = messages?.receive === undefined ? JSON_NODE : declaredTypeOf(messages.receive, at("Receive"));
85
+ if (messages?.send === undefined)
86
+ return { read: asSent(), type: `TypedWebSocket<WsMessage, ${write}>`, wrap: AS_DIALED };
87
+ const read = declaredTypeOf(messages.send, at("Send"));
88
+ const decode = callOf("TypedWebSocket", "json", [newOf(`TypeReference<${read}>`, [], true)]);
89
+ const arms = keyedArms(read, messages.send, ctx);
90
+ if (arms.length === 0)
91
+ return { read: decode, type: `TypedWebSocket<${read}, ${write}>`, wrap: AS_DIALED };
92
+ const sub = keyedReader(SOCKET, read, arms, ctx);
93
+ return { read: decode, type: `${sub}<${write}>`, wrap: (dialed) => newOf(`${sub}<${write}>`, [dialed]) };
94
+ }
12
95
  /** A socket method's lines: `op(params)`, delegating to `op(params, options)`, which dials. */
13
- export function wsMethodLines(op, site) {
96
+ export function wsMethodLines(op, site, ctx) {
14
97
  const { call, constant, name, params } = site;
98
+ const socket = wsSocketOf(op, ctx);
15
99
  const doc = docOf(`${op.id}: the open socket. A refused handshake throws; once open, no timeout bounds it. Close it, or open it in try-with-resources.`);
16
- const signature = (args) => methodHeader(2, { modifiers: ["public"], name, params: args, returns: "TypedWebSocket" });
17
- const dial = callOf("WsDial", "open", ["exchange", constant, "call", "options", callOf("params", "protocols")]);
100
+ const signature = (args) => methodHeader(2, { modifiers: ["public"], name, params: args, returns: socket.type });
101
+ const dial = socket.wrap(callOf("WsDial", "open", ["exchange", constant, "call", "options", callOf("params", "protocols"), socket.read]));
18
102
  return [
19
103
  doc,
20
104
  ...signature([param(params, "params")]),
@@ -2,14 +2,18 @@
2
2
  export function annotationsOf(op) {
3
3
  switch (op.method.toUpperCase()) {
4
4
  case "GET":
5
- case "HEAD":
5
+ case "HEAD": {
6
6
  return { readOnlyHint: true };
7
- case "POST":
7
+ }
8
+ case "POST": {
8
9
  return op.idempotent ? { destructiveHint: false, idempotentHint: true } : { destructiveHint: false };
10
+ }
9
11
  case "PUT":
10
- case "DELETE":
12
+ case "DELETE": {
11
13
  return { idempotentHint: true };
12
- default:
14
+ }
15
+ default: {
13
16
  return undefined;
17
+ }
14
18
  }
15
19
  }
@@ -1,26 +1,26 @@
1
1
  const STRING = { type: "string" };
2
2
  /** The extension's FileInput, marked: the members it requires, the digest's algorithm SHA-256. */
3
3
  const FILE_INPUT = {
4
- type: "object",
5
- "x-mcp-file": {},
6
4
  properties: {
7
5
  digest: {
8
- type: "object",
9
6
  properties: { algorithm: { const: "sha-256" }, value: STRING },
10
7
  required: ["algorithm", "value"],
8
+ type: "object",
11
9
  },
12
10
  },
13
11
  required: ["id", "mimeType", "size", "digest"],
12
+ type: "object",
13
+ "x-mcp-file": {},
14
14
  };
15
15
  /** A file argument's schema: the extension's FileInput, or a path the server reads. */
16
16
  export const FILE_SCHEMA = {
17
17
  anyOf: [
18
18
  FILE_INPUT,
19
19
  {
20
- type: "object",
21
- properties: { path: { type: "string", description: "A file under the server's file root" } },
22
- required: ["path"],
23
20
  additionalProperties: false,
21
+ properties: { path: { description: "A file under the server's file root", type: "string" } },
22
+ required: ["path"],
23
+ type: "object",
24
24
  },
25
25
  ],
26
26
  };
@@ -33,10 +33,10 @@ export const MOUNTED_FILE_SCHEMA = {
33
33
  anyOf: [
34
34
  FILE_INPUT,
35
35
  {
36
- type: "object",
37
- properties: { url: { type: "string", description: "An https URL the server fetches" } },
38
- required: ["url"],
39
36
  additionalProperties: false,
37
+ properties: { url: { description: "An https URL the server fetches", type: "string" } },
38
+ required: ["url"],
39
+ type: "object",
40
40
  },
41
41
  ],
42
42
  };
@@ -16,11 +16,11 @@ import { MCP_PORTABLE, mcpRuntimeSource } from "./runtime.js";
16
16
  import { resolved } from "./server.js";
17
17
  import { isTool, toolsOf, untoolable } from "./tools.js";
18
18
  const MARKER = "// Code generated by clients. DO NOT EDIT.";
19
- /* a directory name a relative import names */
19
+ // a directory name a relative import names
20
20
  const DIR = /^[A-Za-z0-9_][A-Za-z0-9_.-]*$/;
21
21
  /** `op`'s security requirements: its own, else the document's. */
22
22
  function requirementsOf(spec, op) {
23
- /* a tool's operation is the document's own, at its path and method */
23
+ // a tool's operation is the document's own, at its path and method
24
24
  const paths = spec.paths;
25
25
  const own = paths[op.path][op.method.toLowerCase()];
26
26
  return own.security ?? spec.security ?? [];
@@ -4,10 +4,12 @@
4
4
  * an object (2025-11-25), and so is an answer whose operation declares response headers (Q11), as `{result, headers}`:
5
5
  * a body key named `headers` then never meets them. Each header is a string, as it arrives. No JSON success schema
6
6
  * means no outputSchema: the result is text only. An event stream's collect (phase e) is `{events, last_event_id,
7
- * ended}`, each event's data its declared schema, else a string.
7
+ * ended}`, each event's data its declared schema, else a string. A stream that names its events (D7) types each event
8
+ * by its name, as the TS SDK yields it: the names sharing one data schema are one `anyOf` member, `event` their const
9
+ * (one name) or enum (several), and a last member takes a name the operation does not declare, its data the raw text.
8
10
  */
9
11
  import type { IR } from "../../ir/model.ts";
10
- import type { SdkOp } from "../../ir/sdk-model.ts";
12
+ import { type SdkOp } from "../../ir/sdk-model.ts";
11
13
  import { type JsonSchema } from "./schema.ts";
12
14
  /** A tool's outputSchema, and whether its structuredContent wraps the answer. */
13
15
  export type Output = {
@@ -1,16 +1,56 @@
1
+ import { irResolver } from "../../ir/schema.js";
2
+ import { sseEvents } from "../../ir/sdk-model.js";
1
3
  import { jsonSchemaOf } from "./schema.js";
2
- /** What a collect gathered, its events' data as `data` says. */
3
- const collectedOf = (data) => ({
4
+ const STRING = { type: "string" };
5
+ /** An event of a stream that does not name its events: its data as `data` says, its name and id when it has them. */
6
+ const unnamedOf = (data) => ({
4
7
  type: "object",
5
- properties: {
6
- events: {
7
- type: "array",
8
- items: {
9
- type: "object",
10
- properties: { data, event: { type: "string" }, id: { type: "string" } },
11
- required: ["data"],
12
- },
8
+ properties: { data, event: STRING, id: STRING },
9
+ required: ["data"],
10
+ });
11
+ /**
12
+ * An event of a stream that names `events` (D7). An event whose data is JSON is one `anyOf` member per distinct data
13
+ * schema, `event` its const (one name) or enum (several). Any other event's data arrives as its text, so one string
14
+ * member holds the rest, declared or not; `event` names every declared name as an example.
15
+ */
16
+ function namedOf(events, ir) {
17
+ const resolve = irResolver(ir.schemas);
18
+ const groups = new Map();
19
+ const names = [];
20
+ for (const { data, name } of events) {
21
+ if (!names.includes(name))
22
+ names.push(name);
23
+ const schema = resolve(data).kind === "unknown" ? STRING : jsonSchemaOf(data, ir.schemas);
24
+ const key = JSON.stringify(schema);
25
+ if (key === JSON.stringify(STRING))
26
+ continue;
27
+ const group = groups.get(key) ?? { data: schema, names: [] };
28
+ if (!group.names.includes(name))
29
+ group.names.push(name);
30
+ groups.set(key, group);
31
+ }
32
+ const event = { type: "string", examples: names };
33
+ const required = ["data", "event"];
34
+ if (groups.size === 0)
35
+ return { type: "object", properties: { data: STRING, event, id: STRING }, required };
36
+ const members = [...groups.values()].map((group) => ({
37
+ properties: {
38
+ event: group.names.length === 1 ? { const: group.names[0] } : { enum: group.names },
39
+ data: group.data,
13
40
  },
41
+ }));
42
+ return {
43
+ type: "object",
44
+ properties: { event, id: STRING },
45
+ required,
46
+ anyOf: [...members, { properties: { data: STRING } }],
47
+ };
48
+ }
49
+ /** What a collect gathered, each event as `item` says. */
50
+ const collectedOf = (item) => ({
51
+ type: "object",
52
+ properties: {
53
+ events: { type: "array", items: item },
14
54
  last_event_id: { anyOf: [{ type: "string" }, { type: "null" }] },
15
55
  ended: { type: "string", enum: ["end", "max_events", "cap", "timeout"] },
16
56
  },
@@ -18,18 +58,22 @@ const collectedOf = (data) => ({
18
58
  });
19
59
  /** The outputSchema `op`'s success answer gives, or none. */
20
60
  export function outputOf(op, ir) {
21
- if (op.stream === "sse")
61
+ if (op.stream === "sse") {
62
+ const named = sseEvents(op.ir);
63
+ if (named !== undefined)
64
+ return { outputSchema: collectedOf(namedOf(named, ir)) };
22
65
  return {
23
- outputSchema: collectedOf(op.events === undefined ? { type: "string" } : jsonSchemaOf(op.events, ir.schemas)),
66
+ outputSchema: collectedOf(unnamedOf(op.events === undefined ? STRING : jsonSchemaOf(op.events, ir.schemas))),
24
67
  };
25
- /* the SDK model gives a success its schema only when it is JSON */
68
+ }
69
+ // the SDK model gives a success its schema only when it is JSON
26
70
  if (op.success.schema === undefined)
27
71
  return undefined;
28
72
  const result = jsonSchemaOf(op.success.schema, ir.schemas);
29
73
  const names = [...new Set((op.ir.responses[op.success.status]?.headers ?? []).map(({ name }) => name.toLowerCase()))];
30
74
  if (result.type === "object" && names.length === 0)
31
75
  return { outputSchema: result };
32
- /* null-prototype: a header named __proto__ is a property, never the object's prototype */
76
+ // null-prototype: a header named __proto__ is a property, never the object's prototype
33
77
  const headers = Object.create(null);
34
78
  for (const name of names.sort())
35
79
  headers[name] = { type: "string" };
@@ -8,8 +8,6 @@
8
8
  */
9
9
  import type { IR } from "../../ir/model.ts";
10
10
  import type { Metadata } from "../shared/metadata.ts";
11
- /** The schema the file names, the registry's latest dated one. */
12
- export declare const SERVER_SCHEMA = "https://static.modelcontextprotocol.io/schemas/2025-12-11/server.schema.json";
13
11
  /** The server as the registry lists it: its names, the version npm publishes, and what its environment holds. */
14
12
  export type Listing = {
15
13
  readonly name: string;
@@ -1,8 +1,8 @@
1
1
  /** The schema the file names, the registry's latest dated one. */
2
- export const SERVER_SCHEMA = "https://static.modelcontextprotocol.io/schemas/2025-12-11/server.schema.json";
3
- /* the registry's cap on a description, in characters */
2
+ const SERVER_SCHEMA = "https://static.modelcontextprotocol.io/schemas/2025-12-11/server.schema.json";
3
+ // the registry's cap on a description, in characters
4
4
  const DESCRIPTION_MAX = 100;
5
- /* the forges the registry knows by host: the `source` it validates a repository through */
5
+ // the forges the registry knows by host: the `source` it validates a repository through
6
6
  const SOURCES = { "github.com": "github", "gitlab.com": "gitlab" };
7
7
  /** Every variable the server reads over stdio, as its entry reads them; the HTTP transport's are not the package's. */
8
8
  function variablesOf(listing, ir) {
@@ -50,8 +50,9 @@ function variablesOf(listing, ir) {
50
50
  /** The description the registry shows: the run's, else the package's own, refused past the registry's cap. */
51
51
  function descriptionOf(listing, metadata) {
52
52
  const text = metadata.description ?? `The ${listing.name} API as MCP tools`;
53
- if ([...text].length > DESCRIPTION_MAX)
53
+ if ([...text].length > DESCRIPTION_MAX) {
54
54
  throw new Error(`Invalid metadata.description: ${JSON.stringify(text)}: the MCP registry takes ${DESCRIPTION_MAX} characters at most`);
55
+ }
55
56
  return text;
56
57
  }
57
58
  /** The repository as the registry links it, for a forge it knows; none for another host. */
@@ -35,13 +35,13 @@ export const MCP_STANDALONE = [
35
35
  "reader",
36
36
  "listen",
37
37
  ];
38
- /* an import of a sibling runtime module, on one line or several */
38
+ // an import of a sibling runtime module, on one line or several
39
39
  const SIBLING_IMPORT = /^import\s+(?:type\s+)?\{[^}]*\}\s+from\s+"\.\/[\w-]+\.ts"\n/gm;
40
40
  const MARKER = "// Code generated by clients. DO NOT EDIT.";
41
41
  /** The vendored runtime as one module: `names` (the standalone package's by default) in order, sibling imports dropped. */
42
42
  export function mcpRuntimeSource(names = MCP_STANDALONE) {
43
43
  const modules = names.map((name) => readFileSync(new URL(`../../runtime/mcp/${name}.ts`, import.meta.url), "utf8")
44
- .replace(SIBLING_IMPORT, "")
44
+ .replaceAll(SIBLING_IMPORT, "")
45
45
  .trim());
46
46
  return `${MARKER}\n\n${modules.join("\n\n")}\n`;
47
47
  }
@@ -53,33 +53,44 @@ function convert(schema, walk) {
53
53
  if (++walk.nodes.count > walk.budget)
54
54
  throw new Error(`a schema inlines past ${walk.budget} nodes`);
55
55
  switch (schema.kind) {
56
- case "scalar":
56
+ case "scalar": {
57
57
  return scalarOf(schema);
58
- case "const":
58
+ }
59
+ case "const": {
59
60
  return { const: schema.value };
60
- case "object":
61
+ }
62
+ case "object": {
61
63
  return objectOf(schema.fields, schema.additional, walk);
62
- case "array":
64
+ }
65
+ case "array": {
63
66
  return {
64
67
  type: "array",
65
68
  items: convert(schema.items, walk),
66
69
  ...(schema.minItems === undefined ? {} : { minItems: schema.minItems }),
67
70
  ...(schema.maxItems === undefined ? {} : { maxItems: schema.maxItems }),
68
71
  };
69
- case "tuple":
72
+ }
73
+ case "tuple": {
70
74
  return tupleOf(schema, walk);
71
- case "union":
75
+ }
76
+ case "union": {
72
77
  return { anyOf: schema.variants.map((variant) => convert(variant, walk)) };
73
- case "allOf":
78
+ }
79
+ case "allOf": {
74
80
  return { allOf: schema.parts.map((part) => convert(part, walk)) };
75
- case "ref":
81
+ }
82
+ case "ref": {
76
83
  return inlineRef(schema.name, walk);
77
- case "nullable":
84
+ }
85
+ case "nullable": {
78
86
  return { anyOf: [convert(schema.inner, walk), { type: "null" }] };
79
- case "binary":
87
+ }
88
+ case "binary": {
80
89
  return { type: "string", contentEncoding: "base64" };
81
- case "unknown":
90
+ }
91
+ case "unknown": {
82
92
  return {};
93
+ }
83
94
  }
84
95
  }
85
96
  /** `schema` as a self-contained JSON Schema, every ref into `schemas` inlined, refused past `budget` nodes. */