ai 3.3.4 → 3.3.5

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.mjs CHANGED
@@ -3071,6 +3071,13 @@ var DefaultStreamTextResult = class {
3071
3071
  });
3072
3072
  }
3073
3073
  toAIStream(callbacks = {}) {
3074
+ return this.toDataStream({ callbacks });
3075
+ }
3076
+ toDataStream({
3077
+ callbacks = {},
3078
+ getErrorMessage: getErrorMessage4 = () => ""
3079
+ // mask error messages for safety by default
3080
+ } = {}) {
3074
3081
  let aggregatedResponse = "";
3075
3082
  const callbackTransformer = new TransformStream({
3076
3083
  async start() {
@@ -3137,7 +3144,7 @@ var DefaultStreamTextResult = class {
3137
3144
  break;
3138
3145
  case "error":
3139
3146
  controller.enqueue(
3140
- formatStreamPart("error", JSON.stringify(chunk.error))
3147
+ formatStreamPart("error", getErrorMessage4(chunk.error))
3141
3148
  );
3142
3149
  break;
3143
3150
  case "finish":
@@ -3169,7 +3176,7 @@ var DefaultStreamTextResult = class {
3169
3176
  "Content-Type": "text/plain; charset=utf-8",
3170
3177
  ...init == null ? void 0 : init.headers
3171
3178
  });
3172
- const reader = this.toAIStream().getReader();
3179
+ const reader = this.toDataStream().getReader();
3173
3180
  const read = async () => {
3174
3181
  try {
3175
3182
  while (true) {
@@ -3220,7 +3227,8 @@ var DefaultStreamTextResult = class {
3220
3227
  statusText: "statusText" in options ? options.statusText : void 0
3221
3228
  };
3222
3229
  const data = options == null ? void 0 : "data" in options ? options.data : void 0;
3223
- const stream = data ? mergeStreams(data.stream, this.toAIStream()) : this.toAIStream();
3230
+ const getErrorMessage4 = options == null ? void 0 : "getErrorMessage" in options ? options.getErrorMessage : void 0;
3231
+ const stream = data ? mergeStreams(data.stream, this.toDataStream({ getErrorMessage: getErrorMessage4 })) : this.toDataStream({ getErrorMessage: getErrorMessage4 });
3224
3232
  return new Response(stream, {
3225
3233
  status: (_a9 = init == null ? void 0 : init.status) != null ? _a9 : 200,
3226
3234
  statusText: init == null ? void 0 : init.statusText,