opentool 0.20.1 → 0.21.0

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.
@@ -0,0 +1,64 @@
1
+ import { Receipt } from 'mppx';
2
+ import { j as WalletFullContext, c as HexAddress } from '../types-D8s9zx-U.js';
3
+ import 'viem';
4
+ import 'viem/accounts';
5
+
6
+ declare const MPP_TEMPO_MAINNET_CHAIN_ID = 4217;
7
+ declare const MPP_TEMPO_USDCE_ADDRESS: "0x20C000000000000000000000b9537d11c60E8b50";
8
+ declare const MPP_TEMPO_PATHUSD_ADDRESS: "0x20c0000000000000000000000000000000000000";
9
+ declare const MPP_DEFAULT_TEMPO_CURRENCY: "0x20C000000000000000000000b9537d11c60E8b50";
10
+ type MppTempoChargeMode = "push" | "pull";
11
+ type MppAcceptPaymentPolicy = "always" | "same-origin" | "never" | {
12
+ origins: readonly string[];
13
+ };
14
+ interface MppTempoOptions {
15
+ /** Automatically swap through the Tempo DEX when the wallet lacks the challenged currency. */
16
+ autoSwap?: boolean | {
17
+ tokenIn?: HexAddress[];
18
+ slippage?: number;
19
+ };
20
+ /** Initial channel deposit for automatic Tempo session handling. */
21
+ deposit?: string;
22
+ /** Maximum channel deposit for automatic Tempo session handling. */
23
+ maxDeposit?: string;
24
+ /** Preferred one-time charge mode. Defaults are chosen by mppx per account type. */
25
+ mode?: MppTempoChargeMode;
26
+ }
27
+ interface MppClientOptions {
28
+ wallet: WalletFullContext;
29
+ fetch?: typeof globalThis.fetch;
30
+ /**
31
+ * mppx polyfills global fetch by default. OpenTool keeps this opt-in so callers
32
+ * can scope paid requests to a single lambda run or tool call.
33
+ */
34
+ polyfill?: boolean;
35
+ acceptPaymentPolicy?: MppAcceptPaymentPolicy;
36
+ tempo?: MppTempoOptions;
37
+ }
38
+ type MppFetch = (input: RequestInfo | URL, init?: RequestInit & {
39
+ context?: unknown;
40
+ }) => Promise<Response>;
41
+ interface MppClient {
42
+ fetch: MppFetch;
43
+ rawFetch: typeof globalThis.fetch;
44
+ createCredential(response: Response, context?: unknown): Promise<string>;
45
+ }
46
+ interface MppFetchRequest {
47
+ input: RequestInfo | URL;
48
+ init?: RequestInit;
49
+ context?: unknown;
50
+ }
51
+ interface MppFetchResult {
52
+ response: Response;
53
+ receipt: Receipt.Receipt | null;
54
+ }
55
+ interface MppCredentialResult {
56
+ authorization: string;
57
+ }
58
+ declare function createMppClient(options: MppClientOptions): MppClient;
59
+ declare function createMppFetch(options: MppClientOptions): MppFetch;
60
+ declare function createMppCredential(response: Response, options: MppClientOptions, context?: unknown): Promise<MppCredentialResult>;
61
+ declare function fetchWithMpp(request: MppFetchRequest, options: MppClientOptions): Promise<MppFetchResult>;
62
+ declare function readMppReceipt(response: Response): Receipt.Receipt | null;
63
+
64
+ export { MPP_DEFAULT_TEMPO_CURRENCY, MPP_TEMPO_MAINNET_CHAIN_ID, MPP_TEMPO_PATHUSD_ADDRESS, MPP_TEMPO_USDCE_ADDRESS, type MppAcceptPaymentPolicy, type MppClient, type MppClientOptions, type MppCredentialResult, type MppFetch, type MppFetchRequest, type MppFetchResult, type MppTempoChargeMode, type MppTempoOptions, createMppClient, createMppCredential, createMppFetch, fetchWithMpp, readMppReceipt };
@@ -0,0 +1,75 @@
1
+ import { Receipt } from 'mppx';
2
+ import { tempo, Mppx } from 'mppx/client';
3
+
4
+ // src/mpp/index.ts
5
+ var MPP_TEMPO_MAINNET_CHAIN_ID = 4217;
6
+ var MPP_TEMPO_USDCE_ADDRESS = "0x20C000000000000000000000b9537d11c60E8b50";
7
+ var MPP_TEMPO_PATHUSD_ADDRESS = "0x20c0000000000000000000000000000000000000";
8
+ var MPP_DEFAULT_TEMPO_CURRENCY = MPP_TEMPO_USDCE_ADDRESS;
9
+ function createMppClient(options) {
10
+ assertMppWallet(options.wallet);
11
+ const methods = [
12
+ tempo({
13
+ account: options.wallet.account,
14
+ getClient: ({ chainId }) => resolveWalletClient(options.wallet, chainId),
15
+ ...options.tempo?.autoSwap !== void 0 ? { autoSwap: options.tempo.autoSwap } : {},
16
+ ...options.tempo?.deposit !== void 0 ? { deposit: options.tempo.deposit } : {},
17
+ ...options.tempo?.maxDeposit !== void 0 ? { maxDeposit: options.tempo.maxDeposit } : {},
18
+ ...options.tempo?.mode !== void 0 ? { mode: options.tempo.mode } : {}
19
+ })
20
+ ];
21
+ const client = Mppx.create({
22
+ methods,
23
+ polyfill: options.polyfill ?? false,
24
+ ...options.fetch ? { fetch: options.fetch } : {},
25
+ ...options.acceptPaymentPolicy ? { acceptPaymentPolicy: options.acceptPaymentPolicy } : {}
26
+ });
27
+ return {
28
+ fetch: client.fetch,
29
+ rawFetch: client.rawFetch,
30
+ createCredential: (response, context) => client.createCredential(response, context)
31
+ };
32
+ }
33
+ function createMppFetch(options) {
34
+ return createMppClient(options).fetch;
35
+ }
36
+ async function createMppCredential(response, options, context) {
37
+ const client = createMppClient(options);
38
+ const authorization = await client.createCredential(response, context);
39
+ return { authorization };
40
+ }
41
+ async function fetchWithMpp(request, options) {
42
+ const client = createMppClient(options);
43
+ const init = request.context === void 0 ? request.init : {
44
+ ...request.init,
45
+ context: request.context
46
+ };
47
+ const response = await client.fetch(request.input, init);
48
+ return {
49
+ response,
50
+ receipt: readMppReceipt(response)
51
+ };
52
+ }
53
+ function readMppReceipt(response) {
54
+ if (!response.headers.has("Payment-Receipt")) {
55
+ return null;
56
+ }
57
+ return Receipt.fromResponse(response);
58
+ }
59
+ function assertMppWallet(wallet) {
60
+ if (!wallet.account || !wallet.walletClient) {
61
+ throw new Error("MPP payments require a signing wallet context");
62
+ }
63
+ }
64
+ function resolveWalletClient(wallet, chainId) {
65
+ if (chainId !== void 0 && wallet.chain.id !== chainId) {
66
+ throw new Error(
67
+ `MPP challenge requires chain ${chainId}, but wallet is configured for chain ${wallet.chain.id}`
68
+ );
69
+ }
70
+ return wallet.walletClient;
71
+ }
72
+
73
+ export { MPP_DEFAULT_TEMPO_CURRENCY, MPP_TEMPO_MAINNET_CHAIN_ID, MPP_TEMPO_PATHUSD_ADDRESS, MPP_TEMPO_USDCE_ADDRESS, createMppClient, createMppCredential, createMppFetch, fetchWithMpp, readMppReceipt };
74
+ //# sourceMappingURL=index.js.map
75
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/mpp/index.ts"],"names":[],"mappings":";;;;AAMO,IAAM,0BAAA,GAA6B;AACnC,IAAM,uBAAA,GACX;AACK,IAAM,yBAAA,GACX;AACK,IAAM,0BAAA,GAA6B;AA0DnC,SAAS,gBAAgB,OAAA,EAAsC;AACpE,EAAA,eAAA,CAAgB,QAAQ,MAAM,CAAA;AAE9B,EAAA,MAAM,OAAA,GAAU;AAAA,IACd,KAAA,CAAM;AAAA,MACJ,OAAA,EAAS,QAAQ,MAAA,CAAO,OAAA;AAAA,MACxB,SAAA,EAAW,CAAC,EAAE,OAAA,OAAc,mBAAA,CAAoB,OAAA,CAAQ,QAAQ,OAAO,CAAA;AAAA,MACvE,GAAI,OAAA,CAAQ,KAAA,EAAO,QAAA,KAAa,MAAA,GAAY,EAAE,QAAA,EAAU,OAAA,CAAQ,KAAA,CAAM,QAAA,EAAS,GAAI,EAAC;AAAA,MACpF,GAAI,OAAA,CAAQ,KAAA,EAAO,OAAA,KAAY,MAAA,GAAY,EAAE,OAAA,EAAS,OAAA,CAAQ,KAAA,CAAM,OAAA,EAAQ,GAAI,EAAC;AAAA,MACjF,GAAI,OAAA,CAAQ,KAAA,EAAO,UAAA,KAAe,MAAA,GAAY,EAAE,UAAA,EAAY,OAAA,CAAQ,KAAA,CAAM,UAAA,EAAW,GAAI,EAAC;AAAA,MAC1F,GAAI,OAAA,CAAQ,KAAA,EAAO,IAAA,KAAS,MAAA,GAAY,EAAE,IAAA,EAAM,OAAA,CAAQ,KAAA,CAAM,IAAA,EAAK,GAAI;AAAC,KACzE;AAAA,GACH;AAEA,EAAA,MAAM,MAAA,GAAS,KAAK,MAAA,CAAO;AAAA,IACzB,OAAA;AAAA,IACA,QA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AS,OAAA,CAAQ,GAAA,CAAI,iBAAiB,CAAA,EAAG;AAC5C,IAAA,OAAO,IAAA;AAAA,EACT;AACA,EAAA,OAAO,OAAA,CAAQ,aAAa,QAAQ,CAAA;AACtC;AAEA,SAAS,gBAAgB,MAAA,EAAiC;AACxD,EAAA,IAAI,CAAC,MAAA,CAAO,OAAA,IAAW,CAAC,OAAO,YAAA,EAAc;AAC3C,IAAA,MAAM,IAAI,MAAM,+CAA+C,CAAA;AAAA,EACjE;AACF;AAEA,SAAS,mBAAA,CAAoB,QAA2B,OAAA,EAA0B;AAChF,EAAA,IAAI,OAAA,KAAY,MAAA,IAAa,MAAA,CAAO,KAAA,CAAM,OAAO,OAAA,EAAS;AACxD,IAAA,MAAM,IAAI,KAAA;AAAA,MACR,CAAA,6BAAA,EAAgC,OAAO,CAAA,qCAAA,EAAwC,MAAA,CAAO,MAAM,EAAE,CAAA;AAAA,KAChG;AAAA,EACF;AACA,EAAA,OAAO,MAAA,CAAO,YAAA;AAChB","file":"index.js","sourcesContent":["import { Receipt } from \"mppx\";\nimport { Mppx, tempo } from \"mppx/client\";\nimport type { Account, Client } from \"viem\";\n\nimport type { HexAddress, WalletFullContext } from \"../wallet/types\";\n\nexport const MPP_TEMPO_MAINNET_CHAIN_ID = 4217;\nexport const MPP_TEMPO_USDCE_ADDRESS =\n \"0x20C000000000000000000000b9537d11c60E8b50\" as const;\nexport const MPP_TEMPO_PATHUSD_ADDRESS =\n \"0x20c0000000000000000000000000000000000000\" as const;\nexport const MPP_DEFAULT_TEMPO_CURRENCY = MPP_TEMPO_USDCE_ADDRESS;\n\nexport type MppTempoChargeMode = \"push\" | \"pull\";\nexport type MppAcceptPaymentPolicy =\n | \"always\"\n | \"same-origin\"\n | \"never\"\n | { origins: readonly string[] };\n\nexport interface MppTempoOptions {\n /** Automatically swap through the Tempo DEX when the wallet lacks the challenged currency. */\n autoSwap?: boolean | { tokenIn?: HexAddress[]; slippage?: number };\n /** Initial channel deposit for automatic Tempo session handling. */\n deposit?: string;\n /** Maximum channel deposit for automatic Tempo session handling. */\n maxDeposit?: string;\n /** Preferred one-time charge mode. Defaults are chosen by mppx per account type. */\n mode?: MppTempoChargeMode;\n}\n\nexport interface MppClientOptions {\n wallet: WalletFullContext;\n fetch?: typeof globalThis.fetch;\n /**\n * mppx polyfills global fetch by default. OpenTool keeps this opt-in so callers\n * can scope paid requests to a single lambda run or tool call.\n */\n polyfill?: boolean;\n acceptPaymentPolicy?: MppAcceptPaymentPolicy;\n tempo?: MppTempoOptions;\n}\n\nexport type MppFetch = (\n input: RequestInfo | URL,\n init?: RequestInit & { context?: unknown },\n) => Promise<Response>;\n\nexport interface MppClient {\n fetch: MppFetch;\n rawFetch: typeof globalThis.fetch;\n createCredential(response: Response, context?: unknown): Promise<string>;\n}\n\nexport interface MppFetchRequest {\n input: RequestInfo | URL;\n init?: RequestInit;\n context?: unknown;\n}\n\nexport interface MppFetchResult {\n response: Response;\n receipt: Receipt.Receipt | null;\n}\n\nexport interface MppCredentialResult {\n authorization: string;\n}\n\nexport function createMppClient(options: MppClientOptions): MppClient {\n assertMppWallet(options.wallet);\n\n const methods = [\n tempo({\n account: options.wallet.account as Account,\n getClient: ({ chainId }) => resolveWalletClient(options.wallet, chainId),\n ...(options.tempo?.autoSwap !== undefined ? { autoSwap: options.tempo.autoSwap } : {}),\n ...(options.tempo?.deposit !== undefined ? { deposit: options.tempo.deposit } : {}),\n ...(options.tempo?.maxDeposit !== undefined ? { maxDeposit: options.tempo.maxDeposit } : {}),\n ...(options.tempo?.mode !== undefined ? { mode: options.tempo.mode } : {}),\n }),\n ] as const;\n\n const client = Mppx.create({\n methods,\n polyfill: options.polyfill ?? false,\n ...(options.fetch ? { fetch: options.fetch } : {}),\n ...(options.acceptPaymentPolicy ? { acceptPaymentPolicy: options.acceptPaymentPolicy } : {}),\n });\n\n return {\n fetch: client.fetch as MppFetch,\n rawFetch: client.rawFetch,\n createCredential: (response, context) => client.createCredential(response, context as never),\n };\n}\n\nexport function createMppFetch(options: MppClientOptions): MppFetch {\n return createMppClient(options).fetch;\n}\n\nexport async function createMppCredential(\n response: Response,\n options: MppClientOptions,\n context?: unknown,\n): Promise<MppCredentialResult> {\n const client = createMppClient(options);\n const authorization = await client.createCredential(response, context as never);\n return { authorization };\n}\n\nexport async function fetchWithMpp(\n request: MppFetchRequest,\n options: MppClientOptions,\n): Promise<MppFetchResult> {\n const client = createMppClient(options);\n const init =\n request.context === undefined\n ? request.init\n : ({\n ...request.init,\n context: request.context,\n } as RequestInit & { context: unknown });\n const response = await client.fetch(request.input, init);\n return {\n response,\n receipt: readMppReceipt(response),\n };\n}\n\nexport function readMppReceipt(response: Response): Receipt.Receipt | null {\n if (!response.headers.has(\"Payment-Receipt\")) {\n return null;\n }\n return Receipt.fromResponse(response);\n}\n\nfunction assertMppWallet(wallet: WalletFullContext): void {\n if (!wallet.account || !wallet.walletClient) {\n throw new Error(\"MPP payments require a signing wallet context\");\n }\n}\n\nfunction resolveWalletClient(wallet: WalletFullContext, chainId?: number): Client {\n if (chainId !== undefined && wallet.chain.id !== chainId) {\n throw new Error(\n `MPP challenge requires chain ${chainId}, but wallet is configured for chain ${wallet.chain.id}`,\n );\n }\n return wallet.walletClient as unknown as Client;\n}\n"]}