effect 4.0.0-beta.27 → 4.0.0-beta.29

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 (208) hide show
  1. package/dist/Brand.d.ts +1 -1
  2. package/dist/Brand.d.ts.map +1 -1
  3. package/dist/Brand.js +1 -1
  4. package/dist/Brand.js.map +1 -1
  5. package/dist/ConfigProvider.d.ts +1 -1
  6. package/dist/Cron.d.ts +1 -1
  7. package/dist/Data.d.ts +1 -1
  8. package/dist/Data.d.ts.map +1 -1
  9. package/dist/Data.js.map +1 -1
  10. package/dist/Effect.d.ts +300 -184
  11. package/dist/Effect.d.ts.map +1 -1
  12. package/dist/Effect.js +99 -61
  13. package/dist/Effect.js.map +1 -1
  14. package/dist/Encoding.d.ts +1 -1
  15. package/dist/Exit.d.ts +24 -12
  16. package/dist/Exit.d.ts.map +1 -1
  17. package/dist/Exit.js +8 -4
  18. package/dist/Exit.js.map +1 -1
  19. package/dist/Fiber.d.ts +1 -0
  20. package/dist/Fiber.d.ts.map +1 -1
  21. package/dist/Fiber.js.map +1 -1
  22. package/dist/Function.d.ts +1 -9
  23. package/dist/Function.d.ts.map +1 -1
  24. package/dist/Function.js +2 -10
  25. package/dist/Function.js.map +1 -1
  26. package/dist/Graph.d.ts +1 -1
  27. package/dist/Newtype.d.ts +291 -0
  28. package/dist/Newtype.d.ts.map +1 -0
  29. package/dist/Newtype.js +161 -0
  30. package/dist/Newtype.js.map +1 -0
  31. package/dist/PlatformError.d.ts +2 -2
  32. package/dist/References.d.ts +6 -1
  33. package/dist/References.d.ts.map +1 -1
  34. package/dist/References.js +6 -1
  35. package/dist/References.js.map +1 -1
  36. package/dist/RequestResolver.d.ts +19 -19
  37. package/dist/RequestResolver.js +10 -10
  38. package/dist/RequestResolver.js.map +1 -1
  39. package/dist/Schedule.d.ts +142 -80
  40. package/dist/Schedule.d.ts.map +1 -1
  41. package/dist/Schedule.js +58 -32
  42. package/dist/Schedule.js.map +1 -1
  43. package/dist/Scheduler.d.ts +9 -0
  44. package/dist/Scheduler.d.ts.map +1 -1
  45. package/dist/Scheduler.js +11 -0
  46. package/dist/Scheduler.js.map +1 -1
  47. package/dist/Schema.d.ts +1 -1
  48. package/dist/Schema.d.ts.map +1 -1
  49. package/dist/Schema.js +3 -1
  50. package/dist/Schema.js.map +1 -1
  51. package/dist/SchemaAST.d.ts.map +1 -1
  52. package/dist/SchemaAST.js +1 -1
  53. package/dist/SchemaAST.js.map +1 -1
  54. package/dist/Stdio.d.ts +6 -2
  55. package/dist/Stdio.d.ts.map +1 -1
  56. package/dist/Stdio.js +2 -2
  57. package/dist/Stdio.js.map +1 -1
  58. package/dist/Stream.d.ts +8 -4
  59. package/dist/Stream.d.ts.map +1 -1
  60. package/dist/Stream.js +8 -4
  61. package/dist/Stream.js.map +1 -1
  62. package/dist/Types.d.ts +1 -22
  63. package/dist/Types.d.ts.map +1 -1
  64. package/dist/index.d.ts +71 -3
  65. package/dist/index.d.ts.map +1 -1
  66. package/dist/index.js +71 -3
  67. package/dist/index.js.map +1 -1
  68. package/dist/internal/effect.js +3 -1
  69. package/dist/internal/effect.js.map +1 -1
  70. package/dist/unstable/ai/LanguageModel.d.ts +12 -28
  71. package/dist/unstable/ai/LanguageModel.d.ts.map +1 -1
  72. package/dist/unstable/ai/LanguageModel.js +4 -18
  73. package/dist/unstable/ai/LanguageModel.js.map +1 -1
  74. package/dist/unstable/ai/McpSchema.d.ts +20 -1
  75. package/dist/unstable/ai/McpSchema.d.ts.map +1 -1
  76. package/dist/unstable/ai/McpSchema.js +8 -0
  77. package/dist/unstable/ai/McpSchema.js.map +1 -1
  78. package/dist/unstable/ai/McpServer.d.ts +65 -12
  79. package/dist/unstable/ai/McpServer.d.ts.map +1 -1
  80. package/dist/unstable/ai/McpServer.js +159 -45
  81. package/dist/unstable/ai/McpServer.js.map +1 -1
  82. package/dist/unstable/ai/Toolkit.d.ts +1 -1
  83. package/dist/unstable/ai/Toolkit.d.ts.map +1 -1
  84. package/dist/unstable/ai/Toolkit.js +4 -11
  85. package/dist/unstable/ai/Toolkit.js.map +1 -1
  86. package/dist/unstable/ai/internal/codec-transformer.js +0 -5
  87. package/dist/unstable/ai/internal/codec-transformer.js.map +1 -1
  88. package/dist/unstable/cli/Prompt.js +35 -8
  89. package/dist/unstable/cli/Prompt.js.map +1 -1
  90. package/dist/unstable/cluster/Message.d.ts +5 -5
  91. package/dist/unstable/cluster/Reply.d.ts +3 -3
  92. package/dist/unstable/encoding/Msgpack.d.ts +1 -1
  93. package/dist/unstable/encoding/Ndjson.d.ts +1 -1
  94. package/dist/unstable/encoding/Sse.d.ts +1 -1
  95. package/dist/unstable/eventlog/EventJournal.d.ts +1 -1
  96. package/dist/unstable/eventlog/EventLogRemote.d.ts +1 -1
  97. package/dist/unstable/http/Cookies.d.ts +45 -1
  98. package/dist/unstable/http/Cookies.d.ts.map +1 -1
  99. package/dist/unstable/http/Cookies.js +22 -0
  100. package/dist/unstable/http/Cookies.js.map +1 -1
  101. package/dist/unstable/http/HttpBody.d.ts +1 -1
  102. package/dist/unstable/http/HttpClient.d.ts.map +1 -1
  103. package/dist/unstable/http/HttpClient.js +3 -7
  104. package/dist/unstable/http/HttpClient.js.map +1 -1
  105. package/dist/unstable/http/HttpClientError.d.ts +7 -7
  106. package/dist/unstable/http/HttpClientRequest.d.ts +5 -0
  107. package/dist/unstable/http/HttpClientRequest.d.ts.map +1 -1
  108. package/dist/unstable/http/HttpClientRequest.js +21 -17
  109. package/dist/unstable/http/HttpClientRequest.js.map +1 -1
  110. package/dist/unstable/http/HttpEffect.d.ts +7 -0
  111. package/dist/unstable/http/HttpEffect.d.ts.map +1 -1
  112. package/dist/unstable/http/HttpEffect.js +6 -0
  113. package/dist/unstable/http/HttpEffect.js.map +1 -1
  114. package/dist/unstable/http/HttpServerError.d.ts +6 -6
  115. package/dist/unstable/http/HttpServerRequest.d.ts +11 -0
  116. package/dist/unstable/http/HttpServerRequest.d.ts.map +1 -1
  117. package/dist/unstable/http/HttpServerRequest.js +291 -1
  118. package/dist/unstable/http/HttpServerRequest.js.map +1 -1
  119. package/dist/unstable/http/HttpServerResponse.d.ts +47 -1
  120. package/dist/unstable/http/HttpServerResponse.d.ts.map +1 -1
  121. package/dist/unstable/http/HttpServerResponse.js +227 -0
  122. package/dist/unstable/http/HttpServerResponse.js.map +1 -1
  123. package/dist/unstable/http/HttpStaticServer.d.ts +69 -0
  124. package/dist/unstable/http/HttpStaticServer.d.ts.map +1 -0
  125. package/dist/unstable/http/HttpStaticServer.js +353 -0
  126. package/dist/unstable/http/HttpStaticServer.js.map +1 -0
  127. package/dist/unstable/http/Multipart.d.ts +1 -1
  128. package/dist/unstable/http/UrlParams.d.ts +1 -1
  129. package/dist/unstable/http/index.d.ts +4 -0
  130. package/dist/unstable/http/index.d.ts.map +1 -1
  131. package/dist/unstable/http/index.js +4 -0
  132. package/dist/unstable/http/index.js.map +1 -1
  133. package/dist/unstable/httpapi/HttpApiGroup.d.ts +1 -0
  134. package/dist/unstable/httpapi/HttpApiGroup.d.ts.map +1 -1
  135. package/dist/unstable/httpapi/HttpApiGroup.js.map +1 -1
  136. package/dist/unstable/persistence/KeyValueStore.d.ts +1 -1
  137. package/dist/unstable/reactivity/Atom.d.ts +7 -2
  138. package/dist/unstable/reactivity/Atom.d.ts.map +1 -1
  139. package/dist/unstable/reactivity/Atom.js +33 -15
  140. package/dist/unstable/reactivity/Atom.js.map +1 -1
  141. package/dist/unstable/reactivity/AtomHttpApi.d.ts +4 -6
  142. package/dist/unstable/reactivity/AtomHttpApi.d.ts.map +1 -1
  143. package/dist/unstable/reactivity/AtomHttpApi.js +39 -9
  144. package/dist/unstable/reactivity/AtomHttpApi.js.map +1 -1
  145. package/dist/unstable/reactivity/AtomRegistry.js +26 -2
  146. package/dist/unstable/reactivity/AtomRegistry.js.map +1 -1
  147. package/dist/unstable/reactivity/AtomRpc.d.ts +8 -8
  148. package/dist/unstable/reactivity/AtomRpc.d.ts.map +1 -1
  149. package/dist/unstable/reactivity/AtomRpc.js +46 -20
  150. package/dist/unstable/reactivity/AtomRpc.js.map +1 -1
  151. package/dist/unstable/rpc/Rpc.d.ts +1 -1
  152. package/dist/unstable/rpc/Rpc.d.ts.map +1 -1
  153. package/dist/unstable/rpc/Rpc.js.map +1 -1
  154. package/dist/unstable/rpc/RpcMiddleware.d.ts +5 -5
  155. package/dist/unstable/rpc/RpcMiddleware.d.ts.map +1 -1
  156. package/dist/unstable/rpc/RpcMiddleware.js.map +1 -1
  157. package/dist/unstable/rpc/RpcServer.js +2 -2
  158. package/dist/unstable/rpc/RpcServer.js.map +1 -1
  159. package/dist/unstable/rpc/Utils.js +1 -1
  160. package/dist/unstable/rpc/Utils.js.map +1 -1
  161. package/dist/unstable/socket/SocketServer.d.ts +3 -3
  162. package/dist/unstable/sql/Migrator.d.ts +1 -1
  163. package/dist/unstable/sql/SqlResolver.js +2 -2
  164. package/dist/unstable/sql/SqlResolver.js.map +1 -1
  165. package/dist/unstable/workflow/Workflow.d.ts +1 -1
  166. package/package.json +1 -1
  167. package/src/Brand.ts +1 -1
  168. package/src/Data.ts +1 -2
  169. package/src/Effect.ts +300 -184
  170. package/src/Exit.ts +24 -12
  171. package/src/Fiber.ts +1 -0
  172. package/src/Function.ts +2 -10
  173. package/src/Newtype.ts +308 -0
  174. package/src/References.ts +6 -1
  175. package/src/RequestResolver.ts +20 -20
  176. package/src/Schedule.ts +142 -80
  177. package/src/Scheduler.ts +12 -0
  178. package/src/Schema.ts +4 -2
  179. package/src/SchemaAST.ts +1 -4
  180. package/src/Stdio.ts +8 -4
  181. package/src/Stream.ts +8 -4
  182. package/src/Types.ts +1 -23
  183. package/src/index.ts +72 -3
  184. package/src/internal/effect.ts +3 -0
  185. package/src/unstable/ai/LanguageModel.ts +16 -37
  186. package/src/unstable/ai/McpSchema.ts +14 -0
  187. package/src/unstable/ai/McpServer.ts +224 -53
  188. package/src/unstable/ai/Toolkit.ts +5 -14
  189. package/src/unstable/ai/internal/codec-transformer.ts +0 -7
  190. package/src/unstable/cli/Prompt.ts +31 -9
  191. package/src/unstable/http/Cookies.ts +84 -0
  192. package/src/unstable/http/HttpClient.ts +5 -6
  193. package/src/unstable/http/HttpClientRequest.ts +21 -17
  194. package/src/unstable/http/HttpEffect.ts +8 -0
  195. package/src/unstable/http/HttpServerRequest.ts +388 -1
  196. package/src/unstable/http/HttpServerResponse.ts +328 -1
  197. package/src/unstable/http/HttpStaticServer.ts +456 -0
  198. package/src/unstable/http/index.ts +5 -0
  199. package/src/unstable/httpapi/HttpApiGroup.ts +1 -0
  200. package/src/unstable/reactivity/Atom.ts +62 -35
  201. package/src/unstable/reactivity/AtomHttpApi.ts +45 -11
  202. package/src/unstable/reactivity/AtomRegistry.ts +30 -2
  203. package/src/unstable/reactivity/AtomRpc.ts +48 -17
  204. package/src/unstable/rpc/Rpc.ts +1 -3
  205. package/src/unstable/rpc/RpcMiddleware.ts +12 -6
  206. package/src/unstable/rpc/RpcServer.ts +2 -2
  207. package/src/unstable/rpc/Utils.ts +1 -1
  208. package/src/unstable/sql/SqlResolver.ts +2 -2
