effect 4.0.0-beta.31 → 4.0.0-beta.33

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 (481) hide show
  1. package/dist/Array.d.ts +87 -86
  2. package/dist/Array.d.ts.map +1 -1
  3. package/dist/Array.js +47 -40
  4. package/dist/Array.js.map +1 -1
  5. package/dist/BigDecimal.d.ts +46 -45
  6. package/dist/BigDecimal.d.ts.map +1 -1
  7. package/dist/BigDecimal.js +35 -38
  8. package/dist/BigDecimal.js.map +1 -1
  9. package/dist/BigInt.d.ts +39 -32
  10. package/dist/BigInt.d.ts.map +1 -1
  11. package/dist/BigInt.js +32 -29
  12. package/dist/BigInt.js.map +1 -1
  13. package/dist/Chunk.d.ts +58 -57
  14. package/dist/Chunk.d.ts.map +1 -1
  15. package/dist/Chunk.js +20 -21
  16. package/dist/Chunk.js.map +1 -1
  17. package/dist/Config.d.ts.map +1 -1
  18. package/dist/Config.js +4 -1
  19. package/dist/Config.js.map +1 -1
  20. package/dist/Cron.d.ts +3 -6
  21. package/dist/Cron.d.ts.map +1 -1
  22. package/dist/Cron.js +8 -15
  23. package/dist/Cron.js.map +1 -1
  24. package/dist/DateTime.d.ts +16 -15
  25. package/dist/DateTime.d.ts.map +1 -1
  26. package/dist/DateTime.js +8 -8
  27. package/dist/DateTime.js.map +1 -1
  28. package/dist/Deferred.d.ts +7 -5
  29. package/dist/Deferred.d.ts.map +1 -1
  30. package/dist/Deferred.js +7 -5
  31. package/dist/Deferred.js.map +1 -1
  32. package/dist/Duration.d.ts +26 -24
  33. package/dist/Duration.d.ts.map +1 -1
  34. package/dist/Duration.js +23 -22
  35. package/dist/Duration.js.map +1 -1
  36. package/dist/Effect.d.ts +7 -3
  37. package/dist/Effect.d.ts.map +1 -1
  38. package/dist/Effect.js +3 -4
  39. package/dist/Effect.js.map +1 -1
  40. package/dist/Fiber.d.ts +2 -1
  41. package/dist/Fiber.d.ts.map +1 -1
  42. package/dist/Fiber.js.map +1 -1
  43. package/dist/FiberHandle.d.ts +9 -8
  44. package/dist/FiberHandle.d.ts.map +1 -1
  45. package/dist/FiberHandle.js +8 -7
  46. package/dist/FiberHandle.js.map +1 -1
  47. package/dist/FiberMap.d.ts +20 -19
  48. package/dist/FiberMap.d.ts.map +1 -1
  49. package/dist/FiberMap.js +6 -6
  50. package/dist/FiberMap.js.map +1 -1
  51. package/dist/FileSystem.d.ts +17 -16
  52. package/dist/FileSystem.d.ts.map +1 -1
  53. package/dist/FileSystem.js +10 -7
  54. package/dist/FileSystem.js.map +1 -1
  55. package/dist/Graph.d.ts +64 -64
  56. package/dist/Graph.d.ts.map +1 -1
  57. package/dist/Graph.js +53 -53
  58. package/dist/Graph.js.map +1 -1
  59. package/dist/HashMap.d.ts +11 -5
  60. package/dist/HashMap.d.ts.map +1 -1
  61. package/dist/HashMap.js +3 -1
  62. package/dist/HashMap.js.map +1 -1
  63. package/dist/Iterable.d.ts +11 -11
  64. package/dist/Iterable.d.ts.map +1 -1
  65. package/dist/Iterable.js +12 -12
  66. package/dist/Iterable.js.map +1 -1
  67. package/dist/Latch.d.ts +69 -3
  68. package/dist/Latch.d.ts.map +1 -1
  69. package/dist/Latch.js +58 -0
  70. package/dist/Latch.js.map +1 -1
  71. package/dist/Layer.d.ts +84 -0
  72. package/dist/Layer.d.ts.map +1 -1
  73. package/dist/Layer.js +27 -0
  74. package/dist/Layer.js.map +1 -1
  75. package/dist/Number.d.ts +74 -18
  76. package/dist/Number.d.ts.map +1 -1
  77. package/dist/Number.js +34 -15
  78. package/dist/Number.js.map +1 -1
  79. package/dist/Option.d.ts +2 -0
  80. package/dist/Option.d.ts.map +1 -1
  81. package/dist/Option.js.map +1 -1
  82. package/dist/PartitionedSemaphore.d.ts +183 -0
  83. package/dist/PartitionedSemaphore.d.ts.map +1 -0
  84. package/dist/PartitionedSemaphore.js +231 -0
  85. package/dist/PartitionedSemaphore.js.map +1 -0
  86. package/dist/PubSub.d.ts +5 -4
  87. package/dist/PubSub.d.ts.map +1 -1
  88. package/dist/PubSub.js +6 -5
  89. package/dist/PubSub.js.map +1 -1
  90. package/dist/Queue.d.ts +4 -4
  91. package/dist/Queue.d.ts.map +1 -1
  92. package/dist/Queue.js +2 -2
  93. package/dist/Queue.js.map +1 -1
  94. package/dist/Record.d.ts +40 -40
  95. package/dist/Record.d.ts.map +1 -1
  96. package/dist/Record.js +16 -15
  97. package/dist/Record.js.map +1 -1
  98. package/dist/Scheduler.d.ts +25 -123
  99. package/dist/Scheduler.d.ts.map +1 -1
  100. package/dist/Scheduler.js +20 -123
  101. package/dist/Scheduler.js.map +1 -1
  102. package/dist/Schema.d.ts +30 -0
  103. package/dist/Schema.d.ts.map +1 -1
  104. package/dist/Schema.js +28 -1
  105. package/dist/Schema.js.map +1 -1
  106. package/dist/SchemaGetter.js +6 -4
  107. package/dist/SchemaGetter.js.map +1 -1
  108. package/dist/SchemaTransformation.d.ts.map +1 -1
  109. package/dist/SchemaTransformation.js +32 -27
  110. package/dist/SchemaTransformation.js.map +1 -1
  111. package/dist/Semaphore.d.ts +149 -53
  112. package/dist/Semaphore.d.ts.map +1 -1
  113. package/dist/Semaphore.js +137 -117
  114. package/dist/Semaphore.js.map +1 -1
  115. package/dist/ServiceMap.d.ts +26 -0
  116. package/dist/ServiceMap.d.ts.map +1 -1
  117. package/dist/ServiceMap.js +36 -21
  118. package/dist/ServiceMap.js.map +1 -1
  119. package/dist/Stream.js +1 -1
  120. package/dist/Stream.js.map +1 -1
  121. package/dist/String.d.ts +114 -47
  122. package/dist/String.d.ts.map +1 -1
  123. package/dist/String.js +29 -47
  124. package/dist/String.js.map +1 -1
  125. package/dist/SubscriptionRef.d.ts +1 -2
  126. package/dist/SubscriptionRef.d.ts.map +1 -1
  127. package/dist/SubscriptionRef.js +81 -115
  128. package/dist/SubscriptionRef.js.map +1 -1
  129. package/dist/Terminal.d.ts +2 -1
  130. package/dist/Terminal.d.ts.map +1 -1
  131. package/dist/Terminal.js.map +1 -1
  132. package/dist/Tracer.d.ts +5 -4
  133. package/dist/Tracer.d.ts.map +1 -1
  134. package/dist/Tracer.js +2 -1
  135. package/dist/Tracer.js.map +1 -1
  136. package/dist/Trie.d.ts +26 -14
  137. package/dist/Trie.d.ts.map +1 -1
  138. package/dist/Trie.js +8 -4
  139. package/dist/Trie.js.map +1 -1
  140. package/dist/TxHashMap.d.ts +77 -59
  141. package/dist/TxHashMap.d.ts.map +1 -1
  142. package/dist/TxHashMap.js +25 -19
  143. package/dist/TxHashMap.js.map +1 -1
  144. package/dist/TxSemaphore.d.ts +162 -2
  145. package/dist/TxSemaphore.d.ts.map +1 -1
  146. package/dist/TxSemaphore.js +16 -2
  147. package/dist/TxSemaphore.js.map +1 -1
  148. package/dist/index.d.ts +88 -32
  149. package/dist/index.d.ts.map +1 -1
  150. package/dist/index.js +88 -32
  151. package/dist/index.js.map +1 -1
  152. package/dist/internal/dateTime.js +9 -9
  153. package/dist/internal/dateTime.js.map +1 -1
  154. package/dist/internal/effect.js +20 -89
  155. package/dist/internal/effect.js.map +1 -1
  156. package/dist/internal/hashMap.js +2 -1
  157. package/dist/internal/hashMap.js.map +1 -1
  158. package/dist/internal/option.js +6 -0
  159. package/dist/internal/option.js.map +1 -1
  160. package/dist/internal/trie.js +3 -3
  161. package/dist/internal/trie.js.map +1 -1
  162. package/dist/unstable/ai/AiError.js +1 -1
  163. package/dist/unstable/ai/AiError.js.map +1 -1
  164. package/dist/unstable/ai/AnthropicStructuredOutput.d.ts.map +1 -1
  165. package/dist/unstable/ai/AnthropicStructuredOutput.js +4 -0
  166. package/dist/unstable/ai/AnthropicStructuredOutput.js.map +1 -1
  167. package/dist/unstable/ai/Chat.d.ts.map +1 -1
  168. package/dist/unstable/ai/Chat.js +2 -2
  169. package/dist/unstable/ai/Chat.js.map +1 -1
  170. package/dist/unstable/ai/LanguageModel.d.ts +8 -0
  171. package/dist/unstable/ai/LanguageModel.d.ts.map +1 -1
  172. package/dist/unstable/ai/LanguageModel.js +112 -11
  173. package/dist/unstable/ai/LanguageModel.js.map +1 -1
  174. package/dist/unstable/ai/OpenAiStructuredOutput.d.ts.map +1 -1
  175. package/dist/unstable/ai/OpenAiStructuredOutput.js +4 -0
  176. package/dist/unstable/ai/OpenAiStructuredOutput.js.map +1 -1
  177. package/dist/unstable/ai/ResponseIdTracker.d.ts +38 -0
  178. package/dist/unstable/ai/ResponseIdTracker.d.ts.map +1 -0
  179. package/dist/unstable/ai/ResponseIdTracker.js +68 -0
  180. package/dist/unstable/ai/ResponseIdTracker.js.map +1 -0
  181. package/dist/unstable/ai/Tool.d.ts +14 -0
  182. package/dist/unstable/ai/Tool.d.ts.map +1 -1
  183. package/dist/unstable/ai/Tool.js +13 -0
  184. package/dist/unstable/ai/Tool.js.map +1 -1
  185. package/dist/unstable/ai/index.d.ts +4 -0
  186. package/dist/unstable/ai/index.d.ts.map +1 -1
  187. package/dist/unstable/ai/index.js +4 -0
  188. package/dist/unstable/ai/index.js.map +1 -1
  189. package/dist/unstable/cli/Argument.d.ts +2 -4
  190. package/dist/unstable/cli/Argument.d.ts.map +1 -1
  191. package/dist/unstable/cli/Argument.js +1 -3
  192. package/dist/unstable/cli/Argument.js.map +1 -1
  193. package/dist/unstable/cli/CliOutput.d.ts +3 -2
  194. package/dist/unstable/cli/CliOutput.d.ts.map +1 -1
  195. package/dist/unstable/cli/CliOutput.js +4 -3
  196. package/dist/unstable/cli/CliOutput.js.map +1 -1
  197. package/dist/unstable/cli/Command.d.ts +3 -2
  198. package/dist/unstable/cli/Command.d.ts.map +1 -1
  199. package/dist/unstable/cli/Command.js +3 -3
  200. package/dist/unstable/cli/Command.js.map +1 -1
  201. package/dist/unstable/cli/Flag.d.ts +2 -2
  202. package/dist/unstable/cli/Flag.d.ts.map +1 -1
  203. package/dist/unstable/cli/Flag.js +1 -1
  204. package/dist/unstable/cli/Flag.js.map +1 -1
  205. package/dist/unstable/cli/HelpDoc.d.ts +14 -12
  206. package/dist/unstable/cli/HelpDoc.d.ts.map +1 -1
  207. package/dist/unstable/cli/Param.d.ts +4 -4
  208. package/dist/unstable/cli/Param.d.ts.map +1 -1
  209. package/dist/unstable/cli/Param.js +7 -7
  210. package/dist/unstable/cli/Param.js.map +1 -1
  211. package/dist/unstable/cli/Primitive.d.ts +1 -1
  212. package/dist/unstable/cli/Primitive.d.ts.map +1 -1
  213. package/dist/unstable/cli/Primitive.js.map +1 -1
  214. package/dist/unstable/cli/Prompt.js +71 -67
  215. package/dist/unstable/cli/Prompt.js.map +1 -1
  216. package/dist/unstable/cli/internal/completions/CommandDescriptor.js +9 -2
  217. package/dist/unstable/cli/internal/completions/CommandDescriptor.js.map +1 -1
  218. package/dist/unstable/cli/internal/parser.js +8 -3
  219. package/dist/unstable/cli/internal/parser.js.map +1 -1
  220. package/dist/unstable/cluster/ClusterWorkflowEngine.d.ts +3 -2
  221. package/dist/unstable/cluster/ClusterWorkflowEngine.d.ts.map +1 -1
  222. package/dist/unstable/cluster/ClusterWorkflowEngine.js +25 -23
  223. package/dist/unstable/cluster/ClusterWorkflowEngine.js.map +1 -1
  224. package/dist/unstable/cluster/Entity.d.ts +3 -2
  225. package/dist/unstable/cluster/Entity.d.ts.map +1 -1
  226. package/dist/unstable/cluster/Entity.js +7 -7
  227. package/dist/unstable/cluster/Entity.js.map +1 -1
  228. package/dist/unstable/cluster/Message.d.ts +4 -3
  229. package/dist/unstable/cluster/Message.d.ts.map +1 -1
  230. package/dist/unstable/cluster/Message.js +3 -2
  231. package/dist/unstable/cluster/Message.js.map +1 -1
  232. package/dist/unstable/cluster/MessageStorage.d.ts +10 -10
  233. package/dist/unstable/cluster/MessageStorage.d.ts.map +1 -1
  234. package/dist/unstable/cluster/MessageStorage.js +12 -12
  235. package/dist/unstable/cluster/MessageStorage.js.map +1 -1
  236. package/dist/unstable/cluster/Reply.d.ts +2 -1
  237. package/dist/unstable/cluster/Reply.d.ts.map +1 -1
  238. package/dist/unstable/cluster/Reply.js +4 -3
  239. package/dist/unstable/cluster/Reply.js.map +1 -1
  240. package/dist/unstable/cluster/RunnerServer.d.ts.map +1 -1
  241. package/dist/unstable/cluster/RunnerServer.js +9 -8
  242. package/dist/unstable/cluster/RunnerServer.js.map +1 -1
  243. package/dist/unstable/cluster/Runners.d.ts +2 -1
  244. package/dist/unstable/cluster/Runners.d.ts.map +1 -1
  245. package/dist/unstable/cluster/Runners.js +7 -6
  246. package/dist/unstable/cluster/Runners.js.map +1 -1
  247. package/dist/unstable/cluster/Sharding.d.ts.map +1 -1
  248. package/dist/unstable/cluster/Sharding.js +19 -13
  249. package/dist/unstable/cluster/Sharding.js.map +1 -1
  250. package/dist/unstable/cluster/ShardingConfig.d.ts +5 -4
  251. package/dist/unstable/cluster/ShardingConfig.d.ts.map +1 -1
  252. package/dist/unstable/cluster/ShardingConfig.js +4 -4
  253. package/dist/unstable/cluster/ShardingConfig.js.map +1 -1
  254. package/dist/unstable/cluster/SqlMessageStorage.d.ts.map +1 -1
  255. package/dist/unstable/cluster/SqlMessageStorage.js +19 -18
  256. package/dist/unstable/cluster/SqlMessageStorage.js.map +1 -1
  257. package/dist/unstable/cluster/internal/entityManager.js +9 -10
  258. package/dist/unstable/cluster/internal/entityManager.js.map +1 -1
  259. package/dist/unstable/devtools/DevToolsSchema.d.ts +2 -1
  260. package/dist/unstable/devtools/DevToolsSchema.d.ts.map +1 -1
  261. package/dist/unstable/devtools/DevToolsSchema.js +1 -4
  262. package/dist/unstable/devtools/DevToolsSchema.js.map +1 -1
  263. package/dist/unstable/http/Cookies.d.ts +5 -4
  264. package/dist/unstable/http/Cookies.d.ts.map +1 -1
  265. package/dist/unstable/http/Cookies.js +3 -4
  266. package/dist/unstable/http/Cookies.js.map +1 -1
  267. package/dist/unstable/http/Etag.d.ts.map +1 -1
  268. package/dist/unstable/http/Etag.js +5 -1
  269. package/dist/unstable/http/Etag.js.map +1 -1
  270. package/dist/unstable/http/Headers.d.ts +3 -2
  271. package/dist/unstable/http/Headers.d.ts.map +1 -1
  272. package/dist/unstable/http/Headers.js +2 -1
  273. package/dist/unstable/http/Headers.js.map +1 -1
  274. package/dist/unstable/http/HttpClient.d.ts.map +1 -1
  275. package/dist/unstable/http/HttpClient.js +2 -1
  276. package/dist/unstable/http/HttpClient.js.map +1 -1
  277. package/dist/unstable/http/HttpClientRequest.d.ts +4 -3
  278. package/dist/unstable/http/HttpClientRequest.d.ts.map +1 -1
  279. package/dist/unstable/http/HttpClientRequest.js +8 -6
  280. package/dist/unstable/http/HttpClientRequest.js.map +1 -1
  281. package/dist/unstable/http/HttpClientResponse.d.ts.map +1 -1
  282. package/dist/unstable/http/HttpClientResponse.js +2 -1
  283. package/dist/unstable/http/HttpClientResponse.js.map +1 -1
  284. package/dist/unstable/http/HttpIncomingMessage.d.ts +2 -1
  285. package/dist/unstable/http/HttpIncomingMessage.d.ts.map +1 -1
  286. package/dist/unstable/http/HttpIncomingMessage.js.map +1 -1
  287. package/dist/unstable/http/HttpMiddleware.d.ts.map +1 -1
  288. package/dist/unstable/http/HttpMiddleware.js +16 -15
  289. package/dist/unstable/http/HttpMiddleware.js.map +1 -1
  290. package/dist/unstable/http/HttpPlatform.d.ts.map +1 -1
  291. package/dist/unstable/http/HttpPlatform.js +3 -2
  292. package/dist/unstable/http/HttpPlatform.js.map +1 -1
  293. package/dist/unstable/http/HttpRouter.d.ts +2 -1
  294. package/dist/unstable/http/HttpRouter.d.ts.map +1 -1
  295. package/dist/unstable/http/HttpRouter.js +7 -7
  296. package/dist/unstable/http/HttpRouter.js.map +1 -1
  297. package/dist/unstable/http/HttpServer.d.ts.map +1 -1
  298. package/dist/unstable/http/HttpServer.js +2 -2
  299. package/dist/unstable/http/HttpServer.js.map +1 -1
  300. package/dist/unstable/http/HttpServerError.d.ts +2 -1
  301. package/dist/unstable/http/HttpServerError.d.ts.map +1 -1
  302. package/dist/unstable/http/HttpServerError.js +2 -1
  303. package/dist/unstable/http/HttpServerError.js.map +1 -1
  304. package/dist/unstable/http/HttpServerRequest.d.ts +3 -2
  305. package/dist/unstable/http/HttpServerRequest.d.ts.map +1 -1
  306. package/dist/unstable/http/HttpServerRequest.js +14 -10
  307. package/dist/unstable/http/HttpServerRequest.js.map +1 -1
  308. package/dist/unstable/http/HttpServerResponse.d.ts.map +1 -1
  309. package/dist/unstable/http/HttpServerResponse.js +4 -3
  310. package/dist/unstable/http/HttpServerResponse.js.map +1 -1
  311. package/dist/unstable/http/HttpTraceContext.d.ts +3 -2
  312. package/dist/unstable/http/HttpTraceContext.d.ts.map +1 -1
  313. package/dist/unstable/http/HttpTraceContext.js +27 -15
  314. package/dist/unstable/http/HttpTraceContext.js.map +1 -1
  315. package/dist/unstable/http/UrlParams.d.ts +5 -4
  316. package/dist/unstable/http/UrlParams.d.ts.map +1 -1
  317. package/dist/unstable/http/UrlParams.js +5 -6
  318. package/dist/unstable/http/UrlParams.js.map +1 -1
  319. package/dist/unstable/httpapi/HttpApiBuilder.d.ts.map +1 -1
  320. package/dist/unstable/httpapi/HttpApiBuilder.js +4 -2
  321. package/dist/unstable/httpapi/HttpApiBuilder.js.map +1 -1
  322. package/dist/unstable/httpapi/HttpApiError.d.ts +15 -0
  323. package/dist/unstable/httpapi/HttpApiError.d.ts.map +1 -1
  324. package/dist/unstable/httpapi/HttpApiError.js +81 -3
  325. package/dist/unstable/httpapi/HttpApiError.js.map +1 -1
  326. package/dist/unstable/observability/OtlpExporter.d.ts.map +1 -1
  327. package/dist/unstable/observability/OtlpExporter.js +2 -2
  328. package/dist/unstable/observability/OtlpExporter.js.map +1 -1
  329. package/dist/unstable/observability/OtlpTracer.d.ts.map +1 -1
  330. package/dist/unstable/observability/OtlpTracer.js +7 -3
  331. package/dist/unstable/observability/OtlpTracer.js.map +1 -1
  332. package/dist/unstable/reactivity/Atom.d.ts.map +1 -1
  333. package/dist/unstable/reactivity/Atom.js +1 -5
  334. package/dist/unstable/reactivity/Atom.js.map +1 -1
  335. package/dist/unstable/reactivity/AtomRegistry.d.ts.map +1 -1
  336. package/dist/unstable/reactivity/AtomRegistry.js +4 -2
  337. package/dist/unstable/reactivity/AtomRegistry.js.map +1 -1
  338. package/dist/unstable/rpc/Rpc.d.ts.map +1 -1
  339. package/dist/unstable/rpc/Rpc.js +4 -3
  340. package/dist/unstable/rpc/Rpc.js.map +1 -1
  341. package/dist/unstable/rpc/RpcClient.d.ts.map +1 -1
  342. package/dist/unstable/rpc/RpcClient.js +4 -4
  343. package/dist/unstable/rpc/RpcClient.js.map +1 -1
  344. package/dist/unstable/rpc/RpcSchema.d.ts.map +1 -1
  345. package/dist/unstable/rpc/RpcSchema.js +3 -2
  346. package/dist/unstable/rpc/RpcSchema.js.map +1 -1
  347. package/dist/unstable/rpc/RpcSerialization.d.ts.map +1 -1
  348. package/dist/unstable/rpc/RpcSerialization.js +4 -1
  349. package/dist/unstable/rpc/RpcSerialization.js.map +1 -1
  350. package/dist/unstable/rpc/RpcServer.d.ts +1 -1
  351. package/dist/unstable/rpc/RpcServer.d.ts.map +1 -1
  352. package/dist/unstable/rpc/RpcServer.js +3 -2
  353. package/dist/unstable/rpc/RpcServer.js.map +1 -1
  354. package/dist/unstable/socket/Socket.d.ts +2 -1
  355. package/dist/unstable/socket/Socket.d.ts.map +1 -1
  356. package/dist/unstable/socket/Socket.js +5 -3
  357. package/dist/unstable/socket/Socket.js.map +1 -1
  358. package/dist/unstable/sql/SqlClient.d.ts.map +1 -1
  359. package/dist/unstable/sql/SqlClient.js +1 -1
  360. package/dist/unstable/sql/SqlClient.js.map +1 -1
  361. package/dist/unstable/workflow/DurableDeferred.js +6 -6
  362. package/dist/unstable/workflow/DurableDeferred.js.map +1 -1
  363. package/dist/unstable/workflow/Workflow.d.ts +2 -1
  364. package/dist/unstable/workflow/Workflow.d.ts.map +1 -1
  365. package/dist/unstable/workflow/WorkflowEngine.d.ts +5 -4
  366. package/dist/unstable/workflow/WorkflowEngine.d.ts.map +1 -1
  367. package/dist/unstable/workflow/WorkflowEngine.js +19 -14
  368. package/dist/unstable/workflow/WorkflowEngine.js.map +1 -1
  369. package/package.json +1 -1
  370. package/src/Array.ts +112 -105
  371. package/src/BigDecimal.ts +63 -66
  372. package/src/BigInt.ts +49 -41
  373. package/src/Chunk.ts +68 -63
  374. package/src/Config.ts +4 -1
  375. package/src/Cron.ts +10 -15
  376. package/src/DateTime.ts +16 -15
  377. package/src/Deferred.ts +8 -6
  378. package/src/Duration.ts +34 -33
  379. package/src/Effect.ts +12 -23
  380. package/src/Fiber.ts +2 -1
  381. package/src/FiberHandle.ts +10 -9
  382. package/src/FiberMap.ts +22 -22
  383. package/src/FileSystem.ts +25 -22
  384. package/src/Graph.ts +105 -105
  385. package/src/HashMap.ts +11 -5
  386. package/src/Iterable.ts +13 -13
  387. package/src/Latch.ts +85 -3
  388. package/src/Layer.ts +121 -0
  389. package/src/Number.ts +85 -26
  390. package/src/Option.ts +2 -0
  391. package/src/PartitionedSemaphore.ts +414 -0
  392. package/src/PubSub.ts +7 -6
  393. package/src/Queue.ts +6 -6
  394. package/src/Record.ts +52 -47
  395. package/src/Scheduler.ts +37 -126
  396. package/src/Schema.ts +49 -1
  397. package/src/SchemaGetter.ts +4 -4
  398. package/src/SchemaTransformation.ts +27 -27
  399. package/src/Semaphore.ts +271 -183
  400. package/src/ServiceMap.ts +83 -31
  401. package/src/Stream.ts +1 -1
  402. package/src/String.ts +122 -69
  403. package/src/SubscriptionRef.ts +96 -117
  404. package/src/Terminal.ts +2 -1
  405. package/src/Tracer.ts +6 -5
  406. package/src/Trie.ts +26 -14
  407. package/src/TxHashMap.ts +78 -60
  408. package/src/TxSemaphore.ts +186 -11
  409. package/src/index.ts +89 -33
  410. package/src/internal/dateTime.ts +14 -14
  411. package/src/internal/effect.ts +29 -121
  412. package/src/internal/hashMap.ts +4 -3
  413. package/src/internal/option.ts +7 -0
  414. package/src/internal/trie.ts +6 -6
  415. package/src/unstable/ai/AiError.ts +1 -1
  416. package/src/unstable/ai/AnthropicStructuredOutput.ts +4 -0
  417. package/src/unstable/ai/Chat.ts +6 -2
  418. package/src/unstable/ai/LanguageModel.ts +192 -65
  419. package/src/unstable/ai/OpenAiStructuredOutput.ts +4 -0
  420. package/src/unstable/ai/ResponseIdTracker.ts +97 -0
  421. package/src/unstable/ai/Tool.ts +20 -0
  422. package/src/unstable/ai/index.ts +5 -0
  423. package/src/unstable/cli/Argument.ts +2 -4
  424. package/src/unstable/cli/CliOutput.ts +7 -5
  425. package/src/unstable/cli/Command.ts +5 -5
  426. package/src/unstable/cli/Flag.ts +2 -2
  427. package/src/unstable/cli/HelpDoc.ts +14 -12
  428. package/src/unstable/cli/Param.ts +15 -11
  429. package/src/unstable/cli/Primitive.ts +1 -1
  430. package/src/unstable/cli/Prompt.ts +81 -83
  431. package/src/unstable/cli/internal/completions/CommandDescriptor.ts +3 -2
  432. package/src/unstable/cli/internal/parser.ts +7 -4
  433. package/src/unstable/cluster/ClusterWorkflowEngine.ts +35 -30
  434. package/src/unstable/cluster/Entity.ts +13 -12
  435. package/src/unstable/cluster/Message.ts +6 -5
  436. package/src/unstable/cluster/MessageStorage.ts +26 -25
  437. package/src/unstable/cluster/Reply.ts +7 -4
  438. package/src/unstable/cluster/RunnerServer.ts +10 -13
  439. package/src/unstable/cluster/Runners.ts +8 -7
  440. package/src/unstable/cluster/Sharding.ts +24 -17
  441. package/src/unstable/cluster/ShardingConfig.ts +6 -6
  442. package/src/unstable/cluster/SqlMessageStorage.ts +21 -18
  443. package/src/unstable/cluster/internal/entityManager.ts +27 -21
  444. package/src/unstable/devtools/DevToolsSchema.ts +3 -2
  445. package/src/unstable/http/Cookies.ts +7 -8
  446. package/src/unstable/http/Etag.ts +5 -3
  447. package/src/unstable/http/Headers.ts +6 -5
  448. package/src/unstable/http/HttpClient.ts +2 -1
  449. package/src/unstable/http/HttpClientRequest.ts +11 -9
  450. package/src/unstable/http/HttpClientResponse.ts +3 -2
  451. package/src/unstable/http/HttpIncomingMessage.ts +2 -1
  452. package/src/unstable/http/HttpMiddleware.ts +16 -15
  453. package/src/unstable/http/HttpPlatform.ts +3 -2
  454. package/src/unstable/http/HttpRouter.ts +9 -9
  455. package/src/unstable/http/HttpServer.ts +3 -9
  456. package/src/unstable/http/HttpServerError.ts +3 -2
  457. package/src/unstable/http/HttpServerRequest.ts +25 -21
  458. package/src/unstable/http/HttpServerResponse.ts +5 -4
  459. package/src/unstable/http/HttpTraceContext.ts +31 -17
  460. package/src/unstable/http/UrlParams.ts +11 -14
  461. package/src/unstable/httpapi/HttpApiBuilder.ts +9 -3
  462. package/src/unstable/httpapi/HttpApiError.ts +67 -12
  463. package/src/unstable/observability/OtlpExporter.ts +5 -2
  464. package/src/unstable/observability/OtlpTracer.ts +8 -4
  465. package/src/unstable/reactivity/Atom.ts +1 -4
  466. package/src/unstable/reactivity/AtomRegistry.ts +5 -3
  467. package/src/unstable/rpc/Rpc.ts +4 -3
  468. package/src/unstable/rpc/RpcClient.ts +10 -9
  469. package/src/unstable/rpc/RpcSchema.ts +6 -5
  470. package/src/unstable/rpc/RpcSerialization.ts +4 -1
  471. package/src/unstable/rpc/RpcServer.ts +3 -3
  472. package/src/unstable/socket/Socket.ts +14 -9
  473. package/src/unstable/sql/SqlClient.ts +5 -3
  474. package/src/unstable/workflow/DurableDeferred.ts +6 -6
  475. package/src/unstable/workflow/Workflow.ts +1 -1
  476. package/src/unstable/workflow/WorkflowEngine.ts +29 -20
  477. package/dist/NullOr.d.ts +0 -149
  478. package/dist/NullOr.d.ts.map +0 -1
  479. package/dist/NullOr.js +0 -152
  480. package/dist/NullOr.js.map +0 -1
  481. package/src/NullOr.ts +0 -204
