@aixyz/config 0.0.0 → 0.1.1

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.
Files changed (2) hide show
  1. package/index.ts +114 -0
  2. package/package.json +29 -3
package/index.ts ADDED
@@ -0,0 +1,114 @@
1
+ import { resolve } from "path";
2
+ import { loadEnvConfig } from "@next/env";
3
+
4
+ import { z } from "zod";
5
+
6
+ export type Network = `${string}:${string}`;
7
+
8
+ export type AixyzConfig = {
9
+ name: string;
10
+ description: string;
11
+ /**
12
+ * Version of the agent.
13
+ */
14
+ version: string;
15
+ url?: string;
16
+ x402: {
17
+ /**
18
+ * The address that will receive the payment from the agent.
19
+ * Defaults to `process.env.X402_PAY_TO` if not set.
20
+ * Throws an error if neither is provided.
21
+ */
22
+ payTo: string;
23
+ /**
24
+ * The x402 network to use for the agent.
25
+ */
26
+ network: string;
27
+ };
28
+ skills: GetAixyzConfig["skills"];
29
+ };
30
+
31
+ const NetworkSchema = z.custom<Network>((val) => {
32
+ return typeof val === "string" && val.includes(":");
33
+ });
34
+
35
+ const AixyzConfigSchema = z.object({
36
+ name: z.string().nonempty(),
37
+ description: z.string().nonempty(),
38
+ version: z.string().nonempty(),
39
+ url: z
40
+ .string()
41
+ .optional()
42
+ .transform((val) => {
43
+ if (val) {
44
+ return val;
45
+ }
46
+ if (process.env.VERCEL_ENV === "production" && process.env.VERCEL_PROJECT_PRODUCTION_URL) {
47
+ return `https://${process.env.VERCEL_PROJECT_PRODUCTION_URL}/`;
48
+ }
49
+
50
+ if (process.env.VERCEL_URL) {
51
+ return `https://${process.env.VERCEL_URL}/`;
52
+ }
53
+
54
+ return `http://localhost:3000/`;
55
+ })
56
+ .pipe(z.url()),
57
+ x402: z.object({
58
+ payTo: z.string(),
59
+ network: NetworkSchema,
60
+ }),
61
+ skills: z.array(
62
+ z.object({
63
+ id: z.string().nonempty(),
64
+ name: z.string().nonempty(),
65
+ description: z.string().nonempty(),
66
+ tags: z.array(z.string()),
67
+ examples: z.array(z.string()).optional(),
68
+ inputModes: z.array(z.string()).optional(),
69
+ outputModes: z.array(z.string()).optional(),
70
+ security: z.array(z.record(z.string(), z.array(z.string()))).optional(),
71
+ }),
72
+ ),
73
+ });
74
+
75
+ /**
76
+ * This is the materialized config object that is cached for performance.
77
+ * It is the result of parsing and validating the user's `aixyz.config.ts` file,
78
+ * with environment variables loaded and applied.
79
+ */
80
+ export type GetAixyzConfig = z.infer<typeof AixyzConfigSchema>;
81
+
82
+ /**
83
+ * Environment variables are looked up in the following places, in order, stopping once the variable is found.
84
+ * 1. `process.env`
85
+ * 2. `.env.$(NODE_ENV).local`
86
+ * 3. `.env.local (Not checked when NODE_ENV is test.)`
87
+ * 4. `.env.$(NODE_ENV)`
88
+ * 5. `.env`
89
+ *
90
+ * For example, if `NODE_ENV` is `development` and you define a variable in both `.env.development.local` and `.env,
91
+ * the value in `.env.development.local` will be used.
92
+ *
93
+ * In production:
94
+ * This is a materialized config object that is cached for performance.
95
+ */
96
+ export function getAixyzConfig(): GetAixyzConfig {
97
+ const cwd = process.cwd();
98
+ loadEnvConfig(cwd);
99
+
100
+ const configPath = resolve(cwd, "aixyz.config.ts");
101
+ const mod = require(configPath);
102
+ const config = mod.default;
103
+
104
+ if (!config || typeof config !== "object") {
105
+ throw new Error(`aixyz.config.ts must have a default export`);
106
+ }
107
+
108
+ const parsedConfig = AixyzConfigSchema.safeParse(config);
109
+ if (!parsedConfig.success) {
110
+ throw new Error(`aixyz.config.ts: ${parsedConfig.error}`);
111
+ }
112
+
113
+ return parsedConfig.data as GetAixyzConfig;
114
+ }
package/package.json CHANGED
@@ -1,6 +1,32 @@
1
1
  {
2
2
  "name": "@aixyz/config",
3
- "version": "0.0.0",
4
- "private": false,
5
- "files": []
3
+ "version": "0.1.1",
4
+ "description": "",
5
+ "keywords": [
6
+ "ai",
7
+ "agent",
8
+ "a2a",
9
+ "mcp",
10
+ "x402",
11
+ "erc-8004",
12
+ "framework"
13
+ ],
14
+ "homepage": "https://ai-xyz.dev",
15
+ "bugs": {
16
+ "url": "https://github.com/AgentlyHQ/aixyz/issues"
17
+ },
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "git+https://github.com/AgentlyHQ/aixyz.git"
21
+ },
22
+ "license": "MIT",
23
+ "author": "AgentlyHQ",
24
+ "type": "module",
25
+ "files": [
26
+ "**/*.ts"
27
+ ],
28
+ "dependencies": {
29
+ "@next/env": "^16.1.6",
30
+ "zod": "^4.3.6"
31
+ }
6
32
  }