MCPcopy Index your code
hub / github.com/claude-code-best/claude-code / tryGetPDFReference

Function tryGetPDFReference

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

Source from the content-addressed store, hash-verified

3066 * (more than PDF_AT_MENTION_INLINE_THRESHOLD pages), or null otherwise.
3067 */
3068export async function tryGetPDFReference(
3069 filename: string,
3070): Promise<PDFReferenceAttachment | null> {
3071 const ext = parse(filename).ext.toLowerCase()
3072 if (!isPDFExtension(ext)) {
3073 return null
3074 }
3075 try {
3076 const [stats, pageCount] = await Promise.all([
3077 getFsImplementation().stat(filename),
3078 getPDFPageCount(filename),
3079 ])
3080 // Use page count if available, otherwise fall back to size heuristic (~100KB per page)
3081 const effectivePageCount = pageCount ?? Math.ceil(stats.size / (100 * 1024))
3082 if (effectivePageCount > PDF_AT_MENTION_INLINE_THRESHOLD) {
3083 logEvent('tengu_pdf_reference_attachment', {
3084 pageCount: effectivePageCount,
3085 fileSize: stats.size,
3086 hadPdfinfo: pageCount !== null,
3087 } as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS)
3088 return {
3089 type: 'pdf_reference',
3090 filename,
3091 pageCount: effectivePageCount,
3092 fileSize: stats.size,
3093 displayPath: relative(getCwd(), filename),
3094 }
3095 }
3096 } catch {
3097 // If we can't stat the file, return null to proceed with normal reading
3098 }
3099 return null
3100}
3101
3102export async function generateFileAttachment(
3103 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