ai 7.0.110 → 7.0.112
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 +22 -0
- package/dist/index.d.ts +163 -41
- package/dist/index.js +262 -73
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +141 -2
- package/dist/internal/index.js +33 -4
- package/dist/internal/index.js.map +1 -1
- package/docs/03-ai-sdk-core/40-middleware.mdx +92 -7
- package/docs/03-ai-sdk-core/60-telemetry.mdx +56 -3
- package/docs/03-ai-sdk-core/65-lifecycle-callbacks.mdx +124 -2
- package/docs/06-advanced/02-stopping-streams.mdx +8 -0
- package/docs/07-reference/01-ai-sdk-core/02-stream-text.mdx +3 -3
- package/docs/07-reference/01-ai-sdk-core/14-evaluate.mdx +16 -9
- package/docs/07-reference/02-ai-sdk-ui/40-create-ui-message-stream.mdx +9 -3
- package/package.json +12 -12
- package/src/batch/batch.ts +18 -3
- package/src/evaluate/evaluate-events.ts +131 -0
- package/src/evaluate/evaluate.ts +145 -40
- package/src/evaluate/index.ts +6 -0
- package/src/evaluate/restricted-telemetry-dispatcher.ts +46 -0
- package/src/generate-text/convert-language-model-content.ts +15 -6
- package/src/generate-text/generate-text.ts +7 -2
- package/src/generate-text/prune-messages.ts +3 -1
- package/src/generate-text/resolve-generated-file-data.ts +41 -0
- package/src/generate-text/stream-language-model-call.ts +5 -4
- package/src/prompt/convert-to-language-model-prompt.ts +12 -2
- package/src/prompt/file-part-data.ts +11 -1
- package/src/telemetry/create-telemetry-dispatcher.ts +12 -0
- package/src/telemetry/telemetry.ts +34 -0
- package/src/telemetry/tracing-channel.ts +2 -1
- package/src/ui/validate-ui-messages.ts +2 -2
- package/src/ui-message-stream/handle-ui-message-stream-finish.ts +5 -3
- package/src/ui-message-stream/ui-message-stream-on-end-callback.ts +8 -0
- package/src/ui-message-stream/ui-message-stream-outcome.ts +4 -0
package/dist/index.js
CHANGED
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
} from "@ai-sdk/gateway";
|
|
12
12
|
import {
|
|
13
13
|
asSchema as asSchema8,
|
|
14
|
-
createIdGenerator as
|
|
14
|
+
createIdGenerator as createIdGenerator10,
|
|
15
15
|
dynamicTool,
|
|
16
16
|
experimental_toolCaller,
|
|
17
17
|
generateId as generateId4,
|
|
@@ -1334,7 +1334,7 @@ import {
|
|
|
1334
1334
|
} from "@ai-sdk/provider-utils";
|
|
1335
1335
|
|
|
1336
1336
|
// src/version.ts
|
|
1337
|
-
var VERSION = true ? "7.0.
|
|
1337
|
+
var VERSION = true ? "7.0.112" : "0.0.0-test";
|
|
1338
1338
|
|
|
1339
1339
|
// src/util/download/download.ts
|
|
1340
1340
|
var download = async ({
|
|
@@ -1463,6 +1463,13 @@ function convertUrlToFilePartData(url) {
|
|
|
1463
1463
|
}
|
|
1464
1464
|
return { data: { type: "url", url }, mediaType: void 0 };
|
|
1465
1465
|
}
|
|
1466
|
+
function convertUrlStringToFilePartData(content) {
|
|
1467
|
+
const result = convertUrlToFilePartData(new URL(content));
|
|
1468
|
+
if (result.data.type === "url" && result.data.url.toString() !== content) {
|
|
1469
|
+
result.data.originalUrl = content;
|
|
1470
|
+
}
|
|
1471
|
+
return result;
|
|
1472
|
+
}
|
|
1466
1473
|
function convertInlineDataToFilePartData(content) {
|
|
1467
1474
|
if (content instanceof Uint8Array) {
|
|
1468
1475
|
return { data: { type: "data", data: content }, mediaType: void 0 };
|
|
@@ -1514,7 +1521,7 @@ function convertToLanguageModelV4FilePart(content) {
|
|
|
1514
1521
|
}
|
|
1515
1522
|
if (typeof content === "string") {
|
|
1516
1523
|
try {
|
|
1517
|
-
return
|
|
1524
|
+
return convertUrlStringToFilePartData(content);
|
|
1518
1525
|
} catch (e) {
|
|
1519
1526
|
return convertInlineDataToFilePartData(content);
|
|
1520
1527
|
}
|
|
@@ -1995,6 +2002,7 @@ function mapToolResultOutput({
|
|
|
1995
2002
|
}
|
|
1996
2003
|
case "file-url": {
|
|
1997
2004
|
const mediaType = (_a25 = item.mediaType) != null ? _a25 : getMediaTypeFromUrl(item.url);
|
|
2005
|
+
const url = new URL(item.url);
|
|
1998
2006
|
let message = `The "file-url" type for tool result content is deprecated. Use the "file" type with mediaType and { type: 'url', url } instead.`;
|
|
1999
2007
|
if (!item.mediaType) {
|
|
2000
2008
|
const inferenceSuffix = mediaType === "application/octet-stream" ? `Unable to infer media type from URL. Defaulting to 'application/octet-stream'.` : `Inferred media type '${mediaType}' from URL.`;
|
|
@@ -2007,7 +2015,11 @@ function mapToolResultOutput({
|
|
|
2007
2015
|
});
|
|
2008
2016
|
return {
|
|
2009
2017
|
type: "file",
|
|
2010
|
-
data: {
|
|
2018
|
+
data: {
|
|
2019
|
+
type: "url",
|
|
2020
|
+
url,
|
|
2021
|
+
...url.toString() !== item.url ? { originalUrl: item.url } : {}
|
|
2022
|
+
},
|
|
2011
2023
|
mediaType,
|
|
2012
2024
|
providerOptions: item.providerOptions
|
|
2013
2025
|
};
|
|
@@ -2063,6 +2075,7 @@ function mapToolResultOutput({
|
|
|
2063
2075
|
};
|
|
2064
2076
|
}
|
|
2065
2077
|
case "image-url": {
|
|
2078
|
+
const url = new URL(item.url);
|
|
2066
2079
|
warnings.push({
|
|
2067
2080
|
type: "deprecated",
|
|
2068
2081
|
setting: '"tool-result" content of type "image-url"',
|
|
@@ -2070,7 +2083,11 @@ function mapToolResultOutput({
|
|
|
2070
2083
|
});
|
|
2071
2084
|
return {
|
|
2072
2085
|
type: "file",
|
|
2073
|
-
data: {
|
|
2086
|
+
data: {
|
|
2087
|
+
type: "url",
|
|
2088
|
+
url,
|
|
2089
|
+
...url.toString() !== item.url ? { originalUrl: item.url } : {}
|
|
2090
|
+
},
|
|
2074
2091
|
mediaType: "image",
|
|
2075
2092
|
providerOptions: item.providerOptions
|
|
2076
2093
|
};
|
|
@@ -3169,14 +3186,37 @@ var DefaultGeneratedFileWithType = class extends DefaultGeneratedFile {
|
|
|
3169
3186
|
}
|
|
3170
3187
|
};
|
|
3171
3188
|
|
|
3189
|
+
// src/generate-text/resolve-generated-file-data.ts
|
|
3190
|
+
async function resolveGeneratedFileData({
|
|
3191
|
+
data,
|
|
3192
|
+
abortSignal,
|
|
3193
|
+
cache
|
|
3194
|
+
}) {
|
|
3195
|
+
if (data.type === "data") {
|
|
3196
|
+
return data.data;
|
|
3197
|
+
}
|
|
3198
|
+
const cachedData = cache == null ? void 0 : cache.get(data);
|
|
3199
|
+
if (cachedData != null) {
|
|
3200
|
+
return cachedData;
|
|
3201
|
+
}
|
|
3202
|
+
const downloadedData = (await download({
|
|
3203
|
+
url: data.url,
|
|
3204
|
+
abortSignal
|
|
3205
|
+
})).data;
|
|
3206
|
+
cache == null ? void 0 : cache.set(data, downloadedData);
|
|
3207
|
+
return downloadedData;
|
|
3208
|
+
}
|
|
3209
|
+
|
|
3172
3210
|
// src/generate-text/convert-language-model-content.ts
|
|
3173
|
-
function convertLanguageModelContent({
|
|
3211
|
+
async function convertLanguageModelContent({
|
|
3174
3212
|
content,
|
|
3175
3213
|
toolCalls,
|
|
3176
3214
|
toolOutputs,
|
|
3177
3215
|
toolApprovalRequests,
|
|
3178
3216
|
toolApprovalResponses,
|
|
3179
|
-
tools
|
|
3217
|
+
tools,
|
|
3218
|
+
abortSignal,
|
|
3219
|
+
generatedFileDataCache
|
|
3180
3220
|
}) {
|
|
3181
3221
|
const contentParts = [];
|
|
3182
3222
|
const toolOutputsWithApprovalResponses = [];
|
|
@@ -3199,7 +3239,11 @@ function convertLanguageModelContent({
|
|
|
3199
3239
|
contentParts.push({
|
|
3200
3240
|
type: part.type,
|
|
3201
3241
|
file: new DefaultGeneratedFile({
|
|
3202
|
-
data:
|
|
3242
|
+
data: await resolveGeneratedFileData({
|
|
3243
|
+
data: part.data,
|
|
3244
|
+
abortSignal,
|
|
3245
|
+
cache: generatedFileDataCache
|
|
3246
|
+
}),
|
|
3203
3247
|
mediaType: part.mediaType
|
|
3204
3248
|
}),
|
|
3205
3249
|
...part.providerMetadata != null ? { providerMetadata: part.providerMetadata } : {}
|
|
@@ -5129,6 +5173,18 @@ function createTelemetryDispatcher({
|
|
|
5129
5173
|
onEmbedEnd: mergeTelemetryCallback("onEmbedEnd"),
|
|
5130
5174
|
onRerankStart: mergeTelemetryCallback("onRerankStart"),
|
|
5131
5175
|
onRerankEnd: mergeTelemetryCallback("onRerankEnd"),
|
|
5176
|
+
experimental_onEvaluateStart: mergeTelemetryCallback(
|
|
5177
|
+
"experimental_onEvaluateStart"
|
|
5178
|
+
),
|
|
5179
|
+
experimental_onEvaluationModelCallStart: mergeTelemetryCallback(
|
|
5180
|
+
"experimental_onEvaluationModelCallStart"
|
|
5181
|
+
),
|
|
5182
|
+
experimental_onEvaluationModelCallEnd: mergeTelemetryCallback(
|
|
5183
|
+
"experimental_onEvaluationModelCallEnd"
|
|
5184
|
+
),
|
|
5185
|
+
experimental_onEvaluateEnd: mergeTelemetryCallback(
|
|
5186
|
+
"experimental_onEvaluateEnd"
|
|
5187
|
+
),
|
|
5132
5188
|
onEnd: mergeTelemetryCallback("onEnd"),
|
|
5133
5189
|
onAbort: mergeTelemetryCallback("onAbort"),
|
|
5134
5190
|
onError: mergeTelemetryCallback("onError"),
|
|
@@ -6364,13 +6420,16 @@ async function generateText({
|
|
|
6364
6420
|
const toolApprovalRequests = {};
|
|
6365
6421
|
const stepToolApprovalResponses = {};
|
|
6366
6422
|
const blockedToolCallIds = /* @__PURE__ */ new Set();
|
|
6367
|
-
const
|
|
6423
|
+
const generatedFileDataCache = /* @__PURE__ */ new WeakMap();
|
|
6424
|
+
const modelCallContent = await convertLanguageModelContent({
|
|
6368
6425
|
content: currentModelResponse.content,
|
|
6369
6426
|
toolCalls: stepToolCalls,
|
|
6370
6427
|
toolOutputs: [],
|
|
6371
6428
|
toolApprovalRequests: [],
|
|
6372
6429
|
toolApprovalResponses: [],
|
|
6373
|
-
tools
|
|
6430
|
+
tools,
|
|
6431
|
+
abortSignal: mergedAbortSignal,
|
|
6432
|
+
generatedFileDataCache
|
|
6374
6433
|
});
|
|
6375
6434
|
await notify({
|
|
6376
6435
|
event: {
|
|
@@ -6618,13 +6677,15 @@ async function generateText({
|
|
|
6618
6677
|
pendingDeferredToolCalls.delete(part.toolCallId);
|
|
6619
6678
|
}
|
|
6620
6679
|
}
|
|
6621
|
-
const stepContent = convertLanguageModelContent({
|
|
6680
|
+
const stepContent = await convertLanguageModelContent({
|
|
6622
6681
|
content: currentModelResponse.content,
|
|
6623
6682
|
toolCalls: stepToolCalls,
|
|
6624
6683
|
toolOutputs: clientToolOutputs,
|
|
6625
6684
|
toolApprovalRequests: Object.values(toolApprovalRequests),
|
|
6626
6685
|
toolApprovalResponses,
|
|
6627
|
-
tools
|
|
6686
|
+
tools,
|
|
6687
|
+
abortSignal: mergedAbortSignal,
|
|
6688
|
+
generatedFileDataCache
|
|
6628
6689
|
});
|
|
6629
6690
|
const stepResponseMessages = await toResponseMessages({
|
|
6630
6691
|
content: stepContent,
|
|
@@ -8111,7 +8172,7 @@ function handleUIMessageStreamFinish({
|
|
|
8111
8172
|
}
|
|
8112
8173
|
};
|
|
8113
8174
|
let finishCalled = false;
|
|
8114
|
-
const callOnEnd = async () => {
|
|
8175
|
+
const callOnEnd = async ({ isCancelled }) => {
|
|
8115
8176
|
var _a25;
|
|
8116
8177
|
if (finishCalled || !resolvedOnEnd) {
|
|
8117
8178
|
return;
|
|
@@ -8120,8 +8181,10 @@ function handleUIMessageStreamFinish({
|
|
|
8120
8181
|
const isContinuation = state.message.id === (lastMessage == null ? void 0 : lastMessage.id);
|
|
8121
8182
|
const declaredOutcome = (_a25 = getOutcome == null ? void 0 : getOutcome()) != null ? _a25 : { status: "unknown" };
|
|
8122
8183
|
const outcome = hasProcessingFailure ? { status: "failed", error: processingError } : declaredOutcome.status === "unknown" && isAborted ? { status: "aborted" } : declaredOutcome;
|
|
8184
|
+
const isConsumerCancellation = isCancelled && outcome.status === "unknown";
|
|
8123
8185
|
await resolvedOnEnd({
|
|
8124
8186
|
isAborted: isAborted || outcome.status === "aborted",
|
|
8187
|
+
...isConsumerCancellation ? { isCancelled: true } : {},
|
|
8125
8188
|
isContinuation,
|
|
8126
8189
|
outcome,
|
|
8127
8190
|
responseMessage: state.message,
|
|
@@ -8164,10 +8227,10 @@ function handleUIMessageStreamFinish({
|
|
|
8164
8227
|
},
|
|
8165
8228
|
// @ts-expect-error cancel is still new and missing from types https://developer.mozilla.org/en-US/docs/Web/API/TransformStream#browser_compatibility
|
|
8166
8229
|
async cancel() {
|
|
8167
|
-
await callOnEnd();
|
|
8230
|
+
await callOnEnd({ isCancelled: true });
|
|
8168
8231
|
},
|
|
8169
8232
|
async flush() {
|
|
8170
|
-
await callOnEnd();
|
|
8233
|
+
await callOnEnd({ isCancelled: false });
|
|
8171
8234
|
}
|
|
8172
8235
|
})
|
|
8173
8236
|
);
|
|
@@ -9408,7 +9471,10 @@ function createLanguageModelV4StreamPartToLanguageModelStreamPartTransform({
|
|
|
9408
9471
|
case "file":
|
|
9409
9472
|
case "reasoning-file": {
|
|
9410
9473
|
const file = new DefaultGeneratedFileWithType({
|
|
9411
|
-
data:
|
|
9474
|
+
data: await resolveGeneratedFileData({
|
|
9475
|
+
data: chunk.data,
|
|
9476
|
+
abortSignal
|
|
9477
|
+
}),
|
|
9412
9478
|
mediaType: chunk.mediaType
|
|
9413
9479
|
});
|
|
9414
9480
|
modelCallContent.push({
|
|
@@ -12842,7 +12908,7 @@ async function safeValidateUIMessagesInternal({
|
|
|
12842
12908
|
warnIfUIMessageHasDeprecatedRawInput(validatedMessages);
|
|
12843
12909
|
if (metadataSchema) {
|
|
12844
12910
|
for (const [msgIdx, message] of validatedMessages.entries()) {
|
|
12845
|
-
await validateTypes4({
|
|
12911
|
+
message.metadata = await validateTypes4({
|
|
12846
12912
|
value: message.metadata,
|
|
12847
12913
|
schema: metadataSchema,
|
|
12848
12914
|
context: {
|
|
@@ -12874,7 +12940,7 @@ async function safeValidateUIMessagesInternal({
|
|
|
12874
12940
|
})
|
|
12875
12941
|
};
|
|
12876
12942
|
}
|
|
12877
|
-
await validateTypes4({
|
|
12943
|
+
dataPart.data = await validateTypes4({
|
|
12878
12944
|
value: dataPart.data,
|
|
12879
12945
|
schema: dataSchema,
|
|
12880
12946
|
context: {
|
|
@@ -13702,7 +13768,13 @@ function getBatchResults({
|
|
|
13702
13768
|
});
|
|
13703
13769
|
const transformer = {
|
|
13704
13770
|
async transform(item, controller) {
|
|
13705
|
-
controller.enqueue(
|
|
13771
|
+
controller.enqueue(
|
|
13772
|
+
await convertBatchItemResult({
|
|
13773
|
+
item,
|
|
13774
|
+
tools,
|
|
13775
|
+
abortSignal: operationAbortSignal
|
|
13776
|
+
})
|
|
13777
|
+
);
|
|
13706
13778
|
},
|
|
13707
13779
|
cancel(reason) {
|
|
13708
13780
|
streamAbortController.abort(
|
|
@@ -13800,7 +13872,8 @@ function validateBatchReference({
|
|
|
13800
13872
|
}
|
|
13801
13873
|
async function convertBatchItemResult({
|
|
13802
13874
|
item,
|
|
13803
|
-
tools
|
|
13875
|
+
tools,
|
|
13876
|
+
abortSignal
|
|
13804
13877
|
}) {
|
|
13805
13878
|
switch (item.type) {
|
|
13806
13879
|
case "text":
|
|
@@ -13810,7 +13883,11 @@ async function convertBatchItemResult({
|
|
|
13810
13883
|
type: item.type,
|
|
13811
13884
|
id: item.id,
|
|
13812
13885
|
status: item.status,
|
|
13813
|
-
...await convertGenerateResult({
|
|
13886
|
+
...await convertGenerateResult({
|
|
13887
|
+
result: item.result,
|
|
13888
|
+
tools,
|
|
13889
|
+
abortSignal
|
|
13890
|
+
})
|
|
13814
13891
|
};
|
|
13815
13892
|
case "failed":
|
|
13816
13893
|
return {
|
|
@@ -13886,7 +13963,8 @@ function convertImageResult(result) {
|
|
|
13886
13963
|
}
|
|
13887
13964
|
async function convertGenerateResult({
|
|
13888
13965
|
result,
|
|
13889
|
-
tools
|
|
13966
|
+
tools,
|
|
13967
|
+
abortSignal
|
|
13890
13968
|
}) {
|
|
13891
13969
|
var _a25;
|
|
13892
13970
|
const toolCalls = await Promise.all(
|
|
@@ -13903,13 +13981,14 @@ async function convertGenerateResult({
|
|
|
13903
13981
|
})
|
|
13904
13982
|
)
|
|
13905
13983
|
);
|
|
13906
|
-
const content = convertLanguageModelContent({
|
|
13984
|
+
const content = await convertLanguageModelContent({
|
|
13907
13985
|
content: result.content,
|
|
13908
13986
|
toolCalls,
|
|
13909
13987
|
toolOutputs: [],
|
|
13910
13988
|
toolApprovalRequests: [],
|
|
13911
13989
|
toolApprovalResponses: [],
|
|
13912
|
-
tools
|
|
13990
|
+
tools,
|
|
13991
|
+
abortSignal
|
|
13913
13992
|
});
|
|
13914
13993
|
return {
|
|
13915
13994
|
content,
|
|
@@ -14478,9 +14557,40 @@ import {
|
|
|
14478
14557
|
Experimental_EvaluationUnsupportedQuestionTypeError as EvaluationUnsupportedQuestionTypeError
|
|
14479
14558
|
} from "@ai-sdk/provider";
|
|
14480
14559
|
import {
|
|
14560
|
+
createIdGenerator as createIdGenerator6,
|
|
14481
14561
|
withUserAgentSuffix as withUserAgentSuffix8
|
|
14482
14562
|
} from "@ai-sdk/provider-utils";
|
|
14483
14563
|
|
|
14564
|
+
// src/evaluate/restricted-telemetry-dispatcher.ts
|
|
14565
|
+
function createRestrictedTelemetryDispatcher3({
|
|
14566
|
+
telemetry
|
|
14567
|
+
}) {
|
|
14568
|
+
const dispatcher = createTelemetryDispatcher({ telemetry });
|
|
14569
|
+
return {
|
|
14570
|
+
...dispatcher,
|
|
14571
|
+
onStart: (event) => {
|
|
14572
|
+
var _a25;
|
|
14573
|
+
return (_a25 = dispatcher.experimental_onEvaluateStart) == null ? void 0 : _a25.call(dispatcher, {
|
|
14574
|
+
...event,
|
|
14575
|
+
runtimeContext: filterIncludedContext({
|
|
14576
|
+
context: event.runtimeContext,
|
|
14577
|
+
includeContext: telemetry == null ? void 0 : telemetry.includeRuntimeContext
|
|
14578
|
+
})
|
|
14579
|
+
});
|
|
14580
|
+
},
|
|
14581
|
+
onEnd: (event) => {
|
|
14582
|
+
var _a25;
|
|
14583
|
+
return (_a25 = dispatcher.experimental_onEvaluateEnd) == null ? void 0 : _a25.call(dispatcher, {
|
|
14584
|
+
...event,
|
|
14585
|
+
runtimeContext: filterIncludedContext({
|
|
14586
|
+
context: event.runtimeContext,
|
|
14587
|
+
includeContext: telemetry == null ? void 0 : telemetry.includeRuntimeContext
|
|
14588
|
+
})
|
|
14589
|
+
});
|
|
14590
|
+
}
|
|
14591
|
+
};
|
|
14592
|
+
}
|
|
14593
|
+
|
|
14484
14594
|
// src/evaluate/validate-evaluation.ts
|
|
14485
14595
|
import {
|
|
14486
14596
|
InvalidResponseDataError as InvalidResponseDataError3
|
|
@@ -14711,6 +14821,10 @@ function validateEvaluationAnswers({
|
|
|
14711
14821
|
}
|
|
14712
14822
|
|
|
14713
14823
|
// src/evaluate/evaluate.ts
|
|
14824
|
+
var originalGenerateCallId6 = createIdGenerator6({
|
|
14825
|
+
prefix: "call",
|
|
14826
|
+
size: 24
|
|
14827
|
+
});
|
|
14714
14828
|
async function evaluate({
|
|
14715
14829
|
model: modelArg,
|
|
14716
14830
|
state,
|
|
@@ -14718,9 +14832,14 @@ async function evaluate({
|
|
|
14718
14832
|
maxRetries,
|
|
14719
14833
|
abortSignal,
|
|
14720
14834
|
headers,
|
|
14721
|
-
providerOptions = {}
|
|
14835
|
+
providerOptions = {},
|
|
14836
|
+
telemetry,
|
|
14837
|
+
runtimeContext = {},
|
|
14838
|
+
onStart,
|
|
14839
|
+
onEnd,
|
|
14840
|
+
_internal: { generateCallId = originalGenerateCallId6 } = {}
|
|
14722
14841
|
}) {
|
|
14723
|
-
var _a25
|
|
14842
|
+
var _a25;
|
|
14724
14843
|
const model = resolveEvaluationModel(modelArg);
|
|
14725
14844
|
validateEvaluationInput({ state, questions });
|
|
14726
14845
|
for (const [questionId, question] of Object.entries(questions)) {
|
|
@@ -14733,51 +14852,119 @@ async function evaluate({
|
|
|
14733
14852
|
});
|
|
14734
14853
|
}
|
|
14735
14854
|
}
|
|
14736
|
-
const
|
|
14737
|
-
const
|
|
14738
|
-
|
|
14739
|
-
|
|
14740
|
-
state,
|
|
14741
|
-
questions,
|
|
14742
|
-
abortSignal,
|
|
14743
|
-
headers: withUserAgentSuffix8(headers != null ? headers : {}, `ai/${VERSION}`),
|
|
14744
|
-
providerOptions
|
|
14745
|
-
});
|
|
14855
|
+
const callId = generateCallId();
|
|
14856
|
+
const { maxRetries: resolvedMaxRetries, retry } = prepareRetries({
|
|
14857
|
+
maxRetries,
|
|
14858
|
+
abortSignal
|
|
14746
14859
|
});
|
|
14747
|
-
|
|
14748
|
-
|
|
14749
|
-
questions,
|
|
14750
|
-
answers: result.answers,
|
|
14751
|
-
rounding: result.rounding
|
|
14860
|
+
const telemetryDispatcher = createRestrictedTelemetryDispatcher3({
|
|
14861
|
+
telemetry
|
|
14752
14862
|
});
|
|
14753
|
-
|
|
14754
|
-
|
|
14863
|
+
const runInTracingChannelSpan = (_a25 = telemetryDispatcher.runInTracingChannelSpan) != null ? _a25 : (async ({ execute }) => await execute());
|
|
14864
|
+
const startEvent = {
|
|
14865
|
+
callId,
|
|
14866
|
+
operationId: "ai.evaluate",
|
|
14867
|
+
runtimeContext,
|
|
14755
14868
|
provider: model.provider,
|
|
14756
|
-
|
|
14757
|
-
|
|
14758
|
-
|
|
14759
|
-
|
|
14760
|
-
|
|
14761
|
-
|
|
14762
|
-
usage: {
|
|
14763
|
-
inputTokens,
|
|
14764
|
-
outputTokens,
|
|
14765
|
-
totalTokens: inputTokens != null && outputTokens != null ? inputTokens + outputTokens : void 0
|
|
14766
|
-
},
|
|
14767
|
-
warnings: result.warnings,
|
|
14768
|
-
rounding: result.rounding,
|
|
14769
|
-
providerMetadata: result.providerMetadata,
|
|
14770
|
-
response: {
|
|
14771
|
-
...result.response,
|
|
14772
|
-
timestamp: (_d = (_c = result.response) == null ? void 0 : _c.timestamp) != null ? _d : /* @__PURE__ */ new Date(),
|
|
14773
|
-
modelId: (_f = (_e = result.response) == null ? void 0 : _e.modelId) != null ? _f : model.modelId
|
|
14774
|
-
}
|
|
14869
|
+
modelId: model.modelId,
|
|
14870
|
+
state,
|
|
14871
|
+
questions,
|
|
14872
|
+
maxRetries: resolvedMaxRetries,
|
|
14873
|
+
headers,
|
|
14874
|
+
providerOptions
|
|
14775
14875
|
};
|
|
14876
|
+
const tracingStartEvent = {
|
|
14877
|
+
...startEvent,
|
|
14878
|
+
runtimeContext: filterIncludedContext({
|
|
14879
|
+
context: runtimeContext,
|
|
14880
|
+
includeContext: telemetry == null ? void 0 : telemetry.includeRuntimeContext
|
|
14881
|
+
})
|
|
14882
|
+
};
|
|
14883
|
+
return await runInTracingChannelSpan({
|
|
14884
|
+
type: "experimental_evaluate",
|
|
14885
|
+
event: tracingStartEvent,
|
|
14886
|
+
execute: async () => {
|
|
14887
|
+
var _a26, _b25, _c, _d, _e, _f, _g;
|
|
14888
|
+
await notify({
|
|
14889
|
+
event: startEvent,
|
|
14890
|
+
callbacks: [onStart, telemetryDispatcher.onStart]
|
|
14891
|
+
});
|
|
14892
|
+
try {
|
|
14893
|
+
const modelCallEvent = {
|
|
14894
|
+
callId,
|
|
14895
|
+
operationId: "ai.evaluate.doEvaluate",
|
|
14896
|
+
provider: model.provider,
|
|
14897
|
+
modelId: model.modelId,
|
|
14898
|
+
state,
|
|
14899
|
+
questions
|
|
14900
|
+
};
|
|
14901
|
+
await notify({
|
|
14902
|
+
event: modelCallEvent,
|
|
14903
|
+
callbacks: [
|
|
14904
|
+
telemetryDispatcher.experimental_onEvaluationModelCallStart
|
|
14905
|
+
]
|
|
14906
|
+
});
|
|
14907
|
+
const result = await retry(async () => {
|
|
14908
|
+
abortSignal == null ? void 0 : abortSignal.throwIfAborted();
|
|
14909
|
+
return await model.doEvaluate({
|
|
14910
|
+
state,
|
|
14911
|
+
questions,
|
|
14912
|
+
abortSignal,
|
|
14913
|
+
headers: withUserAgentSuffix8(headers != null ? headers : {}, `ai/${VERSION}`),
|
|
14914
|
+
providerOptions
|
|
14915
|
+
});
|
|
14916
|
+
});
|
|
14917
|
+
abortSignal == null ? void 0 : abortSignal.throwIfAborted();
|
|
14918
|
+
validateEvaluationAnswers({
|
|
14919
|
+
questions,
|
|
14920
|
+
answers: result.answers,
|
|
14921
|
+
rounding: result.rounding
|
|
14922
|
+
});
|
|
14923
|
+
await notify({
|
|
14924
|
+
event: { ...modelCallEvent, ...result },
|
|
14925
|
+
callbacks: [
|
|
14926
|
+
telemetryDispatcher.experimental_onEvaluationModelCallEnd
|
|
14927
|
+
]
|
|
14928
|
+
});
|
|
14929
|
+
logWarnings({
|
|
14930
|
+
warnings: result.warnings,
|
|
14931
|
+
provider: model.provider,
|
|
14932
|
+
model: model.modelId
|
|
14933
|
+
});
|
|
14934
|
+
const inputTokens = (_a26 = result.usage) == null ? void 0 : _a26.inputTokens;
|
|
14935
|
+
const outputTokens = (_b25 = result.usage) == null ? void 0 : _b25.outputTokens;
|
|
14936
|
+
const evaluationResult = {
|
|
14937
|
+
answers: result.answers,
|
|
14938
|
+
usage: {
|
|
14939
|
+
inputTokens,
|
|
14940
|
+
outputTokens,
|
|
14941
|
+
totalTokens: inputTokens != null && outputTokens != null ? inputTokens + outputTokens : void 0
|
|
14942
|
+
},
|
|
14943
|
+
warnings: result.warnings,
|
|
14944
|
+
rounding: result.rounding,
|
|
14945
|
+
providerMetadata: result.providerMetadata,
|
|
14946
|
+
response: {
|
|
14947
|
+
...result.response,
|
|
14948
|
+
timestamp: (_d = (_c = result.response) == null ? void 0 : _c.timestamp) != null ? _d : /* @__PURE__ */ new Date(),
|
|
14949
|
+
modelId: (_f = (_e = result.response) == null ? void 0 : _e.modelId) != null ? _f : model.modelId
|
|
14950
|
+
}
|
|
14951
|
+
};
|
|
14952
|
+
await notify({
|
|
14953
|
+
event: { ...startEvent, ...evaluationResult },
|
|
14954
|
+
callbacks: [onEnd, telemetryDispatcher.onEnd]
|
|
14955
|
+
});
|
|
14956
|
+
return evaluationResult;
|
|
14957
|
+
} catch (error) {
|
|
14958
|
+
await ((_g = telemetryDispatcher.onError) == null ? void 0 : _g.call(telemetryDispatcher, { callId, error }));
|
|
14959
|
+
throw error;
|
|
14960
|
+
}
|
|
14961
|
+
}
|
|
14962
|
+
});
|
|
14776
14963
|
}
|
|
14777
14964
|
|
|
14778
14965
|
// src/generate-object/generate-object.ts
|
|
14779
14966
|
import {
|
|
14780
|
-
createIdGenerator as
|
|
14967
|
+
createIdGenerator as createIdGenerator7,
|
|
14781
14968
|
withUserAgentSuffix as withUserAgentSuffix9
|
|
14782
14969
|
} from "@ai-sdk/provider-utils";
|
|
14783
14970
|
|
|
@@ -15253,7 +15440,7 @@ function validateObjectGenerationInput({
|
|
|
15253
15440
|
}
|
|
15254
15441
|
|
|
15255
15442
|
// src/generate-object/generate-object.ts
|
|
15256
|
-
var originalGenerateId4 =
|
|
15443
|
+
var originalGenerateId4 = createIdGenerator7({ prefix: "aiobj", size: 24 });
|
|
15257
15444
|
async function generateObject(options) {
|
|
15258
15445
|
var _a25, _b25, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
15259
15446
|
const {
|
|
@@ -15501,7 +15688,7 @@ var DefaultGenerateObjectResult = class {
|
|
|
15501
15688
|
|
|
15502
15689
|
// src/generate-object/stream-object.ts
|
|
15503
15690
|
import {
|
|
15504
|
-
createIdGenerator as
|
|
15691
|
+
createIdGenerator as createIdGenerator8,
|
|
15505
15692
|
DelayedPromise as DelayedPromise2
|
|
15506
15693
|
} from "@ai-sdk/provider-utils";
|
|
15507
15694
|
|
|
@@ -15626,7 +15813,7 @@ function simulateReadableStream({
|
|
|
15626
15813
|
}
|
|
15627
15814
|
|
|
15628
15815
|
// src/generate-object/stream-object.ts
|
|
15629
|
-
var originalGenerateId5 =
|
|
15816
|
+
var originalGenerateId5 = createIdGenerator8({ prefix: "aiobj", size: 24 });
|
|
15630
15817
|
async function markPromiseAsHandled2(promise) {
|
|
15631
15818
|
try {
|
|
15632
15819
|
await promise;
|
|
@@ -16325,7 +16512,9 @@ function pruneMessages({
|
|
|
16325
16512
|
}
|
|
16326
16513
|
return {
|
|
16327
16514
|
...message,
|
|
16328
|
-
content: message.content.filter(
|
|
16515
|
+
content: message.content.filter(
|
|
16516
|
+
(part) => part.type !== "reasoning" && part.type !== "reasoning-file"
|
|
16517
|
+
)
|
|
16329
16518
|
};
|
|
16330
16519
|
});
|
|
16331
16520
|
}
|
|
@@ -20852,11 +21041,11 @@ import {
|
|
|
20852
21041
|
InvalidResponseDataError as InvalidResponseDataError4
|
|
20853
21042
|
} from "@ai-sdk/provider";
|
|
20854
21043
|
import {
|
|
20855
|
-
createIdGenerator as
|
|
21044
|
+
createIdGenerator as createIdGenerator9
|
|
20856
21045
|
} from "@ai-sdk/provider-utils";
|
|
20857
21046
|
|
|
20858
21047
|
// src/rerank/restricted-telemetry-dispatcher.ts
|
|
20859
|
-
function
|
|
21048
|
+
function createRestrictedTelemetryDispatcher4({
|
|
20860
21049
|
telemetry
|
|
20861
21050
|
}) {
|
|
20862
21051
|
const dispatcher = createTelemetryDispatcher({ telemetry });
|
|
@@ -20886,7 +21075,7 @@ function createRestrictedTelemetryDispatcher3({
|
|
|
20886
21075
|
}
|
|
20887
21076
|
|
|
20888
21077
|
// src/rerank/rerank.ts
|
|
20889
|
-
var
|
|
21078
|
+
var originalGenerateCallId7 = createIdGenerator9({
|
|
20890
21079
|
prefix: "call",
|
|
20891
21080
|
size: 24
|
|
20892
21081
|
});
|
|
@@ -20906,14 +21095,14 @@ async function rerank({
|
|
|
20906
21095
|
experimental_onStart,
|
|
20907
21096
|
onEnd,
|
|
20908
21097
|
experimental_onEnd,
|
|
20909
|
-
_internal: { generateCallId =
|
|
21098
|
+
_internal: { generateCallId = originalGenerateCallId7 } = {}
|
|
20910
21099
|
}) {
|
|
20911
21100
|
var _a25;
|
|
20912
21101
|
const model = resolveRerankingModel(modelArg);
|
|
20913
21102
|
const callId = generateCallId();
|
|
20914
21103
|
const resolvedOnStart = onStart != null ? onStart : experimental_onStart;
|
|
20915
21104
|
const resolvedOnEnd = onEnd != null ? onEnd : experimental_onEnd;
|
|
20916
|
-
const telemetryDispatcher =
|
|
21105
|
+
const telemetryDispatcher = createRestrictedTelemetryDispatcher4({
|
|
20917
21106
|
telemetry
|
|
20918
21107
|
});
|
|
20919
21108
|
const runInTracingChannelSpan = (_a25 = telemetryDispatcher.runInTracingChannelSpan) != null ? _a25 : (async ({ execute }) => await execute());
|
|
@@ -22755,7 +22944,7 @@ export {
|
|
|
22755
22944
|
createAgentUIStreamResponse,
|
|
22756
22945
|
createDownload,
|
|
22757
22946
|
createGateway,
|
|
22758
|
-
|
|
22947
|
+
createIdGenerator10 as createIdGenerator,
|
|
22759
22948
|
createProviderRegistry,
|
|
22760
22949
|
createTextStreamResponse,
|
|
22761
22950
|
createUIMessageStream,
|