UNPKG

@arizeai/phoenix-client

Version:
43 lines 1.66 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.toTraceAnnotationData = toTraceAnnotationData; /** * Build and validate annotation result fields */ function buildTraceAnnotationResult(annotation) { const result = {}; if (annotation.label !== undefined) { result.label = annotation.label.trim() || null; } if (annotation.score !== undefined) { result.score = annotation.score; } if (annotation.explanation !== undefined) { result.explanation = annotation.explanation.trim() || null; } const hasValidResult = result.label || result.score !== undefined || result.explanation; if (!hasValidResult) { throw new Error("At least one of label, score, or explanation must be provided for trace annotation"); } return result; } /** * Convert a TraceAnnotation to the API format */ function toTraceAnnotationData(annotation) { var _a; var _b, _c, _d; if (annotation.name.trim() === "note") { throw new Error('The name "note" is reserved for trace and span notes. Use addTraceNote instead.'); } const result = buildTraceAnnotationResult(annotation); return { trace_id: annotation.traceId.trim(), name: annotation.name.trim(), annotator_kind: (_b = annotation.annotatorKind) !== null && _b !== void 0 ? _b : "HUMAN", result, metadata: (_c = annotation.metadata) !== null && _c !== void 0 ? _c : null, identifier: (_d = (_a = annotation.identifier) === null || _a === void 0 ? void 0 : _a.trim()) !== null && _d !== void 0 ? _d : "", }; } //# sourceMappingURL=types.js.map