( url: string, abortController: AbortController, )
| 382 | } |
| 383 | |
| 384 | export async function getURLMarkdownContent( |
| 385 | url: string, |
| 386 | abortController: AbortController, |
| 387 | ): Promise<FetchedContent | RedirectInfo> { |
| 388 | if (!validateURL(url)) { |
| 389 | throw new Error('Invalid URL') |
| 390 | } |
| 391 | |
| 392 | // Check cache (LRUCache handles TTL automatically) |
| 393 | const cachedEntry = URL_CACHE.get(url) |
| 394 | if (cachedEntry) { |
| 395 | return { |
| 396 | bytes: cachedEntry.bytes, |
| 397 | code: cachedEntry.code, |
| 398 | codeText: cachedEntry.codeText, |
| 399 | content: cachedEntry.content, |
| 400 | contentType: cachedEntry.contentType, |
| 401 | persistedPath: cachedEntry.persistedPath, |
| 402 | persistedSize: cachedEntry.persistedSize, |
| 403 | } |
| 404 | } |
| 405 | |
| 406 | let parsedUrl: URL |
| 407 | let upgradedUrl = url |
| 408 | |
| 409 | try { |
| 410 | parsedUrl = new URL(url) |
| 411 | |
| 412 | // Upgrade http to https if needed |
| 413 | if (parsedUrl.protocol === 'http:') { |
| 414 | parsedUrl.protocol = 'https:' |
| 415 | upgradedUrl = parsedUrl.toString() |
| 416 | } |
| 417 | |
| 418 | const hostname = parsedUrl.hostname |
| 419 | |
| 420 | // Check if the user has opted to skip the blocklist check |
| 421 | // This is for enterprise customers with restrictive security policies |
| 422 | // that prevent outbound connections to claude.ai |
| 423 | const settings = getSettings_DEPRECATED() |
| 424 | if (!settings.skipWebFetchPreflight) { |
| 425 | const checkResult = await checkDomainBlocklist(hostname) |
| 426 | switch (checkResult.status) { |
| 427 | case 'allowed': |
| 428 | // Continue with the fetch |
| 429 | break |
| 430 | case 'blocked': |
| 431 | throw new DomainBlockedError(hostname) |
| 432 | case 'check_failed': |
| 433 | throw new DomainCheckFailedError(hostname) |
| 434 | } |
| 435 | } |
| 436 | |
| 437 | if (process.env.USER_TYPE === 'ant') { |
| 438 | logEvent('tengu_web_fetch_host', { |
| 439 | hostname: |
| 440 | hostname as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS, |
| 441 | }) |
no test coverage detected