effect 4.1.5 → 4.1.7

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 (441) hide show
  1. package/ai-docs/package.json +2 -2
  2. package/dist/Channel.d.ts +104 -7
  3. package/dist/Channel.d.ts.map +1 -1
  4. package/dist/Channel.js +73 -4
  5. package/dist/Channel.js.map +1 -1
  6. package/dist/Codegen.d.ts +7 -2
  7. package/dist/Codegen.d.ts.map +1 -1
  8. package/dist/Codegen.js +7 -2
  9. package/dist/Codegen.js.map +1 -1
  10. package/dist/Config.d.ts +1 -1
  11. package/dist/Config.d.ts.map +1 -1
  12. package/dist/Config.js +5 -3
  13. package/dist/Config.js.map +1 -1
  14. package/dist/Context.d.ts.map +1 -1
  15. package/dist/Context.js +79 -31
  16. package/dist/Context.js.map +1 -1
  17. package/dist/Cron.d.ts.map +1 -1
  18. package/dist/Cron.js +10 -9
  19. package/dist/Cron.js.map +1 -1
  20. package/dist/Effect.d.ts +139 -18
  21. package/dist/Effect.d.ts.map +1 -1
  22. package/dist/Effect.js +10 -2
  23. package/dist/Effect.js.map +1 -1
  24. package/dist/Equal.d.ts +4 -4
  25. package/dist/Equal.d.ts.map +1 -1
  26. package/dist/Equal.js +78 -66
  27. package/dist/Equal.js.map +1 -1
  28. package/dist/Formatter.js +4 -4
  29. package/dist/Formatter.js.map +1 -1
  30. package/dist/Hash.d.ts.map +1 -1
  31. package/dist/Hash.js +34 -41
  32. package/dist/Hash.js.map +1 -1
  33. package/dist/LayerRef.d.ts +1 -1
  34. package/dist/LayerRef.d.ts.map +1 -1
  35. package/dist/LayerRef.js +3 -3
  36. package/dist/LayerRef.js.map +1 -1
  37. package/dist/Logger.d.ts +37 -13
  38. package/dist/Logger.d.ts.map +1 -1
  39. package/dist/Logger.js +39 -10
  40. package/dist/Logger.js.map +1 -1
  41. package/dist/Match.d.ts +23 -23
  42. package/dist/Match.d.ts.map +1 -1
  43. package/dist/Match.js.map +1 -1
  44. package/dist/Metric.d.ts.map +1 -1
  45. package/dist/Metric.js +3 -4
  46. package/dist/Metric.js.map +1 -1
  47. package/dist/Order.js +1 -1
  48. package/dist/Order.js.map +1 -1
  49. package/dist/Pool.d.ts.map +1 -1
  50. package/dist/Pool.js +49 -21
  51. package/dist/Pool.js.map +1 -1
  52. package/dist/Predicate.d.ts.map +1 -1
  53. package/dist/Predicate.js +2 -1
  54. package/dist/Predicate.js.map +1 -1
  55. package/dist/Scheduler.d.ts.map +1 -1
  56. package/dist/Scheduler.js +15 -9
  57. package/dist/Scheduler.js.map +1 -1
  58. package/dist/Schema.d.ts +41 -0
  59. package/dist/Schema.d.ts.map +1 -1
  60. package/dist/Schema.js +51 -390
  61. package/dist/Schema.js.map +1 -1
  62. package/dist/SchemaAST.d.ts +2 -2
  63. package/dist/SchemaAST.d.ts.map +1 -1
  64. package/dist/SchemaAST.js +199 -98
  65. package/dist/SchemaAST.js.map +1 -1
  66. package/dist/SchemaParser.d.ts.map +1 -1
  67. package/dist/SchemaParser.js +29 -50
  68. package/dist/SchemaParser.js.map +1 -1
  69. package/dist/ScopedCache.d.ts.map +1 -1
  70. package/dist/ScopedCache.js +6 -4
  71. package/dist/ScopedCache.js.map +1 -1
  72. package/dist/Stream.d.ts +128 -5
  73. package/dist/Stream.d.ts.map +1 -1
  74. package/dist/Stream.js +124 -29
  75. package/dist/Stream.js.map +1 -1
  76. package/dist/String.js +1 -1
  77. package/dist/String.js.map +1 -1
  78. package/dist/Tracer.d.ts +10 -0
  79. package/dist/Tracer.d.ts.map +1 -1
  80. package/dist/Tracer.js +3 -4
  81. package/dist/Tracer.js.map +1 -1
  82. package/dist/ai/McpClient.d.ts +68 -4
  83. package/dist/ai/McpClient.d.ts.map +1 -1
  84. package/dist/ai/McpClient.js +100 -17
  85. package/dist/ai/McpClient.js.map +1 -1
  86. package/dist/ai/McpClientError.d.ts +46 -4
  87. package/dist/ai/McpClientError.d.ts.map +1 -1
  88. package/dist/ai/McpClientError.js +38 -3
  89. package/dist/ai/McpClientError.js.map +1 -1
  90. package/dist/ai/McpServer.d.ts +158 -7
  91. package/dist/ai/McpServer.d.ts.map +1 -1
  92. package/dist/ai/McpServer.js +103 -49
  93. package/dist/ai/McpServer.js.map +1 -1
  94. package/dist/ai/Prompt.d.ts +3 -1
  95. package/dist/ai/Prompt.d.ts.map +1 -1
  96. package/dist/ai/Prompt.js +17 -3
  97. package/dist/ai/Prompt.js.map +1 -1
  98. package/dist/ai/Skill.d.ts +172 -0
  99. package/dist/ai/Skill.d.ts.map +1 -0
  100. package/dist/ai/Skill.js +209 -0
  101. package/dist/ai/Skill.js.map +1 -0
  102. package/dist/ai/index.d.ts +5 -0
  103. package/dist/ai/index.d.ts.map +1 -1
  104. package/dist/ai/index.js +5 -0
  105. package/dist/ai/index.js.map +1 -1
  106. package/dist/ai/internal/mcpProtocol/v2024_11_05.js +9 -7
  107. package/dist/ai/internal/mcpProtocol/v2024_11_05.js.map +1 -1
  108. package/dist/ai/internal/mcpProtocol/v2025_03_26.js +12 -11
  109. package/dist/ai/internal/mcpProtocol/v2025_03_26.js.map +1 -1
  110. package/dist/ai/internal/mcpProtocol/v2025_06_18.js +18 -17
  111. package/dist/ai/internal/mcpProtocol/v2025_06_18.js.map +1 -1
  112. package/dist/ai/internal/mcpProtocol/v2025_11_25.js +19 -18
  113. package/dist/ai/internal/mcpProtocol/v2025_11_25.js.map +1 -1
  114. package/dist/ai/internal/mcpProtocol/v2026_07_28.js +1 -1
  115. package/dist/ai/internal/mcpProtocol/v2026_07_28.js.map +1 -1
  116. package/dist/ai/internal/mcpProtocol.js +11 -0
  117. package/dist/ai/internal/mcpProtocol.js.map +1 -1
  118. package/dist/ai/internal/mcpRuntime.js +29 -17
  119. package/dist/ai/internal/mcpRuntime.js.map +1 -1
  120. package/dist/ai/internal/mcpSchema/v2024_11_05.js +2 -1
  121. package/dist/ai/internal/mcpSchema/v2024_11_05.js.map +1 -1
  122. package/dist/ai/internal/mcpSchema/v2025_03_26.js +1 -8
  123. package/dist/ai/internal/mcpSchema/v2025_03_26.js.map +1 -1
  124. package/dist/ai/internal/mcpSchema/v2025_06_18.js +5 -9
  125. package/dist/ai/internal/mcpSchema/v2025_06_18.js.map +1 -1
  126. package/dist/ai/internal/mcpSchema/v2025_11_25.js +1 -8
  127. package/dist/ai/internal/mcpSchema/v2025_11_25.js.map +1 -1
  128. package/dist/ai/internal/mcpSchema/v2026_07_28.js +4 -3
  129. package/dist/ai/internal/mcpSchema/v2026_07_28.js.map +1 -1
  130. package/dist/cluster/ClusterCron.d.ts +5 -20
  131. package/dist/cluster/ClusterCron.d.ts.map +1 -1
  132. package/dist/cluster/ClusterCron.js +16 -4
  133. package/dist/cluster/ClusterCron.js.map +1 -1
  134. package/dist/cluster/ClusterWorkflowEngine.d.ts.map +1 -1
  135. package/dist/cluster/ClusterWorkflowEngine.js +155 -83
  136. package/dist/cluster/ClusterWorkflowEngine.js.map +1 -1
  137. package/dist/cluster/MessageStorage.d.ts +56 -0
  138. package/dist/cluster/MessageStorage.d.ts.map +1 -1
  139. package/dist/cluster/MessageStorage.js +18 -2
  140. package/dist/cluster/MessageStorage.js.map +1 -1
  141. package/dist/cluster/SqlMessageStorage.d.ts.map +1 -1
  142. package/dist/cluster/SqlMessageStorage.js +48 -23
  143. package/dist/cluster/SqlMessageStorage.js.map +1 -1
  144. package/dist/cluster/internal/entityActivation.js +2 -0
  145. package/dist/cluster/internal/entityActivation.js.map +1 -1
  146. package/dist/cluster/internal/entityManager.js +8 -5
  147. package/dist/cluster/internal/entityManager.js.map +1 -1
  148. package/dist/encoding/Base64.js +5 -1
  149. package/dist/encoding/Base64.js.map +1 -1
  150. package/dist/encoding/Base64Url.d.ts.map +1 -1
  151. package/dist/encoding/Base64Url.js +6 -1
  152. package/dist/encoding/Base64Url.js.map +1 -1
  153. package/dist/encoding/Hex.js +7 -5
  154. package/dist/encoding/Hex.js.map +1 -1
  155. package/dist/encoding/Xml.d.ts +38 -9
  156. package/dist/encoding/Xml.d.ts.map +1 -1
  157. package/dist/encoding/Xml.js +63 -31
  158. package/dist/encoding/Xml.js.map +1 -1
  159. package/dist/http/FetchHttpClient.d.ts +2 -1
  160. package/dist/http/FetchHttpClient.d.ts.map +1 -1
  161. package/dist/http/FetchHttpClient.js +14 -10
  162. package/dist/http/FetchHttpClient.js.map +1 -1
  163. package/dist/http/Headers.d.ts +201 -3
  164. package/dist/http/Headers.d.ts.map +1 -1
  165. package/dist/http/Headers.js +205 -3
  166. package/dist/http/Headers.js.map +1 -1
  167. package/dist/http/HttpClient.d.ts.map +1 -1
  168. package/dist/http/HttpClient.js +11 -7
  169. package/dist/http/HttpClient.js.map +1 -1
  170. package/dist/http/HttpClientError.d.ts +1 -0
  171. package/dist/http/HttpClientError.d.ts.map +1 -1
  172. package/dist/http/HttpClientError.js +32 -9
  173. package/dist/http/HttpClientError.js.map +1 -1
  174. package/dist/http/HttpClientRequest.d.ts +46 -0
  175. package/dist/http/HttpClientRequest.d.ts.map +1 -1
  176. package/dist/http/HttpClientRequest.js +15 -0
  177. package/dist/http/HttpClientRequest.js.map +1 -1
  178. package/dist/http/HttpClientResponse.d.ts +132 -0
  179. package/dist/http/HttpClientResponse.d.ts.map +1 -1
  180. package/dist/http/HttpClientResponse.js +83 -0
  181. package/dist/http/HttpClientResponse.js.map +1 -1
  182. package/dist/http/HttpEffect.d.ts.map +1 -1
  183. package/dist/http/HttpEffect.js +31 -2
  184. package/dist/http/HttpEffect.js.map +1 -1
  185. package/dist/http/HttpMiddleware.js +1 -1
  186. package/dist/http/HttpMiddleware.js.map +1 -1
  187. package/dist/http/HttpServerError.d.ts +1 -1
  188. package/dist/http/HttpServerError.js +1 -1
  189. package/dist/http/HttpServerResponse.d.ts +118 -0
  190. package/dist/http/HttpServerResponse.d.ts.map +1 -1
  191. package/dist/http/HttpServerResponse.js +43 -0
  192. package/dist/http/HttpServerResponse.js.map +1 -1
  193. package/dist/http/Multipart.d.ts.map +1 -1
  194. package/dist/http/Multipart.js +0 -5
  195. package/dist/http/Multipart.js.map +1 -1
  196. package/dist/http/MultipartParser/internal/contentType.d.ts +6 -0
  197. package/dist/http/MultipartParser/internal/contentType.d.ts.map +1 -1
  198. package/dist/http/MultipartParser/internal/contentType.js +1 -1
  199. package/dist/http/MultipartParser/internal/contentType.js.map +1 -1
  200. package/dist/http/internal/clientPath.d.ts +2 -0
  201. package/dist/http/internal/clientPath.d.ts.map +1 -0
  202. package/dist/http/internal/clientPath.js +24 -0
  203. package/dist/http/internal/clientPath.js.map +1 -0
  204. package/dist/http/internal/redactedPath.js +2 -0
  205. package/dist/http/internal/redactedPath.js.map +1 -1
  206. package/dist/http/internal/tracing.js +5 -3
  207. package/dist/http/internal/tracing.js.map +1 -1
  208. package/dist/http-api/HttpApi.d.ts +2 -2
  209. package/dist/http-api/HttpApi.d.ts.map +1 -1
  210. package/dist/http-api/HttpApi.js +30 -7
  211. package/dist/http-api/HttpApi.js.map +1 -1
  212. package/dist/http-api/HttpApiBuilder.d.ts.map +1 -1
  213. package/dist/http-api/HttpApiBuilder.js +5 -2
  214. package/dist/http-api/HttpApiBuilder.js.map +1 -1
  215. package/dist/http-api/HttpApiClient.d.ts.map +1 -1
  216. package/dist/http-api/HttpApiClient.js +23 -6
  217. package/dist/http-api/HttpApiClient.js.map +1 -1
  218. package/dist/http-api/internal/redactedKeys.d.ts +2 -0
  219. package/dist/http-api/internal/redactedKeys.d.ts.map +1 -0
  220. package/dist/http-api/internal/redactedKeys.js +37 -0
  221. package/dist/http-api/internal/redactedKeys.js.map +1 -0
  222. package/dist/internal/base64.js +34 -2
  223. package/dist/internal/base64.js.map +1 -1
  224. package/dist/internal/core.js +60 -43
  225. package/dist/internal/core.js.map +1 -1
  226. package/dist/internal/dateTime.js +35 -17
  227. package/dist/internal/dateTime.js.map +1 -1
  228. package/dist/internal/effect.js +60 -52
  229. package/dist/internal/effect.js.map +1 -1
  230. package/dist/internal/equal.js +44 -13
  231. package/dist/internal/equal.js.map +1 -1
  232. package/dist/internal/fiberCachedKeys.d.ts +2 -0
  233. package/dist/internal/fiberCachedKeys.d.ts.map +1 -0
  234. package/dist/internal/fiberCachedKeys.js +48 -0
  235. package/dist/internal/fiberCachedKeys.js.map +1 -0
  236. package/dist/internal/hashMap.js +1 -1
  237. package/dist/internal/hashMap.js.map +1 -1
  238. package/dist/internal/matcher.js +17 -17
  239. package/dist/internal/matcher.js.map +1 -1
  240. package/dist/internal/predicate.d.ts +2 -0
  241. package/dist/internal/predicate.d.ts.map +1 -0
  242. package/dist/internal/predicate.js +10 -0
  243. package/dist/internal/predicate.js.map +1 -0
  244. package/dist/internal/references.js +8 -11
  245. package/dist/internal/references.js.map +1 -1
  246. package/dist/internal/schema/schemaCodegen.js +3 -2
  247. package/dist/internal/schema/schemaCodegen.js.map +1 -1
  248. package/dist/internal/schema/schemaCodegenBuiltIns.d.ts +2 -0
  249. package/dist/internal/schema/schemaCodegenBuiltIns.d.ts.map +1 -0
  250. package/dist/internal/schema/schemaCodegenBuiltIns.js +425 -0
  251. package/dist/internal/schema/schemaCodegenBuiltIns.js.map +1 -0
  252. package/dist/internal/schema/toEquivalence.js +3 -4
  253. package/dist/internal/schema/toEquivalence.js.map +1 -1
  254. package/dist/internal/version.js +1 -1
  255. package/dist/jose/JoseError.d.ts +51 -1
  256. package/dist/jose/JoseError.d.ts.map +1 -1
  257. package/dist/jose/JoseError.js +25 -18
  258. package/dist/jose/JoseError.js.map +1 -1
  259. package/dist/jose/internal/compact.js +10 -5
  260. package/dist/jose/internal/compact.js.map +1 -1
  261. package/dist/observability/Otlp.d.ts +19 -0
  262. package/dist/observability/Otlp.d.ts.map +1 -1
  263. package/dist/observability/Otlp.js +10 -0
  264. package/dist/observability/Otlp.js.map +1 -1
  265. package/dist/observability/OtlpExporter.d.ts +49 -13
  266. package/dist/observability/OtlpExporter.d.ts.map +1 -1
  267. package/dist/observability/OtlpExporter.js +135 -54
  268. package/dist/observability/OtlpExporter.js.map +1 -1
  269. package/dist/observability/OtlpLogger.d.ts +14 -0
  270. package/dist/observability/OtlpLogger.d.ts.map +1 -1
  271. package/dist/observability/OtlpLogger.js +10 -2
  272. package/dist/observability/OtlpLogger.js.map +1 -1
  273. package/dist/observability/OtlpMetrics.d.ts.map +1 -1
  274. package/dist/observability/OtlpMetrics.js +2 -0
  275. package/dist/observability/OtlpMetrics.js.map +1 -1
  276. package/dist/observability/OtlpTracer.d.ts +14 -0
  277. package/dist/observability/OtlpTracer.d.ts.map +1 -1
  278. package/dist/observability/OtlpTracer.js +10 -2
  279. package/dist/observability/OtlpTracer.js.map +1 -1
  280. package/dist/persistence/KeyValueStore.d.ts.map +1 -1
  281. package/dist/persistence/KeyValueStore.js +6 -4
  282. package/dist/persistence/KeyValueStore.js.map +1 -1
  283. package/dist/reactivity/Atom.d.ts.map +1 -1
  284. package/dist/reactivity/Atom.js +10 -9
  285. package/dist/reactivity/Atom.js.map +1 -1
  286. package/dist/rpc/RpcClient.d.ts.map +1 -1
  287. package/dist/rpc/RpcClient.js +32 -1
  288. package/dist/rpc/RpcClient.js.map +1 -1
  289. package/dist/rpc/RpcGroup.d.ts +1 -1
  290. package/dist/rpc/RpcGroup.d.ts.map +1 -1
  291. package/dist/rpc/RpcGroup.js +4 -0
  292. package/dist/rpc/RpcGroup.js.map +1 -1
  293. package/dist/sql/Migrator.d.ts.map +1 -1
  294. package/dist/sql/Migrator.js +2 -5
  295. package/dist/sql/Migrator.js.map +1 -1
  296. package/dist/sql/SqlClient.d.ts.map +1 -1
  297. package/dist/sql/SqlClient.js +5 -1
  298. package/dist/sql/SqlClient.js.map +1 -1
  299. package/dist/sql/Statement.d.ts +23 -0
  300. package/dist/sql/Statement.d.ts.map +1 -1
  301. package/dist/sql/Statement.js +30 -5
  302. package/dist/sql/Statement.js.map +1 -1
  303. package/dist/workers/Worker.d.ts +21 -0
  304. package/dist/workers/Worker.d.ts.map +1 -1
  305. package/dist/workers/Worker.js +23 -0
  306. package/dist/workers/Worker.js.map +1 -1
  307. package/dist/workflow/Activity.d.ts +18 -0
  308. package/dist/workflow/Activity.d.ts.map +1 -1
  309. package/dist/workflow/Activity.js +13 -4
  310. package/dist/workflow/Activity.js.map +1 -1
  311. package/dist/workflow/Workflow.d.ts +10 -9
  312. package/dist/workflow/Workflow.d.ts.map +1 -1
  313. package/dist/workflow/Workflow.js +33 -22
  314. package/dist/workflow/Workflow.js.map +1 -1
  315. package/dist/workflow/WorkflowEngine.d.ts.map +1 -1
  316. package/dist/workflow/WorkflowEngine.js +26 -12
  317. package/dist/workflow/WorkflowEngine.js.map +1 -1
  318. package/dist/workflow/internal/retry.d.ts +2 -0
  319. package/dist/workflow/internal/retry.d.ts.map +1 -0
  320. package/dist/workflow/internal/retry.js +11 -0
  321. package/dist/workflow/internal/retry.js.map +1 -0
  322. package/dist/workflow/internal/scope.d.ts +2 -0
  323. package/dist/workflow/internal/scope.d.ts.map +1 -0
  324. package/dist/workflow/internal/scope.js +26 -0
  325. package/dist/workflow/internal/scope.js.map +1 -0
  326. package/package.json +3 -3
  327. package/src/Channel.ts +105 -8
  328. package/src/Codegen.ts +7 -2
  329. package/src/Config.ts +6 -3
  330. package/src/Context.ts +108 -50
  331. package/src/Cron.ts +11 -10
  332. package/src/Effect.ts +224 -48
  333. package/src/Equal.ts +93 -80
  334. package/src/Formatter.ts +4 -4
  335. package/src/Hash.ts +49 -48
  336. package/src/LayerRef.ts +6 -4
  337. package/src/Logger.ts +68 -25
  338. package/src/Match.ts +78 -50
  339. package/src/Metric.ts +4 -4
  340. package/src/Order.ts +1 -1
  341. package/src/Pool.ts +62 -33
  342. package/src/Predicate.ts +2 -5
  343. package/src/Scheduler.ts +27 -10
  344. package/src/Schema.ts +79 -296
  345. package/src/SchemaAST.ts +231 -157
  346. package/src/SchemaParser.ts +40 -57
  347. package/src/ScopedCache.ts +6 -4
  348. package/src/Stream.ts +167 -33
  349. package/src/String.ts +1 -1
  350. package/src/Tracer.ts +11 -2
  351. package/src/ai/McpClient.ts +157 -15
  352. package/src/ai/McpClientError.ts +55 -4
  353. package/src/ai/McpServer.ts +318 -91
  354. package/src/ai/Prompt.ts +20 -3
  355. package/src/ai/Skill.ts +236 -0
  356. package/src/ai/index.ts +6 -0
  357. package/src/ai/internal/mcpProtocol/v2024_11_05.ts +8 -13
  358. package/src/ai/internal/mcpProtocol/v2025_03_26.ts +13 -15
  359. package/src/ai/internal/mcpProtocol/v2025_06_18.ts +21 -23
  360. package/src/ai/internal/mcpProtocol/v2025_11_25.ts +22 -24
  361. package/src/ai/internal/mcpProtocol/v2026_07_28.ts +1 -1
  362. package/src/ai/internal/mcpProtocol.ts +15 -0
  363. package/src/ai/internal/mcpRuntime.ts +36 -13
  364. package/src/ai/internal/mcpSchema/v2024_11_05.ts +2 -1
  365. package/src/ai/internal/mcpSchema/v2025_03_26.ts +1 -9
  366. package/src/ai/internal/mcpSchema/v2025_06_18.ts +3 -10
  367. package/src/ai/internal/mcpSchema/v2025_11_25.ts +1 -9
  368. package/src/ai/internal/mcpSchema/v2026_07_28.ts +6 -8
  369. package/src/cluster/ClusterCron.ts +31 -20
  370. package/src/cluster/ClusterWorkflowEngine.ts +172 -96
  371. package/src/cluster/MessageStorage.ts +51 -2
  372. package/src/cluster/SqlMessageStorage.ts +88 -36
  373. package/src/cluster/internal/entityActivation.ts +6 -0
  374. package/src/cluster/internal/entityManager.ts +8 -4
  375. package/src/encoding/Base64.ts +5 -1
  376. package/src/encoding/Base64Url.ts +6 -1
  377. package/src/encoding/Hex.ts +5 -5
  378. package/src/encoding/Xml.ts +96 -26
  379. package/src/http/FetchHttpClient.ts +8 -5
  380. package/src/http/Headers.ts +309 -3
  381. package/src/http/HttpClient.ts +19 -7
  382. package/src/http/HttpClientError.ts +42 -9
  383. package/src/http/HttpClientRequest.ts +51 -0
  384. package/src/http/HttpClientResponse.ts +156 -0
  385. package/src/http/HttpEffect.ts +23 -3
  386. package/src/http/HttpMiddleware.ts +1 -1
  387. package/src/http/HttpServerError.ts +1 -1
  388. package/src/http/HttpServerResponse.ts +126 -0
  389. package/src/http/Multipart.ts +0 -5
  390. package/src/http/MultipartParser/internal/contentType.ts +1 -1
  391. package/src/http/internal/clientPath.ts +39 -0
  392. package/src/http/internal/redactedPath.ts +4 -0
  393. package/src/http/internal/tracing.ts +6 -3
  394. package/src/http-api/HttpApi.ts +29 -8
  395. package/src/http-api/HttpApiBuilder.ts +7 -2
  396. package/src/http-api/HttpApiClient.ts +30 -7
  397. package/src/http-api/internal/redactedKeys.ts +40 -0
  398. package/src/internal/base64.ts +57 -2
  399. package/src/internal/core.ts +80 -44
  400. package/src/internal/dateTime.ts +43 -24
  401. package/src/internal/effect.ts +115 -157
  402. package/src/internal/equal.ts +73 -17
  403. package/src/internal/fiberCachedKeys.ts +81 -0
  404. package/src/internal/hashMap.ts +1 -1
  405. package/src/internal/matcher.ts +34 -113
  406. package/src/internal/predicate.ts +10 -0
  407. package/src/internal/references.ts +21 -14
  408. package/src/internal/schema/schemaCodegen.ts +5 -4
  409. package/src/internal/schema/schemaCodegenBuiltIns.ts +343 -0
  410. package/src/internal/schema/toEquivalence.ts +3 -5
  411. package/src/internal/version.ts +1 -1
  412. package/src/jose/JoseError.ts +34 -0
  413. package/src/jose/internal/compact.ts +14 -5
  414. package/src/observability/Otlp.ts +29 -0
  415. package/src/observability/OtlpExporter.ts +206 -75
  416. package/src/observability/OtlpLogger.ts +24 -2
  417. package/src/observability/OtlpMetrics.ts +2 -0
  418. package/src/observability/OtlpTracer.ts +24 -3
  419. package/src/persistence/KeyValueStore.ts +17 -14
  420. package/src/reactivity/Atom.ts +12 -18
  421. package/src/rpc/RpcClient.ts +26 -1
  422. package/src/rpc/RpcGroup.ts +4 -1
  423. package/src/sql/Migrator.ts +2 -11
  424. package/src/sql/SqlClient.ts +14 -8
  425. package/src/sql/Statement.ts +48 -12
  426. package/src/workers/Worker.ts +25 -0
  427. package/src/workflow/Activity.ts +28 -4
  428. package/src/workflow/Workflow.ts +68 -44
  429. package/src/workflow/WorkflowEngine.ts +38 -15
  430. package/src/workflow/internal/retry.ts +12 -0
  431. package/src/workflow/internal/scope.ts +36 -0
  432. package/dist/internal/hash.d.ts +0 -2
  433. package/dist/internal/hash.d.ts.map +0 -1
  434. package/dist/internal/hash.js +0 -11
  435. package/dist/internal/hash.js.map +0 -1
  436. package/dist/internal/metric.d.ts +0 -2
  437. package/dist/internal/metric.d.ts.map +0 -1
  438. package/dist/internal/metric.js +0 -3
  439. package/dist/internal/metric.js.map +0 -1
  440. package/src/internal/hash.ts +0 -11
  441. package/src/internal/metric.ts +0 -2
