ai 5.0.288 → 5.0.290
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 +19 -0
- package/dist/index.d.mts +24 -1
- package/dist/index.d.ts +24 -1
- package/dist/index.js +576 -335
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +483 -237
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +1 -1
- package/dist/internal/index.mjs +1 -1
- package/package.json +3 -2
package/dist/index.mjs
CHANGED
|
@@ -758,7 +758,7 @@ import {
|
|
|
758
758
|
} from "@ai-sdk/provider-utils";
|
|
759
759
|
|
|
760
760
|
// src/version.ts
|
|
761
|
-
var VERSION = true ? "5.0.
|
|
761
|
+
var VERSION = true ? "5.0.290" : "0.0.0-test";
|
|
762
762
|
|
|
763
763
|
// src/util/download/download.ts
|
|
764
764
|
var download = async ({
|
|
@@ -2935,6 +2935,9 @@ function asContent({
|
|
|
2935
2935
|
}
|
|
2936
2936
|
|
|
2937
2937
|
// src/generate-text/stream-text.ts
|
|
2938
|
+
import {
|
|
2939
|
+
getErrorMessage as getErrorMessage7
|
|
2940
|
+
} from "@ai-sdk/provider";
|
|
2938
2941
|
import {
|
|
2939
2942
|
createIdGenerator as createIdGenerator2,
|
|
2940
2943
|
DelayedPromise,
|
|
@@ -6008,9 +6011,21 @@ var DefaultStreamTextResult = class {
|
|
|
6008
6011
|
sendSources = false,
|
|
6009
6012
|
sendStart = true,
|
|
6010
6013
|
sendFinish = true,
|
|
6011
|
-
onError
|
|
6012
|
-
|
|
6014
|
+
onError: onErrorOption,
|
|
6015
|
+
redactToolErrors = onErrorOption != null
|
|
6013
6016
|
} = {}) {
|
|
6017
|
+
const onError = onErrorOption != null ? onErrorOption : () => "An error occurred.";
|
|
6018
|
+
const getToolErrorText = (error) => {
|
|
6019
|
+
var _a17;
|
|
6020
|
+
if (redactToolErrors) {
|
|
6021
|
+
return onError(error);
|
|
6022
|
+
}
|
|
6023
|
+
try {
|
|
6024
|
+
return (_a17 = getErrorMessage7(error)) != null ? _a17 : onError(error);
|
|
6025
|
+
} catch (e) {
|
|
6026
|
+
return onError(error);
|
|
6027
|
+
}
|
|
6028
|
+
};
|
|
6014
6029
|
let outcome = { status: "unknown" };
|
|
6015
6030
|
let hasFatalFailure = false;
|
|
6016
6031
|
const setSourceOutcome = (newOutcome) => {
|
|
@@ -6194,7 +6209,7 @@ var DefaultStreamTextResult = class {
|
|
|
6194
6209
|
...part.providerExecuted != null ? { providerExecuted: part.providerExecuted } : {},
|
|
6195
6210
|
...part.providerMetadata != null ? { providerMetadata: part.providerMetadata } : {},
|
|
6196
6211
|
...dynamic != null ? { dynamic } : {},
|
|
6197
|
-
errorText: onError(part.error)
|
|
6212
|
+
errorText: part.providerExecuted ? onError(part.error) : getToolErrorText(part.error)
|
|
6198
6213
|
});
|
|
6199
6214
|
} else {
|
|
6200
6215
|
controller.enqueue({
|
|
@@ -6226,7 +6241,7 @@ var DefaultStreamTextResult = class {
|
|
|
6226
6241
|
controller.enqueue({
|
|
6227
6242
|
type: "tool-output-error",
|
|
6228
6243
|
toolCallId: part.toolCallId,
|
|
6229
|
-
errorText:
|
|
6244
|
+
errorText: part.providerExecuted ? typeof part.error === "string" ? part.error : JSON.stringify(part.error) : getToolErrorText(part.error),
|
|
6230
6245
|
...part.providerExecuted != null ? { providerExecuted: part.providerExecuted } : {},
|
|
6231
6246
|
...dynamic != null ? { dynamic } : {}
|
|
6232
6247
|
});
|
|
@@ -6360,6 +6375,7 @@ var DefaultStreamTextResult = class {
|
|
|
6360
6375
|
sendFinish,
|
|
6361
6376
|
sendStart,
|
|
6362
6377
|
onError,
|
|
6378
|
+
redactToolErrors,
|
|
6363
6379
|
...init
|
|
6364
6380
|
} = {}) {
|
|
6365
6381
|
return pipeUIMessageStreamToResponse({
|
|
@@ -6373,7 +6389,8 @@ var DefaultStreamTextResult = class {
|
|
|
6373
6389
|
sendSources,
|
|
6374
6390
|
sendFinish,
|
|
6375
6391
|
sendStart,
|
|
6376
|
-
onError
|
|
6392
|
+
onError,
|
|
6393
|
+
redactToolErrors
|
|
6377
6394
|
}),
|
|
6378
6395
|
...init
|
|
6379
6396
|
});
|
|
@@ -6395,6 +6412,7 @@ var DefaultStreamTextResult = class {
|
|
|
6395
6412
|
sendFinish,
|
|
6396
6413
|
sendStart,
|
|
6397
6414
|
onError,
|
|
6415
|
+
redactToolErrors,
|
|
6398
6416
|
...init
|
|
6399
6417
|
} = {}) {
|
|
6400
6418
|
return createUIMessageStreamResponse({
|
|
@@ -6407,7 +6425,8 @@ var DefaultStreamTextResult = class {
|
|
|
6407
6425
|
sendSources,
|
|
6408
6426
|
sendFinish,
|
|
6409
6427
|
sendStart,
|
|
6410
|
-
onError
|
|
6428
|
+
onError,
|
|
6429
|
+
redactToolErrors
|
|
6411
6430
|
}),
|
|
6412
6431
|
...init
|
|
6413
6432
|
});
|
|
@@ -7296,8 +7315,117 @@ import {
|
|
|
7296
7315
|
} from "@ai-sdk/provider";
|
|
7297
7316
|
import {
|
|
7298
7317
|
asSchema as asSchema3,
|
|
7318
|
+
safeValidateTypes as safeValidateTypes4
|
|
7319
|
+
} from "@ai-sdk/provider-utils";
|
|
7320
|
+
|
|
7321
|
+
// src/util/array-output-stream.ts
|
|
7322
|
+
import {
|
|
7323
|
+
safeParseJSON as safeParseJSON3,
|
|
7299
7324
|
safeValidateTypes as safeValidateTypes3
|
|
7300
7325
|
} from "@ai-sdk/provider-utils";
|
|
7326
|
+
function createArrayOutputStreamParser(schema, skipInvalidElements) {
|
|
7327
|
+
let phase = 0 /* Prefix */;
|
|
7328
|
+
let prefix = "";
|
|
7329
|
+
let elementText = "";
|
|
7330
|
+
let depth = 0;
|
|
7331
|
+
let inString = false;
|
|
7332
|
+
let escaped = false;
|
|
7333
|
+
let afterComma = false;
|
|
7334
|
+
let pending = [];
|
|
7335
|
+
const elements = [];
|
|
7336
|
+
let publishedCount;
|
|
7337
|
+
async function finishElement() {
|
|
7338
|
+
const parsed = await safeParseJSON3({ text: elementText });
|
|
7339
|
+
if (!parsed.success) {
|
|
7340
|
+
return false;
|
|
7341
|
+
}
|
|
7342
|
+
const validated = await safeValidateTypes3({ value: parsed.value, schema });
|
|
7343
|
+
if (validated.success) {
|
|
7344
|
+
pending = [validated.value];
|
|
7345
|
+
} else if (!skipInvalidElements) {
|
|
7346
|
+
return false;
|
|
7347
|
+
}
|
|
7348
|
+
elementText = "";
|
|
7349
|
+
return true;
|
|
7350
|
+
}
|
|
7351
|
+
function publishPending() {
|
|
7352
|
+
elements.push(...pending);
|
|
7353
|
+
pending = [];
|
|
7354
|
+
}
|
|
7355
|
+
return async (textDelta) => {
|
|
7356
|
+
for (const char of textDelta) {
|
|
7357
|
+
if (phase === 0 /* Prefix */) {
|
|
7358
|
+
prefix += char;
|
|
7359
|
+
if (char === "[") {
|
|
7360
|
+
if (!/^\s*\{\s*"elements"\s*:\s*\[$/.test(prefix)) {
|
|
7361
|
+
return "fallback";
|
|
7362
|
+
}
|
|
7363
|
+
phase = 1 /* Elements */;
|
|
7364
|
+
} else if (prefix.length > 256) {
|
|
7365
|
+
return "fallback";
|
|
7366
|
+
}
|
|
7367
|
+
continue;
|
|
7368
|
+
}
|
|
7369
|
+
if (phase === 2 /* Suffix */ || phase === 3 /* Done */) {
|
|
7370
|
+
if (/\s/.test(char)) {
|
|
7371
|
+
continue;
|
|
7372
|
+
}
|
|
7373
|
+
if (phase === 2 /* Suffix */ && char === "}") {
|
|
7374
|
+
publishPending();
|
|
7375
|
+
phase = 3 /* Done */;
|
|
7376
|
+
continue;
|
|
7377
|
+
}
|
|
7378
|
+
return "fallback";
|
|
7379
|
+
}
|
|
7380
|
+
if (!inString && depth === 0 && (char === "," || char === "]")) {
|
|
7381
|
+
if (elementText.length > 0) {
|
|
7382
|
+
if (!await finishElement()) {
|
|
7383
|
+
return "fallback";
|
|
7384
|
+
}
|
|
7385
|
+
} else if (char === "," || afterComma) {
|
|
7386
|
+
return "fallback";
|
|
7387
|
+
}
|
|
7388
|
+
afterComma = char === ",";
|
|
7389
|
+
if (char === "]") {
|
|
7390
|
+
phase = 2 /* Suffix */;
|
|
7391
|
+
}
|
|
7392
|
+
continue;
|
|
7393
|
+
}
|
|
7394
|
+
if (elementText.length === 0) {
|
|
7395
|
+
if (/\s/.test(char)) {
|
|
7396
|
+
continue;
|
|
7397
|
+
}
|
|
7398
|
+
publishPending();
|
|
7399
|
+
afterComma = false;
|
|
7400
|
+
}
|
|
7401
|
+
elementText += char;
|
|
7402
|
+
if (inString) {
|
|
7403
|
+
if (escaped) {
|
|
7404
|
+
escaped = false;
|
|
7405
|
+
} else if (char === "\\") {
|
|
7406
|
+
escaped = true;
|
|
7407
|
+
} else if (char === '"') {
|
|
7408
|
+
inString = false;
|
|
7409
|
+
}
|
|
7410
|
+
} else if (char === '"') {
|
|
7411
|
+
inString = true;
|
|
7412
|
+
} else if (char === "{" || char === "[") {
|
|
7413
|
+
depth++;
|
|
7414
|
+
} else if (char === "}" || char === "]") {
|
|
7415
|
+
depth--;
|
|
7416
|
+
}
|
|
7417
|
+
}
|
|
7418
|
+
if (phase === 0 /* Prefix */ || publishedCount === elements.length) {
|
|
7419
|
+
return void 0;
|
|
7420
|
+
}
|
|
7421
|
+
const previousCount = publishedCount != null ? publishedCount : 0;
|
|
7422
|
+
const delta = (publishedCount == null ? "[" : "") + (previousCount > 0 && elements.length > previousCount ? "," : "") + elements.slice(previousCount).map((value) => JSON.stringify(value)).join(",") + (phase === 3 /* Done */ ? "]" : "");
|
|
7423
|
+
publishedCount = elements.length;
|
|
7424
|
+
return { partial: elements.slice(), textDelta: delta };
|
|
7425
|
+
};
|
|
7426
|
+
}
|
|
7427
|
+
|
|
7428
|
+
// src/generate-object/output-strategy.ts
|
|
7301
7429
|
var noSchemaOutputStrategy = {
|
|
7302
7430
|
type: "no-schema",
|
|
7303
7431
|
jsonSchema: void 0,
|
|
@@ -7336,7 +7464,7 @@ var objectOutputStrategy = (schema) => ({
|
|
|
7336
7464
|
};
|
|
7337
7465
|
},
|
|
7338
7466
|
async validateFinalResult(value) {
|
|
7339
|
-
return
|
|
7467
|
+
return safeValidateTypes4({ value, schema });
|
|
7340
7468
|
},
|
|
7341
7469
|
createElementStream() {
|
|
7342
7470
|
throw new UnsupportedFunctionalityError2({
|
|
@@ -7348,6 +7476,7 @@ var arrayOutputStrategy = (schema) => {
|
|
|
7348
7476
|
const { $schema, ...itemSchema } = schema.jsonSchema;
|
|
7349
7477
|
return {
|
|
7350
7478
|
type: "array",
|
|
7479
|
+
createArrayStreamParser: () => createArrayOutputStreamParser(schema, false),
|
|
7351
7480
|
// wrap in object that contains array of elements, since most LLMs will not
|
|
7352
7481
|
// be able to generate an array directly:
|
|
7353
7482
|
// possible future optimization: use arrays directly when model supports grammar-guided generation
|
|
@@ -7380,7 +7509,7 @@ var arrayOutputStrategy = (schema) => {
|
|
|
7380
7509
|
const resultArray = [];
|
|
7381
7510
|
for (let i = 0; i < inputArray.length; i++) {
|
|
7382
7511
|
const element = inputArray[i];
|
|
7383
|
-
const result = await
|
|
7512
|
+
const result = await safeValidateTypes4({ value: element, schema });
|
|
7384
7513
|
if (i === inputArray.length - 1 && !isFinalDelta) {
|
|
7385
7514
|
continue;
|
|
7386
7515
|
}
|
|
@@ -7422,7 +7551,7 @@ var arrayOutputStrategy = (schema) => {
|
|
|
7422
7551
|
const inputArray = value.elements;
|
|
7423
7552
|
const resultArray = [];
|
|
7424
7553
|
for (const element of inputArray) {
|
|
7425
|
-
const result = await
|
|
7554
|
+
const result = await safeValidateTypes4({ value: element, schema });
|
|
7426
7555
|
if (!result.success) {
|
|
7427
7556
|
return result;
|
|
7428
7557
|
}
|
|
@@ -7557,9 +7686,9 @@ function getOutputStrategy({
|
|
|
7557
7686
|
|
|
7558
7687
|
// src/generate-object/parse-and-validate-object-result.ts
|
|
7559
7688
|
import { JSONParseError as JSONParseError2, TypeValidationError as TypeValidationError3 } from "@ai-sdk/provider";
|
|
7560
|
-
import { safeParseJSON as
|
|
7689
|
+
import { safeParseJSON as safeParseJSON4 } from "@ai-sdk/provider-utils";
|
|
7561
7690
|
async function parseAndValidateObjectResult(result, outputStrategy, context) {
|
|
7562
|
-
const parseResult = await
|
|
7691
|
+
const parseResult = await safeParseJSON4({ text: result });
|
|
7563
7692
|
if (!parseResult.success) {
|
|
7564
7693
|
throw new NoObjectGeneratedError({
|
|
7565
7694
|
message: "No object generated: could not parse the response.",
|
|
@@ -8311,6 +8440,7 @@ var DefaultStreamObjectResult = class {
|
|
|
8311
8440
|
endWhenDone: false,
|
|
8312
8441
|
endOnError: true,
|
|
8313
8442
|
fn: async (rootSpan) => {
|
|
8443
|
+
var _a17;
|
|
8314
8444
|
const standardizedPrompt = await standardizePrompt({
|
|
8315
8445
|
system,
|
|
8316
8446
|
prompt,
|
|
@@ -8401,6 +8531,7 @@ var DefaultStreamObjectResult = class {
|
|
|
8401
8531
|
let object2;
|
|
8402
8532
|
let error;
|
|
8403
8533
|
let terminalError;
|
|
8534
|
+
let arrayStreamParser = (_a17 = outputStrategy.createArrayStreamParser) == null ? void 0 : _a17.call(outputStrategy);
|
|
8404
8535
|
let accumulatedText = "";
|
|
8405
8536
|
let textDelta = "";
|
|
8406
8537
|
let fullResponse = {
|
|
@@ -8415,7 +8546,7 @@ var DefaultStreamObjectResult = class {
|
|
|
8415
8546
|
const transformedStream = stream.pipeThrough(new TransformStream(transformer)).pipeThrough(
|
|
8416
8547
|
new TransformStream({
|
|
8417
8548
|
async transform(chunk, controller) {
|
|
8418
|
-
var
|
|
8549
|
+
var _a18, _b, _c;
|
|
8419
8550
|
if (typeof chunk === "object" && chunk.type === "stream-start") {
|
|
8420
8551
|
warnings = chunk.warnings;
|
|
8421
8552
|
return;
|
|
@@ -8433,6 +8564,26 @@ var DefaultStreamObjectResult = class {
|
|
|
8433
8564
|
if (typeof chunk === "string") {
|
|
8434
8565
|
accumulatedText += chunk;
|
|
8435
8566
|
textDelta += chunk;
|
|
8567
|
+
if (arrayStreamParser != null) {
|
|
8568
|
+
const result = await arrayStreamParser(chunk);
|
|
8569
|
+
if (result !== "fallback") {
|
|
8570
|
+
if (result != null) {
|
|
8571
|
+
latestObject = result.partial;
|
|
8572
|
+
controller.enqueue({
|
|
8573
|
+
type: "object",
|
|
8574
|
+
object: latestObject
|
|
8575
|
+
});
|
|
8576
|
+
controller.enqueue({
|
|
8577
|
+
type: "text-delta",
|
|
8578
|
+
textDelta: result.textDelta
|
|
8579
|
+
});
|
|
8580
|
+
textDelta = "";
|
|
8581
|
+
isFirstDelta = false;
|
|
8582
|
+
}
|
|
8583
|
+
return;
|
|
8584
|
+
}
|
|
8585
|
+
arrayStreamParser = void 0;
|
|
8586
|
+
}
|
|
8436
8587
|
const { value: currentObjectJson, state: parseState } = await parsePartialJson(accumulatedText);
|
|
8437
8588
|
if (currentObjectJson !== void 0 && !isDeepEqualData(latestObjectJson, currentObjectJson)) {
|
|
8438
8589
|
const validationResult = await outputStrategy.validatePartialResult({
|
|
@@ -8465,7 +8616,7 @@ var DefaultStreamObjectResult = class {
|
|
|
8465
8616
|
switch (chunk.type) {
|
|
8466
8617
|
case "response-metadata": {
|
|
8467
8618
|
fullResponse = {
|
|
8468
|
-
id: (
|
|
8619
|
+
id: (_a18 = chunk.id) != null ? _a18 : fullResponse.id,
|
|
8469
8620
|
timestamp: (_b = chunk.timestamp) != null ? _b : fullResponse.timestamp,
|
|
8470
8621
|
modelId: (_c = chunk.modelId) != null ? _c : fullResponse.modelId
|
|
8471
8622
|
};
|
|
@@ -8844,8 +8995,8 @@ __export(output_exports, {
|
|
|
8844
8995
|
});
|
|
8845
8996
|
import {
|
|
8846
8997
|
asSchema as asSchema4,
|
|
8847
|
-
safeParseJSON as
|
|
8848
|
-
safeValidateTypes as
|
|
8998
|
+
safeParseJSON as safeParseJSON5,
|
|
8999
|
+
safeValidateTypes as safeValidateTypes5
|
|
8849
9000
|
} from "@ai-sdk/provider-utils";
|
|
8850
9001
|
var text = () => ({
|
|
8851
9002
|
type: "text",
|
|
@@ -8886,7 +9037,7 @@ var object = ({
|
|
|
8886
9037
|
}
|
|
8887
9038
|
},
|
|
8888
9039
|
async parseOutput({ text: text2 }, context) {
|
|
8889
|
-
const parseResult = await
|
|
9040
|
+
const parseResult = await safeParseJSON5({ text: text2 });
|
|
8890
9041
|
if (!parseResult.success) {
|
|
8891
9042
|
throw new NoObjectGeneratedError({
|
|
8892
9043
|
message: "No object generated: could not parse the response.",
|
|
@@ -8897,7 +9048,7 @@ var object = ({
|
|
|
8897
9048
|
finishReason: context.finishReason
|
|
8898
9049
|
});
|
|
8899
9050
|
}
|
|
8900
|
-
const validationResult = await
|
|
9051
|
+
const validationResult = await safeValidateTypes5({
|
|
8901
9052
|
value: parseResult.value,
|
|
8902
9053
|
schema
|
|
8903
9054
|
});
|
|
@@ -10660,11 +10811,62 @@ var TextStreamChatTransport = class extends HttpChatTransport {
|
|
|
10660
10811
|
import { TypeValidationError as TypeValidationError4 } from "@ai-sdk/provider";
|
|
10661
10812
|
import {
|
|
10662
10813
|
lazyValidator as lazyValidator2,
|
|
10663
|
-
safeValidateTypes as
|
|
10814
|
+
safeValidateTypes as safeValidateTypes6,
|
|
10664
10815
|
validateTypes as validateTypes2,
|
|
10665
10816
|
zodSchema as zodSchema2
|
|
10666
10817
|
} from "@ai-sdk/provider-utils";
|
|
10667
10818
|
import { z as z8 } from "zod/v4";
|
|
10819
|
+
function findInvalidJsonValuePath(value, path = [], visited = /* @__PURE__ */ new WeakSet()) {
|
|
10820
|
+
switch (typeof value) {
|
|
10821
|
+
case "number":
|
|
10822
|
+
return Number.isFinite(value) ? void 0 : [...path];
|
|
10823
|
+
case "bigint":
|
|
10824
|
+
case "symbol":
|
|
10825
|
+
case "function":
|
|
10826
|
+
return [...path];
|
|
10827
|
+
case "object": {
|
|
10828
|
+
if (value === null || visited.has(value)) {
|
|
10829
|
+
return void 0;
|
|
10830
|
+
}
|
|
10831
|
+
visited.add(value);
|
|
10832
|
+
const keys = Array.isArray(value) ? value.keys() : Object.keys(value);
|
|
10833
|
+
for (const key of keys) {
|
|
10834
|
+
if (key === "__proto__")
|
|
10835
|
+
continue;
|
|
10836
|
+
path.push(key);
|
|
10837
|
+
const invalidPath = findInvalidJsonValuePath(
|
|
10838
|
+
value[key],
|
|
10839
|
+
path,
|
|
10840
|
+
visited
|
|
10841
|
+
);
|
|
10842
|
+
if (invalidPath != null)
|
|
10843
|
+
return invalidPath;
|
|
10844
|
+
path.pop();
|
|
10845
|
+
}
|
|
10846
|
+
return void 0;
|
|
10847
|
+
}
|
|
10848
|
+
default:
|
|
10849
|
+
return void 0;
|
|
10850
|
+
}
|
|
10851
|
+
}
|
|
10852
|
+
function withJsonValueCheck(schema, jsonValuePath = []) {
|
|
10853
|
+
return z8.unknown().check((context) => {
|
|
10854
|
+
let jsonValue = context.value;
|
|
10855
|
+
for (const key of jsonValuePath) {
|
|
10856
|
+
jsonValue = jsonValue != null && typeof jsonValue === "object" ? jsonValue[key] : void 0;
|
|
10857
|
+
}
|
|
10858
|
+
const invalidPath = findInvalidJsonValuePath(jsonValue);
|
|
10859
|
+
if (invalidPath != null) {
|
|
10860
|
+
context.issues.push({
|
|
10861
|
+
code: "custom",
|
|
10862
|
+
message: "Invalid JSON value. Expected null, a string, a finite number, a boolean, an array, or an object.",
|
|
10863
|
+
input: context.value,
|
|
10864
|
+
path: [...jsonValuePath, ...invalidPath]
|
|
10865
|
+
});
|
|
10866
|
+
}
|
|
10867
|
+
}).pipe(schema);
|
|
10868
|
+
}
|
|
10869
|
+
var providerMetadataSchema2 = withJsonValueCheck(providerMetadataSchema);
|
|
10668
10870
|
function isEmptyObject(value) {
|
|
10669
10871
|
return value != null && typeof value === "object" && !Array.isArray(value) && Object.keys(value).length === 0;
|
|
10670
10872
|
}
|
|
@@ -10692,225 +10894,269 @@ function asDynamicToolPart(toolPart) {
|
|
|
10692
10894
|
errorText: toolPart.errorText
|
|
10693
10895
|
});
|
|
10694
10896
|
}
|
|
10695
|
-
|
|
10696
|
-
() =>
|
|
10697
|
-
|
|
10698
|
-
|
|
10699
|
-
|
|
10700
|
-
|
|
10701
|
-
|
|
10702
|
-
|
|
10703
|
-
|
|
10704
|
-
|
|
10705
|
-
type: z8.literal("text"),
|
|
10706
|
-
text: z8.string(),
|
|
10707
|
-
state: z8.enum(["streaming", "done"]).optional(),
|
|
10708
|
-
providerMetadata: providerMetadataSchema.optional()
|
|
10709
|
-
}),
|
|
10710
|
-
z8.object({
|
|
10711
|
-
type: z8.literal("reasoning"),
|
|
10712
|
-
id: z8.string().optional(),
|
|
10713
|
-
text: z8.string(),
|
|
10714
|
-
state: z8.enum(["streaming", "done"]).optional(),
|
|
10715
|
-
providerMetadata: providerMetadataSchema.optional()
|
|
10716
|
-
}),
|
|
10717
|
-
z8.object({
|
|
10718
|
-
type: z8.literal("source-url"),
|
|
10719
|
-
sourceId: z8.string(),
|
|
10720
|
-
url: z8.string(),
|
|
10721
|
-
title: z8.string().optional(),
|
|
10722
|
-
providerMetadata: providerMetadataSchema.optional()
|
|
10723
|
-
}),
|
|
10724
|
-
z8.object({
|
|
10725
|
-
type: z8.literal("source-document"),
|
|
10726
|
-
sourceId: z8.string(),
|
|
10727
|
-
mediaType: z8.string(),
|
|
10728
|
-
title: z8.string(),
|
|
10729
|
-
filename: z8.string().optional(),
|
|
10730
|
-
providerMetadata: providerMetadataSchema.optional()
|
|
10731
|
-
}),
|
|
10732
|
-
z8.object({
|
|
10733
|
-
type: z8.literal("file"),
|
|
10734
|
-
mediaType: z8.string(),
|
|
10735
|
-
filename: z8.string().optional(),
|
|
10736
|
-
url: z8.string(),
|
|
10737
|
-
providerMetadata: providerMetadataSchema.optional()
|
|
10738
|
-
}),
|
|
10739
|
-
z8.object({
|
|
10740
|
-
type: z8.literal("step-start")
|
|
10741
|
-
}),
|
|
10742
|
-
z8.object({
|
|
10743
|
-
type: z8.string().startsWith("data-"),
|
|
10744
|
-
id: z8.string().optional(),
|
|
10745
|
-
data: z8.unknown()
|
|
10746
|
-
}),
|
|
10747
|
-
z8.object({
|
|
10748
|
-
type: z8.literal("dynamic-tool"),
|
|
10749
|
-
dynamic: z8.literal(false).optional(),
|
|
10750
|
-
toolName: z8.string(),
|
|
10751
|
-
toolCallId: z8.string(),
|
|
10752
|
-
state: z8.literal("input-streaming"),
|
|
10753
|
-
input: z8.unknown().optional(),
|
|
10754
|
-
rawInput: z8.string().optional(),
|
|
10755
|
-
providerExecuted: z8.boolean().optional(),
|
|
10756
|
-
output: z8.never().optional(),
|
|
10757
|
-
errorText: z8.never().optional()
|
|
10758
|
-
}),
|
|
10759
|
-
z8.object({
|
|
10760
|
-
type: z8.literal("dynamic-tool"),
|
|
10761
|
-
dynamic: z8.literal(false).optional(),
|
|
10762
|
-
toolName: z8.string(),
|
|
10763
|
-
toolCallId: z8.string(),
|
|
10764
|
-
state: z8.literal("input-available"),
|
|
10765
|
-
input: z8.unknown(),
|
|
10766
|
-
providerExecuted: z8.boolean().optional(),
|
|
10767
|
-
output: z8.never().optional(),
|
|
10768
|
-
errorText: z8.never().optional(),
|
|
10769
|
-
callProviderMetadata: providerMetadataSchema.optional()
|
|
10770
|
-
}),
|
|
10771
|
-
z8.object({
|
|
10772
|
-
type: z8.literal("dynamic-tool"),
|
|
10773
|
-
dynamic: z8.literal(false).optional(),
|
|
10774
|
-
toolName: z8.string(),
|
|
10775
|
-
toolCallId: z8.string(),
|
|
10776
|
-
state: z8.literal("output-available"),
|
|
10777
|
-
input: z8.unknown(),
|
|
10778
|
-
providerExecuted: z8.boolean().optional(),
|
|
10779
|
-
output: z8.unknown(),
|
|
10780
|
-
errorText: z8.never().optional(),
|
|
10781
|
-
callProviderMetadata: providerMetadataSchema.optional(),
|
|
10782
|
-
preliminary: z8.boolean().optional()
|
|
10783
|
-
}),
|
|
10784
|
-
z8.object({
|
|
10785
|
-
type: z8.literal("dynamic-tool"),
|
|
10786
|
-
dynamic: z8.literal(false).optional(),
|
|
10787
|
-
toolName: z8.string(),
|
|
10788
|
-
toolCallId: z8.string(),
|
|
10789
|
-
state: z8.literal("output-error"),
|
|
10790
|
-
input: z8.unknown().optional(),
|
|
10791
|
-
rawInput: z8.unknown().optional(),
|
|
10792
|
-
providerExecuted: z8.boolean().optional(),
|
|
10793
|
-
output: z8.never().optional(),
|
|
10794
|
-
errorText: z8.string(),
|
|
10795
|
-
callProviderMetadata: providerMetadataSchema.optional()
|
|
10796
|
-
}),
|
|
10797
|
-
z8.object({
|
|
10798
|
-
type: z8.string().startsWith("tool-"),
|
|
10799
|
-
toolCallId: z8.string(),
|
|
10800
|
-
state: z8.literal("input-streaming"),
|
|
10801
|
-
providerExecuted: z8.boolean().optional(),
|
|
10802
|
-
input: z8.unknown().optional(),
|
|
10803
|
-
rawInput: z8.string().optional(),
|
|
10804
|
-
output: z8.never().optional(),
|
|
10805
|
-
errorText: z8.never().optional(),
|
|
10806
|
-
approval: z8.never().optional()
|
|
10807
|
-
}),
|
|
10808
|
-
z8.object({
|
|
10809
|
-
type: z8.string().startsWith("tool-"),
|
|
10810
|
-
toolCallId: z8.string(),
|
|
10811
|
-
state: z8.literal("input-available"),
|
|
10812
|
-
providerExecuted: z8.boolean().optional(),
|
|
10813
|
-
input: z8.unknown(),
|
|
10814
|
-
output: z8.never().optional(),
|
|
10815
|
-
errorText: z8.never().optional(),
|
|
10816
|
-
callProviderMetadata: providerMetadataSchema.optional(),
|
|
10817
|
-
approval: z8.never().optional()
|
|
10818
|
-
}),
|
|
10819
|
-
z8.object({
|
|
10820
|
-
type: z8.string().startsWith("tool-"),
|
|
10821
|
-
toolCallId: z8.string(),
|
|
10822
|
-
state: z8.literal("approval-requested"),
|
|
10823
|
-
input: z8.unknown(),
|
|
10824
|
-
providerExecuted: z8.boolean().optional(),
|
|
10825
|
-
output: z8.never().optional(),
|
|
10826
|
-
errorText: z8.never().optional(),
|
|
10827
|
-
callProviderMetadata: providerMetadataSchema.optional(),
|
|
10828
|
-
approval: z8.object({
|
|
10829
|
-
id: z8.string(),
|
|
10830
|
-
approved: z8.never().optional(),
|
|
10831
|
-
reason: z8.never().optional()
|
|
10832
|
-
})
|
|
10833
|
-
}),
|
|
10834
|
-
z8.object({
|
|
10835
|
-
type: z8.string().startsWith("tool-"),
|
|
10836
|
-
toolCallId: z8.string(),
|
|
10837
|
-
state: z8.literal("approval-responded"),
|
|
10838
|
-
input: z8.unknown(),
|
|
10839
|
-
providerExecuted: z8.boolean().optional(),
|
|
10840
|
-
output: z8.never().optional(),
|
|
10841
|
-
errorText: z8.never().optional(),
|
|
10842
|
-
callProviderMetadata: providerMetadataSchema.optional(),
|
|
10843
|
-
approval: z8.object({
|
|
10844
|
-
id: z8.string(),
|
|
10845
|
-
approved: z8.boolean(),
|
|
10846
|
-
reason: z8.string().optional()
|
|
10847
|
-
})
|
|
10848
|
-
}),
|
|
10849
|
-
z8.object({
|
|
10850
|
-
type: z8.string().startsWith("tool-"),
|
|
10851
|
-
toolCallId: z8.string(),
|
|
10852
|
-
state: z8.literal("output-available"),
|
|
10853
|
-
providerExecuted: z8.boolean().optional(),
|
|
10854
|
-
input: z8.unknown(),
|
|
10855
|
-
output: z8.unknown(),
|
|
10856
|
-
errorText: z8.never().optional(),
|
|
10857
|
-
callProviderMetadata: providerMetadataSchema.optional(),
|
|
10858
|
-
preliminary: z8.boolean().optional(),
|
|
10859
|
-
approval: z8.object({
|
|
10860
|
-
id: z8.string(),
|
|
10861
|
-
approved: z8.literal(true),
|
|
10862
|
-
reason: z8.string().optional()
|
|
10863
|
-
}).optional()
|
|
10864
|
-
}),
|
|
10865
|
-
z8.object({
|
|
10866
|
-
type: z8.string().startsWith("tool-"),
|
|
10867
|
-
toolCallId: z8.string(),
|
|
10868
|
-
state: z8.literal("output-error"),
|
|
10869
|
-
providerExecuted: z8.boolean().optional(),
|
|
10870
|
-
input: z8.unknown().optional(),
|
|
10871
|
-
rawInput: z8.unknown().optional(),
|
|
10872
|
-
output: z8.never().optional(),
|
|
10873
|
-
errorText: z8.string(),
|
|
10874
|
-
callProviderMetadata: providerMetadataSchema.optional(),
|
|
10875
|
-
approval: z8.object({
|
|
10876
|
-
id: z8.string(),
|
|
10877
|
-
approved: z8.literal(true),
|
|
10878
|
-
reason: z8.string().optional()
|
|
10879
|
-
}).optional()
|
|
10880
|
-
}),
|
|
10881
|
-
z8.object({
|
|
10882
|
-
type: z8.string().startsWith("tool-"),
|
|
10883
|
-
toolCallId: z8.string(),
|
|
10884
|
-
state: z8.literal("output-denied"),
|
|
10885
|
-
providerExecuted: z8.boolean().optional(),
|
|
10886
|
-
input: z8.unknown(),
|
|
10887
|
-
output: z8.never().optional(),
|
|
10888
|
-
errorText: z8.never().optional(),
|
|
10889
|
-
callProviderMetadata: providerMetadataSchema.optional(),
|
|
10890
|
-
approval: z8.object({
|
|
10891
|
-
id: z8.string(),
|
|
10892
|
-
approved: z8.literal(false),
|
|
10893
|
-
reason: z8.string().optional()
|
|
10894
|
-
})
|
|
10895
|
-
})
|
|
10896
|
-
])
|
|
10897
|
-
)
|
|
10898
|
-
}).superRefine((message, context) => {
|
|
10899
|
-
if (message.role !== "assistant" && message.parts.length === 0) {
|
|
10900
|
-
context.addIssue({
|
|
10901
|
-
origin: "array",
|
|
10902
|
-
code: "too_small",
|
|
10903
|
-
minimum: 1,
|
|
10904
|
-
inclusive: true,
|
|
10905
|
-
input: message.parts,
|
|
10906
|
-
path: ["parts"],
|
|
10907
|
-
message: "Message must contain at least one part"
|
|
10897
|
+
function arrayUntilFirstInvalidElement(selectElementSchema) {
|
|
10898
|
+
return z8.array(z8.unknown()).transform((elements, context) => {
|
|
10899
|
+
const validatedElements = [];
|
|
10900
|
+
for (const [index, element] of elements.entries()) {
|
|
10901
|
+
const result = selectElementSchema(element).safeParse(element);
|
|
10902
|
+
if (!result.success) {
|
|
10903
|
+
for (const issue of result.error.issues) {
|
|
10904
|
+
context.issues.push({
|
|
10905
|
+
...issue,
|
|
10906
|
+
path: [index, ...issue.path]
|
|
10908
10907
|
});
|
|
10909
10908
|
}
|
|
10909
|
+
return z8.NEVER;
|
|
10910
|
+
}
|
|
10911
|
+
validatedElements.push(result.data);
|
|
10912
|
+
}
|
|
10913
|
+
return validatedElements;
|
|
10914
|
+
});
|
|
10915
|
+
}
|
|
10916
|
+
var uiMessagesSchema = lazyValidator2(() => {
|
|
10917
|
+
const invalidPartTypeMessage = 'Invalid UI message part type. Expected a known part type (for example "text" or "dynamic-tool") or a type starting with "data-" or "tool-".';
|
|
10918
|
+
const staticPartSchema = z8.discriminatedUnion(
|
|
10919
|
+
"type",
|
|
10920
|
+
[
|
|
10921
|
+
z8.object({
|
|
10922
|
+
type: z8.literal("text"),
|
|
10923
|
+
text: z8.string(),
|
|
10924
|
+
state: z8.enum(["streaming", "done"]).optional(),
|
|
10925
|
+
providerMetadata: providerMetadataSchema2.optional()
|
|
10926
|
+
}),
|
|
10927
|
+
z8.object({
|
|
10928
|
+
type: z8.literal("reasoning"),
|
|
10929
|
+
id: z8.string().optional(),
|
|
10930
|
+
text: z8.string(),
|
|
10931
|
+
state: z8.enum(["streaming", "done"]).optional(),
|
|
10932
|
+
providerMetadata: providerMetadataSchema2.optional()
|
|
10933
|
+
}),
|
|
10934
|
+
z8.object({
|
|
10935
|
+
type: z8.literal("source-url"),
|
|
10936
|
+
sourceId: z8.string(),
|
|
10937
|
+
url: z8.string(),
|
|
10938
|
+
title: z8.string().optional(),
|
|
10939
|
+
providerMetadata: providerMetadataSchema2.optional()
|
|
10940
|
+
}),
|
|
10941
|
+
z8.object({
|
|
10942
|
+
type: z8.literal("source-document"),
|
|
10943
|
+
sourceId: z8.string(),
|
|
10944
|
+
mediaType: z8.string(),
|
|
10945
|
+
title: z8.string(),
|
|
10946
|
+
filename: z8.string().optional(),
|
|
10947
|
+
providerMetadata: providerMetadataSchema2.optional()
|
|
10948
|
+
}),
|
|
10949
|
+
z8.object({
|
|
10950
|
+
type: z8.literal("file"),
|
|
10951
|
+
mediaType: z8.string(),
|
|
10952
|
+
filename: z8.string().optional(),
|
|
10953
|
+
url: z8.string(),
|
|
10954
|
+
providerMetadata: providerMetadataSchema2.optional()
|
|
10955
|
+
}),
|
|
10956
|
+
z8.object({
|
|
10957
|
+
type: z8.literal("step-start")
|
|
10910
10958
|
})
|
|
10911
|
-
|
|
10912
|
-
|
|
10913
|
-
)
|
|
10959
|
+
],
|
|
10960
|
+
{
|
|
10961
|
+
error: (issue) => issue.code === "invalid_union" ? invalidPartTypeMessage : void 0
|
|
10962
|
+
}
|
|
10963
|
+
);
|
|
10964
|
+
const dataPartSchema = z8.object({
|
|
10965
|
+
type: z8.string().startsWith("data-"),
|
|
10966
|
+
id: z8.string().optional(),
|
|
10967
|
+
data: z8.unknown()
|
|
10968
|
+
});
|
|
10969
|
+
const dynamicToolPartSchema = z8.discriminatedUnion("state", [
|
|
10970
|
+
z8.object({
|
|
10971
|
+
type: z8.literal("dynamic-tool"),
|
|
10972
|
+
dynamic: z8.literal(false).optional(),
|
|
10973
|
+
toolName: z8.string(),
|
|
10974
|
+
toolCallId: z8.string(),
|
|
10975
|
+
state: z8.literal("input-streaming"),
|
|
10976
|
+
input: z8.unknown().optional(),
|
|
10977
|
+
rawInput: z8.string().optional(),
|
|
10978
|
+
providerExecuted: z8.boolean().optional(),
|
|
10979
|
+
output: z8.never().optional(),
|
|
10980
|
+
errorText: z8.never().optional()
|
|
10981
|
+
}),
|
|
10982
|
+
z8.object({
|
|
10983
|
+
type: z8.literal("dynamic-tool"),
|
|
10984
|
+
dynamic: z8.literal(false).optional(),
|
|
10985
|
+
toolName: z8.string(),
|
|
10986
|
+
toolCallId: z8.string(),
|
|
10987
|
+
state: z8.literal("input-available"),
|
|
10988
|
+
input: z8.unknown(),
|
|
10989
|
+
providerExecuted: z8.boolean().optional(),
|
|
10990
|
+
output: z8.never().optional(),
|
|
10991
|
+
errorText: z8.never().optional(),
|
|
10992
|
+
callProviderMetadata: providerMetadataSchema2.optional()
|
|
10993
|
+
}),
|
|
10994
|
+
z8.object({
|
|
10995
|
+
type: z8.literal("dynamic-tool"),
|
|
10996
|
+
dynamic: z8.literal(false).optional(),
|
|
10997
|
+
toolName: z8.string(),
|
|
10998
|
+
toolCallId: z8.string(),
|
|
10999
|
+
state: z8.literal("output-available"),
|
|
11000
|
+
input: z8.unknown(),
|
|
11001
|
+
providerExecuted: z8.boolean().optional(),
|
|
11002
|
+
output: z8.unknown(),
|
|
11003
|
+
errorText: z8.never().optional(),
|
|
11004
|
+
callProviderMetadata: providerMetadataSchema2.optional(),
|
|
11005
|
+
preliminary: z8.boolean().optional()
|
|
11006
|
+
}),
|
|
11007
|
+
z8.object({
|
|
11008
|
+
type: z8.literal("dynamic-tool"),
|
|
11009
|
+
dynamic: z8.literal(false).optional(),
|
|
11010
|
+
toolName: z8.string(),
|
|
11011
|
+
toolCallId: z8.string(),
|
|
11012
|
+
state: z8.literal("output-error"),
|
|
11013
|
+
input: z8.unknown().optional(),
|
|
11014
|
+
rawInput: z8.unknown().optional(),
|
|
11015
|
+
providerExecuted: z8.boolean().optional(),
|
|
11016
|
+
output: z8.never().optional(),
|
|
11017
|
+
errorText: z8.string(),
|
|
11018
|
+
callProviderMetadata: providerMetadataSchema2.optional()
|
|
11019
|
+
})
|
|
11020
|
+
]);
|
|
11021
|
+
const toolPartSchema = z8.discriminatedUnion("state", [
|
|
11022
|
+
z8.object({
|
|
11023
|
+
type: z8.string().startsWith("tool-"),
|
|
11024
|
+
toolCallId: z8.string(),
|
|
11025
|
+
state: z8.literal("input-streaming"),
|
|
11026
|
+
providerExecuted: z8.boolean().optional(),
|
|
11027
|
+
input: z8.unknown().optional(),
|
|
11028
|
+
rawInput: z8.string().optional(),
|
|
11029
|
+
output: z8.never().optional(),
|
|
11030
|
+
errorText: z8.never().optional(),
|
|
11031
|
+
approval: z8.never().optional()
|
|
11032
|
+
}),
|
|
11033
|
+
z8.object({
|
|
11034
|
+
type: z8.string().startsWith("tool-"),
|
|
11035
|
+
toolCallId: z8.string(),
|
|
11036
|
+
state: z8.literal("input-available"),
|
|
11037
|
+
providerExecuted: z8.boolean().optional(),
|
|
11038
|
+
input: z8.unknown(),
|
|
11039
|
+
output: z8.never().optional(),
|
|
11040
|
+
errorText: z8.never().optional(),
|
|
11041
|
+
callProviderMetadata: providerMetadataSchema2.optional(),
|
|
11042
|
+
approval: z8.never().optional()
|
|
11043
|
+
}),
|
|
11044
|
+
z8.object({
|
|
11045
|
+
type: z8.string().startsWith("tool-"),
|
|
11046
|
+
toolCallId: z8.string(),
|
|
11047
|
+
state: z8.literal("approval-requested"),
|
|
11048
|
+
input: z8.unknown(),
|
|
11049
|
+
providerExecuted: z8.boolean().optional(),
|
|
11050
|
+
output: z8.never().optional(),
|
|
11051
|
+
errorText: z8.never().optional(),
|
|
11052
|
+
callProviderMetadata: providerMetadataSchema2.optional(),
|
|
11053
|
+
approval: z8.object({
|
|
11054
|
+
id: z8.string(),
|
|
11055
|
+
approved: z8.never().optional(),
|
|
11056
|
+
reason: z8.never().optional()
|
|
11057
|
+
})
|
|
11058
|
+
}),
|
|
11059
|
+
z8.object({
|
|
11060
|
+
type: z8.string().startsWith("tool-"),
|
|
11061
|
+
toolCallId: z8.string(),
|
|
11062
|
+
state: z8.literal("approval-responded"),
|
|
11063
|
+
input: z8.unknown(),
|
|
11064
|
+
providerExecuted: z8.boolean().optional(),
|
|
11065
|
+
output: z8.never().optional(),
|
|
11066
|
+
errorText: z8.never().optional(),
|
|
11067
|
+
callProviderMetadata: providerMetadataSchema2.optional(),
|
|
11068
|
+
approval: z8.object({
|
|
11069
|
+
id: z8.string(),
|
|
11070
|
+
approved: z8.boolean(),
|
|
11071
|
+
reason: z8.string().optional()
|
|
11072
|
+
})
|
|
11073
|
+
}),
|
|
11074
|
+
z8.object({
|
|
11075
|
+
type: z8.string().startsWith("tool-"),
|
|
11076
|
+
toolCallId: z8.string(),
|
|
11077
|
+
state: z8.literal("output-available"),
|
|
11078
|
+
providerExecuted: z8.boolean().optional(),
|
|
11079
|
+
input: z8.unknown(),
|
|
11080
|
+
output: z8.unknown(),
|
|
11081
|
+
errorText: z8.never().optional(),
|
|
11082
|
+
callProviderMetadata: providerMetadataSchema2.optional(),
|
|
11083
|
+
preliminary: z8.boolean().optional(),
|
|
11084
|
+
approval: z8.object({
|
|
11085
|
+
id: z8.string(),
|
|
11086
|
+
approved: z8.literal(true),
|
|
11087
|
+
reason: z8.string().optional()
|
|
11088
|
+
}).optional()
|
|
11089
|
+
}),
|
|
11090
|
+
z8.object({
|
|
11091
|
+
type: z8.string().startsWith("tool-"),
|
|
11092
|
+
toolCallId: z8.string(),
|
|
11093
|
+
state: z8.literal("output-error"),
|
|
11094
|
+
providerExecuted: z8.boolean().optional(),
|
|
11095
|
+
input: z8.unknown().optional(),
|
|
11096
|
+
rawInput: z8.unknown().optional(),
|
|
11097
|
+
output: z8.never().optional(),
|
|
11098
|
+
errorText: z8.string(),
|
|
11099
|
+
callProviderMetadata: providerMetadataSchema2.optional(),
|
|
11100
|
+
approval: z8.object({
|
|
11101
|
+
id: z8.string(),
|
|
11102
|
+
approved: z8.literal(true),
|
|
11103
|
+
reason: z8.string().optional()
|
|
11104
|
+
}).optional()
|
|
11105
|
+
}),
|
|
11106
|
+
z8.object({
|
|
11107
|
+
type: z8.string().startsWith("tool-"),
|
|
11108
|
+
toolCallId: z8.string(),
|
|
11109
|
+
state: z8.literal("output-denied"),
|
|
11110
|
+
providerExecuted: z8.boolean().optional(),
|
|
11111
|
+
input: z8.unknown(),
|
|
11112
|
+
output: z8.never().optional(),
|
|
11113
|
+
errorText: z8.never().optional(),
|
|
11114
|
+
callProviderMetadata: providerMetadataSchema2.optional(),
|
|
11115
|
+
approval: z8.object({
|
|
11116
|
+
id: z8.string(),
|
|
11117
|
+
approved: z8.literal(false),
|
|
11118
|
+
reason: z8.string().optional()
|
|
11119
|
+
})
|
|
11120
|
+
})
|
|
11121
|
+
]);
|
|
11122
|
+
const messageSchema = z8.object({
|
|
11123
|
+
id: z8.string(),
|
|
11124
|
+
role: z8.enum(["system", "user", "assistant"]),
|
|
11125
|
+
metadata: z8.unknown().optional(),
|
|
11126
|
+
// Validate each part only against the schemas for its type. A union of
|
|
11127
|
+
// all part schemas would report the issues of every alternative for
|
|
11128
|
+
// each invalid part.
|
|
11129
|
+
parts: arrayUntilFirstInvalidElement((part) => {
|
|
11130
|
+
const type = part == null ? void 0 : part.type;
|
|
11131
|
+
if (typeof type === "string") {
|
|
11132
|
+
if (type.startsWith("data-"))
|
|
11133
|
+
return dataPartSchema;
|
|
11134
|
+
if (type.startsWith("tool-"))
|
|
11135
|
+
return toolPartSchema;
|
|
11136
|
+
if (type === "dynamic-tool")
|
|
11137
|
+
return dynamicToolPartSchema;
|
|
11138
|
+
}
|
|
11139
|
+
return staticPartSchema;
|
|
11140
|
+
})
|
|
11141
|
+
}).superRefine((message, context) => {
|
|
11142
|
+
if (message.role !== "assistant" && message.parts.length === 0) {
|
|
11143
|
+
context.addIssue({
|
|
11144
|
+
origin: "array",
|
|
11145
|
+
code: "too_small",
|
|
11146
|
+
minimum: 1,
|
|
11147
|
+
inclusive: true,
|
|
11148
|
+
input: message.parts,
|
|
11149
|
+
path: ["parts"],
|
|
11150
|
+
message: "Message must contain at least one part"
|
|
11151
|
+
});
|
|
11152
|
+
}
|
|
11153
|
+
});
|
|
11154
|
+
return zodSchema2(
|
|
11155
|
+
arrayUntilFirstInvalidElement(() => messageSchema).check(
|
|
11156
|
+
z8.minLength(1, "Messages array must not be empty")
|
|
11157
|
+
)
|
|
11158
|
+
);
|
|
11159
|
+
});
|
|
10914
11160
|
async function safeValidateUIMessages({
|
|
10915
11161
|
messages,
|
|
10916
11162
|
metadataSchema,
|
|
@@ -11000,7 +11246,7 @@ async function safeValidateUIMessages({
|
|
|
11000
11246
|
let dynamicToolPart;
|
|
11001
11247
|
if (toolPart.state === "output-error") {
|
|
11002
11248
|
if (toolPart.input !== void 0) {
|
|
11003
|
-
const result = await
|
|
11249
|
+
const result = await safeValidateTypes6({
|
|
11004
11250
|
value: toolPart.input,
|
|
11005
11251
|
schema: tool2.inputSchema
|
|
11006
11252
|
});
|
|
@@ -11009,7 +11255,7 @@ async function safeValidateUIMessages({
|
|
|
11009
11255
|
}
|
|
11010
11256
|
}
|
|
11011
11257
|
} else if (toolPart.state === "output-available") {
|
|
11012
|
-
const result = await
|
|
11258
|
+
const result = await safeValidateTypes6({
|
|
11013
11259
|
value: toolPart.input,
|
|
11014
11260
|
schema: tool2.inputSchema
|
|
11015
11261
|
});
|