effect 4.0.6 → 4.0.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 (480) hide show
  1. package/dist/Arbitrary.d.ts +10 -2
  2. package/dist/Arbitrary.d.ts.map +1 -1
  3. package/dist/Arbitrary.js +2 -1
  4. package/dist/Arbitrary.js.map +1 -1
  5. package/dist/Channel.d.ts.map +1 -1
  6. package/dist/Channel.js +21 -6
  7. package/dist/Channel.js.map +1 -1
  8. package/dist/Data.d.ts +54 -235
  9. package/dist/Data.d.ts.map +1 -1
  10. package/dist/Data.js.map +1 -1
  11. package/dist/Effect.d.ts +1 -1
  12. package/dist/Effect.js +1 -1
  13. package/dist/Equal.d.ts.map +1 -1
  14. package/dist/Equal.js +8 -1
  15. package/dist/Equal.js.map +1 -1
  16. package/dist/Exit.d.ts +3 -3
  17. package/dist/Exit.d.ts.map +1 -1
  18. package/dist/Exit.js.map +1 -1
  19. package/dist/Formatter.d.ts.map +1 -1
  20. package/dist/Formatter.js +27 -13
  21. package/dist/Formatter.js.map +1 -1
  22. package/dist/Hash.d.ts.map +1 -1
  23. package/dist/Hash.js +4 -1
  24. package/dist/Hash.js.map +1 -1
  25. package/dist/JsonPatch.js +4 -0
  26. package/dist/JsonPatch.js.map +1 -1
  27. package/dist/JsonSchema.d.ts.map +1 -1
  28. package/dist/JsonSchema.js +13 -40
  29. package/dist/JsonSchema.js.map +1 -1
  30. package/dist/Metric.d.ts +3 -3
  31. package/dist/MutableList.d.ts +5 -2
  32. package/dist/MutableList.d.ts.map +1 -1
  33. package/dist/MutableList.js +7 -5
  34. package/dist/MutableList.js.map +1 -1
  35. package/dist/MutableRef.d.ts.map +1 -1
  36. package/dist/MutableRef.js +7 -0
  37. package/dist/MutableRef.js.map +1 -1
  38. package/dist/PartitionedSemaphore.d.ts +2 -1
  39. package/dist/PartitionedSemaphore.d.ts.map +1 -1
  40. package/dist/PartitionedSemaphore.js +22 -12
  41. package/dist/PartitionedSemaphore.js.map +1 -1
  42. package/dist/Pool.d.ts.map +1 -1
  43. package/dist/Pool.js +77 -27
  44. package/dist/Pool.js.map +1 -1
  45. package/dist/PubSub.d.ts.map +1 -1
  46. package/dist/PubSub.js +5 -6
  47. package/dist/PubSub.js.map +1 -1
  48. package/dist/Ref.d.ts.map +1 -1
  49. package/dist/Ref.js +8 -0
  50. package/dist/Ref.js.map +1 -1
  51. package/dist/Schedule.js +1 -1
  52. package/dist/Schedule.js.map +1 -1
  53. package/dist/Schema.d.ts +24 -8
  54. package/dist/Schema.d.ts.map +1 -1
  55. package/dist/Schema.js +37 -28
  56. package/dist/Schema.js.map +1 -1
  57. package/dist/SchemaAST.d.ts +4 -2
  58. package/dist/SchemaAST.d.ts.map +1 -1
  59. package/dist/SchemaAST.js +14 -17
  60. package/dist/SchemaAST.js.map +1 -1
  61. package/dist/SchemaParser.d.ts.map +1 -1
  62. package/dist/SchemaParser.js +48 -22
  63. package/dist/SchemaParser.js.map +1 -1
  64. package/dist/SchemaRepresentation.d.ts +19 -10
  65. package/dist/SchemaRepresentation.d.ts.map +1 -1
  66. package/dist/SchemaRepresentation.js +23 -13
  67. package/dist/SchemaRepresentation.js.map +1 -1
  68. package/dist/SchemaTransformation.d.ts +4 -1
  69. package/dist/SchemaTransformation.d.ts.map +1 -1
  70. package/dist/SchemaTransformation.js +9 -2
  71. package/dist/SchemaTransformation.js.map +1 -1
  72. package/dist/Semaphore.d.ts.map +1 -1
  73. package/dist/Semaphore.js +54 -35
  74. package/dist/Semaphore.js.map +1 -1
  75. package/dist/Sink.d.ts.map +1 -1
  76. package/dist/Sink.js +7 -2
  77. package/dist/Sink.js.map +1 -1
  78. package/dist/Stream.d.ts.map +1 -1
  79. package/dist/Stream.js +22 -10
  80. package/dist/Stream.js.map +1 -1
  81. package/dist/String.d.ts +3 -0
  82. package/dist/String.d.ts.map +1 -1
  83. package/dist/String.js +3 -0
  84. package/dist/String.js.map +1 -1
  85. package/dist/Tracer.d.ts +11 -1
  86. package/dist/Tracer.d.ts.map +1 -1
  87. package/dist/Tracer.js +6 -1
  88. package/dist/Tracer.js.map +1 -1
  89. package/dist/ai/LanguageModel.d.ts.map +1 -1
  90. package/dist/ai/LanguageModel.js +9 -0
  91. package/dist/ai/LanguageModel.js.map +1 -1
  92. package/dist/ai/McpSchema.d.ts +110 -110
  93. package/dist/ai/McpSchema.d.ts.map +1 -1
  94. package/dist/ai/McpServer.d.ts.map +1 -1
  95. package/dist/ai/McpServer.js +21 -15
  96. package/dist/ai/McpServer.js.map +1 -1
  97. package/dist/ai/Prompt.d.ts +52 -0
  98. package/dist/ai/Prompt.d.ts.map +1 -1
  99. package/dist/ai/Prompt.js +38 -0
  100. package/dist/ai/Prompt.js.map +1 -1
  101. package/dist/ai/Response.d.ts +16 -3
  102. package/dist/ai/Response.d.ts.map +1 -1
  103. package/dist/ai/Response.js +4 -0
  104. package/dist/ai/Response.js.map +1 -1
  105. package/dist/ai/Tool.d.ts +24 -0
  106. package/dist/ai/Tool.d.ts.map +1 -1
  107. package/dist/ai/Tool.js +5 -2
  108. package/dist/ai/Tool.js.map +1 -1
  109. package/dist/ai/Toolkit.d.ts.map +1 -1
  110. package/dist/ai/Toolkit.js +8 -1
  111. package/dist/ai/Toolkit.js.map +1 -1
  112. package/dist/cli/Argument.d.ts +15 -0
  113. package/dist/cli/Argument.d.ts.map +1 -1
  114. package/dist/cli/Argument.js +5 -0
  115. package/dist/cli/Argument.js.map +1 -1
  116. package/dist/cli/CliError.d.ts +78 -0
  117. package/dist/cli/CliError.d.ts.map +1 -1
  118. package/dist/cli/CliError.js +65 -3
  119. package/dist/cli/CliError.js.map +1 -1
  120. package/dist/cli/CliOutput.d.ts +155 -6
  121. package/dist/cli/CliOutput.d.ts.map +1 -1
  122. package/dist/cli/CliOutput.js +62 -6
  123. package/dist/cli/CliOutput.js.map +1 -1
  124. package/dist/cli/Command.d.ts +24 -16
  125. package/dist/cli/Command.d.ts.map +1 -1
  126. package/dist/cli/Command.js +59 -29
  127. package/dist/cli/Command.js.map +1 -1
  128. package/dist/cli/Completions.d.ts +58 -0
  129. package/dist/cli/Completions.d.ts.map +1 -1
  130. package/dist/cli/Completions.js +49 -9
  131. package/dist/cli/Completions.js.map +1 -1
  132. package/dist/cli/Flag.d.ts +15 -0
  133. package/dist/cli/Flag.d.ts.map +1 -1
  134. package/dist/cli/Flag.js +5 -0
  135. package/dist/cli/Flag.js.map +1 -1
  136. package/dist/cli/GlobalFlag.d.ts.map +1 -1
  137. package/dist/cli/GlobalFlag.js +15 -7
  138. package/dist/cli/GlobalFlag.js.map +1 -1
  139. package/dist/cli/Param.d.ts +9 -0
  140. package/dist/cli/Param.d.ts.map +1 -1
  141. package/dist/cli/Param.js +21 -2
  142. package/dist/cli/Param.js.map +1 -1
  143. package/dist/cli/TerminalCapabilities.d.ts +3 -2
  144. package/dist/cli/TerminalCapabilities.d.ts.map +1 -1
  145. package/dist/cli/TerminalCapabilities.js +3 -1
  146. package/dist/cli/TerminalCapabilities.js.map +1 -1
  147. package/dist/cli/internal/completions/bash.js +73 -27
  148. package/dist/cli/internal/completions/bash.js.map +1 -1
  149. package/dist/cluster/ClusterWorkflowEngine.d.ts.map +1 -1
  150. package/dist/cluster/ClusterWorkflowEngine.js +45 -10
  151. package/dist/cluster/ClusterWorkflowEngine.js.map +1 -1
  152. package/dist/cluster/MessageStorage.d.ts +23 -45
  153. package/dist/cluster/MessageStorage.d.ts.map +1 -1
  154. package/dist/cluster/MessageStorage.js +6 -7
  155. package/dist/cluster/MessageStorage.js.map +1 -1
  156. package/dist/cluster/Sharding.d.ts.map +1 -1
  157. package/dist/cluster/Sharding.js +61 -21
  158. package/dist/cluster/Sharding.js.map +1 -1
  159. package/dist/cluster/ShardingConfig.d.ts +10 -0
  160. package/dist/cluster/ShardingConfig.d.ts.map +1 -1
  161. package/dist/cluster/ShardingConfig.js.map +1 -1
  162. package/dist/cluster/Snowflake.d.ts.map +1 -1
  163. package/dist/cluster/Snowflake.js +3 -7
  164. package/dist/cluster/Snowflake.js.map +1 -1
  165. package/dist/cluster/SqlRunnerStorage.d.ts.map +1 -1
  166. package/dist/cluster/SqlRunnerStorage.js +87 -39
  167. package/dist/cluster/SqlRunnerStorage.js.map +1 -1
  168. package/dist/cluster/internal/entityManager.js +54 -20
  169. package/dist/cluster/internal/entityManager.js.map +1 -1
  170. package/dist/devtools/DevToolsClient.d.ts.map +1 -1
  171. package/dist/devtools/DevToolsClient.js +2 -0
  172. package/dist/devtools/DevToolsClient.js.map +1 -1
  173. package/dist/encoding/Base64.js +36 -0
  174. package/dist/encoding/Base64.js.map +1 -1
  175. package/dist/encoding/Sse.d.ts.map +1 -1
  176. package/dist/encoding/Sse.js +3 -3
  177. package/dist/encoding/Sse.js.map +1 -1
  178. package/dist/encoding/Toml.d.ts.map +1 -1
  179. package/dist/encoding/Toml.js +21 -16
  180. package/dist/encoding/Toml.js.map +1 -1
  181. package/dist/eventlog/SqlEventJournal.d.ts.map +1 -1
  182. package/dist/eventlog/SqlEventJournal.js +47 -27
  183. package/dist/eventlog/SqlEventJournal.js.map +1 -1
  184. package/dist/eventlog/internal/conflicts.d.ts +0 -1
  185. package/dist/eventlog/internal/conflicts.d.ts.map +1 -1
  186. package/dist/eventlog/internal/conflicts.js +0 -3
  187. package/dist/eventlog/internal/conflicts.js.map +1 -1
  188. package/dist/http/Cookies.d.ts.map +1 -1
  189. package/dist/http/Cookies.js +10 -9
  190. package/dist/http/Cookies.js.map +1 -1
  191. package/dist/http/HttpClient.d.ts +423 -0
  192. package/dist/http/HttpClient.d.ts.map +1 -1
  193. package/dist/http/HttpClient.js +231 -7
  194. package/dist/http/HttpClient.js.map +1 -1
  195. package/dist/http/HttpClientError.d.ts +8 -1
  196. package/dist/http/HttpClientError.d.ts.map +1 -1
  197. package/dist/http/HttpClientError.js +37 -1
  198. package/dist/http/HttpClientError.js.map +1 -1
  199. package/dist/http/HttpClientRequest.d.ts.map +1 -1
  200. package/dist/http/HttpClientRequest.js +1 -1
  201. package/dist/http/HttpClientRequest.js.map +1 -1
  202. package/dist/http/HttpMiddleware.d.ts +1 -1
  203. package/dist/http/HttpMiddleware.d.ts.map +1 -1
  204. package/dist/http/HttpMiddleware.js +14 -16
  205. package/dist/http/HttpMiddleware.js.map +1 -1
  206. package/dist/http/HttpRouter.d.ts.map +1 -1
  207. package/dist/http/HttpRouter.js +2 -1
  208. package/dist/http/HttpRouter.js.map +1 -1
  209. package/dist/http/HttpServerError.js +2 -2
  210. package/dist/http/HttpServerError.js.map +1 -1
  211. package/dist/http/HttpServerRequest.d.ts +6 -1
  212. package/dist/http/HttpServerRequest.d.ts.map +1 -1
  213. package/dist/http/HttpServerRequest.js +73 -10
  214. package/dist/http/HttpServerRequest.js.map +1 -1
  215. package/dist/http/HttpStaticServer.d.ts.map +1 -1
  216. package/dist/http/HttpStaticServer.js +48 -21
  217. package/dist/http/HttpStaticServer.js.map +1 -1
  218. package/dist/http/MultipartParser/internal/contentType.js +3 -3
  219. package/dist/http/UrlParams.d.ts +3 -1
  220. package/dist/http/UrlParams.d.ts.map +1 -1
  221. package/dist/http/UrlParams.js +4 -2
  222. package/dist/http/UrlParams.js.map +1 -1
  223. package/dist/http/internal/compression.js +4 -5
  224. package/dist/http/internal/compression.js.map +1 -1
  225. package/dist/http/internal/decompression.js +3 -0
  226. package/dist/http/internal/decompression.js.map +1 -1
  227. package/dist/http/internal/httpBody.js +8 -1
  228. package/dist/http/internal/httpBody.js.map +1 -1
  229. package/dist/http/internal/urlParams.js +25 -0
  230. package/dist/http/internal/urlParams.js.map +1 -1
  231. package/dist/http-api/HttpApi.d.ts +3 -6
  232. package/dist/http-api/HttpApi.d.ts.map +1 -1
  233. package/dist/http-api/HttpApi.js +3 -6
  234. package/dist/http-api/HttpApi.js.map +1 -1
  235. package/dist/http-api/HttpApiBuilder.d.ts.map +1 -1
  236. package/dist/http-api/HttpApiBuilder.js +27 -11
  237. package/dist/http-api/HttpApiBuilder.js.map +1 -1
  238. package/dist/http-api/HttpApiClient.d.ts +77 -7
  239. package/dist/http-api/HttpApiClient.d.ts.map +1 -1
  240. package/dist/http-api/HttpApiClient.js +142 -44
  241. package/dist/http-api/HttpApiClient.js.map +1 -1
  242. package/dist/http-api/HttpApiEndpoint.d.ts +24 -7
  243. package/dist/http-api/HttpApiEndpoint.d.ts.map +1 -1
  244. package/dist/http-api/HttpApiEndpoint.js +109 -27
  245. package/dist/http-api/HttpApiEndpoint.js.map +1 -1
  246. package/dist/http-api/HttpApiSchema.d.ts +76 -29
  247. package/dist/http-api/HttpApiSchema.d.ts.map +1 -1
  248. package/dist/http-api/HttpApiSchema.js +70 -59
  249. package/dist/http-api/HttpApiSchema.js.map +1 -1
  250. package/dist/http-api/HttpApiTest.d.ts.map +1 -1
  251. package/dist/http-api/HttpApiTest.js +3 -2
  252. package/dist/http-api/HttpApiTest.js.map +1 -1
  253. package/dist/http-api/OpenApi.d.ts.map +1 -1
  254. package/dist/http-api/OpenApi.js +25 -16
  255. package/dist/http-api/OpenApi.js.map +1 -1
  256. package/dist/http-api/internal/toCodecHttpProperties.d.ts +2 -0
  257. package/dist/http-api/internal/toCodecHttpProperties.d.ts.map +1 -0
  258. package/dist/http-api/internal/toCodecHttpProperties.js +38 -0
  259. package/dist/http-api/internal/toCodecHttpProperties.js.map +1 -0
  260. package/dist/internal/arbitrary/runner.d.ts.map +1 -1
  261. package/dist/internal/arbitrary/runner.js +120 -44
  262. package/dist/internal/arbitrary/runner.js.map +1 -1
  263. package/dist/internal/core.js +2 -0
  264. package/dist/internal/core.js.map +1 -1
  265. package/dist/internal/effect.js +21 -13
  266. package/dist/internal/effect.js.map +1 -1
  267. package/dist/internal/equal.js +14 -0
  268. package/dist/internal/equal.js.map +1 -1
  269. package/dist/internal/jsonSchema.d.ts +2 -0
  270. package/dist/internal/jsonSchema.d.ts.map +1 -0
  271. package/dist/internal/jsonSchema.js +28 -0
  272. package/dist/internal/jsonSchema.js.map +1 -0
  273. package/dist/internal/matcher.js +1 -1
  274. package/dist/internal/matcher.js.map +1 -1
  275. package/dist/internal/schema/compilerRegistry.js +4 -1
  276. package/dist/internal/schema/compilerRegistry.js.map +1 -1
  277. package/dist/internal/schema/content.d.ts +2 -0
  278. package/dist/internal/schema/content.d.ts.map +1 -0
  279. package/dist/internal/schema/content.js +13 -0
  280. package/dist/internal/schema/content.js.map +1 -0
  281. package/dist/internal/schema/fromJsonSchemaDocument.js +173 -185
  282. package/dist/internal/schema/fromJsonSchemaDocument.js.map +1 -1
  283. package/dist/internal/schema/fromRepresentation.js +2 -1
  284. package/dist/internal/schema/fromRepresentation.js.map +1 -1
  285. package/dist/internal/schema/standardSchema.js +8 -2
  286. package/dist/internal/schema/standardSchema.js.map +1 -1
  287. package/dist/internal/schema/toCodeDocument.js +3 -3
  288. package/dist/internal/schema/toCodeDocument.js.map +1 -1
  289. package/dist/internal/schema/toCodec.js +21 -24
  290. package/dist/internal/schema/toCodec.js.map +1 -1
  291. package/dist/internal/schema/toJsonSchemaDocument.js +205 -140
  292. package/dist/internal/schema/toJsonSchemaDocument.js.map +1 -1
  293. package/dist/internal/schema/toRepresentation.js +107 -129
  294. package/dist/internal/schema/toRepresentation.js.map +1 -1
  295. package/dist/internal/sql.d.ts +2 -0
  296. package/dist/internal/sql.d.ts.map +1 -0
  297. package/dist/internal/sql.js +13 -0
  298. package/dist/internal/sql.js.map +1 -0
  299. package/dist/internal/version.js +1 -1
  300. package/dist/observability/OtlpProxy.d.ts +154 -0
  301. package/dist/observability/OtlpProxy.d.ts.map +1 -0
  302. package/dist/observability/OtlpProxy.js +235 -0
  303. package/dist/observability/OtlpProxy.js.map +1 -0
  304. package/dist/observability/OtlpTracer.d.ts.map +1 -1
  305. package/dist/observability/OtlpTracer.js +4 -0
  306. package/dist/observability/OtlpTracer.js.map +1 -1
  307. package/dist/observability/index.d.ts +5 -0
  308. package/dist/observability/index.d.ts.map +1 -1
  309. package/dist/observability/index.js +5 -0
  310. package/dist/observability/index.js.map +1 -1
  311. package/dist/persistence/CircuitBreaker.d.ts +897 -0
  312. package/dist/persistence/CircuitBreaker.d.ts.map +1 -0
  313. package/dist/persistence/CircuitBreaker.js +1165 -0
  314. package/dist/persistence/CircuitBreaker.js.map +1 -0
  315. package/dist/persistence/Redis.d.ts +78 -2
  316. package/dist/persistence/Redis.d.ts.map +1 -1
  317. package/dist/persistence/Redis.js +62 -7
  318. package/dist/persistence/Redis.js.map +1 -1
  319. package/dist/persistence/index.d.ts +5 -0
  320. package/dist/persistence/index.d.ts.map +1 -1
  321. package/dist/persistence/index.js +5 -0
  322. package/dist/persistence/index.js.map +1 -1
  323. package/dist/process/ChildProcess.d.ts +30 -4
  324. package/dist/process/ChildProcess.d.ts.map +1 -1
  325. package/dist/process/ChildProcess.js.map +1 -1
  326. package/dist/process/ChildProcessSpawner.d.ts +30 -0
  327. package/dist/process/ChildProcessSpawner.d.ts.map +1 -1
  328. package/dist/process/ChildProcessSpawner.js +5 -2
  329. package/dist/process/ChildProcessSpawner.js.map +1 -1
  330. package/dist/reactivity/AsyncResult.d.ts +1 -1
  331. package/dist/reactivity/AsyncResult.d.ts.map +1 -1
  332. package/dist/rpc/RpcClient.d.ts.map +1 -1
  333. package/dist/rpc/RpcClient.js +9 -8
  334. package/dist/rpc/RpcClient.js.map +1 -1
  335. package/dist/rpc/RpcSerialization.d.ts +14 -0
  336. package/dist/rpc/RpcSerialization.d.ts.map +1 -1
  337. package/dist/rpc/RpcSerialization.js +20 -8
  338. package/dist/rpc/RpcSerialization.js.map +1 -1
  339. package/dist/rpc/RpcServer.d.ts.map +1 -1
  340. package/dist/rpc/RpcServer.js +11 -1
  341. package/dist/rpc/RpcServer.js.map +1 -1
  342. package/dist/rpc/RpcTest.d.ts +1 -0
  343. package/dist/rpc/RpcTest.d.ts.map +1 -1
  344. package/dist/rpc/RpcTest.js +1 -0
  345. package/dist/rpc/RpcTest.js.map +1 -1
  346. package/dist/sql/Migrator.d.ts +2 -1
  347. package/dist/sql/Migrator.d.ts.map +1 -1
  348. package/dist/sql/Migrator.js +11 -8
  349. package/dist/sql/Migrator.js.map +1 -1
  350. package/dist/sql/SqlClient.d.ts +9 -4
  351. package/dist/sql/SqlClient.d.ts.map +1 -1
  352. package/dist/sql/SqlClient.js +8 -1
  353. package/dist/sql/SqlClient.js.map +1 -1
  354. package/dist/sql/SqlResolver.d.ts +4 -0
  355. package/dist/sql/SqlResolver.d.ts.map +1 -1
  356. package/dist/sql/SqlResolver.js +18 -4
  357. package/dist/sql/SqlResolver.js.map +1 -1
  358. package/dist/sql/Statement.d.ts +7 -0
  359. package/dist/sql/Statement.d.ts.map +1 -1
  360. package/dist/sql/Statement.js +21 -2
  361. package/dist/sql/Statement.js.map +1 -1
  362. package/dist/workflow/DurableDeferred.d.ts.map +1 -1
  363. package/dist/workflow/DurableDeferred.js +21 -2
  364. package/dist/workflow/DurableDeferred.js.map +1 -1
  365. package/package.json +1 -1
  366. package/src/Arbitrary.ts +10 -2
  367. package/src/Channel.ts +47 -18
  368. package/src/Data.ts +60 -265
  369. package/src/Effect.ts +1 -1
  370. package/src/Equal.ts +8 -1
  371. package/src/Exit.ts +3 -3
  372. package/src/Formatter.ts +28 -13
  373. package/src/Hash.ts +4 -1
  374. package/src/JsonPatch.ts +4 -0
  375. package/src/JsonSchema.ts +12 -40
  376. package/src/Metric.ts +3 -3
  377. package/src/MutableList.ts +7 -5
  378. package/src/MutableRef.ts +8 -1
  379. package/src/PartitionedSemaphore.ts +24 -13
  380. package/src/Pool.ts +109 -37
  381. package/src/PubSub.ts +5 -6
  382. package/src/Ref.ts +8 -0
  383. package/src/Schedule.ts +1 -1
  384. package/src/Schema.ts +48 -25
  385. package/src/SchemaAST.ts +20 -20
  386. package/src/SchemaParser.ts +51 -18
  387. package/src/SchemaRepresentation.ts +31 -34
  388. package/src/SchemaTransformation.ts +9 -2
  389. package/src/Semaphore.ts +67 -40
  390. package/src/Sink.ts +15 -2
  391. package/src/Stream.ts +33 -16
  392. package/src/String.ts +3 -0
  393. package/src/Tracer.ts +15 -1
  394. package/src/ai/LanguageModel.ts +9 -0
  395. package/src/ai/McpServer.ts +14 -13
  396. package/src/ai/Prompt.ts +65 -0
  397. package/src/ai/Response.ts +34 -9
  398. package/src/ai/Tool.ts +38 -2
  399. package/src/ai/Toolkit.ts +4 -1
  400. package/src/cli/Argument.ts +15 -0
  401. package/src/cli/CliError.ts +90 -3
  402. package/src/cli/CliOutput.ts +183 -6
  403. package/src/cli/Command.ts +53 -41
  404. package/src/cli/Completions.ts +51 -0
  405. package/src/cli/Flag.ts +15 -0
  406. package/src/cli/GlobalFlag.ts +6 -7
  407. package/src/cli/Param.ts +29 -6
  408. package/src/cli/TerminalCapabilities.ts +6 -3
  409. package/src/cli/internal/completions/bash.ts +79 -29
  410. package/src/cluster/ClusterWorkflowEngine.ts +46 -16
  411. package/src/cluster/MessageStorage.ts +19 -14
  412. package/src/cluster/Sharding.ts +83 -21
  413. package/src/cluster/ShardingConfig.ts +5 -0
  414. package/src/cluster/Snowflake.ts +3 -7
  415. package/src/cluster/SqlRunnerStorage.ts +110 -47
  416. package/src/cluster/internal/entityManager.ts +75 -22
  417. package/src/devtools/DevToolsClient.ts +2 -0
  418. package/src/encoding/Base64.ts +38 -0
  419. package/src/encoding/Sse.ts +4 -3
  420. package/src/encoding/Toml.ts +33 -16
  421. package/src/eventlog/SqlEventJournal.ts +68 -45
  422. package/src/eventlog/internal/conflicts.ts +0 -4
  423. package/src/http/Cookies.ts +10 -11
  424. package/src/http/HttpClient.ts +547 -7
  425. package/src/http/HttpClientError.ts +35 -1
  426. package/src/http/HttpClientRequest.ts +9 -1
  427. package/src/http/HttpMiddleware.ts +15 -18
  428. package/src/http/HttpRouter.ts +2 -1
  429. package/src/http/HttpServerError.ts +2 -2
  430. package/src/http/HttpServerRequest.ts +102 -16
  431. package/src/http/HttpStaticServer.ts +51 -22
  432. package/src/http/MultipartParser/internal/contentType.ts +3 -3
  433. package/src/http/UrlParams.ts +6 -1
  434. package/src/http/internal/compression.ts +4 -5
  435. package/src/http/internal/decompression.ts +6 -0
  436. package/src/http/internal/httpBody.ts +10 -2
  437. package/src/http/internal/urlParams.ts +29 -0
  438. package/src/http-api/HttpApi.ts +3 -6
  439. package/src/http-api/HttpApiBuilder.ts +45 -15
  440. package/src/http-api/HttpApiClient.ts +218 -72
  441. package/src/http-api/HttpApiEndpoint.ts +121 -30
  442. package/src/http-api/HttpApiSchema.ts +141 -48
  443. package/src/http-api/HttpApiTest.ts +3 -2
  444. package/src/http-api/OpenApi.ts +20 -17
  445. package/src/http-api/internal/toCodecHttpProperties.ts +56 -0
  446. package/src/internal/arbitrary/runner.ts +133 -36
  447. package/src/internal/core.ts +2 -0
  448. package/src/internal/effect.ts +24 -16
  449. package/src/internal/equal.ts +17 -0
  450. package/src/internal/jsonSchema.ts +27 -0
  451. package/src/internal/matcher.ts +1 -1
  452. package/src/internal/schema/compilerRegistry.ts +6 -1
  453. package/src/internal/schema/content.ts +18 -0
  454. package/src/internal/schema/fromJsonSchemaDocument.ts +228 -190
  455. package/src/internal/schema/fromRepresentation.ts +2 -1
  456. package/src/internal/schema/standardSchema.ts +2 -2
  457. package/src/internal/schema/toCodeDocument.ts +4 -4
  458. package/src/internal/schema/toCodec.ts +26 -22
  459. package/src/internal/schema/toJsonSchemaDocument.ts +189 -167
  460. package/src/internal/schema/toRepresentation.ts +122 -140
  461. package/src/internal/sql.ts +14 -0
  462. package/src/internal/version.ts +1 -1
  463. package/src/observability/OtlpProxy.ts +314 -0
  464. package/src/observability/OtlpTracer.ts +4 -0
  465. package/src/observability/index.ts +6 -0
  466. package/src/persistence/CircuitBreaker.ts +1678 -0
  467. package/src/persistence/Redis.ts +129 -8
  468. package/src/persistence/index.ts +6 -0
  469. package/src/process/ChildProcess.ts +30 -4
  470. package/src/process/ChildProcessSpawner.ts +41 -2
  471. package/src/reactivity/AsyncResult.ts +1 -1
  472. package/src/rpc/RpcClient.ts +13 -10
  473. package/src/rpc/RpcSerialization.ts +32 -9
  474. package/src/rpc/RpcServer.ts +16 -1
  475. package/src/rpc/RpcTest.ts +3 -0
  476. package/src/sql/Migrator.ts +12 -7
  477. package/src/sql/SqlClient.ts +11 -4
  478. package/src/sql/SqlResolver.ts +23 -9
  479. package/src/sql/Statement.ts +30 -2
  480. package/src/workflow/DurableDeferred.ts +23 -6
