Proofreader
Building block for the Web’s Built-in Proofreader API. Corrects grammar, spelling, and punctuation, returning the fully corrected text plus per-issue corrections with offsets into the original input. Session reuse and pluggable result caching included. The React adapter lives at @web-ai-sdk/proofreader/react; see useProofreader.
Usage
import { proofread } from "@web-ai-sdk/proofreader";
const result = await proofread({ input: "I seen him yesterday at the store, and he bought two loafs of bread.", expectedInputLanguages: ["en"],});
console.log(result.output?.correctedInput);for (const c of result.output?.corrections ?? []) { console.log(c.startIndex, c.endIndex, "→", c.correction);}result.output is null when the input is empty; otherwise correctedInput is the corrected text and corrections is the list of per-issue edits.
Options
interface ProofreadOptions { input: string; expectedInputLanguages?: readonly string[]; monitor?: (m: CreateMonitor) => void; cache?: "session" | "local" | { get, set }; cacheKey?: string; signal?: AbortSignal;}Returns
interface ProofreadCorrection { startIndex: number; // inclusive offset into the original input endIndex: number; // exclusive offset into the original input correction: string; // suggested replacement type?: string; // not emitted by Chrome's current build explanation?: string; // not emitted by Chrome's current build}
interface ProofreadOutput { correctedInput: string; corrections: ProofreadCorrection[];}
interface ProofreadResult { output: ProofreadOutput | null; cached: boolean;}Rendering corrections in place
The corrections offsets index into the original input, so you can highlight each error by slicing between offsets:
let cursor = 0;const spans: Array<{ text: string; error: boolean }> = [];for (const c of output.corrections) { if (c.startIndex > cursor) spans.push({ text: input.slice(cursor, c.startIndex), error: false }); spans.push({ text: input.slice(c.startIndex, c.endIndex), error: true }); cursor = c.endIndex;}if (cursor < input.length) spans.push({ text: input.slice(cursor), error: false });No streaming
Unlike the Writer and Rewriter, the Proofreader has no streaming surface; proofread() resolves once with the full result.
Errors and unavailability
The vanilla proofread() throws ProofreaderUnavailableError when the API is missing:
import { proofread, ProofreaderUnavailableError } from "@web-ai-sdk/proofreader";
try { const result = await proofread({ input: text });} catch (err) { if (err instanceof ProofreaderUnavailableError) return; throw err;}AbortSignal is supported.