feat: apply validated graph update proposals
This commit is contained in:
@@ -13,6 +13,7 @@ import {
|
||||
updateCaseRequestSchema,
|
||||
} from "./schema.js";
|
||||
import { buildInitialGraph, describeGraph } from "./builder.js";
|
||||
import { applyValidatedProposal } from "./apply-proposal.js";
|
||||
import { buildGraphUpdatePrompt } from "./prompt-builder.js";
|
||||
import { parseGraphUpdateProposal } from "./update-proposal.js";
|
||||
import {
|
||||
@@ -180,6 +181,9 @@ async function updateCaseWithDependencies(body, dependencies = {}) {
|
||||
dependencies.buildGraphUpdatePrompt ?? buildGraphUpdatePrompt;
|
||||
const parseProposal =
|
||||
dependencies.parseGraphUpdateProposal ?? parseGraphUpdateProposal;
|
||||
const applyProposalUpdate =
|
||||
dependencies.applyValidatedProposal ?? applyValidatedProposal;
|
||||
const shouldApplyProposal = dependencies.applyProposal === true;
|
||||
|
||||
let modelName = null;
|
||||
let rawResponse;
|
||||
@@ -238,6 +242,55 @@ async function updateCaseWithDependencies(body, dependencies = {}) {
|
||||
};
|
||||
}
|
||||
|
||||
if (shouldApplyProposal) {
|
||||
const applicationResult = applyProposalUpdate({
|
||||
situationGraph,
|
||||
proposal: parsedProposal.proposal,
|
||||
});
|
||||
|
||||
if (!applicationResult.success) {
|
||||
return {
|
||||
success: false,
|
||||
stage: applicationResult.stage,
|
||||
errors: applicationResult.errors,
|
||||
diagnostics: {
|
||||
promptVersion: promptVersion ?? null,
|
||||
modelName,
|
||||
responseDurationMs,
|
||||
normalisationsApplied: parsedProposal.normalisationsApplied,
|
||||
graphNodeCount: situationGraph.nodes.length,
|
||||
graphEdgeCount: situationGraph.edges.length,
|
||||
},
|
||||
statusCode:
|
||||
applicationResult.stage === "application" ||
|
||||
applicationResult.stage === "result_validation"
|
||||
? 500
|
||||
: 400,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
stage: "update_applied",
|
||||
updatedSituationGraph: applicationResult.updatedSituationGraph,
|
||||
proposal: applicationResult.graphUpdate,
|
||||
affectedNodeIds: applicationResult.affectedNodeIds,
|
||||
resolvedUnknownNodeIds: applicationResult.resolvedUnknownNodeIds,
|
||||
previousActiveUnknownNodeId:
|
||||
applicationResult.previousActiveUnknownNodeId,
|
||||
newActiveUnknownNodeId: applicationResult.newActiveUnknownNodeId,
|
||||
changesApplied: applicationResult.changesApplied,
|
||||
diagnostics: {
|
||||
promptVersion: promptVersion ?? null,
|
||||
modelName,
|
||||
responseDurationMs,
|
||||
normalisationsApplied: parsedProposal.normalisationsApplied,
|
||||
graphNodeCount: applicationResult.updatedSituationGraph.nodes.length,
|
||||
graphEdgeCount: applicationResult.updatedSituationGraph.edges.length,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
stage: "proposal_ready",
|
||||
|
||||
Reference in New Issue
Block a user