ai 4.1.29 → 4.1.31
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 +12 -0
- package/dist/index.d.mts +32 -5
- package/dist/index.d.ts +32 -5
- package/dist/index.js +23 -18
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +23 -18
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
@@ -2144,9 +2144,7 @@ var arrayOutputStrategy = (schema) => {
|
|
2144
2144
|
}
|
2145
2145
|
case "text-delta":
|
2146
2146
|
case "finish":
|
2147
|
-
break;
|
2148
2147
|
case "error":
|
2149
|
-
controller.error(chunk.error);
|
2150
2148
|
break;
|
2151
2149
|
default: {
|
2152
2150
|
const _exhaustiveCheck = chunk;
|
@@ -2916,6 +2914,7 @@ function streamObject({
|
|
2916
2914
|
experimental_telemetry: telemetry,
|
2917
2915
|
experimental_providerMetadata,
|
2918
2916
|
providerOptions = experimental_providerMetadata,
|
2917
|
+
onError,
|
2919
2918
|
onFinish,
|
2920
2919
|
_internal: {
|
2921
2920
|
generateId: generateId3 = originalGenerateId2,
|
@@ -2950,6 +2949,7 @@ function streamObject({
|
|
2950
2949
|
schemaDescription,
|
2951
2950
|
providerOptions,
|
2952
2951
|
mode,
|
2952
|
+
onError,
|
2953
2953
|
onFinish,
|
2954
2954
|
generateId: generateId3,
|
2955
2955
|
currentDate,
|
@@ -2972,6 +2972,7 @@ var DefaultStreamObjectResult = class {
|
|
2972
2972
|
schemaDescription,
|
2973
2973
|
providerOptions,
|
2974
2974
|
mode,
|
2975
|
+
onError,
|
2975
2976
|
onFinish,
|
2976
2977
|
generateId: generateId3,
|
2977
2978
|
currentDate,
|
@@ -2983,7 +2984,6 @@ var DefaultStreamObjectResult = class {
|
|
2983
2984
|
this.warningsPromise = new DelayedPromise();
|
2984
2985
|
this.requestPromise = new DelayedPromise();
|
2985
2986
|
this.responsePromise = new DelayedPromise();
|
2986
|
-
this.stitchableStream = createStitchableStream();
|
2987
2987
|
const { maxRetries, retry } = prepareRetries({
|
2988
2988
|
maxRetries: maxRetriesArg
|
2989
2989
|
});
|
@@ -2995,6 +2995,16 @@ var DefaultStreamObjectResult = class {
|
|
2995
2995
|
});
|
2996
2996
|
const tracer = getTracer(telemetry);
|
2997
2997
|
const self = this;
|
2998
|
+
const stitchableStream = createStitchableStream();
|
2999
|
+
const eventProcessor = new TransformStream({
|
3000
|
+
transform(chunk, controller) {
|
3001
|
+
controller.enqueue(chunk);
|
3002
|
+
if (chunk.type === "error") {
|
3003
|
+
onError == null ? void 0 : onError({ error: chunk.error });
|
3004
|
+
}
|
3005
|
+
}
|
3006
|
+
});
|
3007
|
+
this.baseStream = stitchableStream.stream.pipeThrough(eventProcessor);
|
2998
3008
|
recordSpan({
|
2999
3009
|
name: "ai.streamObject",
|
3000
3010
|
attributes: selectTelemetryAttributes({
|
@@ -3338,25 +3348,26 @@ var DefaultStreamObjectResult = class {
|
|
3338
3348
|
experimental_providerMetadata: providerMetadata
|
3339
3349
|
}));
|
3340
3350
|
} catch (error2) {
|
3341
|
-
controller.error
|
3351
|
+
controller.enqueue({ type: "error", error: error2 });
|
3342
3352
|
} finally {
|
3343
3353
|
rootSpan.end();
|
3344
3354
|
}
|
3345
3355
|
}
|
3346
3356
|
})
|
3347
3357
|
);
|
3348
|
-
|
3358
|
+
stitchableStream.addStream(transformedStream);
|
3349
3359
|
}
|
3350
3360
|
}).catch((error) => {
|
3351
|
-
|
3361
|
+
stitchableStream.addStream(
|
3352
3362
|
new ReadableStream({
|
3353
3363
|
start(controller) {
|
3354
|
-
controller.
|
3364
|
+
controller.enqueue({ type: "error", error });
|
3365
|
+
controller.close();
|
3355
3366
|
}
|
3356
3367
|
})
|
3357
3368
|
);
|
3358
3369
|
}).finally(() => {
|
3359
|
-
|
3370
|
+
stitchableStream.close();
|
3360
3371
|
});
|
3361
3372
|
this.outputStrategy = outputStrategy;
|
3362
3373
|
}
|
@@ -3380,7 +3391,7 @@ var DefaultStreamObjectResult = class {
|
|
3380
3391
|
}
|
3381
3392
|
get partialObjectStream() {
|
3382
3393
|
return createAsyncIterableStream(
|
3383
|
-
this.
|
3394
|
+
this.baseStream.pipeThrough(
|
3384
3395
|
new TransformStream({
|
3385
3396
|
transform(chunk, controller) {
|
3386
3397
|
switch (chunk.type) {
|
@@ -3389,9 +3400,7 @@ var DefaultStreamObjectResult = class {
|
|
3389
3400
|
break;
|
3390
3401
|
case "text-delta":
|
3391
3402
|
case "finish":
|
3392
|
-
break;
|
3393
3403
|
case "error":
|
3394
|
-
controller.error(chunk.error);
|
3395
3404
|
break;
|
3396
3405
|
default: {
|
3397
3406
|
const _exhaustiveCheck = chunk;
|
@@ -3404,13 +3413,11 @@ var DefaultStreamObjectResult = class {
|
|
3404
3413
|
);
|
3405
3414
|
}
|
3406
3415
|
get elementStream() {
|
3407
|
-
return this.outputStrategy.createElementStream(
|
3408
|
-
this.stitchableStream.stream
|
3409
|
-
);
|
3416
|
+
return this.outputStrategy.createElementStream(this.baseStream);
|
3410
3417
|
}
|
3411
3418
|
get textStream() {
|
3412
3419
|
return createAsyncIterableStream(
|
3413
|
-
this.
|
3420
|
+
this.baseStream.pipeThrough(
|
3414
3421
|
new TransformStream({
|
3415
3422
|
transform(chunk, controller) {
|
3416
3423
|
switch (chunk.type) {
|
@@ -3419,9 +3426,7 @@ var DefaultStreamObjectResult = class {
|
|
3419
3426
|
break;
|
3420
3427
|
case "object":
|
3421
3428
|
case "finish":
|
3422
|
-
break;
|
3423
3429
|
case "error":
|
3424
|
-
controller.error(chunk.error);
|
3425
3430
|
break;
|
3426
3431
|
default: {
|
3427
3432
|
const _exhaustiveCheck = chunk;
|
@@ -3434,7 +3439,7 @@ var DefaultStreamObjectResult = class {
|
|
3434
3439
|
);
|
3435
3440
|
}
|
3436
3441
|
get fullStream() {
|
3437
|
-
return createAsyncIterableStream(this.
|
3442
|
+
return createAsyncIterableStream(this.baseStream);
|
3438
3443
|
}
|
3439
3444
|
pipeTextStreamToResponse(response, init) {
|
3440
3445
|
writeToServerResponse({
|