ai 3.3.11 → 3.3.13
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/index.d.mts +13 -33
- package/dist/index.d.ts +13 -33
- package/dist/index.js +181 -72
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +171 -59
- package/dist/index.mjs.map +1 -1
- package/package.json +8 -8
- package/rsc/dist/index.d.ts +12 -11
- package/rsc/dist/rsc-server.d.mts +12 -11
- package/rsc/dist/rsc-server.mjs +164 -40
- package/rsc/dist/rsc-server.mjs.map +1 -1
package/dist/index.d.mts
CHANGED
@@ -103,12 +103,6 @@ some settings might not be supported, which can lead to suboptimal results.
|
|
103
103
|
*/
|
104
104
|
type CallWarning = LanguageModelV1CallWarning;
|
105
105
|
/**
|
106
|
-
Additional provider-specific metadata. They are passed through
|
107
|
-
to the provider from the AI SDK and enable provider-specific
|
108
|
-
functionality that can be fully encapsulated in the provider.
|
109
|
-
*/
|
110
|
-
type ProviderMetadata = LanguageModelV1ProviderMetadata;
|
111
|
-
/**
|
112
106
|
Tool choice for the generation. It supports the following settings:
|
113
107
|
|
114
108
|
- `auto` (default): the model can choose whether and which tools to call.
|
@@ -121,6 +115,13 @@ type CoreToolChoice<TOOLS extends Record<string, unknown>> = 'auto' | 'none' | '
|
|
121
115
|
toolName: keyof TOOLS;
|
122
116
|
};
|
123
117
|
|
118
|
+
/**
|
119
|
+
Additional provider-specific metadata. They are passed through
|
120
|
+
to the provider from the AI SDK and enable provider-specific
|
121
|
+
functionality that can be fully encapsulated in the provider.
|
122
|
+
*/
|
123
|
+
type ProviderMetadata = LanguageModelV1ProviderMetadata;
|
124
|
+
|
124
125
|
/**
|
125
126
|
* @deprecated Use CompletionTokenUsage instead.
|
126
127
|
*/
|
@@ -344,27 +345,6 @@ type CallSettings = {
|
|
344
345
|
Data content. Can either be a base64-encoded string, a Uint8Array, an ArrayBuffer, or a Buffer.
|
345
346
|
*/
|
346
347
|
type DataContent = string | Uint8Array | ArrayBuffer | Buffer;
|
347
|
-
/**
|
348
|
-
Converts data content to a base64-encoded string.
|
349
|
-
|
350
|
-
@param content - Data content to convert.
|
351
|
-
@returns Base64-encoded string.
|
352
|
-
*/
|
353
|
-
declare function convertDataContentToBase64String(content: DataContent): string;
|
354
|
-
/**
|
355
|
-
Converts data content to a Uint8Array.
|
356
|
-
|
357
|
-
@param content - Data content to convert.
|
358
|
-
@returns Uint8Array.
|
359
|
-
*/
|
360
|
-
declare function convertDataContentToUint8Array(content: DataContent): Uint8Array;
|
361
|
-
/**
|
362
|
-
* Converts a Uint8Array to a string of text.
|
363
|
-
*
|
364
|
-
* @param uint8Array - The Uint8Array to convert.
|
365
|
-
* @returns The converted string.
|
366
|
-
*/
|
367
|
-
declare function convertUint8ArrayToText(uint8Array: Uint8Array): string;
|
368
348
|
|
369
349
|
/**
|
370
350
|
Text content part of a prompt. It contains a string of text.
|
@@ -452,11 +432,6 @@ interface ToolResultPart {
|
|
452
432
|
experimental_providerMetadata?: ProviderMetadata;
|
453
433
|
}
|
454
434
|
|
455
|
-
/**
|
456
|
-
A message that can be used in the `messages` field of a prompt.
|
457
|
-
It can be a user message, an assistant message, or a tool message.
|
458
|
-
*/
|
459
|
-
type CoreMessage = CoreSystemMessage | CoreUserMessage | CoreAssistantMessage | CoreToolMessage;
|
460
435
|
/**
|
461
436
|
A system message. It can contain system information.
|
462
437
|
|
@@ -541,6 +516,11 @@ type ExperimentalToolMessage = CoreToolMessage;
|
|
541
516
|
Content of a tool message. It is an array of tool result parts.
|
542
517
|
*/
|
543
518
|
type ToolContent = Array<ToolResultPart>;
|
519
|
+
/**
|
520
|
+
A message that can be used in the `messages` field of a prompt.
|
521
|
+
It can be a user message, an assistant message, or a tool message.
|
522
|
+
*/
|
523
|
+
type CoreMessage = CoreSystemMessage | CoreUserMessage | CoreAssistantMessage | CoreToolMessage;
|
544
524
|
|
545
525
|
/**
|
546
526
|
Prompt part of the AI function options. It contains a system message, a simple text prompt, or a list of messages.
|
@@ -2801,4 +2781,4 @@ declare const generateId: (size?: number) => string;
|
|
2801
2781
|
*/
|
2802
2782
|
declare const nanoid: (size?: number) => string;
|
2803
2783
|
|
2804
|
-
export { AIStream, AIStreamCallbacksAndOptions, AIStreamParser, AIStreamParserOptions, AWSBedrockAnthropicMessagesStream, AWSBedrockAnthropicStream, AWSBedrockCohereStream, AWSBedrockLlama2Stream, AWSBedrockStream, AnthropicStream, AssistantContent, AssistantResponse, CallWarning, CohereStream, CompletionTokenUsage, CompletionUsage, CoreAssistantMessage, CoreMessage, CoreSystemMessage, CoreTool, CoreToolChoice, CoreToolMessage, CoreUserMessage, DataContent, DownloadError, EmbedManyResult, EmbedResult, Embedding, EmbeddingModel, EmbeddingTokenUsage, ExperimentalAssistantMessage, ExperimentalMessage, ExperimentalTool, ExperimentalToolMessage, ExperimentalUserMessage, FinishReason, FunctionCallPayload, GenerateObjectResult, GenerateTextResult, GoogleGenerativeAIStream, HuggingFaceStream, ImagePart, InkeepAIStreamCallbacksAndOptions, InkeepChatResultCallbacks, InkeepOnFinalMetadata, InkeepStream, InvalidArgumentError, InvalidDataContentError, InvalidMessageRoleError, InvalidModelIdError, InvalidToolArgumentsError, langchainAdapter as LangChainAdapter, LangChainStream, LanguageModel, LogProbs, MistralStream, ModelType, NoObjectGeneratedError, NoSuchModelError, NoSuchProviderError, NoSuchToolError, ObjectStreamInputPart, ObjectStreamPart, OpenAIStream, OpenAIStreamCallbacks, ProviderMetadata, ReplicateStream, RetryError, StreamData, StreamObjectResult, StreamTextResult, StreamingTextResponse, TextPart$1 as TextPart, TextStreamPart, TokenUsage, ToolCallPart, ToolCallPayload, ToolContent, ToolResultPart, UserContent,
|
2784
|
+
export { AIStream, AIStreamCallbacksAndOptions, AIStreamParser, AIStreamParserOptions, AWSBedrockAnthropicMessagesStream, AWSBedrockAnthropicStream, AWSBedrockCohereStream, AWSBedrockLlama2Stream, AWSBedrockStream, AnthropicStream, AssistantContent, AssistantResponse, CallWarning, CohereStream, CompletionTokenUsage, CompletionUsage, CoreAssistantMessage, CoreMessage, CoreSystemMessage, CoreTool, CoreToolChoice, CoreToolMessage, CoreUserMessage, DataContent, DownloadError, EmbedManyResult, EmbedResult, Embedding, EmbeddingModel, EmbeddingTokenUsage, ExperimentalAssistantMessage, ExperimentalMessage, ExperimentalTool, ExperimentalToolMessage, ExperimentalUserMessage, FinishReason, FunctionCallPayload, GenerateObjectResult, GenerateTextResult, GoogleGenerativeAIStream, HuggingFaceStream, ImagePart, InkeepAIStreamCallbacksAndOptions, InkeepChatResultCallbacks, InkeepOnFinalMetadata, InkeepStream, InvalidArgumentError, InvalidDataContentError, InvalidMessageRoleError, InvalidModelIdError, InvalidToolArgumentsError, langchainAdapter as LangChainAdapter, LangChainStream, LanguageModel, LogProbs, MistralStream, ModelType, NoObjectGeneratedError, NoSuchModelError, NoSuchProviderError, NoSuchToolError, ObjectStreamInputPart, ObjectStreamPart, OpenAIStream, OpenAIStreamCallbacks, ProviderMetadata, ReplicateStream, RetryError, StreamData, StreamObjectResult, StreamTextResult, StreamingTextResponse, TextPart$1 as TextPart, TextStreamPart, TokenUsage, ToolCallPart, ToolCallPayload, ToolContent, ToolResultPart, UserContent, convertToCoreMessages, cosineSimilarity, createCallbacksTransformer, createEventStreamTransformer, createStreamDataTransformer, embed, embedMany, experimental_AssistantResponse, experimental_ModelRegistry, experimental_Provider, experimental_ProviderRegistry, experimental_StreamData, experimental_createModelRegistry, experimental_createProviderRegistry, experimental_generateObject, experimental_generateText, experimental_streamObject, experimental_streamText, generateId, generateObject, generateText, nanoid, readableFromAsyncIterable, streamObject, streamText, streamToResponse, tool, trimStartOfStreamHelper };
|
package/dist/index.d.ts
CHANGED
@@ -103,12 +103,6 @@ some settings might not be supported, which can lead to suboptimal results.
|
|
103
103
|
*/
|
104
104
|
type CallWarning = LanguageModelV1CallWarning;
|
105
105
|
/**
|
106
|
-
Additional provider-specific metadata. They are passed through
|
107
|
-
to the provider from the AI SDK and enable provider-specific
|
108
|
-
functionality that can be fully encapsulated in the provider.
|
109
|
-
*/
|
110
|
-
type ProviderMetadata = LanguageModelV1ProviderMetadata;
|
111
|
-
/**
|
112
106
|
Tool choice for the generation. It supports the following settings:
|
113
107
|
|
114
108
|
- `auto` (default): the model can choose whether and which tools to call.
|
@@ -121,6 +115,13 @@ type CoreToolChoice<TOOLS extends Record<string, unknown>> = 'auto' | 'none' | '
|
|
121
115
|
toolName: keyof TOOLS;
|
122
116
|
};
|
123
117
|
|
118
|
+
/**
|
119
|
+
Additional provider-specific metadata. They are passed through
|
120
|
+
to the provider from the AI SDK and enable provider-specific
|
121
|
+
functionality that can be fully encapsulated in the provider.
|
122
|
+
*/
|
123
|
+
type ProviderMetadata = LanguageModelV1ProviderMetadata;
|
124
|
+
|
124
125
|
/**
|
125
126
|
* @deprecated Use CompletionTokenUsage instead.
|
126
127
|
*/
|
@@ -344,27 +345,6 @@ type CallSettings = {
|
|
344
345
|
Data content. Can either be a base64-encoded string, a Uint8Array, an ArrayBuffer, or a Buffer.
|
345
346
|
*/
|
346
347
|
type DataContent = string | Uint8Array | ArrayBuffer | Buffer;
|
347
|
-
/**
|
348
|
-
Converts data content to a base64-encoded string.
|
349
|
-
|
350
|
-
@param content - Data content to convert.
|
351
|
-
@returns Base64-encoded string.
|
352
|
-
*/
|
353
|
-
declare function convertDataContentToBase64String(content: DataContent): string;
|
354
|
-
/**
|
355
|
-
Converts data content to a Uint8Array.
|
356
|
-
|
357
|
-
@param content - Data content to convert.
|
358
|
-
@returns Uint8Array.
|
359
|
-
*/
|
360
|
-
declare function convertDataContentToUint8Array(content: DataContent): Uint8Array;
|
361
|
-
/**
|
362
|
-
* Converts a Uint8Array to a string of text.
|
363
|
-
*
|
364
|
-
* @param uint8Array - The Uint8Array to convert.
|
365
|
-
* @returns The converted string.
|
366
|
-
*/
|
367
|
-
declare function convertUint8ArrayToText(uint8Array: Uint8Array): string;
|
368
348
|
|
369
349
|
/**
|
370
350
|
Text content part of a prompt. It contains a string of text.
|
@@ -452,11 +432,6 @@ interface ToolResultPart {
|
|
452
432
|
experimental_providerMetadata?: ProviderMetadata;
|
453
433
|
}
|
454
434
|
|
455
|
-
/**
|
456
|
-
A message that can be used in the `messages` field of a prompt.
|
457
|
-
It can be a user message, an assistant message, or a tool message.
|
458
|
-
*/
|
459
|
-
type CoreMessage = CoreSystemMessage | CoreUserMessage | CoreAssistantMessage | CoreToolMessage;
|
460
435
|
/**
|
461
436
|
A system message. It can contain system information.
|
462
437
|
|
@@ -541,6 +516,11 @@ type ExperimentalToolMessage = CoreToolMessage;
|
|
541
516
|
Content of a tool message. It is an array of tool result parts.
|
542
517
|
*/
|
543
518
|
type ToolContent = Array<ToolResultPart>;
|
519
|
+
/**
|
520
|
+
A message that can be used in the `messages` field of a prompt.
|
521
|
+
It can be a user message, an assistant message, or a tool message.
|
522
|
+
*/
|
523
|
+
type CoreMessage = CoreSystemMessage | CoreUserMessage | CoreAssistantMessage | CoreToolMessage;
|
544
524
|
|
545
525
|
/**
|
546
526
|
Prompt part of the AI function options. It contains a system message, a simple text prompt, or a list of messages.
|
@@ -2801,4 +2781,4 @@ declare const generateId: (size?: number) => string;
|
|
2801
2781
|
*/
|
2802
2782
|
declare const nanoid: (size?: number) => string;
|
2803
2783
|
|
2804
|
-
export { AIStream, AIStreamCallbacksAndOptions, AIStreamParser, AIStreamParserOptions, AWSBedrockAnthropicMessagesStream, AWSBedrockAnthropicStream, AWSBedrockCohereStream, AWSBedrockLlama2Stream, AWSBedrockStream, AnthropicStream, AssistantContent, AssistantResponse, CallWarning, CohereStream, CompletionTokenUsage, CompletionUsage, CoreAssistantMessage, CoreMessage, CoreSystemMessage, CoreTool, CoreToolChoice, CoreToolMessage, CoreUserMessage, DataContent, DownloadError, EmbedManyResult, EmbedResult, Embedding, EmbeddingModel, EmbeddingTokenUsage, ExperimentalAssistantMessage, ExperimentalMessage, ExperimentalTool, ExperimentalToolMessage, ExperimentalUserMessage, FinishReason, FunctionCallPayload, GenerateObjectResult, GenerateTextResult, GoogleGenerativeAIStream, HuggingFaceStream, ImagePart, InkeepAIStreamCallbacksAndOptions, InkeepChatResultCallbacks, InkeepOnFinalMetadata, InkeepStream, InvalidArgumentError, InvalidDataContentError, InvalidMessageRoleError, InvalidModelIdError, InvalidToolArgumentsError, langchainAdapter as LangChainAdapter, LangChainStream, LanguageModel, LogProbs, MistralStream, ModelType, NoObjectGeneratedError, NoSuchModelError, NoSuchProviderError, NoSuchToolError, ObjectStreamInputPart, ObjectStreamPart, OpenAIStream, OpenAIStreamCallbacks, ProviderMetadata, ReplicateStream, RetryError, StreamData, StreamObjectResult, StreamTextResult, StreamingTextResponse, TextPart$1 as TextPart, TextStreamPart, TokenUsage, ToolCallPart, ToolCallPayload, ToolContent, ToolResultPart, UserContent,
|
2784
|
+
export { AIStream, AIStreamCallbacksAndOptions, AIStreamParser, AIStreamParserOptions, AWSBedrockAnthropicMessagesStream, AWSBedrockAnthropicStream, AWSBedrockCohereStream, AWSBedrockLlama2Stream, AWSBedrockStream, AnthropicStream, AssistantContent, AssistantResponse, CallWarning, CohereStream, CompletionTokenUsage, CompletionUsage, CoreAssistantMessage, CoreMessage, CoreSystemMessage, CoreTool, CoreToolChoice, CoreToolMessage, CoreUserMessage, DataContent, DownloadError, EmbedManyResult, EmbedResult, Embedding, EmbeddingModel, EmbeddingTokenUsage, ExperimentalAssistantMessage, ExperimentalMessage, ExperimentalTool, ExperimentalToolMessage, ExperimentalUserMessage, FinishReason, FunctionCallPayload, GenerateObjectResult, GenerateTextResult, GoogleGenerativeAIStream, HuggingFaceStream, ImagePart, InkeepAIStreamCallbacksAndOptions, InkeepChatResultCallbacks, InkeepOnFinalMetadata, InkeepStream, InvalidArgumentError, InvalidDataContentError, InvalidMessageRoleError, InvalidModelIdError, InvalidToolArgumentsError, langchainAdapter as LangChainAdapter, LangChainStream, LanguageModel, LogProbs, MistralStream, ModelType, NoObjectGeneratedError, NoSuchModelError, NoSuchProviderError, NoSuchToolError, ObjectStreamInputPart, ObjectStreamPart, OpenAIStream, OpenAIStreamCallbacks, ProviderMetadata, ReplicateStream, RetryError, StreamData, StreamObjectResult, StreamTextResult, StreamingTextResponse, TextPart$1 as TextPart, TextStreamPart, TokenUsage, ToolCallPart, ToolCallPayload, ToolContent, ToolResultPart, UserContent, convertToCoreMessages, cosineSimilarity, createCallbacksTransformer, createEventStreamTransformer, createStreamDataTransformer, embed, embedMany, experimental_AssistantResponse, experimental_ModelRegistry, experimental_Provider, experimental_ProviderRegistry, experimental_StreamData, experimental_createModelRegistry, experimental_createProviderRegistry, experimental_generateObject, experimental_generateText, experimental_streamObject, experimental_streamText, generateId, generateObject, generateText, nanoid, readableFromAsyncIterable, streamObject, streamText, streamToResponse, tool, trimStartOfStreamHelper };
|
package/dist/index.js
CHANGED
@@ -59,10 +59,7 @@ __export(streams_exports, {
|
|
59
59
|
StreamingTextResponse: () => StreamingTextResponse,
|
60
60
|
TypeValidationError: () => import_provider14.TypeValidationError,
|
61
61
|
UnsupportedFunctionalityError: () => import_provider14.UnsupportedFunctionalityError,
|
62
|
-
convertDataContentToBase64String: () => convertDataContentToBase64String,
|
63
|
-
convertDataContentToUint8Array: () => convertDataContentToUint8Array,
|
64
62
|
convertToCoreMessages: () => convertToCoreMessages,
|
65
|
-
convertUint8ArrayToText: () => convertUint8ArrayToText,
|
66
63
|
cosineSimilarity: () => cosineSimilarity,
|
67
64
|
createCallbacksTransformer: () => createCallbacksTransformer,
|
68
65
|
createEventStreamTransformer: () => createEventStreamTransformer,
|
@@ -95,7 +92,7 @@ __export(streams_exports, {
|
|
95
92
|
});
|
96
93
|
module.exports = __toCommonJS(streams_exports);
|
97
94
|
var import_ui_utils10 = require("@ai-sdk/ui-utils");
|
98
|
-
var
|
95
|
+
var import_provider_utils8 = require("@ai-sdk/provider-utils");
|
99
96
|
|
100
97
|
// core/index.ts
|
101
98
|
var import_ui_utils6 = require("@ai-sdk/ui-utils");
|
@@ -672,7 +669,7 @@ var DefaultEmbedManyResult = class {
|
|
672
669
|
};
|
673
670
|
|
674
671
|
// core/generate-object/generate-object.ts
|
675
|
-
var
|
672
|
+
var import_provider_utils5 = require("@ai-sdk/provider-utils");
|
676
673
|
var import_ui_utils = require("@ai-sdk/ui-utils");
|
677
674
|
|
678
675
|
// core/prompt/convert-to-language-model-prompt.ts
|
@@ -811,15 +808,20 @@ var InvalidDataContentError = class extends import_provider4.AISDKError {
|
|
811
808
|
_a3 = symbol3;
|
812
809
|
|
813
810
|
// core/prompt/data-content.ts
|
814
|
-
|
815
|
-
|
816
|
-
|
817
|
-
|
818
|
-
|
819
|
-
|
820
|
-
|
821
|
-
|
822
|
-
|
811
|
+
var import_zod = require("zod");
|
812
|
+
var dataContentSchema = import_zod.z.union([
|
813
|
+
import_zod.z.string(),
|
814
|
+
import_zod.z.instanceof(Uint8Array),
|
815
|
+
import_zod.z.instanceof(ArrayBuffer),
|
816
|
+
import_zod.z.custom(
|
817
|
+
// Buffer might not be available in some environments such as CloudFlare:
|
818
|
+
(value) => {
|
819
|
+
var _a12, _b;
|
820
|
+
return (_b = (_a12 = globalThis.Buffer) == null ? void 0 : _a12.isBuffer(value)) != null ? _b : false;
|
821
|
+
},
|
822
|
+
{ message: "Must be a Buffer" }
|
823
|
+
)
|
824
|
+
]);
|
823
825
|
function convertDataContentToUint8Array(content) {
|
824
826
|
if (content instanceof Uint8Array) {
|
825
827
|
return content;
|
@@ -1094,52 +1096,13 @@ async function downloadImages(messages, downloadImplementation) {
|
|
1094
1096
|
);
|
1095
1097
|
}
|
1096
1098
|
|
1097
|
-
// core/prompt/get-validated-prompt.ts
|
1098
|
-
var import_provider6 = require("@ai-sdk/provider");
|
1099
|
-
function getValidatedPrompt(prompt) {
|
1100
|
-
if (prompt.prompt == null && prompt.messages == null) {
|
1101
|
-
throw new import_provider6.InvalidPromptError({
|
1102
|
-
prompt,
|
1103
|
-
message: "prompt or messages must be defined"
|
1104
|
-
});
|
1105
|
-
}
|
1106
|
-
if (prompt.prompt != null && prompt.messages != null) {
|
1107
|
-
throw new import_provider6.InvalidPromptError({
|
1108
|
-
prompt,
|
1109
|
-
message: "prompt and messages cannot be defined at the same time"
|
1110
|
-
});
|
1111
|
-
}
|
1112
|
-
if (prompt.messages != null) {
|
1113
|
-
for (const message of prompt.messages) {
|
1114
|
-
if (message.role === "system" && typeof message.content !== "string") {
|
1115
|
-
throw new import_provider6.InvalidPromptError({
|
1116
|
-
prompt,
|
1117
|
-
message: "system message content must be a string"
|
1118
|
-
});
|
1119
|
-
}
|
1120
|
-
}
|
1121
|
-
}
|
1122
|
-
return prompt.prompt != null ? {
|
1123
|
-
type: "prompt",
|
1124
|
-
prompt: prompt.prompt,
|
1125
|
-
messages: void 0,
|
1126
|
-
system: prompt.system
|
1127
|
-
} : {
|
1128
|
-
type: "messages",
|
1129
|
-
prompt: void 0,
|
1130
|
-
messages: prompt.messages,
|
1131
|
-
// only possible case bc of checks above
|
1132
|
-
system: prompt.system
|
1133
|
-
};
|
1134
|
-
}
|
1135
|
-
|
1136
1099
|
// errors/invalid-argument-error.ts
|
1137
|
-
var
|
1100
|
+
var import_provider6 = require("@ai-sdk/provider");
|
1138
1101
|
var name5 = "AI_InvalidArgumentError";
|
1139
1102
|
var marker5 = `vercel.ai.error.${name5}`;
|
1140
1103
|
var symbol5 = Symbol.for(marker5);
|
1141
1104
|
var _a5;
|
1142
|
-
var InvalidArgumentError = class extends
|
1105
|
+
var InvalidArgumentError = class extends import_provider6.AISDKError {
|
1143
1106
|
constructor({
|
1144
1107
|
parameter,
|
1145
1108
|
value,
|
@@ -1154,7 +1117,7 @@ var InvalidArgumentError = class extends import_provider7.AISDKError {
|
|
1154
1117
|
this.value = value;
|
1155
1118
|
}
|
1156
1119
|
static isInstance(error) {
|
1157
|
-
return
|
1120
|
+
return import_provider6.AISDKError.hasMarker(error, marker5);
|
1158
1121
|
}
|
1159
1122
|
/**
|
1160
1123
|
* @deprecated use `isInstance` instead
|
@@ -1274,6 +1237,155 @@ function prepareCallSettings({
|
|
1274
1237
|
};
|
1275
1238
|
}
|
1276
1239
|
|
1240
|
+
// core/prompt/validate-prompt.ts
|
1241
|
+
var import_provider7 = require("@ai-sdk/provider");
|
1242
|
+
var import_provider_utils4 = require("@ai-sdk/provider-utils");
|
1243
|
+
var import_zod6 = require("zod");
|
1244
|
+
|
1245
|
+
// core/prompt/message.ts
|
1246
|
+
var import_zod5 = require("zod");
|
1247
|
+
|
1248
|
+
// core/types/provider-metadata.ts
|
1249
|
+
var import_zod3 = require("zod");
|
1250
|
+
|
1251
|
+
// core/types/json-value.ts
|
1252
|
+
var import_zod2 = require("zod");
|
1253
|
+
var jsonValueSchema = import_zod2.z.lazy(
|
1254
|
+
() => import_zod2.z.union([
|
1255
|
+
import_zod2.z.null(),
|
1256
|
+
import_zod2.z.string(),
|
1257
|
+
import_zod2.z.number(),
|
1258
|
+
import_zod2.z.boolean(),
|
1259
|
+
import_zod2.z.record(import_zod2.z.string(), jsonValueSchema),
|
1260
|
+
import_zod2.z.array(jsonValueSchema)
|
1261
|
+
])
|
1262
|
+
);
|
1263
|
+
|
1264
|
+
// core/types/provider-metadata.ts
|
1265
|
+
var providerMetadataSchema = import_zod3.z.record(
|
1266
|
+
import_zod3.z.string(),
|
1267
|
+
import_zod3.z.record(import_zod3.z.string(), jsonValueSchema)
|
1268
|
+
);
|
1269
|
+
|
1270
|
+
// core/prompt/content-part.ts
|
1271
|
+
var import_zod4 = require("zod");
|
1272
|
+
var textPartSchema = import_zod4.z.object({
|
1273
|
+
type: import_zod4.z.literal("text"),
|
1274
|
+
text: import_zod4.z.string(),
|
1275
|
+
experimental_providerMetadata: providerMetadataSchema.optional()
|
1276
|
+
});
|
1277
|
+
var imagePartSchema = import_zod4.z.object({
|
1278
|
+
type: import_zod4.z.literal("image"),
|
1279
|
+
image: import_zod4.z.union([dataContentSchema, import_zod4.z.instanceof(URL)]),
|
1280
|
+
mimeType: import_zod4.z.string().optional(),
|
1281
|
+
experimental_providerMetadata: providerMetadataSchema.optional()
|
1282
|
+
});
|
1283
|
+
var toolCallPartSchema = import_zod4.z.object({
|
1284
|
+
type: import_zod4.z.literal("tool-call"),
|
1285
|
+
toolCallId: import_zod4.z.string(),
|
1286
|
+
toolName: import_zod4.z.string(),
|
1287
|
+
args: import_zod4.z.unknown()
|
1288
|
+
});
|
1289
|
+
var toolResultPartSchema = import_zod4.z.object({
|
1290
|
+
type: import_zod4.z.literal("tool-result"),
|
1291
|
+
toolCallId: import_zod4.z.string(),
|
1292
|
+
toolName: import_zod4.z.string(),
|
1293
|
+
result: import_zod4.z.unknown(),
|
1294
|
+
isError: import_zod4.z.boolean().optional(),
|
1295
|
+
experimental_providerMetadata: providerMetadataSchema.optional()
|
1296
|
+
});
|
1297
|
+
|
1298
|
+
// core/prompt/message.ts
|
1299
|
+
var coreSystemMessageSchema = import_zod5.z.object({
|
1300
|
+
role: import_zod5.z.literal("system"),
|
1301
|
+
content: import_zod5.z.string(),
|
1302
|
+
experimental_providerMetadata: providerMetadataSchema.optional()
|
1303
|
+
});
|
1304
|
+
var coreUserMessageSchema = import_zod5.z.object({
|
1305
|
+
role: import_zod5.z.literal("user"),
|
1306
|
+
content: import_zod5.z.union([
|
1307
|
+
import_zod5.z.string(),
|
1308
|
+
import_zod5.z.array(import_zod5.z.union([textPartSchema, imagePartSchema]))
|
1309
|
+
]),
|
1310
|
+
experimental_providerMetadata: providerMetadataSchema.optional()
|
1311
|
+
});
|
1312
|
+
var coreAssistantMessageSchema = import_zod5.z.object({
|
1313
|
+
role: import_zod5.z.literal("assistant"),
|
1314
|
+
content: import_zod5.z.union([
|
1315
|
+
import_zod5.z.string(),
|
1316
|
+
import_zod5.z.array(import_zod5.z.union([textPartSchema, toolCallPartSchema]))
|
1317
|
+
]),
|
1318
|
+
experimental_providerMetadata: providerMetadataSchema.optional()
|
1319
|
+
});
|
1320
|
+
var coreToolMessageSchema = import_zod5.z.object({
|
1321
|
+
role: import_zod5.z.literal("tool"),
|
1322
|
+
content: import_zod5.z.array(toolResultPartSchema),
|
1323
|
+
experimental_providerMetadata: providerMetadataSchema.optional()
|
1324
|
+
});
|
1325
|
+
var coreMessageSchema = import_zod5.z.union([
|
1326
|
+
coreSystemMessageSchema,
|
1327
|
+
coreUserMessageSchema,
|
1328
|
+
coreAssistantMessageSchema,
|
1329
|
+
coreToolMessageSchema
|
1330
|
+
]);
|
1331
|
+
|
1332
|
+
// core/prompt/validate-prompt.ts
|
1333
|
+
function validatePrompt(prompt) {
|
1334
|
+
if (prompt.prompt == null && prompt.messages == null) {
|
1335
|
+
throw new import_provider7.InvalidPromptError({
|
1336
|
+
prompt,
|
1337
|
+
message: "prompt or messages must be defined"
|
1338
|
+
});
|
1339
|
+
}
|
1340
|
+
if (prompt.prompt != null && prompt.messages != null) {
|
1341
|
+
throw new import_provider7.InvalidPromptError({
|
1342
|
+
prompt,
|
1343
|
+
message: "prompt and messages cannot be defined at the same time"
|
1344
|
+
});
|
1345
|
+
}
|
1346
|
+
if (prompt.system != null && typeof prompt.system !== "string") {
|
1347
|
+
throw new import_provider7.InvalidPromptError({
|
1348
|
+
prompt,
|
1349
|
+
message: "system must be a string"
|
1350
|
+
});
|
1351
|
+
}
|
1352
|
+
if (prompt.prompt != null) {
|
1353
|
+
if (typeof prompt.prompt !== "string") {
|
1354
|
+
throw new import_provider7.InvalidPromptError({
|
1355
|
+
prompt,
|
1356
|
+
message: "prompt must be a string"
|
1357
|
+
});
|
1358
|
+
}
|
1359
|
+
return {
|
1360
|
+
type: "prompt",
|
1361
|
+
prompt: prompt.prompt,
|
1362
|
+
messages: void 0,
|
1363
|
+
system: prompt.system
|
1364
|
+
};
|
1365
|
+
}
|
1366
|
+
if (prompt.messages != null) {
|
1367
|
+
const validationResult = (0, import_provider_utils4.safeValidateTypes)({
|
1368
|
+
value: prompt.messages,
|
1369
|
+
schema: import_zod6.z.array(coreMessageSchema)
|
1370
|
+
});
|
1371
|
+
if (!validationResult.success) {
|
1372
|
+
throw new import_provider7.InvalidPromptError({
|
1373
|
+
prompt,
|
1374
|
+
message: "messages must be an array of CoreMessage",
|
1375
|
+
cause: validationResult.error
|
1376
|
+
});
|
1377
|
+
}
|
1378
|
+
return {
|
1379
|
+
type: "messages",
|
1380
|
+
prompt: void 0,
|
1381
|
+
messages: prompt.messages,
|
1382
|
+
// only possible case bc of checks above
|
1383
|
+
system: prompt.system
|
1384
|
+
};
|
1385
|
+
}
|
1386
|
+
throw new Error("unreachable");
|
1387
|
+
}
|
1388
|
+
|
1277
1389
|
// core/types/token-usage.ts
|
1278
1390
|
function calculateCompletionTokenUsage(usage) {
|
1279
1391
|
return {
|
@@ -1415,7 +1527,7 @@ async function generateObject({
|
|
1415
1527
|
let providerMetadata;
|
1416
1528
|
switch (mode) {
|
1417
1529
|
case "json": {
|
1418
|
-
const validatedPrompt =
|
1530
|
+
const validatedPrompt = validatePrompt({
|
1419
1531
|
system: model.supportsStructuredOutputs ? system : injectJsonSchemaIntoSystem({
|
1420
1532
|
system,
|
1421
1533
|
schema: schema.jsonSchema
|
@@ -1501,7 +1613,7 @@ async function generateObject({
|
|
1501
1613
|
break;
|
1502
1614
|
}
|
1503
1615
|
case "tool": {
|
1504
|
-
const validatedPrompt =
|
1616
|
+
const validatedPrompt = validatePrompt({
|
1505
1617
|
system,
|
1506
1618
|
prompt,
|
1507
1619
|
messages
|
@@ -1598,7 +1710,7 @@ async function generateObject({
|
|
1598
1710
|
throw new Error(`Unsupported mode: ${_exhaustiveCheck}`);
|
1599
1711
|
}
|
1600
1712
|
}
|
1601
|
-
const parseResult = (0,
|
1713
|
+
const parseResult = (0, import_provider_utils5.safeParseJSON)({ text: result, schema });
|
1602
1714
|
if (!parseResult.success) {
|
1603
1715
|
throw parseResult.error;
|
1604
1716
|
}
|
@@ -1650,7 +1762,7 @@ var DefaultGenerateObjectResult = class {
|
|
1650
1762
|
var experimental_generateObject = generateObject;
|
1651
1763
|
|
1652
1764
|
// core/generate-object/stream-object.ts
|
1653
|
-
var
|
1765
|
+
var import_provider_utils6 = require("@ai-sdk/provider-utils");
|
1654
1766
|
var import_ui_utils2 = require("@ai-sdk/ui-utils");
|
1655
1767
|
|
1656
1768
|
// util/create-resolvable-promise.ts
|
@@ -1780,7 +1892,7 @@ async function streamObject({
|
|
1780
1892
|
let transformer;
|
1781
1893
|
switch (mode) {
|
1782
1894
|
case "json": {
|
1783
|
-
const validatedPrompt =
|
1895
|
+
const validatedPrompt = validatePrompt({
|
1784
1896
|
system: model.supportsStructuredOutputs ? system : injectJsonSchemaIntoSystem({
|
1785
1897
|
system,
|
1786
1898
|
schema: schema.jsonSchema
|
@@ -1820,7 +1932,7 @@ async function streamObject({
|
|
1820
1932
|
break;
|
1821
1933
|
}
|
1822
1934
|
case "tool": {
|
1823
|
-
const validatedPrompt =
|
1935
|
+
const validatedPrompt = validatePrompt({
|
1824
1936
|
system,
|
1825
1937
|
prompt,
|
1826
1938
|
messages
|
@@ -2002,7 +2114,7 @@ var DefaultStreamObjectResult = class {
|
|
2002
2114
|
controller.enqueue({ ...chunk, usage });
|
2003
2115
|
resolveUsage(usage);
|
2004
2116
|
resolveProviderMetadata(providerMetadata);
|
2005
|
-
const validationResult = (0,
|
2117
|
+
const validationResult = (0, import_provider_utils6.safeValidateTypes)({
|
2006
2118
|
value: latestObject,
|
2007
2119
|
schema
|
2008
2120
|
});
|
@@ -2194,7 +2306,7 @@ function prepareToolsAndToolChoice({
|
|
2194
2306
|
}
|
2195
2307
|
|
2196
2308
|
// core/generate-text/tool-call.ts
|
2197
|
-
var
|
2309
|
+
var import_provider_utils7 = require("@ai-sdk/provider-utils");
|
2198
2310
|
var import_ui_utils4 = require("@ai-sdk/ui-utils");
|
2199
2311
|
|
2200
2312
|
// errors/invalid-tool-arguments-error.ts
|
@@ -2299,7 +2411,7 @@ function parseToolCall({
|
|
2299
2411
|
availableTools: Object.keys(tools)
|
2300
2412
|
});
|
2301
2413
|
}
|
2302
|
-
const parseResult = (0,
|
2414
|
+
const parseResult = (0, import_provider_utils7.safeParseJSON)({
|
2303
2415
|
text: toolCall.args,
|
2304
2416
|
schema: (0, import_ui_utils4.asSchema)(tool2.parameters)
|
2305
2417
|
});
|
@@ -2363,7 +2475,7 @@ async function generateText({
|
|
2363
2475
|
fn: async (span) => {
|
2364
2476
|
var _a13, _b, _c, _d;
|
2365
2477
|
const retry = retryWithExponentialBackoff({ maxRetries });
|
2366
|
-
const validatedPrompt =
|
2478
|
+
const validatedPrompt = validatePrompt({
|
2367
2479
|
system,
|
2368
2480
|
prompt,
|
2369
2481
|
messages
|
@@ -2940,7 +3052,7 @@ async function streamText({
|
|
2940
3052
|
endWhenDone: false,
|
2941
3053
|
fn: async (rootSpan) => {
|
2942
3054
|
const retry = retryWithExponentialBackoff({ maxRetries });
|
2943
|
-
const validatedPrompt =
|
3055
|
+
const validatedPrompt = validatePrompt({ system, prompt, messages });
|
2944
3056
|
const promptMessages = await convertToLanguageModelPrompt({
|
2945
3057
|
prompt: validatedPrompt,
|
2946
3058
|
modelSupportsImageUrls: model.supportsImageUrls
|
@@ -4756,8 +4868,8 @@ var StreamingTextResponse = class extends Response {
|
|
4756
4868
|
};
|
4757
4869
|
|
4758
4870
|
// streams/index.ts
|
4759
|
-
var generateId2 =
|
4760
|
-
var nanoid =
|
4871
|
+
var generateId2 = import_provider_utils8.generateId;
|
4872
|
+
var nanoid = import_provider_utils8.generateId;
|
4761
4873
|
// Annotate the CommonJS export names for ESM import in node:
|
4762
4874
|
0 && (module.exports = {
|
4763
4875
|
AISDKError,
|
@@ -4799,10 +4911,7 @@ var nanoid = import_provider_utils7.generateId;
|
|
4799
4911
|
StreamingTextResponse,
|
4800
4912
|
TypeValidationError,
|
4801
4913
|
UnsupportedFunctionalityError,
|
4802
|
-
convertDataContentToBase64String,
|
4803
|
-
convertDataContentToUint8Array,
|
4804
4914
|
convertToCoreMessages,
|
4805
|
-
convertUint8ArrayToText,
|
4806
4915
|
cosineSimilarity,
|
4807
4916
|
createCallbacksTransformer,
|
4808
4917
|
createEventStreamTransformer,
|