AGENT SKILL

sandbox-ocr

Read the text in an image from a Code node or CodeAct action, with tesseract.js running on the host

License 许可
AGPL-3.0
最近更新
2026-08-18
Stars
★ 1
Forks
0

01 前言 Front Matter

name
sandbox-ocr
description
Read the text in an image from a Code node or CodeAct action, with tesseract.js running on the host

02 资源文件 1

03 SKILL.md 正文

OCR in the sandbox

Specifier: @nodetool-ai/sandbox-ocr. Declare it in the node's packages property and import it at the top of the body.

tesseract.js runs a WASM engine, spawns workers, and downloads its language data on first use — none of which the guest can do. This pack is a host module: the import resolves to a generated facade over NodeTool's own implementation.

recognize — image bytes to text

import { recognize } from "@nodetool-ai/sandbox-ocr";

const { text, confidence, words } = await recognize(
  await workspace.readBytes("receipt.png")
);
const total = words.find((w) => /^\d+[.,]\d{2}$/.test(w.text));
return { text, confidence, total: total?.text ?? null };

One call gives you all three readings:

  • text — the whole page as one string.
  • confidence — the page mean, 0–100.
  • words — {text, confidence, bbox: {x, y, width, height}} per word, in reading order, with the box in image pixels.

Pass { language: "eng+deu" } for anything other than English; the codes are Tesseract's, +-joined. The data file for a language it has not seen before is downloaded the first time you ask for it, so that call is slower.

Get the bytes from workspace.readBytes, from await response.bytes(), or from an asset with assetToSandbox.

Gotchas

  • recognize is async, and the first call to it pays for engine startup.
  • 10 MB per image. Larger input is refused by name.
  • 20 000 words per page.
  • Straight, sharp scans read best. Use image.rotate and image.adjust to deskew and raise contrast before you hand the bytes over.

04 同仓库更多 Skills