// src/providers/http_provider.mjs import { BaseProvider } from "./base.mjs"; /** * Generic HTTP provider. * Expected server contract: * POST { prompt: "..." } → { output: "...", score?: number } */ export class HttpProvider extends BaseProvider { constructor(stage = "reward") { super(); // REWARD_URL, VERIFIER_URL, GENERATOR_URL, HTTP_URL fallback this.url = process.env[`${stage.toUpperCase()}_URL`] || process.env.HTTP_URL || "http://localhost:8001/score"; } async generate(prompt) { const body = { prompt }; const res = await fetch(this.url, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(body) }); if (!res.ok) throw new Error(`HttpProvider error: ${res.status}`); const json = await res.json(); // Normalize: allow reward server to return { output } or full JSON if (typeof json === "string") return json; if (json.output) return json.output; if (json.response) return json.response; return JSON.stringify(json); } }