ai 6.0.0-beta.35 → 6.0.0-beta.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 +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +133 -112
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +141 -119
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +2 -2
- package/dist/internal/index.d.ts +2 -2
- package/dist/internal/index.js +32 -28
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +32 -28
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# ai
|
|
2
2
|
|
|
3
|
+
## 6.0.0-beta.37
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [7e32fea]
|
|
8
|
+
- @ai-sdk/provider-utils@4.0.0-beta.12
|
|
9
|
+
- @ai-sdk/gateway@2.0.0-beta.25
|
|
10
|
+
|
|
11
|
+
## 6.0.0-beta.36
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- Updated dependencies [0e29b8b]
|
|
16
|
+
- @ai-sdk/gateway@2.0.0-beta.24
|
|
17
|
+
|
|
3
18
|
## 6.0.0-beta.35
|
|
4
19
|
|
|
5
20
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -826,7 +826,7 @@ type PartialObject<ObjectType extends object> = {
|
|
|
826
826
|
|
|
827
827
|
interface Output<OUTPUT, PARTIAL> {
|
|
828
828
|
readonly type: 'object' | 'text';
|
|
829
|
-
responseFormat: LanguageModelV3CallOptions['responseFormat']
|
|
829
|
+
responseFormat: PromiseLike<LanguageModelV3CallOptions['responseFormat']>;
|
|
830
830
|
parsePartial(options: {
|
|
831
831
|
text: string;
|
|
832
832
|
}): Promise<{
|
|
@@ -980,7 +980,7 @@ type ToolCallRepairFunction<TOOLS extends ToolSet> = (options: {
|
|
|
980
980
|
tools: TOOLS;
|
|
981
981
|
inputSchema: (options: {
|
|
982
982
|
toolName: string;
|
|
983
|
-
}) => JSONSchema7
|
|
983
|
+
}) => PromiseLike<JSONSchema7>;
|
|
984
984
|
error: NoSuchToolError | InvalidToolInputError;
|
|
985
985
|
}) => Promise<LanguageModelV3ToolCall | null>;
|
|
986
986
|
|
package/dist/index.d.ts
CHANGED
|
@@ -826,7 +826,7 @@ type PartialObject<ObjectType extends object> = {
|
|
|
826
826
|
|
|
827
827
|
interface Output<OUTPUT, PARTIAL> {
|
|
828
828
|
readonly type: 'object' | 'text';
|
|
829
|
-
responseFormat: LanguageModelV3CallOptions['responseFormat']
|
|
829
|
+
responseFormat: PromiseLike<LanguageModelV3CallOptions['responseFormat']>;
|
|
830
830
|
parsePartial(options: {
|
|
831
831
|
text: string;
|
|
832
832
|
}): Promise<{
|
|
@@ -980,7 +980,7 @@ type ToolCallRepairFunction<TOOLS extends ToolSet> = (options: {
|
|
|
980
980
|
tools: TOOLS;
|
|
981
981
|
inputSchema: (options: {
|
|
982
982
|
toolName: string;
|
|
983
|
-
}) => JSONSchema7
|
|
983
|
+
}) => PromiseLike<JSONSchema7>;
|
|
984
984
|
error: NoSuchToolError | InvalidToolInputError;
|
|
985
985
|
}) => Promise<LanguageModelV3ToolCall | null>;
|
|
986
986
|
|
package/dist/index.js
CHANGED
|
@@ -823,7 +823,7 @@ function detectMediaType({
|
|
|
823
823
|
var import_provider_utils2 = require("@ai-sdk/provider-utils");
|
|
824
824
|
|
|
825
825
|
// src/version.ts
|
|
826
|
-
var VERSION = true ? "6.0.0-beta.
|
|
826
|
+
var VERSION = true ? "6.0.0-beta.37" : "0.0.0-test";
|
|
827
827
|
|
|
828
828
|
// src/util/download/download.ts
|
|
829
829
|
var download = async ({ url }) => {
|
|
@@ -1320,7 +1320,7 @@ function isNonEmptyObject(object7) {
|
|
|
1320
1320
|
}
|
|
1321
1321
|
|
|
1322
1322
|
// src/prompt/prepare-tools-and-tool-choice.ts
|
|
1323
|
-
function prepareToolsAndToolChoice({
|
|
1323
|
+
async function prepareToolsAndToolChoice({
|
|
1324
1324
|
tools,
|
|
1325
1325
|
toolChoice,
|
|
1326
1326
|
activeTools
|
|
@@ -1334,33 +1334,37 @@ function prepareToolsAndToolChoice({
|
|
|
1334
1334
|
const filteredTools = activeTools != null ? Object.entries(tools).filter(
|
|
1335
1335
|
([name17]) => activeTools.includes(name17)
|
|
1336
1336
|
) : Object.entries(tools);
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1337
|
+
const languageModelTools = [];
|
|
1338
|
+
for (const [name17, tool3] of filteredTools) {
|
|
1339
|
+
const toolType = tool3.type;
|
|
1340
|
+
switch (toolType) {
|
|
1341
|
+
case void 0:
|
|
1342
|
+
case "dynamic":
|
|
1343
|
+
case "function":
|
|
1344
|
+
languageModelTools.push({
|
|
1345
|
+
type: "function",
|
|
1346
|
+
name: name17,
|
|
1347
|
+
description: tool3.description,
|
|
1348
|
+
inputSchema: await (0, import_provider_utils5.asSchema)(tool3.inputSchema).jsonSchema,
|
|
1349
|
+
providerOptions: tool3.providerOptions
|
|
1350
|
+
});
|
|
1351
|
+
break;
|
|
1352
|
+
case "provider-defined":
|
|
1353
|
+
languageModelTools.push({
|
|
1354
|
+
type: "provider-defined",
|
|
1355
|
+
name: name17,
|
|
1356
|
+
id: tool3.id,
|
|
1357
|
+
args: tool3.args
|
|
1358
|
+
});
|
|
1359
|
+
break;
|
|
1360
|
+
default: {
|
|
1361
|
+
const exhaustiveCheck = toolType;
|
|
1362
|
+
throw new Error(`Unsupported tool type: ${exhaustiveCheck}`);
|
|
1362
1363
|
}
|
|
1363
|
-
}
|
|
1364
|
+
}
|
|
1365
|
+
}
|
|
1366
|
+
return {
|
|
1367
|
+
tools: languageModelTools,
|
|
1364
1368
|
toolChoice: toolChoice == null ? { type: "auto" } : typeof toolChoice === "string" ? { type: toolChoice } : { type: "tool", toolName: toolChoice.toolName }
|
|
1365
1369
|
};
|
|
1366
1370
|
}
|
|
@@ -1727,29 +1731,33 @@ function getTracer({
|
|
|
1727
1731
|
|
|
1728
1732
|
// src/telemetry/record-span.ts
|
|
1729
1733
|
var import_api2 = require("@opentelemetry/api");
|
|
1730
|
-
function recordSpan({
|
|
1734
|
+
async function recordSpan({
|
|
1731
1735
|
name: name17,
|
|
1732
1736
|
tracer,
|
|
1733
1737
|
attributes,
|
|
1734
1738
|
fn,
|
|
1735
1739
|
endWhenDone = true
|
|
1736
1740
|
}) {
|
|
1737
|
-
return tracer.startActiveSpan(
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
span.end();
|
|
1742
|
-
}
|
|
1743
|
-
return result;
|
|
1744
|
-
} catch (error) {
|
|
1741
|
+
return tracer.startActiveSpan(
|
|
1742
|
+
name17,
|
|
1743
|
+
{ attributes: await attributes },
|
|
1744
|
+
async (span) => {
|
|
1745
1745
|
try {
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1746
|
+
const result = await fn(span);
|
|
1747
|
+
if (endWhenDone) {
|
|
1748
|
+
span.end();
|
|
1749
|
+
}
|
|
1750
|
+
return result;
|
|
1751
|
+
} catch (error) {
|
|
1752
|
+
try {
|
|
1753
|
+
recordErrorOnSpan(span, error);
|
|
1754
|
+
} finally {
|
|
1755
|
+
span.end();
|
|
1756
|
+
}
|
|
1757
|
+
throw error;
|
|
1749
1758
|
}
|
|
1750
|
-
throw error;
|
|
1751
1759
|
}
|
|
1752
|
-
|
|
1760
|
+
);
|
|
1753
1761
|
}
|
|
1754
1762
|
function recordErrorOnSpan(span, error) {
|
|
1755
1763
|
if (error instanceof Error) {
|
|
@@ -1768,33 +1776,41 @@ function recordErrorOnSpan(span, error) {
|
|
|
1768
1776
|
}
|
|
1769
1777
|
|
|
1770
1778
|
// src/telemetry/select-telemetry-attributes.ts
|
|
1771
|
-
function selectTelemetryAttributes({
|
|
1779
|
+
async function selectTelemetryAttributes({
|
|
1772
1780
|
telemetry,
|
|
1773
1781
|
attributes
|
|
1774
1782
|
}) {
|
|
1775
1783
|
if ((telemetry == null ? void 0 : telemetry.isEnabled) !== true) {
|
|
1776
1784
|
return {};
|
|
1777
1785
|
}
|
|
1778
|
-
|
|
1786
|
+
const resultAttributes = {};
|
|
1787
|
+
for (const [key, value] of Object.entries(attributes)) {
|
|
1779
1788
|
if (value == null) {
|
|
1780
|
-
|
|
1789
|
+
continue;
|
|
1781
1790
|
}
|
|
1782
1791
|
if (typeof value === "object" && "input" in value && typeof value.input === "function") {
|
|
1783
1792
|
if ((telemetry == null ? void 0 : telemetry.recordInputs) === false) {
|
|
1784
|
-
|
|
1793
|
+
continue;
|
|
1785
1794
|
}
|
|
1786
|
-
const result = value.input();
|
|
1787
|
-
|
|
1795
|
+
const result = await value.input();
|
|
1796
|
+
if (result != null) {
|
|
1797
|
+
resultAttributes[key] = result;
|
|
1798
|
+
}
|
|
1799
|
+
continue;
|
|
1788
1800
|
}
|
|
1789
1801
|
if (typeof value === "object" && "output" in value && typeof value.output === "function") {
|
|
1790
1802
|
if ((telemetry == null ? void 0 : telemetry.recordOutputs) === false) {
|
|
1791
|
-
|
|
1803
|
+
continue;
|
|
1792
1804
|
}
|
|
1793
|
-
const result = value.output();
|
|
1794
|
-
|
|
1805
|
+
const result = await value.output();
|
|
1806
|
+
if (result != null) {
|
|
1807
|
+
resultAttributes[key] = result;
|
|
1808
|
+
}
|
|
1809
|
+
continue;
|
|
1795
1810
|
}
|
|
1796
|
-
|
|
1797
|
-
}
|
|
1811
|
+
resultAttributes[key] = value;
|
|
1812
|
+
}
|
|
1813
|
+
return resultAttributes;
|
|
1798
1814
|
}
|
|
1799
1815
|
|
|
1800
1816
|
// src/telemetry/stringify-for-telemetry.ts
|
|
@@ -2101,7 +2117,7 @@ async function executeToolCall({
|
|
|
2101
2117
|
}
|
|
2102
2118
|
try {
|
|
2103
2119
|
span.setAttributes(
|
|
2104
|
-
selectTelemetryAttributes({
|
|
2120
|
+
await selectTelemetryAttributes({
|
|
2105
2121
|
telemetry,
|
|
2106
2122
|
attributes: {
|
|
2107
2123
|
"ai.toolCall.result": {
|
|
@@ -2213,9 +2229,9 @@ async function parseToolCall({
|
|
|
2213
2229
|
repairedToolCall = await repairToolCall({
|
|
2214
2230
|
toolCall,
|
|
2215
2231
|
tools,
|
|
2216
|
-
inputSchema: ({ toolName }) => {
|
|
2232
|
+
inputSchema: async ({ toolName }) => {
|
|
2217
2233
|
const { inputSchema } = tools[toolName];
|
|
2218
|
-
return (0, import_provider_utils10.asSchema)(inputSchema).jsonSchema;
|
|
2234
|
+
return await (0, import_provider_utils10.asSchema)(inputSchema).jsonSchema;
|
|
2219
2235
|
},
|
|
2220
2236
|
system,
|
|
2221
2237
|
messages,
|
|
@@ -2608,7 +2624,7 @@ async function generateText({
|
|
|
2608
2624
|
supportedUrls: await stepModel.supportedUrls,
|
|
2609
2625
|
download: download2
|
|
2610
2626
|
});
|
|
2611
|
-
const { toolChoice: stepToolChoice, tools: stepTools } = prepareToolsAndToolChoice({
|
|
2627
|
+
const { toolChoice: stepToolChoice, tools: stepTools } = await prepareToolsAndToolChoice({
|
|
2612
2628
|
tools,
|
|
2613
2629
|
toolChoice: (_d = prepareStepResult == null ? void 0 : prepareStepResult.toolChoice) != null ? _d : toolChoice,
|
|
2614
2630
|
activeTools: (_e = prepareStepResult == null ? void 0 : prepareStepResult.activeTools) != null ? _e : activeTools
|
|
@@ -2659,7 +2675,7 @@ async function generateText({
|
|
|
2659
2675
|
...callSettings2,
|
|
2660
2676
|
tools: stepTools,
|
|
2661
2677
|
toolChoice: stepToolChoice,
|
|
2662
|
-
responseFormat: output == null ? void 0 : output.responseFormat,
|
|
2678
|
+
responseFormat: await (output == null ? void 0 : output.responseFormat),
|
|
2663
2679
|
prompt: promptMessages,
|
|
2664
2680
|
providerOptions,
|
|
2665
2681
|
abortSignal,
|
|
@@ -2673,7 +2689,7 @@ async function generateText({
|
|
|
2673
2689
|
body: (_h = result.response) == null ? void 0 : _h.body
|
|
2674
2690
|
};
|
|
2675
2691
|
span2.setAttributes(
|
|
2676
|
-
selectTelemetryAttributes({
|
|
2692
|
+
await selectTelemetryAttributes({
|
|
2677
2693
|
telemetry,
|
|
2678
2694
|
attributes: {
|
|
2679
2695
|
"ai.response.finishReason": result.finishReason,
|
|
@@ -2817,7 +2833,7 @@ async function generateText({
|
|
|
2817
2833
|
!await isStopConditionMet({ stopConditions, steps })
|
|
2818
2834
|
);
|
|
2819
2835
|
span.setAttributes(
|
|
2820
|
-
selectTelemetryAttributes({
|
|
2836
|
+
await selectTelemetryAttributes({
|
|
2821
2837
|
telemetry,
|
|
2822
2838
|
attributes: {
|
|
2823
2839
|
"ai.response.finishReason": currentModelResponse.finishReason,
|
|
@@ -4398,15 +4414,15 @@ async function consumeStream({
|
|
|
4398
4414
|
|
|
4399
4415
|
// src/util/create-resolvable-promise.ts
|
|
4400
4416
|
function createResolvablePromise() {
|
|
4401
|
-
let
|
|
4417
|
+
let resolve3;
|
|
4402
4418
|
let reject;
|
|
4403
4419
|
const promise = new Promise((res, rej) => {
|
|
4404
|
-
|
|
4420
|
+
resolve3 = res;
|
|
4405
4421
|
reject = rej;
|
|
4406
4422
|
});
|
|
4407
4423
|
return {
|
|
4408
4424
|
promise,
|
|
4409
|
-
resolve:
|
|
4425
|
+
resolve: resolve3,
|
|
4410
4426
|
reject
|
|
4411
4427
|
};
|
|
4412
4428
|
}
|
|
@@ -4503,13 +4519,13 @@ var DelayedPromise = class {
|
|
|
4503
4519
|
if (this._promise) {
|
|
4504
4520
|
return this._promise;
|
|
4505
4521
|
}
|
|
4506
|
-
this._promise = new Promise((
|
|
4522
|
+
this._promise = new Promise((resolve3, reject) => {
|
|
4507
4523
|
if (this.status.type === "resolved") {
|
|
4508
|
-
|
|
4524
|
+
resolve3(this.status.value);
|
|
4509
4525
|
} else if (this.status.type === "rejected") {
|
|
4510
4526
|
reject(this.status.error);
|
|
4511
4527
|
}
|
|
4512
|
-
this._resolve =
|
|
4528
|
+
this._resolve = resolve3;
|
|
4513
4529
|
this._reject = reject;
|
|
4514
4530
|
});
|
|
4515
4531
|
return this._promise;
|
|
@@ -5110,7 +5126,7 @@ var DefaultStreamTextResult = class {
|
|
|
5110
5126
|
steps: recordedSteps
|
|
5111
5127
|
}));
|
|
5112
5128
|
rootSpan.setAttributes(
|
|
5113
|
-
selectTelemetryAttributes({
|
|
5129
|
+
await selectTelemetryAttributes({
|
|
5114
5130
|
telemetry,
|
|
5115
5131
|
attributes: {
|
|
5116
5132
|
"ai.response.finishReason": finishReason,
|
|
@@ -5319,7 +5335,7 @@ var DefaultStreamTextResult = class {
|
|
|
5319
5335
|
supportedUrls: await stepModel.supportedUrls,
|
|
5320
5336
|
download: download2
|
|
5321
5337
|
});
|
|
5322
|
-
const { toolChoice: stepToolChoice, tools: stepTools } = prepareToolsAndToolChoice({
|
|
5338
|
+
const { toolChoice: stepToolChoice, tools: stepTools } = await prepareToolsAndToolChoice({
|
|
5323
5339
|
tools,
|
|
5324
5340
|
toolChoice: (_d = prepareStepResult == null ? void 0 : prepareStepResult.toolChoice) != null ? _d : toolChoice,
|
|
5325
5341
|
activeTools: (_e = prepareStepResult == null ? void 0 : prepareStepResult.activeTools) != null ? _e : activeTools
|
|
@@ -5375,7 +5391,7 @@ var DefaultStreamTextResult = class {
|
|
|
5375
5391
|
...callSettings,
|
|
5376
5392
|
tools: stepTools,
|
|
5377
5393
|
toolChoice: stepToolChoice,
|
|
5378
|
-
responseFormat: output == null ? void 0 : output.responseFormat,
|
|
5394
|
+
responseFormat: await (output == null ? void 0 : output.responseFormat),
|
|
5379
5395
|
prompt: promptMessages,
|
|
5380
5396
|
providerOptions,
|
|
5381
5397
|
abortSignal,
|
|
@@ -5578,7 +5594,7 @@ var DefaultStreamTextResult = class {
|
|
|
5578
5594
|
const stepToolCallsJson = stepToolCalls.length > 0 ? JSON.stringify(stepToolCalls) : void 0;
|
|
5579
5595
|
try {
|
|
5580
5596
|
doStreamSpan.setAttributes(
|
|
5581
|
-
selectTelemetryAttributes({
|
|
5597
|
+
await selectTelemetryAttributes({
|
|
5582
5598
|
telemetry,
|
|
5583
5599
|
attributes: {
|
|
5584
5600
|
"ai.response.finishReason": stepFinishReason,
|
|
@@ -6487,7 +6503,7 @@ async function embed({
|
|
|
6487
6503
|
const embedding2 = modelResponse.embeddings[0];
|
|
6488
6504
|
const usage2 = (_a17 = modelResponse.usage) != null ? _a17 : { tokens: NaN };
|
|
6489
6505
|
doEmbedSpan.setAttributes(
|
|
6490
|
-
selectTelemetryAttributes({
|
|
6506
|
+
await selectTelemetryAttributes({
|
|
6491
6507
|
telemetry,
|
|
6492
6508
|
attributes: {
|
|
6493
6509
|
"ai.embeddings": {
|
|
@@ -6510,7 +6526,7 @@ async function embed({
|
|
|
6510
6526
|
)
|
|
6511
6527
|
);
|
|
6512
6528
|
span.setAttributes(
|
|
6513
|
-
selectTelemetryAttributes({
|
|
6529
|
+
await selectTelemetryAttributes({
|
|
6514
6530
|
telemetry,
|
|
6515
6531
|
attributes: {
|
|
6516
6532
|
"ai.embedding": { output: () => JSON.stringify(embedding) },
|
|
@@ -6631,7 +6647,7 @@ async function embedMany({
|
|
|
6631
6647
|
const embeddings3 = modelResponse.embeddings;
|
|
6632
6648
|
const usage2 = (_a18 = modelResponse.usage) != null ? _a18 : { tokens: NaN };
|
|
6633
6649
|
doEmbedSpan.setAttributes(
|
|
6634
|
-
selectTelemetryAttributes({
|
|
6650
|
+
await selectTelemetryAttributes({
|
|
6635
6651
|
telemetry,
|
|
6636
6652
|
attributes: {
|
|
6637
6653
|
"ai.embeddings": {
|
|
@@ -6654,7 +6670,7 @@ async function embedMany({
|
|
|
6654
6670
|
}
|
|
6655
6671
|
);
|
|
6656
6672
|
span.setAttributes(
|
|
6657
|
-
selectTelemetryAttributes({
|
|
6673
|
+
await selectTelemetryAttributes({
|
|
6658
6674
|
telemetry,
|
|
6659
6675
|
attributes: {
|
|
6660
6676
|
"ai.embeddings": {
|
|
@@ -6713,7 +6729,7 @@ async function embedMany({
|
|
|
6713
6729
|
const embeddings2 = modelResponse.embeddings;
|
|
6714
6730
|
const usage = (_a18 = modelResponse.usage) != null ? _a18 : { tokens: NaN };
|
|
6715
6731
|
doEmbedSpan.setAttributes(
|
|
6716
|
-
selectTelemetryAttributes({
|
|
6732
|
+
await selectTelemetryAttributes({
|
|
6717
6733
|
telemetry,
|
|
6718
6734
|
attributes: {
|
|
6719
6735
|
"ai.embeddings": {
|
|
@@ -6757,7 +6773,7 @@ async function embedMany({
|
|
|
6757
6773
|
}
|
|
6758
6774
|
}
|
|
6759
6775
|
span.setAttributes(
|
|
6760
|
-
selectTelemetryAttributes({
|
|
6776
|
+
await selectTelemetryAttributes({
|
|
6761
6777
|
telemetry,
|
|
6762
6778
|
attributes: {
|
|
6763
6779
|
"ai.embeddings": {
|
|
@@ -6921,7 +6937,7 @@ var import_provider25 = require("@ai-sdk/provider");
|
|
|
6921
6937
|
var import_provider_utils20 = require("@ai-sdk/provider-utils");
|
|
6922
6938
|
var noSchemaOutputStrategy = {
|
|
6923
6939
|
type: "no-schema",
|
|
6924
|
-
jsonSchema: void 0,
|
|
6940
|
+
jsonSchema: async () => void 0,
|
|
6925
6941
|
async validatePartialResult({ value, textDelta }) {
|
|
6926
6942
|
return { success: true, value: { partial: value, textDelta } };
|
|
6927
6943
|
},
|
|
@@ -6945,7 +6961,7 @@ var noSchemaOutputStrategy = {
|
|
|
6945
6961
|
};
|
|
6946
6962
|
var objectOutputStrategy = (schema) => ({
|
|
6947
6963
|
type: "object",
|
|
6948
|
-
jsonSchema: schema.jsonSchema,
|
|
6964
|
+
jsonSchema: async () => await schema.jsonSchema,
|
|
6949
6965
|
async validatePartialResult({ value, textDelta }) {
|
|
6950
6966
|
return {
|
|
6951
6967
|
success: true,
|
|
@@ -6966,20 +6982,22 @@ var objectOutputStrategy = (schema) => ({
|
|
|
6966
6982
|
}
|
|
6967
6983
|
});
|
|
6968
6984
|
var arrayOutputStrategy = (schema) => {
|
|
6969
|
-
const { $schema, ...itemSchema } = schema.jsonSchema;
|
|
6970
6985
|
return {
|
|
6971
6986
|
type: "enum",
|
|
6972
6987
|
// wrap in object that contains array of elements, since most LLMs will not
|
|
6973
6988
|
// be able to generate an array directly:
|
|
6974
6989
|
// possible future optimization: use arrays directly when model supports grammar-guided generation
|
|
6975
|
-
jsonSchema: {
|
|
6976
|
-
$schema
|
|
6977
|
-
|
|
6978
|
-
|
|
6979
|
-
|
|
6980
|
-
|
|
6981
|
-
|
|
6982
|
-
|
|
6990
|
+
jsonSchema: async () => {
|
|
6991
|
+
const { $schema, ...itemSchema } = await schema.jsonSchema;
|
|
6992
|
+
return {
|
|
6993
|
+
$schema: "http://json-schema.org/draft-07/schema#",
|
|
6994
|
+
type: "object",
|
|
6995
|
+
properties: {
|
|
6996
|
+
elements: { type: "array", items: itemSchema }
|
|
6997
|
+
},
|
|
6998
|
+
required: ["elements"],
|
|
6999
|
+
additionalProperties: false
|
|
7000
|
+
};
|
|
6983
7001
|
},
|
|
6984
7002
|
async validatePartialResult({
|
|
6985
7003
|
value,
|
|
@@ -7087,7 +7105,7 @@ var enumOutputStrategy = (enumValues) => {
|
|
|
7087
7105
|
// wrap in object that contains result, since most LLMs will not
|
|
7088
7106
|
// be able to generate an enum value directly:
|
|
7089
7107
|
// possible future optimization: use enums directly when model supports top-level enums
|
|
7090
|
-
jsonSchema: {
|
|
7108
|
+
jsonSchema: async () => ({
|
|
7091
7109
|
$schema: "http://json-schema.org/draft-07/schema#",
|
|
7092
7110
|
type: "object",
|
|
7093
7111
|
properties: {
|
|
@@ -7095,7 +7113,7 @@ var enumOutputStrategy = (enumValues) => {
|
|
|
7095
7113
|
},
|
|
7096
7114
|
required: ["result"],
|
|
7097
7115
|
additionalProperties: false
|
|
7098
|
-
},
|
|
7116
|
+
}),
|
|
7099
7117
|
async validateFinalResult(value) {
|
|
7100
7118
|
if (!(0, import_provider25.isJSONObject)(value) || typeof value.result !== "string") {
|
|
7101
7119
|
return {
|
|
@@ -7406,6 +7424,7 @@ async function generateObject(options) {
|
|
|
7406
7424
|
settings: { ...callSettings, maxRetries }
|
|
7407
7425
|
});
|
|
7408
7426
|
const tracer = getTracer(telemetry);
|
|
7427
|
+
const jsonSchema3 = await outputStrategy.jsonSchema();
|
|
7409
7428
|
try {
|
|
7410
7429
|
return await recordSpan({
|
|
7411
7430
|
name: "ai.generateObject",
|
|
@@ -7421,7 +7440,7 @@ async function generateObject(options) {
|
|
|
7421
7440
|
"ai.prompt": {
|
|
7422
7441
|
input: () => JSON.stringify({ system, prompt, messages })
|
|
7423
7442
|
},
|
|
7424
|
-
"ai.schema":
|
|
7443
|
+
"ai.schema": jsonSchema3 != null ? { input: () => JSON.stringify(jsonSchema3) } : void 0,
|
|
7425
7444
|
"ai.schema.name": schemaName,
|
|
7426
7445
|
"ai.schema.description": schemaDescription,
|
|
7427
7446
|
"ai.settings.output": outputStrategy.type
|
|
@@ -7479,7 +7498,7 @@ async function generateObject(options) {
|
|
|
7479
7498
|
const result2 = await model.doGenerate({
|
|
7480
7499
|
responseFormat: {
|
|
7481
7500
|
type: "json",
|
|
7482
|
-
schema:
|
|
7501
|
+
schema: jsonSchema3,
|
|
7483
7502
|
name: schemaName,
|
|
7484
7503
|
description: schemaDescription
|
|
7485
7504
|
},
|
|
@@ -7507,7 +7526,7 @@ async function generateObject(options) {
|
|
|
7507
7526
|
});
|
|
7508
7527
|
}
|
|
7509
7528
|
span2.setAttributes(
|
|
7510
|
-
selectTelemetryAttributes({
|
|
7529
|
+
await selectTelemetryAttributes({
|
|
7511
7530
|
telemetry,
|
|
7512
7531
|
attributes: {
|
|
7513
7532
|
"ai.response.finishReason": result2.finishReason,
|
|
@@ -7559,7 +7578,7 @@ async function generateObject(options) {
|
|
|
7559
7578
|
}
|
|
7560
7579
|
);
|
|
7561
7580
|
span.setAttributes(
|
|
7562
|
-
selectTelemetryAttributes({
|
|
7581
|
+
await selectTelemetryAttributes({
|
|
7563
7582
|
telemetry,
|
|
7564
7583
|
attributes: {
|
|
7565
7584
|
"ai.response.finishReason": finishReason,
|
|
@@ -7709,11 +7728,11 @@ var SerialJobExecutor = class {
|
|
|
7709
7728
|
this.isProcessing = false;
|
|
7710
7729
|
}
|
|
7711
7730
|
async run(job) {
|
|
7712
|
-
return new Promise((
|
|
7731
|
+
return new Promise((resolve3, reject) => {
|
|
7713
7732
|
this.queue.push(async () => {
|
|
7714
7733
|
try {
|
|
7715
7734
|
await job();
|
|
7716
|
-
|
|
7735
|
+
resolve3();
|
|
7717
7736
|
} catch (error) {
|
|
7718
7737
|
reject(error);
|
|
7719
7738
|
}
|
|
@@ -7882,7 +7901,9 @@ var DefaultStreamObjectResult = class {
|
|
|
7882
7901
|
"ai.prompt": {
|
|
7883
7902
|
input: () => JSON.stringify({ system, prompt, messages })
|
|
7884
7903
|
},
|
|
7885
|
-
"ai.schema":
|
|
7904
|
+
"ai.schema": {
|
|
7905
|
+
input: async () => JSON.stringify(await outputStrategy.jsonSchema())
|
|
7906
|
+
},
|
|
7886
7907
|
"ai.schema.name": schemaName,
|
|
7887
7908
|
"ai.schema.description": schemaDescription,
|
|
7888
7909
|
"ai.settings.output": outputStrategy.type
|
|
@@ -7899,7 +7920,7 @@ var DefaultStreamObjectResult = class {
|
|
|
7899
7920
|
const callOptions = {
|
|
7900
7921
|
responseFormat: {
|
|
7901
7922
|
type: "json",
|
|
7902
|
-
schema: outputStrategy.jsonSchema,
|
|
7923
|
+
schema: await outputStrategy.jsonSchema(),
|
|
7903
7924
|
name: schemaName,
|
|
7904
7925
|
description: schemaDescription
|
|
7905
7926
|
},
|
|
@@ -8102,7 +8123,7 @@ var DefaultStreamObjectResult = class {
|
|
|
8102
8123
|
totalTokens: NaN
|
|
8103
8124
|
};
|
|
8104
8125
|
doStreamSpan.setAttributes(
|
|
8105
|
-
selectTelemetryAttributes({
|
|
8126
|
+
await selectTelemetryAttributes({
|
|
8106
8127
|
telemetry,
|
|
8107
8128
|
attributes: {
|
|
8108
8129
|
"ai.response.finishReason": finishReason,
|
|
@@ -8129,7 +8150,7 @@ var DefaultStreamObjectResult = class {
|
|
|
8129
8150
|
);
|
|
8130
8151
|
doStreamSpan.end();
|
|
8131
8152
|
rootSpan.setAttributes(
|
|
8132
|
-
selectTelemetryAttributes({
|
|
8153
|
+
await selectTelemetryAttributes({
|
|
8133
8154
|
telemetry,
|
|
8134
8155
|
attributes: {
|
|
8135
8156
|
"ai.usage.inputTokens": finalUsage.inputTokens,
|
|
@@ -8374,7 +8395,7 @@ __export(output_exports, {
|
|
|
8374
8395
|
var import_provider_utils26 = require("@ai-sdk/provider-utils");
|
|
8375
8396
|
var text = () => ({
|
|
8376
8397
|
type: "text",
|
|
8377
|
-
responseFormat: { type: "text" },
|
|
8398
|
+
responseFormat: Promise.resolve({ type: "text" }),
|
|
8378
8399
|
async parsePartial({ text: text2 }) {
|
|
8379
8400
|
return { partial: text2 };
|
|
8380
8401
|
},
|
|
@@ -8388,10 +8409,10 @@ var object3 = ({
|
|
|
8388
8409
|
const schema = (0, import_provider_utils26.asSchema)(inputSchema);
|
|
8389
8410
|
return {
|
|
8390
8411
|
type: "object",
|
|
8391
|
-
responseFormat: {
|
|
8412
|
+
responseFormat: (0, import_provider_utils26.resolve)(schema.jsonSchema).then((jsonSchema3) => ({
|
|
8392
8413
|
type: "json",
|
|
8393
|
-
schema:
|
|
8394
|
-
},
|
|
8414
|
+
schema: jsonSchema3
|
|
8415
|
+
})),
|
|
8395
8416
|
async parsePartial({ text: text2 }) {
|
|
8396
8417
|
const result = await parsePartialJson(text2);
|
|
8397
8418
|
switch (result.state) {
|
|
@@ -9204,9 +9225,9 @@ var SseMCPTransport = class {
|
|
|
9204
9225
|
this.headers = headers;
|
|
9205
9226
|
}
|
|
9206
9227
|
async start() {
|
|
9207
|
-
return new Promise((
|
|
9228
|
+
return new Promise((resolve3, reject) => {
|
|
9208
9229
|
if (this.connected) {
|
|
9209
|
-
return
|
|
9230
|
+
return resolve3();
|
|
9210
9231
|
}
|
|
9211
9232
|
this.abortController = new AbortController();
|
|
9212
9233
|
const establishConnection = async () => {
|
|
@@ -9256,7 +9277,7 @@ var SseMCPTransport = class {
|
|
|
9256
9277
|
});
|
|
9257
9278
|
}
|
|
9258
9279
|
this.connected = true;
|
|
9259
|
-
|
|
9280
|
+
resolve3();
|
|
9260
9281
|
} else if (event === "message") {
|
|
9261
9282
|
try {
|
|
9262
9283
|
const message = JSONRPCMessageSchema.parse(
|
|
@@ -9459,7 +9480,7 @@ var DefaultMCPClient = class {
|
|
|
9459
9480
|
resultSchema,
|
|
9460
9481
|
options
|
|
9461
9482
|
}) {
|
|
9462
|
-
return new Promise((
|
|
9483
|
+
return new Promise((resolve3, reject) => {
|
|
9463
9484
|
if (this.isClosed) {
|
|
9464
9485
|
return reject(
|
|
9465
9486
|
new MCPClientError({
|
|
@@ -9493,7 +9514,7 @@ var DefaultMCPClient = class {
|
|
|
9493
9514
|
}
|
|
9494
9515
|
try {
|
|
9495
9516
|
const result = resultSchema.parse(response.result);
|
|
9496
|
-
|
|
9517
|
+
resolve3(result);
|
|
9497
9518
|
} catch (error) {
|
|
9498
9519
|
const parseError = new MCPClientError({
|
|
9499
9520
|
message: "Failed to parse server response",
|
|
@@ -9856,11 +9877,11 @@ async function convertFileListToFileUIParts(files) {
|
|
|
9856
9877
|
return Promise.all(
|
|
9857
9878
|
Array.from(files).map(async (file) => {
|
|
9858
9879
|
const { name: name17, type } = file;
|
|
9859
|
-
const dataUrl = await new Promise((
|
|
9880
|
+
const dataUrl = await new Promise((resolve3, reject) => {
|
|
9860
9881
|
const reader = new FileReader();
|
|
9861
9882
|
reader.onload = (readerEvent) => {
|
|
9862
9883
|
var _a17;
|
|
9863
|
-
|
|
9884
|
+
resolve3((_a17 = readerEvent.target) == null ? void 0 : _a17.result);
|
|
9864
9885
|
};
|
|
9865
9886
|
reader.onerror = (error) => reject(error);
|
|
9866
9887
|
reader.readAsDataURL(file);
|
|
@@ -10823,11 +10844,11 @@ function createUIMessageStream({
|
|
|
10823
10844
|
errorText: onError(error)
|
|
10824
10845
|
});
|
|
10825
10846
|
}
|
|
10826
|
-
const waitForStreams = new Promise(async (
|
|
10847
|
+
const waitForStreams = new Promise(async (resolve3) => {
|
|
10827
10848
|
while (ongoingStreamPromises.length > 0) {
|
|
10828
10849
|
await ongoingStreamPromises.shift();
|
|
10829
10850
|
}
|
|
10830
|
-
|
|
10851
|
+
resolve3();
|
|
10831
10852
|
});
|
|
10832
10853
|
waitForStreams.finally(() => {
|
|
10833
10854
|
try {
|