ai 4.0.34 → 4.0.36
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 +14 -0
- package/dist/index.d.mts +36 -30
- package/dist/index.d.ts +36 -30
- package/dist/index.js +50 -50
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +50 -50
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -5
package/dist/index.mjs
CHANGED
@@ -4108,6 +4108,53 @@ var object = ({
|
|
4108
4108
|
};
|
4109
4109
|
};
|
4110
4110
|
|
4111
|
+
// core/generate-text/smooth-stream.ts
|
4112
|
+
import { InvalidArgumentError as InvalidArgumentError2 } from "@ai-sdk/provider";
|
4113
|
+
var CHUNKING_REGEXPS = {
|
4114
|
+
word: /\s*\S+\s+/m,
|
4115
|
+
line: /[^\n]*\n/m
|
4116
|
+
};
|
4117
|
+
function smoothStream({
|
4118
|
+
delayInMs = 10,
|
4119
|
+
chunking = "word",
|
4120
|
+
_internal: { delay: delay2 = delay } = {}
|
4121
|
+
} = {}) {
|
4122
|
+
const chunkingRegexp = typeof chunking === "string" ? CHUNKING_REGEXPS[chunking] : chunking;
|
4123
|
+
if (chunkingRegexp == null) {
|
4124
|
+
throw new InvalidArgumentError2({
|
4125
|
+
argument: "chunking",
|
4126
|
+
message: `Chunking must be "word" or "line" or a RegExp. Received: ${chunking}`
|
4127
|
+
});
|
4128
|
+
}
|
4129
|
+
return () => {
|
4130
|
+
let buffer = "";
|
4131
|
+
return new TransformStream({
|
4132
|
+
async transform(chunk, controller) {
|
4133
|
+
if (chunk.type === "step-finish") {
|
4134
|
+
if (buffer.length > 0) {
|
4135
|
+
controller.enqueue({ type: "text-delta", textDelta: buffer });
|
4136
|
+
buffer = "";
|
4137
|
+
}
|
4138
|
+
controller.enqueue(chunk);
|
4139
|
+
return;
|
4140
|
+
}
|
4141
|
+
if (chunk.type !== "text-delta") {
|
4142
|
+
controller.enqueue(chunk);
|
4143
|
+
return;
|
4144
|
+
}
|
4145
|
+
buffer += chunk.textDelta;
|
4146
|
+
let match;
|
4147
|
+
while ((match = chunkingRegexp.exec(buffer)) != null) {
|
4148
|
+
const chunk2 = match[0];
|
4149
|
+
controller.enqueue({ type: "text-delta", textDelta: chunk2 });
|
4150
|
+
buffer = buffer.slice(chunk2.length);
|
4151
|
+
await delay2(delayInMs);
|
4152
|
+
}
|
4153
|
+
}
|
4154
|
+
});
|
4155
|
+
};
|
4156
|
+
}
|
4157
|
+
|
4111
4158
|
// core/generate-text/stream-text.ts
|
4112
4159
|
import { createIdGenerator as createIdGenerator4 } from "@ai-sdk/provider-utils";
|
4113
4160
|
import { formatDataStreamPart as formatDataStreamPart2 } from "@ai-sdk/ui-utils";
|
@@ -4434,7 +4481,7 @@ function streamText({
|
|
4434
4481
|
tools,
|
4435
4482
|
toolChoice,
|
4436
4483
|
toolCallStreaming,
|
4437
|
-
transform,
|
4484
|
+
transforms: transform == null ? [] : Array.isArray(transform) ? transform : [transform],
|
4438
4485
|
activeTools,
|
4439
4486
|
repairToolCall,
|
4440
4487
|
maxSteps,
|
@@ -4514,7 +4561,7 @@ var DefaultStreamTextResult = class {
|
|
4514
4561
|
tools,
|
4515
4562
|
toolChoice,
|
4516
4563
|
toolCallStreaming,
|
4517
|
-
|
4564
|
+
transforms,
|
4518
4565
|
activeTools,
|
4519
4566
|
repairToolCall,
|
4520
4567
|
maxSteps,
|
@@ -4707,7 +4754,7 @@ var DefaultStreamTextResult = class {
|
|
4707
4754
|
this.addStream = stitchableStream.addStream;
|
4708
4755
|
this.closeStream = stitchableStream.close;
|
4709
4756
|
let stream = stitchableStream.stream;
|
4710
|
-
|
4757
|
+
for (const transform of transforms) {
|
4711
4758
|
stream = stream.pipeThrough(
|
4712
4759
|
transform({
|
4713
4760
|
tools,
|
@@ -5381,53 +5428,6 @@ var DefaultStreamTextResult = class {
|
|
5381
5428
|
}
|
5382
5429
|
};
|
5383
5430
|
|
5384
|
-
// core/generate-text/smooth-stream.ts
|
5385
|
-
import { InvalidArgumentError as InvalidArgumentError2 } from "@ai-sdk/provider";
|
5386
|
-
var CHUNKING_REGEXPS = {
|
5387
|
-
word: /\s*\S+\s+/m,
|
5388
|
-
line: /[^\n]*\n/m
|
5389
|
-
};
|
5390
|
-
function smoothStream({
|
5391
|
-
delayInMs = 10,
|
5392
|
-
chunking = "word",
|
5393
|
-
_internal: { delay: delay2 = delay } = {}
|
5394
|
-
} = {}) {
|
5395
|
-
const chunkingRegexp = typeof chunking === "string" ? CHUNKING_REGEXPS[chunking] : chunking;
|
5396
|
-
if (chunkingRegexp == null) {
|
5397
|
-
throw new InvalidArgumentError2({
|
5398
|
-
argument: "chunking",
|
5399
|
-
message: `Chunking must be "word" or "line" or a RegExp. Received: ${chunking}`
|
5400
|
-
});
|
5401
|
-
}
|
5402
|
-
return () => {
|
5403
|
-
let buffer = "";
|
5404
|
-
return new TransformStream({
|
5405
|
-
async transform(chunk, controller) {
|
5406
|
-
if (chunk.type === "step-finish") {
|
5407
|
-
if (buffer.length > 0) {
|
5408
|
-
controller.enqueue({ type: "text-delta", textDelta: buffer });
|
5409
|
-
buffer = "";
|
5410
|
-
}
|
5411
|
-
controller.enqueue(chunk);
|
5412
|
-
return;
|
5413
|
-
}
|
5414
|
-
if (chunk.type !== "text-delta") {
|
5415
|
-
controller.enqueue(chunk);
|
5416
|
-
return;
|
5417
|
-
}
|
5418
|
-
buffer += chunk.textDelta;
|
5419
|
-
let match;
|
5420
|
-
while ((match = chunkingRegexp.exec(buffer)) != null) {
|
5421
|
-
const chunk2 = match[0];
|
5422
|
-
controller.enqueue({ type: "text-delta", textDelta: chunk2 });
|
5423
|
-
buffer = buffer.slice(chunk2.length);
|
5424
|
-
await delay2(delayInMs);
|
5425
|
-
}
|
5426
|
-
}
|
5427
|
-
});
|
5428
|
-
};
|
5429
|
-
}
|
5430
|
-
|
5431
5431
|
// core/middleware/wrap-language-model.ts
|
5432
5432
|
var experimental_wrapLanguageModel = ({
|
5433
5433
|
model,
|