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.js
CHANGED
|
@@ -584,6 +584,7 @@ function asLanguageModelV3(model) {
|
|
|
584
584
|
const result = await target.doGenerate(...args);
|
|
585
585
|
return {
|
|
586
586
|
...result,
|
|
587
|
+
finishReason: convertV2FinishReasonToV3(result.finishReason),
|
|
587
588
|
usage: convertV2UsageToV3(result.usage)
|
|
588
589
|
};
|
|
589
590
|
};
|
|
@@ -609,6 +610,7 @@ function convertV2StreamToV3(stream) {
|
|
|
609
610
|
case "finish":
|
|
610
611
|
controller.enqueue({
|
|
611
612
|
...chunk,
|
|
613
|
+
finishReason: convertV2FinishReasonToV3(chunk.finishReason),
|
|
612
614
|
usage: convertV2UsageToV3(chunk.usage)
|
|
613
615
|
});
|
|
614
616
|
break;
|
|
@@ -620,6 +622,12 @@ function convertV2StreamToV3(stream) {
|
|
|
620
622
|
})
|
|
621
623
|
);
|
|
622
624
|
}
|
|
625
|
+
function convertV2FinishReasonToV3(finishReason) {
|
|
626
|
+
return {
|
|
627
|
+
unified: finishReason === "unknown" ? "other" : finishReason,
|
|
628
|
+
raw: void 0
|
|
629
|
+
};
|
|
630
|
+
}
|
|
623
631
|
function convertV2UsageToV3(usage) {
|
|
624
632
|
return {
|
|
625
633
|
inputTokens: {
|
|
@@ -943,7 +951,7 @@ var import_provider_utils3 = require("@ai-sdk/provider-utils");
|
|
|
943
951
|
var import_provider_utils4 = require("@ai-sdk/provider-utils");
|
|
944
952
|
|
|
945
953
|
// src/version.ts
|
|
946
|
-
var VERSION = true ? "6.0.0-beta.
|
|
954
|
+
var VERSION = true ? "6.0.0-beta.164" : "0.0.0-test";
|
|
947
955
|
|
|
948
956
|
// src/util/download/download.ts
|
|
949
957
|
var download = async ({ url }) => {
|
|
@@ -3289,6 +3297,7 @@ var DefaultStepResult = class {
|
|
|
3289
3297
|
constructor({
|
|
3290
3298
|
content,
|
|
3291
3299
|
finishReason,
|
|
3300
|
+
rawFinishReason,
|
|
3292
3301
|
usage,
|
|
3293
3302
|
warnings,
|
|
3294
3303
|
request,
|
|
@@ -3297,6 +3306,7 @@ var DefaultStepResult = class {
|
|
|
3297
3306
|
}) {
|
|
3298
3307
|
this.content = content;
|
|
3299
3308
|
this.finishReason = finishReason;
|
|
3309
|
+
this.rawFinishReason = rawFinishReason;
|
|
3300
3310
|
this.usage = usage;
|
|
3301
3311
|
this.warnings = warnings;
|
|
3302
3312
|
this.request = request;
|
|
@@ -3714,7 +3724,7 @@ async function generateText({
|
|
|
3714
3724
|
await selectTelemetryAttributes({
|
|
3715
3725
|
telemetry,
|
|
3716
3726
|
attributes: {
|
|
3717
|
-
"ai.response.finishReason": result.finishReason,
|
|
3727
|
+
"ai.response.finishReason": result.finishReason.unified,
|
|
3718
3728
|
"ai.response.text": {
|
|
3719
3729
|
output: () => extractTextContent(result.content)
|
|
3720
3730
|
},
|
|
@@ -3734,7 +3744,9 @@ async function generateText({
|
|
|
3734
3744
|
"ai.usage.promptTokens": result.usage.inputTokens.total,
|
|
3735
3745
|
"ai.usage.completionTokens": result.usage.outputTokens.total,
|
|
3736
3746
|
// standardized gen-ai llm span attributes:
|
|
3737
|
-
"gen_ai.response.finish_reasons": [
|
|
3747
|
+
"gen_ai.response.finish_reasons": [
|
|
3748
|
+
result.finishReason.unified
|
|
3749
|
+
],
|
|
3738
3750
|
"gen_ai.response.id": responseData.id,
|
|
3739
3751
|
"gen_ai.response.model": responseData.modelId,
|
|
3740
3752
|
"gen_ai.usage.input_tokens": result.usage.inputTokens.total,
|
|
@@ -3858,7 +3870,8 @@ async function generateText({
|
|
|
3858
3870
|
);
|
|
3859
3871
|
const currentStepResult = new DefaultStepResult({
|
|
3860
3872
|
content: stepContent,
|
|
3861
|
-
finishReason: currentModelResponse.finishReason,
|
|
3873
|
+
finishReason: currentModelResponse.finishReason.unified,
|
|
3874
|
+
rawFinishReason: currentModelResponse.finishReason.raw,
|
|
3862
3875
|
usage: asLanguageModelUsage(currentModelResponse.usage),
|
|
3863
3876
|
warnings: currentModelResponse.warnings,
|
|
3864
3877
|
providerMetadata: currentModelResponse.providerMetadata,
|
|
@@ -3887,7 +3900,7 @@ async function generateText({
|
|
|
3887
3900
|
await selectTelemetryAttributes({
|
|
3888
3901
|
telemetry,
|
|
3889
3902
|
attributes: {
|
|
3890
|
-
"ai.response.finishReason": currentModelResponse.finishReason,
|
|
3903
|
+
"ai.response.finishReason": currentModelResponse.finishReason.unified,
|
|
3891
3904
|
"ai.response.text": {
|
|
3892
3905
|
output: () => extractTextContent(currentModelResponse.content)
|
|
3893
3906
|
},
|
|
@@ -3921,6 +3934,7 @@ async function generateText({
|
|
|
3921
3934
|
);
|
|
3922
3935
|
await (onFinish == null ? void 0 : onFinish({
|
|
3923
3936
|
finishReason: lastStep.finishReason,
|
|
3937
|
+
rawFinishReason: lastStep.rawFinishReason,
|
|
3924
3938
|
usage: lastStep.usage,
|
|
3925
3939
|
content: lastStep.content,
|
|
3926
3940
|
text: lastStep.text,
|
|
@@ -4039,6 +4053,9 @@ var DefaultGenerateTextResult = class {
|
|
|
4039
4053
|
get finishReason() {
|
|
4040
4054
|
return this.finalStep.finishReason;
|
|
4041
4055
|
}
|
|
4056
|
+
get rawFinishReason() {
|
|
4057
|
+
return this.finalStep.rawFinishReason;
|
|
4058
|
+
}
|
|
4042
4059
|
get warnings() {
|
|
4043
4060
|
return this.finalStep.warnings;
|
|
4044
4061
|
}
|
|
@@ -4462,8 +4479,7 @@ var uiMessageChunkSchema = (0, import_provider_utils16.lazySchema)(
|
|
|
4462
4479
|
"content-filter",
|
|
4463
4480
|
"tool-calls",
|
|
4464
4481
|
"error",
|
|
4465
|
-
"other"
|
|
4466
|
-
"unknown"
|
|
4482
|
+
"other"
|
|
4467
4483
|
]).optional(),
|
|
4468
4484
|
messageMetadata: import_v47.z.unknown().optional()
|
|
4469
4485
|
}),
|
|
@@ -5337,7 +5353,8 @@ function runToolsTransformation({
|
|
|
5337
5353
|
case "finish": {
|
|
5338
5354
|
finishChunk = {
|
|
5339
5355
|
type: "finish",
|
|
5340
|
-
finishReason: chunk.finishReason,
|
|
5356
|
+
finishReason: chunk.finishReason.unified,
|
|
5357
|
+
rawFinishReason: chunk.finishReason.raw,
|
|
5341
5358
|
usage: asLanguageModelUsage(chunk.usage),
|
|
5342
5359
|
providerMetadata: chunk.providerMetadata
|
|
5343
5360
|
};
|
|
@@ -5650,6 +5667,7 @@ var DefaultStreamTextResult = class {
|
|
|
5650
5667
|
}) {
|
|
5651
5668
|
this._totalUsage = new import_provider_utils19.DelayedPromise();
|
|
5652
5669
|
this._finishReason = new import_provider_utils19.DelayedPromise();
|
|
5670
|
+
this._rawFinishReason = new import_provider_utils19.DelayedPromise();
|
|
5653
5671
|
this._steps = new import_provider_utils19.DelayedPromise();
|
|
5654
5672
|
this.outputSpecification = output;
|
|
5655
5673
|
this.includeRawChunks = includeRawChunks;
|
|
@@ -5658,6 +5676,7 @@ var DefaultStreamTextResult = class {
|
|
|
5658
5676
|
let recordedContent = [];
|
|
5659
5677
|
const recordedResponseMessages = [];
|
|
5660
5678
|
let recordedFinishReason = void 0;
|
|
5679
|
+
let recordedRawFinishReason = void 0;
|
|
5661
5680
|
let recordedTotalUsage = void 0;
|
|
5662
5681
|
let recordedRequest = {};
|
|
5663
5682
|
let recordedWarnings = [];
|
|
@@ -5786,6 +5805,7 @@ var DefaultStreamTextResult = class {
|
|
|
5786
5805
|
const currentStepResult = new DefaultStepResult({
|
|
5787
5806
|
content: recordedContent,
|
|
5788
5807
|
finishReason: part.finishReason,
|
|
5808
|
+
rawFinishReason: part.rawFinishReason,
|
|
5789
5809
|
usage: part.usage,
|
|
5790
5810
|
warnings: recordedWarnings,
|
|
5791
5811
|
request: recordedRequest,
|
|
@@ -5808,6 +5828,7 @@ var DefaultStreamTextResult = class {
|
|
|
5808
5828
|
if (part.type === "finish") {
|
|
5809
5829
|
recordedTotalUsage = part.totalUsage;
|
|
5810
5830
|
recordedFinishReason = part.finishReason;
|
|
5831
|
+
recordedRawFinishReason = part.rawFinishReason;
|
|
5811
5832
|
}
|
|
5812
5833
|
},
|
|
5813
5834
|
async flush(controller) {
|
|
@@ -5817,18 +5838,21 @@ var DefaultStreamTextResult = class {
|
|
|
5817
5838
|
message: "No output generated. Check the stream for errors."
|
|
5818
5839
|
});
|
|
5819
5840
|
self._finishReason.reject(error);
|
|
5841
|
+
self._rawFinishReason.reject(error);
|
|
5820
5842
|
self._totalUsage.reject(error);
|
|
5821
5843
|
self._steps.reject(error);
|
|
5822
5844
|
return;
|
|
5823
5845
|
}
|
|
5824
|
-
const finishReason = recordedFinishReason != null ? recordedFinishReason : "
|
|
5846
|
+
const finishReason = recordedFinishReason != null ? recordedFinishReason : "other";
|
|
5825
5847
|
const totalUsage = recordedTotalUsage != null ? recordedTotalUsage : createNullLanguageModelUsage();
|
|
5826
5848
|
self._finishReason.resolve(finishReason);
|
|
5849
|
+
self._rawFinishReason.resolve(recordedRawFinishReason);
|
|
5827
5850
|
self._totalUsage.resolve(totalUsage);
|
|
5828
5851
|
self._steps.resolve(recordedSteps);
|
|
5829
5852
|
const finalStep = recordedSteps[recordedSteps.length - 1];
|
|
5830
5853
|
await (onFinish == null ? void 0 : onFinish({
|
|
5831
|
-
finishReason,
|
|
5854
|
+
finishReason: finalStep.finishReason,
|
|
5855
|
+
rawFinishReason: finalStep.rawFinishReason,
|
|
5832
5856
|
totalUsage,
|
|
5833
5857
|
usage: finalStep.usage,
|
|
5834
5858
|
content: finalStep.content,
|
|
@@ -6153,7 +6177,8 @@ var DefaultStreamTextResult = class {
|
|
|
6153
6177
|
const stepToolOutputs = [];
|
|
6154
6178
|
let warnings;
|
|
6155
6179
|
const activeToolCallToolNames = {};
|
|
6156
|
-
let stepFinishReason = "
|
|
6180
|
+
let stepFinishReason = "other";
|
|
6181
|
+
let stepRawFinishReason = void 0;
|
|
6157
6182
|
let stepUsage = createNullLanguageModelUsage();
|
|
6158
6183
|
let stepProviderMetadata;
|
|
6159
6184
|
let stepFirstChunk = true;
|
|
@@ -6249,6 +6274,7 @@ var DefaultStreamTextResult = class {
|
|
|
6249
6274
|
case "finish": {
|
|
6250
6275
|
stepUsage = chunk.usage;
|
|
6251
6276
|
stepFinishReason = chunk.finishReason;
|
|
6277
|
+
stepRawFinishReason = chunk.rawFinishReason;
|
|
6252
6278
|
stepProviderMetadata = chunk.providerMetadata;
|
|
6253
6279
|
const msToFinish = now2() - startTimestampMs;
|
|
6254
6280
|
doStreamSpan.addEvent("ai.stream.finish");
|
|
@@ -6361,6 +6387,7 @@ var DefaultStreamTextResult = class {
|
|
|
6361
6387
|
controller.enqueue({
|
|
6362
6388
|
type: "finish-step",
|
|
6363
6389
|
finishReason: stepFinishReason,
|
|
6390
|
+
rawFinishReason: stepRawFinishReason,
|
|
6364
6391
|
usage: stepUsage,
|
|
6365
6392
|
providerMetadata: stepProviderMetadata,
|
|
6366
6393
|
response: {
|
|
@@ -6432,6 +6459,7 @@ var DefaultStreamTextResult = class {
|
|
|
6432
6459
|
controller.enqueue({
|
|
6433
6460
|
type: "finish",
|
|
6434
6461
|
finishReason: stepFinishReason,
|
|
6462
|
+
rawFinishReason: stepRawFinishReason,
|
|
6435
6463
|
totalUsage: combinedUsage
|
|
6436
6464
|
});
|
|
6437
6465
|
self.closeStream();
|
|
@@ -6525,6 +6553,10 @@ var DefaultStreamTextResult = class {
|
|
|
6525
6553
|
this.consumeStream();
|
|
6526
6554
|
return this._finishReason.promise;
|
|
6527
6555
|
}
|
|
6556
|
+
get rawFinishReason() {
|
|
6557
|
+
this.consumeStream();
|
|
6558
|
+
return this._rawFinishReason.promise;
|
|
6559
|
+
}
|
|
6528
6560
|
/**
|
|
6529
6561
|
Split out a new stream from the original stream.
|
|
6530
6562
|
The original stream is replaced to allow for further splitting,
|
|
@@ -8967,14 +8999,14 @@ async function generateObject(options) {
|
|
|
8967
8999
|
message: "No object generated: the model did not return a response.",
|
|
8968
9000
|
response: responseData,
|
|
8969
9001
|
usage: asLanguageModelUsage(result2.usage),
|
|
8970
|
-
finishReason: result2.finishReason
|
|
9002
|
+
finishReason: result2.finishReason.unified
|
|
8971
9003
|
});
|
|
8972
9004
|
}
|
|
8973
9005
|
span2.setAttributes(
|
|
8974
9006
|
await selectTelemetryAttributes({
|
|
8975
9007
|
telemetry,
|
|
8976
9008
|
attributes: {
|
|
8977
|
-
"ai.response.finishReason": result2.finishReason,
|
|
9009
|
+
"ai.response.finishReason": result2.finishReason.unified,
|
|
8978
9010
|
"ai.response.object": { output: () => text2 },
|
|
8979
9011
|
"ai.response.id": responseData.id,
|
|
8980
9012
|
"ai.response.model": responseData.modelId,
|
|
@@ -8986,7 +9018,9 @@ async function generateObject(options) {
|
|
|
8986
9018
|
"ai.usage.promptTokens": result2.usage.inputTokens.total,
|
|
8987
9019
|
"ai.usage.completionTokens": result2.usage.outputTokens.total,
|
|
8988
9020
|
// standardized gen-ai llm span attributes:
|
|
8989
|
-
"gen_ai.response.finish_reasons": [
|
|
9021
|
+
"gen_ai.response.finish_reasons": [
|
|
9022
|
+
result2.finishReason.unified
|
|
9023
|
+
],
|
|
8990
9024
|
"gen_ai.response.id": responseData.id,
|
|
8991
9025
|
"gen_ai.response.model": responseData.modelId,
|
|
8992
9026
|
"gen_ai.usage.input_tokens": result2.usage.inputTokens.total,
|
|
@@ -9004,7 +9038,7 @@ async function generateObject(options) {
|
|
|
9004
9038
|
})
|
|
9005
9039
|
);
|
|
9006
9040
|
result = generateResult.objectText;
|
|
9007
|
-
finishReason = generateResult.finishReason;
|
|
9041
|
+
finishReason = generateResult.finishReason.unified;
|
|
9008
9042
|
usage = asLanguageModelUsage(generateResult.usage);
|
|
9009
9043
|
warnings = generateResult.warnings;
|
|
9010
9044
|
resultProviderMetadata = generateResult.providerMetadata;
|
|
@@ -9518,11 +9552,12 @@ var DefaultStreamObjectResult = class {
|
|
|
9518
9552
|
if (textDelta !== "") {
|
|
9519
9553
|
controller.enqueue({ type: "text-delta", textDelta });
|
|
9520
9554
|
}
|
|
9521
|
-
finishReason = chunk.finishReason;
|
|
9555
|
+
finishReason = chunk.finishReason.unified;
|
|
9522
9556
|
usage = asLanguageModelUsage(chunk.usage);
|
|
9523
9557
|
providerMetadata = chunk.providerMetadata;
|
|
9524
9558
|
controller.enqueue({
|
|
9525
9559
|
...chunk,
|
|
9560
|
+
finishReason: chunk.finishReason.unified,
|
|
9526
9561
|
usage,
|
|
9527
9562
|
response: fullResponse
|
|
9528
9563
|
});
|
|
@@ -9538,7 +9573,7 @@ var DefaultStreamObjectResult = class {
|
|
|
9538
9573
|
...fullResponse,
|
|
9539
9574
|
headers: response == null ? void 0 : response.headers
|
|
9540
9575
|
});
|
|
9541
|
-
self._finishReason.resolve(finishReason != null ? finishReason : "
|
|
9576
|
+
self._finishReason.resolve(finishReason != null ? finishReason : "other");
|
|
9542
9577
|
try {
|
|
9543
9578
|
object2 = await parseAndValidateObjectResultWithRepair(
|
|
9544
9579
|
accumulatedText,
|