@nexusbloom/cli 0.1.9 → 0.1.10

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/package.json +1 -1
  2. package/src/index.js +61 -21
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nexusbloom/cli",
3
- "version": "0.1.9",
3
+ "version": "0.1.10",
4
4
  "description": "NexusBloom CLI — run tools and workflows from your terminal",
5
5
  "type": "module",
6
6
  "bin": {
package/src/index.js CHANGED
@@ -290,35 +290,75 @@ async function executeLocal(slug, input, jsonMode) {
290
290
  // Fetch from API if not cached
291
291
  if (!manifest || !coreLogicSource) {
292
292
  if (!jsonMode) console.log(chalk.dim(` Fetching tool: ${slug}...`));
293
+
294
+ // Try API first
295
+ let apiSuccess = false;
293
296
  try {
294
297
  const res = await fetch(`${API_BASE}/api/run/${slug}`);
295
- if (!res.ok) {
296
- if (jsonMode) return console.log(JSON.stringify({ error: `Tool "${slug}" not found` }));
297
- console.error(chalk.red(`Tool "${slug}" not found.`));
298
- process.exit(1);
298
+ if (res.ok) {
299
+ const data = await res.json();
300
+ manifest = data.data?.manifest || data.manifest || data;
301
+
302
+ const sourceRes = await fetch(`${API_BASE}/api/run/${slug}?source=true`);
303
+ if (sourceRes.ok) {
304
+ const sourceData = await sourceRes.json();
305
+ coreLogicSource = sourceData.data?.v2_source;
306
+ }
307
+ apiSuccess = true;
299
308
  }
300
- const data = await res.json();
301
- manifest = data.data?.manifest || data.manifest || data;
309
+ } catch {
310
+ // API failed, try Supabase fallback
311
+ }
302
312
 
303
- // Fetch the v2 source separately
304
- const sourceRes = await fetch(`${API_BASE}/api/run/${slug}?source=true`);
305
- if (sourceRes.ok) {
306
- const sourceData = await sourceRes.json();
307
- coreLogicSource = sourceData.data?.v2_source;
308
- } else {
309
- coreLogicSource = null;
313
+ // Fallback: query Supabase directly for v2_source
314
+ if (!apiSuccess) {
315
+ try {
316
+ const supabaseUrl = process.env.NEXUSBLOOM_SUPABASE_URL || "https://dhxaqatmuprehrkszxzs.supabase.co";
317
+ const supabaseKey = process.env.NEXUSBLOOM_SUPABASE_ANON_KEY;
318
+ if (supabaseKey) {
319
+ // Get tool from tools table
320
+ const toolRes = await fetch(`${supabaseUrl}/rest/v1/tools?slug=eq.${slug}&select=id`, {
321
+ headers: { apikey: supabaseKey, Authorization: `Bearer ${supabaseKey}` }
322
+ });
323
+ const tools = await toolRes.json();
324
+ const toolId = tools?.[0]?.id;
325
+ if (toolId) {
326
+ // Get v2_source from tool_versions
327
+ const versionRes = await fetch(
328
+ `${supabaseUrl}/rest/v1/tool_versions?tool_id=eq.${toolId}&tool_type=eq.builtin&status=eq.published&select=v2_source&order=created_at.desc&limit=1`,
329
+ { headers: { apikey: supabaseKey, Authorization: `Bearer ${supabaseKey}` } }
330
+ );
331
+ const versions = await versionRes.json();
332
+ const v2Source = versions?.[0]?.v2_source;
333
+ if (v2Source) {
334
+ coreLogicSource = v2Source;
335
+ const manifestMatch = v2Source.match(/export\s+const\s+MANIFEST\s*=\s*({[\s\S]*?});\s*\n/);
336
+ if (manifestMatch) {
337
+ try {
338
+ manifest = JSON.parse(manifestMatch[1].replace(/(\w+):/g, '"$1":').replace(/'/g, '"'));
339
+ } catch {
340
+ manifest = eval("(" + manifestMatch[1] + ")");
341
+ }
342
+ }
343
+ apiSuccess = true;
344
+ }
345
+ }
346
+ }
347
+ } catch {
348
+ // Supabase fallback also failed
310
349
  }
350
+ }
311
351
 
312
- // Cache it
313
- if (manifest) {
314
- fs.writeFileSync(cacheFile, JSON.stringify({ manifest, coreLogicSource, cachedAt: new Date().toISOString() }), "utf-8");
315
- }
316
- } catch (err) {
317
- if (jsonMode) return console.log(JSON.stringify({ error: `Failed to fetch tool: ${err.message}` }));
318
- console.error(chalk.red(`Failed to fetch tool: ${err.message}`));
352
+ if (!apiSuccess) {
353
+ if (jsonMode) return console.log(JSON.stringify({ error: `Tool "${slug}" not found. Ensure API is deployed or set NEXUSBLOOM_SUPABASE_ANON_KEY for local mode.` }));
354
+ console.error(chalk.red(`Tool "${slug}" not found. Ensure API is deployed or set NEXUSBLOOM_SUPABASE_ANON_KEY for local mode.`));
319
355
  process.exit(1);
320
356
  }
321
- }
357
+
358
+ // Cache it
359
+ if (manifest) {
360
+ fs.writeFileSync(cacheFile, JSON.stringify({ manifest, coreLogicSource, cachedAt: new Date().toISOString() }), "utf-8");
361
+ }
322
362
 
323
363
  if (!coreLogicSource) {
324
364
  // Fallback: try to extract coreLogic from the manifest itself