effect 4.0.0-beta.20 → 4.0.0-beta.22
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/Array.d.ts +8 -9
- package/dist/Array.d.ts.map +1 -1
- package/dist/Array.js.map +1 -1
- package/dist/Chunk.d.ts +4 -4
- package/dist/Chunk.d.ts.map +1 -1
- package/dist/Chunk.js.map +1 -1
- package/dist/Duration.d.ts +1 -1
- package/dist/Duration.d.ts.map +1 -1
- package/dist/Duration.js +1 -1
- package/dist/Duration.js.map +1 -1
- package/dist/Effect.d.ts +92 -1
- package/dist/Effect.d.ts.map +1 -1
- package/dist/Effect.js +30 -1
- package/dist/Effect.js.map +1 -1
- package/dist/Filter.d.ts +4 -4
- package/dist/Filter.d.ts.map +1 -1
- package/dist/Filter.js.map +1 -1
- package/dist/HashMap.d.ts +3 -3
- package/dist/HashMap.d.ts.map +1 -1
- package/dist/HashMap.js.map +1 -1
- package/dist/Iterable.d.ts +4 -5
- package/dist/Iterable.d.ts.map +1 -1
- package/dist/Iterable.js.map +1 -1
- package/dist/Record.d.ts +4 -5
- package/dist/Record.d.ts.map +1 -1
- package/dist/Record.js.map +1 -1
- package/dist/Runtime.d.ts.map +1 -1
- package/dist/Runtime.js +7 -1
- package/dist/Runtime.js.map +1 -1
- package/dist/Schedule.d.ts.map +1 -1
- package/dist/Schedule.js +4 -1
- package/dist/Schedule.js.map +1 -1
- package/dist/SchemaAST.js +6 -6
- package/dist/SchemaAST.js.map +1 -1
- package/dist/Stream.d.ts +7 -1
- package/dist/Stream.d.ts.map +1 -1
- package/dist/Stream.js +6 -2
- package/dist/Stream.js.map +1 -1
- package/dist/Trie.d.ts +3 -3
- package/dist/Trie.d.ts.map +1 -1
- package/dist/Trie.js.map +1 -1
- package/dist/TxHashMap.d.ts +3 -3
- package/dist/TxHashMap.d.ts.map +1 -1
- package/dist/TxHashMap.js.map +1 -1
- package/dist/TxPubSub.d.ts +4 -4
- package/dist/TxPubSub.d.ts.map +1 -1
- package/dist/internal/effect.js +48 -38
- package/dist/internal/effect.js.map +1 -1
- package/dist/internal/hashMap.js.map +1 -1
- package/dist/internal/trie.js.map +1 -1
- package/dist/unstable/ai/Chat.d.ts +2 -2
- package/dist/unstable/ai/Chat.d.ts.map +1 -1
- package/dist/unstable/ai/Chat.js +35 -42
- package/dist/unstable/ai/Chat.js.map +1 -1
- package/dist/unstable/ai/LanguageModel.d.ts.map +1 -1
- package/dist/unstable/ai/LanguageModel.js.map +1 -1
- package/dist/unstable/ai/McpServer.js +2 -1
- package/dist/unstable/ai/McpServer.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/http/HttpEffect.js +2 -2
- package/dist/unstable/http/HttpEffect.js.map +1 -1
- package/dist/unstable/http/HttpMiddleware.js +2 -2
- package/dist/unstable/http/HttpMiddleware.js.map +1 -1
- package/dist/unstable/http/HttpServerRequest.d.ts +1 -1
- package/dist/unstable/http/HttpServerRequest.d.ts.map +1 -1
- package/dist/unstable/http/internal/preResponseHandler.js +2 -2
- package/dist/unstable/http/internal/preResponseHandler.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiClient.d.ts +55 -0
- package/dist/unstable/httpapi/HttpApiClient.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiClient.js +37 -0
- package/dist/unstable/httpapi/HttpApiClient.js.map +1 -1
- package/dist/unstable/schema/VariantSchema.d.ts +2 -2
- package/dist/unstable/schema/VariantSchema.d.ts.map +1 -1
- package/dist/unstable/schema/VariantSchema.js +3 -3
- package/dist/unstable/schema/VariantSchema.js.map +1 -1
- package/dist/unstable/workflow/Workflow.d.ts.map +1 -1
- package/dist/unstable/workflow/Workflow.js +1 -1
- package/dist/unstable/workflow/Workflow.js.map +1 -1
- package/dist/unstable/workflow/WorkflowEngine.d.ts +5 -1
- package/dist/unstable/workflow/WorkflowEngine.d.ts.map +1 -1
- package/dist/unstable/workflow/WorkflowEngine.js +5 -1
- package/dist/unstable/workflow/WorkflowEngine.js.map +1 -1
- package/package.json +1 -1
- package/src/Array.ts +15 -13
- package/src/Chunk.ts +6 -6
- package/src/Duration.ts +2 -2
- package/src/Effect.ts +102 -1
- package/src/Filter.ts +4 -5
- package/src/HashMap.ts +3 -3
- package/src/Iterable.ts +6 -7
- package/src/Record.ts +6 -7
- package/src/Runtime.ts +7 -1
- package/src/Schedule.ts +4 -1
- package/src/SchemaAST.ts +6 -6
- package/src/Stream.ts +13 -4
- package/src/Trie.ts +3 -3
- package/src/TxHashMap.ts +4 -4
- package/src/TxPubSub.ts +4 -4
- package/src/internal/effect.ts +107 -49
- package/src/internal/hashMap.ts +3 -4
- package/src/internal/trie.ts +3 -4
- package/src/unstable/ai/Chat.ts +36 -51
- package/src/unstable/ai/LanguageModel.ts +0 -1
- package/src/unstable/ai/McpServer.ts +2 -1
- package/src/unstable/ai/Tool.ts +1 -1
- package/src/unstable/http/HttpEffect.ts +2 -2
- package/src/unstable/http/HttpMiddleware.ts +3 -3
- package/src/unstable/http/HttpServerRequest.ts +1 -1
- package/src/unstable/http/internal/preResponseHandler.ts +3 -3
- package/src/unstable/httpapi/HttpApiClient.ts +82 -1
- package/src/unstable/schema/VariantSchema.ts +3 -3
- package/src/unstable/workflow/Workflow.ts +5 -1
- package/src/unstable/workflow/WorkflowEngine.ts +5 -1
package/src/Trie.ts
CHANGED
|
@@ -16,11 +16,11 @@
|
|
|
16
16
|
* @since 2.0.0
|
|
17
17
|
*/
|
|
18
18
|
import type { Equal } from "./Equal.ts"
|
|
19
|
-
import type * as Filter from "./Filter.ts"
|
|
20
19
|
import type { Inspectable } from "./Inspectable.ts"
|
|
21
20
|
import * as TR from "./internal/trie.ts"
|
|
22
21
|
import type { Option } from "./Option.ts"
|
|
23
22
|
import type { Pipeable } from "./Pipeable.ts"
|
|
23
|
+
import type { Result } from "./Result.ts"
|
|
24
24
|
import type { Covariant, NoInfer } from "./Types.ts"
|
|
25
25
|
|
|
26
26
|
const TypeId = TR.TrieTypeId
|
|
@@ -1585,7 +1585,7 @@ export const filterMap: {
|
|
|
1585
1585
|
* @since 2.0.0
|
|
1586
1586
|
* @category filtering
|
|
1587
1587
|
*/
|
|
1588
|
-
<A, B, X>(f:
|
|
1588
|
+
<A, B, X>(f: (input: A, key: string) => Result<B, X>): (self: Trie<A>) => Trie<B>
|
|
1589
1589
|
/**
|
|
1590
1590
|
* Maps over the entries of the `Trie` using the specified filter and keeps
|
|
1591
1591
|
* only successful results.
|
|
@@ -1634,7 +1634,7 @@ export const filterMap: {
|
|
|
1634
1634
|
* @since 2.0.0
|
|
1635
1635
|
* @category filtering
|
|
1636
1636
|
*/
|
|
1637
|
-
<A, B, X>(self: Trie<A>, f:
|
|
1637
|
+
<A, B, X>(self: Trie<A>, f: (input: A, key: string) => Result<B, X>): Trie<B>
|
|
1638
1638
|
} = TR.filterMap
|
|
1639
1639
|
|
|
1640
1640
|
/**
|
package/src/TxHashMap.ts
CHANGED
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import * as Effect from "./Effect.ts"
|
|
6
|
-
import type * as Filter from "./Filter.ts"
|
|
7
6
|
import { format } from "./Formatter.ts"
|
|
8
7
|
import { dual } from "./Function.ts"
|
|
9
8
|
import * as HashMap from "./HashMap.ts"
|
|
@@ -12,6 +11,7 @@ import { NodeInspectSymbol, toJson } from "./Inspectable.ts"
|
|
|
12
11
|
import * as Option from "./Option.ts"
|
|
13
12
|
import type { Pipeable } from "./Pipeable.ts"
|
|
14
13
|
import { pipeArguments } from "./Pipeable.ts"
|
|
14
|
+
import type { Result } from "./Result.ts"
|
|
15
15
|
import * as TxRef from "./TxRef.ts"
|
|
16
16
|
|
|
17
17
|
const TypeId = "~effect/transactions/TxHashMap"
|
|
@@ -2835,7 +2835,7 @@ export const filterMap: {
|
|
|
2835
2835
|
* @since 2.0.0
|
|
2836
2836
|
* @category combinators
|
|
2837
2837
|
*/
|
|
2838
|
-
<V, K, A, X>(f:
|
|
2838
|
+
<V, K, A, X>(f: (input: V, key: K) => Result<A, X>): (self: TxHashMap<K, V>) => Effect.Effect<TxHashMap<K, A>, never, Effect.Transaction>
|
|
2839
2839
|
/**
|
|
2840
2840
|
* Combines filtering and mapping in a single operation. Applies a filter to each
|
|
2841
2841
|
* entry, keeping only successful results and transforming them.
|
|
@@ -2893,12 +2893,12 @@ export const filterMap: {
|
|
|
2893
2893
|
* @since 2.0.0
|
|
2894
2894
|
* @category combinators
|
|
2895
2895
|
*/
|
|
2896
|
-
<K, V, A, X>(self: TxHashMap<K, V>, f:
|
|
2896
|
+
<K, V, A, X>(self: TxHashMap<K, V>, f: (input: V, key: K) => Result<A, X>): Effect.Effect<TxHashMap<K, A>, never, Effect.Transaction>
|
|
2897
2897
|
} = dual(
|
|
2898
2898
|
2,
|
|
2899
2899
|
<K, V, A, X>(
|
|
2900
2900
|
self: TxHashMap<K, V>,
|
|
2901
|
-
f:
|
|
2901
|
+
f: (input: V, key: K) => Result<A, X>
|
|
2902
2902
|
): Effect.Effect<TxHashMap<K, A>, never, Effect.Transaction> =>
|
|
2903
2903
|
Effect.gen(function*() {
|
|
2904
2904
|
const currentMap = yield* TxRef.get(self.ref)
|
package/src/TxPubSub.ts
CHANGED
|
@@ -430,7 +430,7 @@ export const publish: {
|
|
|
430
430
|
* @since 4.0.0
|
|
431
431
|
* @category mutations
|
|
432
432
|
*/
|
|
433
|
-
<A>(value: A): (self: TxPubSub<A>) => Effect.Effect<boolean>
|
|
433
|
+
<A>(value: A): (self: TxPubSub<A>) => Effect.Effect<boolean, never, Effect.Transaction>
|
|
434
434
|
// =============================================================================
|
|
435
435
|
// Mutations
|
|
436
436
|
// =============================================================================
|
|
@@ -470,7 +470,7 @@ export const publish: {
|
|
|
470
470
|
* @since 4.0.0
|
|
471
471
|
* @category mutations
|
|
472
472
|
*/
|
|
473
|
-
<A>(self: TxPubSub<A>, value: A): Effect.Effect<boolean>
|
|
473
|
+
<A>(self: TxPubSub<A>, value: A): Effect.Effect<boolean, never, Effect.Transaction>
|
|
474
474
|
} = dual(
|
|
475
475
|
2,
|
|
476
476
|
<A>(self: TxPubSub<A>, value: A): Effect.Effect<boolean, never, Effect.Transaction> =>
|
|
@@ -546,7 +546,7 @@ export const publishAll: {
|
|
|
546
546
|
* @since 4.0.0
|
|
547
547
|
* @category mutations
|
|
548
548
|
*/
|
|
549
|
-
<A>(values: Iterable<A>): (self: TxPubSub<A>) => Effect.Effect<boolean>
|
|
549
|
+
<A>(values: Iterable<A>): (self: TxPubSub<A>) => Effect.Effect<boolean, never, Effect.Transaction>
|
|
550
550
|
/**
|
|
551
551
|
* Publishes all messages from an iterable to all current subscribers.
|
|
552
552
|
*
|
|
@@ -575,7 +575,7 @@ export const publishAll: {
|
|
|
575
575
|
* @since 4.0.0
|
|
576
576
|
* @category mutations
|
|
577
577
|
*/
|
|
578
|
-
<A>(self: TxPubSub<A>, values: Iterable<A>): Effect.Effect<boolean>
|
|
578
|
+
<A>(self: TxPubSub<A>, values: Iterable<A>): Effect.Effect<boolean, never, Effect.Transaction>
|
|
579
579
|
} = dual(
|
|
580
580
|
2,
|
|
581
581
|
<A>(self: TxPubSub<A>, values: Iterable<A>): Effect.Effect<boolean, never, Effect.Transaction> =>
|
package/src/internal/effect.ts
CHANGED
|
@@ -493,40 +493,6 @@ const fiberIdStore = { id: 0 }
|
|
|
493
493
|
/** @internal */
|
|
494
494
|
export const getCurrentFiber = (): Fiber.Fiber<any, any> | undefined => (globalThis as any)[currentFiberTypeId]
|
|
495
495
|
|
|
496
|
-
const keepAlive = (() => {
|
|
497
|
-
let isAvailable: boolean | undefined
|
|
498
|
-
const start = () => {
|
|
499
|
-
if (isAvailable === true) return setInterval(constVoid, 2_147_483_647)
|
|
500
|
-
else if (isAvailable === false) return undefined
|
|
501
|
-
|
|
502
|
-
try {
|
|
503
|
-
const running = setInterval(constVoid, 2_147_483_647)
|
|
504
|
-
isAvailable = true
|
|
505
|
-
return running
|
|
506
|
-
} catch {
|
|
507
|
-
isAvailable = false
|
|
508
|
-
return undefined
|
|
509
|
-
}
|
|
510
|
-
}
|
|
511
|
-
let count = 0
|
|
512
|
-
let running: ReturnType<typeof globalThis.setInterval> | undefined = undefined
|
|
513
|
-
return ({
|
|
514
|
-
increment() {
|
|
515
|
-
count++
|
|
516
|
-
if (running === undefined) {
|
|
517
|
-
running = start()
|
|
518
|
-
}
|
|
519
|
-
},
|
|
520
|
-
decrement() {
|
|
521
|
-
count--
|
|
522
|
-
if (count === 0 && running !== undefined) {
|
|
523
|
-
clearInterval(running)
|
|
524
|
-
running = undefined
|
|
525
|
-
}
|
|
526
|
-
}
|
|
527
|
-
})
|
|
528
|
-
})()
|
|
529
|
-
|
|
530
496
|
/** @internal */
|
|
531
497
|
export class FiberImpl<A = any, E = any> implements Fiber.Fiber<A, E> {
|
|
532
498
|
constructor(
|
|
@@ -1056,10 +1022,8 @@ const callbackOptions: <A, E = never, R = never>(
|
|
|
1056
1022
|
}, controller?.signal)
|
|
1057
1023
|
if (yielded !== false) return yielded
|
|
1058
1024
|
yielded = true
|
|
1059
|
-
keepAlive.increment()
|
|
1060
1025
|
fiber._yielded = () => {
|
|
1061
1026
|
resumed = true
|
|
1062
|
-
keepAlive.decrement()
|
|
1063
1027
|
}
|
|
1064
1028
|
if (controller === undefined && onCancel === undefined) {
|
|
1065
1029
|
return Yield
|
|
@@ -1133,7 +1097,7 @@ export const fnUntraced: Effect.fn.Untraced = (
|
|
|
1133
1097
|
body: Function,
|
|
1134
1098
|
...pipeables: Array<any>
|
|
1135
1099
|
) => {
|
|
1136
|
-
|
|
1100
|
+
const fn = pipeables.length === 0
|
|
1137
1101
|
? function(this: any) {
|
|
1138
1102
|
return suspend(() => fromIteratorUnsafe(body.apply(this, arguments)))
|
|
1139
1103
|
}
|
|
@@ -1144,8 +1108,15 @@ export const fnUntraced: Effect.fn.Untraced = (
|
|
|
1144
1108
|
}
|
|
1145
1109
|
return effect
|
|
1146
1110
|
}
|
|
1111
|
+
return defineFunctionLength(body.length, fn)
|
|
1147
1112
|
}
|
|
1148
1113
|
|
|
1114
|
+
const defineFunctionLength = <F extends Function>(length: number, fn: F): F =>
|
|
1115
|
+
Object.defineProperty(fn, "length", {
|
|
1116
|
+
value: length,
|
|
1117
|
+
configurable: true
|
|
1118
|
+
})
|
|
1119
|
+
|
|
1149
1120
|
const fnStackCleaner = makeStackCleaner(2)
|
|
1150
1121
|
|
|
1151
1122
|
/** @internal */
|
|
@@ -1186,7 +1157,7 @@ const makeFn = (
|
|
|
1186
1157
|
? bodyOrOptions
|
|
1187
1158
|
: (pipeables.pop()!).bind(bodyOrOptions.self)
|
|
1188
1159
|
|
|
1189
|
-
return function(this: any, ...args: Array<any>) {
|
|
1160
|
+
return defineFunctionLength(body.length, function(this: any, ...args: Array<any>) {
|
|
1190
1161
|
let result = suspend(() => {
|
|
1191
1162
|
const iter = body.apply(this, arguments)
|
|
1192
1163
|
return isEffect(iter) ? iter : fromIteratorUnsafe(iter)
|
|
@@ -1216,7 +1187,7 @@ const makeFn = (
|
|
|
1216
1187
|
}
|
|
1217
1188
|
})
|
|
1218
1189
|
)
|
|
1219
|
-
}
|
|
1190
|
+
})
|
|
1220
1191
|
}
|
|
1221
1192
|
|
|
1222
1193
|
/** @internal */
|
|
@@ -1224,17 +1195,20 @@ export const fnUntracedEager: Effect.fn.Untraced = (
|
|
|
1224
1195
|
body: Function,
|
|
1225
1196
|
...pipeables: Array<any>
|
|
1226
1197
|
) =>
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
let effect = fromIteratorEagerUnsafe(() => body.apply(this, arguments))
|
|
1233
|
-
for (const pipeable of pipeables) {
|
|
1234
|
-
effect = pipeable(effect)
|
|
1198
|
+
defineFunctionLength(
|
|
1199
|
+
body.length,
|
|
1200
|
+
pipeables.length === 0
|
|
1201
|
+
? function(this: any) {
|
|
1202
|
+
return fromIteratorEagerUnsafe(() => body.apply(this, arguments))
|
|
1235
1203
|
}
|
|
1236
|
-
|
|
1237
|
-
|
|
1204
|
+
: function(this: any) {
|
|
1205
|
+
let effect = fromIteratorEagerUnsafe(() => body.apply(this, arguments))
|
|
1206
|
+
for (const pipeable of pipeables) {
|
|
1207
|
+
effect = pipeable(effect)
|
|
1208
|
+
}
|
|
1209
|
+
return effect
|
|
1210
|
+
}
|
|
1211
|
+
)
|
|
1238
1212
|
|
|
1239
1213
|
const fromIteratorEagerUnsafe = (
|
|
1240
1214
|
evaluate: () => Iterator<Effect.Yieldable<any, any, any, any>>
|
|
@@ -4289,6 +4263,90 @@ export const validate: {
|
|
|
4289
4263
|
)
|
|
4290
4264
|
)
|
|
4291
4265
|
|
|
4266
|
+
/** @internal */
|
|
4267
|
+
export const findFirst: {
|
|
4268
|
+
<A, E, R>(
|
|
4269
|
+
predicate: (a: NoInfer<A>, i: number) => Effect.Effect<boolean, E, R>
|
|
4270
|
+
): (elements: Iterable<A>) => Effect.Effect<Option.Option<A>, E, R>
|
|
4271
|
+
<A, E, R>(
|
|
4272
|
+
elements: Iterable<A>,
|
|
4273
|
+
predicate: (a: NoInfer<A>, i: number) => Effect.Effect<boolean, E, R>
|
|
4274
|
+
): Effect.Effect<Option.Option<A>, E, R>
|
|
4275
|
+
} = dual(
|
|
4276
|
+
(args) => isIterable(args[0]) && !isEffect(args[0]),
|
|
4277
|
+
<A, E, R>(
|
|
4278
|
+
elements: Iterable<A>,
|
|
4279
|
+
predicate: (a: A, i: number) => Effect.Effect<boolean, E, R>
|
|
4280
|
+
): Effect.Effect<Option.Option<A>, E, R> =>
|
|
4281
|
+
suspend(() => {
|
|
4282
|
+
const iterator = elements[Symbol.iterator]()
|
|
4283
|
+
const next = iterator.next()
|
|
4284
|
+
if (!next.done) {
|
|
4285
|
+
return findFirstLoop(iterator, 0, predicate, next.value)
|
|
4286
|
+
}
|
|
4287
|
+
return succeed(Option.none())
|
|
4288
|
+
})
|
|
4289
|
+
)
|
|
4290
|
+
|
|
4291
|
+
const findFirstLoop = <A, E, R>(
|
|
4292
|
+
iterator: Iterator<A>,
|
|
4293
|
+
index: number,
|
|
4294
|
+
predicate: (a: A, i: number) => Effect.Effect<boolean, E, R>,
|
|
4295
|
+
value: A
|
|
4296
|
+
): Effect.Effect<Option.Option<A>, E, R> =>
|
|
4297
|
+
flatMap(predicate(value, index), (keep) => {
|
|
4298
|
+
if (keep) {
|
|
4299
|
+
return succeed(Option.some(value))
|
|
4300
|
+
}
|
|
4301
|
+
const next = iterator.next()
|
|
4302
|
+
if (!next.done) {
|
|
4303
|
+
return findFirstLoop(iterator, index + 1, predicate, next.value)
|
|
4304
|
+
}
|
|
4305
|
+
return succeed(Option.none())
|
|
4306
|
+
})
|
|
4307
|
+
|
|
4308
|
+
/** @internal */
|
|
4309
|
+
export const findFirstFilter: {
|
|
4310
|
+
<A, B, X, E, R>(
|
|
4311
|
+
filter: (input: NoInfer<A>, i: number) => Effect.Effect<Result.Result<B, X>, E, R>
|
|
4312
|
+
): (elements: Iterable<A>) => Effect.Effect<Option.Option<B>, E, R>
|
|
4313
|
+
<A, B, X, E, R>(
|
|
4314
|
+
elements: Iterable<A>,
|
|
4315
|
+
filter: (input: NoInfer<A>, i: number) => Effect.Effect<Result.Result<B, X>, E, R>
|
|
4316
|
+
): Effect.Effect<Option.Option<B>, E, R>
|
|
4317
|
+
} = dual(
|
|
4318
|
+
(args) => isIterable(args[0]) && !isEffect(args[0]),
|
|
4319
|
+
<A, B, X, E, R>(
|
|
4320
|
+
elements: Iterable<A>,
|
|
4321
|
+
filter: (input: A, i: number) => Effect.Effect<Result.Result<B, X>, E, R>
|
|
4322
|
+
): Effect.Effect<Option.Option<B>, E, R> =>
|
|
4323
|
+
suspend(() => {
|
|
4324
|
+
const iterator = elements[Symbol.iterator]()
|
|
4325
|
+
const next = iterator.next()
|
|
4326
|
+
if (!next.done) {
|
|
4327
|
+
return findFirstFilterLoop(iterator, 0, filter, next.value)
|
|
4328
|
+
}
|
|
4329
|
+
return succeed(Option.none())
|
|
4330
|
+
})
|
|
4331
|
+
)
|
|
4332
|
+
|
|
4333
|
+
const findFirstFilterLoop = <A, B, X, E, R>(
|
|
4334
|
+
iterator: Iterator<A>,
|
|
4335
|
+
index: number,
|
|
4336
|
+
filter: (input: A, i: number) => Effect.Effect<Result.Result<B, X>, E, R>,
|
|
4337
|
+
value: A
|
|
4338
|
+
): Effect.Effect<Option.Option<B>, E, R> =>
|
|
4339
|
+
flatMap(filter(value, index), (result) => {
|
|
4340
|
+
if (Result.isSuccess(result)) {
|
|
4341
|
+
return succeed(Option.some(result.success))
|
|
4342
|
+
}
|
|
4343
|
+
const next = iterator.next()
|
|
4344
|
+
if (!next.done) {
|
|
4345
|
+
return findFirstFilterLoop(iterator, index + 1, filter, next.value)
|
|
4346
|
+
}
|
|
4347
|
+
return succeed(Option.none())
|
|
4348
|
+
})
|
|
4349
|
+
|
|
4292
4350
|
/** @internal */
|
|
4293
4351
|
export const whileLoop: <A, E, R>(options: {
|
|
4294
4352
|
readonly while: LazyArg<boolean>
|
package/src/internal/hashMap.ts
CHANGED
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import * as Equal_ from "../Equal.ts"
|
|
6
|
-
import type * as Filter from "../Filter.ts"
|
|
7
6
|
import { format } from "../Formatter.ts"
|
|
8
7
|
import { dual, pipe } from "../Function.ts"
|
|
9
8
|
import * as Hash from "../Hash.ts"
|
|
@@ -1257,9 +1256,9 @@ export const compact = <K, A>(self: HashMap<K, Option.Option<A>>): HashMap<K, A>
|
|
|
1257
1256
|
|
|
1258
1257
|
/** @internal */
|
|
1259
1258
|
export const filterMap = dual<
|
|
1260
|
-
<A, K, B, X>(f:
|
|
1261
|
-
<K, A, B, X>(self: HashMap<K, A>, f:
|
|
1262
|
-
>(2, <K, A, B, X>(self: HashMap<K, A>, f:
|
|
1259
|
+
<A, K, B, X>(f: (input: A, key: K) => Result.Result<B, X>) => (self: HashMap<K, A>) => HashMap<K, B>,
|
|
1260
|
+
<K, A, B, X>(self: HashMap<K, A>, f: (input: A, key: K) => Result.Result<B, X>) => HashMap<K, B>
|
|
1261
|
+
>(2, <K, A, B, X>(self: HashMap<K, A>, f: (input: A, key: K) => Result.Result<B, X>): HashMap<K, B> => {
|
|
1263
1262
|
let result = empty<K, B>()
|
|
1264
1263
|
for (const [key, value] of self) {
|
|
1265
1264
|
const mapped = f(value, key)
|
package/src/internal/trie.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import * as Equal from "../Equal.ts"
|
|
2
|
-
import type * as Filter from "../Filter.ts"
|
|
3
2
|
import { format } from "../Formatter.ts"
|
|
4
3
|
import { dual, pipe } from "../Function.ts"
|
|
5
4
|
import * as Hash from "../Hash.ts"
|
|
@@ -312,10 +311,10 @@ export const filter: {
|
|
|
312
311
|
/** @internal */
|
|
313
312
|
export const filterMap = dual<
|
|
314
313
|
<A, B, X>(
|
|
315
|
-
f:
|
|
314
|
+
f: (input: A, key: string) => Result.Result<B, X>
|
|
316
315
|
) => (self: TR.Trie<A>) => TR.Trie<B>,
|
|
317
|
-
<A, B, X>(self: TR.Trie<A>, f:
|
|
318
|
-
>(2, <A, B, X>(self: TR.Trie<A>, f:
|
|
316
|
+
<A, B, X>(self: TR.Trie<A>, f: (input: A, key: string) => Result.Result<B, X>) => TR.Trie<B>
|
|
317
|
+
>(2, <A, B, X>(self: TR.Trie<A>, f: (input: A, key: string) => Result.Result<B, X>): TR.Trie<B> =>
|
|
319
318
|
reduce(
|
|
320
319
|
self,
|
|
321
320
|
empty<B>(),
|
package/src/unstable/ai/Chat.ts
CHANGED
|
@@ -296,42 +296,8 @@ const encodeHistoryJson = Schema.encodeUnknownEffect(Schema.fromJsonString(Promp
|
|
|
296
296
|
// Constructors
|
|
297
297
|
// =============================================================================
|
|
298
298
|
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
*
|
|
302
|
-
* This is the most common way to start a fresh chat session without
|
|
303
|
-
* any initial context or system prompts.
|
|
304
|
-
*
|
|
305
|
-
* @example
|
|
306
|
-
* ```ts
|
|
307
|
-
* import { Effect } from "effect"
|
|
308
|
-
* import { Chat } from "effect/unstable/ai"
|
|
309
|
-
*
|
|
310
|
-
* const freshChat = Effect.gen(function*() {
|
|
311
|
-
* const chat = yield* Chat.empty
|
|
312
|
-
*
|
|
313
|
-
* const response = yield* chat.generateText({
|
|
314
|
-
* prompt: "Hello! Can you introduce yourself?"
|
|
315
|
-
* })
|
|
316
|
-
*
|
|
317
|
-
* console.log(response.content)
|
|
318
|
-
*
|
|
319
|
-
* return chat
|
|
320
|
-
* })
|
|
321
|
-
* ```
|
|
322
|
-
*
|
|
323
|
-
* @since 4.0.0
|
|
324
|
-
* @category constructors
|
|
325
|
-
*/
|
|
326
|
-
export const empty: Effect.Effect<Service> = Effect.gen(function*() {
|
|
327
|
-
const history = yield* Ref.make(Prompt.empty)
|
|
328
|
-
const services = yield* Effect.services<never>()
|
|
329
|
-
const semaphore = yield* Semaphore.make(1)
|
|
330
|
-
|
|
331
|
-
const provideContext = <A, E, R>(effect: Effect.Effect<A, E, R>): Effect.Effect<A, E, R> =>
|
|
332
|
-
Effect.updateServices(effect, (existing) => ServiceMap.merge(services, existing))
|
|
333
|
-
const provideContextStream = <A, E, R>(stream: Stream.Stream<A, E, R>): Stream.Stream<A, E, R> =>
|
|
334
|
-
Stream.updateServices(stream, (existing) => ServiceMap.merge(services, existing))
|
|
299
|
+
const makeUnsafe = (history: Ref.Ref<Prompt.Prompt>) => {
|
|
300
|
+
const semaphore = Semaphore.makeUnsafe(1)
|
|
335
301
|
|
|
336
302
|
return Chat.of({
|
|
337
303
|
history,
|
|
@@ -368,7 +334,6 @@ export const empty: Effect.Effect<Service> = Effect.gen(function*() {
|
|
|
368
334
|
|
|
369
335
|
return response
|
|
370
336
|
},
|
|
371
|
-
provideContext,
|
|
372
337
|
semaphore.withPermits(1),
|
|
373
338
|
(effect) => Effect.withSpan(effect, "Chat.generateText", { captureStackTrace: false })
|
|
374
339
|
),
|
|
@@ -397,7 +362,6 @@ export const empty: Effect.Effect<Service> = Effect.gen(function*() {
|
|
|
397
362
|
semaphore.release(1)
|
|
398
363
|
)
|
|
399
364
|
)).pipe(
|
|
400
|
-
provideContextStream,
|
|
401
365
|
Stream.withSpan("Chat.streamText", {
|
|
402
366
|
captureStackTrace: false
|
|
403
367
|
})
|
|
@@ -418,7 +382,6 @@ export const empty: Effect.Effect<Service> = Effect.gen(function*() {
|
|
|
418
382
|
|
|
419
383
|
return response
|
|
420
384
|
},
|
|
421
|
-
provideContext,
|
|
422
385
|
semaphore.withPermits(1),
|
|
423
386
|
(effect, options) =>
|
|
424
387
|
Effect.withSpan(effect, "Chat.generateObject", {
|
|
@@ -429,7 +392,36 @@ export const empty: Effect.Effect<Service> = Effect.gen(function*() {
|
|
|
429
392
|
})
|
|
430
393
|
)
|
|
431
394
|
})
|
|
432
|
-
}
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
/**
|
|
398
|
+
* Creates a new Chat service with empty conversation history.
|
|
399
|
+
*
|
|
400
|
+
* This is the most common way to start a fresh chat session without
|
|
401
|
+
* any initial context or system prompts.
|
|
402
|
+
*
|
|
403
|
+
* @example
|
|
404
|
+
* ```ts
|
|
405
|
+
* import { Effect } from "effect"
|
|
406
|
+
* import { Chat } from "effect/unstable/ai"
|
|
407
|
+
*
|
|
408
|
+
* const freshChat = Effect.gen(function*() {
|
|
409
|
+
* const chat = yield* Chat.empty
|
|
410
|
+
*
|
|
411
|
+
* const response = yield* chat.generateText({
|
|
412
|
+
* prompt: "Hello! Can you introduce yourself?"
|
|
413
|
+
* })
|
|
414
|
+
*
|
|
415
|
+
* console.log(response.content)
|
|
416
|
+
*
|
|
417
|
+
* return chat
|
|
418
|
+
* })
|
|
419
|
+
* ```
|
|
420
|
+
*
|
|
421
|
+
* @since 4.0.0
|
|
422
|
+
* @category constructors
|
|
423
|
+
*/
|
|
424
|
+
export const empty: Effect.Effect<Service> = Effect.sync(() => makeUnsafe(Ref.makeUnsafe(Prompt.empty)))
|
|
433
425
|
|
|
434
426
|
/**
|
|
435
427
|
* Creates a new Chat service from an initial prompt.
|
|
@@ -489,13 +481,8 @@ export const empty: Effect.Effect<Service> = Effect.gen(function*() {
|
|
|
489
481
|
* @since 4.0.0
|
|
490
482
|
* @category constructors
|
|
491
483
|
*/
|
|
492
|
-
export const fromPrompt =
|
|
493
|
-
|
|
494
|
-
const chat = yield* empty
|
|
495
|
-
yield* Ref.set(chat.history, Prompt.make(prompt))
|
|
496
|
-
return chat
|
|
497
|
-
}
|
|
498
|
-
)
|
|
484
|
+
export const fromPrompt = (prompt: Prompt.RawInput) =>
|
|
485
|
+
Effect.sync(() => makeUnsafe(Ref.makeUnsafe(Prompt.make(prompt))))
|
|
499
486
|
|
|
500
487
|
/**
|
|
501
488
|
* Creates a Chat service from previously exported chat data.
|
|
@@ -534,8 +521,7 @@ export const fromPrompt = Effect.fnUntraced(
|
|
|
534
521
|
*/
|
|
535
522
|
export const fromExport = (data: unknown): Effect.Effect<
|
|
536
523
|
Service,
|
|
537
|
-
Schema.SchemaError
|
|
538
|
-
LanguageModel.LanguageModel
|
|
524
|
+
Schema.SchemaError
|
|
539
525
|
> => Effect.flatMap(decodeHistory(data), fromPrompt)
|
|
540
526
|
|
|
541
527
|
/**
|
|
@@ -576,8 +562,7 @@ export const fromExport = (data: unknown): Effect.Effect<
|
|
|
576
562
|
*/
|
|
577
563
|
export const fromJson = (data: string): Effect.Effect<
|
|
578
564
|
Service,
|
|
579
|
-
Schema.SchemaError
|
|
580
|
-
LanguageModel.LanguageModel
|
|
565
|
+
Schema.SchemaError
|
|
581
566
|
> => Effect.flatMap(decodeHistoryJson(data), fromPrompt)
|
|
582
567
|
|
|
583
568
|
// =============================================================================
|
|
@@ -1236,7 +1236,6 @@ export const make: (params: ConstructorParams) => Effect.Effect<Service> = Effec
|
|
|
1236
1236
|
const queue = yield* Queue.make<
|
|
1237
1237
|
Response.StreamPart<Tools>,
|
|
1238
1238
|
| AiError.AiError
|
|
1239
|
-
| AiError.AiErrorReason
|
|
1240
1239
|
| Cause.Done
|
|
1241
1240
|
| Schema.SchemaError
|
|
1242
1241
|
>()
|
|
@@ -1057,7 +1057,8 @@ const compileUriTemplate = (segments: TemplateStringsArray, ...schemas: Readonly
|
|
|
1057
1057
|
const key = String(i)
|
|
1058
1058
|
arr.push(toCodecStringTree)
|
|
1059
1059
|
routerPath += `:${key}${segment.replace(":", "::")}`
|
|
1060
|
-
const
|
|
1060
|
+
const schema = schemas[i]
|
|
1061
|
+
const paramName = isParam(schema) ? (schema as Param<string, Schema.Top>).name : `param${key}`
|
|
1061
1062
|
params[paramName] = toCodecStringTree
|
|
1062
1063
|
uriPath += `{${paramName}}${segment}`
|
|
1063
1064
|
}
|
package/src/unstable/ai/Tool.ts
CHANGED
|
@@ -952,7 +952,7 @@ export type HandlerError<T> = T extends Tool<
|
|
|
952
952
|
infer _Name,
|
|
953
953
|
infer _Config,
|
|
954
954
|
infer _Requirements
|
|
955
|
-
> ? _Config["failureMode"] extends "error" ? _Config["failure"]["Type"] | AiError.AiError
|
|
955
|
+
> ? _Config["failureMode"] extends "error" ? _Config["failure"]["Type"] | AiError.AiError
|
|
956
956
|
: never
|
|
957
957
|
: never
|
|
958
958
|
|
|
@@ -37,7 +37,7 @@ export const toHandled = <E, R, EH, RH>(
|
|
|
37
37
|
const fiber = Fiber.getCurrent()!
|
|
38
38
|
reportCauseUnsafe(fiber, cause)
|
|
39
39
|
const request = ServiceMap.getUnsafe(fiber.services, HttpServerRequest)
|
|
40
|
-
const handler = requestPreResponseHandlers.get(request)
|
|
40
|
+
const handler = requestPreResponseHandlers.get(request.source)
|
|
41
41
|
const cont = cause.reasons.length === 0 ? Effect.succeed(response) : Effect.failCause(cause)
|
|
42
42
|
if (handler === undefined) {
|
|
43
43
|
;(request as any)[handledSymbol] = true
|
|
@@ -60,7 +60,7 @@ export const toHandled = <E, R, EH, RH>(
|
|
|
60
60
|
onSuccess: (response) => {
|
|
61
61
|
const fiber = Fiber.getCurrent()!
|
|
62
62
|
const request = ServiceMap.getUnsafe(fiber.services, HttpServerRequest)
|
|
63
|
-
const handler = requestPreResponseHandlers.get(request)
|
|
63
|
+
const handler = requestPreResponseHandlers.get(request.source)
|
|
64
64
|
if (handler === undefined) {
|
|
65
65
|
;(request as any)[handledSymbol] = true
|
|
66
66
|
return Effect.mapEager(handleResponse(request, response), () => response)
|
|
@@ -46,7 +46,7 @@ export declare namespace HttpMiddleware {
|
|
|
46
46
|
*/
|
|
47
47
|
export const make = <M extends HttpMiddleware>(middleware: M): M => middleware
|
|
48
48
|
|
|
49
|
-
const loggerDisabledRequests = new WeakSet<
|
|
49
|
+
const loggerDisabledRequests = new WeakSet<object>()
|
|
50
50
|
|
|
51
51
|
/**
|
|
52
52
|
* @since 4.0.0
|
|
@@ -55,7 +55,7 @@ const loggerDisabledRequests = new WeakSet<HttpServerRequest>()
|
|
|
55
55
|
export const withLoggerDisabled = <A, E, R>(self: Effect.Effect<A, E, R>): Effect.Effect<A, E, R | HttpServerRequest> =>
|
|
56
56
|
Effect.withFiber((fiber) => {
|
|
57
57
|
const request = ServiceMap.getUnsafe(fiber.services, HttpServerRequest)
|
|
58
|
-
loggerDisabledRequests.add(request)
|
|
58
|
+
loggerDisabledRequests.add(request.source)
|
|
59
59
|
return self
|
|
60
60
|
})
|
|
61
61
|
|
|
@@ -97,7 +97,7 @@ export const logger: <E, R>(
|
|
|
97
97
|
const request = ServiceMap.getUnsafe(fiber.services, HttpServerRequest)
|
|
98
98
|
return Effect.withLogSpan(
|
|
99
99
|
Effect.flatMap(Effect.exit(httpApp), (exit) => {
|
|
100
|
-
if (loggerDisabledRequests.has(request)) {
|
|
100
|
+
if (loggerDisabledRequests.has(request.source)) {
|
|
101
101
|
return exit
|
|
102
102
|
} else if (exit._tag === "Failure") {
|
|
103
103
|
const [response, cause] = causeResponseStripped(exit.cause)
|
|
@@ -43,7 +43,7 @@ export const TypeId = "~effect/http/HttpServerRequest"
|
|
|
43
43
|
*/
|
|
44
44
|
export interface HttpServerRequest extends HttpIncomingMessage.HttpIncomingMessage<HttpServerError> {
|
|
45
45
|
readonly [TypeId]: typeof TypeId
|
|
46
|
-
readonly source:
|
|
46
|
+
readonly source: object
|
|
47
47
|
readonly url: string
|
|
48
48
|
readonly originalUrl: string
|
|
49
49
|
readonly method: HttpMethod
|
|
@@ -3,13 +3,13 @@ import type { PreResponseHandler } from "../HttpEffect.ts"
|
|
|
3
3
|
import type { HttpServerRequest } from "../HttpServerRequest.ts"
|
|
4
4
|
|
|
5
5
|
/** @internal */
|
|
6
|
-
export const requestPreResponseHandlers = new WeakMap<
|
|
6
|
+
export const requestPreResponseHandlers = new WeakMap<object, PreResponseHandler>()
|
|
7
7
|
|
|
8
8
|
/** @internal */
|
|
9
9
|
export const appendPreResponseHandlerUnsafe = (request: HttpServerRequest, handler: PreResponseHandler): void => {
|
|
10
|
-
const prev = requestPreResponseHandlers.get(request)
|
|
10
|
+
const prev = requestPreResponseHandlers.get(request.source)
|
|
11
11
|
const next: PreResponseHandler = prev ?
|
|
12
12
|
(request, response) => Effect.flatMap(prev(request, response), (response) => handler(request, response))
|
|
13
13
|
: handler
|
|
14
|
-
requestPreResponseHandlers.set(request, next)
|
|
14
|
+
requestPreResponseHandlers.set(request.source, next)
|
|
15
15
|
}
|