effect 4.0.0-beta.40 → 4.0.0-beta.42

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 (181) hide show
  1. package/dist/BigDecimal.d.ts +36 -0
  2. package/dist/BigDecimal.d.ts.map +1 -1
  3. package/dist/BigDecimal.js +52 -0
  4. package/dist/BigDecimal.js.map +1 -1
  5. package/dist/Effect.d.ts +20 -63
  6. package/dist/Effect.d.ts.map +1 -1
  7. package/dist/Effect.js +24 -65
  8. package/dist/Effect.js.map +1 -1
  9. package/dist/Layer.js +1 -1
  10. package/dist/Layer.js.map +1 -1
  11. package/dist/ManagedRuntime.d.ts.map +1 -1
  12. package/dist/ManagedRuntime.js +19 -7
  13. package/dist/ManagedRuntime.js.map +1 -1
  14. package/dist/MutableList.d.ts.map +1 -1
  15. package/dist/MutableList.js +3 -0
  16. package/dist/MutableList.js.map +1 -1
  17. package/dist/Number.d.ts.map +1 -1
  18. package/dist/Number.js +12 -3
  19. package/dist/Number.js.map +1 -1
  20. package/dist/SchemaRepresentation.d.ts.map +1 -1
  21. package/dist/SchemaRepresentation.js +16 -14
  22. package/dist/SchemaRepresentation.js.map +1 -1
  23. package/dist/ServiceMap.d.ts +14 -26
  24. package/dist/ServiceMap.d.ts.map +1 -1
  25. package/dist/ServiceMap.js +6 -5
  26. package/dist/ServiceMap.js.map +1 -1
  27. package/dist/TxChunk.d.ts +39 -39
  28. package/dist/TxChunk.d.ts.map +1 -1
  29. package/dist/TxChunk.js +3 -3
  30. package/dist/TxChunk.js.map +1 -1
  31. package/dist/TxDeferred.d.ts +9 -9
  32. package/dist/TxDeferred.d.ts.map +1 -1
  33. package/dist/TxDeferred.js +2 -2
  34. package/dist/TxDeferred.js.map +1 -1
  35. package/dist/TxHashMap.d.ts +59 -59
  36. package/dist/TxHashMap.d.ts.map +1 -1
  37. package/dist/TxHashMap.js +8 -8
  38. package/dist/TxHashMap.js.map +1 -1
  39. package/dist/TxHashSet.d.ts +35 -35
  40. package/dist/TxHashSet.d.ts.map +1 -1
  41. package/dist/TxHashSet.js +7 -7
  42. package/dist/TxHashSet.js.map +1 -1
  43. package/dist/TxPriorityQueue.d.ts +23 -23
  44. package/dist/TxPriorityQueue.d.ts.map +1 -1
  45. package/dist/TxPriorityQueue.js +4 -4
  46. package/dist/TxPriorityQueue.js.map +1 -1
  47. package/dist/TxPubSub.d.ts +14 -14
  48. package/dist/TxPubSub.d.ts.map +1 -1
  49. package/dist/TxPubSub.js +12 -12
  50. package/dist/TxPubSub.js.map +1 -1
  51. package/dist/TxQueue.d.ts +33 -33
  52. package/dist/TxQueue.d.ts.map +1 -1
  53. package/dist/TxQueue.js +29 -44
  54. package/dist/TxQueue.js.map +1 -1
  55. package/dist/TxReentrantLock.d.ts +10 -33
  56. package/dist/TxReentrantLock.d.ts.map +1 -1
  57. package/dist/TxReentrantLock.js +14 -37
  58. package/dist/TxReentrantLock.js.map +1 -1
  59. package/dist/TxRef.d.ts +36 -42
  60. package/dist/TxRef.d.ts.map +1 -1
  61. package/dist/TxRef.js +16 -25
  62. package/dist/TxRef.js.map +1 -1
  63. package/dist/TxSemaphore.d.ts +8 -8
  64. package/dist/TxSemaphore.d.ts.map +1 -1
  65. package/dist/TxSemaphore.js +10 -10
  66. package/dist/TxSemaphore.js.map +1 -1
  67. package/dist/TxSubscriptionRef.d.ts +14 -14
  68. package/dist/TxSubscriptionRef.d.ts.map +1 -1
  69. package/dist/TxSubscriptionRef.js +5 -5
  70. package/dist/TxSubscriptionRef.js.map +1 -1
  71. package/dist/index.d.ts +6 -6
  72. package/dist/index.js +6 -6
  73. package/dist/internal/effect.js +3 -0
  74. package/dist/internal/effect.js.map +1 -1
  75. package/dist/internal/schema/representation.js +28 -0
  76. package/dist/internal/schema/representation.js.map +1 -1
  77. package/dist/unstable/ai/Chat.d.ts +31 -2
  78. package/dist/unstable/ai/Chat.d.ts.map +1 -1
  79. package/dist/unstable/ai/Chat.js.map +1 -1
  80. package/dist/unstable/ai/LanguageModel.d.ts +68 -6
  81. package/dist/unstable/ai/LanguageModel.d.ts.map +1 -1
  82. package/dist/unstable/ai/LanguageModel.js +88 -11
  83. package/dist/unstable/ai/LanguageModel.js.map +1 -1
  84. package/dist/unstable/ai/OpenAiStructuredOutput.js +3 -0
  85. package/dist/unstable/ai/OpenAiStructuredOutput.js.map +1 -1
  86. package/dist/unstable/cli/Prompt.js +1 -1
  87. package/dist/unstable/cli/Prompt.js.map +1 -1
  88. package/dist/unstable/cli/internal/command.d.ts.map +1 -1
  89. package/dist/unstable/cli/internal/command.js +12 -1
  90. package/dist/unstable/cli/internal/command.js.map +1 -1
  91. package/dist/unstable/cluster/ClusterSchema.d.ts +18 -0
  92. package/dist/unstable/cluster/ClusterSchema.d.ts.map +1 -1
  93. package/dist/unstable/cluster/ClusterSchema.js +21 -1
  94. package/dist/unstable/cluster/ClusterSchema.js.map +1 -1
  95. package/dist/unstable/cluster/ClusterWorkflowEngine.d.ts.map +1 -1
  96. package/dist/unstable/cluster/ClusterWorkflowEngine.js +6 -3
  97. package/dist/unstable/cluster/ClusterWorkflowEngine.js.map +1 -1
  98. package/dist/unstable/cluster/Entity.d.ts.map +1 -1
  99. package/dist/unstable/cluster/Entity.js +1 -0
  100. package/dist/unstable/cluster/Entity.js.map +1 -1
  101. package/dist/unstable/cluster/Message.d.ts +4 -2
  102. package/dist/unstable/cluster/Message.d.ts.map +1 -1
  103. package/dist/unstable/cluster/Message.js +13 -6
  104. package/dist/unstable/cluster/Message.js.map +1 -1
  105. package/dist/unstable/cluster/MessageStorage.d.ts +23 -0
  106. package/dist/unstable/cluster/MessageStorage.d.ts.map +1 -1
  107. package/dist/unstable/cluster/MessageStorage.js +22 -7
  108. package/dist/unstable/cluster/MessageStorage.js.map +1 -1
  109. package/dist/unstable/cluster/Sharding.d.ts.map +1 -1
  110. package/dist/unstable/cluster/Sharding.js +24 -20
  111. package/dist/unstable/cluster/Sharding.js.map +1 -1
  112. package/dist/unstable/cluster/SqlMessageStorage.d.ts.map +1 -1
  113. package/dist/unstable/cluster/SqlMessageStorage.js +3 -1
  114. package/dist/unstable/cluster/SqlMessageStorage.js.map +1 -1
  115. package/dist/unstable/cluster/internal/entityManager.js +10 -4
  116. package/dist/unstable/cluster/internal/entityManager.js.map +1 -1
  117. package/dist/unstable/http/index.d.ts +2 -2
  118. package/dist/unstable/http/index.d.ts.map +1 -1
  119. package/dist/unstable/http/index.js +2 -2
  120. package/dist/unstable/http/index.js.map +1 -1
  121. package/dist/unstable/httpapi/HttpApiSchema.d.ts +1 -3
  122. package/dist/unstable/httpapi/HttpApiSchema.d.ts.map +1 -1
  123. package/dist/unstable/httpapi/OpenApi.d.ts +1 -0
  124. package/dist/unstable/httpapi/OpenApi.d.ts.map +1 -1
  125. package/dist/unstable/rpc/Rpc.d.ts +1 -0
  126. package/dist/unstable/rpc/Rpc.d.ts.map +1 -1
  127. package/dist/unstable/rpc/Rpc.js.map +1 -1
  128. package/dist/unstable/rpc/RpcClient.d.ts.map +1 -1
  129. package/dist/unstable/rpc/RpcClient.js +43 -26
  130. package/dist/unstable/rpc/RpcClient.js.map +1 -1
  131. package/dist/unstable/socket/Socket.d.ts +1 -1
  132. package/dist/unstable/socket/Socket.d.ts.map +1 -1
  133. package/dist/unstable/socket/Socket.js +1 -1
  134. package/dist/unstable/socket/Socket.js.map +1 -1
  135. package/dist/unstable/workflow/Activity.d.ts +5 -0
  136. package/dist/unstable/workflow/Activity.d.ts.map +1 -1
  137. package/dist/unstable/workflow/Activity.js +13 -0
  138. package/dist/unstable/workflow/Activity.js.map +1 -1
  139. package/package.json +1 -1
  140. package/src/BigDecimal.ts +54 -0
  141. package/src/Effect.ts +25 -75
  142. package/src/Layer.ts +1 -1
  143. package/src/ManagedRuntime.ts +33 -20
  144. package/src/MutableList.ts +3 -0
  145. package/src/Number.ts +13 -3
  146. package/src/SchemaRepresentation.ts +8 -6
  147. package/src/ServiceMap.ts +16 -31
  148. package/src/TxChunk.ts +53 -62
  149. package/src/TxDeferred.ts +14 -17
  150. package/src/TxHashMap.ts +91 -101
  151. package/src/TxHashSet.ts +68 -70
  152. package/src/TxPriorityQueue.ts +34 -38
  153. package/src/TxPubSub.ts +30 -32
  154. package/src/TxQueue.ts +70 -84
  155. package/src/TxReentrantLock.ts +30 -54
  156. package/src/TxRef.ts +53 -65
  157. package/src/TxSemaphore.ts +23 -24
  158. package/src/TxSubscriptionRef.ts +25 -27
  159. package/src/index.ts +6 -6
  160. package/src/internal/effect.ts +3 -0
  161. package/src/internal/schema/representation.ts +28 -0
  162. package/src/unstable/ai/Chat.ts +79 -18
  163. package/src/unstable/ai/LanguageModel.ts +182 -66
  164. package/src/unstable/ai/OpenAiStructuredOutput.ts +3 -0
  165. package/src/unstable/cli/Prompt.ts +3 -1
  166. package/src/unstable/cli/internal/command.ts +16 -1
  167. package/src/unstable/cluster/ClusterSchema.ts +29 -1
  168. package/src/unstable/cluster/ClusterWorkflowEngine.ts +22 -3
  169. package/src/unstable/cluster/Entity.ts +1 -0
  170. package/src/unstable/cluster/Message.ts +22 -10
  171. package/src/unstable/cluster/MessageStorage.ts +37 -6
  172. package/src/unstable/cluster/Sharding.ts +31 -23
  173. package/src/unstable/cluster/SqlMessageStorage.ts +6 -1
  174. package/src/unstable/cluster/internal/entityManager.ts +14 -5
  175. package/src/unstable/http/index.ts +2 -2
  176. package/src/unstable/httpapi/HttpApiSchema.ts +1 -1
  177. package/src/unstable/httpapi/OpenApi.ts +1 -0
  178. package/src/unstable/rpc/Rpc.ts +1 -0
  179. package/src/unstable/rpc/RpcClient.ts +45 -33
  180. package/src/unstable/socket/Socket.ts +1 -1
  181. package/src/unstable/workflow/Activity.ts +23 -0
