ai 7.0.159 → 7.0.161
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 +27 -0
- package/dist/index.d.ts +22 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +123 -67
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts.map +1 -1
- package/dist/internal/index.js +33 -14
- package/dist/internal/index.js.map +1 -1
- package/docs/03-agents/04-loop-control.mdx +29 -1
- package/docs/03-ai-sdk-core/60-telemetry.mdx +32 -1
- package/docs/03-ai-sdk-harnesses/02-harness-agent.mdx +55 -0
- package/docs/07-reference/01-ai-sdk-core/01-generate-text.mdx +1 -1
- package/docs/07-reference/01-ai-sdk-core/02-stream-text.mdx +1 -1
- package/docs/07-reference/01-ai-sdk-core/16-tool-loop-agent.mdx +2 -2
- package/package.json +11 -11
- package/src/generate-text/generate-text.ts +9 -1
- package/src/generate-text/generated-file.ts +7 -4
- package/src/generate-text/smooth-stream.ts +1 -1
- package/src/generate-text/steering.ts +56 -3
- package/src/generate-text/stream-text.ts +9 -1
- package/src/prompt/clone-model-message.ts +53 -17
- package/src/prompt/content-part.ts +4 -2
- package/src/prompt/data-content.ts +10 -8
- package/src/prompt/file-part-data.ts +9 -5
- package/src/ui/process-ui-message-stream.ts +4 -2
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.js";
|
|
2
2
|
import { GatewayAuthenticationError, GatewayError, createGateway, gateway, gateway as gateway$1 } from "@ai-sdk/gateway";
|
|
3
|
-
import { DEFAULT_MAX_DOWNLOAD_SIZE, DelayedPromise, DownloadError, DownloadError as DownloadError$1, EXPERIMENTAL_EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL, EXPERIMENTAL_EMBEDDING_MODEL_PROVIDER_OPTIONS_TRANSFORMER, asArray, asSchema, asSchema as asSchema$1, cancelResponseBody, convertAsyncIteratorToReadableStream, convertBase64ToUint8Array, convertUint8ArrayToBase64, createIdGenerator, createIdGenerator as createIdGenerator$1, delay, detectMediaType, dynamicTool, executeTool, experimental_getToolCaller, experimental_toolCaller, fetchUntrustedUrl, filterNullable, generateId, generateId as generateId$1, getErrorMessage, getRuntimeEnvironmentUserAgent, getWebSocketConstructor, isAbortError, isBuffer, isExecutableTool, isFullMediaType, isNonNullable, isProviderReference, isProviderStreamError, isUrlSupported, jsonSchema, jsonSchema as jsonSchema$1, lazySchema, normalizeHeaders, parseJsonEventStream, parseJsonEventStream as parseJsonEventStream$1, readResponseWithSizeLimit, readWebSocketMessageText, resolve, retryWithExponentialBackoff, safeParseJSON, safeValidateTypes, toWebSocketUrl, tool, tool as tool$1, validateTypes, waitForWebSocketBufferDrain, withUserAgentSuffix, zodSchema, zodSchema as zodSchema$1 } from "@ai-sdk/provider-utils";
|
|
3
|
+
import { DEFAULT_MAX_DOWNLOAD_SIZE, DelayedPromise, DownloadError, DownloadError as DownloadError$1, EXPERIMENTAL_EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL, EXPERIMENTAL_EMBEDDING_MODEL_PROVIDER_OPTIONS_TRANSFORMER, asArray, asSchema, asSchema as asSchema$1, cancelResponseBody, convertAsyncIteratorToReadableStream, convertBase64ToUint8Array, convertUint8ArrayToBase64, createIdGenerator, createIdGenerator as createIdGenerator$1, delay, detectMediaType, dynamicTool, executeTool, experimental_getToolCaller, experimental_toolCaller, fetchUntrustedUrl, filterNullable, generateId, generateId as generateId$1, getErrorMessage, getRuntimeEnvironmentUserAgent, getWebSocketConstructor, isAbortError, isArrayBuffer, isBuffer, isExecutableTool, isFullMediaType, isNonNullable, isProviderReference, isProviderStreamError, isUint8Array, isUrlSupported, jsonSchema, jsonSchema as jsonSchema$1, lazySchema, normalizeHeaders, parseJsonEventStream, parseJsonEventStream as parseJsonEventStream$1, readResponseWithSizeLimit, readWebSocketMessageText, resolve, retryWithExponentialBackoff, safeParseJSON, safeValidateTypes, toWebSocketUrl, tool, tool as tool$1, validateTypes, waitForWebSocketBufferDrain, withUserAgentSuffix, zodSchema, zodSchema as zodSchema$1 } from "@ai-sdk/provider-utils";
|
|
4
4
|
import { AISDKError, AISDKError as AISDKError$1, APICallError, APICallError as APICallError$1, EmptyResponseBodyError, EmptyResponseBodyError as EmptyResponseBodyError$1, Experimental_DecisionRefusalError, Experimental_DecisionRefusalError as Experimental_DecisionRefusalError$1, Experimental_DecisionUnsupportedQuestionTypeError, Experimental_DecisionUnsupportedQuestionTypeError as Experimental_DecisionUnsupportedQuestionTypeError$1, InvalidPromptError, InvalidPromptError as InvalidPromptError$1, InvalidResponseDataError, InvalidResponseDataError as InvalidResponseDataError$1, JSONParseError, JSONParseError as JSONParseError$1, LoadAPIKeyError, LoadSettingError, NoContentGeneratedError, NoSuchModelError, NoSuchModelError as NoSuchModelError$1, NoSuchProviderReferenceError, TooManyEmbeddingValuesForCallError, TypeValidationError, TypeValidationError as TypeValidationError$1, UnsupportedFunctionalityError, UnsupportedFunctionalityError as UnsupportedFunctionalityError$1, getErrorMessage as getErrorMessage$1, isJSONArray, isJSONObject } from "@ai-sdk/provider";
|
|
5
5
|
import { array, boolean, custom, discriminatedUnion, enum as enum$1, instanceof as instanceof$1, lazy, literal, looseObject, never, null as null$1, number, object, record, string, union, unknown } from "zod/v4";
|
|
6
6
|
//#region src/error/invalid-argument-error.ts
|
|
@@ -1162,20 +1162,52 @@ function asEvaluationModel(model) {
|
|
|
1162
1162
|
* currently rejects URL objects, which are valid file/image prompt payloads.
|
|
1163
1163
|
*/
|
|
1164
1164
|
function cloneModelMessages(messages) {
|
|
1165
|
-
return messages
|
|
1166
|
-
}
|
|
1167
|
-
function cloneValue(value) {
|
|
1168
|
-
if (value
|
|
1169
|
-
if (
|
|
1170
|
-
if (value instanceof
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1165
|
+
return cloneValue(messages, /* @__PURE__ */ new Map());
|
|
1166
|
+
}
|
|
1167
|
+
function cloneValue(value, seen) {
|
|
1168
|
+
if (value == null || typeof value !== "object") return value;
|
|
1169
|
+
if (seen.has(value)) return seen.get(value);
|
|
1170
|
+
if (value instanceof URL) {
|
|
1171
|
+
const copy = new URL(value.href);
|
|
1172
|
+
seen.set(value, copy);
|
|
1173
|
+
return copy;
|
|
1174
|
+
}
|
|
1175
|
+
if (Array.isArray(value)) {
|
|
1176
|
+
const copy = new Array(value.length);
|
|
1177
|
+
seen.set(value, copy);
|
|
1178
|
+
value.forEach((item, index) => {
|
|
1179
|
+
copy[index] = cloneValue(item, seen);
|
|
1180
|
+
});
|
|
1181
|
+
return copy;
|
|
1182
|
+
}
|
|
1183
|
+
if (isUint8Array(value)) {
|
|
1184
|
+
const copy = new Uint8Array(value);
|
|
1185
|
+
seen.set(value, copy);
|
|
1186
|
+
return copy;
|
|
1187
|
+
}
|
|
1188
|
+
if (isArrayBuffer(value)) {
|
|
1189
|
+
const copy = new Uint8Array(value).slice().buffer;
|
|
1190
|
+
seen.set(value, copy);
|
|
1191
|
+
return copy;
|
|
1192
|
+
}
|
|
1193
|
+
if (value instanceof Date || Object.prototype.toString.call(value) === "[object Date]") try {
|
|
1194
|
+
const copy = new Date(Date.prototype.getTime.call(value));
|
|
1195
|
+
seen.set(value, copy);
|
|
1196
|
+
return copy;
|
|
1197
|
+
} catch {}
|
|
1198
|
+
const copy = {};
|
|
1199
|
+
seen.set(value, copy);
|
|
1200
|
+
for (const [key, val] of Object.entries(value)) Object.defineProperty(copy, key, {
|
|
1201
|
+
value: cloneValue(val, seen),
|
|
1202
|
+
writable: true,
|
|
1203
|
+
enumerable: true,
|
|
1204
|
+
configurable: true
|
|
1205
|
+
});
|
|
1206
|
+
return copy;
|
|
1175
1207
|
}
|
|
1176
1208
|
//#endregion
|
|
1177
1209
|
//#region src/version.ts
|
|
1178
|
-
const VERSION = "7.0.
|
|
1210
|
+
const VERSION = "7.0.161";
|
|
1179
1211
|
//#endregion
|
|
1180
1212
|
//#region src/util/download/download.ts
|
|
1181
1213
|
/**
|
|
@@ -1266,6 +1298,42 @@ function mergeObjects(base, overrides) {
|
|
|
1266
1298
|
return result;
|
|
1267
1299
|
}
|
|
1268
1300
|
//#endregion
|
|
1301
|
+
//#region src/prompt/data-content.ts
|
|
1302
|
+
/**
|
|
1303
|
+
* Converts data content to a base64-encoded string.
|
|
1304
|
+
*
|
|
1305
|
+
* @param content - Data content to convert.
|
|
1306
|
+
* @returns Base64-encoded string.
|
|
1307
|
+
*/
|
|
1308
|
+
function convertDataContentToBase64String(content) {
|
|
1309
|
+
if (typeof content === "string") return content;
|
|
1310
|
+
return convertUint8ArrayToBase64(convertDataContentToUint8Array(content));
|
|
1311
|
+
}
|
|
1312
|
+
/**
|
|
1313
|
+
* Converts data content to a Uint8Array.
|
|
1314
|
+
*
|
|
1315
|
+
* @param content - Data content to convert.
|
|
1316
|
+
* @returns Uint8Array.
|
|
1317
|
+
*/
|
|
1318
|
+
function convertDataContentToUint8Array(content) {
|
|
1319
|
+
if (isUint8Array(content)) {
|
|
1320
|
+
if (content instanceof Uint8Array) return content;
|
|
1321
|
+
const { buffer, byteOffset, byteLength } = content;
|
|
1322
|
+
return new Uint8Array(buffer, byteOffset, byteLength);
|
|
1323
|
+
}
|
|
1324
|
+
if (typeof content === "string") try {
|
|
1325
|
+
return convertBase64ToUint8Array(content);
|
|
1326
|
+
} catch (error) {
|
|
1327
|
+
throw new InvalidDataContentError({
|
|
1328
|
+
message: "Invalid data content. Content string is not a base64-encoded media.",
|
|
1329
|
+
content,
|
|
1330
|
+
cause: error
|
|
1331
|
+
});
|
|
1332
|
+
}
|
|
1333
|
+
if (isArrayBuffer(content)) return new Uint8Array(content);
|
|
1334
|
+
throw new InvalidDataContentError({ content });
|
|
1335
|
+
}
|
|
1336
|
+
//#endregion
|
|
1269
1337
|
//#region src/prompt/split-data-url.ts
|
|
1270
1338
|
function splitDataUrl(dataUrl) {
|
|
1271
1339
|
try {
|
|
@@ -1318,17 +1386,10 @@ function convertUrlStringToFilePartData(content) {
|
|
|
1318
1386
|
return result;
|
|
1319
1387
|
}
|
|
1320
1388
|
function convertInlineDataToFilePartData(content) {
|
|
1321
|
-
if (content
|
|
1389
|
+
if (isUint8Array(content) || isArrayBuffer(content)) return {
|
|
1322
1390
|
data: {
|
|
1323
1391
|
type: "data",
|
|
1324
|
-
data: content
|
|
1325
|
-
},
|
|
1326
|
-
mediaType: void 0
|
|
1327
|
-
};
|
|
1328
|
-
if (content instanceof ArrayBuffer) return {
|
|
1329
|
-
data: {
|
|
1330
|
-
type: "data",
|
|
1331
|
-
data: new Uint8Array(content)
|
|
1392
|
+
data: convertDataContentToUint8Array(content)
|
|
1332
1393
|
},
|
|
1333
1394
|
mediaType: void 0
|
|
1334
1395
|
};
|
|
@@ -1384,6 +1445,7 @@ function convertToLanguageModelV4FilePart(content) {
|
|
|
1384
1445
|
} catch {
|
|
1385
1446
|
return convertInlineDataToFilePartData(content);
|
|
1386
1447
|
}
|
|
1448
|
+
if (isUint8Array(content) || isArrayBuffer(content)) return convertInlineDataToFilePartData(content);
|
|
1387
1449
|
if (isProviderReference(content)) return {
|
|
1388
1450
|
data: {
|
|
1389
1451
|
type: "reference",
|
|
@@ -2399,9 +2461,8 @@ function collectToolApprovals({ messages }) {
|
|
|
2399
2461
|
//#region src/generate-text/generated-file.ts
|
|
2400
2462
|
var DefaultGeneratedFile = class {
|
|
2401
2463
|
constructor({ data, mediaType, providerMetadata }) {
|
|
2402
|
-
|
|
2403
|
-
this.
|
|
2404
|
-
this.uint8ArrayData = isUint8Array ? data : void 0;
|
|
2464
|
+
this.base64Data = typeof data === "string" ? data : void 0;
|
|
2465
|
+
this.uint8ArrayData = typeof data === "string" ? void 0 : convertDataContentToUint8Array(data);
|
|
2405
2466
|
this.mediaType = mediaType;
|
|
2406
2467
|
this.providerMetadata = providerMetadata;
|
|
2407
2468
|
}
|
|
@@ -4429,11 +4490,25 @@ var DefaultSteering = class {
|
|
|
4429
4490
|
constructor() {
|
|
4430
4491
|
this.state = "idle";
|
|
4431
4492
|
this.pending = [];
|
|
4493
|
+
this.queued = [];
|
|
4432
4494
|
this.taken = [];
|
|
4433
4495
|
this.outcomes = /* @__PURE__ */ new Map();
|
|
4434
4496
|
}
|
|
4435
4497
|
steer(message, options) {
|
|
4436
|
-
|
|
4498
|
+
return this.add({
|
|
4499
|
+
message,
|
|
4500
|
+
id: options?.id,
|
|
4501
|
+
target: this.pending
|
|
4502
|
+
});
|
|
4503
|
+
}
|
|
4504
|
+
queue(message, options) {
|
|
4505
|
+
return this.add({
|
|
4506
|
+
message,
|
|
4507
|
+
id: options?.id,
|
|
4508
|
+
target: this.queued
|
|
4509
|
+
});
|
|
4510
|
+
}
|
|
4511
|
+
add({ message, id = generateSteeringId(), target }) {
|
|
4437
4512
|
const existingOutcome = this.outcomes.get(id);
|
|
4438
4513
|
if (existingOutcome != null) return existingOutcome;
|
|
4439
4514
|
const userMessage = typeof message === "string" ? {
|
|
@@ -4446,7 +4521,7 @@ var DefaultSteering = class {
|
|
|
4446
4521
|
message: userMessage,
|
|
4447
4522
|
reason: "finished"
|
|
4448
4523
|
}) : new Promise((resolve) => {
|
|
4449
|
-
|
|
4524
|
+
target.push({
|
|
4450
4525
|
id,
|
|
4451
4526
|
message: userMessage,
|
|
4452
4527
|
resolve
|
|
@@ -4464,6 +4539,12 @@ var DefaultSteering = class {
|
|
|
4464
4539
|
this.state = "running";
|
|
4465
4540
|
return {
|
|
4466
4541
|
hasPendingMessages: () => this.state === "running" && this.pending.length > 0,
|
|
4542
|
+
promoteQueuedMessage: () => {
|
|
4543
|
+
const next = this.state === "running" ? this.queued.shift() : void 0;
|
|
4544
|
+
if (next == null) return false;
|
|
4545
|
+
this.pending.push(next);
|
|
4546
|
+
return true;
|
|
4547
|
+
},
|
|
4467
4548
|
takeMessages: () => {
|
|
4468
4549
|
if (this.state !== "running") return [];
|
|
4469
4550
|
this.taken = [...this.taken, ...this.pending];
|
|
@@ -4495,9 +4576,14 @@ var DefaultSteering = class {
|
|
|
4495
4576
|
},
|
|
4496
4577
|
end: (reason) => {
|
|
4497
4578
|
if (this.state !== "running") return;
|
|
4498
|
-
const notDelivered = [
|
|
4579
|
+
const notDelivered = [
|
|
4580
|
+
...this.taken,
|
|
4581
|
+
...this.pending,
|
|
4582
|
+
...this.queued
|
|
4583
|
+
];
|
|
4499
4584
|
this.taken = [];
|
|
4500
4585
|
this.pending = [];
|
|
4586
|
+
this.queued = [];
|
|
4501
4587
|
this.state = "ended";
|
|
4502
4588
|
for (const { id, message, resolve } of notDelivered) resolve({
|
|
4503
4589
|
type: "not-delivered",
|
|
@@ -5297,7 +5383,8 @@ async function generateTextInternal({ model: modelArg, tools, toolChoice, instru
|
|
|
5297
5383
|
return false;
|
|
5298
5384
|
}
|
|
5299
5385
|
if (clientToolCalls.length === 0 && pendingDeferredToolCalls.size === 0) {
|
|
5300
|
-
|
|
5386
|
+
const isTruncated = steps[steps.length - 1].finishReason === "length" || steps[steps.length - 1].finishReason === "content-filter";
|
|
5387
|
+
if (!steeringRun?.hasPendingMessages() && (isTruncated || !steeringRun?.promoteQueuedMessage())) return false;
|
|
5301
5388
|
if (steps[steps.length - 1].finishReason === "error") {
|
|
5302
5389
|
steeringEndReason = "error";
|
|
5303
5390
|
return false;
|
|
@@ -7021,12 +7108,13 @@ function processUIMessageStream({ stream, messageMetadataSchema, dataPartSchemas
|
|
|
7021
7108
|
onError?.(new Error(chunk.errorText));
|
|
7022
7109
|
break;
|
|
7023
7110
|
default: if (isDataUIMessageChunk(chunk)) {
|
|
7024
|
-
|
|
7111
|
+
const dataPartSchema = dataPartSchemas?.[chunk.type.slice(5)];
|
|
7112
|
+
if (dataPartSchema != null) {
|
|
7025
7113
|
const partIdx = state.message.parts.findIndex((p) => "id" in p && "data" in p && p.id === chunk.id && p.type === chunk.type);
|
|
7026
7114
|
const actualPartIdx = partIdx >= 0 ? partIdx : state.message.parts.length;
|
|
7027
7115
|
await validateTypes({
|
|
7028
7116
|
value: chunk.data,
|
|
7029
|
-
schema:
|
|
7117
|
+
schema: dataPartSchema,
|
|
7030
7118
|
context: {
|
|
7031
7119
|
field: `message.parts[${actualPartIdx}].data`,
|
|
7032
7120
|
entityName: chunk.type,
|
|
@@ -10149,7 +10237,8 @@ var DefaultStreamTextResult = class {
|
|
|
10149
10237
|
return false;
|
|
10150
10238
|
}
|
|
10151
10239
|
if (clientToolCalls.length === 0 && pendingDeferredToolCalls.size === 0) {
|
|
10152
|
-
|
|
10240
|
+
const isTruncated = stepFinishReason === "length" || stepFinishReason === "content-filter";
|
|
10241
|
+
if (!steeringRun?.hasPendingMessages() && (isTruncated || !steeringRun?.promoteQueuedMessage())) return false;
|
|
10153
10242
|
if (stepFinishReason === "error") {
|
|
10154
10243
|
steeringEndReason = "error";
|
|
10155
10244
|
return false;
|
|
@@ -11743,39 +11832,6 @@ function setOwn(object, key, value) {
|
|
|
11743
11832
|
});
|
|
11744
11833
|
}
|
|
11745
11834
|
//#endregion
|
|
11746
|
-
//#region src/prompt/data-content.ts
|
|
11747
|
-
/**
|
|
11748
|
-
* Converts data content to a base64-encoded string.
|
|
11749
|
-
*
|
|
11750
|
-
* @param content - Data content to convert.
|
|
11751
|
-
* @returns Base64-encoded string.
|
|
11752
|
-
*/
|
|
11753
|
-
function convertDataContentToBase64String(content) {
|
|
11754
|
-
if (typeof content === "string") return content;
|
|
11755
|
-
if (content instanceof ArrayBuffer) return convertUint8ArrayToBase64(new Uint8Array(content));
|
|
11756
|
-
return convertUint8ArrayToBase64(content);
|
|
11757
|
-
}
|
|
11758
|
-
/**
|
|
11759
|
-
* Converts data content to a Uint8Array.
|
|
11760
|
-
*
|
|
11761
|
-
* @param content - Data content to convert.
|
|
11762
|
-
* @returns Uint8Array.
|
|
11763
|
-
*/
|
|
11764
|
-
function convertDataContentToUint8Array(content) {
|
|
11765
|
-
if (content instanceof Uint8Array) return content;
|
|
11766
|
-
if (typeof content === "string") try {
|
|
11767
|
-
return convertBase64ToUint8Array(content);
|
|
11768
|
-
} catch (error) {
|
|
11769
|
-
throw new InvalidDataContentError({
|
|
11770
|
-
message: "Invalid data content. Content string is not a base64-encoded media.",
|
|
11771
|
-
content,
|
|
11772
|
-
cause: error
|
|
11773
|
-
});
|
|
11774
|
-
}
|
|
11775
|
-
if (content instanceof ArrayBuffer) return new Uint8Array(content);
|
|
11776
|
-
throw new InvalidDataContentError({ content });
|
|
11777
|
-
}
|
|
11778
|
-
//#endregion
|
|
11779
11835
|
//#region src/generate-image/generate-image.ts
|
|
11780
11836
|
const gatewayCostMetadataKeys = [
|
|
11781
11837
|
"cost",
|
|
@@ -15151,7 +15207,7 @@ function smoothStream({ delayInMs = 10, chunking = "word", _internal: { delay: d
|
|
|
15151
15207
|
const match = chunking(buffer);
|
|
15152
15208
|
if (match == null) return null;
|
|
15153
15209
|
if (!match.length) throw new Error(`Chunking function must return a non-empty string.`);
|
|
15154
|
-
if (!buffer.startsWith(match)) throw new Error(`Chunking function must return a match that is a prefix of the buffer. Received: "${match}"
|
|
15210
|
+
if (!buffer.startsWith(match)) throw new Error(`Chunking function must return a match that is a prefix of the buffer. Received: "${match}" which is not a prefix of buffer "${buffer}"`);
|
|
15155
15211
|
return match;
|
|
15156
15212
|
};
|
|
15157
15213
|
else {
|
|
@@ -16486,8 +16542,8 @@ function wrapProvider({ provider, languageModelMiddleware, imageModelMiddleware
|
|
|
16486
16542
|
//#region src/prompt/content-part.ts
|
|
16487
16543
|
const fileInlineDataSchema = z.union([
|
|
16488
16544
|
z.string(),
|
|
16489
|
-
z.
|
|
16490
|
-
z.
|
|
16545
|
+
z.custom(isUint8Array, { message: "Must be a Uint8Array" }),
|
|
16546
|
+
z.custom(isArrayBuffer, { message: "Must be an ArrayBuffer" }),
|
|
16491
16547
|
z.custom(isBuffer, { message: "Must be a Buffer" })
|
|
16492
16548
|
]);
|
|
16493
16549
|
const providerReferenceSchema = z.record(z.string(), z.string());
|