@aixyz/cli 0.12.0 → 0.13.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.
@@ -1,6 +1,6 @@
1
1
  import type { BunPlugin } from "bun";
2
2
  import { existsSync, mkdirSync, readdirSync, writeFileSync } from "fs";
3
- import { resolve, relative, basename, join } from "path";
3
+ import { resolve, relative, join } from "path";
4
4
  import { getAixyzConfig } from "@aixyz/config";
5
5
 
6
6
  export function AixyzServerPlugin(entrypoint: string, mode: "vercel" | "standalone" | "executable"): BunPlugin {
@@ -55,8 +55,40 @@ export function getEntrypointMayGenerate(cwd: string, mode: "dev" | "build"): st
55
55
  class AixyzGlob {
56
56
  constructor(readonly config = getAixyzConfig()) {}
57
57
 
58
- includes(file: string): boolean {
59
- const included = this.config.build.includes.some((pattern) => new Bun.Glob(pattern).match(file));
58
+ hasRootAgent(appDir: string): { file: string } | undefined {
59
+ const file = readdirSync(appDir).find((f) => /^agent\.(js|ts)$/.test(f) && this.includesAgent(f));
60
+ return file ? { file } : undefined;
61
+ }
62
+
63
+ getAgents(agentsDir: string): { name: string; identifier: string }[] {
64
+ if (!existsSync(agentsDir)) return [];
65
+ return readdirSync(agentsDir)
66
+ .filter((file) => this.includesAgent(`agents/${file}`))
67
+ .map((file) => {
68
+ const name = file.replace(/\.(js|ts)$/, "");
69
+ return { name, identifier: toIdentifier(name) };
70
+ });
71
+ }
72
+
73
+ getTools(toolsDir: string): { name: string; identifier: string }[] {
74
+ if (!existsSync(toolsDir)) return [];
75
+ return readdirSync(toolsDir)
76
+ .filter((file) => this.includesTool(`tools/${file}`))
77
+ .map((file) => {
78
+ const name = file.replace(/\.(js|ts)$/, "");
79
+ return { name, identifier: toIdentifier(name) };
80
+ });
81
+ }
82
+
83
+ private includesAgent(file: string): boolean {
84
+ const included = this.config.build.agents.some((pattern) => new Bun.Glob(pattern).match(file));
85
+ if (!included) return false;
86
+ const excluded = this.config.build.excludes.some((pattern) => new Bun.Glob(pattern).match(file));
87
+ return !excluded;
88
+ }
89
+
90
+ private includesTool(file: string): boolean {
91
+ const included = this.config.build.tools.some((pattern) => new Bun.Glob(pattern).match(file));
60
92
  if (!included) return false;
61
93
  const excluded = this.config.build.excludes.some((pattern) => new Bun.Glob(pattern).match(file));
62
94
  return !excluded;
@@ -86,25 +118,16 @@ function generateServer(appDir: string, entrypointDir: string): string {
86
118
  imports.push('import { facilitator } from "aixyz/accepts";');
87
119
  }
88
120
 
89
- const hasAgent = existsSync(resolve(appDir, "agent.ts")) && glob.includes("agent.ts");
90
- if (hasAgent) {
121
+ const rootAgent = glob.hasRootAgent(appDir);
122
+ if (rootAgent) {
91
123
  imports.push('import { useA2A } from "aixyz/server/adapters/a2a";');
92
124
  imports.push(`import * as agent from "${importPrefix}/agent";`);
93
125
  }
94
126
 
95
127
  const agentsDir = resolve(appDir, "agents");
96
- const subAgents: { name: string; identifier: string }[] = [];
97
- if (existsSync(agentsDir)) {
98
- for (const file of readdirSync(agentsDir)) {
99
- if (glob.includes(`agents/${file}`)) {
100
- const name = basename(file, ".ts");
101
- const identifier = toIdentifier(name);
102
- subAgents.push({ name, identifier });
103
- }
104
- }
105
- }
128
+ const subAgents = glob.getAgents(agentsDir);
106
129
 
107
- if (!hasAgent && subAgents.length > 0) {
130
+ if (!rootAgent && subAgents.length > 0) {
108
131
  imports.push('import { useA2A } from "aixyz/server/adapters/a2a";');
109
132
  }
110
133
  for (const subAgent of subAgents) {
@@ -112,16 +135,7 @@ function generateServer(appDir: string, entrypointDir: string): string {
112
135
  }
113
136
 
114
137
  const toolsDir = resolve(appDir, "tools");
115
- const tools: { name: string; identifier: string }[] = [];
116
- if (existsSync(toolsDir)) {
117
- for (const file of readdirSync(toolsDir)) {
118
- if (glob.includes(`tools/${file}`)) {
119
- const name = basename(file, ".ts");
120
- const identifier = toIdentifier(name);
121
- tools.push({ name, identifier });
122
- }
123
- }
124
- }
138
+ const tools = glob.getTools(toolsDir);
125
139
 
126
140
  if (tools.length > 0) {
127
141
  imports.push('import { AixyzMCP } from "aixyz/server/adapters/mcp";');
@@ -134,7 +148,7 @@ function generateServer(appDir: string, entrypointDir: string): string {
134
148
  body.push("await server.initialize();");
135
149
  body.push("server.unstable_withIndexPage();");
136
150
 
137
- if (hasAgent) {
151
+ if (rootAgent) {
138
152
  body.push("useA2A(server, agent);");
139
153
  }
140
154
 
@@ -155,7 +169,7 @@ function generateServer(appDir: string, entrypointDir: string): string {
155
169
  imports.push('import { useERC8004 } from "aixyz/server/adapters/erc-8004";');
156
170
  imports.push(`import * as erc8004 from "${importPrefix}/erc-8004";`);
157
171
  const a2aPaths: string[] = [];
158
- if (hasAgent) a2aPaths.push("/.well-known/agent-card.json");
172
+ if (rootAgent) a2aPaths.push("/.well-known/agent-card.json");
159
173
  for (const subAgent of subAgents) a2aPaths.push(`/${subAgent.name}/.well-known/agent-card.json`);
160
174
  body.push(
161
175
  `useERC8004(server, { default: erc8004.default, options: { mcp: ${tools.length > 0}, a2a: ${JSON.stringify(a2aPaths)} } });`,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aixyz/cli",
3
- "version": "0.12.0",
3
+ "version": "0.13.0",
4
4
  "description": "Payment-native SDK for AI Agent",
5
5
  "keywords": [
6
6
  "ai",
@@ -27,8 +27,8 @@
27
27
  "bin.ts"
28
28
  ],
29
29
  "dependencies": {
30
- "@aixyz/config": "0.12.0",
31
- "@aixyz/erc-8004": "0.12.0",
30
+ "@aixyz/config": "0.13.0",
31
+ "@aixyz/erc-8004": "0.13.0",
32
32
  "@inquirer/prompts": "^8.3.0",
33
33
  "@next/env": "^16.1.6",
34
34
  "boxen": "^8.0.1",