package/src/Scheduler.ts CHANGED
@@ -280,3 +280,15 @@ export class MixedScheduler implements Scheduler {
280
280
  export const MaxOpsBeforeYield = ServiceMap.Reference<number>("effect/Scheduler/MaxOpsBeforeYield", {
281
281
  defaultValue: () => 2048
282
282
  })
283
+
284
+ /**
285
+ * A service reference that controls whether the runtime should bypass scheduler
286
+ * yield checks. When set to `true`, the fiber run loop won't call
287
+ * `Scheduler.shouldYield`.
288
+ *
289
+ * @since 4.0.0
290
+ * @category references
291
+ */
292
+ export const PreventSchedulerYield = ServiceMap.Reference<boolean>("effect/Scheduler/PreventSchedulerYield", {
293
+ defaultValue: () => false
294
+ })
package/src/Schema.ts CHANGED
@@ -3590,7 +3590,7 @@ const getUUIDRegExp = (version?: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8): globalThis.RegE
3590
3590
  * @category String checks
3591
3591
  * @since 4.0.0
3592
3592
  */
3593
- export function isUUID(version: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | undefined, annotations?: Annotations.Filter) {
3593
+ export function isUUID(version?: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8, annotations?: Annotations.Filter) {
3594
3594
  const regExp = getUUIDRegExp(version)
3595
3595
  return isPattern(
3596
3596
  regExp,
@@ -8348,7 +8348,9 @@ export const ErrorClass: {
8348
8348
  annotations?: Annotations.Declaration<Self, readonly [Struct<Struct.Fields>]>
8349
8349
  ): ErrorClass<Self, Struct<Struct.Fields>, Cause_.YieldableError & Brand> => {
8350
8350
  const struct = isStruct(schema) ? schema : Struct(schema)
8351
- return makeClass(core.Error, identifier, struct, annotations)
8351
+ const self = makeClass(core.Error, identifier, struct, annotations)
8352
+ ;(self.prototype as any).name = identifier
8353
+ return self
8352
8354
  }
8353
8355
 
8354
8356
  /**
package/src/SchemaAST.ts CHANGED
@@ -3206,10 +3206,7 @@ export const bigIntString = appendChecks(string, [isStringBigInt()])
3206
3206
 
3207
3207
  const bigIntToString = new Link(
3208
3208
  bigIntString,
3209
- new Transformation.Transformation(
3210
- Getter.transform(globalThis.BigInt),
3211
- Getter.String()
3212
- )
3209
+ Transformation.bigintFromString
3213
3210
  )
3214
3211
 
3215
3212
  const REGEXP_PATTERN = "Symbol\\((.*)\\)"
package/src/Stdio.ts CHANGED
@@ -27,8 +27,12 @@ export const TypeId: TypeId = "~effect/Stdio"
27
27
  export interface Stdio {
28
28
  readonly [TypeId]: TypeId
29
29
  readonly args: Effect.Effect<ReadonlyArray<string>>
30
- readonly stdout: Sink.Sink<void, string | Uint8Array, never, PlatformError>
31
- readonly stderr: Sink.Sink<void, string | Uint8Array, never, PlatformError>
30
+ stdout(options?: {
31
+ readonly endOnDone?: boolean | undefined
32
+ }): Sink.Sink<void, string | Uint8Array, never, PlatformError>
33
+ stderr(options?: {
34
+ readonly endOnDone?: boolean | undefined
35
+ }): Sink.Sink<void, string | Uint8Array, never, PlatformError>
32
36
  readonly stdin: Stream.Stream<Uint8Array, PlatformError>
33
37
  }
34
38
  /**
@@ -55,8 +59,8 @@ export const layerTest = (impl: Partial<Stdio>): Layer.Layer<Stdio> =>
55
59
  Stdio,
56
60
  make({
57
61
  args: Effect.succeed([]),
58
- stdout: Sink.drain,
59
- stderr: Sink.drain,
62
+ stdout: () => Sink.drain,
63
+ stderr: () => Sink.drain,
60
64
  stdin: Stream.empty,
61
65
  ...impl
62
66
  })
package/src/Stream.ts CHANGED
@@ -1254,7 +1254,9 @@ export const fromPubSubTake = <A, E>(pubsub: PubSub.PubSub<Take.Take<A, E>>): St
1254
1254
  *
1255
1255
  * @example
1256
1256
  * ```ts
1257
- * import { Console, Effect, Stream } from "effect"
1257
+ * import { Console, Data, Effect, Stream } from "effect"
1258
+ *
1259
+ * class StreamError extends Data.TaggedError("StreamError")<{ readonly cause: unknown }> {}
1258
1260
  *
1259
1261
  * const readableStream = new ReadableStream({
1260
1262
  * start(controller) {
@@ -1268,7 +1270,7 @@ export const fromPubSubTake = <A, E>(pubsub: PubSub.PubSub<Take.Take<A, E>>): St
1268
1270
  * const program = Effect.gen(function*() {
1269
1271
  * const stream = Stream.fromReadableStream({
1270
1272
  * evaluate: () => readableStream,
1271
- * onError: (error) => new Error(String(error))
1273
+ * onError: (cause) => new StreamError({ cause })
1272
1274
  * })
1273
1275
  * const values = yield* Stream.runCollect(stream)
1274
1276
  * yield* Console.log(values)
@@ -1310,7 +1312,9 @@ export const fromReadableStream = <A, E>(
1310
1312
  *
1311
1313
  * @example
1312
1314
  * ```ts
1313
- * import { Console, Effect, Stream } from "effect"
1315
+ * import { Console, Data, Effect, Stream } from "effect"
1316
+ *
1317
+ * class StreamError extends Data.TaggedError("StreamError")<{ readonly cause: unknown }> {}
1314
1318
  *
1315
1319
  * const iterable = (async function*() {
1316
1320
  * yield 1
@@ -1319,7 +1323,7 @@ export const fromReadableStream = <A, E>(
1319
1323
  * })()
1320
1324
  *
1321
1325
  * const program = Effect.gen(function*() {
1322
- * const stream = Stream.fromAsyncIterable(iterable, (error) => new Error(String(error)))
1326
+ * const stream = Stream.fromAsyncIterable(iterable, (cause) => new StreamError({ cause }))
1323
1327
  * const values = yield* Stream.runCollect(stream)
1324
1328
  * yield* Console.log(values)
1325
1329
  * })
package/src/Types.ts CHANGED
@@ -707,28 +707,6 @@ export declare namespace Contravariant {
707
707
  export type Type<A> = A extends Contravariant<infer U> ? U : never
708
708
  }
709
709
 
710
- /**
711
- * Conditional type that checks if `S` is an empty object type.
712
- *
713
- * - Returns `onTrue` if `S` matches `{}` (i.e., has no required properties).
714
- * - Returns `onFalse` otherwise.
715
- * - Useful for branching type-level logic based on whether a service/context
716
- * type has requirements.
717
- *
718
- * **Example** (Branching on empty record)
719
- *
720
- * ```ts
721
- * import type { Types } from "effect"
722
- *
723
- * type A = Types.MatchRecord<{}, "empty", "not empty"> // "empty"
724
- * type B = Types.MatchRecord<{ a: number }, "empty", "not empty"> // "not empty"
725
- * ```
726
- *
727
- * @since 2.0.0
728
- * @category types
729
- */
730
- export type MatchRecord<S, onTrue, onFalse> = {} extends S ? onTrue : onFalse
731
-
732
710
  /**
733
711
  * Conditional type that returns `void` if `S` is an empty object type,
734
712
  * otherwise returns `S`.
@@ -736,7 +714,7 @@ export type MatchRecord<S, onTrue, onFalse> = {} extends S ? onTrue : onFalse
736
714
  * @since 4.0.0
737
715
  * @category types
738
716
  */
739
- export type VoidIfEmpty<S> = MatchRecord<S, void, S>
717
+ export type VoidIfEmpty<S> = keyof S extends never ? void : S
740
718
 
741
719
  /**
742
720
  * Excludes function types from a union, keeping only non-function members.
package/src/index.ts CHANGED
@@ -10,7 +10,7 @@ export {
10
10
  /**
11
11
  * @since 2.0.0
12
12
  */
13
- coerceUnsafe,
13
+ cast,
14
14
  /**
15
15
  * @since 2.0.0
16
16
  */
@@ -956,12 +956,14 @@ export * as Duration from "./Duration.ts"
956
956
  *
957
957
  * @example
958
958
  * ```ts
959
- * import { Effect } from "effect"
959
+ * import { Data, Effect } from "effect"
960
+ *
961
+ * class DiscountRateError extends Data.TaggedError("DiscountRateError")<{}> {}
960
962
  *
961
963
  * // Effect that may fail
962
964
  * const divide = (a: number, b: number) =>
963
965
  * b === 0
964
- * ? Effect.fail(new Error("Division by zero"))
966
+ * ? Effect.fail(new DiscountRateError())
965
967
  * : Effect.succeed(a / b)
966
968
  *
967
969
  * // Error handling
@@ -2312,6 +2314,73 @@ export * as MutableList from "./MutableList.ts"
2312
2314
  */
2313
2315
  export * as MutableRef from "./MutableRef.ts"
2314
2316
 
2317
+ /**
2318
+ * Lightweight wrapper types that prevent accidental mixing of structurally
2319
+ * identical values (e.g. `UserId` vs `OrderId`, both `string` at runtime).
2320
+ *
2321
+ * **Mental model**
2322
+ *
2323
+ * - **Newtype** — a compile-time wrapper around a **carrier** type (the
2324
+ * underlying primitive or object). At runtime the value is unchanged; the
2325
+ * tag exists only in the type system.
2326
+ * - **Key** — a unique string literal that distinguishes one newtype from
2327
+ * another (e.g. `"Label"`, `"UserId"`).
2328
+ * - **Carrier** — the underlying type the newtype wraps (e.g. `string`,
2329
+ * `number`).
2330
+ * - **Iso** — a lossless two-way conversion between a newtype and its carrier,
2331
+ * created with {@link makeIso}. Use `iso.set(carrier)` to wrap and
2332
+ * `iso.get(newtype)` to unwrap.
2333
+ *
2334
+ * **Common tasks**
2335
+ *
2336
+ * - Define a newtype → declare an `interface` extending
2337
+ * `Newtype.Newtype<Key, Carrier>`
2338
+ * - Wrap / unwrap values → {@link makeIso} (returns an `Optic.Iso`)
2339
+ * - Unwrap only → {@link value}
2340
+ * - Lift an `Equivalence` → {@link makeEquivalence}
2341
+ * - Lift an `Order` → {@link makeOrder}
2342
+ * - Lift a `Combiner` → {@link makeCombiner}
2343
+ * - Lift a `Reducer` → {@link makeReducer}
2344
+ *
2345
+ * **Gotchas**
2346
+ *
2347
+ * - Newtypes are **purely compile-time**. There is zero runtime overhead;
2348
+ * `value` and `makeIso` use identity casts.
2349
+ * - Two newtypes sharing the same key string will be assignable to each other.
2350
+ * Choose unique key strings.
2351
+ * - A newtype value is **not** assignable to its carrier type without
2352
+ * explicitly unwrapping via {@link value} or an iso.
2353
+ *
2354
+ * **Quickstart**
2355
+ *
2356
+ * **Example** (defining and using a newtype)
2357
+ *
2358
+ * ```ts
2359
+ * import { Newtype } from "effect"
2360
+ *
2361
+ * // 1. Define a newtype
2362
+ * interface Label extends Newtype.Newtype<"Label", string> {}
2363
+ *
2364
+ * // 2. Create an iso for wrapping/unwrapping
2365
+ * const labelIso = Newtype.makeIso<Label>()
2366
+ *
2367
+ * // 3. Wrap a raw string
2368
+ * const myLabel: Label = labelIso.set("hello")
2369
+ *
2370
+ * // 4. Unwrap back to string
2371
+ * const raw: string = labelIso.get(myLabel) // "hello"
2372
+ * ```
2373
+ *
2374
+ * **See also**
2375
+ *
2376
+ * - {@link Newtype} (the tagged interface)
2377
+ * - {@link makeIso} (wrap and unwrap)
2378
+ * - {@link value} (unwrap only)
2379
+ *
2380
+ * @since 4.0.0
2381
+ */
2382
+ export * as Newtype from "./Newtype.ts"
2383
+
2315
2384
  /**
2316
2385
  * @since 2.0.0
2317
2386
  *
@@ -537,6 +537,7 @@ export class FiberImpl<A = any, E = any> implements Fiber.Fiber<A, E> {
537
537
  currentStackFrame: StackFrame | undefined
538
538
  runtimeMetrics: Metric.FiberRuntimeMetricsService | undefined
539
539
  maxOpsBeforeYield!: number
540
+ currentPreventYield!: boolean
540
541
 
541
542
  getRef<X>(ref: ServiceMap.Reference<X>): X {
542
543
  return ServiceMap.getReferenceUnsafe(this.services, ref)
@@ -615,6 +616,7 @@ export class FiberImpl<A = any, E = any> implements Fiber.Fiber<A, E> {
615
616
  this.currentOpCount++
616
617
  if (
617
618
  !yielding &&
619
+ !this.currentPreventYield &&
618
620
  this.currentScheduler.shouldYield(this as any)
619
621
  ) {
620
622
  yielding = true
@@ -678,6 +680,7 @@ export class FiberImpl<A = any, E = any> implements Fiber.Fiber<A, E> {
678
680
  this.minimumLogLevel = this.getRef(MinimumLogLevel)
679
681
  this.currentStackFrame = services.mapUnsafe.get(CurrentStackFrame.key)
680
682
  this.maxOpsBeforeYield = this.getRef(Scheduler.MaxOpsBeforeYield)
683
+ this.currentPreventYield = this.getRef(Scheduler.PreventSchedulerYield)
681
684
  this.runtimeMetrics = services.mapUnsafe.get(InternalMetric.FiberRuntimeMetricsKey)
682
685
  const currentTracer = services.mapUnsafe.get(Tracer.TracerKey)
683
686
  this.currentTracerContext = currentTracer ? currentTracer["context"] : undefined
@@ -180,22 +180,6 @@ export type CodecTransformer = <T, E, RD, RE>(schema: Schema.Codec<T, E, RD, RE>
180
180
  readonly jsonSchema: JsonSchema.JsonSchema
181
181
  }
182
182
 
183
- /**
184
- * A `ServiceMap.Reference` that holds the current `CodecTransformer` used by
185
- * `LanguageModel.generateObject` to adapt structured output schemas for the
186
- * active provider.
187
- *
188
- * By default, this is the identity function (no transformation). Provider
189
- * packages (e.g. `@effect/ai-anthropic`) override this reference with a
190
- * provider-specific transformer so that schemas are automatically rewritten
191
- * before being sent to the model as well as before decoding the generated value.
192
- *
193
- * @since 4.0.0
194
- * @category services
195
- */
196
- export const CurrentCodecTransformer: ServiceMap.Reference<CodecTransformer> =
197
- InternalCodecTransformer.CurrentCodecTransformer
198
-
199
183
  /**
200
184
  * The default codec transformer that passes schemas through without
201
185
  * provider-specific rewrites.
@@ -625,12 +609,15 @@ export interface ProviderOptions {
625
609
  }
626
610
 
627
611
  /**
628
- * Parameters required to construct a LanguageModel service.
612
+ * Creates a LanguageModel service from provider-specific implementations.
613
+ *
614
+ * This constructor takes provider-specific implementations for text generation
615
+ * and streaming text generation and returns a LanguageModel service.
629
616
  *
630
617
  * @since 4.0.0
631
- * @category models
618
+ * @category constructors
632
619
  */
633
- export interface ConstructorParams {
620
+ export const make: (params: {
634
621
  /**
635
622
  * A method which requests text generation from the large language model
636
623
  * provider.
@@ -651,19 +638,14 @@ export interface ConstructorParams {
651
638
  readonly streamText: (
652
639
  options: ProviderOptions
653
640
  ) => Stream.Stream<Response.StreamPartEncoded, AiError.AiError, IdGenerator>
654
- }
655
641
 
656
- /**
657
- * Creates a LanguageModel service from provider-specific implementations.
658
- *
659
- * This constructor takes provider-specific implementations for text generation
660
- * and streaming text generation and returns a LanguageModel service.
661
- *
662
- * @since 4.0.0
663
- * @category constructors
664
- */
665
- export const make: (params: ConstructorParams) => Effect.Effect<Service> = Effect.fnUntraced(function*(params) {
666
- const codecTransformer = yield* InternalCodecTransformer.CurrentCodecTransformer
642
+ /**
643
+ * A function that transforms a `Schema.Codec` into a provider-compatible form
644
+ * for structured output generation.
645
+ */
646
+ readonly codecTransformer?: CodecTransformer | undefined
647
+ }) => Effect.Effect<Service> = Effect.fnUntraced(function*(params) {
648
+ const codecTransformer = params.codecTransformer ?? defaultCodecTransformer
667
649
 
668
650
  const parentSpanTransformer = yield* Effect.serviceOption(
669
651
  CurrentSpanTransformer
@@ -724,8 +706,7 @@ export const make: (params: ConstructorParams) => Effect.Effect<Service> = Effec
724
706
  })
725
707
  )),
726
708
  (effect, span) => Effect.withParentSpan(effect, span, { captureStackTrace: false }),
727
- Effect.provideService(IdGenerator, idGenerator),
728
- Effect.provideService(InternalCodecTransformer.CurrentCodecTransformer, codecTransformer)
709
+ Effect.provideService(IdGenerator, idGenerator)
729
710
  )
730
711
  ) as any
731
712
 
@@ -803,8 +784,7 @@ export const make: (params: ConstructorParams) => Effect.Effect<Service> = Effec
803
784
  })
804
785
  )),
805
786
  (effect, span) => Effect.withParentSpan(effect, span, { captureStackTrace: false }),
806
- Effect.provideService(IdGenerator, idGenerator),
807
- Effect.provideService(InternalCodecTransformer.CurrentCodecTransformer, codecTransformer)
787
+ Effect.provideService(IdGenerator, idGenerator)
808
788
  )
809
789
  ) as any
810
790
  }
@@ -875,8 +855,7 @@ export const make: (params: ConstructorParams) => Effect.Effect<Service> = Effec
875
855
  })
876
856
  : error
877
857
  ),
878
- Stream.provideService(IdGenerator, idGenerator),
879
- Stream.provideService(InternalCodecTransformer.CurrentCodecTransformer, codecTransformer)
858
+ Stream.provideService(IdGenerator, idGenerator)
880
859
  ) as any
881
860
 
882
861
  const generateContent: <
@@ -1842,6 +1842,7 @@ export class ElicitationDeclined
1842
1842
  */
1843
1843
  export class McpServerClient extends ServiceMap.Service<McpServerClient, {
1844
1844
  readonly clientId: number
1845
+ readonly initializePayload: typeof Initialize.payloadSchema["Type"]
1845
1846
  readonly getClient: Effect.Effect<
1846
1847
  RpcClient.RpcClient<RpcGroup.Rpcs<typeof ServerRequestRpcs>, RpcClientError>,
1847
1848
  never,
@@ -2121,3 +2122,16 @@ export function param<const Name extends string, S extends Schema.Top>(
2121
2122
  ): Param<Name, S> {
2122
2123
  return Schema.make(schema.ast, { [ParamSchemaTypeId]: ParamSchemaTypeId, name, schema })
2123
2124
  }
2125
+
2126
+ /**
2127
+ * Annotation to conditionally enable or disable tools based on client
2128
+ * information.
2129
+ *
2130
+ * @since 4.0.0
2131
+ * @category annotations
2132
+ */
2133
+ export class EnabledWhen
2134
+ extends ServiceMap.Service<EnabledWhen, Predicate.Predicate<typeof Initialize.payloadSchema.Type>>()(
2135
+ "effect/unstable/ai/McpSchema/EnabledWhen"
2136
+ )
2137
+ {}