ai 5.0.198 → 5.0.200
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 +35 -0
- package/dist/index.d.mts +15 -1
- package/dist/index.d.ts +15 -1
- package/dist/index.js +67 -63
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +31 -29
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +69 -97
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +56 -83
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,40 @@
|
|
|
1
1
|
# ai
|
|
2
2
|
|
|
3
|
+
## 5.0.200
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- eea9166: fix: harden download URL SSRF guard against hostname and redirect bypasses
|
|
8
|
+
|
|
9
|
+
`validateDownloadUrl` and the file download helpers (`downloadBlob`, `download`) could be bypassed in several ways when handling untrusted URLs:
|
|
10
|
+
|
|
11
|
+
- A fully-qualified hostname with a trailing dot (e.g. `localhost.`, `myhost.local.`) skipped the localhost/`.local` blocklist.
|
|
12
|
+
- IPv6 addresses that embed an IPv4 address in their last 32 bits — IPv4-compatible (`::127.0.0.1`), IPv4-translated (`::ffff:0:127.0.0.1`), and NAT64 (`64:ff9b::127.0.0.1`, including the `64:ff9b:1::/48` local-use prefix) — were not decoded and checked against the private IPv4 ranges.
|
|
13
|
+
- Redirects were validated only _after_ `fetch` had already followed them, so the request to a redirect target (e.g. an internal/metadata address) had already been issued before the check ran.
|
|
14
|
+
- Several reserved/internal address ranges were not blocked: CGNAT (`100.64.0.0/10`, used by some cloud providers for internal traffic), benchmarking (`198.18.0.0/15`), IETF protocol assignments (`192.0.0.0/24`), the reserved `240.0.0.0/4` block (including the `255.255.255.255` broadcast address), and IPv6 site-local (`fec0::/10`) and multicast (`ff00::/8`).
|
|
15
|
+
|
|
16
|
+
The validator now strips trailing dots before the hostname checks and fully expands IPv6 addresses to detect embedded private IPv4 targets. The download helpers now follow redirects manually (`redirect: 'manual'`), re-validating each hop before requesting it, so an unsafe redirect target is never fetched. When a redirect cannot be inspected because the runtime returns an opaque response, the helpers fail closed (reject the redirect) on the server; only in a real browser — where SSRF is not reachable (fetch is constrained by CORS and cannot reach a server's internal network or cloud-metadata endpoints) — is the redirect followed natively so legitimate redirected downloads keep working.
|
|
17
|
+
|
|
18
|
+
- 15cf74f: Harden stream text processing and middleware against prototype pollution from stream part IDs.
|
|
19
|
+
- 8ad6f80: fix: redact server error details from UI message streams by default
|
|
20
|
+
|
|
21
|
+
`streamText(...).toUIMessageStream()` and `createUIMessageStream` defaulted their `onError` callback to `getErrorMessage`, which serializes the raw error (`error.toString()` / `JSON.stringify(error)`) into the client-facing `{ type: 'error', errorText }` chunk — and also into `tool-output-error` parts. The documented default was `() => 'An error occurred.'`, so applications relying on the documented behavior were unknowingly streaming server exception details (internal hostnames, paths, provider request data, validation inputs) to end users.
|
|
22
|
+
|
|
23
|
+
The default `onError` now returns the documented generic `'An error occurred.'`. Raw error details are only emitted when the developer explicitly supplies an `onError` handler. This also redacts `tool-output-error` and invalid-tool-input error text by default; pass an `onError` to surface richer messages.
|
|
24
|
+
|
|
25
|
+
- Updated dependencies [9f67efe]
|
|
26
|
+
- Updated dependencies [eea9166]
|
|
27
|
+
- @ai-sdk/provider-utils@3.0.26
|
|
28
|
+
- @ai-sdk/gateway@2.0.99
|
|
29
|
+
|
|
30
|
+
## 5.0.199
|
|
31
|
+
|
|
32
|
+
### Patch Changes
|
|
33
|
+
|
|
34
|
+
- 040dc83: fix(ai): return schema-transformed elements in array output mode
|
|
35
|
+
|
|
36
|
+
Previously final array output validation checked each element against the schema but returned the raw model output. Array output now returns the validated values so Zod transforms, coercions, defaults, and pipes are applied consistently with object output.
|
|
37
|
+
|
|
3
38
|
## 5.0.198
|
|
4
39
|
|
|
5
40
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -3964,7 +3964,21 @@ interface UIMessageStreamWriter<UI_MESSAGE extends UIMessage = UIMessage> {
|
|
|
3964
3964
|
onError: ErrorHandler | undefined;
|
|
3965
3965
|
}
|
|
3966
3966
|
|
|
3967
|
-
|
|
3967
|
+
/**
|
|
3968
|
+
* Creates a UI message stream that can be used to send messages to the client.
|
|
3969
|
+
*
|
|
3970
|
+
* @param options.execute - A function that is called with a writer to write UI message chunks to the stream.
|
|
3971
|
+
* @param options.onError - A function that extracts an error message from an error. Defaults to `() => 'An error occurred.'` so server-side error details are not leaked to the client; supply your own to surface richer messages.
|
|
3972
|
+
* @param options.originalMessages - The original messages. If provided, persistence mode is assumed
|
|
3973
|
+
* and a message ID is provided for the response message.
|
|
3974
|
+
* @param options.onStepFinish - A callback that is called when each step finishes. Useful for persisting intermediate messages.
|
|
3975
|
+
* @param options.onFinish - A callback that is called when the stream finishes.
|
|
3976
|
+
* @param options.generateId - A function that generates a unique ID. Defaults to the built-in ID generator.
|
|
3977
|
+
*
|
|
3978
|
+
* @returns A `ReadableStream` of UI message chunks.
|
|
3979
|
+
*/
|
|
3980
|
+
declare function createUIMessageStream<UI_MESSAGE extends UIMessage>({ execute, onError, // prevent leaking server error details to the client by default
|
|
3981
|
+
originalMessages, onFinish, generateId, }: {
|
|
3968
3982
|
execute: (options: {
|
|
3969
3983
|
writer: UIMessageStreamWriter<UI_MESSAGE>;
|
|
3970
3984
|
}) => Promise<void> | void;
|
package/dist/index.d.ts
CHANGED
|
@@ -3964,7 +3964,21 @@ interface UIMessageStreamWriter<UI_MESSAGE extends UIMessage = UIMessage> {
|
|
|
3964
3964
|
onError: ErrorHandler | undefined;
|
|
3965
3965
|
}
|
|
3966
3966
|
|
|
3967
|
-
|
|
3967
|
+
/**
|
|
3968
|
+
* Creates a UI message stream that can be used to send messages to the client.
|
|
3969
|
+
*
|
|
3970
|
+
* @param options.execute - A function that is called with a writer to write UI message chunks to the stream.
|
|
3971
|
+
* @param options.onError - A function that extracts an error message from an error. Defaults to `() => 'An error occurred.'` so server-side error details are not leaked to the client; supply your own to surface richer messages.
|
|
3972
|
+
* @param options.originalMessages - The original messages. If provided, persistence mode is assumed
|
|
3973
|
+
* and a message ID is provided for the response message.
|
|
3974
|
+
* @param options.onStepFinish - A callback that is called when each step finishes. Useful for persisting intermediate messages.
|
|
3975
|
+
* @param options.onFinish - A callback that is called when the stream finishes.
|
|
3976
|
+
* @param options.generateId - A function that generates a unique ID. Defaults to the built-in ID generator.
|
|
3977
|
+
*
|
|
3978
|
+
* @returns A `ReadableStream` of UI message chunks.
|
|
3979
|
+
*/
|
|
3980
|
+
declare function createUIMessageStream<UI_MESSAGE extends UIMessage>({ execute, onError, // prevent leaking server error details to the client by default
|
|
3981
|
+
originalMessages, onFinish, generateId, }: {
|
|
3968
3982
|
execute: (options: {
|
|
3969
3983
|
writer: UIMessageStreamWriter<UI_MESSAGE>;
|
|
3970
3984
|
}) => Promise<void> | void;
|
package/dist/index.js
CHANGED
|
@@ -778,7 +778,7 @@ function detectMediaType({
|
|
|
778
778
|
var import_provider_utils2 = require("@ai-sdk/provider-utils");
|
|
779
779
|
|
|
780
780
|
// src/version.ts
|
|
781
|
-
var VERSION = true ? "5.0.
|
|
781
|
+
var VERSION = true ? "5.0.200" : "0.0.0-test";
|
|
782
782
|
|
|
783
783
|
// src/util/download/download.ts
|
|
784
784
|
var download = async ({
|
|
@@ -788,21 +788,19 @@ var download = async ({
|
|
|
788
788
|
}) => {
|
|
789
789
|
var _a16;
|
|
790
790
|
const urlText = url.toString();
|
|
791
|
-
(0, import_provider_utils2.validateDownloadUrl)(urlText);
|
|
792
791
|
try {
|
|
793
|
-
const
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
792
|
+
const headers = (0, import_provider_utils2.withUserAgentSuffix)(
|
|
793
|
+
{},
|
|
794
|
+
`ai-sdk/${VERSION}`,
|
|
795
|
+
(0, import_provider_utils2.getRuntimeEnvironmentUserAgent)()
|
|
796
|
+
);
|
|
797
|
+
const response = await (0, import_provider_utils2.fetchWithValidatedRedirects)({
|
|
798
|
+
url: urlText,
|
|
799
|
+
headers,
|
|
800
|
+
abortSignal
|
|
800
801
|
});
|
|
801
|
-
if (response.redirected) {
|
|
802
|
-
(0, import_provider_utils2.validateDownloadUrl)(response.url);
|
|
803
|
-
}
|
|
804
802
|
if (!response.ok) {
|
|
805
|
-
throw new DownloadError({
|
|
803
|
+
throw new import_provider_utils2.DownloadError({
|
|
806
804
|
url: urlText,
|
|
807
805
|
statusCode: response.status,
|
|
808
806
|
statusText: response.statusText
|
|
@@ -818,10 +816,10 @@ var download = async ({
|
|
|
818
816
|
mediaType: (_a16 = response.headers.get("content-type")) != null ? _a16 : void 0
|
|
819
817
|
};
|
|
820
818
|
} catch (error) {
|
|
821
|
-
if (DownloadError.isInstance(error)) {
|
|
819
|
+
if (import_provider_utils2.DownloadError.isInstance(error)) {
|
|
822
820
|
throw error;
|
|
823
821
|
}
|
|
824
|
-
throw new DownloadError({ url: urlText, cause: error });
|
|
822
|
+
throw new import_provider_utils2.DownloadError({ url: urlText, cause: error });
|
|
825
823
|
}
|
|
826
824
|
};
|
|
827
825
|
|
|
@@ -2839,7 +2837,6 @@ function asContent({
|
|
|
2839
2837
|
}
|
|
2840
2838
|
|
|
2841
2839
|
// src/generate-text/stream-text.ts
|
|
2842
|
-
var import_provider23 = require("@ai-sdk/provider");
|
|
2843
2840
|
var import_provider_utils15 = require("@ai-sdk/provider-utils");
|
|
2844
2841
|
|
|
2845
2842
|
// src/util/prepare-headers.ts
|
|
@@ -4730,8 +4727,8 @@ var DefaultStreamTextResult = class {
|
|
|
4730
4727
|
let recordedWarnings = [];
|
|
4731
4728
|
const recordedSteps = [];
|
|
4732
4729
|
let rootSpan;
|
|
4733
|
-
let activeTextContent =
|
|
4734
|
-
let activeReasoningContent =
|
|
4730
|
+
let activeTextContent = createIdMap();
|
|
4731
|
+
let activeReasoningContent = createIdMap();
|
|
4735
4732
|
const eventProcessor = new TransformStream({
|
|
4736
4733
|
async transform(chunk, controller) {
|
|
4737
4734
|
var _a16, _b, _c, _d;
|
|
@@ -4835,6 +4832,9 @@ var DefaultStreamTextResult = class {
|
|
|
4835
4832
|
recordedContent.push(part);
|
|
4836
4833
|
}
|
|
4837
4834
|
if (part.type === "start-step") {
|
|
4835
|
+
recordedContent = [];
|
|
4836
|
+
activeReasoningContent = createIdMap();
|
|
4837
|
+
activeTextContent = createIdMap();
|
|
4838
4838
|
recordedRequest = part.request;
|
|
4839
4839
|
recordedWarnings = part.warnings;
|
|
4840
4840
|
}
|
|
@@ -4859,8 +4859,8 @@ var DefaultStreamTextResult = class {
|
|
|
4859
4859
|
logWarnings(recordedWarnings);
|
|
4860
4860
|
recordedSteps.push(currentStepResult);
|
|
4861
4861
|
recordedContent = [];
|
|
4862
|
-
activeReasoningContent =
|
|
4863
|
-
activeTextContent =
|
|
4862
|
+
activeReasoningContent = createIdMap();
|
|
4863
|
+
activeTextContent = createIdMap();
|
|
4864
4864
|
recordedResponseMessages.push(...stepMessages);
|
|
4865
4865
|
stepFinish.resolve();
|
|
4866
4866
|
}
|
|
@@ -5566,7 +5566,8 @@ var DefaultStreamTextResult = class {
|
|
|
5566
5566
|
sendSources = false,
|
|
5567
5567
|
sendStart = true,
|
|
5568
5568
|
sendFinish = true,
|
|
5569
|
-
onError =
|
|
5569
|
+
onError = () => "An error occurred."
|
|
5570
|
+
// prevent leaking server error details to the client by default
|
|
5570
5571
|
} = {}) {
|
|
5571
5572
|
const responseMessageId = generateMessageId != null ? getResponseUIMessageId({
|
|
5572
5573
|
originalMessages,
|
|
@@ -6612,7 +6613,7 @@ function extractReasoningContent(content) {
|
|
|
6612
6613
|
}
|
|
6613
6614
|
|
|
6614
6615
|
// src/generate-object/output-strategy.ts
|
|
6615
|
-
var
|
|
6616
|
+
var import_provider23 = require("@ai-sdk/provider");
|
|
6616
6617
|
var import_provider_utils19 = require("@ai-sdk/provider-utils");
|
|
6617
6618
|
var noSchemaOutputStrategy = {
|
|
6618
6619
|
type: "no-schema",
|
|
@@ -6633,7 +6634,7 @@ var noSchemaOutputStrategy = {
|
|
|
6633
6634
|
} : { success: true, value };
|
|
6634
6635
|
},
|
|
6635
6636
|
createElementStream() {
|
|
6636
|
-
throw new
|
|
6637
|
+
throw new import_provider23.UnsupportedFunctionalityError({
|
|
6637
6638
|
functionality: "element streams in no-schema mode"
|
|
6638
6639
|
});
|
|
6639
6640
|
}
|
|
@@ -6655,7 +6656,7 @@ var objectOutputStrategy = (schema) => ({
|
|
|
6655
6656
|
return (0, import_provider_utils19.safeValidateTypes)({ value, schema });
|
|
6656
6657
|
},
|
|
6657
6658
|
createElementStream() {
|
|
6658
|
-
throw new
|
|
6659
|
+
throw new import_provider23.UnsupportedFunctionalityError({
|
|
6659
6660
|
functionality: "element streams in object mode"
|
|
6660
6661
|
});
|
|
6661
6662
|
}
|
|
@@ -6683,10 +6684,10 @@ var arrayOutputStrategy = (schema) => {
|
|
|
6683
6684
|
isFinalDelta
|
|
6684
6685
|
}) {
|
|
6685
6686
|
var _a16;
|
|
6686
|
-
if (!(0,
|
|
6687
|
+
if (!(0, import_provider23.isJSONObject)(value) || !(0, import_provider23.isJSONArray)(value.elements)) {
|
|
6687
6688
|
return {
|
|
6688
6689
|
success: false,
|
|
6689
|
-
error: new
|
|
6690
|
+
error: new import_provider23.TypeValidationError({
|
|
6690
6691
|
value,
|
|
6691
6692
|
cause: "value must be an object that contains an array of elements"
|
|
6692
6693
|
})
|
|
@@ -6726,23 +6727,25 @@ var arrayOutputStrategy = (schema) => {
|
|
|
6726
6727
|
};
|
|
6727
6728
|
},
|
|
6728
6729
|
async validateFinalResult(value) {
|
|
6729
|
-
if (!(0,
|
|
6730
|
+
if (!(0, import_provider23.isJSONObject)(value) || !(0, import_provider23.isJSONArray)(value.elements)) {
|
|
6730
6731
|
return {
|
|
6731
6732
|
success: false,
|
|
6732
|
-
error: new
|
|
6733
|
+
error: new import_provider23.TypeValidationError({
|
|
6733
6734
|
value,
|
|
6734
6735
|
cause: "value must be an object that contains an array of elements"
|
|
6735
6736
|
})
|
|
6736
6737
|
};
|
|
6737
6738
|
}
|
|
6738
6739
|
const inputArray = value.elements;
|
|
6740
|
+
const resultArray = [];
|
|
6739
6741
|
for (const element of inputArray) {
|
|
6740
6742
|
const result = await (0, import_provider_utils19.safeValidateTypes)({ value: element, schema });
|
|
6741
6743
|
if (!result.success) {
|
|
6742
6744
|
return result;
|
|
6743
6745
|
}
|
|
6746
|
+
resultArray.push(result.value);
|
|
6744
6747
|
}
|
|
6745
|
-
return { success: true, value:
|
|
6748
|
+
return { success: true, value: resultArray };
|
|
6746
6749
|
},
|
|
6747
6750
|
createElementStream(originalStream) {
|
|
6748
6751
|
let publishedElements = 0;
|
|
@@ -6792,10 +6795,10 @@ var enumOutputStrategy = (enumValues) => {
|
|
|
6792
6795
|
additionalProperties: false
|
|
6793
6796
|
},
|
|
6794
6797
|
async validateFinalResult(value) {
|
|
6795
|
-
if (!(0,
|
|
6798
|
+
if (!(0, import_provider23.isJSONObject)(value) || typeof value.result !== "string") {
|
|
6796
6799
|
return {
|
|
6797
6800
|
success: false,
|
|
6798
|
-
error: new
|
|
6801
|
+
error: new import_provider23.TypeValidationError({
|
|
6799
6802
|
value,
|
|
6800
6803
|
cause: 'value must be an object that contains a string in the "result" property.'
|
|
6801
6804
|
})
|
|
@@ -6804,17 +6807,17 @@ var enumOutputStrategy = (enumValues) => {
|
|
|
6804
6807
|
const result = value.result;
|
|
6805
6808
|
return enumValues.includes(result) ? { success: true, value: result } : {
|
|
6806
6809
|
success: false,
|
|
6807
|
-
error: new
|
|
6810
|
+
error: new import_provider23.TypeValidationError({
|
|
6808
6811
|
value,
|
|
6809
6812
|
cause: "value must be a string in the enum"
|
|
6810
6813
|
})
|
|
6811
6814
|
};
|
|
6812
6815
|
},
|
|
6813
6816
|
async validatePartialResult({ value, textDelta }) {
|
|
6814
|
-
if (!(0,
|
|
6817
|
+
if (!(0, import_provider23.isJSONObject)(value) || typeof value.result !== "string") {
|
|
6815
6818
|
return {
|
|
6816
6819
|
success: false,
|
|
6817
|
-
error: new
|
|
6820
|
+
error: new import_provider23.TypeValidationError({
|
|
6818
6821
|
value,
|
|
6819
6822
|
cause: 'value must be an object that contains a string in the "result" property.'
|
|
6820
6823
|
})
|
|
@@ -6827,7 +6830,7 @@ var enumOutputStrategy = (enumValues) => {
|
|
|
6827
6830
|
if (value.result.length === 0 || possibleEnumValues.length === 0) {
|
|
6828
6831
|
return {
|
|
6829
6832
|
success: false,
|
|
6830
|
-
error: new
|
|
6833
|
+
error: new import_provider23.TypeValidationError({
|
|
6831
6834
|
value,
|
|
6832
6835
|
cause: "value must be a string in the enum"
|
|
6833
6836
|
})
|
|
@@ -6842,7 +6845,7 @@ var enumOutputStrategy = (enumValues) => {
|
|
|
6842
6845
|
};
|
|
6843
6846
|
},
|
|
6844
6847
|
createElementStream() {
|
|
6845
|
-
throw new
|
|
6848
|
+
throw new import_provider23.UnsupportedFunctionalityError({
|
|
6846
6849
|
functionality: "element streams in enum mode"
|
|
6847
6850
|
});
|
|
6848
6851
|
}
|
|
@@ -6870,7 +6873,7 @@ function getOutputStrategy({
|
|
|
6870
6873
|
}
|
|
6871
6874
|
|
|
6872
6875
|
// src/generate-object/parse-and-validate-object-result.ts
|
|
6873
|
-
var
|
|
6876
|
+
var import_provider24 = require("@ai-sdk/provider");
|
|
6874
6877
|
var import_provider_utils20 = require("@ai-sdk/provider-utils");
|
|
6875
6878
|
async function parseAndValidateObjectResult(result, outputStrategy, context) {
|
|
6876
6879
|
const parseResult = await (0, import_provider_utils20.safeParseJSON)({ text: result });
|
|
@@ -6908,7 +6911,7 @@ async function parseAndValidateObjectResultWithRepair(result, outputStrategy, re
|
|
|
6908
6911
|
try {
|
|
6909
6912
|
return await parseAndValidateObjectResult(result, outputStrategy, context);
|
|
6910
6913
|
} catch (error) {
|
|
6911
|
-
if (repairText != null && NoObjectGeneratedError.isInstance(error) && (
|
|
6914
|
+
if (repairText != null && NoObjectGeneratedError.isInstance(error) && (import_provider24.JSONParseError.isInstance(error.cause) || import_provider24.TypeValidationError.isInstance(error.cause))) {
|
|
6912
6915
|
const repairedText = await repairText({
|
|
6913
6916
|
text: result,
|
|
6914
6917
|
error: error.cause
|
|
@@ -8221,7 +8224,7 @@ function pruneMessages({
|
|
|
8221
8224
|
|
|
8222
8225
|
// src/generate-text/smooth-stream.ts
|
|
8223
8226
|
var import_provider_utils26 = require("@ai-sdk/provider-utils");
|
|
8224
|
-
var
|
|
8227
|
+
var import_provider25 = require("@ai-sdk/provider");
|
|
8225
8228
|
var CHUNKING_REGEXPS = {
|
|
8226
8229
|
word: /\S+\s+/m,
|
|
8227
8230
|
line: /\n+/m
|
|
@@ -8251,7 +8254,7 @@ function smoothStream({
|
|
|
8251
8254
|
} else {
|
|
8252
8255
|
const chunkingRegex = typeof chunking === "string" ? CHUNKING_REGEXPS[chunking] : chunking;
|
|
8253
8256
|
if (chunkingRegex == null) {
|
|
8254
|
-
throw new
|
|
8257
|
+
throw new import_provider25.InvalidArgumentError({
|
|
8255
8258
|
argument: "chunking",
|
|
8256
8259
|
message: `Chunking must be "word" or "line" or a RegExp. Received: ${chunking}`
|
|
8257
8260
|
});
|
|
@@ -8372,7 +8375,7 @@ function extractReasoningMiddleware({
|
|
|
8372
8375
|
},
|
|
8373
8376
|
wrapStream: async ({ doStream }) => {
|
|
8374
8377
|
const { stream, ...rest } = await doStream();
|
|
8375
|
-
const reasoningExtractions =
|
|
8378
|
+
const reasoningExtractions = createIdMap();
|
|
8376
8379
|
let delayedTextStart;
|
|
8377
8380
|
return {
|
|
8378
8381
|
stream: stream.pipeThrough(
|
|
@@ -8623,7 +8626,7 @@ function wrapProvider({
|
|
|
8623
8626
|
}
|
|
8624
8627
|
|
|
8625
8628
|
// src/registry/custom-provider.ts
|
|
8626
|
-
var
|
|
8629
|
+
var import_provider26 = require("@ai-sdk/provider");
|
|
8627
8630
|
function customProvider({
|
|
8628
8631
|
languageModels,
|
|
8629
8632
|
textEmbeddingModels,
|
|
@@ -8640,7 +8643,7 @@ function customProvider({
|
|
|
8640
8643
|
if (fallbackProvider) {
|
|
8641
8644
|
return fallbackProvider.languageModel(modelId);
|
|
8642
8645
|
}
|
|
8643
|
-
throw new
|
|
8646
|
+
throw new import_provider26.NoSuchModelError({ modelId, modelType: "languageModel" });
|
|
8644
8647
|
},
|
|
8645
8648
|
textEmbeddingModel(modelId) {
|
|
8646
8649
|
if (textEmbeddingModels != null && modelId in textEmbeddingModels) {
|
|
@@ -8649,7 +8652,7 @@ function customProvider({
|
|
|
8649
8652
|
if (fallbackProvider) {
|
|
8650
8653
|
return fallbackProvider.textEmbeddingModel(modelId);
|
|
8651
8654
|
}
|
|
8652
|
-
throw new
|
|
8655
|
+
throw new import_provider26.NoSuchModelError({ modelId, modelType: "textEmbeddingModel" });
|
|
8653
8656
|
},
|
|
8654
8657
|
imageModel(modelId) {
|
|
8655
8658
|
if (imageModels != null && modelId in imageModels) {
|
|
@@ -8658,7 +8661,7 @@ function customProvider({
|
|
|
8658
8661
|
if (fallbackProvider == null ? void 0 : fallbackProvider.imageModel) {
|
|
8659
8662
|
return fallbackProvider.imageModel(modelId);
|
|
8660
8663
|
}
|
|
8661
|
-
throw new
|
|
8664
|
+
throw new import_provider26.NoSuchModelError({ modelId, modelType: "imageModel" });
|
|
8662
8665
|
},
|
|
8663
8666
|
transcriptionModel(modelId) {
|
|
8664
8667
|
if (transcriptionModels != null && modelId in transcriptionModels) {
|
|
@@ -8667,7 +8670,7 @@ function customProvider({
|
|
|
8667
8670
|
if (fallbackProvider == null ? void 0 : fallbackProvider.transcriptionModel) {
|
|
8668
8671
|
return fallbackProvider.transcriptionModel(modelId);
|
|
8669
8672
|
}
|
|
8670
|
-
throw new
|
|
8673
|
+
throw new import_provider26.NoSuchModelError({ modelId, modelType: "transcriptionModel" });
|
|
8671
8674
|
},
|
|
8672
8675
|
speechModel(modelId) {
|
|
8673
8676
|
if (speechModels != null && modelId in speechModels) {
|
|
@@ -8676,19 +8679,19 @@ function customProvider({
|
|
|
8676
8679
|
if (fallbackProvider == null ? void 0 : fallbackProvider.speechModel) {
|
|
8677
8680
|
return fallbackProvider.speechModel(modelId);
|
|
8678
8681
|
}
|
|
8679
|
-
throw new
|
|
8682
|
+
throw new import_provider26.NoSuchModelError({ modelId, modelType: "speechModel" });
|
|
8680
8683
|
}
|
|
8681
8684
|
};
|
|
8682
8685
|
}
|
|
8683
8686
|
var experimental_customProvider = customProvider;
|
|
8684
8687
|
|
|
8685
8688
|
// src/registry/no-such-provider-error.ts
|
|
8686
|
-
var
|
|
8689
|
+
var import_provider27 = require("@ai-sdk/provider");
|
|
8687
8690
|
var name15 = "AI_NoSuchProviderError";
|
|
8688
8691
|
var marker15 = `vercel.ai.error.${name15}`;
|
|
8689
8692
|
var symbol15 = Symbol.for(marker15);
|
|
8690
8693
|
var _a15;
|
|
8691
|
-
var NoSuchProviderError = class extends
|
|
8694
|
+
var NoSuchProviderError = class extends import_provider27.NoSuchModelError {
|
|
8692
8695
|
constructor({
|
|
8693
8696
|
modelId,
|
|
8694
8697
|
modelType,
|
|
@@ -8702,13 +8705,13 @@ var NoSuchProviderError = class extends import_provider28.NoSuchModelError {
|
|
|
8702
8705
|
this.availableProviders = availableProviders;
|
|
8703
8706
|
}
|
|
8704
8707
|
static isInstance(error) {
|
|
8705
|
-
return
|
|
8708
|
+
return import_provider27.AISDKError.hasMarker(error, marker15);
|
|
8706
8709
|
}
|
|
8707
8710
|
};
|
|
8708
8711
|
_a15 = symbol15;
|
|
8709
8712
|
|
|
8710
8713
|
// src/registry/provider-registry.ts
|
|
8711
|
-
var
|
|
8714
|
+
var import_provider28 = require("@ai-sdk/provider");
|
|
8712
8715
|
function createProviderRegistry(providers, {
|
|
8713
8716
|
separator = ":",
|
|
8714
8717
|
languageModelMiddleware
|
|
@@ -8753,7 +8756,7 @@ var DefaultProviderRegistry = class {
|
|
|
8753
8756
|
splitId(id, modelType) {
|
|
8754
8757
|
const index = id.indexOf(this.separator);
|
|
8755
8758
|
if (index === -1) {
|
|
8756
|
-
throw new
|
|
8759
|
+
throw new import_provider28.NoSuchModelError({
|
|
8757
8760
|
modelId: id,
|
|
8758
8761
|
modelType,
|
|
8759
8762
|
message: `Invalid ${modelType} id for registry: ${id} (must be in the format "providerId${this.separator}modelId")`
|
|
@@ -8769,7 +8772,7 @@ var DefaultProviderRegistry = class {
|
|
|
8769
8772
|
modelId
|
|
8770
8773
|
);
|
|
8771
8774
|
if (model == null) {
|
|
8772
|
-
throw new
|
|
8775
|
+
throw new import_provider28.NoSuchModelError({ modelId: id, modelType: "languageModel" });
|
|
8773
8776
|
}
|
|
8774
8777
|
if (this.languageModelMiddleware != null) {
|
|
8775
8778
|
model = wrapLanguageModel({
|
|
@@ -8785,7 +8788,7 @@ var DefaultProviderRegistry = class {
|
|
|
8785
8788
|
const provider = this.getProvider(providerId, "textEmbeddingModel");
|
|
8786
8789
|
const model = (_a16 = provider.textEmbeddingModel) == null ? void 0 : _a16.call(provider, modelId);
|
|
8787
8790
|
if (model == null) {
|
|
8788
|
-
throw new
|
|
8791
|
+
throw new import_provider28.NoSuchModelError({
|
|
8789
8792
|
modelId: id,
|
|
8790
8793
|
modelType: "textEmbeddingModel"
|
|
8791
8794
|
});
|
|
@@ -8798,7 +8801,7 @@ var DefaultProviderRegistry = class {
|
|
|
8798
8801
|
const provider = this.getProvider(providerId, "imageModel");
|
|
8799
8802
|
const model = (_a16 = provider.imageModel) == null ? void 0 : _a16.call(provider, modelId);
|
|
8800
8803
|
if (model == null) {
|
|
8801
|
-
throw new
|
|
8804
|
+
throw new import_provider28.NoSuchModelError({ modelId: id, modelType: "imageModel" });
|
|
8802
8805
|
}
|
|
8803
8806
|
return model;
|
|
8804
8807
|
}
|
|
@@ -8808,7 +8811,7 @@ var DefaultProviderRegistry = class {
|
|
|
8808
8811
|
const provider = this.getProvider(providerId, "transcriptionModel");
|
|
8809
8812
|
const model = (_a16 = provider.transcriptionModel) == null ? void 0 : _a16.call(provider, modelId);
|
|
8810
8813
|
if (model == null) {
|
|
8811
|
-
throw new
|
|
8814
|
+
throw new import_provider28.NoSuchModelError({
|
|
8812
8815
|
modelId: id,
|
|
8813
8816
|
modelType: "transcriptionModel"
|
|
8814
8817
|
});
|
|
@@ -8821,7 +8824,7 @@ var DefaultProviderRegistry = class {
|
|
|
8821
8824
|
const provider = this.getProvider(providerId, "speechModel");
|
|
8822
8825
|
const model = (_a16 = provider.speechModel) == null ? void 0 : _a16.call(provider, modelId);
|
|
8823
8826
|
if (model == null) {
|
|
8824
|
-
throw new
|
|
8827
|
+
throw new import_provider28.NoSuchModelError({ modelId: id, modelType: "speechModel" });
|
|
8825
8828
|
}
|
|
8826
8829
|
return model;
|
|
8827
8830
|
}
|
|
@@ -8831,8 +8834,8 @@ var DefaultProviderRegistry = class {
|
|
|
8831
8834
|
var import_provider_utils27 = require("@ai-sdk/provider-utils");
|
|
8832
8835
|
|
|
8833
8836
|
// src/error/no-transcript-generated-error.ts
|
|
8834
|
-
var
|
|
8835
|
-
var NoTranscriptGeneratedError = class extends
|
|
8837
|
+
var import_provider29 = require("@ai-sdk/provider");
|
|
8838
|
+
var NoTranscriptGeneratedError = class extends import_provider29.AISDKError {
|
|
8836
8839
|
constructor(options) {
|
|
8837
8840
|
super({
|
|
8838
8841
|
name: "AI_NoTranscriptGeneratedError",
|
|
@@ -9610,7 +9613,7 @@ var TextStreamChatTransport = class extends HttpChatTransport {
|
|
|
9610
9613
|
};
|
|
9611
9614
|
|
|
9612
9615
|
// src/ui/validate-ui-messages.ts
|
|
9613
|
-
var
|
|
9616
|
+
var import_provider30 = require("@ai-sdk/provider");
|
|
9614
9617
|
var import_provider_utils32 = require("@ai-sdk/provider-utils");
|
|
9615
9618
|
var import_v48 = require("zod/v4");
|
|
9616
9619
|
var uiMessagesSchema = (0, import_provider_utils32.lazyValidator)(
|
|
@@ -9851,7 +9854,7 @@ async function safeValidateUIMessages({
|
|
|
9851
9854
|
if (!dataSchema) {
|
|
9852
9855
|
return {
|
|
9853
9856
|
success: false,
|
|
9854
|
-
error: new
|
|
9857
|
+
error: new import_provider30.TypeValidationError({
|
|
9855
9858
|
value: dataPart.data,
|
|
9856
9859
|
cause: `No data schema found for data part ${dataName}`
|
|
9857
9860
|
})
|
|
@@ -9875,7 +9878,7 @@ async function safeValidateUIMessages({
|
|
|
9875
9878
|
if (!tool2) {
|
|
9876
9879
|
return {
|
|
9877
9880
|
success: false,
|
|
9878
|
-
error: new
|
|
9881
|
+
error: new import_provider30.TypeValidationError({
|
|
9879
9882
|
value: toolPart.input,
|
|
9880
9883
|
cause: `No tool schema found for tool part ${toolName}`
|
|
9881
9884
|
})
|
|
@@ -9929,7 +9932,8 @@ async function validateUIMessages({
|
|
|
9929
9932
|
var import_provider_utils33 = require("@ai-sdk/provider-utils");
|
|
9930
9933
|
function createUIMessageStream({
|
|
9931
9934
|
execute,
|
|
9932
|
-
onError =
|
|
9935
|
+
onError = () => "An error occurred.",
|
|
9936
|
+
// prevent leaking server error details to the client by default
|
|
9933
9937
|
originalMessages,
|
|
9934
9938
|
onFinish,
|
|
9935
9939
|
generateId: generateId3 = import_provider_utils33.generateId
|