@@ -0,0 +1,236 @@
1
+ /**
2
+ * Standalone Agent Skill value and schema for local agents and MCP servers.
3
+ *
4
+ * A `Skill` models an Agent Skill (https://agentskills.io/specification) as
5
+ * plain data — validated YAML `frontmatter`, markdown `instructions`, and
6
+ * supporting `files` — with `SKILL.md` as its serialization format via
7
+ * {@link toFiles} and {@link fromFiles}.
8
+ *
9
+ * @stability unstable
10
+ * @since 4.1.6
11
+ */
12
+ import * as Cause from "../Cause.ts"
13
+ import * as Effect from "../Effect.ts"
14
+ import * as Yaml from "../encoding/Yaml.ts"
15
+ import * as Predicate from "../Predicate.ts"
16
+ import * as Schema from "../Schema.ts"
17
+ import * as SchemaTransformation from "../SchemaTransformation.ts"
18
+
19
+ const SKILL_NAME = /^[a-z0-9]+(?:-[a-z0-9]+)*$/
20
+
21
+ /**
22
+ * Schema for the YAML frontmatter of an Agent Skill's `SKILL.md`, as the
23
+ * Agent Skills specification defines it (https://agentskills.io/specification).
24
+ *
25
+ * **Details**
26
+ *
27
+ * Fields the specification does not define are kept unchanged.
28
+ *
29
+ * @stability unstable
30
+ * @category schemas
31
+ * @since 4.1.6
32
+ */
33
+ export const Frontmatter = Schema.StructWithRest(
34
+ Schema.Struct({
35
+ /**
36
+ * 1 to 64 lowercase letters, digits and hyphens, with no leading, trailing
37
+ * or consecutive hyphen. It names the directory holding `SKILL.md`.
38
+ */
39
+ name: Schema.String.check(Schema.isMaxLength(64), Schema.isPattern(SKILL_NAME)),
40
+ /**
41
+ * What the skill does and when to use it, in 1 to 1024 characters.
42
+ */
43
+ description: Schema.String.check(Schema.isNonEmpty(), Schema.isMaxLength(1024)),
44
+ /**
45
+ * The skill's license, or the name of a bundled license file.
46
+ */
47
+ license: Schema.optionalKey(Schema.String),
48
+ /**
49
+ * Environment requirements, in 1 to 500 characters.
50
+ */
51
+ compatibility: Schema.optionalKey(Schema.String.check(Schema.isNonEmpty(), Schema.isMaxLength(500))),
52
+ /**
53
+ * Additional properties not defined by the specification.
54
+ */
55
+ metadata: Schema.optionalKey(Schema.Record(Schema.String, Schema.String)),
56
+ /**
57
+ * Space-separated tools the skill asks to run without approval. Hosts must
58
+ * ignore it for a skill served over MCP unless the user approved the grant.
59
+ */
60
+ "allowed-tools": Schema.optionalKey(Schema.String)
61
+ }),
62
+ [Schema.JsonObject]
63
+ )
64
+
65
+ /**
66
+ * The YAML frontmatter of an Agent Skill's `SKILL.md`.
67
+ *
68
+ * @stability unstable
69
+ * @category models
70
+ * @since 4.1.6
71
+ */
72
+ export type Frontmatter = typeof Frontmatter.Type
73
+
74
+ const isSafeSkillFilePath = (path: string): boolean =>
75
+ path !== "" &&
76
+ path !== "SKILL.md" &&
77
+ !path.includes("\\") &&
78
+ !/^[A-Za-z]:/.test(path) &&
79
+ path.split("/").every((segment) => segment !== "" && segment !== "." && segment !== "..")
80
+
81
+ const Bytes = Schema.Uint8Array.annotate({
82
+ toCodecJson: () =>
83
+ Schema.link<Uint8Array<ArrayBufferLike>>()(
84
+ Schema.Struct({ base64: Schema.Uint8ArrayFromBase64 }),
85
+ SchemaTransformation.transform({
86
+ decode: ({ base64 }) => base64,
87
+ encode: (base64) => ({ base64 })
88
+ })
89
+ )
90
+ })
91
+
92
+ const SkillFiles = Schema.Record(Schema.String, Schema.Union([Schema.String, Bytes])).check(
93
+ Schema.makeFilter((files) => {
94
+ const path = Object.keys(files).find((path) => !isSafeSkillFilePath(path))
95
+ return path === undefined || `Invalid skill file path "${path}"`
96
+ })
97
+ )
98
+
99
+ /**
100
+ * Schema and class for an Agent Skill bundle.
101
+ *
102
+ * **Details**
103
+ *
104
+ * Holds validated {@link Frontmatter}, markdown `instructions`, and supporting
105
+ * `files` keyed by safe relative paths (excluding `SKILL.md`). When encoded
106
+ * with `Schema.toCodecJson`, binary `Uint8Array` files are represented as
107
+ * `{ base64: string }` so text and binary files stay distinct.
108
+ *
109
+ * @see {@link make} for constructing a skill
110
+ * @see {@link toFiles} for rendering a skill to a file map including `SKILL.md`
111
+ * @see {@link fromFiles} for parsing a skill from a file map containing `SKILL.md`
112
+ *
113
+ * @stability unstable
114
+ * @category models
115
+ * @since 4.1.6
116
+ */
117
+ export class Skill extends Schema.Class<Skill>("effect/ai/Skill")({
118
+ frontmatter: Frontmatter,
119
+ instructions: Schema.String,
120
+ files: SkillFiles
121
+ }) {}
122
+
123
+ /**
124
+ * Constructs a validated {@link Skill}.
125
+ *
126
+ * **Gotchas**
127
+ *
128
+ * Throws an `Error` (with the validation issue on `cause`) when `frontmatter`
129
+ * fails validation or any key in `files` is `"SKILL.md"` or an unsafe path.
130
+ * Use {@link fromFiles} or `Schema.decodeUnknownEffect(Skill)` for untrusted input.
131
+ *
132
+ * @see {@link fromFiles} for effectful construction from a raw file map
133
+ *
134
+ * @stability unstable
135
+ * @category constructors
136
+ * @since 4.1.6
137
+ */
138
+ export const make = (options: {
139
+ readonly frontmatter: Frontmatter
140
+ readonly instructions: string
141
+ readonly files?: Readonly<Record<string, string | Uint8Array>> | undefined
142
+ }): Skill => new Skill({ ...options, files: options.files ?? {} })
143
+
144
+ /**
145
+ * Renders a {@link Skill} into a file map that includes the generated
146
+ * `SKILL.md` along with all supporting files.
147
+ *
148
+ * **Details**
149
+ *
150
+ * Frontmatter keys and values are JSON-encoded so YAML edge cases round-trip
151
+ * cleanly through {@link fromFiles}.
152
+ *
153
+ * @see {@link fromFiles} for parsing a file map back into a {@link Skill}
154
+ *
155
+ * @stability unstable
156
+ * @category conversions
157
+ * @since 4.1.6
158
+ */
159
+ export const toFiles = (
160
+ self: Skill
161
+ ): { readonly "SKILL.md": string } & Readonly<Record<string, string | Uint8Array>> => {
162
+ const frontmatter = Object.entries(self.frontmatter)
163
+ .map(([key, value]) => `${JSON.stringify(key)}: ${JSON.stringify(value)}`)
164
+ .join("\n")
165
+ return { "SKILL.md": `---\n${frontmatter}\n---\n\n${self.instructions}`, ...self.files }
166
+ }
167
+
168
+ const utf8 = new TextDecoder("utf-8", { fatal: true, ignoreBOM: true })
169
+
170
+ const decodeUtf8 = (content: Uint8Array): string | undefined => {
171
+ try {
172
+ return utf8.decode(content)
173
+ } catch {
174
+ return undefined
175
+ }
176
+ }
177
+
178
+ const FRONTMATTER = /^\uFEFF?---\r?\n([\s\S]*?)\r?\n---[ \t]*(?:\r?\n|$)/
179
+
180
+ const parseSkillMarkdown = (
181
+ markdown: string
182
+ ): { readonly frontmatter: Record<string, unknown>; readonly instructions: string } | undefined => {
183
+ const match = FRONTMATTER.exec(markdown)
184
+ if (match === null) return undefined
185
+ try {
186
+ const parsed = Yaml.parse(match[1])
187
+ if (!Predicate.isObject(parsed)) return undefined
188
+ // Keep only JSON values so `.inf` and `.nan` normalize to `null`.
189
+ const frontmatter: Record<string, unknown> = JSON.parse(JSON.stringify(parsed))
190
+ const instructions = markdown.slice(match[0].length).replace(/^\r?\n/, "")
191
+ return { frontmatter, instructions }
192
+ } catch {
193
+ return undefined
194
+ }
195
+ }
196
+
197
+ const decodeSkill = Schema.decodeUnknownEffect(Skill)
198
+
199
+ /**
200
+ * Parses a {@link Skill} from a file map containing `SKILL.md` and optional
201
+ * supporting files.
202
+ *
203
+ * **Details**
204
+ *
205
+ * Fails with `Cause.IllegalArgumentError` when `SKILL.md` is missing, not
206
+ * valid UTF-8, lacks a valid YAML frontmatter block, or fails {@link Skill}
207
+ * schema validation.
208
+ *
209
+ * @see {@link toFiles} for the inverse conversion
210
+ * @see {@link make} for constructing a skill from structured fields
211
+ *
212
+ * @stability unstable
213
+ * @category constructors
214
+ * @since 4.1.6
215
+ */
216
+ export const fromFiles = (
217
+ files: Readonly<Record<string, string | Uint8Array>>
218
+ ): Effect.Effect<Skill, Cause.IllegalArgumentError> =>
219
+ Effect.suspend(() => {
220
+ // Rest destructuring defines own properties, so a file named `__proto__` survives.
221
+ const { "SKILL.md": skillMd, ...supportingFiles } = files
222
+ if (skillMd === undefined) {
223
+ return Effect.fail(new Cause.IllegalArgumentError("Skill is missing SKILL.md"))
224
+ }
225
+ const markdown = typeof skillMd === "string" ? skillMd : decodeUtf8(skillMd)
226
+ if (markdown === undefined) {
227
+ return Effect.fail(new Cause.IllegalArgumentError("SKILL.md is not valid UTF-8"))
228
+ }
229
+ const parsed = parseSkillMarkdown(markdown)
230
+ if (parsed === undefined) {
231
+ return Effect.fail(new Cause.IllegalArgumentError("SKILL.md is missing valid YAML frontmatter"))
232
+ }
233
+ return decodeSkill({ ...parsed, files: supportingFiles }).pipe(
234
+ Effect.mapError((error) => new Cause.IllegalArgumentError(error.message))
235
+ )
236
+ })
package/src/ai/index.ts CHANGED
@@ -137,6 +137,12 @@ export * as Response from "./Response.ts"
137
137
  */
