ai 3.1.35 → 3.1.37
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 +77 -37
- package/dist/index.d.ts +77 -37
- package/dist/index.js +51 -43
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +50 -43
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -7
package/dist/index.mjs
CHANGED
@@ -2067,21 +2067,24 @@ var InvalidModelIdError = class extends Error {
|
|
2067
2067
|
var NoSuchModelError = class extends Error {
|
2068
2068
|
constructor({
|
2069
2069
|
modelId,
|
2070
|
-
|
2070
|
+
modelType,
|
2071
|
+
message = `No such ${modelType}: ${modelId}`
|
2071
2072
|
}) {
|
2072
2073
|
super(message);
|
2073
2074
|
this.name = "AI_NoSuchModelError";
|
2074
2075
|
this.modelId = modelId;
|
2076
|
+
this.modelType = modelType;
|
2075
2077
|
}
|
2076
2078
|
static isNoSuchModelError(error) {
|
2077
|
-
return error instanceof Error && error.name === "AI_NoSuchModelError" && typeof error.modelId === "string";
|
2079
|
+
return error instanceof Error && error.name === "AI_NoSuchModelError" && typeof error.modelId === "string" && typeof error.modelType === "string";
|
2078
2080
|
}
|
2079
2081
|
toJSON() {
|
2080
2082
|
return {
|
2081
2083
|
name: this.name,
|
2082
2084
|
message: this.message,
|
2083
2085
|
stack: this.stack,
|
2084
|
-
modelId: this.modelId
|
2086
|
+
modelId: this.modelId,
|
2087
|
+
modelType: this.modelType
|
2085
2088
|
};
|
2086
2089
|
}
|
2087
2090
|
};
|
@@ -2090,75 +2093,78 @@ var NoSuchModelError = class extends Error {
|
|
2090
2093
|
var NoSuchProviderError = class extends Error {
|
2091
2094
|
constructor({
|
2092
2095
|
providerId,
|
2093
|
-
|
2096
|
+
availableProviders,
|
2097
|
+
message = `No such provider: ${providerId} (available providers: ${availableProviders.join()})`
|
2094
2098
|
}) {
|
2095
2099
|
super(message);
|
2096
2100
|
this.name = "AI_NoSuchProviderError";
|
2097
2101
|
this.providerId = providerId;
|
2102
|
+
this.availableProviders = availableProviders;
|
2098
2103
|
}
|
2099
2104
|
static isNoSuchProviderError(error) {
|
2100
|
-
return error instanceof Error && error.name === "AI_NoSuchProviderError" && typeof error.providerId === "string";
|
2105
|
+
return error instanceof Error && error.name === "AI_NoSuchProviderError" && typeof error.providerId === "string" && Array.isArray(error.availableProviders);
|
2101
2106
|
}
|
2102
2107
|
toJSON() {
|
2103
2108
|
return {
|
2104
2109
|
name: this.name,
|
2105
2110
|
message: this.message,
|
2106
2111
|
stack: this.stack,
|
2107
|
-
providerId: this.providerId
|
2112
|
+
providerId: this.providerId,
|
2113
|
+
availableProviders: this.availableProviders
|
2108
2114
|
};
|
2109
2115
|
}
|
2110
2116
|
};
|
2111
2117
|
|
2112
|
-
// core/registry/
|
2113
|
-
function
|
2114
|
-
const registry = new
|
2118
|
+
// core/registry/provider-registry.ts
|
2119
|
+
function experimental_createProviderRegistry(providers) {
|
2120
|
+
const registry = new DefaultProviderRegistry();
|
2115
2121
|
for (const [id, provider] of Object.entries(providers)) {
|
2116
|
-
registry.
|
2122
|
+
registry.registerProvider({ id, provider });
|
2117
2123
|
}
|
2118
2124
|
return registry;
|
2119
2125
|
}
|
2120
|
-
var
|
2126
|
+
var experimental_createModelRegistry = experimental_createProviderRegistry;
|
2127
|
+
var DefaultProviderRegistry = class {
|
2121
2128
|
constructor() {
|
2122
|
-
// Mapping of provider id to provider
|
2123
2129
|
this.providers = {};
|
2124
2130
|
}
|
2125
|
-
|
2126
|
-
Registers a language model provider with a given id.
|
2127
|
-
|
2128
|
-
@param {string} id - The id of the provider.
|
2129
|
-
@param {(id: string) => LanguageModel} provider - The provider function to register.
|
2130
|
-
*/
|
2131
|
-
registerLanguageModelProvider({
|
2132
|
-
id,
|
2133
|
-
provider
|
2134
|
-
}) {
|
2131
|
+
registerProvider({ id, provider }) {
|
2135
2132
|
this.providers[id] = provider;
|
2136
2133
|
}
|
2137
|
-
|
2138
|
-
|
2139
|
-
|
2140
|
-
|
2141
|
-
|
2142
|
-
|
2143
|
-
|
2144
|
-
|
2145
|
-
|
2146
|
-
|
2147
|
-
|
2148
|
-
@returns {LanguageModel} The language model associated with the id.
|
2149
|
-
*/
|
2150
|
-
languageModel(id) {
|
2134
|
+
getProvider(id) {
|
2135
|
+
const provider = this.providers[id];
|
2136
|
+
if (provider == null) {
|
2137
|
+
throw new NoSuchProviderError({
|
2138
|
+
providerId: id,
|
2139
|
+
availableProviders: Object.keys(this.providers)
|
2140
|
+
});
|
2141
|
+
}
|
2142
|
+
return provider;
|
2143
|
+
}
|
2144
|
+
splitId(id) {
|
2151
2145
|
if (!id.includes(":")) {
|
2152
2146
|
throw new InvalidModelIdError({ id });
|
2153
2147
|
}
|
2154
|
-
|
2155
|
-
|
2156
|
-
|
2157
|
-
|
2148
|
+
return id.split(":");
|
2149
|
+
}
|
2150
|
+
languageModel(id) {
|
2151
|
+
var _a, _b;
|
2152
|
+
const [providerId, modelId] = this.splitId(id);
|
2153
|
+
const model = (_b = (_a = this.getProvider(providerId)).languageModel) == null ? void 0 : _b.call(_a, modelId);
|
2154
|
+
if (model == null) {
|
2155
|
+
throw new NoSuchModelError({ modelId: id, modelType: "language model" });
|
2158
2156
|
}
|
2159
|
-
|
2160
|
-
|
2161
|
-
|
2157
|
+
return model;
|
2158
|
+
}
|
2159
|
+
textEmbeddingModel(id) {
|
2160
|
+
var _a, _b;
|
2161
|
+
const [providerId, modelId] = this.splitId(id);
|
2162
|
+
const model = (_b = (_a = this.getProvider(providerId)).textEmbedding) == null ? void 0 : _b.call(_a, modelId);
|
2163
|
+
if (model == null) {
|
2164
|
+
throw new NoSuchModelError({
|
2165
|
+
modelId: id,
|
2166
|
+
modelType: "text embedding model"
|
2167
|
+
});
|
2162
2168
|
}
|
2163
2169
|
return model;
|
2164
2170
|
}
|
@@ -3366,6 +3372,7 @@ export {
|
|
3366
3372
|
experimental_AssistantResponse,
|
3367
3373
|
experimental_StreamData,
|
3368
3374
|
experimental_createModelRegistry,
|
3375
|
+
experimental_createProviderRegistry,
|
3369
3376
|
experimental_generateObject,
|
3370
3377
|
experimental_generateText,
|
3371
3378
|
experimental_streamObject,
|