@@ -51,7 +51,7 @@
51
51
  import type * as Cause from "../../Cause.ts"
52
52
  import * as Effect from "../../Effect.ts"
53
53
  import * as FiberSet from "../../FiberSet.ts"
54
- import { constFalse } from "../../Function.ts"
54
+ import { constFalse, identity, pipe } from "../../Function.ts"
55
55
  import type * as JsonSchema from "../../JsonSchema.ts"
56
56
  import * as Option from "../../Option.ts"
57
57
  import * as Predicate from "../../Predicate.ts"
@@ -69,6 +69,7 @@ import { defaultIdGenerator, IdGenerator } from "./IdGenerator.ts"
69
69
  import * as InternalCodecTransformer from "./internal/codec-transformer.ts"
70
70
  import * as Prompt from "./Prompt.ts"
71
71
  import * as Response from "./Response.ts"
72
+ import * as ResponseIdTracker from "./ResponseIdTracker.ts"
72
73
  import type { SpanTransformer } from "./Telemetry.ts"
73
74
  import { CurrentSpanTransformer } from "./Telemetry.ts"
74
75
  import type * as Tool from "./Tool.ts"
@@ -648,6 +649,16 @@ export interface ProviderOptions {
648
649
  * The span to use to trace interactions with the large language model.
649
650
  */
650
651
  readonly span: Span
652
+
653
+ /**
654
+ * The previous response identifier for incremental provider calls.
655
+ */
656
+ readonly previousResponseId: string | undefined
657
+
658
+ /**
659
+ * The prompt reduced to messages not yet seen by the provider.
660
+ */
661
+ readonly incrementalPrompt: Prompt.Prompt | undefined
651
662
  }
