@xyd-js/ask-ai-widget 0.0.0-build-87368f8-20251101145203 → 0.0.0-build-1760f84-20251129221538
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/dist/server-standalone.js +1993 -500
- package/dist/server.js +2854 -1278
- package/package.json +3 -3
|
@@ -39934,9 +39934,6 @@ var postToApi = async ({
|
|
|
39934
39934
|
function tool(tool2) {
|
|
39935
39935
|
return tool2;
|
|
39936
39936
|
}
|
|
39937
|
-
function dynamicTool(tool2) {
|
|
39938
|
-
return { ...tool2, type: "dynamic" };
|
|
39939
|
-
}
|
|
39940
39937
|
function createProviderDefinedToolFactory({
|
|
39941
39938
|
id,
|
|
39942
39939
|
name: name14,
|
|
@@ -42042,23 +42039,6 @@ var name53 = "AI_MCPClientError";
|
|
|
42042
42039
|
var marker53 = `vercel.ai.error.${name53}`;
|
|
42043
42040
|
var symbol53 = Symbol.for(marker53);
|
|
42044
42041
|
var _a53;
|
|
42045
|
-
var MCPClientError = class extends AISDKError {
|
|
42046
|
-
constructor({
|
|
42047
|
-
name: name17 = "MCPClientError",
|
|
42048
|
-
message,
|
|
42049
|
-
cause,
|
|
42050
|
-
data,
|
|
42051
|
-
code
|
|
42052
|
-
}) {
|
|
42053
|
-
super({ name: name17, message, cause });
|
|
42054
|
-
this[_a53] = true;
|
|
42055
|
-
this.data = data;
|
|
42056
|
-
this.code = code;
|
|
42057
|
-
}
|
|
42058
|
-
static isInstance(error40) {
|
|
42059
|
-
return AISDKError.hasMarker(error40, marker53);
|
|
42060
|
-
}
|
|
42061
|
-
};
|
|
42062
42042
|
_a53 = symbol53;
|
|
42063
42043
|
var name63 = "AI_NoImageGeneratedError";
|
|
42064
42044
|
var marker63 = `vercel.ai.error.${name63}`;
|
|
@@ -46446,12 +46426,6 @@ var marker16 = `vercel.ai.error.${name162}`;
|
|
|
46446
46426
|
var symbol16 = Symbol.for(marker16);
|
|
46447
46427
|
var _a16;
|
|
46448
46428
|
_a16 = symbol16;
|
|
46449
|
-
var LATEST_PROTOCOL_VERSION = "2025-06-18";
|
|
46450
|
-
var SUPPORTED_PROTOCOL_VERSIONS = [
|
|
46451
|
-
LATEST_PROTOCOL_VERSION,
|
|
46452
|
-
"2025-03-26",
|
|
46453
|
-
"2024-11-05"
|
|
46454
|
-
];
|
|
46455
46429
|
var ClientOrServerImplementationSchema = exports_external.looseObject({
|
|
46456
46430
|
name: exports_external.string(),
|
|
46457
46431
|
version: exports_external.string()
|
|
@@ -46558,52 +46532,1274 @@ var JSONRPCMessageSchema = exports_external.union([
|
|
|
46558
46532
|
JSONRPCResponseSchema,
|
|
46559
46533
|
JSONRPCErrorSchema
|
|
46560
46534
|
]);
|
|
46561
|
-
var
|
|
46562
|
-
|
|
46563
|
-
|
|
46564
|
-
|
|
46565
|
-
|
|
46566
|
-
|
|
46567
|
-
|
|
46568
|
-
|
|
46535
|
+
var uiMessagesSchema = lazyValidator(() => zodSchema(exports_external.array(exports_external.object({
|
|
46536
|
+
id: exports_external.string(),
|
|
46537
|
+
role: exports_external.enum(["system", "user", "assistant"]),
|
|
46538
|
+
metadata: exports_external.unknown().optional(),
|
|
46539
|
+
parts: exports_external.array(exports_external.union([
|
|
46540
|
+
exports_external.object({
|
|
46541
|
+
type: exports_external.literal("text"),
|
|
46542
|
+
text: exports_external.string(),
|
|
46543
|
+
state: exports_external.enum(["streaming", "done"]).optional(),
|
|
46544
|
+
providerMetadata: providerMetadataSchema.optional()
|
|
46545
|
+
}),
|
|
46546
|
+
exports_external.object({
|
|
46547
|
+
type: exports_external.literal("reasoning"),
|
|
46548
|
+
text: exports_external.string(),
|
|
46549
|
+
state: exports_external.enum(["streaming", "done"]).optional(),
|
|
46550
|
+
providerMetadata: providerMetadataSchema.optional()
|
|
46551
|
+
}),
|
|
46552
|
+
exports_external.object({
|
|
46553
|
+
type: exports_external.literal("source-url"),
|
|
46554
|
+
sourceId: exports_external.string(),
|
|
46555
|
+
url: exports_external.string(),
|
|
46556
|
+
title: exports_external.string().optional(),
|
|
46557
|
+
providerMetadata: providerMetadataSchema.optional()
|
|
46558
|
+
}),
|
|
46559
|
+
exports_external.object({
|
|
46560
|
+
type: exports_external.literal("source-document"),
|
|
46561
|
+
sourceId: exports_external.string(),
|
|
46562
|
+
mediaType: exports_external.string(),
|
|
46563
|
+
title: exports_external.string(),
|
|
46564
|
+
filename: exports_external.string().optional(),
|
|
46565
|
+
providerMetadata: providerMetadataSchema.optional()
|
|
46566
|
+
}),
|
|
46567
|
+
exports_external.object({
|
|
46568
|
+
type: exports_external.literal("file"),
|
|
46569
|
+
mediaType: exports_external.string(),
|
|
46570
|
+
filename: exports_external.string().optional(),
|
|
46571
|
+
url: exports_external.string(),
|
|
46572
|
+
providerMetadata: providerMetadataSchema.optional()
|
|
46573
|
+
}),
|
|
46574
|
+
exports_external.object({
|
|
46575
|
+
type: exports_external.literal("step-start")
|
|
46576
|
+
}),
|
|
46577
|
+
exports_external.object({
|
|
46578
|
+
type: exports_external.string().startsWith("data-"),
|
|
46579
|
+
id: exports_external.string().optional(),
|
|
46580
|
+
data: exports_external.unknown()
|
|
46581
|
+
}),
|
|
46582
|
+
exports_external.object({
|
|
46583
|
+
type: exports_external.literal("dynamic-tool"),
|
|
46584
|
+
toolName: exports_external.string(),
|
|
46585
|
+
toolCallId: exports_external.string(),
|
|
46586
|
+
state: exports_external.literal("input-streaming"),
|
|
46587
|
+
input: exports_external.unknown().optional(),
|
|
46588
|
+
output: exports_external.never().optional(),
|
|
46589
|
+
errorText: exports_external.never().optional()
|
|
46590
|
+
}),
|
|
46591
|
+
exports_external.object({
|
|
46592
|
+
type: exports_external.literal("dynamic-tool"),
|
|
46593
|
+
toolName: exports_external.string(),
|
|
46594
|
+
toolCallId: exports_external.string(),
|
|
46595
|
+
state: exports_external.literal("input-available"),
|
|
46596
|
+
input: exports_external.unknown(),
|
|
46597
|
+
output: exports_external.never().optional(),
|
|
46598
|
+
errorText: exports_external.never().optional(),
|
|
46599
|
+
callProviderMetadata: providerMetadataSchema.optional()
|
|
46600
|
+
}),
|
|
46601
|
+
exports_external.object({
|
|
46602
|
+
type: exports_external.literal("dynamic-tool"),
|
|
46603
|
+
toolName: exports_external.string(),
|
|
46604
|
+
toolCallId: exports_external.string(),
|
|
46605
|
+
state: exports_external.literal("output-available"),
|
|
46606
|
+
input: exports_external.unknown(),
|
|
46607
|
+
output: exports_external.unknown(),
|
|
46608
|
+
errorText: exports_external.never().optional(),
|
|
46609
|
+
callProviderMetadata: providerMetadataSchema.optional(),
|
|
46610
|
+
preliminary: exports_external.boolean().optional()
|
|
46611
|
+
}),
|
|
46612
|
+
exports_external.object({
|
|
46613
|
+
type: exports_external.literal("dynamic-tool"),
|
|
46614
|
+
toolName: exports_external.string(),
|
|
46615
|
+
toolCallId: exports_external.string(),
|
|
46616
|
+
state: exports_external.literal("output-error"),
|
|
46617
|
+
input: exports_external.unknown(),
|
|
46618
|
+
output: exports_external.never().optional(),
|
|
46619
|
+
errorText: exports_external.string(),
|
|
46620
|
+
callProviderMetadata: providerMetadataSchema.optional()
|
|
46621
|
+
}),
|
|
46622
|
+
exports_external.object({
|
|
46623
|
+
type: exports_external.string().startsWith("tool-"),
|
|
46624
|
+
toolCallId: exports_external.string(),
|
|
46625
|
+
state: exports_external.literal("input-streaming"),
|
|
46626
|
+
providerExecuted: exports_external.boolean().optional(),
|
|
46627
|
+
input: exports_external.unknown().optional(),
|
|
46628
|
+
output: exports_external.never().optional(),
|
|
46629
|
+
errorText: exports_external.never().optional(),
|
|
46630
|
+
approval: exports_external.never().optional()
|
|
46631
|
+
}),
|
|
46632
|
+
exports_external.object({
|
|
46633
|
+
type: exports_external.string().startsWith("tool-"),
|
|
46634
|
+
toolCallId: exports_external.string(),
|
|
46635
|
+
state: exports_external.literal("input-available"),
|
|
46636
|
+
providerExecuted: exports_external.boolean().optional(),
|
|
46637
|
+
input: exports_external.unknown(),
|
|
46638
|
+
output: exports_external.never().optional(),
|
|
46639
|
+
errorText: exports_external.never().optional(),
|
|
46640
|
+
callProviderMetadata: providerMetadataSchema.optional(),
|
|
46641
|
+
approval: exports_external.never().optional()
|
|
46642
|
+
}),
|
|
46643
|
+
exports_external.object({
|
|
46644
|
+
type: exports_external.string().startsWith("tool-"),
|
|
46645
|
+
toolCallId: exports_external.string(),
|
|
46646
|
+
state: exports_external.literal("approval-requested"),
|
|
46647
|
+
input: exports_external.unknown(),
|
|
46648
|
+
providerExecuted: exports_external.boolean().optional(),
|
|
46649
|
+
output: exports_external.never().optional(),
|
|
46650
|
+
errorText: exports_external.never().optional(),
|
|
46651
|
+
callProviderMetadata: providerMetadataSchema.optional(),
|
|
46652
|
+
approval: exports_external.object({
|
|
46653
|
+
id: exports_external.string(),
|
|
46654
|
+
approved: exports_external.never().optional(),
|
|
46655
|
+
reason: exports_external.never().optional()
|
|
46656
|
+
})
|
|
46657
|
+
}),
|
|
46658
|
+
exports_external.object({
|
|
46659
|
+
type: exports_external.string().startsWith("tool-"),
|
|
46660
|
+
toolCallId: exports_external.string(),
|
|
46661
|
+
state: exports_external.literal("approval-responded"),
|
|
46662
|
+
input: exports_external.unknown(),
|
|
46663
|
+
providerExecuted: exports_external.boolean().optional(),
|
|
46664
|
+
output: exports_external.never().optional(),
|
|
46665
|
+
errorText: exports_external.never().optional(),
|
|
46666
|
+
callProviderMetadata: providerMetadataSchema.optional(),
|
|
46667
|
+
approval: exports_external.object({
|
|
46668
|
+
id: exports_external.string(),
|
|
46669
|
+
approved: exports_external.boolean(),
|
|
46670
|
+
reason: exports_external.string().optional()
|
|
46671
|
+
})
|
|
46672
|
+
}),
|
|
46673
|
+
exports_external.object({
|
|
46674
|
+
type: exports_external.string().startsWith("tool-"),
|
|
46675
|
+
toolCallId: exports_external.string(),
|
|
46676
|
+
state: exports_external.literal("output-available"),
|
|
46677
|
+
providerExecuted: exports_external.boolean().optional(),
|
|
46678
|
+
input: exports_external.unknown(),
|
|
46679
|
+
output: exports_external.unknown(),
|
|
46680
|
+
errorText: exports_external.never().optional(),
|
|
46681
|
+
callProviderMetadata: providerMetadataSchema.optional(),
|
|
46682
|
+
preliminary: exports_external.boolean().optional(),
|
|
46683
|
+
approval: exports_external.object({
|
|
46684
|
+
id: exports_external.string(),
|
|
46685
|
+
approved: exports_external.literal(true),
|
|
46686
|
+
reason: exports_external.string().optional()
|
|
46687
|
+
}).optional()
|
|
46688
|
+
}),
|
|
46689
|
+
exports_external.object({
|
|
46690
|
+
type: exports_external.string().startsWith("tool-"),
|
|
46691
|
+
toolCallId: exports_external.string(),
|
|
46692
|
+
state: exports_external.literal("output-error"),
|
|
46693
|
+
providerExecuted: exports_external.boolean().optional(),
|
|
46694
|
+
input: exports_external.unknown(),
|
|
46695
|
+
output: exports_external.never().optional(),
|
|
46696
|
+
errorText: exports_external.string(),
|
|
46697
|
+
callProviderMetadata: providerMetadataSchema.optional(),
|
|
46698
|
+
approval: exports_external.object({
|
|
46699
|
+
id: exports_external.string(),
|
|
46700
|
+
approved: exports_external.literal(true),
|
|
46701
|
+
reason: exports_external.string().optional()
|
|
46702
|
+
}).optional()
|
|
46703
|
+
}),
|
|
46704
|
+
exports_external.object({
|
|
46705
|
+
type: exports_external.string().startsWith("tool-"),
|
|
46706
|
+
toolCallId: exports_external.string(),
|
|
46707
|
+
state: exports_external.literal("output-denied"),
|
|
46708
|
+
providerExecuted: exports_external.boolean().optional(),
|
|
46709
|
+
input: exports_external.unknown(),
|
|
46710
|
+
output: exports_external.never().optional(),
|
|
46711
|
+
errorText: exports_external.never().optional(),
|
|
46712
|
+
callProviderMetadata: providerMetadataSchema.optional(),
|
|
46713
|
+
approval: exports_external.object({
|
|
46714
|
+
id: exports_external.string(),
|
|
46715
|
+
approved: exports_external.literal(false),
|
|
46716
|
+
reason: exports_external.string().optional()
|
|
46717
|
+
})
|
|
46718
|
+
})
|
|
46719
|
+
]))
|
|
46720
|
+
}))));
|
|
46721
|
+
// ../../node_modules/.pnpm/@ai-sdk+provider-utils@3.0.18_zod@3.25.76/node_modules/@ai-sdk/provider-utils/dist/index.mjs
|
|
46722
|
+
var createIdGenerator2 = ({
|
|
46723
|
+
prefix,
|
|
46724
|
+
size = 16,
|
|
46725
|
+
alphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
|
|
46726
|
+
separator = "-"
|
|
46727
|
+
} = {}) => {
|
|
46728
|
+
const generator = () => {
|
|
46729
|
+
const alphabetLength = alphabet.length;
|
|
46730
|
+
const chars = new Array(size);
|
|
46731
|
+
for (let i = 0;i < size; i++) {
|
|
46732
|
+
chars[i] = alphabet[Math.random() * alphabetLength | 0];
|
|
46733
|
+
}
|
|
46734
|
+
return chars.join("");
|
|
46735
|
+
};
|
|
46736
|
+
if (prefix == null) {
|
|
46737
|
+
return generator;
|
|
46569
46738
|
}
|
|
46570
|
-
|
|
46571
|
-
|
|
46572
|
-
|
|
46573
|
-
|
|
46574
|
-
|
|
46575
|
-
|
|
46576
|
-
|
|
46577
|
-
|
|
46578
|
-
|
|
46579
|
-
|
|
46580
|
-
|
|
46581
|
-
|
|
46582
|
-
|
|
46583
|
-
|
|
46584
|
-
|
|
46585
|
-
|
|
46586
|
-
|
|
46587
|
-
|
|
46588
|
-
|
|
46589
|
-
|
|
46590
|
-
|
|
46591
|
-
|
|
46592
|
-
|
|
46593
|
-
|
|
46594
|
-
|
|
46595
|
-
|
|
46596
|
-
|
|
46597
|
-
|
|
46598
|
-
|
|
46599
|
-
|
|
46600
|
-
|
|
46601
|
-
|
|
46602
|
-
|
|
46603
|
-
|
|
46604
|
-
|
|
46605
|
-
|
|
46606
|
-
|
|
46739
|
+
if (alphabet.includes(separator)) {
|
|
46740
|
+
throw new InvalidArgumentError({
|
|
46741
|
+
argument: "separator",
|
|
46742
|
+
message: `The separator "${separator}" must not be part of the alphabet "${alphabet}".`
|
|
46743
|
+
});
|
|
46744
|
+
}
|
|
46745
|
+
return () => `${prefix}${separator}${generator()}`;
|
|
46746
|
+
};
|
|
46747
|
+
var generateId2 = createIdGenerator2();
|
|
46748
|
+
function getRuntimeEnvironmentUserAgent2(globalThisAny = globalThis) {
|
|
46749
|
+
var _a18, _b8, _c;
|
|
46750
|
+
if (globalThisAny.window) {
|
|
46751
|
+
return `runtime/browser`;
|
|
46752
|
+
}
|
|
46753
|
+
if ((_a18 = globalThisAny.navigator) == null ? undefined : _a18.userAgent) {
|
|
46754
|
+
return `runtime/${globalThisAny.navigator.userAgent.toLowerCase()}`;
|
|
46755
|
+
}
|
|
46756
|
+
if ((_c = (_b8 = globalThisAny.process) == null ? undefined : _b8.versions) == null ? undefined : _c.node) {
|
|
46757
|
+
return `runtime/node.js/${globalThisAny.process.version.substring(0)}`;
|
|
46758
|
+
}
|
|
46759
|
+
if (globalThisAny.EdgeRuntime) {
|
|
46760
|
+
return `runtime/vercel-edge`;
|
|
46761
|
+
}
|
|
46762
|
+
return "runtime/unknown";
|
|
46763
|
+
}
|
|
46764
|
+
function normalizeHeaders(headers) {
|
|
46765
|
+
if (headers == null) {
|
|
46766
|
+
return {};
|
|
46767
|
+
}
|
|
46768
|
+
const normalized = {};
|
|
46769
|
+
if (headers instanceof Headers) {
|
|
46770
|
+
headers.forEach((value, key) => {
|
|
46771
|
+
normalized[key.toLowerCase()] = value;
|
|
46772
|
+
});
|
|
46773
|
+
} else {
|
|
46774
|
+
if (!Array.isArray(headers)) {
|
|
46775
|
+
headers = Object.entries(headers);
|
|
46776
|
+
}
|
|
46777
|
+
for (const [key, value] of headers) {
|
|
46778
|
+
if (value != null) {
|
|
46779
|
+
normalized[key.toLowerCase()] = value;
|
|
46780
|
+
}
|
|
46781
|
+
}
|
|
46782
|
+
}
|
|
46783
|
+
return normalized;
|
|
46784
|
+
}
|
|
46785
|
+
function withUserAgentSuffix2(headers, ...userAgentSuffixParts) {
|
|
46786
|
+
const normalizedHeaders = new Headers(normalizeHeaders(headers));
|
|
46787
|
+
const currentUserAgentHeader = normalizedHeaders.get("user-agent") || "";
|
|
46788
|
+
normalizedHeaders.set("user-agent", [currentUserAgentHeader, ...userAgentSuffixParts].filter(Boolean).join(" "));
|
|
46789
|
+
return Object.fromEntries(normalizedHeaders.entries());
|
|
46790
|
+
}
|
|
46791
|
+
var validatorSymbol2 = Symbol.for("vercel.ai.validator");
|
|
46792
|
+
function tool2(tool22) {
|
|
46793
|
+
return tool22;
|
|
46794
|
+
}
|
|
46795
|
+
function dynamicTool(tool22) {
|
|
46796
|
+
return { ...tool22, type: "dynamic" };
|
|
46797
|
+
}
|
|
46798
|
+
var ignoreOverride2 = Symbol("Let zodToJsonSchema decide on which parser to use");
|
|
46799
|
+
var ALPHA_NUMERIC2 = new Set("ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvxyz0123456789");
|
|
46800
|
+
var schemaSymbol2 = Symbol.for("vercel.ai.schema");
|
|
46801
|
+
function jsonSchema2(jsonSchema22, {
|
|
46802
|
+
validate
|
|
46803
|
+
} = {}) {
|
|
46804
|
+
return {
|
|
46805
|
+
[schemaSymbol2]: true,
|
|
46806
|
+
_type: undefined,
|
|
46807
|
+
[validatorSymbol2]: true,
|
|
46808
|
+
get jsonSchema() {
|
|
46809
|
+
if (typeof jsonSchema22 === "function") {
|
|
46810
|
+
jsonSchema22 = jsonSchema22();
|
|
46811
|
+
}
|
|
46812
|
+
return jsonSchema22;
|
|
46813
|
+
},
|
|
46814
|
+
validate
|
|
46815
|
+
};
|
|
46816
|
+
}
|
|
46817
|
+
|
|
46818
|
+
// ../../node_modules/.pnpm/pkce-challenge@5.0.0/node_modules/pkce-challenge/dist/index.node.js
|
|
46819
|
+
var crypto;
|
|
46820
|
+
crypto = globalThis.crypto?.webcrypto ?? globalThis.crypto ?? import("node:crypto").then((m) => m.webcrypto);
|
|
46821
|
+
async function getRandomValues(size) {
|
|
46822
|
+
return (await crypto).getRandomValues(new Uint8Array(size));
|
|
46823
|
+
}
|
|
46824
|
+
async function random(size) {
|
|
46825
|
+
const mask = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~";
|
|
46826
|
+
let result = "";
|
|
46827
|
+
const randomUints = await getRandomValues(size);
|
|
46828
|
+
for (let i = 0;i < size; i++) {
|
|
46829
|
+
const randomIndex = randomUints[i] % mask.length;
|
|
46830
|
+
result += mask[randomIndex];
|
|
46831
|
+
}
|
|
46832
|
+
return result;
|
|
46833
|
+
}
|
|
46834
|
+
async function generateVerifier(length) {
|
|
46835
|
+
return await random(length);
|
|
46836
|
+
}
|
|
46837
|
+
async function generateChallenge(code_verifier) {
|
|
46838
|
+
const buffer = await (await crypto).subtle.digest("SHA-256", new TextEncoder().encode(code_verifier));
|
|
46839
|
+
return btoa(String.fromCharCode(...new Uint8Array(buffer))).replace(/\//g, "_").replace(/\+/g, "-").replace(/=/g, "");
|
|
46840
|
+
}
|
|
46841
|
+
async function pkceChallenge(length) {
|
|
46842
|
+
if (!length)
|
|
46843
|
+
length = 43;
|
|
46844
|
+
if (length < 43 || length > 128) {
|
|
46845
|
+
throw `Expected a length between 43 and 128. Received ${length}.`;
|
|
46846
|
+
}
|
|
46847
|
+
const verifier = await generateVerifier(length);
|
|
46848
|
+
const challenge = await generateChallenge(verifier);
|
|
46849
|
+
return {
|
|
46850
|
+
code_verifier: verifier,
|
|
46851
|
+
code_challenge: challenge
|
|
46852
|
+
};
|
|
46853
|
+
}
|
|
46854
|
+
|
|
46855
|
+
// ../../node_modules/.pnpm/@ai-sdk+mcp@0.0.11_zod@3.25.76/node_modules/@ai-sdk/mcp/dist/index.mjs
|
|
46856
|
+
var name17 = "AI_MCPClientError";
|
|
46857
|
+
var marker18 = `vercel.ai.error.${name17}`;
|
|
46858
|
+
var symbol19 = Symbol.for(marker18);
|
|
46859
|
+
var _a18;
|
|
46860
|
+
var _b8;
|
|
46861
|
+
var MCPClientError = class extends (_b8 = AISDKError, _a18 = symbol19, _b8) {
|
|
46862
|
+
constructor({
|
|
46863
|
+
name: name34 = "MCPClientError",
|
|
46864
|
+
message,
|
|
46865
|
+
cause,
|
|
46866
|
+
data,
|
|
46867
|
+
code
|
|
46868
|
+
}) {
|
|
46869
|
+
super({ name: name34, message, cause });
|
|
46870
|
+
this[_a18] = true;
|
|
46871
|
+
this.data = data;
|
|
46872
|
+
this.code = code;
|
|
46873
|
+
}
|
|
46874
|
+
static isInstance(error40) {
|
|
46875
|
+
return AISDKError.hasMarker(error40, marker18);
|
|
46876
|
+
}
|
|
46877
|
+
};
|
|
46878
|
+
var LATEST_PROTOCOL_VERSION = "2025-06-18";
|
|
46879
|
+
var SUPPORTED_PROTOCOL_VERSIONS = [
|
|
46880
|
+
LATEST_PROTOCOL_VERSION,
|
|
46881
|
+
"2025-03-26",
|
|
46882
|
+
"2024-11-05"
|
|
46883
|
+
];
|
|
46884
|
+
var ClientOrServerImplementationSchema2 = exports_external.looseObject({
|
|
46885
|
+
name: exports_external.string(),
|
|
46886
|
+
version: exports_external.string()
|
|
46887
|
+
});
|
|
46888
|
+
var BaseParamsSchema2 = exports_external.looseObject({
|
|
46889
|
+
_meta: exports_external.optional(exports_external.object({}).loose())
|
|
46890
|
+
});
|
|
46891
|
+
var ResultSchema2 = BaseParamsSchema2;
|
|
46892
|
+
var RequestSchema2 = exports_external.object({
|
|
46893
|
+
method: exports_external.string(),
|
|
46894
|
+
params: exports_external.optional(BaseParamsSchema2)
|
|
46895
|
+
});
|
|
46896
|
+
var ElicitationCapabilitySchema = exports_external.object({
|
|
46897
|
+
applyDefaults: exports_external.optional(exports_external.boolean())
|
|
46898
|
+
}).loose();
|
|
46899
|
+
var ServerCapabilitiesSchema2 = exports_external.looseObject({
|
|
46900
|
+
experimental: exports_external.optional(exports_external.object({}).loose()),
|
|
46901
|
+
logging: exports_external.optional(exports_external.object({}).loose()),
|
|
46902
|
+
prompts: exports_external.optional(exports_external.looseObject({
|
|
46903
|
+
listChanged: exports_external.optional(exports_external.boolean())
|
|
46904
|
+
})),
|
|
46905
|
+
resources: exports_external.optional(exports_external.looseObject({
|
|
46906
|
+
subscribe: exports_external.optional(exports_external.boolean()),
|
|
46907
|
+
listChanged: exports_external.optional(exports_external.boolean())
|
|
46908
|
+
})),
|
|
46909
|
+
tools: exports_external.optional(exports_external.looseObject({
|
|
46910
|
+
listChanged: exports_external.optional(exports_external.boolean())
|
|
46911
|
+
})),
|
|
46912
|
+
elicitation: exports_external.optional(ElicitationCapabilitySchema)
|
|
46913
|
+
});
|
|
46914
|
+
var ClientCapabilitiesSchema = exports_external.object({
|
|
46915
|
+
elicitation: exports_external.optional(ElicitationCapabilitySchema)
|
|
46916
|
+
}).loose();
|
|
46917
|
+
var InitializeResultSchema2 = ResultSchema2.extend({
|
|
46918
|
+
protocolVersion: exports_external.string(),
|
|
46919
|
+
capabilities: ServerCapabilitiesSchema2,
|
|
46920
|
+
serverInfo: ClientOrServerImplementationSchema2,
|
|
46921
|
+
instructions: exports_external.optional(exports_external.string())
|
|
46922
|
+
});
|
|
46923
|
+
var PaginatedResultSchema2 = ResultSchema2.extend({
|
|
46924
|
+
nextCursor: exports_external.optional(exports_external.string())
|
|
46925
|
+
});
|
|
46926
|
+
var ToolSchema2 = exports_external.object({
|
|
46927
|
+
name: exports_external.string(),
|
|
46928
|
+
description: exports_external.optional(exports_external.string()),
|
|
46929
|
+
inputSchema: exports_external.object({
|
|
46930
|
+
type: exports_external.literal("object"),
|
|
46931
|
+
properties: exports_external.optional(exports_external.object({}).loose())
|
|
46932
|
+
}).loose()
|
|
46933
|
+
}).loose();
|
|
46934
|
+
var ListToolsResultSchema2 = PaginatedResultSchema2.extend({
|
|
46935
|
+
tools: exports_external.array(ToolSchema2)
|
|
46936
|
+
});
|
|
46937
|
+
var TextContentSchema2 = exports_external.object({
|
|
46938
|
+
type: exports_external.literal("text"),
|
|
46939
|
+
text: exports_external.string()
|
|
46940
|
+
}).loose();
|
|
46941
|
+
var ImageContentSchema2 = exports_external.object({
|
|
46942
|
+
type: exports_external.literal("image"),
|
|
46943
|
+
data: exports_external.base64(),
|
|
46944
|
+
mimeType: exports_external.string()
|
|
46945
|
+
}).loose();
|
|
46946
|
+
var ResourceSchema = exports_external.object({
|
|
46947
|
+
uri: exports_external.string(),
|
|
46948
|
+
name: exports_external.string(),
|
|
46949
|
+
title: exports_external.optional(exports_external.string()),
|
|
46950
|
+
description: exports_external.optional(exports_external.string()),
|
|
46951
|
+
mimeType: exports_external.optional(exports_external.string()),
|
|
46952
|
+
size: exports_external.optional(exports_external.number())
|
|
46953
|
+
}).loose();
|
|
46954
|
+
var ListResourcesResultSchema = PaginatedResultSchema2.extend({
|
|
46955
|
+
resources: exports_external.array(ResourceSchema)
|
|
46956
|
+
});
|
|
46957
|
+
var ResourceContentsSchema2 = exports_external.object({
|
|
46958
|
+
uri: exports_external.string(),
|
|
46959
|
+
name: exports_external.optional(exports_external.string()),
|
|
46960
|
+
title: exports_external.optional(exports_external.string()),
|
|
46961
|
+
mimeType: exports_external.optional(exports_external.string())
|
|
46962
|
+
}).loose();
|
|
46963
|
+
var TextResourceContentsSchema2 = ResourceContentsSchema2.extend({
|
|
46964
|
+
text: exports_external.string()
|
|
46965
|
+
});
|
|
46966
|
+
var BlobResourceContentsSchema2 = ResourceContentsSchema2.extend({
|
|
46967
|
+
blob: exports_external.base64()
|
|
46968
|
+
});
|
|
46969
|
+
var EmbeddedResourceSchema2 = exports_external.object({
|
|
46970
|
+
type: exports_external.literal("resource"),
|
|
46971
|
+
resource: exports_external.union([TextResourceContentsSchema2, BlobResourceContentsSchema2])
|
|
46972
|
+
}).loose();
|
|
46973
|
+
var CallToolResultSchema2 = ResultSchema2.extend({
|
|
46974
|
+
content: exports_external.array(exports_external.union([TextContentSchema2, ImageContentSchema2, EmbeddedResourceSchema2])),
|
|
46975
|
+
isError: exports_external.boolean().default(false).optional()
|
|
46976
|
+
}).or(ResultSchema2.extend({
|
|
46977
|
+
toolResult: exports_external.unknown()
|
|
46978
|
+
}));
|
|
46979
|
+
var ResourceTemplateSchema = exports_external.object({
|
|
46980
|
+
uriTemplate: exports_external.string(),
|
|
46981
|
+
name: exports_external.string(),
|
|
46982
|
+
title: exports_external.optional(exports_external.string()),
|
|
46983
|
+
description: exports_external.optional(exports_external.string()),
|
|
46984
|
+
mimeType: exports_external.optional(exports_external.string())
|
|
46985
|
+
}).loose();
|
|
46986
|
+
var ListResourceTemplatesResultSchema = ResultSchema2.extend({
|
|
46987
|
+
resourceTemplates: exports_external.array(ResourceTemplateSchema)
|
|
46988
|
+
});
|
|
46989
|
+
var ReadResourceResultSchema = ResultSchema2.extend({
|
|
46990
|
+
contents: exports_external.array(exports_external.union([TextResourceContentsSchema2, BlobResourceContentsSchema2]))
|
|
46991
|
+
});
|
|
46992
|
+
var PromptArgumentSchema = exports_external.object({
|
|
46993
|
+
name: exports_external.string(),
|
|
46994
|
+
description: exports_external.optional(exports_external.string()),
|
|
46995
|
+
required: exports_external.optional(exports_external.boolean())
|
|
46996
|
+
}).loose();
|
|
46997
|
+
var PromptSchema = exports_external.object({
|
|
46998
|
+
name: exports_external.string(),
|
|
46999
|
+
title: exports_external.optional(exports_external.string()),
|
|
47000
|
+
description: exports_external.optional(exports_external.string()),
|
|
47001
|
+
arguments: exports_external.optional(exports_external.array(PromptArgumentSchema))
|
|
47002
|
+
}).loose();
|
|
47003
|
+
var ListPromptsResultSchema = PaginatedResultSchema2.extend({
|
|
47004
|
+
prompts: exports_external.array(PromptSchema)
|
|
47005
|
+
});
|
|
47006
|
+
var PromptMessageSchema = exports_external.object({
|
|
47007
|
+
role: exports_external.union([exports_external.literal("user"), exports_external.literal("assistant")]),
|
|
47008
|
+
content: exports_external.union([
|
|
47009
|
+
TextContentSchema2,
|
|
47010
|
+
ImageContentSchema2,
|
|
47011
|
+
EmbeddedResourceSchema2
|
|
47012
|
+
])
|
|
47013
|
+
}).loose();
|
|
47014
|
+
var GetPromptResultSchema = ResultSchema2.extend({
|
|
47015
|
+
description: exports_external.optional(exports_external.string()),
|
|
47016
|
+
messages: exports_external.array(PromptMessageSchema)
|
|
47017
|
+
});
|
|
47018
|
+
var ElicitationRequestParamsSchema = BaseParamsSchema2.extend({
|
|
47019
|
+
message: exports_external.string(),
|
|
47020
|
+
requestedSchema: exports_external.unknown()
|
|
47021
|
+
});
|
|
47022
|
+
var ElicitationRequestSchema = RequestSchema2.extend({
|
|
47023
|
+
method: exports_external.literal("elicitation/create"),
|
|
47024
|
+
params: ElicitationRequestParamsSchema
|
|
47025
|
+
});
|
|
47026
|
+
var ElicitResultSchema = ResultSchema2.extend({
|
|
47027
|
+
action: exports_external.union([
|
|
47028
|
+
exports_external.literal("accept"),
|
|
47029
|
+
exports_external.literal("decline"),
|
|
47030
|
+
exports_external.literal("cancel")
|
|
47031
|
+
]),
|
|
47032
|
+
content: exports_external.optional(exports_external.record(exports_external.string(), exports_external.unknown()))
|
|
47033
|
+
});
|
|
47034
|
+
var JSONRPC_VERSION2 = "2.0";
|
|
47035
|
+
var JSONRPCRequestSchema2 = exports_external.object({
|
|
47036
|
+
jsonrpc: exports_external.literal(JSONRPC_VERSION2),
|
|
47037
|
+
id: exports_external.union([exports_external.string(), exports_external.number().int()])
|
|
47038
|
+
}).merge(RequestSchema2).strict();
|
|
47039
|
+
var JSONRPCResponseSchema2 = exports_external.object({
|
|
47040
|
+
jsonrpc: exports_external.literal(JSONRPC_VERSION2),
|
|
47041
|
+
id: exports_external.union([exports_external.string(), exports_external.number().int()]),
|
|
47042
|
+
result: ResultSchema2
|
|
47043
|
+
}).strict();
|
|
47044
|
+
var JSONRPCErrorSchema2 = exports_external.object({
|
|
47045
|
+
jsonrpc: exports_external.literal(JSONRPC_VERSION2),
|
|
47046
|
+
id: exports_external.union([exports_external.string(), exports_external.number().int()]),
|
|
47047
|
+
error: exports_external.object({
|
|
47048
|
+
code: exports_external.number().int(),
|
|
47049
|
+
message: exports_external.string(),
|
|
47050
|
+
data: exports_external.optional(exports_external.unknown())
|
|
47051
|
+
})
|
|
47052
|
+
}).strict();
|
|
47053
|
+
var JSONRPCNotificationSchema2 = exports_external.object({
|
|
47054
|
+
jsonrpc: exports_external.literal(JSONRPC_VERSION2)
|
|
47055
|
+
}).merge(exports_external.object({
|
|
47056
|
+
method: exports_external.string(),
|
|
47057
|
+
params: exports_external.optional(BaseParamsSchema2)
|
|
47058
|
+
})).strict();
|
|
47059
|
+
var JSONRPCMessageSchema2 = exports_external.union([
|
|
47060
|
+
JSONRPCRequestSchema2,
|
|
47061
|
+
JSONRPCNotificationSchema2,
|
|
47062
|
+
JSONRPCResponseSchema2,
|
|
47063
|
+
JSONRPCErrorSchema2
|
|
47064
|
+
]);
|
|
47065
|
+
var VERSION4 = typeof __PACKAGE_VERSION__ !== "undefined" ? __PACKAGE_VERSION__ : "0.0.0-test";
|
|
47066
|
+
var OAuthTokensSchema = exports_external.object({
|
|
47067
|
+
access_token: exports_external.string(),
|
|
47068
|
+
id_token: exports_external.string().optional(),
|
|
47069
|
+
token_type: exports_external.string(),
|
|
47070
|
+
expires_in: exports_external.number().optional(),
|
|
47071
|
+
scope: exports_external.string().optional(),
|
|
47072
|
+
refresh_token: exports_external.string().optional()
|
|
47073
|
+
}).strip();
|
|
47074
|
+
var SafeUrlSchema = exports_external.string().url().superRefine((val, ctx) => {
|
|
47075
|
+
if (!URL.canParse(val)) {
|
|
47076
|
+
ctx.addIssue({
|
|
47077
|
+
code: exports_external.ZodIssueCode.custom,
|
|
47078
|
+
message: "URL must be parseable",
|
|
47079
|
+
fatal: true
|
|
47080
|
+
});
|
|
47081
|
+
return exports_external.NEVER;
|
|
47082
|
+
}
|
|
47083
|
+
}).refine((url2) => {
|
|
47084
|
+
const u = new URL(url2);
|
|
47085
|
+
return u.protocol !== "javascript:" && u.protocol !== "data:" && u.protocol !== "vbscript:";
|
|
47086
|
+
}, { message: "URL cannot use javascript:, data:, or vbscript: scheme" });
|
|
47087
|
+
var OAuthProtectedResourceMetadataSchema = exports_external.object({
|
|
47088
|
+
resource: exports_external.string().url(),
|
|
47089
|
+
authorization_servers: exports_external.array(SafeUrlSchema).optional(),
|
|
47090
|
+
jwks_uri: exports_external.string().url().optional(),
|
|
47091
|
+
scopes_supported: exports_external.array(exports_external.string()).optional(),
|
|
47092
|
+
bearer_methods_supported: exports_external.array(exports_external.string()).optional(),
|
|
47093
|
+
resource_signing_alg_values_supported: exports_external.array(exports_external.string()).optional(),
|
|
47094
|
+
resource_name: exports_external.string().optional(),
|
|
47095
|
+
resource_documentation: exports_external.string().optional(),
|
|
47096
|
+
resource_policy_uri: exports_external.string().url().optional(),
|
|
47097
|
+
resource_tos_uri: exports_external.string().url().optional(),
|
|
47098
|
+
tls_client_certificate_bound_access_tokens: exports_external.boolean().optional(),
|
|
47099
|
+
authorization_details_types_supported: exports_external.array(exports_external.string()).optional(),
|
|
47100
|
+
dpop_signing_alg_values_supported: exports_external.array(exports_external.string()).optional(),
|
|
47101
|
+
dpop_bound_access_tokens_required: exports_external.boolean().optional()
|
|
47102
|
+
}).passthrough();
|
|
47103
|
+
var OAuthMetadataSchema = exports_external.object({
|
|
47104
|
+
issuer: exports_external.string(),
|
|
47105
|
+
authorization_endpoint: SafeUrlSchema,
|
|
47106
|
+
token_endpoint: SafeUrlSchema,
|
|
47107
|
+
registration_endpoint: SafeUrlSchema.optional(),
|
|
47108
|
+
scopes_supported: exports_external.array(exports_external.string()).optional(),
|
|
47109
|
+
response_types_supported: exports_external.array(exports_external.string()),
|
|
47110
|
+
grant_types_supported: exports_external.array(exports_external.string()).optional(),
|
|
47111
|
+
code_challenge_methods_supported: exports_external.array(exports_external.string()),
|
|
47112
|
+
token_endpoint_auth_methods_supported: exports_external.array(exports_external.string()).optional(),
|
|
47113
|
+
token_endpoint_auth_signing_alg_values_supported: exports_external.array(exports_external.string()).optional()
|
|
47114
|
+
}).passthrough();
|
|
47115
|
+
var OpenIdProviderMetadataSchema = exports_external.object({
|
|
47116
|
+
issuer: exports_external.string(),
|
|
47117
|
+
authorization_endpoint: SafeUrlSchema,
|
|
47118
|
+
token_endpoint: SafeUrlSchema,
|
|
47119
|
+
userinfo_endpoint: SafeUrlSchema.optional(),
|
|
47120
|
+
jwks_uri: SafeUrlSchema,
|
|
47121
|
+
registration_endpoint: SafeUrlSchema.optional(),
|
|
47122
|
+
scopes_supported: exports_external.array(exports_external.string()).optional(),
|
|
47123
|
+
response_types_supported: exports_external.array(exports_external.string()),
|
|
47124
|
+
grant_types_supported: exports_external.array(exports_external.string()).optional(),
|
|
47125
|
+
subject_types_supported: exports_external.array(exports_external.string()),
|
|
47126
|
+
id_token_signing_alg_values_supported: exports_external.array(exports_external.string()),
|
|
47127
|
+
claims_supported: exports_external.array(exports_external.string()).optional(),
|
|
47128
|
+
token_endpoint_auth_methods_supported: exports_external.array(exports_external.string()).optional()
|
|
47129
|
+
}).passthrough();
|
|
47130
|
+
var OpenIdProviderDiscoveryMetadataSchema = OpenIdProviderMetadataSchema.merge(OAuthMetadataSchema.pick({
|
|
47131
|
+
code_challenge_methods_supported: true
|
|
47132
|
+
}));
|
|
47133
|
+
var OAuthClientInformationSchema = exports_external.object({
|
|
47134
|
+
client_id: exports_external.string(),
|
|
47135
|
+
client_secret: exports_external.string().optional(),
|
|
47136
|
+
client_id_issued_at: exports_external.number().optional(),
|
|
47137
|
+
client_secret_expires_at: exports_external.number().optional()
|
|
47138
|
+
}).strip();
|
|
47139
|
+
var OAuthClientMetadataSchema = exports_external.object({
|
|
47140
|
+
redirect_uris: exports_external.array(SafeUrlSchema),
|
|
47141
|
+
token_endpoint_auth_method: exports_external.string().optional(),
|
|
47142
|
+
grant_types: exports_external.array(exports_external.string()).optional(),
|
|
47143
|
+
response_types: exports_external.array(exports_external.string()).optional(),
|
|
47144
|
+
client_name: exports_external.string().optional(),
|
|
47145
|
+
client_uri: SafeUrlSchema.optional(),
|
|
47146
|
+
logo_uri: SafeUrlSchema.optional(),
|
|
47147
|
+
scope: exports_external.string().optional(),
|
|
47148
|
+
contacts: exports_external.array(exports_external.string()).optional(),
|
|
47149
|
+
tos_uri: SafeUrlSchema.optional(),
|
|
47150
|
+
policy_uri: exports_external.string().optional(),
|
|
47151
|
+
jwks_uri: SafeUrlSchema.optional(),
|
|
47152
|
+
jwks: exports_external.any().optional(),
|
|
47153
|
+
software_id: exports_external.string().optional(),
|
|
47154
|
+
software_version: exports_external.string().optional(),
|
|
47155
|
+
software_statement: exports_external.string().optional()
|
|
47156
|
+
}).strip();
|
|
47157
|
+
var OAuthErrorResponseSchema = exports_external.object({
|
|
47158
|
+
error: exports_external.string(),
|
|
47159
|
+
error_description: exports_external.string().optional(),
|
|
47160
|
+
error_uri: exports_external.string().optional()
|
|
47161
|
+
});
|
|
47162
|
+
var OAuthClientInformationFullSchema = OAuthClientMetadataSchema.merge(OAuthClientInformationSchema);
|
|
47163
|
+
var name24 = "AI_MCPClientOAuthError";
|
|
47164
|
+
var marker24 = `vercel.ai.error.${name24}`;
|
|
47165
|
+
var symbol24 = Symbol.for(marker24);
|
|
47166
|
+
var _a24;
|
|
47167
|
+
var _b22;
|
|
47168
|
+
var MCPClientOAuthError = class extends (_b22 = AISDKError, _a24 = symbol24, _b22) {
|
|
47169
|
+
constructor({
|
|
47170
|
+
name: name34 = "MCPClientOAuthError",
|
|
47171
|
+
message,
|
|
47172
|
+
cause
|
|
47173
|
+
}) {
|
|
47174
|
+
super({ name: name34, message, cause });
|
|
47175
|
+
this[_a24] = true;
|
|
47176
|
+
}
|
|
47177
|
+
static isInstance(error40) {
|
|
47178
|
+
return AISDKError.hasMarker(error40, marker24);
|
|
47179
|
+
}
|
|
47180
|
+
};
|
|
47181
|
+
var ServerError = class extends MCPClientOAuthError {
|
|
47182
|
+
};
|
|
47183
|
+
ServerError.errorCode = "server_error";
|
|
47184
|
+
var InvalidClientError = class extends MCPClientOAuthError {
|
|
47185
|
+
};
|
|
47186
|
+
InvalidClientError.errorCode = "invalid_client";
|
|
47187
|
+
var InvalidGrantError = class extends MCPClientOAuthError {
|
|
47188
|
+
};
|
|
47189
|
+
InvalidGrantError.errorCode = "invalid_grant";
|
|
47190
|
+
var UnauthorizedClientError = class extends MCPClientOAuthError {
|
|
47191
|
+
};
|
|
47192
|
+
UnauthorizedClientError.errorCode = "unauthorized_client";
|
|
47193
|
+
var OAUTH_ERRORS = {
|
|
47194
|
+
[ServerError.errorCode]: ServerError,
|
|
47195
|
+
[InvalidClientError.errorCode]: InvalidClientError,
|
|
47196
|
+
[InvalidGrantError.errorCode]: InvalidGrantError,
|
|
47197
|
+
[UnauthorizedClientError.errorCode]: UnauthorizedClientError
|
|
47198
|
+
};
|
|
47199
|
+
function resourceUrlFromServerUrl(url2) {
|
|
47200
|
+
const resourceURL = typeof url2 === "string" ? new URL(url2) : new URL(url2.href);
|
|
47201
|
+
resourceURL.hash = "";
|
|
47202
|
+
return resourceURL;
|
|
47203
|
+
}
|
|
47204
|
+
function checkResourceAllowed({
|
|
47205
|
+
requestedResource,
|
|
47206
|
+
configuredResource
|
|
47207
|
+
}) {
|
|
47208
|
+
const requested = typeof requestedResource === "string" ? new URL(requestedResource) : new URL(requestedResource.href);
|
|
47209
|
+
const configured = typeof configuredResource === "string" ? new URL(configuredResource) : new URL(configuredResource.href);
|
|
47210
|
+
if (requested.origin !== configured.origin) {
|
|
47211
|
+
return false;
|
|
47212
|
+
}
|
|
47213
|
+
if (requested.pathname.length < configured.pathname.length) {
|
|
47214
|
+
return false;
|
|
47215
|
+
}
|
|
47216
|
+
const requestedPath = requested.pathname.endsWith("/") ? requested.pathname : requested.pathname + "/";
|
|
47217
|
+
const configuredPath = configured.pathname.endsWith("/") ? configured.pathname : configured.pathname + "/";
|
|
47218
|
+
return requestedPath.startsWith(configuredPath);
|
|
47219
|
+
}
|
|
47220
|
+
var UnauthorizedError = class extends Error {
|
|
47221
|
+
constructor(message = "Unauthorized") {
|
|
47222
|
+
super(message);
|
|
47223
|
+
this.name = "UnauthorizedError";
|
|
47224
|
+
}
|
|
47225
|
+
};
|
|
47226
|
+
function extractResourceMetadataUrl(response) {
|
|
47227
|
+
var _a34;
|
|
47228
|
+
const header = (_a34 = response.headers.get("www-authenticate")) != null ? _a34 : response.headers.get("WWW-Authenticate");
|
|
47229
|
+
if (!header) {
|
|
47230
|
+
return;
|
|
47231
|
+
}
|
|
47232
|
+
const [type, scheme] = header.split(" ");
|
|
47233
|
+
if (type.toLowerCase() !== "bearer" || !scheme) {
|
|
47234
|
+
return;
|
|
47235
|
+
}
|
|
47236
|
+
const regex = /resource_metadata="([^"]*)"/;
|
|
47237
|
+
const match = header.match(regex);
|
|
47238
|
+
if (!match) {
|
|
47239
|
+
return;
|
|
47240
|
+
}
|
|
47241
|
+
try {
|
|
47242
|
+
return new URL(match[1]);
|
|
47243
|
+
} catch (e) {
|
|
47244
|
+
return;
|
|
47245
|
+
}
|
|
47246
|
+
}
|
|
47247
|
+
function buildWellKnownPath(wellKnownPrefix, pathname = "", options = {}) {
|
|
47248
|
+
if (pathname.endsWith("/")) {
|
|
47249
|
+
pathname = pathname.slice(0, -1);
|
|
47250
|
+
}
|
|
47251
|
+
return options.prependPathname ? `${pathname}/.well-known/${wellKnownPrefix}` : `/.well-known/${wellKnownPrefix}${pathname}`;
|
|
47252
|
+
}
|
|
47253
|
+
async function fetchWithCorsRetry(url2, headers, fetchFn = fetch) {
|
|
47254
|
+
try {
|
|
47255
|
+
return await fetchFn(url2, { headers });
|
|
47256
|
+
} catch (error40) {
|
|
47257
|
+
if (error40 instanceof TypeError) {
|
|
47258
|
+
if (headers) {
|
|
47259
|
+
return fetchWithCorsRetry(url2, undefined, fetchFn);
|
|
47260
|
+
} else {
|
|
47261
|
+
return;
|
|
47262
|
+
}
|
|
47263
|
+
}
|
|
47264
|
+
throw error40;
|
|
47265
|
+
}
|
|
47266
|
+
}
|
|
47267
|
+
async function tryMetadataDiscovery(url2, protocolVersion, fetchFn = fetch) {
|
|
47268
|
+
const headers = {
|
|
47269
|
+
"MCP-Protocol-Version": protocolVersion
|
|
47270
|
+
};
|
|
47271
|
+
return await fetchWithCorsRetry(url2, headers, fetchFn);
|
|
47272
|
+
}
|
|
47273
|
+
function shouldAttemptFallback(response, pathname) {
|
|
47274
|
+
return !response || response.status >= 400 && response.status < 500 && pathname !== "/";
|
|
47275
|
+
}
|
|
47276
|
+
async function discoverMetadataWithFallback(serverUrl, wellKnownType, fetchFn, opts) {
|
|
47277
|
+
var _a34, _b32;
|
|
47278
|
+
const issuer = new URL(serverUrl);
|
|
47279
|
+
const protocolVersion = (_a34 = opts == null ? undefined : opts.protocolVersion) != null ? _a34 : LATEST_PROTOCOL_VERSION;
|
|
47280
|
+
let url2;
|
|
47281
|
+
if (opts == null ? undefined : opts.metadataUrl) {
|
|
47282
|
+
url2 = new URL(opts.metadataUrl);
|
|
47283
|
+
} else {
|
|
47284
|
+
const wellKnownPath = buildWellKnownPath(wellKnownType, issuer.pathname);
|
|
47285
|
+
url2 = new URL(wellKnownPath, (_b32 = opts == null ? undefined : opts.metadataServerUrl) != null ? _b32 : issuer);
|
|
47286
|
+
url2.search = issuer.search;
|
|
47287
|
+
}
|
|
47288
|
+
let response = await tryMetadataDiscovery(url2, protocolVersion, fetchFn);
|
|
47289
|
+
if (!(opts == null ? undefined : opts.metadataUrl) && shouldAttemptFallback(response, issuer.pathname)) {
|
|
47290
|
+
const rootUrl = new URL(`/.well-known/${wellKnownType}`, issuer);
|
|
47291
|
+
response = await tryMetadataDiscovery(rootUrl, protocolVersion, fetchFn);
|
|
47292
|
+
}
|
|
47293
|
+
return response;
|
|
47294
|
+
}
|
|
47295
|
+
async function discoverOAuthProtectedResourceMetadata(serverUrl, opts, fetchFn = fetch) {
|
|
47296
|
+
const response = await discoverMetadataWithFallback(serverUrl, "oauth-protected-resource", fetchFn, {
|
|
47297
|
+
protocolVersion: opts == null ? undefined : opts.protocolVersion,
|
|
47298
|
+
metadataUrl: opts == null ? undefined : opts.resourceMetadataUrl
|
|
47299
|
+
});
|
|
47300
|
+
if (!response || response.status === 404) {
|
|
47301
|
+
throw new Error(`Resource server does not implement OAuth 2.0 Protected Resource Metadata.`);
|
|
47302
|
+
}
|
|
47303
|
+
if (!response.ok) {
|
|
47304
|
+
throw new Error(`HTTP ${response.status} trying to load well-known OAuth protected resource metadata.`);
|
|
47305
|
+
}
|
|
47306
|
+
return OAuthProtectedResourceMetadataSchema.parse(await response.json());
|
|
47307
|
+
}
|
|
47308
|
+
function buildDiscoveryUrls(authorizationServerUrl) {
|
|
47309
|
+
const url2 = typeof authorizationServerUrl === "string" ? new URL(authorizationServerUrl) : authorizationServerUrl;
|
|
47310
|
+
const hasPath = url2.pathname !== "/";
|
|
47311
|
+
const urlsToTry = [];
|
|
47312
|
+
if (!hasPath) {
|
|
47313
|
+
urlsToTry.push({
|
|
47314
|
+
url: new URL("/.well-known/oauth-authorization-server", url2.origin),
|
|
47315
|
+
type: "oauth"
|
|
47316
|
+
});
|
|
47317
|
+
urlsToTry.push({
|
|
47318
|
+
url: new URL("/.well-known/openid-configuration", url2.origin),
|
|
47319
|
+
type: "oidc"
|
|
47320
|
+
});
|
|
47321
|
+
return urlsToTry;
|
|
47322
|
+
}
|
|
47323
|
+
let pathname = url2.pathname;
|
|
47324
|
+
if (pathname.endsWith("/")) {
|
|
47325
|
+
pathname = pathname.slice(0, -1);
|
|
47326
|
+
}
|
|
47327
|
+
urlsToTry.push({
|
|
47328
|
+
url: new URL(`/.well-known/oauth-authorization-server${pathname}`, url2.origin),
|
|
47329
|
+
type: "oauth"
|
|
47330
|
+
});
|
|
47331
|
+
urlsToTry.push({
|
|
47332
|
+
url: new URL("/.well-known/oauth-authorization-server", url2.origin),
|
|
47333
|
+
type: "oauth"
|
|
47334
|
+
});
|
|
47335
|
+
urlsToTry.push({
|
|
47336
|
+
url: new URL(`/.well-known/openid-configuration${pathname}`, url2.origin),
|
|
47337
|
+
type: "oidc"
|
|
47338
|
+
});
|
|
47339
|
+
urlsToTry.push({
|
|
47340
|
+
url: new URL(`${pathname}/.well-known/openid-configuration`, url2.origin),
|
|
47341
|
+
type: "oidc"
|
|
47342
|
+
});
|
|
47343
|
+
return urlsToTry;
|
|
47344
|
+
}
|
|
47345
|
+
async function discoverAuthorizationServerMetadata(authorizationServerUrl, {
|
|
47346
|
+
fetchFn = fetch,
|
|
47347
|
+
protocolVersion = LATEST_PROTOCOL_VERSION
|
|
47348
|
+
} = {}) {
|
|
47349
|
+
var _a34;
|
|
47350
|
+
const headers = { "MCP-Protocol-Version": protocolVersion };
|
|
47351
|
+
const urlsToTry = buildDiscoveryUrls(authorizationServerUrl);
|
|
47352
|
+
for (const { url: endpointUrl, type } of urlsToTry) {
|
|
47353
|
+
const response = await fetchWithCorsRetry(endpointUrl, headers, fetchFn);
|
|
47354
|
+
if (!response) {
|
|
47355
|
+
continue;
|
|
47356
|
+
}
|
|
47357
|
+
if (!response.ok) {
|
|
47358
|
+
if (response.status >= 400 && response.status < 500) {
|
|
47359
|
+
continue;
|
|
47360
|
+
}
|
|
47361
|
+
throw new Error(`HTTP ${response.status} trying to load ${type === "oauth" ? "OAuth" : "OpenID provider"} metadata from ${endpointUrl}`);
|
|
47362
|
+
}
|
|
47363
|
+
if (type === "oauth") {
|
|
47364
|
+
return OAuthMetadataSchema.parse(await response.json());
|
|
47365
|
+
} else {
|
|
47366
|
+
const metadata = OpenIdProviderDiscoveryMetadataSchema.parse(await response.json());
|
|
47367
|
+
if (!((_a34 = metadata.code_challenge_methods_supported) == null ? undefined : _a34.includes("S256"))) {
|
|
47368
|
+
throw new Error(`Incompatible OIDC provider at ${endpointUrl}: does not support S256 code challenge method required by MCP specification`);
|
|
47369
|
+
}
|
|
47370
|
+
return metadata;
|
|
47371
|
+
}
|
|
47372
|
+
}
|
|
47373
|
+
return;
|
|
47374
|
+
}
|
|
47375
|
+
async function startAuthorization(authorizationServerUrl, {
|
|
47376
|
+
metadata,
|
|
47377
|
+
clientInformation,
|
|
47378
|
+
redirectUrl,
|
|
47379
|
+
scope,
|
|
47380
|
+
state,
|
|
47381
|
+
resource
|
|
47382
|
+
}) {
|
|
47383
|
+
const responseType = "code";
|
|
47384
|
+
const codeChallengeMethod = "S256";
|
|
47385
|
+
let authorizationUrl;
|
|
47386
|
+
if (metadata) {
|
|
47387
|
+
authorizationUrl = new URL(metadata.authorization_endpoint);
|
|
47388
|
+
if (!metadata.response_types_supported.includes(responseType)) {
|
|
47389
|
+
throw new Error(`Incompatible auth server: does not support response type ${responseType}`);
|
|
47390
|
+
}
|
|
47391
|
+
if (!metadata.code_challenge_methods_supported || !metadata.code_challenge_methods_supported.includes(codeChallengeMethod)) {
|
|
47392
|
+
throw new Error(`Incompatible auth server: does not support code challenge method ${codeChallengeMethod}`);
|
|
47393
|
+
}
|
|
47394
|
+
} else {
|
|
47395
|
+
authorizationUrl = new URL("/authorize", authorizationServerUrl);
|
|
47396
|
+
}
|
|
47397
|
+
const challenge = await pkceChallenge();
|
|
47398
|
+
const codeVerifier = challenge.code_verifier;
|
|
47399
|
+
const codeChallenge = challenge.code_challenge;
|
|
47400
|
+
authorizationUrl.searchParams.set("response_type", responseType);
|
|
47401
|
+
authorizationUrl.searchParams.set("client_id", clientInformation.client_id);
|
|
47402
|
+
authorizationUrl.searchParams.set("code_challenge", codeChallenge);
|
|
47403
|
+
authorizationUrl.searchParams.set("code_challenge_method", codeChallengeMethod);
|
|
47404
|
+
authorizationUrl.searchParams.set("redirect_uri", String(redirectUrl));
|
|
47405
|
+
if (state) {
|
|
47406
|
+
authorizationUrl.searchParams.set("state", state);
|
|
47407
|
+
}
|
|
47408
|
+
if (scope) {
|
|
47409
|
+
authorizationUrl.searchParams.set("scope", scope);
|
|
47410
|
+
}
|
|
47411
|
+
if (scope == null ? undefined : scope.includes("offline_access")) {
|
|
47412
|
+
authorizationUrl.searchParams.append("prompt", "consent");
|
|
47413
|
+
}
|
|
47414
|
+
if (resource) {
|
|
47415
|
+
authorizationUrl.searchParams.set("resource", resource.href);
|
|
47416
|
+
}
|
|
47417
|
+
return { authorizationUrl, codeVerifier };
|
|
47418
|
+
}
|
|
47419
|
+
function selectClientAuthMethod(clientInformation, supportedMethods) {
|
|
47420
|
+
const hasClientSecret = clientInformation.client_secret !== undefined;
|
|
47421
|
+
if (supportedMethods.length === 0) {
|
|
47422
|
+
return hasClientSecret ? "client_secret_post" : "none";
|
|
47423
|
+
}
|
|
47424
|
+
if (hasClientSecret && supportedMethods.includes("client_secret_basic")) {
|
|
47425
|
+
return "client_secret_basic";
|
|
47426
|
+
}
|
|
47427
|
+
if (hasClientSecret && supportedMethods.includes("client_secret_post")) {
|
|
47428
|
+
return "client_secret_post";
|
|
47429
|
+
}
|
|
47430
|
+
if (supportedMethods.includes("none")) {
|
|
47431
|
+
return "none";
|
|
47432
|
+
}
|
|
47433
|
+
return hasClientSecret ? "client_secret_post" : "none";
|
|
47434
|
+
}
|
|
47435
|
+
function applyClientAuthentication(method, clientInformation, headers, params) {
|
|
47436
|
+
const { client_id, client_secret } = clientInformation;
|
|
47437
|
+
switch (method) {
|
|
47438
|
+
case "client_secret_basic":
|
|
47439
|
+
applyBasicAuth(client_id, client_secret, headers);
|
|
47440
|
+
return;
|
|
47441
|
+
case "client_secret_post":
|
|
47442
|
+
applyPostAuth(client_id, client_secret, params);
|
|
47443
|
+
return;
|
|
47444
|
+
case "none":
|
|
47445
|
+
applyPublicAuth(client_id, params);
|
|
47446
|
+
return;
|
|
47447
|
+
default:
|
|
47448
|
+
throw new Error(`Unsupported client authentication method: ${method}`);
|
|
47449
|
+
}
|
|
47450
|
+
}
|
|
47451
|
+
function applyBasicAuth(clientId, clientSecret, headers) {
|
|
47452
|
+
if (!clientSecret) {
|
|
47453
|
+
throw new Error("client_secret_basic authentication requires a client_secret");
|
|
47454
|
+
}
|
|
47455
|
+
const credentials = btoa(`${clientId}:${clientSecret}`);
|
|
47456
|
+
headers.set("Authorization", `Basic ${credentials}`);
|
|
47457
|
+
}
|
|
47458
|
+
function applyPostAuth(clientId, clientSecret, params) {
|
|
47459
|
+
params.set("client_id", clientId);
|
|
47460
|
+
if (clientSecret) {
|
|
47461
|
+
params.set("client_secret", clientSecret);
|
|
47462
|
+
}
|
|
47463
|
+
}
|
|
47464
|
+
function applyPublicAuth(clientId, params) {
|
|
47465
|
+
params.set("client_id", clientId);
|
|
47466
|
+
}
|
|
47467
|
+
async function parseErrorResponse(input) {
|
|
47468
|
+
const statusCode = input instanceof Response ? input.status : undefined;
|
|
47469
|
+
const body = input instanceof Response ? await input.text() : input;
|
|
47470
|
+
try {
|
|
47471
|
+
const result = OAuthErrorResponseSchema.parse(JSON.parse(body));
|
|
47472
|
+
const { error: error40, error_description, error_uri } = result;
|
|
47473
|
+
const errorClass = OAUTH_ERRORS[error40] || ServerError;
|
|
47474
|
+
return new errorClass({
|
|
47475
|
+
message: error_description || "",
|
|
47476
|
+
cause: error_uri
|
|
47477
|
+
});
|
|
47478
|
+
} catch (error40) {
|
|
47479
|
+
const errorMessage = `${statusCode ? `HTTP ${statusCode}: ` : ""}Invalid OAuth error response: ${error40}. Raw body: ${body}`;
|
|
47480
|
+
return new ServerError({ message: errorMessage });
|
|
47481
|
+
}
|
|
47482
|
+
}
|
|
47483
|
+
async function exchangeAuthorization(authorizationServerUrl, {
|
|
47484
|
+
metadata,
|
|
47485
|
+
clientInformation,
|
|
47486
|
+
authorizationCode,
|
|
47487
|
+
codeVerifier,
|
|
47488
|
+
redirectUri,
|
|
47489
|
+
resource,
|
|
47490
|
+
addClientAuthentication,
|
|
47491
|
+
fetchFn
|
|
47492
|
+
}) {
|
|
47493
|
+
var _a34;
|
|
47494
|
+
const grantType = "authorization_code";
|
|
47495
|
+
const tokenUrl = (metadata == null ? undefined : metadata.token_endpoint) ? new URL(metadata.token_endpoint) : new URL("/token", authorizationServerUrl);
|
|
47496
|
+
if ((metadata == null ? undefined : metadata.grant_types_supported) && !metadata.grant_types_supported.includes(grantType)) {
|
|
47497
|
+
throw new Error(`Incompatible auth server: does not support grant type ${grantType}`);
|
|
47498
|
+
}
|
|
47499
|
+
const headers = new Headers({
|
|
47500
|
+
"Content-Type": "application/x-www-form-urlencoded",
|
|
47501
|
+
Accept: "application/json"
|
|
47502
|
+
});
|
|
47503
|
+
const params = new URLSearchParams({
|
|
47504
|
+
grant_type: grantType,
|
|
47505
|
+
code: authorizationCode,
|
|
47506
|
+
code_verifier: codeVerifier,
|
|
47507
|
+
redirect_uri: String(redirectUri)
|
|
47508
|
+
});
|
|
47509
|
+
if (addClientAuthentication) {
|
|
47510
|
+
addClientAuthentication(headers, params, authorizationServerUrl, metadata);
|
|
47511
|
+
} else {
|
|
47512
|
+
const supportedMethods = (_a34 = metadata == null ? undefined : metadata.token_endpoint_auth_methods_supported) != null ? _a34 : [];
|
|
47513
|
+
const authMethod = selectClientAuthMethod(clientInformation, supportedMethods);
|
|
47514
|
+
applyClientAuthentication(authMethod, clientInformation, headers, params);
|
|
47515
|
+
}
|
|
47516
|
+
if (resource) {
|
|
47517
|
+
params.set("resource", resource.href);
|
|
47518
|
+
}
|
|
47519
|
+
const response = await (fetchFn != null ? fetchFn : fetch)(tokenUrl, {
|
|
47520
|
+
method: "POST",
|
|
47521
|
+
headers,
|
|
47522
|
+
body: params
|
|
47523
|
+
});
|
|
47524
|
+
if (!response.ok) {
|
|
47525
|
+
throw await parseErrorResponse(response);
|
|
47526
|
+
}
|
|
47527
|
+
return OAuthTokensSchema.parse(await response.json());
|
|
47528
|
+
}
|
|
47529
|
+
async function refreshAuthorization(authorizationServerUrl, {
|
|
47530
|
+
metadata,
|
|
47531
|
+
clientInformation,
|
|
47532
|
+
refreshToken,
|
|
47533
|
+
resource,
|
|
47534
|
+
addClientAuthentication,
|
|
47535
|
+
fetchFn
|
|
47536
|
+
}) {
|
|
47537
|
+
var _a34;
|
|
47538
|
+
const grantType = "refresh_token";
|
|
47539
|
+
let tokenUrl;
|
|
47540
|
+
if (metadata) {
|
|
47541
|
+
tokenUrl = new URL(metadata.token_endpoint);
|
|
47542
|
+
if (metadata.grant_types_supported && !metadata.grant_types_supported.includes(grantType)) {
|
|
47543
|
+
throw new Error(`Incompatible auth server: does not support grant type ${grantType}`);
|
|
47544
|
+
}
|
|
47545
|
+
} else {
|
|
47546
|
+
tokenUrl = new URL("/token", authorizationServerUrl);
|
|
47547
|
+
}
|
|
47548
|
+
const headers = new Headers({
|
|
47549
|
+
"Content-Type": "application/x-www-form-urlencoded"
|
|
47550
|
+
});
|
|
47551
|
+
const params = new URLSearchParams({
|
|
47552
|
+
grant_type: grantType,
|
|
47553
|
+
refresh_token: refreshToken
|
|
47554
|
+
});
|
|
47555
|
+
if (addClientAuthentication) {
|
|
47556
|
+
addClientAuthentication(headers, params, authorizationServerUrl, metadata);
|
|
47557
|
+
} else {
|
|
47558
|
+
const supportedMethods = (_a34 = metadata == null ? undefined : metadata.token_endpoint_auth_methods_supported) != null ? _a34 : [];
|
|
47559
|
+
const authMethod = selectClientAuthMethod(clientInformation, supportedMethods);
|
|
47560
|
+
applyClientAuthentication(authMethod, clientInformation, headers, params);
|
|
47561
|
+
}
|
|
47562
|
+
if (resource) {
|
|
47563
|
+
params.set("resource", resource.href);
|
|
47564
|
+
}
|
|
47565
|
+
const response = await (fetchFn != null ? fetchFn : fetch)(tokenUrl, {
|
|
47566
|
+
method: "POST",
|
|
47567
|
+
headers,
|
|
47568
|
+
body: params
|
|
47569
|
+
});
|
|
47570
|
+
if (!response.ok) {
|
|
47571
|
+
throw await parseErrorResponse(response);
|
|
47572
|
+
}
|
|
47573
|
+
return OAuthTokensSchema.parse({
|
|
47574
|
+
refresh_token: refreshToken,
|
|
47575
|
+
...await response.json()
|
|
47576
|
+
});
|
|
47577
|
+
}
|
|
47578
|
+
async function registerClient(authorizationServerUrl, {
|
|
47579
|
+
metadata,
|
|
47580
|
+
clientMetadata,
|
|
47581
|
+
fetchFn
|
|
47582
|
+
}) {
|
|
47583
|
+
let registrationUrl;
|
|
47584
|
+
if (metadata) {
|
|
47585
|
+
if (!metadata.registration_endpoint) {
|
|
47586
|
+
throw new Error("Incompatible auth server: does not support dynamic client registration");
|
|
47587
|
+
}
|
|
47588
|
+
registrationUrl = new URL(metadata.registration_endpoint);
|
|
47589
|
+
} else {
|
|
47590
|
+
registrationUrl = new URL("/register", authorizationServerUrl);
|
|
47591
|
+
}
|
|
47592
|
+
const response = await (fetchFn != null ? fetchFn : fetch)(registrationUrl, {
|
|
47593
|
+
method: "POST",
|
|
47594
|
+
headers: {
|
|
47595
|
+
"Content-Type": "application/json"
|
|
47596
|
+
},
|
|
47597
|
+
body: JSON.stringify(clientMetadata)
|
|
47598
|
+
});
|
|
47599
|
+
if (!response.ok) {
|
|
47600
|
+
throw await parseErrorResponse(response);
|
|
47601
|
+
}
|
|
47602
|
+
return OAuthClientInformationFullSchema.parse(await response.json());
|
|
47603
|
+
}
|
|
47604
|
+
async function auth(provider, options) {
|
|
47605
|
+
var _a34, _b32;
|
|
47606
|
+
try {
|
|
47607
|
+
return await authInternal(provider, options);
|
|
47608
|
+
} catch (error40) {
|
|
47609
|
+
if (error40 instanceof InvalidClientError || error40 instanceof UnauthorizedClientError) {
|
|
47610
|
+
await ((_a34 = provider.invalidateCredentials) == null ? undefined : _a34.call(provider, "all"));
|
|
47611
|
+
return await authInternal(provider, options);
|
|
47612
|
+
} else if (error40 instanceof InvalidGrantError) {
|
|
47613
|
+
await ((_b32 = provider.invalidateCredentials) == null ? undefined : _b32.call(provider, "tokens"));
|
|
47614
|
+
return await authInternal(provider, options);
|
|
47615
|
+
}
|
|
47616
|
+
throw error40;
|
|
47617
|
+
}
|
|
47618
|
+
}
|
|
47619
|
+
async function selectResourceURL(serverUrl, provider, resourceMetadata) {
|
|
47620
|
+
const defaultResource = resourceUrlFromServerUrl(serverUrl);
|
|
47621
|
+
if (provider.validateResourceURL) {
|
|
47622
|
+
return await provider.validateResourceURL(defaultResource, resourceMetadata == null ? undefined : resourceMetadata.resource);
|
|
47623
|
+
}
|
|
47624
|
+
if (!resourceMetadata) {
|
|
47625
|
+
return;
|
|
47626
|
+
}
|
|
47627
|
+
if (!checkResourceAllowed({
|
|
47628
|
+
requestedResource: defaultResource,
|
|
47629
|
+
configuredResource: resourceMetadata.resource
|
|
47630
|
+
})) {
|
|
47631
|
+
throw new Error(`Protected resource ${resourceMetadata.resource} does not match expected ${defaultResource} (or origin)`);
|
|
47632
|
+
}
|
|
47633
|
+
return new URL(resourceMetadata.resource);
|
|
47634
|
+
}
|
|
47635
|
+
async function authInternal(provider, {
|
|
47636
|
+
serverUrl,
|
|
47637
|
+
authorizationCode,
|
|
47638
|
+
scope,
|
|
47639
|
+
resourceMetadataUrl,
|
|
47640
|
+
fetchFn
|
|
47641
|
+
}) {
|
|
47642
|
+
let resourceMetadata;
|
|
47643
|
+
let authorizationServerUrl;
|
|
47644
|
+
try {
|
|
47645
|
+
resourceMetadata = await discoverOAuthProtectedResourceMetadata(serverUrl, { resourceMetadataUrl }, fetchFn);
|
|
47646
|
+
if (resourceMetadata.authorization_servers && resourceMetadata.authorization_servers.length > 0) {
|
|
47647
|
+
authorizationServerUrl = resourceMetadata.authorization_servers[0];
|
|
47648
|
+
}
|
|
47649
|
+
} catch (e) {}
|
|
47650
|
+
if (!authorizationServerUrl) {
|
|
47651
|
+
authorizationServerUrl = serverUrl;
|
|
47652
|
+
}
|
|
47653
|
+
const resource = await selectResourceURL(serverUrl, provider, resourceMetadata);
|
|
47654
|
+
const metadata = await discoverAuthorizationServerMetadata(authorizationServerUrl, {
|
|
47655
|
+
fetchFn
|
|
47656
|
+
});
|
|
47657
|
+
let clientInformation = await Promise.resolve(provider.clientInformation());
|
|
47658
|
+
if (!clientInformation) {
|
|
47659
|
+
if (authorizationCode !== undefined) {
|
|
47660
|
+
throw new Error("Existing OAuth client information is required when exchanging an authorization code");
|
|
47661
|
+
}
|
|
47662
|
+
if (!provider.saveClientInformation) {
|
|
47663
|
+
throw new Error("OAuth client information must be saveable for dynamic registration");
|
|
47664
|
+
}
|
|
47665
|
+
const fullInformation = await registerClient(authorizationServerUrl, {
|
|
47666
|
+
metadata,
|
|
47667
|
+
clientMetadata: provider.clientMetadata,
|
|
47668
|
+
fetchFn
|
|
47669
|
+
});
|
|
47670
|
+
await provider.saveClientInformation(fullInformation);
|
|
47671
|
+
clientInformation = fullInformation;
|
|
47672
|
+
}
|
|
47673
|
+
if (authorizationCode !== undefined) {
|
|
47674
|
+
const codeVerifier2 = await provider.codeVerifier();
|
|
47675
|
+
const tokens2 = await exchangeAuthorization(authorizationServerUrl, {
|
|
47676
|
+
metadata,
|
|
47677
|
+
clientInformation,
|
|
47678
|
+
authorizationCode,
|
|
47679
|
+
codeVerifier: codeVerifier2,
|
|
47680
|
+
redirectUri: provider.redirectUrl,
|
|
47681
|
+
resource,
|
|
47682
|
+
addClientAuthentication: provider.addClientAuthentication,
|
|
47683
|
+
fetchFn
|
|
47684
|
+
});
|
|
47685
|
+
await provider.saveTokens(tokens2);
|
|
47686
|
+
return "AUTHORIZED";
|
|
47687
|
+
}
|
|
47688
|
+
const tokens = await provider.tokens();
|
|
47689
|
+
if (tokens == null ? undefined : tokens.refresh_token) {
|
|
47690
|
+
try {
|
|
47691
|
+
const newTokens = await refreshAuthorization(authorizationServerUrl, {
|
|
47692
|
+
metadata,
|
|
47693
|
+
clientInformation,
|
|
47694
|
+
refreshToken: tokens.refresh_token,
|
|
47695
|
+
resource,
|
|
47696
|
+
addClientAuthentication: provider.addClientAuthentication,
|
|
47697
|
+
fetchFn
|
|
47698
|
+
});
|
|
47699
|
+
await provider.saveTokens(newTokens);
|
|
47700
|
+
return "AUTHORIZED";
|
|
47701
|
+
} catch (error40) {
|
|
47702
|
+
if (!(error40 instanceof MCPClientOAuthError) || error40 instanceof ServerError) {} else {
|
|
47703
|
+
throw error40;
|
|
47704
|
+
}
|
|
47705
|
+
}
|
|
47706
|
+
}
|
|
47707
|
+
const state = provider.state ? await provider.state() : undefined;
|
|
47708
|
+
const { authorizationUrl, codeVerifier } = await startAuthorization(authorizationServerUrl, {
|
|
47709
|
+
metadata,
|
|
47710
|
+
clientInformation,
|
|
47711
|
+
state,
|
|
47712
|
+
redirectUrl: provider.redirectUrl,
|
|
47713
|
+
scope: scope || provider.clientMetadata.scope,
|
|
47714
|
+
resource
|
|
47715
|
+
});
|
|
47716
|
+
await provider.saveCodeVerifier(codeVerifier);
|
|
47717
|
+
await provider.redirectToAuthorization(authorizationUrl);
|
|
47718
|
+
return "REDIRECT";
|
|
47719
|
+
}
|
|
47720
|
+
var SseMCPTransport = class {
|
|
47721
|
+
constructor({
|
|
47722
|
+
url: url2,
|
|
47723
|
+
headers,
|
|
47724
|
+
authProvider
|
|
47725
|
+
}) {
|
|
47726
|
+
this.connected = false;
|
|
47727
|
+
this.url = new URL(url2);
|
|
47728
|
+
this.headers = headers;
|
|
47729
|
+
this.authProvider = authProvider;
|
|
47730
|
+
}
|
|
47731
|
+
async commonHeaders(base) {
|
|
47732
|
+
const headers = {
|
|
47733
|
+
...this.headers,
|
|
47734
|
+
...base,
|
|
47735
|
+
"mcp-protocol-version": LATEST_PROTOCOL_VERSION
|
|
47736
|
+
};
|
|
47737
|
+
if (this.authProvider) {
|
|
47738
|
+
const tokens = await this.authProvider.tokens();
|
|
47739
|
+
if (tokens == null ? undefined : tokens.access_token) {
|
|
47740
|
+
headers["Authorization"] = `Bearer ${tokens.access_token}`;
|
|
47741
|
+
}
|
|
47742
|
+
}
|
|
47743
|
+
return withUserAgentSuffix2(headers, `ai-sdk/${VERSION4}`, getRuntimeEnvironmentUserAgent2());
|
|
47744
|
+
}
|
|
47745
|
+
async start() {
|
|
47746
|
+
return new Promise((resolve2, reject) => {
|
|
47747
|
+
if (this.connected) {
|
|
47748
|
+
return resolve2();
|
|
47749
|
+
}
|
|
47750
|
+
this.abortController = new AbortController;
|
|
47751
|
+
const establishConnection = async (triedAuth = false) => {
|
|
47752
|
+
var _a34, _b32, _c, _d, _e;
|
|
47753
|
+
try {
|
|
47754
|
+
const headers = await this.commonHeaders({
|
|
47755
|
+
Accept: "text/event-stream"
|
|
47756
|
+
});
|
|
47757
|
+
const response = await fetch(this.url.href, {
|
|
47758
|
+
headers,
|
|
47759
|
+
signal: (_a34 = this.abortController) == null ? undefined : _a34.signal
|
|
47760
|
+
});
|
|
47761
|
+
if (response.status === 401 && this.authProvider && !triedAuth) {
|
|
47762
|
+
this.resourceMetadataUrl = extractResourceMetadataUrl(response);
|
|
47763
|
+
try {
|
|
47764
|
+
const result = await auth(this.authProvider, {
|
|
47765
|
+
serverUrl: this.url,
|
|
47766
|
+
resourceMetadataUrl: this.resourceMetadataUrl
|
|
47767
|
+
});
|
|
47768
|
+
if (result !== "AUTHORIZED") {
|
|
47769
|
+
const error40 = new UnauthorizedError;
|
|
47770
|
+
(_b32 = this.onerror) == null || _b32.call(this, error40);
|
|
47771
|
+
return reject(error40);
|
|
47772
|
+
}
|
|
47773
|
+
} catch (error40) {
|
|
47774
|
+
(_c = this.onerror) == null || _c.call(this, error40);
|
|
47775
|
+
return reject(error40);
|
|
47776
|
+
}
|
|
47777
|
+
return establishConnection(true);
|
|
47778
|
+
}
|
|
47779
|
+
if (!response.ok || !response.body) {
|
|
47780
|
+
let errorMessage = `MCP SSE Transport Error: ${response.status} ${response.statusText}`;
|
|
47781
|
+
if (response.status === 405) {
|
|
47782
|
+
errorMessage += ". This server does not support SSE transport. Try using `http` transport instead";
|
|
47783
|
+
}
|
|
47784
|
+
const error40 = new MCPClientError({
|
|
47785
|
+
message: errorMessage
|
|
47786
|
+
});
|
|
47787
|
+
(_d = this.onerror) == null || _d.call(this, error40);
|
|
47788
|
+
return reject(error40);
|
|
47789
|
+
}
|
|
47790
|
+
const stream = response.body.pipeThrough(new TextDecoderStream).pipeThrough(new EventSourceParserStream);
|
|
47791
|
+
const reader = stream.getReader();
|
|
47792
|
+
const processEvents = async () => {
|
|
47793
|
+
var _a44, _b42, _c2;
|
|
47794
|
+
try {
|
|
47795
|
+
while (true) {
|
|
47796
|
+
const { done, value } = await reader.read();
|
|
47797
|
+
if (done) {
|
|
47798
|
+
if (this.connected) {
|
|
47799
|
+
this.connected = false;
|
|
47800
|
+
throw new MCPClientError({
|
|
47801
|
+
message: "MCP SSE Transport Error: Connection closed unexpectedly"
|
|
47802
|
+
});
|
|
46607
47803
|
}
|
|
46608
47804
|
return;
|
|
46609
47805
|
}
|
|
@@ -46619,14 +47815,14 @@ var SseMCPTransport = class {
|
|
|
46619
47815
|
resolve2();
|
|
46620
47816
|
} else if (event === "message") {
|
|
46621
47817
|
try {
|
|
46622
|
-
const message =
|
|
46623
|
-
(
|
|
47818
|
+
const message = JSONRPCMessageSchema2.parse(JSON.parse(data));
|
|
47819
|
+
(_a44 = this.onmessage) == null || _a44.call(this, message);
|
|
46624
47820
|
} catch (error40) {
|
|
46625
47821
|
const e = new MCPClientError({
|
|
46626
47822
|
message: "MCP SSE Transport Error: Failed to parse message",
|
|
46627
47823
|
cause: error40
|
|
46628
47824
|
});
|
|
46629
|
-
(
|
|
47825
|
+
(_b42 = this.onerror) == null || _b42.call(this, e);
|
|
46630
47826
|
}
|
|
46631
47827
|
}
|
|
46632
47828
|
}
|
|
@@ -46646,7 +47842,7 @@ var SseMCPTransport = class {
|
|
|
46646
47842
|
if (error40 instanceof Error && error40.name === "AbortError") {
|
|
46647
47843
|
return;
|
|
46648
47844
|
}
|
|
46649
|
-
(
|
|
47845
|
+
(_e = this.onerror) == null || _e.call(this, error40);
|
|
46650
47846
|
reject(error40);
|
|
46651
47847
|
}
|
|
46652
47848
|
};
|
|
@@ -46654,52 +47850,377 @@ var SseMCPTransport = class {
|
|
|
46654
47850
|
});
|
|
46655
47851
|
}
|
|
46656
47852
|
async close() {
|
|
46657
|
-
var
|
|
47853
|
+
var _a34, _b32, _c;
|
|
46658
47854
|
this.connected = false;
|
|
46659
|
-
(
|
|
46660
|
-
(
|
|
47855
|
+
(_a34 = this.sseConnection) == null || _a34.close();
|
|
47856
|
+
(_b32 = this.abortController) == null || _b32.abort();
|
|
46661
47857
|
(_c = this.onclose) == null || _c.call(this);
|
|
46662
47858
|
}
|
|
46663
47859
|
async send(message) {
|
|
46664
|
-
var _a172, _b8, _c;
|
|
46665
47860
|
if (!this.endpoint || !this.connected) {
|
|
46666
47861
|
throw new MCPClientError({
|
|
46667
47862
|
message: "MCP SSE Transport Error: Not connected"
|
|
46668
47863
|
});
|
|
46669
47864
|
}
|
|
47865
|
+
const endpoint = this.endpoint;
|
|
47866
|
+
const attempt = async (triedAuth = false) => {
|
|
47867
|
+
var _a34, _b32, _c, _d, _e;
|
|
47868
|
+
try {
|
|
47869
|
+
const headers = await this.commonHeaders({
|
|
47870
|
+
"Content-Type": "application/json"
|
|
47871
|
+
});
|
|
47872
|
+
const init = {
|
|
47873
|
+
method: "POST",
|
|
47874
|
+
headers,
|
|
47875
|
+
body: JSON.stringify(message),
|
|
47876
|
+
signal: (_a34 = this.abortController) == null ? undefined : _a34.signal
|
|
47877
|
+
};
|
|
47878
|
+
const response = await fetch(endpoint, init);
|
|
47879
|
+
if (response.status === 401 && this.authProvider && !triedAuth) {
|
|
47880
|
+
this.resourceMetadataUrl = extractResourceMetadataUrl(response);
|
|
47881
|
+
try {
|
|
47882
|
+
const result = await auth(this.authProvider, {
|
|
47883
|
+
serverUrl: this.url,
|
|
47884
|
+
resourceMetadataUrl: this.resourceMetadataUrl
|
|
47885
|
+
});
|
|
47886
|
+
if (result !== "AUTHORIZED") {
|
|
47887
|
+
const error40 = new UnauthorizedError;
|
|
47888
|
+
(_b32 = this.onerror) == null || _b32.call(this, error40);
|
|
47889
|
+
return;
|
|
47890
|
+
}
|
|
47891
|
+
} catch (error40) {
|
|
47892
|
+
(_c = this.onerror) == null || _c.call(this, error40);
|
|
47893
|
+
return;
|
|
47894
|
+
}
|
|
47895
|
+
return attempt(true);
|
|
47896
|
+
}
|
|
47897
|
+
if (!response.ok) {
|
|
47898
|
+
const text2 = await response.text().catch(() => null);
|
|
47899
|
+
const error40 = new MCPClientError({
|
|
47900
|
+
message: `MCP SSE Transport Error: POSTing to endpoint (HTTP ${response.status}): ${text2}`
|
|
47901
|
+
});
|
|
47902
|
+
(_d = this.onerror) == null || _d.call(this, error40);
|
|
47903
|
+
return;
|
|
47904
|
+
}
|
|
47905
|
+
} catch (error40) {
|
|
47906
|
+
(_e = this.onerror) == null || _e.call(this, error40);
|
|
47907
|
+
return;
|
|
47908
|
+
}
|
|
47909
|
+
};
|
|
47910
|
+
await attempt();
|
|
47911
|
+
}
|
|
47912
|
+
};
|
|
47913
|
+
var HttpMCPTransport = class {
|
|
47914
|
+
constructor({
|
|
47915
|
+
url: url2,
|
|
47916
|
+
headers,
|
|
47917
|
+
authProvider
|
|
47918
|
+
}) {
|
|
47919
|
+
this.inboundReconnectAttempts = 0;
|
|
47920
|
+
this.reconnectionOptions = {
|
|
47921
|
+
initialReconnectionDelay: 1000,
|
|
47922
|
+
maxReconnectionDelay: 30000,
|
|
47923
|
+
reconnectionDelayGrowFactor: 1.5,
|
|
47924
|
+
maxRetries: 2
|
|
47925
|
+
};
|
|
47926
|
+
this.url = new URL(url2);
|
|
47927
|
+
this.headers = headers;
|
|
47928
|
+
this.authProvider = authProvider;
|
|
47929
|
+
}
|
|
47930
|
+
async commonHeaders(base) {
|
|
47931
|
+
const headers = {
|
|
47932
|
+
...this.headers,
|
|
47933
|
+
...base,
|
|
47934
|
+
"mcp-protocol-version": LATEST_PROTOCOL_VERSION
|
|
47935
|
+
};
|
|
47936
|
+
if (this.sessionId) {
|
|
47937
|
+
headers["mcp-session-id"] = this.sessionId;
|
|
47938
|
+
}
|
|
47939
|
+
if (this.authProvider) {
|
|
47940
|
+
const tokens = await this.authProvider.tokens();
|
|
47941
|
+
if (tokens == null ? undefined : tokens.access_token) {
|
|
47942
|
+
headers["Authorization"] = `Bearer ${tokens.access_token}`;
|
|
47943
|
+
}
|
|
47944
|
+
}
|
|
47945
|
+
return withUserAgentSuffix2(headers, `ai-sdk/${VERSION4}`, getRuntimeEnvironmentUserAgent2());
|
|
47946
|
+
}
|
|
47947
|
+
async start() {
|
|
47948
|
+
if (this.abortController) {
|
|
47949
|
+
throw new MCPClientError({
|
|
47950
|
+
message: "MCP HTTP Transport Error: Transport already started. Note: client.connect() calls start() automatically."
|
|
47951
|
+
});
|
|
47952
|
+
}
|
|
47953
|
+
this.abortController = new AbortController;
|
|
47954
|
+
this.openInboundSse();
|
|
47955
|
+
}
|
|
47956
|
+
async close() {
|
|
47957
|
+
var _a34, _b32, _c;
|
|
47958
|
+
(_a34 = this.inboundSseConnection) == null || _a34.close();
|
|
46670
47959
|
try {
|
|
46671
|
-
|
|
46672
|
-
|
|
46673
|
-
|
|
46674
|
-
|
|
46675
|
-
|
|
46676
|
-
|
|
47960
|
+
if (this.sessionId && this.abortController && !this.abortController.signal.aborted) {
|
|
47961
|
+
const headers = await this.commonHeaders({});
|
|
47962
|
+
await fetch(this.url, {
|
|
47963
|
+
method: "DELETE",
|
|
47964
|
+
headers,
|
|
47965
|
+
signal: this.abortController.signal
|
|
47966
|
+
}).catch(() => {
|
|
47967
|
+
return;
|
|
47968
|
+
});
|
|
47969
|
+
}
|
|
47970
|
+
} catch (e) {}
|
|
47971
|
+
(_b32 = this.abortController) == null || _b32.abort();
|
|
47972
|
+
(_c = this.onclose) == null || _c.call(this);
|
|
47973
|
+
}
|
|
47974
|
+
async send(message) {
|
|
47975
|
+
const attempt = async (triedAuth = false) => {
|
|
47976
|
+
var _a34, _b32, _c, _d, _e, _f, _g;
|
|
47977
|
+
try {
|
|
47978
|
+
const headers = await this.commonHeaders({
|
|
47979
|
+
"Content-Type": "application/json",
|
|
47980
|
+
Accept: "application/json, text/event-stream"
|
|
47981
|
+
});
|
|
47982
|
+
const init = {
|
|
47983
|
+
method: "POST",
|
|
47984
|
+
headers,
|
|
47985
|
+
body: JSON.stringify(message),
|
|
47986
|
+
signal: (_a34 = this.abortController) == null ? undefined : _a34.signal
|
|
47987
|
+
};
|
|
47988
|
+
const response = await fetch(this.url, init);
|
|
47989
|
+
const sessionId = response.headers.get("mcp-session-id");
|
|
47990
|
+
if (sessionId) {
|
|
47991
|
+
this.sessionId = sessionId;
|
|
47992
|
+
}
|
|
47993
|
+
if (response.status === 401 && this.authProvider && !triedAuth) {
|
|
47994
|
+
this.resourceMetadataUrl = extractResourceMetadataUrl(response);
|
|
47995
|
+
try {
|
|
47996
|
+
const result = await auth(this.authProvider, {
|
|
47997
|
+
serverUrl: this.url,
|
|
47998
|
+
resourceMetadataUrl: this.resourceMetadataUrl
|
|
47999
|
+
});
|
|
48000
|
+
if (result !== "AUTHORIZED") {
|
|
48001
|
+
const error210 = new UnauthorizedError;
|
|
48002
|
+
throw error210;
|
|
48003
|
+
}
|
|
48004
|
+
} catch (error210) {
|
|
48005
|
+
(_b32 = this.onerror) == null || _b32.call(this, error210);
|
|
48006
|
+
throw error210;
|
|
48007
|
+
}
|
|
48008
|
+
return attempt(true);
|
|
48009
|
+
}
|
|
48010
|
+
if (response.status === 202) {
|
|
48011
|
+
if (!this.inboundSseConnection) {
|
|
48012
|
+
this.openInboundSse();
|
|
48013
|
+
}
|
|
48014
|
+
return;
|
|
48015
|
+
}
|
|
48016
|
+
if (!response.ok) {
|
|
48017
|
+
const text2 = await response.text().catch(() => null);
|
|
48018
|
+
let errorMessage = `MCP HTTP Transport Error: POSTing to endpoint (HTTP ${response.status}): ${text2}`;
|
|
48019
|
+
if (response.status === 404) {
|
|
48020
|
+
errorMessage += ". This server does not support HTTP transport. Try using `sse` transport instead";
|
|
48021
|
+
}
|
|
48022
|
+
const error210 = new MCPClientError({
|
|
48023
|
+
message: errorMessage
|
|
48024
|
+
});
|
|
48025
|
+
(_c = this.onerror) == null || _c.call(this, error210);
|
|
48026
|
+
throw error210;
|
|
48027
|
+
}
|
|
48028
|
+
const contentType = response.headers.get("content-type") || "";
|
|
48029
|
+
if (contentType.includes("application/json")) {
|
|
48030
|
+
const data = await response.json();
|
|
48031
|
+
const messages = Array.isArray(data) ? data.map((m) => JSONRPCMessageSchema2.parse(m)) : [JSONRPCMessageSchema2.parse(data)];
|
|
48032
|
+
for (const m of messages)
|
|
48033
|
+
(_d = this.onmessage) == null || _d.call(this, m);
|
|
48034
|
+
return;
|
|
48035
|
+
}
|
|
48036
|
+
if (contentType.includes("text/event-stream")) {
|
|
48037
|
+
if (!response.body) {
|
|
48038
|
+
const error210 = new MCPClientError({
|
|
48039
|
+
message: "MCP HTTP Transport Error: text/event-stream response without body"
|
|
48040
|
+
});
|
|
48041
|
+
(_e = this.onerror) == null || _e.call(this, error210);
|
|
48042
|
+
throw error210;
|
|
48043
|
+
}
|
|
48044
|
+
const stream = response.body.pipeThrough(new TextDecoderStream).pipeThrough(new EventSourceParserStream);
|
|
48045
|
+
const reader = stream.getReader();
|
|
48046
|
+
const processEvents = async () => {
|
|
48047
|
+
var _a44, _b42, _c2;
|
|
48048
|
+
try {
|
|
48049
|
+
while (true) {
|
|
48050
|
+
const { done, value } = await reader.read();
|
|
48051
|
+
if (done)
|
|
48052
|
+
return;
|
|
48053
|
+
const { event, data } = value;
|
|
48054
|
+
if (event === "message") {
|
|
48055
|
+
try {
|
|
48056
|
+
const msg = JSONRPCMessageSchema2.parse(JSON.parse(data));
|
|
48057
|
+
(_a44 = this.onmessage) == null || _a44.call(this, msg);
|
|
48058
|
+
} catch (error210) {
|
|
48059
|
+
const e = new MCPClientError({
|
|
48060
|
+
message: "MCP HTTP Transport Error: Failed to parse message",
|
|
48061
|
+
cause: error210
|
|
48062
|
+
});
|
|
48063
|
+
(_b42 = this.onerror) == null || _b42.call(this, e);
|
|
48064
|
+
}
|
|
48065
|
+
}
|
|
48066
|
+
}
|
|
48067
|
+
} catch (error210) {
|
|
48068
|
+
if (error210 instanceof Error && error210.name === "AbortError") {
|
|
48069
|
+
return;
|
|
48070
|
+
}
|
|
48071
|
+
(_c2 = this.onerror) == null || _c2.call(this, error210);
|
|
48072
|
+
}
|
|
48073
|
+
};
|
|
48074
|
+
processEvents();
|
|
48075
|
+
return;
|
|
48076
|
+
}
|
|
48077
|
+
const error40 = new MCPClientError({
|
|
48078
|
+
message: `MCP HTTP Transport Error: Unexpected content type: ${contentType}`
|
|
48079
|
+
});
|
|
48080
|
+
(_f = this.onerror) == null || _f.call(this, error40);
|
|
48081
|
+
throw error40;
|
|
48082
|
+
} catch (error40) {
|
|
48083
|
+
(_g = this.onerror) == null || _g.call(this, error40);
|
|
48084
|
+
throw error40;
|
|
48085
|
+
}
|
|
48086
|
+
};
|
|
48087
|
+
await attempt();
|
|
48088
|
+
}
|
|
48089
|
+
getNextReconnectionDelay(attempt) {
|
|
48090
|
+
const {
|
|
48091
|
+
initialReconnectionDelay,
|
|
48092
|
+
reconnectionDelayGrowFactor,
|
|
48093
|
+
maxReconnectionDelay
|
|
48094
|
+
} = this.reconnectionOptions;
|
|
48095
|
+
return Math.min(initialReconnectionDelay * Math.pow(reconnectionDelayGrowFactor, attempt), maxReconnectionDelay);
|
|
48096
|
+
}
|
|
48097
|
+
scheduleInboundSseReconnection() {
|
|
48098
|
+
var _a34;
|
|
48099
|
+
const { maxRetries } = this.reconnectionOptions;
|
|
48100
|
+
if (maxRetries > 0 && this.inboundReconnectAttempts >= maxRetries) {
|
|
48101
|
+
(_a34 = this.onerror) == null || _a34.call(this, new MCPClientError({
|
|
48102
|
+
message: `MCP HTTP Transport Error: Maximum reconnection attempts (${maxRetries}) exceeded.`
|
|
48103
|
+
}));
|
|
48104
|
+
return;
|
|
48105
|
+
}
|
|
48106
|
+
const delay2 = this.getNextReconnectionDelay(this.inboundReconnectAttempts);
|
|
48107
|
+
this.inboundReconnectAttempts += 1;
|
|
48108
|
+
setTimeout(async () => {
|
|
48109
|
+
var _a44;
|
|
48110
|
+
if ((_a44 = this.abortController) == null ? undefined : _a44.signal.aborted)
|
|
48111
|
+
return;
|
|
48112
|
+
await this.openInboundSse(false, this.lastInboundEventId);
|
|
48113
|
+
}, delay2);
|
|
48114
|
+
}
|
|
48115
|
+
async openInboundSse(triedAuth = false, resumeToken) {
|
|
48116
|
+
var _a34, _b32, _c, _d, _e, _f;
|
|
48117
|
+
try {
|
|
48118
|
+
const headers = await this.commonHeaders({
|
|
48119
|
+
Accept: "text/event-stream"
|
|
48120
|
+
});
|
|
48121
|
+
if (resumeToken) {
|
|
48122
|
+
headers["last-event-id"] = resumeToken;
|
|
48123
|
+
}
|
|
48124
|
+
const response = await fetch(this.url.href, {
|
|
48125
|
+
method: "GET",
|
|
46677
48126
|
headers,
|
|
46678
|
-
|
|
46679
|
-
|
|
46680
|
-
|
|
46681
|
-
|
|
46682
|
-
|
|
46683
|
-
|
|
48127
|
+
signal: (_a34 = this.abortController) == null ? undefined : _a34.signal
|
|
48128
|
+
});
|
|
48129
|
+
const sessionId = response.headers.get("mcp-session-id");
|
|
48130
|
+
if (sessionId) {
|
|
48131
|
+
this.sessionId = sessionId;
|
|
48132
|
+
}
|
|
48133
|
+
if (response.status === 401 && this.authProvider && !triedAuth) {
|
|
48134
|
+
this.resourceMetadataUrl = extractResourceMetadataUrl(response);
|
|
48135
|
+
try {
|
|
48136
|
+
const result = await auth(this.authProvider, {
|
|
48137
|
+
serverUrl: this.url,
|
|
48138
|
+
resourceMetadataUrl: this.resourceMetadataUrl
|
|
48139
|
+
});
|
|
48140
|
+
if (result !== "AUTHORIZED") {
|
|
48141
|
+
const error40 = new UnauthorizedError;
|
|
48142
|
+
(_b32 = this.onerror) == null || _b32.call(this, error40);
|
|
48143
|
+
return;
|
|
48144
|
+
}
|
|
48145
|
+
} catch (error40) {
|
|
48146
|
+
(_c = this.onerror) == null || _c.call(this, error40);
|
|
48147
|
+
return;
|
|
48148
|
+
}
|
|
48149
|
+
return this.openInboundSse(true, resumeToken);
|
|
48150
|
+
}
|
|
48151
|
+
if (response.status === 405) {
|
|
48152
|
+
return;
|
|
48153
|
+
}
|
|
48154
|
+
if (!response.ok || !response.body) {
|
|
46684
48155
|
const error40 = new MCPClientError({
|
|
46685
|
-
message: `MCP
|
|
48156
|
+
message: `MCP HTTP Transport Error: GET SSE failed: ${response.status} ${response.statusText}`
|
|
46686
48157
|
});
|
|
46687
|
-
(
|
|
48158
|
+
(_d = this.onerror) == null || _d.call(this, error40);
|
|
46688
48159
|
return;
|
|
46689
48160
|
}
|
|
48161
|
+
const stream = response.body.pipeThrough(new TextDecoderStream).pipeThrough(new EventSourceParserStream);
|
|
48162
|
+
const reader = stream.getReader();
|
|
48163
|
+
const processEvents = async () => {
|
|
48164
|
+
var _a44, _b42, _c2, _d2;
|
|
48165
|
+
try {
|
|
48166
|
+
while (true) {
|
|
48167
|
+
const { done, value } = await reader.read();
|
|
48168
|
+
if (done)
|
|
48169
|
+
return;
|
|
48170
|
+
const { event, data, id } = value;
|
|
48171
|
+
if (id) {
|
|
48172
|
+
this.lastInboundEventId = id;
|
|
48173
|
+
}
|
|
48174
|
+
if (event === "message") {
|
|
48175
|
+
try {
|
|
48176
|
+
const msg = JSONRPCMessageSchema2.parse(JSON.parse(data));
|
|
48177
|
+
(_a44 = this.onmessage) == null || _a44.call(this, msg);
|
|
48178
|
+
} catch (error40) {
|
|
48179
|
+
const e = new MCPClientError({
|
|
48180
|
+
message: "MCP HTTP Transport Error: Failed to parse message",
|
|
48181
|
+
cause: error40
|
|
48182
|
+
});
|
|
48183
|
+
(_b42 = this.onerror) == null || _b42.call(this, e);
|
|
48184
|
+
}
|
|
48185
|
+
}
|
|
48186
|
+
}
|
|
48187
|
+
} catch (error40) {
|
|
48188
|
+
if (error40 instanceof Error && error40.name === "AbortError") {
|
|
48189
|
+
return;
|
|
48190
|
+
}
|
|
48191
|
+
(_c2 = this.onerror) == null || _c2.call(this, error40);
|
|
48192
|
+
if (!((_d2 = this.abortController) == null ? undefined : _d2.signal.aborted)) {
|
|
48193
|
+
this.scheduleInboundSseReconnection();
|
|
48194
|
+
}
|
|
48195
|
+
}
|
|
48196
|
+
};
|
|
48197
|
+
this.inboundSseConnection = {
|
|
48198
|
+
close: () => reader.cancel()
|
|
48199
|
+
};
|
|
48200
|
+
this.inboundReconnectAttempts = 0;
|
|
48201
|
+
processEvents();
|
|
46690
48202
|
} catch (error40) {
|
|
46691
|
-
(
|
|
46692
|
-
|
|
48203
|
+
if (error40 instanceof Error && error40.name === "AbortError") {
|
|
48204
|
+
return;
|
|
48205
|
+
}
|
|
48206
|
+
(_e = this.onerror) == null || _e.call(this, error40);
|
|
48207
|
+
if (!((_f = this.abortController) == null ? undefined : _f.signal.aborted)) {
|
|
48208
|
+
this.scheduleInboundSseReconnection();
|
|
48209
|
+
}
|
|
46693
48210
|
}
|
|
46694
48211
|
}
|
|
46695
48212
|
};
|
|
46696
48213
|
function createMcpTransport(config2) {
|
|
46697
|
-
|
|
46698
|
-
|
|
46699
|
-
|
|
46700
|
-
|
|
48214
|
+
switch (config2.type) {
|
|
48215
|
+
case "sse":
|
|
48216
|
+
return new SseMCPTransport(config2);
|
|
48217
|
+
case "http":
|
|
48218
|
+
return new HttpMCPTransport(config2);
|
|
48219
|
+
default:
|
|
48220
|
+
throw new MCPClientError({
|
|
48221
|
+
message: "Unsupported or invalid transport configuration. If you are using a custom transport, make sure it implements the MCPTransport interface."
|
|
48222
|
+
});
|
|
46701
48223
|
}
|
|
46702
|
-
return new SseMCPTransport(config2);
|
|
46703
48224
|
}
|
|
46704
48225
|
function isCustomMcpTransport(transport) {
|
|
46705
48226
|
return "start" in transport && typeof transport.start === "function" && "send" in transport && typeof transport.send === "function" && "close" in transport && typeof transport.close === "function";
|
|
@@ -46713,14 +48234,17 @@ async function createMCPClient(config2) {
|
|
|
46713
48234
|
var DefaultMCPClient = class {
|
|
46714
48235
|
constructor({
|
|
46715
48236
|
transport: transportConfig,
|
|
46716
|
-
name:
|
|
46717
|
-
|
|
48237
|
+
name: name34 = "ai-sdk-mcp-client",
|
|
48238
|
+
version: version2 = CLIENT_VERSION,
|
|
48239
|
+
onUncaughtError,
|
|
48240
|
+
capabilities
|
|
46718
48241
|
}) {
|
|
46719
48242
|
this.requestMessageId = 0;
|
|
46720
48243
|
this.responseHandlers = /* @__PURE__ */ new Map;
|
|
46721
48244
|
this.serverCapabilities = {};
|
|
46722
48245
|
this.isClosed = true;
|
|
46723
48246
|
this.onUncaughtError = onUncaughtError;
|
|
48247
|
+
this.clientCapabilities = capabilities != null ? capabilities : {};
|
|
46724
48248
|
if (isCustomMcpTransport(transportConfig)) {
|
|
46725
48249
|
this.transport = transportConfig;
|
|
46726
48250
|
} else {
|
|
@@ -46730,16 +48254,20 @@ var DefaultMCPClient = class {
|
|
|
46730
48254
|
this.transport.onerror = (error40) => this.onError(error40);
|
|
46731
48255
|
this.transport.onmessage = (message) => {
|
|
46732
48256
|
if ("method" in message) {
|
|
46733
|
-
|
|
46734
|
-
message
|
|
46735
|
-
}
|
|
48257
|
+
if ("id" in message) {
|
|
48258
|
+
this.onRequestMessage(message);
|
|
48259
|
+
} else {
|
|
48260
|
+
this.onError(new MCPClientError({
|
|
48261
|
+
message: "Unsupported message type"
|
|
48262
|
+
}));
|
|
48263
|
+
}
|
|
46736
48264
|
return;
|
|
46737
48265
|
}
|
|
46738
48266
|
this.onResponse(message);
|
|
46739
48267
|
};
|
|
46740
48268
|
this.clientInfo = {
|
|
46741
|
-
name:
|
|
46742
|
-
version:
|
|
48269
|
+
name: name34,
|
|
48270
|
+
version: version2
|
|
46743
48271
|
};
|
|
46744
48272
|
}
|
|
46745
48273
|
async init() {
|
|
@@ -46751,11 +48279,11 @@ var DefaultMCPClient = class {
|
|
|
46751
48279
|
method: "initialize",
|
|
46752
48280
|
params: {
|
|
46753
48281
|
protocolVersion: LATEST_PROTOCOL_VERSION,
|
|
46754
|
-
capabilities:
|
|
48282
|
+
capabilities: this.clientCapabilities,
|
|
46755
48283
|
clientInfo: this.clientInfo
|
|
46756
48284
|
}
|
|
46757
48285
|
},
|
|
46758
|
-
resultSchema:
|
|
48286
|
+
resultSchema: InitializeResultSchema2
|
|
46759
48287
|
});
|
|
46760
48288
|
if (result === undefined) {
|
|
46761
48289
|
throw new MCPClientError({
|
|
@@ -46778,10 +48306,10 @@ var DefaultMCPClient = class {
|
|
|
46778
48306
|
}
|
|
46779
48307
|
}
|
|
46780
48308
|
async close() {
|
|
46781
|
-
var
|
|
48309
|
+
var _a34;
|
|
46782
48310
|
if (this.isClosed)
|
|
46783
48311
|
return;
|
|
46784
|
-
await ((
|
|
48312
|
+
await ((_a34 = this.transport) == null ? undefined : _a34.close());
|
|
46785
48313
|
this.onClose();
|
|
46786
48314
|
}
|
|
46787
48315
|
assertCapability(method) {
|
|
@@ -46796,6 +48324,23 @@ var DefaultMCPClient = class {
|
|
|
46796
48324
|
});
|
|
46797
48325
|
}
|
|
46798
48326
|
break;
|
|
48327
|
+
case "resources/list":
|
|
48328
|
+
case "resources/read":
|
|
48329
|
+
case "resources/templates/list":
|
|
48330
|
+
if (!this.serverCapabilities.resources) {
|
|
48331
|
+
throw new MCPClientError({
|
|
48332
|
+
message: `Server does not support resources`
|
|
48333
|
+
});
|
|
48334
|
+
}
|
|
48335
|
+
break;
|
|
48336
|
+
case "prompts/list":
|
|
48337
|
+
case "prompts/get":
|
|
48338
|
+
if (!this.serverCapabilities.prompts) {
|
|
48339
|
+
throw new MCPClientError({
|
|
48340
|
+
message: `Server does not support prompts`
|
|
48341
|
+
});
|
|
48342
|
+
}
|
|
48343
|
+
break;
|
|
46799
48344
|
default:
|
|
46800
48345
|
throw new MCPClientError({
|
|
46801
48346
|
message: `Unsupported method: ${method}`
|
|
@@ -46859,7 +48404,7 @@ var DefaultMCPClient = class {
|
|
|
46859
48404
|
try {
|
|
46860
48405
|
return this.request({
|
|
46861
48406
|
request: { method: "tools/list", params },
|
|
46862
|
-
resultSchema:
|
|
48407
|
+
resultSchema: ListToolsResultSchema2,
|
|
46863
48408
|
options
|
|
46864
48409
|
});
|
|
46865
48410
|
} catch (error40) {
|
|
@@ -46867,14 +48412,14 @@ var DefaultMCPClient = class {
|
|
|
46867
48412
|
}
|
|
46868
48413
|
}
|
|
46869
48414
|
async callTool({
|
|
46870
|
-
name:
|
|
48415
|
+
name: name34,
|
|
46871
48416
|
args,
|
|
46872
48417
|
options
|
|
46873
48418
|
}) {
|
|
46874
48419
|
try {
|
|
46875
48420
|
return this.request({
|
|
46876
|
-
request: { method: "tools/call", params: { name:
|
|
46877
|
-
resultSchema:
|
|
48421
|
+
request: { method: "tools/call", params: { name: name34, arguments: args } },
|
|
48422
|
+
resultSchema: CallToolResultSchema2,
|
|
46878
48423
|
options: {
|
|
46879
48424
|
signal: options == null ? undefined : options.abortSignal
|
|
46880
48425
|
}
|
|
@@ -46883,6 +48428,76 @@ var DefaultMCPClient = class {
|
|
|
46883
48428
|
throw error40;
|
|
46884
48429
|
}
|
|
46885
48430
|
}
|
|
48431
|
+
async listResourcesInternal({
|
|
48432
|
+
params,
|
|
48433
|
+
options
|
|
48434
|
+
} = {}) {
|
|
48435
|
+
try {
|
|
48436
|
+
return this.request({
|
|
48437
|
+
request: { method: "resources/list", params },
|
|
48438
|
+
resultSchema: ListResourcesResultSchema,
|
|
48439
|
+
options
|
|
48440
|
+
});
|
|
48441
|
+
} catch (error40) {
|
|
48442
|
+
throw error40;
|
|
48443
|
+
}
|
|
48444
|
+
}
|
|
48445
|
+
async readResourceInternal({
|
|
48446
|
+
uri,
|
|
48447
|
+
options
|
|
48448
|
+
}) {
|
|
48449
|
+
try {
|
|
48450
|
+
return this.request({
|
|
48451
|
+
request: { method: "resources/read", params: { uri } },
|
|
48452
|
+
resultSchema: ReadResourceResultSchema,
|
|
48453
|
+
options
|
|
48454
|
+
});
|
|
48455
|
+
} catch (error40) {
|
|
48456
|
+
throw error40;
|
|
48457
|
+
}
|
|
48458
|
+
}
|
|
48459
|
+
async listResourceTemplatesInternal({
|
|
48460
|
+
options
|
|
48461
|
+
} = {}) {
|
|
48462
|
+
try {
|
|
48463
|
+
return this.request({
|
|
48464
|
+
request: { method: "resources/templates/list" },
|
|
48465
|
+
resultSchema: ListResourceTemplatesResultSchema,
|
|
48466
|
+
options
|
|
48467
|
+
});
|
|
48468
|
+
} catch (error40) {
|
|
48469
|
+
throw error40;
|
|
48470
|
+
}
|
|
48471
|
+
}
|
|
48472
|
+
async listPromptsInternal({
|
|
48473
|
+
params,
|
|
48474
|
+
options
|
|
48475
|
+
} = {}) {
|
|
48476
|
+
try {
|
|
48477
|
+
return this.request({
|
|
48478
|
+
request: { method: "prompts/list", params },
|
|
48479
|
+
resultSchema: ListPromptsResultSchema,
|
|
48480
|
+
options
|
|
48481
|
+
});
|
|
48482
|
+
} catch (error40) {
|
|
48483
|
+
throw error40;
|
|
48484
|
+
}
|
|
48485
|
+
}
|
|
48486
|
+
async getPromptInternal({
|
|
48487
|
+
name: name34,
|
|
48488
|
+
args,
|
|
48489
|
+
options
|
|
48490
|
+
}) {
|
|
48491
|
+
try {
|
|
48492
|
+
return this.request({
|
|
48493
|
+
request: { method: "prompts/get", params: { name: name34, arguments: args } },
|
|
48494
|
+
resultSchema: GetPromptResultSchema,
|
|
48495
|
+
options
|
|
48496
|
+
});
|
|
48497
|
+
} catch (error40) {
|
|
48498
|
+
throw error40;
|
|
48499
|
+
}
|
|
48500
|
+
}
|
|
46886
48501
|
async notification(notification) {
|
|
46887
48502
|
const jsonrpcNotification = {
|
|
46888
48503
|
...notification,
|
|
@@ -46893,38 +48508,139 @@ var DefaultMCPClient = class {
|
|
|
46893
48508
|
async tools({
|
|
46894
48509
|
schemas: schemas3 = "automatic"
|
|
46895
48510
|
} = {}) {
|
|
46896
|
-
var
|
|
48511
|
+
var _a34;
|
|
46897
48512
|
const tools = {};
|
|
46898
48513
|
try {
|
|
46899
|
-
const listToolsResult = await this.listTools();
|
|
46900
|
-
for (const { name:
|
|
46901
|
-
if (schemas3 !== "automatic" && !(
|
|
46902
|
-
continue;
|
|
46903
|
-
}
|
|
46904
|
-
const self = this;
|
|
46905
|
-
const execute = async (args, options) => {
|
|
46906
|
-
var
|
|
46907
|
-
(
|
|
46908
|
-
return self.callTool({ name:
|
|
46909
|
-
};
|
|
46910
|
-
const toolWithExecute = schemas3 === "automatic" ? dynamicTool({
|
|
46911
|
-
description,
|
|
46912
|
-
inputSchema:
|
|
46913
|
-
...inputSchema,
|
|
46914
|
-
properties: (
|
|
46915
|
-
additionalProperties: false
|
|
46916
|
-
}),
|
|
46917
|
-
execute
|
|
46918
|
-
}) :
|
|
46919
|
-
description,
|
|
46920
|
-
inputSchema: schemas3[
|
|
46921
|
-
execute
|
|
48514
|
+
const listToolsResult = await this.listTools();
|
|
48515
|
+
for (const { name: name34, description, inputSchema } of listToolsResult.tools) {
|
|
48516
|
+
if (schemas3 !== "automatic" && !(name34 in schemas3)) {
|
|
48517
|
+
continue;
|
|
48518
|
+
}
|
|
48519
|
+
const self = this;
|
|
48520
|
+
const execute = async (args, options) => {
|
|
48521
|
+
var _a44;
|
|
48522
|
+
(_a44 = options == null ? undefined : options.abortSignal) == null || _a44.throwIfAborted();
|
|
48523
|
+
return self.callTool({ name: name34, args, options });
|
|
48524
|
+
};
|
|
48525
|
+
const toolWithExecute = schemas3 === "automatic" ? dynamicTool({
|
|
48526
|
+
description,
|
|
48527
|
+
inputSchema: jsonSchema2({
|
|
48528
|
+
...inputSchema,
|
|
48529
|
+
properties: (_a34 = inputSchema.properties) != null ? _a34 : {},
|
|
48530
|
+
additionalProperties: false
|
|
48531
|
+
}),
|
|
48532
|
+
execute
|
|
48533
|
+
}) : tool2({
|
|
48534
|
+
description,
|
|
48535
|
+
inputSchema: schemas3[name34].inputSchema,
|
|
48536
|
+
execute
|
|
48537
|
+
});
|
|
48538
|
+
tools[name34] = toolWithExecute;
|
|
48539
|
+
}
|
|
48540
|
+
return tools;
|
|
48541
|
+
} catch (error40) {
|
|
48542
|
+
throw error40;
|
|
48543
|
+
}
|
|
48544
|
+
}
|
|
48545
|
+
listResources({
|
|
48546
|
+
params,
|
|
48547
|
+
options
|
|
48548
|
+
} = {}) {
|
|
48549
|
+
return this.listResourcesInternal({ params, options });
|
|
48550
|
+
}
|
|
48551
|
+
readResource({
|
|
48552
|
+
uri,
|
|
48553
|
+
options
|
|
48554
|
+
}) {
|
|
48555
|
+
return this.readResourceInternal({ uri, options });
|
|
48556
|
+
}
|
|
48557
|
+
listResourceTemplates({
|
|
48558
|
+
options
|
|
48559
|
+
} = {}) {
|
|
48560
|
+
return this.listResourceTemplatesInternal({ options });
|
|
48561
|
+
}
|
|
48562
|
+
listPrompts({
|
|
48563
|
+
params,
|
|
48564
|
+
options
|
|
48565
|
+
} = {}) {
|
|
48566
|
+
return this.listPromptsInternal({ params, options });
|
|
48567
|
+
}
|
|
48568
|
+
getPrompt({
|
|
48569
|
+
name: name34,
|
|
48570
|
+
arguments: args,
|
|
48571
|
+
options
|
|
48572
|
+
}) {
|
|
48573
|
+
return this.getPromptInternal({ name: name34, args, options });
|
|
48574
|
+
}
|
|
48575
|
+
onElicitationRequest(schema, handler) {
|
|
48576
|
+
if (schema !== ElicitationRequestSchema) {
|
|
48577
|
+
throw new MCPClientError({
|
|
48578
|
+
message: "Unsupported request schema. Only ElicitationRequestSchema is supported."
|
|
48579
|
+
});
|
|
48580
|
+
}
|
|
48581
|
+
this.elicitationRequestHandler = handler;
|
|
48582
|
+
}
|
|
48583
|
+
async onRequestMessage(request) {
|
|
48584
|
+
try {
|
|
48585
|
+
if (request.method !== "elicitation/create") {
|
|
48586
|
+
await this.transport.send({
|
|
48587
|
+
jsonrpc: "2.0",
|
|
48588
|
+
id: request.id,
|
|
48589
|
+
error: {
|
|
48590
|
+
code: -32601,
|
|
48591
|
+
message: `Unsupported request method: ${request.method}`
|
|
48592
|
+
}
|
|
46922
48593
|
});
|
|
46923
|
-
|
|
48594
|
+
return;
|
|
48595
|
+
}
|
|
48596
|
+
if (!this.elicitationRequestHandler) {
|
|
48597
|
+
await this.transport.send({
|
|
48598
|
+
jsonrpc: "2.0",
|
|
48599
|
+
id: request.id,
|
|
48600
|
+
error: {
|
|
48601
|
+
code: -32601,
|
|
48602
|
+
message: "No elicitation handler registered on client"
|
|
48603
|
+
}
|
|
48604
|
+
});
|
|
48605
|
+
return;
|
|
48606
|
+
}
|
|
48607
|
+
const parsedRequest = ElicitationRequestSchema.safeParse({
|
|
48608
|
+
method: request.method,
|
|
48609
|
+
params: request.params
|
|
48610
|
+
});
|
|
48611
|
+
if (!parsedRequest.success) {
|
|
48612
|
+
await this.transport.send({
|
|
48613
|
+
jsonrpc: "2.0",
|
|
48614
|
+
id: request.id,
|
|
48615
|
+
error: {
|
|
48616
|
+
code: -32602,
|
|
48617
|
+
message: `Invalid elicitation request: ${parsedRequest.error.message}`,
|
|
48618
|
+
data: parsedRequest.error.issues
|
|
48619
|
+
}
|
|
48620
|
+
});
|
|
48621
|
+
return;
|
|
48622
|
+
}
|
|
48623
|
+
try {
|
|
48624
|
+
const result = await this.elicitationRequestHandler(parsedRequest.data);
|
|
48625
|
+
const validatedResult = ElicitResultSchema.parse(result);
|
|
48626
|
+
await this.transport.send({
|
|
48627
|
+
jsonrpc: "2.0",
|
|
48628
|
+
id: request.id,
|
|
48629
|
+
result: validatedResult
|
|
48630
|
+
});
|
|
48631
|
+
} catch (error40) {
|
|
48632
|
+
await this.transport.send({
|
|
48633
|
+
jsonrpc: "2.0",
|
|
48634
|
+
id: request.id,
|
|
48635
|
+
error: {
|
|
48636
|
+
code: -32603,
|
|
48637
|
+
message: error40 instanceof Error ? error40.message : "Failed to handle elicitation request"
|
|
48638
|
+
}
|
|
48639
|
+
});
|
|
48640
|
+
this.onError(error40);
|
|
46924
48641
|
}
|
|
46925
|
-
return tools;
|
|
46926
48642
|
} catch (error40) {
|
|
46927
|
-
|
|
48643
|
+
this.onError(error40);
|
|
46928
48644
|
}
|
|
46929
48645
|
}
|
|
46930
48646
|
onClose() {
|
|
@@ -46961,192 +48677,6 @@ var DefaultMCPClient = class {
|
|
|
46961
48677
|
}));
|
|
46962
48678
|
}
|
|
46963
48679
|
};
|
|
46964
|
-
var uiMessagesSchema = lazyValidator(() => zodSchema(exports_external.array(exports_external.object({
|
|
46965
|
-
id: exports_external.string(),
|
|
46966
|
-
role: exports_external.enum(["system", "user", "assistant"]),
|
|
46967
|
-
metadata: exports_external.unknown().optional(),
|
|
46968
|
-
parts: exports_external.array(exports_external.union([
|
|
46969
|
-
exports_external.object({
|
|
46970
|
-
type: exports_external.literal("text"),
|
|
46971
|
-
text: exports_external.string(),
|
|
46972
|
-
state: exports_external.enum(["streaming", "done"]).optional(),
|
|
46973
|
-
providerMetadata: providerMetadataSchema.optional()
|
|
46974
|
-
}),
|
|
46975
|
-
exports_external.object({
|
|
46976
|
-
type: exports_external.literal("reasoning"),
|
|
46977
|
-
text: exports_external.string(),
|
|
46978
|
-
state: exports_external.enum(["streaming", "done"]).optional(),
|
|
46979
|
-
providerMetadata: providerMetadataSchema.optional()
|
|
46980
|
-
}),
|
|
46981
|
-
exports_external.object({
|
|
46982
|
-
type: exports_external.literal("source-url"),
|
|
46983
|
-
sourceId: exports_external.string(),
|
|
46984
|
-
url: exports_external.string(),
|
|
46985
|
-
title: exports_external.string().optional(),
|
|
46986
|
-
providerMetadata: providerMetadataSchema.optional()
|
|
46987
|
-
}),
|
|
46988
|
-
exports_external.object({
|
|
46989
|
-
type: exports_external.literal("source-document"),
|
|
46990
|
-
sourceId: exports_external.string(),
|
|
46991
|
-
mediaType: exports_external.string(),
|
|
46992
|
-
title: exports_external.string(),
|
|
46993
|
-
filename: exports_external.string().optional(),
|
|
46994
|
-
providerMetadata: providerMetadataSchema.optional()
|
|
46995
|
-
}),
|
|
46996
|
-
exports_external.object({
|
|
46997
|
-
type: exports_external.literal("file"),
|
|
46998
|
-
mediaType: exports_external.string(),
|
|
46999
|
-
filename: exports_external.string().optional(),
|
|
47000
|
-
url: exports_external.string(),
|
|
47001
|
-
providerMetadata: providerMetadataSchema.optional()
|
|
47002
|
-
}),
|
|
47003
|
-
exports_external.object({
|
|
47004
|
-
type: exports_external.literal("step-start")
|
|
47005
|
-
}),
|
|
47006
|
-
exports_external.object({
|
|
47007
|
-
type: exports_external.string().startsWith("data-"),
|
|
47008
|
-
id: exports_external.string().optional(),
|
|
47009
|
-
data: exports_external.unknown()
|
|
47010
|
-
}),
|
|
47011
|
-
exports_external.object({
|
|
47012
|
-
type: exports_external.literal("dynamic-tool"),
|
|
47013
|
-
toolName: exports_external.string(),
|
|
47014
|
-
toolCallId: exports_external.string(),
|
|
47015
|
-
state: exports_external.literal("input-streaming"),
|
|
47016
|
-
input: exports_external.unknown().optional(),
|
|
47017
|
-
output: exports_external.never().optional(),
|
|
47018
|
-
errorText: exports_external.never().optional()
|
|
47019
|
-
}),
|
|
47020
|
-
exports_external.object({
|
|
47021
|
-
type: exports_external.literal("dynamic-tool"),
|
|
47022
|
-
toolName: exports_external.string(),
|
|
47023
|
-
toolCallId: exports_external.string(),
|
|
47024
|
-
state: exports_external.literal("input-available"),
|
|
47025
|
-
input: exports_external.unknown(),
|
|
47026
|
-
output: exports_external.never().optional(),
|
|
47027
|
-
errorText: exports_external.never().optional(),
|
|
47028
|
-
callProviderMetadata: providerMetadataSchema.optional()
|
|
47029
|
-
}),
|
|
47030
|
-
exports_external.object({
|
|
47031
|
-
type: exports_external.literal("dynamic-tool"),
|
|
47032
|
-
toolName: exports_external.string(),
|
|
47033
|
-
toolCallId: exports_external.string(),
|
|
47034
|
-
state: exports_external.literal("output-available"),
|
|
47035
|
-
input: exports_external.unknown(),
|
|
47036
|
-
output: exports_external.unknown(),
|
|
47037
|
-
errorText: exports_external.never().optional(),
|
|
47038
|
-
callProviderMetadata: providerMetadataSchema.optional(),
|
|
47039
|
-
preliminary: exports_external.boolean().optional()
|
|
47040
|
-
}),
|
|
47041
|
-
exports_external.object({
|
|
47042
|
-
type: exports_external.literal("dynamic-tool"),
|
|
47043
|
-
toolName: exports_external.string(),
|
|
47044
|
-
toolCallId: exports_external.string(),
|
|
47045
|
-
state: exports_external.literal("output-error"),
|
|
47046
|
-
input: exports_external.unknown(),
|
|
47047
|
-
output: exports_external.never().optional(),
|
|
47048
|
-
errorText: exports_external.string(),
|
|
47049
|
-
callProviderMetadata: providerMetadataSchema.optional()
|
|
47050
|
-
}),
|
|
47051
|
-
exports_external.object({
|
|
47052
|
-
type: exports_external.string().startsWith("tool-"),
|
|
47053
|
-
toolCallId: exports_external.string(),
|
|
47054
|
-
state: exports_external.literal("input-streaming"),
|
|
47055
|
-
providerExecuted: exports_external.boolean().optional(),
|
|
47056
|
-
input: exports_external.unknown().optional(),
|
|
47057
|
-
output: exports_external.never().optional(),
|
|
47058
|
-
errorText: exports_external.never().optional(),
|
|
47059
|
-
approval: exports_external.never().optional()
|
|
47060
|
-
}),
|
|
47061
|
-
exports_external.object({
|
|
47062
|
-
type: exports_external.string().startsWith("tool-"),
|
|
47063
|
-
toolCallId: exports_external.string(),
|
|
47064
|
-
state: exports_external.literal("input-available"),
|
|
47065
|
-
providerExecuted: exports_external.boolean().optional(),
|
|
47066
|
-
input: exports_external.unknown(),
|
|
47067
|
-
output: exports_external.never().optional(),
|
|
47068
|
-
errorText: exports_external.never().optional(),
|
|
47069
|
-
callProviderMetadata: providerMetadataSchema.optional(),
|
|
47070
|
-
approval: exports_external.never().optional()
|
|
47071
|
-
}),
|
|
47072
|
-
exports_external.object({
|
|
47073
|
-
type: exports_external.string().startsWith("tool-"),
|
|
47074
|
-
toolCallId: exports_external.string(),
|
|
47075
|
-
state: exports_external.literal("approval-requested"),
|
|
47076
|
-
input: exports_external.unknown(),
|
|
47077
|
-
providerExecuted: exports_external.boolean().optional(),
|
|
47078
|
-
output: exports_external.never().optional(),
|
|
47079
|
-
errorText: exports_external.never().optional(),
|
|
47080
|
-
callProviderMetadata: providerMetadataSchema.optional(),
|
|
47081
|
-
approval: exports_external.object({
|
|
47082
|
-
id: exports_external.string(),
|
|
47083
|
-
approved: exports_external.never().optional(),
|
|
47084
|
-
reason: exports_external.never().optional()
|
|
47085
|
-
})
|
|
47086
|
-
}),
|
|
47087
|
-
exports_external.object({
|
|
47088
|
-
type: exports_external.string().startsWith("tool-"),
|
|
47089
|
-
toolCallId: exports_external.string(),
|
|
47090
|
-
state: exports_external.literal("approval-responded"),
|
|
47091
|
-
input: exports_external.unknown(),
|
|
47092
|
-
providerExecuted: exports_external.boolean().optional(),
|
|
47093
|
-
output: exports_external.never().optional(),
|
|
47094
|
-
errorText: exports_external.never().optional(),
|
|
47095
|
-
callProviderMetadata: providerMetadataSchema.optional(),
|
|
47096
|
-
approval: exports_external.object({
|
|
47097
|
-
id: exports_external.string(),
|
|
47098
|
-
approved: exports_external.boolean(),
|
|
47099
|
-
reason: exports_external.string().optional()
|
|
47100
|
-
})
|
|
47101
|
-
}),
|
|
47102
|
-
exports_external.object({
|
|
47103
|
-
type: exports_external.string().startsWith("tool-"),
|
|
47104
|
-
toolCallId: exports_external.string(),
|
|
47105
|
-
state: exports_external.literal("output-available"),
|
|
47106
|
-
providerExecuted: exports_external.boolean().optional(),
|
|
47107
|
-
input: exports_external.unknown(),
|
|
47108
|
-
output: exports_external.unknown(),
|
|
47109
|
-
errorText: exports_external.never().optional(),
|
|
47110
|
-
callProviderMetadata: providerMetadataSchema.optional(),
|
|
47111
|
-
preliminary: exports_external.boolean().optional(),
|
|
47112
|
-
approval: exports_external.object({
|
|
47113
|
-
id: exports_external.string(),
|
|
47114
|
-
approved: exports_external.literal(true),
|
|
47115
|
-
reason: exports_external.string().optional()
|
|
47116
|
-
}).optional()
|
|
47117
|
-
}),
|
|
47118
|
-
exports_external.object({
|
|
47119
|
-
type: exports_external.string().startsWith("tool-"),
|
|
47120
|
-
toolCallId: exports_external.string(),
|
|
47121
|
-
state: exports_external.literal("output-error"),
|
|
47122
|
-
providerExecuted: exports_external.boolean().optional(),
|
|
47123
|
-
input: exports_external.unknown(),
|
|
47124
|
-
output: exports_external.never().optional(),
|
|
47125
|
-
errorText: exports_external.string(),
|
|
47126
|
-
callProviderMetadata: providerMetadataSchema.optional(),
|
|
47127
|
-
approval: exports_external.object({
|
|
47128
|
-
id: exports_external.string(),
|
|
47129
|
-
approved: exports_external.literal(true),
|
|
47130
|
-
reason: exports_external.string().optional()
|
|
47131
|
-
}).optional()
|
|
47132
|
-
}),
|
|
47133
|
-
exports_external.object({
|
|
47134
|
-
type: exports_external.string().startsWith("tool-"),
|
|
47135
|
-
toolCallId: exports_external.string(),
|
|
47136
|
-
state: exports_external.literal("output-denied"),
|
|
47137
|
-
providerExecuted: exports_external.boolean().optional(),
|
|
47138
|
-
input: exports_external.unknown(),
|
|
47139
|
-
output: exports_external.never().optional(),
|
|
47140
|
-
errorText: exports_external.never().optional(),
|
|
47141
|
-
callProviderMetadata: providerMetadataSchema.optional(),
|
|
47142
|
-
approval: exports_external.object({
|
|
47143
|
-
id: exports_external.string(),
|
|
47144
|
-
approved: exports_external.literal(false),
|
|
47145
|
-
reason: exports_external.string().optional()
|
|
47146
|
-
})
|
|
47147
|
-
})
|
|
47148
|
-
]))
|
|
47149
|
-
}))));
|
|
47150
48680
|
|
|
47151
48681
|
// ../xyd-ask-ai/dist/_rollupPluginBabelHelpers-B0vHBMb8.js
|
|
47152
48682
|
function t(t2, r) {
|
|
@@ -47472,45 +49002,8 @@ function g(t2) {
|
|
|
47472
49002
|
}, g(t2);
|
|
47473
49003
|
}
|
|
47474
49004
|
|
|
47475
|
-
// ../../node_modules/.pnpm/pkce-challenge@5.0.0/node_modules/pkce-challenge/dist/index.node.js
|
|
47476
|
-
var crypto;
|
|
47477
|
-
crypto = globalThis.crypto?.webcrypto ?? globalThis.crypto ?? import("node:crypto").then((m2) => m2.webcrypto);
|
|
47478
|
-
async function getRandomValues(size) {
|
|
47479
|
-
return (await crypto).getRandomValues(new Uint8Array(size));
|
|
47480
|
-
}
|
|
47481
|
-
async function random(size) {
|
|
47482
|
-
const mask = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~";
|
|
47483
|
-
let result = "";
|
|
47484
|
-
const randomUints = await getRandomValues(size);
|
|
47485
|
-
for (let i2 = 0;i2 < size; i2++) {
|
|
47486
|
-
const randomIndex = randomUints[i2] % mask.length;
|
|
47487
|
-
result += mask[randomIndex];
|
|
47488
|
-
}
|
|
47489
|
-
return result;
|
|
47490
|
-
}
|
|
47491
|
-
async function generateVerifier(length) {
|
|
47492
|
-
return await random(length);
|
|
47493
|
-
}
|
|
47494
|
-
async function generateChallenge(code_verifier) {
|
|
47495
|
-
const buffer = await (await crypto).subtle.digest("SHA-256", new TextEncoder().encode(code_verifier));
|
|
47496
|
-
return btoa(String.fromCharCode(...new Uint8Array(buffer))).replace(/\//g, "_").replace(/\+/g, "-").replace(/=/g, "");
|
|
47497
|
-
}
|
|
47498
|
-
async function pkceChallenge(length) {
|
|
47499
|
-
if (!length)
|
|
47500
|
-
length = 43;
|
|
47501
|
-
if (length < 43 || length > 128) {
|
|
47502
|
-
throw `Expected a length between 43 and 128. Received ${length}.`;
|
|
47503
|
-
}
|
|
47504
|
-
const verifier = await generateVerifier(length);
|
|
47505
|
-
const challenge = await generateChallenge(verifier);
|
|
47506
|
-
return {
|
|
47507
|
-
code_verifier: verifier,
|
|
47508
|
-
code_challenge: challenge
|
|
47509
|
-
};
|
|
47510
|
-
}
|
|
47511
|
-
|
|
47512
49005
|
// ../../node_modules/.pnpm/@ai-sdk+anthropic@2.0.30_zod@3.25.76/node_modules/@ai-sdk/anthropic/dist/index.mjs
|
|
47513
|
-
var
|
|
49006
|
+
var VERSION5 = "2.0.30";
|
|
47514
49007
|
var anthropicErrorDataSchema = lazySchema(() => zodSchema(exports_external.object({
|
|
47515
49008
|
type: exports_external.literal("error"),
|
|
47516
49009
|
error: exports_external.object({
|
|
@@ -47948,9 +49441,9 @@ var anthropicProviderOptions = exports_external.object({
|
|
|
47948
49441
|
}).optional()
|
|
47949
49442
|
});
|
|
47950
49443
|
function getCacheControl(providerMetadata) {
|
|
47951
|
-
var
|
|
49444
|
+
var _a19;
|
|
47952
49445
|
const anthropic2 = providerMetadata == null ? undefined : providerMetadata.anthropic;
|
|
47953
|
-
const cacheControlValue = (
|
|
49446
|
+
const cacheControlValue = (_a19 = anthropic2 == null ? undefined : anthropic2.cacheControl) != null ? _a19 : anthropic2 == null ? undefined : anthropic2.cache_control;
|
|
47954
49447
|
return cacheControlValue;
|
|
47955
49448
|
}
|
|
47956
49449
|
var textEditor_20250728ArgsSchema = lazySchema(() => zodSchema(exports_external.object({
|
|
@@ -48057,20 +49550,20 @@ async function prepareTools({
|
|
|
48057
49550
|
return { tools: undefined, toolChoice: undefined, toolWarnings, betas };
|
|
48058
49551
|
}
|
|
48059
49552
|
const anthropicTools2 = [];
|
|
48060
|
-
for (const
|
|
48061
|
-
switch (
|
|
49553
|
+
for (const tool3 of tools) {
|
|
49554
|
+
switch (tool3.type) {
|
|
48062
49555
|
case "function": {
|
|
48063
|
-
const cacheControl = getCacheControl(
|
|
49556
|
+
const cacheControl = getCacheControl(tool3.providerOptions);
|
|
48064
49557
|
anthropicTools2.push({
|
|
48065
|
-
name:
|
|
48066
|
-
description:
|
|
48067
|
-
input_schema:
|
|
49558
|
+
name: tool3.name,
|
|
49559
|
+
description: tool3.description,
|
|
49560
|
+
input_schema: tool3.inputSchema,
|
|
48068
49561
|
cache_control: cacheControl
|
|
48069
49562
|
});
|
|
48070
49563
|
break;
|
|
48071
49564
|
}
|
|
48072
49565
|
case "provider-defined": {
|
|
48073
|
-
switch (
|
|
49566
|
+
switch (tool3.id) {
|
|
48074
49567
|
case "anthropic.code_execution_20250522": {
|
|
48075
49568
|
betas.add("code-execution-2025-05-22");
|
|
48076
49569
|
anthropicTools2.push({
|
|
@@ -48092,9 +49585,9 @@ async function prepareTools({
|
|
|
48092
49585
|
anthropicTools2.push({
|
|
48093
49586
|
name: "computer",
|
|
48094
49587
|
type: "computer_20250124",
|
|
48095
|
-
display_width_px:
|
|
48096
|
-
display_height_px:
|
|
48097
|
-
display_number:
|
|
49588
|
+
display_width_px: tool3.args.displayWidthPx,
|
|
49589
|
+
display_height_px: tool3.args.displayHeightPx,
|
|
49590
|
+
display_number: tool3.args.displayNumber
|
|
48098
49591
|
});
|
|
48099
49592
|
break;
|
|
48100
49593
|
}
|
|
@@ -48103,9 +49596,9 @@ async function prepareTools({
|
|
|
48103
49596
|
anthropicTools2.push({
|
|
48104
49597
|
name: "computer",
|
|
48105
49598
|
type: "computer_20241022",
|
|
48106
|
-
display_width_px:
|
|
48107
|
-
display_height_px:
|
|
48108
|
-
display_number:
|
|
49599
|
+
display_width_px: tool3.args.displayWidthPx,
|
|
49600
|
+
display_height_px: tool3.args.displayHeightPx,
|
|
49601
|
+
display_number: tool3.args.displayNumber
|
|
48109
49602
|
});
|
|
48110
49603
|
break;
|
|
48111
49604
|
}
|
|
@@ -48135,7 +49628,7 @@ async function prepareTools({
|
|
|
48135
49628
|
}
|
|
48136
49629
|
case "anthropic.text_editor_20250728": {
|
|
48137
49630
|
const args = await validateTypes({
|
|
48138
|
-
value:
|
|
49631
|
+
value: tool3.args,
|
|
48139
49632
|
schema: textEditor_20250728ArgsSchema
|
|
48140
49633
|
});
|
|
48141
49634
|
anthropicTools2.push({
|
|
@@ -48172,7 +49665,7 @@ async function prepareTools({
|
|
|
48172
49665
|
case "anthropic.web_fetch_20250910": {
|
|
48173
49666
|
betas.add("web-fetch-2025-09-10");
|
|
48174
49667
|
const args = await validateTypes({
|
|
48175
|
-
value:
|
|
49668
|
+
value: tool3.args,
|
|
48176
49669
|
schema: webFetch_20250910ArgsSchema
|
|
48177
49670
|
});
|
|
48178
49671
|
anthropicTools2.push({
|
|
@@ -48188,7 +49681,7 @@ async function prepareTools({
|
|
|
48188
49681
|
}
|
|
48189
49682
|
case "anthropic.web_search_20250305": {
|
|
48190
49683
|
const args = await validateTypes({
|
|
48191
|
-
value:
|
|
49684
|
+
value: tool3.args,
|
|
48192
49685
|
schema: webSearch_20250305ArgsSchema
|
|
48193
49686
|
});
|
|
48194
49687
|
anthropicTools2.push({
|
|
@@ -48202,14 +49695,14 @@ async function prepareTools({
|
|
|
48202
49695
|
break;
|
|
48203
49696
|
}
|
|
48204
49697
|
default: {
|
|
48205
|
-
toolWarnings.push({ type: "unsupported-tool", tool:
|
|
49698
|
+
toolWarnings.push({ type: "unsupported-tool", tool: tool3 });
|
|
48206
49699
|
break;
|
|
48207
49700
|
}
|
|
48208
49701
|
}
|
|
48209
49702
|
break;
|
|
48210
49703
|
}
|
|
48211
49704
|
default: {
|
|
48212
|
-
toolWarnings.push({ type: "unsupported-tool", tool:
|
|
49705
|
+
toolWarnings.push({ type: "unsupported-tool", tool: tool3 });
|
|
48213
49706
|
break;
|
|
48214
49707
|
}
|
|
48215
49708
|
}
|
|
@@ -48379,19 +49872,19 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
48379
49872
|
sendReasoning,
|
|
48380
49873
|
warnings
|
|
48381
49874
|
}) {
|
|
48382
|
-
var
|
|
49875
|
+
var _a19, _b9, _c, _d, _e;
|
|
48383
49876
|
const betas = /* @__PURE__ */ new Set;
|
|
48384
49877
|
const blocks = groupIntoBlocks(prompt);
|
|
48385
49878
|
let system = undefined;
|
|
48386
49879
|
const messages = [];
|
|
48387
49880
|
async function shouldEnableCitations(providerMetadata) {
|
|
48388
|
-
var
|
|
49881
|
+
var _a25, _b23;
|
|
48389
49882
|
const anthropicOptions = await parseProviderOptions({
|
|
48390
49883
|
provider: "anthropic",
|
|
48391
49884
|
providerOptions: providerMetadata,
|
|
48392
49885
|
schema: anthropicFilePartProviderOptions
|
|
48393
49886
|
});
|
|
48394
|
-
return (
|
|
49887
|
+
return (_b23 = (_a25 = anthropicOptions == null ? undefined : anthropicOptions.citations) == null ? undefined : _a25.enabled) != null ? _b23 : false;
|
|
48395
49888
|
}
|
|
48396
49889
|
async function getDocumentMetadata(providerMetadata) {
|
|
48397
49890
|
const anthropicOptions = await parseProviderOptions({
|
|
@@ -48431,7 +49924,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
48431
49924
|
for (let j2 = 0;j2 < content.length; j2++) {
|
|
48432
49925
|
const part = content[j2];
|
|
48433
49926
|
const isLastPart = j2 === content.length - 1;
|
|
48434
|
-
const cacheControl = (
|
|
49927
|
+
const cacheControl = (_a19 = getCacheControl(part.providerOptions)) != null ? _a19 : isLastPart ? getCacheControl(message.providerOptions) : undefined;
|
|
48435
49928
|
switch (part.type) {
|
|
48436
49929
|
case "text": {
|
|
48437
49930
|
anthropicContent.push({
|
|
@@ -48469,7 +49962,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
48469
49962
|
media_type: "application/pdf",
|
|
48470
49963
|
data: convertToBase64(part.data)
|
|
48471
49964
|
},
|
|
48472
|
-
title: (
|
|
49965
|
+
title: (_b9 = metadata.title) != null ? _b9 : part.filename,
|
|
48473
49966
|
...metadata.context && { context: metadata.context },
|
|
48474
49967
|
...enableCitations && {
|
|
48475
49968
|
citations: { enabled: true }
|
|
@@ -48882,7 +50375,7 @@ function mapAnthropicStopReason({
|
|
|
48882
50375
|
}
|
|
48883
50376
|
}
|
|
48884
50377
|
function createCitationSource(citation, citationDocuments, generateId3) {
|
|
48885
|
-
var
|
|
50378
|
+
var _a19;
|
|
48886
50379
|
if (citation.type !== "page_location" && citation.type !== "char_location") {
|
|
48887
50380
|
return;
|
|
48888
50381
|
}
|
|
@@ -48895,7 +50388,7 @@ function createCitationSource(citation, citationDocuments, generateId3) {
|
|
|
48895
50388
|
sourceType: "document",
|
|
48896
50389
|
id: generateId3(),
|
|
48897
50390
|
mediaType: documentInfo.mediaType,
|
|
48898
|
-
title: (
|
|
50391
|
+
title: (_a19 = citation.document_title) != null ? _a19 : documentInfo.title,
|
|
48899
50392
|
filename: documentInfo.filename,
|
|
48900
50393
|
providerMetadata: {
|
|
48901
50394
|
anthropic: citation.type === "page_location" ? {
|
|
@@ -48913,10 +50406,10 @@ function createCitationSource(citation, citationDocuments, generateId3) {
|
|
|
48913
50406
|
var AnthropicMessagesLanguageModel = class {
|
|
48914
50407
|
constructor(modelId, config2) {
|
|
48915
50408
|
this.specificationVersion = "v2";
|
|
48916
|
-
var
|
|
50409
|
+
var _a19;
|
|
48917
50410
|
this.modelId = modelId;
|
|
48918
50411
|
this.config = config2;
|
|
48919
|
-
this.generateId = (
|
|
50412
|
+
this.generateId = (_a19 = config2.generateId) != null ? _a19 : generateId;
|
|
48920
50413
|
}
|
|
48921
50414
|
supportsUrl(url2) {
|
|
48922
50415
|
return url2.protocol === "https:";
|
|
@@ -48925,8 +50418,8 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
48925
50418
|
return this.config.provider;
|
|
48926
50419
|
}
|
|
48927
50420
|
get supportedUrls() {
|
|
48928
|
-
var
|
|
48929
|
-
return (_c = (
|
|
50421
|
+
var _a19, _b9, _c;
|
|
50422
|
+
return (_c = (_b9 = (_a19 = this.config).supportedUrls) == null ? undefined : _b9.call(_a19)) != null ? _c : {};
|
|
48930
50423
|
}
|
|
48931
50424
|
async getArgs({
|
|
48932
50425
|
prompt,
|
|
@@ -48943,7 +50436,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
48943
50436
|
toolChoice,
|
|
48944
50437
|
providerOptions
|
|
48945
50438
|
}) {
|
|
48946
|
-
var
|
|
50439
|
+
var _a19, _b9, _c;
|
|
48947
50440
|
const warnings = [];
|
|
48948
50441
|
if (frequencyPenalty != null) {
|
|
48949
50442
|
warnings.push({
|
|
@@ -48991,10 +50484,10 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
48991
50484
|
});
|
|
48992
50485
|
const { prompt: messagesPrompt, betas: messagesBetas } = await convertToAnthropicMessagesPrompt({
|
|
48993
50486
|
prompt,
|
|
48994
|
-
sendReasoning: (
|
|
50487
|
+
sendReasoning: (_a19 = anthropicOptions == null ? undefined : anthropicOptions.sendReasoning) != null ? _a19 : true,
|
|
48995
50488
|
warnings
|
|
48996
50489
|
});
|
|
48997
|
-
const isThinking = ((
|
|
50490
|
+
const isThinking = ((_b9 = anthropicOptions == null ? undefined : anthropicOptions.thinking) == null ? undefined : _b9.type) === "enabled";
|
|
48998
50491
|
const thinkingBudget = (_c = anthropicOptions == null ? undefined : anthropicOptions.thinking) == null ? undefined : _c.budgetTokens;
|
|
48999
50492
|
const baseArgs = {
|
|
49000
50493
|
model: this.modelId,
|
|
@@ -49073,38 +50566,38 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
49073
50566
|
return combineHeaders(await resolve(this.config.headers), betas.size > 0 ? { "anthropic-beta": Array.from(betas).join(",") } : {}, headers);
|
|
49074
50567
|
}
|
|
49075
50568
|
buildRequestUrl(isStreaming) {
|
|
49076
|
-
var
|
|
49077
|
-
return (_c = (
|
|
50569
|
+
var _a19, _b9, _c;
|
|
50570
|
+
return (_c = (_b9 = (_a19 = this.config).buildRequestUrl) == null ? undefined : _b9.call(_a19, this.config.baseURL, isStreaming)) != null ? _c : `${this.config.baseURL}/messages`;
|
|
49078
50571
|
}
|
|
49079
50572
|
transformRequestBody(args) {
|
|
49080
|
-
var
|
|
49081
|
-
return (_c = (
|
|
50573
|
+
var _a19, _b9, _c;
|
|
50574
|
+
return (_c = (_b9 = (_a19 = this.config).transformRequestBody) == null ? undefined : _b9.call(_a19, args)) != null ? _c : args;
|
|
49082
50575
|
}
|
|
49083
50576
|
extractCitationDocuments(prompt) {
|
|
49084
50577
|
const isCitationPart = (part) => {
|
|
49085
|
-
var
|
|
50578
|
+
var _a19, _b9;
|
|
49086
50579
|
if (part.type !== "file") {
|
|
49087
50580
|
return false;
|
|
49088
50581
|
}
|
|
49089
50582
|
if (part.mediaType !== "application/pdf" && part.mediaType !== "text/plain") {
|
|
49090
50583
|
return false;
|
|
49091
50584
|
}
|
|
49092
|
-
const anthropic2 = (
|
|
50585
|
+
const anthropic2 = (_a19 = part.providerOptions) == null ? undefined : _a19.anthropic;
|
|
49093
50586
|
const citationsConfig = anthropic2 == null ? undefined : anthropic2.citations;
|
|
49094
|
-
return (
|
|
50587
|
+
return (_b9 = citationsConfig == null ? undefined : citationsConfig.enabled) != null ? _b9 : false;
|
|
49095
50588
|
};
|
|
49096
50589
|
return prompt.filter((message) => message.role === "user").flatMap((message) => message.content).filter(isCitationPart).map((part) => {
|
|
49097
|
-
var
|
|
50590
|
+
var _a19;
|
|
49098
50591
|
const filePart = part;
|
|
49099
50592
|
return {
|
|
49100
|
-
title: (
|
|
50593
|
+
title: (_a19 = filePart.filename) != null ? _a19 : "Untitled Document",
|
|
49101
50594
|
filename: filePart.filename,
|
|
49102
50595
|
mediaType: filePart.mediaType
|
|
49103
50596
|
};
|
|
49104
50597
|
});
|
|
49105
50598
|
}
|
|
49106
50599
|
async doGenerate(options) {
|
|
49107
|
-
var
|
|
50600
|
+
var _a19, _b9, _c, _d, _e, _f;
|
|
49108
50601
|
const { args, warnings, betas, usesJsonResponseTool } = await this.getArgs(options);
|
|
49109
50602
|
const citationDocuments = this.extractCitationDocuments(options.prompt);
|
|
49110
50603
|
const {
|
|
@@ -49238,11 +50731,11 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
49238
50731
|
toolCallId: part.tool_use_id,
|
|
49239
50732
|
toolName: "web_search",
|
|
49240
50733
|
result: part.content.map((result) => {
|
|
49241
|
-
var
|
|
50734
|
+
var _a25;
|
|
49242
50735
|
return {
|
|
49243
50736
|
url: result.url,
|
|
49244
50737
|
title: result.title,
|
|
49245
|
-
pageAge: (
|
|
50738
|
+
pageAge: (_a25 = result.page_age) != null ? _a25 : null,
|
|
49246
50739
|
encryptedContent: result.encrypted_content,
|
|
49247
50740
|
type: result.type
|
|
49248
50741
|
};
|
|
@@ -49258,7 +50751,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
49258
50751
|
title: result.title,
|
|
49259
50752
|
providerMetadata: {
|
|
49260
50753
|
anthropic: {
|
|
49261
|
-
pageAge: (
|
|
50754
|
+
pageAge: (_a19 = result.page_age) != null ? _a19 : null
|
|
49262
50755
|
}
|
|
49263
50756
|
}
|
|
49264
50757
|
});
|
|
@@ -49330,7 +50823,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
49330
50823
|
inputTokens: response.usage.input_tokens,
|
|
49331
50824
|
outputTokens: response.usage.output_tokens,
|
|
49332
50825
|
totalTokens: response.usage.input_tokens + response.usage.output_tokens,
|
|
49333
|
-
cachedInputTokens: (
|
|
50826
|
+
cachedInputTokens: (_b9 = response.usage.cache_read_input_tokens) != null ? _b9 : undefined
|
|
49334
50827
|
},
|
|
49335
50828
|
request: { body: args },
|
|
49336
50829
|
response: {
|
|
@@ -49380,7 +50873,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
49380
50873
|
controller.enqueue({ type: "stream-start", warnings });
|
|
49381
50874
|
},
|
|
49382
50875
|
transform(chunk, controller) {
|
|
49383
|
-
var
|
|
50876
|
+
var _a19, _b9, _c, _d, _e, _f, _g, _h;
|
|
49384
50877
|
if (options.includeRawChunks) {
|
|
49385
50878
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
49386
50879
|
}
|
|
@@ -49513,11 +51006,11 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
49513
51006
|
toolCallId: part.tool_use_id,
|
|
49514
51007
|
toolName: "web_search",
|
|
49515
51008
|
result: part.content.map((result) => {
|
|
49516
|
-
var
|
|
51009
|
+
var _a25;
|
|
49517
51010
|
return {
|
|
49518
51011
|
url: result.url,
|
|
49519
51012
|
title: result.title,
|
|
49520
|
-
pageAge: (
|
|
51013
|
+
pageAge: (_a25 = result.page_age) != null ? _a25 : null,
|
|
49521
51014
|
encryptedContent: result.encrypted_content,
|
|
49522
51015
|
type: result.type
|
|
49523
51016
|
};
|
|
@@ -49533,7 +51026,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
49533
51026
|
title: result.title,
|
|
49534
51027
|
providerMetadata: {
|
|
49535
51028
|
anthropic: {
|
|
49536
|
-
pageAge: (
|
|
51029
|
+
pageAge: (_a19 = result.page_age) != null ? _a19 : null
|
|
49537
51030
|
}
|
|
49538
51031
|
}
|
|
49539
51032
|
});
|
|
@@ -49726,7 +51219,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
49726
51219
|
}
|
|
49727
51220
|
case "message_start": {
|
|
49728
51221
|
usage.inputTokens = value.message.usage.input_tokens;
|
|
49729
|
-
usage.cachedInputTokens = (
|
|
51222
|
+
usage.cachedInputTokens = (_b9 = value.message.usage.cache_read_input_tokens) != null ? _b9 : undefined;
|
|
49730
51223
|
rawUsage = {
|
|
49731
51224
|
...value.message.usage
|
|
49732
51225
|
};
|
|
@@ -49949,8 +51442,8 @@ var anthropicTools = {
|
|
|
49949
51442
|
webSearch_20250305
|
|
49950
51443
|
};
|
|
49951
51444
|
function createAnthropic(options = {}) {
|
|
49952
|
-
var
|
|
49953
|
-
const baseURL = (
|
|
51445
|
+
var _a19;
|
|
51446
|
+
const baseURL = (_a19 = withoutTrailingSlash(options.baseURL)) != null ? _a19 : "https://api.anthropic.com/v1";
|
|
49954
51447
|
const getHeaders = () => withUserAgentSuffix({
|
|
49955
51448
|
"anthropic-version": "2023-06-01",
|
|
49956
51449
|
"x-api-key": loadApiKey({
|
|
@@ -49959,15 +51452,15 @@ function createAnthropic(options = {}) {
|
|
|
49959
51452
|
description: "Anthropic"
|
|
49960
51453
|
}),
|
|
49961
51454
|
...options.headers
|
|
49962
|
-
}, `ai-sdk/anthropic/${
|
|
51455
|
+
}, `ai-sdk/anthropic/${VERSION5}`);
|
|
49963
51456
|
const createChatModel = (modelId) => {
|
|
49964
|
-
var
|
|
51457
|
+
var _a25;
|
|
49965
51458
|
return new AnthropicMessagesLanguageModel(modelId, {
|
|
49966
51459
|
provider: "anthropic.messages",
|
|
49967
51460
|
baseURL,
|
|
49968
51461
|
headers: getHeaders,
|
|
49969
51462
|
fetch: options.fetch,
|
|
49970
|
-
generateId: (
|
|
51463
|
+
generateId: (_a25 = options.generateId) != null ? _a25 : generateId,
|
|
49971
51464
|
supportedUrls: () => ({
|
|
49972
51465
|
"image/*": [/^https?:\/\/.*$/]
|
|
49973
51466
|
})
|
|
@@ -50046,7 +51539,7 @@ function convertToOpenAIChatMessages({
|
|
|
50046
51539
|
messages.push({
|
|
50047
51540
|
role: "user",
|
|
50048
51541
|
content: content.map((part, index) => {
|
|
50049
|
-
var
|
|
51542
|
+
var _a19, _b9, _c;
|
|
50050
51543
|
switch (part.type) {
|
|
50051
51544
|
case "text": {
|
|
50052
51545
|
return { type: "text", text: part.text };
|
|
@@ -50058,7 +51551,7 @@ function convertToOpenAIChatMessages({
|
|
|
50058
51551
|
type: "image_url",
|
|
50059
51552
|
image_url: {
|
|
50060
51553
|
url: part.data instanceof URL ? part.data.toString() : `data:${mediaType};base64,${convertToBase64(part.data)}`,
|
|
50061
|
-
detail: (
|
|
51554
|
+
detail: (_b9 = (_a19 = part.providerOptions) == null ? undefined : _a19.openai) == null ? undefined : _b9.imageDetail
|
|
50062
51555
|
}
|
|
50063
51556
|
};
|
|
50064
51557
|
} else if (part.mediaType.startsWith("audio/")) {
|
|
@@ -50338,21 +51831,21 @@ function prepareChatTools({
|
|
|
50338
51831
|
return { tools: undefined, toolChoice: undefined, toolWarnings };
|
|
50339
51832
|
}
|
|
50340
51833
|
const openaiTools2 = [];
|
|
50341
|
-
for (const
|
|
50342
|
-
switch (
|
|
51834
|
+
for (const tool3 of tools) {
|
|
51835
|
+
switch (tool3.type) {
|
|
50343
51836
|
case "function":
|
|
50344
51837
|
openaiTools2.push({
|
|
50345
51838
|
type: "function",
|
|
50346
51839
|
function: {
|
|
50347
|
-
name:
|
|
50348
|
-
description:
|
|
50349
|
-
parameters:
|
|
51840
|
+
name: tool3.name,
|
|
51841
|
+
description: tool3.description,
|
|
51842
|
+
parameters: tool3.inputSchema,
|
|
50350
51843
|
strict: structuredOutputs ? strictJsonSchema : undefined
|
|
50351
51844
|
}
|
|
50352
51845
|
});
|
|
50353
51846
|
break;
|
|
50354
51847
|
default:
|
|
50355
|
-
toolWarnings.push({ type: "unsupported-tool", tool:
|
|
51848
|
+
toolWarnings.push({ type: "unsupported-tool", tool: tool3 });
|
|
50356
51849
|
break;
|
|
50357
51850
|
}
|
|
50358
51851
|
}
|
|
@@ -50411,14 +51904,14 @@ var OpenAIChatLanguageModel = class {
|
|
|
50411
51904
|
toolChoice,
|
|
50412
51905
|
providerOptions
|
|
50413
51906
|
}) {
|
|
50414
|
-
var
|
|
51907
|
+
var _a19, _b9, _c, _d;
|
|
50415
51908
|
const warnings = [];
|
|
50416
|
-
const openaiOptions = (
|
|
51909
|
+
const openaiOptions = (_a19 = await parseProviderOptions({
|
|
50417
51910
|
provider: "openai",
|
|
50418
51911
|
providerOptions,
|
|
50419
51912
|
schema: openaiChatLanguageModelOptions
|
|
50420
|
-
})) != null ?
|
|
50421
|
-
const structuredOutputs = (
|
|
51913
|
+
})) != null ? _a19 : {};
|
|
51914
|
+
const structuredOutputs = (_b9 = openaiOptions.structuredOutputs) != null ? _b9 : true;
|
|
50422
51915
|
if (topK != null) {
|
|
50423
51916
|
warnings.push({
|
|
50424
51917
|
type: "unsupported-setting",
|
|
@@ -50578,7 +52071,7 @@ var OpenAIChatLanguageModel = class {
|
|
|
50578
52071
|
};
|
|
50579
52072
|
}
|
|
50580
52073
|
async doGenerate(options) {
|
|
50581
|
-
var
|
|
52074
|
+
var _a19, _b9, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
|
|
50582
52075
|
const { args: body, warnings } = await this.getArgs(options);
|
|
50583
52076
|
const {
|
|
50584
52077
|
responseHeaders,
|
|
@@ -50602,10 +52095,10 @@ var OpenAIChatLanguageModel = class {
|
|
|
50602
52095
|
if (text2 != null && text2.length > 0) {
|
|
50603
52096
|
content.push({ type: "text", text: text2 });
|
|
50604
52097
|
}
|
|
50605
|
-
for (const toolCall of (
|
|
52098
|
+
for (const toolCall of (_a19 = choice.message.tool_calls) != null ? _a19 : []) {
|
|
50606
52099
|
content.push({
|
|
50607
52100
|
type: "tool-call",
|
|
50608
|
-
toolCallId: (
|
|
52101
|
+
toolCallId: (_b9 = toolCall.id) != null ? _b9 : generateId(),
|
|
50609
52102
|
toolName: toolCall.function.name,
|
|
50610
52103
|
input: toolCall.function.arguments
|
|
50611
52104
|
});
|
|
@@ -50688,7 +52181,7 @@ var OpenAIChatLanguageModel = class {
|
|
|
50688
52181
|
controller.enqueue({ type: "stream-start", warnings });
|
|
50689
52182
|
},
|
|
50690
52183
|
transform(chunk, controller) {
|
|
50691
|
-
var
|
|
52184
|
+
var _a19, _b9, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x;
|
|
50692
52185
|
if (options.includeRawChunks) {
|
|
50693
52186
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
50694
52187
|
}
|
|
@@ -50711,8 +52204,8 @@ var OpenAIChatLanguageModel = class {
|
|
|
50711
52204
|
});
|
|
50712
52205
|
}
|
|
50713
52206
|
if (value.usage != null) {
|
|
50714
|
-
usage.inputTokens = (
|
|
50715
|
-
usage.outputTokens = (
|
|
52207
|
+
usage.inputTokens = (_a19 = value.usage.prompt_tokens) != null ? _a19 : undefined;
|
|
52208
|
+
usage.outputTokens = (_b9 = value.usage.completion_tokens) != null ? _b9 : undefined;
|
|
50716
52209
|
usage.totalTokens = (_c = value.usage.total_tokens) != null ? _c : undefined;
|
|
50717
52210
|
usage.reasoningTokens = (_e = (_d = value.usage.completion_tokens_details) == null ? undefined : _d.reasoning_tokens) != null ? _e : undefined;
|
|
50718
52211
|
usage.cachedInputTokens = (_g = (_f = value.usage.prompt_tokens_details) == null ? undefined : _f.cached_tokens) != null ? _g : undefined;
|
|
@@ -50872,11 +52365,11 @@ function supportsPriorityProcessing(modelId) {
|
|
|
50872
52365
|
return modelId.startsWith("gpt-4") || modelId.startsWith("gpt-5-mini") || modelId.startsWith("gpt-5") && !modelId.startsWith("gpt-5-nano") && !modelId.startsWith("gpt-5-chat") || modelId.startsWith("o3") || modelId.startsWith("o4-mini");
|
|
50873
52366
|
}
|
|
50874
52367
|
function getSystemMessageMode(modelId) {
|
|
50875
|
-
var
|
|
52368
|
+
var _a19, _b9;
|
|
50876
52369
|
if (!isReasoningModel(modelId)) {
|
|
50877
52370
|
return "system";
|
|
50878
52371
|
}
|
|
50879
|
-
return (
|
|
52372
|
+
return (_b9 = (_a19 = reasoningModels[modelId]) == null ? undefined : _a19.systemMessageMode) != null ? _b9 : "developer";
|
|
50880
52373
|
}
|
|
50881
52374
|
var reasoningModels = {
|
|
50882
52375
|
"o1-mini": {
|
|
@@ -51137,7 +52630,7 @@ var OpenAICompletionLanguageModel = class {
|
|
|
51137
52630
|
};
|
|
51138
52631
|
}
|
|
51139
52632
|
async doGenerate(options) {
|
|
51140
|
-
var
|
|
52633
|
+
var _a19, _b9, _c;
|
|
51141
52634
|
const { args, warnings } = await this.getArgs(options);
|
|
51142
52635
|
const {
|
|
51143
52636
|
responseHeaders,
|
|
@@ -51163,8 +52656,8 @@ var OpenAICompletionLanguageModel = class {
|
|
|
51163
52656
|
return {
|
|
51164
52657
|
content: [{ type: "text", text: choice.text }],
|
|
51165
52658
|
usage: {
|
|
51166
|
-
inputTokens: (
|
|
51167
|
-
outputTokens: (
|
|
52659
|
+
inputTokens: (_a19 = response.usage) == null ? undefined : _a19.prompt_tokens,
|
|
52660
|
+
outputTokens: (_b9 = response.usage) == null ? undefined : _b9.completion_tokens,
|
|
51168
52661
|
totalTokens: (_c = response.usage) == null ? undefined : _c.total_tokens
|
|
51169
52662
|
},
|
|
51170
52663
|
finishReason: mapOpenAIFinishReason2(choice.finish_reason),
|
|
@@ -51297,7 +52790,7 @@ var OpenAIEmbeddingModel = class {
|
|
|
51297
52790
|
abortSignal,
|
|
51298
52791
|
providerOptions
|
|
51299
52792
|
}) {
|
|
51300
|
-
var
|
|
52793
|
+
var _a19;
|
|
51301
52794
|
if (values.length > this.maxEmbeddingsPerCall) {
|
|
51302
52795
|
throw new TooManyEmbeddingValuesForCallError({
|
|
51303
52796
|
provider: this.provider,
|
|
@@ -51306,11 +52799,11 @@ var OpenAIEmbeddingModel = class {
|
|
|
51306
52799
|
values
|
|
51307
52800
|
});
|
|
51308
52801
|
}
|
|
51309
|
-
const openaiOptions = (
|
|
52802
|
+
const openaiOptions = (_a19 = await parseProviderOptions({
|
|
51310
52803
|
provider: "openai",
|
|
51311
52804
|
providerOptions,
|
|
51312
52805
|
schema: openaiEmbeddingProviderOptions
|
|
51313
|
-
})) != null ?
|
|
52806
|
+
})) != null ? _a19 : {};
|
|
51314
52807
|
const {
|
|
51315
52808
|
responseHeaders,
|
|
51316
52809
|
value: response,
|
|
@@ -51363,8 +52856,8 @@ var OpenAIImageModel = class {
|
|
|
51363
52856
|
this.specificationVersion = "v2";
|
|
51364
52857
|
}
|
|
51365
52858
|
get maxImagesPerCall() {
|
|
51366
|
-
var
|
|
51367
|
-
return (
|
|
52859
|
+
var _a19;
|
|
52860
|
+
return (_a19 = modelMaxImagesPerCall[this.modelId]) != null ? _a19 : 1;
|
|
51368
52861
|
}
|
|
51369
52862
|
get provider() {
|
|
51370
52863
|
return this.config.provider;
|
|
@@ -51379,7 +52872,7 @@ var OpenAIImageModel = class {
|
|
|
51379
52872
|
headers,
|
|
51380
52873
|
abortSignal
|
|
51381
52874
|
}) {
|
|
51382
|
-
var
|
|
52875
|
+
var _a19, _b9, _c, _d;
|
|
51383
52876
|
const warnings = [];
|
|
51384
52877
|
if (aspectRatio != null) {
|
|
51385
52878
|
warnings.push({
|
|
@@ -51391,7 +52884,7 @@ var OpenAIImageModel = class {
|
|
|
51391
52884
|
if (seed != null) {
|
|
51392
52885
|
warnings.push({ type: "unsupported-setting", setting: "seed" });
|
|
51393
52886
|
}
|
|
51394
|
-
const currentDate = (_c = (
|
|
52887
|
+
const currentDate = (_c = (_b9 = (_a19 = this.config._internal) == null ? undefined : _a19.currentDate) == null ? undefined : _b9.call(_a19)) != null ? _c : /* @__PURE__ */ new Date;
|
|
51395
52888
|
const { value: response, responseHeaders } = await postJsonToApi({
|
|
51396
52889
|
url: this.config.url({
|
|
51397
52890
|
path: "/images/generations",
|
|
@@ -51623,7 +53116,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
51623
53116
|
store,
|
|
51624
53117
|
hasLocalShellTool = false
|
|
51625
53118
|
}) {
|
|
51626
|
-
var
|
|
53119
|
+
var _a19, _b9, _c, _d;
|
|
51627
53120
|
const input = [];
|
|
51628
53121
|
const warnings = [];
|
|
51629
53122
|
for (const { role, content } of prompt) {
|
|
@@ -51656,7 +53149,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
51656
53149
|
input.push({
|
|
51657
53150
|
role: "user",
|
|
51658
53151
|
content: content.map((part, index) => {
|
|
51659
|
-
var
|
|
53152
|
+
var _a25, _b23, _c2;
|
|
51660
53153
|
switch (part.type) {
|
|
51661
53154
|
case "text": {
|
|
51662
53155
|
return { type: "input_text", text: part.text };
|
|
@@ -51669,7 +53162,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
51669
53162
|
...part.data instanceof URL ? { image_url: part.data.toString() } : typeof part.data === "string" && isFileId(part.data, fileIdPrefixes) ? { file_id: part.data } : {
|
|
51670
53163
|
image_url: `data:${mediaType};base64,${convertToBase64(part.data)}`
|
|
51671
53164
|
},
|
|
51672
|
-
detail: (
|
|
53165
|
+
detail: (_b23 = (_a25 = part.providerOptions) == null ? undefined : _a25.openai) == null ? undefined : _b23.imageDetail
|
|
51673
53166
|
};
|
|
51674
53167
|
} else if (part.mediaType === "application/pdf") {
|
|
51675
53168
|
if (part.data instanceof URL) {
|
|
@@ -51702,7 +53195,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
51702
53195
|
for (const part of content) {
|
|
51703
53196
|
switch (part.type) {
|
|
51704
53197
|
case "text": {
|
|
51705
|
-
const id = (
|
|
53198
|
+
const id = (_b9 = (_a19 = part.providerOptions) == null ? undefined : _a19.openai) == null ? undefined : _b9.itemId;
|
|
51706
53199
|
if (store && id != null) {
|
|
51707
53200
|
input.push({ type: "item_reference", id });
|
|
51708
53201
|
break;
|
|
@@ -52378,22 +53871,22 @@ async function prepareResponsesTools({
|
|
|
52378
53871
|
return { tools: undefined, toolChoice: undefined, toolWarnings };
|
|
52379
53872
|
}
|
|
52380
53873
|
const openaiTools2 = [];
|
|
52381
|
-
for (const
|
|
52382
|
-
switch (
|
|
53874
|
+
for (const tool3 of tools) {
|
|
53875
|
+
switch (tool3.type) {
|
|
52383
53876
|
case "function":
|
|
52384
53877
|
openaiTools2.push({
|
|
52385
53878
|
type: "function",
|
|
52386
|
-
name:
|
|
52387
|
-
description:
|
|
52388
|
-
parameters:
|
|
53879
|
+
name: tool3.name,
|
|
53880
|
+
description: tool3.description,
|
|
53881
|
+
parameters: tool3.inputSchema,
|
|
52389
53882
|
strict: strictJsonSchema
|
|
52390
53883
|
});
|
|
52391
53884
|
break;
|
|
52392
53885
|
case "provider-defined": {
|
|
52393
|
-
switch (
|
|
53886
|
+
switch (tool3.id) {
|
|
52394
53887
|
case "openai.file_search": {
|
|
52395
53888
|
const args = await validateTypes({
|
|
52396
|
-
value:
|
|
53889
|
+
value: tool3.args,
|
|
52397
53890
|
schema: fileSearchArgsSchema
|
|
52398
53891
|
});
|
|
52399
53892
|
openaiTools2.push({
|
|
@@ -52416,7 +53909,7 @@ async function prepareResponsesTools({
|
|
|
52416
53909
|
}
|
|
52417
53910
|
case "openai.web_search_preview": {
|
|
52418
53911
|
const args = await validateTypes({
|
|
52419
|
-
value:
|
|
53912
|
+
value: tool3.args,
|
|
52420
53913
|
schema: webSearchPreviewArgsSchema
|
|
52421
53914
|
});
|
|
52422
53915
|
openaiTools2.push({
|
|
@@ -52428,7 +53921,7 @@ async function prepareResponsesTools({
|
|
|
52428
53921
|
}
|
|
52429
53922
|
case "openai.web_search": {
|
|
52430
53923
|
const args = await validateTypes({
|
|
52431
|
-
value:
|
|
53924
|
+
value: tool3.args,
|
|
52432
53925
|
schema: webSearchArgsSchema
|
|
52433
53926
|
});
|
|
52434
53927
|
openaiTools2.push({
|
|
@@ -52441,7 +53934,7 @@ async function prepareResponsesTools({
|
|
|
52441
53934
|
}
|
|
52442
53935
|
case "openai.code_interpreter": {
|
|
52443
53936
|
const args = await validateTypes({
|
|
52444
|
-
value:
|
|
53937
|
+
value: tool3.args,
|
|
52445
53938
|
schema: codeInterpreterArgsSchema
|
|
52446
53939
|
});
|
|
52447
53940
|
openaiTools2.push({
|
|
@@ -52452,7 +53945,7 @@ async function prepareResponsesTools({
|
|
|
52452
53945
|
}
|
|
52453
53946
|
case "openai.image_generation": {
|
|
52454
53947
|
const args = await validateTypes({
|
|
52455
|
-
value:
|
|
53948
|
+
value: tool3.args,
|
|
52456
53949
|
schema: imageGenerationArgsSchema
|
|
52457
53950
|
});
|
|
52458
53951
|
openaiTools2.push({
|
|
@@ -52476,7 +53969,7 @@ async function prepareResponsesTools({
|
|
|
52476
53969
|
break;
|
|
52477
53970
|
}
|
|
52478
53971
|
default:
|
|
52479
|
-
toolWarnings.push({ type: "unsupported-tool", tool:
|
|
53972
|
+
toolWarnings.push({ type: "unsupported-tool", tool: tool3 });
|
|
52480
53973
|
break;
|
|
52481
53974
|
}
|
|
52482
53975
|
}
|
|
@@ -52531,7 +54024,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
52531
54024
|
toolChoice,
|
|
52532
54025
|
responseFormat
|
|
52533
54026
|
}) {
|
|
52534
|
-
var
|
|
54027
|
+
var _a19, _b9, _c, _d;
|
|
52535
54028
|
const warnings = [];
|
|
52536
54029
|
const modelConfig = getResponsesModelConfig(this.modelId);
|
|
52537
54030
|
if (topK != null) {
|
|
@@ -52564,11 +54057,11 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
52564
54057
|
prompt,
|
|
52565
54058
|
systemMessageMode: modelConfig.systemMessageMode,
|
|
52566
54059
|
fileIdPrefixes: this.config.fileIdPrefixes,
|
|
52567
|
-
store: (
|
|
54060
|
+
store: (_a19 = openaiOptions == null ? undefined : openaiOptions.store) != null ? _a19 : true,
|
|
52568
54061
|
hasLocalShellTool: hasOpenAITool("openai.local_shell")
|
|
52569
54062
|
});
|
|
52570
54063
|
warnings.push(...inputWarnings);
|
|
52571
|
-
const strictJsonSchema = (
|
|
54064
|
+
const strictJsonSchema = (_b9 = openaiOptions == null ? undefined : openaiOptions.strictJsonSchema) != null ? _b9 : false;
|
|
52572
54065
|
let include = openaiOptions == null ? undefined : openaiOptions.include;
|
|
52573
54066
|
function addInclude(key) {
|
|
52574
54067
|
if (include == null) {
|
|
@@ -52578,13 +54071,13 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
52578
54071
|
}
|
|
52579
54072
|
}
|
|
52580
54073
|
function hasOpenAITool(id) {
|
|
52581
|
-
return (tools == null ? undefined : tools.find((
|
|
54074
|
+
return (tools == null ? undefined : tools.find((tool3) => tool3.type === "provider-defined" && tool3.id === id)) != null;
|
|
52582
54075
|
}
|
|
52583
54076
|
const topLogprobs = typeof (openaiOptions == null ? undefined : openaiOptions.logprobs) === "number" ? openaiOptions == null ? undefined : openaiOptions.logprobs : (openaiOptions == null ? undefined : openaiOptions.logprobs) === true ? TOP_LOGPROBS_MAX : undefined;
|
|
52584
54077
|
if (topLogprobs) {
|
|
52585
54078
|
addInclude("message.output_text.logprobs");
|
|
52586
54079
|
}
|
|
52587
|
-
const webSearchToolName = (_c = tools == null ? undefined : tools.find((
|
|
54080
|
+
const webSearchToolName = (_c = tools == null ? undefined : tools.find((tool3) => tool3.type === "provider-defined" && (tool3.id === "openai.web_search" || tool3.id === "openai.web_search_preview"))) == null ? undefined : _c.name;
|
|
52588
54081
|
if (webSearchToolName) {
|
|
52589
54082
|
addInclude("web_search_call.action.sources");
|
|
52590
54083
|
}
|
|
@@ -52713,7 +54206,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
52713
54206
|
};
|
|
52714
54207
|
}
|
|
52715
54208
|
async doGenerate(options) {
|
|
52716
|
-
var
|
|
54209
|
+
var _a19, _b9, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s;
|
|
52717
54210
|
const {
|
|
52718
54211
|
args: body,
|
|
52719
54212
|
warnings,
|
|
@@ -52763,7 +54256,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
52763
54256
|
providerMetadata: {
|
|
52764
54257
|
openai: {
|
|
52765
54258
|
itemId: part.id,
|
|
52766
|
-
reasoningEncryptedContent: (
|
|
54259
|
+
reasoningEncryptedContent: (_a19 = part.encrypted_content) != null ? _a19 : null
|
|
52767
54260
|
}
|
|
52768
54261
|
}
|
|
52769
54262
|
});
|
|
@@ -52807,7 +54300,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
52807
54300
|
}
|
|
52808
54301
|
case "message": {
|
|
52809
54302
|
for (const contentPart of part.content) {
|
|
52810
|
-
if (((_c = (
|
|
54303
|
+
if (((_c = (_b9 = options.providerOptions) == null ? undefined : _b9.openai) == null ? undefined : _c.logprobs) && contentPart.logprobs) {
|
|
52811
54304
|
logprobs.push(contentPart.logprobs);
|
|
52812
54305
|
}
|
|
52813
54306
|
content.push({
|
|
@@ -53019,7 +54512,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
53019
54512
|
controller.enqueue({ type: "stream-start", warnings });
|
|
53020
54513
|
},
|
|
53021
54514
|
transform(chunk, controller) {
|
|
53022
|
-
var
|
|
54515
|
+
var _a19, _b9, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v;
|
|
53023
54516
|
if (options.includeRawChunks) {
|
|
53024
54517
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
53025
54518
|
}
|
|
@@ -53129,7 +54622,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
53129
54622
|
providerMetadata: {
|
|
53130
54623
|
openai: {
|
|
53131
54624
|
itemId: value.item.id,
|
|
53132
|
-
reasoningEncryptedContent: (
|
|
54625
|
+
reasoningEncryptedContent: (_a19 = value.item.encrypted_content) != null ? _a19 : null
|
|
53133
54626
|
}
|
|
53134
54627
|
}
|
|
53135
54628
|
});
|
|
@@ -53193,7 +54686,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
53193
54686
|
toolName: "file_search",
|
|
53194
54687
|
result: {
|
|
53195
54688
|
queries: value.item.queries,
|
|
53196
|
-
results: (_c = (
|
|
54689
|
+
results: (_c = (_b9 = value.item.results) == null ? undefined : _b9.map((result) => ({
|
|
53197
54690
|
attributes: result.attributes,
|
|
53198
54691
|
fileId: result.file_id,
|
|
53199
54692
|
filename: result.filename,
|
|
@@ -53499,10 +54992,10 @@ function getResponsesModelConfig(modelId) {
|
|
|
53499
54992
|
};
|
|
53500
54993
|
}
|
|
53501
54994
|
function mapWebSearchOutput(action) {
|
|
53502
|
-
var
|
|
54995
|
+
var _a19;
|
|
53503
54996
|
switch (action.type) {
|
|
53504
54997
|
case "search":
|
|
53505
|
-
return { action: { type: "search", query: (
|
|
54998
|
+
return { action: { type: "search", query: (_a19 = action.query) != null ? _a19 : undefined } };
|
|
53506
54999
|
case "open_page":
|
|
53507
55000
|
return { action: { type: "openPage", url: action.url } };
|
|
53508
55001
|
case "find":
|
|
@@ -53580,8 +55073,8 @@ var OpenAISpeechModel = class {
|
|
|
53580
55073
|
};
|
|
53581
55074
|
}
|
|
53582
55075
|
async doGenerate(options) {
|
|
53583
|
-
var
|
|
53584
|
-
const currentDate = (_c = (
|
|
55076
|
+
var _a19, _b9, _c;
|
|
55077
|
+
const currentDate = (_c = (_b9 = (_a19 = this.config._internal) == null ? undefined : _a19.currentDate) == null ? undefined : _b9.call(_a19)) != null ? _c : /* @__PURE__ */ new Date;
|
|
53585
55078
|
const { requestBody, warnings } = await this.getArgs(options);
|
|
53586
55079
|
const {
|
|
53587
55080
|
value: audio,
|
|
@@ -53757,8 +55250,8 @@ var OpenAITranscriptionModel = class {
|
|
|
53757
55250
|
};
|
|
53758
55251
|
}
|
|
53759
55252
|
async doGenerate(options) {
|
|
53760
|
-
var
|
|
53761
|
-
const currentDate = (_c = (
|
|
55253
|
+
var _a19, _b9, _c, _d, _e, _f, _g, _h;
|
|
55254
|
+
const currentDate = (_c = (_b9 = (_a19 = this.config._internal) == null ? undefined : _a19.currentDate) == null ? undefined : _b9.call(_a19)) != null ? _c : /* @__PURE__ */ new Date;
|
|
53762
55255
|
const { formData, warnings } = await this.getArgs(options);
|
|
53763
55256
|
const {
|
|
53764
55257
|
value: response,
|
|
@@ -53800,14 +55293,14 @@ var OpenAITranscriptionModel = class {
|
|
|
53800
55293
|
};
|
|
53801
55294
|
}
|
|
53802
55295
|
};
|
|
53803
|
-
var
|
|
55296
|
+
var VERSION6 = "2.0.52";
|
|
53804
55297
|
function createOpenAI(options = {}) {
|
|
53805
|
-
var
|
|
53806
|
-
const baseURL = (
|
|
55298
|
+
var _a19, _b9;
|
|
55299
|
+
const baseURL = (_a19 = withoutTrailingSlash(loadOptionalSetting({
|
|
53807
55300
|
settingValue: options.baseURL,
|
|
53808
55301
|
environmentVariableName: "OPENAI_BASE_URL"
|
|
53809
|
-
}))) != null ?
|
|
53810
|
-
const providerName = (
|
|
55302
|
+
}))) != null ? _a19 : "https://api.openai.com/v1";
|
|
55303
|
+
const providerName = (_b9 = options.name) != null ? _b9 : "openai";
|
|
53811
55304
|
const getHeaders = () => withUserAgentSuffix({
|
|
53812
55305
|
Authorization: `Bearer ${loadApiKey({
|
|
53813
55306
|
apiKey: options.apiKey,
|
|
@@ -53817,7 +55310,7 @@ function createOpenAI(options = {}) {
|
|
|
53817
55310
|
"OpenAI-Organization": options.organization,
|
|
53818
55311
|
"OpenAI-Project": options.project,
|
|
53819
55312
|
...options.headers
|
|
53820
|
-
}, `ai-sdk/openai/${
|
|
55313
|
+
}, `ai-sdk/openai/${VERSION6}`);
|
|
53821
55314
|
const createChatModel = (modelId) => new OpenAIChatLanguageModel(modelId, {
|
|
53822
55315
|
provider: `${providerName}.chat`,
|
|
53823
55316
|
url: ({ path }) => `${baseURL}${path}`,
|
|
@@ -57499,29 +58992,29 @@ var ma = function() {
|
|
|
57499
58992
|
var e3, t2, n2, r2, a2, o2, c2, l2;
|
|
57500
58993
|
}();
|
|
57501
58994
|
var ya;
|
|
57502
|
-
var
|
|
58995
|
+
var _a19;
|
|
57503
58996
|
var ga;
|
|
57504
58997
|
async function ka(e3, a2, i2, s2, o2) {
|
|
57505
58998
|
try {
|
|
57506
58999
|
if (!ya) {
|
|
57507
|
-
const
|
|
57508
|
-
ya = await createMCPClient({ transport:
|
|
59000
|
+
const t2 = new ma(new URL(e3 || "http://localhost:3000/mcp"));
|
|
59001
|
+
ya = await createMCPClient({ transport: t2 });
|
|
57509
59002
|
}
|
|
57510
|
-
if (!
|
|
59003
|
+
if (!_a19)
|
|
57511
59004
|
switch (a2) {
|
|
57512
59005
|
case "openai":
|
|
57513
59006
|
const e4 = createOpenAI({ apiKey: s2 });
|
|
57514
|
-
|
|
59007
|
+
_a19 = e4(i2);
|
|
57515
59008
|
break;
|
|
57516
59009
|
case "anthropic":
|
|
57517
59010
|
const t2 = createAnthropic({ apiKey: s2 });
|
|
57518
|
-
|
|
59011
|
+
_a19 = t2(i2);
|
|
57519
59012
|
break;
|
|
57520
59013
|
default:
|
|
57521
59014
|
throw new Error("Invalid AI provider");
|
|
57522
59015
|
}
|
|
57523
59016
|
ga || (ga = await ya.tools());
|
|
57524
|
-
return (await streamText({ model:
|
|
59017
|
+
return (await streamText({ model: _a19, tools: ga, stopWhen: stepCountIs(5), messages: [{ role: "user", content: [{ type: "text", text: o2 }] }] })).textStream;
|
|
57525
59018
|
} catch (e4) {
|
|
57526
59019
|
throw console.error(e4), e4;
|
|
57527
59020
|
}
|