( url: string, abortController: AbortController, )
| 345 | } |
| 346 | |
| 347 | export async function getURLMarkdownContent( |
| 348 | url: string, |
| 349 | abortController: AbortController, |
| 350 | ): Promise<FetchedContent | RedirectInfo> { |
| 351 | if (!validateURL(url)) { |
| 352 | throw new Error('Invalid URL') |
| 353 | } |
| 354 | |
| 355 | // Check cache (LRUCache handles TTL automatically) |
| 356 | const cachedEntry = URL_CACHE.get(url) |
| 357 | if (cachedEntry) { |
| 358 | return { |
| 359 | bytes: cachedEntry.bytes, |
| 360 | code: cachedEntry.code, |
| 361 | codeText: cachedEntry.codeText, |
| 362 | content: cachedEntry.content, |
| 363 | contentType: cachedEntry.contentType, |
| 364 | persistedPath: cachedEntry.persistedPath, |
| 365 | persistedSize: cachedEntry.persistedSize, |
| 366 | } |
| 367 | } |
| 368 | |
| 369 | let parsedUrl: URL |
| 370 | let upgradedUrl = url |
| 371 | |
| 372 | try { |
| 373 | parsedUrl = new URL(url) |
| 374 | |
| 375 | // Upgrade http to https if needed |
| 376 | if (parsedUrl.protocol === 'http:') { |
| 377 | parsedUrl.protocol = 'https:' |
| 378 | upgradedUrl = parsedUrl.toString() |
| 379 | } |
| 380 | |
| 381 | const hostname = parsedUrl.hostname |
| 382 | |
| 383 | // Check if the user has opted to skip the blocklist check |
| 384 | // This is for enterprise customers with restrictive security policies |
| 385 | // that prevent outbound connections to claude.ai |
| 386 | const settings = getSettings_DEPRECATED() |
| 387 | if (!settings.skipWebFetchPreflight) { |
| 388 | const checkResult = await checkDomainBlocklist(hostname) |
| 389 | switch (checkResult.status) { |
| 390 | case 'allowed': |
| 391 | // Continue with the fetch |
| 392 | break |
| 393 | case 'blocked': |
| 394 | throw new DomainBlockedError(hostname) |
| 395 | case 'check_failed': |
| 396 | throw new DomainCheckFailedError(hostname) |
| 397 | } |
| 398 | } |
| 399 | |
| 400 | if (process.env.USER_TYPE === 'ant') { |
| 401 | logEvent('tengu_web_fetch_host', { |
| 402 | hostname: |
| 403 | hostname as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS, |
| 404 | }) |
no test coverage detected