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

Function tryGetPDFReference

src/utils/attachments.ts:2987–3019  ·  view source on GitHub ↗
(
  filename: string,
)

Source from the content-addressed store, hash-verified

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