ai 7.0.132 → 7.0.134

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.132";
1177
+ const VERSION = "7.0.134";
1178
1178
  //#endregion
1179
1179
  //#region src/util/download/download.ts
1180
1180
  /**
@@ -12678,6 +12678,37 @@ var DefaultEmbedManyResult = class {
12678
12678
  }
12679
12679
  };
12680
12680
  //#endregion
12681
+ //#region src/decide/decision-state.ts
12682
+ function isDecisionStateParts(state) {
12683
+ return Array.isArray(state);
12684
+ }
12685
+ async function prepareDecisionState(state, abortSignal) {
12686
+ if (typeof state === "string") return [{
12687
+ type: "text",
12688
+ text: state
12689
+ }];
12690
+ if (!isDecisionStateParts(state)) return [{
12691
+ type: "json",
12692
+ value: state
12693
+ }];
12694
+ if (state.every((part) => part.type !== "file")) return state;
12695
+ const message = (await convertToLanguageModelPrompt({
12696
+ prompt: {
12697
+ instructions: void 0,
12698
+ messages: [{
12699
+ role: "user",
12700
+ content: state.filter((part) => part.type === "file")
12701
+ }]
12702
+ },
12703
+ supportedUrls: {},
12704
+ download: void 0,
12705
+ abortSignal
12706
+ }))[0];
12707
+ if (message.role !== "user") throw new Error("Expected user message.");
12708
+ let fileIndex = 0;
12709
+ return state.map((part) => part.type === "file" ? message.content[fileIndex++] : part);
12710
+ }
12711
+ //#endregion
12681
12712
  //#region src/decide/restricted-telemetry-dispatcher.ts
12682
12713
  function createRestrictedTelemetryDispatcher$1({ telemetry }) {
12683
12714
  const dispatcher = createTelemetryDispatcher({ telemetry });
@@ -12728,7 +12759,15 @@ function invalidInput(parameter, value, message) {
12728
12759
  });
12729
12760
  }
12730
12761
  function validateDecisionInput({ state, questions }) {
12731
- if (!isInput(state)) invalidInput("state", state, "must be a JSON-compatible string, object, or array");
12762
+ if (!(Array.isArray(state) ? Array.from(state).every((part) => {
12763
+ if (!isRecord(part)) return false;
12764
+ switch (part.type) {
12765
+ case "text": return textPartSchema.safeParse(part).success;
12766
+ case "file": return filePartSchema.safeParse(part).success;
12767
+ case "json": return isJSON(part.value);
12768
+ default: return false;
12769
+ }
12770
+ }) : (typeof state === "string" || isRecord(state)) && isJSON(state))) invalidInput("state", state, "must be a string, JSON object, or array of text, file, or json parts");
12732
12771
  if (!isRecord(questions) || Object.keys(questions).length === 0) invalidInput("questions", questions, "must be a nonempty question map");
12733
12772
  for (const [id, question] of Object.entries(questions)) {
12734
12773
  const parameter = `questions.${id}`;
@@ -12850,12 +12889,13 @@ async function decide({ model: modelArg, state, questions, maxRetries, abortSign
12850
12889
  callbacks: [onStart, telemetryDispatcher.onStart]
12851
12890
  });
12852
12891
  try {
12892
+ const preparedState = await prepareDecisionState(state, abortSignal);
12853
12893
  const modelCallEvent = {
12854
12894
  callId,
12855
12895
  operationId: "ai.decide.doDecide",
12856
12896
  provider: model.provider,
12857
12897
  modelId: model.modelId,
12858
- state,
12898
+ state: preparedState,
12859
12899
  questions
12860
12900
  };
12861
12901
  await notify({
@@ -12865,7 +12905,7 @@ async function decide({ model: modelArg, state, questions, maxRetries, abortSign
12865
12905
  const result = await retry(async () => {
12866
12906
  abortSignal?.throwIfAborted();
12867
12907
  return await model.doDecide({
12868
- state,
12908
+ state: preparedState,
12869
12909
  questions,
12870
12910
  abortSignal,
12871
12911
  headers: withUserAgentSuffix(headers ?? {}, `ai/${VERSION}`),
@@ -19753,8 +19793,8 @@ var AbstractChat = class {
19753
19793
  this.pendingApprovalMessageId = message.id;
19754
19794
  }
19755
19795
  if (this.activeResponse) this.activeResponse.state.message.parts = this.activeResponse.state.message.parts.map(updatePart);
19756
- if (this.status !== "streaming" && this.status !== "submitted" && this.sendAutomaticallyWhen) this.shouldSendAutomatically().then((shouldSend) => {
19757
- if (shouldSend) {
19796
+ if (this.status !== "streaming" && this.status !== "submitted" && this.sendAutomaticallyWhen) {
19797
+ if (await this.shouldSendAutomatically()) {
19758
19798
  const messageId = messageIndex === -1 ? this.lastMessage?.id : messages[messageIndex].id;
19759
19799
  this.makeRequestForToolApproval({
19760
19800
  messageId,
@@ -19762,7 +19802,7 @@ var AbstractChat = class {
19762
19802
  ...options
19763
19803
  });
19764
19804
  }
19765
- });
19805
+ }
19766
19806
  });
19767
19807
  this.addToolOutput = async ({ state, toolCallId, output, errorText, options }) => this.jobExecutor.run(async () => {
19768
19808
  const messages = this.state.messages;
@@ -19795,13 +19835,13 @@ var AbstractChat = class {
19795
19835
  parts: lastMessage.parts.map(updatePart)
19796
19836
  });
19797
19837
  if (this.activeResponse) this.activeResponse.state.message.parts = this.activeResponse.state.message.parts.map(updatePart);
19798
- if (this.status !== "streaming" && this.status !== "submitted" && this.sendAutomaticallyWhen) this.shouldSendAutomatically().then((shouldSend) => {
19799
- if (shouldSend) this.makeRequest({
19838
+ if (this.status !== "streaming" && this.status !== "submitted" && this.sendAutomaticallyWhen) {
19839
+ if (await this.shouldSendAutomatically()) this.makeRequest({
19800
19840
  trigger: "submit-message",
19801
19841
  messageId: this.lastMessage?.id,
19802
19842
  ...options
19803
19843
  });
19804
- });
19844
+ }
19805
19845
  });
19806
19846
  this.addToolResult = this.addToolOutput;
19807
19847
  this.stop = async () => {
@@ -19930,7 +19970,7 @@ var AbstractChat = class {
19930
19970
  const lastMessage = this.lastMessage;
19931
19971
  const responseMessageIndex = trigger === "submit-message" && messageId != null ? this.state.messages.findIndex((message) => message.id === messageId) : this.state.messages.length - 1;
19932
19972
  const responseMessage = responseMessageIndex === -1 ? lastMessage : this.state.messages[responseMessageIndex];
19933
- const resumableResponseMessage = trigger === "resume-stream" && responseMessage?.role === "assistant" && responseMessage.parts.some((part) => isToolUIPart(part) && (part.state === "input-streaming" || part.state === "approval-responded")) ? this.state.snapshot(responseMessage) : void 0;
19973
+ const resumableResponseMessage = trigger === "resume-stream" && responseMessage?.role === "assistant" && responseMessage.parts.some((part) => isToolUIPart(part) && (part.state === "input-streaming" || part.state === "input-available" && part.providerExecuted || part.state === "approval-responded")) ? this.state.snapshot(responseMessage) : void 0;
19934
19974
  const usesEarlierAssistantMessage = responseMessageIndex !== -1 && responseMessageIndex < this.state.messages.length - 1 && responseMessage?.role === "assistant";
19935
19975
  let isAbort = false;
19936
19976
  let isDisconnect = false;