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.
- package/dist/Channel.d.ts +10 -1
- package/dist/Channel.d.ts.map +1 -1
- package/dist/Channel.js +5 -1
- package/dist/Channel.js.map +1 -1
- package/dist/Config.d.ts +4 -0
- package/dist/Config.d.ts.map +1 -1
- package/dist/Config.js.map +1 -1
- package/dist/Effect.d.ts +5 -3
- package/dist/Effect.d.ts.map +1 -1
- package/dist/Effect.js +4 -4
- package/dist/Effect.js.map +1 -1
- package/dist/FileSystem.d.ts.map +1 -1
- package/dist/FileSystem.js +2 -1
- package/dist/FileSystem.js.map +1 -1
- package/dist/Graph.d.ts.map +1 -1
- package/dist/Graph.js +2 -1
- package/dist/Graph.js.map +1 -1
- package/dist/Layer.d.ts +5 -2
- package/dist/Layer.d.ts.map +1 -1
- package/dist/Layer.js +14 -1
- package/dist/Layer.js.map +1 -1
- package/dist/MutableHashMap.d.ts +7 -0
- package/dist/MutableHashMap.d.ts.map +1 -1
- package/dist/MutableHashMap.js +8 -0
- package/dist/MutableHashMap.js.map +1 -1
- package/dist/MutableHashSet.d.ts +7 -0
- package/dist/MutableHashSet.d.ts.map +1 -1
- package/dist/MutableHashSet.js +8 -0
- package/dist/MutableHashSet.js.map +1 -1
- package/dist/Resource.d.ts.map +1 -1
- package/dist/Resource.js +2 -1
- package/dist/Resource.js.map +1 -1
- package/dist/Schema.d.ts +21 -0
- package/dist/Schema.d.ts.map +1 -1
- package/dist/Schema.js +20 -0
- package/dist/Schema.js.map +1 -1
- package/dist/Stream.d.ts +10 -1
- package/dist/Stream.d.ts.map +1 -1
- package/dist/Stream.js +5 -1
- package/dist/Stream.js.map +1 -1
- package/dist/SubscriptionRef.d.ts.map +1 -1
- package/dist/SubscriptionRef.js +2 -1
- package/dist/SubscriptionRef.js.map +1 -1
- package/dist/TxDeferred.d.ts.map +1 -1
- package/dist/TxDeferred.js +2 -1
- package/dist/TxDeferred.js.map +1 -1
- package/dist/TxHashMap.d.ts.map +1 -1
- package/dist/TxHashMap.js +2 -1
- package/dist/TxHashMap.js.map +1 -1
- package/dist/TxHashSet.d.ts +1 -1
- package/dist/TxHashSet.d.ts.map +1 -1
- package/dist/TxHashSet.js +2 -1
- package/dist/TxHashSet.js.map +1 -1
- package/dist/TxPriorityQueue.d.ts +1 -1
- package/dist/TxPriorityQueue.d.ts.map +1 -1
- package/dist/TxPriorityQueue.js +2 -1
- package/dist/TxPriorityQueue.js.map +1 -1
- package/dist/TxSemaphore.d.ts.map +1 -1
- package/dist/TxSemaphore.js +2 -1
- package/dist/TxSemaphore.js.map +1 -1
- package/dist/internal/dateTime.js +8 -1
- package/dist/internal/dateTime.js.map +1 -1
- package/dist/internal/effect.js +1 -1
- package/dist/internal/effect.js.map +1 -1
- package/dist/unstable/ai/AiError.d.ts +2 -3
- package/dist/unstable/ai/AiError.d.ts.map +1 -1
- package/dist/unstable/ai/AiError.js +8 -6
- package/dist/unstable/ai/AiError.js.map +1 -1
- package/dist/unstable/ai/EmbeddingModel.d.ts +130 -0
- package/dist/unstable/ai/EmbeddingModel.d.ts.map +1 -0
- package/dist/unstable/ai/EmbeddingModel.js +127 -0
- package/dist/unstable/ai/EmbeddingModel.js.map +1 -0
- package/dist/unstable/ai/LanguageModel.d.ts.map +1 -1
- package/dist/unstable/ai/LanguageModel.js +34 -8
- package/dist/unstable/ai/LanguageModel.js.map +1 -1
- package/dist/unstable/ai/ResponseIdTracker.js +3 -3
- package/dist/unstable/ai/ResponseIdTracker.js.map +1 -1
- package/dist/unstable/ai/Tool.d.ts +1 -1
- package/dist/unstable/ai/Tool.d.ts.map +1 -1
- package/dist/unstable/ai/Tool.js +1 -1
- package/dist/unstable/ai/Tool.js.map +1 -1
- package/dist/unstable/ai/index.d.ts +17 -0
- package/dist/unstable/ai/index.d.ts.map +1 -1
- package/dist/unstable/ai/index.js +17 -0
- package/dist/unstable/ai/index.js.map +1 -1
- package/dist/unstable/cli/CliOutput.js +4 -3
- package/dist/unstable/cli/CliOutput.js.map +1 -1
- package/dist/unstable/http/Url.d.ts +604 -0
- package/dist/unstable/http/Url.d.ts.map +1 -0
- package/dist/unstable/http/Url.js +256 -0
- package/dist/unstable/http/Url.js.map +1 -0
- package/dist/unstable/http/index.d.ts +4 -0
- package/dist/unstable/http/index.d.ts.map +1 -1
- package/dist/unstable/http/index.js +4 -0
- package/dist/unstable/http/index.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiMiddleware.d.ts +30 -1
- package/dist/unstable/httpapi/HttpApiMiddleware.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiMiddleware.js +27 -0
- package/dist/unstable/httpapi/HttpApiMiddleware.js.map +1 -1
- package/dist/unstable/rpc/RpcSerialization.js +1 -1
- package/dist/unstable/rpc/RpcSerialization.js.map +1 -1
- package/package.json +1 -1
- package/src/Channel.ts +11 -1
- package/src/Config.ts +5 -0
- package/src/Effect.ts +8 -7
- package/src/FileSystem.ts +2 -1
- package/src/Graph.ts +2 -1
- package/src/Layer.ts +27 -9
- package/src/MutableHashMap.ts +9 -0
- package/src/MutableHashSet.ts +9 -0
- package/src/Resource.ts +2 -1
- package/src/Schema.ts +30 -0
- package/src/Stream.ts +11 -1
- package/src/SubscriptionRef.ts +2 -1
- package/src/TxDeferred.ts +2 -2
- package/src/TxHashMap.ts +2 -1
- package/src/TxHashSet.ts +2 -2
- package/src/TxPriorityQueue.ts +2 -3
- package/src/TxSemaphore.ts +2 -1
- package/src/internal/dateTime.ts +8 -1
- package/src/internal/effect.ts +15 -6
- package/src/unstable/ai/AiError.ts +5 -5
- package/src/unstable/ai/EmbeddingModel.ts +209 -0
- package/src/unstable/ai/LanguageModel.ts +44 -8
- package/src/unstable/ai/ResponseIdTracker.ts +3 -3
- package/src/unstable/ai/Tool.ts +2 -2
- package/src/unstable/ai/index.ts +18 -0
- package/src/unstable/cli/CliOutput.ts +5 -4
- package/src/unstable/http/Url.ts +650 -0
- package/src/unstable/http/index.ts +5 -0
- package/src/unstable/httpapi/HttpApiMiddleware.ts +46 -1
- 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*
|
|
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*
|
|
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*
|
|
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*
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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*
|
|
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
|
-
|
|
41
|
+
const sentParts = new Map<object, string>()
|
|
42
42
|
|
|
43
43
|
const none = () => {
|
|
44
|
-
sentParts
|
|
44
|
+
sentParts.clear()
|
|
45
45
|
return Option.none<PrepareResult>()
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
return {
|
|
49
49
|
clearUnsafe() {
|
|
50
|
-
sentParts
|
|
50
|
+
sentParts.clear()
|
|
51
51
|
},
|
|
52
52
|
markParts(parts, responseId) {
|
|
53
53
|
for (let i = 0; i < parts.length; i++) {
|
package/src/unstable/ai/Tool.ts
CHANGED
|
@@ -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
|
|
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 ??
|
|
1213
|
+
parametersSchema: options?.parameters ?? EmptyParams,
|
|
1214
1214
|
successSchema,
|
|
1215
1215
|
failureSchema,
|
|
1216
1216
|
failureMode: options?.failureMode ?? "error",
|
package/src/unstable/ai/index.ts
CHANGED
|
@@ -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
|
|
410
|
-
const
|
|
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
|
|
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
|
|
529
|
+
sections.push(renderTable(globalFlagRows))
|
|
529
530
|
sections.push("")
|
|
530
531
|
}
|
|
531
532
|
|