UNPKG

mindstudio

Version:

Client library for MindStudio AI Workers

53 lines (52 loc) 2 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.MindStudio = void 0; const client_1 = require("./core/http/client"); const loader_1 = require("./core/workers/loader"); const keyManager_1 = require("./core/auth/keyManager"); const errors_1 = require("./errors"); class MindStudio { constructor(apiKey, options) { this.apiKey = keyManager_1.KeyManager.resolveKey(apiKey); this.httpClient = new client_1.HttpClient(this.apiKey, { baseUrl: options === null || options === void 0 ? void 0 : options.baseUrl, }); this.workerLoader = new loader_1.WorkerLoader(this.run.bind(this)); this._workers = this.workerLoader.loadFromConfig(); } /** * Type-safe worker access - only available if types are generated */ get workers() { if (!this._workers) { throw new errors_1.MindStudioError("Type-safe workers not available. Run 'npx mindstudio sync' first to generate types.", "types_not_generated", 400); } return this._workers; } /** * Direct worker execution without type safety */ async run(params) { try { const response = await this.httpClient.post("/workers/run", { workerId: params.workerId, workflow: params.workflow, variables: params.variables || {}, callbackUrl: params.callbackUrl, progressUrl: params.progressUrl, }); return { threadId: response.threadId, result: response.result, billingCost: response.billingCost, }; } catch (error) { if (error instanceof errors_1.MindStudioError) { throw error; } throw new errors_1.MindStudioError(error instanceof Error ? error.message : String(error), "workflow_execution_failed", 500); } } } exports.MindStudio = MindStudio;