effect 4.0.0-beta.33 → 4.0.0-beta.35

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 (132) hide show
  1. package/dist/Channel.d.ts +10 -1
  2. package/dist/Channel.d.ts.map +1 -1
  3. package/dist/Channel.js +5 -1
  4. package/dist/Channel.js.map +1 -1
  5. package/dist/Config.d.ts +4 -0
  6. package/dist/Config.d.ts.map +1 -1
  7. package/dist/Config.js.map +1 -1
  8. package/dist/Effect.d.ts +5 -3
  9. package/dist/Effect.d.ts.map +1 -1
  10. package/dist/Effect.js +4 -4
  11. package/dist/Effect.js.map +1 -1
  12. package/dist/FileSystem.d.ts.map +1 -1
  13. package/dist/FileSystem.js +2 -1
  14. package/dist/FileSystem.js.map +1 -1
  15. package/dist/Graph.d.ts.map +1 -1
  16. package/dist/Graph.js +2 -1
  17. package/dist/Graph.js.map +1 -1
  18. package/dist/Layer.d.ts +5 -2
  19. package/dist/Layer.d.ts.map +1 -1
  20. package/dist/Layer.js +14 -1
  21. package/dist/Layer.js.map +1 -1
  22. package/dist/MutableHashMap.d.ts +7 -0
  23. package/dist/MutableHashMap.d.ts.map +1 -1
  24. package/dist/MutableHashMap.js +8 -0
  25. package/dist/MutableHashMap.js.map +1 -1
  26. package/dist/MutableHashSet.d.ts +7 -0
  27. package/dist/MutableHashSet.d.ts.map +1 -1
  28. package/dist/MutableHashSet.js +8 -0
  29. package/dist/MutableHashSet.js.map +1 -1
  30. package/dist/Resource.d.ts.map +1 -1
  31. package/dist/Resource.js +2 -1
  32. package/dist/Resource.js.map +1 -1
  33. package/dist/Schema.d.ts +21 -0
  34. package/dist/Schema.d.ts.map +1 -1
  35. package/dist/Schema.js +20 -0
  36. package/dist/Schema.js.map +1 -1
  37. package/dist/Stream.d.ts +10 -1
  38. package/dist/Stream.d.ts.map +1 -1
  39. package/dist/Stream.js +5 -1
  40. package/dist/Stream.js.map +1 -1
  41. package/dist/SubscriptionRef.d.ts.map +1 -1
  42. package/dist/SubscriptionRef.js +2 -1
  43. package/dist/SubscriptionRef.js.map +1 -1
  44. package/dist/TxDeferred.d.ts.map +1 -1
  45. package/dist/TxDeferred.js +2 -1
  46. package/dist/TxDeferred.js.map +1 -1
  47. package/dist/TxHashMap.d.ts.map +1 -1
  48. package/dist/TxHashMap.js +2 -1
  49. package/dist/TxHashMap.js.map +1 -1
  50. package/dist/TxHashSet.d.ts +1 -1
  51. package/dist/TxHashSet.d.ts.map +1 -1
  52. package/dist/TxHashSet.js +2 -1
  53. package/dist/TxHashSet.js.map +1 -1
  54. package/dist/TxPriorityQueue.d.ts +1 -1
  55. package/dist/TxPriorityQueue.d.ts.map +1 -1
  56. package/dist/TxPriorityQueue.js +2 -1
  57. package/dist/TxPriorityQueue.js.map +1 -1
  58. package/dist/TxSemaphore.d.ts.map +1 -1
  59. package/dist/TxSemaphore.js +2 -1
  60. package/dist/TxSemaphore.js.map +1 -1
  61. package/dist/internal/dateTime.js +8 -1
  62. package/dist/internal/dateTime.js.map +1 -1
  63. package/dist/internal/effect.js +1 -1
  64. package/dist/internal/effect.js.map +1 -1
  65. package/dist/unstable/ai/AiError.d.ts +2 -3
  66. package/dist/unstable/ai/AiError.d.ts.map +1 -1
  67. package/dist/unstable/ai/AiError.js +8 -6
  68. package/dist/unstable/ai/AiError.js.map +1 -1
  69. package/dist/unstable/ai/EmbeddingModel.d.ts +130 -0
  70. package/dist/unstable/ai/EmbeddingModel.d.ts.map +1 -0
  71. package/dist/unstable/ai/EmbeddingModel.js +127 -0
  72. package/dist/unstable/ai/EmbeddingModel.js.map +1 -0
  73. package/dist/unstable/ai/LanguageModel.d.ts.map +1 -1
  74. package/dist/unstable/ai/LanguageModel.js +34 -8
  75. package/dist/unstable/ai/LanguageModel.js.map +1 -1
  76. package/dist/unstable/ai/ResponseIdTracker.js +3 -3
  77. package/dist/unstable/ai/ResponseIdTracker.js.map +1 -1
  78. package/dist/unstable/ai/Tool.d.ts +1 -1
  79. package/dist/unstable/ai/Tool.d.ts.map +1 -1
  80. package/dist/unstable/ai/Tool.js +1 -1
  81. package/dist/unstable/ai/Tool.js.map +1 -1
  82. package/dist/unstable/ai/index.d.ts +17 -0
  83. package/dist/unstable/ai/index.d.ts.map +1 -1
  84. package/dist/unstable/ai/index.js +17 -0
  85. package/dist/unstable/ai/index.js.map +1 -1
  86. package/dist/unstable/cli/CliOutput.js +4 -3
  87. package/dist/unstable/cli/CliOutput.js.map +1 -1
  88. package/dist/unstable/http/Url.d.ts +604 -0
  89. package/dist/unstable/http/Url.d.ts.map +1 -0
  90. package/dist/unstable/http/Url.js +256 -0
  91. package/dist/unstable/http/Url.js.map +1 -0
  92. package/dist/unstable/http/index.d.ts +4 -0
  93. package/dist/unstable/http/index.d.ts.map +1 -1
  94. package/dist/unstable/http/index.js +4 -0
  95. package/dist/unstable/http/index.js.map +1 -1
  96. package/dist/unstable/httpapi/HttpApiMiddleware.d.ts +30 -1
  97. package/dist/unstable/httpapi/HttpApiMiddleware.d.ts.map +1 -1
  98. package/dist/unstable/httpapi/HttpApiMiddleware.js +27 -0
  99. package/dist/unstable/httpapi/HttpApiMiddleware.js.map +1 -1
  100. package/dist/unstable/rpc/RpcSerialization.js +1 -1
  101. package/dist/unstable/rpc/RpcSerialization.js.map +1 -1
  102. package/package.json +1 -1
  103. package/src/Channel.ts +11 -1
  104. package/src/Config.ts +5 -0
  105. package/src/Effect.ts +8 -7
  106. package/src/FileSystem.ts +2 -1
  107. package/src/Graph.ts +2 -1
  108. package/src/Layer.ts +27 -9
  109. package/src/MutableHashMap.ts +9 -0
  110. package/src/MutableHashSet.ts +9 -0
  111. package/src/Resource.ts +2 -1
  112. package/src/Schema.ts +30 -0
  113. package/src/Stream.ts +11 -1
  114. package/src/SubscriptionRef.ts +2 -1
  115. package/src/TxDeferred.ts +2 -2
  116. package/src/TxHashMap.ts +2 -1
  117. package/src/TxHashSet.ts +2 -2
  118. package/src/TxPriorityQueue.ts +2 -3
  119. package/src/TxSemaphore.ts +2 -1
  120. package/src/internal/dateTime.ts +8 -1
  121. package/src/internal/effect.ts +15 -6
  122. package/src/unstable/ai/AiError.ts +5 -5
  123. package/src/unstable/ai/EmbeddingModel.ts +209 -0
  124. package/src/unstable/ai/LanguageModel.ts +44 -8
  125. package/src/unstable/ai/ResponseIdTracker.ts +3 -3
  126. package/src/unstable/ai/Tool.ts +2 -2
  127. package/src/unstable/ai/index.ts +18 -0
  128. package/src/unstable/cli/CliOutput.ts +5 -4
  129. package/src/unstable/http/Url.ts +650 -0
  130. package/src/unstable/http/index.ts +5 -0
  131. package/src/unstable/httpapi/HttpApiMiddleware.ts +46 -1
  132. package/src/unstable/rpc/RpcSerialization.ts +1 -1