@@ -92,7 +92,7 @@ const TxSubscriptionRefProto: Omit<TxSubscriptionRef<any>, typeof TypeId | "ref"
92
92
  * @since 4.0.0
93
93
  * @category constructors
94
94
  */
95
- export const make = <A>(value: A): Effect.Effect<TxSubscriptionRef<A>, never, Effect.Transaction> =>
95
+ export const make = <A>(value: A): Effect.Effect<TxSubscriptionRef<A>> =>
96
96
  Effect.gen(function*() {
97
97
  const ref = yield* TxRef.make(value)
98
98
  const pubsub = yield* TxPubSub.unbounded<A>()
@@ -101,7 +101,7 @@ export const make = <A>(value: A): Effect.Effect<TxSubscriptionRef<A>, never, Ef
101
101
  self.ref = ref
102
102
  self.pubsub = pubsub
103
103
  return self
104
- })
104
+ }).pipe(Effect.tx)
105
105
 
106
106
  // =============================================================================
107
107
  // Getters
@@ -124,7 +124,7 @@ export const make = <A>(value: A): Effect.Effect<TxSubscriptionRef<A>, never, Ef
124
124
  * @since 4.0.0
125
125
  * @category getters
126
126
  */
127
- export const get = <A>(self: TxSubscriptionRef<A>): Effect.Effect<A, never, Effect.Transaction> => TxRef.get(self.ref)
127
+ export const get = <A>(self: TxSubscriptionRef<A>): Effect.Effect<A> => TxRef.get(self.ref)
128
128
 
