ai 4.0.19 → 4.0.20

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 CHANGED
@@ -1,5 +1,12 @@
1
1
  # ai
2
2
 
3
+ ## 4.0.20
4
+
5
+ ### Patch Changes
6
+
7
+ - da9d240: fix (ai/core): suppress errors caused by writing to closed stream
8
+ - 6f1bfde: fix (ai/core): invoke streamText tool call repair when tool cannot be found
9
+
3
10
  ## 4.0.19
4
11
 
5
12
  ### Patch Changes
package/dist/index.js CHANGED
@@ -95,15 +95,19 @@ function createDataStream({
95
95
  controller = controllerArg;
96
96
  }
97
97
  });
98
+ function safeEnqueue(data) {
99
+ try {
100
+ controller.enqueue(data);
101
+ } catch (error) {
102
+ }
103
+ }
98
104
  try {
99
105
  const result = execute({
100
106
  writeData(data) {
101
- controller.enqueue((0, import_ui_utils.formatDataStreamPart)("data", [data]));
107
+ safeEnqueue((0, import_ui_utils.formatDataStreamPart)("data", [data]));
102
108
  },
103
109
  writeMessageAnnotation(annotation) {
104
- controller.enqueue(
105
- (0, import_ui_utils.formatDataStreamPart)("message_annotations", [annotation])
106
- );
110
+ safeEnqueue((0, import_ui_utils.formatDataStreamPart)("message_annotations", [annotation]));
107
111
  },
108
112
  merge(streamArg) {
109
113
  ongoingStreamPromises.push(
@@ -113,10 +117,10 @@ function createDataStream({
113
117
  const { done, value } = await reader.read();
114
118
  if (done)
115
119
  break;
116
- controller.enqueue(value);
120
+ safeEnqueue(value);
117
121
  }
118
122
  })().catch((error) => {
119
- controller.enqueue((0, import_ui_utils.formatDataStreamPart)("error", onError(error)));
123
+ safeEnqueue((0, import_ui_utils.formatDataStreamPart)("error", onError(error)));
120
124
  })
121
125
  );
122
126
  },
@@ -125,12 +129,12 @@ function createDataStream({
125
129
  if (result) {
126
130
  ongoingStreamPromises.push(
127
131
  result.catch((error) => {
128
- controller.enqueue((0, import_ui_utils.formatDataStreamPart)("error", onError(error)));
132
+ safeEnqueue((0, import_ui_utils.formatDataStreamPart)("error", onError(error)));
129
133
  })
130
134
  );
131
135
  }
132
136
  } catch (error) {
133
- controller.enqueue((0, import_ui_utils.formatDataStreamPart)("error", onError(error)));
137
+ safeEnqueue((0, import_ui_utils.formatDataStreamPart)("error", onError(error)));
134
138
  }
135
139
  const waitForStreams = new Promise(async (resolve) => {
136
140
  while (ongoingStreamPromises.length > 0) {
@@ -139,7 +143,10 @@ function createDataStream({
139
143
  resolve();
140
144
  });
141
145
  waitForStreams.finally(() => {
142
- controller.close();
146
+ try {
147
+ controller.close();
148
+ } catch (error) {
149
+ }
143
150
  });
144
151
  return stream;
145
152
  }
@@ -4167,25 +4174,6 @@ function runToolsTransformation({
4167
4174
  break;
4168
4175
  }
4169
4176
  case "tool-call": {
4170
- const toolName = chunk.toolName;
4171
- if (tools == null) {
4172
- toolResultsStreamController.enqueue({
4173
- type: "error",
4174
- error: new NoSuchToolError({ toolName: chunk.toolName })
4175
- });
4176
- break;
4177
- }
4178
- const tool2 = tools[toolName];
4179
- if (tool2 == null) {
4180
- toolResultsStreamController.enqueue({
4181
- type: "error",
4182
- error: new NoSuchToolError({
4183
- toolName: chunk.toolName,
4184
- availableTools: Object.keys(tools)
4185
- })
4186
- });
4187
- break;
4188
- }
4189
4177
  try {
4190
4178
  const toolCall = await parseToolCall({
4191
4179
  toolCall: chunk,
@@ -4195,6 +4183,7 @@ function runToolsTransformation({
4195
4183
  messages
4196
4184
  });
4197
4185
  controller.enqueue(toolCall);
4186
+ const tool2 = tools[toolCall.toolName];
4198
4187
  if (tool2.execute != null) {
4199
4188
  const toolExecutionId = (0, import_ui_utils7.generateId)();
4200
4189
  outstandingToolResults.add(toolExecutionId);