ai 3.1.32 → 3.1.33

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.mjs CHANGED
@@ -11,7 +11,7 @@ import {
11
11
  readDataStream,
12
12
  parseComplexResponse
13
13
  } from "@ai-sdk/ui-utils";
14
- import { generateId as generateId2, generateId as generateId3 } from "@ai-sdk/provider-utils";
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";
@@ -1974,6 +1974,130 @@ function convertToCoreMessages(messages) {
1974
1974
  return coreMessages;
1975
1975
  }
1976
1976
 
1977
+ // core/registry/invalid-model-id-error.ts
1978
+ var InvalidModelIdError = class extends Error {
1979
+ constructor({
1980
+ id,
1981
+ message = `Invalid model id: ${id}`
1982
+ }) {
1983
+ super(message);
1984
+ this.name = "AI_InvalidModelIdError";
1985
+ this.id = id;
1986
+ }
1987
+ static isInvalidModelIdError(error) {
1988
+ return error instanceof Error && error.name === "AI_InvalidModelIdError" && typeof error.id === "string";
1989
+ }
1990
+ toJSON() {
1991
+ return {
1992
+ name: this.name,
1993
+ message: this.message,
1994
+ stack: this.stack,
1995
+ id: this.id
1996
+ };
1997
+ }
1998
+ };
1999
+
2000
+ // core/registry/no-such-model-error.ts
2001
+ var NoSuchModelError = class extends Error {
2002
+ constructor({
2003
+ modelId,
2004
+ message = `No such model: ${modelId}`
2005
+ }) {
2006
+ super(message);
2007
+ this.name = "AI_NoSuchModelError";
2008
+ this.modelId = modelId;
2009
+ }
2010
+ static isNoSuchModelError(error) {
2011
+ return error instanceof Error && error.name === "AI_NoSuchModelError" && typeof error.modelId === "string";
2012
+ }
2013
+ toJSON() {
2014
+ return {
2015
+ name: this.name,
2016
+ message: this.message,
2017
+ stack: this.stack,
2018
+ modelId: this.modelId
2019
+ };
2020
+ }
2021
+ };
2022
+
2023
+ // core/registry/no-such-provider-error.ts
2024
+ var NoSuchProviderError = class extends Error {
2025
+ constructor({
2026
+ providerId,
2027
+ message = `No such provider: ${providerId}`
2028
+ }) {
2029
+ super(message);
2030
+ this.name = "AI_NoSuchProviderError";
2031
+ this.providerId = providerId;
2032
+ }
2033
+ static isNoSuchProviderError(error) {
2034
+ return error instanceof Error && error.name === "AI_NoSuchProviderError" && typeof error.providerId === "string";
2035
+ }
2036
+ toJSON() {
2037
+ return {
2038
+ name: this.name,
2039
+ message: this.message,
2040
+ stack: this.stack,
2041
+ providerId: this.providerId
2042
+ };
2043
+ }
2044
+ };
2045
+
2046
+ // core/registry/model-registry.ts
2047
+ function experimental_createModelRegistry(providers) {
2048
+ const registry = new DefaultModelRegistry();
2049
+ for (const [id, provider] of Object.entries(providers)) {
2050
+ registry.registerLanguageModelProvider({ id, provider });
2051
+ }
2052
+ return registry;
2053
+ }
2054
+ var DefaultModelRegistry = class {
2055
+ constructor() {
2056
+ // Mapping of provider id to provider
2057
+ this.providers = {};
2058
+ }
2059
+ /**
2060
+ Registers a language model provider with a given id.
2061
+
2062
+ @param {string} id - The id of the provider.
2063
+ @param {(id: string) => LanguageModel} provider - The provider function to register.
2064
+ */
2065
+ registerLanguageModelProvider({
2066
+ id,
2067
+ provider
2068
+ }) {
2069
+ this.providers[id] = provider;
2070
+ }
2071
+ /**
2072
+ Returns the language model with the given id.
2073
+ The id can either be a registered model id or use a provider prefix.
2074
+ Provider ids are separated from the model id by a colon: `providerId:modelId`.
2075
+ The model id is then passed to the provider function to get the model.
2076
+
2077
+ @param {string} id - The id of the model to return.
2078
+
2079
+ @throws {NoSuchModelError} If no model with the given id exists.
2080
+ @throws {NoSuchProviderError} If no provider with the given id exists.
2081
+
2082
+ @returns {LanguageModel} The language model associated with the id.
2083
+ */
2084
+ languageModel(id) {
2085
+ if (!id.includes(":")) {
2086
+ throw new InvalidModelIdError({ id });
2087
+ }
2088
+ const [providerId, modelId] = id.split(":");
2089
+ const provider = this.providers[providerId];
2090
+ if (!provider) {
2091
+ throw new NoSuchProviderError({ providerId });
2092
+ }
2093
+ const model = provider(modelId);
2094
+ if (!model) {
2095
+ throw new NoSuchModelError({ modelId: id });
2096
+ }
2097
+ return model;
2098
+ }
2099
+ };
2100
+
1977
2101
  // core/tool/tool.ts
1978
2102
  function tool(tool2) {
1979
2103
  return tool2;
@@ -3095,6 +3219,10 @@ var StreamingTextResponse = class extends Response {
3095
3219
  });
3096
3220
  }
3097
3221
  };
3222
+
3223
+ // streams/index.ts
3224
+ var generateId2 = generateIdImpl;
3225
+ var nanoid = generateIdImpl;
3098
3226
  export {
3099
3227
  AIStream,
3100
3228
  APICallError2 as APICallError,
@@ -3116,6 +3244,7 @@ export {
3116
3244
  InkeepStream,
3117
3245
  InvalidArgumentError2 as InvalidArgumentError,
3118
3246
  InvalidDataContentError2 as InvalidDataContentError,
3247
+ InvalidModelIdError,
3119
3248
  InvalidPromptError2 as InvalidPromptError,
3120
3249
  InvalidResponseDataError,
3121
3250
  InvalidToolArgumentsError2 as InvalidToolArgumentsError,
@@ -3125,6 +3254,8 @@ export {
3125
3254
  LoadAPIKeyError,
3126
3255
  MistralStream,
3127
3256
  NoObjectGeneratedError2 as NoObjectGeneratedError,
3257
+ NoSuchModelError,
3258
+ NoSuchProviderError,
3128
3259
  NoSuchToolError3 as NoSuchToolError,
3129
3260
  OpenAIStream,
3130
3261
  ReplicateStream,
@@ -3147,6 +3278,7 @@ export {
3147
3278
  embedMany,
3148
3279
  experimental_AssistantResponse,
3149
3280
  experimental_StreamData,
3281
+ experimental_createModelRegistry,
3150
3282
  experimental_generateObject,
3151
3283
  experimental_generateText,
3152
3284
  experimental_streamObject,
@@ -3155,7 +3287,7 @@ export {
3155
3287
  generateId2 as generateId,
3156
3288
  generateObject,
3157
3289
  generateText,
3158
- generateId3 as nanoid,
3290
+ nanoid,
3159
3291
  parseComplexResponse,
3160
3292
  parseStreamPart,
3161
3293
  readDataStream,