This commit is contained in:
Dax Raad
2025-06-11 12:44:17 -04:00
parent 95d5e1f231
commit 6cf8784ecf
6 changed files with 62 additions and 12 deletions

View File

@@ -72,26 +72,57 @@ export const WebFetchTool = Tool.define({
const content = new TextDecoder().decode(arrayBuffer)
const contentType = response.headers.get("content-type") || ""
const title = `${params.url} (${contentType})`
switch (params.format) {
case "text":
if (contentType.includes("text/html")) {
const text = extractTextFromHTML(content)
return { output: text, metadata: {} }
return {
output: text,
metadata: {
title,
},
}
}
return {
output: content,
metadata: {
title,
},
}
return { output: content, metadata: {} }
case "markdown":
if (contentType.includes("text/html")) {
const markdown = convertHTMLToMarkdown(content)
return { output: markdown, metadata: {} }
return {
output: markdown,
metadata: {
title,
},
}
}
return {
output: "```\n" + content + "\n```",
metadata: {
title,
},
}
return { output: "```\n" + content + "\n```", metadata: {} }
case "html":
return { output: content, metadata: {} }
return {
output: content,
metadata: {
title,
},
}
default:
return { output: content, metadata: {} }
return {
output: content,
metadata: {
title,
},
}
}
},
})