# web Web fetch, search, and image tools for Pi. ## Install / load Loaded through the root `pi-ext` package. See [../../README.md](../../README.md). ## Commands / tools / settings Commands: none. Tools: - `web_fetch` - `url`: URL to fetch. - `format`: optional; `markdown` default, or `text`, `html`, `json`, `raw`. - `maxChars`: optional; default `100000`. - `timeout`: optional; default `120000` ms. - `web_search` - `query`: search query. - `count`: optional; default `5`, max `20`. - `format`: optional; `text` default, or `json`. - `timeout`: optional; default `120000` ms. - `understand_image` - `prompt`: image question or extraction request. - `image_source`: HTTP/HTTPS URL, local path, `@`-prefixed local path, or data URL. Hooks: - `session_shutdown`: removes temp dirs created for fetched binary/image/media/PDF/office content. Settings: none registered. External binaries used when needed: - `pandoc`: HTML conversion; DOCX/ODT/EPUB/RTF extraction. - `pdftotext`: PDF extraction. - `identify`: image metadata. - `ffprobe`: audio/video metadata. Provider/env config read by source: - Z.AI search key: Pi model registry providers `zai`, `z-ai`, `z.ai`, `bigmodel`; fallback env `ZAI_API_KEY`, `Z_AI_API_KEY`. - Z.AI search endpoint/options: `ZAI_SEARCH_MCP_URL`, `ZAI_SEARCH_BASE_URL`, `ZAI_SEARCH_FRESHNESS`, `ZAI_SEARCH_CONTENT_SIZE`, `ZAI_SEARCH_LOCATION`. - MiniMax key: Pi model registry provider `minimax`; fallback env `MINIMAX_API_KEY`. - MiniMax base URL: model registry providers `minimax`, `minimax-cn`; fallback env `MINIMAX_API_HOST`. ## Behavior - `web_fetch` uses native `fetch` with browser-like headers and a per-host referer. - Content routing is based on `Content-Type`: - HTML/XHTML: strips common prompt-injection delivery vectors, extracts main content, converts with `pandoc` and `llm-extract.lua`. - Text/XML/YAML/CSV/TSV: returns UTF-8 text. - JSON: pretty-prints when parseable, otherwise returns raw text. - PDF: writes temp file, runs `pdftotext -layout`. - DOCX/ODT/EPUB/RTF: writes temp file, runs `pandoc` to plain text. - Images: writes temp file, returns metadata from `identify`, plus inline image content. - Audio/video: writes temp file, returns summary and `ffprobe` JSON. - Other binary: writes temp file and returns path plus content type. - HTML cleanup removes comments, scripts, styles, iframes, objects, templates, noscript blocks, embeds, hidden inputs, long meta content, hidden/visually-hidden elements, and non-image `aria-label`/`alt`/`title` attrs. - Main-content extraction prefers `
`, `#mw-content-text`, `#docContent`, `#content`, `
`, then `role="main"`; fallback is full page. - Fetched and searched text returned to the model is wrapped as untrusted external data. - `web_search` provider order: Z.AI Coding Plan MCP when configured, then MiniMax search when configured, then DuckDuckGo HTML. - DuckDuckGo fallback throttles requests to at least 2 seconds apart and reports captcha/dedup diagnostics. - `understand_image` sends the prompt and image data to MiniMax VLM. It accepts HTTP/HTTPS URLs, data URLs, and local files. Local file data is base64 encoded before the request. ## Demo ![Tools suite](assets/tools_suite.gif)