Defer property assessor email gate
This commit is contained in:
@@ -20,6 +20,7 @@ export interface AssessPropertyResult {
|
||||
ok: true;
|
||||
needsAssessmentPurpose: boolean;
|
||||
needsRecipientEmails: boolean;
|
||||
pdfReady: boolean;
|
||||
message: string;
|
||||
outputPath: string | null;
|
||||
reportPayload: ReportPayload | null;
|
||||
@@ -58,6 +59,13 @@ function asStringArray(value: unknown): string[] {
|
||||
return [String(value).trim()].filter(Boolean);
|
||||
}
|
||||
|
||||
function shouldRenderPdf(
|
||||
options: AssessPropertyOptions,
|
||||
recipientEmails: string[]
|
||||
): boolean {
|
||||
return Boolean(options.output || recipientEmails.length);
|
||||
}
|
||||
|
||||
function slugify(value: string): string {
|
||||
return value
|
||||
.toLowerCase()
|
||||
@@ -371,6 +379,7 @@ export async function assessProperty(
|
||||
ok: true,
|
||||
needsAssessmentPurpose: true,
|
||||
needsRecipientEmails: false,
|
||||
pdfReady: false,
|
||||
message:
|
||||
"Missing assessment purpose. Stop and ask the user why they want this property assessed before producing a decision-grade analysis.",
|
||||
outputPath: null,
|
||||
@@ -403,12 +412,14 @@ export async function assessProperty(
|
||||
photoResolution.photoReview
|
||||
);
|
||||
const recipientEmails = asStringArray(options.recipientEmails);
|
||||
const renderPdf = shouldRenderPdf(options, recipientEmails);
|
||||
|
||||
if (!recipientEmails.length) {
|
||||
if (renderPdf && !recipientEmails.length) {
|
||||
return {
|
||||
ok: true,
|
||||
needsAssessmentPurpose: false,
|
||||
needsRecipientEmails: true,
|
||||
pdfReady: false,
|
||||
message:
|
||||
"Missing target email. Stop and ask the user for target email address(es) before generating or sending the property assessment PDF.",
|
||||
outputPath: null,
|
||||
@@ -417,6 +428,20 @@ export async function assessProperty(
|
||||
};
|
||||
}
|
||||
|
||||
if (!renderPdf) {
|
||||
return {
|
||||
ok: true,
|
||||
needsAssessmentPurpose: false,
|
||||
needsRecipientEmails: false,
|
||||
pdfReady: true,
|
||||
message:
|
||||
"Assessment payload is ready to render later. Review the analysis now; recipient email is only needed when you want the PDF.",
|
||||
outputPath: null,
|
||||
reportPayload,
|
||||
publicRecords
|
||||
};
|
||||
}
|
||||
|
||||
const outputPath =
|
||||
options.output ||
|
||||
path.join(
|
||||
@@ -429,6 +454,7 @@ export async function assessProperty(
|
||||
ok: true,
|
||||
needsAssessmentPurpose: false,
|
||||
needsRecipientEmails: false,
|
||||
pdfReady: true,
|
||||
message: `Property assessment PDF rendered: ${renderedPath}`,
|
||||
outputPath: renderedPath,
|
||||
reportPayload,
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
import { execFile } from "node:child_process";
|
||||
import { promisify } from "node:util";
|
||||
|
||||
const execFileAsync = promisify(execFile);
|
||||
import { discoverHarListing } from "../../web-automation/scripts/har-discover.js";
|
||||
import { discoverZillowListing } from "../../web-automation/scripts/zillow-discover.js";
|
||||
|
||||
export interface ListingDiscoveryResult {
|
||||
attempts: string[];
|
||||
@@ -9,37 +7,13 @@ export interface ListingDiscoveryResult {
|
||||
harUrl: string | null;
|
||||
}
|
||||
|
||||
function parseJsonOutput(raw: string, context: string): any {
|
||||
const text = raw.trim();
|
||||
if (!text) {
|
||||
throw new Error(`${context} produced no JSON output.`);
|
||||
}
|
||||
return JSON.parse(text);
|
||||
}
|
||||
|
||||
async function runDiscoveryScript(
|
||||
scriptName: string,
|
||||
address: string
|
||||
): Promise<{ listingUrl: string | null; attempts: string[] }> {
|
||||
const scriptPath = `/Users/stefano/.openclaw/workspace/skills/web-automation/scripts/${scriptName}`;
|
||||
const { stdout } = await execFileAsync(process.execPath, [scriptPath, address], {
|
||||
timeout: 120000,
|
||||
maxBuffer: 2 * 1024 * 1024
|
||||
});
|
||||
const payload = parseJsonOutput(stdout, scriptName);
|
||||
return {
|
||||
listingUrl: typeof payload.listingUrl === "string" && payload.listingUrl.trim() ? payload.listingUrl.trim() : null,
|
||||
attempts: Array.isArray(payload.attempts) ? payload.attempts.map(String) : []
|
||||
};
|
||||
}
|
||||
|
||||
export async function discoverListingSources(address: string): Promise<ListingDiscoveryResult> {
|
||||
const attempts: string[] = [];
|
||||
let zillowUrl: string | null = null;
|
||||
let harUrl: string | null = null;
|
||||
|
||||
try {
|
||||
const result = await runDiscoveryScript("zillow-discover.js", address);
|
||||
const result = await discoverZillowListing(address);
|
||||
zillowUrl = result.listingUrl;
|
||||
attempts.push(...result.attempts);
|
||||
} catch (error) {
|
||||
@@ -49,7 +23,7 @@ export async function discoverListingSources(address: string): Promise<ListingDi
|
||||
}
|
||||
|
||||
try {
|
||||
const result = await runDiscoveryScript("har-discover.js", address);
|
||||
const result = await discoverHarListing(address);
|
||||
harUrl = result.listingUrl;
|
||||
attempts.push(...result.attempts);
|
||||
} catch (error) {
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
import { execFile } from "node:child_process";
|
||||
import { promisify } from "node:util";
|
||||
|
||||
const execFileAsync = promisify(execFile);
|
||||
import { extractHarPhotos } from "../../web-automation/scripts/har-photos.js";
|
||||
import { extractZillowPhotos } from "../../web-automation/scripts/zillow-photos.js";
|
||||
|
||||
export type PhotoSource = "zillow" | "har";
|
||||
|
||||
@@ -21,28 +19,25 @@ export interface PhotoReviewResolution {
|
||||
discoveredListingUrls: Array<{ label: string; url: string }>;
|
||||
}
|
||||
|
||||
function parseJsonOutput(raw: string, context: string): any {
|
||||
const text = raw.trim();
|
||||
if (!text) {
|
||||
throw new Error(`${context} produced no JSON output.`);
|
||||
}
|
||||
return JSON.parse(text);
|
||||
}
|
||||
|
||||
export async function extractPhotoData(
|
||||
source: PhotoSource,
|
||||
url: string
|
||||
): Promise<PhotoExtractionResult> {
|
||||
const scriptMap: Record<PhotoSource, string> = {
|
||||
zillow: "zillow-photos.js",
|
||||
har: "har-photos.js"
|
||||
};
|
||||
const scriptPath = `/Users/stefano/.openclaw/workspace/skills/web-automation/scripts/${scriptMap[source]}`;
|
||||
const { stdout } = await execFileAsync(process.execPath, [scriptPath, url], {
|
||||
timeout: 180000,
|
||||
maxBuffer: 5 * 1024 * 1024
|
||||
});
|
||||
const payload = parseJsonOutput(stdout, scriptMap[source]);
|
||||
if (source === "zillow") {
|
||||
const payload = await extractZillowPhotos(url);
|
||||
return {
|
||||
source,
|
||||
requestedUrl: String(payload.requestedUrl || url),
|
||||
finalUrl: typeof payload.finalUrl === "string" ? payload.finalUrl : undefined,
|
||||
expectedPhotoCount: typeof payload.expectedPhotoCount === "number" ? payload.expectedPhotoCount : null,
|
||||
complete: Boolean(payload.complete),
|
||||
photoCount: Number(payload.photoCount || 0),
|
||||
imageUrls: Array.isArray(payload.imageUrls) ? payload.imageUrls.map(String) : [],
|
||||
notes: Array.isArray(payload.notes) ? payload.notes.map(String) : []
|
||||
};
|
||||
}
|
||||
|
||||
const payload = await extractHarPhotos(url);
|
||||
return {
|
||||
source,
|
||||
requestedUrl: String(payload.requestedUrl || url),
|
||||
|
||||
Reference in New Issue
Block a user