ai 3.1.32 → 3.1.34
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 +101 -2
- package/dist/index.d.ts +101 -2
- package/dist/index.js +188 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +182 -5
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/rsc/dist/rsc-server.mjs +27 -3
- package/rsc/dist/rsc-server.mjs.map +1 -1
package/dist/index.mjs
CHANGED
@@ -11,7 +11,7 @@ import {
|
|
11
11
|
readDataStream,
|
12
12
|
parseComplexResponse
|
13
13
|
} from "@ai-sdk/ui-utils";
|
14
|
-
import { generateId as
|
14
|
+
import { generateId as generateIdImpl } from "@ai-sdk/provider-utils";
|
15
15
|
|
16
16
|
// core/util/retry-with-exponential-backoff.ts
|
17
17
|
import { APICallError, RetryError } from "@ai-sdk/provider";
|
@@ -215,6 +215,29 @@ function convertDataContentToUint8Array(content) {
|
|
215
215
|
throw new InvalidDataContentError({ content });
|
216
216
|
}
|
217
217
|
|
218
|
+
// core/prompt/invalid-message-role-error.ts
|
219
|
+
var InvalidMessageRoleError = class extends Error {
|
220
|
+
constructor({
|
221
|
+
role,
|
222
|
+
message = `Invalid message role: '${role}'. Must be one of: "system", "user", "assistant", "tool".`
|
223
|
+
}) {
|
224
|
+
super(message);
|
225
|
+
this.name = "AI_InvalidMessageRoleError";
|
226
|
+
this.role = role;
|
227
|
+
}
|
228
|
+
static isInvalidMessageRoleError(error) {
|
229
|
+
return error instanceof Error && error.name === "AI_InvalidMessageRoleError" && typeof error.role === "string";
|
230
|
+
}
|
231
|
+
toJSON() {
|
232
|
+
return {
|
233
|
+
name: this.name,
|
234
|
+
message: this.message,
|
235
|
+
stack: this.stack,
|
236
|
+
role: this.role
|
237
|
+
};
|
238
|
+
}
|
239
|
+
};
|
240
|
+
|
218
241
|
// core/prompt/convert-to-language-model-prompt.ts
|
219
242
|
function convertToLanguageModelPrompt(prompt) {
|
220
243
|
const languageModelMessages = [];
|
@@ -244,7 +267,8 @@ function convertToLanguageModelPrompt(prompt) {
|
|
244
267
|
return languageModelMessages;
|
245
268
|
}
|
246
269
|
function convertToLanguageModelMessage(message) {
|
247
|
-
|
270
|
+
const role = message.role;
|
271
|
+
switch (role) {
|
248
272
|
case "system": {
|
249
273
|
return { role: "system", content: message.content };
|
250
274
|
}
|
@@ -303,8 +327,8 @@ function convertToLanguageModelMessage(message) {
|
|
303
327
|
return message;
|
304
328
|
}
|
305
329
|
default: {
|
306
|
-
const _exhaustiveCheck =
|
307
|
-
throw new
|
330
|
+
const _exhaustiveCheck = role;
|
331
|
+
throw new InvalidMessageRoleError({ role: _exhaustiveCheck });
|
308
332
|
}
|
309
333
|
}
|
310
334
|
}
|
@@ -1974,6 +1998,130 @@ function convertToCoreMessages(messages) {
|
|
1974
1998
|
return coreMessages;
|
1975
1999
|
}
|
1976
2000
|
|
2001
|
+
// core/registry/invalid-model-id-error.ts
|
2002
|
+
var InvalidModelIdError = class extends Error {
|
2003
|
+
constructor({
|
2004
|
+
id,
|
2005
|
+
message = `Invalid model id: ${id}`
|
2006
|
+
}) {
|
2007
|
+
super(message);
|
2008
|
+
this.name = "AI_InvalidModelIdError";
|
2009
|
+
this.id = id;
|
2010
|
+
}
|
2011
|
+
static isInvalidModelIdError(error) {
|
2012
|
+
return error instanceof Error && error.name === "AI_InvalidModelIdError" && typeof error.id === "string";
|
2013
|
+
}
|
2014
|
+
toJSON() {
|
2015
|
+
return {
|
2016
|
+
name: this.name,
|
2017
|
+
message: this.message,
|
2018
|
+
stack: this.stack,
|
2019
|
+
id: this.id
|
2020
|
+
};
|
2021
|
+
}
|
2022
|
+
};
|
2023
|
+
|
2024
|
+
// core/registry/no-such-model-error.ts
|
2025
|
+
var NoSuchModelError = class extends Error {
|
2026
|
+
constructor({
|
2027
|
+
modelId,
|
2028
|
+
message = `No such model: ${modelId}`
|
2029
|
+
}) {
|
2030
|
+
super(message);
|
2031
|
+
this.name = "AI_NoSuchModelError";
|
2032
|
+
this.modelId = modelId;
|
2033
|
+
}
|
2034
|
+
static isNoSuchModelError(error) {
|
2035
|
+
return error instanceof Error && error.name === "AI_NoSuchModelError" && typeof error.modelId === "string";
|
2036
|
+
}
|
2037
|
+
toJSON() {
|
2038
|
+
return {
|
2039
|
+
name: this.name,
|
2040
|
+
message: this.message,
|
2041
|
+
stack: this.stack,
|
2042
|
+
modelId: this.modelId
|
2043
|
+
};
|
2044
|
+
}
|
2045
|
+
};
|
2046
|
+
|
2047
|
+
// core/registry/no-such-provider-error.ts
|
2048
|
+
var NoSuchProviderError = class extends Error {
|
2049
|
+
constructor({
|
2050
|
+
providerId,
|
2051
|
+
message = `No such provider: ${providerId}`
|
2052
|
+
}) {
|
2053
|
+
super(message);
|
2054
|
+
this.name = "AI_NoSuchProviderError";
|
2055
|
+
this.providerId = providerId;
|
2056
|
+
}
|
2057
|
+
static isNoSuchProviderError(error) {
|
2058
|
+
return error instanceof Error && error.name === "AI_NoSuchProviderError" && typeof error.providerId === "string";
|
2059
|
+
}
|
2060
|
+
toJSON() {
|
2061
|
+
return {
|
2062
|
+
name: this.name,
|
2063
|
+
message: this.message,
|
2064
|
+
stack: this.stack,
|
2065
|
+
providerId: this.providerId
|
2066
|
+
};
|
2067
|
+
}
|
2068
|
+
};
|
2069
|
+
|
2070
|
+
// core/registry/model-registry.ts
|
2071
|
+
function experimental_createModelRegistry(providers) {
|
2072
|
+
const registry = new DefaultModelRegistry();
|
2073
|
+
for (const [id, provider] of Object.entries(providers)) {
|
2074
|
+
registry.registerLanguageModelProvider({ id, provider });
|
2075
|
+
}
|
2076
|
+
return registry;
|
2077
|
+
}
|
2078
|
+
var DefaultModelRegistry = class {
|
2079
|
+
constructor() {
|
2080
|
+
// Mapping of provider id to provider
|
2081
|
+
this.providers = {};
|
2082
|
+
}
|
2083
|
+
/**
|
2084
|
+
Registers a language model provider with a given id.
|
2085
|
+
|
2086
|
+
@param {string} id - The id of the provider.
|
2087
|
+
@param {(id: string) => LanguageModel} provider - The provider function to register.
|
2088
|
+
*/
|
2089
|
+
registerLanguageModelProvider({
|
2090
|
+
id,
|
2091
|
+
provider
|
2092
|
+
}) {
|
2093
|
+
this.providers[id] = provider;
|
2094
|
+
}
|
2095
|
+
/**
|
2096
|
+
Returns the language model with the given id.
|
2097
|
+
The id can either be a registered model id or use a provider prefix.
|
2098
|
+
Provider ids are separated from the model id by a colon: `providerId:modelId`.
|
2099
|
+
The model id is then passed to the provider function to get the model.
|
2100
|
+
|
2101
|
+
@param {string} id - The id of the model to return.
|
2102
|
+
|
2103
|
+
@throws {NoSuchModelError} If no model with the given id exists.
|
2104
|
+
@throws {NoSuchProviderError} If no provider with the given id exists.
|
2105
|
+
|
2106
|
+
@returns {LanguageModel} The language model associated with the id.
|
2107
|
+
*/
|
2108
|
+
languageModel(id) {
|
2109
|
+
if (!id.includes(":")) {
|
2110
|
+
throw new InvalidModelIdError({ id });
|
2111
|
+
}
|
2112
|
+
const [providerId, modelId] = id.split(":");
|
2113
|
+
const provider = this.providers[providerId];
|
2114
|
+
if (!provider) {
|
2115
|
+
throw new NoSuchProviderError({ providerId });
|
2116
|
+
}
|
2117
|
+
const model = provider(modelId);
|
2118
|
+
if (!model) {
|
2119
|
+
throw new NoSuchModelError({ modelId: id });
|
2120
|
+
}
|
2121
|
+
return model;
|
2122
|
+
}
|
2123
|
+
};
|
2124
|
+
|
1977
2125
|
// core/tool/tool.ts
|
1978
2126
|
function tool(tool2) {
|
1979
2127
|
return tool2;
|
@@ -1999,6 +2147,25 @@ import {
|
|
1999
2147
|
UnsupportedJSONSchemaError
|
2000
2148
|
} from "@ai-sdk/provider";
|
2001
2149
|
|
2150
|
+
// core/util/cosine-similarity.ts
|
2151
|
+
function cosineSimilarity(vector1, vector2) {
|
2152
|
+
if (vector1.length !== vector2.length) {
|
2153
|
+
throw new Error(
|
2154
|
+
`Vectors must have the same length (vector1: ${vector1.length} elements, vector2: ${vector2.length} elements)`
|
2155
|
+
);
|
2156
|
+
}
|
2157
|
+
return dotProduct(vector1, vector2) / (magnitude(vector1) * magnitude(vector2));
|
2158
|
+
}
|
2159
|
+
function dotProduct(vector1, vector2) {
|
2160
|
+
return vector1.reduce(
|
2161
|
+
(accumulator, value, index) => accumulator + value * vector2[index],
|
2162
|
+
0
|
2163
|
+
);
|
2164
|
+
}
|
2165
|
+
function magnitude(vector) {
|
2166
|
+
return Math.sqrt(dotProduct(vector, vector));
|
2167
|
+
}
|
2168
|
+
|
2002
2169
|
// streams/ai-stream.ts
|
2003
2170
|
import {
|
2004
2171
|
createParser
|
@@ -3095,6 +3262,10 @@ var StreamingTextResponse = class extends Response {
|
|
3095
3262
|
});
|
3096
3263
|
}
|
3097
3264
|
};
|
3265
|
+
|
3266
|
+
// streams/index.ts
|
3267
|
+
var generateId2 = generateIdImpl;
|
3268
|
+
var nanoid = generateIdImpl;
|
3098
3269
|
export {
|
3099
3270
|
AIStream,
|
3100
3271
|
APICallError2 as APICallError,
|
@@ -3116,6 +3287,8 @@ export {
|
|
3116
3287
|
InkeepStream,
|
3117
3288
|
InvalidArgumentError2 as InvalidArgumentError,
|
3118
3289
|
InvalidDataContentError2 as InvalidDataContentError,
|
3290
|
+
InvalidMessageRoleError,
|
3291
|
+
InvalidModelIdError,
|
3119
3292
|
InvalidPromptError2 as InvalidPromptError,
|
3120
3293
|
InvalidResponseDataError,
|
3121
3294
|
InvalidToolArgumentsError2 as InvalidToolArgumentsError,
|
@@ -3125,6 +3298,8 @@ export {
|
|
3125
3298
|
LoadAPIKeyError,
|
3126
3299
|
MistralStream,
|
3127
3300
|
NoObjectGeneratedError2 as NoObjectGeneratedError,
|
3301
|
+
NoSuchModelError,
|
3302
|
+
NoSuchProviderError,
|
3128
3303
|
NoSuchToolError3 as NoSuchToolError,
|
3129
3304
|
OpenAIStream,
|
3130
3305
|
ReplicateStream,
|
@@ -3140,6 +3315,7 @@ export {
|
|
3140
3315
|
convertDataContentToBase64String,
|
3141
3316
|
convertDataContentToUint8Array,
|
3142
3317
|
convertToCoreMessages,
|
3318
|
+
cosineSimilarity,
|
3143
3319
|
createCallbacksTransformer,
|
3144
3320
|
createEventStreamTransformer,
|
3145
3321
|
createStreamDataTransformer,
|
@@ -3147,6 +3323,7 @@ export {
|
|
3147
3323
|
embedMany,
|
3148
3324
|
experimental_AssistantResponse,
|
3149
3325
|
experimental_StreamData,
|
3326
|
+
experimental_createModelRegistry,
|
3150
3327
|
experimental_generateObject,
|
3151
3328
|
experimental_generateText,
|
3152
3329
|
experimental_streamObject,
|
@@ -3155,7 +3332,7 @@ export {
|
|
3155
3332
|
generateId2 as generateId,
|
3156
3333
|
generateObject,
|
3157
3334
|
generateText,
|
3158
|
-
|
3335
|
+
nanoid,
|
3159
3336
|
parseComplexResponse,
|
3160
3337
|
parseStreamPart,
|
3161
3338
|
readDataStream,
|