Skip to content

Annotations AI Draft

Submodule of Annotations. Adds a "Draft with AI" button to annotation text fields.


Requirements

  • annotations:annotations
  • ai:ai, with a configured default chat provider
  • field_widget_actions:field_widget_actions

What it does

Adds a "Draft with AI" button (DraftGuidanceWithAi plugin) to any string_textarea/string_long field on an annotation type — the base value field, or any custom field added to a type. It drafts guidance text from the target field's real Field API definition, a handful of real values sampled from existing content, and any sibling annotations already written for the same target/field (for voice/format consistency, never copied verbatim — see DEVELOPING.md for a prompt-design pitfall found during testing).

Not on by default — enable per field via the gear icon on Manage Form Display for the relevant annotation type, in the "Field Widget Actions" third-party settings section. Currently enabled on the editorial and rules types' value fields on this site (core.entity_form_display.annotation.{editorial,rules}.default, exported to config/sync) as a working demo; enable it on other types/fields the same way.

Per-field settings include an Instruction override textarea. Leave it blank and the default instruction is used ("Draft a short, specific piece of editorial guidance..."); fill it in and it replaces that instruction for this field only, e.g. "Write this as a one-line tooltip, max 15 words" — the auto-gathered context (field facts, real examples, sibling annotations) is still assembled either way, only the instruction sentence changes.


Permissions

Permission Notes
use annotations ai draft Required to see and use the "Draft with AI" button anywhere it's enabled. Not granted to any role by default — the button is invisible until a role has this. Distinct from any edit {type} annotations permission: editing an annotation type doesn't imply permission to trigger AI generation on it, since each use is a real AI provider call with associated cost. restrict access: true (flagged as security-sensitive in the permissions UI) since it triggers external calls and sends field/content data to whatever provider is configured.

Enforced twice: DraftGuidanceWithAi::isAvailable() keeps the button out of the form entirely for users without the permission (this is real access control, not just hiding an element — see DEVELOPING.md), and ajaxCallback() re-checks it directly before doing anything, in case that ever changes.