@@ -15,9 +15,10 @@ export const chatWithPageContent = definePrompt(async (question: string, pages:
15
15
? `<search_results>
16
16
${ onlineInfo
17
17
. map ( ( page , idx ) => {
18
+ const text = page . textContent ?. replace ( / ( \s | \t ) + / g, ' ' ) . replace ( / \n + / g, '\n' ) . trim ( ) ?? ''
18
19
return `<search_result id="${ idx + 1 } ">
19
20
Title: ${ page . title ?? '' } | URL: ${ page . url ?? '' }
20
- ${ page . textContent ?? '' }
21
+ ${ text }
21
22
</search_result>
22
23
`
23
24
} )
@@ -28,9 +29,10 @@ ${page.textContent ?? ''}
28
29
const tabContext = `<tabs_context>
29
30
${ pages
30
31
. map ( ( page , _idx ) => {
32
+ const text = page . textContent ?. replace ( / ( \s | \t ) + / g, ' ' ) . replace ( / \n + / g, '\n' ) . trim ( ) ?? ''
31
33
return `<tab>
32
34
Title: ${ page . title ?? '' } | URL: ${ page . url ?? '' }
33
- ${ page . textContent ?? '' }
35
+ ${ text }
34
36
</tab>
35
37
`
36
38
} )
@@ -48,10 +50,11 @@ Question: ${question}`
48
50
export const summarizeWithPageContent = definePrompt ( async ( page : Page , question : string ) => {
49
51
const userConfig = await getUserConfig ( )
50
52
const system = userConfig . llm . summarizeSystemPrompt . get ( )
53
+ const pageText = page . textContent ?. replace ( / ( \s | \t ) + / g, ' ' ) . replace ( / \n + / g, '\n' ) . trim ( ) ?? ''
51
54
52
55
const user = `<tab_context>
53
56
Title: ${ page . title ?? '' } | URL: ${ page . url ?? '' }
54
- ${ page . textContent ?? '' }
57
+ ${ pageText }
55
58
</tab_context>
56
59
57
60
Question: ${ question } `
@@ -85,7 +88,7 @@ Note: Each tab content shows only the first 1000 characters. Consider whether th
85
88
86
89
${ pages
87
90
. map ( ( page ) => {
88
- const text = page . textContent ?. replace ( / \s + / g, ' ' ) . trim ( ) ?? ''
91
+ const text = page . textContent ?. replace ( / ( \s | \t ) + / g, ' ' ) . replace ( / \n + / g , '\n ') . trim ( ) ?? ''
89
92
const length = text ?. length ?? 0
90
93
const truncatedText = length > 1000 ? text . slice ( 0 , 1000 ) + '...[content truncated]' : text
91
94
return `<tab>
@@ -124,7 +127,7 @@ Return only the keywords in a JSON array without any explanations.`
124
127
? `<tabs_context>
125
128
${ pages
126
129
. map ( ( page ) => {
127
- const text = page . textContent ?. replace ( / \s + / g, ' ' ) . trim ( ) ?? ''
130
+ const text = page . textContent ?. replace ( / ( \s | \t ) + / g, ' ' ) . replace ( / \n + / g , '\n ') . trim ( ) ?? ''
128
131
const length = text ?. length ?? 0
129
132
const truncatedText = length > 1000 ? text . slice ( 0 , 1000 ) + '...[content truncated]' : text
130
133
return `<tab>
0 commit comments