ai 6.0.0-beta.42 → 6.0.0-beta.44

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
@@ -720,7 +720,7 @@ import {
720
720
  } from "@ai-sdk/provider-utils";
721
721
 
722
722
  // src/version.ts
723
- var VERSION = true ? "6.0.0-beta.42" : "0.0.0-test";
723
+ var VERSION = true ? "6.0.0-beta.44" : "0.0.0-test";
724
724
 
725
725
  // src/util/download/download.ts
726
726
  var download = async ({ url }) => {
@@ -6307,16 +6307,16 @@ function convertToModelMessages(messages, options) {
6307
6307
  }
6308
6308
  var convertToCoreMessages = convertToModelMessages;
6309
6309
 
6310
- // src/agent/agent.ts
6311
- var Agent = class {
6310
+ // src/agent/basic-agent.ts
6311
+ var BasicAgent = class {
6312
6312
  constructor(settings) {
6313
6313
  this.settings = settings;
6314
6314
  }
6315
6315
  /**
6316
- * The name of the agent.
6316
+ * The id of the agent.
6317
6317
  */
6318
- get name() {
6319
- return this.settings.name;
6318
+ get id() {
6319
+ return this.settings.id;
6320
6320
  }
6321
6321
  /**
6322
6322
  * The tools that the agent can use.
@@ -8401,6 +8401,85 @@ var object = ({
8401
8401
  };
8402
8402
  };
8403
8403
 
8404
+ // src/generate-text/prune-messages.ts
8405
+ function pruneMessages({
8406
+ messages,
8407
+ reasoning = "none",
8408
+ toolCalls = [],
8409
+ emptyMessages = "remove"
8410
+ }) {
8411
+ if (reasoning === "all" || reasoning === "before-last-message") {
8412
+ messages = messages.map((message, messageIndex) => {
8413
+ if (message.role !== "assistant" || typeof message.content === "string" || reasoning === "before-last-message" && messageIndex === messages.length - 1) {
8414
+ return message;
8415
+ }
8416
+ return {
8417
+ ...message,
8418
+ content: message.content.filter((part) => part.type !== "reasoning")
8419
+ };
8420
+ });
8421
+ }
8422
+ if (toolCalls === "none") {
8423
+ toolCalls = [];
8424
+ } else if (toolCalls === "all") {
8425
+ toolCalls = [{ type: "all" }];
8426
+ } else if (toolCalls === "before-last-message") {
8427
+ toolCalls = [{ type: "before-last-message" }];
8428
+ } else if (typeof toolCalls === "string") {
8429
+ toolCalls = [{ type: toolCalls }];
8430
+ }
8431
+ for (const toolCall of toolCalls) {
8432
+ const keepLastMessagesCount = toolCall.type === "all" ? void 0 : toolCall.type === "before-last-message" ? 1 : Number(
8433
+ toolCall.type.slice("before-last-".length).slice(0, -"-messages".length)
8434
+ );
8435
+ const keptToolCallIds = /* @__PURE__ */ new Set();
8436
+ const keptApprovalIds = /* @__PURE__ */ new Set();
8437
+ if (keepLastMessagesCount != null) {
8438
+ for (const message of messages.slice(0, -keepLastMessagesCount)) {
8439
+ if ((message.role === "assistant" || message.role === "tool") && typeof message.content !== "string") {
8440
+ for (const part of message.content) {
8441
+ if (part.type === "tool-call" || part.type === "tool-result") {
8442
+ keptToolCallIds.add(part.toolCallId);
8443
+ } else if (part.type === "tool-approval-request" || part.type === "tool-approval-response") {
8444
+ keptApprovalIds.add(part.approvalId);
8445
+ }
8446
+ }
8447
+ }
8448
+ }
8449
+ }
8450
+ messages = messages.map((message, messageIndex) => {
8451
+ if (message.role !== "assistant" && message.role !== "tool" || typeof message.content === "string" || keepLastMessagesCount && messageIndex >= messages.length - keepLastMessagesCount) {
8452
+ return message;
8453
+ }
8454
+ const toolCallIdToToolName = {};
8455
+ const approvalIdToToolName = {};
8456
+ return {
8457
+ ...message,
8458
+ content: message.content.filter((part) => {
8459
+ if (part.type !== "tool-call" && part.type !== "tool-result" && part.type !== "tool-approval-request" && part.type !== "tool-approval-response") {
8460
+ return true;
8461
+ }
8462
+ if (part.type === "tool-call") {
8463
+ toolCallIdToToolName[part.toolCallId] = part.toolName;
8464
+ } else if (part.type === "tool-approval-request") {
8465
+ approvalIdToToolName[part.approvalId] = toolCallIdToToolName[part.toolCallId];
8466
+ }
8467
+ if ((part.type === "tool-call" || part.type === "tool-result") && keptToolCallIds.has(part.toolCallId) || (part.type === "tool-approval-request" || part.type === "tool-approval-response") && keptApprovalIds.has(part.approvalId)) {
8468
+ return true;
8469
+ }
8470
+ return toolCall.tools != null && !toolCall.tools.includes(
8471
+ part.type === "tool-call" || part.type === "tool-result" ? part.toolName : approvalIdToToolName[part.approvalId]
8472
+ );
8473
+ })
8474
+ };
8475
+ });
8476
+ }
8477
+ if (emptyMessages === "remove") {
8478
+ messages = messages.filter((message) => message.content.length > 0);
8479
+ }
8480
+ return messages;
8481
+ }
8482
+
8404
8483
  // src/generate-text/smooth-stream.ts
8405
8484
  import { delay as originalDelay } from "@ai-sdk/provider-utils";
8406
8485
  import { InvalidArgumentError as InvalidArgumentError2 } from "@ai-sdk/provider";
@@ -10884,11 +10963,11 @@ export {
10884
10963
  AISDKError18 as AISDKError,
10885
10964
  APICallError,
10886
10965
  AbstractChat,
10887
- Agent,
10966
+ BasicAgent,
10888
10967
  DefaultChatTransport,
10889
10968
  DownloadError,
10890
10969
  EmptyResponseBodyError,
10891
- Agent as Experimental_Agent,
10970
+ BasicAgent as Experimental_Agent,
10892
10971
  HttpChatTransport,
10893
10972
  InvalidArgumentError,
10894
10973
  InvalidDataContentError,
@@ -10971,6 +11050,7 @@ export {
10971
11050
  parsePartialJson,
10972
11051
  pipeTextStreamToResponse,
10973
11052
  pipeUIMessageStreamToResponse,
11053
+ pruneMessages,
10974
11054
  readUIMessageStream,
10975
11055
  safeValidateUIMessages,
10976
11056
  simulateReadableStream,