652
663
 
653
664
  /**
@@ -727,7 +738,9 @@ export const make: (params: {
727
738
  tools: [],
728
739
  toolChoice: "none",
729
740
  responseFormat: { type: "text" },
730
- span
741
+ span,
742
+ previousResponseId: undefined,
743
+ incrementalPrompt: undefined
731
744
  }
732
745
  const content = yield* generateContent(options, providerOptions)
733
746
 
@@ -790,7 +803,9 @@ export const make: (params: {
790
803
  objectName,
791
804
  schema: options.schema
792
805
  },
793
- span
806
+ span,
807
+ previousResponseId: undefined,
808
+ incrementalPrompt: undefined
794
809
  }
795
810
 
796
811
  const content = yield* generateContent(options, providerOptions)
@@ -857,7 +872,9 @@ export const make: (params: {
857
872
  tools: [],
858
873
  toolChoice: "none",
859
874
  responseFormat: { type: "text" },
860
- span
875
+ span,
876
+ previousResponseId: undefined,
877
+ incrementalPrompt: undefined
861
878
  }
862
879
 
863
880
  // Resolve the content stream for the request
@@ -917,6 +934,7 @@ export const make: (params: {
917
934
  options: Options & GenerateTextOptions<Tools>,
918
935
  providerOptions: Mutable<ProviderOptions>
919
936
  ) {
937
+ const tracker = Option.getOrUndefined(yield* Effect.serviceOption(ResponseIdTracker.ResponseIdTracker))
920
938
  const toolChoice = options.toolChoice ?? "auto"
921
939
 
922
940
  // Check for pending approvals that need resolution
@@ -940,11 +958,24 @@ export const make: (params: {
940
958
  })
941
959
  })
942
960
  }
961
+ if (tracker) {
962
+ const prepared = tracker.prepareUnsafe(providerOptions.prompt)
963
+ if (Option.isSome(prepared)) {
964
+ providerOptions.previousResponseId = prepared.value.previousResponseId
965
+ providerOptions.incrementalPrompt = prepared.value.prompt
966
+ }
967
+ }
943
968
  const ResponseSchema = Schema.mutable(
944
969
  Schema.Array(Response.Part(Toolkit.empty))
945
970
  )
946
971
  const rawContent = yield* params.generateText(providerOptions)
947
972
  const content = yield* Schema.decodeEffect(ResponseSchema)(rawContent)
973
+ if (tracker) {
974
+ const responseMetadata = content.find((part) => part.type === "response-metadata")
975
+ if (Predicate.isNotUndefined(responseMetadata) && Predicate.isNotUndefined(responseMetadata.id)) {
976
+ tracker.markParts(providerOptions.prompt.content, responseMetadata.id)
977
+ }
978
+ }
948
979
  return content as Array<Response.Part<Tools>>
949
980
  }
950
981
 
@@ -965,11 +996,24 @@ export const make: (params: {
965
996
  })
966
997
  })
967
998
  }
999
+ if (tracker) {
1000
+ const prepared = tracker.prepareUnsafe(providerOptions.prompt)
1001
+ if (Option.isSome(prepared)) {
1002
+ providerOptions.previousResponseId = prepared.value.previousResponseId
1003
+ providerOptions.incrementalPrompt = prepared.value.prompt
1004
+ }
1005
+ }
968
1006
  const ResponseSchema = Schema.mutable(
969
1007
  Schema.Array(Response.Part(Toolkit.empty))
970
1008
  )
971
1009
  const rawContent = yield* params.generateText(providerOptions)
972
1010
  const content = yield* Schema.decodeEffect(ResponseSchema)(rawContent)
1011
+ if (tracker) {
1012
+ const responseMetadata = content.find((part) => part.type === "response-metadata")
1013
+ if (Predicate.isNotUndefined(responseMetadata) && Predicate.isNotUndefined(responseMetadata.id)) {
1014
+ tracker.markParts(providerOptions.prompt.content, responseMetadata.id)
1015
+ }
1016
+ }
973
1017
  return content as Array<Response.Part<Tools>>
974
1018
  }
975
1019
 
@@ -1025,6 +1069,14 @@ export const make: (params: {
1025
1069
  providerOptions.tools = tools
1026
1070
  providerOptions.toolChoice = toolChoice
1027
1071
 
1072
+ if (tracker) {
1073
+ const prepared = tracker.prepareUnsafe(providerOptions.prompt)
1074
+ if (Option.isSome(prepared)) {
1075
+ providerOptions.previousResponseId = prepared.value.previousResponseId
1076
+ providerOptions.incrementalPrompt = prepared.value.prompt
1077
+ }
1078
+ }
1079
+
1028
1080
  // Construct the response schema with the tools from the toolkit
1029
1081
  const ResponseSchema = Schema.mutable(
1030
1082
  Schema.Array(Response.Part(toolkit))
@@ -1035,6 +1087,12 @@ export const make: (params: {
1035
1087
  if (options.disableToolCallResolution === true) {
1036
1088
  const rawContent = yield* params.generateText(providerOptions)
1037
1089
  const content = yield* Schema.decodeEffect(ResponseSchema)(rawContent)
1090
+ if (tracker) {
1091
+ const responseMetadata = content.find((part) => part.type === "response-metadata")
1092
+ if (Predicate.isNotUndefined(responseMetadata) && Predicate.isNotUndefined(responseMetadata.id)) {
1093
+ tracker.markParts(providerOptions.prompt.content, responseMetadata.id)
1094
+ }
1095
+ }
1038
1096
  return content as Array<Response.Part<Tools>>
1039
1097
  }
1040
1098
 
@@ -1057,6 +1115,13 @@ export const make: (params: {
1057
1115
 
1058
1116
  const content = yield* Schema.decodeEffect(ResponseSchema)(rawContent)
1059
1117
 
1118
+ if (tracker) {
1119
+ const responseMetadata = content.find((part) => part.type === "response-metadata")
1120
+ if (Predicate.isNotUndefined(responseMetadata) && Predicate.isNotUndefined(responseMetadata.id)) {
1121
+ tracker.markParts(providerOptions.prompt.content, responseMetadata.id)
1122
+ }
1123
+ }
1124
+
1060
1125
  // Return the content merged with the tool call results
1061
1126
  return [...content, ...toolResults] as Array<Response.Part<Tools>>
1062
1127
  })
@@ -1086,6 +1151,7 @@ export const make: (params: {
1086
1151
  options: Options & GenerateTextOptions<Tools>,
1087
1152
  providerOptions: Mutable<ProviderOptions>
1088
1153
  ) {
1154
+ const tracker = Option.getOrUndefined(yield* Effect.serviceOption(ResponseIdTracker.ResponseIdTracker))
1089
1155
  const toolChoice = options.toolChoice ?? "auto"
1090
1156
 
1091
1157
  // Check for pending approvals that need resolution
@@ -1108,17 +1174,36 @@ export const make: (params: {
1108
1174
  })
1109
1175
  })
1110
1176
  }
1177
+ if (tracker) {
1178
+ const prepared = tracker.prepareUnsafe(providerOptions.prompt)
1179
+ if (Option.isSome(prepared)) {
1180
+ providerOptions.previousResponseId = prepared.value.previousResponseId
1181
+ providerOptions.incrementalPrompt = prepared.value.prompt
1182
+ }
1183
+ }
1111
1184
  const schema = Schema.NonEmptyArray(Response.StreamPart(Toolkit.empty))
1112
1185
  const decodeParts = Schema.decodeEffect(schema)
1113
- return params
1114
- .streamText(providerOptions)
1115
- .pipe(
1116
- Stream.mapArrayEffect((parts) => decodeParts(parts))
1117
- ) as Stream.Stream<
1118
- Response.StreamPart<Tools>,
1119
- AiError.AiError | Schema.SchemaError,
1120
- IdGenerator
1121
- >
1186
+ return pipe(
1187
+ params.streamText(providerOptions),
1188
+ Stream.mapArrayEffect((parts) =>
1189
+ decodeParts(parts).pipe(
1190
+ tracker ?
1191
+ Effect.tap((decodedParts) => {
1192
+ for (const part of decodedParts) {
1193
+ if (part.type === "response-metadata" && Predicate.isNotUndefined(part.id)) {
1194
+ tracker.markParts(providerOptions.prompt.content, part.id)
1195
+ }
1196
+ }
1197
+ return Effect.void
1198
+ }) :
1199
+ identity
1200
+ )
1201
+ )
1202
+ ) as Stream.Stream<
1203
+ Response.StreamPart<Tools>,
1204
+ AiError.AiError | Schema.SchemaError,
1205
+ IdGenerator
1206
+ >
1122
1207
  }
1123
1208
 
1124
1209
  // If there is a toolkit resolve and apply it to the provider options
@@ -1138,17 +1223,36 @@ export const make: (params: {
1138
1223
  })
1139
1224
  })
1140
1225
  }
1226
+ if (tracker) {
1227
+ const prepared = tracker.prepareUnsafe(providerOptions.prompt)
1228
+ if (Option.isSome(prepared)) {
1229
+ providerOptions.previousResponseId = prepared.value.previousResponseId
1230
+ providerOptions.incrementalPrompt = prepared.value.prompt
1231
+ }
1232
+ }
1141
1233
  const schema = Schema.NonEmptyArray(Response.StreamPart(Toolkit.empty))
1142
1234
  const decodeParts = Schema.decodeEffect(schema)
1143
- return params
1144
- .streamText(providerOptions)
1145
- .pipe(
1146
- Stream.mapArrayEffect((parts) => decodeParts(parts))
1147
- ) as Stream.Stream<
1148
- Response.StreamPart<Tools>,
1149
- AiError.AiError | Schema.SchemaError,
1150
- IdGenerator
1151
- >
1235
+ return pipe(
1236
+ params.streamText(providerOptions),
1237
+ Stream.mapArrayEffect((parts) =>
1238
+ decodeParts(parts).pipe(
1239
+ tracker ?
1240
+ Effect.tap((decodedParts) => {
1241
+ for (const part of decodedParts) {
1242
+ if (part.type === "response-metadata" && part.id) {
1243
+ tracker.markParts(providerOptions.prompt.content, part.id)
1244
+ }
1245
+ }
1246
+ return Effect.void
1247
+ }) :
1248
+ identity
1249
+ )
1250
+ )
1251
+ ) as Stream.Stream<
1252
+ Response.StreamPart<Tools>,
1253
+ AiError.AiError | Schema.SchemaError,
1254
+ IdGenerator
1255
+ >
1152
1256
  }
1153
1257
 
1154
1258
  // Pre-resolve pending tool approvals before calling the LLM
@@ -1222,20 +1326,39 @@ export const make: (params: {
1222
1326
  providerOptions.tools = tools
1223
1327
  providerOptions.toolChoice = toolChoice
1224
1328
 
1329
+ if (tracker) {
1330
+ const prepared = tracker.prepareUnsafe(providerOptions.prompt)
1331
+ if (Option.isSome(prepared)) {
1332
+ providerOptions.previousResponseId = prepared.value.previousResponseId
1333
+ providerOptions.incrementalPrompt = prepared.value.prompt
1334
+ }
1335
+ }
1336
+
1225
1337
  // If tool call resolution is disabled, return the response without
1226
1338
  // resolving the tool calls that were generated
1227
1339
  if (options.disableToolCallResolution === true) {
1228
1340
  const schema = Schema.NonEmptyArray(Response.StreamPart(toolkit))
1229
1341
  const decodeParts = Schema.decodeEffect(schema)
1230
- return params
1231
- .streamText(providerOptions)
1232
- .pipe(
1233
- Stream.mapArrayEffect((parts) => decodeParts(parts))
1234
- ) as Stream.Stream<
1235
- Response.StreamPart<Tools>,
1236
- AiError.AiError | Schema.SchemaError,
1237
- IdGenerator
1238
- >
1342
+ return params.streamText(providerOptions).pipe(
1343
+ Stream.mapArrayEffect((parts) =>
1344
+ decodeParts(parts).pipe(
1345
+ tracker ?
1346
+ Effect.tap((decodedParts) => {
1347
+ for (const part of decodedParts) {
1348
+ if (part.type === "response-metadata" && Predicate.isNotUndefined(part.id)) {
1349
+ tracker.markParts(providerOptions.prompt.content, part.id)
1350
+ }
1351
+ }
1352
+ return Effect.void
1353
+ }) :
1354
+ identity
1355
+ )
1356
+ )
1357
+ ) as Stream.Stream<
1358
+ Response.StreamPart<Tools>,
1359
+ AiError.AiError | Schema.SchemaError,
1360
+ IdGenerator
1361
+ >
1239
1362
  }
1240
1363
 
1241
1364
  const ResponseSchema = Schema.NonEmptyArray(Response.StreamPart(toolkit))
@@ -1260,48 +1383,52 @@ export const make: (params: {
1260
1383
  const toolCallFibers = yield* FiberSet.make<void, AiError.AiError>()
1261
1384
 
1262
1385
  // Helper function to handle tool calls with approval logic
1263
- const handleToolCall = (part: Response.ToolCallPartEncoded) =>
1264
- Effect.gen(function*() {
1265
- const tool = toolkit.tools[part.name]
1266
- if (!tool) {
1267
- return
1268
- }
1386
+ const handleToolCall = Effect.fnUntraced(function*(part: Response.ToolCallPartEncoded) {
1387
+ const tool = toolkit.tools[part.name]
1388
+ if (!tool) return
1269
1389
 
1270
- const needsApproval = yield* isApprovalNeeded(
1271
- tool,
1272
- part,
1273
- providerOptions.prompt.content
1274
- )
1390
+ const needsApproval = yield* isApprovalNeeded(
1391
+ tool,
1392
+ part,
1393
+ providerOptions.prompt.content
1394
+ )
1275
1395
 
1276
- if (needsApproval) {
1277
- const idGen = yield* IdGenerator
1278
- const approvalId = yield* idGen.generateId()
1279
- const approvalPart = Response.makePart("tool-approval-request", {
1280
- approvalId,
1281
- toolCallId: part.id
1282
- }) as Response.StreamPart<Tools>
1283
- yield* Queue.offer(queue, approvalPart)
1284
- return
1285
- }
1396
+ if (needsApproval) {
1397
+ const idGen = yield* IdGenerator
1398
+ const approvalId = yield* idGen.generateId()
1399
+ const approvalPart = Response.makePart("tool-approval-request", {
1400
+ approvalId,
1401
+ toolCallId: part.id
1402
+ }) as Response.StreamPart<Tools>
1403
+ yield* Queue.offer(queue, approvalPart)
1404
+ return
1405
+ }
1286
1406
 
1287
- yield* toolkit.handle(part.name, part.params as any).pipe(
1288
- Stream.unwrap,
1289
- Stream.runForEach((result) => {
1290
- const toolResultPart = Response.makePart("tool-result", {
1291
- id: part.id,
1292
- name: part.name,
1293
- providerExecuted: false,
1294
- ...result
1295
- }) as Response.StreamPart<Tools>
1296
- return Queue.offer(queue, toolResultPart)
1297
- })
1298
- )
1299
- })
1407
+ yield* toolkit.handle(part.name, part.params as any).pipe(
1408
+ Stream.unwrap,
1409
+ Stream.runForEach((result) => {
1410
+ const toolResultPart = Response.makePart("tool-result", {
1411
+ id: part.id,
1412
+ name: part.name,
1413
+ providerExecuted: false,
1414
+ ...result
1415
+ }) as Response.StreamPart<Tools>
1416
+ return Queue.offer(queue, toolResultPart)
1417
+ })
1418
+ )
1419
+ })
1300
1420
 
1301
1421
  yield* params.streamText(providerOptions).pipe(
1302
1422
  Stream.runForEachArray(
1303
1423
  Effect.fnUntraced(function*(chunk) {
1304
1424
  const parts = yield* decodeParts(chunk)
1425
+ if (tracker) {
1426
+ for (const part of parts) {
1427
+ if (part.type === "response-metadata" && part.id) {
1428
+ tracker.markParts(providerOptions.prompt.content, part.id)
1429
+ }
1430
+ }
1431
+ }
1305
1432
  // Add decoded response parts to the output queue
1306
1433
  yield* Queue.offerAll(queue, parts)
1307
1434
  // Fork tool call handlers - use the raw chunk for encoded params
@@ -11,6 +11,7 @@ import * as Rec from "../../Record.ts"
11
11
  import * as Schema from "../../Schema.ts"
12
12
  import * as AST from "../../SchemaAST.ts"
13
13
  import * as Transformation from "../../SchemaTransformation.ts"
14
+ import * as Tool from "./Tool.ts"
14
15
 
15
16
  /**
16
17
  * Transforms a `Schema.Codec` into a form compatible with OpenAI's
@@ -243,6 +244,9 @@ function recurOpenAI(ast: AST.AST): AST.AST {
243
244
  }
244
245
  } else if (ast.indexSignatures.length === 1 && ast.propertySignatures.length === 0) {
245
246
  const is = ast.indexSignatures[0]
247
+ if (Tool.isEmptyParamsRecord(is)) {
248
+ return ast
249
+ }
246
250
  // records are not supported by OpenAI, so we translate them to arrays of key-value pairs
247
251
  if (annotations !== undefined && typeof annotations.description === "string") {
248
252
  annotations.description = `${RECORD_DESCRIPTION}; ${annotations.description}`
@@ -0,0 +1,97 @@
1
+ /**
2
+ * @since 4.0.0
3
+ */
4
+ import * as Effect from "../../Effect.ts"
5
+ import * as Option from "../../Option.ts"
6
+ import * as ServiceMap from "../../ServiceMap.ts"
7
+ import * as Prompt from "./Prompt.ts"
8
+
9
+ /**
10
+ * @since 4.0.0
11
+ * @category models
12
+ */
13
+ export interface PrepareResult {
14
+ readonly previousResponseId: string
15
+ readonly prompt: Prompt.Prompt
16
+ }
17
+
18
+ /**
19
+ * @since 4.0.0
20
+ * @category models
21
+ */
22
+ export interface Service {
23
+ clearUnsafe(): void
24
+ markParts(parts: ReadonlyArray<object>, responseId: string): void
25
+ prepareUnsafe(prompt: Prompt.Prompt): Option.Option<PrepareResult>
26
+ }
27
+
28
+ /**
29
+ * @since 4.0.0
30
+ * @category Services
31
+ */
32
+ export class ResponseIdTracker
33
+ extends ServiceMap.Service<ResponseIdTracker, Service>()("effect/ai/ResponseIdTracker")
34
+ {}
35
+
36
+ /**
37
+ * @since 4.0.0
38
+ * @category constructors
39
+ */
40
+ export const make: Effect.Effect<Service> = Effect.sync(() => {
41
+ let sentParts = new WeakMap<object, string>()
42
+
43
+ const none = () => {
44
+ sentParts = new WeakMap<object, string>()
45
+ return Option.none<PrepareResult>()
46
+ }
47
+
48
+ return {
49
+ clearUnsafe() {
50
+ sentParts = new WeakMap<object, string>()
51
+ },
52
+ markParts(parts, responseId) {
53
+ for (let i = 0; i < parts.length; i++) {
54
+ sentParts.set(parts[i], responseId)
55
+ }
56
+ },
57
+ prepareUnsafe(prompt) {
58
+ const messages = prompt.content
59
+
60
+ let anyTracked = false
61
+ for (let i = 0; i < messages.length; i++) {
62
+ if (sentParts.has(messages[i])) {
63
+ anyTracked = true
64
+ break
65
+ }
66
+ }
67
+ if (!anyTracked) return none()
68
+
69
+ let lastAssistantIndex = -1
70
+ for (let i = messages.length - 1; i >= 0; i--) {
71
+ if (messages[i].role === "assistant") {
72
+ lastAssistantIndex = i
73
+ break
74
+ }
75
+ }
76
+ if (lastAssistantIndex === -1) return none()
77
+
78
+ let responseId: string | undefined
79
+ for (let i = 0; i < lastAssistantIndex; i++) {
80
+ const id = sentParts.get(messages[i])
81
+ if (id === undefined) return none()
82
+ responseId = id
83
+ }
84
+ if (responseId === undefined) return none()
85
+
86
+ const partsAfterLastAssistant = messages.slice(lastAssistantIndex + 1)
87
+ if (partsAfterLastAssistant.length === 0) {
88
+ return none()
89
+ }
90
+
91
+ return Option.some({
92
+ previousResponseId: responseId,
93
+ prompt: Prompt.fromMessages(partsAfterLastAssistant)
94
+ })
95
+ }
96
+ }
97
+ })
@@ -1129,6 +1129,9 @@ const dynamicProto = <
1129
1129
  * can call. The tool definition includes parameter validation, success/failure
