uaibuilder 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.
Files changed (2) hide show
  1. package/index.mjs +193 -0
  2. package/package.json +15 -0
package/index.mjs ADDED
@@ -0,0 +1,193 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { readFileSync, writeFileSync, existsSync, mkdirSync } from 'node:fs';
4
+ import { resolve, join } from 'node:path';
5
+ import { homedir } from 'node:os';
6
+
7
+ const HELP = `
8
+ UaiBuilder CLI — connect your AI to UaiBuilder via MCP
9
+
10
+ Usage:
11
+ npx uaibuilder setup --token=<MCP_TOKEN> Configure Claude Code to use UaiBuilder
12
+ npx uaibuilder setup --token=<MCP_TOKEN> --provider=cursor Configure Cursor
13
+ npx uaibuilder remove Remove UaiBuilder from AI config
14
+ npx uaibuilder status Check current configuration
15
+
16
+ Get your token at https://uaibuilder.com/app
17
+ `;
18
+
19
+ const args = process.argv.slice(2);
20
+ const command = args[0];
21
+
22
+ function parseFlags(args) {
23
+ const flags = {};
24
+ for (const arg of args) {
25
+ const match = arg.match(/^--([a-z-]+)=(.+)$/);
26
+ if (match) flags[match[1]] = match[2];
27
+ else if (arg.startsWith('--')) flags[arg.slice(2)] = true;
28
+ }
29
+ return flags;
30
+ }
31
+
32
+ // ─── Config paths per provider ────────────────────────
33
+
34
+ function getConfigPath(provider) {
35
+ const home = homedir();
36
+ switch (provider) {
37
+ case 'claude':
38
+ return join(home, '.claude', 'settings.json');
39
+ case 'cursor':
40
+ // Cursor uses .cursor/mcp.json
41
+ return join(home, '.cursor', 'mcp.json');
42
+ case 'windsurf':
43
+ return join(home, '.codeium', 'windsurf', 'mcp_config.json');
44
+ default:
45
+ return join(home, '.claude', 'settings.json');
46
+ }
47
+ }
48
+
49
+ function getConfigTemplate(provider) {
50
+ // Claude Code uses "mcpServers" at root
51
+ // Cursor/Windsurf use "mcpServers" at root too
52
+ return provider;
53
+ }
54
+
55
+ // ─── MCP server entry ─────────────────────────────────
56
+
57
+ function buildMcpEntry(token) {
58
+ return {
59
+ type: 'http',
60
+ url: 'https://uaibuilder.com/api/mcp',
61
+ headers: {
62
+ Authorization: `Bearer ${token}`,
63
+ },
64
+ };
65
+ }
66
+
67
+ // ─── Read/Write config safely ─────────────────────────
68
+
69
+ function readConfig(path) {
70
+ if (!existsSync(path)) return {};
71
+ try {
72
+ return JSON.parse(readFileSync(path, 'utf-8'));
73
+ } catch {
74
+ console.error(` Warning: ${path} has invalid JSON. Creating backup.`);
75
+ writeFileSync(path + '.bak', readFileSync(path));
76
+ return {};
77
+ }
78
+ }
79
+
80
+ function writeConfig(path, config) {
81
+ const dir = resolve(path, '..');
82
+ if (!existsSync(dir)) mkdirSync(dir, { recursive: true });
83
+ writeFileSync(path, JSON.stringify(config, null, 2) + '\n');
84
+ }
85
+
86
+ // ─── Commands ─────────────────────────────────────────
87
+
88
+ function setup(flags) {
89
+ const token = flags.token;
90
+ if (!token) {
91
+ console.error('\n Error: --token is required\n');
92
+ console.log(' Get your token at https://uaibuilder.com/app\n');
93
+ console.log(' Usage: npx uaibuilder setup --token=YOUR_TOKEN\n');
94
+ process.exit(1);
95
+ }
96
+
97
+ const provider = flags.provider || 'claude';
98
+ const configPath = getConfigPath(provider);
99
+ const config = readConfig(configPath);
100
+
101
+ // Ensure mcpServers exists
102
+ if (!config.mcpServers) config.mcpServers = {};
103
+
104
+ // Add/update UaiBuilder entry
105
+ config.mcpServers.uaibuilder = buildMcpEntry(token);
106
+
107
+ // For Claude Code, also ensure enabledMcpjsonServers includes uaibuilder
108
+ if (provider === 'claude') {
109
+ if (!Array.isArray(config.enabledMcpjsonServers)) {
110
+ config.enabledMcpjsonServers = [];
111
+ }
112
+ if (!config.enabledMcpjsonServers.includes('uaibuilder')) {
113
+ config.enabledMcpjsonServers.push('uaibuilder');
114
+ }
115
+ }
116
+
117
+ writeConfig(configPath, config);
118
+
119
+ console.log(`
120
+ UaiBuilder configured for ${provider}!
121
+
122
+ Config: ${configPath}
123
+ Server: uaibuilder (MCP HTTP)
124
+
125
+ Next steps:
126
+ ${provider === 'claude' ? ' 1. Restart Claude Code (close and reopen)' : ' 1. Restart your editor'}
127
+ 2. Ask your AI: "Cria um app de tarefas com auth e deploy"
128
+ 3. Watch it build
129
+
130
+ Dashboard: https://uaibuilder.com/app
131
+ `);
132
+ }
133
+
134
+ function remove(flags) {
135
+ const provider = flags.provider || 'claude';
136
+ const configPath = getConfigPath(provider);
137
+ const config = readConfig(configPath);
138
+
139
+ if (config.mcpServers?.uaibuilder) {
140
+ delete config.mcpServers.uaibuilder;
141
+ }
142
+ if (Array.isArray(config.enabledMcpjsonServers)) {
143
+ config.enabledMcpjsonServers = config.enabledMcpjsonServers.filter(s => s !== 'uaibuilder');
144
+ }
145
+
146
+ writeConfig(configPath, config);
147
+ console.log(`\n UaiBuilder removed from ${provider}.\n`);
148
+ }
149
+
150
+ function status(flags) {
151
+ const provider = flags.provider || 'claude';
152
+ const configPath = getConfigPath(provider);
153
+
154
+ if (!existsSync(configPath)) {
155
+ console.log(`\n No config found at ${configPath}\n Run: npx uaibuilder setup --token=YOUR_TOKEN\n`);
156
+ return;
157
+ }
158
+
159
+ const config = readConfig(configPath);
160
+ const entry = config.mcpServers?.uaibuilder;
161
+
162
+ if (!entry) {
163
+ console.log(`\n UaiBuilder not configured in ${provider}.\n Run: npx uaibuilder setup --token=YOUR_TOKEN\n`);
164
+ return;
165
+ }
166
+
167
+ console.log(`
168
+ UaiBuilder is configured for ${provider}
169
+
170
+ Config: ${configPath}
171
+ Type: ${entry.type || 'stdio'}
172
+ URL: ${entry.url || 'local'}
173
+ Token: ${entry.headers?.Authorization ? entry.headers.Authorization.slice(0, 25) + '...' : 'none'}
174
+ `);
175
+ }
176
+
177
+ // ─── Main ─────────────────────────────────────────────
178
+
179
+ const flags = parseFlags(args.slice(1));
180
+
181
+ switch (command) {
182
+ case 'setup':
183
+ setup(flags);
184
+ break;
185
+ case 'remove':
186
+ remove(flags);
187
+ break;
188
+ case 'status':
189
+ status(flags);
190
+ break;
191
+ default:
192
+ console.log(HELP);
193
+ }
package/package.json ADDED
@@ -0,0 +1,15 @@
1
+ {
2
+ "name": "uaibuilder",
3
+ "version": "0.1.0",
4
+ "description": "UaiBuilder CLI — connect any AI to your apps via MCP",
5
+ "bin": {
6
+ "uaibuilder": "./index.mjs"
7
+ },
8
+ "type": "module",
9
+ "license": "MIT",
10
+ "keywords": ["uaibuilder", "mcp", "ai", "paas", "cloudflare"],
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "https://github.com/UaiBuilder/uaibuilder"
14
+ }
15
+ }