aixyz 0.1.2 → 0.2.4

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 CHANGED
@@ -1,3 +1,7 @@
1
+ import { z } from "zod";
2
+ import { FacilitatorClient, HTTPFacilitatorClient } from "@x402/core/server";
3
+ import { getFacilitatorClient } from "./facilitator";
4
+
1
5
  export type Accepts = AcceptsX402 | AcceptsFree;
2
6
 
3
7
  export type AcceptsX402 = {
@@ -10,3 +14,24 @@ export type AcceptsX402 = {
10
14
  export type AcceptsFree = {
11
15
  scheme: "free";
12
16
  };
17
+
18
+ export const AcceptsScheme = z.discriminatedUnion("scheme", [
19
+ z.object({
20
+ scheme: z.literal("exact"),
21
+ price: z.string(),
22
+ network: z.string().optional(),
23
+ payTo: z.string().optional(),
24
+ }),
25
+ z.object({
26
+ scheme: z.literal("free"),
27
+ }),
28
+ ]);
29
+
30
+ export type { FacilitatorClient };
31
+
32
+ export { HTTPFacilitatorClient };
33
+
34
+ /**
35
+ * The default facilitator client provided by aixyz.
36
+ */
37
+ export const facilitator: FacilitatorClient = getFacilitatorClient();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aixyz",
3
- "version": "0.1.2",
3
+ "version": "0.2.4",
4
4
  "description": "AI agent framework for building autonomous agents with X402 and ERC-8004 support.",
5
5
  "keywords": [
6
6
  "ai",
@@ -28,21 +28,19 @@
28
28
  ],
29
29
  "dependencies": {
30
30
  "@a2a-js/sdk": "^0.3.10",
31
- "@aixyz/cli": "workspace:*",
32
- "@aixyz/config": "workspace:*",
31
+ "@aixyz/cli": "0.0.0",
32
+ "@aixyz/config": "0.0.0",
33
33
  "@modelcontextprotocol/sdk": "^1.26.0",
34
- "@next/env": "^16.1.6",
35
34
  "@x402/core": "^2.3.1",
36
35
  "@x402/evm": "^2.3.1",
37
36
  "@x402/express": "^2.3.0",
38
37
  "@x402/mcp": "^2.3.0",
39
- "commander": "^13.0.0",
40
- "express": "^5.2.1",
41
- "jose": "^5.10.0",
42
- "zod": "^4.3.6"
38
+ "express": "^5",
39
+ "jose": "^6.1.3",
40
+ "zod": "^4"
43
41
  },
44
42
  "devDependencies": {
45
- "@types/express": "^5.0.6",
43
+ "@types/express": "^5",
46
44
  "ai": "^6"
47
45
  },
48
46
  "peerDependencies": {
@@ -9,10 +9,10 @@ import {
9
9
  } from "@a2a-js/sdk/server";
10
10
  import { AgentCard, Message, TextPart } from "@a2a-js/sdk";
11
11
  import type { ToolLoopAgent, ToolSet } from "ai";
12
- import { getAixyzConfig } from "../../config";
12
+ import { getAixyzConfigRuntime } from "../../config";
13
13
  import { AixyzServer } from "../index";
14
14
  import { agentCardHandler, jsonRpcHandler, UserBuilder } from "@a2a-js/sdk/server/express";
15
- import { Accepts } from "../../accepts";
15
+ import { Accepts, AcceptsScheme } from "../../accepts";
16
16
 
17
17
  export class ToolLoopAgentExecutor<TOOLS extends ToolSet = ToolSet> implements AgentExecutor {
18
18
  constructor(private agent: ToolLoopAgent<never, TOOLS>) {}
@@ -63,7 +63,7 @@ export class ToolLoopAgentExecutor<TOOLS extends ToolSet = ToolSet> implements A
63
63
  }
64
64
 
65
65
  export function getAgentCard(): AgentCard {
66
- const config = getAixyzConfig();
66
+ const config = getAixyzConfigRuntime();
67
67
  return {
68
68
  name: config.name,
69
69
  description: config.description,
@@ -88,7 +88,10 @@ export function useA2A<TOOLS extends ToolSet = ToolSet>(
88
88
  },
89
89
  taskStore: TaskStore = new InMemoryTaskStore(),
90
90
  ): void {
91
- if (!exports.accepts) {
91
+ if (exports.accepts) {
92
+ // TODO(@fuxingloh): validation should be done at build stage
93
+ AcceptsScheme.parse(exports.accepts);
94
+ } else {
92
95
  // TODO(@fuxingloh): right now we just don't register the agent if accepts is not provided,
93
96
  // but it might be a better idea to do it in aixyz-cli (aixyz-pack).
94
97
  return;
@@ -105,7 +108,7 @@ export function useA2A<TOOLS extends ToolSet = ToolSet>(
105
108
  );
106
109
 
107
110
  if (exports.accepts.scheme === "exact") {
108
- app.withX402("POST /agent", exports.accepts);
111
+ app.withX402Exact("POST /agent", exports.accepts);
109
112
  }
110
113
 
111
114
  app.express.use(
@@ -5,7 +5,7 @@ import express from "express";
5
5
  import type { IncomingMessage, ServerResponse } from "node:http";
6
6
  import { AixyzServer } from "../index";
7
7
  import { createPaymentWrapper } from "@x402/mcp";
8
- import { Accepts, AcceptsX402 } from "../../accepts";
8
+ import { Accepts, AcceptsScheme, AcceptsX402 } from "../../accepts";
9
9
 
10
10
  export class AixyzMCP {
11
11
  private registeredTools: Array<{
@@ -60,7 +60,10 @@ export class AixyzMCP {
60
60
  accepts?: Accepts;
61
61
  },
62
62
  ) {
63
- if (!exports.accepts) {
63
+ if (exports.accepts) {
64
+ // TODO(@fuxingloh): validation should be done at build stage
65
+ AcceptsScheme.parse(exports.accepts);
66
+ } else {
64
67
  // TODO(@fuxingloh): right now we just don't register the agent if accepts is not provided,
65
68
  // but it might be a better idea to do it in aixyz-cli (aixyz-pack).
66
69
  return;
package/server/index.ts CHANGED
@@ -1,24 +1,25 @@
1
1
  import { getAixyzConfig, Network } from "../config";
2
2
  import initExpress from "express";
3
- import { x402ResourceServer } from "@x402/core/server";
3
+ import { FacilitatorClient, x402ResourceServer } from "@x402/core/server";
4
4
  import { paymentMiddleware, PaymentRequirements } from "@x402/express";
5
- import { getFacilitatorClient } from "../facilitator";
6
5
  import { ExactEvmScheme } from "@x402/evm/exact/server";
7
6
  import { z } from "zod";
8
7
  import { AcceptsX402 } from "../accepts";
8
+ import { getFacilitatorClient } from "../facilitator";
9
9
 
10
10
  // TODO(@fuxingloh): rename to unstable_AixyzApp?
11
11
  export class AixyzServer extends x402ResourceServer {
12
12
  constructor(
13
+ facilitator: FacilitatorClient = getFacilitatorClient(),
13
14
  public config = getAixyzConfig(),
14
15
  public express: initExpress.Express = initExpress(),
15
16
  ) {
16
- super(getFacilitatorClient());
17
+ super(facilitator);
17
18
  this.register(config.x402.network as any, new ExactEvmScheme());
18
19
  }
19
20
 
20
21
  public unstable_withIndexPage(path = "/") {
21
- if (!path || typeof path !== "string" || !path.startsWith("/")) {
22
+ if (!path?.startsWith("/")) {
22
23
  throw new Error(`Invalid path: ${path}. Path must be a string starting with "/"`);
23
24
  }
24
25
 
@@ -57,7 +58,7 @@ export class AixyzServer extends x402ResourceServer {
57
58
 
58
59
  // TODO(@fuxingloh): add back x402 Bazaar compatibility
59
60
 
60
- private withAccepts(accepts: AcceptsX402) {
61
+ private withSchemeExact(accepts: AcceptsX402) {
61
62
  const schema = z.object({
62
63
  scheme: z.literal("exact"),
63
64
  price: z.string(),
@@ -72,12 +73,12 @@ export class AixyzServer extends x402ResourceServer {
72
73
  return schema.parse(accepts);
73
74
  }
74
75
 
75
- withX402(route: `${"GET" | "POST"} /${string}`, accepts: AcceptsX402) {
76
+ withX402Exact(route: `${"GET" | "POST"} /${string}`, accepts: AcceptsX402) {
76
77
  this.express.use(
77
78
  paymentMiddleware(
78
79
  {
79
80
  [route]: {
80
- accepts: this.withAccepts(accepts),
81
+ accepts: this.withSchemeExact(accepts),
81
82
  mimeType: "application/json",
82
83
  description: `A2A Payment: ${this.config.description}`,
83
84
  },
@@ -91,6 +92,6 @@ export class AixyzServer extends x402ResourceServer {
91
92
  }
92
93
 
93
94
  async withPaymentRequirements(accepts: AcceptsX402): Promise<PaymentRequirements[]> {
94
- return this.buildPaymentRequirements(this.withAccepts(accepts));
95
+ return this.buildPaymentRequirements(this.withSchemeExact(accepts));
95
96
  }
96
97
  }