129
129
  // =============================================================================
130
130
  // Mutations
@@ -173,7 +173,7 @@ export const modify: {
173
173
  * @since 4.0.0
174
174
  * @category mutations
175
175
  */
176
- <A, B>(f: (current: A) => [returnValue: B, newValue: A]): (self: TxSubscriptionRef<A>) => Effect.Effect<B, never, Effect.Transaction>
176
+ <A, B>(f: (current: A) => [returnValue: B, newValue: A]): (self: TxSubscriptionRef<A>) => Effect.Effect<B>
177
177
  // =============================================================================
178
178
  // Mutations
179
179
  // =============================================================================
@@ -200,20 +200,20 @@ export const modify: {
200
200
  <A, B>(
201
201
  self: TxSubscriptionRef<A>,
202
202
  f: (current: A) => [returnValue: B, newValue: A]
203
- ): Effect.Effect<B, never, Effect.Transaction>
203
+ ): Effect.Effect<B>
204
204
  } = dual(
205
205
  2,
206
206
  <A, B>(
207
207
  self: TxSubscriptionRef<A>,
208
208
  f: (current: A) => [returnValue: B, newValue: A]
209
- ): Effect.Effect<B, never, Effect.Transaction> =>
209
+ ): Effect.Effect<B> =>
210
210
  Effect.gen(function*() {
211
211
  const current = yield* TxRef.get(self.ref)
212
212
  const [returnValue, newValue] = f(current)
213
213
  yield* TxRef.set(self.ref, newValue)
214
214
  yield* TxPubSub.publish(self.pubsub, newValue)
215
215
  return returnValue
216
- })
216
+ }).pipe(Effect.tx)
217
217
  )
