UNPKG

mindstudio

Version:

Client library for MindStudio AI Workers

62 lines (61 loc) • 3.09 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ListCommand = void 0; const keyManager_1 = require("../../core/auth/keyManager"); const nameFormatter_1 = require("../../core/utils/nameFormatter"); const discovery_1 = require("../services/discovery"); const base_1 = require("./base"); class ListCommand extends base_1.BaseCommand { constructor(configManager) { super(); this.configManager = configManager; } async execute(options) { try { this.logDebug("Checking for existing configuration...", options); if (this.configManager.exists()) { this.logDebug("Using existing configuration", options); const config = this.configManager.readConfig(); this.logDebug(`Found ${config.workers.length} workers in config`, options); this.displayWorkers(config.workers); return; } this.logDebug("No configuration found, fetching from API", options); const apiKey = keyManager_1.KeyManager.resolveKey(options.key); this.logDebug("API key resolved", options); const workers = await discovery_1.WorkerDiscoveryService.fetchWorkerDefinitions(apiKey, options.baseUrl); this.logDebug(`Fetched ${workers.length} workers from API`, options); this.displayWorkers(workers); } catch (error) { this.logError(error, "Failed to list workers", options); console.warn("\n Note: Run 'npx mindstudio sync' first to fetch worker definitions\n"); } } displayWorkers(workers) { console.log("\nšŸ“¦ Available Workers\n"); workers.forEach((worker) => { const formattedWorkerName = nameFormatter_1.EntityFormatter.formatWorker(worker); console.log(`\x1b[1m${worker.name}\x1b[0m`); console.log(`Import: workers.${formattedWorkerName}\n`); worker.workflows.forEach((workflow) => { const formattedWorkflowName = nameFormatter_1.EntityFormatter.formatWorkflow(workflow); console.log(` šŸ”¹ ${workflow.name}`); // Create function signature const inputs = workflow.launchVariables.length ? `{ ${workflow.launchVariables.join(", ")} }` : ""; console.log(` └─ workers.${formattedWorkerName}.${formattedWorkflowName}(${inputs})`); // Show return type const returns = workflow.outputVariables.length ? `{ ${workflow.outputVariables.join(", ")} }` : "string | undefined"; console.log(` Returns: ${returns}`); console.log(""); // Add spacing between workflows }); console.log("─".repeat(50) + "\n"); // Add separator between workers }); console.log("šŸ’” Run 'npx mindstudio sync' to generate type definitions for these workers\n"); } } exports.ListCommand = ListCommand;