ai 4.1.48 → 4.1.49

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,11 @@
1
1
  # ai
2
2
 
3
+ ## 4.1.49
4
+
5
+ ### Patch Changes
6
+
7
+ - dc027d3: fix (ai/core): add reasoning support to appendResponseMessages
8
+
3
9
  ## 4.1.48
4
10
 
5
11
  ### Patch Changes
package/dist/index.js CHANGED
@@ -6180,7 +6180,7 @@ function appendResponseMessages({
6180
6180
  const lastMessage = clonedMessages[clonedMessages.length - 1];
6181
6181
  const isLastMessageAssistant = lastMessage.role === "assistant";
6182
6182
  switch (role) {
6183
- case "assistant":
6183
+ case "assistant": {
6184
6184
  let getToolInvocations2 = function(step) {
6185
6185
  return (typeof message.content === "string" ? [] : message.content.filter((part) => part.type === "tool-call")).map((call) => ({
6186
6186
  state: "call",
@@ -6191,19 +6191,74 @@ function appendResponseMessages({
6191
6191
  }));
6192
6192
  };
6193
6193
  var getToolInvocations = getToolInvocations2;
6194
- const textContent = typeof message.content === "string" ? message.content : message.content.filter((part) => part.type === "text").map((part) => part.text).join("");
6194
+ const parts = [];
6195
+ let textContent = "";
6196
+ let reasoningTextContent = void 0;
6197
+ if (typeof message.content === "string") {
6198
+ textContent = message.content;
6199
+ parts.push({
6200
+ type: "text",
6201
+ text: message.content
6202
+ });
6203
+ } else {
6204
+ let reasoningPart = void 0;
6205
+ for (const part of message.content) {
6206
+ switch (part.type) {
6207
+ case "text": {
6208
+ reasoningPart = void 0;
6209
+ textContent += part.text;
6210
+ parts.push({
6211
+ type: "text",
6212
+ text: part.text
6213
+ });
6214
+ break;
6215
+ }
6216
+ case "reasoning": {
6217
+ if (reasoningPart == null) {
6218
+ reasoningPart = {
6219
+ type: "reasoning",
6220
+ reasoning: "",
6221
+ details: []
6222
+ };
6223
+ parts.push(reasoningPart);
6224
+ }
6225
+ reasoningTextContent = (reasoningTextContent != null ? reasoningTextContent : "") + part.text;
6226
+ reasoningPart.reasoning += part.text;
6227
+ reasoningPart.details.push({
6228
+ type: "text",
6229
+ text: part.text,
6230
+ signature: part.signature
6231
+ });
6232
+ break;
6233
+ }
6234
+ case "redacted-reasoning": {
6235
+ if (reasoningPart == null) {
6236
+ reasoningPart = {
6237
+ type: "reasoning",
6238
+ reasoning: "",
6239
+ details: []
6240
+ };
6241
+ parts.push(reasoningPart);
6242
+ }
6243
+ reasoningPart.details.push({
6244
+ type: "redacted",
6245
+ data: part.data
6246
+ });
6247
+ break;
6248
+ }
6249
+ case "tool-call":
6250
+ break;
6251
+ }
6252
+ }
6253
+ }
6195
6254
  if (isLastMessageAssistant) {
6196
6255
  const maxStep = (0, import_ui_utils9.extractMaxToolInvocationStep)(
6197
6256
  lastMessage.toolInvocations
6198
6257
  );
6199
6258
  (_a16 = lastMessage.parts) != null ? _a16 : lastMessage.parts = [];
6200
6259
  lastMessage.content = textContent;
6201
- if (textContent.length > 0) {
6202
- lastMessage.parts.push({
6203
- type: "text",
6204
- text: textContent
6205
- });
6206
- }
6260
+ lastMessage.reasoning = reasoningTextContent;
6261
+ lastMessage.parts.push(...parts);
6207
6262
  lastMessage.toolInvocations = [
6208
6263
  ...(_b = lastMessage.toolInvocations) != null ? _b : [],
6209
6264
  ...getToolInvocations2(maxStep === void 0 ? 0 : maxStep + 1)
@@ -6221,9 +6276,10 @@ function appendResponseMessages({
6221
6276
  createdAt: currentDate(),
6222
6277
  // generate a createdAt date for the message, will be overridden by the client
6223
6278
  content: textContent,
6279
+ reasoning: reasoningTextContent,
6224
6280
  toolInvocations: getToolInvocations2(0),
6225
6281
  parts: [
6226
- ...textContent.length > 0 ? [{ type: "text", text: textContent }] : [],
6282
+ ...parts,
6227
6283
  ...getToolInvocations2(0).map((call) => ({
6228
6284
  type: "tool-invocation",
6229
6285
  toolInvocation: call
@@ -6232,6 +6288,7 @@ function appendResponseMessages({
6232
6288
  });
6233
6289
  }
6234
6290
  break;
6291
+ }
6235
6292
  case "tool": {
6236
6293
  (_c = lastMessage.toolInvocations) != null ? _c : lastMessage.toolInvocations = [];
6237
6294
  if (lastMessage.role !== "assistant") {