@sly_ai/sdk 0.1.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.
- package/README.md +346 -0
- package/dist/a2a.d.mts +108 -0
- package/dist/a2a.d.ts +108 -0
- package/dist/a2a.js +173 -0
- package/dist/a2a.js.map +1 -0
- package/dist/a2a.mjs +171 -0
- package/dist/a2a.mjs.map +1 -0
- package/dist/acp.d.mts +201 -0
- package/dist/acp.d.ts +201 -0
- package/dist/acp.js +143 -0
- package/dist/acp.js.map +1 -0
- package/dist/acp.mjs +141 -0
- package/dist/acp.mjs.map +1 -0
- package/dist/ap2.d.mts +188 -0
- package/dist/ap2.d.ts +188 -0
- package/dist/ap2.js +135 -0
- package/dist/ap2.js.map +1 -0
- package/dist/ap2.mjs +133 -0
- package/dist/ap2.mjs.map +1 -0
- package/dist/cards.d.mts +750 -0
- package/dist/cards.d.ts +750 -0
- package/dist/cards.js +373 -0
- package/dist/cards.js.map +1 -0
- package/dist/cards.mjs +369 -0
- package/dist/cards.mjs.map +1 -0
- package/dist/client-Cwe2CLU7.d.mts +41 -0
- package/dist/client-CyJe3uWO.d.ts +41 -0
- package/dist/index.d.mts +662 -0
- package/dist/index.d.ts +662 -0
- package/dist/index.js +2709 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +2700 -0
- package/dist/index.mjs.map +1 -0
- package/dist/langchain.d.mts +11 -0
- package/dist/langchain.d.ts +11 -0
- package/dist/langchain.js +25 -0
- package/dist/langchain.js.map +1 -0
- package/dist/langchain.mjs +23 -0
- package/dist/langchain.mjs.map +1 -0
- package/dist/types-df1EICn_.d.mts +165 -0
- package/dist/types-df1EICn_.d.ts +165 -0
- package/dist/ucp.d.mts +844 -0
- package/dist/ucp.d.ts +844 -0
- package/dist/ucp.js +616 -0
- package/dist/ucp.js.map +1 -0
- package/dist/ucp.mjs +614 -0
- package/dist/ucp.mjs.map +1 -0
- package/dist/vercel.d.mts +178 -0
- package/dist/vercel.d.ts +178 -0
- package/dist/vercel.js +143 -0
- package/dist/vercel.js.map +1 -0
- package/dist/vercel.mjs +138 -0
- package/dist/vercel.mjs.map +1 -0
- package/dist/x402.d.mts +209 -0
- package/dist/x402.d.ts +209 -0
- package/dist/x402.js +476 -0
- package/dist/x402.js.map +1 -0
- package/dist/x402.mjs +471 -0
- package/dist/x402.mjs.map +1 -0
- package/package.json +118 -0
package/dist/vercel.mjs
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { tool } from 'ai';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
// src/vercel/tools.ts
|
|
5
|
+
function createSlyVercelTools(sly) {
|
|
6
|
+
return {
|
|
7
|
+
get_settlement_quote: tool({
|
|
8
|
+
description: "Get a settlement quote for cross-border payment with FX rates and fees. Use this when a user wants to know how much money will be received in another currency.",
|
|
9
|
+
parameters: z.object({
|
|
10
|
+
fromCurrency: z.enum(["USD", "BRL", "MXN", "USDC"]).describe("Source currency"),
|
|
11
|
+
toCurrency: z.enum(["USD", "BRL", "MXN", "USDC"]).describe("Destination currency"),
|
|
12
|
+
amount: z.string().describe("Amount to convert"),
|
|
13
|
+
rail: z.enum(["pix", "spei", "wire", "usdc"]).optional().describe("Settlement rail (optional)")
|
|
14
|
+
}),
|
|
15
|
+
execute: async ({ fromCurrency, toCurrency, amount, rail }) => {
|
|
16
|
+
try {
|
|
17
|
+
const quote = await sly.getSettlementQuote({
|
|
18
|
+
fromCurrency,
|
|
19
|
+
toCurrency,
|
|
20
|
+
amount,
|
|
21
|
+
rail
|
|
22
|
+
});
|
|
23
|
+
return {
|
|
24
|
+
success: true,
|
|
25
|
+
data: quote
|
|
26
|
+
};
|
|
27
|
+
} catch (error) {
|
|
28
|
+
return {
|
|
29
|
+
success: false,
|
|
30
|
+
error: error.message
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}),
|
|
35
|
+
create_settlement: tool({
|
|
36
|
+
description: "Execute a settlement using a quote ID. Use this after getting a quote to actually send the money.",
|
|
37
|
+
parameters: z.object({
|
|
38
|
+
quoteId: z.string().describe("Quote ID from get_settlement_quote"),
|
|
39
|
+
destinationAccountId: z.string().describe("Destination account ID"),
|
|
40
|
+
metadata: z.record(z.any()).optional().describe("Optional metadata")
|
|
41
|
+
}),
|
|
42
|
+
execute: async ({ quoteId, destinationAccountId, metadata }) => {
|
|
43
|
+
try {
|
|
44
|
+
const settlement = await sly.createSettlement({
|
|
45
|
+
quoteId,
|
|
46
|
+
destinationAccountId,
|
|
47
|
+
metadata
|
|
48
|
+
});
|
|
49
|
+
return {
|
|
50
|
+
success: true,
|
|
51
|
+
data: settlement
|
|
52
|
+
};
|
|
53
|
+
} catch (error) {
|
|
54
|
+
return {
|
|
55
|
+
success: false,
|
|
56
|
+
error: error.message
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}),
|
|
61
|
+
get_settlement_status: tool({
|
|
62
|
+
description: "Check the status of a settlement. Use this to track if a payment has completed.",
|
|
63
|
+
parameters: z.object({
|
|
64
|
+
settlementId: z.string().describe("Settlement ID")
|
|
65
|
+
}),
|
|
66
|
+
execute: async ({ settlementId }) => {
|
|
67
|
+
try {
|
|
68
|
+
const settlement = await sly.getSettlement(settlementId);
|
|
69
|
+
return {
|
|
70
|
+
success: true,
|
|
71
|
+
data: settlement
|
|
72
|
+
};
|
|
73
|
+
} catch (error) {
|
|
74
|
+
return {
|
|
75
|
+
success: false,
|
|
76
|
+
error: error.message
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}),
|
|
81
|
+
check_compliance: tool({
|
|
82
|
+
description: "Check if a recipient passes compliance checks before sending payment. Use this to verify a recipient is valid.",
|
|
83
|
+
parameters: z.object({
|
|
84
|
+
recipientAccountId: z.string().describe("Recipient account ID"),
|
|
85
|
+
amount: z.string().describe("Payment amount"),
|
|
86
|
+
currency: z.enum(["USD", "BRL", "MXN"]).describe("Payment currency")
|
|
87
|
+
}),
|
|
88
|
+
execute: async ({ recipientAccountId, amount, currency }) => {
|
|
89
|
+
try {
|
|
90
|
+
const result = await sly.checkCompliance({
|
|
91
|
+
recipientAccountId,
|
|
92
|
+
amount,
|
|
93
|
+
currency
|
|
94
|
+
});
|
|
95
|
+
return {
|
|
96
|
+
success: true,
|
|
97
|
+
data: result
|
|
98
|
+
};
|
|
99
|
+
} catch (error) {
|
|
100
|
+
return {
|
|
101
|
+
success: false,
|
|
102
|
+
error: error.message
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
})
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
var SLY_VERCEL_SYSTEM_PROMPT = `You are a helpful AI assistant with access to Sly payment operations.
|
|
110
|
+
|
|
111
|
+
You can help users with:
|
|
112
|
+
- Getting settlement quotes for cross-border payments (USD, BRL, MXN, USDC)
|
|
113
|
+
- Creating settlements and transfers
|
|
114
|
+
- Checking settlement status
|
|
115
|
+
- Verifying compliance for recipients
|
|
116
|
+
|
|
117
|
+
Payment rails available:
|
|
118
|
+
- Pix (Brazil): Instant settlement in ~10 seconds
|
|
119
|
+
- SPEI (Mexico): Fast settlement in ~1 minute
|
|
120
|
+
- Wire: Traditional bank transfer
|
|
121
|
+
- USDC: Stablecoin settlement on blockchain
|
|
122
|
+
|
|
123
|
+
Always:
|
|
124
|
+
1. Get a quote before creating a settlement
|
|
125
|
+
2. Check compliance for new recipients
|
|
126
|
+
3. Confirm important actions with the user
|
|
127
|
+
4. Provide clear information about exchange rates and fees
|
|
128
|
+
5. Explain the estimated settlement time
|
|
129
|
+
|
|
130
|
+
When presenting quotes:
|
|
131
|
+
- Show the exchange rate clearly
|
|
132
|
+
- Mention any fees
|
|
133
|
+
- Explain the estimated settlement time
|
|
134
|
+
- Ask for confirmation before executing`;
|
|
135
|
+
|
|
136
|
+
export { SLY_VERCEL_SYSTEM_PROMPT as PAYOS_VERCEL_SYSTEM_PROMPT, SLY_VERCEL_SYSTEM_PROMPT, createSlyVercelTools as createPayOSVercelTools, createSlyVercelTools };
|
|
137
|
+
//# sourceMappingURL=vercel.mjs.map
|
|
138
|
+
//# sourceMappingURL=vercel.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/vercel/tools.ts"],"names":[],"mappings":";;;;AAiCO,SAAS,qBAAqB,GAAA,EAAU;AAC7C,EAAA,OAAO;AAAA,IACL,sBAAsB,IAAA,CAAK;AAAA,MACzB,WAAA,EAAa,iKAAA;AAAA,MACb,UAAA,EAAY,EAAE,MAAA,CAAO;AAAA,QACnB,YAAA,EAAc,CAAA,CAAE,IAAA,CAAK,CAAC,KAAA,EAAO,KAAA,EAAO,KAAA,EAAO,MAAM,CAAC,CAAA,CAAE,QAAA,CAAS,iBAAiB,CAAA;AAAA,QAC9E,UAAA,EAAY,CAAA,CAAE,IAAA,CAAK,CAAC,KAAA,EAAO,KAAA,EAAO,KAAA,EAAO,MAAM,CAAC,CAAA,CAAE,QAAA,CAAS,sBAAsB,CAAA;AAAA,QACjF,MAAA,EAAQ,CAAA,CAAE,MAAA,EAAO,CAAE,SAAS,mBAAmB,CAAA;AAAA,QAC/C,IAAA,EAAM,CAAA,CAAE,IAAA,CAAK,CAAC,KAAA,EAAO,MAAA,EAAQ,MAAA,EAAQ,MAAM,CAAC,CAAA,CAAE,QAAA,EAAS,CAAE,SAAS,4BAA4B;AAAA,OAC/F,CAAA;AAAA,MACD,SAAS,OAAO,EAAE,cAAc,UAAA,EAAY,MAAA,EAAQ,MAAK,KAAM;AAC7D,QAAA,IAAI;AACF,UAAA,MAAM,KAAA,GAAQ,MAAM,GAAA,CAAI,kBAAA,CAAmB;AAAA,YACzC,YAAA;AAAA,YACA,UAAA;AAAA,YACA,MAAA;AAAA,YACA;AAAA,WACD,CAAA;AACD,UAAA,OAAO;AAAA,YACL,OAAA,EAAS,IAAA;AAAA,YACT,IAAA,EAAM;AAAA,WACR;AAAA,QACF,SAAS,KA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AA;AAAA;AAAA;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA,uCAAA","file":"vercel.mjs","sourcesContent":["/**\n * Vercel AI SDK Tools for Sly\n *\n * Provides Sly capabilities as Vercel AI SDK tools for use with\n * Next.js applications, streaming responses, and React hooks.\n *\n * @example\n * ```typescript\n * import { createSlyVercelTools } from '@sly/sdk/vercel';\n * import { openai } from '@ai-sdk/openai';\n * import { generateText } from 'ai';\n *\n * const sly = new Sly({ apiKey: '...', environment: 'sandbox' });\n * const tools = createSlyVercelTools(sly);\n *\n * const result = await generateText({\n * model: openai('gpt-4'),\n * prompt: 'Send $100 to Brazil via Pix',\n * tools,\n * });\n * ```\n */\n\nimport { tool } from 'ai';\nimport { z } from 'zod';\nimport type { Sly } from '../index';\n\n/**\n * Create Vercel AI SDK tools from a Sly instance\n *\n * Returns an object with tools that can be passed directly to\n * `generateText`, `streamText`, or `generateObject` from the `ai` package.\n */\nexport function createSlyVercelTools(sly: Sly) {\n return {\n get_settlement_quote: tool({\n description: 'Get a settlement quote for cross-border payment with FX rates and fees. Use this when a user wants to know how much money will be received in another currency.',\n parameters: z.object({\n fromCurrency: z.enum(['USD', 'BRL', 'MXN', 'USDC']).describe('Source currency'),\n toCurrency: z.enum(['USD', 'BRL', 'MXN', 'USDC']).describe('Destination currency'),\n amount: z.string().describe('Amount to convert'),\n rail: z.enum(['pix', 'spei', 'wire', 'usdc']).optional().describe('Settlement rail (optional)'),\n }),\n execute: async ({ fromCurrency, toCurrency, amount, rail }) => {\n try {\n const quote = await sly.getSettlementQuote({\n fromCurrency,\n toCurrency,\n amount,\n rail,\n });\n return {\n success: true,\n data: quote,\n };\n } catch (error: any) {\n return {\n success: false,\n error: error.message,\n };\n }\n },\n }),\n\n create_settlement: tool({\n description: 'Execute a settlement using a quote ID. Use this after getting a quote to actually send the money.',\n parameters: z.object({\n quoteId: z.string().describe('Quote ID from get_settlement_quote'),\n destinationAccountId: z.string().describe('Destination account ID'),\n metadata: z.record(z.any()).optional().describe('Optional metadata'),\n }),\n execute: async ({ quoteId, destinationAccountId, metadata }) => {\n try {\n const settlement = await sly.createSettlement({\n quoteId,\n destinationAccountId,\n metadata,\n });\n return {\n success: true,\n data: settlement,\n };\n } catch (error: any) {\n return {\n success: false,\n error: error.message,\n };\n }\n },\n }),\n\n get_settlement_status: tool({\n description: 'Check the status of a settlement. Use this to track if a payment has completed.',\n parameters: z.object({\n settlementId: z.string().describe('Settlement ID'),\n }),\n execute: async ({ settlementId }) => {\n try {\n const settlement = await sly.getSettlement(settlementId);\n return {\n success: true,\n data: settlement,\n };\n } catch (error: any) {\n return {\n success: false,\n error: error.message,\n };\n }\n },\n }),\n\n check_compliance: tool({\n description: 'Check if a recipient passes compliance checks before sending payment. Use this to verify a recipient is valid.',\n parameters: z.object({\n recipientAccountId: z.string().describe('Recipient account ID'),\n amount: z.string().describe('Payment amount'),\n currency: z.enum(['USD', 'BRL', 'MXN']).describe('Payment currency'),\n }),\n execute: async ({ recipientAccountId, amount, currency }) => {\n try {\n const result = await sly.checkCompliance({\n recipientAccountId,\n amount,\n currency,\n });\n return {\n success: true,\n data: result,\n };\n } catch (error: any) {\n return {\n success: false,\n error: error.message,\n };\n }\n },\n }),\n };\n}\n\n/**\n * System prompt for Vercel AI SDK agents using Sly tools\n */\nexport const SLY_VERCEL_SYSTEM_PROMPT = `You are a helpful AI assistant with access to Sly payment operations.\n\nYou can help users with:\n- Getting settlement quotes for cross-border payments (USD, BRL, MXN, USDC)\n- Creating settlements and transfers\n- Checking settlement status\n- Verifying compliance for recipients\n\nPayment rails available:\n- Pix (Brazil): Instant settlement in ~10 seconds\n- SPEI (Mexico): Fast settlement in ~1 minute\n- Wire: Traditional bank transfer\n- USDC: Stablecoin settlement on blockchain\n\nAlways:\n1. Get a quote before creating a settlement\n2. Check compliance for new recipients\n3. Confirm important actions with the user\n4. Provide clear information about exchange rates and fees\n5. Explain the estimated settlement time\n\nWhen presenting quotes:\n- Show the exchange rate clearly\n- Mention any fees\n- Explain the estimated settlement time\n- Ask for confirmation before executing`;\n\n// Backward compatibility alias\nexport { SLY_VERCEL_SYSTEM_PROMPT as PAYOS_VERCEL_SYSTEM_PROMPT };\n\n/**\n * Type for Vercel AI SDK tools\n */\nexport type SlyVercelTools = ReturnType<typeof createSlyVercelTools>;\n\n// Backward compatibility alias\nexport type PayOSVercelTools = SlyVercelTools;\n\n// Backward compatibility alias for function\nexport { createSlyVercelTools as createPayOSVercelTools };\n\n"]}
|
package/dist/x402.d.mts
ADDED
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
import { P as PayOSEnvironment, g as SlyEnvironment } from './types-df1EICn_.mjs';
|
|
2
|
+
import { RequestHandler } from 'express';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Types for x402 protocol support
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* x402 Client configuration
|
|
10
|
+
*/
|
|
11
|
+
interface X402ClientConfig {
|
|
12
|
+
/**
|
|
13
|
+
* PayOS API key
|
|
14
|
+
*/
|
|
15
|
+
apiKey: string;
|
|
16
|
+
/**
|
|
17
|
+
* Environment (sandbox, testnet, production)
|
|
18
|
+
*/
|
|
19
|
+
environment: PayOSEnvironment;
|
|
20
|
+
/**
|
|
21
|
+
* EVM private key (required for testnet/production)
|
|
22
|
+
*/
|
|
23
|
+
evmPrivateKey?: string;
|
|
24
|
+
/**
|
|
25
|
+
* Custom facilitator URL (overrides environment default)
|
|
26
|
+
*/
|
|
27
|
+
facilitatorUrl?: string;
|
|
28
|
+
/**
|
|
29
|
+
* Maximum auto-pay amount per request (default: $1)
|
|
30
|
+
*/
|
|
31
|
+
maxAutoPayAmount?: string;
|
|
32
|
+
/**
|
|
33
|
+
* Maximum daily spend limit (default: $100)
|
|
34
|
+
*/
|
|
35
|
+
maxDailySpend?: string;
|
|
36
|
+
/**
|
|
37
|
+
* Callback fired before payment is sent
|
|
38
|
+
*/
|
|
39
|
+
onPayment?: (payment: X402PaymentInfo) => void | Promise<void>;
|
|
40
|
+
/**
|
|
41
|
+
* Callback fired after settlement is confirmed
|
|
42
|
+
*/
|
|
43
|
+
onSettlement?: (settlement: X402SettlementInfo) => void | Promise<void>;
|
|
44
|
+
/**
|
|
45
|
+
* Trigger LATAM rail settlement after x402 payment
|
|
46
|
+
*/
|
|
47
|
+
settleToRail?: 'pix' | 'spei' | 'none';
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* x402 payment information
|
|
51
|
+
*/
|
|
52
|
+
interface X402PaymentInfo {
|
|
53
|
+
amount: string;
|
|
54
|
+
currency: string;
|
|
55
|
+
from: string;
|
|
56
|
+
to: string;
|
|
57
|
+
scheme: string;
|
|
58
|
+
network: string;
|
|
59
|
+
timestamp: string;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* x402 settlement information
|
|
63
|
+
*/
|
|
64
|
+
interface X402SettlementInfo {
|
|
65
|
+
transactionHash: string;
|
|
66
|
+
amount: string;
|
|
67
|
+
currency: string;
|
|
68
|
+
timestamp: string;
|
|
69
|
+
railSettlementId?: string;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Client status
|
|
73
|
+
*/
|
|
74
|
+
interface X402ClientStatus {
|
|
75
|
+
environment: PayOSEnvironment;
|
|
76
|
+
dailySpent: string;
|
|
77
|
+
dailyLimit: string;
|
|
78
|
+
walletAddress?: string;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* 402 response from server
|
|
82
|
+
*/
|
|
83
|
+
interface X402Response {
|
|
84
|
+
statusCode: 402;
|
|
85
|
+
accepts: Array<{
|
|
86
|
+
scheme: string;
|
|
87
|
+
network: string;
|
|
88
|
+
token: string;
|
|
89
|
+
amount: string;
|
|
90
|
+
facilitator: string;
|
|
91
|
+
[key: string]: unknown;
|
|
92
|
+
}>;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* x402 Client for making payments
|
|
97
|
+
*
|
|
98
|
+
* Automatically handles 402 responses by creating payments and retrying.
|
|
99
|
+
* Supports sandbox mode (no blockchain) and production mode (real EVM).
|
|
100
|
+
*/
|
|
101
|
+
declare class SlyX402Client {
|
|
102
|
+
private config;
|
|
103
|
+
private dailySpent;
|
|
104
|
+
private lastResetDate;
|
|
105
|
+
private sandboxFacilitator?;
|
|
106
|
+
constructor(config: X402ClientConfig);
|
|
107
|
+
/**
|
|
108
|
+
* Fetch a resource with automatic 402 payment handling
|
|
109
|
+
*/
|
|
110
|
+
fetch(url: string, options?: RequestInit & {
|
|
111
|
+
maxPayment?: string;
|
|
112
|
+
}): Promise<Response>;
|
|
113
|
+
/**
|
|
114
|
+
* Get client status
|
|
115
|
+
*/
|
|
116
|
+
getStatus(): X402ClientStatus;
|
|
117
|
+
/**
|
|
118
|
+
* Parse 402 response
|
|
119
|
+
*/
|
|
120
|
+
private parse402Response;
|
|
121
|
+
/**
|
|
122
|
+
* Create payment based on environment
|
|
123
|
+
*/
|
|
124
|
+
private createPayment;
|
|
125
|
+
/**
|
|
126
|
+
* Create sandbox payment (mock)
|
|
127
|
+
*/
|
|
128
|
+
private createSandboxPayment;
|
|
129
|
+
/**
|
|
130
|
+
* Create blockchain payment (real EVM)
|
|
131
|
+
*/
|
|
132
|
+
private createBlockchainPayment;
|
|
133
|
+
/**
|
|
134
|
+
* Get wallet address based on environment
|
|
135
|
+
*/
|
|
136
|
+
private getWalletAddress;
|
|
137
|
+
/**
|
|
138
|
+
* Reset daily spend if date has changed
|
|
139
|
+
*/
|
|
140
|
+
private resetDailySpendIfNeeded;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* x402 Provider configuration
|
|
145
|
+
*/
|
|
146
|
+
interface X402ProviderConfig {
|
|
147
|
+
/**
|
|
148
|
+
* Sly API key
|
|
149
|
+
*/
|
|
150
|
+
apiKey: string;
|
|
151
|
+
/**
|
|
152
|
+
* Environment (sandbox, testnet, production)
|
|
153
|
+
*/
|
|
154
|
+
environment: SlyEnvironment;
|
|
155
|
+
/**
|
|
156
|
+
* Route configuration
|
|
157
|
+
* Maps route patterns to prices
|
|
158
|
+
*/
|
|
159
|
+
routes: Record<string, {
|
|
160
|
+
price: string;
|
|
161
|
+
description?: string;
|
|
162
|
+
token?: string;
|
|
163
|
+
}>;
|
|
164
|
+
/**
|
|
165
|
+
* Custom facilitator URL (overrides environment default)
|
|
166
|
+
*/
|
|
167
|
+
facilitatorUrl?: string;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* x402 Provider for accepting payments
|
|
171
|
+
*
|
|
172
|
+
* Express middleware that returns 402 responses for protected routes
|
|
173
|
+
* and verifies payments before serving content.
|
|
174
|
+
*/
|
|
175
|
+
declare class SlyX402Provider {
|
|
176
|
+
private config;
|
|
177
|
+
private sandboxFacilitator?;
|
|
178
|
+
constructor(config: X402ProviderConfig);
|
|
179
|
+
/**
|
|
180
|
+
* Create Express middleware
|
|
181
|
+
*/
|
|
182
|
+
middleware(): RequestHandler;
|
|
183
|
+
/**
|
|
184
|
+
* Get route configuration for request
|
|
185
|
+
*/
|
|
186
|
+
private getRouteConfig;
|
|
187
|
+
/**
|
|
188
|
+
* Simple route pattern matching
|
|
189
|
+
*/
|
|
190
|
+
private matchRoute;
|
|
191
|
+
/**
|
|
192
|
+
* Return 402 Payment Required response
|
|
193
|
+
*/
|
|
194
|
+
private return402;
|
|
195
|
+
/**
|
|
196
|
+
* Verify payment
|
|
197
|
+
*/
|
|
198
|
+
private verifyPayment;
|
|
199
|
+
/**
|
|
200
|
+
* Verify sandbox payment
|
|
201
|
+
*/
|
|
202
|
+
private verifySandboxPayment;
|
|
203
|
+
/**
|
|
204
|
+
* Verify blockchain payment
|
|
205
|
+
*/
|
|
206
|
+
private verifyBlockchainPayment;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
export { SlyX402Client as PayOSX402Client, SlyX402Provider as PayOSX402Provider, SlyX402Client, SlyX402Provider, type X402ClientConfig, type X402ClientStatus, type X402PaymentInfo, type X402ProviderConfig, type X402Response, type X402SettlementInfo };
|
package/dist/x402.d.ts
ADDED
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
import { P as PayOSEnvironment, g as SlyEnvironment } from './types-df1EICn_.js';
|
|
2
|
+
import { RequestHandler } from 'express';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Types for x402 protocol support
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* x402 Client configuration
|
|
10
|
+
*/
|
|
11
|
+
interface X402ClientConfig {
|
|
12
|
+
/**
|
|
13
|
+
* PayOS API key
|
|
14
|
+
*/
|
|
15
|
+
apiKey: string;
|
|
16
|
+
/**
|
|
17
|
+
* Environment (sandbox, testnet, production)
|
|
18
|
+
*/
|
|
19
|
+
environment: PayOSEnvironment;
|
|
20
|
+
/**
|
|
21
|
+
* EVM private key (required for testnet/production)
|
|
22
|
+
*/
|
|
23
|
+
evmPrivateKey?: string;
|
|
24
|
+
/**
|
|
25
|
+
* Custom facilitator URL (overrides environment default)
|
|
26
|
+
*/
|
|
27
|
+
facilitatorUrl?: string;
|
|
28
|
+
/**
|
|
29
|
+
* Maximum auto-pay amount per request (default: $1)
|
|
30
|
+
*/
|
|
31
|
+
maxAutoPayAmount?: string;
|
|
32
|
+
/**
|
|
33
|
+
* Maximum daily spend limit (default: $100)
|
|
34
|
+
*/
|
|
35
|
+
maxDailySpend?: string;
|
|
36
|
+
/**
|
|
37
|
+
* Callback fired before payment is sent
|
|
38
|
+
*/
|
|
39
|
+
onPayment?: (payment: X402PaymentInfo) => void | Promise<void>;
|
|
40
|
+
/**
|
|
41
|
+
* Callback fired after settlement is confirmed
|
|
42
|
+
*/
|
|
43
|
+
onSettlement?: (settlement: X402SettlementInfo) => void | Promise<void>;
|
|
44
|
+
/**
|
|
45
|
+
* Trigger LATAM rail settlement after x402 payment
|
|
46
|
+
*/
|
|
47
|
+
settleToRail?: 'pix' | 'spei' | 'none';
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* x402 payment information
|
|
51
|
+
*/
|
|
52
|
+
interface X402PaymentInfo {
|
|
53
|
+
amount: string;
|
|
54
|
+
currency: string;
|
|
55
|
+
from: string;
|
|
56
|
+
to: string;
|
|
57
|
+
scheme: string;
|
|
58
|
+
network: string;
|
|
59
|
+
timestamp: string;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* x402 settlement information
|
|
63
|
+
*/
|
|
64
|
+
interface X402SettlementInfo {
|
|
65
|
+
transactionHash: string;
|
|
66
|
+
amount: string;
|
|
67
|
+
currency: string;
|
|
68
|
+
timestamp: string;
|
|
69
|
+
railSettlementId?: string;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Client status
|
|
73
|
+
*/
|
|
74
|
+
interface X402ClientStatus {
|
|
75
|
+
environment: PayOSEnvironment;
|
|
76
|
+
dailySpent: string;
|
|
77
|
+
dailyLimit: string;
|
|
78
|
+
walletAddress?: string;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* 402 response from server
|
|
82
|
+
*/
|
|
83
|
+
interface X402Response {
|
|
84
|
+
statusCode: 402;
|
|
85
|
+
accepts: Array<{
|
|
86
|
+
scheme: string;
|
|
87
|
+
network: string;
|
|
88
|
+
token: string;
|
|
89
|
+
amount: string;
|
|
90
|
+
facilitator: string;
|
|
91
|
+
[key: string]: unknown;
|
|
92
|
+
}>;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* x402 Client for making payments
|
|
97
|
+
*
|
|
98
|
+
* Automatically handles 402 responses by creating payments and retrying.
|
|
99
|
+
* Supports sandbox mode (no blockchain) and production mode (real EVM).
|
|
100
|
+
*/
|
|
101
|
+
declare class SlyX402Client {
|
|
102
|
+
private config;
|
|
103
|
+
private dailySpent;
|
|
104
|
+
private lastResetDate;
|
|
105
|
+
private sandboxFacilitator?;
|
|
106
|
+
constructor(config: X402ClientConfig);
|
|
107
|
+
/**
|
|
108
|
+
* Fetch a resource with automatic 402 payment handling
|
|
109
|
+
*/
|
|
110
|
+
fetch(url: string, options?: RequestInit & {
|
|
111
|
+
maxPayment?: string;
|
|
112
|
+
}): Promise<Response>;
|
|
113
|
+
/**
|
|
114
|
+
* Get client status
|
|
115
|
+
*/
|
|
116
|
+
getStatus(): X402ClientStatus;
|
|
117
|
+
/**
|
|
118
|
+
* Parse 402 response
|
|
119
|
+
*/
|
|
120
|
+
private parse402Response;
|
|
121
|
+
/**
|
|
122
|
+
* Create payment based on environment
|
|
123
|
+
*/
|
|
124
|
+
private createPayment;
|
|
125
|
+
/**
|
|
126
|
+
* Create sandbox payment (mock)
|
|
127
|
+
*/
|
|
128
|
+
private createSandboxPayment;
|
|
129
|
+
/**
|
|
130
|
+
* Create blockchain payment (real EVM)
|
|
131
|
+
*/
|
|
132
|
+
private createBlockchainPayment;
|
|
133
|
+
/**
|
|
134
|
+
* Get wallet address based on environment
|
|
135
|
+
*/
|
|
136
|
+
private getWalletAddress;
|
|
137
|
+
/**
|
|
138
|
+
* Reset daily spend if date has changed
|
|
139
|
+
*/
|
|
140
|
+
private resetDailySpendIfNeeded;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* x402 Provider configuration
|
|
145
|
+
*/
|
|
146
|
+
interface X402ProviderConfig {
|
|
147
|
+
/**
|
|
148
|
+
* Sly API key
|
|
149
|
+
*/
|
|
150
|
+
apiKey: string;
|
|
151
|
+
/**
|
|
152
|
+
* Environment (sandbox, testnet, production)
|
|
153
|
+
*/
|
|
154
|
+
environment: SlyEnvironment;
|
|
155
|
+
/**
|
|
156
|
+
* Route configuration
|
|
157
|
+
* Maps route patterns to prices
|
|
158
|
+
*/
|
|
159
|
+
routes: Record<string, {
|
|
160
|
+
price: string;
|
|
161
|
+
description?: string;
|
|
162
|
+
token?: string;
|
|
163
|
+
}>;
|
|
164
|
+
/**
|
|
165
|
+
* Custom facilitator URL (overrides environment default)
|
|
166
|
+
*/
|
|
167
|
+
facilitatorUrl?: string;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* x402 Provider for accepting payments
|
|
171
|
+
*
|
|
172
|
+
* Express middleware that returns 402 responses for protected routes
|
|
173
|
+
* and verifies payments before serving content.
|
|
174
|
+
*/
|
|
175
|
+
declare class SlyX402Provider {
|
|
176
|
+
private config;
|
|
177
|
+
private sandboxFacilitator?;
|
|
178
|
+
constructor(config: X402ProviderConfig);
|
|
179
|
+
/**
|
|
180
|
+
* Create Express middleware
|
|
181
|
+
*/
|
|
182
|
+
middleware(): RequestHandler;
|
|
183
|
+
/**
|
|
184
|
+
* Get route configuration for request
|
|
185
|
+
*/
|
|
186
|
+
private getRouteConfig;
|
|
187
|
+
/**
|
|
188
|
+
* Simple route pattern matching
|
|
189
|
+
*/
|
|
190
|
+
private matchRoute;
|
|
191
|
+
/**
|
|
192
|
+
* Return 402 Payment Required response
|
|
193
|
+
*/
|
|
194
|
+
private return402;
|
|
195
|
+
/**
|
|
196
|
+
* Verify payment
|
|
197
|
+
*/
|
|
198
|
+
private verifyPayment;
|
|
199
|
+
/**
|
|
200
|
+
* Verify sandbox payment
|
|
201
|
+
*/
|
|
202
|
+
private verifySandboxPayment;
|
|
203
|
+
/**
|
|
204
|
+
* Verify blockchain payment
|
|
205
|
+
*/
|
|
206
|
+
private verifyBlockchainPayment;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
export { SlyX402Client as PayOSX402Client, SlyX402Provider as PayOSX402Provider, SlyX402Client, SlyX402Provider, type X402ClientConfig, type X402ClientStatus, type X402PaymentInfo, type X402ProviderConfig, type X402Response, type X402SettlementInfo };
|