138
138
  export * as ResponseIdTracker from "./ResponseIdTracker.ts"
139
139
 
140
+ /**
141
+ * @stability unstable
142
+ * @since 4.1.6
143
+ */
144
+ export * as Skill from "./Skill.ts"
145
+
140
146
  /**
141
147
  * @stability unstable
142
148
  * @since 4.0.0
@@ -18,6 +18,12 @@ const ClientRpcs = ClientRequestRpcs.merge(McpSchema.ClientNotificationRpcs)
18
18
 
19
19
  const AdapterRpcs = ClientRpcs.omit("ping")
20
20
 
21
+ const projectTool = McpProtocol.makeToolProjector(McpSchema.Tool, (tool) => ({
22
+ name: tool.name,
23
+ description: tool.description,
24
+ inputSchema: McpProtocol.projectLegacyToolInputSchema(tool.inputSchema)
25
+ }))
26
+
21
27
  const profileFromInitialize = (
22
28
  initialize: typeof McpSchema.Initialize.payloadSchema.Type
23
29
  ): McpCore.NegotiatedProtocolProfile => ({
@@ -246,19 +252,8 @@ export const protocol = McpProtocol.make({
246
252
  })
247
253
  }),
248
254
  "tools/list": Effect.fnUntraced(function*(pageRequest) {
249
- return yield* McpProtocol.listForClient(core.tools.list, pageRequest?.cursor).pipe(
250
- Effect.map((tools) =>
251
- McpSchema.ListToolsResult.make({
252
- tools: tools.map((tool) =>
253
- McpSchema.Tool.make({
254
- name: tool.name,
255
- description: tool.description,
256
- inputSchema: McpProtocol.projectLegacyToolInputSchema(tool.inputSchema)
257
- })
258
- )
259
- })
260
- )
261
- )
255
+ const tools = yield* McpProtocol.listForClient(core.tools.list, pageRequest?.cursor)
256
+ return { tools: yield* Effect.orDie(Effect.forEach(tools, projectTool)) }
262
257
  }),
263
258
  "tools/call": Effect.fnUntraced(function*(call) {
264
259
  const request = yield* PublicMcpSchema.McpServerClient
@@ -18,6 +18,18 @@ const ClientRpcs = ClientRequestRpcs.merge(McpSchema.ClientNotificationRpcs)
18
18
 
19
19
  const AdapterRpcs = ClientRpcs.omit("ping")
20
20
 
21
+ const projectTool = McpProtocol.makeToolProjector(McpSchema.Tool, (tool) => ({
22
+ name: tool.name,
23
+ description: tool.description,
24
+ inputSchema: McpProtocol.projectLegacyToolInputSchema(tool.inputSchema),
25
+ annotations: tool.title === undefined && tool.annotations === undefined
26
+ ? undefined
27
+ : {
28
+ ...tool.annotations,
29
+ title: tool.title
30
+ }
31
+ }))
32
+
21
33
  const profileFromInitialize = (
22
34
  initialize: typeof McpSchema.Initialize.payloadSchema.Type
23
35
  ): McpCore.NegotiatedProtocolProfile => ({
@@ -270,21 +282,7 @@ export const protocol = McpProtocol.make({
270
282
  }),
271
283
  "tools/list": Effect.fnUntraced(function*(pageRequest) {
272
284
  const tools = yield* McpProtocol.listForClient(core.tools.list, pageRequest?.cursor)
273
- return McpSchema.ListToolsResult.make({
274
- tools: tools.map((tool) =>
275
- McpSchema.Tool.make({
276
- name: tool.name,
277
- description: tool.description,
278
- inputSchema: McpProtocol.projectLegacyToolInputSchema(tool.inputSchema),
279
- annotations: tool.title === undefined && tool.annotations === undefined
280
- ? undefined
281
- : McpSchema.ToolAnnotations.make({
282
- ...tool.annotations,
283
- title: tool.title
284
- })
285
- })
286
- )
287
- })
285
+ return { tools: yield* Effect.orDie(Effect.forEach(tools, projectTool)) }
288
286
  }),
289
287
  "tools/call": Effect.fnUntraced(function*(call) {
290
288
  const request = yield* PublicMcpSchema.McpServerClient
@@ -35,6 +35,26 @@ const isToolOutputSchema = (
35
35
  return isPropertiesSupported && isRequiredDefined
36
36
  }
37
37
 
38
+ const projectTool = McpProtocol.makeToolProjector(McpSchema.Tool, (tool) => ({
39
+ name: tool.name,
40
+ title: tool.title,
41
+ description: tool.description,
42
+ inputSchema: tool.inputSchema,
43
+ outputSchema: isToolOutputSchema(tool.outputSchema)
44
+ ? tool.outputSchema
45
+ : undefined,
46
+ annotations: tool.annotations === undefined
47
+ ? undefined
48
+ : {
49
+ title: tool.annotations.title,
50
+ readOnlyHint: tool.annotations.readOnlyHint,
51
+ destructiveHint: tool.annotations.destructiveHint,
52
+ idempotentHint: tool.annotations.idempotentHint,
53
+ openWorldHint: tool.annotations.openWorldHint
54
+ },
55
+ _meta: tool._meta
56
+ }))
57
+
38
58
  const profileFromInitialize = (
39
59
  initialize: typeof McpSchema.Initialize.payloadSchema.Type
40
60
  ): McpCore.NegotiatedProtocolProfile => ({
@@ -263,29 +283,7 @@ export const protocol = McpProtocol.make({
263
283
  }),
264
284
  "tools/list": Effect.fnUntraced(function*(pageRequest) {
265
285
  const tools = yield* McpProtocol.listForClient(core.tools.list, pageRequest?.cursor)
266
- return McpSchema.ListToolsResult.make({
267
- tools: tools.map((tool) =>
268
- McpSchema.Tool.make({
269
- name: tool.name,
270
- title: tool.title,
271
- description: tool.description,
272
- inputSchema: tool.inputSchema,
273
- outputSchema: isToolOutputSchema(tool.outputSchema)
274
- ? tool.outputSchema
275
- : undefined,
276
- annotations: tool.annotations === undefined
277
- ? undefined
278
- : McpSchema.ToolAnnotations.make({
279
- title: tool.annotations.title,
280
- readOnlyHint: tool.annotations.readOnlyHint,
281
- destructiveHint: tool.annotations.destructiveHint,
282
- idempotentHint: tool.annotations.idempotentHint,
283
- openWorldHint: tool.annotations.openWorldHint
284
- }),
285
- _meta: tool._meta
286
- })
287
- )
288
- })
286
+ return { tools: yield* Effect.orDie(Effect.forEach(tools, projectTool)) }
289
287
  }),
290
288
  "tools/call": Effect.fnUntraced(function*(call) {
291
289
  const request = yield* PublicMcpSchema.McpServerClient
@@ -34,6 +34,27 @@ const isToolOutputSchema = (
34
34
  return isPropertiesSupported && isRequiredDefined
35
35
  }
36
36
 
37
+ const projectTool = McpProtocol.makeToolProjector(McpSchema.Tool, (tool) => ({
38
+ name: tool.name,
39
+ title: tool.title,
40
+ description: tool.description,
41
+ inputSchema: tool.inputSchema,
42
+ outputSchema: isToolOutputSchema(tool.outputSchema)
43
+ ? tool.outputSchema
44
+ : undefined,
45
+ icons: tool.icons,
46
+ annotations: tool.annotations === undefined
47
+ ? undefined
48
+ : {
49
+ title: tool.annotations.title,
50
+ readOnlyHint: tool.annotations.readOnlyHint,
51
+ destructiveHint: tool.annotations.destructiveHint,
52
+ idempotentHint: tool.annotations.idempotentHint,
53
+ openWorldHint: tool.annotations.openWorldHint
54
+ },
55
+ _meta: tool._meta
56
+ }))
57
+
37
58
  const unsupported = (
38
59
  operation: PublicMcpSchema.McpReverseOperationUnsupported["operation"],
39
60
  reason: string
@@ -286,30 +307,7 @@ export const protocol = McpProtocol.make({
286
307
  }),
287
308
  "tools/list": Effect.fnUntraced(function*(pageRequest) {
288
309
  const tools = yield* McpProtocol.listForClient(core.tools.list, pageRequest?.cursor)
289
- return McpSchema.ListToolsResult.make({
290
- tools: tools.map((tool) =>
291
- McpSchema.Tool.make({
292
- name: tool.name,
293
- title: tool.title,
294
- description: tool.description,
295
- inputSchema: tool.inputSchema,
296
- outputSchema: isToolOutputSchema(tool.outputSchema)
297
- ? tool.outputSchema
298
- : undefined,
299
- icons: tool.icons,
300
- annotations: tool.annotations === undefined
301
- ? undefined
302
- : McpSchema.ToolAnnotations.make({
303
- title: tool.annotations.title,
304
- readOnlyHint: tool.annotations.readOnlyHint,
305
- destructiveHint: tool.annotations.destructiveHint,
306
- idempotentHint: tool.annotations.idempotentHint,
307
- openWorldHint: tool.annotations.openWorldHint
308
- }),
309
- _meta: tool._meta
310
- })
311
- )
312
- })
310
+ return { tools: yield* Effect.orDie(Effect.forEach(tools, projectTool)) }
313
311
  }),
314
312
  "tools/call": Effect.fnUntraced(function*(call) {
315
313
  const request = yield* PublicMcpSchema.McpServerClient
@@ -209,7 +209,7 @@ const projectResourceTemplate = (resourceTemplate: PublicMcpSchema.ResourceTempl
209
209
 
210
210
  const projectPrompt = (prompt: PublicMcpSchema.Prompt) => Schema.encodeEffect(McpSchema.Prompt)(prompt)
211
211
 
212
- const projectTool = (tool: PublicMcpSchema.Tool) => McpProtocol.transcode(PublicMcpSchema.Tool, McpSchema.Tool, tool)
212
+ const projectTool = McpProtocol.makeToolProjector(McpSchema.Tool, (tool) => tool)
213
213
 
214
214
  const privateStaleCache = {
215
215
  ttlMs: 0,
@@ -1,6 +1,7 @@
1
1
  import * as Data from "../../Data.ts"
2
2
  import * as Effect from "../../Effect.ts"
3
3
  import * as Base64 from "../../encoding/Base64.ts"
4
+ import { memoize } from "../../Function.ts"
4
5
  import type * as Headers from "../../http/Headers.ts"
5
6
  import type * as LogLevel from "../../LogLevel.ts"
6
7
  import * as Match from "../../Match.ts"
@@ -357,6 +358,20 @@ export const transcodeStrict = <
357
358
  Effect.flatMap(Schema.decodeUnknownEffect(to, { onExcessProperty: "error" }))
358
359
  )
359
360
 
361
+ /**
362
+ * Encodes each tool descriptor instance to its JSON wire form once. A
363
+ * replaced tool is a new instance, so it is encoded afresh.
364
+ *
365
+ * @internal
366
+ */
367
+ export const makeToolProjector = <A>(
368
+ schema: Schema.Codec<A, unknown>,
369
+ project: (tool: PublicMcpSchema.Tool) => A
370
+ ) => {
371
+ const encode = Schema.encodeExit(Schema.toCodecJson(schema))
372
+ return memoize((tool: PublicMcpSchema.Tool) => encode(project(tool)))
373
+ }
374
+
360
375
  /**
361
376
  * @internal
362
377
  */
