feat(reconstruction): evaluate end-to-end readiness
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
import type { McpServer } from "@modelcontextprotocol/server";
|
||||
|
||||
import {
|
||||
evaluateReconstructionReadinessValidated,
|
||||
resolveReconstructionReadinessRequest,
|
||||
} from "../../application/ReconstructionReadinessService.js";
|
||||
import { applicationToolContract } from "../../contracts/applicationToolContracts.js";
|
||||
import { reconstructionReadinessInputSchema } from "../../domain/reconstructionReadinessSchemas.js";
|
||||
import { reconstructionReadinessReportSchema } from "../../domain/reconstructionReadinessSchemas.js";
|
||||
import { logToolExecution } from "../toolLogging.js";
|
||||
import { safeParseToolInput } from "../toolInputValidation.js";
|
||||
import { toolRegistrationOptions } from "../toolRegistrationOptions.js";
|
||||
import { toCallToolResult } from "../toolResult.js";
|
||||
import { recordSources } from "./helpers.js";
|
||||
import type { ApplicationToolRegistration } from "./types.js";
|
||||
|
||||
const contract = applicationToolContract("evaluate_reconstruction_readiness");
|
||||
|
||||
/** Register deterministic public-contract reconstruction conformance. */
|
||||
export const registerReconstructionReadinessTool = (
|
||||
server: McpServer,
|
||||
options: ApplicationToolRegistration,
|
||||
): void => {
|
||||
server.registerTool(
|
||||
contract.name,
|
||||
toolRegistrationOptions(contract),
|
||||
async (input) => {
|
||||
const parsed = safeParseToolInput(
|
||||
reconstructionReadinessInputSchema,
|
||||
input,
|
||||
contract.name,
|
||||
);
|
||||
if (!parsed.ok) return toCallToolResult(parsed, contract);
|
||||
const resolved = resolveReconstructionReadinessRequest(parsed.value);
|
||||
if (!resolved.ok) return toCallToolResult(resolved, contract);
|
||||
const result = await logToolExecution(options.logger, contract.name, () =>
|
||||
Promise.resolve(
|
||||
evaluateReconstructionReadinessValidated(resolved.value),
|
||||
),
|
||||
);
|
||||
if (!result.ok) return toCallToolResult(result, contract);
|
||||
const recorded = recordSources(
|
||||
options.recordEvidence,
|
||||
resolved.value.evidence_bundle.records,
|
||||
);
|
||||
if (!recorded.ok) return toCallToolResult(recorded, contract);
|
||||
const recordedResult = options.recordEvidence?.(result.value);
|
||||
if (recordedResult !== undefined && !recordedResult.ok)
|
||||
return toCallToolResult(recordedResult, contract);
|
||||
const report = reconstructionReadinessReportSchema.parse(
|
||||
result.value.normalized_result,
|
||||
);
|
||||
const reportUri = `rea://evidence/${result.value.evidence_id}/reconstruction-readiness-report`;
|
||||
const projection = {
|
||||
schema: report.schema,
|
||||
schema_version: report.schema_version,
|
||||
report_id: report.report_id,
|
||||
source_digest: report.source_digest,
|
||||
report_digest: report.report_digest,
|
||||
status: report.status,
|
||||
summary: report.summary,
|
||||
metrics: report.metrics,
|
||||
report_resource_uri: reportUri,
|
||||
};
|
||||
return toCallToolResult({ ok: true, value: result.value }, contract, {
|
||||
evidenceResourcesAvailable: recordedResult !== undefined,
|
||||
evidenceResultProjection: projection,
|
||||
evidenceTextProjection: projection,
|
||||
resourceLinks: [
|
||||
{
|
||||
uri: reportUri,
|
||||
name: report.report_id,
|
||||
description: "Full deterministic reconstruction readiness report",
|
||||
},
|
||||
],
|
||||
});
|
||||
},
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,69 @@
|
||||
import {
|
||||
ResourceNotFoundError,
|
||||
ResourceTemplate,
|
||||
type McpServer,
|
||||
} from "@modelcontextprotocol/server";
|
||||
|
||||
import type { BinarySessionPort } from "../application/BinarySessionPort.js";
|
||||
import { reconstructionReadinessReportSchema } from "../domain/reconstructionReadinessSchemas.js";
|
||||
|
||||
/** Expose retained full readiness reports outside compact tool responses. */
|
||||
export const registerReconstructionReadinessResource = (
|
||||
server: McpServer,
|
||||
session: BinarySessionPort,
|
||||
): void => {
|
||||
server.registerResource(
|
||||
"reconstruction-readiness-report",
|
||||
new ResourceTemplate(
|
||||
"rea://evidence/{evidenceId}/reconstruction-readiness-report",
|
||||
{
|
||||
list: undefined,
|
||||
complete: {
|
||||
evidenceId: (prefix) =>
|
||||
session
|
||||
.exportEvidenceBundle()
|
||||
.records.filter(
|
||||
({ predicate_type: predicateType }) =>
|
||||
predicateType === "rea.reconstruction-readiness-report/v1",
|
||||
)
|
||||
.map(({ evidence_id: evidenceId }) => evidenceId)
|
||||
.filter((evidenceId) => evidenceId.startsWith(prefix)),
|
||||
},
|
||||
},
|
||||
),
|
||||
{
|
||||
title: "Reconstruction readiness report",
|
||||
description:
|
||||
"Full deterministic nine-stage conformance report and replay identity.",
|
||||
mimeType: "application/json",
|
||||
},
|
||||
(uri, variables) => {
|
||||
const evidenceId = variables.evidenceId;
|
||||
if (typeof evidenceId !== "string")
|
||||
throw new ResourceNotFoundError(uri.href);
|
||||
const evidence = session.evidenceById(evidenceId);
|
||||
if (
|
||||
evidence === undefined ||
|
||||
evidence.predicate_type !== "rea.reconstruction-readiness-report/v1"
|
||||
)
|
||||
throw new ResourceNotFoundError(uri.href);
|
||||
const report = reconstructionReadinessReportSchema.safeParse(
|
||||
evidence.normalized_result,
|
||||
);
|
||||
if (!report.success) throw new ResourceNotFoundError(uri.href);
|
||||
return {
|
||||
contents: [
|
||||
{
|
||||
uri: uri.href,
|
||||
mimeType: "application/json",
|
||||
text: JSON.stringify(
|
||||
{ evidence_id: evidence.evidence_id, report: report.data },
|
||||
null,
|
||||
2,
|
||||
),
|
||||
},
|
||||
],
|
||||
};
|
||||
},
|
||||
);
|
||||
};
|
||||
Reference in New Issue
Block a user