ai 5.0.0-canary.0 → 5.0.0-canary.2
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.mts +52 -93
- package/dist/index.d.ts +52 -93
- package/dist/index.js +94 -30
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +94 -30
- 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.mjs
CHANGED
@@ -1035,13 +1035,15 @@ var NoObjectGeneratedError = class extends AISDKError4 {
|
|
1035
1035
|
cause,
|
1036
1036
|
text: text2,
|
1037
1037
|
response,
|
1038
|
-
usage
|
1038
|
+
usage,
|
1039
|
+
finishReason
|
1039
1040
|
}) {
|
1040
1041
|
super({ name: name4, message, cause });
|
1041
1042
|
this[_a4] = true;
|
1042
1043
|
this.text = text2;
|
1043
1044
|
this.response = response;
|
1044
1045
|
this.usage = usage;
|
1046
|
+
this.finishReason = finishReason;
|
1045
1047
|
}
|
1046
1048
|
static isInstance(error) {
|
1047
1049
|
return AISDKError4.hasMarker(error, marker4);
|
@@ -2211,7 +2213,8 @@ var noSchemaOutputStrategy = {
|
|
2211
2213
|
message: "No object generated: response did not match schema.",
|
2212
2214
|
text: context.text,
|
2213
2215
|
response: context.response,
|
2214
|
-
usage: context.usage
|
2216
|
+
usage: context.usage,
|
2217
|
+
finishReason: context.finishReason
|
2215
2218
|
})
|
2216
2219
|
} : { success: true, value };
|
2217
2220
|
},
|
@@ -2708,7 +2711,8 @@ async function generateObject({
|
|
2708
2711
|
throw new NoObjectGeneratedError({
|
2709
2712
|
message: "No object generated: the model did not return a response.",
|
2710
2713
|
response: responseData,
|
2711
|
-
usage: calculateLanguageModelUsage(result2.usage)
|
2714
|
+
usage: calculateLanguageModelUsage(result2.usage),
|
2715
|
+
finishReason: result2.finishReason
|
2712
2716
|
});
|
2713
2717
|
}
|
2714
2718
|
span2.setAttributes(
|
@@ -2817,7 +2821,8 @@ async function generateObject({
|
|
2817
2821
|
throw new NoObjectGeneratedError({
|
2818
2822
|
message: "No object generated: the tool was not called.",
|
2819
2823
|
response: responseData,
|
2820
|
-
usage: calculateLanguageModelUsage(result2.usage)
|
2824
|
+
usage: calculateLanguageModelUsage(result2.usage),
|
2825
|
+
finishReason: result2.finishReason
|
2821
2826
|
});
|
2822
2827
|
}
|
2823
2828
|
span2.setAttributes(
|
@@ -2873,7 +2878,8 @@ async function generateObject({
|
|
2873
2878
|
cause: parseResult.error,
|
2874
2879
|
text: result2,
|
2875
2880
|
response,
|
2876
|
-
usage: calculateLanguageModelUsage(usage)
|
2881
|
+
usage: calculateLanguageModelUsage(usage),
|
2882
|
+
finishReason
|
2877
2883
|
});
|
2878
2884
|
}
|
2879
2885
|
const validationResult = outputStrategy.validateFinalResult(
|
@@ -2890,7 +2896,8 @@ async function generateObject({
|
|
2890
2896
|
cause: validationResult.error,
|
2891
2897
|
text: result2,
|
2892
2898
|
response,
|
2893
|
-
usage: calculateLanguageModelUsage(usage)
|
2899
|
+
usage: calculateLanguageModelUsage(usage),
|
2900
|
+
finishReason
|
2894
2901
|
});
|
2895
2902
|
}
|
2896
2903
|
return validationResult.value;
|
@@ -3498,7 +3505,8 @@ var DefaultStreamObjectResult = class {
|
|
3498
3505
|
cause: validationResult.error,
|
3499
3506
|
text: accumulatedText,
|
3500
3507
|
response,
|
3501
|
-
usage
|
3508
|
+
usage,
|
3509
|
+
finishReason
|
3502
3510
|
});
|
3503
3511
|
self.objectPromise.reject(error);
|
3504
3512
|
}
|
@@ -4326,7 +4334,11 @@ async function generateText({
|
|
4326
4334
|
}
|
4327
4335
|
return output.parseOutput(
|
4328
4336
|
{ text: text2 },
|
4329
|
-
{
|
4337
|
+
{
|
4338
|
+
response: currentModelResponse.response,
|
4339
|
+
usage,
|
4340
|
+
finishReason: currentModelResponse.finishReason
|
4341
|
+
}
|
4330
4342
|
);
|
4331
4343
|
},
|
4332
4344
|
toolCalls: currentToolCalls,
|
@@ -4586,7 +4598,8 @@ var object = ({
|
|
4586
4598
|
cause: parseResult.error,
|
4587
4599
|
text: text2,
|
4588
4600
|
response: context.response,
|
4589
|
-
usage: context.usage
|
4601
|
+
usage: context.usage,
|
4602
|
+
finishReason: context.finishReason
|
4590
4603
|
});
|
4591
4604
|
}
|
4592
4605
|
const validationResult = safeValidateTypes4({
|
@@ -4599,7 +4612,8 @@ var object = ({
|
|
4599
4612
|
cause: validationResult.error,
|
4600
4613
|
text: text2,
|
4601
4614
|
response: context.response,
|
4602
|
-
usage: context.usage
|
4615
|
+
usage: context.usage,
|
4616
|
+
finishReason: context.finishReason
|
4603
4617
|
});
|
4604
4618
|
}
|
4605
4619
|
return validationResult.value;
|
@@ -4608,23 +4622,49 @@ var object = ({
|
|
4608
4622
|
};
|
4609
4623
|
|
4610
4624
|
// core/generate-text/smooth-stream.ts
|
4611
|
-
import { InvalidArgumentError as InvalidArgumentError2 } from "@ai-sdk/provider";
|
4612
4625
|
import { delay as originalDelay } from "@ai-sdk/provider-utils";
|
4626
|
+
import { InvalidArgumentError as InvalidArgumentError2 } from "@ai-sdk/provider";
|
4613
4627
|
var CHUNKING_REGEXPS = {
|
4614
|
-
word: /\
|
4615
|
-
line:
|
4628
|
+
word: /\S+\s+/m,
|
4629
|
+
line: /\n+/m
|
4616
4630
|
};
|
4617
4631
|
function smoothStream({
|
4618
4632
|
delayInMs = 10,
|
4619
4633
|
chunking = "word",
|
4620
4634
|
_internal: { delay: delay2 = originalDelay } = {}
|
4621
4635
|
} = {}) {
|
4622
|
-
|
4623
|
-
if (
|
4624
|
-
|
4625
|
-
|
4626
|
-
|
4627
|
-
|
4636
|
+
let detectChunk;
|
4637
|
+
if (typeof chunking === "function") {
|
4638
|
+
detectChunk = (buffer) => {
|
4639
|
+
const match = chunking(buffer);
|
4640
|
+
if (match == null) {
|
4641
|
+
return null;
|
4642
|
+
}
|
4643
|
+
if (!match.length) {
|
4644
|
+
throw new Error(`Chunking function must return a non-empty string.`);
|
4645
|
+
}
|
4646
|
+
if (!buffer.startsWith(match)) {
|
4647
|
+
throw new Error(
|
4648
|
+
`Chunking function must return a match that is a prefix of the buffer. Received: "${match}" expected to start with "${buffer}"`
|
4649
|
+
);
|
4650
|
+
}
|
4651
|
+
return match;
|
4652
|
+
};
|
4653
|
+
} else {
|
4654
|
+
const chunkingRegex = typeof chunking === "string" ? CHUNKING_REGEXPS[chunking] : chunking;
|
4655
|
+
if (chunkingRegex == null) {
|
4656
|
+
throw new InvalidArgumentError2({
|
4657
|
+
argument: "chunking",
|
4658
|
+
message: `Chunking must be "word" or "line" or a RegExp. Received: ${chunking}`
|
4659
|
+
});
|
4660
|
+
}
|
4661
|
+
detectChunk = (buffer) => {
|
4662
|
+
const match = chunkingRegex.exec(buffer);
|
4663
|
+
if (!match) {
|
4664
|
+
return null;
|
4665
|
+
}
|
4666
|
+
return buffer.slice(0, match.index) + (match == null ? void 0 : match[0]);
|
4667
|
+
};
|
4628
4668
|
}
|
4629
4669
|
return () => {
|
4630
4670
|
let buffer = "";
|
@@ -4640,10 +4680,9 @@ function smoothStream({
|
|
4640
4680
|
}
|
4641
4681
|
buffer += chunk.textDelta;
|
4642
4682
|
let match;
|
4643
|
-
while ((match =
|
4644
|
-
|
4645
|
-
|
4646
|
-
buffer = buffer.slice(chunk2.length);
|
4683
|
+
while ((match = detectChunk(buffer)) != null) {
|
4684
|
+
controller.enqueue({ type: "text-delta", textDelta: match });
|
4685
|
+
buffer = buffer.slice(match.length);
|
4647
4686
|
await delay2(delayInMs);
|
4648
4687
|
}
|
4649
4688
|
}
|
@@ -4661,6 +4700,25 @@ function asArray(value) {
|
|
4661
4700
|
return value === void 0 ? [] : Array.isArray(value) ? value : [value];
|
4662
4701
|
}
|
4663
4702
|
|
4703
|
+
// util/consume-stream.ts
|
4704
|
+
async function consumeStream({
|
4705
|
+
stream,
|
4706
|
+
onError
|
4707
|
+
}) {
|
4708
|
+
const reader = stream.getReader();
|
4709
|
+
try {
|
4710
|
+
while (true) {
|
4711
|
+
const { done } = await reader.read();
|
4712
|
+
if (done)
|
4713
|
+
break;
|
4714
|
+
}
|
4715
|
+
} catch (error) {
|
4716
|
+
onError == null ? void 0 : onError(error);
|
4717
|
+
} finally {
|
4718
|
+
reader.releaseLock();
|
4719
|
+
}
|
4720
|
+
}
|
4721
|
+
|
4664
4722
|
// core/util/merge-streams.ts
|
4665
4723
|
function mergeStreams(stream1, stream2) {
|
4666
4724
|
const reader1 = stream1.getReader();
|
@@ -5902,9 +5960,15 @@ var DefaultStreamTextResult = class {
|
|
5902
5960
|
)
|
5903
5961
|
);
|
5904
5962
|
}
|
5905
|
-
async consumeStream() {
|
5906
|
-
|
5907
|
-
|
5963
|
+
async consumeStream(options) {
|
5964
|
+
var _a17;
|
5965
|
+
try {
|
5966
|
+
await consumeStream({
|
5967
|
+
stream: this.fullStream,
|
5968
|
+
onError: options == null ? void 0 : options.onError
|
5969
|
+
});
|
5970
|
+
} catch (error) {
|
5971
|
+
(_a17 = options == null ? void 0 : options.onError) == null ? void 0 : _a17.call(options, error);
|
5908
5972
|
}
|
5909
5973
|
}
|
5910
5974
|
get experimental_partialOutputStream() {
|
@@ -6213,7 +6277,7 @@ function defaultSettingsMiddleware({
|
|
6213
6277
|
settings
|
6214
6278
|
}) {
|
6215
6279
|
return {
|
6216
|
-
middlewareVersion: "
|
6280
|
+
middlewareVersion: "v2",
|
6217
6281
|
transformParams: async ({ params }) => {
|
6218
6282
|
var _a17;
|
6219
6283
|
return {
|
@@ -6258,7 +6322,7 @@ function extractReasoningMiddleware({
|
|
6258
6322
|
const openingTag = `<${tagName}>`;
|
6259
6323
|
const closingTag = `</${tagName}>`;
|
6260
6324
|
return {
|
6261
|
-
middlewareVersion: "
|
6325
|
+
middlewareVersion: "v2",
|
6262
6326
|
wrapGenerate: async ({ doGenerate }) => {
|
6263
6327
|
const { text: rawText, ...rest } = await doGenerate();
|
6264
6328
|
if (rawText == null) {
|
@@ -6344,7 +6408,7 @@ function extractReasoningMiddleware({
|
|
6344
6408
|
// core/middleware/simulate-streaming-middleware.ts
|
6345
6409
|
function simulateStreamingMiddleware() {
|
6346
6410
|
return {
|
6347
|
-
middlewareVersion: "
|
6411
|
+
middlewareVersion: "v2",
|
6348
6412
|
wrapStream: async ({ doGenerate }) => {
|
6349
6413
|
const result = await doGenerate();
|
6350
6414
|
const simulatedStream = new ReadableStream({
|
@@ -6449,7 +6513,7 @@ var doWrap = ({
|
|
6449
6513
|
return transformParams ? await transformParams({ params, type }) : params;
|
6450
6514
|
}
|
6451
6515
|
return {
|
6452
|
-
specificationVersion: "
|
6516
|
+
specificationVersion: "v2",
|
6453
6517
|
provider: providerId != null ? providerId : model.provider,
|
6454
6518
|
modelId: modelId != null ? modelId : model.modelId,
|
6455
6519
|
defaultObjectGenerationMode: model.defaultObjectGenerationMode,
|