ai 7.0.131 → 7.0.132

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.js CHANGED
@@ -1174,7 +1174,7 @@ function cloneValue(value) {
1174
1174
  }
1175
1175
  //#endregion
1176
1176
  //#region src/version.ts
1177
- const VERSION = "7.0.131";
1177
+ const VERSION = "7.0.132";
1178
1178
  //#endregion
1179
1179
  //#region src/util/download/download.ts
1180
1180
  /**
@@ -7422,9 +7422,9 @@ function toUIMessageChunk(part, { tools, sendReasoning = true, sendSources = fal
7422
7422
  * Converts a stream of `TextStreamPart<TOOLS>` chunks (as emitted by
7423
7423
  * `streamText`'s `stream`) into a stream of `UIMessageChunk`s suitable for
7424
7424
  * UI message streaming, including response message ID injection and
7425
- * `onEnd` handling.
7425
+ * step and stream end callbacks.
7426
7426
  */
7427
- function toUIMessageStream({ stream, tools, sendReasoning = true, sendSources = false, sendStart = true, sendFinish = true, onError = () => "An error occurred.", messageMetadata, originalMessages, generateMessageId, onEnd, onFinish }) {
7427
+ function toUIMessageStream({ stream, tools, sendReasoning = true, sendSources = false, sendStart = true, sendFinish = true, onError = () => "An error occurred.", messageMetadata, originalMessages, generateMessageId, onStepEnd, onStepFinish, onEnd, onFinish }) {
7428
7428
  let outcome = { status: "unknown" };
7429
7429
  let hasFatalFailure = false;
7430
7430
  const setSourceOutcome = (newOutcome) => {
@@ -7489,11 +7489,12 @@ function toUIMessageStream({ stream, tools, sendReasoning = true, sendSources =
7489
7489
  messageMetadata: messageMetadataValue,
7490
7490
  responseMessageId
7491
7491
  });
7492
- if (uiMessageChunk != null) controller.enqueue(uiMessageChunk);
7492
+ if (uiMessageChunk != null && part.type !== "finish-step") controller.enqueue(uiMessageChunk);
7493
7493
  if (messageMetadataValue != null && part.type !== "start" && part.type !== "finish") controller.enqueue({
7494
7494
  type: "message-metadata",
7495
7495
  messageMetadata: messageMetadataValue
7496
7496
  });
7497
+ if (uiMessageChunk != null && part.type === "finish-step") controller.enqueue(uiMessageChunk);
7497
7498
  if (part.type === "finish") setSourceOutcome({ status: "completed" });
7498
7499
  else if (part.type === "abort") setSourceOutcome({ status: "aborted" });
7499
7500
  else if (part.type === "error") setSourceOutcome({
@@ -7507,6 +7508,7 @@ function toUIMessageStream({ stream, tools, sendReasoning = true, sendSources =
7507
7508
  } })),
7508
7509
  messageId: responseMessageId ?? generateMessageId?.(),
7509
7510
  originalMessages,
7511
+ onStepEnd: onStepEnd ?? onStepFinish,
7510
7512
  onEnd: onEnd ?? onFinish,
7511
7513
  onError,
7512
7514
  getOutcome: () => outcome
@@ -10242,12 +10244,13 @@ var DefaultStreamTextResult = class {
10242
10244
  get output() {
10243
10245
  return this.getOutputPromise();
10244
10246
  }
10245
- toUIMessageStream({ originalMessages, generateMessageId, onEnd, onFinish, messageMetadata, sendReasoning, sendSources, sendStart, sendFinish, onError } = {}) {
10247
+ toUIMessageStream({ originalMessages, generateMessageId, onStepEnd, onStepFinish, onEnd, onFinish, messageMetadata, sendReasoning, sendSources, sendStart, sendFinish, onError } = {}) {
10246
10248
  return createAsyncIterableStream(toUIMessageStream({
10247
10249
  stream: this.stream,
10248
10250
  tools: this.tools,
10249
10251
  originalMessages,
10250
10252
  generateMessageId,
10253
+ onStepEnd: onStepEnd ?? onStepFinish,
10251
10254
  onEnd: onEnd ?? onFinish,
10252
10255
  messageMetadata,
10253
10256
  sendReasoning,
@@ -10257,12 +10260,13 @@ var DefaultStreamTextResult = class {
10257
10260
  onError
10258
10261
  }));
10259
10262
  }
10260
- pipeUIMessageStreamToResponse(response, { originalMessages, generateMessageId, onEnd, onFinish, messageMetadata, sendReasoning, sendSources, sendFinish, sendStart, onError, ...init } = {}) {
10263
+ pipeUIMessageStreamToResponse(response, { originalMessages, generateMessageId, onStepEnd, onStepFinish, onEnd, onFinish, messageMetadata, sendReasoning, sendSources, sendFinish, sendStart, onError, ...init } = {}) {
10261
10264
  return pipeUIMessageStreamToResponse({
10262
10265
  response,
10263
10266
  stream: this.toUIMessageStream({
10264
10267
  originalMessages,
10265
10268
  generateMessageId,
10269
+ onStepEnd: onStepEnd ?? onStepFinish,
10266
10270
  onEnd: onEnd ?? onFinish,
10267
10271
  messageMetadata,
10268
10272
  sendReasoning,
@@ -10281,11 +10285,12 @@ var DefaultStreamTextResult = class {
10281
10285
  ...init
10282
10286
  });
10283
10287
  }
10284
- toUIMessageStreamResponse({ originalMessages, generateMessageId, onEnd, onFinish, messageMetadata, sendReasoning, sendSources, sendFinish, sendStart, onError, ...init } = {}) {
10288
+ toUIMessageStreamResponse({ originalMessages, generateMessageId, onStepEnd, onStepFinish, onEnd, onFinish, messageMetadata, sendReasoning, sendSources, sendFinish, sendStart, onError, ...init } = {}) {
10285
10289
  return createUIMessageStreamResponse({
10286
10290
  stream: this.toUIMessageStream({
10287
10291
  originalMessages,
10288
10292
  generateMessageId,
10293
+ onStepEnd: onStepEnd ?? onStepFinish,
10289
10294
  onEnd: onEnd ?? onFinish,
10290
10295
  messageMetadata,
10291
10296
  sendReasoning,
@@ -11384,10 +11389,11 @@ async function validateUIMessagesForAgent(options) {
11384
11389
  * @param experimental_transform - The stream transformations. Optional.
11385
11390
  * @param onStepEnd - Callback that is called when each step ends. Optional.
11386
11391
  * @param onStepFinish - Deprecated alias for `onStepEnd`. Optional.
11392
+ * @param onUIMessageStepEnd - Callback with the accumulated UI message after each step. Optional.
11387
11393
  *
11388
11394
  * @returns The UI message stream.
11389
11395
  */
11390
- async function createAgentUIStream({ agent, uiMessages, convertDataPart, options, abortSignal, timeout, experimental_sandbox: sandbox, experimental_transform, onStepEnd, onStepFinish, ...uiMessageStreamOptions }) {
11396
+ async function createAgentUIStream({ agent, uiMessages, convertDataPart, options, abortSignal, timeout, experimental_sandbox: sandbox, experimental_transform, onStepEnd, onStepFinish, onUIMessageStepEnd, ...uiMessageStreamOptions }) {
11391
11397
  const validatedMessages = await validateUIMessagesForAgent({
11392
11398
  messages: uiMessages,
11393
11399
  tools: agent.tools
@@ -11409,6 +11415,7 @@ async function createAgentUIStream({ agent, uiMessages, convertDataPart, options
11409
11415
  return createAsyncIterableStream(toUIMessageStream({
11410
11416
  ...uiMessageStreamOptions,
11411
11417
  originalMessages,
11418
+ onStepEnd: onUIMessageStepEnd,
11412
11419
  stream: result.stream,
11413
11420
  tools: agent.tools
11414
11421
  }));
@@ -11428,6 +11435,7 @@ async function createAgentUIStream({ agent, uiMessages, convertDataPart, options
11428
11435
  * @param experimental_transform - Stream transformations. Optional.
11429
11436
  * @param onStepEnd - Callback that is called when each step ends. Optional.
11430
11437
  * @param onStepFinish - Deprecated alias for `onStepEnd`. Optional.
11438
+ * @param onUIMessageStepEnd - Callback with the accumulated UI message after each step. Optional.
11431
11439
  * @param headers - Additional headers for the response. Optional.
11432
11440
  * @param status - The status code for the response. Optional.
11433
11441
  * @param statusText - The status text for the response. Optional.
@@ -11462,6 +11470,7 @@ async function createAgentUIStreamResponse({ headers, status, statusText, keepAl
11462
11470
  * @param experimental_transform - Stream transformations. Optional.
11463
11471
  * @param onStepEnd - Callback that is called when each step ends. Optional.
11464
11472
  * @param onStepFinish - Deprecated alias for `onStepEnd`. Optional.
11473
+ * @param onUIMessageStepEnd - Callback with the accumulated UI message after each step. Optional.
11465
11474
  * @param headers - Additional headers for the response. Optional.
11466
11475
  * @param status - The status code for the response. Optional.
11467
11476
  * @param statusText - The status text for the response. Optional.