/*
 * Copyright OpenSearch Contributors
 * SPDX-License-Identifier: Apache-2.0
 */
const KIND_LABEL = {
    judge_failed: 'Judge evaluation failed',
    trace_timeout: 'Traces never arrived',
    trace_incomplete: 'Trace did not converge',
    trace_callback_failed: 'Post-trace callback failed',
    trace_fetch_failed: 'Trace fetch failed',
    unknown: 'Evaluator error',
};
/**
 * Build the canonical "evaluator could not run" patch for `runs.update()`.
 *
 * @param kind   short tag used in logs and as the `traceError` prefix
 * @param error  the underlying error or message; we extract `.message`
 *               when given an Error so logs aren't `[object Object]`
 */
export function buildEvaluatorErrorPatch(kind, error) {
    const message = error instanceof Error
        ? error.message
        : typeof error === 'string'
            ? error
            : 'Unknown error';
    const label = KIND_LABEL[kind];
    return {
        metricsStatus: 'error',
        // Both the human label AND the machine-readable kind token are
        // included — logs / dashboards can grep by `kind=judge_failed`
        // without having to parse the human label, while users skimming
        // a trace view still see the friendly prose form. Format:
        // `<Human Label> (kind=<kind>): <underlying message>`.
        traceError: `${label} (kind=${kind}): ${message}`,
        // The Judge tab renders this directly. Keep the prose concise and
        // explicit: the user must immediately see *why* there is no score.
        llmJudgeReasoning: `**Evaluator could not run.**\n\n` +
            `The agent may have completed normally, but the evaluator (judge or trace pipeline) ` +
            `failed before it could produce a verdict. This run is excluded from pass-rate aggregation.\n\n` +
            `**Reason (${kind}):** ${message}`,
        passFailStatus: null,
        metrics: { accuracy: 0, faithfulness: 0, latency_score: 0, trajectory_alignment_score: 0 },
    };
}
//# sourceMappingURL=evaluatorError.js.map