1130
1130
  * schemas, and optional service dependencies.
1131
1131
  *
1132
+ * If a tool accepts no parameters but still needs an explicit empty object
1133
+ * schema, use {@link EmptyParams}.
1134
+ *
1132
1135
  * @example
1133
1136
  * ```ts
1134
1137
  * import { Schema } from "effect"
@@ -1866,3 +1869,20 @@ export const unsafeSecureJsonParse = (text: string): unknown => {
1866
1869
  Error.stackTraceLimit = stackTraceLimit
1867
1870
  }
1868
1871
  }
1872
+
1873
+ /**
1874
+ * @since 4.0.0
1875
+ */
1876
+ export interface EmptyParams extends Schema.$Record<Schema.String, Schema.Never> {}
1877
+
1878
+ /**
1879
+ * A schema for tools that accept no parameters.
1880
+ *
1881
+ * @since 4.0.0
1882
+ */
1883
+ export const EmptyParams: EmptyParams = Schema.Record(Schema.String, Schema.Never)
1884
+
1885
+ /** @internal */
1886
+ export function isEmptyParamsRecord(indexSignature: AST.IndexSignature): boolean {
1887
+ return indexSignature.parameter === AST.string && AST.isNever(indexSignature.type)
1888
+ }
@@ -388,6 +388,11 @@ export * as Prompt from "./Prompt.ts"
388
388
  */
389
389
  export * as Response from "./Response.ts"
390
390
 
391
+ /**
392
+ * @since 4.0.0
393
+ */
394
+ export * as ResponseIdTracker from "./ResponseIdTracker.ts"
395
+
391
396
  /**
392
397
  * The `Telemetry` module provides OpenTelemetry integration for operations
393
398
  * performed against a large language model provider by defining telemetry
@@ -226,9 +226,7 @@ export const fileParse = (
226
226
  * host: Schema.String
227
227
  * })
228
228
  *
229
- * const JsonConfigSchema = Schema.fromJsonString(ConfigSchema)
230
- *
231
- * const config = Argument.fileSchema("config", JsonConfigSchema)
229
+ * const config = Argument.fileSchema("config", ConfigSchema)
232
230
  * ```
