calabasas 0.1.7 → 0.1.9
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/dist/index.js +87 -43
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2623,39 +2623,47 @@ import * as fs from "fs";
|
|
|
2623
2623
|
import * as path from "path";
|
|
2624
2624
|
import * as os from "os";
|
|
2625
2625
|
var CONFIG_DIR = path.join(os.homedir(), ".calabasas");
|
|
2626
|
-
|
|
2626
|
+
function getConfigFile(env) {
|
|
2627
|
+
if (env === "dev")
|
|
2628
|
+
return path.join(CONFIG_DIR, "config.dev.json");
|
|
2629
|
+
return path.join(CONFIG_DIR, "config.json");
|
|
2630
|
+
}
|
|
2627
2631
|
var PROD_API_URL = "https://savory-llama-364.convex.site";
|
|
2628
2632
|
var DEV_API_URL = "https://notable-monitor-41.convex.site";
|
|
2629
|
-
|
|
2633
|
+
var PROD_WEB_URL = "https://calabasas-web.vercel.app";
|
|
2634
|
+
var DEV_WEB_URL = "http://localhost:3000";
|
|
2635
|
+
function getConfig(env) {
|
|
2630
2636
|
try {
|
|
2631
|
-
|
|
2637
|
+
const configFile = getConfigFile(env);
|
|
2638
|
+
if (!fs.existsSync(configFile)) {
|
|
2632
2639
|
return {};
|
|
2633
2640
|
}
|
|
2634
|
-
const content = fs.readFileSync(
|
|
2641
|
+
const content = fs.readFileSync(configFile, "utf-8");
|
|
2635
2642
|
return JSON.parse(content);
|
|
2636
2643
|
} catch {
|
|
2637
2644
|
return {};
|
|
2638
2645
|
}
|
|
2639
2646
|
}
|
|
2640
|
-
function saveConfig(config) {
|
|
2641
|
-
const existing = getConfig();
|
|
2647
|
+
function saveConfig(config, env) {
|
|
2648
|
+
const existing = getConfig(env);
|
|
2642
2649
|
const merged = { ...existing, ...config };
|
|
2643
2650
|
if (!fs.existsSync(CONFIG_DIR)) {
|
|
2644
2651
|
fs.mkdirSync(CONFIG_DIR, { recursive: true });
|
|
2645
2652
|
}
|
|
2646
|
-
fs.writeFileSync(
|
|
2653
|
+
fs.writeFileSync(getConfigFile(env), JSON.stringify(merged, null, 2));
|
|
2647
2654
|
}
|
|
2648
|
-
function clearConfig() {
|
|
2649
|
-
|
|
2650
|
-
|
|
2655
|
+
function clearConfig(env) {
|
|
2656
|
+
const configFile = getConfigFile(env);
|
|
2657
|
+
if (fs.existsSync(configFile)) {
|
|
2658
|
+
fs.unlinkSync(configFile);
|
|
2651
2659
|
}
|
|
2652
2660
|
}
|
|
2653
|
-
function isAuthenticated() {
|
|
2654
|
-
const config = getConfig();
|
|
2661
|
+
function isAuthenticated(env) {
|
|
2662
|
+
const config = getConfig(env);
|
|
2655
2663
|
return !!config.apiKey;
|
|
2656
2664
|
}
|
|
2657
|
-
function getApiUrl() {
|
|
2658
|
-
const config = getConfig();
|
|
2665
|
+
function getApiUrl(env) {
|
|
2666
|
+
const config = getConfig(env);
|
|
2659
2667
|
return config.apiUrl || PROD_API_URL;
|
|
2660
2668
|
}
|
|
2661
2669
|
function getApiUrlForEnv(env) {
|
|
@@ -2665,11 +2673,21 @@ function getApiUrlForEnv(env) {
|
|
|
2665
2673
|
return PROD_API_URL;
|
|
2666
2674
|
return getApiUrl();
|
|
2667
2675
|
}
|
|
2676
|
+
function getWebUrlForEnv(env) {
|
|
2677
|
+
if (env === "dev")
|
|
2678
|
+
return DEV_WEB_URL;
|
|
2679
|
+
return PROD_WEB_URL;
|
|
2680
|
+
}
|
|
2668
2681
|
|
|
2669
2682
|
// src/commands/login.ts
|
|
2670
2683
|
var CALLBACK_PORT = 9876;
|
|
2671
|
-
async function login() {
|
|
2672
|
-
|
|
2684
|
+
async function login(options) {
|
|
2685
|
+
if (options.dev && options.prod) {
|
|
2686
|
+
console.error("Error: Cannot use both --dev and --prod flags.");
|
|
2687
|
+
process.exit(1);
|
|
2688
|
+
}
|
|
2689
|
+
const env = options.dev ? "dev" : options.prod ? "prod" : undefined;
|
|
2690
|
+
const existing = getConfig(env);
|
|
2673
2691
|
if (existing.apiKey) {
|
|
2674
2692
|
console.log("You are already logged in.");
|
|
2675
2693
|
console.log(`API Key: ${existing.apiKey.slice(0, 8)}...`);
|
|
@@ -2684,7 +2702,7 @@ async function login() {
|
|
|
2684
2702
|
if (url.pathname === "/callback") {
|
|
2685
2703
|
const apiKey = url.searchParams.get("key");
|
|
2686
2704
|
if (apiKey) {
|
|
2687
|
-
saveConfig({ apiKey });
|
|
2705
|
+
saveConfig({ apiKey }, env);
|
|
2688
2706
|
res.writeHead(200, { "Content-Type": "text/html" });
|
|
2689
2707
|
res.end(`
|
|
2690
2708
|
<!DOCTYPE html>
|
|
@@ -2735,7 +2753,7 @@ async function login() {
|
|
|
2735
2753
|
}
|
|
2736
2754
|
});
|
|
2737
2755
|
server.listen(CALLBACK_PORT, async () => {
|
|
2738
|
-
const authUrl =
|
|
2756
|
+
const authUrl = `${getWebUrlForEnv(env)}/auth/cli?callback=http://localhost:${CALLBACK_PORT}/callback`;
|
|
2739
2757
|
console.log("If the browser doesn't open automatically, visit:");
|
|
2740
2758
|
console.log(` ${authUrl}
|
|
2741
2759
|
`);
|
|
@@ -2757,9 +2775,15 @@ Authentication timed out. Please try again.`);
|
|
|
2757
2775
|
}
|
|
2758
2776
|
|
|
2759
2777
|
// src/commands/logout.ts
|
|
2760
|
-
async function logout() {
|
|
2761
|
-
|
|
2762
|
-
|
|
2778
|
+
async function logout(options) {
|
|
2779
|
+
if (options.dev && options.prod) {
|
|
2780
|
+
console.error("Error: Cannot use both --dev and --prod flags.");
|
|
2781
|
+
process.exit(1);
|
|
2782
|
+
}
|
|
2783
|
+
const env = options.dev ? "dev" : options.prod ? "prod" : undefined;
|
|
2784
|
+
clearConfig(env);
|
|
2785
|
+
const label = env ?? "prod";
|
|
2786
|
+
console.log(`✅ Logged out of ${label} successfully. Credentials cleared.`);
|
|
2763
2787
|
}
|
|
2764
2788
|
|
|
2765
2789
|
// src/commands/init.ts
|
|
@@ -2900,11 +2924,11 @@ async function push(options) {
|
|
|
2900
2924
|
console.error("Run `calabasas init` to create a calabasas.config.ts file.");
|
|
2901
2925
|
process.exit(1);
|
|
2902
2926
|
}
|
|
2903
|
-
if (!isAuthenticated()) {
|
|
2927
|
+
if (!isAuthenticated(env)) {
|
|
2904
2928
|
console.error("Error: Not authenticated. Run `calabasas login` first.");
|
|
2905
2929
|
process.exit(1);
|
|
2906
2930
|
}
|
|
2907
|
-
const config = getConfig();
|
|
2931
|
+
const config = getConfig(env);
|
|
2908
2932
|
const apiKey = config.apiKey;
|
|
2909
2933
|
let botId = options.bot;
|
|
2910
2934
|
if (!botId) {
|
|
@@ -5286,9 +5310,9 @@ Selected intents value: ${total}`);
|
|
|
5286
5310
|
process.stdin.on("data", onKeypress);
|
|
5287
5311
|
});
|
|
5288
5312
|
}
|
|
5289
|
-
async function apiRequest(method, path8, body) {
|
|
5290
|
-
const config = getConfig();
|
|
5291
|
-
const url = `${
|
|
5313
|
+
async function apiRequest(method, path8, body, env) {
|
|
5314
|
+
const config = getConfig(env);
|
|
5315
|
+
const url = `${getApiUrlForEnv(env)}${path8}`;
|
|
5292
5316
|
const response = await fetch(url, {
|
|
5293
5317
|
method,
|
|
5294
5318
|
headers: {
|
|
@@ -5300,8 +5324,13 @@ async function apiRequest(method, path8, body) {
|
|
|
5300
5324
|
const data = await response.json();
|
|
5301
5325
|
return { ok: response.ok, data, status: response.status };
|
|
5302
5326
|
}
|
|
5303
|
-
async function botAdd() {
|
|
5304
|
-
if (
|
|
5327
|
+
async function botAdd(options) {
|
|
5328
|
+
if (options.dev && options.prod) {
|
|
5329
|
+
console.error("Error: Cannot use both --dev and --prod flags.");
|
|
5330
|
+
process.exit(1);
|
|
5331
|
+
}
|
|
5332
|
+
const env = options.dev ? "dev" : options.prod ? "prod" : undefined;
|
|
5333
|
+
if (!isAuthenticated(env)) {
|
|
5305
5334
|
console.log("Not logged in. Run `calabasas login` first.");
|
|
5306
5335
|
return;
|
|
5307
5336
|
}
|
|
@@ -5339,7 +5368,7 @@ async function botAdd() {
|
|
|
5339
5368
|
intents,
|
|
5340
5369
|
convexUrl: convexUrl.trim(),
|
|
5341
5370
|
sharedSecret
|
|
5342
|
-
});
|
|
5371
|
+
}, env);
|
|
5343
5372
|
if (!ok) {
|
|
5344
5373
|
console.log(`
|
|
5345
5374
|
Failed to create bot: ${data.error || `HTTP ${status}`}`);
|
|
@@ -5356,12 +5385,17 @@ Failed to create bot: ${data.error || `HTTP ${status}`}`);
|
|
|
5356
5385
|
console.log("2. Create your handler in convex/discord.ts");
|
|
5357
5386
|
console.log("3. Add CALABASAS_SECRET to your Convex environment variables");
|
|
5358
5387
|
}
|
|
5359
|
-
async function botList() {
|
|
5360
|
-
if (
|
|
5388
|
+
async function botList(options) {
|
|
5389
|
+
if (options.dev && options.prod) {
|
|
5390
|
+
console.error("Error: Cannot use both --dev and --prod flags.");
|
|
5391
|
+
process.exit(1);
|
|
5392
|
+
}
|
|
5393
|
+
const env = options.dev ? "dev" : options.prod ? "prod" : undefined;
|
|
5394
|
+
if (!isAuthenticated(env)) {
|
|
5361
5395
|
console.log("Not logged in. Run `calabasas login` first.");
|
|
5362
5396
|
return;
|
|
5363
5397
|
}
|
|
5364
|
-
const { ok, data, status } = await apiRequest("GET", "/api/cli/bots");
|
|
5398
|
+
const { ok, data, status } = await apiRequest("GET", "/api/cli/bots", undefined, env);
|
|
5365
5399
|
if (!ok) {
|
|
5366
5400
|
console.log(`Failed to list bots: ${data.error || `HTTP ${status}`}`);
|
|
5367
5401
|
return;
|
|
@@ -5383,8 +5417,13 @@ async function botList() {
|
|
|
5383
5417
|
console.log("");
|
|
5384
5418
|
}
|
|
5385
5419
|
}
|
|
5386
|
-
async function botRemove(botId) {
|
|
5387
|
-
if (
|
|
5420
|
+
async function botRemove(botId, options) {
|
|
5421
|
+
if (options.dev && options.prod) {
|
|
5422
|
+
console.error("Error: Cannot use both --dev and --prod flags.");
|
|
5423
|
+
process.exit(1);
|
|
5424
|
+
}
|
|
5425
|
+
const env = options.dev ? "dev" : options.prod ? "prod" : undefined;
|
|
5426
|
+
if (!isAuthenticated(env)) {
|
|
5388
5427
|
console.log("Not logged in. Run `calabasas login` first.");
|
|
5389
5428
|
return;
|
|
5390
5429
|
}
|
|
@@ -5393,7 +5432,7 @@ async function botRemove(botId) {
|
|
|
5393
5432
|
console.log("Cancelled.");
|
|
5394
5433
|
return;
|
|
5395
5434
|
}
|
|
5396
|
-
const { ok, data, status } = await apiRequest("DELETE", `/api/cli/bots?id=${botId}
|
|
5435
|
+
const { ok, data, status } = await apiRequest("DELETE", `/api/cli/bots?id=${botId}`, undefined, env);
|
|
5397
5436
|
if (!ok) {
|
|
5398
5437
|
console.log(`Failed to remove bot: ${data.error || `HTTP ${status}`}`);
|
|
5399
5438
|
return;
|
|
@@ -5401,7 +5440,12 @@ async function botRemove(botId) {
|
|
|
5401
5440
|
console.log("✅ Bot removed successfully!");
|
|
5402
5441
|
}
|
|
5403
5442
|
async function botEdit(botId, options) {
|
|
5404
|
-
if (
|
|
5443
|
+
if (options.dev && options.prod) {
|
|
5444
|
+
console.error("Error: Cannot use both --dev and --prod flags.");
|
|
5445
|
+
process.exit(1);
|
|
5446
|
+
}
|
|
5447
|
+
const env = options.dev ? "dev" : options.prod ? "prod" : undefined;
|
|
5448
|
+
if (!isAuthenticated(env)) {
|
|
5405
5449
|
console.log("Not logged in. Run `calabasas login` first.");
|
|
5406
5450
|
return;
|
|
5407
5451
|
}
|
|
@@ -5430,7 +5474,7 @@ async function botEdit(botId, options) {
|
|
|
5430
5474
|
return;
|
|
5431
5475
|
}
|
|
5432
5476
|
console.log("Updating bot...");
|
|
5433
|
-
const { ok, data, status } = await apiRequest("PATCH", "/api/cli/bots", updates);
|
|
5477
|
+
const { ok, data, status } = await apiRequest("PATCH", "/api/cli/bots", updates, env);
|
|
5434
5478
|
if (!ok) {
|
|
5435
5479
|
console.log(`Failed to update bot: ${data.error || `HTTP ${status}`}`);
|
|
5436
5480
|
return;
|
|
@@ -5443,16 +5487,16 @@ async function botEdit(botId, options) {
|
|
|
5443
5487
|
// src/index.ts
|
|
5444
5488
|
var program2 = new Command;
|
|
5445
5489
|
program2.name("calabasas").description("CLI for Calabasas - Discord Gateway as a Service for Convex").version("0.0.1");
|
|
5446
|
-
program2.command("login").description("Authenticate with Calabasas using your API key").action(login);
|
|
5447
|
-
program2.command("logout").description("Clear stored credentials").action(logout);
|
|
5490
|
+
program2.command("login").description("Authenticate with Calabasas using your API key").option("--dev", "Use development environment").option("--prod", "Use production environment").action(login);
|
|
5491
|
+
program2.command("logout").description("Clear stored credentials").option("--dev", "Use development environment").option("--prod", "Use production environment").action(logout);
|
|
5448
5492
|
program2.command("init").description("Initialize Calabasas config in your Convex project").action(init);
|
|
5449
5493
|
program2.command("push").description("Push your calabasas.config.ts to Calabasas").option("-c, --config <path>", "Path to config file", "convex/calabasas.config.ts").option("-b, --bot <botId>", "Bot ID to configure (prompts if not specified)").option("--dev", "Push to development environment").option("--prod", "Push to production environment").action(push);
|
|
5450
5494
|
program2.command("generate").description("Generate discord.generated.ts with type-safe handlers").option("-o, --output <path>", "Output path", "convex/discord.generated.ts").action(generate);
|
|
5451
5495
|
program2.command("skill").description("Generate Calabasas documentation for AI assistants").action(skill);
|
|
5452
5496
|
program2.command("add [components...]").description("Add Discord UI components to your project").action(add);
|
|
5453
5497
|
var bot = program2.command("bot").description("Manage Discord bots");
|
|
5454
|
-
bot.command("add").description("Add a new Discord bot").action(botAdd);
|
|
5455
|
-
bot.command("list").alias("ls").description("List your Discord bots").action(botList);
|
|
5456
|
-
bot.command("remove <botId>").alias("rm").description("Remove a Discord bot").action(botRemove);
|
|
5457
|
-
bot.command("edit <botId>").description("Edit a Discord bot").option("-n, --name <name>", "New bot name").option("-u, --url <url>", "New Convex URL").option("-t, --token <token>", "New bot token").option("-i, --intents <intents>", "New intents value").action(botEdit);
|
|
5498
|
+
bot.command("add").description("Add a new Discord bot").option("--dev", "Use development environment").option("--prod", "Use production environment").action(botAdd);
|
|
5499
|
+
bot.command("list").alias("ls").description("List your Discord bots").option("--dev", "Use development environment").option("--prod", "Use production environment").action(botList);
|
|
5500
|
+
bot.command("remove <botId>").alias("rm").description("Remove a Discord bot").option("--dev", "Use development environment").option("--prod", "Use production environment").action(botRemove);
|
|
5501
|
+
bot.command("edit <botId>").description("Edit a Discord bot").option("-n, --name <name>", "New bot name").option("-u, --url <url>", "New Convex URL").option("-t, --token <token>", "New bot token").option("-i, --intents <intents>", "New intents value").option("--dev", "Use development environment").option("--prod", "Use production environment").action(botEdit);
|
|
5458
5502
|
program2.parse();
|