ai 6.0.0-beta.162 → 6.0.0-beta.164
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +19 -0
- package/dist/index.d.mts +49 -32
- package/dist/index.d.ts +49 -32
- package/dist/index.js +52 -17
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +52 -17
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +1 -1
- package/dist/internal/index.mjs +1 -1
- package/dist/test/index.d.mts +5 -5
- package/dist/test/index.d.ts +5 -5
- package/dist/test/index.js.map +1 -1
- package/dist/test/index.mjs.map +1 -1
- package/package.json +5 -5
package/dist/index.mjs
CHANGED
|
@@ -480,6 +480,7 @@ function asLanguageModelV3(model) {
|
|
|
480
480
|
const result = await target.doGenerate(...args);
|
|
481
481
|
return {
|
|
482
482
|
...result,
|
|
483
|
+
finishReason: convertV2FinishReasonToV3(result.finishReason),
|
|
483
484
|
usage: convertV2UsageToV3(result.usage)
|
|
484
485
|
};
|
|
485
486
|
};
|
|
@@ -505,6 +506,7 @@ function convertV2StreamToV3(stream) {
|
|
|
505
506
|
case "finish":
|
|
506
507
|
controller.enqueue({
|
|
507
508
|
...chunk,
|
|
509
|
+
finishReason: convertV2FinishReasonToV3(chunk.finishReason),
|
|
508
510
|
usage: convertV2UsageToV3(chunk.usage)
|
|
509
511
|
});
|
|
510
512
|
break;
|
|
@@ -516,6 +518,12 @@ function convertV2StreamToV3(stream) {
|
|
|
516
518
|
})
|
|
517
519
|
);
|
|
518
520
|
}
|
|
521
|
+
function convertV2FinishReasonToV3(finishReason) {
|
|
522
|
+
return {
|
|
523
|
+
unified: finishReason === "unknown" ? "other" : finishReason,
|
|
524
|
+
raw: void 0
|
|
525
|
+
};
|
|
526
|
+
}
|
|
519
527
|
function convertV2UsageToV3(usage) {
|
|
520
528
|
return {
|
|
521
529
|
inputTokens: {
|
|
@@ -844,7 +852,7 @@ import {
|
|
|
844
852
|
} from "@ai-sdk/provider-utils";
|
|
845
853
|
|
|
846
854
|
// src/version.ts
|
|
847
|
-
var VERSION = true ? "6.0.0-beta.
|
|
855
|
+
var VERSION = true ? "6.0.0-beta.164" : "0.0.0-test";
|
|
848
856
|
|
|
849
857
|
// src/util/download/download.ts
|
|
850
858
|
var download = async ({ url }) => {
|
|
@@ -3209,6 +3217,7 @@ var DefaultStepResult = class {
|
|
|
3209
3217
|
constructor({
|
|
3210
3218
|
content,
|
|
3211
3219
|
finishReason,
|
|
3220
|
+
rawFinishReason,
|
|
3212
3221
|
usage,
|
|
3213
3222
|
warnings,
|
|
3214
3223
|
request,
|
|
@@ -3217,6 +3226,7 @@ var DefaultStepResult = class {
|
|
|
3217
3226
|
}) {
|
|
3218
3227
|
this.content = content;
|
|
3219
3228
|
this.finishReason = finishReason;
|
|
3229
|
+
this.rawFinishReason = rawFinishReason;
|
|
3220
3230
|
this.usage = usage;
|
|
3221
3231
|
this.warnings = warnings;
|
|
3222
3232
|
this.request = request;
|
|
@@ -3634,7 +3644,7 @@ async function generateText({
|
|
|
3634
3644
|
await selectTelemetryAttributes({
|
|
3635
3645
|
telemetry,
|
|
3636
3646
|
attributes: {
|
|
3637
|
-
"ai.response.finishReason": result.finishReason,
|
|
3647
|
+
"ai.response.finishReason": result.finishReason.unified,
|
|
3638
3648
|
"ai.response.text": {
|
|
3639
3649
|
output: () => extractTextContent(result.content)
|
|
3640
3650
|
},
|
|
@@ -3654,7 +3664,9 @@ async function generateText({
|
|
|
3654
3664
|
"ai.usage.promptTokens": result.usage.inputTokens.total,
|
|
3655
3665
|
"ai.usage.completionTokens": result.usage.outputTokens.total,
|
|
3656
3666
|
// standardized gen-ai llm span attributes:
|
|
3657
|
-
"gen_ai.response.finish_reasons": [
|
|
3667
|
+
"gen_ai.response.finish_reasons": [
|
|
3668
|
+
result.finishReason.unified
|
|
3669
|
+
],
|
|
3658
3670
|
"gen_ai.response.id": responseData.id,
|
|
3659
3671
|
"gen_ai.response.model": responseData.modelId,
|
|
3660
3672
|
"gen_ai.usage.input_tokens": result.usage.inputTokens.total,
|
|
@@ -3778,7 +3790,8 @@ async function generateText({
|
|
|
3778
3790
|
);
|
|
3779
3791
|
const currentStepResult = new DefaultStepResult({
|
|
3780
3792
|
content: stepContent,
|
|
3781
|
-
finishReason: currentModelResponse.finishReason,
|
|
3793
|
+
finishReason: currentModelResponse.finishReason.unified,
|
|
3794
|
+
rawFinishReason: currentModelResponse.finishReason.raw,
|
|
3782
3795
|
usage: asLanguageModelUsage(currentModelResponse.usage),
|
|
3783
3796
|
warnings: currentModelResponse.warnings,
|
|
3784
3797
|
providerMetadata: currentModelResponse.providerMetadata,
|
|
@@ -3807,7 +3820,7 @@ async function generateText({
|
|
|
3807
3820
|
await selectTelemetryAttributes({
|
|
3808
3821
|
telemetry,
|
|
3809
3822
|
attributes: {
|
|
3810
|
-
"ai.response.finishReason": currentModelResponse.finishReason,
|
|
3823
|
+
"ai.response.finishReason": currentModelResponse.finishReason.unified,
|
|
3811
3824
|
"ai.response.text": {
|
|
3812
3825
|
output: () => extractTextContent(currentModelResponse.content)
|
|
3813
3826
|
},
|
|
@@ -3841,6 +3854,7 @@ async function generateText({
|
|
|
3841
3854
|
);
|
|
3842
3855
|
await (onFinish == null ? void 0 : onFinish({
|
|
3843
3856
|
finishReason: lastStep.finishReason,
|
|
3857
|
+
rawFinishReason: lastStep.rawFinishReason,
|
|
3844
3858
|
usage: lastStep.usage,
|
|
3845
3859
|
content: lastStep.content,
|
|
3846
3860
|
text: lastStep.text,
|
|
@@ -3959,6 +3973,9 @@ var DefaultGenerateTextResult = class {
|
|
|
3959
3973
|
get finishReason() {
|
|
3960
3974
|
return this.finalStep.finishReason;
|
|
3961
3975
|
}
|
|
3976
|
+
get rawFinishReason() {
|
|
3977
|
+
return this.finalStep.rawFinishReason;
|
|
3978
|
+
}
|
|
3962
3979
|
get warnings() {
|
|
3963
3980
|
return this.finalStep.warnings;
|
|
3964
3981
|
}
|
|
@@ -4388,8 +4405,7 @@ var uiMessageChunkSchema = lazySchema(
|
|
|
4388
4405
|
"content-filter",
|
|
4389
4406
|
"tool-calls",
|
|
4390
4407
|
"error",
|
|
4391
|
-
"other"
|
|
4392
|
-
"unknown"
|
|
4408
|
+
"other"
|
|
4393
4409
|
]).optional(),
|
|
4394
4410
|
messageMetadata: z7.unknown().optional()
|
|
4395
4411
|
}),
|
|
@@ -5265,7 +5281,8 @@ function runToolsTransformation({
|
|
|
5265
5281
|
case "finish": {
|
|
5266
5282
|
finishChunk = {
|
|
5267
5283
|
type: "finish",
|
|
5268
|
-
finishReason: chunk.finishReason,
|
|
5284
|
+
finishReason: chunk.finishReason.unified,
|
|
5285
|
+
rawFinishReason: chunk.finishReason.raw,
|
|
5269
5286
|
usage: asLanguageModelUsage(chunk.usage),
|
|
5270
5287
|
providerMetadata: chunk.providerMetadata
|
|
5271
5288
|
};
|
|
@@ -5578,6 +5595,7 @@ var DefaultStreamTextResult = class {
|
|
|
5578
5595
|
}) {
|
|
5579
5596
|
this._totalUsage = new DelayedPromise();
|
|
5580
5597
|
this._finishReason = new DelayedPromise();
|
|
5598
|
+
this._rawFinishReason = new DelayedPromise();
|
|
5581
5599
|
this._steps = new DelayedPromise();
|
|
5582
5600
|
this.outputSpecification = output;
|
|
5583
5601
|
this.includeRawChunks = includeRawChunks;
|
|
@@ -5586,6 +5604,7 @@ var DefaultStreamTextResult = class {
|
|
|
5586
5604
|
let recordedContent = [];
|
|
5587
5605
|
const recordedResponseMessages = [];
|
|
5588
5606
|
let recordedFinishReason = void 0;
|
|
5607
|
+
let recordedRawFinishReason = void 0;
|
|
5589
5608
|
let recordedTotalUsage = void 0;
|
|
5590
5609
|
let recordedRequest = {};
|
|
5591
5610
|
let recordedWarnings = [];
|
|
@@ -5714,6 +5733,7 @@ var DefaultStreamTextResult = class {
|
|
|
5714
5733
|
const currentStepResult = new DefaultStepResult({
|
|
5715
5734
|
content: recordedContent,
|
|
5716
5735
|
finishReason: part.finishReason,
|
|
5736
|
+
rawFinishReason: part.rawFinishReason,
|
|
5717
5737
|
usage: part.usage,
|
|
5718
5738
|
warnings: recordedWarnings,
|
|
5719
5739
|
request: recordedRequest,
|
|
@@ -5736,6 +5756,7 @@ var DefaultStreamTextResult = class {
|
|
|
5736
5756
|
if (part.type === "finish") {
|
|
5737
5757
|
recordedTotalUsage = part.totalUsage;
|
|
5738
5758
|
recordedFinishReason = part.finishReason;
|
|
5759
|
+
recordedRawFinishReason = part.rawFinishReason;
|
|
5739
5760
|
}
|
|
5740
5761
|
},
|
|
5741
5762
|
async flush(controller) {
|
|
@@ -5745,18 +5766,21 @@ var DefaultStreamTextResult = class {
|
|
|
5745
5766
|
message: "No output generated. Check the stream for errors."
|
|
5746
5767
|
});
|
|
5747
5768
|
self._finishReason.reject(error);
|
|
5769
|
+
self._rawFinishReason.reject(error);
|
|
5748
5770
|
self._totalUsage.reject(error);
|
|
5749
5771
|
self._steps.reject(error);
|
|
5750
5772
|
return;
|
|
5751
5773
|
}
|
|
5752
|
-
const finishReason = recordedFinishReason != null ? recordedFinishReason : "
|
|
5774
|
+
const finishReason = recordedFinishReason != null ? recordedFinishReason : "other";
|
|
5753
5775
|
const totalUsage = recordedTotalUsage != null ? recordedTotalUsage : createNullLanguageModelUsage();
|
|
5754
5776
|
self._finishReason.resolve(finishReason);
|
|
5777
|
+
self._rawFinishReason.resolve(recordedRawFinishReason);
|
|
5755
5778
|
self._totalUsage.resolve(totalUsage);
|
|
5756
5779
|
self._steps.resolve(recordedSteps);
|
|
5757
5780
|
const finalStep = recordedSteps[recordedSteps.length - 1];
|
|
5758
5781
|
await (onFinish == null ? void 0 : onFinish({
|
|
5759
|
-
finishReason,
|
|
5782
|
+
finishReason: finalStep.finishReason,
|
|
5783
|
+
rawFinishReason: finalStep.rawFinishReason,
|
|
5760
5784
|
totalUsage,
|
|
5761
5785
|
usage: finalStep.usage,
|
|
5762
5786
|
content: finalStep.content,
|
|
@@ -6081,7 +6105,8 @@ var DefaultStreamTextResult = class {
|
|
|
6081
6105
|
const stepToolOutputs = [];
|
|
6082
6106
|
let warnings;
|
|
6083
6107
|
const activeToolCallToolNames = {};
|
|
6084
|
-
let stepFinishReason = "
|
|
6108
|
+
let stepFinishReason = "other";
|
|
6109
|
+
let stepRawFinishReason = void 0;
|
|
6085
6110
|
let stepUsage = createNullLanguageModelUsage();
|
|
6086
6111
|
let stepProviderMetadata;
|
|
6087
6112
|
let stepFirstChunk = true;
|
|
@@ -6177,6 +6202,7 @@ var DefaultStreamTextResult = class {
|
|
|
6177
6202
|
case "finish": {
|
|
6178
6203
|
stepUsage = chunk.usage;
|
|
6179
6204
|
stepFinishReason = chunk.finishReason;
|
|
6205
|
+
stepRawFinishReason = chunk.rawFinishReason;
|
|
6180
6206
|
stepProviderMetadata = chunk.providerMetadata;
|
|
6181
6207
|
const msToFinish = now2() - startTimestampMs;
|
|
6182
6208
|
doStreamSpan.addEvent("ai.stream.finish");
|
|
@@ -6289,6 +6315,7 @@ var DefaultStreamTextResult = class {
|
|
|
6289
6315
|
controller.enqueue({
|
|
6290
6316
|
type: "finish-step",
|
|
6291
6317
|
finishReason: stepFinishReason,
|
|
6318
|
+
rawFinishReason: stepRawFinishReason,
|
|
6292
6319
|
usage: stepUsage,
|
|
6293
6320
|
providerMetadata: stepProviderMetadata,
|
|
6294
6321
|
response: {
|
|
@@ -6360,6 +6387,7 @@ var DefaultStreamTextResult = class {
|
|
|
6360
6387
|
controller.enqueue({
|
|
6361
6388
|
type: "finish",
|
|
6362
6389
|
finishReason: stepFinishReason,
|
|
6390
|
+
rawFinishReason: stepRawFinishReason,
|
|
6363
6391
|
totalUsage: combinedUsage
|
|
6364
6392
|
});
|
|
6365
6393
|
self.closeStream();
|
|
@@ -6453,6 +6481,10 @@ var DefaultStreamTextResult = class {
|
|
|
6453
6481
|
this.consumeStream();
|
|
6454
6482
|
return this._finishReason.promise;
|
|
6455
6483
|
}
|
|
6484
|
+
get rawFinishReason() {
|
|
6485
|
+
this.consumeStream();
|
|
6486
|
+
return this._rawFinishReason.promise;
|
|
6487
|
+
}
|
|
6456
6488
|
/**
|
|
6457
6489
|
Split out a new stream from the original stream.
|
|
6458
6490
|
The original stream is replaced to allow for further splitting,
|
|
@@ -8918,14 +8950,14 @@ async function generateObject(options) {
|
|
|
8918
8950
|
message: "No object generated: the model did not return a response.",
|
|
8919
8951
|
response: responseData,
|
|
8920
8952
|
usage: asLanguageModelUsage(result2.usage),
|
|
8921
|
-
finishReason: result2.finishReason
|
|
8953
|
+
finishReason: result2.finishReason.unified
|
|
8922
8954
|
});
|
|
8923
8955
|
}
|
|
8924
8956
|
span2.setAttributes(
|
|
8925
8957
|
await selectTelemetryAttributes({
|
|
8926
8958
|
telemetry,
|
|
8927
8959
|
attributes: {
|
|
8928
|
-
"ai.response.finishReason": result2.finishReason,
|
|
8960
|
+
"ai.response.finishReason": result2.finishReason.unified,
|
|
8929
8961
|
"ai.response.object": { output: () => text2 },
|
|
8930
8962
|
"ai.response.id": responseData.id,
|
|
8931
8963
|
"ai.response.model": responseData.modelId,
|
|
@@ -8937,7 +8969,9 @@ async function generateObject(options) {
|
|
|
8937
8969
|
"ai.usage.promptTokens": result2.usage.inputTokens.total,
|
|
8938
8970
|
"ai.usage.completionTokens": result2.usage.outputTokens.total,
|
|
8939
8971
|
// standardized gen-ai llm span attributes:
|
|
8940
|
-
"gen_ai.response.finish_reasons": [
|
|
8972
|
+
"gen_ai.response.finish_reasons": [
|
|
8973
|
+
result2.finishReason.unified
|
|
8974
|
+
],
|
|
8941
8975
|
"gen_ai.response.id": responseData.id,
|
|
8942
8976
|
"gen_ai.response.model": responseData.modelId,
|
|
8943
8977
|
"gen_ai.usage.input_tokens": result2.usage.inputTokens.total,
|
|
@@ -8955,7 +8989,7 @@ async function generateObject(options) {
|
|
|
8955
8989
|
})
|
|
8956
8990
|
);
|
|
8957
8991
|
result = generateResult.objectText;
|
|
8958
|
-
finishReason = generateResult.finishReason;
|
|
8992
|
+
finishReason = generateResult.finishReason.unified;
|
|
8959
8993
|
usage = asLanguageModelUsage(generateResult.usage);
|
|
8960
8994
|
warnings = generateResult.warnings;
|
|
8961
8995
|
resultProviderMetadata = generateResult.providerMetadata;
|
|
@@ -9472,11 +9506,12 @@ var DefaultStreamObjectResult = class {
|
|
|
9472
9506
|
if (textDelta !== "") {
|
|
9473
9507
|
controller.enqueue({ type: "text-delta", textDelta });
|
|
9474
9508
|
}
|
|
9475
|
-
finishReason = chunk.finishReason;
|
|
9509
|
+
finishReason = chunk.finishReason.unified;
|
|
9476
9510
|
usage = asLanguageModelUsage(chunk.usage);
|
|
9477
9511
|
providerMetadata = chunk.providerMetadata;
|
|
9478
9512
|
controller.enqueue({
|
|
9479
9513
|
...chunk,
|
|
9514
|
+
finishReason: chunk.finishReason.unified,
|
|
9480
9515
|
usage,
|
|
9481
9516
|
response: fullResponse
|
|
9482
9517
|
});
|
|
@@ -9492,7 +9527,7 @@ var DefaultStreamObjectResult = class {
|
|
|
9492
9527
|
...fullResponse,
|
|
9493
9528
|
headers: response == null ? void 0 : response.headers
|
|
9494
9529
|
});
|
|
9495
|
-
self._finishReason.resolve(finishReason != null ? finishReason : "
|
|
9530
|
+
self._finishReason.resolve(finishReason != null ? finishReason : "other");
|
|
9496
9531
|
try {
|
|
9497
9532
|
object2 = await parseAndValidateObjectResultWithRepair(
|
|
9498
9533
|
accumulatedText,
|