aixyz 0.0.1 → 0.1.2
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/accepts.ts +12 -0
- package/bin.js +2 -0
- package/config.ts +1 -0
- package/facilitator/coinbase.ts +387 -0
- package/facilitator/index.ts +12 -0
- package/index.ts +0 -0
- package/package.json +11 -18
- package/server/adapters/a2a.ts +118 -0
- package/server/adapters/mcp.ts +100 -0
- package/server/index.ts +96 -0
- package/dist/cli/bin.js +0 -16351
package/server/index.ts
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { getAixyzConfig, Network } from "../config";
|
|
2
|
+
import initExpress from "express";
|
|
3
|
+
import { x402ResourceServer } from "@x402/core/server";
|
|
4
|
+
import { paymentMiddleware, PaymentRequirements } from "@x402/express";
|
|
5
|
+
import { getFacilitatorClient } from "../facilitator";
|
|
6
|
+
import { ExactEvmScheme } from "@x402/evm/exact/server";
|
|
7
|
+
import { z } from "zod";
|
|
8
|
+
import { AcceptsX402 } from "../accepts";
|
|
9
|
+
|
|
10
|
+
// TODO(@fuxingloh): rename to unstable_AixyzApp?
|
|
11
|
+
export class AixyzServer extends x402ResourceServer {
|
|
12
|
+
constructor(
|
|
13
|
+
public config = getAixyzConfig(),
|
|
14
|
+
public express: initExpress.Express = initExpress(),
|
|
15
|
+
) {
|
|
16
|
+
super(getFacilitatorClient());
|
|
17
|
+
this.register(config.x402.network as any, new ExactEvmScheme());
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
public unstable_withIndexPage(path = "/") {
|
|
21
|
+
if (!path || typeof path !== "string" || !path.startsWith("/")) {
|
|
22
|
+
throw new Error(`Invalid path: ${path}. Path must be a string starting with "/"`);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Simple human interface at root
|
|
26
|
+
this.express.get(path, (_req, res) => {
|
|
27
|
+
const { name, description, version, skills } = this.config;
|
|
28
|
+
|
|
29
|
+
let text = `${name}\n`;
|
|
30
|
+
text += `${"=".repeat(name.length)}\n\n`;
|
|
31
|
+
text += `Description: ${description}\n`;
|
|
32
|
+
text += `Version: ${version}\n\n`;
|
|
33
|
+
|
|
34
|
+
if (skills && skills.length > 0) {
|
|
35
|
+
text += `Skills:\n`;
|
|
36
|
+
skills.forEach((skill, index) => {
|
|
37
|
+
text += `\n${index + 1}. ${skill.name}\n`;
|
|
38
|
+
text += ` ID: ${skill.id}\n`;
|
|
39
|
+
text += ` Description: ${skill.description}\n`;
|
|
40
|
+
if (skill.tags && skill.tags.length > 0) {
|
|
41
|
+
text += ` Tags: ${skill.tags.join(", ")}\n`;
|
|
42
|
+
}
|
|
43
|
+
if (skill.examples && skill.examples.length > 0) {
|
|
44
|
+
text += ` Examples:\n`;
|
|
45
|
+
skill.examples.forEach((example) => {
|
|
46
|
+
text += ` - ${example}\n`;
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
res.type("text/plain").send(text);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
return this;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// TODO(@fuxingloh): add back x402 Bazaar compatibility
|
|
59
|
+
|
|
60
|
+
private withAccepts(accepts: AcceptsX402) {
|
|
61
|
+
const schema = z.object({
|
|
62
|
+
scheme: z.literal("exact"),
|
|
63
|
+
price: z.string(),
|
|
64
|
+
payTo: z.string().default(this.config.x402.payTo),
|
|
65
|
+
network: z
|
|
66
|
+
.custom<Network>((val) => {
|
|
67
|
+
return typeof val === "string" && val.includes(":");
|
|
68
|
+
})
|
|
69
|
+
.default(this.config.x402.network),
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
return schema.parse(accepts);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
withX402(route: `${"GET" | "POST"} /${string}`, accepts: AcceptsX402) {
|
|
76
|
+
this.express.use(
|
|
77
|
+
paymentMiddleware(
|
|
78
|
+
{
|
|
79
|
+
[route]: {
|
|
80
|
+
accepts: this.withAccepts(accepts),
|
|
81
|
+
mimeType: "application/json",
|
|
82
|
+
description: `A2A Payment: ${this.config.description}`,
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
this,
|
|
86
|
+
undefined,
|
|
87
|
+
undefined,
|
|
88
|
+
false,
|
|
89
|
+
),
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
async withPaymentRequirements(accepts: AcceptsX402): Promise<PaymentRequirements[]> {
|
|
94
|
+
return this.buildPaymentRequirements(this.withAccepts(accepts));
|
|
95
|
+
}
|
|
96
|
+
}
|