@mastra/ai-sdk 1.1.2 → 1.1.3-alpha.0

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
@@ -6416,13 +6416,21 @@ async function handleChatStream({
6416
6416
  }
6417
6417
  }
6418
6418
  }
6419
- const mergedOptions = {
6420
- ...defaultOptions2,
6421
- ...rest,
6419
+ const { structuredOutput: restStructuredOutput, ...restOptions } = rest;
6420
+ const { structuredOutput: defaultStructuredOutput, ...defaultOptionsRest } = defaultOptions2 ?? {};
6421
+ const structuredOutput = restStructuredOutput ?? defaultStructuredOutput;
6422
+ const mergedProviderOptions = {
6423
+ ...defaultOptions2?.providerOptions,
6424
+ ...restOptions.providerOptions
6425
+ };
6426
+ const baseOptions = {
6427
+ ...defaultOptionsRest,
6428
+ ...restOptions,
6422
6429
  ...runId && { runId },
6423
- requestContext: requestContext || defaultOptions2?.requestContext
6430
+ requestContext: requestContext || defaultOptions2?.requestContext,
6431
+ ...Object.keys(mergedProviderOptions).length > 0 && { providerOptions: mergedProviderOptions }
6424
6432
  };
6425
- const result = resumeData ? await agentObj.resumeStream(resumeData, mergedOptions) : await agentObj.stream(messagesToSend, mergedOptions);
6433
+ const result = resumeData ? structuredOutput ? await agentObj.resumeStream(resumeData, { ...baseOptions, structuredOutput }) : await agentObj.resumeStream(resumeData, baseOptions) : structuredOutput ? await agentObj.stream(messagesToSend, { ...baseOptions, structuredOutput }) : await agentObj.stream(messagesToSend, baseOptions);
6426
6434
  return createUIMessageStream({
6427
6435
  originalMessages: messages,
6428
6436
  execute: async ({ writer }) => {
@@ -7143,6 +7151,13 @@ function createProcessorMiddleware(options) {
7143
7151
  messages: messageList.get.all.db(),
7144
7152
  messageList,
7145
7153
  state: {},
7154
+ result: {
7155
+ text: "",
7156
+ usage: { inputTokens: 0, outputTokens: 0, totalTokens: 0 },
7157
+ finishReason: "unknown",
7158
+ steps: []
7159
+ },
7160
+ retryCount: 0,
7146
7161
  requestContext,
7147
7162
  abort: (reason) => {
7148
7163
  throw new TripWire(reason || "Aborted by processor");
@@ -7277,10 +7292,23 @@ function createProcessorMiddleware(options) {
7277
7292
  if (!processor.processOutputResult) continue;
7278
7293
  try {
7279
7294
  const procState = processorStates.get(processor.id);
7295
+ const finishChunk = (procState?.streamParts ?? []).find((p) => p.type === "finish");
7296
+ const outputResult = {
7297
+ text: (procState?.streamParts ?? []).filter((p) => p.type === "text-delta").map((p) => p.payload?.text ?? "").join(""),
7298
+ usage: finishChunk?.payload?.output?.usage ?? {
7299
+ inputTokens: 0,
7300
+ outputTokens: 0,
7301
+ totalTokens: 0
7302
+ },
7303
+ finishReason: finishChunk?.payload?.stepResult?.reason ?? "unknown",
7304
+ steps: []
7305
+ };
7280
7306
  await processor.processOutputResult({
7281
7307
  messages: messageList.get.all.db(),
7282
7308
  messageList,
7283
7309
  state: procState?.customState ?? {},
7310
+ result: outputResult,
7311
+ retryCount: 0,
7284
7312
  requestContext,
7285
7313
  abort: (reason) => {
7286
7314
  throw new TripWire(reason || "Aborted by processor");