ai 3.3.16 → 3.3.17
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 +160 -187
- package/dist/index.d.ts +160 -187
- package/dist/index.js +250 -92
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +236 -74
- package/dist/index.mjs.map +1 -1
- package/package.json +6 -6
package/dist/index.mjs
CHANGED
@@ -589,7 +589,6 @@ var DefaultEmbedManyResult = class {
|
|
589
589
|
|
590
590
|
// core/generate-object/generate-object.ts
|
591
591
|
import { safeParseJSON } from "@ai-sdk/provider-utils";
|
592
|
-
import { asSchema } from "@ai-sdk/ui-utils";
|
593
592
|
|
594
593
|
// core/prompt/convert-to-language-model-prompt.ts
|
595
594
|
import { getErrorMessage as getErrorMessage2 } from "@ai-sdk/provider-utils";
|
@@ -1388,6 +1387,173 @@ var NoObjectGeneratedError = class extends AISDKError6 {
|
|
1388
1387
|
};
|
1389
1388
|
_a6 = symbol6;
|
1390
1389
|
|
1390
|
+
// core/generate-object/output-strategy.ts
|
1391
|
+
import {
|
1392
|
+
isJSONArray,
|
1393
|
+
isJSONObject,
|
1394
|
+
TypeValidationError,
|
1395
|
+
UnsupportedFunctionalityError
|
1396
|
+
} from "@ai-sdk/provider";
|
1397
|
+
import { safeValidateTypes as safeValidateTypes2 } from "@ai-sdk/provider-utils";
|
1398
|
+
import { asSchema } from "@ai-sdk/ui-utils";
|
1399
|
+
|
1400
|
+
// core/util/async-iterable-stream.ts
|
1401
|
+
function createAsyncIterableStream(source, transformer) {
|
1402
|
+
const transformedStream = source.pipeThrough(
|
1403
|
+
new TransformStream(transformer)
|
1404
|
+
);
|
1405
|
+
transformedStream[Symbol.asyncIterator] = () => {
|
1406
|
+
const reader = transformedStream.getReader();
|
1407
|
+
return {
|
1408
|
+
async next() {
|
1409
|
+
const { done, value } = await reader.read();
|
1410
|
+
return done ? { done: true, value: void 0 } : { done: false, value };
|
1411
|
+
}
|
1412
|
+
};
|
1413
|
+
};
|
1414
|
+
return transformedStream;
|
1415
|
+
}
|
1416
|
+
|
1417
|
+
// core/generate-object/output-strategy.ts
|
1418
|
+
var noSchemaOutputStrategy = {
|
1419
|
+
type: "no-schema",
|
1420
|
+
jsonSchema: void 0,
|
1421
|
+
validatePartialResult({ value }) {
|
1422
|
+
return { success: true, value };
|
1423
|
+
},
|
1424
|
+
validateFinalResult(value) {
|
1425
|
+
return value === void 0 ? { success: false, error: new NoObjectGeneratedError() } : { success: true, value };
|
1426
|
+
},
|
1427
|
+
createElementStream() {
|
1428
|
+
throw new UnsupportedFunctionalityError({
|
1429
|
+
functionality: "element streams in no-schema mode"
|
1430
|
+
});
|
1431
|
+
}
|
1432
|
+
};
|
1433
|
+
var objectOutputStrategy = (schema) => ({
|
1434
|
+
type: "object",
|
1435
|
+
jsonSchema: schema.jsonSchema,
|
1436
|
+
validatePartialResult({ value }) {
|
1437
|
+
return { success: true, value };
|
1438
|
+
},
|
1439
|
+
validateFinalResult(value) {
|
1440
|
+
return safeValidateTypes2({ value, schema });
|
1441
|
+
},
|
1442
|
+
createElementStream() {
|
1443
|
+
throw new UnsupportedFunctionalityError({
|
1444
|
+
functionality: "element streams in object mode"
|
1445
|
+
});
|
1446
|
+
}
|
1447
|
+
});
|
1448
|
+
var arrayOutputStrategy = (schema) => {
|
1449
|
+
const { $schema, ...itemSchema } = schema.jsonSchema;
|
1450
|
+
return {
|
1451
|
+
type: "object",
|
1452
|
+
// wrap in object that contains array of elements, since most LLMs will not
|
1453
|
+
// be able to generate an array directly:
|
1454
|
+
// possible future optimization: use arrays directly when model supports grammar-guided generation
|
1455
|
+
jsonSchema: {
|
1456
|
+
$schema: "http://json-schema.org/draft-07/schema#",
|
1457
|
+
type: "object",
|
1458
|
+
properties: {
|
1459
|
+
elements: { type: "array", items: itemSchema }
|
1460
|
+
},
|
1461
|
+
required: ["elements"],
|
1462
|
+
additionalProperties: false
|
1463
|
+
},
|
1464
|
+
validatePartialResult({
|
1465
|
+
value,
|
1466
|
+
parseState
|
1467
|
+
}) {
|
1468
|
+
if (!isJSONObject(value) || !isJSONArray(value.elements)) {
|
1469
|
+
return {
|
1470
|
+
success: false,
|
1471
|
+
error: new TypeValidationError({
|
1472
|
+
value,
|
1473
|
+
cause: "value must be an object that contains an array of elements"
|
1474
|
+
})
|
1475
|
+
};
|
1476
|
+
}
|
1477
|
+
const inputArray = value.elements;
|
1478
|
+
const resultArray = [];
|
1479
|
+
for (let i = 0; i < inputArray.length; i++) {
|
1480
|
+
const element = inputArray[i];
|
1481
|
+
const result = safeValidateTypes2({ value: element, schema });
|
1482
|
+
if (i === inputArray.length - 1 && (!result.success || parseState !== "successful-parse")) {
|
1483
|
+
continue;
|
1484
|
+
}
|
1485
|
+
if (!result.success) {
|
1486
|
+
return result;
|
1487
|
+
}
|
1488
|
+
resultArray.push(result.value);
|
1489
|
+
}
|
1490
|
+
return { success: true, value: resultArray };
|
1491
|
+
},
|
1492
|
+
validateFinalResult(value) {
|
1493
|
+
if (!isJSONObject(value) || !isJSONArray(value.elements)) {
|
1494
|
+
return {
|
1495
|
+
success: false,
|
1496
|
+
error: new TypeValidationError({
|
1497
|
+
value,
|
1498
|
+
cause: "value must be an object that contains an array of elements"
|
1499
|
+
})
|
1500
|
+
};
|
1501
|
+
}
|
1502
|
+
const inputArray = value.elements;
|
1503
|
+
for (const element of inputArray) {
|
1504
|
+
const result = safeValidateTypes2({ value: element, schema });
|
1505
|
+
if (!result.success) {
|
1506
|
+
return result;
|
1507
|
+
}
|
1508
|
+
}
|
1509
|
+
return { success: true, value: inputArray };
|
1510
|
+
},
|
1511
|
+
createElementStream(originalStream) {
|
1512
|
+
let publishedElements = 0;
|
1513
|
+
return createAsyncIterableStream(originalStream, {
|
1514
|
+
transform(chunk, controller) {
|
1515
|
+
switch (chunk.type) {
|
1516
|
+
case "object": {
|
1517
|
+
const array = chunk.object;
|
1518
|
+
for (; publishedElements < array.length; publishedElements++) {
|
1519
|
+
controller.enqueue(array[publishedElements]);
|
1520
|
+
}
|
1521
|
+
break;
|
1522
|
+
}
|
1523
|
+
case "text-delta":
|
1524
|
+
case "finish":
|
1525
|
+
break;
|
1526
|
+
case "error":
|
1527
|
+
controller.error(chunk.error);
|
1528
|
+
break;
|
1529
|
+
default: {
|
1530
|
+
const _exhaustiveCheck = chunk;
|
1531
|
+
throw new Error(`Unsupported chunk type: ${_exhaustiveCheck}`);
|
1532
|
+
}
|
1533
|
+
}
|
1534
|
+
}
|
1535
|
+
});
|
1536
|
+
}
|
1537
|
+
};
|
1538
|
+
};
|
1539
|
+
function getOutputStrategy({
|
1540
|
+
output,
|
1541
|
+
schema
|
1542
|
+
}) {
|
1543
|
+
switch (output) {
|
1544
|
+
case "object":
|
1545
|
+
return objectOutputStrategy(asSchema(schema));
|
1546
|
+
case "array":
|
1547
|
+
return arrayOutputStrategy(asSchema(schema));
|
1548
|
+
case "no-schema":
|
1549
|
+
return noSchemaOutputStrategy;
|
1550
|
+
default: {
|
1551
|
+
const _exhaustiveCheck = output;
|
1552
|
+
throw new Error(`Unsupported output: ${_exhaustiveCheck}`);
|
1553
|
+
}
|
1554
|
+
}
|
1555
|
+
}
|
1556
|
+
|
1391
1557
|
// core/generate-object/validate-object-generation-input.ts
|
1392
1558
|
function validateObjectGenerationInput({
|
1393
1559
|
output,
|
@@ -1396,7 +1562,7 @@ function validateObjectGenerationInput({
|
|
1396
1562
|
schemaName,
|
1397
1563
|
schemaDescription
|
1398
1564
|
}) {
|
1399
|
-
if (output != null && output !== "object" && output !== "no-schema") {
|
1565
|
+
if (output != null && output !== "object" && output !== "array" && output !== "no-schema") {
|
1400
1566
|
throw new InvalidArgumentError({
|
1401
1567
|
parameter: "output",
|
1402
1568
|
value: output,
|
@@ -1442,6 +1608,15 @@ function validateObjectGenerationInput({
|
|
1442
1608
|
});
|
1443
1609
|
}
|
1444
1610
|
}
|
1611
|
+
if (output === "array") {
|
1612
|
+
if (schema == null) {
|
1613
|
+
throw new InvalidArgumentError({
|
1614
|
+
parameter: "schema",
|
1615
|
+
value: schema,
|
1616
|
+
message: "Element schema is required for array output."
|
1617
|
+
});
|
1618
|
+
}
|
1619
|
+
}
|
1445
1620
|
}
|
1446
1621
|
|
1447
1622
|
// core/generate-object/generate-object.ts
|
@@ -1469,7 +1644,8 @@ async function generateObject({
|
|
1469
1644
|
schemaName,
|
1470
1645
|
schemaDescription
|
1471
1646
|
});
|
1472
|
-
|
1647
|
+
const outputStrategy = getOutputStrategy({ output, schema: inputSchema });
|
1648
|
+
if (outputStrategy.type === "no-schema" && mode === void 0) {
|
1473
1649
|
mode = "json";
|
1474
1650
|
}
|
1475
1651
|
const baseTelemetryAttributes = getBaseTelemetryAttributes({
|
@@ -1478,7 +1654,6 @@ async function generateObject({
|
|
1478
1654
|
headers,
|
1479
1655
|
settings: { ...settings, maxRetries }
|
1480
1656
|
});
|
1481
|
-
const schema = inputSchema != null ? asSchema(inputSchema) : void 0;
|
1482
1657
|
const tracer = getTracer({ isEnabled: (_a12 = telemetry == null ? void 0 : telemetry.isEnabled) != null ? _a12 : false });
|
1483
1658
|
return recordSpan({
|
1484
1659
|
name: "ai.generateObject",
|
@@ -1494,10 +1669,10 @@ async function generateObject({
|
|
1494
1669
|
"ai.prompt": {
|
1495
1670
|
input: () => JSON.stringify({ system, prompt, messages })
|
1496
1671
|
},
|
1497
|
-
"ai.schema":
|
1672
|
+
"ai.schema": outputStrategy.jsonSchema != null ? { input: () => JSON.stringify(outputStrategy.jsonSchema) } : void 0,
|
1498
1673
|
"ai.schema.name": schemaName,
|
1499
1674
|
"ai.schema.description": schemaDescription,
|
1500
|
-
"ai.settings.output":
|
1675
|
+
"ai.settings.output": outputStrategy.type,
|
1501
1676
|
"ai.settings.mode": mode
|
1502
1677
|
}
|
1503
1678
|
}),
|
@@ -1517,9 +1692,9 @@ async function generateObject({
|
|
1517
1692
|
switch (mode) {
|
1518
1693
|
case "json": {
|
1519
1694
|
const validatedPrompt = validatePrompt({
|
1520
|
-
system:
|
1695
|
+
system: outputStrategy.jsonSchema == null ? injectJsonInstruction({ prompt: system }) : model.supportsStructuredOutputs ? system : injectJsonInstruction({
|
1521
1696
|
prompt: system,
|
1522
|
-
schema:
|
1697
|
+
schema: outputStrategy.jsonSchema
|
1523
1698
|
}),
|
1524
1699
|
prompt,
|
1525
1700
|
messages
|
@@ -1560,7 +1735,7 @@ async function generateObject({
|
|
1560
1735
|
const result2 = await model.doGenerate({
|
1561
1736
|
mode: {
|
1562
1737
|
type: "object-json",
|
1563
|
-
schema:
|
1738
|
+
schema: outputStrategy.jsonSchema,
|
1564
1739
|
name: schemaName,
|
1565
1740
|
description: schemaDescription
|
1566
1741
|
},
|
@@ -1648,7 +1823,7 @@ async function generateObject({
|
|
1648
1823
|
type: "function",
|
1649
1824
|
name: schemaName != null ? schemaName : "json",
|
1650
1825
|
description: schemaDescription != null ? schemaDescription : "Respond with a JSON object.",
|
1651
|
-
parameters:
|
1826
|
+
parameters: outputStrategy.jsonSchema
|
1652
1827
|
}
|
1653
1828
|
},
|
1654
1829
|
...prepareCallSettings(settings),
|
@@ -1699,15 +1874,16 @@ async function generateObject({
|
|
1699
1874
|
throw new Error(`Unsupported mode: ${_exhaustiveCheck}`);
|
1700
1875
|
}
|
1701
1876
|
}
|
1702
|
-
const parseResult = safeParseJSON({
|
1703
|
-
text: result,
|
1704
|
-
// type casting required for `undefined` schema (no-schema mode),
|
1705
|
-
// in which case <T> is <JSONValue> as desired.
|
1706
|
-
schema
|
1707
|
-
});
|
1877
|
+
const parseResult = safeParseJSON({ text: result });
|
1708
1878
|
if (!parseResult.success) {
|
1709
1879
|
throw parseResult.error;
|
1710
1880
|
}
|
1881
|
+
const validationResult = outputStrategy.validateFinalResult(
|
1882
|
+
parseResult.value
|
1883
|
+
);
|
1884
|
+
if (!validationResult.success) {
|
1885
|
+
throw validationResult.error;
|
1886
|
+
}
|
1711
1887
|
span.setAttributes(
|
1712
1888
|
selectTelemetryAttributes({
|
1713
1889
|
telemetry,
|
@@ -1716,13 +1892,13 @@ async function generateObject({
|
|
1716
1892
|
"ai.usage.promptTokens": usage.promptTokens,
|
1717
1893
|
"ai.usage.completionTokens": usage.completionTokens,
|
1718
1894
|
"ai.result.object": {
|
1719
|
-
output: () => JSON.stringify(
|
1895
|
+
output: () => JSON.stringify(validationResult.value)
|
1720
1896
|
}
|
1721
1897
|
}
|
1722
1898
|
})
|
1723
1899
|
);
|
1724
1900
|
return new DefaultGenerateObjectResult({
|
1725
|
-
object:
|
1901
|
+
object: validationResult.value,
|
1726
1902
|
finishReason,
|
1727
1903
|
usage: calculateCompletionTokenUsage(usage),
|
1728
1904
|
warnings,
|
@@ -1756,9 +1932,7 @@ var DefaultGenerateObjectResult = class {
|
|
1756
1932
|
var experimental_generateObject = generateObject;
|
1757
1933
|
|
1758
1934
|
// core/generate-object/stream-object.ts
|
1759
|
-
import { safeValidateTypes as safeValidateTypes2 } from "@ai-sdk/provider-utils";
|
1760
1935
|
import {
|
1761
|
-
asSchema as asSchema2,
|
1762
1936
|
isDeepEqualData,
|
1763
1937
|
parsePartialJson
|
1764
1938
|
} from "@ai-sdk/ui-utils";
|
@@ -1816,23 +1990,6 @@ var DelayedPromise = class {
|
|
1816
1990
|
}
|
1817
1991
|
};
|
1818
1992
|
|
1819
|
-
// core/util/async-iterable-stream.ts
|
1820
|
-
function createAsyncIterableStream(source, transformer) {
|
1821
|
-
const transformedStream = source.pipeThrough(
|
1822
|
-
new TransformStream(transformer)
|
1823
|
-
);
|
1824
|
-
transformedStream[Symbol.asyncIterator] = () => {
|
1825
|
-
const reader = transformedStream.getReader();
|
1826
|
-
return {
|
1827
|
-
async next() {
|
1828
|
-
const { done, value } = await reader.read();
|
1829
|
-
return done ? { done: true, value: void 0 } : { done: false, value };
|
1830
|
-
}
|
1831
|
-
};
|
1832
|
-
};
|
1833
|
-
return transformedStream;
|
1834
|
-
}
|
1835
|
-
|
1836
1993
|
// core/generate-object/stream-object.ts
|
1837
1994
|
async function streamObject({
|
1838
1995
|
model,
|
@@ -1859,7 +2016,8 @@ async function streamObject({
|
|
1859
2016
|
schemaName,
|
1860
2017
|
schemaDescription
|
1861
2018
|
});
|
1862
|
-
|
2019
|
+
const outputStrategy = getOutputStrategy({ output, schema: inputSchema });
|
2020
|
+
if (outputStrategy.type === "no-schema" && mode === void 0) {
|
1863
2021
|
mode = "json";
|
1864
2022
|
}
|
1865
2023
|
const baseTelemetryAttributes = getBaseTelemetryAttributes({
|
@@ -1870,7 +2028,6 @@ async function streamObject({
|
|
1870
2028
|
});
|
1871
2029
|
const tracer = getTracer({ isEnabled: (_a12 = telemetry == null ? void 0 : telemetry.isEnabled) != null ? _a12 : false });
|
1872
2030
|
const retry = retryWithExponentialBackoff({ maxRetries });
|
1873
|
-
const schema = inputSchema != null ? asSchema2(inputSchema) : void 0;
|
1874
2031
|
return recordSpan({
|
1875
2032
|
name: "ai.streamObject",
|
1876
2033
|
attributes: selectTelemetryAttributes({
|
@@ -1885,10 +2042,10 @@ async function streamObject({
|
|
1885
2042
|
"ai.prompt": {
|
1886
2043
|
input: () => JSON.stringify({ system, prompt, messages })
|
1887
2044
|
},
|
1888
|
-
"ai.schema":
|
2045
|
+
"ai.schema": outputStrategy.jsonSchema != null ? { input: () => JSON.stringify(outputStrategy.jsonSchema) } : void 0,
|
1889
2046
|
"ai.schema.name": schemaName,
|
1890
2047
|
"ai.schema.description": schemaDescription,
|
1891
|
-
"ai.settings.output":
|
2048
|
+
"ai.settings.output": outputStrategy.type,
|
1892
2049
|
"ai.settings.mode": mode
|
1893
2050
|
}
|
1894
2051
|
}),
|
@@ -1903,9 +2060,9 @@ async function streamObject({
|
|
1903
2060
|
switch (mode) {
|
1904
2061
|
case "json": {
|
1905
2062
|
const validatedPrompt = validatePrompt({
|
1906
|
-
system:
|
2063
|
+
system: outputStrategy.jsonSchema == null ? injectJsonInstruction({ prompt: system }) : model.supportsStructuredOutputs ? system : injectJsonInstruction({
|
1907
2064
|
prompt: system,
|
1908
|
-
schema:
|
2065
|
+
schema: outputStrategy.jsonSchema
|
1909
2066
|
}),
|
1910
2067
|
prompt,
|
1911
2068
|
messages
|
@@ -1913,7 +2070,7 @@ async function streamObject({
|
|
1913
2070
|
callOptions = {
|
1914
2071
|
mode: {
|
1915
2072
|
type: "object-json",
|
1916
|
-
schema:
|
2073
|
+
schema: outputStrategy.jsonSchema,
|
1917
2074
|
name: schemaName,
|
1918
2075
|
description: schemaDescription
|
1919
2076
|
},
|
@@ -1954,7 +2111,7 @@ async function streamObject({
|
|
1954
2111
|
type: "function",
|
1955
2112
|
name: schemaName != null ? schemaName : "json",
|
1956
2113
|
description: schemaDescription != null ? schemaDescription : "Respond with a JSON object.",
|
1957
|
-
parameters:
|
2114
|
+
parameters: outputStrategy.jsonSchema
|
1958
2115
|
}
|
1959
2116
|
},
|
1960
2117
|
...prepareCallSettings(settings),
|
@@ -2032,12 +2189,10 @@ async function streamObject({
|
|
2032
2189
|
})
|
2033
2190
|
);
|
2034
2191
|
return new DefaultStreamObjectResult({
|
2192
|
+
outputStrategy,
|
2035
2193
|
stream: stream.pipeThrough(new TransformStream(transformer)),
|
2036
2194
|
warnings,
|
2037
2195
|
rawResponse,
|
2038
|
-
// type casting required for `undefined` schema (no-schema mode),
|
2039
|
-
// in which case <T> is <JSONValue> as desired.
|
2040
|
-
schema,
|
2041
2196
|
onFinish,
|
2042
2197
|
rootSpan,
|
2043
2198
|
doStreamSpan,
|
@@ -2052,7 +2207,7 @@ var DefaultStreamObjectResult = class {
|
|
2052
2207
|
stream,
|
2053
2208
|
warnings,
|
2054
2209
|
rawResponse,
|
2055
|
-
|
2210
|
+
outputStrategy,
|
2056
2211
|
onFinish,
|
2057
2212
|
rootSpan,
|
2058
2213
|
doStreamSpan,
|
@@ -2061,6 +2216,7 @@ var DefaultStreamObjectResult = class {
|
|
2061
2216
|
}) {
|
2062
2217
|
this.warnings = warnings;
|
2063
2218
|
this.rawResponse = rawResponse;
|
2219
|
+
this.outputStrategy = outputStrategy;
|
2064
2220
|
this.objectPromise = new DelayedPromise();
|
2065
2221
|
const { resolve: resolveUsage, promise: usagePromise } = createResolvablePromise();
|
2066
2222
|
this.usage = usagePromise;
|
@@ -2076,6 +2232,7 @@ var DefaultStreamObjectResult = class {
|
|
2076
2232
|
let error;
|
2077
2233
|
let accumulatedText = "";
|
2078
2234
|
let delta = "";
|
2235
|
+
let latestObjectJson = void 0;
|
2079
2236
|
let latestObject = void 0;
|
2080
2237
|
let firstChunk = true;
|
2081
2238
|
const self = this;
|
@@ -2095,20 +2252,25 @@ var DefaultStreamObjectResult = class {
|
|
2095
2252
|
if (typeof chunk === "string") {
|
2096
2253
|
accumulatedText += chunk;
|
2097
2254
|
delta += chunk;
|
2098
|
-
const
|
2099
|
-
|
2100
|
-
|
2101
|
-
|
2102
|
-
|
2103
|
-
controller.enqueue({
|
2104
|
-
type: "object",
|
2105
|
-
object: currentObject
|
2106
|
-
});
|
2107
|
-
controller.enqueue({
|
2108
|
-
type: "text-delta",
|
2109
|
-
textDelta: delta
|
2255
|
+
const { value: currentObjectJson, state: parseState } = parsePartialJson(accumulatedText);
|
2256
|
+
if (currentObjectJson !== void 0 && !isDeepEqualData(latestObjectJson, currentObjectJson)) {
|
2257
|
+
const validationResult = outputStrategy.validatePartialResult({
|
2258
|
+
value: currentObjectJson,
|
2259
|
+
parseState
|
2110
2260
|
});
|
2111
|
-
|
2261
|
+
if (validationResult.success && !isDeepEqualData(latestObject, validationResult.value)) {
|
2262
|
+
latestObjectJson = currentObjectJson;
|
2263
|
+
latestObject = validationResult.value;
|
2264
|
+
controller.enqueue({
|
2265
|
+
type: "object",
|
2266
|
+
object: latestObject
|
2267
|
+
});
|
2268
|
+
controller.enqueue({
|
2269
|
+
type: "text-delta",
|
2270
|
+
textDelta: delta
|
2271
|
+
});
|
2272
|
+
delta = "";
|
2273
|
+
}
|
2112
2274
|
}
|
2113
2275
|
return;
|
2114
2276
|
}
|
@@ -2126,10 +2288,7 @@ var DefaultStreamObjectResult = class {
|
|
2126
2288
|
controller.enqueue({ ...chunk, usage });
|
2127
2289
|
resolveUsage(usage);
|
2128
2290
|
resolveProviderMetadata(providerMetadata);
|
2129
|
-
const validationResult =
|
2130
|
-
value: latestObject,
|
2131
|
-
schema
|
2132
|
-
});
|
2291
|
+
const validationResult = outputStrategy.validateFinalResult(latestObjectJson);
|
2133
2292
|
if (validationResult.success) {
|
2134
2293
|
object = validationResult.value;
|
2135
2294
|
self.objectPromise.resolve(object);
|
@@ -2224,6 +2383,9 @@ var DefaultStreamObjectResult = class {
|
|
2224
2383
|
}
|
2225
2384
|
});
|
2226
2385
|
}
|
2386
|
+
get elementStream() {
|
2387
|
+
return this.outputStrategy.createElementStream(this.originalStream);
|
2388
|
+
}
|
2227
2389
|
get textStream() {
|
2228
2390
|
return createAsyncIterableStream(this.originalStream, {
|
2229
2391
|
transform(chunk, controller) {
|
@@ -2288,7 +2450,7 @@ var DefaultStreamObjectResult = class {
|
|
2288
2450
|
var experimental_streamObject = streamObject;
|
2289
2451
|
|
2290
2452
|
// core/prompt/prepare-tools-and-tool-choice.ts
|
2291
|
-
import { asSchema as
|
2453
|
+
import { asSchema as asSchema2 } from "@ai-sdk/ui-utils";
|
2292
2454
|
|
2293
2455
|
// core/util/is-non-empty-object.ts
|
2294
2456
|
function isNonEmptyObject(object) {
|
@@ -2311,7 +2473,7 @@ function prepareToolsAndToolChoice({
|
|
2311
2473
|
type: "function",
|
2312
2474
|
name: name12,
|
2313
2475
|
description: tool2.description,
|
2314
|
-
parameters:
|
2476
|
+
parameters: asSchema2(tool2.parameters).jsonSchema
|
2315
2477
|
})),
|
2316
2478
|
toolChoice: toolChoice == null ? { type: "auto" } : typeof toolChoice === "string" ? { type: toolChoice } : { type: "tool", toolName: toolChoice.toolName }
|
2317
2479
|
};
|
@@ -2319,7 +2481,7 @@ function prepareToolsAndToolChoice({
|
|
2319
2481
|
|
2320
2482
|
// core/generate-text/tool-call.ts
|
2321
2483
|
import { safeParseJSON as safeParseJSON2 } from "@ai-sdk/provider-utils";
|
2322
|
-
import { asSchema as
|
2484
|
+
import { asSchema as asSchema3 } from "@ai-sdk/ui-utils";
|
2323
2485
|
|
2324
2486
|
// errors/invalid-tool-arguments-error.ts
|
2325
2487
|
import { AISDKError as AISDKError7, getErrorMessage as getErrorMessage3 } from "@ai-sdk/provider";
|
@@ -2425,7 +2587,7 @@ function parseToolCall({
|
|
2425
2587
|
}
|
2426
2588
|
const parseResult = safeParseJSON2({
|
2427
2589
|
text: toolCall.args,
|
2428
|
-
schema:
|
2590
|
+
schema: asSchema3(tool2.parameters)
|
2429
2591
|
});
|
2430
2592
|
if (parseResult.success === false) {
|
2431
2593
|
throw new InvalidToolArgumentsError({
|
@@ -3843,8 +4005,8 @@ import {
|
|
3843
4005
|
InvalidResponseDataError,
|
3844
4006
|
JSONParseError,
|
3845
4007
|
LoadAPIKeyError,
|
3846
|
-
TypeValidationError,
|
3847
|
-
UnsupportedFunctionalityError
|
4008
|
+
TypeValidationError as TypeValidationError2,
|
4009
|
+
UnsupportedFunctionalityError as UnsupportedFunctionalityError2
|
3848
4010
|
} from "@ai-sdk/provider";
|
3849
4011
|
|
3850
4012
|
// streams/ai-stream.ts
|
@@ -4937,8 +5099,8 @@ export {
|
|
4937
5099
|
RetryError,
|
4938
5100
|
StreamData2 as StreamData,
|
4939
5101
|
StreamingTextResponse,
|
4940
|
-
TypeValidationError,
|
4941
|
-
UnsupportedFunctionalityError,
|
5102
|
+
TypeValidationError2 as TypeValidationError,
|
5103
|
+
UnsupportedFunctionalityError2 as UnsupportedFunctionalityError,
|
4942
5104
|
convertToCoreMessages,
|
4943
5105
|
cosineSimilarity,
|
4944
5106
|
createCallbacksTransformer,
|