effect 4.0.0-beta.40 → 4.0.0-beta.42
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 +20 -63
- package/dist/Effect.d.ts.map +1 -1
- package/dist/Effect.js +24 -65
- 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/MutableList.d.ts.map +1 -1
- package/dist/MutableList.js +3 -0
- package/dist/MutableList.js.map +1 -1
- package/dist/Number.d.ts.map +1 -1
- package/dist/Number.js +12 -3
- package/dist/Number.js.map +1 -1
- package/dist/SchemaRepresentation.d.ts.map +1 -1
- package/dist/SchemaRepresentation.js +16 -14
- package/dist/SchemaRepresentation.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/TxChunk.d.ts +39 -39
- package/dist/TxChunk.d.ts.map +1 -1
- package/dist/TxChunk.js +3 -3
- package/dist/TxChunk.js.map +1 -1
- package/dist/TxDeferred.d.ts +9 -9
- package/dist/TxDeferred.d.ts.map +1 -1
- package/dist/TxDeferred.js +2 -2
- package/dist/TxDeferred.js.map +1 -1
- package/dist/TxHashMap.d.ts +59 -59
- package/dist/TxHashMap.d.ts.map +1 -1
- package/dist/TxHashMap.js +8 -8
- package/dist/TxHashMap.js.map +1 -1
- package/dist/TxHashSet.d.ts +35 -35
- package/dist/TxHashSet.d.ts.map +1 -1
- package/dist/TxHashSet.js +7 -7
- package/dist/TxHashSet.js.map +1 -1
- package/dist/TxPriorityQueue.d.ts +23 -23
- package/dist/TxPriorityQueue.d.ts.map +1 -1
- package/dist/TxPriorityQueue.js +4 -4
- package/dist/TxPriorityQueue.js.map +1 -1
- package/dist/TxPubSub.d.ts +14 -14
- package/dist/TxPubSub.d.ts.map +1 -1
- package/dist/TxPubSub.js +12 -12
- package/dist/TxPubSub.js.map +1 -1
- package/dist/TxQueue.d.ts +33 -33
- package/dist/TxQueue.d.ts.map +1 -1
- package/dist/TxQueue.js +29 -44
- package/dist/TxQueue.js.map +1 -1
- package/dist/TxReentrantLock.d.ts +10 -33
- package/dist/TxReentrantLock.d.ts.map +1 -1
- package/dist/TxReentrantLock.js +14 -37
- package/dist/TxReentrantLock.js.map +1 -1
- package/dist/TxRef.d.ts +36 -42
- package/dist/TxRef.d.ts.map +1 -1
- package/dist/TxRef.js +16 -25
- package/dist/TxRef.js.map +1 -1
- package/dist/TxSemaphore.d.ts +8 -8
- package/dist/TxSemaphore.d.ts.map +1 -1
- package/dist/TxSemaphore.js +10 -10
- package/dist/TxSemaphore.js.map +1 -1
- package/dist/TxSubscriptionRef.d.ts +14 -14
- package/dist/TxSubscriptionRef.d.ts.map +1 -1
- package/dist/TxSubscriptionRef.js +5 -5
- package/dist/TxSubscriptionRef.js.map +1 -1
- package/dist/index.d.ts +6 -6
- package/dist/index.js +6 -6
- 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/ai/OpenAiStructuredOutput.js +3 -0
- package/dist/unstable/ai/OpenAiStructuredOutput.js.map +1 -1
- package/dist/unstable/cli/Prompt.js +1 -1
- package/dist/unstable/cli/Prompt.js.map +1 -1
- package/dist/unstable/cli/internal/command.d.ts.map +1 -1
- package/dist/unstable/cli/internal/command.js +12 -1
- package/dist/unstable/cli/internal/command.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 +3 -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/socket/Socket.d.ts +1 -1
- package/dist/unstable/socket/Socket.d.ts.map +1 -1
- package/dist/unstable/socket/Socket.js +1 -1
- package/dist/unstable/socket/Socket.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 +25 -75
- package/src/Layer.ts +1 -1
- package/src/ManagedRuntime.ts +33 -20
- package/src/MutableList.ts +3 -0
- package/src/Number.ts +13 -3
- package/src/SchemaRepresentation.ts +8 -6
- package/src/ServiceMap.ts +16 -31
- package/src/TxChunk.ts +53 -62
- package/src/TxDeferred.ts +14 -17
- package/src/TxHashMap.ts +91 -101
- package/src/TxHashSet.ts +68 -70
- package/src/TxPriorityQueue.ts +34 -38
- package/src/TxPubSub.ts +30 -32
- package/src/TxQueue.ts +70 -84
- package/src/TxReentrantLock.ts +30 -54
- package/src/TxRef.ts +53 -65
- package/src/TxSemaphore.ts +23 -24
- package/src/TxSubscriptionRef.ts +25 -27
- package/src/index.ts +6 -6
- 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/ai/OpenAiStructuredOutput.ts +3 -0
- package/src/unstable/cli/Prompt.ts +3 -1
- package/src/unstable/cli/internal/command.ts +16 -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 +6 -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/socket/Socket.ts +1 -1
- package/src/unstable/workflow/Activity.ts +23 -0
|
@@ -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
|
}
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
import * as Arr from "../../../Array.ts"
|
|
9
9
|
import * as Effect from "../../../Effect.ts"
|
|
10
10
|
import { YieldableProto } from "../../../internal/core.ts"
|
|
11
|
+
import * as Option from "../../../Option.ts"
|
|
11
12
|
import { pipeArguments } from "../../../Pipeable.ts"
|
|
12
13
|
import * as Predicate from "../../../Predicate.ts"
|
|
13
14
|
import * as ServiceMap from "../../../ServiceMap.ts"
|
|
@@ -228,11 +229,25 @@ export const toFlagDoc = (single: Param.Single<typeof Param.flagKind, unknown>):
|
|
|
228
229
|
name: single.name,
|
|
229
230
|
aliases: formattedAliases,
|
|
230
231
|
type: single.typeName ?? Primitive.getTypeName(single.primitiveType),
|
|
231
|
-
description: single.description,
|
|
232
|
+
description: appendChoiceKeys(single.description, Primitive.getChoiceKeys(single.primitiveType)),
|
|
232
233
|
required: single.primitiveType._tag !== "Boolean"
|
|
233
234
|
}
|
|
234
235
|
}
|
|
235
236
|
|
|
237
|
+
const appendChoiceKeys = (
|
|
238
|
+
description: Option.Option<string>,
|
|
239
|
+
choiceKeys: ReadonlyArray<string> | undefined
|
|
240
|
+
): Option.Option<string> => {
|
|
241
|
+
if (choiceKeys === undefined || choiceKeys.length === 0) {
|
|
242
|
+
return description
|
|
243
|
+
}
|
|
244
|
+
const choiceSuffix = `(choices: ${choiceKeys.join(", ")})`
|
|
245
|
+
return Option.match(description, {
|
|
246
|
+
onNone: () => Option.some(choiceSuffix),
|
|
247
|
+
onSome: (value) => Option.some(`${value} ${choiceSuffix}`)
|
|
248
|
+
})
|
|
249
|
+
}
|
|
250
|
+
|
|
236
251
|
/**
|
|
237
252
|
* Creates a parser for a given config. Used as the default for both `parse`
|
|
238
253
|
* and `parseContext`, and also by `withSharedFlags` to avoid constructing a
|
|
@@ -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({
|
|
@@ -5,10 +5,11 @@ import * as Data from "../../Data.ts"
|
|
|
5
5
|
import * as Effect from "../../Effect.ts"
|
|
6
6
|
import * as Option from "../../Option.ts"
|
|
7
7
|
import * as Schema from "../../Schema.ts"
|
|
8
|
-
import
|
|
8
|
+
import * as ServiceMap from "../../ServiceMap.ts"
|
|
9
9
|
import * as Rpc from "../rpc/Rpc.ts"
|
|
10
10
|
import type { PersistenceError } from "./ClusterError.ts"
|
|
11
11
|
import { MalformedMessage } from "./ClusterError.ts"
|
|
12
|
+
import * as ClusterSchema from "./ClusterSchema.ts"
|
|
12
13
|
import type { EntityAddress } from "./EntityAddress.ts"
|
|
13
14
|
import * as Envelope from "./Envelope.ts"
|
|
14
15
|
import type * as Reply from "./Reply.ts"
|
|
@@ -35,6 +36,10 @@ export const incomingLocalFromOutgoing = <R extends Rpc.Any>(self: Outgoing<R>):
|
|
|
35
36
|
return new IncomingEnvelope({ envelope: self.envelope })
|
|
36
37
|
}
|
|
37
38
|
return new IncomingRequestLocal({
|
|
39
|
+
annotations: ServiceMap.get(self.rpc.annotations, ClusterSchema.Dynamic)(
|
|
40
|
+
self.rpc.annotations,
|
|
41
|
+
self.envelope as any
|
|
42
|
+
),
|
|
38
43
|
envelope: self.envelope,
|
|
39
44
|
respond: self.respond,
|
|
40
45
|
lastSentReply: Option.none()
|
|
@@ -59,6 +64,7 @@ export class IncomingRequestLocal<R extends Rpc.Any> extends Data.TaggedClass("I
|
|
|
59
64
|
readonly envelope: Envelope.Request<R>
|
|
60
65
|
readonly lastSentReply: Option.Option<Reply.Reply<R>>
|
|
61
66
|
readonly respond: (reply: Reply.Reply<R>) => Effect.Effect<void, MalformedMessage | PersistenceError>
|
|
67
|
+
readonly annotations: ServiceMap.ServiceMap<never>
|
|
62
68
|
}> {}
|
|
63
69
|
|
|
64
70
|
/**
|
|
@@ -82,10 +88,11 @@ export type Outgoing<R extends Rpc.Any> = OutgoingRequest<R> | OutgoingEnvelope
|
|
|
82
88
|
*/
|
|
83
89
|
export class OutgoingRequest<R extends Rpc.Any> extends Data.TaggedClass("OutgoingRequest")<{
|
|
84
90
|
readonly envelope: Envelope.Request<R>
|
|
85
|
-
readonly services: ServiceMap<Rpc.Services<R>>
|
|
91
|
+
readonly services: ServiceMap.ServiceMap<Rpc.Services<R>>
|
|
86
92
|
readonly lastReceivedReply: Option.Option<Reply.Reply<R>>
|
|
87
93
|
readonly rpc: R
|
|
88
94
|
readonly respond: (reply: Reply.Reply<R>) => Effect.Effect<void>
|
|
95
|
+
readonly annotations: ServiceMap.ServiceMap<never>
|
|
89
96
|
}> {
|
|
90
97
|
/**
|
|
91
98
|
* @since 4.0.0
|
|
@@ -191,15 +198,20 @@ export const deserializeLocal = <Rpc extends Rpc.Any>(
|
|
|
191
198
|
return Schema.decodeEffect(Schema.toCodecJson(rpc.payloadSchema))(encoded.payload).pipe(
|
|
192
199
|
Effect.provideServices(self.services),
|
|
193
200
|
MalformedMessage.refail,
|
|
194
|
-
Effect.map((payload) =>
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
201
|
+
Effect.map((payload) => {
|
|
202
|
+
const envelope = Envelope.makeRequest({
|
|
203
|
+
...encoded,
|
|
204
|
+
payload
|
|
205
|
+
} as any) as Envelope.Request<Rpc>
|
|
206
|
+
return new IncomingRequestLocal({
|
|
207
|
+
envelope,
|
|
200
208
|
lastSentReply: Option.none(),
|
|
201
|
-
respond: self.respond
|
|
209
|
+
respond: self.respond,
|
|
210
|
+
annotations: ServiceMap.get(rpc.annotations, ClusterSchema.Dynamic)(
|
|
211
|
+
rpc.annotations,
|
|
212
|
+
envelope as any
|
|
213
|
+
)
|
|
202
214
|
})
|
|
203
|
-
)
|
|
215
|
+
})
|
|
204
216
|
) as Effect.Effect<IncomingRequestLocal<Rpc>, MalformedMessage>
|
|
205
217
|
}
|