import { getFromCache, decodeContentHandle } from "../lib/cache.js";
export async function fetchFullContent(params) {
const { contentHandle, outputFormat = "markdown" } = params;
const timestamp = new Date().toISOString();
try {
const url = decodeContentHandle(contentHandle);
if (!url) {
return {
url: "",
title: "",
timestamp,
error: "Invalid contentHandle format. Ensure it was generated by rag() tool.",
};
}
const cached = await getFromCache(url);
if (!cached) {
return {
url,
title: "",
fromCache: false,
timestamp,
error: `Content not found in cache. Cache TTL is 1 hour. Please run rag() again to re-fetch and cache the content.`,
};
}
const result = {
url: cached.url,
title: cached.title,
fromCache: true,
timestamp,
contentLength: outputFormat === "markdown"
? cached.markdown.length
: cached.content.length,
};
if (outputFormat === "markdown") {
result.markdown = cached.markdown;
}
else if (outputFormat === "text") {
result.text = cached.content;
}
else if (outputFormat === "html") {
result.html = cached.content;
}
return result;
}
catch (error) {
return {
url: "",
title: "",
fromCache: false,
timestamp,
error: `Fetch failed: ${error.message}`,
};
}
}
//# sourceMappingURL=fetch.js.map