Class DocumentTools

java.lang.Object
com.tnsai.tools.document.DocumentTools

public class DocumentTools extends Object
Function-shape document tools — text extraction, Markdown→HTML, image conversion + metadata, and Reveal.js slide generation. Replaces the legacy DocumentReaderTool, MarkdownConverterTool, ImageConverterTool, and SlideTool.
MethodPurposeIdempotent
documentRead(java.lang.String, java.lang.String)Extract text from URL or local file (HTML strip, PDF via PDFBox if on classpath)true
markdownToHtml(java.lang.String, boolean, java.lang.String)Regex-based Markdown → HTML (h1-h6, bold, italic, code, links, lists)true
imageConvert(java.lang.String, java.lang.String, java.lang.String)Java ImageIO format conversion (PNG / JPG / GIF / BMP)true (deterministic write)
imageInfo(java.lang.String)Width / height / format / sizetrue
slidesCreate(java.lang.String, java.util.List<java.util.Map<java.lang.String, java.lang.Object>>, java.lang.String, java.lang.String)Reveal.js HTML presentation generatortrue (deterministic write)

Pure-JDK + optional PDFBox (already on the tnsai-tools classpath). No API keys, no network for image / markdown / slides; documentRead optionally fetches http(s) URLs.

Since:
0.5.7 (Phase 2 batch 25 — built-in tool migration to function shape, see #188)
  • Field Details

    • DEFAULT_EXTENSIONS

      public static final Set<String> DEFAULT_EXTENSIONS
      Default read/write extension whitelist covering everything DocumentTools handles.
  • Constructor Details

    • DocumentTools

      public DocumentTools()
    • DocumentTools

      public DocumentTools(FileGuardConfig guardConfig)
    • DocumentTools

      public DocumentTools(HttpClient http, com.fasterxml.jackson.databind.ObjectMapper mapper)
    • DocumentTools

      public DocumentTools(HttpClient http, com.fasterxml.jackson.databind.ObjectMapper mapper, FileGuardConfig guardConfig)
  • Method Details

    • documentRead

      @Tool(name="document_read", description="Extract text content from a URL (http/https) or local file. Auto-detects format from extension or content; optional {format} hint overrides (\"text\" / \"html\" / \"markdown\" / \"pdf\"). HTML is tag-stripped to plain text; PDF requires PDFBox on the classpath. Caps result at 100k chars. Read-safe to call repeatedly.", keywords={"document","read","extract","text","html","pdf","url"}, idempotent=true) public String documentRead(@ToolParam(description="URL (http/https) or absolute file path") String source, @ToolParam(description="Optional format hint: text / html / markdown / pdf",required=false,defaultValue="") String format) throws IOException, InterruptedException
      Throws:
      IOException
      InterruptedException
    • markdownToHtml

      @Tool(name="markdown_to_html", description="Convert a Markdown string to HTML. Supports headers (h1-h6), bold (**text**), italic (*text*), inline code (`code`), code fences (```), links ([text](url)), images (![alt](url)), unordered + ordered lists, and paragraphs. {fullDocument}=true wraps in <html><body>\u2026 with optional {title}.", keywords={"markdown","html","convert","render"}, idempotent=true) public String markdownToHtml(@ToolParam(description="Markdown source") String markdown, @ToolParam(description="true \u2192 wrap in <html><head><title>\u2026</title></head><body>\u2026</body></html>",required=false,defaultValue="false") boolean fullDocument, @ToolParam(description="Document title when fullDocument=true",required=false,defaultValue="") String title)
    • imageConvert

      @Tool(name="image_convert", description="Convert an image to a different format using Java ImageIO. {format} \u2208 {png, jpg, gif, bmp}. Returns the absolute path of the written file. Uses ImageIO so supports the JDK\'s bundled readers (PNG / JPG / GIF / BMP / WBMP) on the input side.", keywords={"image","convert","png","jpg","gif","bmp"}, idempotent=true) public String imageConvert(@ToolParam(description="Source image path") String inputPath, @ToolParam(description="Destination image path (parent dirs auto-created)") String outputPath, @ToolParam(description="Output format: png / jpg / jpeg / gif / bmp",required=false,defaultValue="png") String format) throws IOException
      Throws:
      IOException
    • imageInfo

      @Tool(name="image_info", description="Read image metadata: width, height, file size in bytes. Returns a name\u2192value map. Throws NoSuchFileException when the path doesn\'t exist.", keywords={"image","info","metadata","width","height"}, idempotent=true) public Map<String,Object> imageInfo(@ToolParam(description="Image path") String imagePath) throws IOException
      Throws:
      IOException
    • slidesCreate

      @Tool(name="slides_create", description="Generate a Reveal.js HTML presentation. {slides} is a list of slide maps (each with \"title\" + \"content\" keys). {theme} \u2208 {black (default), white, league, beige, sky, night, serif, simple, solarized, moon, dracula}. Returns the absolute path of the written HTML file (CDN-hosted Reveal.js assets \u2014 no local deps).", keywords={"slide","presentation","reveal","html"}, idempotent=true) public String slidesCreate(@ToolParam(description="Presentation title") String title, @ToolParam(description="List of slide maps; each has \"title\" + \"content\" string keys") List<Map<String,Object>> slides, @ToolParam(description="Output HTML file path") String outputPath, @ToolParam(description="Reveal.js theme (default \"black\")",required=false,defaultValue="black") String theme) throws IOException
      Throws:
      IOException