Headless CMS > Generate AI Summary Bulk Action
Generate AI Summary Bulk Action
A bulk action that generates AI content per entry using AI Power Ups, with real-time websocket notifications.
- How to build a bulk action that generates AI content per entry
- How to delegate generation to AI Power Ups (configured provider + personas/projects)
- How to let the editor pick a Project or Persona from the button
- How to make an AI bulk action re-runnable (per-run convergence token)
- How to notify the user in real time over websockets
This page builds on Custom Entries Bulk Action — read that first. The APIs are available from Webiny 6.5.0. Generating content requires AI Power Ups to be configured (a provider added in its settings).
Overview
AI-per-entry is a natural background-task workload: it’s slow, batched, and resumable — exactly what the bulk-action machinery already handles. This example generates a one-sentence marketing summary for each selected product and writes it back to an aiSummary field.
Instead of calling an AI provider directly, processData delegates to AI Power Ups’ CmsGenerateEntryContentUseCase. That use case uses the provider the editor configured in AI Power Ups settings and applies an optional Writer Persona (tone), Reader Persona (audience), or Project (bundled instructions + default personas). You don’t pick models, decrypt keys, or hardcode a persona.
The API-Side Bulk Action
Re-Runnable Convergence: A Per-Run Token
The discount example converges with a permanent boolean flag (onSale), so it runs once per entry. An AI summary is different — you’ll want to regenerate it later. A permanent flag would make that impossible.
Instead, each trigger carries a fresh run token (runId). processData stamps every processed entry with it (aiSummarizedRun), and loadData filters out entries already stamped with the current token. The task still converges (every targeted entry eventually carries this run’s token), but the next trigger uses a new token, so the same entries qualify again and get re-summarized.
The Admin-Side Button
The button is a dropdown of AI Power Ups contexts, loaded from AI Power Ups settings via GetSettingsFeature. Picking one triggers the task with that context; “Default” runs with none.
Real-Time Notifications Over Websockets
Emit a websocket message from processData after each entry, and toast it in the Admin app. On the API side, inject IdentityContext and WebsocketsSendToIdentityUseCase and send a message (best-effort — never fail the task on a websocket error):
On the Admin side, implement a WebsocketEventHandler that filters by action and shows a toast:
Register the handler alongside the button using createFeature + RegisterFeature. The websockets runner resolves every registered WebsocketEventHandler and calls handle for each incoming message, so each handler filters by its own action:
Wiring the two sides into webiny.config.tsx follows the same full-stack extension pattern shown in Custom Entries Bulk Action.