Skip to content

Commit a1a51f1

Browse files
Add full context length with a hard upper limit
1 parent 32d7491 commit a1a51f1

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

injected/src/features/duck-ai-listener.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1380,6 +1380,7 @@ class DuckAiPromptTelemetry {
13801380
/**
13811381
* Send context pixel info when context is used
13821382
* @param {Object} contextData - Context data object
1383+
* @param {string} pixelName - Name of pixel to fire
13831384
*/
13841385
sendContextPixelInfo(contextData, pixelName) {
13851386
if (!contextData?.content || contextData.content.length === 0) {
@@ -1388,7 +1389,7 @@ class DuckAiPromptTelemetry {
13881389
}
13891390

13901391
this.sendPixel(pixelName, {
1391-
contextLength: contextData.content.length,
1392+
contextLength: contextData.fullContentLength
13921393
});
13931394
}
13941395

injected/src/features/page-context.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ export default class PageContext extends ContentFeature {
243243
metaDescription: this.getMetaDescription(),
244244
content: mainContent,
245245
truncated,
246+
fullContentLength: this.fullContentLength, // Include full content length before truncation
246247
headings: this.getHeadings(),
247248
links: this.getLinks(),
248249
images: this.getImages(),
@@ -272,7 +273,9 @@ export default class PageContext extends ContentFeature {
272273
}
273274

274275
getMainContent() {
275-
const maxLength = this.getFeatureSetting('maxContentLength') || 950;
276+
const maxLength = this.getFeatureSetting('maxContentLength') || 9500;
277+
// Used to avoid large content serialization
278+
const upperLimit = this.getFeatureSetting('upperLimit') || 500000;
276279
let excludeSelectors = this.getFeatureSetting('excludeSelectors') || ['.ad', '.sidebar', '.footer', '.nav', '.header'];
277280
excludeSelectors = excludeSelectors.concat(['script', 'style', 'link', 'meta', 'noscript', 'svg', 'canvas']);
278281

@@ -296,16 +299,20 @@ export default class PageContext extends ContentFeature {
296299
});
297300

298301
this.log.info('Calling domToMarkdown', clone.innerHTML);
299-
content += domToMarkdown(clone, maxLength);
302+
content += domToMarkdown(clone, upperLimit);
300303
}
304+
content = content.trim();
305+
306+
// Store the full content length before truncation
307+
this.fullContentLength = content.length;
301308

302309
// Limit content length
303310
if (content.length > maxLength) {
304311
this.log.info('Truncating content', content);
305312
content = content.substring(0, maxLength) + '...';
306313
}
307314

308-
return content.trim();
315+
return content;
309316
}
310317

311318
getHeadings() {

0 commit comments

Comments
 (0)