@@ -61,6 +61,12 @@ const routingNameKey = (method: string): "name" | "uri" | undefined => {
61
61
  }
62
62
  }
63
63
 
64
+ /**
65
+ * @internal
66
+ */
67
+ export const jsonRpcError = (status: number, error: unknown, id: string | number | null = null) =>
68
+ HttpServerResponse.jsonUnsafe({ jsonrpc: "2.0", id, error }, { status })
69
+
64
70
  const headerMismatch = (message: string): HttpProtocolSelection => ({
65
71
  _tag: "Rejected",
66
72
  status: 400,
@@ -97,11 +103,11 @@ type HttpProtocolSelection =
97
103
  | {
98
104
  readonly _tag: "Rejected"
99
105
  readonly status: 400 | 404
100
- readonly error?: {
106
+ readonly error: {
101
107
  readonly code: number
102
108
  readonly message: string
103
109
  readonly data?: unknown
104
- } | undefined
110
+ }
105
111
  }
106
112
 
107
113
  /**
@@ -241,7 +247,7 @@ export const make = Effect.fnUntraced(function*(
241
247
  const sessionTerminationListeners = new Set<(binding: RequestBinding) => Effect.Effect<void>>()
242
248
  const unsupportedProtocolVersion = (requested: string) => ({
243
249
  code: PublicMcpSchema.UNSUPPORTED_PROTOCOL_VERSION_ERROR_CODE,
244
- message: `Unsupported protocol version '${requested}'`,
250
+ message: `Unsupported protocol version '${requested}'; supported versions: ${protocolVersions.join(", ")}`,
245
251
  data: { supported: protocolVersions, requested }
246
252
  })
247
253
  const selectHttpSession = (headers: Headers.Headers, isInitialize: boolean): HttpProtocolSelection => {
@@ -249,7 +255,15 @@ export const make = Effect.fnUntraced(function*(
249
255
  const sessionId = headers[MCP_SESSION_ID_HEADER]
250
256
  const binding = sessionId === undefined ? undefined : stateful?.resolveSessionId(sessionId)
251
257
  if (sessionId !== undefined && binding === undefined) {
252
- return { _tag: "Rejected", status: 404 }
258
+ return {
259
+ _tag: "Rejected",
260
+ status: 404,
261
+ error: {
262
+ code: PublicMcpSchema.INVALID_REQUEST_ERROR_CODE,
263
+ message:
264
+ "Unknown or expired MCP-Session-Id; send initialize without an MCP-Session-Id header to start a new session"
265
+ }
266
+ }
253
267
  }
254
268
  if (!isInitialize && protocolVersion !== undefined) {
255
269
  if (!protocolVersions.includes(protocolVersion)) {
@@ -266,6 +280,8 @@ export const make = Effect.fnUntraced(function*(
266
280
  }
267
281
  return { _tag: "Accepted", binding, protocol: binding?.protocol }
268
282
  }
283
+ const isStatelessVersion = (headers: Headers.Headers) =>
284
+ statelessProtocol !== undefined && headers[MCP_PROTOCOL_VERSION_HEADER] === statelessProtocol.protocolVersion
269
285
  const selectHttpProtocol = (headers: Headers.Headers, input: unknown): HttpProtocolSelection => {
270
286
  const protocolVersion = headers[MCP_PROTOCOL_VERSION_HEADER]
271
287
  const inputRecord = asRecord(input)
@@ -395,18 +411,17 @@ export const make = Effect.fnUntraced(function*(
395
411
  _tag: "Rejected",
396
412
  response: error === undefined
397
413
  ? HttpServerResponse.empty({ status })
398
- : HttpServerResponse.jsonUnsafe({ jsonrpc: "2.0", id, error }, { status })
414
+ : jsonRpcError(status, error, id)
399
415
  })
400
416
  if (Result.isFailure(parsed)) {
401
417
  const version = headers[MCP_PROTOCOL_VERSION_HEADER]
402
418
  if (version !== undefined && !protocolVersions.includes(version)) {
403
419
  return reject(400, unsupportedProtocolVersion(version))
404
420
  }
405
- const admission = selectHttpProtocol(headers, undefined)
406
421
  // Session and protocol-header errors take precedence over parse errors.
407
- return admission._tag === "Rejected" &&
408
- (admission.error === undefined || admission.error.code === PublicMcpSchema.HEADER_MISMATCH_ERROR_CODE)
409
- ? reject(admission.status, admission.error)
422
+ const selection = isStatelessVersion(headers) ? undefined : selectHttpSession(headers, false)
423
+ return selection?._tag === "Rejected"
424
+ ? reject(selection.status, selection.error)
410
425
  : reject(200, new PublicMcpSchema.ParseError({ message: "Parse error" }))
411
426
  }
412
427
  const input = parsed.success
@@ -414,14 +429,22 @@ export const make = Effect.fnUntraced(function*(
414
429
  if (input.length === 0) {
415
430
  return reject(400, new PublicMcpSchema.InvalidRequest({ message: "Invalid Request" }))
416
431
  }
417
- const admission = selectHttpProtocol(headers, input)
432
+ const admission = selectHttpSession(headers, false)
433
+ if (admission._tag === "Rejected") {
434
+ return reject(admission.status, admission.error)
435
+ }
418
436
  if (
419
- admission._tag === "Rejected" ||
437
+ isStatelessVersion(headers) ||
420
438
  input.some(hasRequestProtocolVersion) ||
421
439
  input.some((message) => Predicate.hasProperty(message, "method") && message.method === "initialize") ||
422
440
  admission.binding?.protocol.runtime.transport.jsonRpc.acceptsBatches !== true
423
441
  ) {
424
- return reject(400)
442
+ return reject(
443
+ 400,
444
+ new PublicMcpSchema.InvalidRequest({
445
+ message: "JSON-RPC batches are not supported; send each message in its own POST request"
446
+ })
447
+ )
425
448
  }
426
449
  return {
427
450
  _tag: "Accepted",
@@ -492,7 +515,7 @@ export const make = Effect.fnUntraced(function*(
492
515
  }
493
516
  const selection = selectHttpSession(headers, false)
494
517
  if (selection._tag === "Rejected") {
495
- return Effect.succeed(HttpServerResponse.empty({ status: selection.status }))
518
+ return Effect.succeed(jsonRpcError(selection.status, selection.error))
496
519
  }
497
520
  const binding = selection.binding!
498
521
  stateful!.terminateSession(sessionId)
@@ -408,7 +408,8 @@ export const GetPromptResult = Schema.Struct({
408
408
  */
409
409
  export const ListToolsResult = Schema.Struct({
410
410
  ...PaginatedResult.fields,
411
- tools: Schema.Array(Tool)
411
+ // Already JSON-encoded by the protocol adapter.
412
+ tools: Schema.Any
412
413
  })
413
414
 
414
415
  /**
@@ -113,14 +113,6 @@ export const GetPromptResult = Schema.Struct({
113
113
  messages: Schema.Array(PromptMessage)
114
114
  })
115
115
 
116
- /**
117
- * @internal
118
- */
119
- export const ListToolsResult = Schema.Struct({
120
- ...Previous.PaginatedResult.fields,
121
- tools: Schema.Array(Tool)
122
- })
123
-
124
116
  /**
125
117
  * @internal
126
118
  */
@@ -172,7 +164,7 @@ export class GetPrompt extends Rpc.make("prompts/get", {
172
164
  * @internal
173
165
  */
174
166
  export class ListTools extends Rpc.make("tools/list", {
175
- success: ListToolsResult,
167
+ success: Previous.ListToolsResult,
176
168
  error: Previous.McpError,
177
169
  payload: Schema.UndefinedOr(Previous.PaginatedRequest)
178
170
  }) {}
@@ -356,14 +356,6 @@ export const GetPromptResult = Schema.Struct({
356
356
  messages: Schema.Array(PromptMessage)
357
357
  })
358
358
 
359
- /**
360
- * @internal
361
- */
362
- export const ListToolsResult = Schema.Struct({
363
- ...Previous.PaginatedResult.fields,
364
- tools: Schema.Array(Tool)
365
- })
366
-
367
359
  /**
368
360
  * @internal
369
361
  */
@@ -417,7 +409,7 @@ export class GetPrompt extends Rpc.make("prompts/get", {
417
409
  * @internal
418
410
  */
419
411
  export class ListTools extends Rpc.make("tools/list", {
420
- success: ListToolsResult,
412
+ success: Previous.ListToolsResult,
421
413
  error: Previous.McpError,
422
414
  payload: Schema.UndefinedOr(Previous.PaginatedRequest)
423
415
  }) {}
@@ -479,7 +471,8 @@ const RequestedSchema = Schema.Struct({
479
471
  type: Schema.Literal("object"),
480
472
  properties: Schema.Record(
481
473
  Schema.String,
482
- Schema.Union([StringSchema, NumberSchema, BooleanSchema, EnumSchema])
474
+ // EnumSchema first: StringSchema also matches an enum and would drop its values.
475
+ Schema.Union([EnumSchema, StringSchema, NumberSchema, BooleanSchema])
483
476
  ),
484
477
  required: optional(Schema.Array(Schema.String))
485
478
  })