feat(flight-finder): implement milestone M2 - report workflow and delivery gates
This commit is contained in:
@@ -0,0 +1,83 @@
|
||||
import type {
|
||||
FlightReportPayload,
|
||||
FlightReportStatusResult,
|
||||
NormalizedFlightReportRequest
|
||||
} from "./types.js";
|
||||
import { isPlausibleEmail } from "./input-validation.js";
|
||||
|
||||
export function getFlightReportStatus(
|
||||
normalizedRequest: NormalizedFlightReportRequest,
|
||||
payload?: FlightReportPayload | null
|
||||
): FlightReportStatusResult {
|
||||
if (normalizedRequest.missingSearchInputs.length) {
|
||||
return {
|
||||
needsMissingInputs: normalizedRequest.missingSearchInputs,
|
||||
readyToSearch: false,
|
||||
pdfReady: false,
|
||||
emailReady: false,
|
||||
chatSummaryReady: false,
|
||||
terminalOutcome: "missing-inputs",
|
||||
degraded: false,
|
||||
degradedReasons: [],
|
||||
blockingReason: "Missing search-critical trip inputs."
|
||||
};
|
||||
}
|
||||
|
||||
if (!payload) {
|
||||
return {
|
||||
needsMissingInputs: normalizedRequest.missingDeliveryInputs,
|
||||
readyToSearch: true,
|
||||
pdfReady: false,
|
||||
emailReady: false,
|
||||
chatSummaryReady: false,
|
||||
terminalOutcome: "report-incomplete",
|
||||
degraded: false,
|
||||
degradedReasons: [],
|
||||
lastCompletedPhase: "intake",
|
||||
blockingReason: "Search and report assembly have not completed yet."
|
||||
};
|
||||
}
|
||||
|
||||
const allSourcesFailed =
|
||||
payload.sourceFindings.length > 0 &&
|
||||
payload.sourceFindings.every((finding) => finding.status === "blocked") &&
|
||||
payload.quotes.length === 0;
|
||||
|
||||
if (allSourcesFailed) {
|
||||
return {
|
||||
needsMissingInputs: normalizedRequest.missingDeliveryInputs,
|
||||
readyToSearch: true,
|
||||
pdfReady: false,
|
||||
emailReady: false,
|
||||
chatSummaryReady: true,
|
||||
terminalOutcome: "all-sources-failed",
|
||||
degraded: true,
|
||||
degradedReasons: payload.degradedReasons,
|
||||
lastCompletedPhase: payload.lastCompletedPhase || "search",
|
||||
blockingReason: "All configured travel sources failed or were blocked."
|
||||
};
|
||||
}
|
||||
|
||||
const reportComplete = Boolean(
|
||||
payload.quotes.length &&
|
||||
payload.rankedOptions.length &&
|
||||
payload.executiveSummary.length
|
||||
);
|
||||
const validRecipient = isPlausibleEmail(normalizedRequest.request.recipientEmail);
|
||||
|
||||
return {
|
||||
needsMissingInputs: validRecipient ? [] : normalizedRequest.missingDeliveryInputs,
|
||||
readyToSearch: true,
|
||||
pdfReady: reportComplete,
|
||||
emailReady: reportComplete && validRecipient,
|
||||
chatSummaryReady:
|
||||
payload.quotes.length > 0 ||
|
||||
payload.rankedOptions.length > 0 ||
|
||||
payload.executiveSummary.length > 0,
|
||||
terminalOutcome: reportComplete ? "ready" : "report-incomplete",
|
||||
degraded: payload.degradedReasons.length > 0,
|
||||
degradedReasons: payload.degradedReasons,
|
||||
lastCompletedPhase: payload.lastCompletedPhase,
|
||||
blockingReason: reportComplete ? undefined : "The report payload is still incomplete."
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user