218
218
 
219
219
  /**
@@ -251,7 +251,7 @@ export const set: {
251
251
  * @since 4.0.0
252
252
  * @category mutations
253
253
  */
254
- <A>(value: A): (self: TxSubscriptionRef<A>) => Effect.Effect<void, never, Effect.Transaction>
254
+ <A>(value: A): (self: TxSubscriptionRef<A>) => Effect.Effect<void>
255
255
  /**
256
256
  * Sets the value of the TxSubscriptionRef and publishes the new value to all subscribers.
257
257
  *
@@ -269,11 +269,10 @@ export const set: {
269
269
  * @since 4.0.0
270
270
  * @category mutations
271
271
  */
272
- <A>(self: TxSubscriptionRef<A>, value: A): Effect.Effect<void, never, Effect.Transaction>
272
+ <A>(self: TxSubscriptionRef<A>, value: A): Effect.Effect<void>
273
273
  } = dual(
274
274
  2,
275
- <A>(self: TxSubscriptionRef<A>, value: A): Effect.Effect<void, never, Effect.Transaction> =>
276
- modify(self, () => [void 0, value])
275
+ <A>(self: TxSubscriptionRef<A>, value: A): Effect.Effect<void> => modify(self, () => [void 0, value])
277
276
  )
278
277
 
279
278
  /**
@@ -313,7 +312,7 @@ export const update: {
313
312
  * @since 4.0.0
314
313
  * @category mutations
315
314
  */
316
- <A>(f: (current: A) => A): (self: TxSubscriptionRef<A>) => Effect.Effect<void, never, Effect.Transaction>
315
+ <A>(f: (current: A) => A): (self: TxSubscriptionRef<A>) => Effect.Effect<void>
317
316
  /**
318
317
  * Updates the value of the TxSubscriptionRef using a function and publishes the new
319
318
  * value to all subscribers.
@@ -332,10 +331,10 @@ export const update: {
332
331
  * @since 4.0.0
333
332
  * @category mutations
334
333
  */
335
- <A>(self: TxSubscriptionRef<A>, f: (current: A) => A): Effect.Effect<void, never, Effect.Transaction>
334
+ <A>(self: TxSubscriptionRef<A>, f: (current: A) => A): Effect.Effect<void>
336
335
  } = dual(
337
336
  2,
338
- <A>(self: TxSubscriptionRef<A>, f: (current: A) => A): Effect.Effect<void, never, Effect.Transaction> =>
337
+ <A>(self: TxSubscriptionRef<A>, f: (current: A) => A): Effect.Effect<void> =>
339
338
  modify(self, (current) => [void 0, f(current)])
340
339
  )
341
340
 
