agentmail 0.3.0 → 0.3.1

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.
@@ -43,8 +43,8 @@ function normalizeClientOptions(options) {
43
43
  const headers = (0, headers_js_1.mergeHeaders)({
44
44
  "X-Fern-Language": "JavaScript",
45
45
  "X-Fern-SDK-Name": "agentmail",
46
- "X-Fern-SDK-Version": "0.3.0",
47
- "User-Agent": "agentmail/0.3.0",
46
+ "X-Fern-SDK-Version": "0.3.1",
47
+ "User-Agent": "agentmail/0.3.1",
48
48
  "X-Fern-Runtime": core.RUNTIME.type,
49
49
  "X-Fern-Runtime-Version": core.RUNTIME.version,
50
50
  }, options === null || options === void 0 ? void 0 : options.headers);
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "0.3.0";
1
+ export declare const SDK_VERSION = "0.3.1";
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SDK_VERSION = void 0;
4
- exports.SDK_VERSION = "0.3.0";
4
+ exports.SDK_VERSION = "0.3.1";
@@ -1,21 +1,28 @@
1
1
  import type { x402Client } from "@x402/fetch";
2
- import { AgentMailClient as FernAgentMailClient } from "../Client.js";
2
+ import type { Mppx } from "mppx/client";
3
3
  import { Supplier } from "../core/index.js";
4
+ import { AgentMailClient as FernAgentMailClient } from "../Client.js";
4
5
  import { WebsocketsClient } from "./WebsocketsClient.js";
5
6
  type SharedOptions = Omit<FernAgentMailClient.Options, "apiKey">;
6
7
  export declare namespace AgentMailClient {
7
8
  type Options = SharedOptions & ({
8
9
  x402: x402Client;
10
+ mpp?: never;
11
+ apiKey?: never;
12
+ } | {
13
+ mpp: Mppx.Mppx;
14
+ x402?: never;
9
15
  apiKey?: never;
10
16
  } | {
11
17
  apiKey?: Supplier<string>;
12
18
  x402?: never;
19
+ mpp?: never;
13
20
  });
14
21
  type RequestOptions = FernAgentMailClient.RequestOptions;
15
22
  }
16
23
  export declare class AgentMailClient extends FernAgentMailClient {
17
24
  protected _websockets: WebsocketsClient | undefined;
18
- private readonly _x402Client;
25
+ private readonly _getPaymentHeaders;
19
26
  get websockets(): WebsocketsClient;
20
27
  constructor(options?: AgentMailClient.Options);
21
28
  }
@@ -54,23 +54,26 @@ var __rest = (this && this.__rest) || function (s, e) {
54
54
  };
55
55
  Object.defineProperty(exports, "__esModule", { value: true });
56
56
  exports.AgentMailClient = void 0;
57
- const Client_js_1 = require("../Client.js");
58
57
  const index_js_1 = require("../core/index.js");
58
+ const NoOpAuthProvider_js_1 = require("../core/auth/NoOpAuthProvider.js");
59
59
  const environments_js_1 = require("../environments.js");
60
+ const Client_js_1 = require("../Client.js");
60
61
  const WebsocketsClient_js_1 = require("./WebsocketsClient.js");
62
+ const x402_js_1 = require("./x402.js");
63
+ const mpp_js_1 = require("./mpp.js");
61
64
  class AgentMailClient extends Client_js_1.AgentMailClient {
62
65
  get websockets() {
63
66
  var _a;
64
- return ((_a = this._websockets) !== null && _a !== void 0 ? _a : (this._websockets = new WebsocketsClient_js_1.WebsocketsClient(this._options, this._x402Client)));
67
+ return ((_a = this._websockets) !== null && _a !== void 0 ? _a : (this._websockets = new WebsocketsClient_js_1.WebsocketsClient(this._options, this._getPaymentHeaders)));
65
68
  }
66
69
  constructor(options = {}) {
67
70
  if (options.x402) {
68
71
  const { x402 } = options, rest = __rest(options, ["x402"]);
69
72
  let wrappedFetch;
70
- const fernOptions = Object.assign(Object.assign({}, rest), { fetch: (input, init) => __awaiter(this, void 0, void 0, function* () {
73
+ const fernOptions = Object.assign(Object.assign({}, rest), { authProvider: new NoOpAuthProvider_js_1.NoOpAuthProvider(), fetch: (input, init) => __awaiter(this, void 0, void 0, function* () {
71
74
  if (!wrappedFetch) {
72
- const { wrapFetchWithPayment } = yield Promise.resolve().then(() => __importStar(require("@x402/fetch")));
73
- wrappedFetch = wrapFetchWithPayment(fetch, x402);
75
+ const mod = yield Promise.resolve().then(() => __importStar(require("@x402/fetch")));
76
+ wrappedFetch = mod.wrapFetchWithPayment(fetch, x402);
74
77
  }
75
78
  return wrappedFetch(input, init);
76
79
  }) });
@@ -78,7 +81,16 @@ class AgentMailClient extends Client_js_1.AgentMailClient {
78
81
  fernOptions.environment = environments_js_1.AgentMailEnvironment.ProdX402;
79
82
  }
80
83
  super(fernOptions);
81
- this._x402Client = x402;
84
+ this._getPaymentHeaders = (wsUrl) => (0, x402_js_1.getPaymentHeaders)(wsUrl, x402);
85
+ }
86
+ else if (options.mpp) {
87
+ const { mpp } = options, rest = __rest(options, ["mpp"]);
88
+ const fernOptions = Object.assign(Object.assign({}, rest), { authProvider: new NoOpAuthProvider_js_1.NoOpAuthProvider(), fetch: mpp.fetch });
89
+ if (!fernOptions.environment && !fernOptions.baseUrl) {
90
+ fernOptions.environment = environments_js_1.AgentMailEnvironment.ProdMpp;
91
+ }
92
+ super(fernOptions);
93
+ this._getPaymentHeaders = (wsUrl) => (0, mpp_js_1.getPaymentHeaders)(wsUrl, mpp);
82
94
  }
83
95
  else {
84
96
  let fernOptions = options;
@@ -92,7 +104,7 @@ class AgentMailClient extends Client_js_1.AgentMailClient {
92
104
  }) });
93
105
  }
94
106
  super(fernOptions);
95
- this._x402Client = undefined;
107
+ this._getPaymentHeaders = undefined;
96
108
  }
97
109
  }
98
110
  }
@@ -1,8 +1,8 @@
1
- import type { x402Client } from "@x402/fetch";
2
1
  import { WebsocketsClient as FernWebsocketsClient } from "../api/resources/websockets/client/Client.js";
3
2
  import type { WebsocketsSocket } from "../api/resources/websockets/client/Socket.js";
3
+ export type GetPaymentHeaders = (wsUrl: string) => Promise<Record<string, string>>;
4
4
  export declare class WebsocketsClient extends FernWebsocketsClient {
5
- private readonly _x402Client;
6
- constructor(options: FernWebsocketsClient.Options, x402Client?: x402Client);
5
+ private readonly _getPaymentHeaders;
6
+ constructor(options: FernWebsocketsClient.Options, getPaymentHeaders?: GetPaymentHeaders);
7
7
  connect(args?: FernWebsocketsClient.ConnectArgs): Promise<WebsocketsSocket>;
8
8
  }
@@ -46,11 +46,10 @@ exports.WebsocketsClient = void 0;
46
46
  const Client_js_1 = require("../api/resources/websockets/client/Client.js");
47
47
  const core = __importStar(require("../core/index.js"));
48
48
  const environments = __importStar(require("../environments.js"));
49
- const x402_js_1 = require("./x402.js");
50
49
  class WebsocketsClient extends Client_js_1.WebsocketsClient {
51
- constructor(options, x402Client) {
50
+ constructor(options, getPaymentHeaders) {
52
51
  super(options);
53
- this._x402Client = x402Client;
52
+ this._getPaymentHeaders = getPaymentHeaders;
54
53
  }
55
54
  connect() {
56
55
  const _super = Object.create(null, {
@@ -58,10 +57,10 @@ class WebsocketsClient extends Client_js_1.WebsocketsClient {
58
57
  });
59
58
  return __awaiter(this, arguments, void 0, function* (args = {}) {
60
59
  var _a, _b, _c;
61
- if (this._x402Client) {
60
+ if (this._getPaymentHeaders) {
62
61
  const wsUrl = core.url.join((_a = (yield core.Supplier.get(this._options.baseUrl))) !== null && _a !== void 0 ? _a : ((_b = (yield core.Supplier.get(this._options.environment))) !== null && _b !== void 0 ? _b : environments.AgentMailEnvironment.Prod)
63
62
  .websockets, "/v0");
64
- const paymentHeaders = yield (0, x402_js_1.getPaymentHeaders)(wsUrl, this._x402Client);
63
+ const paymentHeaders = yield this._getPaymentHeaders(wsUrl);
65
64
  return _super.connect.call(this, Object.assign(Object.assign({}, args), { headers: Object.assign(Object.assign({}, paymentHeaders), args.headers) }));
66
65
  }
67
66
  if (!args.apiKey) {
@@ -1,2 +1 @@
1
1
  export { AgentMailClient } from "./Client.js";
2
- export { WebsocketsClient } from "./WebsocketsClient.js";
@@ -1,7 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.WebsocketsClient = exports.AgentMailClient = void 0;
3
+ exports.AgentMailClient = void 0;
4
4
  var Client_js_1 = require("./Client.js");
5
5
  Object.defineProperty(exports, "AgentMailClient", { enumerable: true, get: function () { return Client_js_1.AgentMailClient; } });
6
- var WebsocketsClient_js_1 = require("./WebsocketsClient.js");
7
- Object.defineProperty(exports, "WebsocketsClient", { enumerable: true, get: function () { return WebsocketsClient_js_1.WebsocketsClient; } });
@@ -0,0 +1,2 @@
1
+ import type { Mppx } from "mppx/client";
2
+ export declare function getPaymentHeaders(wsUrl: string, mpp: Mppx.Mppx): Promise<Record<string, string>>;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.getPaymentHeaders = getPaymentHeaders;
13
+ const probe402_js_1 = require("./probe402.js");
14
+ function getPaymentHeaders(wsUrl, mpp) {
15
+ return __awaiter(this, void 0, void 0, function* () {
16
+ const response = yield (0, probe402_js_1.probe402)(wsUrl);
17
+ const credential = yield mpp.createCredential(response);
18
+ const signed = mpp.transport.setCredential(new Request(wsUrl), credential);
19
+ const headers = {};
20
+ signed.headers.forEach((value, key) => {
21
+ headers[key] = value;
22
+ });
23
+ return headers;
24
+ });
25
+ }
@@ -0,0 +1 @@
1
+ export declare function probe402(wsUrl: string): Promise<Response>;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.probe402 = probe402;
13
+ function probe402(wsUrl) {
14
+ return __awaiter(this, void 0, void 0, function* () {
15
+ const httpUrl = wsUrl.replace(/^wss:\/\//, "https://").replace(/^ws:\/\//, "http://");
16
+ const response = yield fetch(httpUrl);
17
+ if (response.status !== 402) {
18
+ throw new Error(`Expected 402 from ${httpUrl} but got ${response.status}`);
19
+ }
20
+ return response;
21
+ });
22
+ }
@@ -43,15 +43,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
43
43
  };
44
44
  Object.defineProperty(exports, "__esModule", { value: true });
45
45
  exports.getPaymentHeaders = getPaymentHeaders;
46
+ const probe402_js_1 = require("./probe402.js");
46
47
  function getPaymentHeaders(wsUrl, client) {
47
48
  return __awaiter(this, void 0, void 0, function* () {
48
49
  const { x402HTTPClient } = yield Promise.resolve().then(() => __importStar(require("@x402/fetch")));
49
50
  const httpClient = new x402HTTPClient(client);
50
- const httpUrl = wsUrl.replace(/^wss:\/\//, "https://").replace(/^ws:\/\//, "http://");
51
- const response = yield fetch(httpUrl);
52
- if (response.status !== 402) {
53
- throw new Error(`x402: expected 402 from ${httpUrl} but got ${response.status}`);
54
- }
51
+ const response = yield (0, probe402_js_1.probe402)(wsUrl);
55
52
  let body;
56
53
  try {
57
54
  body = JSON.parse(yield response.text());
@@ -6,8 +6,8 @@ export function normalizeClientOptions(options) {
6
6
  const headers = mergeHeaders({
7
7
  "X-Fern-Language": "JavaScript",
8
8
  "X-Fern-SDK-Name": "agentmail",
9
- "X-Fern-SDK-Version": "0.3.0",
10
- "User-Agent": "agentmail/0.3.0",
9
+ "X-Fern-SDK-Version": "0.3.1",
10
+ "User-Agent": "agentmail/0.3.1",
11
11
  "X-Fern-Runtime": core.RUNTIME.type,
12
12
  "X-Fern-Runtime-Version": core.RUNTIME.version,
13
13
  }, options === null || options === void 0 ? void 0 : options.headers);
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "0.3.0";
1
+ export declare const SDK_VERSION = "0.3.1";
@@ -1 +1 @@
1
- export const SDK_VERSION = "0.3.0";
1
+ export const SDK_VERSION = "0.3.1";
@@ -1,21 +1,28 @@
1
1
  import type { x402Client } from "@x402/fetch";
2
- import { AgentMailClient as FernAgentMailClient } from "../Client.mjs";
2
+ import type { Mppx } from "mppx/client";
3
3
  import { Supplier } from "../core/index.mjs";
4
+ import { AgentMailClient as FernAgentMailClient } from "../Client.mjs";
4
5
  import { WebsocketsClient } from "./WebsocketsClient.mjs";
5
6
  type SharedOptions = Omit<FernAgentMailClient.Options, "apiKey">;
6
7
  export declare namespace AgentMailClient {
7
8
  type Options = SharedOptions & ({
8
9
  x402: x402Client;
10
+ mpp?: never;
11
+ apiKey?: never;
12
+ } | {
13
+ mpp: Mppx.Mppx;
14
+ x402?: never;
9
15
  apiKey?: never;
10
16
  } | {
11
17
  apiKey?: Supplier<string>;
12
18
  x402?: never;
19
+ mpp?: never;
13
20
  });
14
21
  type RequestOptions = FernAgentMailClient.RequestOptions;
15
22
  }
16
23
  export declare class AgentMailClient extends FernAgentMailClient {
17
24
  protected _websockets: WebsocketsClient | undefined;
18
- private readonly _x402Client;
25
+ private readonly _getPaymentHeaders;
19
26
  get websockets(): WebsocketsClient;
20
27
  constructor(options?: AgentMailClient.Options);
21
28
  }
@@ -18,23 +18,26 @@ var __rest = (this && this.__rest) || function (s, e) {
18
18
  }
19
19
  return t;
20
20
  };
21
- import { AgentMailClient as FernAgentMailClient } from "../Client.mjs";
22
21
  import { Supplier } from "../core/index.mjs";
22
+ import { NoOpAuthProvider } from "../core/auth/NoOpAuthProvider.mjs";
23
23
  import { AgentMailEnvironment } from "../environments.mjs";
24
+ import { AgentMailClient as FernAgentMailClient } from "../Client.mjs";
24
25
  import { WebsocketsClient } from "./WebsocketsClient.mjs";
26
+ import { getPaymentHeaders as getX402PaymentHeaders } from "./x402.mjs";
27
+ import { getPaymentHeaders as getMppPaymentHeaders } from "./mpp.mjs";
25
28
  export class AgentMailClient extends FernAgentMailClient {
26
29
  get websockets() {
27
30
  var _a;
28
- return ((_a = this._websockets) !== null && _a !== void 0 ? _a : (this._websockets = new WebsocketsClient(this._options, this._x402Client)));
31
+ return ((_a = this._websockets) !== null && _a !== void 0 ? _a : (this._websockets = new WebsocketsClient(this._options, this._getPaymentHeaders)));
29
32
  }
30
33
  constructor(options = {}) {
31
34
  if (options.x402) {
32
35
  const { x402 } = options, rest = __rest(options, ["x402"]);
33
36
  let wrappedFetch;
34
- const fernOptions = Object.assign(Object.assign({}, rest), { fetch: (input, init) => __awaiter(this, void 0, void 0, function* () {
37
+ const fernOptions = Object.assign(Object.assign({}, rest), { authProvider: new NoOpAuthProvider(), fetch: (input, init) => __awaiter(this, void 0, void 0, function* () {
35
38
  if (!wrappedFetch) {
36
- const { wrapFetchWithPayment } = yield import("@x402/fetch");
37
- wrappedFetch = wrapFetchWithPayment(fetch, x402);
39
+ const mod = yield import("@x402/fetch");
40
+ wrappedFetch = mod.wrapFetchWithPayment(fetch, x402);
38
41
  }
39
42
  return wrappedFetch(input, init);
40
43
  }) });
@@ -42,7 +45,16 @@ export class AgentMailClient extends FernAgentMailClient {
42
45
  fernOptions.environment = AgentMailEnvironment.ProdX402;
43
46
  }
44
47
  super(fernOptions);
45
- this._x402Client = x402;
48
+ this._getPaymentHeaders = (wsUrl) => getX402PaymentHeaders(wsUrl, x402);
49
+ }
50
+ else if (options.mpp) {
51
+ const { mpp } = options, rest = __rest(options, ["mpp"]);
52
+ const fernOptions = Object.assign(Object.assign({}, rest), { authProvider: new NoOpAuthProvider(), fetch: mpp.fetch });
53
+ if (!fernOptions.environment && !fernOptions.baseUrl) {
54
+ fernOptions.environment = AgentMailEnvironment.ProdMpp;
55
+ }
56
+ super(fernOptions);
57
+ this._getPaymentHeaders = (wsUrl) => getMppPaymentHeaders(wsUrl, mpp);
46
58
  }
47
59
  else {
48
60
  let fernOptions = options;
@@ -56,7 +68,7 @@ export class AgentMailClient extends FernAgentMailClient {
56
68
  }) });
57
69
  }
58
70
  super(fernOptions);
59
- this._x402Client = undefined;
71
+ this._getPaymentHeaders = undefined;
60
72
  }
61
73
  }
62
74
  }
@@ -1,8 +1,8 @@
1
- import type { x402Client } from "@x402/fetch";
2
1
  import { WebsocketsClient as FernWebsocketsClient } from "../api/resources/websockets/client/Client.mjs";
3
2
  import type { WebsocketsSocket } from "../api/resources/websockets/client/Socket.mjs";
3
+ export type GetPaymentHeaders = (wsUrl: string) => Promise<Record<string, string>>;
4
4
  export declare class WebsocketsClient extends FernWebsocketsClient {
5
- private readonly _x402Client;
6
- constructor(options: FernWebsocketsClient.Options, x402Client?: x402Client);
5
+ private readonly _getPaymentHeaders;
6
+ constructor(options: FernWebsocketsClient.Options, getPaymentHeaders?: GetPaymentHeaders);
7
7
  connect(args?: FernWebsocketsClient.ConnectArgs): Promise<WebsocketsSocket>;
8
8
  }
@@ -10,11 +10,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  import { WebsocketsClient as FernWebsocketsClient } from "../api/resources/websockets/client/Client.mjs";
11
11
  import * as core from "../core/index.mjs";
12
12
  import * as environments from "../environments.mjs";
13
- import { getPaymentHeaders } from "./x402.mjs";
14
13
  export class WebsocketsClient extends FernWebsocketsClient {
15
- constructor(options, x402Client) {
14
+ constructor(options, getPaymentHeaders) {
16
15
  super(options);
17
- this._x402Client = x402Client;
16
+ this._getPaymentHeaders = getPaymentHeaders;
18
17
  }
19
18
  connect() {
20
19
  const _super = Object.create(null, {
@@ -22,10 +21,10 @@ export class WebsocketsClient extends FernWebsocketsClient {
22
21
  });
23
22
  return __awaiter(this, arguments, void 0, function* (args = {}) {
24
23
  var _a, _b, _c;
25
- if (this._x402Client) {
24
+ if (this._getPaymentHeaders) {
26
25
  const wsUrl = core.url.join((_a = (yield core.Supplier.get(this._options.baseUrl))) !== null && _a !== void 0 ? _a : ((_b = (yield core.Supplier.get(this._options.environment))) !== null && _b !== void 0 ? _b : environments.AgentMailEnvironment.Prod)
27
26
  .websockets, "/v0");
28
- const paymentHeaders = yield getPaymentHeaders(wsUrl, this._x402Client);
27
+ const paymentHeaders = yield this._getPaymentHeaders(wsUrl);
29
28
  return _super.connect.call(this, Object.assign(Object.assign({}, args), { headers: Object.assign(Object.assign({}, paymentHeaders), args.headers) }));
30
29
  }
31
30
  if (!args.apiKey) {
@@ -1,2 +1 @@
1
1
  export { AgentMailClient } from "./Client.mjs";
2
- export { WebsocketsClient } from "./WebsocketsClient.mjs";
@@ -1,2 +1 @@
1
1
  export { AgentMailClient } from "./Client.mjs";
2
- export { WebsocketsClient } from "./WebsocketsClient.mjs";
@@ -0,0 +1,2 @@
1
+ import type { Mppx } from "mppx/client";
2
+ export declare function getPaymentHeaders(wsUrl: string, mpp: Mppx.Mppx): Promise<Record<string, string>>;
@@ -0,0 +1,22 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { probe402 } from "./probe402.mjs";
11
+ export function getPaymentHeaders(wsUrl, mpp) {
12
+ return __awaiter(this, void 0, void 0, function* () {
13
+ const response = yield probe402(wsUrl);
14
+ const credential = yield mpp.createCredential(response);
15
+ const signed = mpp.transport.setCredential(new Request(wsUrl), credential);
16
+ const headers = {};
17
+ signed.headers.forEach((value, key) => {
18
+ headers[key] = value;
19
+ });
20
+ return headers;
21
+ });
22
+ }
@@ -0,0 +1 @@
1
+ export declare function probe402(wsUrl: string): Promise<Response>;
@@ -0,0 +1,19 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ export function probe402(wsUrl) {
11
+ return __awaiter(this, void 0, void 0, function* () {
12
+ const httpUrl = wsUrl.replace(/^wss:\/\//, "https://").replace(/^ws:\/\//, "http://");
13
+ const response = yield fetch(httpUrl);
14
+ if (response.status !== 402) {
15
+ throw new Error(`Expected 402 from ${httpUrl} but got ${response.status}`);
16
+ }
17
+ return response;
18
+ });
19
+ }
@@ -7,15 +7,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
+ import { probe402 } from "./probe402.mjs";
10
11
  export function getPaymentHeaders(wsUrl, client) {
11
12
  return __awaiter(this, void 0, void 0, function* () {
12
13
  const { x402HTTPClient } = yield import("@x402/fetch");
13
14
  const httpClient = new x402HTTPClient(client);
14
- const httpUrl = wsUrl.replace(/^wss:\/\//, "https://").replace(/^ws:\/\//, "http://");
15
- const response = yield fetch(httpUrl);
16
- if (response.status !== 402) {
17
- throw new Error(`x402: expected 402 from ${httpUrl} but got ${response.status}`);
18
- }
15
+ const response = yield probe402(wsUrl);
19
16
  let body;
20
17
  try {
21
18
  body = JSON.parse(yield response.text());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agentmail",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "private": false,
5
5
  "repository": {
6
6
  "type": "git",