# Convert Lab: guide for AI agents

Convert Lab converts video, audio, images (including HEIC), PDF, Word, EPUB, Markdown, GIF and ZIP/TAR archives **inside the browser tab**. Files are never uploaded. Page: https://vijayathuluri.netlify.app/portfolioprojects/convert-lab.html

There are three ways in. Use the first one you have.

## 1. WebMCP tools (browser agents)

If your browser exposes `document.modelContext`, the page registers these tools:

| Tool | Hints | Purpose |
|---|---|---|
| `list_conversions` | readOnly | Formats, reachable targets, option keys, ready-made recipes with share links |
| `inspect_file` | readOnly | Real format from signature bytes, extension mismatch, photo camera/GPS metadata |
| `plan_conversion` | readOnly | Dry run: engine per step, exact ffmpeg command with each flag explained, expected size change |
| `convert_file` | none | Converts and returns base64 outputs; results also appear on the page for the person |
| `convert_units` | readOnly | Length, mass, volume, area, speed, storage (KB vs KiB), time, energy, temperature |
| `convert_time` | readOnly | DST-aware time-zone conversion and Unix timestamps |

Pass files as `files: [{name, base64}]` or `files: [{url}]` (fetched by the page, so CORS applies), or use `loadedFileIndex` for files the person already dropped on the page.

## 2. JavaScript API (`window.convertLab`)

For agents that run scripts in the page (browser automation, DevTools):

```js
await convertLab.listConversions({ from: 'heic' })
await convertLab.inspect({ files: [fileOrBlob] })
await convertLab.plan({ from: 'mov', recipe: 'mp4:maxsize=10MB|gif:width=480' })
const r = await convertLab.convert({ files: [blob], to: 'mp4', options: { maxsize: '9.5MB', width: 1280 } })
// r.outputs[i] = { outputId, name, mime, size, base64 }
```

For big files, use `beginUpload({name})` → `uploadChunk({uploadId, base64})` → `convert({files:[{uploadId}], returnData:false})` → `readOutput({outputId, offset, length})`. Every call is shown to the person in the page's **Agents** tab.

## 3. MCP server / Claude Code plugin (files on disk)

```
/plugin marketplace add vathuluri/personalblog
/plugin install convert-lab@vijay-tools
```

Tools: `convert_files`, `inspect_files`, `plan_conversion`, `list_conversions`, `convert_units`, `convert_time`. The server has no npm dependencies. It drives this page in a local headless Chrome/Edge, and writes outputs next to the inputs without overwriting.

## Recipes

`target[:key=value,key=value][|next step]`. Each step's output feeds the next. Share link: `convert-lab.html#recipe=<url-encoded recipe>`.

| Recipe | Use |
|---|---|
| `mp4:maxsize=24MB,width=1280` | Email attachment |
| `mp4:maxsize=9.5MB,width=1280` | Discord / Slack |
| `gif:duration=6,width=480,fps=12` | Shareable GIF from a clip |
| `webp:width=1600,quality=80` | Web photos; strips EXIF/GPS |
| `jpg:width=1800,quality=82\|pdf:page=a4` | Phone photos (HEIC too) → one PDF |
| `mp3:bitrate=128k` | Podcast audio from video |
| `ico` | Favicon with 16–256 px sizes |

## Options

`quality` (40–100) · `width` (px) · `maxsize` ("10MB": solves bitrate from duration for audio/video, binary-searches quality for images) · `start`, `duration` (s) · `fps` · `crf` · `bitrate` ("128k") · `copy` (remux without re-encoding) · `colors` (SVG tracing) · `page` ("fit" | "a4") · `delay` (s per image in GIFs) · `dpi`, `pages` ("1-3,7") for PDFs · `engine` ("html2pdf" | "print"; agents should leave this as html2pdf)

## Behaviors worth knowing

- Formats are detected from bytes, not names. A `.jpg` that is really WebP is converted correctly and reported as a mismatch.
- Re-encoding through a canvas drops all EXIF, so photo GPS location is removed.
- PDF → Word/EPUB/TXT keeps text only. Scanned PDFs have no text layer (that needs OCR).
- ffmpeg is single-threaded WebAssembly: about 3–10× slower than native. Its 31 MB core loads on first use.
