@vinaystwt/xmpp-mcp 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/LICENSE +21 -0
- package/README.md +10 -0
- package/dist/apps/mcp-server/src/index.d.ts +2 -0
- package/dist/apps/mcp-server/src/index.js +10 -0
- package/dist/apps/mcp-server/src/server.d.ts +9 -0
- package/dist/apps/mcp-server/src/server.js +232 -0
- package/dist/packages/config/src/index.d.ts +49 -0
- package/dist/packages/config/src/index.js +117 -0
- package/dist/packages/contract-runtime/src/index.d.ts +44 -0
- package/dist/packages/contract-runtime/src/index.js +364 -0
- package/dist/packages/http-interceptor/src/agents.d.ts +5 -0
- package/dist/packages/http-interceptor/src/agents.js +88 -0
- package/dist/packages/http-interceptor/src/idempotency.d.ts +68 -0
- package/dist/packages/http-interceptor/src/idempotency.js +149 -0
- package/dist/packages/http-interceptor/src/index.d.ts +10 -0
- package/dist/packages/http-interceptor/src/index.js +870 -0
- package/dist/packages/http-interceptor/src/state.d.ts +17 -0
- package/dist/packages/http-interceptor/src/state.js +188 -0
- package/dist/packages/logger/src/index.d.ts +2 -0
- package/dist/packages/logger/src/index.js +18 -0
- package/dist/packages/payment-adapters/src/index.d.ts +27 -0
- package/dist/packages/payment-adapters/src/index.js +512 -0
- package/dist/packages/policy-engine/src/index.d.ts +8 -0
- package/dist/packages/policy-engine/src/index.js +90 -0
- package/dist/packages/router/src/index.d.ts +23 -0
- package/dist/packages/router/src/index.js +432 -0
- package/dist/packages/types/src/index.d.ts +343 -0
- package/dist/packages/types/src/index.js +1 -0
- package/dist/packages/wallet/src/index.d.ts +14 -0
- package/dist/packages/wallet/src/index.js +250 -0
- package/package.json +69 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 xMPP contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# @vinaystwt/xmpp-mcp
|
|
2
|
+
|
|
3
|
+
Installable MCP server for xMPP.
|
|
4
|
+
|
|
5
|
+
It exposes xMPP fetch, wallet, receipt, route-planning, workflow-estimation, and operator-state tools for agent clients that speak MCP over stdio.
|
|
6
|
+
|
|
7
|
+
Project documentation lives at the repo root:
|
|
8
|
+
|
|
9
|
+
- https://github.com/Vinaystwt/xMPP
|
|
10
|
+
- https://github.com/Vinaystwt/xMPP/blob/main/docs/sdk.md
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { runXmppMcpServer } from './server.js';
|
|
3
|
+
runXmppMcpServer()
|
|
4
|
+
.then(() => {
|
|
5
|
+
console.error('[xMPP] MCP server running on stdio');
|
|
6
|
+
})
|
|
7
|
+
.catch((error) => {
|
|
8
|
+
console.error('[xMPP] MCP server error', error);
|
|
9
|
+
process.exit(1);
|
|
10
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
|
+
export declare function createXmppMcpServer(options?: {
|
|
3
|
+
name?: string;
|
|
4
|
+
version?: string;
|
|
5
|
+
}): McpServer;
|
|
6
|
+
export declare function runXmppMcpServer(options?: {
|
|
7
|
+
name?: string;
|
|
8
|
+
version?: string;
|
|
9
|
+
}): Promise<McpServer>;
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
|
+
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
3
|
+
import * as z from 'zod/v4';
|
|
4
|
+
import { listAgentPolicySnapshots, listAgentSessions } from '@xmpp/contract-runtime';
|
|
5
|
+
import { getXmppMetadata, getXmppOperatorState, listLocalSessions, listEffectiveXmppAgentProfiles, xmppFetch, } from '@xmpp/http-interceptor';
|
|
6
|
+
import { createRouter } from '@xmpp/router';
|
|
7
|
+
import { getWalletInfo, verifyXmppReceipt } from '@xmpp/wallet';
|
|
8
|
+
const router = createRouter();
|
|
9
|
+
const signedReceiptSchema = z.object({
|
|
10
|
+
receiptId: z.string(),
|
|
11
|
+
issuedAt: z.string(),
|
|
12
|
+
network: z.string(),
|
|
13
|
+
agent: z.string(),
|
|
14
|
+
serviceId: z.string(),
|
|
15
|
+
url: z.url(),
|
|
16
|
+
method: z.string(),
|
|
17
|
+
route: z.enum(['x402', 'mpp-charge', 'mpp-session-open', 'mpp-session-reuse']),
|
|
18
|
+
amountUsd: z.number(),
|
|
19
|
+
txHash: z.string().optional(),
|
|
20
|
+
explorerUrl: z.url().optional(),
|
|
21
|
+
paymentReference: z.string().optional(),
|
|
22
|
+
signature: z.string(),
|
|
23
|
+
});
|
|
24
|
+
function safeJson(text) {
|
|
25
|
+
try {
|
|
26
|
+
return JSON.parse(text);
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
return text;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
export function createXmppMcpServer(options = {}) {
|
|
33
|
+
let budgetAlertState = 'clear';
|
|
34
|
+
const server = new McpServer({
|
|
35
|
+
name: options.name ?? 'xmpp',
|
|
36
|
+
version: options.version ?? '0.1.0',
|
|
37
|
+
});
|
|
38
|
+
async function maybeSendBudgetAlert(metadata) {
|
|
39
|
+
const budget = metadata?.budget;
|
|
40
|
+
if (!budget) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
const spent = budget.spentThisSessionUsd;
|
|
44
|
+
const remaining = budget.remainingDailyBudgetUsd;
|
|
45
|
+
const total = spent + remaining;
|
|
46
|
+
if (total <= 0) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
const ratio = spent / total;
|
|
50
|
+
const nextState = ratio >= 1 ? 'critical' : ratio >= 0.8 ? 'warning' : 'clear';
|
|
51
|
+
if (nextState === 'clear' ||
|
|
52
|
+
(budgetAlertState === 'warning' && nextState === 'warning') ||
|
|
53
|
+
budgetAlertState === nextState) {
|
|
54
|
+
budgetAlertState = nextState;
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
budgetAlertState = nextState;
|
|
58
|
+
await server.sendLoggingMessage({
|
|
59
|
+
level: nextState === 'critical' ? 'critical' : 'warning',
|
|
60
|
+
logger: 'xmpp-budget',
|
|
61
|
+
data: {
|
|
62
|
+
spentThisSessionUsd: budget.spentThisSessionUsd,
|
|
63
|
+
remainingDailyBudgetUsd: budget.remainingDailyBudgetUsd,
|
|
64
|
+
recommendation: budget.recommendation,
|
|
65
|
+
message: nextState === 'critical'
|
|
66
|
+
? 'xMPP budget exhausted. Pause or raise the operator ceiling before further autopay.'
|
|
67
|
+
: 'xMPP budget has crossed the 80% threshold. Prefer session reuse or stop premium calls.',
|
|
68
|
+
},
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
server.registerTool('xmpp_fetch', {
|
|
72
|
+
description: 'Fetch a paid resource through xMPP and auto-route payment across x402 or MPP.',
|
|
73
|
+
inputSchema: {
|
|
74
|
+
url: z.url(),
|
|
75
|
+
method: z.string().default('GET'),
|
|
76
|
+
agentId: z.string().optional(),
|
|
77
|
+
serviceId: z.string().optional(),
|
|
78
|
+
projectedRequests: z.number().int().positive().optional(),
|
|
79
|
+
streaming: z.boolean().optional(),
|
|
80
|
+
maxAutoPayUsd: z.number().positive().optional(),
|
|
81
|
+
idempotencyKey: z.string().optional(),
|
|
82
|
+
},
|
|
83
|
+
}, async ({ url, method, agentId, serviceId, projectedRequests, streaming, maxAutoPayUsd, idempotencyKey, }) => {
|
|
84
|
+
const response = await xmppFetch(url, { method }, { agentId, serviceId, projectedRequests, streaming, maxAutoPayUsd, idempotencyKey });
|
|
85
|
+
const text = await response.text();
|
|
86
|
+
const metadata = getXmppMetadata(response);
|
|
87
|
+
await maybeSendBudgetAlert(metadata);
|
|
88
|
+
return {
|
|
89
|
+
content: [
|
|
90
|
+
{
|
|
91
|
+
type: 'text',
|
|
92
|
+
text: JSON.stringify({
|
|
93
|
+
status: response.status,
|
|
94
|
+
payment: metadata,
|
|
95
|
+
body: safeJson(text),
|
|
96
|
+
}, null, 2),
|
|
97
|
+
},
|
|
98
|
+
],
|
|
99
|
+
structuredContent: {
|
|
100
|
+
status: response.status,
|
|
101
|
+
payment: metadata,
|
|
102
|
+
body: safeJson(text),
|
|
103
|
+
},
|
|
104
|
+
};
|
|
105
|
+
});
|
|
106
|
+
server.registerTool('xmpp_agent_profiles', {
|
|
107
|
+
description: 'List xMPP shared-treasury agents, their budgets, and their current spend.',
|
|
108
|
+
}, async () => {
|
|
109
|
+
const profiles = await listEffectiveXmppAgentProfiles();
|
|
110
|
+
const result = {
|
|
111
|
+
profiles,
|
|
112
|
+
contractPolicies: await listAgentPolicySnapshots(),
|
|
113
|
+
state: getXmppOperatorState(profiles).agentStates,
|
|
114
|
+
};
|
|
115
|
+
return {
|
|
116
|
+
content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
|
|
117
|
+
structuredContent: result,
|
|
118
|
+
};
|
|
119
|
+
});
|
|
120
|
+
server.registerTool('xmpp_receipt_verify', {
|
|
121
|
+
description: 'Verify a signed xMPP payment receipt against the agent public key.',
|
|
122
|
+
inputSchema: {
|
|
123
|
+
receipt: signedReceiptSchema,
|
|
124
|
+
},
|
|
125
|
+
}, async ({ receipt }) => {
|
|
126
|
+
const result = verifyXmppReceipt(receipt);
|
|
127
|
+
return {
|
|
128
|
+
content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
|
|
129
|
+
structuredContent: result,
|
|
130
|
+
};
|
|
131
|
+
});
|
|
132
|
+
server.registerTool('xmpp_wallet_info', {
|
|
133
|
+
description: 'Return current xMPP wallet status.',
|
|
134
|
+
}, async () => {
|
|
135
|
+
const wallet = await getWalletInfo();
|
|
136
|
+
return {
|
|
137
|
+
content: [{ type: 'text', text: JSON.stringify(wallet, null, 2) }],
|
|
138
|
+
structuredContent: wallet,
|
|
139
|
+
};
|
|
140
|
+
});
|
|
141
|
+
server.registerTool('xmpp_policy_preview', {
|
|
142
|
+
description: 'Preview the payment route xMPP would choose without paying.',
|
|
143
|
+
inputSchema: {
|
|
144
|
+
url: z.url(),
|
|
145
|
+
method: z.string().default('GET'),
|
|
146
|
+
serviceId: z.string().optional(),
|
|
147
|
+
projectedRequests: z.number().int().positive().optional(),
|
|
148
|
+
streaming: z.boolean().optional(),
|
|
149
|
+
},
|
|
150
|
+
}, async ({ url, method, serviceId, projectedRequests, streaming }) => {
|
|
151
|
+
const preview = await router.preview({
|
|
152
|
+
url,
|
|
153
|
+
method,
|
|
154
|
+
serviceId,
|
|
155
|
+
projectedRequests,
|
|
156
|
+
streaming,
|
|
157
|
+
});
|
|
158
|
+
return {
|
|
159
|
+
content: [{ type: 'text', text: JSON.stringify(preview, null, 2) }],
|
|
160
|
+
structuredContent: preview,
|
|
161
|
+
};
|
|
162
|
+
});
|
|
163
|
+
server.registerTool('xmpp_explain', {
|
|
164
|
+
description: 'Explain how xMPP scores routes for a request, including cost and break-even context.',
|
|
165
|
+
inputSchema: {
|
|
166
|
+
url: z.url(),
|
|
167
|
+
method: z.string().default('GET'),
|
|
168
|
+
serviceId: z.string().optional(),
|
|
169
|
+
projectedRequests: z.number().int().positive().optional(),
|
|
170
|
+
streaming: z.boolean().optional(),
|
|
171
|
+
hasReusableSession: z.boolean().optional(),
|
|
172
|
+
},
|
|
173
|
+
}, async ({ url, method, serviceId, projectedRequests, streaming, hasReusableSession }) => {
|
|
174
|
+
const explanation = router.explain({
|
|
175
|
+
url,
|
|
176
|
+
method,
|
|
177
|
+
serviceId,
|
|
178
|
+
projectedRequests,
|
|
179
|
+
streaming,
|
|
180
|
+
hasReusableSession,
|
|
181
|
+
});
|
|
182
|
+
return {
|
|
183
|
+
content: [{ type: 'text', text: JSON.stringify(explanation, null, 2) }],
|
|
184
|
+
structuredContent: explanation,
|
|
185
|
+
};
|
|
186
|
+
});
|
|
187
|
+
server.registerTool('xmpp_session_list', {
|
|
188
|
+
description: 'List local and contract-backed xMPP sessions for the current agent.',
|
|
189
|
+
}, async () => {
|
|
190
|
+
const localSessions = listLocalSessions();
|
|
191
|
+
const contractSessions = await listAgentSessions();
|
|
192
|
+
const merged = new Map(localSessions.map((session) => [session.sessionId, session]));
|
|
193
|
+
for (const session of contractSessions) {
|
|
194
|
+
merged.set(session.sessionId, session);
|
|
195
|
+
}
|
|
196
|
+
const result = {
|
|
197
|
+
totalSessions: merged.size,
|
|
198
|
+
localSessions,
|
|
199
|
+
contractSessions,
|
|
200
|
+
sessions: [...merged.values()],
|
|
201
|
+
};
|
|
202
|
+
return {
|
|
203
|
+
content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
|
|
204
|
+
structuredContent: result,
|
|
205
|
+
};
|
|
206
|
+
});
|
|
207
|
+
server.registerTool('xmpp_estimate_workflow', {
|
|
208
|
+
description: 'Estimate multi-step workflow cost, selected routes, and savings against naive x402.',
|
|
209
|
+
inputSchema: {
|
|
210
|
+
steps: z.array(z.object({
|
|
211
|
+
url: z.url(),
|
|
212
|
+
method: z.string().default('GET').optional(),
|
|
213
|
+
serviceId: z.string().optional(),
|
|
214
|
+
projectedRequests: z.number().int().positive(),
|
|
215
|
+
streaming: z.boolean().optional(),
|
|
216
|
+
})),
|
|
217
|
+
},
|
|
218
|
+
}, async ({ steps }) => {
|
|
219
|
+
const estimate = router.estimateWorkflow(steps);
|
|
220
|
+
return {
|
|
221
|
+
content: [{ type: 'text', text: JSON.stringify(estimate, null, 2) }],
|
|
222
|
+
structuredContent: estimate,
|
|
223
|
+
};
|
|
224
|
+
});
|
|
225
|
+
return server;
|
|
226
|
+
}
|
|
227
|
+
export async function runXmppMcpServer(options) {
|
|
228
|
+
const server = createXmppMcpServer(options);
|
|
229
|
+
const transport = new StdioServerTransport();
|
|
230
|
+
await server.connect(transport);
|
|
231
|
+
return server;
|
|
232
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
export declare const config: {
|
|
2
|
+
readonly nodeEnv: string;
|
|
3
|
+
readonly network: string;
|
|
4
|
+
readonly paymentExecutionMode: "mock" | "testnet";
|
|
5
|
+
readonly rpcUrl: string;
|
|
6
|
+
readonly networkPassphrase: string;
|
|
7
|
+
readonly gatewayPort: number;
|
|
8
|
+
readonly dashboardPort: number;
|
|
9
|
+
readonly dashboardGatewayUrl: string | undefined;
|
|
10
|
+
readonly dailyBudgetUsd: number;
|
|
11
|
+
readonly facilitatorUrl: string;
|
|
12
|
+
readonly wallet: {
|
|
13
|
+
readonly agentSecretKey: string | undefined;
|
|
14
|
+
readonly smartAccountContractId: string | undefined;
|
|
15
|
+
readonly smartAccountWasmHash: string;
|
|
16
|
+
readonly webauthnVerifierAddress: string;
|
|
17
|
+
readonly ed25519VerifierAddress: string;
|
|
18
|
+
readonly spendingLimitPolicyAddress: string;
|
|
19
|
+
readonly thresholdPolicyAddress: string;
|
|
20
|
+
};
|
|
21
|
+
readonly x402: {
|
|
22
|
+
readonly facilitatorUrl: string;
|
|
23
|
+
readonly facilitatorApiKey: string | undefined;
|
|
24
|
+
readonly maxTransactionFeeStroops: number;
|
|
25
|
+
readonly facilitatorPrivateKey: string | undefined;
|
|
26
|
+
readonly recipientAddress: string | undefined;
|
|
27
|
+
};
|
|
28
|
+
readonly mpp: {
|
|
29
|
+
readonly secretKey: string | undefined;
|
|
30
|
+
readonly recipientAddress: string | undefined;
|
|
31
|
+
readonly channelContractId: string | undefined;
|
|
32
|
+
readonly feeSponsorshipEnabled: boolean;
|
|
33
|
+
readonly feeSponsorship: {
|
|
34
|
+
readonly chargeEnabled: boolean;
|
|
35
|
+
readonly sessionEnabled: boolean;
|
|
36
|
+
};
|
|
37
|
+
readonly feeSponsorSecretKey: string | undefined;
|
|
38
|
+
readonly feeBumpSecretKey: string | undefined;
|
|
39
|
+
};
|
|
40
|
+
readonly services: {
|
|
41
|
+
readonly research: string;
|
|
42
|
+
readonly market: string;
|
|
43
|
+
readonly stream: string;
|
|
44
|
+
};
|
|
45
|
+
readonly contracts: {
|
|
46
|
+
readonly policyContractId: string | undefined;
|
|
47
|
+
readonly sessionRegistryContractId: string | undefined;
|
|
48
|
+
};
|
|
49
|
+
};
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { config as loadEnv } from 'dotenv';
|
|
2
|
+
import { dirname, resolve } from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
const moduleDir = dirname(fileURLToPath(import.meta.url));
|
|
6
|
+
const repoRoot = resolve(moduleDir, '../../../');
|
|
7
|
+
loadEnv({ path: resolve(repoRoot, '.env') });
|
|
8
|
+
loadEnv({ path: resolve(repoRoot, '.env.local'), override: true });
|
|
9
|
+
loadEnv();
|
|
10
|
+
const envSchema = z.object({
|
|
11
|
+
NODE_ENV: z.string().default('development'),
|
|
12
|
+
XMPP_NETWORK: z.string().default('stellar:testnet'),
|
|
13
|
+
XMPP_PAYMENT_EXECUTION_MODE: z.enum(['mock', 'testnet']).default('mock'),
|
|
14
|
+
XMPP_RPC_URL: z.string().default('https://soroban-testnet.stellar.org'),
|
|
15
|
+
XMPP_NETWORK_PASSPHRASE: z.string().default('Test SDF Network ; September 2015'),
|
|
16
|
+
XMPP_GATEWAY_PORT: z.coerce.number().default(4300),
|
|
17
|
+
XMPP_DASHBOARD_PORT: z.coerce.number().default(4310),
|
|
18
|
+
XMPP_DASHBOARD_GATEWAY_URL: z.string().optional(),
|
|
19
|
+
XMPP_DAILY_BUDGET_USD: z.coerce.number().default(0.5),
|
|
20
|
+
XMPP_AGENT_SECRET_KEY: z.string().optional(),
|
|
21
|
+
XMPP_SMART_ACCOUNT_CONTRACT_ID: z.string().optional(),
|
|
22
|
+
XMPP_SMART_ACCOUNT_WASM_HASH: z
|
|
23
|
+
.string()
|
|
24
|
+
.default('3e51f5b222dec74650f0b33367acb42a41ce497f72639230463070e666abba2c'),
|
|
25
|
+
XMPP_WEBAUTHN_VERIFIER_ADDRESS: z
|
|
26
|
+
.string()
|
|
27
|
+
.default('CATPTBRWVMH5ZCIKO5HN2F4FMPXVZEXC56RKGHRXCM7EEZGGXK7PICEH'),
|
|
28
|
+
XMPP_ED25519_VERIFIER_ADDRESS: z
|
|
29
|
+
.string()
|
|
30
|
+
.default('CAIKK32K3BZJYTWVTXHZFPIEEDBR6YCVTGPABH4UQUQ4XFA3OLYXG27G'),
|
|
31
|
+
XMPP_SPENDING_LIMIT_POLICY_ADDRESS: z
|
|
32
|
+
.string()
|
|
33
|
+
.default('CBYLPYZGLQ6JVY2IQ5P23QLQPR3KAMMKMZLNWG6RUUKJDNYGPLVHK7U4'),
|
|
34
|
+
XMPP_THRESHOLD_POLICY_ADDRESS: z
|
|
35
|
+
.string()
|
|
36
|
+
.default('CDDQLFG7CV74QHWPSP6NZIPNBR2PPCMTUVYCJF4P3ONDYHODRFGR7LWC'),
|
|
37
|
+
X402_FACILITATOR_URL: z.string().default('http://localhost:4022'),
|
|
38
|
+
X402_FACILITATOR_API_KEY: z.string().optional(),
|
|
39
|
+
X402_MAX_TRANSACTION_FEE_STROOPS: z.coerce.number().default(2000000),
|
|
40
|
+
X402_RECIPIENT_ADDRESS: z.string().optional(),
|
|
41
|
+
FACILITATOR_STELLAR_PRIVATE_KEY: z.string().optional(),
|
|
42
|
+
MPP_SECRET_KEY: z.string().optional(),
|
|
43
|
+
MPP_RECIPIENT_ADDRESS: z.string().optional(),
|
|
44
|
+
MPP_CHANNEL_CONTRACT_ID: z.string().optional(),
|
|
45
|
+
XMPP_ENABLE_MPP_FEE_SPONSORSHIP: z
|
|
46
|
+
.enum(['true', 'false'])
|
|
47
|
+
.default('false')
|
|
48
|
+
.transform((value) => value === 'true'),
|
|
49
|
+
XMPP_ENABLE_MPP_CHARGE_FEE_SPONSORSHIP: z
|
|
50
|
+
.enum(['true', 'false'])
|
|
51
|
+
.optional()
|
|
52
|
+
.transform((value) => value === 'true'),
|
|
53
|
+
XMPP_ENABLE_MPP_SESSION_FEE_SPONSORSHIP: z
|
|
54
|
+
.enum(['true', 'false'])
|
|
55
|
+
.optional()
|
|
56
|
+
.transform((value) => value === 'true'),
|
|
57
|
+
XMPP_MPP_FEE_SPONSOR_SECRET_KEY: z.string().optional(),
|
|
58
|
+
XMPP_MPP_FEE_BUMP_SECRET_KEY: z.string().optional(),
|
|
59
|
+
XMPP_RESEARCH_API_URL: z.string().default('http://localhost:4101'),
|
|
60
|
+
XMPP_MARKET_API_URL: z.string().default('http://localhost:4102'),
|
|
61
|
+
XMPP_STREAM_API_URL: z.string().default('http://localhost:4103'),
|
|
62
|
+
XMPP_POLICY_CONTRACT_ID: z.string().optional(),
|
|
63
|
+
XMPP_SESSION_REGISTRY_CONTRACT_ID: z.string().optional(),
|
|
64
|
+
});
|
|
65
|
+
const env = envSchema.parse(process.env);
|
|
66
|
+
const mppFeeSponsorshipEnabled = env.XMPP_ENABLE_MPP_FEE_SPONSORSHIP;
|
|
67
|
+
const mppChargeFeeSponsorshipEnabled = env.XMPP_ENABLE_MPP_CHARGE_FEE_SPONSORSHIP ?? mppFeeSponsorshipEnabled;
|
|
68
|
+
const mppSessionFeeSponsorshipEnabled = env.XMPP_ENABLE_MPP_SESSION_FEE_SPONSORSHIP ?? mppFeeSponsorshipEnabled;
|
|
69
|
+
export const config = {
|
|
70
|
+
nodeEnv: env.NODE_ENV,
|
|
71
|
+
network: env.XMPP_NETWORK,
|
|
72
|
+
paymentExecutionMode: env.XMPP_PAYMENT_EXECUTION_MODE,
|
|
73
|
+
rpcUrl: env.XMPP_RPC_URL,
|
|
74
|
+
networkPassphrase: env.XMPP_NETWORK_PASSPHRASE,
|
|
75
|
+
gatewayPort: env.XMPP_GATEWAY_PORT,
|
|
76
|
+
dashboardPort: env.XMPP_DASHBOARD_PORT,
|
|
77
|
+
dashboardGatewayUrl: env.XMPP_DASHBOARD_GATEWAY_URL,
|
|
78
|
+
dailyBudgetUsd: env.XMPP_DAILY_BUDGET_USD,
|
|
79
|
+
facilitatorUrl: env.X402_FACILITATOR_URL,
|
|
80
|
+
wallet: {
|
|
81
|
+
agentSecretKey: env.XMPP_AGENT_SECRET_KEY,
|
|
82
|
+
smartAccountContractId: env.XMPP_SMART_ACCOUNT_CONTRACT_ID,
|
|
83
|
+
smartAccountWasmHash: env.XMPP_SMART_ACCOUNT_WASM_HASH,
|
|
84
|
+
webauthnVerifierAddress: env.XMPP_WEBAUTHN_VERIFIER_ADDRESS,
|
|
85
|
+
ed25519VerifierAddress: env.XMPP_ED25519_VERIFIER_ADDRESS,
|
|
86
|
+
spendingLimitPolicyAddress: env.XMPP_SPENDING_LIMIT_POLICY_ADDRESS,
|
|
87
|
+
thresholdPolicyAddress: env.XMPP_THRESHOLD_POLICY_ADDRESS,
|
|
88
|
+
},
|
|
89
|
+
x402: {
|
|
90
|
+
facilitatorUrl: env.X402_FACILITATOR_URL,
|
|
91
|
+
facilitatorApiKey: env.X402_FACILITATOR_API_KEY,
|
|
92
|
+
maxTransactionFeeStroops: env.X402_MAX_TRANSACTION_FEE_STROOPS,
|
|
93
|
+
facilitatorPrivateKey: env.FACILITATOR_STELLAR_PRIVATE_KEY,
|
|
94
|
+
recipientAddress: env.X402_RECIPIENT_ADDRESS,
|
|
95
|
+
},
|
|
96
|
+
mpp: {
|
|
97
|
+
secretKey: env.MPP_SECRET_KEY,
|
|
98
|
+
recipientAddress: env.MPP_RECIPIENT_ADDRESS,
|
|
99
|
+
channelContractId: env.MPP_CHANNEL_CONTRACT_ID,
|
|
100
|
+
feeSponsorshipEnabled: mppFeeSponsorshipEnabled,
|
|
101
|
+
feeSponsorship: {
|
|
102
|
+
chargeEnabled: mppChargeFeeSponsorshipEnabled,
|
|
103
|
+
sessionEnabled: mppSessionFeeSponsorshipEnabled,
|
|
104
|
+
},
|
|
105
|
+
feeSponsorSecretKey: env.XMPP_MPP_FEE_SPONSOR_SECRET_KEY,
|
|
106
|
+
feeBumpSecretKey: env.XMPP_MPP_FEE_BUMP_SECRET_KEY,
|
|
107
|
+
},
|
|
108
|
+
services: {
|
|
109
|
+
research: env.XMPP_RESEARCH_API_URL,
|
|
110
|
+
market: env.XMPP_MARKET_API_URL,
|
|
111
|
+
stream: env.XMPP_STREAM_API_URL,
|
|
112
|
+
},
|
|
113
|
+
contracts: {
|
|
114
|
+
policyContractId: env.XMPP_POLICY_CONTRACT_ID,
|
|
115
|
+
sessionRegistryContractId: env.XMPP_SESSION_REGISTRY_CONTRACT_ID,
|
|
116
|
+
},
|
|
117
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { RouteKind, XmppAgentPolicySnapshot, XmppContractAgentTreasuryState, XmppContractTreasurySnapshot, XmppSessionRecord } from '@xmpp/types';
|
|
2
|
+
export type PolicyRuntimeSnapshot = {
|
|
3
|
+
source: 'local' | 'contract' | 'fallback';
|
|
4
|
+
pauseFlag: boolean;
|
|
5
|
+
globalPolicy: {
|
|
6
|
+
maxSpendUsdCents: number;
|
|
7
|
+
allowUnknownServices: boolean;
|
|
8
|
+
allowPostAutopay: boolean;
|
|
9
|
+
} | null;
|
|
10
|
+
servicePolicy: {
|
|
11
|
+
serviceId: string;
|
|
12
|
+
enabled: boolean;
|
|
13
|
+
maxSpendUsdCents: number;
|
|
14
|
+
preferredRoute: string;
|
|
15
|
+
allowSessionReuse: boolean;
|
|
16
|
+
} | null;
|
|
17
|
+
};
|
|
18
|
+
export type AgentPolicyRuntimeSnapshot = {
|
|
19
|
+
source: 'local' | 'contract' | 'fallback';
|
|
20
|
+
agentPolicy: XmppAgentPolicySnapshot | null;
|
|
21
|
+
};
|
|
22
|
+
export type SessionRouteEventInput = {
|
|
23
|
+
sessionId: string;
|
|
24
|
+
serviceId: string;
|
|
25
|
+
route: RouteKind;
|
|
26
|
+
status: 'open' | 'reused' | 'closed';
|
|
27
|
+
callCount: number;
|
|
28
|
+
receiptId: string;
|
|
29
|
+
totalAmountUsdCents?: number;
|
|
30
|
+
};
|
|
31
|
+
export declare function getAgentPolicySnapshot(agentId: string): Promise<AgentPolicyRuntimeSnapshot>;
|
|
32
|
+
export declare function listAgentPolicySnapshots(): Promise<XmppAgentPolicySnapshot[]>;
|
|
33
|
+
export declare function getTreasurySnapshot(): Promise<XmppContractTreasurySnapshot | null>;
|
|
34
|
+
export declare function getAgentTreasuryState(agentId: string): Promise<XmppContractAgentTreasuryState | null>;
|
|
35
|
+
export declare function listAgentTreasuryStates(): Promise<XmppContractAgentTreasuryState[]>;
|
|
36
|
+
export declare function getPolicyRuntimeSnapshot(serviceId?: string): Promise<PolicyRuntimeSnapshot>;
|
|
37
|
+
export declare function recordTreasurySpend(input: {
|
|
38
|
+
agentId: string;
|
|
39
|
+
serviceId: string;
|
|
40
|
+
route: RouteKind;
|
|
41
|
+
amountUsdCents: number;
|
|
42
|
+
}): Promise<XmppContractAgentTreasuryState | null>;
|
|
43
|
+
export declare function recordSessionRouteEvent(input: SessionRouteEventInput): Promise<XmppSessionRecord | null>;
|
|
44
|
+
export declare function listAgentSessions(): Promise<XmppSessionRecord[]>;
|