Package com.tnsai.tools.document
Class DocumentTools
java.lang.Object
com.tnsai.tools.document.DocumentTools
Function-shape document tools — text extraction, Markdown→HTML, image
conversion + metadata, and Reveal.js slide generation. Replaces the
legacy
DocumentReaderTool, MarkdownConverterTool,
ImageConverterTool, and SlideTool.
| Method | Purpose | Idempotent |
|---|---|---|
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 / size | true |
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 generator | true (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 Summary
FieldsModifier and TypeFieldDescriptionDefault read/write extension whitelist covering everything DocumentTools handles. -
Constructor Summary
ConstructorsConstructorDescriptionDocumentTools(FileGuardConfig guardConfig) DocumentTools(HttpClient http, com.fasterxml.jackson.databind.ObjectMapper mapper) DocumentTools(HttpClient http, com.fasterxml.jackson.databind.ObjectMapper mapper, FileGuardConfig guardConfig) -
Method Summary
Modifier and TypeMethodDescriptiondocumentRead(String source, String format) imageConvert(String inputPath, String outputPath, String format) markdownToHtml(String markdown, boolean fullDocument, String title)
-
Field Details
-
DEFAULT_EXTENSIONS
Default read/write extension whitelist covering everything DocumentTools handles.
-
-
Constructor Details
-
DocumentTools
public DocumentTools() -
DocumentTools
-
DocumentTools
-
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:
IOExceptionInterruptedException
-
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 (), 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
-