ai 4.0.31 → 4.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/CHANGELOG.md +12 -0
- package/dist/index.d.mts +7 -1
- package/dist/index.d.ts +7 -1
- package/dist/index.js +28 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +28 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,17 @@
|
|
1
1
|
# ai
|
2
2
|
|
3
|
+
## 4.0.33
|
4
|
+
|
5
|
+
### Patch Changes
|
6
|
+
|
7
|
+
- 5510ee7: feat (ai/core): add stopStream option to streamText transforms
|
8
|
+
|
9
|
+
## 4.0.32
|
10
|
+
|
11
|
+
### Patch Changes
|
12
|
+
|
13
|
+
- de66619: feat (ai/core): add tool call id to ToolExecution error
|
14
|
+
|
3
15
|
## 4.0.31
|
4
16
|
|
5
17
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
@@ -2134,9 +2134,13 @@ Enable streaming of tool call deltas as they are generated. Disabled by default.
|
|
2134
2134
|
experimental_toolCallStreaming?: boolean;
|
2135
2135
|
/**
|
2136
2136
|
Optional transformation that is applied to the stream.
|
2137
|
+
|
2138
|
+
@param stopStream - A function that stops the source stream.
|
2139
|
+
@param tools - The tools that are accessible to and can be called by the model. The model needs to support calling tools.
|
2137
2140
|
*/
|
2138
2141
|
experimental_transform?: (options: {
|
2139
2142
|
tools: TOOLS;
|
2143
|
+
stopStream: () => void;
|
2140
2144
|
}) => TransformStream<TextStreamPart<TOOLS>, TextStreamPart<TOOLS>>;
|
2141
2145
|
/**
|
2142
2146
|
Callback that is called for each chunk of the stream. The stream processing will pause until the callback promise is resolved.
|
@@ -2404,10 +2408,12 @@ declare class ToolExecutionError extends AISDKError {
|
|
2404
2408
|
private readonly [symbol$5];
|
2405
2409
|
readonly toolName: string;
|
2406
2410
|
readonly toolArgs: JSONValue;
|
2407
|
-
|
2411
|
+
readonly toolCallId: string;
|
2412
|
+
constructor({ toolArgs, toolName, toolCallId, cause, message, }: {
|
2408
2413
|
message?: string;
|
2409
2414
|
toolArgs: JSONValue;
|
2410
2415
|
toolName: string;
|
2416
|
+
toolCallId: string;
|
2411
2417
|
cause: unknown;
|
2412
2418
|
});
|
2413
2419
|
static isInstance(error: unknown): error is ToolExecutionError;
|
package/dist/index.d.ts
CHANGED
@@ -2134,9 +2134,13 @@ Enable streaming of tool call deltas as they are generated. Disabled by default.
|
|
2134
2134
|
experimental_toolCallStreaming?: boolean;
|
2135
2135
|
/**
|
2136
2136
|
Optional transformation that is applied to the stream.
|
2137
|
+
|
2138
|
+
@param stopStream - A function that stops the source stream.
|
2139
|
+
@param tools - The tools that are accessible to and can be called by the model. The model needs to support calling tools.
|
2137
2140
|
*/
|
2138
2141
|
experimental_transform?: (options: {
|
2139
2142
|
tools: TOOLS;
|
2143
|
+
stopStream: () => void;
|
2140
2144
|
}) => TransformStream<TextStreamPart<TOOLS>, TextStreamPart<TOOLS>>;
|
2141
2145
|
/**
|
2142
2146
|
Callback that is called for each chunk of the stream. The stream processing will pause until the callback promise is resolved.
|
@@ -2404,10 +2408,12 @@ declare class ToolExecutionError extends AISDKError {
|
|
2404
2408
|
private readonly [symbol$5];
|
2405
2409
|
readonly toolName: string;
|
2406
2410
|
readonly toolArgs: JSONValue;
|
2407
|
-
|
2411
|
+
readonly toolCallId: string;
|
2412
|
+
constructor({ toolArgs, toolName, toolCallId, cause, message, }: {
|
2408
2413
|
message?: string;
|
2409
2414
|
toolArgs: JSONValue;
|
2410
2415
|
toolName: string;
|
2416
|
+
toolCallId: string;
|
2411
2417
|
cause: unknown;
|
2412
2418
|
});
|
2413
2419
|
static isInstance(error: unknown): error is ToolExecutionError;
|
package/dist/index.js
CHANGED
@@ -2765,12 +2765,27 @@ function createStitchableStream() {
|
|
2765
2765
|
innerStreamReaders.push(innerStream.getReader());
|
2766
2766
|
waitForNewStream.resolve();
|
2767
2767
|
},
|
2768
|
+
/**
|
2769
|
+
* Gracefully close the outer stream. This will let the inner streams
|
2770
|
+
* finish processing and then close the outer stream.
|
2771
|
+
*/
|
2768
2772
|
close: () => {
|
2769
2773
|
isClosed = true;
|
2770
2774
|
waitForNewStream.resolve();
|
2771
2775
|
if (innerStreamReaders.length === 0) {
|
2772
2776
|
controller == null ? void 0 : controller.close();
|
2773
2777
|
}
|
2778
|
+
},
|
2779
|
+
/**
|
2780
|
+
* Immediately close the outer stream. This will cancel all inner streams
|
2781
|
+
* and close the outer stream.
|
2782
|
+
*/
|
2783
|
+
terminate: () => {
|
2784
|
+
isClosed = true;
|
2785
|
+
waitForNewStream.resolve();
|
2786
|
+
innerStreamReaders.forEach((reader) => reader.cancel());
|
2787
|
+
innerStreamReaders = [];
|
2788
|
+
controller == null ? void 0 : controller.close();
|
2774
2789
|
}
|
2775
2790
|
};
|
2776
2791
|
}
|
@@ -3368,6 +3383,7 @@ var ToolExecutionError = class extends import_provider12.AISDKError {
|
|
3368
3383
|
constructor({
|
3369
3384
|
toolArgs,
|
3370
3385
|
toolName,
|
3386
|
+
toolCallId,
|
3371
3387
|
cause,
|
3372
3388
|
message = `Error executing tool ${toolName}: ${(0, import_provider12.getErrorMessage)(cause)}`
|
3373
3389
|
}) {
|
@@ -3375,6 +3391,7 @@ var ToolExecutionError = class extends import_provider12.AISDKError {
|
|
3375
3391
|
this[_a9] = true;
|
3376
3392
|
this.toolArgs = toolArgs;
|
3377
3393
|
this.toolName = toolName;
|
3394
|
+
this.toolCallId = toolCallId;
|
3378
3395
|
}
|
3379
3396
|
static isInstance(error) {
|
3380
3397
|
return import_provider12.AISDKError.hasMarker(error, marker9);
|
@@ -3997,6 +4014,7 @@ async function executeTools({
|
|
3997
4014
|
return result2;
|
3998
4015
|
} catch (error) {
|
3999
4016
|
throw new ToolExecutionError({
|
4017
|
+
toolCallId,
|
4000
4018
|
toolName,
|
4001
4019
|
toolArgs: args,
|
4002
4020
|
cause: error
|
@@ -4340,6 +4358,7 @@ function runToolsTransformation({
|
|
4340
4358
|
toolResultsStreamController.enqueue({
|
4341
4359
|
type: "error",
|
4342
4360
|
error: new ToolExecutionError({
|
4361
|
+
toolCallId: toolCall.toolCallId,
|
4343
4362
|
toolName: toolCall.toolName,
|
4344
4363
|
toolArgs: toolCall.args,
|
4345
4364
|
cause: error
|
@@ -4451,7 +4470,7 @@ function streamText({
|
|
4451
4470
|
tools,
|
4452
4471
|
toolChoice,
|
4453
4472
|
toolCallStreaming,
|
4454
|
-
transform
|
4473
|
+
transform,
|
4455
4474
|
activeTools,
|
4456
4475
|
repairToolCall,
|
4457
4476
|
maxSteps,
|
@@ -4725,7 +4744,14 @@ var DefaultStreamTextResult = class {
|
|
4725
4744
|
this.closeStream = stitchableStream.close;
|
4726
4745
|
let stream = stitchableStream.stream;
|
4727
4746
|
if (transform) {
|
4728
|
-
stream = stream.pipeThrough(
|
4747
|
+
stream = stream.pipeThrough(
|
4748
|
+
transform({
|
4749
|
+
tools,
|
4750
|
+
stopStream() {
|
4751
|
+
stitchableStream.terminate();
|
4752
|
+
}
|
4753
|
+
})
|
4754
|
+
);
|
4729
4755
|
}
|
4730
4756
|
this.baseStream = stream.pipeThrough(createOutputTransformStream(output)).pipeThrough(eventProcessor);
|
4731
4757
|
const { maxRetries, retry } = prepareRetries({
|