ai 4.1.45 → 4.1.46
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 +11 -0
- package/README.md +2 -2
- package/dist/index.d.mts +135 -10
- package/dist/index.d.ts +135 -10
- package/dist/index.js +341 -162
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +319 -141
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -5
- package/rsc/dist/index.d.ts +45 -1
- package/rsc/dist/rsc-server.d.mts +45 -1
- package/rsc/dist/rsc-server.mjs +65 -17
- package/rsc/dist/rsc-server.mjs.map +1 -1
package/dist/index.mjs
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
var __defProp = Object.defineProperty;
|
2
2
|
var __export = (target, all) => {
|
3
|
-
for (var
|
4
|
-
__defProp(target,
|
3
|
+
for (var name16 in all)
|
4
|
+
__defProp(target, name16, { get: all[name16], enumerable: true });
|
5
5
|
};
|
6
6
|
|
7
7
|
// core/index.ts
|
@@ -354,7 +354,7 @@ function getBaseTelemetryAttributes({
|
|
354
354
|
telemetry,
|
355
355
|
headers
|
356
356
|
}) {
|
357
|
-
var
|
357
|
+
var _a16;
|
358
358
|
return {
|
359
359
|
"ai.model.provider": model.provider,
|
360
360
|
"ai.model.id": model.modelId,
|
@@ -364,7 +364,7 @@ function getBaseTelemetryAttributes({
|
|
364
364
|
return attributes;
|
365
365
|
}, {}),
|
366
366
|
// add metadata as attributes:
|
367
|
-
...Object.entries((
|
367
|
+
...Object.entries((_a16 = telemetry == null ? void 0 : telemetry.metadata) != null ? _a16 : {}).reduce(
|
368
368
|
(attributes, [key, value]) => {
|
369
369
|
attributes[`ai.telemetry.metadata.${key}`] = value;
|
370
370
|
return attributes;
|
@@ -389,7 +389,7 @@ var noopTracer = {
|
|
389
389
|
startSpan() {
|
390
390
|
return noopSpan;
|
391
391
|
},
|
392
|
-
startActiveSpan(
|
392
|
+
startActiveSpan(name16, arg1, arg2, arg3) {
|
393
393
|
if (typeof arg1 === "function") {
|
394
394
|
return arg1(noopSpan);
|
395
395
|
}
|
@@ -459,13 +459,13 @@ function getTracer({
|
|
459
459
|
// core/telemetry/record-span.ts
|
460
460
|
import { SpanStatusCode } from "@opentelemetry/api";
|
461
461
|
function recordSpan({
|
462
|
-
name:
|
462
|
+
name: name16,
|
463
463
|
tracer,
|
464
464
|
attributes,
|
465
465
|
fn,
|
466
466
|
endWhenDone = true
|
467
467
|
}) {
|
468
|
-
return tracer.startActiveSpan(
|
468
|
+
return tracer.startActiveSpan(name16, { attributes }, async (span) => {
|
469
469
|
try {
|
470
470
|
const result = await fn(span);
|
471
471
|
if (endWhenDone) {
|
@@ -573,14 +573,14 @@ async function embed({
|
|
573
573
|
}),
|
574
574
|
tracer,
|
575
575
|
fn: async (doEmbedSpan) => {
|
576
|
-
var
|
576
|
+
var _a16;
|
577
577
|
const modelResponse = await model.doEmbed({
|
578
578
|
values: [value],
|
579
579
|
abortSignal,
|
580
580
|
headers
|
581
581
|
});
|
582
582
|
const embedding2 = modelResponse.embeddings[0];
|
583
|
-
const usage2 = (
|
583
|
+
const usage2 = (_a16 = modelResponse.usage) != null ? _a16 : { tokens: NaN };
|
584
584
|
doEmbedSpan.setAttributes(
|
585
585
|
selectTelemetryAttributes({
|
586
586
|
telemetry,
|
@@ -690,14 +690,14 @@ async function embedMany({
|
|
690
690
|
}),
|
691
691
|
tracer,
|
692
692
|
fn: async (doEmbedSpan) => {
|
693
|
-
var
|
693
|
+
var _a16;
|
694
694
|
const modelResponse = await model.doEmbed({
|
695
695
|
values,
|
696
696
|
abortSignal,
|
697
697
|
headers
|
698
698
|
});
|
699
699
|
const embeddings3 = modelResponse.embeddings;
|
700
|
-
const usage2 = (
|
700
|
+
const usage2 = (_a16 = modelResponse.usage) != null ? _a16 : { tokens: NaN };
|
701
701
|
doEmbedSpan.setAttributes(
|
702
702
|
selectTelemetryAttributes({
|
703
703
|
telemetry,
|
@@ -749,14 +749,14 @@ async function embedMany({
|
|
749
749
|
}),
|
750
750
|
tracer,
|
751
751
|
fn: async (doEmbedSpan) => {
|
752
|
-
var
|
752
|
+
var _a16;
|
753
753
|
const modelResponse = await model.doEmbed({
|
754
754
|
values: chunk,
|
755
755
|
abortSignal,
|
756
756
|
headers
|
757
757
|
});
|
758
758
|
const embeddings2 = modelResponse.embeddings;
|
759
|
-
const usage2 = (
|
759
|
+
const usage2 = (_a16 = modelResponse.usage) != null ? _a16 : { tokens: NaN };
|
760
760
|
doEmbedSpan.setAttributes(
|
761
761
|
selectTelemetryAttributes({
|
762
762
|
telemetry,
|
@@ -846,9 +846,9 @@ async function generateImage({
|
|
846
846
|
currentDate: () => /* @__PURE__ */ new Date()
|
847
847
|
}
|
848
848
|
}) {
|
849
|
-
var
|
849
|
+
var _a16;
|
850
850
|
const { retry } = prepareRetries({ maxRetries: maxRetriesArg });
|
851
|
-
const maxImagesPerCall = (
|
851
|
+
const maxImagesPerCall = (_a16 = model.maxImagesPerCall) != null ? _a16 : 1;
|
852
852
|
const callCount = Math.ceil(n / maxImagesPerCall);
|
853
853
|
const callImageCounts = Array.from({ length: callCount }, (_, i) => {
|
854
854
|
if (i < callCount - 1) {
|
@@ -984,7 +984,7 @@ async function download({
|
|
984
984
|
url,
|
985
985
|
fetchImplementation = fetch
|
986
986
|
}) {
|
987
|
-
var
|
987
|
+
var _a16;
|
988
988
|
const urlText = url.toString();
|
989
989
|
try {
|
990
990
|
const response = await fetchImplementation(urlText);
|
@@ -997,7 +997,7 @@ async function download({
|
|
997
997
|
}
|
998
998
|
return {
|
999
999
|
data: new Uint8Array(await response.arrayBuffer()),
|
1000
|
-
mimeType: (
|
1000
|
+
mimeType: (_a16 = response.headers.get("content-type")) != null ? _a16 : void 0
|
1001
1001
|
};
|
1002
1002
|
} catch (error) {
|
1003
1003
|
if (DownloadError.isInstance(error)) {
|
@@ -1060,8 +1060,8 @@ var dataContentSchema = z.union([
|
|
1060
1060
|
z.custom(
|
1061
1061
|
// Buffer might not be available in some environments such as CloudFlare:
|
1062
1062
|
(value) => {
|
1063
|
-
var
|
1064
|
-
return (_b = (
|
1063
|
+
var _a16, _b;
|
1064
|
+
return (_b = (_a16 = globalThis.Buffer) == null ? void 0 : _a16.isBuffer(value)) != null ? _b : false;
|
1065
1065
|
},
|
1066
1066
|
{ message: "Must be a Buffer" }
|
1067
1067
|
)
|
@@ -1161,14 +1161,14 @@ async function convertToLanguageModelPrompt({
|
|
1161
1161
|
];
|
1162
1162
|
}
|
1163
1163
|
function convertToLanguageModelMessage(message, downloadedAssets) {
|
1164
|
-
var
|
1164
|
+
var _a16, _b, _c, _d, _e, _f;
|
1165
1165
|
const role = message.role;
|
1166
1166
|
switch (role) {
|
1167
1167
|
case "system": {
|
1168
1168
|
return {
|
1169
1169
|
role: "system",
|
1170
1170
|
content: message.content,
|
1171
|
-
providerMetadata: (
|
1171
|
+
providerMetadata: (_a16 = message.providerOptions) != null ? _a16 : message.experimental_providerMetadata
|
1172
1172
|
};
|
1173
1173
|
}
|
1174
1174
|
case "user": {
|
@@ -1212,7 +1212,7 @@ function convertToLanguageModelMessage(message, downloadedAssets) {
|
|
1212
1212
|
return {
|
1213
1213
|
role: "tool",
|
1214
1214
|
content: message.content.map((part) => {
|
1215
|
-
var
|
1215
|
+
var _a17;
|
1216
1216
|
return {
|
1217
1217
|
type: "tool-result",
|
1218
1218
|
toolCallId: part.toolCallId,
|
@@ -1220,7 +1220,7 @@ function convertToLanguageModelMessage(message, downloadedAssets) {
|
|
1220
1220
|
result: part.result,
|
1221
1221
|
content: part.experimental_content,
|
1222
1222
|
isError: part.isError,
|
1223
|
-
providerMetadata: (
|
1223
|
+
providerMetadata: (_a17 = part.providerOptions) != null ? _a17 : part.experimental_providerMetadata
|
1224
1224
|
};
|
1225
1225
|
}),
|
1226
1226
|
providerMetadata: (_f = message.providerOptions) != null ? _f : message.experimental_providerMetadata
|
@@ -1256,7 +1256,7 @@ async function downloadAssets(messages, downloadImplementation, modelSupportsIma
|
|
1256
1256
|
);
|
1257
1257
|
}
|
1258
1258
|
function convertPartToLanguageModelPart(part, downloadedAssets) {
|
1259
|
-
var
|
1259
|
+
var _a16;
|
1260
1260
|
if (part.type === "text") {
|
1261
1261
|
return {
|
1262
1262
|
type: "text",
|
@@ -1309,7 +1309,7 @@ function convertPartToLanguageModelPart(part, downloadedAssets) {
|
|
1309
1309
|
switch (type) {
|
1310
1310
|
case "image": {
|
1311
1311
|
if (normalizedData instanceof Uint8Array) {
|
1312
|
-
mimeType = (
|
1312
|
+
mimeType = (_a16 = detectImageMimeType(normalizedData)) != null ? _a16 : mimeType;
|
1313
1313
|
}
|
1314
1314
|
return {
|
1315
1315
|
type: "image",
|
@@ -1432,7 +1432,7 @@ import { z as z7 } from "zod";
|
|
1432
1432
|
|
1433
1433
|
// core/prompt/attachments-to-parts.ts
|
1434
1434
|
function attachmentsToParts(attachments) {
|
1435
|
-
var
|
1435
|
+
var _a16, _b, _c;
|
1436
1436
|
const parts = [];
|
1437
1437
|
for (const attachment of attachments) {
|
1438
1438
|
let url;
|
@@ -1444,7 +1444,7 @@ function attachmentsToParts(attachments) {
|
|
1444
1444
|
switch (url.protocol) {
|
1445
1445
|
case "http:":
|
1446
1446
|
case "https:": {
|
1447
|
-
if ((
|
1447
|
+
if ((_a16 = attachment.contentType) == null ? void 0 : _a16.startsWith("image/")) {
|
1448
1448
|
parts.push({ type: "image", image: url });
|
1449
1449
|
} else {
|
1450
1450
|
if (!attachment.contentType) {
|
@@ -1530,8 +1530,8 @@ _a8 = symbol8;
|
|
1530
1530
|
|
1531
1531
|
// core/prompt/convert-to-core-messages.ts
|
1532
1532
|
function convertToCoreMessages(messages, options) {
|
1533
|
-
var
|
1534
|
-
const tools = (
|
1533
|
+
var _a16, _b;
|
1534
|
+
const tools = (_a16 = options == null ? void 0 : options.tools) != null ? _a16 : {};
|
1535
1535
|
const coreMessages = [];
|
1536
1536
|
for (let i = 0; i < messages.length; i++) {
|
1537
1537
|
const message = messages[i];
|
@@ -1558,24 +1558,52 @@ function convertToCoreMessages(messages, options) {
|
|
1558
1558
|
case "assistant": {
|
1559
1559
|
if (message.parts != null) {
|
1560
1560
|
let processBlock2 = function() {
|
1561
|
+
const content2 = [];
|
1562
|
+
for (const part of block) {
|
1563
|
+
switch (part.type) {
|
1564
|
+
case "text":
|
1565
|
+
content2.push({
|
1566
|
+
type: "text",
|
1567
|
+
text: part.text
|
1568
|
+
});
|
1569
|
+
break;
|
1570
|
+
case "reasoning": {
|
1571
|
+
for (const detail of part.details) {
|
1572
|
+
switch (detail.type) {
|
1573
|
+
case "text":
|
1574
|
+
content2.push({
|
1575
|
+
type: "reasoning",
|
1576
|
+
text: detail.text,
|
1577
|
+
signature: detail.signature
|
1578
|
+
});
|
1579
|
+
break;
|
1580
|
+
case "redacted":
|
1581
|
+
content2.push({
|
1582
|
+
type: "redacted-reasoning",
|
1583
|
+
data: detail.data
|
1584
|
+
});
|
1585
|
+
break;
|
1586
|
+
}
|
1587
|
+
}
|
1588
|
+
break;
|
1589
|
+
}
|
1590
|
+
case "tool-invocation":
|
1591
|
+
content2.push({
|
1592
|
+
type: "tool-call",
|
1593
|
+
toolCallId: part.toolInvocation.toolCallId,
|
1594
|
+
toolName: part.toolInvocation.toolName,
|
1595
|
+
args: part.toolInvocation.args
|
1596
|
+
});
|
1597
|
+
break;
|
1598
|
+
default: {
|
1599
|
+
const _exhaustiveCheck = part;
|
1600
|
+
throw new Error(`Unsupported part: ${_exhaustiveCheck}`);
|
1601
|
+
}
|
1602
|
+
}
|
1603
|
+
}
|
1561
1604
|
coreMessages.push({
|
1562
1605
|
role: "assistant",
|
1563
|
-
content:
|
1564
|
-
switch (part.type) {
|
1565
|
-
case "text":
|
1566
|
-
return {
|
1567
|
-
type: "text",
|
1568
|
-
text: part.text
|
1569
|
-
};
|
1570
|
-
default:
|
1571
|
-
return {
|
1572
|
-
type: "tool-call",
|
1573
|
-
toolCallId: part.toolInvocation.toolCallId,
|
1574
|
-
toolName: part.toolInvocation.toolName,
|
1575
|
-
args: part.toolInvocation.args
|
1576
|
-
};
|
1577
|
-
}
|
1578
|
-
})
|
1606
|
+
content: content2
|
1579
1607
|
});
|
1580
1608
|
const stepInvocations = block.filter(
|
1581
1609
|
(part) => part.type === "tool-invocation"
|
@@ -1620,6 +1648,7 @@ function convertToCoreMessages(messages, options) {
|
|
1620
1648
|
for (const part of message.parts) {
|
1621
1649
|
switch (part.type) {
|
1622
1650
|
case "reasoning":
|
1651
|
+
block.push(part);
|
1623
1652
|
break;
|
1624
1653
|
case "text": {
|
1625
1654
|
if (blockHasToolInvocations) {
|
@@ -1647,14 +1676,14 @@ function convertToCoreMessages(messages, options) {
|
|
1647
1676
|
break;
|
1648
1677
|
}
|
1649
1678
|
const maxStep = toolInvocations.reduce((max, toolInvocation) => {
|
1650
|
-
var
|
1651
|
-
return Math.max(max, (
|
1679
|
+
var _a17;
|
1680
|
+
return Math.max(max, (_a17 = toolInvocation.step) != null ? _a17 : 0);
|
1652
1681
|
}, 0);
|
1653
1682
|
for (let i2 = 0; i2 <= maxStep; i2++) {
|
1654
1683
|
const stepInvocations = toolInvocations.filter(
|
1655
1684
|
(toolInvocation) => {
|
1656
|
-
var
|
1657
|
-
return ((
|
1685
|
+
var _a17;
|
1686
|
+
return ((_a17 = toolInvocation.step) != null ? _a17 : 0) === i2;
|
1658
1687
|
}
|
1659
1688
|
);
|
1660
1689
|
if (stepInvocations.length === 0) {
|
@@ -1817,6 +1846,18 @@ var filePartSchema = z5.object({
|
|
1817
1846
|
providerOptions: providerMetadataSchema.optional(),
|
1818
1847
|
experimental_providerMetadata: providerMetadataSchema.optional()
|
1819
1848
|
});
|
1849
|
+
var reasoningPartSchema = z5.object({
|
1850
|
+
type: z5.literal("reasoning"),
|
1851
|
+
text: z5.string(),
|
1852
|
+
providerOptions: providerMetadataSchema.optional(),
|
1853
|
+
experimental_providerMetadata: providerMetadataSchema.optional()
|
1854
|
+
});
|
1855
|
+
var redactedReasoningPartSchema = z5.object({
|
1856
|
+
type: z5.literal("redacted-reasoning"),
|
1857
|
+
data: z5.string(),
|
1858
|
+
providerOptions: providerMetadataSchema.optional(),
|
1859
|
+
experimental_providerMetadata: providerMetadataSchema.optional()
|
1860
|
+
});
|
1820
1861
|
var toolCallPartSchema = z5.object({
|
1821
1862
|
type: z5.literal("tool-call"),
|
1822
1863
|
toolCallId: z5.string(),
|
@@ -1856,7 +1897,14 @@ var coreAssistantMessageSchema = z6.object({
|
|
1856
1897
|
role: z6.literal("assistant"),
|
1857
1898
|
content: z6.union([
|
1858
1899
|
z6.string(),
|
1859
|
-
z6.array(
|
1900
|
+
z6.array(
|
1901
|
+
z6.union([
|
1902
|
+
textPartSchema,
|
1903
|
+
reasoningPartSchema,
|
1904
|
+
redactedReasoningPartSchema,
|
1905
|
+
toolCallPartSchema
|
1906
|
+
])
|
1907
|
+
)
|
1860
1908
|
]),
|
1861
1909
|
providerOptions: providerMetadataSchema.optional(),
|
1862
1910
|
experimental_providerMetadata: providerMetadataSchema.optional()
|
@@ -2073,7 +2121,7 @@ var arrayOutputStrategy = (schema) => {
|
|
2073
2121
|
additionalProperties: false
|
2074
2122
|
},
|
2075
2123
|
validatePartialResult({ value, latestObject, isFirstDelta, isFinalDelta }) {
|
2076
|
-
var
|
2124
|
+
var _a16;
|
2077
2125
|
if (!isJSONObject(value) || !isJSONArray(value.elements)) {
|
2078
2126
|
return {
|
2079
2127
|
success: false,
|
@@ -2096,7 +2144,7 @@ var arrayOutputStrategy = (schema) => {
|
|
2096
2144
|
}
|
2097
2145
|
resultArray.push(result.value);
|
2098
2146
|
}
|
2099
|
-
const publishedElementCount = (
|
2147
|
+
const publishedElementCount = (_a16 = latestObject == null ? void 0 : latestObject.length) != null ? _a16 : 0;
|
2100
2148
|
let textDelta = "";
|
2101
2149
|
if (isFirstDelta) {
|
2102
2150
|
textDelta += "[";
|
@@ -2434,7 +2482,7 @@ async function generateObject({
|
|
2434
2482
|
}),
|
2435
2483
|
tracer,
|
2436
2484
|
fn: async (span) => {
|
2437
|
-
var
|
2485
|
+
var _a16, _b, _c, _d;
|
2438
2486
|
if (mode === "auto" || mode == null) {
|
2439
2487
|
mode = model.defaultObjectGenerationMode;
|
2440
2488
|
}
|
@@ -2463,7 +2511,7 @@ async function generateObject({
|
|
2463
2511
|
const promptMessages = await convertToLanguageModelPrompt({
|
2464
2512
|
prompt: standardizedPrompt,
|
2465
2513
|
modelSupportsImageUrls: model.supportsImageUrls,
|
2466
|
-
modelSupportsUrl: (
|
2514
|
+
modelSupportsUrl: (_a16 = model.supportsUrl) == null ? void 0 : _a16.bind(model)
|
2467
2515
|
// support 'this' context
|
2468
2516
|
});
|
2469
2517
|
const generateResult = await retry(
|
@@ -2497,7 +2545,7 @@ async function generateObject({
|
|
2497
2545
|
}),
|
2498
2546
|
tracer,
|
2499
2547
|
fn: async (span2) => {
|
2500
|
-
var
|
2548
|
+
var _a17, _b2, _c2, _d2, _e, _f;
|
2501
2549
|
const result2 = await model.doGenerate({
|
2502
2550
|
mode: {
|
2503
2551
|
type: "object-json",
|
@@ -2513,7 +2561,7 @@ async function generateObject({
|
|
2513
2561
|
headers
|
2514
2562
|
});
|
2515
2563
|
const responseData = {
|
2516
|
-
id: (_b2 = (
|
2564
|
+
id: (_b2 = (_a17 = result2.response) == null ? void 0 : _a17.id) != null ? _b2 : generateId3(),
|
2517
2565
|
timestamp: (_d2 = (_c2 = result2.response) == null ? void 0 : _c2.timestamp) != null ? _d2 : currentDate(),
|
2518
2566
|
modelId: (_f = (_e = result2.response) == null ? void 0 : _e.modelId) != null ? _f : model.modelId
|
2519
2567
|
};
|
@@ -2602,7 +2650,7 @@ async function generateObject({
|
|
2602
2650
|
}),
|
2603
2651
|
tracer,
|
2604
2652
|
fn: async (span2) => {
|
2605
|
-
var
|
2653
|
+
var _a17, _b2, _c2, _d2, _e, _f, _g, _h;
|
2606
2654
|
const result2 = await model.doGenerate({
|
2607
2655
|
mode: {
|
2608
2656
|
type: "object-tool",
|
@@ -2620,7 +2668,7 @@ async function generateObject({
|
|
2620
2668
|
abortSignal,
|
2621
2669
|
headers
|
2622
2670
|
});
|
2623
|
-
const objectText = (_b2 = (
|
2671
|
+
const objectText = (_b2 = (_a17 = result2.toolCalls) == null ? void 0 : _a17[0]) == null ? void 0 : _b2.args;
|
2624
2672
|
const responseData = {
|
2625
2673
|
id: (_d2 = (_c2 = result2.response) == null ? void 0 : _c2.id) != null ? _d2 : generateId3(),
|
2626
2674
|
timestamp: (_f = (_e = result2.response) == null ? void 0 : _e.timestamp) != null ? _f : currentDate(),
|
@@ -2767,9 +2815,9 @@ var DefaultGenerateObjectResult = class {
|
|
2767
2815
|
this.logprobs = options.logprobs;
|
2768
2816
|
}
|
2769
2817
|
toJsonResponse(init) {
|
2770
|
-
var
|
2818
|
+
var _a16;
|
2771
2819
|
return new Response(JSON.stringify(this.object), {
|
2772
|
-
status: (
|
2820
|
+
status: (_a16 = init == null ? void 0 : init.status) != null ? _a16 : 200,
|
2773
2821
|
headers: prepareResponseHeaders(init == null ? void 0 : init.headers, {
|
2774
2822
|
contentType: "application/json; charset=utf-8"
|
2775
2823
|
})
|
@@ -2807,17 +2855,17 @@ var DelayedPromise = class {
|
|
2807
2855
|
return this.promise;
|
2808
2856
|
}
|
2809
2857
|
resolve(value) {
|
2810
|
-
var
|
2858
|
+
var _a16;
|
2811
2859
|
this.status = { type: "resolved", value };
|
2812
2860
|
if (this.promise) {
|
2813
|
-
(
|
2861
|
+
(_a16 = this._resolve) == null ? void 0 : _a16.call(this, value);
|
2814
2862
|
}
|
2815
2863
|
}
|
2816
2864
|
reject(error) {
|
2817
|
-
var
|
2865
|
+
var _a16;
|
2818
2866
|
this.status = { type: "rejected", error };
|
2819
2867
|
if (this.promise) {
|
2820
|
-
(
|
2868
|
+
(_a16 = this._reject) == null ? void 0 : _a16.call(this, error);
|
2821
2869
|
}
|
2822
2870
|
}
|
2823
2871
|
};
|
@@ -2921,8 +2969,8 @@ function createStitchableStream() {
|
|
2921
2969
|
|
2922
2970
|
// core/util/now.ts
|
2923
2971
|
function now() {
|
2924
|
-
var
|
2925
|
-
return (_b = (
|
2972
|
+
var _a16, _b;
|
2973
|
+
return (_b = (_a16 = globalThis == null ? void 0 : globalThis.performance) == null ? void 0 : _a16.now()) != null ? _b : Date.now();
|
2926
2974
|
}
|
2927
2975
|
|
2928
2976
|
// core/generate-object/stream-object.ts
|
@@ -3058,7 +3106,7 @@ var DefaultStreamObjectResult = class {
|
|
3058
3106
|
tracer,
|
3059
3107
|
endWhenDone: false,
|
3060
3108
|
fn: async (rootSpan) => {
|
3061
|
-
var
|
3109
|
+
var _a16, _b;
|
3062
3110
|
if (mode === "auto" || mode == null) {
|
3063
3111
|
mode = model.defaultObjectGenerationMode;
|
3064
3112
|
}
|
@@ -3089,7 +3137,7 @@ var DefaultStreamObjectResult = class {
|
|
3089
3137
|
prompt: await convertToLanguageModelPrompt({
|
3090
3138
|
prompt: standardizedPrompt,
|
3091
3139
|
modelSupportsImageUrls: model.supportsImageUrls,
|
3092
|
-
modelSupportsUrl: (
|
3140
|
+
modelSupportsUrl: (_a16 = model.supportsUrl) == null ? void 0 : _a16.bind(model)
|
3093
3141
|
// support 'this' context
|
3094
3142
|
}),
|
3095
3143
|
providerMetadata: providerOptions,
|
@@ -3227,7 +3275,7 @@ var DefaultStreamObjectResult = class {
|
|
3227
3275
|
const transformedStream = stream.pipeThrough(new TransformStream(transformer)).pipeThrough(
|
3228
3276
|
new TransformStream({
|
3229
3277
|
async transform(chunk, controller) {
|
3230
|
-
var
|
3278
|
+
var _a17, _b2, _c;
|
3231
3279
|
if (isFirstChunk) {
|
3232
3280
|
const msToFirstChunk = now2() - startTimestampMs;
|
3233
3281
|
isFirstChunk = false;
|
@@ -3273,7 +3321,7 @@ var DefaultStreamObjectResult = class {
|
|
3273
3321
|
switch (chunk.type) {
|
3274
3322
|
case "response-metadata": {
|
3275
3323
|
response = {
|
3276
|
-
id: (
|
3324
|
+
id: (_a17 = chunk.id) != null ? _a17 : response.id,
|
3277
3325
|
timestamp: (_b2 = chunk.timestamp) != null ? _b2 : response.timestamp,
|
3278
3326
|
modelId: (_c = chunk.modelId) != null ? _c : response.modelId
|
3279
3327
|
};
|
@@ -3486,9 +3534,9 @@ var DefaultStreamObjectResult = class {
|
|
3486
3534
|
});
|
3487
3535
|
}
|
3488
3536
|
toTextStreamResponse(init) {
|
3489
|
-
var
|
3537
|
+
var _a16;
|
3490
3538
|
return new Response(this.textStream.pipeThrough(new TextEncoderStream()), {
|
3491
|
-
status: (
|
3539
|
+
status: (_a16 = init == null ? void 0 : init.status) != null ? _a16 : 200,
|
3492
3540
|
headers: prepareResponseHeaders(init == null ? void 0 : init.headers, {
|
3493
3541
|
contentType: "text/plain; charset=utf-8"
|
3494
3542
|
})
|
@@ -3564,24 +3612,24 @@ function prepareToolsAndToolChoice({
|
|
3564
3612
|
};
|
3565
3613
|
}
|
3566
3614
|
const filteredTools = activeTools != null ? Object.entries(tools).filter(
|
3567
|
-
([
|
3615
|
+
([name16]) => activeTools.includes(name16)
|
3568
3616
|
) : Object.entries(tools);
|
3569
3617
|
return {
|
3570
|
-
tools: filteredTools.map(([
|
3618
|
+
tools: filteredTools.map(([name16, tool2]) => {
|
3571
3619
|
const toolType = tool2.type;
|
3572
3620
|
switch (toolType) {
|
3573
3621
|
case void 0:
|
3574
3622
|
case "function":
|
3575
3623
|
return {
|
3576
3624
|
type: "function",
|
3577
|
-
name:
|
3625
|
+
name: name16,
|
3578
3626
|
description: tool2.description,
|
3579
3627
|
parameters: asSchema2(tool2.parameters).jsonSchema
|
3580
3628
|
};
|
3581
3629
|
case "provider-defined":
|
3582
3630
|
return {
|
3583
3631
|
type: "provider-defined",
|
3584
|
-
name:
|
3632
|
+
name: name16,
|
3585
3633
|
id: tool2.id,
|
3586
3634
|
args: tool2.args
|
3587
3635
|
};
|
@@ -3754,6 +3802,7 @@ async function doParseToolCall({
|
|
3754
3802
|
// core/generate-text/to-response-messages.ts
|
3755
3803
|
function toResponseMessages({
|
3756
3804
|
text: text2 = "",
|
3805
|
+
reasoning,
|
3757
3806
|
tools,
|
3758
3807
|
toolCalls,
|
3759
3808
|
toolResults,
|
@@ -3763,7 +3812,13 @@ function toResponseMessages({
|
|
3763
3812
|
const responseMessages = [];
|
3764
3813
|
responseMessages.push({
|
3765
3814
|
role: "assistant",
|
3766
|
-
content: [
|
3815
|
+
content: [
|
3816
|
+
...reasoning.map(
|
3817
|
+
(part) => part.type === "text" ? { ...part, type: "reasoning" } : { ...part, type: "redacted-reasoning" }
|
3818
|
+
),
|
3819
|
+
{ type: "text", text: text2 },
|
3820
|
+
...toolCalls
|
3821
|
+
],
|
3767
3822
|
id: messageId
|
3768
3823
|
});
|
3769
3824
|
if (toolResults.length > 0) {
|
@@ -3792,6 +3847,12 @@ function toResponseMessages({
|
|
3792
3847
|
return responseMessages;
|
3793
3848
|
}
|
3794
3849
|
|
3850
|
+
// core/generate-text/reasoning-detail.ts
|
3851
|
+
function asReasoningText(reasoning) {
|
3852
|
+
const reasoningText = reasoning.filter((part) => part.type === "text").map((part) => part.text).join("");
|
3853
|
+
return reasoningText.length > 0 ? reasoningText : void 0;
|
3854
|
+
}
|
3855
|
+
|
3795
3856
|
// core/generate-text/generate-text.ts
|
3796
3857
|
var originalGenerateId3 = createIdGenerator3({
|
3797
3858
|
prefix: "aitxt",
|
@@ -3827,7 +3888,7 @@ async function generateText({
|
|
3827
3888
|
onStepFinish,
|
3828
3889
|
...settings
|
3829
3890
|
}) {
|
3830
|
-
var
|
3891
|
+
var _a16;
|
3831
3892
|
if (maxSteps < 1) {
|
3832
3893
|
throw new InvalidArgumentError({
|
3833
3894
|
parameter: "maxSteps",
|
@@ -3844,7 +3905,7 @@ async function generateText({
|
|
3844
3905
|
});
|
3845
3906
|
const initialPrompt = standardizePrompt({
|
3846
3907
|
prompt: {
|
3847
|
-
system: (
|
3908
|
+
system: (_a16 = output == null ? void 0 : output.injectIntoSystemPrompt({ system, model })) != null ? _a16 : system,
|
3848
3909
|
prompt,
|
3849
3910
|
messages
|
3850
3911
|
},
|
@@ -3870,7 +3931,7 @@ async function generateText({
|
|
3870
3931
|
}),
|
3871
3932
|
tracer,
|
3872
3933
|
fn: async (span) => {
|
3873
|
-
var
|
3934
|
+
var _a17, _b, _c, _d, _e, _f, _g, _h, _i;
|
3874
3935
|
const mode = {
|
3875
3936
|
type: "regular",
|
3876
3937
|
...prepareToolsAndToolChoice({ tools, toolChoice, activeTools })
|
@@ -3879,6 +3940,7 @@ async function generateText({
|
|
3879
3940
|
let currentModelResponse;
|
3880
3941
|
let currentToolCalls = [];
|
3881
3942
|
let currentToolResults = [];
|
3943
|
+
let currentReasoningDetails = [];
|
3882
3944
|
let stepCount = 0;
|
3883
3945
|
const responseMessages = [];
|
3884
3946
|
let text2 = "";
|
@@ -3903,7 +3965,7 @@ async function generateText({
|
|
3903
3965
|
messages: stepInputMessages
|
3904
3966
|
},
|
3905
3967
|
modelSupportsImageUrls: model.supportsImageUrls,
|
3906
|
-
modelSupportsUrl: (
|
3968
|
+
modelSupportsUrl: (_a17 = model.supportsUrl) == null ? void 0 : _a17.bind(model)
|
3907
3969
|
// support 'this' context
|
3908
3970
|
});
|
3909
3971
|
currentModelResponse = await retry(
|
@@ -3924,8 +3986,8 @@ async function generateText({
|
|
3924
3986
|
"ai.prompt.tools": {
|
3925
3987
|
// convert the language model level tools:
|
3926
3988
|
input: () => {
|
3927
|
-
var
|
3928
|
-
return (
|
3989
|
+
var _a18;
|
3990
|
+
return (_a18 = mode.tools) == null ? void 0 : _a18.map((tool2) => JSON.stringify(tool2));
|
3929
3991
|
}
|
3930
3992
|
},
|
3931
3993
|
"ai.prompt.toolChoice": {
|
@@ -3945,7 +4007,7 @@ async function generateText({
|
|
3945
4007
|
}),
|
3946
4008
|
tracer,
|
3947
4009
|
fn: async (span2) => {
|
3948
|
-
var
|
4010
|
+
var _a18, _b2, _c2, _d2, _e2, _f2;
|
3949
4011
|
const result = await model.doGenerate({
|
3950
4012
|
mode,
|
3951
4013
|
...callSettings,
|
@@ -3957,7 +4019,7 @@ async function generateText({
|
|
3957
4019
|
headers
|
3958
4020
|
});
|
3959
4021
|
const responseData = {
|
3960
|
-
id: (_b2 = (
|
4022
|
+
id: (_b2 = (_a18 = result.response) == null ? void 0 : _a18.id) != null ? _b2 : generateId3(),
|
3961
4023
|
timestamp: (_d2 = (_c2 = result.response) == null ? void 0 : _c2.timestamp) != null ? _d2 : currentDate(),
|
3962
4024
|
modelId: (_f2 = (_e2 = result.response) == null ? void 0 : _e2.modelId) != null ? _f2 : model.modelId
|
3963
4025
|
};
|
@@ -4031,6 +4093,9 @@ async function generateText({
|
|
4031
4093
|
text2.trimEnd() !== text2 ? originalText.trimStart() : originalText;
|
4032
4094
|
const stepText = nextStepType === "continue" ? removeTextAfterLastWhitespace(stepTextLeadingWhitespaceTrimmed) : stepTextLeadingWhitespaceTrimmed;
|
4033
4095
|
text2 = nextStepType === "continue" || stepType === "continue" ? text2 + stepText : stepText;
|
4096
|
+
currentReasoningDetails = asReasoningDetails(
|
4097
|
+
currentModelResponse.reasoning
|
4098
|
+
);
|
4034
4099
|
sources.push(...(_d = currentModelResponse.sources) != null ? _d : []);
|
4035
4100
|
if (stepType === "continue") {
|
4036
4101
|
const lastMessage = responseMessages[responseMessages.length - 1];
|
@@ -4046,6 +4111,7 @@ async function generateText({
|
|
4046
4111
|
responseMessages.push(
|
4047
4112
|
...toResponseMessages({
|
4048
4113
|
text: text2,
|
4114
|
+
reasoning: asReasoningDetails(currentModelResponse.reasoning),
|
4049
4115
|
tools: tools != null ? tools : {},
|
4050
4116
|
toolCalls: currentToolCalls,
|
4051
4117
|
toolResults: currentToolResults,
|
@@ -4057,7 +4123,9 @@ async function generateText({
|
|
4057
4123
|
const currentStepResult = {
|
4058
4124
|
stepType,
|
4059
4125
|
text: stepText,
|
4060
|
-
|
4126
|
+
// TODO v5: rename reasoning to reasoningText (and use reasoning for composite array)
|
4127
|
+
reasoning: asReasoningText(currentReasoningDetails),
|
4128
|
+
reasoningDetails: currentReasoningDetails,
|
4061
4129
|
sources: (_e = currentModelResponse.sources) != null ? _e : [],
|
4062
4130
|
toolCalls: currentToolCalls,
|
4063
4131
|
toolResults: currentToolResults,
|
@@ -4098,7 +4166,8 @@ async function generateText({
|
|
4098
4166
|
);
|
4099
4167
|
return new DefaultGenerateTextResult({
|
4100
4168
|
text: text2,
|
4101
|
-
reasoning:
|
4169
|
+
reasoning: asReasoningText(currentReasoningDetails),
|
4170
|
+
reasoningDetails: currentReasoningDetails,
|
4102
4171
|
sources,
|
4103
4172
|
outputResolver: () => {
|
4104
4173
|
if (output == null) {
|
@@ -4206,6 +4275,7 @@ var DefaultGenerateTextResult = class {
|
|
4206
4275
|
constructor(options) {
|
4207
4276
|
this.text = options.text;
|
4208
4277
|
this.reasoning = options.reasoning;
|
4278
|
+
this.reasoningDetails = options.reasoningDetails;
|
4209
4279
|
this.toolCalls = options.toolCalls;
|
4210
4280
|
this.toolResults = options.toolResults;
|
4211
4281
|
this.finishReason = options.finishReason;
|
@@ -4224,6 +4294,15 @@ var DefaultGenerateTextResult = class {
|
|
4224
4294
|
return this.outputResolver();
|
4225
4295
|
}
|
4226
4296
|
};
|
4297
|
+
function asReasoningDetails(reasoning) {
|
4298
|
+
if (reasoning == null) {
|
4299
|
+
return [];
|
4300
|
+
}
|
4301
|
+
if (typeof reasoning === "string") {
|
4302
|
+
return [{ type: "text", text: reasoning }];
|
4303
|
+
}
|
4304
|
+
return reasoning;
|
4305
|
+
}
|
4227
4306
|
|
4228
4307
|
// core/generate-text/output.ts
|
4229
4308
|
var output_exports = {};
|
@@ -4239,7 +4318,7 @@ import {
|
|
4239
4318
|
|
4240
4319
|
// errors/index.ts
|
4241
4320
|
import {
|
4242
|
-
AISDKError as
|
4321
|
+
AISDKError as AISDKError15,
|
4243
4322
|
APICallError as APICallError2,
|
4244
4323
|
EmptyResponseBodyError,
|
4245
4324
|
InvalidPromptError as InvalidPromptError2,
|
@@ -4252,6 +4331,27 @@ import {
|
|
4252
4331
|
UnsupportedFunctionalityError as UnsupportedFunctionalityError2
|
4253
4332
|
} from "@ai-sdk/provider";
|
4254
4333
|
|
4334
|
+
// errors/invalid-stream-part-error.ts
|
4335
|
+
import { AISDKError as AISDKError14 } from "@ai-sdk/provider";
|
4336
|
+
var name14 = "AI_InvalidStreamPartError";
|
4337
|
+
var marker14 = `vercel.ai.error.${name14}`;
|
4338
|
+
var symbol14 = Symbol.for(marker14);
|
4339
|
+
var _a14;
|
4340
|
+
var InvalidStreamPartError = class extends AISDKError14 {
|
4341
|
+
constructor({
|
4342
|
+
chunk,
|
4343
|
+
message
|
4344
|
+
}) {
|
4345
|
+
super({ name: name14, message });
|
4346
|
+
this[_a14] = true;
|
4347
|
+
this.chunk = chunk;
|
4348
|
+
}
|
4349
|
+
static isInstance(error) {
|
4350
|
+
return AISDKError14.hasMarker(error, marker14);
|
4351
|
+
}
|
4352
|
+
};
|
4353
|
+
_a14 = symbol14;
|
4354
|
+
|
4255
4355
|
// core/generate-text/output.ts
|
4256
4356
|
var text = () => ({
|
4257
4357
|
type: "text",
|
@@ -4378,6 +4478,7 @@ function smoothStream({
|
|
4378
4478
|
}
|
4379
4479
|
|
4380
4480
|
// core/generate-text/stream-text.ts
|
4481
|
+
import { AISDKError as AISDKError16 } from "@ai-sdk/provider";
|
4381
4482
|
import { createIdGenerator as createIdGenerator4 } from "@ai-sdk/provider-utils";
|
4382
4483
|
import { formatDataStreamPart as formatDataStreamPart2 } from "@ai-sdk/ui-utils";
|
4383
4484
|
|
@@ -4511,6 +4612,8 @@ function runToolsTransformation({
|
|
4511
4612
|
switch (chunkType) {
|
4512
4613
|
case "text-delta":
|
4513
4614
|
case "reasoning":
|
4615
|
+
case "reasoning-signature":
|
4616
|
+
case "redacted-reasoning":
|
4514
4617
|
case "source":
|
4515
4618
|
case "response-metadata":
|
4516
4619
|
case "error": {
|
@@ -4822,13 +4925,14 @@ var DefaultStreamTextResult = class {
|
|
4822
4925
|
this.providerMetadataPromise = new DelayedPromise();
|
4823
4926
|
this.textPromise = new DelayedPromise();
|
4824
4927
|
this.reasoningPromise = new DelayedPromise();
|
4928
|
+
this.reasoningDetailsPromise = new DelayedPromise();
|
4825
4929
|
this.sourcesPromise = new DelayedPromise();
|
4826
4930
|
this.toolCallsPromise = new DelayedPromise();
|
4827
4931
|
this.toolResultsPromise = new DelayedPromise();
|
4828
4932
|
this.requestPromise = new DelayedPromise();
|
4829
4933
|
this.responsePromise = new DelayedPromise();
|
4830
4934
|
this.stepsPromise = new DelayedPromise();
|
4831
|
-
var
|
4935
|
+
var _a16;
|
4832
4936
|
if (maxSteps < 1) {
|
4833
4937
|
throw new InvalidArgumentError({
|
4834
4938
|
parameter: "maxSteps",
|
@@ -4840,7 +4944,8 @@ var DefaultStreamTextResult = class {
|
|
4840
4944
|
let recordedStepText = "";
|
4841
4945
|
let recordedContinuationText = "";
|
4842
4946
|
let recordedFullText = "";
|
4843
|
-
|
4947
|
+
const stepReasoning = [];
|
4948
|
+
let activeReasoningText = void 0;
|
4844
4949
|
let recordedStepSources = [];
|
4845
4950
|
const recordedSources = [];
|
4846
4951
|
const recordedResponse = {
|
@@ -4872,7 +4977,25 @@ var DefaultStreamTextResult = class {
|
|
4872
4977
|
recordedFullText += part.textDelta;
|
4873
4978
|
}
|
4874
4979
|
if (part.type === "reasoning") {
|
4875
|
-
|
4980
|
+
if (activeReasoningText == null) {
|
4981
|
+
activeReasoningText = { type: "text", text: part.textDelta };
|
4982
|
+
stepReasoning.push(activeReasoningText);
|
4983
|
+
} else {
|
4984
|
+
activeReasoningText.text += part.textDelta;
|
4985
|
+
}
|
4986
|
+
}
|
4987
|
+
if (part.type === "reasoning-signature") {
|
4988
|
+
if (activeReasoningText == null) {
|
4989
|
+
throw new AISDKError16({
|
4990
|
+
name: "InvalidStreamPart",
|
4991
|
+
message: "reasoning-signature without reasoning"
|
4992
|
+
});
|
4993
|
+
}
|
4994
|
+
activeReasoningText.signature = part.signature;
|
4995
|
+
activeReasoningText = void 0;
|
4996
|
+
}
|
4997
|
+
if (part.type === "redacted-reasoning") {
|
4998
|
+
stepReasoning.push({ type: "redacted", data: part.data });
|
4876
4999
|
}
|
4877
5000
|
if (part.type === "source") {
|
4878
5001
|
recordedSources.push(part.source);
|
@@ -4887,6 +5010,7 @@ var DefaultStreamTextResult = class {
|
|
4887
5010
|
if (part.type === "step-finish") {
|
4888
5011
|
const stepMessages = toResponseMessages({
|
4889
5012
|
text: recordedContinuationText,
|
5013
|
+
reasoning: stepReasoning,
|
4890
5014
|
tools: tools != null ? tools : {},
|
4891
5015
|
toolCalls: recordedToolCalls,
|
4892
5016
|
toolResults: recordedToolResults,
|
@@ -4910,7 +5034,8 @@ var DefaultStreamTextResult = class {
|
|
4910
5034
|
const currentStepResult = {
|
4911
5035
|
stepType,
|
4912
5036
|
text: recordedStepText,
|
4913
|
-
reasoning:
|
5037
|
+
reasoning: asReasoningText(stepReasoning),
|
5038
|
+
reasoningDetails: stepReasoning,
|
4914
5039
|
sources: recordedStepSources,
|
4915
5040
|
toolCalls: recordedToolCalls,
|
4916
5041
|
toolResults: recordedToolResults,
|
@@ -4951,7 +5076,7 @@ var DefaultStreamTextResult = class {
|
|
4951
5076
|
}
|
4952
5077
|
},
|
4953
5078
|
async flush(controller) {
|
4954
|
-
var
|
5079
|
+
var _a17;
|
4955
5080
|
try {
|
4956
5081
|
if (recordedSteps.length === 0) {
|
4957
5082
|
return;
|
@@ -4965,6 +5090,8 @@ var DefaultStreamTextResult = class {
|
|
4965
5090
|
self.providerMetadataPromise.resolve(
|
4966
5091
|
lastStep.experimental_providerMetadata
|
4967
5092
|
);
|
5093
|
+
self.reasoningPromise.resolve(lastStep.reasoning);
|
5094
|
+
self.reasoningDetailsPromise.resolve(lastStep.reasoningDetails);
|
4968
5095
|
const finishReason = recordedFinishReason != null ? recordedFinishReason : "unknown";
|
4969
5096
|
const usage = recordedUsage != null ? recordedUsage : {
|
4970
5097
|
completionTokens: NaN,
|
@@ -4974,7 +5101,6 @@ var DefaultStreamTextResult = class {
|
|
4974
5101
|
self.finishReasonPromise.resolve(finishReason);
|
4975
5102
|
self.usagePromise.resolve(usage);
|
4976
5103
|
self.textPromise.resolve(recordedFullText);
|
4977
|
-
self.reasoningPromise.resolve(recordedReasoningText);
|
4978
5104
|
self.sourcesPromise.resolve(recordedSources);
|
4979
5105
|
self.stepsPromise.resolve(recordedSteps);
|
4980
5106
|
await (onFinish == null ? void 0 : onFinish({
|
@@ -4983,10 +5109,11 @@ var DefaultStreamTextResult = class {
|
|
4983
5109
|
usage,
|
4984
5110
|
text: recordedFullText,
|
4985
5111
|
reasoning: lastStep.reasoning,
|
5112
|
+
reasoningDetails: lastStep.reasoningDetails,
|
4986
5113
|
sources: lastStep.sources,
|
4987
5114
|
toolCalls: lastStep.toolCalls,
|
4988
5115
|
toolResults: lastStep.toolResults,
|
4989
|
-
request: (
|
5116
|
+
request: (_a17 = lastStep.request) != null ? _a17 : {},
|
4990
5117
|
response: lastStep.response,
|
4991
5118
|
warnings: lastStep.warnings,
|
4992
5119
|
providerMetadata: lastStep.providerMetadata,
|
@@ -5001,8 +5128,8 @@ var DefaultStreamTextResult = class {
|
|
5001
5128
|
"ai.response.text": { output: () => recordedFullText },
|
5002
5129
|
"ai.response.toolCalls": {
|
5003
5130
|
output: () => {
|
5004
|
-
var
|
5005
|
-
return ((
|
5131
|
+
var _a18;
|
5132
|
+
return ((_a18 = lastStep.toolCalls) == null ? void 0 : _a18.length) ? JSON.stringify(lastStep.toolCalls) : void 0;
|
5006
5133
|
}
|
5007
5134
|
},
|
5008
5135
|
"ai.usage.promptTokens": usage.promptTokens,
|
@@ -5044,7 +5171,7 @@ var DefaultStreamTextResult = class {
|
|
5044
5171
|
});
|
5045
5172
|
const initialPrompt = standardizePrompt({
|
5046
5173
|
prompt: {
|
5047
|
-
system: (
|
5174
|
+
system: (_a16 = output == null ? void 0 : output.injectIntoSystemPrompt({ system, model })) != null ? _a16 : system,
|
5048
5175
|
prompt,
|
5049
5176
|
messages
|
5050
5177
|
},
|
@@ -5078,7 +5205,7 @@ var DefaultStreamTextResult = class {
|
|
5078
5205
|
hasLeadingWhitespace,
|
5079
5206
|
messageId
|
5080
5207
|
}) {
|
5081
|
-
var
|
5208
|
+
var _a17;
|
5082
5209
|
const promptFormat = responseMessages.length === 0 ? initialPrompt.type : "messages";
|
5083
5210
|
const stepInputMessages = [
|
5084
5211
|
...initialPrompt.messages,
|
@@ -5091,7 +5218,7 @@ var DefaultStreamTextResult = class {
|
|
5091
5218
|
messages: stepInputMessages
|
5092
5219
|
},
|
5093
5220
|
modelSupportsImageUrls: model.supportsImageUrls,
|
5094
|
-
modelSupportsUrl: (
|
5221
|
+
modelSupportsUrl: (_a17 = model.supportsUrl) == null ? void 0 : _a17.bind(model)
|
5095
5222
|
// support 'this' context
|
5096
5223
|
});
|
5097
5224
|
const mode = {
|
@@ -5122,8 +5249,8 @@ var DefaultStreamTextResult = class {
|
|
5122
5249
|
"ai.prompt.tools": {
|
5123
5250
|
// convert the language model level tools:
|
5124
5251
|
input: () => {
|
5125
|
-
var
|
5126
|
-
return (
|
5252
|
+
var _a18;
|
5253
|
+
return (_a18 = mode.tools) == null ? void 0 : _a18.map((tool2) => JSON.stringify(tool2));
|
5127
5254
|
}
|
5128
5255
|
},
|
5129
5256
|
"ai.prompt.toolChoice": {
|
@@ -5174,6 +5301,8 @@ var DefaultStreamTextResult = class {
|
|
5174
5301
|
const stepRequest = request != null ? request : {};
|
5175
5302
|
const stepToolCalls = [];
|
5176
5303
|
const stepToolResults = [];
|
5304
|
+
const stepReasoning2 = [];
|
5305
|
+
let activeReasoningText2 = void 0;
|
5177
5306
|
let stepFinishReason = "unknown";
|
5178
5307
|
let stepUsage = {
|
5179
5308
|
promptTokens: 0,
|
@@ -5183,7 +5312,6 @@ var DefaultStreamTextResult = class {
|
|
5183
5312
|
let stepProviderMetadata;
|
5184
5313
|
let stepFirstChunk = true;
|
5185
5314
|
let stepText = "";
|
5186
|
-
let stepReasoning = "";
|
5187
5315
|
let fullStepText = stepType2 === "continue" ? previousStepText : "";
|
5188
5316
|
let stepLogProbs;
|
5189
5317
|
let stepResponse = {
|
@@ -5209,7 +5337,7 @@ var DefaultStreamTextResult = class {
|
|
5209
5337
|
transformedStream.pipeThrough(
|
5210
5338
|
new TransformStream({
|
5211
5339
|
async transform(chunk, controller) {
|
5212
|
-
var
|
5340
|
+
var _a18, _b, _c;
|
5213
5341
|
if (stepFirstChunk) {
|
5214
5342
|
const msToFirstChunk = now2() - startTimestampMs;
|
5215
5343
|
stepFirstChunk = false;
|
@@ -5257,11 +5385,35 @@ var DefaultStreamTextResult = class {
|
|
5257
5385
|
}
|
5258
5386
|
case "reasoning": {
|
5259
5387
|
controller.enqueue(chunk);
|
5260
|
-
|
5388
|
+
if (activeReasoningText2 == null) {
|
5389
|
+
activeReasoningText2 = {
|
5390
|
+
type: "text",
|
5391
|
+
text: chunk.textDelta
|
5392
|
+
};
|
5393
|
+
stepReasoning2.push(activeReasoningText2);
|
5394
|
+
} else {
|
5395
|
+
activeReasoningText2.text += chunk.textDelta;
|
5396
|
+
}
|
5261
5397
|
break;
|
5262
5398
|
}
|
5263
|
-
case "
|
5399
|
+
case "reasoning-signature": {
|
5264
5400
|
controller.enqueue(chunk);
|
5401
|
+
if (activeReasoningText2 == null) {
|
5402
|
+
throw new InvalidStreamPartError({
|
5403
|
+
chunk,
|
5404
|
+
message: "reasoning-signature without reasoning"
|
5405
|
+
});
|
5406
|
+
}
|
5407
|
+
activeReasoningText2.signature = chunk.signature;
|
5408
|
+
activeReasoningText2 = void 0;
|
5409
|
+
break;
|
5410
|
+
}
|
5411
|
+
case "redacted-reasoning": {
|
5412
|
+
controller.enqueue(chunk);
|
5413
|
+
stepReasoning2.push({
|
5414
|
+
type: "redacted",
|
5415
|
+
data: chunk.data
|
5416
|
+
});
|
5265
5417
|
break;
|
5266
5418
|
}
|
5267
5419
|
case "tool-call": {
|
@@ -5276,7 +5428,7 @@ var DefaultStreamTextResult = class {
|
|
5276
5428
|
}
|
5277
5429
|
case "response-metadata": {
|
5278
5430
|
stepResponse = {
|
5279
|
-
id: (
|
5431
|
+
id: (_a18 = chunk.id) != null ? _a18 : stepResponse.id,
|
5280
5432
|
timestamp: (_b = chunk.timestamp) != null ? _b : stepResponse.timestamp,
|
5281
5433
|
modelId: (_c = chunk.modelId) != null ? _c : stepResponse.modelId
|
5282
5434
|
};
|
@@ -5295,6 +5447,7 @@ var DefaultStreamTextResult = class {
|
|
5295
5447
|
});
|
5296
5448
|
break;
|
5297
5449
|
}
|
5450
|
+
case "source":
|
5298
5451
|
case "tool-call-streaming-start":
|
5299
5452
|
case "tool-call-delta": {
|
5300
5453
|
controller.enqueue(chunk);
|
@@ -5412,6 +5565,7 @@ var DefaultStreamTextResult = class {
|
|
5412
5565
|
responseMessages.push(
|
5413
5566
|
...toResponseMessages({
|
5414
5567
|
text: stepText,
|
5568
|
+
reasoning: stepReasoning2,
|
5415
5569
|
tools: tools != null ? tools : {},
|
5416
5570
|
toolCalls: stepToolCalls,
|
5417
5571
|
toolResults: stepToolResults,
|
@@ -5485,6 +5639,9 @@ var DefaultStreamTextResult = class {
|
|
5485
5639
|
get reasoning() {
|
5486
5640
|
return this.reasoningPromise.value;
|
5487
5641
|
}
|
5642
|
+
get reasoningDetails() {
|
5643
|
+
return this.reasoningDetailsPromise.value;
|
5644
|
+
}
|
5488
5645
|
get sources() {
|
5489
5646
|
return this.sourcesPromise.value;
|
5490
5647
|
}
|
@@ -5585,6 +5742,26 @@ var DefaultStreamTextResult = class {
|
|
5585
5742
|
}
|
5586
5743
|
break;
|
5587
5744
|
}
|
5745
|
+
case "redacted-reasoning": {
|
5746
|
+
if (sendReasoning) {
|
5747
|
+
controller.enqueue(
|
5748
|
+
formatDataStreamPart2("redacted_reasoning", {
|
5749
|
+
data: chunk.data
|
5750
|
+
})
|
5751
|
+
);
|
5752
|
+
}
|
5753
|
+
break;
|
5754
|
+
}
|
5755
|
+
case "reasoning-signature": {
|
5756
|
+
if (sendReasoning) {
|
5757
|
+
controller.enqueue(
|
5758
|
+
formatDataStreamPart2("reasoning_signature", {
|
5759
|
+
signature: chunk.signature
|
5760
|
+
})
|
5761
|
+
);
|
5762
|
+
}
|
5763
|
+
break;
|
5764
|
+
}
|
5588
5765
|
case "source": {
|
5589
5766
|
if (sendSources) {
|
5590
5767
|
controller.enqueue(
|
@@ -5765,9 +5942,9 @@ var DefaultStreamTextResult = class {
|
|
5765
5942
|
);
|
5766
5943
|
}
|
5767
5944
|
toTextStreamResponse(init) {
|
5768
|
-
var
|
5945
|
+
var _a16;
|
5769
5946
|
return new Response(this.textStream.pipeThrough(new TextEncoderStream()), {
|
5770
|
-
status: (
|
5947
|
+
status: (_a16 = init == null ? void 0 : init.status) != null ? _a16 : 200,
|
5771
5948
|
headers: prepareResponseHeaders(init == null ? void 0 : init.headers, {
|
5772
5949
|
contentType: "text/plain; charset=utf-8"
|
5773
5950
|
})
|
@@ -5902,7 +6079,7 @@ var doWrap = ({
|
|
5902
6079
|
modelId,
|
5903
6080
|
providerId
|
5904
6081
|
}) => {
|
5905
|
-
var
|
6082
|
+
var _a16;
|
5906
6083
|
async function doTransform({
|
5907
6084
|
params,
|
5908
6085
|
type
|
@@ -5915,7 +6092,7 @@ var doWrap = ({
|
|
5915
6092
|
modelId: modelId != null ? modelId : model.modelId,
|
5916
6093
|
defaultObjectGenerationMode: model.defaultObjectGenerationMode,
|
5917
6094
|
supportsImageUrls: model.supportsImageUrls,
|
5918
|
-
supportsUrl: (
|
6095
|
+
supportsUrl: (_a16 = model.supportsUrl) == null ? void 0 : _a16.bind(model),
|
5919
6096
|
supportsStructuredOutputs: model.supportsStructuredOutputs,
|
5920
6097
|
async doGenerate(params) {
|
5921
6098
|
const transformedParams = await doTransform({ params, type: "generate" });
|
@@ -5951,7 +6128,7 @@ function appendResponseMessages({
|
|
5951
6128
|
responseMessages,
|
5952
6129
|
_internal: { currentDate = () => /* @__PURE__ */ new Date() } = {}
|
5953
6130
|
}) {
|
5954
|
-
var
|
6131
|
+
var _a16, _b, _c, _d;
|
5955
6132
|
const clonedMessages = structuredClone(messages);
|
5956
6133
|
for (const message of responseMessages) {
|
5957
6134
|
const role = message.role;
|
@@ -5974,7 +6151,7 @@ function appendResponseMessages({
|
|
5974
6151
|
const maxStep = extractMaxToolInvocationStep(
|
5975
6152
|
lastMessage.toolInvocations
|
5976
6153
|
);
|
5977
|
-
(
|
6154
|
+
(_a16 = lastMessage.parts) != null ? _a16 : lastMessage.parts = [];
|
5978
6155
|
lastMessage.content = textContent;
|
5979
6156
|
if (textContent.length > 0) {
|
5980
6157
|
lastMessage.parts.push({
|
@@ -6092,11 +6269,11 @@ function customProvider({
|
|
6092
6269
|
var experimental_customProvider = customProvider;
|
6093
6270
|
|
6094
6271
|
// core/registry/no-such-provider-error.ts
|
6095
|
-
import { AISDKError as
|
6096
|
-
var
|
6097
|
-
var
|
6098
|
-
var
|
6099
|
-
var
|
6272
|
+
import { AISDKError as AISDKError17, NoSuchModelError as NoSuchModelError3 } from "@ai-sdk/provider";
|
6273
|
+
var name15 = "AI_NoSuchProviderError";
|
6274
|
+
var marker15 = `vercel.ai.error.${name15}`;
|
6275
|
+
var symbol15 = Symbol.for(marker15);
|
6276
|
+
var _a15;
|
6100
6277
|
var NoSuchProviderError = class extends NoSuchModelError3 {
|
6101
6278
|
constructor({
|
6102
6279
|
modelId,
|
@@ -6105,16 +6282,16 @@ var NoSuchProviderError = class extends NoSuchModelError3 {
|
|
6105
6282
|
availableProviders,
|
6106
6283
|
message = `No such provider: ${providerId} (available providers: ${availableProviders.join()})`
|
6107
6284
|
}) {
|
6108
|
-
super({ errorName:
|
6109
|
-
this[
|
6285
|
+
super({ errorName: name15, modelId, modelType, message });
|
6286
|
+
this[_a15] = true;
|
6110
6287
|
this.providerId = providerId;
|
6111
6288
|
this.availableProviders = availableProviders;
|
6112
6289
|
}
|
6113
6290
|
static isInstance(error) {
|
6114
|
-
return
|
6291
|
+
return AISDKError17.hasMarker(error, marker15);
|
6115
6292
|
}
|
6116
6293
|
};
|
6117
|
-
|
6294
|
+
_a15 = symbol15;
|
6118
6295
|
|
6119
6296
|
// core/registry/provider-registry.ts
|
6120
6297
|
import { NoSuchModelError as NoSuchModelError4 } from "@ai-sdk/provider";
|
@@ -6159,19 +6336,19 @@ var DefaultProviderRegistry = class {
|
|
6159
6336
|
return [id.slice(0, index), id.slice(index + 1)];
|
6160
6337
|
}
|
6161
6338
|
languageModel(id) {
|
6162
|
-
var
|
6339
|
+
var _a16, _b;
|
6163
6340
|
const [providerId, modelId] = this.splitId(id, "languageModel");
|
6164
|
-
const model = (_b = (
|
6341
|
+
const model = (_b = (_a16 = this.getProvider(providerId)).languageModel) == null ? void 0 : _b.call(_a16, modelId);
|
6165
6342
|
if (model == null) {
|
6166
6343
|
throw new NoSuchModelError4({ modelId: id, modelType: "languageModel" });
|
6167
6344
|
}
|
6168
6345
|
return model;
|
6169
6346
|
}
|
6170
6347
|
textEmbeddingModel(id) {
|
6171
|
-
var
|
6348
|
+
var _a16;
|
6172
6349
|
const [providerId, modelId] = this.splitId(id, "textEmbeddingModel");
|
6173
6350
|
const provider = this.getProvider(providerId);
|
6174
|
-
const model = (
|
6351
|
+
const model = (_a16 = provider.textEmbeddingModel) == null ? void 0 : _a16.call(provider, modelId);
|
6175
6352
|
if (model == null) {
|
6176
6353
|
throw new NoSuchModelError4({
|
6177
6354
|
modelId: id,
|
@@ -6181,10 +6358,10 @@ var DefaultProviderRegistry = class {
|
|
6181
6358
|
return model;
|
6182
6359
|
}
|
6183
6360
|
imageModel(id) {
|
6184
|
-
var
|
6361
|
+
var _a16;
|
6185
6362
|
const [providerId, modelId] = this.splitId(id, "imageModel");
|
6186
6363
|
const provider = this.getProvider(providerId);
|
6187
|
-
const model = (
|
6364
|
+
const model = (_a16 = provider.imageModel) == null ? void 0 : _a16.call(provider, modelId);
|
6188
6365
|
if (model == null) {
|
6189
6366
|
throw new NoSuchModelError4({ modelId: id, modelType: "imageModel" });
|
6190
6367
|
}
|
@@ -6245,8 +6422,8 @@ function simulateReadableStream({
|
|
6245
6422
|
chunkDelayInMs = 0,
|
6246
6423
|
_internal
|
6247
6424
|
}) {
|
6248
|
-
var
|
6249
|
-
const delay2 = (
|
6425
|
+
var _a16;
|
6426
|
+
const delay2 = (_a16 = _internal == null ? void 0 : _internal.delay) != null ? _a16 : delayFunction;
|
6250
6427
|
let index = 0;
|
6251
6428
|
return new ReadableStream({
|
6252
6429
|
async pull(controller) {
|
@@ -6267,7 +6444,7 @@ import {
|
|
6267
6444
|
function AssistantResponse({ threadId, messageId }, process2) {
|
6268
6445
|
const stream = new ReadableStream({
|
6269
6446
|
async start(controller) {
|
6270
|
-
var
|
6447
|
+
var _a16;
|
6271
6448
|
const textEncoder = new TextEncoder();
|
6272
6449
|
const sendMessage = (message) => {
|
6273
6450
|
controller.enqueue(
|
@@ -6289,7 +6466,7 @@ function AssistantResponse({ threadId, messageId }, process2) {
|
|
6289
6466
|
);
|
6290
6467
|
};
|
6291
6468
|
const forwardStream = async (stream2) => {
|
6292
|
-
var
|
6469
|
+
var _a17, _b;
|
6293
6470
|
let result = void 0;
|
6294
6471
|
for await (const value of stream2) {
|
6295
6472
|
switch (value.event) {
|
@@ -6306,7 +6483,7 @@ function AssistantResponse({ threadId, messageId }, process2) {
|
|
6306
6483
|
break;
|
6307
6484
|
}
|
6308
6485
|
case "thread.message.delta": {
|
6309
|
-
const content = (
|
6486
|
+
const content = (_a17 = value.data.delta.content) == null ? void 0 : _a17[0];
|
6310
6487
|
if ((content == null ? void 0 : content.type) === "text" && ((_b = content.text) == null ? void 0 : _b.value) != null) {
|
6311
6488
|
controller.enqueue(
|
6312
6489
|
textEncoder.encode(
|
@@ -6340,7 +6517,7 @@ function AssistantResponse({ threadId, messageId }, process2) {
|
|
6340
6517
|
forwardStream
|
6341
6518
|
});
|
6342
6519
|
} catch (error) {
|
6343
|
-
sendError((
|
6520
|
+
sendError((_a16 = error.message) != null ? _a16 : `${error}`);
|
6344
6521
|
} finally {
|
6345
6522
|
controller.close();
|
6346
6523
|
}
|
@@ -6401,7 +6578,7 @@ function toDataStreamInternal(stream, callbacks) {
|
|
6401
6578
|
return stream.pipeThrough(
|
6402
6579
|
new TransformStream({
|
6403
6580
|
transform: async (value, controller) => {
|
6404
|
-
var
|
6581
|
+
var _a16;
|
6405
6582
|
if (typeof value === "string") {
|
6406
6583
|
controller.enqueue(value);
|
6407
6584
|
return;
|
@@ -6409,7 +6586,7 @@ function toDataStreamInternal(stream, callbacks) {
|
|
6409
6586
|
if ("event" in value) {
|
6410
6587
|
if (value.event === "on_chat_model_stream") {
|
6411
6588
|
forwardAIMessageChunk(
|
6412
|
-
(
|
6589
|
+
(_a16 = value.data) == null ? void 0 : _a16.chunk,
|
6413
6590
|
controller
|
6414
6591
|
);
|
6415
6592
|
}
|
@@ -6432,7 +6609,7 @@ function toDataStream(stream, callbacks) {
|
|
6432
6609
|
);
|
6433
6610
|
}
|
6434
6611
|
function toDataStreamResponse(stream, options) {
|
6435
|
-
var
|
6612
|
+
var _a16;
|
6436
6613
|
const dataStream = toDataStreamInternal(
|
6437
6614
|
stream,
|
6438
6615
|
options == null ? void 0 : options.callbacks
|
@@ -6441,7 +6618,7 @@ function toDataStreamResponse(stream, options) {
|
|
6441
6618
|
const init = options == null ? void 0 : options.init;
|
6442
6619
|
const responseStream = data ? mergeStreams(data.stream, dataStream) : dataStream;
|
6443
6620
|
return new Response(responseStream, {
|
6444
|
-
status: (
|
6621
|
+
status: (_a16 = init == null ? void 0 : init.status) != null ? _a16 : 200,
|
6445
6622
|
statusText: init == null ? void 0 : init.statusText,
|
6446
6623
|
headers: prepareResponseHeaders(init == null ? void 0 : init.headers, {
|
6447
6624
|
contentType: "text/plain; charset=utf-8",
|
@@ -6496,14 +6673,14 @@ function toDataStream2(stream, callbacks) {
|
|
6496
6673
|
);
|
6497
6674
|
}
|
6498
6675
|
function toDataStreamResponse2(stream, options = {}) {
|
6499
|
-
var
|
6676
|
+
var _a16;
|
6500
6677
|
const { init, data, callbacks } = options;
|
6501
6678
|
const dataStream = toDataStreamInternal2(stream, callbacks).pipeThrough(
|
6502
6679
|
new TextEncoderStream()
|
6503
6680
|
);
|
6504
6681
|
const responseStream = data ? mergeStreams(data.stream, dataStream) : dataStream;
|
6505
6682
|
return new Response(responseStream, {
|
6506
|
-
status: (
|
6683
|
+
status: (_a16 = init == null ? void 0 : init.status) != null ? _a16 : 200,
|
6507
6684
|
statusText: init == null ? void 0 : init.statusText,
|
6508
6685
|
headers: prepareResponseHeaders(init == null ? void 0 : init.headers, {
|
6509
6686
|
contentType: "text/plain; charset=utf-8",
|
@@ -6595,7 +6772,7 @@ var StreamData = class {
|
|
6595
6772
|
}
|
6596
6773
|
};
|
6597
6774
|
export {
|
6598
|
-
|
6775
|
+
AISDKError15 as AISDKError,
|
6599
6776
|
APICallError2 as APICallError,
|
6600
6777
|
AssistantResponse,
|
6601
6778
|
DownloadError,
|
@@ -6605,6 +6782,7 @@ export {
|
|
6605
6782
|
InvalidMessageRoleError,
|
6606
6783
|
InvalidPromptError2 as InvalidPromptError,
|
6607
6784
|
InvalidResponseDataError,
|
6785
|
+
InvalidStreamPartError,
|
6608
6786
|
InvalidToolArgumentsError,
|
6609
6787
|
JSONParseError2 as JSONParseError,
|
6610
6788
|
langchain_adapter_exports as LangChainAdapter,
|