@@ -1136,29 +1136,62 @@ function runSync<T>(effect: Effect.Effect<T, SchemaIssue.Issue>, message: string
1136
1136
  throw new Error("Schema validation failed", { cause: issue })
1137
1137
  }
1138
1138
 
1139
+ const constructorDefectMessage = "Constructor adapter can only throw schema issues"
1140
+
1141
+ function throwConstructorDefect(error: unknown): never {
1142
+ throw new Error(constructorDefectMessage, { cause: Cause.die(error) })
1143
+ }
1144
+
1139
1145
  function makeConstructorSync<T, E>(
1140
1146
  ast: SchemaAST.AST
1141
1147
  ): (input: E, options?: Schema.MakeOptions) => T {
1142
1148
  let entry: CompilerRegistry.Entry | undefined
1143
- let parser: Parser | undefined
1144
- return (input, options) => {
1145
- entry ??= CompilerRegistry.resolve(ast)
1146
- const parseOptions = options?.disableChecks
1147
- ? options.parseOptions ? { ...options.parseOptions, disableChecks: true } : { disableChecks: true }
1148
- : options?.parseOptions ?? SchemaAST.defaultParseOptions
1149
- const make = entry.make
1150
- if (make !== undefined && input !== InternalParser.missing) {
1151
- let output: unknown
1152
- try {
1153
- output = make(input, parseOptions)
1154
- } catch (error) {
1155
- InternalSchemaCause.getSchemaIssueOrThrow(Cause.die(error), "Constructor adapter can only throw schema issues")
1156
- throw error
1157
- }
1158
- if (output !== CompilerRegistry.invalid && output !== InternalParser.missing) return output as T
1149
+ return (input, options) => constructSync(entry ??= CompilerRegistry.resolve(ast), input, options)
1150
+ }
1151
+
1152
+ function constructSync<T>(entry: CompilerRegistry.Entry, input: unknown, options: Schema.MakeOptions | undefined): T {
1153
+ const parseOptions = options?.disableChecks
1154
+ ? options.parseOptions ? { ...options.parseOptions, disableChecks: true } : { disableChecks: true }
1155
+ : options?.parseOptions ?? SchemaAST.defaultParseOptions
1156
+ const make = entry.make
1157
+ if (make !== undefined && input !== InternalParser.missing) {
1158
+ let output: unknown
1159
+ try {
1160
+ output = make(input, parseOptions)
1161
+ } catch (error) {
1162
+ throwConstructorDefect(error)
1159
1163
  }
1160
- const result = (parser ??= entry.makeEffect)(input, parseOptions)
1161
- return runSync(parserResult<T, never>(result, input), "Constructor adapter can only throw schema issues")
1164
+ if (output !== CompilerRegistry.invalid && output !== InternalParser.missing) return output as T
1165
+ }
1166
+ return runSync(parserResult<T, never>(entry.makeEffect(input, parseOptions), input), constructorDefectMessage)
1167
+ }
1168
+
1169
+ /**
1170
+ * Constructs a class instance from its type-side declaration.
1171
+ *
1172
+ * When the declaration has no compiled constructor, the fields are validated first
1173
+ * and the instance is built outside the parser, so stacks captured by the
1174
+ * class constructor keep the caller's frames.
1175
+ *
1176
+ * @internal
1177
+ */
1178
+ export function makeClassSync<T>(
1179
+ ast: SchemaAST.AST,
1180
+ input: unknown,
1181
+ options: Schema.MakeOptions | undefined,
1182
+ construct: (fields: object) => T
1183
+ ): T {
1184
+ const entry = CompilerRegistry.resolve(ast)
1185
+ const descriptor = SchemaAST.getConstructorDescriptor(ast)
1186
+ if (descriptor === undefined || entry.make !== undefined || entry.compiledMakeEffect !== undefined) {
1187
+ return constructSync(entry, input, options)
1188
+ }
1189
+ if (descriptor.isConstructed(input)) return input as T
1190
+ const fields = constructSync<object>((entry.resolve ?? CompilerRegistry.resolve)(descriptor.link.to), input, options)
1191
+ try {
1192
+ return construct(fields)
1193
+ } catch (error) {
1194
+ throwConstructorDefect(error)
1162
1195
  }
1163
1196
  }
1164
1197
 
@@ -288,13 +288,19 @@ export interface Unknown extends Keyword<"Unknown"> {}
288
288
  export interface Any extends Keyword<"Any"> {}
289
289
 
290
290
  /**
291
- * A string representation.
291
+ * A string representation, optionally describing its content through a media
292
+ * type and a schema for the value encoded in the string.
292
293
  *
293
294
  * @stability stable
294
295
  * @category models
295
296
  * @since 4.0.0
296
297
  */
297
- export interface String extends Keyword<"String"> {}
298
+ export interface String extends Keyword<"String"> {
299
+ readonly content?: {
300
+ readonly mediaType: string
301
+ readonly schema?: Representation | undefined
302
+ } | undefined
303
+ }
298
304
 
299
305
  /**
300
306
  * A number representation.
@@ -2388,26 +2394,6 @@ export const MutableJsonReviver: DeclarationReviver<null> = makeFixedDeclaration
2388
2394
  Schema.MutableJson
2389
2395
  )
2390
2396
 
2391
- const jsonSchemaRevivers: ReadonlyArray<AnyReviver> = [
2392
- JsonReviver,
2393
- isPatternReviver,
2394
- isFiniteReviver,
2395
- isGreaterThanReviver,
2396
- isGreaterThanOrEqualToReviver,
2397
- isLessThanReviver,
2398
- isLessThanOrEqualToReviver,
2399
- isMultipleOfReviver,
2400
- isIntReviver,
2401
- isMinLengthReviver,
2402
- isMaxLengthReviver,
2403
- isMinCodePointsReviver,
2404
- isMaxCodePointsReviver,
2405
- isMinPropertiesReviver,
2406
- isMaxPropertiesReviver,
2407
- isPropertyNamesReviver,
2408
- isUniqueReviver
2409
- ]
2410
-
2411
2397
  /**
2412
2398
  * Options for importing JSON Schema Draft 2020-12 documents.
2413
2399
  *
@@ -2965,7 +2951,14 @@ const RepresentationUnion = Schema.Union([
2965
2951
  makeKeywordSchema("Never"),
2966
2952
  makeKeywordSchema("Unknown"),
2967
2953
  makeKeywordSchema("Any"),
2968
- makeKeywordSchema("String"),
2954
+ Schema.Struct({
2955
+ _tag: Schema.tag("String"),
2956
+ ...KeywordFields,
2957
+ content: Schema.optional(Schema.Struct({
2958
+ mediaType: Schema.String,
2959
+ schema: Schema.optional(RepresentationSchema)
2960
+ }))
2961
+ }),
2969
2962
  makeKeywordSchema("Number"),
2970
2963
  makeKeywordSchema("Boolean"),
2971
2964
  makeKeywordSchema("BigInt"),
@@ -3192,11 +3185,13 @@ export function fromRepresentations(
3192
3185
  * - Intersections of overlapping unions are limited to disjoint root-type partitions and finite primitive `anyOf`
3193
3186
  * literal sets. Other union intersections, including cases that would duplicate a nested choice, are rejected.
3194
3187
  * - Unknown extension keywords are ignored and their semantics are not enforced.
3195
- * - Only direct local references to top-level definitions in the form `#/$defs/<escaped-token>` are supported. Root
3196
- * references, external references, and pointers below a definition are rejected with the supported reference format.
3197
- * Missing definitions are reported by name. References reached inside nested schema
3198
- * resources introduced by `$id` are rejected instead of resolved against the top-level definitions.
3199
- * - Built-in declarations and checks are reconstructed with importer-owned revivers.
3188
+ * - Only local references to top-level definitions in the form `#/$defs/<escaped-token>` are supported, optionally
3189
+ * followed by a pointer below the definition. A pointer target becomes a definition keyed by its escaped tokens, such
3190
+ * as `Name/properties/field`, and is rejected if a top-level definition already uses that key. Root references and
3191
+ * external references are rejected with the supported reference format. Missing definitions are reported by name.
3192
+ * References reached inside nested schema resources introduced by `$id` are rejected instead of resolved against the
3193
+ * top-level definitions.
3194
+ * - Imported constraints use built-in schemas and checks.
3200
3195
  * - Pattern constraints reached during translation cause an error by default. Use `patterns: "apply"` only for trusted
3201
3196
  * documents, or `patterns: "ignore"` to skip them. Ignoring patterns can both admit invalid values and reject valid
3202
3197
  * values when `oneOf` branches start overlapping.
@@ -3214,7 +3209,7 @@ export function fromJsonSchemaDocument(
3214
3209
  document: JsonSchema.Document<"draft-2020-12">,
3215
3210
  options?: FromJsonSchemaOptions
3216
3211
  ): Schema.Top {
3217
- return InternalFromJsonSchemaDocument.fromJsonSchemaDocument(document, options, jsonSchemaRevivers)
3212
+ return InternalFromJsonSchemaDocument.fromJsonSchemaDocument(document, options)
3218
3213
  }
3219
3214
 
3220
3215
  /**
@@ -3238,10 +3233,12 @@ export function fromJsonSchemaDocument(
3238
3233
  * are supported.
3239
3234
  * - Intersections of overlapping unions are limited to disjoint root-type partitions and finite primitive `anyOf`
3240
3235
  * literal sets. Other union intersections, including cases that would duplicate a nested choice, are rejected.
3241
- * - Only direct local references to top-level definitions in the form `#/$defs/<escaped-token>` are supported. Root
3242
- * references, external references, and pointers below a definition are rejected with the supported reference format.
3243
- * Missing definitions are reported by name. References reached inside nested schema
3244
- * resources introduced by `$id` are rejected instead of resolved against the top-level definitions.
3236
+ * - Only local references to top-level definitions in the form `#/$defs/<escaped-token>` are supported, optionally
3237
+ * followed by a pointer below the definition. A pointer target becomes a definition keyed by its escaped tokens, such
3238
+ * as `Name/properties/field`, and is rejected if a top-level definition already uses that key. Root references and
3239
+ * external references are rejected with the supported reference format. Missing definitions are reported by name.
3240
+ * References reached inside nested schema resources introduced by `$id` are rejected instead of resolved against the
3241
+ * top-level definitions.
3245
3242
  * - Pattern constraints reached during translation cause an error by default. Use `patterns: "apply"` only for trusted
3246
3243
  * documents, or `patterns: "ignore"` to skip them. Ignoring patterns can both admit invalid values and reject valid
3247
3244
  * values when `oneOf` branches start overlapping.
@@ -3258,5 +3255,5 @@ export function fromJsonSchemaMultiDocument(
3258
3255
  document: JsonSchema.MultiDocument<"draft-2020-12">,
3259
3256
  options?: FromJsonSchemaOptions
3260
3257
  ): readonly [Schema.Top, ...Array<Schema.Top>] {
3261
- return InternalFromJsonSchemaDocument.fromJsonSchemaMultiDocument(document, options, jsonSchemaRevivers)
3258
+ return InternalFromJsonSchemaDocument.fromJsonSchemaMultiDocument(document, options)
3262
3259
  }
@@ -20,6 +20,7 @@ import * as Duration from "./Duration.ts"
20
20
  import * as Effect from "./Effect.ts"
21
21
  import { format, formatDate, formatJson } from "./Formatter.ts"
22
22
  import { dual } from "./Function.ts"
23
+ import * as InternalContent from "./internal/schema/content.ts"
23
24
  import * as Option from "./Option.ts"
24
25
  import * as Pipeable from "./Pipeable.ts"
25
26
  import * as Predicate from "./Predicate.ts"
@@ -613,7 +614,10 @@ export function trim(): Transformation<string, string> {
613
614
  *
614
615
  * Decoding converts values such as `"my_field_name"` to `"myFieldName"`.
615
616
  * Encoding converts values such as `"myFieldName"` back to `"my_field_name"`.
616
- * The transformation is round-trippable for standard snake_case and camelCase.
617
+ * Lowercase snake_case values round-trip when single underscores separate the
618
+ * segments and every segment after the first starts with a letter. A segment
619
+ * that starts with a digit does not: `"foo_2_bar"` decodes to `"foo2Bar"`,
620
+ * which encodes to `"foo2_bar"`.
617
621
  *
618
622
  * **Example** (Converting snake case to camel case)
619
623
  *
@@ -1950,7 +1954,10 @@ export function fromJsonString(options?: {
1950
1954
  }): Transformation<unknown, string> {
1951
1955
  return new Transformation(
1952
1956
  SchemaGetter.parseJson(options ?? {}),
1953
- SchemaGetter.stringifyJson(options)
1957
+ InternalContent.setContent(SchemaGetter.stringifyJson(options), {
1958
+ mediaType: "application/json",
1959
+ preserveSchema: options?.reviver === undefined && options?.replacer === undefined
1960
+ })
1954
1961
  )
1955
1962
  }
1956
1963
 
package/src/Semaphore.ts CHANGED
@@ -13,7 +13,7 @@
13
13
  */
14
14
  import type * as Effect from "./Effect.ts"
15
15
  import type { Fiber } from "./Fiber.ts"
16
- import { dual } from "./Function.ts"
16
+ import { dual, identity } from "./Function.ts"
17
17
  import * as core from "./internal/core.ts"
18
18
  import * as internal from "./internal/effect.ts"
19
19
  import type * as Option from "./Option.ts"
@@ -214,26 +214,58 @@ export interface Semaphore {
214
214
  */
215
215
  export const makeUnsafe = (permits: number): Semaphore => new SemaphoreImpl(permits)
216
216
 
217
- const waitForPermits = <A, E, R>(
217
+ interface Waiter {
218
+ readonly permits: number
219
+ resume: ((effect: Effect.Effect<void>) => void) | undefined
220
+ }
221
+
222
+ // The first queued request that fits in the free permits. Larger requests
223
+ // ahead of it keep their place but are overtaken, as documented on `take`.
224
+ const firstAvailableWaiter = (self: SemaphoreImpl): Waiter | undefined => {
225
+ for (const waiter of self.waiters) {
226
+ if (waiter.permits <= self.free) return waiter
227
+ }
228
+ }
229
+
230
+ const takePermits = <A, E, R>(
218
231
  self: SemaphoreImpl,
219
232
  n: number,
220
- effect: Effect.Effect<A, E, R>
233
+ onAcquire: () => Effect.Effect<A, E, R>,
234
+ restore: <AX, EX, RX>(effect: Effect.Effect<AX, EX, RX>) => Effect.Effect<AX, EX, RX> = identity
221
235
  ): Effect.Effect<A, E, R> =>
222
- internal.callback((resume) => {
223
- if (self.free >= n) return resume(effect)
224
- const observer = () => {
225
- if (self.free < n) return
226
- self.waiters.delete(observer)
227
- resume(effect)
236
+ core.withFiber((fiber) => {
237
+ if (self.free >= n && firstAvailableWaiter(self) === undefined) {
238
+ self.taken += n
239
+ return onAcquire()
240
+ }
241
+ // A wake does not reserve permits: the waiter keeps its queue entry until
242
+ // it acquires or is interrupted, and re-checks eligibility when it runs.
243
+ const waiter: Waiter = { permits: n, resume: undefined }
244
+ const remove = () => {
245
+ if (self.waiters.delete(waiter)) self.releaseUnsafe(fiber, 0)
246
+ return undefined
228
247
  }
229
- self.waiters.add(observer)
230
- return internal.sync(() => {
231
- self.waiters.delete(observer)
248
+ self.waiters.add(waiter)
249
+ internal.onExitUnsafe(fiber, remove)
250
+ const wait = restore(internal.callback<void>((resume) => {
251
+ // The fiber may have yielded since the last check, missing a wake.
252
+ if (firstAvailableWaiter(self) === waiter) {
253
+ resume(internal.void)
254
+ } else {
255
+ waiter.resume = resume
256
+ }
257
+ }))
258
+ const loop: Effect.Effect<A, E, R> = internal.flatMap(wait, () => {
259
+ if (firstAvailableWaiter(self) !== waiter) return loop
260
+ self.taken += n
261
+ remove()
262
+ return onAcquire()
232
263
  })
264
+ return loop
233
265
  })
234
266
 
235
267
  class SemaphoreImpl implements Semaphore {
236
- public waiters = new Set<() => void>()
268
+ public waiters = new Set<Waiter>()
237
269
  public taken = 0
238
270
  public permits: number
239
271
 
@@ -246,14 +278,7 @@ class SemaphoreImpl implements Semaphore {
246
278
  }
247
279
 
248
280
  take(n: number): Effect.Effect<number> {
249
- const take: Effect.Effect<number> = internal.suspend(() => {
250
- if (this.free < n) {
251
- return waitForPermits(this, n, take)
252
- }
253
- this.taken += n
254
- return internal.succeed(n)
255
- })
256
- return take
281
+ return takePermits(this, n, () => internal.succeed(n))
257
282
  }
258
283
 
259
284
  takeIfAvailable(n: number): Effect.Effect<boolean> {
@@ -268,9 +293,17 @@ class SemaphoreImpl implements Semaphore {
268
293
  this.taken -= n
269
294
  if (this.waiters.size > 0) {
270
295
  fiber.currentDispatcher.scheduleTask(() => {
271
- for (const observer of this.waiters) {
272
- if (this.free <= 0) break
273
- observer()
296
+ // Wake every queued request that fits in the free permits. Waiters
297
+ // that were already woken still count against the budget, since they
298
+ // keep their place until they acquire. Resumed fibers run inline and
299
+ // can add or remove waiters, so iterate over a snapshot.
300
+ let remaining = this.free
301
+ for (const waiter of Array.from(this.waiters)) {
302
+ if (!this.waiters.has(waiter) || waiter.permits > remaining) continue
303
+ remaining -= waiter.permits
304
+ const resume = waiter.resume
305
+ waiter.resume = undefined
306
+ resume?.(internal.void)
274
307
  }
275
308
  }, 0)
276
309
  }
@@ -296,24 +329,18 @@ class SemaphoreImpl implements Semaphore {
296
329
 
297
330
  withPermits(n: number) {
298
331
  return <A, E, R>(self: Effect.Effect<A, E, R>) =>
299
- internal.uninterruptibleMask((restore) => {
300
- const acquire: Effect.Effect<A, E, R> = internal.suspend(() => {
301
- if (this.free < n) {
302
- const wait = waitForPermits(this, n, internal.void)
303
- return internal.flatMap(restore(wait), () => acquire)
304
- }
305
- this.taken += n
306
- return internal.onExitPrimitive(
307
- restore(self),
308
- () => {
332
+ internal.uninterruptibleMask((restore) =>
333
+ takePermits(
334
+ this,
335
+ n,
336
+ () =>
337
+ internal.onExitPrimitive(restore(self), () => {
309
338
  this.releaseUnsafe(internal.getCurrentFiber()!, n)
310
339
  return undefined
311
- },
312
- true
313
- )
314
- })
315
- return acquire
316
- })
340
+ }, true),
341
+ restore
342
+ )
343
+ )
317
344
  }
318
345
 
319
346
  readonly withPermit = this.withPermits(1)
package/src/Sink.ts CHANGED
@@ -2687,7 +2687,12 @@ export const catchCause: {
2687
2687
  ): Sink<A | A2, In, L, E2, R | R2> =>
2688
2688
  transformEffect(
2689
2689
  self,
2690
- Effect.catchCause((cause) => Effect.map(f(cause), (a2) => [a2 as A | A2] as const))
2690
+ Effect.catchCause((cause) =>
2691
+ // Upstream failures are not sink errors, so they bypass the handler.
2692
+ Channel.hasUpstreamFailure(cause)
2693
+ ? Effect.failCause(cause as Cause.Cause<never>)
2694
+ : Effect.map(f(cause), (a2) => [a2 as A | A2] as const)
2695
+ )
2691
2696
  ))
2692
2697
 
2693
2698
  const catch_: {
@@ -2774,7 +2779,15 @@ export const onExit: {
2774
2779
  ): Sink<A, In, L, E | E2, R | R2> =>
2775
2780
  transformEffect(
2776
2781
  self,
2777
- Effect.onExit((exit) => f(Exit.map(exit, ([a]) => a)))
2782
+ Effect.onExit((exit) =>
2783
+ // Upstream failures stop the sink like an interruption; they are not
2784
+ // sink errors.
2785
+ f(
2786
+ Exit.isFailure(exit) && Channel.hasUpstreamFailure(exit.cause)
2787
+ ? Exit.interrupt()
2788
+ : Exit.map(exit, ([a]) => a)
2789
+ )
2790
+ )
2778
2791
  ))
2779
2792
 
2780
2793
  /**
package/src/Stream.ts CHANGED
@@ -7295,17 +7295,12 @@ export const peel: {
7295
7295
  ): Effect.fn.Return<[A2, Stream<A, E, never>], E | E2, Scope.Scope | R | R2> {
7296
7296
  let cause: Cause.Cause<E | Cause.Done<void>> | undefined = undefined
7297
7297
  const originalPull = yield* Channel.toPull(self.channel)
7298
- const pull: Pull.Pull<
7299
- Arr.NonEmptyReadonlyArray<A>,
7300
- E
7301
- > = Effect.catchCause(originalPull, (cause_) => {
7298
+ const pull = Effect.catchCause(originalPull, (cause_) => {
7302
7299
  cause = cause_
7303
7300
  return Effect.failCause(cause_)
7304
7301
  })
7305
7302
 
7306
- const [result, leftover] = yield* Effect.scopedWith((scope) =>
7307
- sink.transform(pull as Pull.Pull<Arr.NonEmptyReadonlyArray<A>>, scope)
7308
- )
7303
+ const [result, leftover] = yield* Effect.scopedWith((scope) => runSink(sink, pull, scope))
7309
7304
  let stream: Stream<A, E> = cause ? empty : fromPull(Effect.succeed(originalPull))
7310
7305
  if (leftover) {
7311
7306
  stream = concat(fromArray(leftover), stream)
@@ -11098,7 +11093,7 @@ export const takeRight: {
11098
11093
  const count = Count.normalize(n)
11099
11094
  if (count === 0) return empty
11100
11095
  return mapAccumArray(self, MutableList.make<A>, (list, arr) => {
11101
- MutableList.appendAll(list, arr)
11096
+ MutableList.appendAllUnsafe(list, arr)
11102
11097
  if (list.length > count) {
11103
11098
  MutableList.takeNVoid(list, list.length - count)
11104
11099
  }
@@ -12528,10 +12523,10 @@ export const rechunk: {
12528
12523
  let chunk = Arr.empty<A>() as Arr.NonEmptyArray<A>
12529
12524
  let index = 0
12530
12525
  let current: Arr.NonEmptyReadonlyArray<A> | undefined
12531
- let done = false
12526
+ let cause: Cause.Cause<E | Cause.Done> | undefined
12532
12527
 
12533
12528
  return Effect.suspend(function loop(): Pull.Pull<Arr.NonEmptyReadonlyArray<A>, E, void, R> {
12534
- if (done) return Cause.done()
12529
+ if (cause) return Effect.failCause(cause)
12535
12530
  else if (current === undefined) {
12536
12531
  return Effect.flatMap(pull, (arr) => {
12537
12532
  if (chunk.length === 0 && arr.length === target) {
@@ -12558,10 +12553,10 @@ export const rechunk: {
12558
12553
  current = undefined
12559
12554
  return loop()
12560
12555
  }).pipe(
12561
- Pull.catchDone(() => {
12562
- if (chunk.length === 0) return Cause.done()
12556
+ Effect.catchCause((cause_) => {
12557
+ if (chunk.length === 0) return Effect.failCause(cause_)
12563
12558
  const result = chunk
12564
- done = true
12559
+ cause = cause_
12565
12560
  chunk = [] as any
12566
12561
  return Effect.succeed(result)
12567
12562
  })
@@ -15122,7 +15117,12 @@ const groupByImpl = <A, E, R, K, V, E2, R2>(
15122
15117
  body: constant(Effect.flatMap(pull, (arr) => f(arr, queues, queueMap))),
15123
15118
  step: constVoid
15124
15119
  }).pipe(
15125
- Effect.catchCause((cause) => Queue.failCause(out, cause)),
15120
+ Effect.catchCause((cause) => {
15121
+ for (const [, queue] of queueMap) {
15122
+ Queue.endUnsafe(queue)
15123
+ }
15124
+ return Queue.failCause(out, cause)
15125
+ }),
15126
15126
  Effect.forkIn(scope)
15127
15127
  )
15128
15128
 
@@ -15659,7 +15659,7 @@ export const aggregateWithin: {
15659
15659
  return buffer.state.exit as Exit.Exit<never, Cause.Done<void> | E>
15660
15660
  }
15661
15661
  hasInput.closeUnsafe()
15662
- const pull = emit(Effect.suspend(() => sink.transform(sinkUpstream as any, scope)))
15662
+ const pull = emit(Effect.suspend(() => runSink(sink, sinkUpstream, scope)))
15663
15663
  return buffer.state._tag === "Open" ? Effect.raceFirst(pull, stepToBuffer) : pull
15664
15664
  })
15665
15665
  }))))
@@ -19327,11 +19327,28 @@ export const run: {
19327
19327
  ): Effect.Effect<A2, E | E2, R | R2> =>
19328
19328
  Effect.scopedWith((scope) =>
19329
19329
  Channel.toPullScoped(self.channel, scope).pipe(
19330
- Effect.flatMap((upstream) => sink.transform(upstream as any, scope)),
19330
+ Effect.flatMap((upstream) => runSink(sink, upstream, scope)),
19331
19331
  Effect.map(([a]) => a)
19332
19332
  )
19333
19333
  ))
19334
19334
 
19335
+ /**
19336
+ * Runs `sink` against `upstream`. Upstream failures bypass the sink's error
19337
+ * handlers and are restored once the sink has exited.
19338
+ */
19339
+ const runSink = <A, E, R, A2, L, E2, R2>(
19340
+ sink: Sink.Sink<A2, A, L, E2, R2>,
19341
+ upstream: Pull.Pull<Arr.NonEmptyReadonlyArray<A>, E, void, R>,
19342
+ scope: Scope.Scope
19343
+ ): Effect.Effect<Sink.End<A2, L>, E | E2, R | R2> =>
19344
+ Channel.restoreUpstreamFailure<Sink.End<A2, L>, E | E2, R2>(
19345
+ // The upstream pull runs in this fiber, which already provides `R`.
19346
+ sink.transform(
19347
+ Channel.upstreamFailureToDefect(upstream) as Pull.Pull<Arr.NonEmptyReadonlyArray<A>, never, void>,
19348
+ scope
19349
+ )
19350
+ )
19351
+
19335
19352
  /**
19336
19353
  * Runs the stream and collects all elements into an array.
19337
19354
  *
package/src/String.ts CHANGED
@@ -1860,6 +1860,9 @@ export const constantCase: (self: string) => string = noCase({
1860
1860
  * Unlike {@link constantCase}, digit-letter boundaries are not split. For
1861
1861
  * example, `"api-v2 xml"` becomes `"API_V2_XML"`.
1862
1862
  *
1863
+ * `configCase` is not idempotent: `"field2value"` becomes `"FIELD2VALUE"`, and
1864
+ * applying it again gives `"FIELD2_VALUE"`.
1865
+ *
1863
1866
  * @see {@link constantCase} for standard uppercase underscore-separated output
1864
1867
  * @stability stable
1865
1868
  * @category transforming
package/src/Tracer.ts CHANGED
@@ -326,6 +326,15 @@ export type SpanKind = "internal" | "server" | "client" | "producer" | "consumer
326
326
  * annotations, attributes, links, sampling and kind information, lifecycle
327
327
  * status, and methods to end the span or add attributes, events, and links.
328
328
  *
329
+ * **Details**
330
+ *
331
+ * Once a span has `Ended` status, implementations should ignore further calls
332
+ * to `end`, `attribute`, `event`, and `addLinks`, following the OpenTelemetry
333
+ * tracing specification. An ended span can still be read and used as a parent.
334
+ * The built-in span implementations follow this rule, and Effect does not
335
+ * record logs or `annotateCurrentSpan` attributes on an ended span, such as
336
+ * when a fiber outlives the span it was forked in.
337
+ *
329
338
  * **Example** (Working with spans)
330
339
  *
331
340
  * ```ts import.meta.vitest
@@ -684,7 +693,8 @@ export const nativeTracer: Tracer = make({
684
693
  * identifiers, the attribute map, and the event list are created lazily on
685
694
  * first access, so spans that are never inspected allocate as little as
686
695
  * possible. Attributes, events, links, and status are mutated through `Span`
687
- * methods.
696
+ * methods. Once the span has ended, those methods do nothing, so a second `end`
697
+ * keeps the original end time and exit.
688
698
  *
689
699
  * @see {@link Span} for the interface implemented by native spans
690
700
  *
@@ -748,6 +758,7 @@ export class NativeSpan implements Span {
748
758
  }
749
759
 
750
760
  end(endTime: bigint, exit: Exit.Exit<unknown, unknown>): void {
761
+ if (this.status._tag === "Ended") return
751
762
  this.status = {
752
763
  _tag: "Ended",
753
764
  endTime,
@@ -757,14 +768,17 @@ export class NativeSpan implements Span {
757
768
  }
758
769
 
759
770
  attribute(key: string, value: unknown): void {
771
+ if (this.status._tag === "Ended") return
760
772
  this.attributes.set(key, value)
761
773
  }
762
774
 
763
775
  event(name: string, startTime: bigint, attributes?: Record<string, unknown>): void {
776
+ if (this.status._tag === "Ended") return
764
777
  this.events.push([name, startTime, attributes ?? {}])
765
778
  }
766
779
 
767
780
  addLinks(links: ReadonlyArray<SpanLink>): void {
781
+ if (this.status._tag === "Ended") return
768
782
  // oxlint-disable-next-line no-restricted-syntax
769
783
  this.links.push(...links)
770
784
  }
@@ -1553,6 +1553,7 @@ export const make: (params: {
1553
1553
  preliminary: false,
1554
1554
  result: r.encodedResult,
1555
1555
  encodedResult: r.encodedResult,
1556
+ ...modelOutputField(r.modelOutput),
1556
1557
  isFailure: r.isFailure
1557
1558
  }) as Response.StreamPart<Tools>
1558
1559
  )
@@ -1680,6 +1681,7 @@ export const make: (params: {
1680
1681
  providerExecuted: false,
1681
1682
  result: result.result,
1682
1683
  encodedResult: result.encodedResult,
1684
+ ...modelOutputField(result.modelOutput),
1683
1685
  isFailure: result.isFailure,
1684
1686
  preliminary: result.preliminary
1685
1687
  }) as Response.StreamPart<Tools>
@@ -2268,6 +2270,7 @@ const executeApprovedToolCalls = <Tools extends Record<string, Tool.Any>>(
2268
2270
  name: toolCall.name,
2269
2271
  result: terminalResult.result,
2270
2272
  encodedResult: terminalResult.encodedResult,
2273
+ ...modelOutputField(terminalResult.modelOutput),
2271
2274
  isFailure: terminalResult.isFailure,
2272
2275
  preliminary: terminalResult.preliminary,
2273
2276
  providerExecuted: false
@@ -2347,6 +2350,10 @@ const makeInterruptedToolResult = (
2347
2350
  })
2348
2351
  }
2349
2352
 
2353
+ // Omits the key entirely so unmapped tool result parts keep their shape.
2354
+ const modelOutputField = (modelOutput: ReadonlyArray<Prompt.ToolModelOutputPart> | undefined) =>
2355
+ modelOutput === undefined ? undefined : { modelOutput }
2356
+
2350
2357
  type ToolResolutionResult<Tools extends Record<string, Tool.Any>> =
2351
2358
  | Response.ToolResultPart<
2352
2359
  Tool.Name<Tools[keyof Tools]>,
@@ -2417,6 +2424,7 @@ const resolveToolCalls = <Tools extends Record<string, Tool.Any>>(
2417
2424
  providerExecuted: false,
2418
2425
  result: result.result,
2419
2426
  encodedResult: result.encodedResult,
2427
+ ...modelOutputField(result.modelOutput),
2420
2428
  isFailure: result.isFailure,
2421
2429
  preliminary: result.preliminary
2422
2430
  }) as ToolResolutionResult<Tools>
@@ -2446,6 +2454,7 @@ const resolveToolCalls = <Tools extends Record<string, Tool.Any>>(
2446
2454
  providerExecuted: false,
2447
2455
  result: result.result,
2448
2456
  encodedResult: result.encodedResult,
2457
+ ...modelOutputField(result.modelOutput),
2449
2458
  isFailure: result.isFailure,
2450
2459
  preliminary: result.preliminary
2451
2460
  }) as ToolResolutionResult<Tools>