ai 5.0.0-canary.0 → 5.0.0-canary.1
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 +16 -0
- package/dist/index.d.mts +46 -92
- package/dist/index.d.ts +46 -92
- package/dist/index.js +66 -27
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +66 -27
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -13
- package/rsc/dist/index.d.ts +7 -7
- package/rsc/dist/rsc-server.d.mts +7 -7
- package/rsc/dist/rsc-server.mjs.map +1 -1
- package/test/dist/index.d.mts +18 -18
- package/test/dist/index.d.ts +18 -18
- package/test/dist/index.js +4 -4
- package/test/dist/index.js.map +1 -1
- package/test/dist/index.mjs +3 -3
- package/test/dist/index.mjs.map +1 -1
- package/react/dist/index.d.mts +0 -18
- package/react/dist/index.d.ts +0 -18
- package/react/dist/index.js +0 -39
- package/react/dist/index.js.map +0 -1
- package/react/dist/index.mjs +0 -17
- package/react/dist/index.mjs.map +0 -1
package/dist/index.js
CHANGED
@@ -1112,13 +1112,15 @@ var NoObjectGeneratedError = class extends import_provider5.AISDKError {
|
|
1112
1112
|
cause,
|
1113
1113
|
text: text2,
|
1114
1114
|
response,
|
1115
|
-
usage
|
1115
|
+
usage,
|
1116
|
+
finishReason
|
1116
1117
|
}) {
|
1117
1118
|
super({ name: name4, message, cause });
|
1118
1119
|
this[_a4] = true;
|
1119
1120
|
this.text = text2;
|
1120
1121
|
this.response = response;
|
1121
1122
|
this.usage = usage;
|
1123
|
+
this.finishReason = finishReason;
|
1122
1124
|
}
|
1123
1125
|
static isInstance(error) {
|
1124
1126
|
return import_provider5.AISDKError.hasMarker(error, marker4);
|
@@ -2280,7 +2282,8 @@ var noSchemaOutputStrategy = {
|
|
2280
2282
|
message: "No object generated: response did not match schema.",
|
2281
2283
|
text: context.text,
|
2282
2284
|
response: context.response,
|
2283
|
-
usage: context.usage
|
2285
|
+
usage: context.usage,
|
2286
|
+
finishReason: context.finishReason
|
2284
2287
|
})
|
2285
2288
|
} : { success: true, value };
|
2286
2289
|
},
|
@@ -2777,7 +2780,8 @@ async function generateObject({
|
|
2777
2780
|
throw new NoObjectGeneratedError({
|
2778
2781
|
message: "No object generated: the model did not return a response.",
|
2779
2782
|
response: responseData,
|
2780
|
-
usage: calculateLanguageModelUsage(result2.usage)
|
2783
|
+
usage: calculateLanguageModelUsage(result2.usage),
|
2784
|
+
finishReason: result2.finishReason
|
2781
2785
|
});
|
2782
2786
|
}
|
2783
2787
|
span2.setAttributes(
|
@@ -2886,7 +2890,8 @@ async function generateObject({
|
|
2886
2890
|
throw new NoObjectGeneratedError({
|
2887
2891
|
message: "No object generated: the tool was not called.",
|
2888
2892
|
response: responseData,
|
2889
|
-
usage: calculateLanguageModelUsage(result2.usage)
|
2893
|
+
usage: calculateLanguageModelUsage(result2.usage),
|
2894
|
+
finishReason: result2.finishReason
|
2890
2895
|
});
|
2891
2896
|
}
|
2892
2897
|
span2.setAttributes(
|
@@ -2942,7 +2947,8 @@ async function generateObject({
|
|
2942
2947
|
cause: parseResult.error,
|
2943
2948
|
text: result2,
|
2944
2949
|
response,
|
2945
|
-
usage: calculateLanguageModelUsage(usage)
|
2950
|
+
usage: calculateLanguageModelUsage(usage),
|
2951
|
+
finishReason
|
2946
2952
|
});
|
2947
2953
|
}
|
2948
2954
|
const validationResult = outputStrategy.validateFinalResult(
|
@@ -2959,7 +2965,8 @@ async function generateObject({
|
|
2959
2965
|
cause: validationResult.error,
|
2960
2966
|
text: result2,
|
2961
2967
|
response,
|
2962
|
-
usage: calculateLanguageModelUsage(usage)
|
2968
|
+
usage: calculateLanguageModelUsage(usage),
|
2969
|
+
finishReason
|
2963
2970
|
});
|
2964
2971
|
}
|
2965
2972
|
return validationResult.value;
|
@@ -3564,7 +3571,8 @@ var DefaultStreamObjectResult = class {
|
|
3564
3571
|
cause: validationResult.error,
|
3565
3572
|
text: accumulatedText,
|
3566
3573
|
response,
|
3567
|
-
usage
|
3574
|
+
usage,
|
3575
|
+
finishReason
|
3568
3576
|
});
|
3569
3577
|
self.objectPromise.reject(error);
|
3570
3578
|
}
|
@@ -4392,7 +4400,11 @@ async function generateText({
|
|
4392
4400
|
}
|
4393
4401
|
return output.parseOutput(
|
4394
4402
|
{ text: text2 },
|
4395
|
-
{
|
4403
|
+
{
|
4404
|
+
response: currentModelResponse.response,
|
4405
|
+
usage,
|
4406
|
+
finishReason: currentModelResponse.finishReason
|
4407
|
+
}
|
4396
4408
|
);
|
4397
4409
|
},
|
4398
4410
|
toolCalls: currentToolCalls,
|
@@ -4637,7 +4649,8 @@ var object = ({
|
|
4637
4649
|
cause: parseResult.error,
|
4638
4650
|
text: text2,
|
4639
4651
|
response: context.response,
|
4640
|
-
usage: context.usage
|
4652
|
+
usage: context.usage,
|
4653
|
+
finishReason: context.finishReason
|
4641
4654
|
});
|
4642
4655
|
}
|
4643
4656
|
const validationResult = (0, import_provider_utils10.safeValidateTypes)({
|
@@ -4650,7 +4663,8 @@ var object = ({
|
|
4650
4663
|
cause: validationResult.error,
|
4651
4664
|
text: text2,
|
4652
4665
|
response: context.response,
|
4653
|
-
usage: context.usage
|
4666
|
+
usage: context.usage,
|
4667
|
+
finishReason: context.finishReason
|
4654
4668
|
});
|
4655
4669
|
}
|
4656
4670
|
return validationResult.value;
|
@@ -4659,23 +4673,49 @@ var object = ({
|
|
4659
4673
|
};
|
4660
4674
|
|
4661
4675
|
// core/generate-text/smooth-stream.ts
|
4662
|
-
var import_provider21 = require("@ai-sdk/provider");
|
4663
4676
|
var import_provider_utils11 = require("@ai-sdk/provider-utils");
|
4677
|
+
var import_provider21 = require("@ai-sdk/provider");
|
4664
4678
|
var CHUNKING_REGEXPS = {
|
4665
|
-
word: /\
|
4666
|
-
line:
|
4679
|
+
word: /\S+\s+/m,
|
4680
|
+
line: /\n+/m
|
4667
4681
|
};
|
4668
4682
|
function smoothStream({
|
4669
4683
|
delayInMs = 10,
|
4670
4684
|
chunking = "word",
|
4671
4685
|
_internal: { delay: delay2 = import_provider_utils11.delay } = {}
|
4672
4686
|
} = {}) {
|
4673
|
-
|
4674
|
-
if (
|
4675
|
-
|
4676
|
-
|
4677
|
-
|
4678
|
-
|
4687
|
+
let detectChunk;
|
4688
|
+
if (typeof chunking === "function") {
|
4689
|
+
detectChunk = (buffer) => {
|
4690
|
+
const match = chunking(buffer);
|
4691
|
+
if (match == null) {
|
4692
|
+
return null;
|
4693
|
+
}
|
4694
|
+
if (!match.length) {
|
4695
|
+
throw new Error(`Chunking function must return a non-empty string.`);
|
4696
|
+
}
|
4697
|
+
if (!buffer.startsWith(match)) {
|
4698
|
+
throw new Error(
|
4699
|
+
`Chunking function must return a match that is a prefix of the buffer. Received: "${match}" expected to start with "${buffer}"`
|
4700
|
+
);
|
4701
|
+
}
|
4702
|
+
return match;
|
4703
|
+
};
|
4704
|
+
} else {
|
4705
|
+
const chunkingRegex = typeof chunking === "string" ? CHUNKING_REGEXPS[chunking] : chunking;
|
4706
|
+
if (chunkingRegex == null) {
|
4707
|
+
throw new import_provider21.InvalidArgumentError({
|
4708
|
+
argument: "chunking",
|
4709
|
+
message: `Chunking must be "word" or "line" or a RegExp. Received: ${chunking}`
|
4710
|
+
});
|
4711
|
+
}
|
4712
|
+
detectChunk = (buffer) => {
|
4713
|
+
const match = chunkingRegex.exec(buffer);
|
4714
|
+
if (!match) {
|
4715
|
+
return null;
|
4716
|
+
}
|
4717
|
+
return buffer.slice(0, match.index) + (match == null ? void 0 : match[0]);
|
4718
|
+
};
|
4679
4719
|
}
|
4680
4720
|
return () => {
|
4681
4721
|
let buffer = "";
|
@@ -4691,10 +4731,9 @@ function smoothStream({
|
|
4691
4731
|
}
|
4692
4732
|
buffer += chunk.textDelta;
|
4693
4733
|
let match;
|
4694
|
-
while ((match =
|
4695
|
-
|
4696
|
-
|
4697
|
-
buffer = buffer.slice(chunk2.length);
|
4734
|
+
while ((match = detectChunk(buffer)) != null) {
|
4735
|
+
controller.enqueue({ type: "text-delta", textDelta: match });
|
4736
|
+
buffer = buffer.slice(match.length);
|
4698
4737
|
await delay2(delayInMs);
|
4699
4738
|
}
|
4700
4739
|
}
|
@@ -6264,7 +6303,7 @@ function defaultSettingsMiddleware({
|
|
6264
6303
|
settings
|
6265
6304
|
}) {
|
6266
6305
|
return {
|
6267
|
-
middlewareVersion: "
|
6306
|
+
middlewareVersion: "v2",
|
6268
6307
|
transformParams: async ({ params }) => {
|
6269
6308
|
var _a17;
|
6270
6309
|
return {
|
@@ -6309,7 +6348,7 @@ function extractReasoningMiddleware({
|
|
6309
6348
|
const openingTag = `<${tagName}>`;
|
6310
6349
|
const closingTag = `</${tagName}>`;
|
6311
6350
|
return {
|
6312
|
-
middlewareVersion: "
|
6351
|
+
middlewareVersion: "v2",
|
6313
6352
|
wrapGenerate: async ({ doGenerate }) => {
|
6314
6353
|
const { text: rawText, ...rest } = await doGenerate();
|
6315
6354
|
if (rawText == null) {
|
@@ -6395,7 +6434,7 @@ function extractReasoningMiddleware({
|
|
6395
6434
|
// core/middleware/simulate-streaming-middleware.ts
|
6396
6435
|
function simulateStreamingMiddleware() {
|
6397
6436
|
return {
|
6398
|
-
middlewareVersion: "
|
6437
|
+
middlewareVersion: "v2",
|
6399
6438
|
wrapStream: async ({ doGenerate }) => {
|
6400
6439
|
const result = await doGenerate();
|
6401
6440
|
const simulatedStream = new ReadableStream({
|
@@ -6500,7 +6539,7 @@ var doWrap = ({
|
|
6500
6539
|
return transformParams ? await transformParams({ params, type }) : params;
|
6501
6540
|
}
|
6502
6541
|
return {
|
6503
|
-
specificationVersion: "
|
6542
|
+
specificationVersion: "v2",
|
6504
6543
|
provider: providerId != null ? providerId : model.provider,
|
6505
6544
|
modelId: modelId != null ? modelId : model.modelId,
|
6506
6545
|
defaultObjectGenerationMode: model.defaultObjectGenerationMode,
|