MCPcopy
hub / github.com/codeaashu/claude-code / tryGetPDFReference

Function tryGetPDFReference

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

Source from the content-addressed store, hash-verified

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