You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Handle content based on requested format and actual content type
94
+
letoutput=""
92
95
switch(params.format){
93
96
case"markdown":
94
97
if(contentType.includes("text/html")){
95
-
constmarkdown=convertHTMLToMarkdown(content)
96
-
return{
97
-
output: markdown,
98
-
title,
99
-
metadata: {},
100
-
}
101
-
}
102
-
return{
103
-
output: content,
104
-
title,
105
-
metadata: {},
98
+
output=convertHTMLToMarkdown(content)
99
+
}else{
100
+
output=content
106
101
}
102
+
break
107
103
108
104
case"text":
109
105
if(contentType.includes("text/html")){
110
-
consttext=awaitextractTextFromHTML(content)
111
-
return{
112
-
output: text,
113
-
title,
114
-
metadata: {},
115
-
}
116
-
}
117
-
return{
118
-
output: content,
119
-
title,
120
-
metadata: {},
106
+
output=awaitextractTextFromHTML(content)
107
+
}else{
108
+
output=content
121
109
}
110
+
break
122
111
123
112
case"html":
124
-
return{
125
-
output: content,
126
-
title,
127
-
metadata: {},
128
-
}
113
+
output=content
114
+
break
129
115
130
116
default:
131
-
return{
132
-
output: content,
133
-
title,
134
-
metadata: {},
135
-
}
117
+
output=content
118
+
}
119
+
120
+
// Truncate if exceeds token limit
121
+
consttokenCount=Token.estimate(output)
122
+
if(tokenCount>MAX_TOKENS){
123
+
constcharsPerToken=4
124
+
constmaxChars=MAX_TOKENS*charsPerToken
125
+
output=output.slice(0,maxChars)
126
+
output+=`\n\n[Content truncated: Response was ~${tokenCount.toLocaleString()} tokens, truncated to ${MAX_TOKENS.toLocaleString()} tokens to avoid exceeding budget]`
0 commit comments