ai 5.0.0-beta.26 → 5.0.0-beta.28

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
@@ -879,7 +879,8 @@ function prepareToolsAndToolChoice({
879
879
  type: "function",
880
880
  name: name16,
881
881
  description: tool3.description,
882
- inputSchema: asSchema(tool3.inputSchema).jsonSchema
882
+ inputSchema: asSchema(tool3.inputSchema).jsonSchema,
883
+ providerOptions: tool3.providerOptions
883
884
  };
884
885
  case "provider-defined":
885
886
  return {
@@ -8633,7 +8634,8 @@ var AbstractChat = class {
8633
8634
  onError,
8634
8635
  onToolCall,
8635
8636
  onFinish,
8636
- onData
8637
+ onData,
8638
+ sendAutomaticallyWhen
8637
8639
  }) {
8638
8640
  this.activeResponse = void 0;
8639
8641
  this.jobExecutor = new SerialJobExecutor();
@@ -8731,35 +8733,33 @@ var AbstractChat = class {
8731
8733
  tool: tool3,
8732
8734
  toolCallId,
8733
8735
  output
8734
- }) => {
8735
- this.jobExecutor.run(async () => {
8736
- const messages = this.state.messages;
8737
- const lastMessage = messages[messages.length - 1];
8738
- this.state.replaceMessage(messages.length - 1, {
8739
- ...lastMessage,
8740
- parts: lastMessage.parts.map(
8741
- (part) => isToolUIPart(part) && part.toolCallId === toolCallId ? { ...part, state: "output-available", output } : part
8742
- )
8743
- });
8744
- if (this.activeResponse) {
8745
- this.activeResponse.state.message.parts = this.activeResponse.state.message.parts.map(
8746
- (part) => isToolUIPart(part) && part.toolCallId === toolCallId ? {
8747
- ...part,
8748
- state: "output-available",
8749
- output,
8750
- errorText: void 0
8751
- } : part
8752
- );
8753
- }
8736
+ }) => this.jobExecutor.run(async () => {
8737
+ var _a16, _b;
8738
+ const messages = this.state.messages;
8739
+ const lastMessage = messages[messages.length - 1];
8740
+ this.state.replaceMessage(messages.length - 1, {
8741
+ ...lastMessage,
8742
+ parts: lastMessage.parts.map(
8743
+ (part) => isToolUIPart(part) && part.toolCallId === toolCallId ? { ...part, state: "output-available", output } : part
8744
+ )
8754
8745
  });
8755
- };
8756
- /**
8757
- * Checks if the assistant message can be submitted, i.e. if it
8758
- * has tool calls and all tool calls have results.
8759
- *
8760
- * @returns {boolean} True if the assistant message can be submitted, false otherwise.
8761
- */
8762
- this.canAssistantMessageBeSubmitted = () => isAssistantMessageWithCompletedToolCalls(this.lastMessage);
8746
+ if (this.activeResponse) {
8747
+ this.activeResponse.state.message.parts = this.activeResponse.state.message.parts.map(
8748
+ (part) => isToolUIPart(part) && part.toolCallId === toolCallId ? {
8749
+ ...part,
8750
+ state: "output-available",
8751
+ output,
8752
+ errorText: void 0
8753
+ } : part
8754
+ );
8755
+ }
8756
+ if (this.status !== "streaming" && this.status !== "submitted" && ((_a16 = this.sendAutomaticallyWhen) == null ? void 0 : _a16.call(this, { messages: this.state.messages }))) {
8757
+ this.makeRequest({
8758
+ trigger: "submit-message",
8759
+ messageId: (_b = this.lastMessage) == null ? void 0 : _b.id
8760
+ });
8761
+ }
8762
+ });
8763
8763
  /**
8764
8764
  * Abort the current request immediately, keep the generated tokens if any.
8765
8765
  */
@@ -8781,6 +8781,7 @@ var AbstractChat = class {
8781
8781
  this.onToolCall = onToolCall;
8782
8782
  this.onFinish = onFinish;
8783
8783
  this.onData = onData;
8784
+ this.sendAutomaticallyWhen = sendAutomaticallyWhen;
8784
8785
  }
8785
8786
  /**
8786
8787
  * Hook status:
@@ -8821,7 +8822,7 @@ var AbstractChat = class {
8821
8822
  body,
8822
8823
  messageId
8823
8824
  }) {
8824
- var _a16;
8825
+ var _a16, _b, _c;
8825
8826
  this.setStatus({ status: "submitted", error: void 0 });
8826
8827
  const lastMessage = this.lastMessage;
8827
8828
  try {
@@ -8908,21 +8909,17 @@ var AbstractChat = class {
8908
8909
  } finally {
8909
8910
  this.activeResponse = void 0;
8910
8911
  }
8912
+ if ((_b = this.sendAutomaticallyWhen) == null ? void 0 : _b.call(this, { messages: this.state.messages })) {
8913
+ await this.makeRequest({
8914
+ trigger: "submit-message",
8915
+ messageId: (_c = this.lastMessage) == null ? void 0 : _c.id,
8916
+ metadata,
8917
+ headers,
8918
+ body
8919
+ });
8920
+ }
8911
8921
  }
8912
8922
  };
8913
- function isAssistantMessageWithCompletedToolCalls(message) {
8914
- if (!message) {
8915
- return false;
8916
- }
8917
- if (message.role !== "assistant") {
8918
- return false;
8919
- }
8920
- const lastStepStartIndex = message.parts.reduce((lastIndex, part, index) => {
8921
- return part.type === "step-start" ? index : lastIndex;
8922
- }, -1);
8923
- const lastStepToolInvocations = message.parts.slice(lastStepStartIndex + 1).filter(isToolUIPart);
8924
- return lastStepToolInvocations.length > 0 && lastStepToolInvocations.every((part) => part.state === "output-available");
8925
- }
8926
8923
 
8927
8924
  // src/ui/convert-to-model-messages.ts
8928
8925
  function convertToModelMessages(messages, options) {
@@ -9095,6 +9092,24 @@ function convertToModelMessages(messages, options) {
9095
9092
  }
9096
9093
  var convertToCoreMessages = convertToModelMessages;
9097
9094
 
9095
+ // src/ui/last-assistant-message-is-complete-with-tool-calls.ts
9096
+ function lastAssistantMessageIsCompleteWithToolCalls({
9097
+ messages
9098
+ }) {
9099
+ const message = messages[messages.length - 1];
9100
+ if (!message) {
9101
+ return false;
9102
+ }
9103
+ if (message.role !== "assistant") {
9104
+ return false;
9105
+ }
9106
+ const lastStepStartIndex = message.parts.reduce((lastIndex, part, index) => {
9107
+ return part.type === "step-start" ? index : lastIndex;
9108
+ }, -1);
9109
+ const lastStepToolInvocations = message.parts.slice(lastStepStartIndex + 1).filter(isToolUIPart);
9110
+ return lastStepToolInvocations.length > 0 && lastStepToolInvocations.every((part) => part.state === "output-available");
9111
+ }
9112
+
9098
9113
  // src/ui/transform-text-to-ui-message-stream.ts
9099
9114
  function transformTextToUiMessageStream({
9100
9115
  stream
@@ -9341,6 +9356,7 @@ export {
9341
9356
  isDeepEqualData,
9342
9357
  isToolUIPart,
9343
9358
  jsonSchema2 as jsonSchema,
9359
+ lastAssistantMessageIsCompleteWithToolCalls,
9344
9360
  modelMessageSchema,
9345
9361
  parsePartialJson,
9346
9362
  pipeTextStreamToResponse,