effect 4.0.0-beta.40 → 4.0.0-beta.41
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/BigDecimal.d.ts +36 -0
- package/dist/BigDecimal.d.ts.map +1 -1
- package/dist/BigDecimal.js +52 -0
- package/dist/BigDecimal.js.map +1 -1
- package/dist/Effect.d.ts +1 -0
- package/dist/Effect.d.ts.map +1 -1
- package/dist/Effect.js.map +1 -1
- package/dist/Layer.js +1 -1
- package/dist/Layer.js.map +1 -1
- package/dist/ManagedRuntime.d.ts.map +1 -1
- package/dist/ManagedRuntime.js +19 -7
- package/dist/ManagedRuntime.js.map +1 -1
- package/dist/ServiceMap.d.ts +14 -26
- package/dist/ServiceMap.d.ts.map +1 -1
- package/dist/ServiceMap.js +6 -5
- package/dist/ServiceMap.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +3 -3
- package/dist/internal/effect.js +3 -0
- package/dist/internal/effect.js.map +1 -1
- package/dist/internal/schema/representation.js +28 -0
- package/dist/internal/schema/representation.js.map +1 -1
- package/dist/unstable/ai/Chat.d.ts +31 -2
- package/dist/unstable/ai/Chat.d.ts.map +1 -1
- package/dist/unstable/ai/Chat.js.map +1 -1
- package/dist/unstable/ai/LanguageModel.d.ts +68 -6
- package/dist/unstable/ai/LanguageModel.d.ts.map +1 -1
- package/dist/unstable/ai/LanguageModel.js +88 -11
- package/dist/unstable/ai/LanguageModel.js.map +1 -1
- package/dist/unstable/cli/Prompt.js +1 -1
- package/dist/unstable/cli/Prompt.js.map +1 -1
- package/dist/unstable/cluster/ClusterSchema.d.ts +18 -0
- package/dist/unstable/cluster/ClusterSchema.d.ts.map +1 -1
- package/dist/unstable/cluster/ClusterSchema.js +21 -1
- package/dist/unstable/cluster/ClusterSchema.js.map +1 -1
- package/dist/unstable/cluster/ClusterWorkflowEngine.d.ts.map +1 -1
- package/dist/unstable/cluster/ClusterWorkflowEngine.js +6 -3
- package/dist/unstable/cluster/ClusterWorkflowEngine.js.map +1 -1
- package/dist/unstable/cluster/Entity.d.ts.map +1 -1
- package/dist/unstable/cluster/Entity.js +1 -0
- package/dist/unstable/cluster/Entity.js.map +1 -1
- package/dist/unstable/cluster/Message.d.ts +4 -2
- package/dist/unstable/cluster/Message.d.ts.map +1 -1
- package/dist/unstable/cluster/Message.js +13 -6
- package/dist/unstable/cluster/Message.js.map +1 -1
- package/dist/unstable/cluster/MessageStorage.d.ts +23 -0
- package/dist/unstable/cluster/MessageStorage.d.ts.map +1 -1
- package/dist/unstable/cluster/MessageStorage.js +22 -7
- package/dist/unstable/cluster/MessageStorage.js.map +1 -1
- package/dist/unstable/cluster/Sharding.d.ts.map +1 -1
- package/dist/unstable/cluster/Sharding.js +24 -20
- package/dist/unstable/cluster/Sharding.js.map +1 -1
- package/dist/unstable/cluster/SqlMessageStorage.d.ts.map +1 -1
- package/dist/unstable/cluster/SqlMessageStorage.js +6 -1
- package/dist/unstable/cluster/SqlMessageStorage.js.map +1 -1
- package/dist/unstable/cluster/internal/entityManager.js +10 -4
- package/dist/unstable/cluster/internal/entityManager.js.map +1 -1
- package/dist/unstable/http/index.d.ts +2 -2
- package/dist/unstable/http/index.d.ts.map +1 -1
- package/dist/unstable/http/index.js +2 -2
- package/dist/unstable/http/index.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiSchema.d.ts +1 -3
- package/dist/unstable/httpapi/HttpApiSchema.d.ts.map +1 -1
- package/dist/unstable/httpapi/OpenApi.d.ts +1 -0
- package/dist/unstable/httpapi/OpenApi.d.ts.map +1 -1
- package/dist/unstable/rpc/Rpc.d.ts +1 -0
- package/dist/unstable/rpc/Rpc.d.ts.map +1 -1
- package/dist/unstable/rpc/Rpc.js.map +1 -1
- package/dist/unstable/rpc/RpcClient.d.ts.map +1 -1
- package/dist/unstable/rpc/RpcClient.js +43 -26
- package/dist/unstable/rpc/RpcClient.js.map +1 -1
- package/dist/unstable/workflow/Activity.d.ts +5 -0
- package/dist/unstable/workflow/Activity.d.ts.map +1 -1
- package/dist/unstable/workflow/Activity.js +13 -0
- package/dist/unstable/workflow/Activity.js.map +1 -1
- package/package.json +1 -1
- package/src/BigDecimal.ts +54 -0
- package/src/Effect.ts +1 -0
- package/src/Layer.ts +1 -1
- package/src/ManagedRuntime.ts +33 -20
- package/src/ServiceMap.ts +16 -31
- package/src/index.ts +3 -3
- package/src/internal/effect.ts +3 -0
- package/src/internal/schema/representation.ts +28 -0
- package/src/unstable/ai/Chat.ts +79 -18
- package/src/unstable/ai/LanguageModel.ts +182 -66
- package/src/unstable/cli/Prompt.ts +3 -1
- package/src/unstable/cluster/ClusterSchema.ts +29 -1
- package/src/unstable/cluster/ClusterWorkflowEngine.ts +22 -3
- package/src/unstable/cluster/Entity.ts +1 -0
- package/src/unstable/cluster/Message.ts +22 -10
- package/src/unstable/cluster/MessageStorage.ts +37 -6
- package/src/unstable/cluster/Sharding.ts +31 -23
- package/src/unstable/cluster/SqlMessageStorage.ts +10 -1
- package/src/unstable/cluster/internal/entityManager.ts +14 -5
- package/src/unstable/http/index.ts +2 -2
- package/src/unstable/httpapi/HttpApiSchema.ts +1 -1
- package/src/unstable/httpapi/OpenApi.ts +1 -0
- package/src/unstable/rpc/Rpc.ts +1 -0
- package/src/unstable/rpc/RpcClient.ts +45 -33
- package/src/unstable/workflow/Activity.ts +23 -0
package/src/unstable/ai/Chat.ts
CHANGED
|
@@ -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<
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
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<
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
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
|
|
@@ -120,16 +120,42 @@ export interface Service {
|
|
|
120
120
|
/**
|
|
121
121
|
* Generate text using the language model.
|
|
122
122
|
*/
|
|
123
|
-
readonly generateText:
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
123
|
+
readonly generateText: {
|
|
124
|
+
// No toolkit: force `{}` instead of falling back to `Record<string, Tool.Any>`.
|
|
125
|
+
<Options extends NoExcessProperties<GenerateTextOptionsWithoutToolkit, Options>>(
|
|
126
|
+
options: Options & GenerateTextOptionsWithoutToolkit
|
|
127
|
+
): Effect.Effect<
|
|
128
|
+
GenerateTextResponse<{}>,
|
|
129
|
+
ExtractError<Options>,
|
|
130
|
+
ExtractServices<Options>
|
|
131
|
+
>
|
|
132
|
+
// Generic toolkit: preserve caller-supplied `Tools` in helpers like `<Tools>(toolkit: WithHandler<Tools>) => ...`.
|
|
133
|
+
<
|
|
134
|
+
Tools extends Record<string, Tool.Any>,
|
|
135
|
+
Options extends NoExcessProperties<
|
|
136
|
+
GenerateTextOptions<Tools> & { readonly toolkit: ToolkitInput<Tools> },
|
|
137
|
+
Options
|
|
138
|
+
>
|
|
139
|
+
>(
|
|
140
|
+
options: Options & GenerateTextOptions<Tools> & { readonly toolkit: ToolkitInput<Tools> }
|
|
141
|
+
): Effect.Effect<
|
|
142
|
+
GenerateTextResponse<Tools>,
|
|
143
|
+
ExtractError<Options>,
|
|
144
|
+
ExtractServices<Options>
|
|
145
|
+
>
|
|
146
|
+
// Toolkit unions: recover distributive `ExtractTools<Options>` inference for `toolkitA | toolkitB` call sites.
|
|
147
|
+
<
|
|
148
|
+
Options extends {
|
|
149
|
+
readonly toolkit: ToolkitOption<any>
|
|
150
|
+
} & NoExcessProperties<GenerateTextOptions<any>, Options>
|
|
151
|
+
>(
|
|
152
|
+
options: Options & GenerateTextOptions<ExtractTools<Options>> & { readonly toolkit: Options["toolkit"] }
|
|
153
|
+
): Effect.Effect<
|
|
154
|
+
GenerateTextResponse<ExtractTools<Options>>,
|
|
155
|
+
ExtractError<Options>,
|
|
156
|
+
ExtractServices<Options>
|
|
157
|
+
>
|
|
158
|
+
}
|
|
133
159
|
|
|
134
160
|
/**
|
|
135
161
|
* Generate a structured object from a schema using the language model.
|
|
@@ -153,16 +179,42 @@ export interface Service {
|
|
|
153
179
|
/**
|
|
154
180
|
* Generate text using the language model with streaming output.
|
|
155
181
|
*/
|
|
156
|
-
readonly streamText:
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
182
|
+
readonly streamText: {
|
|
183
|
+
// No toolkit: force `{}` instead of falling back to `Record<string, Tool.Any>`.
|
|
184
|
+
<Options extends NoExcessProperties<GenerateTextOptionsWithoutToolkit, Options>>(
|
|
185
|
+
options: Options & GenerateTextOptionsWithoutToolkit
|
|
186
|
+
): Stream.Stream<
|
|
187
|
+
Response.StreamPart<{}>,
|
|
188
|
+
ExtractError<Options>,
|
|
189
|
+
ExtractServices<Options>
|
|
190
|
+
>
|
|
191
|
+
// Generic toolkit: preserve caller-supplied `Tools` in helpers like `<Tools>(toolkit: WithHandler<Tools>) => ...`.
|
|
192
|
+
<
|
|
193
|
+
Tools extends Record<string, Tool.Any>,
|
|
194
|
+
Options extends NoExcessProperties<
|
|
195
|
+
GenerateTextOptions<Tools> & { readonly toolkit: ToolkitInput<Tools> },
|
|
196
|
+
Options
|
|
197
|
+
>
|
|
198
|
+
>(
|
|
199
|
+
options: Options & GenerateTextOptions<Tools> & { readonly toolkit: ToolkitInput<Tools> }
|
|
200
|
+
): Stream.Stream<
|
|
201
|
+
Response.StreamPart<Tools>,
|
|
202
|
+
ExtractError<Options>,
|
|
203
|
+
ExtractServices<Options>
|
|
204
|
+
>
|
|
205
|
+
// Toolkit unions: recover distributive `ExtractTools<Options>` inference for `toolkitA | toolkitB` call sites.
|
|
206
|
+
<
|
|
207
|
+
Options extends {
|
|
208
|
+
readonly toolkit: ToolkitOption<any>
|
|
209
|
+
} & NoExcessProperties<GenerateTextOptions<any>, Options>
|
|
210
|
+
>(
|
|
211
|
+
options: Options & GenerateTextOptions<ExtractTools<Options>> & { readonly toolkit: Options["toolkit"] }
|
|
212
|
+
): Stream.Stream<
|
|
213
|
+
Response.StreamPart<ExtractTools<Options>>,
|
|
214
|
+
ExtractError<Options>,
|
|
215
|
+
ExtractServices<Options>
|
|
216
|
+
>
|
|
217
|
+
}
|
|
166
218
|
}
|
|
167
219
|
|
|
168
220
|
/**
|
|
@@ -206,7 +258,7 @@ export interface GenerateTextOptions<Tools extends Record<string, Tool.Any>> {
|
|
|
206
258
|
* A toolkit containing both the tools and the tool call handler to use to
|
|
207
259
|
* augment text generation.
|
|
208
260
|
*/
|
|
209
|
-
readonly toolkit?:
|
|
261
|
+
readonly toolkit?: ToolkitInput<Tools> | undefined
|
|
210
262
|
|
|
211
263
|
/**
|
|
212
264
|
* The tool choice mode for the language model.
|
|
@@ -246,6 +298,10 @@ export interface GenerateTextOptions<Tools extends Record<string, Tool.Any>> {
|
|
|
246
298
|
readonly disableToolCallResolution?: boolean | undefined
|
|
247
299
|
}
|
|
248
300
|
|
|
301
|
+
type GenerateTextOptionsWithoutToolkit = Omit<GenerateTextOptions<{}>, "toolkit"> & {
|
|
302
|
+
readonly toolkit?: undefined
|
|
303
|
+
}
|
|
304
|
+
|
|
249
305
|
/**
|
|
250
306
|
* Configuration options for structured object generation.
|
|
251
307
|
*
|
|
@@ -481,6 +537,30 @@ export type ToolkitOption<
|
|
|
481
537
|
)
|
|
482
538
|
: never
|
|
483
539
|
|
|
540
|
+
/**
|
|
541
|
+
* The supported toolkit input shapes for language model operation options.
|
|
542
|
+
*
|
|
543
|
+
* Unlike `ToolkitOption`, this type does not distribute over unions. It is
|
|
544
|
+
* intended for call-site assignability, while `ToolkitOption` remains the
|
|
545
|
+
* distributive helper used for extraction and inference.
|
|
546
|
+
*
|
|
547
|
+
* @since 4.0.0
|
|
548
|
+
* @category utility types
|
|
549
|
+
*/
|
|
550
|
+
export type ToolkitInput<
|
|
551
|
+
Tools extends Record<string, Tool.Any>,
|
|
552
|
+
E = never,
|
|
553
|
+
R = any
|
|
554
|
+
> =
|
|
555
|
+
| ToolkitOption<Tools, E, R>
|
|
556
|
+
| Toolkit.WithHandler<Tools>
|
|
557
|
+
| Effect.Yieldable<
|
|
558
|
+
Toolkit.Toolkit<Tools>,
|
|
559
|
+
Toolkit.WithHandler<Tools>,
|
|
560
|
+
E,
|
|
561
|
+
R
|
|
562
|
+
>
|
|
563
|
+
|
|
484
564
|
type ExtractToolsFromToolkitOption<ToolkitValue> = ToolkitValue extends Toolkit.WithHandler<infer Tools> ? Tools
|
|
485
565
|
: ToolkitValue extends Effect.Yieldable<
|
|
486
566
|
Toolkit.Toolkit<infer Tools>,
|
|
@@ -1509,9 +1589,9 @@ export const make: (params: {
|
|
|
1509
1589
|
}) as any
|
|
1510
1590
|
|
|
1511
1591
|
return {
|
|
1512
|
-
generateText,
|
|
1592
|
+
generateText: generateText as Service["generateText"],
|
|
1513
1593
|
generateObject,
|
|
1514
|
-
streamText
|
|
1594
|
+
streamText: streamText as Service["streamText"]
|
|
1515
1595
|
} as const
|
|
1516
1596
|
})
|
|
1517
1597
|
|
|
@@ -1543,27 +1623,49 @@ export const make: (params: {
|
|
|
1543
1623
|
* @since 4.0.0
|
|
1544
1624
|
* @category text generation
|
|
1545
1625
|
*/
|
|
1546
|
-
export
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1626
|
+
export const generateText: {
|
|
1627
|
+
// No toolkit: force `{}` instead of falling back to `Record<string, Tool.Any>`.
|
|
1628
|
+
<
|
|
1629
|
+
Options extends NoExcessProperties<GenerateTextOptionsWithoutToolkit, Options>
|
|
1630
|
+
>(
|
|
1631
|
+
options: Options & GenerateTextOptionsWithoutToolkit
|
|
1632
|
+
): Effect.Effect<
|
|
1633
|
+
GenerateTextResponse<{}>,
|
|
1634
|
+
ExtractError<Options>,
|
|
1635
|
+
LanguageModel | ExtractServices<Options>
|
|
1636
|
+
>
|
|
1637
|
+
// Generic toolkit: preserve caller-supplied `Tools` in helpers like `<Tools>(toolkit: WithHandler<Tools>) => ...`.
|
|
1638
|
+
<
|
|
1639
|
+
Tools extends Record<string, Tool.Any>,
|
|
1640
|
+
Options extends NoExcessProperties<GenerateTextOptions<Tools> & { readonly toolkit: ToolkitInput<Tools> }, Options>
|
|
1641
|
+
>(
|
|
1642
|
+
options: Options & GenerateTextOptions<Tools> & { readonly toolkit: ToolkitInput<Tools> }
|
|
1643
|
+
): Effect.Effect<
|
|
1644
|
+
GenerateTextResponse<Tools>,
|
|
1645
|
+
ExtractError<Options>,
|
|
1646
|
+
LanguageModel | ExtractServices<Options>
|
|
1647
|
+
>
|
|
1648
|
+
// Toolkit unions: recover distributive `ExtractTools<Options>` inference for `toolkitA | toolkitB` call sites.
|
|
1649
|
+
<
|
|
1650
|
+
Options extends {
|
|
1651
|
+
readonly toolkit: ToolkitOption<any>
|
|
1652
|
+
} & NoExcessProperties<GenerateTextOptions<any>, Options>
|
|
1653
|
+
>(
|
|
1654
|
+
options: Options & GenerateTextOptions<ExtractTools<Options>> & { readonly toolkit: Options["toolkit"] }
|
|
1655
|
+
): Effect.Effect<
|
|
1656
|
+
GenerateTextResponse<ExtractTools<Options>>,
|
|
1657
|
+
ExtractError<Options>,
|
|
1658
|
+
ExtractServices<Options> | LanguageModel
|
|
1659
|
+
>
|
|
1660
|
+
} = (options: GenerateTextOptions<any>): Effect.Effect<
|
|
1558
1661
|
GenerateTextResponse<any>,
|
|
1559
1662
|
AiError.AiError,
|
|
1560
1663
|
LanguageModel
|
|
1561
|
-
>
|
|
1562
|
-
|
|
1664
|
+
> =>
|
|
1665
|
+
Effect.flatMap(
|
|
1563
1666
|
Effect.service(LanguageModel),
|
|
1564
1667
|
(model) => model.generateText(options as any)
|
|
1565
1668
|
)
|
|
1566
|
-
}
|
|
1567
1669
|
|
|
1568
1670
|
/**
|
|
1569
1671
|
* Generate a structured object from a schema using a language model.
|
|
@@ -1597,7 +1699,7 @@ export function generateText(
|
|
|
1597
1699
|
* @since 4.0.0
|
|
1598
1700
|
* @category object generation
|
|
1599
1701
|
*/
|
|
1600
|
-
export
|
|
1702
|
+
export const generateObject = <
|
|
1601
1703
|
ObjectEncoded extends Record<string, any>,
|
|
1602
1704
|
StructuredOutputSchema extends Schema.Encoder<ObjectEncoded, unknown>,
|
|
1603
1705
|
Options extends NoExcessProperties<
|
|
@@ -1610,19 +1712,11 @@ export function generateObject<
|
|
|
1610
1712
|
GenerateObjectResponse<ExtractTools<Options>, StructuredOutputSchema["Type"]>,
|
|
1611
1713
|
ExtractError<Options>,
|
|
1612
1714
|
ExtractServices<Options> | StructuredOutputSchema["DecodingServices"] | LanguageModel
|
|
1613
|
-
>
|
|
1614
|
-
|
|
1615
|
-
options: GenerateObjectOptions<any, Schema.Top>
|
|
1616
|
-
): Effect.Effect<
|
|
1617
|
-
GenerateObjectResponse<any, any>,
|
|
1618
|
-
AiError.AiError,
|
|
1619
|
-
LanguageModel
|
|
1620
|
-
> {
|
|
1621
|
-
return Effect.flatMap(
|
|
1715
|
+
> =>
|
|
1716
|
+
Effect.flatMap(
|
|
1622
1717
|
Effect.service(LanguageModel),
|
|
1623
1718
|
(model) => model.generateObject(options as any)
|
|
1624
1719
|
) as any
|
|
1625
|
-
}
|
|
1626
1720
|
|
|
1627
1721
|
/**
|
|
1628
1722
|
* Generate text using a language model with streaming output.
|
|
@@ -1648,27 +1742,49 @@ export function generateObject(
|
|
|
1648
1742
|
* @since 4.0.0
|
|
1649
1743
|
* @category text generation
|
|
1650
1744
|
*/
|
|
1651
|
-
export
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1745
|
+
export const streamText: {
|
|
1746
|
+
// No toolkit: force `{}` instead of falling back to `Record<string, Tool.Any>`.
|
|
1747
|
+
<
|
|
1748
|
+
Options extends NoExcessProperties<GenerateTextOptionsWithoutToolkit, Options>
|
|
1749
|
+
>(
|
|
1750
|
+
options: Options & GenerateTextOptionsWithoutToolkit
|
|
1751
|
+
): Stream.Stream<
|
|
1752
|
+
Response.StreamPart<{}>,
|
|
1753
|
+
ExtractError<Options>,
|
|
1754
|
+
ExtractServices<Options> | LanguageModel
|
|
1755
|
+
>
|
|
1756
|
+
// Generic toolkit: preserve caller-supplied `Tools` in helpers like `<Tools>(toolkit: WithHandler<Tools>) => ...`.
|
|
1757
|
+
<
|
|
1758
|
+
Tools extends Record<string, Tool.Any>,
|
|
1759
|
+
Options extends NoExcessProperties<GenerateTextOptions<Tools> & { readonly toolkit: ToolkitInput<Tools> }, Options>
|
|
1760
|
+
>(
|
|
1761
|
+
options: Options & GenerateTextOptions<Tools> & { readonly toolkit: ToolkitInput<Tools> }
|
|
1762
|
+
): Stream.Stream<
|
|
1763
|
+
Response.StreamPart<Tools>,
|
|
1764
|
+
ExtractError<Options>,
|
|
1765
|
+
ExtractServices<Options> | LanguageModel
|
|
1766
|
+
>
|
|
1767
|
+
// Toolkit unions: recover distributive `ExtractTools<Options>` inference for `toolkitA | toolkitB` call sites.
|
|
1768
|
+
<
|
|
1769
|
+
Options extends {
|
|
1770
|
+
readonly toolkit: ToolkitOption<any>
|
|
1771
|
+
} & NoExcessProperties<GenerateTextOptions<any>, Options>
|
|
1772
|
+
>(
|
|
1773
|
+
options: Options & GenerateTextOptions<ExtractTools<Options>> & { readonly toolkit: Options["toolkit"] }
|
|
1774
|
+
): Stream.Stream<
|
|
1775
|
+
Response.StreamPart<ExtractTools<Options>>,
|
|
1776
|
+
ExtractError<Options>,
|
|
1777
|
+
ExtractServices<Options> | LanguageModel
|
|
1778
|
+
>
|
|
1779
|
+
} = (options: GenerateTextOptions<any>): Stream.Stream<
|
|
1780
|
+
Response.StreamPart<{}>,
|
|
1664
1781
|
AiError.AiError,
|
|
1665
1782
|
LanguageModel
|
|
1666
|
-
>
|
|
1667
|
-
|
|
1783
|
+
> =>
|
|
1784
|
+
Stream.unwrap(Effect.map(
|
|
1668
1785
|
Effect.service(LanguageModel),
|
|
1669
1786
|
(model) => model.streamText(options as any)
|
|
1670
1787
|
)) as any
|
|
1671
|
-
}
|
|
1672
1788
|
|
|
1673
1789
|
// =============================================================================
|
|
1674
1790
|
// Tool Approval Helpers
|
|
@@ -2045,7 +2161,7 @@ const resolveToolCalls = <Tools extends Record<string, Tool.Any>>(
|
|
|
2045
2161
|
// =============================================================================
|
|
2046
2162
|
|
|
2047
2163
|
const resolveToolkit = <Tools extends Record<string, Tool.Any>, E, R>(
|
|
2048
|
-
toolkit:
|
|
2164
|
+
toolkit: ToolkitInput<Tools, E, R>
|
|
2049
2165
|
): Effect.Effect<Toolkit.WithHandler<Tools>, E, R> =>
|
|
2050
2166
|
("asEffect" in toolkit
|
|
2051
2167
|
? toolkit.asEffect()
|
|
@@ -2356,7 +2356,9 @@ const renderMultiSelectChoices = <A>(
|
|
|
2356
2356
|
const annotatedCheckbox = isHighlighted && renderOptions?.plain !== true
|
|
2357
2357
|
? Ansi.annotate(checkbox, Ansi.cyanBright)
|
|
2358
2358
|
: checkbox
|
|
2359
|
-
const title =
|
|
2359
|
+
const title = isHighlighted && renderOptions?.plain !== true
|
|
2360
|
+
? Ansi.annotate(choice.title, Ansi.cyanBright)
|
|
2361
|
+
: choice.title
|
|
2360
2362
|
const description = renderChoiceDescription(choice as SelectChoice<A>, isHighlighted, renderOptions)
|
|
2361
2363
|
documents.push(prefix + " " + annotatedCheckbox + " " + title + " " + description)
|
|
2362
2364
|
}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @since 4.0.0
|
|
3
3
|
*/
|
|
4
|
-
import { constFalse, constTrue } from "../../Function.ts"
|
|
4
|
+
import { constFalse, constTrue, identity } from "../../Function.ts"
|
|
5
5
|
import * as ServiceMap from "../../ServiceMap.ts"
|
|
6
|
+
import type * as Rpc from "../rpc/Rpc.ts"
|
|
6
7
|
import type { EntityId } from "./EntityId.ts"
|
|
8
|
+
import type { Request } from "./Envelope.ts"
|
|
7
9
|
|
|
8
10
|
/**
|
|
9
11
|
* @since 4.0.0
|
|
@@ -13,6 +15,18 @@ export const Persisted = ServiceMap.Reference<boolean>("effect/cluster/ClusterSc
|
|
|
13
15
|
defaultValue: constFalse
|
|
14
16
|
})
|
|
15
17
|
|
|
18
|
+
/**
|
|
19
|
+
* Whether to wrap the request with a storage transaction, so sql queries are
|
|
20
|
+
* committed atomically.
|
|
21
|
+
*
|
|
22
|
+
* @since 4.0.0
|
|
23
|
+
* @category Annotations
|
|
24
|
+
*/
|
|
25
|
+
export const WithTransaction = ServiceMap.Reference<boolean>(
|
|
26
|
+
"effect/cluster/ClusterSchema/WithTransaction",
|
|
27
|
+
{ defaultValue: constFalse }
|
|
28
|
+
)
|
|
29
|
+
|
|
16
30
|
/**
|
|
17
31
|
* @since 4.0.0
|
|
18
32
|
* @category Annotations
|
|
@@ -56,3 +70,17 @@ export const ShardGroup = ServiceMap.Reference<(entityId: EntityId) => string>(
|
|
|
56
70
|
export const ClientTracingEnabled = ServiceMap.Reference<boolean>("effect/cluster/ClusterSchema/ClientTracingEnabled", {
|
|
57
71
|
defaultValue: constTrue
|
|
58
72
|
})
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Dynamically transform the request annotations based on the request.
|
|
76
|
+
* This only applies to the requests handled by the Entity, not the client.
|
|
77
|
+
*
|
|
78
|
+
* @since 4.0.0
|
|
79
|
+
* @category Annotations
|
|
80
|
+
*/
|
|
81
|
+
export const Dynamic = ServiceMap.Reference<
|
|
82
|
+
(annotations: ServiceMap.ServiceMap<never>, request: Request<Rpc.AnyWithProps>) => ServiceMap.ServiceMap<never>
|
|
83
|
+
>(
|
|
84
|
+
"effect/cluster/ClusterSchema/Dynamic",
|
|
85
|
+
{ defaultValue: () => identity }
|
|
86
|
+
)
|
|
@@ -6,6 +6,7 @@ import * as Duration from "../../Duration.ts"
|
|
|
6
6
|
import * as Effect from "../../Effect.ts"
|
|
7
7
|
import * as Exit from "../../Exit.ts"
|
|
8
8
|
import * as Fiber from "../../Fiber.ts"
|
|
9
|
+
import { constFalse } from "../../Function.ts"
|
|
9
10
|
import * as Latch from "../../Latch.ts"
|
|
10
11
|
import * as Layer from "../../Layer.ts"
|
|
11
12
|
import * as Option from "../../Option.ts"
|
|
@@ -66,7 +67,9 @@ export const make = Effect.gen(function*() {
|
|
|
66
67
|
| Rpc.Rpc<"deferred", Schema.Struct<{ name: typeof Schema.String; exit: typeof ExitUnknown }>, typeof ExitUnknown>
|
|
67
68
|
| Rpc.Rpc<
|
|
68
69
|
"activity",
|
|
69
|
-
Schema.Struct<
|
|
70
|
+
Schema.Struct<
|
|
71
|
+
{ name: typeof Schema.String; attempt: typeof Schema.Number; withTransaction: typeof Schema.Boolean }
|
|
72
|
+
>,
|
|
70
73
|
Schema.declare<Workflow.Result<any, any>>
|
|
71
74
|
>
|
|
72
75
|
| Rpc.Rpc<"resume", Schema.Struct<{}>>
|
|
@@ -435,7 +438,13 @@ export const make = Effect.gen(function*() {
|
|
|
435
438
|
activityLatches.delete(activityId)
|
|
436
439
|
}
|
|
437
440
|
}
|
|
438
|
-
const result = yield* Effect.orDie(
|
|
441
|
+
const result = yield* Effect.orDie(
|
|
442
|
+
client.activity({
|
|
443
|
+
name: activity.name,
|
|
444
|
+
attempt,
|
|
445
|
+
withTransaction: ServiceMap.get(activity.annotations, ClusterSchema.WithTransaction)
|
|
446
|
+
})
|
|
447
|
+
)
|
|
439
448
|
// If the activity has suspended and did not execute, we need to resume
|
|
440
449
|
// it by resetting the attempt and re-executing.
|
|
441
450
|
if (result._tag === "Suspended" && (activities.has(activityId) || interruptedActivities.has(activityId))) {
|
|
@@ -532,7 +541,10 @@ const ExitUnknown = Schema.Exit(AnyOrVoid, AnyOrVoid, Schema.Any)
|
|
|
532
541
|
const ActivityRpc = Rpc.make("activity", {
|
|
533
542
|
payload: {
|
|
534
543
|
name: Schema.String,
|
|
535
|
-
attempt: Schema.Number
|
|
544
|
+
attempt: Schema.Number,
|
|
545
|
+
withTransaction: Schema.Boolean.pipe(
|
|
546
|
+
Schema.withDecodingDefault(constFalse)
|
|
547
|
+
)
|
|
536
548
|
},
|
|
537
549
|
primaryKey: ({ attempt, name }) => activityPrimaryKey(name, attempt),
|
|
538
550
|
success: Workflow.Result({
|
|
@@ -541,6 +553,13 @@ const ActivityRpc = Rpc.make("activity", {
|
|
|
541
553
|
})
|
|
542
554
|
})
|
|
543
555
|
.annotate(ClusterSchema.Persisted, true)
|
|
556
|
+
.annotate(
|
|
557
|
+
ClusterSchema.Dynamic,
|
|
558
|
+
(annotations, request) =>
|
|
559
|
+
(request.payload as any).withTransaction
|
|
560
|
+
? ServiceMap.add(annotations, ClusterSchema.WithTransaction, true)
|
|
561
|
+
: annotations
|
|
562
|
+
)
|
|
544
563
|
|
|
545
564
|
const DeferredRpc = Rpc.make("deferred", {
|
|
546
565
|
payload: {
|
|
@@ -608,6 +608,7 @@ export const keepAlive: (
|
|
|
608
608
|
olatch.value.closeUnsafe()
|
|
609
609
|
yield* Effect.orDie(sharding.sendOutgoing(
|
|
610
610
|
new Message.OutgoingRequest({
|
|
611
|
+
annotations: ServiceMap.empty(),
|
|
611
612
|
rpc: KeepAliveRpc,
|
|
612
613
|
services: ServiceMap.empty() as any,
|
|
613
614
|
envelope: Envelope.makeRequest({
|