Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion packages/provider-rea/src/reaMcp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,51 @@ function cleanEnvironment(environment: NodeJS.ProcessEnv): Record<string, string
);
}

function asRecord(value: unknown): Record<string, unknown> | undefined {
if (value && typeof value === "object" && !Array.isArray(value)) return value as Record<string, unknown>;
return undefined;
}

function diagnosticMessage(value: unknown): string | undefined {
const error = asRecord(asRecord(value)?.error);
if (!error) return undefined;
const details = asRecord(error.details);
const rejections = details?.rejections;
if (Array.isArray(rejections) && typeof details?.requested_provider_id === "string") {
const selected = rejections.map(asRecord).find((entry) => entry?.provider_id === details.requested_provider_id);
const probe = asRecord(asRecord(selected?.diagnostics)?.java_probe_failure);
if (probe?.process_error_code === "ETIMEDOUT") {
return "The Java runtime check timed out. Retry when the machine is less busy.";
}
if (typeof selected?.reason === "string" && selected.reason.trim()) return selected.reason.trim();
}
return typeof error.message === "string" ? error.message.trim() : undefined;
}

function providerErrorDetail(reply: unknown): string | null {
if (!reply || typeof reply !== "object" || Array.isArray(reply)) return null;
const response = reply as Record<string, unknown>;
const diagnostic = diagnosticMessage(response.structuredContent);
if (diagnostic) return diagnostic;
const textParts = Array.isArray(response.content)
? response.content.flatMap((item) => {
if (!item || typeof item !== "object" || Array.isArray(item)) return [];
const record = item as Record<string, unknown>;
return typeof record.text === "string" && record.text.trim() ? [record.text.trim()] : [];
})
: [];
if (textParts.length > 0) return textParts.join(" ");
if (textParts.length > 0) {
const text = textParts.join(" ");
if (text.startsWith("{")) {
try {
const summary = diagnosticMessage(JSON.parse(text));
if (summary) return summary;
} catch {
// Some provider errors are plain text that begins with a brace.
}
}
return text;
}

if (response.structuredContent && typeof response.structuredContent === "object" && !Array.isArray(response.structuredContent)) {
const record = response.structuredContent as Record<string, unknown>;
Expand Down
16 changes: 16 additions & 0 deletions packages/provider-rea/test/reaMcp.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,3 +231,19 @@ test("uses structured provider detail without inventing a setup diagnosis", () =
assert.match(error.message, /Unsupported target language/);
assert.doesNotMatch(error.message, /Verify Ghidra|Verify a compatible JDK/);
});

test("summarizes a timed-out Java probe for the requested provider", () => {
const report = { error: { message: "Provider unavailable", details: {
requested_provider_id: "ghidra", rejections: [
{ provider_id: "other", reason: "Other launcher missing" },
{ provider_id: "ghidra", reason: "Update JAVA_HOME", diagnostics: {
java_probe_failure: { process_error_code: "ETIMEDOUT", output: "private system settings" },
} },
],
} } };
for (const reply of [{ structuredContent: report }, { content: [{ text: JSON.stringify(report) }] }]) {
const error = __mcpTest.providerFailure("open_binary", reply);
assert.match(error.message, /Java runtime check timed out/);
assert.doesNotMatch(error.message, /private system settings|JAVA_HOME|Other launcher|Verify Ghidra/);
}
});
Loading