(args, extras)
| 5 | const DEFAULT_FETCH_URL_CHAR_LIMIT = 20000; |
| 6 | |
| 7 | export const fetchUrlContentImpl: ToolImpl = async (args, extras) => { |
| 8 | const url = getStringArg(args, "url"); |
| 9 | |
| 10 | const contextItems = await getUrlContextItems(url, extras.fetch); |
| 11 | |
| 12 | // Track truncated content |
| 13 | const truncatedUrls: string[] = []; |
| 14 | |
| 15 | // Check and truncate each context item |
| 16 | const processedItems = contextItems.map((item) => { |
| 17 | if (item.content.length > DEFAULT_FETCH_URL_CHAR_LIMIT) { |
| 18 | truncatedUrls.push(url); |
| 19 | return { |
| 20 | ...item, |
| 21 | content: item.content.substring(0, DEFAULT_FETCH_URL_CHAR_LIMIT), |
| 22 | }; |
| 23 | } |
| 24 | return item; |
| 25 | }); |
| 26 | |
| 27 | // Add truncation warning if needed |
| 28 | if (truncatedUrls.length > 0) { |
| 29 | processedItems.push({ |
| 30 | name: "Truncation warning", |
| 31 | description: "", |
| 32 | content: `The content from ${truncatedUrls.join(", ")} was truncated because it exceeded the ${DEFAULT_FETCH_URL_CHAR_LIMIT} character limit. If you need more content, consider fetching specific sections or using a more targeted approach.`, |
| 33 | }); |
| 34 | } |
| 35 | |
| 36 | return processedItems; |
| 37 | }; |
no test coverage detected