ai 5.0.183 → 5.0.185
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 +14 -0
- package/dist/index.d.mts +11 -2
- package/dist/index.d.ts +11 -2
- package/dist/index.js +45 -21
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +45 -21
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +21 -1
- package/dist/internal/index.d.ts +21 -1
- package/dist/internal/index.js +29 -17
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +29 -17
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -687,7 +687,7 @@ import {
|
|
|
687
687
|
} from "@ai-sdk/provider-utils";
|
|
688
688
|
|
|
689
689
|
// src/version.ts
|
|
690
|
-
var VERSION = true ? "5.0.
|
|
690
|
+
var VERSION = true ? "5.0.185" : "0.0.0-test";
|
|
691
691
|
|
|
692
692
|
// src/util/download/download.ts
|
|
693
693
|
var download = async ({
|
|
@@ -1364,33 +1364,35 @@ var modelMessageSchema = z5.union([
|
|
|
1364
1364
|
var coreMessageSchema = modelMessageSchema;
|
|
1365
1365
|
|
|
1366
1366
|
// src/prompt/standardize-prompt.ts
|
|
1367
|
-
async function standardizePrompt(
|
|
1368
|
-
|
|
1367
|
+
async function standardizePrompt({
|
|
1368
|
+
allowSystemInMessages,
|
|
1369
|
+
system,
|
|
1370
|
+
prompt,
|
|
1371
|
+
messages
|
|
1372
|
+
}) {
|
|
1373
|
+
if (prompt == null && messages == null) {
|
|
1369
1374
|
throw new InvalidPromptError2({
|
|
1370
1375
|
prompt,
|
|
1371
1376
|
message: "prompt or messages must be defined"
|
|
1372
1377
|
});
|
|
1373
1378
|
}
|
|
1374
|
-
if (prompt
|
|
1379
|
+
if (prompt != null && messages != null) {
|
|
1375
1380
|
throw new InvalidPromptError2({
|
|
1376
1381
|
prompt,
|
|
1377
1382
|
message: "prompt and messages cannot be defined at the same time"
|
|
1378
1383
|
});
|
|
1379
1384
|
}
|
|
1380
|
-
if (
|
|
1385
|
+
if (system != null && typeof system !== "string") {
|
|
1381
1386
|
throw new InvalidPromptError2({
|
|
1382
1387
|
prompt,
|
|
1383
1388
|
message: "system must be a string"
|
|
1384
1389
|
});
|
|
1385
1390
|
}
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
} else if (prompt.messages != null) {
|
|
1392
|
-
messages = prompt.messages;
|
|
1393
|
-
} else {
|
|
1391
|
+
if (prompt != null && typeof prompt === "string") {
|
|
1392
|
+
messages = [{ role: "user", content: prompt }];
|
|
1393
|
+
} else if (prompt != null && Array.isArray(prompt)) {
|
|
1394
|
+
messages = prompt;
|
|
1395
|
+
} else if (messages == null) {
|
|
1394
1396
|
throw new InvalidPromptError2({
|
|
1395
1397
|
prompt,
|
|
1396
1398
|
message: "prompt or messages must be defined"
|
|
@@ -1402,6 +1404,19 @@ async function standardizePrompt(prompt) {
|
|
|
1402
1404
|
message: "messages must not be empty"
|
|
1403
1405
|
});
|
|
1404
1406
|
}
|
|
1407
|
+
if (messages.some((message) => message.role === "system")) {
|
|
1408
|
+
if (allowSystemInMessages === false) {
|
|
1409
|
+
throw new InvalidPromptError2({
|
|
1410
|
+
prompt,
|
|
1411
|
+
message: "System messages are not allowed in the prompt or messages fields. Use the system option instead."
|
|
1412
|
+
});
|
|
1413
|
+
}
|
|
1414
|
+
if (allowSystemInMessages === void 0) {
|
|
1415
|
+
console.warn(
|
|
1416
|
+
"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."
|
|
1417
|
+
);
|
|
1418
|
+
}
|
|
1419
|
+
}
|
|
1405
1420
|
const validationResult = await safeValidateTypes({
|
|
1406
1421
|
value: messages,
|
|
1407
1422
|
schema: z6.array(modelMessageSchema)
|
|
@@ -1413,10 +1428,7 @@ async function standardizePrompt(prompt) {
|
|
|
1413
1428
|
cause: validationResult.error
|
|
1414
1429
|
});
|
|
1415
1430
|
}
|
|
1416
|
-
return {
|
|
1417
|
-
messages,
|
|
1418
|
-
system: prompt.system
|
|
1419
|
-
};
|
|
1431
|
+
return { messages, system };
|
|
1420
1432
|
}
|
|
1421
1433
|
|
|
1422
1434
|
// src/prompt/wrap-gateway-error.ts
|
|
@@ -2170,6 +2182,7 @@ async function generateText({
|
|
|
2170
2182
|
system,
|
|
2171
2183
|
prompt,
|
|
2172
2184
|
messages,
|
|
2185
|
+
allowSystemInMessages,
|
|
2173
2186
|
maxRetries: maxRetriesArg,
|
|
2174
2187
|
abortSignal,
|
|
2175
2188
|
headers,
|
|
@@ -2211,7 +2224,8 @@ async function generateText({
|
|
|
2211
2224
|
const initialPrompt = await standardizePrompt({
|
|
2212
2225
|
system,
|
|
2213
2226
|
prompt,
|
|
2214
|
-
messages
|
|
2227
|
+
messages,
|
|
2228
|
+
allowSystemInMessages
|
|
2215
2229
|
});
|
|
2216
2230
|
const tracer = getTracer(telemetry);
|
|
2217
2231
|
try {
|
|
@@ -4470,6 +4484,7 @@ function streamText({
|
|
|
4470
4484
|
system,
|
|
4471
4485
|
prompt,
|
|
4472
4486
|
messages,
|
|
4487
|
+
allowSystemInMessages,
|
|
4473
4488
|
maxRetries,
|
|
4474
4489
|
abortSignal,
|
|
4475
4490
|
headers,
|
|
@@ -4509,6 +4524,7 @@ function streamText({
|
|
|
4509
4524
|
system,
|
|
4510
4525
|
prompt,
|
|
4511
4526
|
messages,
|
|
4527
|
+
allowSystemInMessages,
|
|
4512
4528
|
tools,
|
|
4513
4529
|
toolChoice,
|
|
4514
4530
|
transforms: asArray(transform),
|
|
@@ -4607,6 +4623,7 @@ var DefaultStreamTextResult = class {
|
|
|
4607
4623
|
system,
|
|
4608
4624
|
prompt,
|
|
4609
4625
|
messages,
|
|
4626
|
+
allowSystemInMessages,
|
|
4610
4627
|
tools,
|
|
4611
4628
|
toolChoice,
|
|
4612
4629
|
transforms,
|
|
@@ -4944,7 +4961,8 @@ var DefaultStreamTextResult = class {
|
|
|
4944
4961
|
const initialPrompt = await standardizePrompt({
|
|
4945
4962
|
system,
|
|
4946
4963
|
prompt,
|
|
4947
|
-
messages
|
|
4964
|
+
messages,
|
|
4965
|
+
allowSystemInMessages
|
|
4948
4966
|
});
|
|
4949
4967
|
const stepInputMessages = [
|
|
4950
4968
|
...initialPrompt.messages,
|
|
@@ -6982,6 +7000,7 @@ async function generateObject(options) {
|
|
|
6982
7000
|
system,
|
|
6983
7001
|
prompt,
|
|
6984
7002
|
messages,
|
|
7003
|
+
allowSystemInMessages,
|
|
6985
7004
|
maxRetries: maxRetriesArg,
|
|
6986
7005
|
abortSignal,
|
|
6987
7006
|
headers,
|
|
@@ -7065,7 +7084,8 @@ async function generateObject(options) {
|
|
|
7065
7084
|
const standardizedPrompt = await standardizePrompt({
|
|
7066
7085
|
system,
|
|
7067
7086
|
prompt,
|
|
7068
|
-
messages
|
|
7087
|
+
messages,
|
|
7088
|
+
allowSystemInMessages
|
|
7069
7089
|
});
|
|
7070
7090
|
const promptMessages = await convertToLanguageModelPrompt({
|
|
7071
7091
|
prompt: standardizedPrompt,
|
|
@@ -7387,6 +7407,7 @@ function streamObject(options) {
|
|
|
7387
7407
|
system,
|
|
7388
7408
|
prompt,
|
|
7389
7409
|
messages,
|
|
7410
|
+
allowSystemInMessages,
|
|
7390
7411
|
maxRetries,
|
|
7391
7412
|
abortSignal,
|
|
7392
7413
|
headers,
|
|
@@ -7434,6 +7455,7 @@ function streamObject(options) {
|
|
|
7434
7455
|
system,
|
|
7435
7456
|
prompt,
|
|
7436
7457
|
messages,
|
|
7458
|
+
allowSystemInMessages,
|
|
7437
7459
|
schemaName,
|
|
7438
7460
|
schemaDescription,
|
|
7439
7461
|
providerOptions,
|
|
@@ -7458,6 +7480,7 @@ var DefaultStreamObjectResult = class {
|
|
|
7458
7480
|
system,
|
|
7459
7481
|
prompt,
|
|
7460
7482
|
messages,
|
|
7483
|
+
allowSystemInMessages,
|
|
7461
7484
|
schemaName,
|
|
7462
7485
|
schemaDescription,
|
|
7463
7486
|
providerOptions,
|
|
@@ -7526,7 +7549,8 @@ var DefaultStreamObjectResult = class {
|
|
|
7526
7549
|
const standardizedPrompt = await standardizePrompt({
|
|
7527
7550
|
system,
|
|
7528
7551
|
prompt,
|
|
7529
|
-
messages
|
|
7552
|
+
messages,
|
|
7553
|
+
allowSystemInMessages
|
|
7530
7554
|
});
|
|
7531
7555
|
const callOptions = {
|
|
7532
7556
|
responseFormat: {
|