mindstudio
Version:
Client library for MindStudio AI Workers
53 lines (52 loc) • 2.37 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.TestCommand = void 0;
const client_1 = require("../../client");
const base_1 = require("./base");
const keyManager_1 = require("../../core/auth/keyManager");
class TestCommand extends base_1.BaseCommand {
constructor(config, prompts) {
super();
this.config = config;
this.prompts = prompts;
}
async execute(options) {
var _a, _b;
try {
const config = this.config.readConfig();
this.logDebug(`Loaded config with ${config.workers.length} workers`, options);
const apiKey = keyManager_1.KeyManager.resolveKey(options.key);
this.logDebug("API key resolved", options);
const client = new client_1.MindStudio(apiKey, {
baseUrl: options.baseUrl,
});
this.logDebug(`Client initialized with base URL: ${options.baseUrl || "default"}`, options);
const { worker, workflow } = options.worker && options.workflow
? { worker: options.worker, workflow: options.workflow }
: await this.prompts.selectWorkerAndWorkflow(config);
this.logDebug(`Selected worker: ${worker}, workflow: ${workflow}`, options);
const input = options.input
? JSON.parse(options.input)
: await this.prompts.getWorkflowInput(config, worker, workflow);
this.logDebug(`Input prepared: ${JSON.stringify(input)}`, options);
console.log("\n Executing workflow...");
const result = await client.run({
workerId: worker,
workflow: ((_b = (_a = config.workers
.find((w) => w.id === worker)) === null || _a === void 0 ? void 0 : _a.workflows.find((w) => w.id === workflow)) === null || _b === void 0 ? void 0 : _b.name) || "",
variables: input,
});
console.log("\n✨ Success!");
console.log("Result:", JSON.stringify(result, null, 2));
}
catch (error) {
if (error instanceof SyntaxError) {
this.logError(error, "Invalid JSON input", options);
}
else {
this.logError(error, "Test failed", options);
}
}
}
}
exports.TestCommand = TestCommand;