|
@@ -7,12 +7,22 @@ function appendLog(entry: Record<string, unknown>) {
|
|
|
fs.appendFileSync(LOG_FILE, JSON.stringify(entry) + "\n", "utf8");
|
|
fs.appendFileSync(LOG_FILE, JSON.stringify(entry) + "\n", "utf8");
|
|
|
} catch {}
|
|
} catch {}
|
|
|
}
|
|
}
|
|
|
-function extractText(content: any): string {
|
|
|
|
|
|
|
+function extractText(content: any, seen?: Set<any>): string {
|
|
|
if (typeof content === "string") return content;
|
|
if (typeof content === "string") return content;
|
|
|
|
|
+ if (content === null || content === undefined) return "";
|
|
|
|
|
+ const seenSet = seen ?? new Set<any>();
|
|
|
|
|
+ if (seenSet.has(content)) return "";
|
|
|
|
|
+ seenSet.add(content);
|
|
|
if (Array.isArray(content)) {
|
|
if (Array.isArray(content)) {
|
|
|
return content
|
|
return content
|
|
|
- .filter((b: any) => b.type === "text")
|
|
|
|
|
- .map((b: any) => b.text as string)
|
|
|
|
|
|
|
+ .map((item) => extractText(item, seenSet))
|
|
|
|
|
+ .filter((text) => !!text)
|
|
|
|
|
+ .join("");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (typeof content === "object") {
|
|
|
|
|
+ return Object.values(content)
|
|
|
|
|
+ .map((value) => extractText(value, seenSet))
|
|
|
|
|
+ .filter((text) => !!text)
|
|
|
.join("");
|
|
.join("");
|
|
|
}
|
|
}
|
|
|
return "";
|
|
return "";
|