agents 0.0.0-bfc9c75 → 0.0.0-bfe9e3d

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.
Files changed (60) hide show
  1. package/dist/_esm-LV5FJ3HK.js +3922 -0
  2. package/dist/_esm-LV5FJ3HK.js.map +1 -0
  3. package/dist/ai-chat-agent.d.ts +2 -1
  4. package/dist/ai-chat-agent.js +350 -57
  5. package/dist/ai-chat-agent.js.map +1 -1
  6. package/dist/ai-chat-v5-migration.js +1 -0
  7. package/dist/ai-react.d.ts +8 -1
  8. package/dist/ai-react.js +157 -111
  9. package/dist/ai-react.js.map +1 -1
  10. package/dist/ai-types.d.ts +1 -0
  11. package/dist/ai-types.js +2 -1
  12. package/dist/ccip-CMBYN64O.js +15 -0
  13. package/dist/ccip-CMBYN64O.js.map +1 -0
  14. package/dist/{chunk-YDUDMOL6.js → chunk-254F4GDT.js} +97 -50
  15. package/dist/chunk-254F4GDT.js.map +1 -0
  16. package/dist/{chunk-MH46VMM4.js → chunk-3OT2NNEW.js} +396 -67
  17. package/dist/chunk-3OT2NNEW.js.map +1 -0
  18. package/dist/chunk-5Y6BEZDY.js +276 -0
  19. package/dist/chunk-5Y6BEZDY.js.map +1 -0
  20. package/dist/{chunk-AVYJQSLW.js → chunk-BER7KXUJ.js} +2 -1
  21. package/dist/chunk-BER7KXUJ.js.map +1 -0
  22. package/dist/chunk-JJBFIGUC.js +5202 -0
  23. package/dist/chunk-JJBFIGUC.js.map +1 -0
  24. package/dist/chunk-PR4QN5HX.js +43 -0
  25. package/dist/chunk-PR4QN5HX.js.map +1 -0
  26. package/dist/chunk-TYAY6AU6.js +159 -0
  27. package/dist/chunk-TYAY6AU6.js.map +1 -0
  28. package/dist/{chunk-LL2AFX7V.js → chunk-Z44WASMA.js} +7 -2
  29. package/dist/{chunk-LL2AFX7V.js.map → chunk-Z44WASMA.js.map} +1 -1
  30. package/dist/{client-CvaJdLQA.d.ts → client-DVoPb3-C.d.ts} +131 -26
  31. package/dist/client.js +2 -1
  32. package/dist/codemode/ai.d.ts +25 -0
  33. package/dist/codemode/ai.js +5112 -0
  34. package/dist/codemode/ai.js.map +1 -0
  35. package/dist/index.d.ts +25 -32
  36. package/dist/index.js +5 -4
  37. package/dist/mcp/client.d.ts +2 -1
  38. package/dist/mcp/client.js +2 -1
  39. package/dist/mcp/do-oauth-client-provider.js +2 -1
  40. package/dist/mcp/index.d.ts +13 -31
  41. package/dist/mcp/index.js +233 -163
  42. package/dist/mcp/index.js.map +1 -1
  43. package/dist/mcp/x402.d.ts +39 -0
  44. package/dist/mcp/x402.js +3195 -0
  45. package/dist/mcp/x402.js.map +1 -0
  46. package/dist/mcp-BH1fJeiU.d.ts +58 -0
  47. package/dist/observability/index.d.ts +12 -24
  48. package/dist/observability/index.js +5 -4
  49. package/dist/react.d.ts +10 -6
  50. package/dist/react.js +101 -3
  51. package/dist/react.js.map +1 -1
  52. package/dist/schedule.js +2 -0
  53. package/dist/schedule.js.map +1 -1
  54. package/dist/secp256k1-M22GZP2U.js +2193 -0
  55. package/dist/secp256k1-M22GZP2U.js.map +1 -0
  56. package/package.json +19 -6
  57. package/src/index.ts +141 -57
  58. package/dist/chunk-AVYJQSLW.js.map +0 -1
  59. package/dist/chunk-MH46VMM4.js.map +0 -1
  60. package/dist/chunk-YDUDMOL6.js.map +0 -1
