ai 4.0.35 → 4.0.37
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 +15 -0
- package/dist/index.d.mts +21 -3
- package/dist/index.d.ts +21 -3
- package/dist/index.js +97 -20
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +94 -18
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
@@ -13,7 +13,7 @@ import {
|
|
13
13
|
processDataStream,
|
14
14
|
processTextStream
|
15
15
|
} from "@ai-sdk/ui-utils";
|
16
|
-
import { generateId as
|
16
|
+
import { generateId as generateId3 } from "@ai-sdk/provider-utils";
|
17
17
|
|
18
18
|
// core/index.ts
|
19
19
|
import { jsonSchema } from "@ai-sdk/ui-utils";
|
@@ -2225,7 +2225,7 @@ async function generateObject({
|
|
2225
2225
|
experimental_telemetry: telemetry,
|
2226
2226
|
experimental_providerMetadata: providerMetadata,
|
2227
2227
|
_internal: {
|
2228
|
-
generateId:
|
2228
|
+
generateId: generateId4 = originalGenerateId,
|
2229
2229
|
currentDate = () => /* @__PURE__ */ new Date()
|
2230
2230
|
} = {},
|
2231
2231
|
...settings
|
@@ -2355,7 +2355,7 @@ async function generateObject({
|
|
2355
2355
|
headers
|
2356
2356
|
});
|
2357
2357
|
const responseData = {
|
2358
|
-
id: (_b2 = (_a15 = result2.response) == null ? void 0 : _a15.id) != null ? _b2 :
|
2358
|
+
id: (_b2 = (_a15 = result2.response) == null ? void 0 : _a15.id) != null ? _b2 : generateId4(),
|
2359
2359
|
timestamp: (_d = (_c = result2.response) == null ? void 0 : _c.timestamp) != null ? _d : currentDate(),
|
2360
2360
|
modelId: (_f = (_e = result2.response) == null ? void 0 : _e.modelId) != null ? _f : model.modelId
|
2361
2361
|
};
|
@@ -2463,7 +2463,7 @@ async function generateObject({
|
|
2463
2463
|
});
|
2464
2464
|
const objectText = (_b2 = (_a15 = result2.toolCalls) == null ? void 0 : _a15[0]) == null ? void 0 : _b2.args;
|
2465
2465
|
const responseData = {
|
2466
|
-
id: (_d = (_c = result2.response) == null ? void 0 : _c.id) != null ? _d :
|
2466
|
+
id: (_d = (_c = result2.response) == null ? void 0 : _c.id) != null ? _d : generateId4(),
|
2467
2467
|
timestamp: (_f = (_e = result2.response) == null ? void 0 : _e.timestamp) != null ? _f : currentDate(),
|
2468
2468
|
modelId: (_h = (_g = result2.response) == null ? void 0 : _g.modelId) != null ? _h : model.modelId
|
2469
2469
|
};
|
@@ -2764,7 +2764,7 @@ function streamObject({
|
|
2764
2764
|
experimental_providerMetadata: providerMetadata,
|
2765
2765
|
onFinish,
|
2766
2766
|
_internal: {
|
2767
|
-
generateId:
|
2767
|
+
generateId: generateId4 = originalGenerateId2,
|
2768
2768
|
currentDate = () => /* @__PURE__ */ new Date(),
|
2769
2769
|
now: now2 = now
|
2770
2770
|
} = {},
|
@@ -2797,7 +2797,7 @@ function streamObject({
|
|
2797
2797
|
inputProviderMetadata: providerMetadata,
|
2798
2798
|
mode,
|
2799
2799
|
onFinish,
|
2800
|
-
generateId:
|
2800
|
+
generateId: generateId4,
|
2801
2801
|
currentDate,
|
2802
2802
|
now: now2
|
2803
2803
|
});
|
@@ -2819,7 +2819,7 @@ var DefaultStreamObjectResult = class {
|
|
2819
2819
|
inputProviderMetadata,
|
2820
2820
|
mode,
|
2821
2821
|
onFinish,
|
2822
|
-
generateId:
|
2822
|
+
generateId: generateId4,
|
2823
2823
|
currentDate,
|
2824
2824
|
now: now2
|
2825
2825
|
}) {
|
@@ -3020,7 +3020,7 @@ var DefaultStreamObjectResult = class {
|
|
3020
3020
|
let accumulatedText = "";
|
3021
3021
|
let textDelta = "";
|
3022
3022
|
let response = {
|
3023
|
-
id:
|
3023
|
+
id: generateId4(),
|
3024
3024
|
timestamp: currentDate(),
|
3025
3025
|
modelId: model.modelId
|
3026
3026
|
};
|
@@ -3613,7 +3613,7 @@ async function generateText({
|
|
3613
3613
|
experimental_activeTools: activeTools,
|
3614
3614
|
experimental_repairToolCall: repairToolCall,
|
3615
3615
|
_internal: {
|
3616
|
-
generateId:
|
3616
|
+
generateId: generateId4 = originalGenerateId3,
|
3617
3617
|
currentDate = () => /* @__PURE__ */ new Date()
|
3618
3618
|
} = {},
|
3619
3619
|
onStepFinish,
|
@@ -3747,7 +3747,7 @@ async function generateText({
|
|
3747
3747
|
headers
|
3748
3748
|
});
|
3749
3749
|
const responseData = {
|
3750
|
-
id: (_b2 = (_a16 = result.response) == null ? void 0 : _a16.id) != null ? _b2 :
|
3750
|
+
id: (_b2 = (_a16 = result.response) == null ? void 0 : _a16.id) != null ? _b2 : generateId4(),
|
3751
3751
|
timestamp: (_d2 = (_c2 = result.response) == null ? void 0 : _c2.timestamp) != null ? _d2 : currentDate(),
|
3752
3752
|
modelId: (_f2 = (_e2 = result.response) == null ? void 0 : _e2.modelId) != null ? _f2 : model.modelId
|
3753
3753
|
};
|
@@ -4463,7 +4463,7 @@ function streamText({
|
|
4463
4463
|
onStepFinish,
|
4464
4464
|
_internal: {
|
4465
4465
|
now: now2 = now,
|
4466
|
-
generateId:
|
4466
|
+
generateId: generateId4 = originalGenerateId4,
|
4467
4467
|
currentDate = () => /* @__PURE__ */ new Date()
|
4468
4468
|
} = {},
|
4469
4469
|
...settings
|
@@ -4493,7 +4493,7 @@ function streamText({
|
|
4493
4493
|
onStepFinish,
|
4494
4494
|
now: now2,
|
4495
4495
|
currentDate,
|
4496
|
-
generateId:
|
4496
|
+
generateId: generateId4
|
4497
4497
|
});
|
4498
4498
|
}
|
4499
4499
|
function createOutputTransformStream(output) {
|
@@ -4573,7 +4573,7 @@ var DefaultStreamTextResult = class {
|
|
4573
4573
|
onStepFinish,
|
4574
4574
|
now: now2,
|
4575
4575
|
currentDate,
|
4576
|
-
generateId:
|
4576
|
+
generateId: generateId4
|
4577
4577
|
}) {
|
4578
4578
|
this.warningsPromise = new DelayedPromise();
|
4579
4579
|
this.usagePromise = new DelayedPromise();
|
@@ -4598,7 +4598,7 @@ var DefaultStreamTextResult = class {
|
|
4598
4598
|
let recordedContinuationText = "";
|
4599
4599
|
let recordedFullText = "";
|
4600
4600
|
const recordedResponse = {
|
4601
|
-
id:
|
4601
|
+
id: generateId4(),
|
4602
4602
|
timestamp: currentDate(),
|
4603
4603
|
modelId: model.modelId,
|
4604
4604
|
messages: []
|
@@ -4916,7 +4916,7 @@ var DefaultStreamTextResult = class {
|
|
4916
4916
|
let fullStepText = stepType2 === "continue" ? previousStepText : "";
|
4917
4917
|
let stepLogProbs;
|
4918
4918
|
let stepResponse = {
|
4919
|
-
id:
|
4919
|
+
id: generateId4(),
|
4920
4920
|
timestamp: currentDate(),
|
4921
4921
|
modelId: model.modelId
|
4922
4922
|
};
|
@@ -5462,6 +5462,66 @@ var experimental_wrapLanguageModel = ({
|
|
5462
5462
|
};
|
5463
5463
|
};
|
5464
5464
|
|
5465
|
+
// core/prompt/append-response-messages.ts
|
5466
|
+
import { generateId as generateId2 } from "@ai-sdk/provider-utils";
|
5467
|
+
function appendResponseMessages({
|
5468
|
+
messages,
|
5469
|
+
responseMessages
|
5470
|
+
}) {
|
5471
|
+
var _a14;
|
5472
|
+
const clonedMessages = structuredClone(messages);
|
5473
|
+
for (const message of responseMessages) {
|
5474
|
+
const role = message.role;
|
5475
|
+
switch (role) {
|
5476
|
+
case "system":
|
5477
|
+
case "user": {
|
5478
|
+
throw new Error(
|
5479
|
+
"AI response must not contain system or user messages: " + role
|
5480
|
+
);
|
5481
|
+
}
|
5482
|
+
case "assistant": {
|
5483
|
+
clonedMessages.push({
|
5484
|
+
role: "assistant",
|
5485
|
+
id: generateId2(),
|
5486
|
+
// generate an id for the message, will be overridden by the client
|
5487
|
+
createdAt: /* @__PURE__ */ new Date(),
|
5488
|
+
// generate a createdAt date for the message, will be overridden by the client
|
5489
|
+
// only include text in the content:
|
5490
|
+
content: typeof message.content === "string" ? message.content : message.content.filter((part) => part.type === "text").map((part) => part.text).join(""),
|
5491
|
+
// separate tool calls from the content:
|
5492
|
+
toolInvocations: (typeof message.content === "string" ? [] : message.content.filter((part) => part.type === "tool-call")).map((call) => ({
|
5493
|
+
state: "call",
|
5494
|
+
...call
|
5495
|
+
}))
|
5496
|
+
});
|
5497
|
+
break;
|
5498
|
+
}
|
5499
|
+
case "tool": {
|
5500
|
+
const previousMessage = clonedMessages[clonedMessages.length - 1];
|
5501
|
+
(_a14 = previousMessage.toolInvocations) != null ? _a14 : previousMessage.toolInvocations = [];
|
5502
|
+
if (previousMessage.role !== "assistant") {
|
5503
|
+
throw new Error(
|
5504
|
+
`Tool result must follow an assistant message: ${previousMessage.role}`
|
5505
|
+
);
|
5506
|
+
}
|
5507
|
+
for (const part of message.content) {
|
5508
|
+
const toolCall = previousMessage.toolInvocations.find(
|
5509
|
+
(call) => call.toolCallId === part.toolCallId
|
5510
|
+
);
|
5511
|
+
if (!toolCall) {
|
5512
|
+
throw new Error("Tool call not found in previous message");
|
5513
|
+
}
|
5514
|
+
toolCall.state = "result";
|
5515
|
+
const toolResult = toolCall;
|
5516
|
+
toolResult.result = part.result;
|
5517
|
+
}
|
5518
|
+
break;
|
5519
|
+
}
|
5520
|
+
}
|
5521
|
+
}
|
5522
|
+
return clonedMessages;
|
5523
|
+
}
|
5524
|
+
|
5465
5525
|
// core/registry/custom-provider.ts
|
5466
5526
|
import { NoSuchModelError as NoSuchModelError2 } from "@ai-sdk/provider";
|
5467
5527
|
function experimental_customProvider({
|
@@ -5591,13 +5651,28 @@ function tool(tool2) {
|
|
5591
5651
|
}
|
5592
5652
|
|
5593
5653
|
// core/util/cosine-similarity.ts
|
5594
|
-
function cosineSimilarity(vector1, vector2
|
5654
|
+
function cosineSimilarity(vector1, vector2, options = {
|
5655
|
+
throwErrorForEmptyVectors: false
|
5656
|
+
}) {
|
5657
|
+
const { throwErrorForEmptyVectors } = options;
|
5595
5658
|
if (vector1.length !== vector2.length) {
|
5596
5659
|
throw new Error(
|
5597
5660
|
`Vectors must have the same length (vector1: ${vector1.length} elements, vector2: ${vector2.length} elements)`
|
5598
5661
|
);
|
5599
5662
|
}
|
5600
|
-
|
5663
|
+
if (throwErrorForEmptyVectors && vector1.length === 0) {
|
5664
|
+
throw new InvalidArgumentError({
|
5665
|
+
parameter: "vector1",
|
5666
|
+
value: vector1,
|
5667
|
+
message: "Vectors cannot be empty"
|
5668
|
+
});
|
5669
|
+
}
|
5670
|
+
const magnitude1 = magnitude(vector1);
|
5671
|
+
const magnitude2 = magnitude(vector2);
|
5672
|
+
if (magnitude1 === 0 || magnitude2 === 0) {
|
5673
|
+
return 0;
|
5674
|
+
}
|
5675
|
+
return dotProduct(vector1, vector2) / (magnitude1 * magnitude2);
|
5601
5676
|
}
|
5602
5677
|
function dotProduct(vector1, vector2) {
|
5603
5678
|
return vector1.reduce(
|
@@ -5995,6 +6070,7 @@ export {
|
|
5995
6070
|
ToolExecutionError,
|
5996
6071
|
TypeValidationError2 as TypeValidationError,
|
5997
6072
|
UnsupportedFunctionalityError2 as UnsupportedFunctionalityError,
|
6073
|
+
appendResponseMessages,
|
5998
6074
|
convertToCoreMessages,
|
5999
6075
|
cosineSimilarity,
|
6000
6076
|
createDataStream,
|
@@ -6007,7 +6083,7 @@ export {
|
|
6007
6083
|
experimental_wrapLanguageModel,
|
6008
6084
|
formatAssistantStreamPart2 as formatAssistantStreamPart,
|
6009
6085
|
formatDataStreamPart6 as formatDataStreamPart,
|
6010
|
-
|
6086
|
+
generateId3 as generateId,
|
6011
6087
|
generateObject,
|
6012
6088
|
generateText,
|
6013
6089
|
jsonSchema,
|