233
231
  *
234
232
  * @since 4.0.0
@@ -236,7 +234,7 @@ export const fileParse = (
236
234
  */
237
235
  export const fileSchema = <A>(
238
236
  name: string,
239
- schema: Schema.Codec<A, string>,
237
+ schema: Schema.Decoder<A>,
240
238
  options?: Primitive.FileSchemaOptions | undefined
241
239
  ): Argument<A> => Param.fileSchema(Param.argumentKind, name, schema, options)
242
240
 
@@ -3,6 +3,7 @@
3
3
  */
4
4
 
5
5
  import * as Layer from "../../Layer.ts"
6
+ import * as Option from "../../Option.ts"
6
7
  import * as ServiceMap from "../../ServiceMap.ts"
7
8
  import type * as CliError from "./CliError.ts"
8
9
  import type { HelpDoc } from "./HelpDoc.ts"
@@ -44,6 +45,7 @@ export interface Formatter {
44
45
  *
45
46
  * @example
46
47
  * ```ts
48
+ * import { Option as O } from "effect"
47
49
  * import type { HelpDoc } from "effect/unstable/cli"
48
50
  * import { CliOutput } from "effect/unstable/cli"
49
51
  *
@@ -55,7 +57,7 @@ export interface Formatter {
55
57
  * name: "verbose",
56
58
  * aliases: ["-v"],
57
59
  * type: "boolean",
58
- * description: "Enable verbose output",
60
+ * description: O.some("Enable verbose output"),
59
61
  * required: false
60
62
  * }
61
63
  * ],
@@ -63,7 +65,7 @@ export interface Formatter {
63
65
  * {
64
66
  * name: "file",
65
67
  * type: "string",
66
- * description: "Input file to process",
68
+ * description: O.some("Input file to process"),
67
69
  * required: true,
68
70
  * variadic: false
69
71
  * }
@@ -459,7 +461,7 @@ const formatHelpDocImpl = (doc: HelpDoc, colors: ColorFunctions): string => {
459
461
  const nameType = `${coloredName} ${coloredType}`
460
462
 
461
463
  const optionalSuffix = arg.required ? "" : colors.dim(" (optional)")
462
- const description = (arg.description ?? "") + optionalSuffix
464
+ const description = Option.getOrElse(arg.description, () => "") + optionalSuffix
463
465
 
464
466
  return {
465
467
  left: nameType,
@@ -491,7 +493,7 @@ const formatHelpDocImpl = (doc: HelpDoc, colors: ColorFunctions): string => {
491
493
 
492
494
  return {
493
495
  left: namesPart + typePart,
494
- right: flag.description ?? ""
496
+ right: Option.getOrElse(flag.description, () => "")
495
497
  }
496
498
  })
497
499
 
@@ -519,7 +521,7 @@ const formatHelpDocImpl = (doc: HelpDoc, colors: ColorFunctions): string => {
519
521
 
520
522
  return {
521
523
  left: namesPart + typePart,
522
- right: flag.description ?? ""
524
+ right: Option.getOrElse(flag.description, () => "")
523
525
  }
524
526
  })
525
527
 
@@ -360,10 +360,10 @@ export interface ParsedTokens {
360
360
  readonly flags: Record<string, ReadonlyArray<string>>
361
361
  readonly arguments: ReadonlyArray<string>
362
362
  readonly errors?: ReadonlyArray<CliError.CliError>
363
- readonly subcommand?: {
363
+ readonly subcommand: Option.Option<{
364
364
  readonly name: string
365
365
  readonly parsedInput: ParsedTokens
366
- }
366
+ }>
367
367
  }
368
368
 
369
369
  /**
@@ -939,17 +939,17 @@ export const withSubcommands: {
939
939
  type InternalInput = NextInput & { readonly [SubcommandStateSymbol]?: SubcommandState }
940
940
 
941
941
  const parse = Effect.fnUntraced(function*(raw: ParsedTokens) {
942
- if (!raw.subcommand) {
942
+ if (Option.isNone(raw.subcommand)) {
943
943
  return (yield* impl.parse(raw)) as NextInput
944
944
  }
945
945
 
946
- const sub = byName.get(raw.subcommand.name)
946
+ const sub = byName.get(raw.subcommand.value.name)
947
947
  if (!sub) {
948
948
  return (yield* impl.parse(raw)) as NextInput
949
949
  }
950
950
 
951
951
  const context = yield* impl.parseContext(raw)
952
- const result = yield* sub.parse(raw.subcommand.parsedInput)
952
+ const result = yield* sub.parse(raw.subcommand.value.parsedInput)
953
953
  return Object.assign({}, context, { [SubcommandStateSymbol]: { name: sub.name, result } }) as NextInput
954
954
  })
955
955