@@ -0,0 +1,43 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
8
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
9
+ }) : x)(function(x) {
10
+ if (typeof require !== "undefined") return require.apply(this, arguments);
11
+ throw Error('Dynamic require of "' + x + '" is not supported');
12
+ });
13
+ var __commonJS = (cb, mod) => function __require2() {
14
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
15
+ };
16
+ var __export = (target, all) => {
17
+ for (var name in all)
18
+ __defProp(target, name, { get: all[name], enumerable: true });
19
+ };
20
+ var __copyProps = (to, from, except, desc) => {
21
+ if (from && typeof from === "object" || typeof from === "function") {
22
+ for (let key of __getOwnPropNames(from))
23
+ if (!__hasOwnProp.call(to, key) && key !== except)
24
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
25
+ }
26
+ return to;
27
+ };
28
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
29
+ // If the importer is in node compatibility mode or this is not an ESM
30
+ // file that has been converted to a CommonJS file using a Babel-
31
+ // compatible transform (i.e. "__esModule" has not been set), then set
32
+ // "default" to the CommonJS "module.exports" for node compatibility.
33
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
34
+ mod
35
+ ));
36
+
37
+ export {
38
+ __require,
39
+ __commonJS,
40
+ __export,
41
+ __toESM
42
+ };
43
+ //# sourceMappingURL=chunk-PR4QN5HX.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,159 @@
1
+ // ../../node_modules/@noble/hashes/esm/cryptoNode.js
2
+ import * as nc from "crypto";
3
+ var crypto = nc && typeof nc === "object" && "webcrypto" in nc ? nc.webcrypto : nc && typeof nc === "object" && "randomBytes" in nc ? nc : void 0;
4
+
5
+ // ../../node_modules/@noble/hashes/esm/utils.js
6
+ function isBytes(a) {
7
+ return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array";
8
+ }
9
+ function anumber(n) {
10
+ if (!Number.isSafeInteger(n) || n < 0)
11
+ throw new Error("positive integer expected, got " + n);
12
+ }
13
+ function abytes(b, ...lengths) {
14
+ if (!isBytes(b))
15
+ throw new Error("Uint8Array expected");
16
+ if (lengths.length > 0 && !lengths.includes(b.length))
17
+ throw new Error("Uint8Array expected of length " + lengths + ", got length=" + b.length);
18
+ }
19
+ function ahash(h) {
20
+ if (typeof h !== "function" || typeof h.create !== "function")
21
+ throw new Error("Hash should be wrapped by utils.createHasher");
22
+ anumber(h.outputLen);
23
+ anumber(h.blockLen);
24
+ }
25
+ function aexists(instance, checkFinished = true) {
26
+ if (instance.destroyed)
27
+ throw new Error("Hash instance has been destroyed");
28
+ if (checkFinished && instance.finished)
29
+ throw new Error("Hash#digest() has already been called");
30
+ }
31
+ function aoutput(out, instance) {
32
+ abytes(out);
33
+ const min = instance.outputLen;
34
+ if (out.length < min) {
35
+ throw new Error("digestInto() expects output buffer of length at least " + min);
36
+ }
37
+ }
38
+ function u32(arr) {
39
+ return new Uint32Array(arr.buffer, arr.byteOffset, Math.floor(arr.byteLength / 4));
40
+ }
41
+ function clean(...arrays) {
42
+ for (let i = 0; i < arrays.length; i++) {
43
+ arrays[i].fill(0);
44
+ }
45
+ }
46
+ function createView(arr) {
47
+ return new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
48
+ }
49
+ function rotr(word, shift) {
50
+ return word << 32 - shift | word >>> shift;
51
+ }
52
+ var isLE = /* @__PURE__ */ (() => new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68)();
53
+ function byteSwap(word) {
54
+ return word << 24 & 4278190080 | word << 8 & 16711680 | word >>> 8 & 65280 | word >>> 24 & 255;
55
+ }
56
+ function byteSwap32(arr) {
57
+ for (let i = 0; i < arr.length; i++) {
58
+ arr[i] = byteSwap(arr[i]);
59
+ }
60
+ return arr;
61
+ }
62
+ var swap32IfBE = isLE ? (u) => u : byteSwap32;
63
+ function utf8ToBytes(str) {
64
+ if (typeof str !== "string")
65
+ throw new Error("string expected");
66
+ return new Uint8Array(new TextEncoder().encode(str));
67
+ }
68
+ function toBytes(data) {
69
+ if (typeof data === "string")
70
+ data = utf8ToBytes(data);
71
+ abytes(data);
72
+ return data;
73
+ }
74
+ function concatBytes(...arrays) {
75
+ let sum = 0;
76
+ for (let i = 0; i < arrays.length; i++) {
77
+ const a = arrays[i];
78
+ abytes(a);
79
+ sum += a.length;
80
+ }
81
+ const res = new Uint8Array(sum);
82
+ for (let i = 0, pad = 0; i < arrays.length; i++) {
83
+ const a = arrays[i];
84
+ res.set(a, pad);
85
+ pad += a.length;
86
+ }
87
+ return res;
88
+ }
89
+ var Hash = class {
90
+ };
91
+ function createHasher(hashCons) {
92
+ const hashC = (msg) => hashCons().update(toBytes(msg)).digest();
93
+ const tmp = hashCons();
94
+ hashC.outputLen = tmp.outputLen;
95
+ hashC.blockLen = tmp.blockLen;
96
+ hashC.create = () => hashCons();
97
+ return hashC;
98
+ }
99
+ function randomBytes(bytesLength = 32) {
100
+ if (crypto && typeof crypto.getRandomValues === "function") {
101
+ return crypto.getRandomValues(new Uint8Array(bytesLength));
102
+ }
103
+ if (crypto && typeof crypto.randomBytes === "function") {
104
+ return Uint8Array.from(crypto.randomBytes(bytesLength));
105
+ }
106
+ throw new Error("crypto.getRandomValues must be defined");
107
+ }
108
+
109
+ // ../../node_modules/@noble/hashes/esm/_u64.js
110
+ var U32_MASK64 = /* @__PURE__ */ BigInt(2 ** 32 - 1);
111
+ var _32n = /* @__PURE__ */ BigInt(32);
112
+ function fromBig(n, le = false) {
113
+ if (le)
114
+ return { h: Number(n & U32_MASK64), l: Number(n >> _32n & U32_MASK64) };
115
+ return { h: Number(n >> _32n & U32_MASK64) | 0, l: Number(n & U32_MASK64) | 0 };
116
+ }
117
+ function split(lst, le = false) {
118
+ const len = lst.length;
119
+ let Ah = new Uint32Array(len);
120
+ let Al = new Uint32Array(len);
121
+ for (let i = 0; i < len; i++) {
122
+ const { h, l } = fromBig(lst[i], le);
123
+ [Ah[i], Al[i]] = [h, l];
124
+ }
125
+ return [Ah, Al];
126
+ }
127
+ var rotlSH = (h, l, s) => h << s | l >>> 32 - s;
128
+ var rotlSL = (h, l, s) => l << s | h >>> 32 - s;
129
+ var rotlBH = (h, l, s) => l << s - 32 | h >>> 64 - s;
130
+ var rotlBL = (h, l, s) => h << s - 32 | l >>> 64 - s;
131
+
132
+ export {
133
+ anumber,
134
+ abytes,
135
+ ahash,
136
+ aexists,
137
+ aoutput,
138
+ u32,
139
+ clean,
140
+ createView,
141
+ rotr,
142
+ swap32IfBE,
143
+ toBytes,
144
+ concatBytes,
145
+ Hash,
146
+ createHasher,
147
+ randomBytes,
148
+ split,
149
+ rotlSH,
150
+ rotlSL,
151
+ rotlBH,
152
+ rotlBL
153
+ };
154
+ /*! Bundled license information:
155
+
156
+ @noble/hashes/esm/utils.js:
157
+ (*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
158
+ */
159
+ //# sourceMappingURL=chunk-TYAY6AU6.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../node_modules/@noble/hashes/src/cryptoNode.ts","../../../node_modules/@noble/hashes/src/utils.ts","../../../node_modules/@noble/hashes/src/_u64.ts"],"sourcesContent":["/**\n * Internal webcrypto alias.\n * We prefer WebCrypto aka globalThis.crypto, which exists in node.js 16+.\n * Falls back to Node.js built-in crypto for Node.js <=v14.\n * See utils.ts for details.\n * @module\n */\n// @ts-ignore\nimport * as nc from 'node:crypto';\nexport const crypto: any =\n nc && typeof nc === 'object' && 'webcrypto' in nc\n ? (nc.webcrypto as any)\n : nc && typeof nc === 'object' && 'randomBytes' in nc\n ? nc\n : undefined;\n","/**\n * Utilities for hex, bytes, CSPRNG.\n * @module\n */\n/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */\n\n// We use WebCrypto aka globalThis.crypto, which exists in browsers and node.js 16+.\n// node.js versions earlier than v19 don't declare it in global scope.\n// For node.js, package.json#exports field mapping rewrites import\n// from `crypto` to `cryptoNode`, which imports native module.\n// Makes the utils un-importable in browsers without a bundler.\n// Once node.js 18 is deprecated (2025-04-30), we can just drop the import.\nimport { crypto } from '@noble/hashes/crypto';\n\n/** Checks if something is Uint8Array. Be careful: nodejs Buffer will return true. */\nexport function isBytes(a: unknown): a is Uint8Array {\n return a instanceof Uint8Array || (ArrayBuffer.isView(a) && a.constructor.name === 'Uint8Array');\n}\n\n/** Asserts something is positive integer. */\nexport function anumber(n: number): void {\n if (!Number.isSafeInteger(n) || n < 0) throw new Error('positive integer expected, got ' + n);\n}\n\n/** Asserts something is Uint8Array. */\nexport function abytes(b: Uint8Array | undefined, ...lengths: number[]): void {\n if (!isBytes(b)) throw new Error('Uint8Array expected');\n if (lengths.length > 0 && !lengths.includes(b.length))\n throw new Error('Uint8Array expected of length ' + lengths + ', got length=' + b.length);\n}\n\n/** Asserts something is hash */\nexport function ahash(h: IHash): void {\n if (typeof h !== 'function' || typeof h.create !== 'function')\n throw new Error('Hash should be wrapped by utils.createHasher');\n anumber(h.outputLen);\n anumber(h.blockLen);\n}\n\n/** Asserts a hash instance has not been destroyed / finished */\nexport function aexists(instance: any, checkFinished = true): void {\n if (instance.destroyed) throw new Error('Hash instance has been destroyed');\n if (checkFinished && instance.finished) throw new Error('Hash#digest() has already been called');\n}\n\n/** Asserts output is properly-sized byte array */\nexport function aoutput(out: any, instance: any): void {\n abytes(out);\n const min = instance.outputLen;\n if (out.length < min) {\n throw new Error('digestInto() expects output buffer of length at least ' + min);\n }\n}\n\n/** Generic type encompassing 8/16/32-byte arrays - but not 64-byte. */\n// prettier-ignore\nexport type TypedArray = Int8Array | Uint8ClampedArray | Uint8Array |\n Uint16Array | Int16Array | Uint32Array | Int32Array;\n\n/** Cast u8 / u16 / u32 to u8. */\nexport function u8(arr: TypedArray): Uint8Array {\n return new Uint8Array(arr.buffer, arr.byteOffset, arr.byteLength);\n}\n\n/** Cast u8 / u16 / u32 to u32. */\nexport function u32(arr: TypedArray): Uint32Array {\n return new Uint32Array(arr.buffer, arr.byteOffset, Math.floor(arr.byteLength / 4));\n}\n\n/** Zeroize a byte array. Warning: JS provides no guarantees. */\nexport function clean(...arrays: TypedArray[]): void {\n for (let i = 0; i < arrays.length; i++) {\n arrays[i].fill(0);\n }\n}\n\n/** Create DataView of an array for easy byte-level manipulation. */\nexport function createView(arr: TypedArray): DataView {\n return new DataView(arr.buffer, arr.byteOffset, arr.byteLength);\n}\n\n/** The rotate right (circular right shift) operation for uint32 */\nexport function rotr(word: number, shift: number): number {\n return (word << (32 - shift)) | (word >>> shift);\n}\n\n/** The rotate left (circular left shift) operation for uint32 */\nexport function rotl(word: number, shift: number): number {\n return (word << shift) | ((word >>> (32 - shift)) >>> 0);\n}\n\n/** Is current platform little-endian? Most are. Big-Endian platform: IBM */\nexport const isLE: boolean = /* @__PURE__ */ (() =>\n new Uint8Array(new Uint32Array([0x11223344]).buffer)[0] === 0x44)();\n\n/** The byte swap operation for uint32 */\nexport function byteSwap(word: number): number {\n return (\n ((word << 24) & 0xff000000) |\n ((word << 8) & 0xff0000) |\n ((word >>> 8) & 0xff00) |\n ((word >>> 24) & 0xff)\n );\n}\n/** Conditionally byte swap if on a big-endian platform */\nexport const swap8IfBE: (n: number) => number = isLE\n ? (n: number) => n\n : (n: number) => byteSwap(n);\n\n/** @deprecated */\nexport const byteSwapIfBE: typeof swap8IfBE = swap8IfBE;\n/** In place byte swap for Uint32Array */\nexport function byteSwap32(arr: Uint32Array): Uint32Array {\n for (let i = 0; i < arr.length; i++) {\n arr[i] = byteSwap(arr[i]);\n }\n return arr;\n}\n\nexport const swap32IfBE: (u: Uint32Array) => Uint32Array = isLE\n ? (u: Uint32Array) => u\n : byteSwap32;\n\n// Built-in hex conversion https://caniuse.com/mdn-javascript_builtins_uint8array_fromhex\nconst hasHexBuiltin: boolean = /* @__PURE__ */ (() =>\n // @ts-ignore\n typeof Uint8Array.from([]).toHex === 'function' && typeof Uint8Array.fromHex === 'function')();\n\n// Array where index 0xf0 (240) is mapped to string 'f0'\nconst hexes = /* @__PURE__ */ Array.from({ length: 256 }, (_, i) =>\n i.toString(16).padStart(2, '0')\n);\n\n/**\n * Convert byte array to hex string. Uses built-in function, when available.\n * @example bytesToHex(Uint8Array.from([0xca, 0xfe, 0x01, 0x23])) // 'cafe0123'\n */\nexport function bytesToHex(bytes: Uint8Array): string {\n abytes(bytes);\n // @ts-ignore\n if (hasHexBuiltin) return bytes.toHex();\n // pre-caching improves the speed 6x\n let hex = '';\n for (let i = 0; i < bytes.length; i++) {\n hex += hexes[bytes[i]];\n }\n return hex;\n}\n\n// We use optimized technique to convert hex string to byte array\nconst asciis = { _0: 48, _9: 57, A: 65, F: 70, a: 97, f: 102 } as const;\nfunction asciiToBase16(ch: number): number | undefined {\n if (ch >= asciis._0 && ch <= asciis._9) return ch - asciis._0; // '2' => 50-48\n if (ch >= asciis.A && ch <= asciis.F) return ch - (asciis.A - 10); // 'B' => 66-(65-10)\n if (ch >= asciis.a && ch <= asciis.f) return ch - (asciis.a - 10); // 'b' => 98-(97-10)\n return;\n}\n\n/**\n * Convert hex string to byte array. Uses built-in function, when available.\n * @example hexToBytes('cafe0123') // Uint8Array.from([0xca, 0xfe, 0x01, 0x23])\n */\nexport function hexToBytes(hex: string): Uint8Array {\n if (typeof hex !== 'string') throw new Error('hex string expected, got ' + typeof hex);\n // @ts-ignore\n if (hasHexBuiltin) return Uint8Array.fromHex(hex);\n const hl = hex.length;\n const al = hl / 2;\n if (hl % 2) throw new Error('hex string expected, got unpadded hex of length ' + hl);\n const array = new Uint8Array(al);\n for (let ai = 0, hi = 0; ai < al; ai++, hi += 2) {\n const n1 = asciiToBase16(hex.charCodeAt(hi));\n const n2 = asciiToBase16(hex.charCodeAt(hi + 1));\n if (n1 === undefined || n2 === undefined) {\n const char = hex[hi] + hex[hi + 1];\n throw new Error('hex string expected, got non-hex character \"' + char + '\" at index ' + hi);\n }\n array[ai] = n1 * 16 + n2; // multiply first octet, e.g. 'a3' => 10*16+3 => 160 + 3 => 163\n }\n return array;\n}\n\n/**\n * There is no setImmediate in browser and setTimeout is slow.\n * Call of async fn will return Promise, which will be fullfiled only on\n * next scheduler queue processing step and this is exactly what we need.\n */\nexport const nextTick = async (): Promise<void> => {};\n\n/** Returns control to thread each 'tick' ms to avoid blocking. */\nexport async function asyncLoop(\n iters: number,\n tick: number,\n cb: (i: number) => void\n): Promise<void> {\n let ts = Date.now();\n for (let i = 0; i < iters; i++) {\n cb(i);\n // Date.now() is not monotonic, so in case if clock goes backwards we return return control too\n const diff = Date.now() - ts;\n if (diff >= 0 && diff < tick) continue;\n await nextTick();\n ts += diff;\n }\n}\n\n// Global symbols, but ts doesn't see them: https://github.com/microsoft/TypeScript/issues/31535\ndeclare const TextEncoder: any;\ndeclare const TextDecoder: any;\n\n/**\n * Converts string to bytes using UTF8 encoding.\n * @example utf8ToBytes('abc') // Uint8Array.from([97, 98, 99])\n */\nexport function utf8ToBytes(str: string): Uint8Array {\n if (typeof str !== 'string') throw new Error('string expected');\n return new Uint8Array(new TextEncoder().encode(str)); // https://bugzil.la/1681809\n}\n\n/**\n * Converts bytes to string using UTF8 encoding.\n * @example bytesToUtf8(Uint8Array.from([97, 98, 99])) // 'abc'\n */\nexport function bytesToUtf8(bytes: Uint8Array): string {\n return new TextDecoder().decode(bytes);\n}\n\n/** Accepted input of hash functions. Strings are converted to byte arrays. */\nexport type Input = string | Uint8Array;\n/**\n * Normalizes (non-hex) string or Uint8Array to Uint8Array.\n * Warning: when Uint8Array is passed, it would NOT get copied.\n * Keep in mind for future mutable operations.\n */\nexport function toBytes(data: Input): Uint8Array {\n if (typeof data === 'string') data = utf8ToBytes(data);\n abytes(data);\n return data;\n}\n\n/** KDFs can accept string or Uint8Array for user convenience. */\nexport type KDFInput = string | Uint8Array;\n/**\n * Helper for KDFs: consumes uint8array or string.\n * When string is passed, does utf8 decoding, using TextDecoder.\n */\nexport function kdfInputToBytes(data: KDFInput): Uint8Array {\n if (typeof data === 'string') data = utf8ToBytes(data);\n abytes(data);\n return data;\n}\n\n/** Copies several Uint8Arrays into one. */\nexport function concatBytes(...arrays: Uint8Array[]): Uint8Array {\n let sum = 0;\n for (let i = 0; i < arrays.length; i++) {\n const a = arrays[i];\n abytes(a);\n sum += a.length;\n }\n const res = new Uint8Array(sum);\n for (let i = 0, pad = 0; i < arrays.length; i++) {\n const a = arrays[i];\n res.set(a, pad);\n pad += a.length;\n }\n return res;\n}\n\ntype EmptyObj = {};\nexport function checkOpts<T1 extends EmptyObj, T2 extends EmptyObj>(\n defaults: T1,\n opts?: T2\n): T1 & T2 {\n if (opts !== undefined && {}.toString.call(opts) !== '[object Object]')\n throw new Error('options should be object or undefined');\n const merged = Object.assign(defaults, opts);\n return merged as T1 & T2;\n}\n\n/** Hash interface. */\nexport type IHash = {\n (data: Uint8Array): Uint8Array;\n blockLen: number;\n outputLen: number;\n create: any;\n};\n\n/** For runtime check if class implements interface */\nexport abstract class Hash<T extends Hash<T>> {\n abstract blockLen: number; // Bytes per block\n abstract outputLen: number; // Bytes in output\n abstract update(buf: Input): this;\n // Writes digest into buf\n abstract digestInto(buf: Uint8Array): void;\n abstract digest(): Uint8Array;\n /**\n * Resets internal state. Makes Hash instance unusable.\n * Reset is impossible for keyed hashes if key is consumed into state. If digest is not consumed\n * by user, they will need to manually call `destroy()` when zeroing is necessary.\n */\n abstract destroy(): void;\n /**\n * Clones hash instance. Unsafe: doesn't check whether `to` is valid. Can be used as `clone()`\n * when no options are passed.\n * Reasons to use `_cloneInto` instead of clone: 1) performance 2) reuse instance => all internal\n * buffers are overwritten => causes buffer overwrite which is used for digest in some cases.\n * There are no guarantees for clean-up because it's impossible in JS.\n */\n abstract _cloneInto(to?: T): T;\n // Safe version that clones internal state\n abstract clone(): T;\n}\n\n/**\n * XOF: streaming API to read digest in chunks.\n * Same as 'squeeze' in keccak/k12 and 'seek' in blake3, but more generic name.\n * When hash used in XOF mode it is up to user to call '.destroy' afterwards, since we cannot\n * destroy state, next call can require more bytes.\n */\nexport type HashXOF<T extends Hash<T>> = Hash<T> & {\n xof(bytes: number): Uint8Array; // Read 'bytes' bytes from digest stream\n xofInto(buf: Uint8Array): Uint8Array; // read buf.length bytes from digest stream into buf\n};\n\n/** Hash function */\nexport type CHash = ReturnType<typeof createHasher>;\n/** Hash function with output */\nexport type CHashO = ReturnType<typeof createOptHasher>;\n/** XOF with output */\nexport type CHashXO = ReturnType<typeof createXOFer>;\n\n/** Wraps hash function, creating an interface on top of it */\nexport function createHasher<T extends Hash<T>>(\n hashCons: () => Hash<T>\n): {\n (msg: Input): Uint8Array;\n outputLen: number;\n blockLen: number;\n create(): Hash<T>;\n} {\n const hashC = (msg: Input): Uint8Array => hashCons().update(toBytes(msg)).digest();\n const tmp = hashCons();\n hashC.outputLen = tmp.outputLen;\n hashC.blockLen = tmp.blockLen;\n hashC.create = () => hashCons();\n return hashC;\n}\n\nexport function createOptHasher<H extends Hash<H>, T extends Object>(\n hashCons: (opts?: T) => Hash<H>\n): {\n (msg: Input, opts?: T): Uint8Array;\n outputLen: number;\n blockLen: number;\n create(opts?: T): Hash<H>;\n} {\n const hashC = (msg: Input, opts?: T): Uint8Array => hashCons(opts).update(toBytes(msg)).digest();\n const tmp = hashCons({} as T);\n hashC.outputLen = tmp.outputLen;\n hashC.blockLen = tmp.blockLen;\n hashC.create = (opts?: T) => hashCons(opts);\n return hashC;\n}\n\nexport function createXOFer<H extends HashXOF<H>, T extends Object>(\n hashCons: (opts?: T) => HashXOF<H>\n): {\n (msg: Input, opts?: T): Uint8Array;\n outputLen: number;\n blockLen: number;\n create(opts?: T): HashXOF<H>;\n} {\n const hashC = (msg: Input, opts?: T): Uint8Array => hashCons(opts).update(toBytes(msg)).digest();\n const tmp = hashCons({} as T);\n hashC.outputLen = tmp.outputLen;\n hashC.blockLen = tmp.blockLen;\n hashC.create = (opts?: T) => hashCons(opts);\n return hashC;\n}\nexport const wrapConstructor: typeof createHasher = createHasher;\nexport const wrapConstructorWithOpts: typeof createOptHasher = createOptHasher;\nexport const wrapXOFConstructorWithOpts: typeof createXOFer = createXOFer;\n\n/** Cryptographically secure PRNG. Uses internal OS-level `crypto.getRandomValues`. */\nexport function randomBytes(bytesLength = 32): Uint8Array {\n if (crypto && typeof crypto.getRandomValues === 'function') {\n return crypto.getRandomValues(new Uint8Array(bytesLength));\n }\n // Legacy Node.js compatibility\n if (crypto && typeof crypto.randomBytes === 'function') {\n return Uint8Array.from(crypto.randomBytes(bytesLength));\n }\n throw new Error('crypto.getRandomValues must be defined');\n}\n","/**\n * Internal helpers for u64. BigUint64Array is too slow as per 2025, so we implement it using Uint32Array.\n * @todo re-check https://issues.chromium.org/issues/42212588\n * @module\n */\nconst U32_MASK64 = /* @__PURE__ */ BigInt(2 ** 32 - 1);\nconst _32n = /* @__PURE__ */ BigInt(32);\n\nfunction fromBig(\n n: bigint,\n le = false\n): {\n h: number;\n l: number;\n} {\n if (le) return { h: Number(n & U32_MASK64), l: Number((n >> _32n) & U32_MASK64) };\n return { h: Number((n >> _32n) & U32_MASK64) | 0, l: Number(n & U32_MASK64) | 0 };\n}\n\nfunction split(lst: bigint[], le = false): Uint32Array[] {\n const len = lst.length;\n let Ah = new Uint32Array(len);\n let Al = new Uint32Array(len);\n for (let i = 0; i < len; i++) {\n const { h, l } = fromBig(lst[i], le);\n [Ah[i], Al[i]] = [h, l];\n }\n return [Ah, Al];\n}\n\nconst toBig = (h: number, l: number): bigint => (BigInt(h >>> 0) << _32n) | BigInt(l >>> 0);\n// for Shift in [0, 32)\nconst shrSH = (h: number, _l: number, s: number): number => h >>> s;\nconst shrSL = (h: number, l: number, s: number): number => (h << (32 - s)) | (l >>> s);\n// Right rotate for Shift in [1, 32)\nconst rotrSH = (h: number, l: number, s: number): number => (h >>> s) | (l << (32 - s));\nconst rotrSL = (h: number, l: number, s: number): number => (h << (32 - s)) | (l >>> s);\n// Right rotate for Shift in (32, 64), NOTE: 32 is special case.\nconst rotrBH = (h: number, l: number, s: number): number => (h << (64 - s)) | (l >>> (s - 32));\nconst rotrBL = (h: number, l: number, s: number): number => (h >>> (s - 32)) | (l << (64 - s));\n// Right rotate for shift===32 (just swaps l&h)\nconst rotr32H = (_h: number, l: number): number => l;\nconst rotr32L = (h: number, _l: number): number => h;\n// Left rotate for Shift in [1, 32)\nconst rotlSH = (h: number, l: number, s: number): number => (h << s) | (l >>> (32 - s));\nconst rotlSL = (h: number, l: number, s: number): number => (l << s) | (h >>> (32 - s));\n// Left rotate for Shift in (32, 64), NOTE: 32 is special case.\nconst rotlBH = (h: number, l: number, s: number): number => (l << (s - 32)) | (h >>> (64 - s));\nconst rotlBL = (h: number, l: number, s: number): number => (h << (s - 32)) | (l >>> (64 - s));\n\n// JS uses 32-bit signed integers for bitwise operations which means we cannot\n// simple take carry out of low bit sum by shift, we need to use division.\nfunction add(\n Ah: number,\n Al: number,\n Bh: number,\n Bl: number\n): {\n h: number;\n l: number;\n} {\n const l = (Al >>> 0) + (Bl >>> 0);\n return { h: (Ah + Bh + ((l / 2 ** 32) | 0)) | 0, l: l | 0 };\n}\n// Addition with more than 2 elements\nconst add3L = (Al: number, Bl: number, Cl: number): number => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0);\nconst add3H = (low: number, Ah: number, Bh: number, Ch: number): number =>\n (Ah + Bh + Ch + ((low / 2 ** 32) | 0)) | 0;\nconst add4L = (Al: number, Bl: number, Cl: number, Dl: number): number =>\n (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0);\nconst add4H = (low: number, Ah: number, Bh: number, Ch: number, Dh: number): number =>\n (Ah + Bh + Ch + Dh + ((low / 2 ** 32) | 0)) | 0;\nconst add5L = (Al: number, Bl: number, Cl: number, Dl: number, El: number): number =>\n (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0) + (El >>> 0);\nconst add5H = (low: number, Ah: number, Bh: number, Ch: number, Dh: number, Eh: number): number =>\n (Ah + Bh + Ch + Dh + Eh + ((low / 2 ** 32) | 0)) | 0;\n\n// prettier-ignore\nexport {\n add, add3H, add3L, add4H, add4L, add5H, add5L, fromBig, rotlBH, rotlBL, rotlSH, rotlSL, rotr32H, rotr32L, rotrBH, rotrBL, rotrSH, rotrSL, shrSH, shrSL, split, toBig\n};\n// prettier-ignore\nconst u64: { fromBig: typeof fromBig; split: typeof split; toBig: (h: number, l: number) => bigint; shrSH: (h: number, _l: number, s: number) => number; shrSL: (h: number, l: number, s: number) => number; rotrSH: (h: number, l: number, s: number) => number; rotrSL: (h: number, l: number, s: number) => number; rotrBH: (h: number, l: number, s: number) => number; rotrBL: (h: number, l: number, s: number) => number; rotr32H: (_h: number, l: number) => number; rotr32L: (h: number, _l: number) => number; rotlSH: (h: number, l: number, s: number) => number; rotlSL: (h: number, l: number, s: number) => number; rotlBH: (h: number, l: number, s: number) => number; rotlBL: (h: number, l: number, s: number) => number; add: typeof add; add3L: (Al: number, Bl: number, Cl: number) => number; add3H: (low: number, Ah: number, Bh: number, Ch: number) => number; add4L: (Al: number, Bl: number, Cl: number, Dl: number) => number; add4H: (low: number, Ah: number, Bh: number, Ch: number, Dh: number) => number; add5H: (low: number, Ah: number, Bh: number, Ch: number, Dh: number, Eh: number) => number; add5L: (Al: number, Bl: number, Cl: number, Dl: number, El: number) => number; } = {\n fromBig, split, toBig,\n shrSH, shrSL,\n rotrSH, rotrSL, rotrBH, rotrBL,\n rotr32H, rotr32L,\n rotlSH, rotlSL, rotlBH, rotlBL,\n add, add3L, add3H, add4L, add4H, add5H, add5L,\n};\nexport default u64;\n"],"mappings":";AAQA,YAAY,QAAQ;AACb,IAAM,SACX,MAAM,OAAO,OAAO,YAAY,eAAe,KACvC,eACJ,MAAM,OAAO,OAAO,YAAY,iBAAiB,KAC/C,KACA;;;ACCF,SAAU,QAAQ,GAAU;AAChC,SAAO,aAAa,cAAe,YAAY,OAAO,CAAC,KAAK,EAAE,YAAY,SAAS;AACrF;AAGM,SAAU,QAAQ,GAAS;AAC/B,MAAI,CAAC,OAAO,cAAc,CAAC,KAAK,IAAI;AAAG,UAAM,IAAI,MAAM,oCAAoC,CAAC;AAC9F;AAG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Id)}/code_verifier`;
91
91
  }
