fix(confidence-engine): expose failed provider path

This commit is contained in:
2026-09-05 17:00:33 +01:00
parent 677f5e5757
commit dabd9e2245
9 changed files with 81 additions and 6 deletions
+4 -1
View File
@@ -81,6 +81,8 @@ export async function analyseScenario(scenario, opts = {}) {
return buildErrorResponse(
e.message || "Provider error during analysis",
Date.now() - startTime,
"500",
e.providerApiPath,
);
}
@@ -154,7 +156,7 @@ function tryValidateAgainstSchema(data, schema) {
// ── Result builders ──────────────────────────────────
function buildErrorResponse(message, elapsed, statusCode = 500) {
function buildErrorResponse(message, elapsed, statusCode = 500, providerApiPath) {
return {
success: false,
error: message,
@@ -164,6 +166,7 @@ function buildErrorResponse(message, elapsed, statusCode = 500) {
rawResponse: null,
promptVersion: null,
statusCode,
providerApiPath,
};
}
+1
View File
@@ -372,6 +372,7 @@ export async function startCase(body, dependencies = {}) {
}),
analysisErrors: analysis.errors ?? undefined,
validationIssues: analysis.validationIssues ?? undefined,
providerApiPath: analysis.providerApiPath ?? undefined,
rawResponse: analysis.rawResponse ?? undefined,
statusCode: Number(analysis.statusCode) || 502,
};
+12 -5
View File
@@ -119,7 +119,8 @@ class OllamaLlmProvider {
try {
const controller = new AbortController();
const timeout = setTimeout(() => controller.abort(), 60000);
apiUsed = "/api/chat";
const res = await fetch(`${baseUrl}/api/chat`, {
method: "POST",
headers: { "Content-Type": "application/json" },
@@ -180,14 +181,14 @@ class OllamaLlmProvider {
}
fullResponseData = await res.json();
rawResponse = typeof fullResponseData.response === "string"
? fullResponseData.response
: JSON.stringify(fullResponseData);
} catch (e) {
if (apiUsed === "/api/generate") {
throw new Error(
const error = new Error(
`Ollama /api/generate request timed out after 5 minutes.\n\n` +
`This usually means:\n` +
`1. The model is loading into memory for the first time (cold start) — this can take several minutes\n` +
@@ -198,6 +199,8 @@ class OllamaLlmProvider {
`- Use a smaller model (e.g., llama3.1 instead of llama3.1:70b)\n` +
`- Check Ollama logs: \`ollama serve\` or look at your system logs`
);
error.providerApiPath = apiUsed;
throw error;
}
throw e;
}
@@ -225,7 +228,7 @@ class OllamaLlmProvider {
}
}
throw new Error(
const error = new Error(
"Model produced empty output.\n\n" +
"API used: " + (apiUsed || "none") + "\n" +
"/api/chat supported: " + chatSupported + "\n" +
@@ -236,6 +239,8 @@ class OllamaLlmProvider {
"- This Ollama version does not support format:json — using prompt instructions only (reliability varies)\n" +
"- If your model is very small (e.g., tinyllama, phi), try a larger one like llama3.1 or mistral"
);
error.providerApiPath = apiUsed;
throw error;
}
// ================================================================
@@ -245,7 +250,7 @@ class OllamaLlmProvider {
return recoverJson(rawResponse);
} catch (e) {
if (e instanceof SyntaxError) {
throw new Error(
const error = new Error(
"Model returned output that could not be parsed as valid JSON.\n\n" +
"API used: " + (apiUsed || "none") + "\n" +
"/api/chat supported: " + chatSupported + "\n" +
@@ -256,6 +261,8 @@ class OllamaLlmProvider {
"- Shorten your scenario to under 500 words\n" +
"- Consider upgrading Ollama: https://ollama.com/download"
);
error.providerApiPath = apiUsed;
throw error;
}
throw e;
}