@@ -937,6 +937,24 @@ export const make: (params: {
937
937
  const tracker = Option.getOrUndefined(yield* Effect.serviceOption(ResponseIdTracker.ResponseIdTracker))
938
938
  const toolChoice = options.toolChoice ?? "auto"
939
939
 
940
+ const generateWithNonIncrementalFallback = () => {
941
+ const requestOptions: ProviderOptions = {
942
+ ...providerOptions
943
+ }
944
+ const fallbackPrompt = requestOptions.prompt
945
+ const fallbackOptions: ProviderOptions = {
946
+ ...requestOptions,
947
+ prompt: fallbackPrompt,
948
+ incrementalPrompt: undefined,
949
+ previousResponseId: undefined
950
+ }
951
+ return requestOptions.incrementalPrompt
952
+ ? params.generateText(requestOptions).pipe(
953
+ Effect.catchReason("AiError", "InvalidRequestError", (_) => params.generateText(fallbackOptions))
954
+ )
955
+ : params.generateText(requestOptions)
956
+ }
957
+
940
958
  // Check for pending approvals that need resolution
941
959
  const { approved, denied } = collectToolApprovals(
942
960
  providerOptions.prompt.content,
@@ -968,7 +986,7 @@ export const make: (params: {
968
986
  const ResponseSchema = Schema.mutable(
969
987
  Schema.Array(Response.Part(Toolkit.empty))
970
988
  )
971
- const rawContent = yield* params.generateText(providerOptions)
989
+ const rawContent = yield* generateWithNonIncrementalFallback()
972
990
  const content = yield* Schema.decodeEffect(ResponseSchema)(rawContent)
973
991
  if (tracker) {
974
992
  const responseMetadata = content.find((part) => part.type === "response-metadata")
@@ -1006,7 +1024,7 @@ export const make: (params: {
1006
1024
  const ResponseSchema = Schema.mutable(
1007
1025
  Schema.Array(Response.Part(Toolkit.empty))
1008
1026
  )
1009
- const rawContent = yield* params.generateText(providerOptions)
1027
+ const rawContent = yield* generateWithNonIncrementalFallback()
1010
1028
  const content = yield* Schema.decodeEffect(ResponseSchema)(rawContent)
1011
1029
  if (tracker) {
1012
1030
  const responseMetadata = content.find((part) => part.type === "response-metadata")
@@ -1085,7 +1103,7 @@ export const make: (params: {
1085
1103
  // If tool call resolution is disabled, return the response without
1086
1104
  // resolving the tool calls that were generated
1087
1105
  if (options.disableToolCallResolution === true) {
1088
- const rawContent = yield* params.generateText(providerOptions)
1106
+ const rawContent = yield* generateWithNonIncrementalFallback()
1089
1107
  const content = yield* Schema.decodeEffect(ResponseSchema)(rawContent)
1090
1108
  if (tracker) {
1091
1109
  const responseMetadata = content.find((part) => part.type === "response-metadata")
@@ -1096,7 +1114,7 @@ export const make: (params: {
1096
1114
  return content as Array<Response.Part<Tools>>
1097
1115
  }
1098
1116
 
1099
- const rawContent = yield* params.generateText(providerOptions)
1117
+ const rawContent = yield* generateWithNonIncrementalFallback()
1100
1118
 
1101
1119
  // Resolve the generated tool calls
1102
1120
  const toolResults = yield* resolveToolCalls(
@@ -1154,6 +1172,24 @@ export const make: (params: {
1154
1172
  const tracker = Option.getOrUndefined(yield* Effect.serviceOption(ResponseIdTracker.ResponseIdTracker))
1155
1173
  const toolChoice = options.toolChoice ?? "auto"
1156
1174
 
1175
+ const streamWithNonIncrementalFallback = () => {
1176
+ const requestOptions: ProviderOptions = {
1177
+ ...providerOptions
1178
+ }
1179
+ const fallbackPrompt = requestOptions.prompt
1180
+ const fallbackOptions: ProviderOptions = {
1181
+ ...requestOptions,
1182
+ prompt: fallbackPrompt,
1183
+ incrementalPrompt: undefined,
1184
+ previousResponseId: undefined
1185
+ }
1186
+ return requestOptions.incrementalPrompt
1187
+ ? params.streamText(requestOptions).pipe(
1188
+ Stream.catchReason("AiError", "InvalidRequestError", (_) => params.streamText(fallbackOptions))
1189
+ )
1190
+ : params.streamText(requestOptions)
1191
+ }
1192
+
1157
1193
  // Check for pending approvals that need resolution
1158
1194
  const { approved: pendingApproved, denied: pendingDenied } = collectToolApprovals(providerOptions.prompt.content, {
1159
1195
  excludeResolved: true
@@ -1184,7 +1220,7 @@ export const make: (params: {
1184
1220
  const schema = Schema.NonEmptyArray(Response.StreamPart(Toolkit.empty))
1185
1221
  const decodeParts = Schema.decodeEffect(schema)
1186
1222
  return pipe(
1187
- params.streamText(providerOptions),
1223
+ streamWithNonIncrementalFallback(),
1188
1224
  Stream.mapArrayEffect((parts) =>
1189
1225
  decodeParts(parts).pipe(
1190
1226
  tracker ?
@@ -1233,7 +1269,7 @@ export const make: (params: {
1233
1269
  const schema = Schema.NonEmptyArray(Response.StreamPart(Toolkit.empty))
1234
1270
  const decodeParts = Schema.decodeEffect(schema)
1235
1271
  return pipe(
1236
- params.streamText(providerOptions),
1272
+ streamWithNonIncrementalFallback(),
1237
1273
  Stream.mapArrayEffect((parts) =>
1238
1274
  decodeParts(parts).pipe(
1239
1275
  tracker ?
@@ -1339,7 +1375,7 @@ export const make: (params: {
1339
1375
  if (options.disableToolCallResolution === true) {
1340
1376
  const schema = Schema.NonEmptyArray(Response.StreamPart(toolkit))
1341
1377
  const decodeParts = Schema.decodeEffect(schema)
1342
- return params.streamText(providerOptions).pipe(
1378
+ return streamWithNonIncrementalFallback().pipe(
1343
1379
  Stream.mapArrayEffect((parts) =>
1344
1380
  decodeParts(parts).pipe(
1345
1381
  tracker ?
@@ -1418,7 +1454,7 @@ export const make: (params: {
1418
1454
  )
1419
1455
  })
1420
1456
 
1421
- yield* params.streamText(providerOptions).pipe(
1457
+ yield* streamWithNonIncrementalFallback().pipe(
1422
1458
  Stream.runForEachArray(
1423
1459
  Effect.fnUntraced(function*(chunk) {
1424
1460
  const parts = yield* decodeParts(chunk)
@@ -38,16 +38,16 @@ export class ResponseIdTracker
38
38
  * @category constructors
39
39
  */
40
40
  export const make: Effect.Effect<Service> = Effect.sync(() => {
41
- let sentParts = new WeakMap<object, string>()
41
+ const sentParts = new Map<object, string>()
42
42
 
43
43
  const none = () => {
44
- sentParts = new WeakMap<object, string>()
44
+ sentParts.clear()
45
45
  return Option.none<PrepareResult>()
46
46
  }
47
47
 
48
48
  return {
49
49
  clearUnsafe() {
50
- sentParts = new WeakMap<object, string>()
50
+ sentParts.clear()
51
51
  },
52
52
  markParts(parts, responseId) {
53
53
  for (let i = 0; i < parts.length; i++) {
@@ -1149,7 +1149,7 @@ const dynamicProto = <
1149
1149
  */
1150
1150
  export const make = <
1151
1151
  const Name extends string,
1152
- Parameters extends Schema.Top = typeof Schema.Void,
1152
+ Parameters extends Schema.Top = typeof EmptyParams,
1153
1153
  Success extends Schema.Top = typeof Schema.Void,
1154
1154
  Failure extends Schema.Top = typeof Schema.Never,
1155
1155
  Mode extends FailureMode | undefined = undefined,
@@ -1210,7 +1210,7 @@ export const make = <
1210
1210
  return userDefinedProto({
1211
1211
  name,
1212
1212
  description: options?.description,
1213
- parametersSchema: options?.parameters ?? Schema.Void,
1213
+ parametersSchema: options?.parameters ?? EmptyParams,
1214
1214
  successSchema,
1215
1215
  failureSchema,
1216
1216
  failureMode: options?.failureMode ?? "error",
@@ -153,6 +153,24 @@ export * as AnthropicStructuredOutput from "./AnthropicStructuredOutput.ts"
153
153
  */
154
154
  export * as Chat from "./Chat.ts"
155
155
 
156
+ /**
157
+ * The `EmbeddingModel` module provides provider-agnostic text embedding capabilities.
158
+ *
159
+ * @example
160
+ * ```ts
161
+ * import { Effect } from "effect"
162
+ * import { EmbeddingModel } from "effect/unstable/ai"
163
+ *
164
+ * const program = Effect.gen(function*() {
165
+ * const model = yield* EmbeddingModel.EmbeddingModel
166
+ * return yield* model.embed("hello world")
167
+ * })
168
+ * ```
169
+ *
170
+ * @since 4.0.0
171
+ */
172
+ export * as EmbeddingModel from "./EmbeddingModel.ts"
173
+
156
174
  /**
157
175
  * The `IdGenerator` module provides a pluggable system for generating unique identifiers
158
176
  * for tool calls and other items in the Effect AI SDKs.
@@ -406,8 +406,9 @@ interface Row {
406
406
  * Renders a table with aligned columns.
407
407
  * @internal
408
408
  */
409
- const renderTable = (rows: ReadonlyArray<Row>, widthCap: number) => {
410
- const col = Math.min(Math.max(...rows.map((r) => visualLength(r.left))) + 4, widthCap)
409
+ const renderTable = (rows: ReadonlyArray<Row>, widthCap?: number) => {
410
+ const maxColumn = Math.max(...rows.map((r) => visualLength(r.left))) + 4
411
+ const col = widthCap === undefined ? maxColumn : Math.min(maxColumn, widthCap)
411
412
  return rows.map(({ left, right }) => ` ${pad(left, col)}${right}`).join("\n")
412
413
  }
413
414
 
@@ -497,7 +498,7 @@ const formatHelpDocImpl = (doc: HelpDoc, colors: ColorFunctions): string => {
497
498
  }
498
499
  })
499
500
 
500
- sections.push(renderTable(flagRows, 30))
501
+ sections.push(renderTable(flagRows))
501
502
  sections.push("")
502
503
  }
503
504
 
@@ -525,7 +526,7 @@ const formatHelpDocImpl = (doc: HelpDoc, colors: ColorFunctions): string => {
525
526
  }
526
527
  })
527
528
 
528
- sections.push(renderTable(globalFlagRows, 30))
529
+ sections.push(renderTable(globalFlagRows))
529
530
  sections.push("")
530
531
  }
531
532