MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / tryGetPDFReference

Function tryGetPDFReference

source code/utils/attachments.ts:2988–3020  ·  view source on GitHub ↗
(
  filename: string,
)

Source from the content-addressed store, hash-verified

2986 * (more than PDF_AT_MENTION_INLINE_THRESHOLD pages), or null otherwise.
2987 */
2988export async function tryGetPDFReference(
2989 filename: string,
2990): Promise<PDFReferenceAttachment | null> {
2991 const ext = parse(filename).ext.toLowerCase()
2992 if (!isPDFExtension(ext)) {
2993 return null
2994 }
2995 try {
2996 const [stats, pageCount] = await Promise.all([
2997 getFsImplementation().stat(filename),
2998 getPDFPageCount(filename),
2999 ])
3000 // Use page count if available, otherwise fall back to size heuristic (~100KB per page)
3001 const effectivePageCount = pageCount ?? Math.ceil(stats.size / (100 * 1024))
3002 if (effectivePageCount > PDF_AT_MENTION_INLINE_THRESHOLD) {
3003 logEvent('tengu_pdf_reference_attachment', {
3004 pageCount: effectivePageCount,
3005 fileSize: stats.size,
3006 hadPdfinfo: pageCount !== null,
3007 } as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS)
3008 return {
3009 type: 'pdf_reference',
3010 filename,
3011 pageCount: effectivePageCount,
3012 fileSize: stats.size,
3013 displayPath: relative(getCwd(), filename),
3014 }
3015 }
3016 } catch {
3017 // If we can't stat the file, return null to proceed with normal reading
3018 }
3019 return null
3020}
3021
3022export async function generateFileAttachment(
3023 filename: string,

Callers 1

generateFileAttachmentFunction · 0.85

Calls 6

parseFunction · 0.85
isPDFExtensionFunction · 0.85
getFsImplementationFunction · 0.85
getPDFPageCountFunction · 0.85
logEventFunction · 0.85
getCwdFunction · 0.85

Tested by

no test coverage detected