ai 6.0.0-beta.135 → 6.0.0-beta.137

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,17 @@
1
1
  # ai
2
2
 
3
+ ## 6.0.0-beta.137
4
+
5
+ ### Patch Changes
6
+
7
+ - 9ba4324: feat(ai): support SystemModelMessage[] in system and instructions properties
8
+
9
+ ## 6.0.0-beta.136
10
+
11
+ ### Patch Changes
12
+
13
+ - 3d83f38: chore(ai): improve addToolInputExamplesMiddleware
14
+
3
15
  ## 6.0.0-beta.135
4
16
 
5
17
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -902,7 +902,7 @@ type Prompt = {
902
902
  /**
903
903
  System message to include in the prompt. Can be used with `prompt` or `messages`.
904
904
  */
905
- system?: string | SystemModelMessage;
905
+ system?: string | SystemModelMessage | Array<SystemModelMessage>;
906
906
  } & ({
907
907
  /**
908
908
  A prompt. It can be either a text prompt or a list of messages.
@@ -1013,7 +1013,7 @@ type PrepareStepResult<TOOLS extends Record<string, Tool> = Record<string, Tool>
1013
1013
  model?: LanguageModel;
1014
1014
  toolChoice?: ToolChoice<NoInfer<TOOLS>>;
1015
1015
  activeTools?: Array<keyof NoInfer<TOOLS>>;
1016
- system?: string | SystemModelMessage;
1016
+ system?: string | SystemModelMessage | Array<SystemModelMessage>;
1017
1017
  messages?: Array<ModelMessage>;
1018
1018
  } | undefined;
1019
1019
 
@@ -1070,7 +1070,7 @@ declare const modelMessageSchema: z.ZodType<ModelMessage>;
1070
1070
  * @param options.error - The error that occurred while parsing the tool call.
1071
1071
  */
1072
1072
  type ToolCallRepairFunction<TOOLS extends ToolSet> = (options: {
1073
- system: string | SystemModelMessage | undefined;
1073
+ system: string | SystemModelMessage | Array<SystemModelMessage> | undefined;
1074
1074
  messages: ModelMessage[];
1075
1075
  toolCall: LanguageModelV3ToolCall;
1076
1076
  tools: TOOLS;
@@ -2637,7 +2637,7 @@ type ToolLoopAgentSettings<CALL_OPTIONS = never, TOOLS extends ToolSet = {}, OUT
2637
2637
  *
2638
2638
  * It can be a string, or, if you need to pass additional provider options (e.g. for caching), a `SystemModelMessage`.
2639
2639
  */
2640
- instructions?: string | SystemModelMessage;
2640
+ instructions?: string | SystemModelMessage | Array<SystemModelMessage>;
2641
2641
  /**
2642
2642
  The language model to use.
2643
2643
  */
@@ -4754,10 +4754,10 @@ declare function simulateStreamingMiddleware(): LanguageModelMiddleware;
4754
4754
  * property. The middleware serializes examples into the tool's description text.
4755
4755
  *
4756
4756
  * @param options - Configuration options for the middleware.
4757
- * @param options.examplesPrefix - A prefix to prepend before the examples.
4758
- * @param options.formatExample - Optional custom formatter for each example.
4757
+ * @param options.prefix - A prefix to prepend before the examples. Default: 'Input Examples:'
4758
+ * @param options.format - Optional custom formatter for each example.
4759
4759
  * Receives the example object and its index. Default: JSON.stringify(example.input)
4760
- * @param options.removeInputExamples - Whether to remove the inputExamples property
4760
+ * @param options.remove - Whether to remove the inputExamples property
4761
4761
  * after adding them to the description. Default: true
4762
4762
  *
4763
4763
  * @example
@@ -4766,30 +4766,28 @@ declare function simulateStreamingMiddleware(): LanguageModelMiddleware;
4766
4766
  *
4767
4767
  * const model = wrapLanguageModel({
4768
4768
  * model: yourModel,
4769
- * middleware: addToolInputExamplesMiddleware({
4770
- * examplesPrefix: 'Input Examples:',
4771
- * }),
4769
+ * middleware: addToolInputExamplesMiddleware(),
4772
4770
  * });
4773
4771
  * ```
4774
4772
  */
4775
- declare function addToolInputExamplesMiddleware({ examplesPrefix, formatExample, removeInputExamples, }: {
4773
+ declare function addToolInputExamplesMiddleware({ prefix, format, remove, }?: {
4776
4774
  /**
4777
- * A prefix/header to prepend before the examples.
4775
+ * A prefix to prepend before the examples.
4778
4776
  */
4779
- examplesPrefix: string;
4777
+ prefix?: string;
4780
4778
  /**
4781
4779
  * Optional custom formatter for each example.
4782
4780
  * Receives the example object and its index.
4783
4781
  * Default: JSON.stringify(example.input)
4784
4782
  */
4785
- formatExample?: (example: {
4783
+ format?: (example: {
4786
4784
  input: JSONObject;
4787
4785
  }, index: number) => string;
4788
4786
  /**
4789
4787
  * Whether to remove the inputExamples property after adding them to the description.
4790
4788
  * Default: true
4791
4789
  */
4792
- removeInputExamples?: boolean;
4790
+ remove?: boolean;
4793
4791
  }): LanguageModelMiddleware;
4794
4792
 
4795
4793
  /**
package/dist/index.d.ts CHANGED
@@ -902,7 +902,7 @@ type Prompt = {
902
902
  /**
903
903
  System message to include in the prompt. Can be used with `prompt` or `messages`.
904
904
  */
905
- system?: string | SystemModelMessage;
905
+ system?: string | SystemModelMessage | Array<SystemModelMessage>;
906
906
  } & ({
907
907
  /**
908
908
  A prompt. It can be either a text prompt or a list of messages.
@@ -1013,7 +1013,7 @@ type PrepareStepResult<TOOLS extends Record<string, Tool> = Record<string, Tool>
1013
1013
  model?: LanguageModel;
1014
1014
  toolChoice?: ToolChoice<NoInfer<TOOLS>>;
1015
1015
  activeTools?: Array<keyof NoInfer<TOOLS>>;
1016
- system?: string | SystemModelMessage;
1016
+ system?: string | SystemModelMessage | Array<SystemModelMessage>;
1017
1017
  messages?: Array<ModelMessage>;
1018
1018
  } | undefined;
1019
1019
 
@@ -1070,7 +1070,7 @@ declare const modelMessageSchema: z.ZodType<ModelMessage>;
1070
1070
  * @param options.error - The error that occurred while parsing the tool call.
1071
1071
  */
1072
1072
  type ToolCallRepairFunction<TOOLS extends ToolSet> = (options: {
1073
- system: string | SystemModelMessage | undefined;
1073
+ system: string | SystemModelMessage | Array<SystemModelMessage> | undefined;
1074
1074
  messages: ModelMessage[];
1075
1075
  toolCall: LanguageModelV3ToolCall;
1076
1076
  tools: TOOLS;
@@ -2637,7 +2637,7 @@ type ToolLoopAgentSettings<CALL_OPTIONS = never, TOOLS extends ToolSet = {}, OUT
2637
2637
  *
2638
2638
  * It can be a string, or, if you need to pass additional provider options (e.g. for caching), a `SystemModelMessage`.
2639
2639
  */
2640
- instructions?: string | SystemModelMessage;
2640
+ instructions?: string | SystemModelMessage | Array<SystemModelMessage>;
2641
2641
  /**
2642
2642
  The language model to use.
2643
2643
  */
@@ -4754,10 +4754,10 @@ declare function simulateStreamingMiddleware(): LanguageModelMiddleware;
4754
4754
  * property. The middleware serializes examples into the tool's description text.
4755
4755
  *
4756
4756
  * @param options - Configuration options for the middleware.
4757
- * @param options.examplesPrefix - A prefix to prepend before the examples.
4758
- * @param options.formatExample - Optional custom formatter for each example.
4757
+ * @param options.prefix - A prefix to prepend before the examples. Default: 'Input Examples:'
4758
+ * @param options.format - Optional custom formatter for each example.
4759
4759
  * Receives the example object and its index. Default: JSON.stringify(example.input)
4760
- * @param options.removeInputExamples - Whether to remove the inputExamples property
4760
+ * @param options.remove - Whether to remove the inputExamples property
4761
4761
  * after adding them to the description. Default: true
4762
4762
  *
4763
4763
  * @example
@@ -4766,30 +4766,28 @@ declare function simulateStreamingMiddleware(): LanguageModelMiddleware;
4766
4766
  *
4767
4767
  * const model = wrapLanguageModel({
4768
4768
  * model: yourModel,
4769
- * middleware: addToolInputExamplesMiddleware({
4770
- * examplesPrefix: 'Input Examples:',
4771
- * }),
4769
+ * middleware: addToolInputExamplesMiddleware(),
4772
4770
  * });
4773
4771
  * ```
4774
4772
  */
4775
- declare function addToolInputExamplesMiddleware({ examplesPrefix, formatExample, removeInputExamples, }: {
4773
+ declare function addToolInputExamplesMiddleware({ prefix, format, remove, }?: {
4776
4774
  /**
4777
- * A prefix/header to prepend before the examples.
4775
+ * A prefix to prepend before the examples.
4778
4776
  */
4779
- examplesPrefix: string;
4777
+ prefix?: string;
4780
4778
  /**
4781
4779
  * Optional custom formatter for each example.
4782
4780
  * Receives the example object and its index.
4783
4781
  * Default: JSON.stringify(example.input)
4784
4782
  */
4785
- formatExample?: (example: {
4783
+ format?: (example: {
4786
4784
  input: JSONObject;
4787
4785
  }, index: number) => string;
4788
4786
  /**
4789
4787
  * Whether to remove the inputExamples property after adding them to the description.
4790
4788
  * Default: true
4791
4789
  */
4792
- removeInputExamples?: boolean;
4790
+ remove?: boolean;
4793
4791
  }): LanguageModelMiddleware;
4794
4792
 
4795
4793
  /**
package/dist/index.js CHANGED
@@ -909,7 +909,7 @@ function detectMediaType({
909
909
  var import_provider_utils2 = require("@ai-sdk/provider-utils");
910
910
 
911
911
  // src/version.ts
912
- var VERSION = true ? "6.0.0-beta.135" : "0.0.0-test";
912
+ var VERSION = true ? "6.0.0-beta.137" : "0.0.0-test";
913
913
 
914
914
  // src/util/download/download.ts
915
915
  var download = async ({ url }) => {
@@ -1041,6 +1041,11 @@ function convertDataContentToUint8Array(content) {
1041
1041
  throw new InvalidDataContentError({ content });
1042
1042
  }
1043
1043
 
1044
+ // src/util/as-array.ts
1045
+ function asArray(value) {
1046
+ return value === void 0 ? [] : Array.isArray(value) ? value : [value];
1047
+ }
1048
+
1044
1049
  // src/prompt/convert-to-language-model-prompt.ts
1045
1050
  async function convertToLanguageModelPrompt({
1046
1051
  prompt,
@@ -1053,13 +1058,11 @@ async function convertToLanguageModelPrompt({
1053
1058
  supportedUrls
1054
1059
  );
1055
1060
  const messages = [
1056
- ...prompt.system != null ? typeof prompt.system === "string" ? [{ role: "system", content: prompt.system }] : [
1057
- {
1058
- role: "system",
1059
- content: prompt.system.content,
1060
- providerOptions: prompt.system.providerOptions
1061
- }
1062
- ] : [],
1061
+ ...prompt.system != null ? typeof prompt.system === "string" ? [{ role: "system", content: prompt.system }] : asArray(prompt.system).map((message) => ({
1062
+ role: "system",
1063
+ content: message.content,
1064
+ providerOptions: message.providerOptions
1065
+ })) : [],
1063
1066
  ...prompt.messages.map(
1064
1067
  (message) => convertToLanguageModelMessage({ message, downloadedAssets })
1065
1068
  )
@@ -1713,10 +1716,12 @@ async function standardizePrompt(prompt) {
1713
1716
  message: "prompt and messages cannot be defined at the same time"
1714
1717
  });
1715
1718
  }
1716
- if (prompt.system != null && typeof prompt.system !== "string" && "role" in prompt.system && prompt.system.role !== "system") {
1719
+ if (prompt.system != null && typeof prompt.system !== "string" && !asArray(prompt.system).every(
1720
+ (message) => typeof message === "object" && message !== null && "role" in message && message.role === "system"
1721
+ )) {
1717
1722
  throw new import_provider19.InvalidPromptError({
1718
1723
  prompt,
1719
- message: "system must be a string"
1724
+ message: "system must be a string, SystemModelMessage, or array of SystemModelMessage"
1720
1725
  });
1721
1726
  }
1722
1727
  let messages;
@@ -2019,11 +2024,6 @@ function addImageModelUsage(usage1, usage2) {
2019
2024
  };
2020
2025
  }
2021
2026
 
2022
- // src/util/as-array.ts
2023
- function asArray(value) {
2024
- return value === void 0 ? [] : Array.isArray(value) ? value : [value];
2025
- }
2026
-
2027
2027
  // src/util/retry-with-exponential-backoff.ts
2028
2028
  var import_provider21 = require("@ai-sdk/provider");
2029
2029
  var import_provider_utils7 = require("@ai-sdk/provider-utils");
@@ -9948,10 +9948,10 @@ function defaultFormatExample(example) {
9948
9948
  return JSON.stringify(example.input);
9949
9949
  }
9950
9950
  function addToolInputExamplesMiddleware({
9951
- examplesPrefix,
9952
- formatExample = defaultFormatExample,
9953
- removeInputExamples = true
9954
- }) {
9951
+ prefix = "Input Examples:",
9952
+ format = defaultFormatExample,
9953
+ remove = true
9954
+ } = {}) {
9955
9955
  return {
9956
9956
  specificationVersion: "v3",
9957
9957
  transformParams: async ({ params }) => {
@@ -9964,8 +9964,8 @@ function addToolInputExamplesMiddleware({
9964
9964
  if (tool2.type !== "function" || !((_a16 = tool2.inputExamples) == null ? void 0 : _a16.length)) {
9965
9965
  return tool2;
9966
9966
  }
9967
- const formattedExamples = tool2.inputExamples.map((example, index) => formatExample(example, index)).join("\n");
9968
- const examplesSection = `${examplesPrefix}
9967
+ const formattedExamples = tool2.inputExamples.map((example, index) => format(example, index)).join("\n");
9968
+ const examplesSection = `${prefix}
9969
9969
  ${formattedExamples}`;
9970
9970
  const toolDescription = tool2.description ? `${tool2.description}
9971
9971
 
@@ -9973,7 +9973,7 @@ ${examplesSection}` : examplesSection;
9973
9973
  return {
9974
9974
  ...tool2,
9975
9975
  description: toolDescription,
9976
- inputExamples: removeInputExamples ? void 0 : tool2.inputExamples
9976
+ inputExamples: remove ? void 0 : tool2.inputExamples
9977
9977
  };
9978
9978
  });
9979
9979
  return {