@@ -378,7 +377,7 @@ export const getAndSet: {
378
377
  * @since 4.0.0
379
378
  * @category mutations
380
379
  */
381
- <A>(value: A): (self: TxSubscriptionRef<A>) => Effect.Effect<A, never, Effect.Transaction>
380
+ <A>(value: A): (self: TxSubscriptionRef<A>) => Effect.Effect<A>
382
381
  /**
383
382
  * Gets the current value and sets a new value atomically. Publishes the new value
384
383
  * to all subscribers.
@@ -398,11 +397,10 @@ export const getAndSet: {
398
397
  * @since 4.0.0
399
398
  * @category mutations
400
399
  */
401
- <A>(self: TxSubscriptionRef<A>, value: A): Effect.Effect<A, never, Effect.Transaction>
400
+ <A>(self: TxSubscriptionRef<A>, value: A): Effect.Effect<A>
402
401
  } = dual(
403
402
  2,
404
- <A>(self: TxSubscriptionRef<A>, value: A): Effect.Effect<A, never, Effect.Transaction> =>
405
- modify(self, (current) => [current, value])
403
+ <A>(self: TxSubscriptionRef<A>, value: A): Effect.Effect<A> => modify(self, (current) => [current, value])
406
404
  )
407
405
 
408
406
  /**
@@ -444,7 +442,7 @@ export const getAndUpdate: {
444
442
  * @since 4.0.0
445
443
  * @category mutations
446
444
  */
447
- <A>(f: (current: A) => A): (self: TxSubscriptionRef<A>) => Effect.Effect<A, never, Effect.Transaction>
445
+ <A>(f: (current: A) => A): (self: TxSubscriptionRef<A>) => Effect.Effect<A>
448
446
  /**
449
447
  * Gets the current value and updates it using a function atomically. Publishes
450
448
  * the new value to all subscribers.
@@ -464,10 +462,10 @@ export const getAndUpdate: {
464
462
  * @since 4.0.0
465
463
  * @category mutations
466
464
  */
467
- <A>(self: TxSubscriptionRef<A>, f: (current: A) => A): Effect.Effect<A, never, Effect.Transaction>
465
+ <A>(self: TxSubscriptionRef<A>, f: (current: A) => A): Effect.Effect<A>
468
466
  } = dual(
469
467
  2,
470
- <A>(self: TxSubscriptionRef<A>, f: (current: A) => A): Effect.Effect<A, never, Effect.Transaction> =>
468
+ <A>(self: TxSubscriptionRef<A>, f: (current: A) => A): Effect.Effect<A> =>
471
469
  modify(self, (current) => [current, f(current)])
472
470
  )
473
471
 
