Add purpose-aware property assessor intake
This commit is contained in:
56
skills/property-assessor/src/photo-review.ts
Normal file
56
skills/property-assessor/src/photo-review.ts
Normal file
@@ -0,0 +1,56 @@
|
||||
import { execFile } from "node:child_process";
|
||||
import { promisify } from "node:util";
|
||||
|
||||
const execFileAsync = promisify(execFile);
|
||||
|
||||
export type PhotoSource = "zillow" | "har";
|
||||
|
||||
export interface PhotoExtractionResult {
|
||||
source: PhotoSource;
|
||||
requestedUrl: string;
|
||||
finalUrl?: string;
|
||||
expectedPhotoCount?: number | null;
|
||||
complete?: boolean;
|
||||
photoCount: number;
|
||||
imageUrls: string[];
|
||||
notes: string[];
|
||||
}
|
||||
|
||||
export interface PhotoReviewResolution {
|
||||
review: Record<string, unknown>;
|
||||
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]);
|
||||
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) : []
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user