@librechat/agents 2.4.316 → 2.4.318
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/tools/search/content.cjs +140 -0
- package/dist/cjs/tools/search/content.cjs.map +1 -0
- package/dist/cjs/tools/search/firecrawl.cjs +17 -37
- package/dist/cjs/tools/search/firecrawl.cjs.map +1 -1
- package/dist/cjs/tools/search/format.cjs +79 -29
- package/dist/cjs/tools/search/format.cjs.map +1 -1
- package/dist/cjs/tools/search/highlights.cjs +64 -13
- package/dist/cjs/tools/search/highlights.cjs.map +1 -1
- package/dist/cjs/tools/search/search.cjs +13 -15
- package/dist/cjs/tools/search/search.cjs.map +1 -1
- package/dist/cjs/tools/search/tool.cjs +44 -12
- package/dist/cjs/tools/search/tool.cjs.map +1 -1
- package/dist/cjs/tools/search/utils.cjs +35 -0
- package/dist/cjs/tools/search/utils.cjs.map +1 -0
- package/dist/esm/tools/search/content.mjs +119 -0
- package/dist/esm/tools/search/content.mjs.map +1 -0
- package/dist/esm/tools/search/firecrawl.mjs +18 -37
- package/dist/esm/tools/search/firecrawl.mjs.map +1 -1
- package/dist/esm/tools/search/format.mjs +79 -29
- package/dist/esm/tools/search/format.mjs.map +1 -1
- package/dist/esm/tools/search/highlights.mjs +64 -13
- package/dist/esm/tools/search/highlights.mjs.map +1 -1
- package/dist/esm/tools/search/search.mjs +12 -14
- package/dist/esm/tools/search/search.mjs.map +1 -1
- package/dist/esm/tools/search/tool.mjs +44 -12
- package/dist/esm/tools/search/tool.mjs.map +1 -1
- package/dist/esm/tools/search/utils.mjs +32 -0
- package/dist/esm/tools/search/utils.mjs.map +1 -0
- package/dist/types/tools/search/content.d.ts +4 -0
- package/dist/types/tools/search/firecrawl.d.ts +6 -86
- package/dist/types/tools/search/format.d.ts +4 -1
- package/dist/types/tools/search/highlights.d.ts +1 -1
- package/dist/types/tools/search/search.d.ts +1 -1
- package/dist/types/tools/search/test.d.ts +1 -0
- package/dist/types/tools/search/tool.d.ts +12 -4
- package/dist/types/tools/search/types.d.ts +380 -46
- package/dist/types/tools/search/utils.d.ts +3 -0
- package/package.json +3 -2
- package/src/scripts/search.ts +5 -3
- package/src/tools/search/content.test.ts +173 -0
- package/src/tools/search/content.ts +147 -0
- package/src/tools/search/firecrawl.ts +27 -144
- package/src/tools/search/format.ts +89 -31
- package/src/tools/search/highlights.ts +99 -17
- package/src/tools/search/output.md +2775 -0
- package/src/tools/search/search.ts +42 -54
- package/src/tools/search/test.html +884 -0
- package/src/tools/search/test.md +643 -0
- package/src/tools/search/test.ts +159 -0
- package/src/tools/search/tool.ts +54 -15
- package/src/tools/search/types.ts +430 -52
- package/src/tools/search/utils.ts +43 -0
|
@@ -122,6 +122,89 @@ function findBestBoundary(text: string, direction = 'backward'): number {
|
|
|
122
122
|
return direction === 'backward' ? text.length : 0;
|
|
123
123
|
}
|
|
124
124
|
|
|
125
|
+
/**
|
|
126
|
+
* Tracks references used in a highlight without changing their numbers
|
|
127
|
+
*/
|
|
128
|
+
function trackReferencesInHighlight(
|
|
129
|
+
text: string,
|
|
130
|
+
sourceResult: t.ValidSource // Source containing the original references
|
|
131
|
+
): {
|
|
132
|
+
references: {
|
|
133
|
+
type: 'link' | 'image' | 'video';
|
|
134
|
+
originalIndex: number;
|
|
135
|
+
reference: t.MediaReference; // Original reference object
|
|
136
|
+
}[];
|
|
137
|
+
} {
|
|
138
|
+
// Track used references
|
|
139
|
+
const references: {
|
|
140
|
+
type: 'link' | 'image' | 'video';
|
|
141
|
+
originalIndex: number;
|
|
142
|
+
reference: t.MediaReference;
|
|
143
|
+
}[] = [];
|
|
144
|
+
|
|
145
|
+
if (!text || text.length === 0 || !text.includes('#')) {
|
|
146
|
+
return { references }; // Early return
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// Quick check for reference markers
|
|
150
|
+
if (
|
|
151
|
+
!text.includes('link#') &&
|
|
152
|
+
!text.includes('image#') &&
|
|
153
|
+
!text.includes('video#')
|
|
154
|
+
) {
|
|
155
|
+
return { references };
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// Get references from the source if available
|
|
159
|
+
const sourceRefs = sourceResult.references || {
|
|
160
|
+
links: [],
|
|
161
|
+
images: [],
|
|
162
|
+
videos: [],
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
// Find references but don't modify text
|
|
166
|
+
const refRegex = /\((link|image|video)#(\d+)(?:\s+"([^"]*)")?\)/g;
|
|
167
|
+
let match;
|
|
168
|
+
|
|
169
|
+
while ((match = refRegex.exec(text)) !== null) {
|
|
170
|
+
const [, type, indexStr] = match;
|
|
171
|
+
const originalIndex = parseInt(indexStr, 10) - 1; // Convert to 0-based
|
|
172
|
+
|
|
173
|
+
// Get the source array for this type
|
|
174
|
+
const refType = type as 'link' | 'image' | 'video';
|
|
175
|
+
const sourceArray = sourceRefs[`${refType}s`] as
|
|
176
|
+
| t.MediaReference[]
|
|
177
|
+
| undefined;
|
|
178
|
+
|
|
179
|
+
// Skip if invalid reference
|
|
180
|
+
if (
|
|
181
|
+
!sourceArray ||
|
|
182
|
+
originalIndex < 0 ||
|
|
183
|
+
originalIndex >= sourceArray.length
|
|
184
|
+
) {
|
|
185
|
+
continue; // Skip invalid references
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// Get original reference
|
|
189
|
+
const reference = sourceArray[originalIndex];
|
|
190
|
+
|
|
191
|
+
// Track if not already tracked
|
|
192
|
+
const alreadyTracked = references.some(
|
|
193
|
+
(ref) => ref.type === refType && ref.originalIndex === originalIndex
|
|
194
|
+
);
|
|
195
|
+
|
|
196
|
+
if (!alreadyTracked) {
|
|
197
|
+
references.push({
|
|
198
|
+
type: refType,
|
|
199
|
+
originalIndex,
|
|
200
|
+
reference,
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
return { references };
|
|
206
|
+
}
|
|
207
|
+
|
|
125
208
|
/**
|
|
126
209
|
* Expand highlights in search results using smart boundary detection.
|
|
127
210
|
*
|
|
@@ -131,25 +214,19 @@ function findBestBoundary(text: string, direction = 'backward'): number {
|
|
|
131
214
|
* @param searchResults - Search results object
|
|
132
215
|
* @param mainExpandBy - Primary expansion size on each side (default: 300)
|
|
133
216
|
* @param separatorExpandBy - Additional range to look for separators (default: 150)
|
|
134
|
-
* @returns Copy of search results with expanded highlights
|
|
217
|
+
* @returns Copy of search results with expanded highlights and tracked references
|
|
135
218
|
*/
|
|
136
219
|
export function expandHighlights(
|
|
137
220
|
searchResults: t.SearchResultData,
|
|
138
221
|
mainExpandBy = 300,
|
|
139
222
|
separatorExpandBy = 150
|
|
140
223
|
): t.SearchResultData {
|
|
141
|
-
//
|
|
224
|
+
// Avoid deep copy - only copy what we modify
|
|
142
225
|
const resultCopy = { ...searchResults };
|
|
226
|
+
if (resultCopy.organic) resultCopy.organic = [...resultCopy.organic];
|
|
227
|
+
if (resultCopy.topStories) resultCopy.topStories = [...resultCopy.topStories];
|
|
143
228
|
|
|
144
|
-
//
|
|
145
|
-
if (resultCopy.organic) {
|
|
146
|
-
resultCopy.organic = [...resultCopy.organic];
|
|
147
|
-
}
|
|
148
|
-
if (resultCopy.topStories) {
|
|
149
|
-
resultCopy.topStories = [...resultCopy.topStories];
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
// 5. Process the results efficiently
|
|
229
|
+
// Process the results efficiently
|
|
153
230
|
const processResultTypes = ['organic', 'topStories'] as const;
|
|
154
231
|
|
|
155
232
|
for (const resultType of processResultTypes) {
|
|
@@ -170,23 +247,26 @@ export function expandHighlights(
|
|
|
170
247
|
const resultCopy = { ...result };
|
|
171
248
|
const content = result.content;
|
|
172
249
|
const highlights = [];
|
|
173
|
-
|
|
174
250
|
// Process each highlight
|
|
175
251
|
for (const highlight of result.highlights) {
|
|
176
|
-
const
|
|
252
|
+
const { references } = trackReferencesInHighlight(
|
|
253
|
+
highlight.text,
|
|
254
|
+
result
|
|
255
|
+
);
|
|
177
256
|
|
|
178
|
-
let startPos = content.indexOf(
|
|
179
|
-
let highlightLen =
|
|
257
|
+
let startPos = content.indexOf(highlight.text);
|
|
258
|
+
let highlightLen = highlight.text.length;
|
|
180
259
|
|
|
181
260
|
if (startPos === -1) {
|
|
182
261
|
// Try with stripped whitespace
|
|
183
|
-
const strippedHighlight =
|
|
262
|
+
const strippedHighlight = highlight.text.trim();
|
|
184
263
|
startPos = content.indexOf(strippedHighlight);
|
|
185
264
|
|
|
186
265
|
if (startPos === -1) {
|
|
187
266
|
highlights.push({
|
|
188
267
|
text: highlight.text,
|
|
189
268
|
score: highlight.score,
|
|
269
|
+
references,
|
|
190
270
|
});
|
|
191
271
|
continue;
|
|
192
272
|
}
|
|
@@ -225,11 +305,13 @@ export function expandHighlights(
|
|
|
225
305
|
highlights.push({
|
|
226
306
|
text: expandedHighlightText,
|
|
227
307
|
score: highlight.score,
|
|
308
|
+
references,
|
|
228
309
|
});
|
|
229
310
|
}
|
|
230
311
|
|
|
231
|
-
delete resultCopy.content;
|
|
232
312
|
resultCopy.highlights = highlights;
|
|
313
|
+
delete resultCopy.content;
|
|
314
|
+
delete resultCopy.references;
|
|
233
315
|
return resultCopy;
|
|
234
316
|
});
|
|
235
317
|
}
|