@@ -508,7 +506,7 @@ export const updateAndGet: {
508
506
  * @since 4.0.0
509
507
  * @category mutations
510
508
  */
511
- <A>(f: (current: A) => A): (self: TxSubscriptionRef<A>) => Effect.Effect<A, never, Effect.Transaction>
509
+ <A>(f: (current: A) => A): (self: TxSubscriptionRef<A>) => Effect.Effect<A>
512
510
  /**
513
511
  * Updates the value using a function and returns the new value. Publishes the
514
512
  * new value to all subscribers.
@@ -527,10 +525,10 @@ export const updateAndGet: {
527
525
  * @since 4.0.0
528
526
  * @category mutations
529
527
  */
530
- <A>(self: TxSubscriptionRef<A>, f: (current: A) => A): Effect.Effect<A, never, Effect.Transaction>
528
+ <A>(self: TxSubscriptionRef<A>, f: (current: A) => A): Effect.Effect<A>
531
529
  } = dual(
532
530
  2,
533
- <A>(self: TxSubscriptionRef<A>, f: (current: A) => A): Effect.Effect<A, never, Effect.Transaction> =>
531
+ <A>(self: TxSubscriptionRef<A>, f: (current: A) => A): Effect.Effect<A> =>
534
532
  modify(self, (current) => {
535
533
  const newValue = f(current)
536
534
  return [newValue, newValue]
@@ -573,7 +571,7 @@ export const changes = <A>(
573
571
  self: TxSubscriptionRef<A>
574
572
  ): Effect.Effect<TxQueue.TxQueue<A>, never, Scope.Scope> =>
575
573
  Effect.acquireRelease(
576
- Effect.transaction(
574
+ Effect.tx(
577
575
  Effect.gen(function*() {
578
576
  const sub = yield* TxPubSub.acquireSubscriber(self.pubsub)
579
577
  const current = yield* TxRef.get(self.ref)
@@ -581,7 +579,7 @@ export const changes = <A>(
581
579
  return sub
582
580
  })
583
581
  ),
584
- (queue) => Effect.transaction(TxPubSub.releaseSubscriber(self.pubsub, queue))
582
+ (queue) => Effect.tx(TxPubSub.releaseSubscriber(self.pubsub, queue))
585
583
  )
586
584
 
587
585
  /**
@@ -611,7 +609,7 @@ export const changesStream = <A>(self: TxSubscriptionRef<A>): Stream.Stream<A, n
611
609
  Stream.unwrap(
612
610
  Effect.map(
613
611
  changes(self),
614
- (sub) => Stream.fromEffectRepeat(Effect.transaction(TxQueue.take(sub)))
612
+ (sub) => Stream.fromEffectRepeat(Effect.tx(TxQueue.take(sub)))
615
613
  )
616
614
  )
617
615
 
package/src/index.ts CHANGED
@@ -1086,7 +1086,7 @@ export * as Equal from "./Equal.ts"
1086
1086
  * - Using strict equality (`===`) → {@link strictEqual}
1087
1087
  * - Combining multiple equivalences (AND logic) → {@link combine}, {@link combineAll}
1088
1088
  * - Transforming input before comparison → {@link mapInput}
1089
- * - Creating equivalences for structured types → {@link Struct}, {@link Tuple}, {@link Array}, {@link Record}
1089
+ * - Creating equivalences for structured types → {@link Struct}, {@link Tuple}, {@link Array_}, {@link Record}
1090
1090
  *
1091
1091
  * ## Gotchas
1092
1092
  *
@@ -1114,7 +1114,7 @@ export * as Equal from "./Equal.ts"
1114
1114
  * ## See also
1115
1115
  *
1116
1116
  * - {@link Equal} - For structural equality (can convert to Equivalence)
1117
- * - {@link Array.dedupeWith} - Remove duplicates using an equivalence
1117
+ * - {@link Array_.dedupeWith} - Remove duplicates using an equivalence
1118
1118
  * - {@link Chunk} - Collections that use equivalences for operations
1119
1119
  *
1120
1120
  * @since 2.0.0
@@ -3270,7 +3270,7 @@ export * as Scheduler from "./Scheduler.ts"
3270
3270
  *
3271
3271
  * - Define a struct: {@link Struct}
3272
3272
  * - Define a union: {@link Union}, {@link TaggedUnion}, {@link Literals}
3273
- * - Define an array: {@link Array}, {@link NonEmptyArray}
3273
+ * - Define an array: {@link ArraySchema}, {@link NonEmptyArray}
3274
3274
  * - Define a record: {@link Record}
3275
3275
  * - Define a tuple: {@link Tuple}, {@link TupleWithRest}
3276
3276
  * - Validate unknown data synchronously: {@link decodeUnknownSync}
@@ -4039,7 +4039,7 @@ export * as Tuple from "./Tuple.ts"
4039
4039
  *
4040
4040
  * Accessed values are tracked by the transaction in order to detect conflicts and to track changes.
4041
4041
  * A transaction will retry whenever a conflict is detected or whenever the transaction explicitly
4042
- * calls `Effect.retryTransaction` and any of the accessed TxChunk values change.
4042
+ * calls `Effect.txRetry` and any of the accessed TxChunk values change.
4043
4043
  *
4044
4044
  * @since 4.0.0
4045
4045
  */
@@ -4089,7 +4089,7 @@ export * as TxPubSub from "./TxPubSub.ts"
4089
4089
  *
4090
4090
  * Accessed values are tracked by the transaction in order to detect conflicts and to track changes.
4091
4091
  * A transaction will retry whenever a conflict is detected or whenever the transaction explicitly
4092
- * calls `Effect.retryTransaction` and any of the accessed TxQueue values change.
4092
+ * calls `Effect.txRetry` and any of the accessed TxQueue values change.
4093
4093
  *
4094
4094
  * @since 4.0.0
4095
4095
  */
@@ -4110,7 +4110,7 @@ export * as TxReentrantLock from "./TxReentrantLock.ts"
4110
4110
  *
4111
4111
  * Accessed values are tracked by the transaction in order to detect conflicts and in order to
4112
4112
  * track changes, a transaction will retry whenever a conflict is detected or whenever the
4113
- * transaction explicitely calls to `Effect.retryTransaction` and any of the accessed TxRef values
4113
+ * transaction explicitely calls to `Effect.txRetry` and any of the accessed TxRef values
4114
4114
  * change.
4115
4115
  *
4116
4116
  * @since 4.0.0
@@ -5025,6 +5025,9 @@ export const runForkWith = <R>(services: ServiceMap.ServiceMap<R>) =>
5025
5025
  fiber.addObserver(() => options.signal!.removeEventListener("abort", abort))
5026
5026
  }
5027
5027
  }
5028
+ if (options?.onFiberStart) {
5029
+ options.onFiberStart(fiber)
5030
+ }
5028
5031
  return fiber
5029
5032
  }
5030
5033
 
@@ -527,11 +527,39 @@ export function toJsonSchemaMultiDocument(
527
527
  // anyOf MUST be a non-empty array
528
528
  return { not: {} }
529
529
  }
530
+ if (types.length > 1) {
531
+ const compacted = compactEnums(types)
532
+ if (compacted) return compacted
533
+ }
530
534
  return schema.mode === "anyOf" ? { anyOf: types } : { oneOf: types }
531
535
  }
532
536
  }
