docparse

package
v0.7.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 20, 2026 License: Apache-2.0 Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package docparse extracts plain text from uploaded context documents. Markdown/plain text/CSV pass through verbatim; .docx and .xlsx are unzipped and their XML text extracted; .pdf text is extracted with a pure-Go PDF reader after a bounded pre-validation pass. Images are detected but not text-extractable (they are handled by the vision path, not here).

Index

Constants

View Source
const MaxExtractedBytes = 2 << 20

MaxExtractedBytes caps the extracted text per document (mirrors the 2 MiB upload cap, §48 input budget). Extraction is deterministic and bounded.

Variables

This section is empty.

Functions

func ExtractText

func ExtractText(filename string, data []byte) (string, error)

ExtractText returns the plain-text body of a document. Unsupported formats (including images, which need the vision path) return an error so the daemon rejects them rather than ingesting binary garbage.

func ImageMediaType

func ImageMediaType(data []byte) string

ImageMediaType returns the MIME type for a recognized image (by magic bytes) or "" when data is not a JPEG/PNG/GIF/WebP. Used as the media-type allowlist for vision requests instead of content-sniffing.

func InferKind

func InferKind(filename string) string

InferKind guesses the semantic context-doc kind (prd/design/tech/market/ other) from a filename, used when the uploader does not specify one. It is the single canonical mapping shared by the CLI and the daemon.

func Sniff

func Sniff(filename string, data []byte) string

Sniff returns the concrete file format: "pdf", "docx", "xlsx", "image", "text", or "unsupported". Magic bytes win over the extension; unknown binary input is classified "unsupported" so it is never ingested as garbage text. Images are classified by MAGIC BYTES ONLY — an extension-only match is NOT treated as an image, so a text file renamed to .png/.jpg still flows through the text path (credential-swept + redacted) instead of bypassing it.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL