ai 6.0.266 → 6.0.270
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 +34 -0
- package/dist/index.d.mts +5 -3
- package/dist/index.d.ts +5 -3
- package/dist/index.js +159 -76
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +93 -10
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +1 -1
- package/dist/internal/index.mjs +1 -1
- package/dist/test/index.d.mts +4 -1
- package/dist/test/index.d.ts +4 -1
- package/dist/test/index.js +6 -0
- package/dist/test/index.js.map +1 -1
- package/dist/test/index.mjs +6 -0
- package/dist/test/index.mjs.map +1 -1
- package/docs/07-reference/01-ai-sdk-core/06-embed-many.mdx +6 -2
- package/package.json +3 -3
- package/src/embed/embed-many.ts +75 -6
- package/src/generate-text/execute-tool-call.ts +6 -0
- package/src/generate-text/generate-text-result.ts +2 -1
- package/src/generate-text/generate-text.ts +6 -2
- package/src/middleware/wrap-embedding-model.ts +8 -1
- package/src/model/get-embedding-model-max-input-bytes-per-call.ts +15 -0
- package/src/test/mock-embedding-model-v3.ts +9 -0
- package/src/ui/last-assistant-message-is-complete-with-approval-responses.ts +1 -0
- package/src/util/create-stitchable-stream.ts +35 -3
package/dist/index.mjs
CHANGED
|
@@ -1193,7 +1193,7 @@ import {
|
|
|
1193
1193
|
} from "@ai-sdk/provider-utils";
|
|
1194
1194
|
|
|
1195
1195
|
// src/version.ts
|
|
1196
|
-
var VERSION = true ? "6.0.
|
|
1196
|
+
var VERSION = true ? "6.0.270" : "0.0.0-test";
|
|
1197
1197
|
|
|
1198
1198
|
// src/util/download/download.ts
|
|
1199
1199
|
var download = async ({
|
|
@@ -2908,6 +2908,7 @@ async function executeToolCall({
|
|
|
2908
2908
|
onToolCallStart,
|
|
2909
2909
|
onToolCallFinish
|
|
2910
2910
|
}) {
|
|
2911
|
+
var _a22;
|
|
2911
2912
|
const { toolName, toolCallId, input } = toolCall;
|
|
2912
2913
|
const tool2 = tools == null ? void 0 : tools[toolName];
|
|
2913
2914
|
if ((tool2 == null ? void 0 : tool2.execute) == null) {
|
|
@@ -2932,6 +2933,12 @@ async function executeToolCall({
|
|
|
2932
2933
|
operationId: "ai.toolCall",
|
|
2933
2934
|
telemetry
|
|
2934
2935
|
}),
|
|
2936
|
+
...Object.fromEntries(
|
|
2937
|
+
Object.entries((_a22 = telemetry == null ? void 0 : telemetry.metadata) != null ? _a22 : {}).map(([key, value]) => [
|
|
2938
|
+
`ai.telemetry.metadata.${key}`,
|
|
2939
|
+
value
|
|
2940
|
+
])
|
|
2941
|
+
),
|
|
2935
2942
|
"ai.toolCall.name": toolName,
|
|
2936
2943
|
"ai.toolCall.id": toolCallId,
|
|
2937
2944
|
"ai.toolCall.args": {
|
|
@@ -5121,7 +5128,7 @@ async function generateText({
|
|
|
5121
5128
|
]
|
|
5122
5129
|
});
|
|
5123
5130
|
let resolvedOutput;
|
|
5124
|
-
if (lastStep.finishReason === "stop") {
|
|
5131
|
+
if (lastStep.finishReason === "stop" || lastStep.finishReason !== "tool-calls" && lastStep.text.length > 0) {
|
|
5125
5132
|
const outputSpecification = output != null ? output : text();
|
|
5126
5133
|
resolvedOutput = await outputSpecification.parseCompleteOutput(
|
|
5127
5134
|
{ text: lastStep.text },
|
|
@@ -6599,8 +6606,12 @@ function createStitchableStream() {
|
|
|
6599
6606
|
let innerStreams = [];
|
|
6600
6607
|
let controller = null;
|
|
6601
6608
|
let isClosed = false;
|
|
6609
|
+
let isCancelled = false;
|
|
6602
6610
|
let waitForNewStream = createResolvablePromise();
|
|
6603
6611
|
const terminate = () => {
|
|
6612
|
+
if (isCancelled) {
|
|
6613
|
+
return;
|
|
6614
|
+
}
|
|
6604
6615
|
isClosed = true;
|
|
6605
6616
|
waitForNewStream.resolve();
|
|
6606
6617
|
innerStreams.forEach(({ reader, onCancel }) => {
|
|
@@ -6611,7 +6622,10 @@ function createStitchableStream() {
|
|
|
6611
6622
|
controller == null ? void 0 : controller.close();
|
|
6612
6623
|
};
|
|
6613
6624
|
const processPull = async () => {
|
|
6614
|
-
var _a22
|
|
6625
|
+
var _a22;
|
|
6626
|
+
if (isCancelled) {
|
|
6627
|
+
return;
|
|
6628
|
+
}
|
|
6615
6629
|
if (isClosed && innerStreams.length === 0) {
|
|
6616
6630
|
controller == null ? void 0 : controller.close();
|
|
6617
6631
|
return;
|
|
@@ -6621,8 +6635,12 @@ function createStitchableStream() {
|
|
|
6621
6635
|
await waitForNewStream.promise;
|
|
6622
6636
|
return processPull();
|
|
6623
6637
|
}
|
|
6638
|
+
const currentStream = innerStreams[0];
|
|
6624
6639
|
try {
|
|
6625
|
-
const { value, done } = await
|
|
6640
|
+
const { value, done } = await currentStream.reader.read();
|
|
6641
|
+
if (isCancelled) {
|
|
6642
|
+
return;
|
|
6643
|
+
}
|
|
6626
6644
|
if (done) {
|
|
6627
6645
|
innerStreams.shift();
|
|
6628
6646
|
if (innerStreams.length === 0 && isClosed) {
|
|
@@ -6634,7 +6652,10 @@ function createStitchableStream() {
|
|
|
6634
6652
|
controller == null ? void 0 : controller.enqueue(value);
|
|
6635
6653
|
}
|
|
6636
6654
|
} catch (error) {
|
|
6637
|
-
|
|
6655
|
+
if (isCancelled) {
|
|
6656
|
+
return;
|
|
6657
|
+
}
|
|
6658
|
+
(_a22 = currentStream.onError) == null ? void 0 : _a22.call(currentStream, error);
|
|
6638
6659
|
controller == null ? void 0 : controller.error(error);
|
|
6639
6660
|
innerStreams.shift();
|
|
6640
6661
|
terminate();
|
|
@@ -6647,15 +6668,24 @@ function createStitchableStream() {
|
|
|
6647
6668
|
},
|
|
6648
6669
|
pull: processPull,
|
|
6649
6670
|
async cancel() {
|
|
6671
|
+
isCancelled = true;
|
|
6672
|
+
isClosed = true;
|
|
6673
|
+
waitForNewStream.resolve();
|
|
6650
6674
|
for (const { reader, onCancel } of innerStreams) {
|
|
6651
6675
|
onCancel == null ? void 0 : onCancel();
|
|
6652
6676
|
await reader.cancel();
|
|
6653
6677
|
}
|
|
6654
6678
|
innerStreams = [];
|
|
6655
|
-
isClosed = true;
|
|
6656
6679
|
}
|
|
6657
6680
|
}),
|
|
6658
6681
|
addStream: (innerStream, callbacks) => {
|
|
6682
|
+
var _a22;
|
|
6683
|
+
if (isCancelled) {
|
|
6684
|
+
(_a22 = callbacks == null ? void 0 : callbacks.onCancel) == null ? void 0 : _a22.call(callbacks);
|
|
6685
|
+
void innerStream.cancel().catch(() => {
|
|
6686
|
+
});
|
|
6687
|
+
return;
|
|
6688
|
+
}
|
|
6659
6689
|
if (isClosed) {
|
|
6660
6690
|
throw new Error("Cannot add inner stream: outer stream is closed");
|
|
6661
6691
|
}
|
|
@@ -6670,6 +6700,9 @@ function createStitchableStream() {
|
|
|
6670
6700
|
* finish processing and then close the outer stream.
|
|
6671
6701
|
*/
|
|
6672
6702
|
close: () => {
|
|
6703
|
+
if (isCancelled) {
|
|
6704
|
+
return;
|
|
6705
|
+
}
|
|
6673
6706
|
isClosed = true;
|
|
6674
6707
|
waitForNewStream.resolve();
|
|
6675
6708
|
if (innerStreams.length === 0) {
|
|
@@ -10060,6 +10093,12 @@ import {
|
|
|
10060
10093
|
withUserAgentSuffix as withUserAgentSuffix4
|
|
10061
10094
|
} from "@ai-sdk/provider-utils";
|
|
10062
10095
|
|
|
10096
|
+
// src/model/get-embedding-model-max-input-bytes-per-call.ts
|
|
10097
|
+
import { EXPERIMENTAL_EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL } from "@ai-sdk/provider-utils";
|
|
10098
|
+
function getEmbeddingModelMaxInputBytesPerCall(model) {
|
|
10099
|
+
return model[EXPERIMENTAL_EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL];
|
|
10100
|
+
}
|
|
10101
|
+
|
|
10063
10102
|
// src/util/split-array.ts
|
|
10064
10103
|
function splitArray(array2, chunkSize) {
|
|
10065
10104
|
if (chunkSize <= 0) {
|
|
@@ -10115,11 +10154,18 @@ async function embedMany({
|
|
|
10115
10154
|
tracer,
|
|
10116
10155
|
fn: async (span) => {
|
|
10117
10156
|
var _a22;
|
|
10118
|
-
const [
|
|
10157
|
+
const [
|
|
10158
|
+
maxEmbeddingsPerCall,
|
|
10159
|
+
maxInputBytesPerCall,
|
|
10160
|
+
supportsParallelCalls
|
|
10161
|
+
] = await Promise.all([
|
|
10119
10162
|
model.maxEmbeddingsPerCall,
|
|
10163
|
+
getEmbeddingModelMaxInputBytesPerCall(model),
|
|
10120
10164
|
model.supportsParallelCalls
|
|
10121
10165
|
]);
|
|
10122
|
-
|
|
10166
|
+
const hasEmbeddingLimit = maxEmbeddingsPerCall != null && maxEmbeddingsPerCall !== Infinity;
|
|
10167
|
+
const hasInputByteLimit = maxInputBytesPerCall != null && maxInputBytesPerCall !== Infinity;
|
|
10168
|
+
if (!hasEmbeddingLimit && !hasInputByteLimit) {
|
|
10123
10169
|
const { embeddings: embeddings2, usage, warnings: warnings2, response, providerMetadata: providerMetadata2 } = await retry(() => {
|
|
10124
10170
|
return recordSpan({
|
|
10125
10171
|
name: "ai.embedMany.doEmbed",
|
|
@@ -10196,7 +10242,11 @@ async function embedMany({
|
|
|
10196
10242
|
responses: [response]
|
|
10197
10243
|
});
|
|
10198
10244
|
}
|
|
10199
|
-
const valueChunks =
|
|
10245
|
+
const valueChunks = splitByEmbeddingLimits({
|
|
10246
|
+
values,
|
|
10247
|
+
maxEmbeddingsPerCall: hasEmbeddingLimit ? maxEmbeddingsPerCall : Infinity,
|
|
10248
|
+
maxInputBytesPerCall: hasInputByteLimit ? maxInputBytesPerCall : Infinity
|
|
10249
|
+
});
|
|
10200
10250
|
const embeddings = [];
|
|
10201
10251
|
const warnings = [];
|
|
10202
10252
|
const responses = [];
|
|
@@ -10310,6 +10360,37 @@ async function embedMany({
|
|
|
10310
10360
|
}
|
|
10311
10361
|
});
|
|
10312
10362
|
}
|
|
10363
|
+
var textEncoder = new TextEncoder();
|
|
10364
|
+
function splitByEmbeddingLimits({
|
|
10365
|
+
values,
|
|
10366
|
+
maxEmbeddingsPerCall,
|
|
10367
|
+
maxInputBytesPerCall
|
|
10368
|
+
}) {
|
|
10369
|
+
if (maxEmbeddingsPerCall <= 0) {
|
|
10370
|
+
throw new Error("maxEmbeddingsPerCall must be greater than 0");
|
|
10371
|
+
}
|
|
10372
|
+
if (maxInputBytesPerCall <= 0) {
|
|
10373
|
+
throw new Error("maxInputBytesPerCall must be greater than 0");
|
|
10374
|
+
}
|
|
10375
|
+
if (values.length === 0) {
|
|
10376
|
+
return [];
|
|
10377
|
+
}
|
|
10378
|
+
const chunks = [];
|
|
10379
|
+
let currentChunk = [];
|
|
10380
|
+
let currentInputBytes = 0;
|
|
10381
|
+
for (const value of values) {
|
|
10382
|
+
const inputBytes = textEncoder.encode(value).length;
|
|
10383
|
+
if (currentChunk.length > 0 && (currentChunk.length >= maxEmbeddingsPerCall || currentInputBytes + inputBytes > maxInputBytesPerCall)) {
|
|
10384
|
+
chunks.push(currentChunk);
|
|
10385
|
+
currentChunk = [];
|
|
10386
|
+
currentInputBytes = 0;
|
|
10387
|
+
}
|
|
10388
|
+
currentChunk.push(value);
|
|
10389
|
+
currentInputBytes += inputBytes;
|
|
10390
|
+
}
|
|
10391
|
+
chunks.push(currentChunk);
|
|
10392
|
+
return chunks;
|
|
10393
|
+
}
|
|
10313
10394
|
var DefaultEmbedManyResult = class {
|
|
10314
10395
|
constructor(options) {
|
|
10315
10396
|
this.values = options.values;
|
|
@@ -13007,6 +13088,7 @@ var doWrap = ({
|
|
|
13007
13088
|
};
|
|
13008
13089
|
|
|
13009
13090
|
// src/middleware/wrap-embedding-model.ts
|
|
13091
|
+
import { EXPERIMENTAL_EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL as EXPERIMENTAL_EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL2 } from "@ai-sdk/provider-utils";
|
|
13010
13092
|
var wrapEmbeddingModel = ({
|
|
13011
13093
|
model,
|
|
13012
13094
|
middleware: middlewareArg,
|
|
@@ -13041,6 +13123,7 @@ var doWrap2 = ({
|
|
|
13041
13123
|
provider: (_a22 = providerId != null ? providerId : overrideProvider == null ? void 0 : overrideProvider({ model })) != null ? _a22 : model.provider,
|
|
13042
13124
|
modelId: (_b = modelId != null ? modelId : overrideModelId == null ? void 0 : overrideModelId({ model })) != null ? _b : model.modelId,
|
|
13043
13125
|
maxEmbeddingsPerCall: (_c = overrideMaxEmbeddingsPerCall == null ? void 0 : overrideMaxEmbeddingsPerCall({ model })) != null ? _c : model.maxEmbeddingsPerCall,
|
|
13126
|
+
[EXPERIMENTAL_EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL2]: getEmbeddingModelMaxInputBytesPerCall(model),
|
|
13044
13127
|
supportsParallelCalls: (_d = overrideSupportsParallelCalls == null ? void 0 : overrideSupportsParallelCalls({ model })) != null ? _d : model.supportsParallelCalls,
|
|
13045
13128
|
async doEmbed(params) {
|
|
13046
13129
|
const transformedParams = await doTransform({ params });
|
|
@@ -14430,7 +14513,7 @@ function lastAssistantMessageIsCompleteWithApprovalResponses({
|
|
|
14430
14513
|
// has at least one tool approval response
|
|
14431
14514
|
lastStepToolInvocations.filter((part) => part.state === "approval-responded").length > 0 && // all tool approvals must have a response
|
|
14432
14515
|
lastStepToolInvocations.every(
|
|
14433
|
-
(part) => part.state === "output-available" || part.state === "output-error" || part.state === "approval-responded"
|
|
14516
|
+
(part) => part.state === "output-available" || part.state === "output-error" || part.state === "output-denied" || part.state === "approval-responded"
|
|
14434
14517
|
)
|
|
14435
14518
|
);
|
|
14436
14519
|
}
|