533
537
  }
534
538
 
539
+ // Collapses [{type:"string",enum:["a"]},{type:"string",enum:["b"]}] into {type:"string",enum:["a","b"]}.
540
+ // Returns undefined if members have different types, extra keys (e.g. title), or empty enums.
541
+ function compactEnums(
542
+ types: ReadonlyArray<JsonSchema.JsonSchema>
543
+ ): JsonSchema.JsonSchema | undefined {
544
+ let sharedType: string | undefined
545
+ const values: Array<unknown> = []
546
+ for (const t of types) {
547
+ const keys = Object.keys(t)
548
+ if (keys.length !== 2 || t.type === undefined || !Array.isArray(t.enum) || t.enum.length === 0) {
549
+ return undefined
550
+ }
551
+ if (sharedType === undefined) {
552
+ sharedType = t.type as string
553
+ } else if (t.type !== sharedType) {
554
+ return undefined
555
+ }
556
+ for (const v of t.enum) {
557
+ values.push(v)
558
+ }
559
+ }
560
+ return { type: sharedType, enum: values }
561
+ }
562
+
535
563
  function collectJsonSchemaAnnotations(
536
564
  annotations: Schema.Annotations.Annotations | undefined
537
565
  ): JsonSchema.JsonSchema | undefined {
@@ -64,6 +64,7 @@ import * as IdGenerator from "./IdGenerator.ts"
64
64
  import * as LanguageModel from "./LanguageModel.ts"
65
65
  import * as Prompt from "./Prompt.ts"
66
66
  import type * as Response from "./Response.ts"
67
+ import type * as Tool from "./Tool.ts"
67
68
 
68
69
  /**
69
70
  * The `Chat` service tag for dependency injection.
@@ -198,13 +199,43 @@ export interface Service {
198
199
  * })
199
200
  * ```
200
201
  */
201
- readonly generateText: <
202
- Options extends NoExcessProperties<LanguageModel.GenerateTextOptions<any>, Options>
203
- >(options: Options & LanguageModel.GenerateTextOptions<LanguageModel.ExtractTools<Options>>) => Effect.Effect<
204
- LanguageModel.GenerateTextResponse<LanguageModel.ExtractTools<Options>>,
205
- LanguageModel.ExtractError<Options>,
206
- LanguageModel.LanguageModel | LanguageModel.ExtractServices<Options>
207
- >
202
+ readonly generateText: {
203
+ <Options extends NoExcessProperties<LanguageModel.GenerateTextOptions<{}>, Options>>(
204
+ options: Options & { readonly toolkit?: undefined } & LanguageModel.GenerateTextOptions<{}>
205
+ ): Effect.Effect<
206
+ LanguageModel.GenerateTextResponse<{}>,
207
+ LanguageModel.ExtractError<Options>,
208
+ LanguageModel.LanguageModel | LanguageModel.ExtractServices<Options>
209
+ >
210
+ <
211
+ Tools extends Record<string, Tool.Any>,
212
+ Options extends NoExcessProperties<
213
+ LanguageModel.GenerateTextOptions<Tools> & { readonly toolkit: LanguageModel.ToolkitInput<Tools> },
214
+ Options
215
+ >
216
+ >(
217
+ options: Options & LanguageModel.GenerateTextOptions<Tools> & {
218
+ readonly toolkit: LanguageModel.ToolkitInput<Tools>
219
+ }
220
+ ): Effect.Effect<
221
+ LanguageModel.GenerateTextResponse<Tools>,
222
+ LanguageModel.ExtractError<Options>,
223
+ LanguageModel.LanguageModel | LanguageModel.ExtractServices<Options>
224
+ >
225
+ <
226
+ Options extends {
227
+ readonly toolkit: LanguageModel.ToolkitOption<any>
228
+ } & NoExcessProperties<LanguageModel.GenerateTextOptions<any>, Options>
229
+ >(
230
+ options: Options & LanguageModel.GenerateTextOptions<LanguageModel.ExtractTools<Options>> & {
231
+ readonly toolkit: Options["toolkit"]
232
+ }
233
+ ): Effect.Effect<
234
+ LanguageModel.GenerateTextResponse<LanguageModel.ExtractTools<Options>>,
235
+ LanguageModel.ExtractError<Options>,
236
+ LanguageModel.LanguageModel | LanguageModel.ExtractServices<Options>
237
+ >
238
+ }
208
239
 
209
240
  /**
210
241
  * Generate text using a language model with streaming output.
@@ -231,13 +262,43 @@ export interface Service {
231
262
  * })
232
263
  * ```
233
264
  */
234
- readonly streamText: <
235
- Options extends NoExcessProperties<LanguageModel.GenerateTextOptions<any>, Options>
236
- >(options: Options & LanguageModel.GenerateTextOptions<LanguageModel.ExtractTools<Options>>) => Stream.Stream<
237
- Response.StreamPart<LanguageModel.ExtractTools<Options>>,
238
- LanguageModel.ExtractError<Options>,
239
- LanguageModel.LanguageModel | LanguageModel.ExtractServices<Options>
240
- >
265
+ readonly streamText: {
266
+ <Options extends NoExcessProperties<LanguageModel.GenerateTextOptions<{}>, Options>>(
267
+ options: Options & { readonly toolkit?: undefined } & LanguageModel.GenerateTextOptions<{}>
268
+ ): Stream.Stream<
269
+ Response.StreamPart<{}>,
270
+ LanguageModel.ExtractError<Options>,
271
+ LanguageModel.LanguageModel | LanguageModel.ExtractServices<Options>
272
+ >
273
+ <
274
+ Tools extends Record<string, Tool.Any>,
275
+ Options extends NoExcessProperties<
276
+ LanguageModel.GenerateTextOptions<Tools> & { readonly toolkit: LanguageModel.ToolkitInput<Tools> },
277
+ Options
278
+ >
279
+ >(
280
+ options: Options & LanguageModel.GenerateTextOptions<Tools> & {
281
+ readonly toolkit: LanguageModel.ToolkitInput<Tools>
282
+ }
283
+ ): Stream.Stream<
284
+ Response.StreamPart<Tools>,
285
+ LanguageModel.ExtractError<Options>,
286
+ LanguageModel.LanguageModel | LanguageModel.ExtractServices<Options>
287
+ >
288
+ <
289
+ Options extends {
290
+ readonly toolkit: LanguageModel.ToolkitOption<any>
291
+ } & NoExcessProperties<LanguageModel.GenerateTextOptions<any>, Options>
292
+ >(
293
+ options: Options & LanguageModel.GenerateTextOptions<LanguageModel.ExtractTools<Options>> & {
294
+ readonly toolkit: Options["toolkit"]
295
+ }
296
+ ): Stream.Stream<
297
+ Response.StreamPart<LanguageModel.ExtractTools<Options>>,
298
+ LanguageModel.ExtractError<Options>,
299
+ LanguageModel.LanguageModel | LanguageModel.ExtractServices<Options>
300
+ >
301
+ }
241
302
 
242
303
  /**
243
304
  * Generate a structured object using a language model and schema.
@@ -334,7 +395,7 @@ const makeUnsafe = (history: Ref.Ref<Prompt.Prompt>) => {
334
395
  },
335
396
  semaphore.withPermits(1),
336
397
  (effect) => Effect.withSpan(effect, "Chat.generateText", { captureStackTrace: false })
337
- ),
398
+ ) as Service["generateText"],
338
399
  streamText: Effect.fnUntraced(
339
400
  function*(options) {
340
401
  let parts = Chunk.empty<Response.AnyPart>()
@@ -366,7 +427,7 @@ const makeUnsafe = (history: Ref.Ref<Prompt.Prompt>) => {
366
427
  )
367
428
  },
368
429
  Stream.unwrap
369
- ),
430
+ ) as Service["streamText"],
370
431
  generateObject: Effect.fnUntraced(
371
432
  function*(options) {
372
433
  const newPrompt = Prompt.make(options.prompt)
@@ -713,7 +774,7 @@ export const makePersisted = Effect.fnUntraced(function*(options: {
713
774
  return yield* chat.generateText(options).pipe(
714
775
  Effect.ensuring(Effect.orDie(saveChat(history)))
715
776
  )
716
- }),
777
+ }) as Service["generateText"],
717
778
  generateObject: Effect.fnUntraced(function*(options) {
718
779
  const history = yield* Ref.get(chat.history)
719
780
  return yield* chat.generateObject(options).pipe(
@@ -726,7 +787,7 @@ export const makePersisted = Effect.fnUntraced(function*(options: {
726
787
  Stream.ensuring(Effect.orDie(saveChat(history)))
727
788
  )
728
789
  return stream
729
- }, Stream.unwrap)
790
+ }, Stream.unwrap) as Service["streamText"]
730
791
  }
731
792
 
732
793
  return persisted