mirror of
https://github.com/morluto/rea.git
synced 2026-11-07 05:56:19 -10:00
refactor(mcp): reuse desktop retained-summary handler
This commit is contained in:
1 parent
b9ee8fe057
commit
971b48f702
1 file changed
+6
-26
@@ -5,11 +5,8 @@ import type { EvidenceLookup } from "../application/EvidenceInputResolver.js";
|
||||
import type { EvidenceWriter } from "../application/investigation/InvestigationRecordPort.js";
|
||||
import type { WithAdmittedAnalysis } from "./analysisAdmission.js";
|
||||
import { toolContract } from "../contracts/toolContracts.js";
|
||||
import { createEvidenceToolHandler } from "./contractToolHandler.js";
|
||||
import { createRetainedSummaryToolHandler } from "./contractToolHandler.js";
|
||||
import { applicationToolRegistrationOptions } from "./toolRegistrationOptions.js";
|
||||
import { retainedSummaryDelivery } from "./retainedSummaryDelivery.js";
|
||||
import { analysisInputErrorFromIssues } from "../domain/inputIssueProjection.js";
|
||||
import { err } from "../domain/result.js";
|
||||
|
||||
/** Bind the named contract and refuse unretained summary delivery before I/O. */
|
||||
export const registerDesktopApplicationTool = (
|
||||
@@ -21,34 +18,17 @@ export const registerDesktopApplicationTool = (
|
||||
evidenceById: EvidenceLookup | undefined,
|
||||
): void => {
|
||||
const contract = toolContract("inspect_desktop_application");
|
||||
const delivery = retainedSummaryDelivery(new Set([contract.name]), {
|
||||
recordEvidence,
|
||||
evidenceById,
|
||||
});
|
||||
const handler = createEvidenceToolHandler(
|
||||
const handler = createRetainedSummaryToolHandler(
|
||||
server,
|
||||
async (raw, options) => {
|
||||
const parsed = contract.inputSchema.safeParse(raw);
|
||||
if (!parsed.success)
|
||||
return err(
|
||||
analysisInputErrorFromIssues(contract.name, parsed.error.issues, raw),
|
||||
);
|
||||
const { detail, ...input } = parsed.data;
|
||||
const parameters = { detail };
|
||||
const ready = delivery.preflight(contract.name, parameters);
|
||||
if (!ready.ok) return ready;
|
||||
const result = await service.inspect(input, options);
|
||||
return result.ok
|
||||
? delivery.projectEvidence(contract.name, parameters, result.value)
|
||||
: result;
|
||||
},
|
||||
contract,
|
||||
(input, options) => service.inspect(input, options),
|
||||
logger,
|
||||
recordEvidence,
|
||||
{ recordEvidence, evidenceById },
|
||||
withAdmittedAnalysis,
|
||||
);
|
||||
server.registerTool(
|
||||
contract.name,
|
||||
applicationToolRegistrationOptions(contract),
|
||||
handler(contract),
|
||||
handler,
|
||||
);
|
||||
};
|
||||
Reference in new issue
Block a user