@@ -12,8 +12,11 @@ import { PrismaClient } from "../../lib/generated/prisma/client";
1212const adapter = new PrismaPg ( { connectionString : process . env . DATABASE_URL ! } ) ;
1313const prisma = new PrismaClient ( { adapter } ) ;
1414
15+ import TurndownService from "turndown" ;
1516import { DEFAULT_MODEL , REASONING_MODELS } from "@/lib/models" ;
1617
18+ const turndown = new TurndownService ( ) ;
19+
1720const MODELS : Record < string , ( ) => LanguageModel > = {
1821 "gpt-4o-mini" : ( ) => openai ( "gpt-4o-mini" ) ,
1922 "gpt-4o" : ( ) => openai ( "gpt-4o" ) ,
@@ -98,20 +101,8 @@ const webFetch = tool({
98101 let text = await response . text ( ) ;
99102 const contentType = response . headers . get ( "content-type" ) ?? "" ;
100103
101- // Strip HTML to plain text for readability
102104 if ( contentType . includes ( "html" ) ) {
103- text = text
104- . replace ( / < s c r i p t [ \s \S ] * ?< \/ s c r i p t > / gi, "" )
105- . replace ( / < s t y l e [ \s \S ] * ?< \/ s t y l e > / gi, "" )
106- . replace ( / < [ ^ > ] + > / g, " " )
107- . replace ( / & n b s p ; / g, " " )
108- . replace ( / & a m p ; / g, "&" )
109- . replace ( / & l t ; / g, "<" )
110- . replace ( / & g t ; / g, ">" )
111- . replace ( / & q u o t ; / g, '"' )
112- . replace ( / & # 3 9 ; / g, "'" )
113- . replace ( / \s + / g, " " )
114- . trim ( ) ;
105+ text = turndown . turndown ( text ) ;
115106 }
116107
117108 return {
@@ -204,16 +195,7 @@ export const deepResearch = schemaTask({
204195 const contentType = response . headers . get ( "content-type" ) ?? "" ;
205196
206197 if ( contentType . includes ( "html" ) ) {
207- text = text
208- . replace ( / < s c r i p t [ \s \S ] * ?< \/ s c r i p t > / gi, "" )
209- . replace ( / < s t y l e [ \s \S ] * ?< \/ s t y l e > / gi, "" )
210- . replace ( / < [ ^ > ] + > / g, " " )
211- . replace ( / & n b s p ; / g, " " )
212- . replace ( / & a m p ; / g, "&" )
213- . replace ( / & l t ; / g, "<" )
214- . replace ( / & g t ; / g, ">" )
215- . replace ( / \s + / g, " " )
216- . trim ( ) ;
198+ text = turndown . turndown ( text ) ;
217199 }
218200
219201 results . push ( {
0 commit comments