effect 4.1.4 → 4.1.5

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 (723) hide show
  1. package/THIRD_PARTY_NOTICES.md +88 -0
  2. package/ai-docs/package.json +2 -2
  3. package/dist/Arbitrary.d.ts +44 -2
  4. package/dist/Arbitrary.d.ts.map +1 -1
  5. package/dist/Arbitrary.js +9 -1
  6. package/dist/Arbitrary.js.map +1 -1
  7. package/dist/BigInt.d.ts +200 -1
  8. package/dist/BigInt.d.ts.map +1 -1
  9. package/dist/BigInt.js +105 -9
  10. package/dist/BigInt.js.map +1 -1
  11. package/dist/Cache.d.ts.map +1 -1
  12. package/dist/Cache.js +4 -2
  13. package/dist/Cache.js.map +1 -1
  14. package/dist/Cause.d.ts +3 -3
  15. package/dist/Cause.js +1 -1
  16. package/dist/Chunk.d.ts +5 -0
  17. package/dist/Chunk.d.ts.map +1 -1
  18. package/dist/Chunk.js +7 -2
  19. package/dist/Chunk.js.map +1 -1
  20. package/dist/Clock.d.ts +5 -2
  21. package/dist/Clock.d.ts.map +1 -1
  22. package/dist/Clock.js +2 -1
  23. package/dist/Clock.js.map +1 -1
  24. package/dist/Codegen.d.ts +295 -0
  25. package/dist/Codegen.d.ts.map +1 -0
  26. package/dist/Codegen.js +521 -0
  27. package/dist/Codegen.js.map +1 -0
  28. package/dist/Config.d.ts +31 -2
  29. package/dist/Config.d.ts.map +1 -1
  30. package/dist/Config.js +12 -1
  31. package/dist/Config.js.map +1 -1
  32. package/dist/ConfigProvider.d.ts +11 -1
  33. package/dist/ConfigProvider.d.ts.map +1 -1
  34. package/dist/ConfigProvider.js +17 -6
  35. package/dist/ConfigProvider.js.map +1 -1
  36. package/dist/Effect.d.ts +869 -109
  37. package/dist/Effect.d.ts.map +1 -1
  38. package/dist/Effect.js +400 -47
  39. package/dist/Effect.js.map +1 -1
  40. package/dist/Equivalence.d.ts +11 -9
  41. package/dist/Equivalence.d.ts.map +1 -1
  42. package/dist/Equivalence.js +15 -12
  43. package/dist/Equivalence.js.map +1 -1
  44. package/dist/Fiber.d.ts +58 -8
  45. package/dist/Fiber.d.ts.map +1 -1
  46. package/dist/Fiber.js +28 -4
  47. package/dist/Fiber.js.map +1 -1
  48. package/dist/FiberHandle.d.ts +81 -10
  49. package/dist/FiberHandle.d.ts.map +1 -1
  50. package/dist/FiberHandle.js +40 -8
  51. package/dist/FiberHandle.js.map +1 -1
  52. package/dist/FiberMap.d.ts +80 -10
  53. package/dist/FiberMap.d.ts.map +1 -1
  54. package/dist/FiberMap.js +37 -6
  55. package/dist/FiberMap.js.map +1 -1
  56. package/dist/FiberSet.d.ts +93 -8
  57. package/dist/FiberSet.d.ts.map +1 -1
  58. package/dist/FiberSet.js +46 -4
  59. package/dist/FiberSet.js.map +1 -1
  60. package/dist/Formatter.d.ts +2 -0
  61. package/dist/Formatter.d.ts.map +1 -1
  62. package/dist/Formatter.js +2 -0
  63. package/dist/Formatter.js.map +1 -1
  64. package/dist/LayerMap.d.ts +12 -3
  65. package/dist/LayerMap.d.ts.map +1 -1
  66. package/dist/LayerMap.js +12 -2
  67. package/dist/LayerMap.js.map +1 -1
  68. package/dist/LayerRef.d.ts +2 -2
  69. package/dist/Match.d.ts +12 -0
  70. package/dist/Match.d.ts.map +1 -1
  71. package/dist/Match.js +16 -0
  72. package/dist/Match.js.map +1 -1
  73. package/dist/Metric.js +1 -1
  74. package/dist/Metric.js.map +1 -1
  75. package/dist/Option.d.ts +4 -1
  76. package/dist/Option.d.ts.map +1 -1
  77. package/dist/Option.js +6 -2
  78. package/dist/Option.js.map +1 -1
  79. package/dist/Order.d.ts +7 -5
  80. package/dist/Order.d.ts.map +1 -1
  81. package/dist/Order.js +7 -2
  82. package/dist/Order.js.map +1 -1
  83. package/dist/Pool.d.ts +4 -3
  84. package/dist/Pool.d.ts.map +1 -1
  85. package/dist/Pool.js +21 -18
  86. package/dist/Pool.js.map +1 -1
  87. package/dist/Predicate.d.ts +4 -1
  88. package/dist/Predicate.d.ts.map +1 -1
  89. package/dist/Predicate.js +5 -1
  90. package/dist/Predicate.js.map +1 -1
  91. package/dist/Queue.d.ts +69 -22
  92. package/dist/Queue.d.ts.map +1 -1
  93. package/dist/Queue.js +40 -18
  94. package/dist/Queue.js.map +1 -1
  95. package/dist/Rational.d.ts +179 -0
  96. package/dist/Rational.d.ts.map +1 -1
  97. package/dist/Rational.js +63 -0
  98. package/dist/Rational.js.map +1 -1
  99. package/dist/Request.d.ts +20 -0
  100. package/dist/Request.d.ts.map +1 -1
  101. package/dist/Request.js +20 -0
  102. package/dist/Request.js.map +1 -1
  103. package/dist/Result.d.ts +3 -1
  104. package/dist/Result.d.ts.map +1 -1
  105. package/dist/Result.js +5 -2
  106. package/dist/Result.js.map +1 -1
  107. package/dist/Schema.d.ts +49 -19
  108. package/dist/Schema.d.ts.map +1 -1
  109. package/dist/Schema.js +44 -27
  110. package/dist/Schema.js.map +1 -1
  111. package/dist/SchemaAST.d.ts.map +1 -1
  112. package/dist/SchemaAST.js +11 -4
  113. package/dist/SchemaAST.js.map +1 -1
  114. package/dist/SchemaGetter.d.ts +5 -6
  115. package/dist/SchemaGetter.d.ts.map +1 -1
  116. package/dist/SchemaGetter.js +14 -10
  117. package/dist/SchemaGetter.js.map +1 -1
  118. package/dist/SchemaRepresentation.d.ts +19 -64
  119. package/dist/SchemaRepresentation.d.ts.map +1 -1
  120. package/dist/SchemaRepresentation.js +1 -28
  121. package/dist/SchemaRepresentation.js.map +1 -1
  122. package/dist/SchemaTransformation.d.ts +11 -10
  123. package/dist/SchemaTransformation.d.ts.map +1 -1
  124. package/dist/SchemaTransformation.js +12 -11
  125. package/dist/SchemaTransformation.js.map +1 -1
  126. package/dist/Scope.d.ts +12 -6
  127. package/dist/Scope.d.ts.map +1 -1
  128. package/dist/Scope.js +12 -6
  129. package/dist/Scope.js.map +1 -1
  130. package/dist/ScopedCache.d.ts.map +1 -1
  131. package/dist/ScopedCache.js +2 -1
  132. package/dist/ScopedCache.js.map +1 -1
  133. package/dist/Semaphore.d.ts.map +1 -1
  134. package/dist/Semaphore.js +18 -4
  135. package/dist/Semaphore.js.map +1 -1
  136. package/dist/Stream.d.ts.map +1 -1
  137. package/dist/Stream.js +55 -14
  138. package/dist/Stream.js.map +1 -1
  139. package/dist/String.d.ts +57 -3
  140. package/dist/String.d.ts.map +1 -1
  141. package/dist/String.js +62 -4
  142. package/dist/String.js.map +1 -1
  143. package/dist/Struct.d.ts +135 -1
  144. package/dist/Struct.d.ts.map +1 -1
  145. package/dist/Struct.js +64 -5
  146. package/dist/Struct.js.map +1 -1
  147. package/dist/TextDiff.d.ts +105 -0
  148. package/dist/TextDiff.d.ts.map +1 -1
  149. package/dist/TextDiff.js +137 -24
  150. package/dist/TextDiff.js.map +1 -1
  151. package/dist/TxPriorityQueue.js +2 -2
  152. package/dist/TxPriorityQueue.js.map +1 -1
  153. package/dist/ai/LanguageModel.d.ts.map +1 -1
  154. package/dist/ai/LanguageModel.js +1 -1
  155. package/dist/ai/LanguageModel.js.map +1 -1
  156. package/dist/ai/McpSchema.d.ts +88 -88
  157. package/dist/ai/McpSchema.d.ts.map +1 -1
  158. package/dist/ai/McpServer.d.ts +47 -2
  159. package/dist/ai/McpServer.d.ts.map +1 -1
  160. package/dist/ai/McpServer.js +135 -16
  161. package/dist/ai/McpServer.js.map +1 -1
  162. package/dist/ai/Tool.d.ts +3 -2
  163. package/dist/ai/Tool.d.ts.map +1 -1
  164. package/dist/ai/Tool.js +3 -2
  165. package/dist/ai/Tool.js.map +1 -1
  166. package/dist/ai/Toolkit.d.ts.map +1 -1
  167. package/dist/ai/Toolkit.js +5 -1
  168. package/dist/ai/Toolkit.js.map +1 -1
  169. package/dist/chat/Chat.d.ts +90 -0
  170. package/dist/chat/Chat.d.ts.map +1 -0
  171. package/dist/chat/Chat.js +127 -0
  172. package/dist/chat/Chat.js.map +1 -0
  173. package/dist/chat/ChatAdapter.d.ts +386 -0
  174. package/dist/chat/ChatAdapter.d.ts.map +1 -0
  175. package/dist/chat/ChatAdapter.js +110 -0
  176. package/dist/chat/ChatAdapter.js.map +1 -0
  177. package/dist/chat/ChatError.d.ts +500 -0
  178. package/dist/chat/ChatError.d.ts.map +1 -0
  179. package/dist/chat/ChatError.js +521 -0
  180. package/dist/chat/ChatError.js.map +1 -0
  181. package/dist/chat/ChatEvent.d.ts +321 -0
  182. package/dist/chat/ChatEvent.d.ts.map +1 -0
  183. package/dist/chat/ChatEvent.js +163 -0
  184. package/dist/chat/ChatEvent.js.map +1 -0
  185. package/dist/chat/ChatHandler.d.ts +81 -0
  186. package/dist/chat/ChatHandler.d.ts.map +1 -0
  187. package/dist/chat/ChatHandler.js +85 -0
  188. package/dist/chat/ChatHandler.js.map +1 -0
  189. package/dist/chat/ChatInteraction.d.ts +1519 -0
  190. package/dist/chat/ChatInteraction.d.ts.map +1 -0
  191. package/dist/chat/ChatInteraction.js +1052 -0
  192. package/dist/chat/ChatInteraction.js.map +1 -0
  193. package/dist/chat/ChatMarkdown.d.ts +280 -0
  194. package/dist/chat/ChatMarkdown.d.ts.map +1 -0
  195. package/dist/chat/ChatMarkdown.js +1172 -0
  196. package/dist/chat/ChatMarkdown.js.map +1 -0
  197. package/dist/chat/ChatMessage.d.ts +224 -0
  198. package/dist/chat/ChatMessage.d.ts.map +1 -0
  199. package/dist/chat/ChatMessage.js +172 -0
  200. package/dist/chat/ChatMessage.js.map +1 -0
  201. package/dist/chat/ChatTest.d.ts +407 -0
  202. package/dist/chat/ChatTest.d.ts.map +1 -0
  203. package/dist/chat/ChatTest.js +2145 -0
  204. package/dist/chat/ChatTest.js.map +1 -0
  205. package/dist/chat/ChatThread.d.ts +92 -0
  206. package/dist/chat/ChatThread.d.ts.map +1 -0
  207. package/dist/chat/ChatThread.js +116 -0
  208. package/dist/chat/ChatThread.js.map +1 -0
  209. package/dist/chat/ChatUi.d.ts +362 -0
  210. package/dist/chat/ChatUi.d.ts.map +1 -0
  211. package/dist/chat/ChatUi.js +209 -0
  212. package/dist/chat/ChatUi.js.map +1 -0
  213. package/dist/chat/index.d.ts +60 -0
  214. package/dist/chat/index.d.ts.map +1 -0
  215. package/dist/chat/index.js +61 -0
  216. package/dist/chat/index.js.map +1 -0
  217. package/dist/chat/internal/retries.d.ts +2 -0
  218. package/dist/chat/internal/retries.d.ts.map +1 -0
  219. package/dist/chat/internal/retries.js +7 -0
  220. package/dist/chat/internal/retries.js.map +1 -0
  221. package/dist/cli/CliOutput.d.ts.map +1 -1
  222. package/dist/cli/CliOutput.js +6 -7
  223. package/dist/cli/CliOutput.js.map +1 -1
  224. package/dist/cli/Command.d.ts +20 -2
  225. package/dist/cli/Command.d.ts.map +1 -1
  226. package/dist/cli/Command.js +4 -0
  227. package/dist/cli/Command.js.map +1 -1
  228. package/dist/cli/Prompt.d.ts +5 -6
  229. package/dist/cli/Prompt.d.ts.map +1 -1
  230. package/dist/cli/Prompt.js +9 -4
  231. package/dist/cli/Prompt.js.map +1 -1
  232. package/dist/cli/internal/command.d.ts +1 -1
  233. package/dist/cli/internal/command.d.ts.map +1 -1
  234. package/dist/cli/internal/config.d.ts +1 -1
  235. package/dist/cli/internal/config.d.ts.map +1 -1
  236. package/dist/cli/internal/config.js +3 -3
  237. package/dist/cli/internal/config.js.map +1 -1
  238. package/dist/cluster/ClusterCron.d.ts +21 -1
  239. package/dist/cluster/ClusterCron.d.ts.map +1 -1
  240. package/dist/cluster/ClusterCron.js +24 -6
  241. package/dist/cluster/ClusterCron.js.map +1 -1
  242. package/dist/cluster/ClusterWorkflowEngine.d.ts.map +1 -1
  243. package/dist/cluster/ClusterWorkflowEngine.js +30 -22
  244. package/dist/cluster/ClusterWorkflowEngine.js.map +1 -1
  245. package/dist/cluster/Sharding.d.ts.map +1 -1
  246. package/dist/cluster/Sharding.js +15 -3
  247. package/dist/cluster/Sharding.js.map +1 -1
  248. package/dist/cluster/ShardingConfig.d.ts +6 -0
  249. package/dist/cluster/ShardingConfig.d.ts.map +1 -1
  250. package/dist/cluster/ShardingConfig.js.map +1 -1
  251. package/dist/cluster/SqlMessageStorage.d.ts.map +1 -1
  252. package/dist/cluster/SqlMessageStorage.js +13 -15
  253. package/dist/cluster/SqlMessageStorage.js.map +1 -1
  254. package/dist/cluster/SqlRunnerStorage.d.ts.map +1 -1
  255. package/dist/cluster/SqlRunnerStorage.js +18 -8
  256. package/dist/cluster/SqlRunnerStorage.js.map +1 -1
  257. package/dist/cluster/internal/entityManager.js +12 -8
  258. package/dist/cluster/internal/entityManager.js.map +1 -1
  259. package/dist/cluster/internal/entityReaper.js +1 -1
  260. package/dist/cluster/internal/entityReaper.js.map +1 -1
  261. package/dist/crypto/Kdf.d.ts +2 -1
  262. package/dist/crypto/Kdf.d.ts.map +1 -1
  263. package/dist/crypto/Kdf.js +2 -1
  264. package/dist/crypto/Kdf.js.map +1 -1
  265. package/dist/crypto/Password.d.ts +162 -0
  266. package/dist/crypto/Password.d.ts.map +1 -0
  267. package/dist/crypto/Password.js +217 -0
  268. package/dist/crypto/Password.js.map +1 -0
  269. package/dist/crypto/index.d.ts +5 -0
  270. package/dist/crypto/index.d.ts.map +1 -1
  271. package/dist/crypto/index.js +5 -0
  272. package/dist/crypto/index.js.map +1 -1
  273. package/dist/encoding/Base64.d.ts +63 -0
  274. package/dist/encoding/Base64.d.ts.map +1 -1
  275. package/dist/encoding/Base64.js +77 -0
  276. package/dist/encoding/Base64.js.map +1 -1
  277. package/dist/encoding/Base64Url.d.ts +1 -0
  278. package/dist/encoding/Base64Url.d.ts.map +1 -1
  279. package/dist/encoding/Base64Url.js +1 -0
  280. package/dist/encoding/Base64Url.js.map +1 -1
  281. package/dist/encoding/Csv.d.ts.map +1 -1
  282. package/dist/encoding/Csv.js +44 -16
  283. package/dist/encoding/Csv.js.map +1 -1
  284. package/dist/encoding/Hex.d.ts +5 -0
  285. package/dist/encoding/Hex.d.ts.map +1 -1
  286. package/dist/encoding/Hex.js +5 -0
  287. package/dist/encoding/Hex.js.map +1 -1
  288. package/dist/encoding/SchemaBinary.d.ts.map +1 -1
  289. package/dist/encoding/SchemaBinary.js +13 -124
  290. package/dist/encoding/SchemaBinary.js.map +1 -1
  291. package/dist/encoding/Sse.d.ts +1 -0
  292. package/dist/encoding/Sse.d.ts.map +1 -1
  293. package/dist/encoding/Sse.js +7 -5
  294. package/dist/encoding/Sse.js.map +1 -1
  295. package/dist/encoding/Xml.d.ts +117 -11
  296. package/dist/encoding/Xml.d.ts.map +1 -1
  297. package/dist/encoding/Xml.js +332 -42
  298. package/dist/encoding/Xml.js.map +1 -1
  299. package/dist/eventlog/EventJournal.d.ts.map +1 -1
  300. package/dist/eventlog/EventJournal.js +3 -8
  301. package/dist/eventlog/EventJournal.js.map +1 -1
  302. package/dist/eventlog/SqlEventLogServerEncrypted.js +6 -8
  303. package/dist/eventlog/SqlEventLogServerEncrypted.js.map +1 -1
  304. package/dist/http/FindMyWay/internal/router.js +163 -116
  305. package/dist/http/FindMyWay/internal/router.js.map +1 -1
  306. package/dist/http/FindMyWay.d.ts +99 -0
  307. package/dist/http/FindMyWay.d.ts.map +1 -1
  308. package/dist/http/FindMyWay.js +39 -0
  309. package/dist/http/FindMyWay.js.map +1 -1
  310. package/dist/http/HttpClient.d.ts.map +1 -1
  311. package/dist/http/HttpClient.js +1 -1
  312. package/dist/http/HttpClient.js.map +1 -1
  313. package/dist/http/HttpMiddleware.d.ts.map +1 -1
  314. package/dist/http/HttpMiddleware.js +15 -8
  315. package/dist/http/HttpMiddleware.js.map +1 -1
  316. package/dist/http/HttpRouter.d.ts +49 -1
  317. package/dist/http/HttpRouter.d.ts.map +1 -1
  318. package/dist/http/HttpRouter.js +70 -20
  319. package/dist/http/HttpRouter.js.map +1 -1
  320. package/dist/http/HttpServerResponse.d.ts.map +1 -1
  321. package/dist/http/HttpServerResponse.js +24 -58
  322. package/dist/http/HttpServerResponse.js.map +1 -1
  323. package/dist/http/Mime.d.ts.map +1 -1
  324. package/dist/http/Mime.js +3 -2
  325. package/dist/http/Mime.js.map +1 -1
  326. package/dist/http/internal/compression.d.ts.map +1 -1
  327. package/dist/http/internal/compression.js +2 -2
  328. package/dist/http/internal/compression.js.map +1 -1
  329. package/dist/http/internal/mediaType.d.ts.map +1 -0
  330. package/dist/{http-api → http}/internal/mediaType.js +4 -0
  331. package/dist/{http-api → http}/internal/mediaType.js.map +1 -1
  332. package/dist/http/internal/redactedPath.d.ts +2 -0
  333. package/dist/http/internal/redactedPath.d.ts.map +1 -0
  334. package/dist/http/internal/redactedPath.js +138 -0
  335. package/dist/http/internal/redactedPath.js.map +1 -0
  336. package/dist/http/internal/requestState.js +1 -0
  337. package/dist/http/internal/requestState.js.map +1 -1
  338. package/dist/http-api/HttpApi.d.ts +13 -2
  339. package/dist/http-api/HttpApi.d.ts.map +1 -1
  340. package/dist/http-api/HttpApi.js +16 -2
  341. package/dist/http-api/HttpApi.js.map +1 -1
  342. package/dist/http-api/HttpApiBuilder.d.ts.map +1 -1
  343. package/dist/http-api/HttpApiBuilder.js +3 -2
  344. package/dist/http-api/HttpApiBuilder.js.map +1 -1
  345. package/dist/http-api/HttpApiClient.d.ts.map +1 -1
  346. package/dist/http-api/HttpApiClient.js +6 -6
  347. package/dist/http-api/HttpApiClient.js.map +1 -1
  348. package/dist/http-api/HttpApiEndpoint.d.ts.map +1 -1
  349. package/dist/http-api/HttpApiEndpoint.js +1 -1
  350. package/dist/http-api/HttpApiEndpoint.js.map +1 -1
  351. package/dist/http-api/HttpApiScalar.d.ts +4 -0
  352. package/dist/http-api/HttpApiScalar.d.ts.map +1 -1
  353. package/dist/http-api/HttpApiScalar.js +10 -1
  354. package/dist/http-api/HttpApiScalar.js.map +1 -1
  355. package/dist/http-api/HttpApiSchema.d.ts.map +1 -1
  356. package/dist/http-api/HttpApiSchema.js +1 -1
  357. package/dist/http-api/HttpApiSchema.js.map +1 -1
  358. package/dist/http-api/OpenApi.d.ts +2 -0
  359. package/dist/http-api/OpenApi.d.ts.map +1 -1
  360. package/dist/http-api/internal/httpApiScalar.js +5 -2
  361. package/dist/http-api/internal/httpApiScalar.js.map +1 -1
  362. package/dist/index.d.ts +5 -0
  363. package/dist/index.d.ts.map +1 -1
  364. package/dist/index.js +5 -0
  365. package/dist/index.js.map +1 -1
  366. package/dist/internal/arbitrary/model.js +0 -5
  367. package/dist/internal/arbitrary/model.js.map +1 -1
  368. package/dist/internal/arbitrary/regexp.js +2 -1
  369. package/dist/internal/arbitrary/regexp.js.map +1 -1
  370. package/dist/internal/arbitrary/runner.d.ts.map +1 -1
  371. package/dist/internal/arbitrary/runner.js +21 -16
  372. package/dist/internal/arbitrary/runner.js.map +1 -1
  373. package/dist/internal/arbitrary/schema.js +140 -23
  374. package/dist/internal/arbitrary/schema.js.map +1 -1
  375. package/dist/internal/codegen.d.ts +2 -0
  376. package/dist/internal/codegen.d.ts.map +1 -0
  377. package/dist/internal/codegen.js +59 -0
  378. package/dist/internal/codegen.js.map +1 -0
  379. package/dist/internal/core.js +3 -3
  380. package/dist/internal/core.js.map +1 -1
  381. package/dist/internal/dateTime.js +26 -12
  382. package/dist/internal/dateTime.js.map +1 -1
  383. package/dist/internal/effect.js +21 -7
  384. package/dist/internal/effect.js.map +1 -1
  385. package/dist/internal/hashMap.js +7 -7
  386. package/dist/internal/hashMap.js.map +1 -1
  387. package/dist/internal/matcher.js +2 -1
  388. package/dist/internal/matcher.js.map +1 -1
  389. package/dist/internal/record.js +18 -4
  390. package/dist/internal/record.js.map +1 -1
  391. package/dist/internal/result.js +1 -1
  392. package/dist/internal/result.js.map +1 -1
  393. package/dist/internal/schema/codeExpression.d.ts +4 -0
  394. package/dist/internal/schema/codeExpression.d.ts.map +1 -0
  395. package/dist/internal/schema/codeExpression.js +179 -0
  396. package/dist/internal/schema/codeExpression.js.map +1 -0
  397. package/dist/internal/schema/codeImports.d.ts +8 -0
  398. package/dist/internal/schema/codeImports.d.ts.map +1 -0
  399. package/dist/internal/schema/codeImports.js +135 -0
  400. package/dist/internal/schema/codeImports.js.map +1 -0
  401. package/dist/internal/schema/codeTokens.d.ts +8 -0
  402. package/dist/internal/schema/codeTokens.d.ts.map +1 -0
  403. package/dist/internal/schema/codeTokens.js +17 -0
  404. package/dist/internal/schema/codeTokens.js.map +1 -0
  405. package/dist/internal/schema/passthrough.d.ts +2 -0
  406. package/dist/internal/schema/passthrough.d.ts.map +1 -0
  407. package/dist/internal/schema/passthrough.js +8 -0
  408. package/dist/internal/schema/passthrough.js.map +1 -0
  409. package/dist/internal/schema/schemaCodegen.d.ts +2 -0
  410. package/dist/internal/schema/schemaCodegen.d.ts.map +1 -0
  411. package/dist/internal/schema/schemaCodegen.js +377 -0
  412. package/dist/internal/schema/schemaCodegen.js.map +1 -0
  413. package/dist/internal/schema/toJsonSchemaDocument.js +11 -4
  414. package/dist/internal/schema/toJsonSchemaDocument.js.map +1 -1
  415. package/dist/internal/trie.js +51 -64
  416. package/dist/internal/trie.js.map +1 -1
  417. package/dist/internal/utf8.d.ts +2 -0
  418. package/dist/internal/utf8.d.ts.map +1 -0
  419. package/dist/internal/utf8.js +151 -0
  420. package/dist/internal/utf8.js.map +1 -0
  421. package/dist/internal/version.js +1 -1
  422. package/dist/jose/Jwks.d.ts +13 -0
  423. package/dist/jose/Jwks.d.ts.map +1 -1
  424. package/dist/jose/Jwks.js +10 -2
  425. package/dist/jose/Jwks.js.map +1 -1
  426. package/dist/observability/OtlpExporter.d.ts.map +1 -1
  427. package/dist/observability/OtlpExporter.js +12 -10
  428. package/dist/observability/OtlpExporter.js.map +1 -1
  429. package/dist/observability/OtlpLogger.d.ts.map +1 -1
  430. package/dist/observability/OtlpLogger.js +5 -3
  431. package/dist/observability/OtlpLogger.js.map +1 -1
  432. package/dist/observability/internal/otlpProtobuf.d.ts +4 -2
  433. package/dist/observability/internal/otlpProtobuf.d.ts.map +1 -1
  434. package/dist/observability/internal/otlpProtobuf.js +238 -156
  435. package/dist/observability/internal/otlpProtobuf.js.map +1 -1
  436. package/dist/persistence/PersistedQueue.d.ts.map +1 -1
  437. package/dist/persistence/PersistedQueue.js +20 -3
  438. package/dist/persistence/PersistedQueue.js.map +1 -1
  439. package/dist/protobuf/ProtobufDescriptor.d.ts +377 -0
  440. package/dist/protobuf/ProtobufDescriptor.d.ts.map +1 -0
  441. package/dist/protobuf/ProtobufDescriptor.js +135 -0
  442. package/dist/protobuf/ProtobufDescriptor.js.map +1 -0
  443. package/dist/protobuf/ProtobufDescriptorProto.d.ts +2083 -0
  444. package/dist/protobuf/ProtobufDescriptorProto.d.ts.map +1 -0
  445. package/dist/protobuf/ProtobufDescriptorProto.js +2674 -0
  446. package/dist/protobuf/ProtobufDescriptorProto.js.map +1 -0
  447. package/dist/protobuf/ProtobufMessage.d.ts +183 -0
  448. package/dist/protobuf/ProtobufMessage.d.ts.map +1 -0
  449. package/dist/protobuf/ProtobufMessage.js +232 -0
  450. package/dist/protobuf/ProtobufMessage.js.map +1 -0
  451. package/dist/protobuf/ProtobufReader.d.ts +350 -0
  452. package/dist/protobuf/ProtobufReader.d.ts.map +1 -0
  453. package/dist/protobuf/ProtobufReader.js +698 -0
  454. package/dist/protobuf/ProtobufReader.js.map +1 -0
  455. package/dist/protobuf/ProtobufWriter.d.ts +224 -0
  456. package/dist/protobuf/ProtobufWriter.d.ts.map +1 -0
  457. package/dist/protobuf/ProtobufWriter.js +483 -0
  458. package/dist/protobuf/ProtobufWriter.js.map +1 -0
  459. package/dist/protobuf/index.d.ts +30 -0
  460. package/dist/protobuf/index.d.ts.map +1 -0
  461. package/dist/protobuf/index.js +31 -0
  462. package/dist/protobuf/index.js.map +1 -0
  463. package/dist/protobuf/internal/binary.d.ts +2 -0
  464. package/dist/protobuf/internal/binary.d.ts.map +1 -0
  465. package/dist/protobuf/internal/binary.js +966 -0
  466. package/dist/protobuf/internal/binary.js.map +1 -0
  467. package/dist/protobuf/internal/resolve.d.ts +2 -0
  468. package/dist/protobuf/internal/resolve.d.ts.map +1 -0
  469. package/dist/protobuf/internal/resolve.js +463 -0
  470. package/dist/protobuf/internal/resolve.js.map +1 -0
  471. package/dist/protobuf/internal/wireType.d.ts +2 -0
  472. package/dist/protobuf/internal/wireType.d.ts.map +1 -0
  473. package/dist/protobuf/internal/wireType.js +10 -0
  474. package/dist/protobuf/internal/wireType.js.map +1 -0
  475. package/dist/reactivity/AsyncResult.d.ts +3 -0
  476. package/dist/reactivity/AsyncResult.d.ts.map +1 -1
  477. package/dist/reactivity/AsyncResult.js +4 -1
  478. package/dist/reactivity/AsyncResult.js.map +1 -1
  479. package/dist/reactivity/Atom.d.ts +10 -4
  480. package/dist/reactivity/Atom.d.ts.map +1 -1
  481. package/dist/reactivity/Atom.js +38 -13
  482. package/dist/reactivity/Atom.js.map +1 -1
  483. package/dist/reactivity/AtomHttpApi.d.ts +5 -0
  484. package/dist/reactivity/AtomHttpApi.d.ts.map +1 -1
  485. package/dist/reactivity/AtomHttpApi.js +5 -1
  486. package/dist/reactivity/AtomHttpApi.js.map +1 -1
  487. package/dist/reactivity/AtomRegistry.js +13 -0
  488. package/dist/reactivity/AtomRegistry.js.map +1 -1
  489. package/dist/reactivity/AtomRpc.d.ts +5 -0
  490. package/dist/reactivity/AtomRpc.d.ts.map +1 -1
  491. package/dist/reactivity/AtomRpc.js +6 -1
  492. package/dist/reactivity/AtomRpc.js.map +1 -1
  493. package/dist/rpc/Rpc.d.ts +25 -0
  494. package/dist/rpc/Rpc.d.ts.map +1 -1
  495. package/dist/rpc/Rpc.js +18 -0
  496. package/dist/rpc/Rpc.js.map +1 -1
  497. package/dist/rpc/RpcClient.d.ts.map +1 -1
  498. package/dist/rpc/RpcClient.js +38 -21
  499. package/dist/rpc/RpcClient.js.map +1 -1
  500. package/dist/rpc/RpcGroup.d.ts +5 -0
  501. package/dist/rpc/RpcGroup.d.ts.map +1 -1
  502. package/dist/rpc/RpcGroup.js.map +1 -1
  503. package/dist/rpc/RpcMiddleware.d.ts +9 -0
  504. package/dist/rpc/RpcMiddleware.d.ts.map +1 -1
  505. package/dist/rpc/RpcMiddleware.js.map +1 -1
  506. package/dist/rpc/RpcSerialization.d.ts +7 -1
  507. package/dist/rpc/RpcSerialization.d.ts.map +1 -1
  508. package/dist/rpc/RpcSerialization.js +22 -5
  509. package/dist/rpc/RpcSerialization.js.map +1 -1
  510. package/dist/rpc/RpcServer.d.ts.map +1 -1
  511. package/dist/rpc/RpcServer.js +33 -18
  512. package/dist/rpc/RpcServer.js.map +1 -1
  513. package/dist/schema/SchemaCompiler/runtime.js +2 -1
  514. package/dist/schema/SchemaCompiler/runtime.js.map +1 -1
  515. package/dist/schema/VariantSchema.d.ts +10 -2
  516. package/dist/schema/VariantSchema.d.ts.map +1 -1
  517. package/dist/schema/VariantSchema.js +7 -1
  518. package/dist/schema/VariantSchema.js.map +1 -1
  519. package/dist/socket/Socket.d.ts +24 -10
  520. package/dist/socket/Socket.d.ts.map +1 -1
  521. package/dist/socket/Socket.js +52 -17
  522. package/dist/socket/Socket.js.map +1 -1
  523. package/dist/sql/Migrator.d.ts +3 -0
  524. package/dist/sql/Migrator.d.ts.map +1 -1
  525. package/dist/sql/Migrator.js +10 -1
  526. package/dist/sql/Migrator.js.map +1 -1
  527. package/dist/sql/SqlModel.d.ts.map +1 -1
  528. package/dist/sql/SqlModel.js +1 -0
  529. package/dist/sql/SqlModel.js.map +1 -1
  530. package/dist/testing/TestConsole.d.ts +96 -0
  531. package/dist/testing/TestConsole.d.ts.map +1 -1
  532. package/dist/testing/TestConsole.js +78 -6
  533. package/dist/testing/TestConsole.js.map +1 -1
  534. package/dist/testing/TestSchema.d.ts +5 -1
  535. package/dist/testing/TestSchema.d.ts.map +1 -1
  536. package/dist/testing/TestSchema.js +7 -2
  537. package/dist/testing/TestSchema.js.map +1 -1
  538. package/dist/workers/SharedMemory.d.ts +115 -0
  539. package/dist/workers/SharedMemory.d.ts.map +1 -0
  540. package/dist/workers/SharedMemory.js +149 -0
  541. package/dist/workers/SharedMemory.js.map +1 -0
  542. package/dist/workers/Transferable.d.ts.map +1 -1
  543. package/dist/workers/Transferable.js +1 -4
  544. package/dist/workers/Transferable.js.map +1 -1
  545. package/dist/workers/index.d.ts +5 -0
  546. package/dist/workers/index.d.ts.map +1 -1
  547. package/dist/workers/index.js +5 -0
  548. package/dist/workers/index.js.map +1 -1
  549. package/dist/workflow/WorkflowEngine.d.ts.map +1 -1
  550. package/dist/workflow/WorkflowEngine.js +3 -1
  551. package/dist/workflow/WorkflowEngine.js.map +1 -1
  552. package/package.json +7 -4
  553. package/src/Arbitrary.ts +60 -3
  554. package/src/BigInt.ts +247 -9
  555. package/src/Cache.ts +4 -2
  556. package/src/Cause.ts +3 -3
  557. package/src/Chunk.ts +7 -3
  558. package/src/Clock.ts +5 -2
  559. package/src/Codegen.ts +741 -0
  560. package/src/Config.ts +35 -4
  561. package/src/ConfigProvider.ts +24 -7
  562. package/src/Effect.ts +871 -109
  563. package/src/Equivalence.ts +16 -13
  564. package/src/Fiber.ts +58 -8
  565. package/src/FiberHandle.ts +86 -12
  566. package/src/FiberMap.ts +83 -10
  567. package/src/FiberSet.ts +96 -8
  568. package/src/Formatter.ts +2 -0
  569. package/src/LayerMap.ts +14 -4
  570. package/src/LayerRef.ts +2 -2
  571. package/src/Match.ts +16 -0
  572. package/src/Metric.ts +1 -1
  573. package/src/Option.ts +9 -5
  574. package/src/Order.ts +9 -4
  575. package/src/Pool.ts +22 -17
  576. package/src/Predicate.ts +7 -3
  577. package/src/Queue.ts +84 -31
  578. package/src/Rational.ts +198 -0
  579. package/src/Request.ts +20 -0
  580. package/src/Result.ts +9 -6
  581. package/src/Schema.ts +69 -32
  582. package/src/SchemaAST.ts +15 -4
  583. package/src/SchemaGetter.ts +17 -10
  584. package/src/SchemaRepresentation.ts +19 -74
  585. package/src/SchemaTransformation.ts +12 -11
  586. package/src/Scope.ts +12 -6
  587. package/src/ScopedCache.ts +2 -1
  588. package/src/Semaphore.ts +18 -4
  589. package/src/Stream.ts +66 -20
  590. package/src/String.ts +83 -6
  591. package/src/Struct.ts +138 -5
  592. package/src/TextDiff.ts +186 -30
  593. package/src/TxPriorityQueue.ts +2 -2
  594. package/src/ai/LanguageModel.ts +2 -1
  595. package/src/ai/McpServer.ts +145 -22
  596. package/src/ai/Tool.ts +3 -2
  597. package/src/ai/Toolkit.ts +3 -1
  598. package/src/chat/Chat.ts +164 -0
  599. package/src/chat/ChatAdapter.ts +444 -0
  600. package/src/chat/ChatError.ts +684 -0
  601. package/src/chat/ChatEvent.ts +221 -0
  602. package/src/chat/ChatHandler.ts +102 -0
  603. package/src/chat/ChatInteraction.ts +1979 -0
  604. package/src/chat/ChatMarkdown.ts +1406 -0
  605. package/src/chat/ChatMessage.ts +213 -0
  606. package/src/chat/ChatTest.ts +2606 -0
  607. package/src/chat/ChatThread.ts +132 -0
  608. package/src/chat/ChatUi.ts +320 -0
  609. package/src/chat/index.ts +72 -0
  610. package/src/chat/internal/retries.ts +7 -0
  611. package/src/cli/CliOutput.ts +4 -5
  612. package/src/cli/Command.ts +20 -2
  613. package/src/cli/Prompt.ts +15 -9
  614. package/src/cli/internal/config.ts +8 -8
  615. package/src/cluster/ClusterCron.ts +33 -10
  616. package/src/cluster/ClusterWorkflowEngine.ts +42 -23
  617. package/src/cluster/Sharding.ts +17 -3
  618. package/src/cluster/ShardingConfig.ts +3 -0
  619. package/src/cluster/SqlMessageStorage.ts +16 -20
  620. package/src/cluster/SqlRunnerStorage.ts +21 -8
  621. package/src/cluster/internal/entityManager.ts +19 -10
  622. package/src/cluster/internal/entityReaper.ts +1 -1
  623. package/src/crypto/Kdf.ts +2 -1
  624. package/src/crypto/Password.ts +258 -0
  625. package/src/crypto/index.ts +6 -0
  626. package/src/encoding/Base64.ts +79 -0
  627. package/src/encoding/Base64Url.ts +1 -0
  628. package/src/encoding/Csv.ts +47 -20
  629. package/src/encoding/Hex.ts +5 -0
  630. package/src/encoding/SchemaBinary.ts +13 -79
  631. package/src/encoding/Sse.ts +7 -5
  632. package/src/encoding/Xml.ts +394 -47
  633. package/src/eventlog/EventJournal.ts +3 -8
  634. package/src/eventlog/SqlEventLogServerEncrypted.ts +9 -9
  635. package/src/http/FindMyWay/internal/router.ts +181 -129
  636. package/src/http/FindMyWay.ts +106 -0
  637. package/src/http/HttpClient.ts +2 -1
  638. package/src/http/HttpMiddleware.ts +22 -9
  639. package/src/http/HttpRouter.ts +84 -20
  640. package/src/http/HttpServerResponse.ts +33 -61
  641. package/src/http/Mime.ts +3 -2
  642. package/src/http/internal/compression.ts +2 -2
  643. package/src/{http-api → http}/internal/mediaType.ts +4 -0
  644. package/src/http/internal/redactedPath.ts +144 -0
  645. package/src/http/internal/requestState.ts +2 -0
  646. package/src/http-api/HttpApi.ts +25 -2
  647. package/src/http-api/HttpApiBuilder.ts +5 -2
  648. package/src/http-api/HttpApiClient.ts +10 -6
  649. package/src/http-api/HttpApiEndpoint.ts +1 -1
  650. package/src/http-api/HttpApiScalar.ts +9 -1
  651. package/src/http-api/HttpApiSchema.ts +1 -1
  652. package/src/http-api/OpenApi.ts +2 -0
  653. package/src/http-api/internal/httpApiScalar.ts +5 -1
  654. package/src/index.ts +6 -0
  655. package/src/internal/arbitrary/model.ts +3 -9
  656. package/src/internal/arbitrary/regexp.ts +3 -1
  657. package/src/internal/arbitrary/runner.ts +28 -14
  658. package/src/internal/arbitrary/schema.ts +140 -35
  659. package/src/internal/codegen.ts +53 -0
  660. package/src/internal/core.ts +3 -3
  661. package/src/internal/dateTime.ts +30 -13
  662. package/src/internal/effect.ts +25 -9
  663. package/src/internal/hashMap.ts +8 -7
  664. package/src/internal/matcher.ts +2 -1
  665. package/src/internal/record.ts +19 -4
  666. package/src/internal/result.ts +1 -1
  667. package/src/internal/schema/codeExpression.ts +179 -0
  668. package/src/internal/schema/codeImports.ts +142 -0
  669. package/src/internal/schema/codeTokens.ts +39 -0
  670. package/src/internal/schema/passthrough.ts +8 -0
  671. package/src/internal/schema/schemaCodegen.ts +543 -0
  672. package/src/internal/schema/toJsonSchemaDocument.ts +13 -4
  673. package/src/internal/trie.ts +46 -60
  674. package/src/internal/utf8.ts +106 -0
  675. package/src/internal/version.ts +1 -1
  676. package/src/jose/Jwks.ts +23 -4
  677. package/src/observability/OtlpExporter.ts +12 -10
  678. package/src/observability/OtlpLogger.ts +5 -3
  679. package/src/observability/internal/otlpProtobuf.ts +386 -457
  680. package/src/persistence/PersistedQueue.ts +21 -4
  681. package/src/protobuf/ProtobufDescriptor.ts +503 -0
  682. package/src/protobuf/ProtobufDescriptorProto.ts +3611 -0
  683. package/src/protobuf/ProtobufMessage.ts +277 -0
  684. package/src/protobuf/ProtobufReader.ts +756 -0
  685. package/src/protobuf/ProtobufWriter.ts +530 -0
  686. package/src/protobuf/index.ts +36 -0
  687. package/src/protobuf/internal/binary.ts +1215 -0
  688. package/src/protobuf/internal/resolve.ts +533 -0
  689. package/src/protobuf/internal/wireType.ts +9 -0
  690. package/src/reactivity/AsyncResult.ts +6 -1
  691. package/src/reactivity/Atom.ts +55 -16
  692. package/src/reactivity/AtomHttpApi.ts +10 -1
  693. package/src/reactivity/AtomRegistry.ts +16 -0
  694. package/src/reactivity/AtomRpc.ts +11 -1
  695. package/src/rpc/Rpc.ts +31 -0
  696. package/src/rpc/RpcClient.ts +30 -21
  697. package/src/rpc/RpcGroup.ts +5 -0
  698. package/src/rpc/RpcMiddleware.ts +9 -0
  699. package/src/rpc/RpcSerialization.ts +26 -6
  700. package/src/rpc/RpcServer.ts +33 -20
  701. package/src/schema/SchemaCompiler/runtime.ts +2 -3
  702. package/src/schema/VariantSchema.ts +12 -4
  703. package/src/socket/Socket.ts +67 -20
  704. package/src/sql/Migrator.ts +8 -1
  705. package/src/sql/SqlModel.ts +4 -0
  706. package/src/testing/TestConsole.ts +119 -9
  707. package/src/testing/TestSchema.ts +8 -3
  708. package/src/workers/SharedMemory.ts +227 -0
  709. package/src/workers/Transferable.ts +1 -5
  710. package/src/workers/index.ts +6 -0
  711. package/src/workflow/WorkflowEngine.ts +3 -1
  712. package/dist/http-api/internal/mediaType.d.ts.map +0 -1
  713. package/dist/internal/schema/toCodeDocument.d.ts +0 -2
  714. package/dist/internal/schema/toCodeDocument.d.ts.map +0 -1
  715. package/dist/internal/schema/toCodeDocument.js +0 -447
  716. package/dist/internal/schema/toCodeDocument.js.map +0 -1
  717. package/dist/observability/internal/protobuf.d.ts +0 -2
  718. package/dist/observability/internal/protobuf.d.ts.map +0 -1
  719. package/dist/observability/internal/protobuf.js +0 -169
  720. package/dist/observability/internal/protobuf.js.map +0 -1
  721. package/src/internal/schema/toCodeDocument.ts +0 -578
  722. package/src/observability/internal/protobuf.ts +0 -225
  723. /package/dist/{http-api → http}/internal/mediaType.d.ts +0 -0
