ai 5.0.0-beta.31 → 5.0.0-beta.33
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 +20 -0
- package/dist/index.d.mts +24 -52
- package/dist/index.d.ts +24 -52
- package/dist/index.js +112 -76
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +112 -76
- package/dist/index.mjs.map +1 -1
- package/dist/mcp-stdio/index.js +24 -24
- package/dist/mcp-stdio/index.js.map +1 -1
- package/dist/mcp-stdio/index.mjs +24 -24
- package/dist/mcp-stdio/index.mjs.map +1 -1
- package/dist/test/index.js.map +1 -1
- package/dist/test/index.mjs.map +1 -1
- package/package.json +18 -9
- package/dist/bin/ai.min.js +0 -126
package/dist/index.mjs
CHANGED
@@ -1823,12 +1823,15 @@ function createToolModelOutput({
|
|
1823
1823
|
if (errorMode === "text") {
|
1824
1824
|
return { type: "error-text", value: getErrorMessage4(output) };
|
1825
1825
|
} else if (errorMode === "json") {
|
1826
|
-
return { type: "error-json", value: output };
|
1826
|
+
return { type: "error-json", value: toJSONValue(output) };
|
1827
1827
|
}
|
1828
1828
|
if (tool3 == null ? void 0 : tool3.toModelOutput) {
|
1829
1829
|
return tool3.toModelOutput(output);
|
1830
1830
|
}
|
1831
|
-
return typeof output === "string" ? { type: "text", value: output } : { type: "json", value: output };
|
1831
|
+
return typeof output === "string" ? { type: "text", value: output } : { type: "json", value: toJSONValue(output) };
|
1832
|
+
}
|
1833
|
+
function toJSONValue(value) {
|
1834
|
+
return value === void 0 ? null : value;
|
1832
1835
|
}
|
1833
1836
|
|
1834
1837
|
// src/generate-text/to-response-messages.ts
|
@@ -5341,7 +5344,7 @@ async function embed({
|
|
5341
5344
|
}),
|
5342
5345
|
tracer,
|
5343
5346
|
fn: async (span) => {
|
5344
|
-
const { embedding, usage, response } = await retry(
|
5347
|
+
const { embedding, usage, response, providerMetadata } = await retry(
|
5345
5348
|
() => (
|
5346
5349
|
// nested spans to align with the embedMany telemetry data:
|
5347
5350
|
recordSpan({
|
@@ -5385,6 +5388,7 @@ async function embed({
|
|
5385
5388
|
return {
|
5386
5389
|
embedding: embedding2,
|
5387
5390
|
usage: usage2,
|
5391
|
+
providerMetadata: modelResponse.providerMetadata,
|
5388
5392
|
response: modelResponse.response
|
5389
5393
|
};
|
5390
5394
|
}
|
@@ -5404,6 +5408,7 @@ async function embed({
|
|
5404
5408
|
value,
|
5405
5409
|
embedding,
|
5406
5410
|
usage,
|
5411
|
+
providerMetadata,
|
5407
5412
|
response
|
5408
5413
|
});
|
5409
5414
|
}
|
@@ -5414,6 +5419,7 @@ var DefaultEmbedResult = class {
|
|
5414
5419
|
this.value = options.value;
|
5415
5420
|
this.embedding = options.embedding;
|
5416
5421
|
this.usage = options.usage;
|
5422
|
+
this.providerMetadata = options.providerMetadata;
|
5417
5423
|
this.response = options.response;
|
5418
5424
|
}
|
5419
5425
|
};
|
@@ -5471,58 +5477,64 @@ async function embedMany({
|
|
5471
5477
|
}),
|
5472
5478
|
tracer,
|
5473
5479
|
fn: async (span) => {
|
5480
|
+
var _a16;
|
5474
5481
|
const [maxEmbeddingsPerCall, supportsParallelCalls] = await Promise.all([
|
5475
5482
|
model.maxEmbeddingsPerCall,
|
5476
5483
|
model.supportsParallelCalls
|
5477
5484
|
]);
|
5478
5485
|
if (maxEmbeddingsPerCall == null || maxEmbeddingsPerCall === Infinity) {
|
5479
|
-
const { embeddings: embeddings2, usage, response } = await retry(
|
5480
|
-
|
5481
|
-
|
5482
|
-
|
5483
|
-
|
5484
|
-
|
5485
|
-
|
5486
|
-
|
5487
|
-
|
5488
|
-
|
5489
|
-
|
5490
|
-
|
5491
|
-
|
5492
|
-
|
5486
|
+
const { embeddings: embeddings2, usage, response, providerMetadata: providerMetadata2 } = await retry(
|
5487
|
+
() => {
|
5488
|
+
return recordSpan({
|
5489
|
+
name: "ai.embedMany.doEmbed",
|
5490
|
+
attributes: selectTelemetryAttributes({
|
5491
|
+
telemetry,
|
5492
|
+
attributes: {
|
5493
|
+
...assembleOperationName({
|
5494
|
+
operationId: "ai.embedMany.doEmbed",
|
5495
|
+
telemetry
|
5496
|
+
}),
|
5497
|
+
...baseTelemetryAttributes,
|
5498
|
+
// specific settings that only make sense on the outer level:
|
5499
|
+
"ai.values": {
|
5500
|
+
input: () => values.map((value) => JSON.stringify(value))
|
5501
|
+
}
|
5493
5502
|
}
|
5503
|
+
}),
|
5504
|
+
tracer,
|
5505
|
+
fn: async (doEmbedSpan) => {
|
5506
|
+
var _a17;
|
5507
|
+
const modelResponse = await model.doEmbed({
|
5508
|
+
values,
|
5509
|
+
abortSignal,
|
5510
|
+
headers,
|
5511
|
+
providerOptions
|
5512
|
+
});
|
5513
|
+
const embeddings3 = modelResponse.embeddings;
|
5514
|
+
const usage2 = (_a17 = modelResponse.usage) != null ? _a17 : { tokens: NaN };
|
5515
|
+
doEmbedSpan.setAttributes(
|
5516
|
+
selectTelemetryAttributes({
|
5517
|
+
telemetry,
|
5518
|
+
attributes: {
|
5519
|
+
"ai.embeddings": {
|
5520
|
+
output: () => embeddings3.map(
|
5521
|
+
(embedding) => JSON.stringify(embedding)
|
5522
|
+
)
|
5523
|
+
},
|
5524
|
+
"ai.usage.tokens": usage2.tokens
|
5525
|
+
}
|
5526
|
+
})
|
5527
|
+
);
|
5528
|
+
return {
|
5529
|
+
embeddings: embeddings3,
|
5530
|
+
usage: usage2,
|
5531
|
+
providerMetadata: modelResponse.providerMetadata,
|
5532
|
+
response: modelResponse.response
|
5533
|
+
};
|
5494
5534
|
}
|
5495
|
-
})
|
5496
|
-
|
5497
|
-
|
5498
|
-
var _a16;
|
5499
|
-
const modelResponse = await model.doEmbed({
|
5500
|
-
values,
|
5501
|
-
abortSignal,
|
5502
|
-
headers,
|
5503
|
-
providerOptions
|
5504
|
-
});
|
5505
|
-
const embeddings3 = modelResponse.embeddings;
|
5506
|
-
const usage2 = (_a16 = modelResponse.usage) != null ? _a16 : { tokens: NaN };
|
5507
|
-
doEmbedSpan.setAttributes(
|
5508
|
-
selectTelemetryAttributes({
|
5509
|
-
telemetry,
|
5510
|
-
attributes: {
|
5511
|
-
"ai.embeddings": {
|
5512
|
-
output: () => embeddings3.map((embedding) => JSON.stringify(embedding))
|
5513
|
-
},
|
5514
|
-
"ai.usage.tokens": usage2.tokens
|
5515
|
-
}
|
5516
|
-
})
|
5517
|
-
);
|
5518
|
-
return {
|
5519
|
-
embeddings: embeddings3,
|
5520
|
-
usage: usage2,
|
5521
|
-
response: modelResponse.response
|
5522
|
-
};
|
5523
|
-
}
|
5524
|
-
});
|
5525
|
-
});
|
5535
|
+
});
|
5536
|
+
}
|
5537
|
+
);
|
5526
5538
|
span.setAttributes(
|
5527
5539
|
selectTelemetryAttributes({
|
5528
5540
|
telemetry,
|
@@ -5538,6 +5550,7 @@ async function embedMany({
|
|
5538
5550
|
values,
|
5539
5551
|
embeddings: embeddings2,
|
5540
5552
|
usage,
|
5553
|
+
providerMetadata: providerMetadata2,
|
5541
5554
|
responses: [response]
|
5542
5555
|
});
|
5543
5556
|
}
|
@@ -5545,6 +5558,7 @@ async function embedMany({
|
|
5545
5558
|
const embeddings = [];
|
5546
5559
|
const responses = [];
|
5547
5560
|
let tokens = 0;
|
5561
|
+
let providerMetadata;
|
5548
5562
|
const parallelChunks = splitArray(
|
5549
5563
|
valueChunks,
|
5550
5564
|
supportsParallelCalls ? maxParallelCalls : 1
|
@@ -5571,7 +5585,7 @@ async function embedMany({
|
|
5571
5585
|
}),
|
5572
5586
|
tracer,
|
5573
5587
|
fn: async (doEmbedSpan) => {
|
5574
|
-
var
|
5588
|
+
var _a17;
|
5575
5589
|
const modelResponse = await model.doEmbed({
|
5576
5590
|
values: chunk,
|
5577
5591
|
abortSignal,
|
@@ -5579,7 +5593,7 @@ async function embedMany({
|
|
5579
5593
|
providerOptions
|
5580
5594
|
});
|
5581
5595
|
const embeddings2 = modelResponse.embeddings;
|
5582
|
-
const usage = (
|
5596
|
+
const usage = (_a17 = modelResponse.usage) != null ? _a17 : { tokens: NaN };
|
5583
5597
|
doEmbedSpan.setAttributes(
|
5584
5598
|
selectTelemetryAttributes({
|
5585
5599
|
telemetry,
|
@@ -5596,6 +5610,7 @@ async function embedMany({
|
|
5596
5610
|
return {
|
5597
5611
|
embeddings: embeddings2,
|
5598
5612
|
usage,
|
5613
|
+
providerMetadata: modelResponse.providerMetadata,
|
5599
5614
|
response: modelResponse.response
|
5600
5615
|
};
|
5601
5616
|
}
|
@@ -5607,6 +5622,20 @@ async function embedMany({
|
|
5607
5622
|
embeddings.push(...result.embeddings);
|
5608
5623
|
responses.push(result.response);
|
5609
5624
|
tokens += result.usage.tokens;
|
5625
|
+
if (result.providerMetadata) {
|
5626
|
+
if (!providerMetadata) {
|
5627
|
+
providerMetadata = { ...result.providerMetadata };
|
5628
|
+
} else {
|
5629
|
+
for (const [providerName, metadata] of Object.entries(
|
5630
|
+
result.providerMetadata
|
5631
|
+
)) {
|
5632
|
+
providerMetadata[providerName] = {
|
5633
|
+
...(_a16 = providerMetadata[providerName]) != null ? _a16 : {},
|
5634
|
+
...metadata
|
5635
|
+
};
|
5636
|
+
}
|
5637
|
+
}
|
5638
|
+
}
|
5610
5639
|
}
|
5611
5640
|
}
|
5612
5641
|
span.setAttributes(
|
@@ -5624,6 +5653,7 @@ async function embedMany({
|
|
5624
5653
|
values,
|
5625
5654
|
embeddings,
|
5626
5655
|
usage: { tokens },
|
5656
|
+
providerMetadata,
|
5627
5657
|
responses
|
5628
5658
|
});
|
5629
5659
|
}
|
@@ -5634,6 +5664,7 @@ var DefaultEmbedManyResult = class {
|
|
5634
5664
|
this.values = options.values;
|
5635
5665
|
this.embeddings = options.embeddings;
|
5636
5666
|
this.usage = options.usage;
|
5667
|
+
this.providerMetadata = options.providerMetadata;
|
5637
5668
|
this.responses = options.responses;
|
5638
5669
|
}
|
5639
5670
|
};
|
@@ -6650,6 +6681,7 @@ var DefaultStreamObjectResult = class {
|
|
6650
6681
|
this._warnings = new DelayedPromise();
|
6651
6682
|
this._request = new DelayedPromise();
|
6652
6683
|
this._response = new DelayedPromise();
|
6684
|
+
this._finishReason = new DelayedPromise();
|
6653
6685
|
const model = resolveLanguageModel(modelArg);
|
6654
6686
|
const { maxRetries, retry } = prepareRetries({
|
6655
6687
|
maxRetries: maxRetriesArg
|
@@ -6869,6 +6901,7 @@ var DefaultStreamObjectResult = class {
|
|
6869
6901
|
...fullResponse,
|
6870
6902
|
headers: response == null ? void 0 : response.headers
|
6871
6903
|
});
|
6904
|
+
self._finishReason.resolve(finishReason != null ? finishReason : "unknown");
|
6872
6905
|
const validationResult = await outputStrategy.validateFinalResult(
|
6873
6906
|
latestObjectJson,
|
6874
6907
|
{
|
@@ -7003,6 +7036,9 @@ var DefaultStreamObjectResult = class {
|
|
7003
7036
|
get response() {
|
7004
7037
|
return this._response.promise;
|
7005
7038
|
}
|
7039
|
+
get finishReason() {
|
7040
|
+
return this._finishReason.promise;
|
7041
|
+
}
|
7006
7042
|
get partialObjectStream() {
|
7007
7043
|
return createAsyncIterableStream(
|
7008
7044
|
this.baseStream.pipeThrough(
|
@@ -7867,38 +7903,38 @@ var SUPPORTED_PROTOCOL_VERSIONS = [
|
|
7867
7903
|
"2025-03-26",
|
7868
7904
|
"2024-11-05"
|
7869
7905
|
];
|
7870
|
-
var ClientOrServerImplementationSchema = z8.
|
7906
|
+
var ClientOrServerImplementationSchema = z8.looseObject({
|
7871
7907
|
name: z8.string(),
|
7872
7908
|
version: z8.string()
|
7873
|
-
})
|
7874
|
-
var BaseParamsSchema = z8.
|
7875
|
-
_meta: z8.optional(z8.object({}).
|
7876
|
-
})
|
7909
|
+
});
|
7910
|
+
var BaseParamsSchema = z8.looseObject({
|
7911
|
+
_meta: z8.optional(z8.object({}).loose())
|
7912
|
+
});
|
7877
7913
|
var ResultSchema = BaseParamsSchema;
|
7878
7914
|
var RequestSchema = z8.object({
|
7879
7915
|
method: z8.string(),
|
7880
7916
|
params: z8.optional(BaseParamsSchema)
|
7881
7917
|
});
|
7882
|
-
var ServerCapabilitiesSchema = z8.
|
7883
|
-
experimental: z8.optional(z8.object({}).
|
7884
|
-
logging: z8.optional(z8.object({}).
|
7918
|
+
var ServerCapabilitiesSchema = z8.looseObject({
|
7919
|
+
experimental: z8.optional(z8.object({}).loose()),
|
7920
|
+
logging: z8.optional(z8.object({}).loose()),
|
7885
7921
|
prompts: z8.optional(
|
7886
|
-
z8.
|
7922
|
+
z8.looseObject({
|
7887
7923
|
listChanged: z8.optional(z8.boolean())
|
7888
|
-
})
|
7924
|
+
})
|
7889
7925
|
),
|
7890
7926
|
resources: z8.optional(
|
7891
|
-
z8.
|
7927
|
+
z8.looseObject({
|
7892
7928
|
subscribe: z8.optional(z8.boolean()),
|
7893
7929
|
listChanged: z8.optional(z8.boolean())
|
7894
|
-
})
|
7930
|
+
})
|
7895
7931
|
),
|
7896
7932
|
tools: z8.optional(
|
7897
|
-
z8.
|
7933
|
+
z8.looseObject({
|
7898
7934
|
listChanged: z8.optional(z8.boolean())
|
7899
|
-
})
|
7935
|
+
})
|
7900
7936
|
)
|
7901
|
-
})
|
7937
|
+
});
|
7902
7938
|
var InitializeResultSchema = ResultSchema.extend({
|
7903
7939
|
protocolVersion: z8.string(),
|
7904
7940
|
capabilities: ServerCapabilitiesSchema,
|
@@ -7913,21 +7949,21 @@ var ToolSchema = z8.object({
|
|
7913
7949
|
description: z8.optional(z8.string()),
|
7914
7950
|
inputSchema: z8.object({
|
7915
7951
|
type: z8.literal("object"),
|
7916
|
-
properties: z8.optional(z8.object({}).
|
7917
|
-
}).
|
7918
|
-
}).
|
7952
|
+
properties: z8.optional(z8.object({}).loose())
|
7953
|
+
}).loose()
|
7954
|
+
}).loose();
|
7919
7955
|
var ListToolsResultSchema = PaginatedResultSchema.extend({
|
7920
7956
|
tools: z8.array(ToolSchema)
|
7921
7957
|
});
|
7922
7958
|
var TextContentSchema = z8.object({
|
7923
7959
|
type: z8.literal("text"),
|
7924
7960
|
text: z8.string()
|
7925
|
-
}).
|
7961
|
+
}).loose();
|
7926
7962
|
var ImageContentSchema = z8.object({
|
7927
7963
|
type: z8.literal("image"),
|
7928
|
-
data: z8.
|
7964
|
+
data: z8.base64(),
|
7929
7965
|
mimeType: z8.string()
|
7930
|
-
}).
|
7966
|
+
}).loose();
|
7931
7967
|
var ResourceContentsSchema = z8.object({
|
7932
7968
|
/**
|
7933
7969
|
* The URI of this resource.
|
@@ -7937,17 +7973,17 @@ var ResourceContentsSchema = z8.object({
|
|
7937
7973
|
* The MIME type of this resource, if known.
|
7938
7974
|
*/
|
7939
7975
|
mimeType: z8.optional(z8.string())
|
7940
|
-
}).
|
7976
|
+
}).loose();
|
7941
7977
|
var TextResourceContentsSchema = ResourceContentsSchema.extend({
|
7942
7978
|
text: z8.string()
|
7943
7979
|
});
|
7944
7980
|
var BlobResourceContentsSchema = ResourceContentsSchema.extend({
|
7945
|
-
blob: z8.
|
7981
|
+
blob: z8.base64()
|
7946
7982
|
});
|
7947
7983
|
var EmbeddedResourceSchema = z8.object({
|
7948
7984
|
type: z8.literal("resource"),
|
7949
7985
|
resource: z8.union([TextResourceContentsSchema, BlobResourceContentsSchema])
|
7950
|
-
}).
|
7986
|
+
}).loose();
|
7951
7987
|
var CallToolResultSchema = ResultSchema.extend({
|
7952
7988
|
content: z8.array(
|
7953
7989
|
z8.union([TextContentSchema, ImageContentSchema, EmbeddedResourceSchema])
|
@@ -8145,11 +8181,11 @@ function isCustomMcpTransport(transport) {
|
|
8145
8181
|
// src/tool/mcp/mcp-client.ts
|
8146
8182
|
var CLIENT_VERSION = "1.0.0";
|
8147
8183
|
async function createMCPClient(config) {
|
8148
|
-
const client = new
|
8184
|
+
const client = new DefaultMCPClient(config);
|
8149
8185
|
await client.init();
|
8150
8186
|
return client;
|
8151
8187
|
}
|
8152
|
-
var
|
8188
|
+
var DefaultMCPClient = class {
|
8153
8189
|
constructor({
|
8154
8190
|
transport: transportConfig,
|
8155
8191
|
name: name16 = "ai-sdk-mcp-client",
|