MCPcopy Create free account
hub / github.com/HELPMEEADICE/doge-code / tryGetPDFReference

Function tryGetPDFReference

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

Source from the content-addressed store, hash-verified

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

Callers 1

generateFileAttachmentFunction · 0.85

Calls 6

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

Tested by

no test coverage detected