- ClayJS
- Reference
- Plugins
- ai-edit
ai-edit
Comment-to-edit AI editing built on the wire: select text, describe the change, keep or revert it.
Comment-to-edit AI editing, built on the wire. Hover a heading or paragraph for the chip, press ⌘J with the caret in one (a selection rides along as a quote), click bare section padding for the nearest unit, or use the bottom-right bubble for the whole page. The comment goes to the host’s ai-edit helper as a named wire request and comes back as that element’s HTML, morphed in place: Keep saves it, Revert puts the snapshot back. @file.ext in the comment adds context, and @page saves the page first so the helper reads it from disk.
Loading#
<script src="https://clayjs.com/v1/clay.js?plugins=ai-edit"></script>
Check “AI editing” in the configurator, or add ?plugins=ai-edit yourself. Asking for ai-edit loads wire with it. It is dormant unless the host lists an ai-edit helper. Listed as unavailable (the host’s AI editing switch is off), ⌘J opens the panel with a note and no Send. Edit mode only. HTML Clay, Hyperclay Local and hyperclay.com list the helper; on hyperclay.com it is listed for the document’s owner and its team editors.
Across a mode change#
The chrome is built when the page enters edit, and taken down when it leaves. Leaving edit is refused with pending-input while an edit is unresolved: a request on the wire, a reply waiting for Keep or Revert, a Keep that is still saving, or a comment typed and not sent. pending names which. Finish or discard it, and the exit goes ahead.
await clay.aiEdit.open(element, { prompt }) opens the composer on an element from your own code. It returns true when it opened, and false when the helper is unavailable, an edit is already running, or the element is not a content element of this page. It never sends by itself.
Rewrite a paragraph#
The rewrite replaces the original paragraph on the page. You can read it before deciding whether to save it.
- Select the sentence you want changed, such as “Visitors arriving late will not be admitted”. Keep the selection inside one paragraph.
- Press ⌘J on macOS or Ctrl+J on Windows and Linux. You can also click the small AI chip at the end of the selection. The selected words stay highlighted. A panel opens under them with one box and a Send button. Escape closes the panel. Clicking outside it also closes it. Your unsent request stays as a draft for that part of the page.
- In the “Describe the change” box, type “Make this friendlier. Keep the rule that late arrivals cannot enter”. Shift+Enter adds a line to your request.
- Press Enter or click Send. The panel closes and a bottom bar shows progress and Stop. Stop or Escape cancels the running request and restores the original paragraph. When the reply arrives, the rewrite replaces the paragraph and the bar offers Keep and Revert.
- Check that the rewrite still says what you mean. Revert restores the original paragraph. Keep or Escape keeps the rewrite and saves it into the file. Check the bar for a save confirmation or an error.
Every save waits while you review the rewrite, including autosave and ⌘S. Revert runs any waiting save with the original paragraph back. Keep saves the rewrite instead.
After Keep, open the file in your text editor. If you kept the example rewrite, the paragraph now contains:
<p>Please arrive on time, as we're unable to admit late arrivals.</p>
The earlier version is in Backups in HTML Clay’s tray menu. Hyperclay Local keeps earlier versions in .hyperclay/versions/ inside the served folder.