import type { IndemnClient } from './client.js'; import type { EvaluationTriggerInput, EvaluationTriggerResponse, EvaluationRun, EvaluationResult, BotContext, } from './types.js'; export class EvalSDK { constructor(private client: IndemnClient) {} async triggerEvaluation(input: EvaluationTriggerInput): Promise { return this.client.evalsPost('/api/v1/evaluations', input); } async listRuns(agentId?: string): Promise { const query = agentId ? { agent_id: agentId } : undefined; return this.client.evalsGet('/api/v1/runs', query); } async getRunStatus(runId: string): Promise { return this.client.evalsGet(`/api/v1/runs/${runId}`); } async getRunResults(runId: string): Promise { return this.client.evalsGet(`/api/v1/runs/${runId}/results`); } async getBotContext(botId: string): Promise { return this.client.evalsGet(`/api/v1/bots/${botId}/context`); } async pollRunUntilComplete( runId: string, intervalMs = 5000, timeoutMs = 300000, ): Promise { const startTime = Date.now(); while (true) { const run = await this.getRunStatus(runId); if (run.status === 'completed' || run.status === 'failed') { return run; } if (Date.now() - startTime >= timeoutMs) { throw new Error( `Evaluation run ${runId} did not complete within ${timeoutMs / 1000}s (last status: ${run.status})`, ); } await new Promise((resolve) => setTimeout(resolve, intervalMs)); } } }