@@ -0,0 +1,164 @@
1
+ /**
2
+ * The routed outbound chat service.
3
+ *
4
+ * `Chat` has the ops of every registered adapter and routes each call by the
5
+ * address's platform. `Chat.layer` provides the router and an empty
6
+ * `ChatAdapter.Registry`; adapter layers stack on top with
7
+ * `Layer.provideMerge`, and a platform that is off is a layer left out.
8
+ *
9
+ * **Example** (Posting through the router)
10
+ *
11
+ * ```ts
12
+ * import { Effect } from "effect"
13
+ * import { Chat, ChatThread } from "effect/chat"
14
+ *
15
+ * const program = Effect.gen(function*() {
16
+ * const chat = yield* Chat.Chat
17
+ * const posted = yield* chat.post(ChatThread.make("slack", "T1/C1"), { markdown: "Hello" })
18
+ * return posted.id
19
+ * })
20
+ * ```
21
+ *
22
+ * @stability unstable
23
+ * @since 4.1.5
24
+ */
25
+ import * as Context from "../Context.ts"
26
+ import * as Effect from "../Effect.ts"
27
+ import * as Layer from "../Layer.ts"
28
+ import * as Stream from "../Stream.ts"
29
+ import type { ChatAdapter, Descriptor, Ops, User } from "./ChatAdapter.ts"
30
+ import { Registry } from "./ChatAdapter.ts"
31
+ import { ChatError, NoAdapter } from "./ChatError.ts"
32
+ import type { ChatThread } from "./ChatThread.ts"
33
+ import { RetriesDisabled } from "./internal/retries.ts"
34
+
35
+ /**
36
+ * Service that routes chat operations to the adapter registered for each
37
+ * address's platform.
38
+ *
39
+ * **Details**
40
+ *
41
+ * - Every op takes an address and goes to the adapter for
42
+ * `thread.platform`, failing with `NoAdapter` when there is none.
43
+ * - `getUser` takes the platform first, because a bare user id names none.
44
+ * - `followUp` is routed by the platform of the deferred command's thread.
45
+ * One call per deferral is the portable contract: the first is the
46
+ * answer, and a second is platform-specific, a new message on Slack (up to
47
+ * five) and an overwrite of the first on Discord. It is rendered as
48
+ * `respond` is, so it never mentions anyone: Slack shows the token as
49
+ * text and Discord renders it and notifies nobody.
50
+ * - `descriptor` returns a platform's capabilities and limits.
51
+ * - Each call runs in a `Chat.{op}` span whose attributes are the platform, the
52
+ * op and, on failure, the error reason and retry value.
53
+ *
54
+ * @stability unstable
55
+ * @category services
56
+ * @since 4.1.5
57
+ */
58
+ export class Chat extends Context.Service<
59
+ Chat,
60
+ Omit<Ops, "getUser"> & {
61
+ readonly getUser: (
62
+ platform: string,
63
+ id: string,
64
+ options?: { readonly in?: ChatThread | undefined }
65
+ ) => Effect.Effect<User, ChatError>
66
+ readonly descriptor: (platform: string) => Effect.Effect<Descriptor, ChatError>
67
+ }
68
+ >()("effect/chat/Chat") {}
69
+
70
+ const spanAttributes = (platform: string, op: string) => ({ "chat.platform": platform, "chat.op": op })
71
+
72
+ const annotateFailure = (error: ChatError) =>
73
+ Effect.annotateCurrentSpan({ "chat.error.reason": error.reason._tag, "chat.error.retry": error.retry })
74
+
75
+ const make = Effect.sync(() => {
76
+ const adapters = new Map<string, ChatAdapter>()
77
+
78
+ const lookup = (platform: string, op: string): Effect.Effect<ChatAdapter, ChatError> =>
79
+ Effect.suspend(() => {
80
+ const adapter = adapters.get(platform)
81
+ return adapter === undefined
82
+ ? Effect.fail(new ChatError({ platform, op, reason: new NoAdapter({}) }))
83
+ : Effect.succeed(adapter)
84
+ })
85
+
86
+ const route = <A>(
87
+ platform: string,
88
+ op: string,
89
+ f: (adapter: ChatAdapter) => Effect.Effect<A, ChatError>
90
+ ): Effect.Effect<A, ChatError> =>
91
+ lookup(platform, op).pipe(
92
+ Effect.flatMap(f),
93
+ Effect.tapError(annotateFailure),
94
+ Effect.withSpan(`Chat.${op}`, { attributes: spanAttributes(platform, op) })
95
+ )
96
+
97
+ const routeStream = <A>(
98
+ platform: string,
99
+ op: string,
100
+ f: (adapter: ChatAdapter) => Stream.Stream<A, ChatError>
101
+ ): Stream.Stream<A, ChatError> =>
102
+ Stream.unwrap(Effect.map(lookup(platform, op), f)).pipe(
103
+ Stream.tapError(annotateFailure),
104
+ Stream.withSpan(`Chat.${op}`, { attributes: spanAttributes(platform, op) })
105
+ )
106
+
107
+ const registry = Registry.of({
108
+ register: (adapter) => Effect.sync(() => void adapters.set(adapter.descriptor.platform, adapter)),
109
+ get: (platform) => lookup(platform, "get"),
110
+ descriptors: Effect.sync(() => Array.from(adapters.values(), (adapter) => adapter.descriptor))
111
+ })
112
+
113
+ const chat = Chat.of({
114
+ post: (thread, content) => route(thread.platform, "post", (adapter) => adapter.post(thread, content)),
115
+ edit: (thread, messageId, content) =>
116
+ route(thread.platform, "edit", (adapter) => adapter.edit(thread, messageId, content)),
117
+ delete: (thread, messageId) => route(thread.platform, "delete", (adapter) => adapter.delete(thread, messageId)),
118
+ fetchMessage: (thread, messageId) =>
119
+ route(thread.platform, "fetchMessage", (adapter) => adapter.fetchMessage(thread, messageId)),
120
+ history: (thread, options) =>
121
+ routeStream(thread.platform, "history", (adapter) => adapter.history(thread, options)),
122
+ download: (thread, attachment, options) =>
123
+ routeStream(thread.platform, "download", (adapter) => adapter.download(thread, attachment, options)),
124
+ startThread: (thread, messageId, options) =>
125
+ route(thread.platform, "startThread", (adapter) => adapter.startThread(thread, messageId, options)),
126
+ getThread: (thread) => route(thread.platform, "getThread", (adapter) => adapter.getThread(thread)),
127
+ opener: (thread) => route(thread.platform, "opener", (adapter) => adapter.opener(thread)),
128
+ getUser: (platform, id, options) => route(platform, "getUser", (adapter) => adapter.getUser(id, options)),
129
+ followUp: (deferred, content) =>
130
+ route(deferred.command.thread.platform, "followUp", (adapter) => adapter.followUp(deferred, content)),
131
+ descriptor: (platform) => route(platform, "descriptor", (adapter) => Effect.succeed(adapter.descriptor))
132
+ })
133
+
134
+ return Context.make(Registry, registry).pipe(Context.add(Chat, chat))
135
+ })
136
+
137
+ /**
138
+ * Layer that provides the `Chat` router and an empty `ChatAdapter.Registry`.
139
+ *
140
+ * **When to use**
141
+ *
142
+ * Use as the base of a chat setup. Adapter layers go on top with
143
+ * `Layer.provideMerge`.
144
+ *
145
+ * @stability unstable
146
+ * @category layers
147
+ * @since 4.1.5
148
+ */
149
+ export const layer: Layer.Layer<Chat | Registry> = Layer.effectContext(make)
150
+
151
+ /**
152
+ * Runs an effect with adapter retries turned off, so every adapter call inside
153
+ * it makes one attempt.
154
+ *
155
+ * **Gotchas**
156
+ *
157
+ * The name is provisional.
158
+ *
159
+ * @stability unstable
160
+ * @category combinators
161
+ * @since 4.1.5
162
+ */
163
+ export const withoutRetries = <A, E, R>(effect: Effect.Effect<A, E, R>): Effect.Effect<A, E, R> =>
164
+ Effect.provideService(effect, RetriesDisabled, true)
@@ -0,0 +1,444 @@
1
+ /**
2
+ * What a chat platform adapter implements.
3
+ *
4
+ * An adapter is a set of `Ops` plus a static `Descriptor` of what the
5
+ * platform supports. Adapters register in the `Registry`, which `Chat`
6
+ * routes through by `thread.platform`.
7
+ *
8
+ * **Details**
9
+ *
10
+ * - Every op exists on every platform. Where the platform has no equivalent
11
+ * the op fails with `Unsupported`, naming the capability.
12
+ * - A post notifies nobody unless asked: mentions in Markdown do not notify by
13
+ * default.
14
+ * - Length is checked before the call, with `checkMessageLength`, in the
15
+ * unit the descriptor's `measure` counts.
16
+ * - Adapters retry `retry` failures with `retrySafe` and never retry
17
+ * `uncertain` ones.
18
+ *
19
+ * @stability unstable
20
+ * @since 4.1.5
21
+ */
22
+ import * as Context from "../Context.ts"
23
+ import type * as DateTime from "../DateTime.ts"
24
+ import * as Duration from "../Duration.ts"
25
+ import * as Effect from "../Effect.ts"
26
+ import * as Layer from "../Layer.ts"
27
+ import type * as Option from "../Option.ts"
28
+ import type * as Schema from "../Schema.ts"
29
+ import type * as Scope from "../Scope.ts"
30
+ import type * as Stream from "../Stream.ts"
31
+ import type { Capability } from "./ChatError.ts"
32
+ import { ChatError, TooLarge } from "./ChatError.ts"
33
+ import type { ThreadKind } from "./ChatEvent.ts"
34
+ import type { Defer } from "./ChatInteraction.ts"
35
+ import type { Attachment, ChatMessage, ReplyTo } from "./ChatMessage.ts"
36
+ import type { ChatThread } from "./ChatThread.ts"
37
+ import type { Action } from "./ChatUi.ts"
38
+ import { RetriesDisabled } from "./internal/retries.ts"
39
+
40
+ /**
41
+ * Static description of a platform: its capabilities and limits, readable
42
+ * without a call to the platform.
43
+ *
44
+ * **Details**
45
+ *
46
+ * - An op whose capability is missing from `capabilities` fails with
47
+ * `Unsupported`.
48
+ * - `limits.messageLength` is the platform's own limit for one message, in
49
+ * the platform's own unit. Where every message also carries a fixed
50
+ * overhead that the text does not, such as a card's structure, it is that
51
+ * limit less a fixed reservation for the overhead, and the adapter's docs
52
+ * give both numbers.
53
+ * - `measure` gives what a Markdown string costs against
54
+ * `limits.messageLength` and `limits.streamLength`. It is pure and makes
55
+ * no call to the platform. It is an upper bound, never less than what the
56
+ * adapter sends for the text, and it adds up:
57
+ * `measure(a + b) <= measure(a) + measure(b)`. It measures ASCII letters
58
+ * at one each.
59
+ * - `measure` takes the `actions` a message carries as an optional second
60
+ * argument. Where text and elements share one budget (Slack) they add to
61
+ * the cost, and elsewhere the argument is ignored. With it,
62
+ * `measure(md, actions) <= measure(md) + measure("", actions)`, so a caller
63
+ * can set room aside for the elements before it cuts the text,
64
+ * `measure(md, actions) >= measure(md)`, and `measure(md, [])` is
65
+ * `measure(md)`. A `measure` with one parameter fits the type.
66
+ * - `limits.minWriteInterval` is the default floor between two writes to one
67
+ * thread, for streamed and multi-part posts.
68
+ * - `limits.streamLength` and `limits.streamAge` apply to native streams
69
+ * only. `streamLength` is never more than `messageLength`, so a stream's
70
+ * text always fits an `edit`.
71
+ * - `limits.actionsPerMessage`, `limits.actionDataLength`,
72
+ * `limits.modalMetadataLength` and `limits.modalFields` are there exactly
73
+ * when the matching capability is (`buttons` for the first two, `modals`
74
+ * for the last two). Each is the platform's number in the platform's unit,
75
+ * as `messageLength` is. Where the platform publishes none, it is the
76
+ * adapter's own cap, documented as the adapter's, and set so that a
77
+ * message holding every element at its cap still fits `messageLength`.
78
+ * The adapter checks them exactly and fails
79
+ * `TooLarge`: before the call for a message's elements, and before it
80
+ * opens a modal.
81
+ * - `limits.followUpAge` is there exactly when `commands` is: how long after
82
+ * a command its `followUp` still works.
83
+ *
84
+ * **Gotchas**
85
+ *
86
+ * Title and label limits of a modal are not on the descriptor. The adapter
87
+ * checks them the same way, and its docs list them.
88
+ *
89
+ * @stability unstable
90
+ * @category models
91
+ * @since 4.1.5
92
+ */
93
+ export interface Descriptor {
94
+ readonly platform: string
95
+ readonly capabilities: ReadonlySet<Capability>
96
+ readonly measure: (markdown: string, actions?: ReadonlyArray<Action>) => number
97
+ readonly limits: {
98
+ readonly messageLength: number
99
+ readonly filesPerMessage: number
100
+ readonly uploadBytes: number
101
+ readonly minWriteInterval: Duration.Duration
102
+ readonly streamLength?: number | undefined
103
+ readonly streamAge?: Duration.Duration | undefined
104
+ /** How many elements one message's `actions` may hold. */
105
+ readonly actionsPerMessage?: number | undefined
106
+ /** The most an element's id and encoded value may take together. */
107
+ readonly actionDataLength?: number | undefined
108
+ /** The most a modal's id and its encoded metadata may take together, after what the adapter adds. */
109
+ readonly modalMetadataLength?: number | undefined
110
+ /** How many inputs and texts one modal may hold. */
111
+ readonly modalFields?: number | undefined
112
+ /** How long after a command its `followUp` still works. */
113
+ readonly followUpAge?: Duration.Duration | undefined
114
+ }
115
+ }
116
+
117
+ /**
118
+ * A file to upload with a post.
119
+ *
120
+ * @stability unstable
121
+ * @category models
122
+ * @since 4.1.5
123
+ */
124
+ export interface File {
125
+ readonly name: string
126
+ readonly contentType: string
127
+ readonly content: Uint8Array
128
+ }
129
+
130
+ /**
131
+ * The message a successful post created.
132
+ *
133
+ * @stability unstable
134
+ * @category models
135
+ * @since 4.1.5
136
+ */
137
+ export interface Posted {
138
+ readonly id: string
139
+ readonly thread: ChatThread
140
+ readonly timestamp: DateTime.Utc
141
+ }
142
+
143
+ /**
144
+ * What the platform says about an address.
145
+ *
146
+ * @stability unstable
147
+ * @category models
148
+ * @since 4.1.5
149
+ */
150
+ export interface ThreadInfo {
151
+ readonly thread: ChatThread
152
+ readonly kind: ThreadKind
153
+ readonly name?: string | undefined
154
+ readonly topic?: string | undefined
155
+ readonly parent?: ChatThread | undefined
156
+ readonly createdAt?: DateTime.Utc | undefined
157
+ readonly raw: Schema.Json
158
+ }
159
+
160
+ /**
161
+ * A user as the platform reports them.
162
+ *
163
+ * **Details**
164
+ *
165
+ * - `name` is the guild nick when `in` was given and the platform has one.
166
+ * - `raw` is the platform's own record of the user. What the model has no
167
+ * field for, such as a Slack user's team or a Discord member's roles, is
168
+ * read from there. Each adapter documents what its `raw` holds.
169
+ *
170
+ * @stability unstable
171
+ * @category models
172
+ * @since 4.1.5
173
+ */
174
+ export interface User {
175
+ readonly id: string
176
+ readonly name: string
177
+ readonly isBot: boolean
178
+ readonly isSelf: boolean
179
+ readonly raw: Schema.Json
180
+ }
181
+
182
+ /**
183
+ * The operations of one platform. `Chat` has the same ops, routed by
184
+ * `thread.platform`.
185
+ *
186
+ * **Details**
187
+ *
188
+ * - `post` takes standard Markdown that must fit `limits.messageLength`. It
189
+ * never splits or truncates: the adapter checks the length itself and fails
190
+ * with `TooLarge` without calling the platform. Mentions in it notify nobody.
191
+ * - A `post` shows no link preview unless requested through the adapter's
192
+ * scoped `withPostOptions`. This rule does not cover edits or native streams.
193
+ * - `fetchMessage` fails with `NotFound` for a message that is gone.
194
+ * - `history` pages lazily. `backward` runs newest to oldest, `forward`
195
+ * oldest to newest, and `from` is exclusive. A thread's oldest message is its
196
+ * opener, whose `thread` is the thread's parent: the one message in a
197
+ * thread's history that is not addressed to that thread. Without an opener,
198
+ * history starts at the first reply, whether the opener was deleted or the
199
+ * platform's thread root is not a message. A `backward` read that stops
200
+ * early has not reached the opener: `opener` reads it by itself.
201
+ * - `download` fails with `TooLarge` as soon as more than `maxBytes` arrive.
202
+ * It streams, so a file is never held whole unless the caller asks:
203
+ * `Stream.mkUint8Array` collects the stream into one array.
204
+ * - `startThread` returns the thread under `messageId`, created when there is
205
+ * none. It is get-or-create, and the only way from an opener to its thread.
206
+ * - `opener` is the message a thread hangs off: `None` for a channel or
207
+ * direct address, or when it was deleted.
208
+ * - `actions` is a flat list of elements beside the Markdown, and the
209
+ * adapter lays out the rows. A platform without an element fails
210
+ * `Unsupported` before the call, naming `buttons` or `selects`. An
211
+ * `edit` replaces the whole message, so an edit without `actions`
212
+ * removes them.
213
+ * - `followUp` sends the answer a command's `Defer` promised, to whoever
214
+ * its `visibility` names. It is routed by `deferred.command.thread` and
215
+ * never retried. It takes no files, and `withPostOptions` does not reach
216
+ * it. The contract is one call per deferral: a second posts another
217
+ * message on Slack and replaces the first on Discord. An adapter does not
218
+ * stop it, and `ChatTest`'s fake fails it. It fails
219
+ * `NotFound` with detail `interaction_expired` past `limits.followUpAge`,
220
+ * and `Unsupported` without `commands`.
221
+ *
222
+ * @stability unstable
223
+ * @category models
224
+ * @since 4.1.5
225
+ */
226
+ export interface Ops {
227
+ readonly post: (thread: ChatThread, content: {
228
+ readonly markdown: string
229
+ readonly replyTo?: ReplyTo | undefined
230
+ readonly files?: ReadonlyArray<File> | undefined
231
+ readonly actions?: ReadonlyArray<Action> | undefined
232
+ }) => Effect.Effect<Posted, ChatError>
233
+ readonly edit: (
234
+ thread: ChatThread,
235
+ messageId: string,
236
+ content: {
237
+ readonly markdown: string
238
+ readonly actions?: ReadonlyArray<Action> | undefined
239
+ }
240
+ ) => Effect.Effect<void, ChatError>
241
+ readonly delete: (thread: ChatThread, messageId: string) => Effect.Effect<void, ChatError>
242
+ readonly fetchMessage: (thread: ChatThread, messageId: string) => Effect.Effect<ChatMessage, ChatError>
243
+ readonly history: (thread: ChatThread, options: {
244
+ readonly direction: "backward" | "forward"
245
+ readonly from?: string | undefined
246
+ }) => Stream.Stream<ChatMessage, ChatError>
247
+ readonly download: (
248
+ thread: ChatThread,
249
+ attachment: Attachment,
250
+ options: { readonly maxBytes: number }
251
+ ) => Stream.Stream<Uint8Array, ChatError>
252
+ readonly startThread: (
253
+ thread: ChatThread,
254
+ messageId: string,
255
+ options?: { readonly name?: string | undefined }
256
+ ) => Effect.Effect<ChatThread, ChatError>
257
+ readonly getThread: (thread: ChatThread) => Effect.Effect<ThreadInfo, ChatError>
258
+ readonly opener: (thread: ChatThread) => Effect.Effect<Option.Option<ChatMessage>, ChatError>
259
+ readonly getUser: (
260
+ id: string,
261
+ options?: { readonly in?: ChatThread | undefined }
262
+ ) => Effect.Effect<User, ChatError>
263
+ readonly followUp: (deferred: Defer, content: {
264
+ readonly markdown: string
265
+ readonly actions?: ReadonlyArray<Action> | undefined
266
+ }) => Effect.Effect<void, ChatError>
267
+ }
268
+
269
+ /**
270
+ * A platform's native streaming of one message, used by `ChatMarkdown.stream`
271
+ * when present. It is adapter-facing and not on `Chat`.
272
+ *
273
+ * **Details**
274
+ *
275
+ * - `start` fails with `Unsupported` when the platform refuses the feature
276
+ * for this thread or recipient, and the caller falls back to post-then-edit.
277
+ * It holds nothing back: all of `markdown` is sent. Do not end `markdown`
278
+ * inside a surrogate pair: a lone surrogate is sent as U+FFFD.
279
+ * - `append` is never retried by the adapter. `open` means the text was
280
+ * added apart from its last `held` UTF-16 code units, `stopped` means
281
+ * nothing was added because a user stopped the stream, and `closed` means
282
+ * nothing was added because the stream is closed or expired.
283
+ * - `held` counts the trailing code units the adapter could not send yet,
284
+ * such as an unclosed `<` or a high surrogate whose other half has not
285
+ * arrived. The caller keeps `markdown.slice(markdown.length - held)` and
286
+ * sends it again at the front of the next append. `flush` holds nothing
287
+ * back and sends a lone surrogate as U+FFFD. A `TooLarge` failure means
288
+ * nothing was added and the stream is still open.
289
+ * - `stop` closes the stream. `stopped` says whether a user had clicked stop
290
+ * on it. It succeeds with `stopped: false` on a stream that is already
291
+ * closed.
292
+ * - `continues` on `start` is the message id of the reply's previous part,
293
+ * absent for a reply's first message. It tells the adapter which reply the
294
+ * stream belongs to, so state kept per reply, such as a rate limit's
295
+ * backoff, carries over a rotation and never passes to another reply.
296
+ *
297
+ * @stability unstable
298
+ * @category models
299
+ * @since 4.1.5
300
+ */
301
+ export interface NativeStream {
302
+ readonly start: (thread: ChatThread, options: {
303
+ readonly markdown: string
304
+ readonly replyTo?: ReplyTo | undefined
305
+ readonly recipient?: string | undefined
306
+ readonly continues?: string | undefined
307
+ }) => Effect.Effect<Posted, ChatError>
308
+ readonly append: (
309
+ thread: ChatThread,
310
+ messageId: string,
311
+ markdown: string,
312
+ options?: { readonly flush?: boolean | undefined }
313
+ ) => Effect.Effect<
314
+ { readonly state: "open" | "stopped" | "closed"; readonly held: number },
315
+ ChatError
316
+ >
317
+ readonly stop: (
318
+ thread: ChatThread,
319
+ messageId: string,
320
+ options: { readonly end: "done" | "rotating" }
321
+ ) => Effect.Effect<{ readonly stopped: boolean }, ChatError>
322
+ }
323
+
324
+ /**
325
+ * What an adapter package builds: the platform's ops, its descriptor and,
326
+ * when the platform has one, its native stream.
327
+ *
328
+ * @stability unstable
329
+ * @category models
330
+ * @since 4.1.5
331
+ */
332
+ export interface ChatAdapter extends Ops {
333
+ readonly descriptor: Descriptor
334
+ readonly nativeStream?: NativeStream | undefined
335
+ }
336
+
337
+ /**
338
+ * Service that holds the adapters by platform. `Chat.layer` provides it.
339
+ *
340
+ * **Details**
341
+ *
342
+ * `get` fails with `NoAdapter` for a platform with no adapter registered.
343
+ * Registering a second adapter for a platform replaces the first.
344
+ *
345
+ * @stability unstable
346
+ * @category services
347
+ * @since 4.1.5
348
+ */
349
+ export class Registry extends Context.Service<Registry, {
350
+ readonly register: (adapter: ChatAdapter) => Effect.Effect<void>
351
+ readonly get: (platform: string) => Effect.Effect<ChatAdapter, ChatError>
352
+ readonly descriptors: Effect.Effect<ReadonlyArray<Descriptor>>
353
+ }>()("effect/chat/ChatAdapter/Registry") {}
354
+
355
+ /**
356
+ * Creates the layer that registers an adapter in the `Registry`.
357
+ *
358
+ * **When to use**
359
+ *
360
+ * Use when building an adapter package's layer. A platform that is off is a
361
+ * layer left out.
362
+ *
363
+ * @stability unstable
364
+ * @category layers
365
+ * @since 4.1.5
366
+ */
367
+ export const layer = <E, R>(
368
+ adapter: Effect.Effect<ChatAdapter, E, R>
369
+ ): Layer.Layer<never, E, Exclude<R, Scope.Scope> | Registry> =>
370
+ Layer.effectDiscard(Effect.gen(function*() {
371
+ const registry = yield* Registry
372
+ yield* registry.register(yield* adapter)
373
+ }))
374
+
375
+ /**
376
+ * Fails with `TooLarge` when Markdown does not fit the descriptor's
377
+ * `limits.messageLength`, measured with the descriptor's `measure`.
378
+ *
379
+ * **When to use**
380
+ *
381
+ * Use when implementing `post`, `edit` and `NativeStream.start` in an adapter,
382
+ * so a message that is too long fails without a call to the platform.
383
+ *
384
+ * **Details**
385
+ *
386
+ * Pass the string the adapter is about to send, after escaping. For a
387
+ * `measure` that counts what escaping adds, measuring the escaped string
388
+ * gives the exact cost, so a post is neither refused when the platform would
389
+ * take it nor passed when the platform would refuse it on length. Pass the
390
+ * message's `actions` too, so they are measured with it.
391
+ *
392
+ * @stability unstable
393
+ * @category validation
394
+ * @since 4.1.5
395
+ */
396
+ export const checkMessageLength = (
397
+ descriptor: Descriptor,
398
+ op: string,
399
+ markdown: string,
400
+ actions?: ReadonlyArray<Action> | undefined
401
+ ): Effect.Effect<void, ChatError> =>
402
+ descriptor.measure(markdown, actions ?? []) <= descriptor.limits.messageLength ? Effect.void : Effect.fail(
403
+ new ChatError({
404
+ platform: descriptor.platform,
405
+ op,
406
+ reason: new TooLarge({ subject: "text", detail: "message_too_long" })
407
+ })
408
+ )
409
+
410
+ const maxRetries = 3
411
+ const baseDelay = Duration.millis(500)
412
+
413
+ /**
414
+ * Retries an adapter request with the policy adapters share.
415
+ *
416
+ * **Details**
417
+ *
418
+ * - Only failures whose retry value is `retry` are retried, up to three
419
+ * times. `uncertain` and `denied` failures are returned at once.
420
+ * - The wait is the error's `retryAfter` when it has one, otherwise an
421
+ * exponential backoff from 500 milliseconds.
422
+ * - Inside `Chat.withoutRetries` the request runs once.
423
+ *
424
+ * @stability unstable
425
+ * @category error handling
426
+ * @since 4.1.5
427
+ */
428
+ export const retrySafe = <A, R>(effect: Effect.Effect<A, ChatError, R>): Effect.Effect<A, ChatError, R> =>
429
+ Effect.flatMap(RetriesDisabled, (disabled) => {
430
+ if (disabled) {
431
+ return effect
432
+ }
433
+ const loop = (attempt: number): Effect.Effect<A, ChatError, R> =>
434
+ Effect.catchIf(
435
+ effect,
436
+ (error) => error.retry === "retry" && attempt < maxRetries,
437
+ (error) =>
438
+ Effect.flatMap(
439
+ Effect.sleep(error.retryAfter ?? Duration.times(baseDelay, 2 ** attempt)),
440
+ () => loop(attempt + 1)
441
+ )
442
+ )
443
+ return loop(0)
444
+ })