ai 5.0.0-canary.14 → 5.0.0-canary.16
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/CHANGELOG.md +32 -0
- package/dist/index.d.mts +143 -210
- package/dist/index.d.ts +143 -210
- package/dist/index.js +192 -329
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +138 -259
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +36 -78
- package/dist/internal/index.d.ts +36 -78
- package/dist/internal/index.js +11 -130
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +6 -111
- package/dist/internal/index.mjs.map +1 -1
- package/dist/mcp-stdio/index.d.mts +2 -2
- package/dist/mcp-stdio/index.d.ts +2 -2
- package/dist/test/index.d.mts +4 -3
- package/dist/test/index.d.ts +4 -3
- package/dist/test/index.js +5 -2
- package/dist/test/index.js.map +1 -1
- package/dist/test/index.mjs +5 -2
- package/dist/test/index.mjs.map +1 -1
- package/package.json +3 -4
@@ -1,7 +1,7 @@
|
|
1
|
-
import
|
1
|
+
import * as _ai_sdk_provider from '@ai-sdk/provider';
|
2
|
+
import { SharedV2ProviderOptions, JSONValue as JSONValue$1, LanguageModelV2Source, LanguageModelV2Usage, LanguageModelV2FinishReason, JSONObject, LanguageModelV2FunctionTool, LanguageModelV2ProviderDefinedTool, LanguageModelV2ToolChoice, LanguageModelV2Prompt } from '@ai-sdk/provider';
|
2
3
|
import { z } from 'zod';
|
3
|
-
import { ToolCall, ToolResult,
|
4
|
-
import { JSONSchema7 } from 'json-schema';
|
4
|
+
import { ToolCall, ToolResult, Schema } from '@ai-sdk/provider-utils';
|
5
5
|
|
6
6
|
type ToolResultContent = Array<{
|
7
7
|
type: 'text';
|
@@ -255,6 +255,8 @@ It can be a user message, an assistant message, or a tool message.
|
|
255
255
|
*/
|
256
256
|
type CoreMessage = CoreSystemMessage | CoreUserMessage | CoreAssistantMessage | CoreToolMessage;
|
257
257
|
|
258
|
+
type JSONValue = JSONValue$1;
|
259
|
+
|
258
260
|
/**
|
259
261
|
A source that has been used as input to generate the response.
|
260
262
|
*/
|
@@ -272,25 +274,6 @@ type ToolChoice<TOOLS extends Record<string, unknown>> = 'auto' | 'none' | 'requ
|
|
272
274
|
toolName: Extract<keyof TOOLS, string>;
|
273
275
|
};
|
274
276
|
|
275
|
-
/**
|
276
|
-
Represents the number of tokens used in a prompt and completion.
|
277
|
-
*/
|
278
|
-
type LanguageModelUsage = {
|
279
|
-
/**
|
280
|
-
The number of tokens used in the prompt.
|
281
|
-
*/
|
282
|
-
promptTokens: number;
|
283
|
-
/**
|
284
|
-
The number of tokens used in the completion.
|
285
|
-
*/
|
286
|
-
completionTokens: number;
|
287
|
-
/**
|
288
|
-
The total number of tokens used (promptTokens + completionTokens).
|
289
|
-
*/
|
290
|
-
totalTokens: number;
|
291
|
-
};
|
292
|
-
declare function calculateLanguageModelUsage({ inputTokens, outputTokens, }: LanguageModelV2Usage): LanguageModelUsage;
|
293
|
-
|
294
277
|
/**
|
295
278
|
Tool invocations are either tool calls or tool results. For each assistant tool call,
|
296
279
|
there is one tool invocation. While the call is in progress, the invocation is a tool call.
|
@@ -331,7 +314,7 @@ interface Attachment {
|
|
331
314
|
/**
|
332
315
|
* AI SDK UI Messages. They are used in the client and to communicate between the frontend and the API routes.
|
333
316
|
*/
|
334
|
-
interface
|
317
|
+
interface UIMessage {
|
335
318
|
/**
|
336
319
|
A unique identifier for the message.
|
337
320
|
*/
|
@@ -345,44 +328,26 @@ interface Message {
|
|
345
328
|
*/
|
346
329
|
content: string;
|
347
330
|
/**
|
348
|
-
|
349
|
-
|
350
|
-
@deprecated Use `parts` instead.
|
351
|
-
*/
|
352
|
-
reasoning?: string;
|
353
|
-
/**
|
354
|
-
* Additional attachments to be sent along with the message.
|
331
|
+
Additional attachments to be sent along with the message.
|
355
332
|
*/
|
356
333
|
experimental_attachments?: Attachment[];
|
357
334
|
/**
|
358
|
-
The
|
359
|
-
*/
|
360
|
-
role: 'system' | 'user' | 'assistant' | 'data';
|
361
|
-
/**
|
362
|
-
For data messages.
|
363
|
-
|
364
|
-
@deprecated Data messages will be removed.
|
335
|
+
The role of the message.
|
365
336
|
*/
|
366
|
-
|
337
|
+
role: 'system' | 'user' | 'assistant';
|
367
338
|
/**
|
368
|
-
|
339
|
+
Additional message-specific information added on the server via StreamData
|
369
340
|
*/
|
370
|
-
annotations?: JSONValue[] | undefined;
|
341
|
+
annotations?: JSONValue$1[] | undefined;
|
371
342
|
/**
|
372
|
-
|
373
|
-
that the assistant made as part of this message.
|
343
|
+
The parts of the message. Use this for rendering the message in the UI.
|
374
344
|
|
375
|
-
|
376
|
-
|
377
|
-
toolInvocations?: Array<ToolInvocation>;
|
378
|
-
/**
|
379
|
-
* The parts of the message. Use this for rendering the message in the UI.
|
380
|
-
*
|
381
|
-
* Assistant messages can have text, reasoning and tool invocation parts.
|
382
|
-
* User messages can have text parts.
|
345
|
+
Assistant messages can have text, reasoning and tool invocation parts.
|
346
|
+
User messages can have text parts.
|
383
347
|
*/
|
384
|
-
parts
|
348
|
+
parts: Array<UIMessagePart>;
|
385
349
|
}
|
350
|
+
type UIMessagePart = TextUIPart | ReasoningUIPart | ToolInvocationUIPart | SourceUIPart | FileUIPart | StepStartUIPart;
|
386
351
|
/**
|
387
352
|
* A text part of a message.
|
388
353
|
*/
|
@@ -401,7 +366,7 @@ type ReasoningUIPart = {
|
|
401
366
|
/**
|
402
367
|
* The reasoning text.
|
403
368
|
*/
|
404
|
-
|
369
|
+
text: string;
|
405
370
|
/**
|
406
371
|
* The provider metadata.
|
407
372
|
*/
|
@@ -449,13 +414,25 @@ type FileUIPart = {
|
|
449
414
|
type StepStartUIPart = {
|
450
415
|
type: 'step-start';
|
451
416
|
};
|
417
|
+
|
452
418
|
/**
|
453
|
-
|
454
|
-
JSON values can be serialized and deserialized by the JSON.stringify and JSON.parse methods.
|
419
|
+
Represents the number of tokens used in a prompt and completion.
|
455
420
|
*/
|
456
|
-
type
|
457
|
-
|
458
|
-
|
421
|
+
type LanguageModelUsage = {
|
422
|
+
/**
|
423
|
+
The number of tokens used in the prompt.
|
424
|
+
*/
|
425
|
+
promptTokens: number;
|
426
|
+
/**
|
427
|
+
The number of tokens used in the completion.
|
428
|
+
*/
|
429
|
+
completionTokens: number;
|
430
|
+
/**
|
431
|
+
The total number of tokens used (promptTokens + completionTokens).
|
432
|
+
*/
|
433
|
+
totalTokens: number;
|
434
|
+
};
|
435
|
+
declare function calculateLanguageModelUsage({ inputTokens, outputTokens, }: LanguageModelV2Usage): LanguageModelUsage;
|
459
436
|
|
460
437
|
type DataStreamString = `${(typeof DataStreamStringPrefixes)[keyof typeof DataStreamStringPrefixes]}:${string}\n`;
|
461
438
|
interface DataStreamPart<CODE extends string, NAME extends string, TYPE> {
|
@@ -466,7 +443,7 @@ interface DataStreamPart<CODE extends string, NAME extends string, TYPE> {
|
|
466
443
|
value: TYPE;
|
467
444
|
};
|
468
445
|
}
|
469
|
-
declare const dataStreamParts: readonly [DataStreamPart<"0", "text", string>, DataStreamPart<"2", "data", JSONValue[]>, DataStreamPart<"3", "error", string>, DataStreamPart<"8", "message_annotations", JSONValue[]>, DataStreamPart<"9", "tool_call", ToolCall<string, any>>, DataStreamPart<"a", "tool_result", Omit<ToolResult<string, any, any>, "toolName" | "args">>, DataStreamPart<"b", "tool_call_streaming_start", {
|
446
|
+
declare const dataStreamParts: readonly [DataStreamPart<"0", "text", string>, DataStreamPart<"2", "data", _ai_sdk_provider.JSONValue[]>, DataStreamPart<"3", "error", string>, DataStreamPart<"8", "message_annotations", _ai_sdk_provider.JSONValue[]>, DataStreamPart<"9", "tool_call", ToolCall<string, any>>, DataStreamPart<"a", "tool_result", Omit<ToolResult<string, any, any>, "toolName" | "args">>, DataStreamPart<"b", "tool_call_streaming_start", {
|
470
447
|
toolCallId: string;
|
471
448
|
toolName: string;
|
472
449
|
}>, DataStreamPart<"c", "tool_call_delta", {
|
@@ -532,25 +509,6 @@ It ensures type-safety for the part type and value.
|
|
532
509
|
*/
|
533
510
|
declare function formatDataStreamPart<T extends keyof DataStreamPartValueType>(type: T, value: DataStreamPartValueType[T]): DataStreamString;
|
534
511
|
|
535
|
-
/**
|
536
|
-
* Used to mark schemas so we can support both Zod and custom schemas.
|
537
|
-
*/
|
538
|
-
declare const schemaSymbol: unique symbol;
|
539
|
-
type Schema<OBJECT = unknown> = Validator<OBJECT> & {
|
540
|
-
/**
|
541
|
-
* Used to mark schemas so we can support both Zod and custom schemas.
|
542
|
-
*/
|
543
|
-
[schemaSymbol]: true;
|
544
|
-
/**
|
545
|
-
* Schema type for inference.
|
546
|
-
*/
|
547
|
-
_type: OBJECT;
|
548
|
-
/**
|
549
|
-
* The JSON Schema for the schema. It is passed to the providers.
|
550
|
-
*/
|
551
|
-
readonly jsonSchema: JSONSchema7;
|
552
|
-
};
|
553
|
-
|
554
512
|
type ToolParameters<T = JSONObject> = z.Schema<T> | Schema<T>;
|
555
513
|
interface ToolExecutionOptions {
|
556
514
|
/**
|
@@ -639,7 +597,7 @@ type Prompt = {
|
|
639
597
|
/**
|
640
598
|
A list of messages. You can either use `prompt` or `messages` but not both.
|
641
599
|
*/
|
642
|
-
messages?: Array<CoreMessage> | Array<Omit<
|
600
|
+
messages?: Array<CoreMessage> | Array<Omit<UIMessage, 'id'>>;
|
643
601
|
};
|
644
602
|
|
645
603
|
type StandardizedPrompt = {
|
package/dist/internal/index.d.ts
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
import
|
1
|
+
import * as _ai_sdk_provider from '@ai-sdk/provider';
|
2
|
+
import { SharedV2ProviderOptions, JSONValue as JSONValue$1, LanguageModelV2Source, LanguageModelV2Usage, LanguageModelV2FinishReason, JSONObject, LanguageModelV2FunctionTool, LanguageModelV2ProviderDefinedTool, LanguageModelV2ToolChoice, LanguageModelV2Prompt } from '@ai-sdk/provider';
|
2
3
|
import { z } from 'zod';
|
3
|
-
import { ToolCall, ToolResult,
|
4
|
-
import { JSONSchema7 } from 'json-schema';
|
4
|
+
import { ToolCall, ToolResult, Schema } from '@ai-sdk/provider-utils';
|
5
5
|
|
6
6
|
type ToolResultContent = Array<{
|
7
7
|
type: 'text';
|
@@ -255,6 +255,8 @@ It can be a user message, an assistant message, or a tool message.
|
|
255
255
|
*/
|
256
256
|
type CoreMessage = CoreSystemMessage | CoreUserMessage | CoreAssistantMessage | CoreToolMessage;
|
257
257
|
|
258
|
+
type JSONValue = JSONValue$1;
|
259
|
+
|
258
260
|
/**
|
259
261
|
A source that has been used as input to generate the response.
|
260
262
|
*/
|
@@ -272,25 +274,6 @@ type ToolChoice<TOOLS extends Record<string, unknown>> = 'auto' | 'none' | 'requ
|
|
272
274
|
toolName: Extract<keyof TOOLS, string>;
|
273
275
|
};
|
274
276
|
|
275
|
-
/**
|
276
|
-
Represents the number of tokens used in a prompt and completion.
|
277
|
-
*/
|
278
|
-
type LanguageModelUsage = {
|
279
|
-
/**
|
280
|
-
The number of tokens used in the prompt.
|
281
|
-
*/
|
282
|
-
promptTokens: number;
|
283
|
-
/**
|
284
|
-
The number of tokens used in the completion.
|
285
|
-
*/
|
286
|
-
completionTokens: number;
|
287
|
-
/**
|
288
|
-
The total number of tokens used (promptTokens + completionTokens).
|
289
|
-
*/
|
290
|
-
totalTokens: number;
|
291
|
-
};
|
292
|
-
declare function calculateLanguageModelUsage({ inputTokens, outputTokens, }: LanguageModelV2Usage): LanguageModelUsage;
|
293
|
-
|
294
277
|
/**
|
295
278
|
Tool invocations are either tool calls or tool results. For each assistant tool call,
|
296
279
|
there is one tool invocation. While the call is in progress, the invocation is a tool call.
|
@@ -331,7 +314,7 @@ interface Attachment {
|
|
331
314
|
/**
|
332
315
|
* AI SDK UI Messages. They are used in the client and to communicate between the frontend and the API routes.
|
333
316
|
*/
|
334
|
-
interface
|
317
|
+
interface UIMessage {
|
335
318
|
/**
|
336
319
|
A unique identifier for the message.
|
337
320
|
*/
|
@@ -345,44 +328,26 @@ interface Message {
|
|
345
328
|
*/
|
346
329
|
content: string;
|
347
330
|
/**
|
348
|
-
|
349
|
-
|
350
|
-
@deprecated Use `parts` instead.
|
351
|
-
*/
|
352
|
-
reasoning?: string;
|
353
|
-
/**
|
354
|
-
* Additional attachments to be sent along with the message.
|
331
|
+
Additional attachments to be sent along with the message.
|
355
332
|
*/
|
356
333
|
experimental_attachments?: Attachment[];
|
357
334
|
/**
|
358
|
-
The
|
359
|
-
*/
|
360
|
-
role: 'system' | 'user' | 'assistant' | 'data';
|
361
|
-
/**
|
362
|
-
For data messages.
|
363
|
-
|
364
|
-
@deprecated Data messages will be removed.
|
335
|
+
The role of the message.
|
365
336
|
*/
|
366
|
-
|
337
|
+
role: 'system' | 'user' | 'assistant';
|
367
338
|
/**
|
368
|
-
|
339
|
+
Additional message-specific information added on the server via StreamData
|
369
340
|
*/
|
370
|
-
annotations?: JSONValue[] | undefined;
|
341
|
+
annotations?: JSONValue$1[] | undefined;
|
371
342
|
/**
|
372
|
-
|
373
|
-
that the assistant made as part of this message.
|
343
|
+
The parts of the message. Use this for rendering the message in the UI.
|
374
344
|
|
375
|
-
|
376
|
-
|
377
|
-
toolInvocations?: Array<ToolInvocation>;
|
378
|
-
/**
|
379
|
-
* The parts of the message. Use this for rendering the message in the UI.
|
380
|
-
*
|
381
|
-
* Assistant messages can have text, reasoning and tool invocation parts.
|
382
|
-
* User messages can have text parts.
|
345
|
+
Assistant messages can have text, reasoning and tool invocation parts.
|
346
|
+
User messages can have text parts.
|
383
347
|
*/
|
384
|
-
parts
|
348
|
+
parts: Array<UIMessagePart>;
|
385
349
|
}
|
350
|
+
type UIMessagePart = TextUIPart | ReasoningUIPart | ToolInvocationUIPart | SourceUIPart | FileUIPart | StepStartUIPart;
|
386
351
|
/**
|
387
352
|
* A text part of a message.
|
388
353
|
*/
|
@@ -401,7 +366,7 @@ type ReasoningUIPart = {
|
|
401
366
|
/**
|
402
367
|
* The reasoning text.
|
403
368
|
*/
|
404
|
-
|
369
|
+
text: string;
|
405
370
|
/**
|
406
371
|
* The provider metadata.
|
407
372
|
*/
|
@@ -449,13 +414,25 @@ type FileUIPart = {
|
|
449
414
|
type StepStartUIPart = {
|
450
415
|
type: 'step-start';
|
451
416
|
};
|
417
|
+
|
452
418
|
/**
|
453
|
-
|
454
|
-
JSON values can be serialized and deserialized by the JSON.stringify and JSON.parse methods.
|
419
|
+
Represents the number of tokens used in a prompt and completion.
|
455
420
|
*/
|
456
|
-
type
|
457
|
-
|
458
|
-
|
421
|
+
type LanguageModelUsage = {
|
422
|
+
/**
|
423
|
+
The number of tokens used in the prompt.
|
424
|
+
*/
|
425
|
+
promptTokens: number;
|
426
|
+
/**
|
427
|
+
The number of tokens used in the completion.
|
428
|
+
*/
|
429
|
+
completionTokens: number;
|
430
|
+
/**
|
431
|
+
The total number of tokens used (promptTokens + completionTokens).
|
432
|
+
*/
|
433
|
+
totalTokens: number;
|
434
|
+
};
|
435
|
+
declare function calculateLanguageModelUsage({ inputTokens, outputTokens, }: LanguageModelV2Usage): LanguageModelUsage;
|
459
436
|
|
460
437
|
type DataStreamString = `${(typeof DataStreamStringPrefixes)[keyof typeof DataStreamStringPrefixes]}:${string}\n`;
|
461
438
|
interface DataStreamPart<CODE extends string, NAME extends string, TYPE> {
|
@@ -466,7 +443,7 @@ interface DataStreamPart<CODE extends string, NAME extends string, TYPE> {
|
|
466
443
|
value: TYPE;
|
467
444
|
};
|
468
445
|
}
|
469
|
-
declare const dataStreamParts: readonly [DataStreamPart<"0", "text", string>, DataStreamPart<"2", "data", JSONValue[]>, DataStreamPart<"3", "error", string>, DataStreamPart<"8", "message_annotations", JSONValue[]>, DataStreamPart<"9", "tool_call", ToolCall<string, any>>, DataStreamPart<"a", "tool_result", Omit<ToolResult<string, any, any>, "toolName" | "args">>, DataStreamPart<"b", "tool_call_streaming_start", {
|
446
|
+
declare const dataStreamParts: readonly [DataStreamPart<"0", "text", string>, DataStreamPart<"2", "data", _ai_sdk_provider.JSONValue[]>, DataStreamPart<"3", "error", string>, DataStreamPart<"8", "message_annotations", _ai_sdk_provider.JSONValue[]>, DataStreamPart<"9", "tool_call", ToolCall<string, any>>, DataStreamPart<"a", "tool_result", Omit<ToolResult<string, any, any>, "toolName" | "args">>, DataStreamPart<"b", "tool_call_streaming_start", {
|
470
447
|
toolCallId: string;
|
471
448
|
toolName: string;
|
472
449
|
}>, DataStreamPart<"c", "tool_call_delta", {
|
@@ -532,25 +509,6 @@ It ensures type-safety for the part type and value.
|
|
532
509
|
*/
|
533
510
|
declare function formatDataStreamPart<T extends keyof DataStreamPartValueType>(type: T, value: DataStreamPartValueType[T]): DataStreamString;
|
534
511
|
|
535
|
-
/**
|
536
|
-
* Used to mark schemas so we can support both Zod and custom schemas.
|
537
|
-
*/
|
538
|
-
declare const schemaSymbol: unique symbol;
|
539
|
-
type Schema<OBJECT = unknown> = Validator<OBJECT> & {
|
540
|
-
/**
|
541
|
-
* Used to mark schemas so we can support both Zod and custom schemas.
|
542
|
-
*/
|
543
|
-
[schemaSymbol]: true;
|
544
|
-
/**
|
545
|
-
* Schema type for inference.
|
546
|
-
*/
|
547
|
-
_type: OBJECT;
|
548
|
-
/**
|
549
|
-
* The JSON Schema for the schema. It is passed to the providers.
|
550
|
-
*/
|
551
|
-
readonly jsonSchema: JSONSchema7;
|
552
|
-
};
|
553
|
-
|
554
512
|
type ToolParameters<T = JSONObject> = z.Schema<T> | Schema<T>;
|
555
513
|
interface ToolExecutionOptions {
|
556
514
|
/**
|
@@ -639,7 +597,7 @@ type Prompt = {
|
|
639
597
|
/**
|
640
598
|
A list of messages. You can either use `prompt` or `messages` but not both.
|
641
599
|
*/
|
642
|
-
messages?: Array<CoreMessage> | Array<Omit<
|
600
|
+
messages?: Array<CoreMessage> | Array<Omit<UIMessage, 'id'>>;
|
643
601
|
};
|
644
602
|
|
645
603
|
type StandardizedPrompt = {
|
package/dist/internal/index.js
CHANGED
@@ -1,9 +1,7 @@
|
|
1
1
|
"use strict";
|
2
|
-
var __create = Object.create;
|
3
2
|
var __defProp = Object.defineProperty;
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
5
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
7
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
8
6
|
var __export = (target, all) => {
|
9
7
|
for (var name7 in all)
|
@@ -17,14 +15,6 @@ var __copyProps = (to, from, except, desc) => {
|
|
17
15
|
}
|
18
16
|
return to;
|
19
17
|
};
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
26
|
-
mod
|
27
|
-
));
|
28
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
29
19
|
|
30
20
|
// internal/index.ts
|
@@ -321,7 +311,7 @@ function convertToCoreMessages(messages, options) {
|
|
321
311
|
case "reasoning": {
|
322
312
|
content2.push({
|
323
313
|
type: "reasoning",
|
324
|
-
text: part.
|
314
|
+
text: part.text,
|
325
315
|
providerOptions: part.providerMetadata
|
326
316
|
});
|
327
317
|
break;
|
@@ -411,73 +401,11 @@ function convertToCoreMessages(messages, options) {
|
|
411
401
|
processBlock2();
|
412
402
|
break;
|
413
403
|
}
|
414
|
-
const toolInvocations = message.toolInvocations;
|
415
|
-
if (toolInvocations == null || toolInvocations.length === 0) {
|
416
|
-
coreMessages.push({ role: "assistant", content });
|
417
|
-
break;
|
418
|
-
}
|
419
|
-
const maxStep = toolInvocations.reduce((max, toolInvocation) => {
|
420
|
-
var _a8;
|
421
|
-
return Math.max(max, (_a8 = toolInvocation.step) != null ? _a8 : 0);
|
422
|
-
}, 0);
|
423
|
-
for (let i2 = 0; i2 <= maxStep; i2++) {
|
424
|
-
const stepInvocations = toolInvocations.filter(
|
425
|
-
(toolInvocation) => {
|
426
|
-
var _a8;
|
427
|
-
return ((_a8 = toolInvocation.step) != null ? _a8 : 0) === i2;
|
428
|
-
}
|
429
|
-
);
|
430
|
-
if (stepInvocations.length === 0) {
|
431
|
-
continue;
|
432
|
-
}
|
433
|
-
coreMessages.push({
|
434
|
-
role: "assistant",
|
435
|
-
content: [
|
436
|
-
...isLastMessage && content && i2 === 0 ? [{ type: "text", text: content }] : [],
|
437
|
-
...stepInvocations.map(
|
438
|
-
({ toolCallId, toolName, args }) => ({
|
439
|
-
type: "tool-call",
|
440
|
-
toolCallId,
|
441
|
-
toolName,
|
442
|
-
args
|
443
|
-
})
|
444
|
-
)
|
445
|
-
]
|
446
|
-
});
|
447
|
-
coreMessages.push({
|
448
|
-
role: "tool",
|
449
|
-
content: stepInvocations.map((toolInvocation) => {
|
450
|
-
if (!("result" in toolInvocation)) {
|
451
|
-
throw new MessageConversionError({
|
452
|
-
originalMessage: message,
|
453
|
-
message: "ToolInvocation must have a result: " + JSON.stringify(toolInvocation)
|
454
|
-
});
|
455
|
-
}
|
456
|
-
const { toolCallId, toolName, result } = toolInvocation;
|
457
|
-
const tool = tools[toolName];
|
458
|
-
return (tool == null ? void 0 : tool.experimental_toToolResultContent) != null ? {
|
459
|
-
type: "tool-result",
|
460
|
-
toolCallId,
|
461
|
-
toolName,
|
462
|
-
result: tool.experimental_toToolResultContent(result),
|
463
|
-
experimental_content: tool.experimental_toToolResultContent(result)
|
464
|
-
} : {
|
465
|
-
type: "tool-result",
|
466
|
-
toolCallId,
|
467
|
-
toolName,
|
468
|
-
result
|
469
|
-
};
|
470
|
-
})
|
471
|
-
});
|
472
|
-
}
|
473
404
|
if (content && !isLastMessage) {
|
474
405
|
coreMessages.push({ role: "assistant", content });
|
475
406
|
}
|
476
407
|
break;
|
477
408
|
}
|
478
|
-
case "data": {
|
479
|
-
break;
|
480
|
-
}
|
481
409
|
default: {
|
482
410
|
const _exhaustiveCheck = role;
|
483
411
|
throw new MessageConversionError({
|
@@ -728,7 +656,7 @@ async function standardizePrompt({
|
|
728
656
|
}
|
729
657
|
|
730
658
|
// core/util/index.ts
|
731
|
-
var
|
659
|
+
var import_provider_utils3 = require("@ai-sdk/provider-utils");
|
732
660
|
|
733
661
|
// core/util/data-stream-parts.ts
|
734
662
|
var textStreamPart = {
|
@@ -986,53 +914,6 @@ function formatDataStreamPart(type, value) {
|
|
986
914
|
`;
|
987
915
|
}
|
988
916
|
|
989
|
-
// core/util/schema.ts
|
990
|
-
var import_provider_utils3 = require("@ai-sdk/provider-utils");
|
991
|
-
|
992
|
-
// core/util/zod-schema.ts
|
993
|
-
var import_zod_to_json_schema = __toESM(require("zod-to-json-schema"));
|
994
|
-
function zodSchema(zodSchema2, options) {
|
995
|
-
var _a7;
|
996
|
-
const useReferences = (_a7 = options == null ? void 0 : options.useReferences) != null ? _a7 : false;
|
997
|
-
return jsonSchema(
|
998
|
-
(0, import_zod_to_json_schema.default)(zodSchema2, {
|
999
|
-
$refStrategy: useReferences ? "root" : "none",
|
1000
|
-
target: "jsonSchema7"
|
1001
|
-
// note: openai mode breaks various gemini conversions
|
1002
|
-
}),
|
1003
|
-
{
|
1004
|
-
validate: (value) => {
|
1005
|
-
const result = zodSchema2.safeParse(value);
|
1006
|
-
return result.success ? { success: true, value: result.data } : { success: false, error: result.error };
|
1007
|
-
}
|
1008
|
-
}
|
1009
|
-
);
|
1010
|
-
}
|
1011
|
-
|
1012
|
-
// core/util/schema.ts
|
1013
|
-
var schemaSymbol = Symbol.for("vercel.ai.schema");
|
1014
|
-
function jsonSchema(jsonSchema2, {
|
1015
|
-
validate
|
1016
|
-
} = {}) {
|
1017
|
-
return {
|
1018
|
-
[schemaSymbol]: true,
|
1019
|
-
_type: void 0,
|
1020
|
-
// should never be used directly
|
1021
|
-
[import_provider_utils3.validatorSymbol]: true,
|
1022
|
-
jsonSchema: jsonSchema2,
|
1023
|
-
validate
|
1024
|
-
};
|
1025
|
-
}
|
1026
|
-
function isSchema(value) {
|
1027
|
-
return typeof value === "object" && value !== null && schemaSymbol in value && value[schemaSymbol] === true && "jsonSchema" in value && "validate" in value;
|
1028
|
-
}
|
1029
|
-
function asSchema(schema) {
|
1030
|
-
return schema == null ? jsonSchema({
|
1031
|
-
properties: {},
|
1032
|
-
additionalProperties: false
|
1033
|
-
}) : isSchema(schema) ? schema : zodSchema(schema);
|
1034
|
-
}
|
1035
|
-
|
1036
917
|
// core/util/is-non-empty-object.ts
|
1037
918
|
function isNonEmptyObject(object) {
|
1038
919
|
return object != null && Object.keys(object).length > 0;
|
@@ -1063,7 +944,7 @@ function prepareToolsAndToolChoice({
|
|
1063
944
|
type: "function",
|
1064
945
|
name: name7,
|
1065
946
|
description: tool.description,
|
1066
|
-
parameters: asSchema(tool.parameters).jsonSchema
|
947
|
+
parameters: (0, import_provider_utils3.asSchema)(tool.parameters).jsonSchema
|
1067
948
|
};
|
1068
949
|
case "provider-defined":
|
1069
950
|
return {
|
@@ -1110,7 +991,7 @@ _a3 = symbol3;
|
|
1110
991
|
|
1111
992
|
// util/retry-with-exponential-backoff.ts
|
1112
993
|
var import_provider7 = require("@ai-sdk/provider");
|
1113
|
-
var
|
994
|
+
var import_provider_utils4 = require("@ai-sdk/provider-utils");
|
1114
995
|
|
1115
996
|
// util/retry-error.ts
|
1116
997
|
var import_provider6 = require("@ai-sdk/provider");
|
@@ -1154,13 +1035,13 @@ async function _retryWithExponentialBackoff(f, {
|
|
1154
1035
|
try {
|
1155
1036
|
return await f();
|
1156
1037
|
} catch (error) {
|
1157
|
-
if ((0,
|
1038
|
+
if ((0, import_provider_utils4.isAbortError)(error)) {
|
1158
1039
|
throw error;
|
1159
1040
|
}
|
1160
1041
|
if (maxRetries === 0) {
|
1161
1042
|
throw error;
|
1162
1043
|
}
|
1163
|
-
const errorMessage = (0,
|
1044
|
+
const errorMessage = (0, import_provider_utils4.getErrorMessage)(error);
|
1164
1045
|
const newErrors = [...errors, error];
|
1165
1046
|
const tryNumber = newErrors.length;
|
1166
1047
|
if (tryNumber > maxRetries) {
|
@@ -1171,7 +1052,7 @@ async function _retryWithExponentialBackoff(f, {
|
|
1171
1052
|
});
|
1172
1053
|
}
|
1173
1054
|
if (error instanceof Error && import_provider7.APICallError.isInstance(error) && error.isRetryable === true && tryNumber <= maxRetries) {
|
1174
|
-
await (0,
|
1055
|
+
await (0, import_provider_utils4.delay)(delayInMs);
|
1175
1056
|
return _retryWithExponentialBackoff(
|
1176
1057
|
f,
|
1177
1058
|
{ maxRetries, delayInMs: backoffFactor * delayInMs, backoffFactor },
|
@@ -1361,7 +1242,7 @@ async function download({ url }) {
|
|
1361
1242
|
}
|
1362
1243
|
|
1363
1244
|
// core/util/detect-media-type.ts
|
1364
|
-
var
|
1245
|
+
var import_provider_utils5 = require("@ai-sdk/provider-utils");
|
1365
1246
|
var imageMediaTypeSignatures = [
|
1366
1247
|
{
|
1367
1248
|
mediaType: "image/gif",
|
@@ -1436,7 +1317,7 @@ var imageMediaTypeSignatures = [
|
|
1436
1317
|
}
|
1437
1318
|
];
|
1438
1319
|
var stripID3 = (data) => {
|
1439
|
-
const bytes = typeof data === "string" ? (0,
|
1320
|
+
const bytes = typeof data === "string" ? (0, import_provider_utils5.convertBase64ToUint8Array)(data) : data;
|
1440
1321
|
const id3Size = (bytes[6] & 127) << 21 | (bytes[7] & 127) << 14 | (bytes[8] & 127) << 7 | bytes[9] & 127;
|
1441
1322
|
return bytes.slice(id3Size + 10);
|
1442
1323
|
};
|
@@ -1483,7 +1364,7 @@ var InvalidMessageRoleError = class extends import_provider9.AISDKError {
|
|
1483
1364
|
_a6 = symbol6;
|
1484
1365
|
|
1485
1366
|
// core/prompt/convert-to-language-model-prompt.ts
|
1486
|
-
var
|
1367
|
+
var import_provider_utils6 = require("@ai-sdk/provider-utils");
|
1487
1368
|
async function convertToLanguageModelPrompt({
|
1488
1369
|
prompt,
|
1489
1370
|
supportedUrls,
|
@@ -1620,7 +1501,7 @@ async function downloadAssets(messages, downloadImplementation, supportedUrls) {
|
|
1620
1501
|
}
|
1621
1502
|
return { mediaType, data };
|
1622
1503
|
}).filter(
|
1623
|
-
(part) => part.data instanceof URL && part.mediaType != null && !(0,
|
1504
|
+
(part) => part.data instanceof URL && part.mediaType != null && !(0, import_provider_utils6.isUrlSupported)({
|
1624
1505
|
url: part.data.toString(),
|
1625
1506
|
mediaType: part.mediaType,
|
1626
1507
|
supportedUrls
|