ai 3.0.31 → 3.0.33
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/dist/index.d.mts +13 -1
- package/dist/index.d.ts +13 -1
- package/dist/index.js +58 -24
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +59 -25
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
@@ -274,7 +274,7 @@ function convertZodToJSONSchema(zodSchema) {
|
|
274
274
|
|
275
275
|
// core/util/retry-with-exponential-backoff.ts
|
276
276
|
import { APICallError, RetryError } from "@ai-sdk/provider";
|
277
|
-
import { getErrorMessage } from "@ai-sdk/provider-utils";
|
277
|
+
import { getErrorMessage, isAbortError } from "@ai-sdk/provider-utils";
|
278
278
|
|
279
279
|
// core/util/delay.ts
|
280
280
|
async function delay(delayInMs) {
|
@@ -299,7 +299,7 @@ async function _retryWithExponentialBackoff(f, {
|
|
299
299
|
try {
|
300
300
|
return await f();
|
301
301
|
} catch (error) {
|
302
|
-
if (error
|
302
|
+
if (isAbortError(error)) {
|
303
303
|
throw error;
|
304
304
|
}
|
305
305
|
if (maxRetries === 0) {
|
@@ -1321,25 +1321,27 @@ function runToolsTransformation({
|
|
1321
1321
|
});
|
1322
1322
|
return new ReadableStream({
|
1323
1323
|
async start(controller) {
|
1324
|
-
|
1325
|
-
|
1326
|
-
|
1327
|
-
|
1328
|
-
|
1329
|
-
|
1330
|
-
|
1331
|
-
|
1332
|
-
|
1333
|
-
|
1334
|
-
|
1335
|
-
|
1336
|
-
|
1337
|
-
|
1338
|
-
|
1339
|
-
|
1340
|
-
|
1341
|
-
|
1342
|
-
|
1324
|
+
return Promise.all([
|
1325
|
+
generatorStream.pipeThrough(forwardStream).pipeTo(
|
1326
|
+
new WritableStream({
|
1327
|
+
write(chunk) {
|
1328
|
+
controller.enqueue(chunk);
|
1329
|
+
},
|
1330
|
+
close() {
|
1331
|
+
}
|
1332
|
+
})
|
1333
|
+
),
|
1334
|
+
toolResultsStream.pipeTo(
|
1335
|
+
new WritableStream({
|
1336
|
+
write(chunk) {
|
1337
|
+
controller.enqueue(chunk);
|
1338
|
+
},
|
1339
|
+
close() {
|
1340
|
+
controller.close();
|
1341
|
+
}
|
1342
|
+
})
|
1343
|
+
)
|
1344
|
+
]);
|
1343
1345
|
}
|
1344
1346
|
});
|
1345
1347
|
}
|
@@ -1445,7 +1447,7 @@ var StreamTextResult = class {
|
|
1445
1447
|
/**
|
1446
1448
|
Writes stream data output to a Node.js response-like object.
|
1447
1449
|
It sets a `Content-Type` header to `text/plain; charset=utf-8` and
|
1448
|
-
writes each
|
1450
|
+
writes each stream data part as a separate chunk.
|
1449
1451
|
|
1450
1452
|
@param response A Node.js response-like object (ServerResponse).
|
1451
1453
|
@param init Optional headers and status code.
|
@@ -1474,6 +1476,38 @@ var StreamTextResult = class {
|
|
1474
1476
|
read();
|
1475
1477
|
}
|
1476
1478
|
/**
|
1479
|
+
Writes text delta output to a Node.js response-like object.
|
1480
|
+
It sets a `Content-Type` header to `text/plain; charset=utf-8` and
|
1481
|
+
writes each text delta as a separate chunk.
|
1482
|
+
|
1483
|
+
@param response A Node.js response-like object (ServerResponse).
|
1484
|
+
@param init Optional headers and status code.
|
1485
|
+
*/
|
1486
|
+
pipeTextStreamToResponse(response, init) {
|
1487
|
+
var _a;
|
1488
|
+
response.writeHead((_a = init == null ? void 0 : init.status) != null ? _a : 200, {
|
1489
|
+
"Content-Type": "text/plain; charset=utf-8",
|
1490
|
+
...init == null ? void 0 : init.headers
|
1491
|
+
});
|
1492
|
+
const reader = this.textStream.getReader();
|
1493
|
+
const read = async () => {
|
1494
|
+
const encoder = new TextEncoder();
|
1495
|
+
try {
|
1496
|
+
while (true) {
|
1497
|
+
const { done, value } = await reader.read();
|
1498
|
+
if (done)
|
1499
|
+
break;
|
1500
|
+
response.write(encoder.encode(value));
|
1501
|
+
}
|
1502
|
+
} catch (error) {
|
1503
|
+
throw error;
|
1504
|
+
} finally {
|
1505
|
+
response.end();
|
1506
|
+
}
|
1507
|
+
};
|
1508
|
+
read();
|
1509
|
+
}
|
1510
|
+
/**
|
1477
1511
|
Converts the result to a streamed response object with a stream data part stream.
|
1478
1512
|
It can be used with the `useChat` and `useCompletion` hooks.
|
1479
1513
|
|
@@ -1883,7 +1917,7 @@ function readableFromAsyncIterable(iterable) {
|
|
1883
1917
|
}
|
1884
1918
|
|
1885
1919
|
// streams/stream-data.ts
|
1886
|
-
var
|
1920
|
+
var StreamData = class {
|
1887
1921
|
constructor() {
|
1888
1922
|
this.encoder = new TextEncoder();
|
1889
1923
|
this.controller = null;
|
@@ -1979,7 +2013,7 @@ function createStreamDataTransformer() {
|
|
1979
2013
|
}
|
1980
2014
|
});
|
1981
2015
|
}
|
1982
|
-
var experimental_StreamData = class extends
|
2016
|
+
var experimental_StreamData = class extends StreamData {
|
1983
2017
|
};
|
1984
2018
|
|
1985
2019
|
// streams/anthropic-stream.ts
|
@@ -2923,7 +2957,7 @@ export {
|
|
2923
2957
|
MistralStream,
|
2924
2958
|
OpenAIStream,
|
2925
2959
|
ReplicateStream,
|
2926
|
-
|
2960
|
+
StreamData,
|
2927
2961
|
StreamObjectResult,
|
2928
2962
|
StreamTextResult,
|
2929
2963
|
StreamingTextResponse,
|