ai 6.0.169 → 6.0.170

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
@@ -1143,7 +1143,7 @@ import {
1143
1143
  } from "@ai-sdk/provider-utils";
1144
1144
 
1145
1145
  // src/version.ts
1146
- var VERSION = true ? "6.0.169" : "0.0.0-test";
1146
+ var VERSION = true ? "6.0.170" : "0.0.0-test";
1147
1147
 
1148
1148
  // src/util/download/download.ts
1149
1149
  var download = async ({
@@ -2040,35 +2040,35 @@ var modelMessageSchema = z5.union([
2040
2040
  ]);
2041
2041
 
2042
2042
  // src/prompt/standardize-prompt.ts
2043
- async function standardizePrompt(prompt) {
2044
- if (prompt.prompt == null && prompt.messages == null) {
2043
+ async function standardizePrompt({
2044
+ allowSystemInMessages,
2045
+ system,
2046
+ prompt,
2047
+ messages
2048
+ }) {
2049
+ if (prompt == null && messages == null) {
2045
2050
  throw new InvalidPromptError2({
2046
2051
  prompt,
2047
2052
  message: "prompt or messages must be defined"
2048
2053
  });
2049
2054
  }
2050
- if (prompt.prompt != null && prompt.messages != null) {
2055
+ if (prompt != null && messages != null) {
2051
2056
  throw new InvalidPromptError2({
2052
2057
  prompt,
2053
2058
  message: "prompt and messages cannot be defined at the same time"
2054
2059
  });
2055
2060
  }
2056
- if (prompt.system != null && typeof prompt.system !== "string" && !asArray(prompt.system).every(
2057
- (message) => typeof message === "object" && message !== null && "role" in message && message.role === "system"
2058
- )) {
2061
+ if (typeof system !== "string" && !asArray(system).every((message) => message.role === "system")) {
2059
2062
  throw new InvalidPromptError2({
2060
2063
  prompt,
2061
2064
  message: "system must be a string, SystemModelMessage, or array of SystemModelMessage"
2062
2065
  });
2063
2066
  }
2064
- let messages;
2065
- if (prompt.prompt != null && typeof prompt.prompt === "string") {
2066
- messages = [{ role: "user", content: prompt.prompt }];
2067
- } else if (prompt.prompt != null && Array.isArray(prompt.prompt)) {
2068
- messages = prompt.prompt;
2069
- } else if (prompt.messages != null) {
2070
- messages = prompt.messages;
2071
- } else {
2067
+ if (prompt != null && typeof prompt === "string") {
2068
+ messages = [{ role: "user", content: prompt }];
2069
+ } else if (prompt != null && Array.isArray(prompt)) {
2070
+ messages = prompt;
2071
+ } else if (messages == null) {
2072
2072
  throw new InvalidPromptError2({
2073
2073
  prompt,
2074
2074
  message: "prompt or messages must be defined"
@@ -2080,6 +2080,19 @@ async function standardizePrompt(prompt) {
2080
2080
  message: "messages must not be empty"
2081
2081
  });
2082
2082
  }
2083
+ if (messages.some((message) => message.role === "system")) {
2084
+ if (allowSystemInMessages === false) {
2085
+ throw new InvalidPromptError2({
2086
+ prompt,
2087
+ message: "System messages are not allowed in the prompt or messages fields. Use the system option instead."
2088
+ });
2089
+ }
2090
+ if (allowSystemInMessages === void 0) {
2091
+ console.warn(
2092
+ "AI SDK Warning: System messages in the prompt or messages fields can be a security risk because they may enable prompt injection attacks. Use the system option instead when possible. Set allowSystemInMessages to true to suppress this warning, or false to throw an error."
2093
+ );
2094
+ }
2095
+ }
2083
2096
  const validationResult = await safeValidateTypes({
2084
2097
  value: messages,
2085
2098
  schema: z6.array(modelMessageSchema)
@@ -2091,10 +2104,7 @@ async function standardizePrompt(prompt) {
2091
2104
  cause: validationResult.error
2092
2105
  });
2093
2106
  }
2094
- return {
2095
- messages,
2096
- system: prompt.system
2097
- };
2107
+ return { messages, system };
2098
2108
  }
2099
2109
 
2100
2110
  // src/prompt/wrap-gateway-error.ts
@@ -4028,6 +4038,7 @@ async function generateText({
4028
4038
  system,
4029
4039
  prompt,
4030
4040
  messages,
4041
+ allowSystemInMessages,
4031
4042
  maxRetries: maxRetriesArg,
4032
4043
  abortSignal,
4033
4044
  timeout,
@@ -4084,7 +4095,8 @@ async function generateText({
4084
4095
  const initialPrompt = await standardizePrompt({
4085
4096
  system,
4086
4097
  prompt,
4087
- messages
4098
+ messages,
4099
+ allowSystemInMessages
4088
4100
  });
4089
4101
  const globalTelemetry = createGlobalTelemetry(telemetry == null ? void 0 : telemetry.integrations);
4090
4102
  await notify({
@@ -6374,6 +6386,7 @@ function streamText({
6374
6386
  system,
6375
6387
  prompt,
6376
6388
  messages,
6389
+ allowSystemInMessages,
6377
6390
  maxRetries,
6378
6391
  abortSignal,
6379
6392
  timeout,
@@ -6430,6 +6443,7 @@ function streamText({
6430
6443
  system,
6431
6444
  prompt,
6432
6445
  messages,
6446
+ allowSystemInMessages,
6433
6447
  tools,
6434
6448
  toolChoice,
6435
6449
  transforms: asArray(transform),
@@ -6536,6 +6550,7 @@ var DefaultStreamTextResult = class {
6536
6550
  system,
6537
6551
  prompt,
6538
6552
  messages,
6553
+ allowSystemInMessages,
6539
6554
  tools,
6540
6555
  toolChoice,
6541
6556
  transforms,
@@ -6927,7 +6942,8 @@ var DefaultStreamTextResult = class {
6927
6942
  const initialPrompt = await standardizePrompt({
6928
6943
  system,
6929
6944
  prompt,
6930
- messages
6945
+ messages,
6946
+ allowSystemInMessages
6931
6947
  });
6932
6948
  await notify({
6933
6949
  event: {
@@ -10057,6 +10073,7 @@ async function generateObject(options) {
10057
10073
  system,
10058
10074
  prompt,
10059
10075
  messages,
10076
+ allowSystemInMessages,
10060
10077
  maxRetries: maxRetriesArg,
10061
10078
  abortSignal,
10062
10079
  headers,
@@ -10141,7 +10158,8 @@ async function generateObject(options) {
10141
10158
  const standardizedPrompt = await standardizePrompt({
10142
10159
  system,
10143
10160
  prompt,
10144
- messages
10161
+ messages,
10162
+ allowSystemInMessages
10145
10163
  });
10146
10164
  const promptMessages = await convertToLanguageModelPrompt({
10147
10165
  prompt: standardizedPrompt,
@@ -10469,6 +10487,7 @@ function streamObject(options) {
10469
10487
  system,
10470
10488
  prompt,
10471
10489
  messages,
10490
+ allowSystemInMessages,
10472
10491
  maxRetries,
10473
10492
  abortSignal,
10474
10493
  headers,
@@ -10516,6 +10535,7 @@ function streamObject(options) {
10516
10535
  system,
10517
10536
  prompt,
10518
10537
  messages,
10538
+ allowSystemInMessages,
10519
10539
  schemaName,
10520
10540
  schemaDescription,
10521
10541
  providerOptions,
@@ -10540,6 +10560,7 @@ var DefaultStreamObjectResult = class {
10540
10560
  system,
10541
10561
  prompt,
10542
10562
  messages,
10563
+ allowSystemInMessages,
10543
10564
  schemaName,
10544
10565
  schemaDescription,
10545
10566
  providerOptions,
@@ -10610,7 +10631,8 @@ var DefaultStreamObjectResult = class {
10610
10631
  const standardizedPrompt = await standardizePrompt({
10611
10632
  system,
10612
10633
  prompt,
10613
- messages
10634
+ messages,
10635
+ allowSystemInMessages
10614
10636
  });
10615
10637
  const callOptions = {
10616
10638
  responseFormat: {