92
92
  async saveCodeVerifier(verifier) {
93
- await this.storage.put(this.codeVerifierKey(this.clientId), verifier);
93
+ const key = this.codeVerifierKey(this.clientId);
94
+ const existing = await this.storage.get(key);
95
+ if (existing) {
96
+ return;
97
+ }
98
+ await this.storage.put(key, verifier);
94
99
  }
95
100
  async codeVerifier() {
96
101
  const codeVerifier = await this.storage.get(
@@ -106,4 +111,4 @@ var DurableObjectOAuthClientProvider = class {
106
111
  export {
107
112
  DurableObjectOAuthClientProvider
108
113
  };
109
- //# sourceMappingURL=chunk-LL2AFX7V.js.map
114
+ //# sourceMappingURL=chunk-Z44WASMA.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/mcp/do-oauth-client-provider.ts"],"sourcesContent":["import type { OAuthClientProvider } from \"@modelcontextprotocol/sdk/client/auth.js\";\nimport type {\n OAuthClientInformation,\n OAuthClientInformationFull,\n OAuthClientMetadata,\n OAuthTokens\n} from \"@modelcontextprotocol/sdk/shared/auth.js\";\n\n// A slight extension to the standard OAuthClientProvider interface because `redirectToAuthorization` doesn't give us the interface we need\n// This allows us to track authentication for a specific server and associated dynamic client registration\nexport interface AgentsOAuthProvider extends OAuthClientProvider {\n authUrl: string | undefined;\n clientId: string | undefined;\n serverId: string | undefined;\n}\n\nexport class DurableObjectOAuthClientProvider implements AgentsOAuthProvider {\n private _authUrl_: string | undefined;\n private _serverId_: string | undefined;\n private _clientId_: string | undefined;\n\n constructor(\n public storage: DurableObjectStorage,\n public clientName: string,\n public baseRedirectUrl: string\n ) {}\n\n get clientMetadata(): OAuthClientMetadata {\n return {\n client_name: this.clientName,\n client_uri: this.clientUri,\n grant_types: [\"authorization_code\", \"refresh_token\"],\n redirect_uris: [this.redirectUrl],\n response_types: [\"code\"],\n token_endpoint_auth_method: \"none\"\n };\n }\n\n get clientUri() {\n return new URL(this.redirectUrl).origin;\n }\n\n get redirectUrl() {\n return `${this.baseRedirectUrl}/${this.serverId}`;\n }\n\n get clientId() {\n if (!this._clientId_) {\n throw new Error(\"Trying to access clientId before it was set\");\n }\n return this._clientId_;\n }\n\n set clientId(clientId_: string) {\n this._clientId_ = clientId_;\n }\n\n get serverId() {\n if (!this._serverId_) {\n throw new Error(\"Trying to access serverId before it was set\");\n }\n return this._serverId_;\n }\n\n set serverId(serverId_: string) {\n this._serverId_ = serverId_;\n }\n\n keyPrefix(clientId: string) {\n return `/${this.clientName}/${this.serverId}/${clientId}`;\n }\n\n clientInfoKey(clientId: string) {\n return `${this.keyPrefix(clientId)}/client_info/`;\n }\n\n async clientInformation(): Promise<OAuthClientInformation | undefined> {\n if (!this._clientId_) {\n return undefined;\n }\n return (\n (await this.storage.get<OAuthClientInformation>(\n this.clientInfoKey(this.clientId)\n )) ?? undefined\n );\n }\n\n async saveClientInformation(\n clientInformation: OAuthClientInformationFull\n ): Promise<void> {\n await this.storage.put(\n this.clientInfoKey(clientInformation.client_id),\n clientInformation\n );\n this.clientId = clientInformation.client_id;\n }\n\n tokenKey(clientId: string) {\n return `${this.keyPrefix(clientId)}/token`;\n }\n\n async tokens(): Promise<OAuthTokens | undefined> {\n if (!this._clientId_) {\n return undefined;\n }\n return (\n (await this.storage.get<OAuthTokens>(this.tokenKey(this.clientId))) ??\n undefined\n );\n }\n\n async saveTokens(tokens: OAuthTokens): Promise<void> {\n await this.storage.put(this.tokenKey(this.clientId), tokens);\n }\n\n get authUrl() {\n return this._authUrl_;\n }\n\n /**\n * Because this operates on the server side (but we need browser auth), we send this url back to the user\n * and require user interact to initiate the redirect flow\n */\n async redirectToAuthorization(authUrl: URL): Promise<void> {\n // We want to track the client ID in state here because the typescript SSE client sometimes does\n // a dynamic client registration AFTER generating this redirect URL.\n const client_id = authUrl.searchParams.get(\"client_id\");\n if (client_id) {\n authUrl.searchParams.append(\"state\", client_id);\n }\n this._authUrl_ = authUrl.toString();\n }\n\n codeVerifierKey(clientId: string) {\n return `${this.keyPrefix(clientId)}/code_verifier`;\n }\n\n async saveCodeVerifier(verifier: string): Promise<void> {\n await this.storage.put(this.codeVerifierKey(this.clientId), verifier);\n }\n\n async codeVerifier(): Promise<string> {\n const codeVerifier = await this.storage.get<string>(\n this.codeVerifierKey(this.clientId)\n );\n if (!codeVerifier) {\n throw new Error(\"No code verifier found\");\n }\n return codeVerifier;\n }\n}\n"],"mappings":";AAgBO,IAAM,mCAAN,MAAsE;AAAA,EAK3E,YACS,SACA,YACA,iBACP;AAHO;AACA;AACA;AAAA,EACN;AAAA,EAEH,IAAI,iBAAsC;AACxC,WAAO;AAAA,MACL,aAAa,KAAK;AAAA,MAClB,YAAY,KAAK;AAAA,MACjB,aAAa,CAAC,sBAAsB,eAAe;AAAA,MACnD,eAAe,CAAC,KAAK,WAAW;AAAA,MAChC,gBAAgB,CAAC,MAAM;AAAA,MACvB,4BAA4B;AAAA,IAC9B;AAAA,EACF;AAAA,EAEA,IAAI,YAAY;AACd,WAAO,IAAI,IAAI,KAAK,WAAW,EAAE;AAAA,EACnC;AAAA,EAEA,IAAI,cAAc;AAChB,WAAO,GAAG,KAAK,eAAe,IAAI,KAAK,QAAQ;AAAA,EACjD;AAAA,EAEA,IAAI,WAAW;AACb,QAAI,CAAC,KAAK,YAAY;AACpB,YAAM,IAAI,MAAM,6CAA6C;AAAA,IAC/D;AACA,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,IAAI,SAAS,WAAmB;AAC9B,SAAK,aAAa;AAAA,EACpB;AAAA,EAEA,IAAI,WAAW;AACb,QAAI,CAAC,KAAK,YAAY;AACpB,YAAM,IAAI,MAAM,6CAA6C;AAAA,IAC/D;AACA,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,IAAI,SAAS,WAAmB;AAC9B,SAAK,aAAa;AAAA,EACpB;AAAA,EAEA,UAAU,UAAkB;AAC1B,WAAO,IAAI,KAAK,UAAU,IAAI,KAAK,QAAQ,IAAI,QAAQ;AAAA,EACzD;AAAA,EAEA,cAAc,UAAkB;AAC9B,WAAO,GAAG,KAAK,UAAU,QAAQ,CAAC;A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A,MACtC,KAAK,gBAAgB,KAAK,QAAQ;AAAA,IACpC;AACA,QAAI,CAAC,cAAc;AACjB,YAAM,IAAI,MAAM,wBAAwB;AAAA,IAC1C;AACA,WAAO;AAAA,EACT;AACF;","names":[]}
1
+ {"version":3,"sources":["../src/mcp/do-oauth-client-provider.ts"],"sourcesContent":["import type { OAuthClientProvider } from \"@modelcontextprotocol/sdk/client/auth.js\";\nimport type {\n OAuthClientInformation,\n OAuthClientInformationFull,\n OAuthClientMetadata,\n OAuthTokens\n} from \"@modelcontextprotocol/sdk/shared/auth.js\";\n\n// A slight extension to the standard OAuthClientProvider interface because `redirectToAuthorization` doesn't give us the interface we need\n// This allows us to track authentication for a specific server and associated dynamic client registration\nexport interface AgentsOAuthProvider extends OAuthClientProvider {\n authUrl: string | undefined;\n clientId: string | undefined;\n serverId: string | undefined;\n}\n\nexport class DurableObjectOAuthClientProvider implements AgentsOAuthProvider {\n private _authUrl_: string | undefined;\n private _serverId_: string | undefined;\n private _clientId_: string | undefined;\n\n constructor(\n public storage: DurableObjectStorage,\n public clientName: string,\n public baseRedirectUrl: string\n ) {}\n\n get clientMetadata(): OAuthClientMetadata {\n return {\n client_name: this.clientName,\n client_uri: this.clientUri,\n grant_types: [\"authorization_code\", \"refresh_token\"],\n redirect_uris: [this.redirectUrl],\n response_types: [\"code\"],\n token_endpoint_auth_method: \"none\"\n };\n }\n\n get clientUri() {\n return new URL(this.redirectUrl).origin;\n }\n\n get redirectUrl() {\n return `${this.baseRedirectUrl}/${this.serverId}`;\n }\n\n get clientId() {\n if (!this._clientId_) {\n throw new Error(\"Trying to access clientId before it was set\");\n }\n return this._clientId_;\n }\n\n set clientId(clientId_: string) {\n this._clientId_ = clientId_;\n }\n\n get serverId() {\n if (!this._serverId_) {\n throw new Error(\"Trying to access serverId before it was set\");\n }\n return this._serverId_;\n }\n\n set serverId(serverId_: string) {\n this._serverId_ = serverId_;\n }\n\n keyPrefix(clientId: string) {\n return `/${this.clientName}/${this.serverId}/${clientId}`;\n }\n\n clientInfoKey(clientId: string) {\n return `${this.keyPrefix(clientId)}/client_info/`;\n }\n\n async clientInformation(): Promise<OAuthClientInformation | undefined> {\n if (!this._clientId_) {\n return undefined;\n }\n return (\n (await this.storage.get<OAuthClientInformation>(\n this.clientInfoKey(this.clientId)\n )) ?? undefined\n );\n }\n\n async saveClientInformation(\n clientInformation: OAuthClientInformationFull\n ): Promise<void> {\n await this.storage.put(\n this.clientInfoKey(clientInformation.client_id),\n clientInformation\n );\n this.clientId = clientInformation.client_id;\n }\n\n tokenKey(clientId: string) {\n return `${this.keyPrefix(clientId)}/token`;\n }\n\n async tokens(): Promise<OAuthTokens | undefined> {\n if (!this._clientId_) {\n return undefined;\n }\n return (\n (await this.storage.get<OAuthTokens>(this.tokenKey(this.clientId))) ??\n undefined\n );\n }\n\n async saveTokens(tokens: OAuthTokens): Promise<void> {\n await this.storage.put(this.tokenKey(this.clientId), tokens);\n }\n\n get authUrl() {\n return this._authUrl_;\n }\n\n /**\n * Because this operates on the server side (but we need browser auth), we send this url back to the user\n * and require user interact to initiate the redirect flow\n */\n async redirectToAuthorization(authUrl: URL): Promise<void> {\n // We want to track the client ID in state here because the typescript SSE client sometimes does\n // a dynamic client registration AFTER generating this redirect URL.\n const client_id = authUrl.searchParams.get(\"client_id\");\n if (client_id) {\n authUrl.searchParams.append(\"state\", client_id);\n }\n this._authUrl_ = authUrl.toString();\n }\n\n codeVerifierKey(clientId: string) {\n return `${this.keyPrefix(clientId)}/code_verifier`;\n }\n\n async saveCodeVerifier(verifier: string): Promise<void> {\n const key = this.codeVerifierKey(this.clientId);\n\n // Don't overwrite existing verifier to preserve first PKCE verifier\n const existing = await this.storage.get<string>(key);\n if (existing) {\n return;\n }\n\n await this.storage.put(key, verifier);\n }\n\n async codeVerifier(): Promise<string> {\n const codeVerifier = await this.storage.get<string>(\n this.codeVerifierKey(this.clientId)\n );\n if (!codeVerifier) {\n throw new Error(\"No code verifier found\");\n }\n return codeVerifier;\n }\n}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AM,IAAI,MAAM,wBAAwB;AAAA,IAC1C;AACA,WAAO;AAAA,EACT;AACF;","names":[]}
@@ -16,6 +16,7 @@ import {
16
16
  GetPromptRequest
17
17
  } from "@modelcontextprotocol/sdk/types.js";
18
18
  import { ToolSet } from "ai";
19
+ import { M as MCPObservabilityEvent } from "./mcp-BH1fJeiU.js";
19
20
  import {
20
21
  SSEClientTransport,
21
22
  SSEClientTransportOptions
@@ -26,6 +27,11 @@ import {
26
27
  } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
27
28
  import { AgentsOAuthProvider } from "./mcp/do-oauth-client-provider.js";
28
29
 
30
+ interface Disposable {
31
+ dispose(): void;
32
+ }
33
+ type Event<T> = (listener: (e: T) => void) => Disposable;
34
+
29
35
  declare class SSEEdgeClientTransport extends SSEClientTransport {
30
36
  private authProvider;
31
37
  /**
@@ -54,14 +60,38 @@ declare class StreamableHTTPEdgeClientTransport extends StreamableHTTPClientTran
54
60
  >;
55
61
  }
56
62
 
63
+ type MaybePromise<T> = T | Promise<T>;
64
+ type BaseTransportType = "sse" | "streamable-http";
65
+ type TransportType = BaseTransportType | "auto";
66
+ interface CORSOptions {
67
+ origin?: string;
68
+ methods?: string;
69
+ headers?: string;
70
+ maxAge?: number;
71
+ exposeHeaders?: string;
72
+ }
73
+ interface ServeOptions {
74
+ binding?: string;
75
+ corsOptions?: CORSOptions;
76
+ transport?: BaseTransportType;
77
+ }
78
+
79
+ /**
80
+ * Connection state for MCP client connections
81
+ */
82
+ type MCPConnectionState =
83
+ | "authenticating"
84
+ | "connecting"
85
+ | "ready"
86
+ | "discovering"
87
+ | "failed";
57
88
  type MCPTransportOptions = (
58
89
  | SSEClientTransportOptions
59
90
  | StreamableHTTPClientTransportOptions
60
91
  ) & {
61
92
  authProvider?: AgentsOAuthProvider;
62
- type?: "sse" | "streamable-http" | "auto";
93
+ type?: TransportType;
63
94
  };
64
- type TransportType = Exclude<MCPTransportOptions["type"], "auto">;
65
95
  declare class MCPClientConnection {
66
96
  url: URL;
67
97
  options: {
@@ -69,18 +99,16 @@ declare class MCPClientConnection {
69
99
  client: ConstructorParameters<typeof Client>[1];
70
100
  };
71
101
  client: Client;
72
- connectionState:
73
- | "authenticating"
74
- | "connecting"
75
- | "ready"
76
- | "discovering"
77
- | "failed";
102
+ connectionState: MCPConnectionState;
103
+ lastConnectedTransport: BaseTransportType | undefined;
78
104
  instructions?: string;
79
105
  tools: Tool[];
80
106
  prompts: Prompt[];
81
107
  resources: Resource[];
82
108
  resourceTemplates: ResourceTemplate[];
83
109
  serverCapabilities: ServerCapabilities | undefined;
110
+ private readonly _onObservabilityEvent;
111
+ readonly onObservabilityEvent: Event<MCPObservabilityEvent>;
84
112
  constructor(
85
113
  url: URL,
86
114
  info: ConstructorParameters<typeof Client>[0],
@@ -92,10 +120,27 @@ declare class MCPClientConnection {
92
120
  /**
93
121
  * Initialize a client connection
94
122
  *
95
- * @param code Optional OAuth code to initialize the connection with if auth hasn't been initialized
96
123
  * @returns
97
124
  */
98
- init(code?: string): Promise<void>;
125
+ init(): Promise<void>;
126
+ /**
127
+ * Finish OAuth by probing transports based on configured type.
128
+ * - Explicit: finish on that transport
129
+ * - Auto: try streamable-http, then sse on 404/405/Not Implemented
130
+ */
131
+ private finishAuthProbe;
132
+ /**
133
+ * Complete OAuth authorization
134
+ */
135
+ completeAuthorization(code: string): Promise<void>;
136
+ /**
137
+ * Establish connection after successful authorization
138
+ */
139
+ establishConnection(): Promise<void>;
140
+ /**
141
+ * Discover server capabilities and register tools, resources, prompts, and templates
142
+ */
143
+ private discoverAndRegister;
99
144
  /**
100
145
  * Notification handler registration
101
146
  */
@@ -130,12 +175,12 @@ declare class MCPClientConnection {
130
175
  }
131
176
  | undefined;
132
177
  description?: string | undefined;
178
+ title?: string | undefined;
133
179
  _meta?:
134
180
  | {
135
181
  [x: string]: unknown;
136
182
  }
137
183
  | undefined;
138
- title?: string | undefined;
139
184
  annotations?:
140
185
  | {
141
186
  [x: string]: unknown;
@@ -162,12 +207,12 @@ declare class MCPClientConnection {
162
207
  name: string;
163
208
  uri: string;
164
209
  description?: string | undefined;
210
+ title?: string | undefined;
165
211
  _meta?:
166
212
  | {
167
213
  [x: string]: unknown;
168
214
  }
169
215
  | undefined;
170
- title?: string | undefined;
171
216
  icons?:
172
217
  | {
173
218
  [x: string]: unknown;
@@ -184,12 +229,12 @@ declare class MCPClientConnection {
184
229
  [x: string]: unknown;
185
230
  name: string;
186
231
  description?: string | undefined;
232
+ title?: string | undefined;
187
233
  _meta?:
188
234
  | {
189
235
  [x: string]: unknown;
190
236
  }
191
237
  | undefined;
192
- title?: string | undefined;
193
238
  icons?:
194
239
  | {
195
240
  [x: string]: unknown;
@@ -214,12 +259,12 @@ declare class MCPClientConnection {
214
259
  name: string;
215
260
  uriTemplate: string;
216
261
  description?: string | undefined;
262
+ title?: string | undefined;
217
263
  _meta?:
218
264
  | {
219
265
  [x: string]: unknown;
220
266
  }
221
267
  | undefined;
222
- title?: string | undefined;
223
268
  mimeType?: string | undefined;
224
269
  }[]
225
270
  >;
@@ -234,14 +279,22 @@ declare class MCPClientConnection {
234
279
  * @returns The transport for the client
235
280
  */
236
281
  getTransport(
237
- transportType: TransportType
282
+ transportType: BaseTransportType
238
283
  ): SSEEdgeClientTransport | StreamableHTTPEdgeClientTransport;
239
- tryConnect(
240
- transportType: MCPTransportOptions["type"],
241
- code?: string
242
- ): Promise<void>;
284
+ private tryConnect;
285
+ private _capabilityErrorHandler;
243
286
  }
244
287
 
288
+ type MCPClientOAuthCallbackConfig = {
289
+ successRedirect?: string;
290
+ errorRedirect?: string;
291
+ customHandler?: (result: MCPClientOAuthResult) => Response;
292
+ };
293
+ type MCPClientOAuthResult = {
294
+ serverId: string;
295
+ authSuccess: boolean;
296
+ authError?: string;
297
+ };
245
298
  /**
246
299
  * Utility class that aggregates multiple MCP clients into one
247
300
  */
@@ -251,6 +304,12 @@ declare class MCPClientManager {
251
304
  mcpConnections: Record<string, MCPClientConnection>;
252
305
  private _callbackUrls;
253
306
  private _didWarnAboutUnstableGetAITools;
307
+ private _oauthCallbackConfig?;
308
+ private _connectionDisposables;
309
+ private readonly _onObservabilityEvent;
310
+ readonly onObservabilityEvent: Event<MCPObservabilityEvent>;
311
+ private readonly _onConnected;
312
+ readonly onConnected: Event<string>;
254
313
  /**
255
314
  * @param _name Name of the MCP client
256
315
  * @param _version Version of the MCP Client
@@ -281,9 +340,44 @@ declare class MCPClientManager {
281
340
  clientId?: string;
282
341
  }>;
283
342
  isCallbackRequest(req: Request): boolean;
284
- handleCallbackRequest(req: Request): Promise<{
285
- serverId: string;
286
- }>;
343
+ handleCallbackRequest(req: Request): Promise<
344
+ | {
345
+ serverId: string;
346
+ authSuccess: boolean;
347
+ authError?: undefined;
348
+ }
349
+ | {
350
+ serverId: string;
351
+ authSuccess: boolean;
352
+ authError: string;
353
+ }
354
+ >;
355
+ /**
356
+ * Establish connection in the background after OAuth completion
357
+ * This method is called asynchronously and doesn't block the OAuth callback response
358
+ * @param serverId The server ID to establish connection for
359
+ */
360
+ establishConnection(serverId: string): Promise<void>;
361
+ /**
362
+ * Register a callback URL for OAuth handling
363
+ * @param url The callback URL to register
364
+ */
365
+ registerCallbackUrl(url: string): void;
366
+ /**
367
+ * Unregister a callback URL
368
+ * @param serverId The server ID whose callback URL should be removed
369
+ */
370
+ unregisterCallbackUrl(serverId: string): void;
371
+ /**
372
+ * Configure OAuth callback handling
373
+ * @param config OAuth callback configuration
374
+ */
375
+ configureOAuthCallback(config: MCPClientOAuthCallbackConfig): void;
376
+ /**
377
+ * Get the current OAuth callback configuration
378
+ * @returns The current OAuth callback configuration
379
+ */
380
+ getOAuthCallbackConfig(): MCPClientOAuthCallbackConfig | undefined;
287
381
  /**
288
382
  * @returns namespaced list of tools
289
383
  */
@@ -300,12 +394,16 @@ declare class MCPClientManager {
300
394
  /**
301
395
  * Closes all connections to MCP servers
302
396
  */
303
- closeAllConnections(): Promise<void[]>;
397
+ closeAllConnections(): Promise<void>;
304
398
  /**
305
399
  * Closes a connection to an MCP server
306
400
  * @param id The id of the connection to close
307
401
  */
308
402
  closeConnection(id: string): Promise<void>;
403
+ /**
404
+ * Dispose the manager and all resources.
405
+ */
406
+ dispose(): Promise<void>;
309
407
  /**
310
408
  * @returns namespaced list of prompts
311
409
  */
@@ -5008,8 +5106,15 @@ declare function getNamespacedData<T extends keyof NamespacedData>(
5008
5106
  ): NamespacedData[T];
5009
5107
 
5010
5108
  export {
5011
- MCPClientManager as M,
5012
- SSEEdgeClientTransport as S,
5013
- StreamableHTTPEdgeClientTransport as a,
5109
+ type BaseTransportType as B,
5110
+ type MaybePromise as M,
5111
+ type ServeOptions as S,
5112
+ type TransportType as T,
5113
+ SSEEdgeClientTransport as a,
5114
+ StreamableHTTPEdgeClientTransport as b,
5115
+ type MCPClientOAuthResult as c,
5116
+ type MCPClientOAuthCallbackConfig as d,
5117
+ MCPClientManager as e,
5118
+ type MCPConnectionState as f,
5014
5119
  getNamespacedData as g
5015
5120
  };
package/dist/client.js CHANGED
@@ -3,7 +3,8 @@ import {
3
3
  agentFetch,
4
4
  camelCaseToKebabCase
5
5
  } from "./chunk-QEVM4BVL.js";
6
- import "./chunk-AVYJQSLW.js";
6
+ import "./chunk-BER7KXUJ.js";
7
+ import "./chunk-PR4QN5HX.js";
7
8
  export {
8
9
  AgentClient,
9
10
  agentFetch,
@@ -0,0 +1,25 @@
1
+ import { ToolSet } from 'ai';
2
+ import { WorkerEntrypoint } from 'cloudflare:workers';
3
+
4
+ declare class CodeModeProxy extends WorkerEntrypoint<Cloudflare.Env, {
5
+ binding: string;
6
+ name: string;
7
+ callback: string;
8
+ }> {
9
+ callFunction(options: {
10
+ functionName: string;
11
+ args: unknown[];
12
+ }): Promise<any>;
13
+ }
14
+ declare function experimental_codemode(options: {
15
+ tools: ToolSet;
16
+ prompt: string;
17
+ globalOutbound: Fetcher;
18
+ loader: WorkerLoader;
19
+ proxy: Fetcher<CodeModeProxy>;
20
+ }): Promise<{
21
+ prompt: string;
22
+ tools: ToolSet;
23
+ }>;
24
+
25
+ export { CodeModeProxy, experimental_codemode };