ai 3.0.12 → 3.0.14
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/README.md +1 -1
- package/ai-model-specification/dist/index.d.mts +704 -0
- package/ai-model-specification/dist/index.d.ts +704 -0
- package/ai-model-specification/dist/index.js +806 -0
- package/ai-model-specification/dist/index.js.map +1 -0
- package/ai-model-specification/dist/index.mjs +742 -0
- package/ai-model-specification/dist/index.mjs.map +1 -0
- package/dist/index.d.mts +686 -4
- package/dist/index.d.ts +686 -4
- package/dist/index.js +1723 -15
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1700 -15
- package/dist/index.mjs.map +1 -1
- package/mistral/dist/index.d.mts +367 -0
- package/mistral/dist/index.d.ts +367 -0
- package/mistral/dist/index.js +936 -0
- package/mistral/dist/index.js.map +1 -0
- package/mistral/dist/index.mjs +900 -0
- package/mistral/dist/index.mjs.map +1 -0
- package/openai/dist/index.d.mts +430 -0
- package/openai/dist/index.d.ts +430 -0
- package/openai/dist/index.js +1355 -0
- package/openai/dist/index.js.map +1 -0
- package/openai/dist/index.mjs +1319 -0
- package/openai/dist/index.mjs.map +1 -0
- package/package.json +33 -7
- package/prompts/dist/index.d.mts +13 -1
- package/prompts/dist/index.d.ts +13 -1
- package/prompts/dist/index.js +13 -0
- package/prompts/dist/index.js.map +1 -1
- package/prompts/dist/index.mjs +12 -0
- package/prompts/dist/index.mjs.map +1 -1
- package/react/dist/index.d.mts +8 -4
- package/react/dist/index.d.ts +8 -4
- package/react/dist/index.js +36 -34
- package/react/dist/index.js.map +1 -1
- package/react/dist/index.mjs +36 -34
- package/react/dist/index.mjs.map +1 -1
- package/rsc/dist/index.d.ts +45 -8
- package/rsc/dist/rsc-server.d.mts +45 -8
- package/rsc/dist/rsc-server.mjs +67 -13
- package/rsc/dist/rsc-server.mjs.map +1 -1
- package/rsc/dist/rsc-shared.d.mts +5 -8
- package/rsc/dist/rsc-shared.mjs +23 -2
- package/rsc/dist/rsc-shared.mjs.map +1 -1
- package/solid/dist/index.js +29 -27
- package/solid/dist/index.js.map +1 -1
- package/solid/dist/index.mjs +29 -27
- package/solid/dist/index.mjs.map +1 -1
- package/svelte/dist/index.js +31 -29
- package/svelte/dist/index.js.map +1 -1
- package/svelte/dist/index.mjs +31 -29
- package/svelte/dist/index.mjs.map +1 -1
- package/vue/dist/index.js +29 -27
- package/vue/dist/index.js.map +1 -1
- package/vue/dist/index.mjs +29 -27
- package/vue/dist/index.mjs.map +1 -1
package/dist/index.d.ts
CHANGED
@@ -1,7 +1,684 @@
|
|
1
|
+
import { z } from 'zod';
|
1
2
|
import { AssistantStream } from 'openai/lib/AssistantStream';
|
3
|
+
import { Run } from 'openai/resources/beta/threads/runs/runs';
|
2
4
|
import { ChatCompletionResponseChunk } from '@mistralai/mistralai';
|
3
5
|
import { ServerResponse } from 'node:http';
|
4
6
|
|
7
|
+
type JsonSchema = Record<string, unknown>;
|
8
|
+
|
9
|
+
type LanguageModelV1CallSettings = {
|
10
|
+
/**
|
11
|
+
* Maximum number of tokens to generate.
|
12
|
+
*/
|
13
|
+
maxTokens?: number;
|
14
|
+
/**
|
15
|
+
* Temperature setting. This is a number between 0 (almost no randomness) and
|
16
|
+
* 1 (very random).
|
17
|
+
*
|
18
|
+
* Different LLM providers have different temperature
|
19
|
+
* scales, so they'd need to map it (without mapping, the same temperature has
|
20
|
+
* different effects on different models). The provider can also chose to map
|
21
|
+
* this to topP, potentially even using a custom setting on their model.
|
22
|
+
*
|
23
|
+
* Note: This is an example of a setting that requires a clear specification of
|
24
|
+
* the semantics.
|
25
|
+
*/
|
26
|
+
temperature?: number;
|
27
|
+
/**
|
28
|
+
* Nucleus sampling. This is a number between 0 and 1.
|
29
|
+
*
|
30
|
+
* E.g. 0.1 would mean that only tokens with the top 10% probability mass
|
31
|
+
* are considered.
|
32
|
+
*
|
33
|
+
* It is recommended to set either `temperature` or `topP`, but not both.
|
34
|
+
*/
|
35
|
+
topP?: number;
|
36
|
+
/**
|
37
|
+
* Presence penalty setting. It affects the likelihood of the model to
|
38
|
+
* repeat information that is already in the prompt.
|
39
|
+
*
|
40
|
+
* The presence penalty is a number between -1 (increase repetition)
|
41
|
+
* and 1 (maximum penalty, decrease repetition). 0 means no penalty.
|
42
|
+
*/
|
43
|
+
presencePenalty?: number;
|
44
|
+
/**
|
45
|
+
* Frequency penalty setting. It affects the likelihood of the model
|
46
|
+
* to repeatedly use the same words or phrases.
|
47
|
+
*
|
48
|
+
* The frequency penalty is a number between -1 (increase repetition)
|
49
|
+
* and 1 (maximum penalty, decrease repetition). 0 means no penalty.
|
50
|
+
*/
|
51
|
+
frequencyPenalty?: number;
|
52
|
+
/**
|
53
|
+
* The seed (integer) to use for random sampling. If set and supported
|
54
|
+
* by the model, calls will generate deterministic results.
|
55
|
+
*/
|
56
|
+
seed?: number;
|
57
|
+
/**
|
58
|
+
* Abort signal for cancelling the operation.
|
59
|
+
*/
|
60
|
+
abortSignal?: AbortSignal;
|
61
|
+
};
|
62
|
+
|
63
|
+
/**
|
64
|
+
* A tool has a name, a description, and a set of parameters.
|
65
|
+
*
|
66
|
+
* Note: this is **not** the user-facing tool definition. The AI SDK methods will
|
67
|
+
* map the user-facing tool definitions to this format.
|
68
|
+
*/
|
69
|
+
type LanguageModelV1FunctionTool = {
|
70
|
+
/**
|
71
|
+
* The type of the tool. Only functions for now, but this gives us room to
|
72
|
+
* add more specific tool types in the future and use a discriminated union.
|
73
|
+
*/
|
74
|
+
type: 'function';
|
75
|
+
/**
|
76
|
+
* The name of the tool. Unique within this model call.
|
77
|
+
*/
|
78
|
+
name: string;
|
79
|
+
description?: string;
|
80
|
+
parameters: JsonSchema;
|
81
|
+
};
|
82
|
+
|
83
|
+
/**
|
84
|
+
* A prompt is a list of messages.
|
85
|
+
*
|
86
|
+
* Note: Not all models and prompt formats support multi-modal inputs and
|
87
|
+
* tool calls. The validation happens at runtime.
|
88
|
+
*
|
89
|
+
* Note: This is not a user-facing prompt. The AI SDK methods will map the
|
90
|
+
* user-facing prompt types such as chat or instruction prompts to this format.
|
91
|
+
*/
|
92
|
+
type LanguageModelV1Prompt = Array<LanguageModelV1Message>;
|
93
|
+
type LanguageModelV1Message = {
|
94
|
+
role: 'system';
|
95
|
+
content: string;
|
96
|
+
} | {
|
97
|
+
role: 'user';
|
98
|
+
content: Array<LanguageModelV1TextPart | LanguageModelV1ImagePart>;
|
99
|
+
} | {
|
100
|
+
role: 'assistant';
|
101
|
+
content: Array<LanguageModelV1TextPart | LanguageModelV1ToolCallPart>;
|
102
|
+
} | {
|
103
|
+
role: 'tool';
|
104
|
+
content: Array<LanguageModelV1ToolResultPart>;
|
105
|
+
};
|
106
|
+
interface LanguageModelV1TextPart {
|
107
|
+
type: 'text';
|
108
|
+
/**
|
109
|
+
* The text content.
|
110
|
+
*/
|
111
|
+
text: string;
|
112
|
+
}
|
113
|
+
interface LanguageModelV1ImagePart {
|
114
|
+
type: 'image';
|
115
|
+
/**
|
116
|
+
* Image data as a Uint8Array (e.g. from a Blob or Buffer) or a URL.
|
117
|
+
*/
|
118
|
+
image: Uint8Array | URL;
|
119
|
+
/**
|
120
|
+
* Optional mime type of the image.
|
121
|
+
*/
|
122
|
+
mimeType?: string;
|
123
|
+
}
|
124
|
+
interface LanguageModelV1ToolCallPart {
|
125
|
+
type: 'tool-call';
|
126
|
+
toolCallId: string;
|
127
|
+
toolName: string;
|
128
|
+
args: unknown;
|
129
|
+
}
|
130
|
+
interface LanguageModelV1ToolResultPart {
|
131
|
+
type: 'tool-result';
|
132
|
+
toolCallId: string;
|
133
|
+
toolName: string;
|
134
|
+
result: unknown;
|
135
|
+
}
|
136
|
+
|
137
|
+
type LanguageModelV1CallOptions = LanguageModelV1CallSettings & {
|
138
|
+
/**
|
139
|
+
* Whether the user provided the input as messages or as
|
140
|
+
* a prompt. This can help guide non-chat models in the
|
141
|
+
* expansion, bc different expansions can be needed for
|
142
|
+
* chat/non-chat use cases.
|
143
|
+
*/
|
144
|
+
inputFormat: 'messages' | 'prompt';
|
145
|
+
/**
|
146
|
+
* The mode affects the behavior of the language model. It is required to
|
147
|
+
* support provider-independent streaming and generation of structured objects.
|
148
|
+
* The model can take this information and e.g. configure json mode, the correct
|
149
|
+
* low level grammar, etc. It can also be used to optimize the efficiency of the
|
150
|
+
* streaming, e.g. tool-delta stream parts are only needed in the
|
151
|
+
* object-tool mode.
|
152
|
+
*/
|
153
|
+
mode: {
|
154
|
+
type: 'regular';
|
155
|
+
tools?: Array<LanguageModelV1FunctionTool>;
|
156
|
+
} | {
|
157
|
+
type: 'object-json';
|
158
|
+
} | {
|
159
|
+
type: 'object-grammar';
|
160
|
+
schema: JsonSchema;
|
161
|
+
} | {
|
162
|
+
type: 'object-tool';
|
163
|
+
tool: LanguageModelV1FunctionTool;
|
164
|
+
};
|
165
|
+
/**
|
166
|
+
* A language mode prompt is a standardized prompt type.
|
167
|
+
*
|
168
|
+
* Note: This is **not** the user-facing prompt. The AI SDK methods will map the
|
169
|
+
* user-facing prompt types such as chat or instruction prompts to this format.
|
170
|
+
* That approach allows us to evolve the user facing prompts without breaking
|
171
|
+
* the language model interface.
|
172
|
+
*/
|
173
|
+
prompt: LanguageModelV1Prompt;
|
174
|
+
};
|
175
|
+
|
176
|
+
/**
|
177
|
+
* Warning from the model provider for this call. The call will proceed, but e.g.
|
178
|
+
* some settings might not be supported, which can lead to suboptimal results.
|
179
|
+
*/
|
180
|
+
type LanguageModelV1CallWarning = {
|
181
|
+
type: 'unsupported-setting';
|
182
|
+
setting: keyof LanguageModelV1CallSettings;
|
183
|
+
} | {
|
184
|
+
type: 'other';
|
185
|
+
message: string;
|
186
|
+
};
|
187
|
+
|
188
|
+
type LanguageModelV1FinishReason = 'stop' | 'length' | 'content-filter' | 'tool-calls' | 'error' | 'other';
|
189
|
+
|
190
|
+
type LanguageModelV1FunctionToolCall = {
|
191
|
+
toolCallType: 'function';
|
192
|
+
toolCallId: string;
|
193
|
+
toolName: string;
|
194
|
+
/**
|
195
|
+
* Stringified JSON object with the tool call arguments. Must match the
|
196
|
+
* parameters schema of the tool.
|
197
|
+
*/
|
198
|
+
args: string;
|
199
|
+
};
|
200
|
+
|
201
|
+
type LanguageModelV1 = {
|
202
|
+
/**
|
203
|
+
* The language model must specify which language model interface
|
204
|
+
* version it implements. This will allow us to evolve the language
|
205
|
+
* model interface and retain backwards compatibility. The different
|
206
|
+
* implementation versions can be handled as a discriminated union
|
207
|
+
* on our side.
|
208
|
+
*/
|
209
|
+
readonly specificationVersion: 'v1';
|
210
|
+
/**
|
211
|
+
* Name of the provider for logging purposes.
|
212
|
+
*/
|
213
|
+
readonly provider: string;
|
214
|
+
/**
|
215
|
+
* Provider-specific model ID for logging purposes.
|
216
|
+
*/
|
217
|
+
readonly modelId: string;
|
218
|
+
/**
|
219
|
+
* Default object generation mode that should be used with this model when
|
220
|
+
* no mode is specified. Should be the mode with the best results for this
|
221
|
+
* model. `undefined` can be returned if object generation is not supported.
|
222
|
+
*
|
223
|
+
* This is needed to generate the best objects possible w/o requiring the
|
224
|
+
* user to explicitly specify the object generation mode.
|
225
|
+
*/
|
226
|
+
readonly defaultObjectGenerationMode: 'json' | 'tool' | 'grammar' | undefined;
|
227
|
+
/**
|
228
|
+
* Generates a language model output (non-streaming).
|
229
|
+
*
|
230
|
+
* Naming: "do" prefix to prevent accidental direct usage of the method
|
231
|
+
* by the user.
|
232
|
+
*/
|
233
|
+
doGenerate(options: LanguageModelV1CallOptions): PromiseLike<{
|
234
|
+
/**
|
235
|
+
* Text that the model has generated. Can be undefined if the model
|
236
|
+
* has only generated tool calls.
|
237
|
+
*/
|
238
|
+
text?: string;
|
239
|
+
/**
|
240
|
+
* Tool calls that the model has generated. Can be undefined if the
|
241
|
+
* model has only generated text.
|
242
|
+
*/
|
243
|
+
toolCalls?: Array<LanguageModelV1FunctionToolCall>;
|
244
|
+
/**
|
245
|
+
* Finish reason.
|
246
|
+
*/
|
247
|
+
finishReason: LanguageModelV1FinishReason;
|
248
|
+
/**
|
249
|
+
* Usage information.
|
250
|
+
*/
|
251
|
+
usage: {
|
252
|
+
promptTokens: number;
|
253
|
+
completionTokens: number;
|
254
|
+
};
|
255
|
+
/**
|
256
|
+
* Raw prompt and setting information for observability provider integration.
|
257
|
+
*/
|
258
|
+
rawCall: {
|
259
|
+
/**
|
260
|
+
* Raw prompt after expansion and conversion to the format that the
|
261
|
+
* provider uses to send the information to their API.
|
262
|
+
*/
|
263
|
+
rawPrompt: unknown;
|
264
|
+
/**
|
265
|
+
* Raw settings that are used for the API call. Includes provider-specific
|
266
|
+
* settings.
|
267
|
+
*/
|
268
|
+
rawSettings: Record<string, unknown>;
|
269
|
+
};
|
270
|
+
warnings?: LanguageModelV1CallWarning[];
|
271
|
+
}>;
|
272
|
+
/**
|
273
|
+
* Generates a language model output (streaming).
|
274
|
+
*
|
275
|
+
* Naming: "do" prefix to prevent accidental direct usage of the method
|
276
|
+
* by the user.
|
277
|
+
*
|
278
|
+
* @return A stream of higher-level language model output parts.
|
279
|
+
*/
|
280
|
+
doStream(options: LanguageModelV1CallOptions): PromiseLike<{
|
281
|
+
stream: ReadableStream<LanguageModelV1StreamPart>;
|
282
|
+
/**
|
283
|
+
* Raw prompt and setting information for observability provider integration.
|
284
|
+
*/
|
285
|
+
rawCall: {
|
286
|
+
/**
|
287
|
+
* Raw prompt after expansion and conversion to the format that the
|
288
|
+
* provider uses to send the information to their API.
|
289
|
+
*/
|
290
|
+
rawPrompt: unknown;
|
291
|
+
/**
|
292
|
+
* Raw settings that are used for the API call. Includes provider-specific
|
293
|
+
* settings.
|
294
|
+
*/
|
295
|
+
rawSettings: Record<string, unknown>;
|
296
|
+
};
|
297
|
+
warnings?: LanguageModelV1CallWarning[];
|
298
|
+
}>;
|
299
|
+
};
|
300
|
+
type LanguageModelV1StreamPart = {
|
301
|
+
type: 'text-delta';
|
302
|
+
textDelta: string;
|
303
|
+
} | ({
|
304
|
+
type: 'tool-call';
|
305
|
+
} & LanguageModelV1FunctionToolCall) | {
|
306
|
+
type: 'tool-call-delta';
|
307
|
+
toolCallType: 'function';
|
308
|
+
toolCallId: string;
|
309
|
+
toolName: string;
|
310
|
+
argsTextDelta: string;
|
311
|
+
} | {
|
312
|
+
type: 'finish';
|
313
|
+
finishReason: LanguageModelV1FinishReason;
|
314
|
+
usage: {
|
315
|
+
promptTokens: number;
|
316
|
+
completionTokens: number;
|
317
|
+
};
|
318
|
+
} | {
|
319
|
+
type: 'error';
|
320
|
+
error: unknown;
|
321
|
+
};
|
322
|
+
|
323
|
+
type TokenUsage = {
|
324
|
+
promptTokens: number;
|
325
|
+
completionTokens: number;
|
326
|
+
totalTokens: number;
|
327
|
+
};
|
328
|
+
|
329
|
+
type CallSettings = {
|
330
|
+
/**
|
331
|
+
* Maximum number of tokens to generate.
|
332
|
+
*/
|
333
|
+
maxTokens?: number;
|
334
|
+
/**
|
335
|
+
* Temperature setting. This is a number between 0 (almost no randomness) and
|
336
|
+
* 1 (very random).
|
337
|
+
*
|
338
|
+
* It is recommended to set either `temperature` or `topP`, but not both.
|
339
|
+
*
|
340
|
+
* @default 0
|
341
|
+
*/
|
342
|
+
temperature?: number;
|
343
|
+
/**
|
344
|
+
* Nucleus sampling. This is a number between 0 and 1.
|
345
|
+
*
|
346
|
+
* E.g. 0.1 would mean that only tokens with the top 10% probability mass
|
347
|
+
* are considered.
|
348
|
+
*
|
349
|
+
* It is recommended to set either `temperature` or `topP`, but not both.
|
350
|
+
*/
|
351
|
+
topP?: number;
|
352
|
+
/**
|
353
|
+
* Presence penalty setting. It affects the likelihood of the model to
|
354
|
+
* repeat information that is already in the prompt.
|
355
|
+
*
|
356
|
+
* The presence penalty is a number between -1 (increase repetition)
|
357
|
+
* and 1 (maximum penalty, decrease repetition). 0 means no penalty.
|
358
|
+
*
|
359
|
+
* @default 0
|
360
|
+
*/
|
361
|
+
presencePenalty?: number;
|
362
|
+
/**
|
363
|
+
* Frequency penalty setting. It affects the likelihood of the model
|
364
|
+
* to repeatedly use the same words or phrases.
|
365
|
+
*
|
366
|
+
* The frequency penalty is a number between -1 (increase repetition)
|
367
|
+
* and 1 (maximum penalty, decrease repetition). 0 means no penalty.
|
368
|
+
*
|
369
|
+
* @default 0
|
370
|
+
*/
|
371
|
+
frequencyPenalty?: number;
|
372
|
+
/**
|
373
|
+
* The seed (integer) to use for random sampling. If set and supported
|
374
|
+
* by the model, calls will generate deterministic results.
|
375
|
+
*/
|
376
|
+
seed?: number;
|
377
|
+
/**
|
378
|
+
* Maximum number of retries. Set to 0 to disable retries.
|
379
|
+
*
|
380
|
+
* @default 2
|
381
|
+
*/
|
382
|
+
maxRetries?: number;
|
383
|
+
/**
|
384
|
+
* Abort signal.
|
385
|
+
*/
|
386
|
+
abortSignal?: AbortSignal;
|
387
|
+
};
|
388
|
+
|
389
|
+
/**
|
390
|
+
* Data content. Can either be a base64-encoded string, a Uint8Array, an ArrayBuffer, or a Buffer.
|
391
|
+
*/
|
392
|
+
type DataContent = string | Uint8Array | ArrayBuffer | Buffer;
|
393
|
+
declare function convertDataContentToBase64String(content: DataContent): string;
|
394
|
+
declare function convertDataContentToUint8Array(content: DataContent): Uint8Array;
|
395
|
+
|
396
|
+
interface TextPart$1 {
|
397
|
+
type: 'text';
|
398
|
+
/**
|
399
|
+
* The text content.
|
400
|
+
*/
|
401
|
+
text: string;
|
402
|
+
}
|
403
|
+
interface ImagePart {
|
404
|
+
type: 'image';
|
405
|
+
/**
|
406
|
+
* Image data. Can either be:
|
407
|
+
*
|
408
|
+
* - data: a base64-encoded string, a Uint8Array, an ArrayBuffer, or a Buffer
|
409
|
+
* - URL: a URL that points to the image
|
410
|
+
*/
|
411
|
+
image: DataContent | URL;
|
412
|
+
/**
|
413
|
+
* Optional mime type of the image.
|
414
|
+
*/
|
415
|
+
mimeType?: string;
|
416
|
+
}
|
417
|
+
interface ToolCallPart {
|
418
|
+
type: 'tool-call';
|
419
|
+
toolCallId: string;
|
420
|
+
toolName: string;
|
421
|
+
args: unknown;
|
422
|
+
}
|
423
|
+
interface ToolResultPart {
|
424
|
+
type: 'tool-result';
|
425
|
+
toolCallId: string;
|
426
|
+
toolName: string;
|
427
|
+
result: unknown;
|
428
|
+
}
|
429
|
+
|
430
|
+
type ExperimentalMessage = ExperimentalUserMessage | ExperimentalAssistantMessage | ExperimentalToolMessage;
|
431
|
+
type ExperimentalUserMessage = {
|
432
|
+
role: 'user';
|
433
|
+
content: UserContent;
|
434
|
+
};
|
435
|
+
type ExperimentalAssistantMessage = {
|
436
|
+
role: 'assistant';
|
437
|
+
content: AssistantContent;
|
438
|
+
};
|
439
|
+
type ExperimentalToolMessage = {
|
440
|
+
role: 'tool';
|
441
|
+
content: ToolContent;
|
442
|
+
};
|
443
|
+
type UserContent = string | Array<TextPart$1 | ImagePart>;
|
444
|
+
type AssistantContent = string | Array<TextPart$1 | ToolCallPart>;
|
445
|
+
type ToolContent = Array<ToolResultPart>;
|
446
|
+
|
447
|
+
type Prompt = {
|
448
|
+
system?: string;
|
449
|
+
prompt?: string;
|
450
|
+
messages?: Array<ExperimentalMessage>;
|
451
|
+
};
|
452
|
+
|
453
|
+
/**
|
454
|
+
* Generate a structured, typed object using a language model.
|
455
|
+
*/
|
456
|
+
declare function experimental_generateObject<T>({ model, schema, mode, system, prompt, messages, maxRetries, abortSignal, ...settings }: CallSettings & Prompt & {
|
457
|
+
model: LanguageModelV1;
|
458
|
+
schema: z.Schema<T>;
|
459
|
+
mode?: 'auto' | 'json' | 'tool' | 'grammar';
|
460
|
+
}): Promise<GenerateObjectResult<T>>;
|
461
|
+
declare class GenerateObjectResult<T> {
|
462
|
+
readonly object: T;
|
463
|
+
readonly finishReason: LanguageModelV1FinishReason;
|
464
|
+
readonly usage: TokenUsage;
|
465
|
+
readonly warnings: LanguageModelV1CallWarning[] | undefined;
|
466
|
+
constructor(options: {
|
467
|
+
object: T;
|
468
|
+
finishReason: LanguageModelV1FinishReason;
|
469
|
+
usage: TokenUsage;
|
470
|
+
warnings: LanguageModelV1CallWarning[] | undefined;
|
471
|
+
});
|
472
|
+
}
|
473
|
+
|
474
|
+
type AsyncIterableStream<T> = AsyncIterable<T> & ReadableStream<T>;
|
475
|
+
|
476
|
+
/**
|
477
|
+
Create a type from an object with all keys and nested keys set to optional.
|
478
|
+
The helper supports normal objects and Zod schemas (which are resolved automatically).
|
479
|
+
It always recurses into arrays.
|
480
|
+
|
481
|
+
Adopted from [type-fest](https://github.com/sindresorhus/type-fest/tree/main) PartialDeep.
|
482
|
+
*/
|
483
|
+
type DeepPartial<T> = T extends null | undefined | string | number | boolean | symbol | bigint | void | Date | RegExp | ((...arguments_: any[]) => unknown) | (new (...arguments_: any[]) => unknown) ? T : T extends Map<infer KeyType, infer ValueType> ? PartialMap<KeyType, ValueType> : T extends Set<infer ItemType> ? PartialSet<ItemType> : T extends ReadonlyMap<infer KeyType, infer ValueType> ? PartialReadonlyMap<KeyType, ValueType> : T extends ReadonlySet<infer ItemType> ? PartialReadonlySet<ItemType> : T extends z.Schema<any> ? DeepPartial<T['_type']> : T extends object ? T extends ReadonlyArray<infer ItemType> ? ItemType[] extends T ? readonly ItemType[] extends T ? ReadonlyArray<DeepPartial<ItemType | undefined>> : Array<DeepPartial<ItemType | undefined>> : PartialObject<T> : PartialObject<T> : unknown;
|
484
|
+
type PartialMap<KeyType, ValueType> = {} & Map<DeepPartial<KeyType>, DeepPartial<ValueType>>;
|
485
|
+
type PartialSet<T> = {} & Set<DeepPartial<T>>;
|
486
|
+
type PartialReadonlyMap<KeyType, ValueType> = {} & ReadonlyMap<DeepPartial<KeyType>, DeepPartial<ValueType>>;
|
487
|
+
type PartialReadonlySet<T> = {} & ReadonlySet<DeepPartial<T>>;
|
488
|
+
type PartialObject<ObjectType extends object> = {
|
489
|
+
[KeyType in keyof ObjectType]?: DeepPartial<ObjectType[KeyType]>;
|
490
|
+
};
|
491
|
+
|
492
|
+
/**
|
493
|
+
* Stream an object as a partial object stream.
|
494
|
+
*/
|
495
|
+
declare function experimental_streamObject<T>({ model, schema, mode, system, prompt, messages, maxRetries, abortSignal, ...settings }: CallSettings & Prompt & {
|
496
|
+
model: LanguageModelV1;
|
497
|
+
schema: z.Schema<T>;
|
498
|
+
mode?: 'auto' | 'json' | 'tool' | 'grammar';
|
499
|
+
}): Promise<StreamObjectResult<T>>;
|
500
|
+
declare class StreamObjectResult<T> {
|
501
|
+
private readonly originalStream;
|
502
|
+
readonly warnings: LanguageModelV1CallWarning[] | undefined;
|
503
|
+
constructor({ stream, warnings, }: {
|
504
|
+
stream: ReadableStream<string | ErrorStreamPart>;
|
505
|
+
warnings: LanguageModelV1CallWarning[] | undefined;
|
506
|
+
});
|
507
|
+
get partialObjectStream(): AsyncIterableStream<DeepPartial<T>>;
|
508
|
+
}
|
509
|
+
type ErrorStreamPart = {
|
510
|
+
type: 'error';
|
511
|
+
error: unknown;
|
512
|
+
};
|
513
|
+
|
514
|
+
/**
|
515
|
+
* A tool contains the description and the schema of the input that the tool expects.
|
516
|
+
* This enables the language model to generate the input.
|
517
|
+
*
|
518
|
+
* The tool can also contain an optional execute function for the actual execution function of the tool.
|
519
|
+
*/
|
520
|
+
interface ExperimentalTool<PARAMETERS extends z.ZodTypeAny = any, RESULT = any> {
|
521
|
+
/**
|
522
|
+
* A optional description of what the tool does. Will be used by the language model to decide whether to use the tool.
|
523
|
+
*/
|
524
|
+
description?: string;
|
525
|
+
/**
|
526
|
+
* The schema of the input that the tool expects. The language model will use this to generate the input.
|
527
|
+
* Use descriptions to make the input understandable for the language model.
|
528
|
+
*/
|
529
|
+
parameters: PARAMETERS;
|
530
|
+
/**
|
531
|
+
* An optional execute function for the actual execution function of the tool.
|
532
|
+
* If not provided, the tool will not be executed automatically.
|
533
|
+
*/
|
534
|
+
execute?: (args: z.infer<PARAMETERS>) => PromiseLike<RESULT>;
|
535
|
+
}
|
536
|
+
/**
|
537
|
+
* Helper function for inferring the execute args of a tool.
|
538
|
+
*/
|
539
|
+
declare function tool<PARAMETERS extends z.ZodTypeAny, RESULT>(tool: ExperimentalTool<PARAMETERS, RESULT> & {
|
540
|
+
execute: (args: z.infer<PARAMETERS>) => PromiseLike<RESULT>;
|
541
|
+
}): ExperimentalTool<PARAMETERS, RESULT> & {
|
542
|
+
execute: (args: z.infer<PARAMETERS>) => PromiseLike<RESULT>;
|
543
|
+
};
|
544
|
+
declare function tool<PARAMETERS extends z.ZodTypeAny, RESULT>(tool: ExperimentalTool<PARAMETERS, RESULT> & {
|
545
|
+
execute?: undefined;
|
546
|
+
}): ExperimentalTool<PARAMETERS, RESULT> & {
|
547
|
+
execute: undefined;
|
548
|
+
};
|
549
|
+
|
550
|
+
/**
|
551
|
+
Create a union of the given object's values, and optionally specify which keys to get the values from.
|
552
|
+
|
553
|
+
Please upvote [this issue](https://github.com/microsoft/TypeScript/issues/31438) if you want to have this type as a built-in in TypeScript.
|
554
|
+
|
555
|
+
@example
|
556
|
+
```
|
557
|
+
// data.json
|
558
|
+
{
|
559
|
+
'foo': 1,
|
560
|
+
'bar': 2,
|
561
|
+
'biz': 3
|
562
|
+
}
|
563
|
+
|
564
|
+
// main.ts
|
565
|
+
import type {ValueOf} from 'type-fest';
|
566
|
+
import data = require('./data.json');
|
567
|
+
|
568
|
+
export function getData(name: string): ValueOf<typeof data> {
|
569
|
+
return data[name];
|
570
|
+
}
|
571
|
+
|
572
|
+
export function onlyBar(name: string): ValueOf<typeof data, 'bar'> {
|
573
|
+
return data[name];
|
574
|
+
}
|
575
|
+
|
576
|
+
// file.ts
|
577
|
+
import {getData, onlyBar} from './main';
|
578
|
+
|
579
|
+
getData('foo');
|
580
|
+
//=> 1
|
581
|
+
|
582
|
+
onlyBar('foo');
|
583
|
+
//=> TypeError ...
|
584
|
+
|
585
|
+
onlyBar('bar');
|
586
|
+
//=> 2
|
587
|
+
```
|
588
|
+
* @see https://github.com/sindresorhus/type-fest/blob/main/source/value-of.d.ts
|
589
|
+
*/
|
590
|
+
type ValueOf<ObjectType, ValueType extends keyof ObjectType = keyof ObjectType> = ObjectType[ValueType];
|
591
|
+
|
592
|
+
type ToToolCall<TOOLS extends Record<string, ExperimentalTool>> = ValueOf<{
|
593
|
+
[NAME in keyof TOOLS]: {
|
594
|
+
toolCallId: string;
|
595
|
+
toolName: NAME & string;
|
596
|
+
args: z.infer<TOOLS[NAME]['parameters']>;
|
597
|
+
};
|
598
|
+
}>;
|
599
|
+
type ToToolCallArray<TOOLS extends Record<string, ExperimentalTool>> = Array<ToToolCall<TOOLS>>;
|
600
|
+
|
601
|
+
type ToToolsWithExecute<TOOLS extends Record<string, ExperimentalTool>> = {
|
602
|
+
[K in keyof TOOLS as TOOLS[K] extends {
|
603
|
+
execute: any;
|
604
|
+
} ? K : never]: TOOLS[K];
|
605
|
+
};
|
606
|
+
type ToToolsWithDefinedExecute<TOOLS extends Record<string, ExperimentalTool>> = {
|
607
|
+
[K in keyof TOOLS as TOOLS[K]['execute'] extends undefined ? never : K]: TOOLS[K];
|
608
|
+
};
|
609
|
+
type ToToolResultObject<TOOLS extends Record<string, ExperimentalTool>> = ValueOf<{
|
610
|
+
[NAME in keyof TOOLS]: {
|
611
|
+
toolCallId: string;
|
612
|
+
toolName: NAME & string;
|
613
|
+
args: z.infer<TOOLS[NAME]['parameters']>;
|
614
|
+
result: Awaited<ReturnType<Exclude<TOOLS[NAME]['execute'], undefined>>>;
|
615
|
+
};
|
616
|
+
}>;
|
617
|
+
type ToToolResult<TOOLS extends Record<string, ExperimentalTool>> = ToToolResultObject<ToToolsWithDefinedExecute<ToToolsWithExecute<TOOLS>>>;
|
618
|
+
type ToToolResultArray<TOOLS extends Record<string, ExperimentalTool>> = Array<ToToolResult<TOOLS>>;
|
619
|
+
|
620
|
+
/**
|
621
|
+
* Generate a text and call tools using a language model.
|
622
|
+
*/
|
623
|
+
declare function experimental_generateText<TOOLS extends Record<string, ExperimentalTool>>({ model, tools, system, prompt, messages, maxRetries, abortSignal, ...settings }: CallSettings & Prompt & {
|
624
|
+
model: LanguageModelV1;
|
625
|
+
tools?: TOOLS;
|
626
|
+
}): Promise<GenerateTextResult<TOOLS>>;
|
627
|
+
declare class GenerateTextResult<TOOLS extends Record<string, ExperimentalTool>> {
|
628
|
+
readonly text: string;
|
629
|
+
readonly toolCalls: ToToolCallArray<TOOLS>;
|
630
|
+
readonly toolResults: ToToolResultArray<TOOLS>;
|
631
|
+
readonly finishReason: LanguageModelV1FinishReason;
|
632
|
+
readonly usage: TokenUsage;
|
633
|
+
readonly warnings: LanguageModelV1CallWarning[] | undefined;
|
634
|
+
constructor(options: {
|
635
|
+
text: string;
|
636
|
+
toolCalls: ToToolCallArray<TOOLS>;
|
637
|
+
toolResults: ToToolResultArray<TOOLS>;
|
638
|
+
finishReason: LanguageModelV1FinishReason;
|
639
|
+
usage: TokenUsage;
|
640
|
+
warnings: LanguageModelV1CallWarning[] | undefined;
|
641
|
+
});
|
642
|
+
}
|
643
|
+
|
644
|
+
/**
|
645
|
+
* Stream text generated by a language model.
|
646
|
+
*/
|
647
|
+
declare function experimental_streamText<TOOLS extends Record<string, ExperimentalTool>>({ model, tools, system, prompt, messages, maxRetries, abortSignal, ...settings }: CallSettings & Prompt & {
|
648
|
+
model: LanguageModelV1;
|
649
|
+
tools?: TOOLS;
|
650
|
+
}): Promise<StreamTextResult<TOOLS>>;
|
651
|
+
type TextStreamPart<TOOLS extends Record<string, ExperimentalTool>> = {
|
652
|
+
type: 'text-delta';
|
653
|
+
textDelta: string;
|
654
|
+
} | ({
|
655
|
+
type: 'tool-call';
|
656
|
+
} & ToToolCall<TOOLS>) | {
|
657
|
+
type: 'error';
|
658
|
+
error: unknown;
|
659
|
+
} | ({
|
660
|
+
type: 'tool-result';
|
661
|
+
} & ToToolResult<TOOLS>) | {
|
662
|
+
type: 'finish';
|
663
|
+
finishReason: LanguageModelV1FinishReason;
|
664
|
+
usage: {
|
665
|
+
promptTokens: number;
|
666
|
+
completionTokens: number;
|
667
|
+
totalTokens: number;
|
668
|
+
};
|
669
|
+
};
|
670
|
+
declare class StreamTextResult<TOOLS extends Record<string, ExperimentalTool>> {
|
671
|
+
private readonly originalStream;
|
672
|
+
readonly warnings: LanguageModelV1CallWarning[] | undefined;
|
673
|
+
constructor({ stream, warnings, }: {
|
674
|
+
stream: ReadableStream<TextStreamPart<TOOLS>>;
|
675
|
+
warnings: LanguageModelV1CallWarning[] | undefined;
|
676
|
+
});
|
677
|
+
get textStream(): AsyncIterableStream<string>;
|
678
|
+
get fullStream(): AsyncIterableStream<TextStreamPart<TOOLS>>;
|
679
|
+
toAIStream(callbacks?: AIStreamCallbacksAndOptions): ReadableStream<any>;
|
680
|
+
}
|
681
|
+
|
5
682
|
interface FunctionCall {
|
6
683
|
/**
|
7
684
|
* The arguments to call the function with, as generated by the model in JSON
|
@@ -341,7 +1018,11 @@ declare const StreamStringPrefixes: {
|
|
341
1018
|
readonly message_annotations: "8";
|
342
1019
|
};
|
343
1020
|
|
344
|
-
|
1021
|
+
/**
|
1022
|
+
* Generates a 7-character random string to use for IDs. Not secure.
|
1023
|
+
*/
|
1024
|
+
declare const generateId: (size?: number | undefined) => string;
|
1025
|
+
|
345
1026
|
declare function createChunkDecoder(): (chunk: Uint8Array | undefined) => string;
|
346
1027
|
declare function createChunkDecoder(complex: false): (chunk: Uint8Array | undefined) => string;
|
347
1028
|
declare function createChunkDecoder(complex: true): (chunk: Uint8Array | undefined) => StreamPartType[];
|
@@ -805,7 +1486,7 @@ type AssistantResponseCallback = (options: {
|
|
805
1486
|
messageId: string;
|
806
1487
|
sendMessage: (message: AssistantMessage) => void;
|
807
1488
|
sendDataMessage: (message: DataMessage) => void;
|
808
|
-
forwardStream: (stream: AssistantStream) => Promise<
|
1489
|
+
forwardStream: (stream: AssistantStream) => Promise<Run | undefined>;
|
809
1490
|
}) => Promise<void>;
|
810
1491
|
declare function experimental_AssistantResponse({ threadId, messageId }: AssistantResponseSettings, process: AssistantResponseCallback): Response;
|
811
1492
|
|
@@ -816,6 +1497,7 @@ interface AWSBedrockResponse {
|
|
816
1497
|
};
|
817
1498
|
}>;
|
818
1499
|
}
|
1500
|
+
declare function AWSBedrockAnthropicMessagesStream(response: AWSBedrockResponse, callbacks?: AIStreamCallbacksAndOptions): ReadableStream;
|
819
1501
|
declare function AWSBedrockAnthropicStream(response: AWSBedrockResponse, callbacks?: AIStreamCallbacksAndOptions): ReadableStream;
|
820
1502
|
declare function AWSBedrockCohereStream(response: AWSBedrockResponse, callbacks?: AIStreamCallbacksAndOptions): ReadableStream;
|
821
1503
|
declare function AWSBedrockLlama2Stream(response: AWSBedrockResponse, callbacks?: AIStreamCallbacksAndOptions): ReadableStream;
|
@@ -976,7 +1658,7 @@ declare class experimental_StreamingReactResponse {
|
|
976
1658
|
constructor(res: ReadableStream, options?: {
|
977
1659
|
ui?: (message: {
|
978
1660
|
content: string;
|
979
|
-
data?: JSONValue[]
|
1661
|
+
data?: JSONValue[];
|
980
1662
|
}) => UINode | Promise<UINode>;
|
981
1663
|
data?: experimental_StreamData;
|
982
1664
|
generateId?: IdGenerator;
|
@@ -997,4 +1679,4 @@ declare function streamToResponse(res: ReadableStream, response: ServerResponse,
|
|
997
1679
|
status?: number;
|
998
1680
|
}): void;
|
999
1681
|
|
1000
|
-
export { AIStream, AIStreamCallbacksAndOptions, AIStreamParser, AIStreamParserOptions, AWSBedrockAnthropicStream, AWSBedrockCohereStream, AWSBedrockLlama2Stream, AWSBedrockStream, AnthropicStream, AssistantMessage, COMPLEX_HEADER, ChatRequest, ChatRequestOptions, CohereStream, CompletionUsage, CreateMessage, DataMessage, Function, FunctionCall, FunctionCallHandler, FunctionCallPayload, GoogleGenerativeAIStream, HuggingFaceStream, IdGenerator, InkeepAIStreamCallbacksAndOptions, InkeepChatResultCallbacks, InkeepOnFinalMetadata, InkeepStream, JSONValue, LangChainStream, Message$1 as Message, MistralStream, OpenAIStream, OpenAIStreamCallbacks, ReactResponseRow, ReplicateStream, RequestOptions, StreamString, StreamingTextResponse, Tool, ToolCall, ToolCallHandler, ToolCallPayload, ToolChoice, UseChatOptions, UseCompletionOptions, createCallbacksTransformer, createChunkDecoder, createEventStreamTransformer, createStreamDataTransformer, experimental_AssistantResponse, experimental_StreamData, experimental_StreamingReactResponse, isStreamStringEqualToType, nanoid, readableFromAsyncIterable, streamToResponse, trimStartOfStreamHelper };
|
1682
|
+
export { AIStream, AIStreamCallbacksAndOptions, AIStreamParser, AIStreamParserOptions, AWSBedrockAnthropicMessagesStream, AWSBedrockAnthropicStream, AWSBedrockCohereStream, AWSBedrockLlama2Stream, AWSBedrockStream, AnthropicStream, AssistantContent, AssistantMessage, COMPLEX_HEADER, ChatRequest, ChatRequestOptions, CohereStream, CompletionUsage, CreateMessage, DataContent, DataMessage, DeepPartial, ErrorStreamPart, ExperimentalAssistantMessage, ExperimentalMessage, ExperimentalTool, ExperimentalToolMessage, ExperimentalUserMessage, Function, FunctionCall, FunctionCallHandler, FunctionCallPayload, GenerateObjectResult, GenerateTextResult, GoogleGenerativeAIStream, HuggingFaceStream, IdGenerator, ImagePart, InkeepAIStreamCallbacksAndOptions, InkeepChatResultCallbacks, InkeepOnFinalMetadata, InkeepStream, JSONValue, LangChainStream, Message$1 as Message, MistralStream, OpenAIStream, OpenAIStreamCallbacks, ReactResponseRow, ReplicateStream, RequestOptions, StreamObjectResult, StreamString, StreamTextResult, StreamingTextResponse, TextPart$1 as TextPart, TextStreamPart, Tool, ToolCall, ToolCallHandler, ToolCallPart, ToolCallPayload, ToolChoice, ToolContent, ToolResultPart, UseChatOptions, UseCompletionOptions, UserContent, convertDataContentToBase64String, convertDataContentToUint8Array, createCallbacksTransformer, createChunkDecoder, createEventStreamTransformer, createStreamDataTransformer, experimental_AssistantResponse, experimental_StreamData, experimental_StreamingReactResponse, experimental_generateObject, experimental_generateText, experimental_streamObject, experimental_streamText, generateId, isStreamStringEqualToType, generateId as nanoid, readableFromAsyncIterable, streamToResponse, tool, trimStartOfStreamHelper };
|