@gentrace/core
Version:
Core Gentrace Node.JS library
46 lines (43 loc) • 2.12 kB
JavaScript
import { globalGentraceApiV2 } from './init.mjs';
var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
/**
* Retrieves evaluators for a given pipeline from the Gentrace API
* @async
* @param {string} pipelineIdentifier - The pipeline slug, pipeline ID, or null (for evaluator templates)
* @throws {Error} Throws an error if the SDK is not initialized. Call init() first.
* @returns {Promise<Array<EvaluatorV2>>} A Promise that resolves with an array of evaluators.
*/
const getEvaluators = (pipelineIdentifier) => __awaiter(void 0, void 0, void 0, function* () {
var _a;
if (!globalGentraceApiV2) {
throw new Error("Gentrace API key not initialized. Call init() first.");
}
let pipelineId = pipelineIdentifier;
let pipelineSlug = pipelineIdentifier;
if (pipelineIdentifier && isUUID(pipelineIdentifier)) {
pipelineSlug = null; // no pipeline slug
}
else {
pipelineId = null;
}
if (!pipelineIdentifier) {
pipelineId = "null"; // get template evaluators
}
const response = yield globalGentraceApiV2.v2EvaluatorsGet(pipelineId, pipelineSlug);
const evaluators = (_a = response.data.data) !== null && _a !== void 0 ? _a : [];
return evaluators;
});
function isUUID(str) {
const uuidPattern = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-5][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$/;
return uuidPattern.test(str);
}
export { getEvaluators };
//# sourceMappingURL=evaluator.mjs.map