wearejust / statamic-ai-page-builder
Draft Statamic 6 entries with AI (Anthropic or OpenAI) from a prompt, using the blueprint's fields and editorial guidelines. Never saves on its own.
Package info
github.com/wearejust/statamic-ai-page-builder
Type:statamic-addon
pkg:composer/wearejust/statamic-ai-page-builder
Requires
- php: ^8.3
- anthropic-ai/sdk: ^1.0
- guzzlehttp/guzzle: ^7.8
- statamic/cms: ^6.0
Requires (Dev)
- laravel/pint: ^1.24
- orchestra/testbench: ^10.8
- pestphp/pest: ^4.4
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
A Statamic 6 addon that drafts an entry with AI. On the entry create screen, editors click Create this page with AI and describe the page. The addon asks the configured AI provider (Anthropic Claude or OpenAI) for content that fits the blueprint's fields, validates it, and fills the publish form. The editor reviews the result, adds media and saves. The addon never creates or saves an entry itself.
How it works
- The editor's prompt is sent together with:
- fixed system rules (
resources/ai-page-builder/system.md): output format, no invented facts, IDs or URLs, rich-text rules; - the editorial guideline for the blueprint (managed in the CP, see below);
- a compact outline of the blueprint's fields, generated from the blueprint (handles, types, options, limits, conditions, replicator sets).
- fixed system rules (
- The model returns one JSON object:
{"values": {...}, "notes": [...]}. URLs in the prompt can be read: with Anthropic's web fetch tool, or with OpenAI's web search tool. - The server validates the values against the blueprint: unknown fields are ignored, invalid blocks are dropped, show/hide conditions are applied, rich text is sanitised, and the slug is derived from the title. Blocks that only miss media are kept and reported as a to-do. If the output can't be used, the request is retried once with the problems as feedback. Provider and configuration errors are not retried.
- The modal shows the fields that will change, the to-dos and the skipped fields. Applying writes the values (and their field meta) into the publish form, so dirty tracking, validation and saving work as normal.
Installation
composer require wearejust/statamic-ai-page-builder
Then configure a provider.
Anthropic (default):
STATAMIC_AI_PAGE_BUILDER_PROVIDER=anthropic ANTHROPIC_API_KEY=
OpenAI:
STATAMIC_AI_PAGE_BUILDER_PROVIDER=openai OPENAI_API_KEY= # Optional OPENAI_ORGANIZATION= OPENAI_PROJECT=
Both providers get the same prompt, rules and guidelines, and their output goes through the same validation. Switching provider needs no other changes.
Optionally publish the config with php artisan vendor:publish --tag=ai-page-builder-config.
Permissions
- Use AI Page Builder: generate content. Users also need the collection's Create Entries permission.
- Manage AI Page Builder guidelines: edit the guidelines page under Tools → AI Page Builder.
Super users have both. Nothing is granted to other roles automatically.
Configuration
| Env / config key | Default | Notes |
|---|---|---|
STATAMIC_AI_PAGE_BUILDER_PROVIDER |
anthropic |
anthropic or openai. |
STATAMIC_AI_PAGE_BUILDER_ANTHROPIC_MODEL |
claude-sonnet-5-5 |
STATAMIC_AI_PAGE_BUILDER_MODEL is still read as a fallback. |
STATAMIC_AI_PAGE_BUILDER_OPENAI_MODEL |
gpt-6-luna |
|
OPENAI_BASE_URL |
https://api.openai.com/v1 |
For a proxy or compatible gateway that supports the Responses API. |
STATAMIC_AI_PAGE_BUILDER_EFFORT |
medium |
Reasoning effort, low to max; higher is slower and more thorough. Supported values vary per model. |
STATAMIC_AI_PAGE_BUILDER_MAX_TOKENS |
16000 |
Reasoning counts towards this limit. |
STATAMIC_AI_PAGE_BUILDER_TIMEOUT |
180 |
Seconds per provider request. |
STATAMIC_AI_PAGE_BUILDER_MAX_RETRIES |
2 |
Retries for rate limits, overloads and connection errors. |
STATAMIC_AI_PAGE_BUILDER_WEB_FETCH |
true |
Let the model read URLs from the prompt. |
web_fetch.allowed_domains |
[] |
Restrict fetching (Anthropic) or searching (OpenAI) to these domains. |
enabled_collections / disabled_blueprints |
all | disabled_blueprints accepts blueprint or collection.blueprint. |
guidelines_file |
resources/ai-page-builder/guidelines.yaml |
|
STATAMIC_AI_PAGE_BUILDER_LOG_PROMPTS |
false |
Logs prompts and responses (never the API key). |
Timeouts. A generation can take one to two minutes, longer with web fetch, and up to two provider requests. PHP's max_execution_time is raised for the request, but the web server and any proxy (for example nginx proxy_read_timeout / fastcgi_read_timeout) must allow at least 2 × timeout + 30 seconds.
Reading URLs. With Anthropic, web fetch must also be allowed in the Anthropic Console organization settings; it reads exactly the URLs in the prompt (at most web_fetch.max_uses per request). With OpenAI, the web search tool is used: it searches and opens pages, and may also consult other pages than the ones in the prompt. Use web_fetch.allowed_domains to restrict it.
Providers in code. Anthropic is called through the official anthropic-ai/sdk package. OpenAI is called over plain HTTP (POST /v1/responses, store: false), because OpenAI publishes no official PHP SDK. OpenAI doesn't allow web search together with JSON mode, so web search is only added when the prompt contains a link; other requests use JSON mode. Without JSON mode the system rules still require a single JSON object, and unusable output is retried once.
Guidelines
Under Tools → AI Page Builder, content managers edit:
- a general guideline for every entry (falls back to the addon's default when empty);
- a guideline per collection → blueprint, which replaces the general guideline for that blueprint. Leave it empty to use the general one. The Start from the general guideline field action copies the general text in.
Guidelines describe tone of voice, page structure and which block to use for what. The system rules (output format and safety) are fixed and can't be changed from the CP. Preview prompt shows the full assembled prompt for the saved guidelines.
Guidelines are stored in a flat YAML file, so they can be committed with the rest of the content. Guidelines for blueprints that no longer exist are shown as orphaned and kept until deleted. Field config may also include an ai_hint, which is added to the field outline.
Extending
Third-party addons can add support for their fieldtypes by registering a handler with FieldtypeSchemaRegistry in a service provider. A handler receives the Statamic Field and returns a JSON Schema fragment used for validation, or null to skip the field.
Data and security
Sent to the configured provider (Anthropic or OpenAI): the system rules, the guideline, the field outline, the editor's prompt and the content of pages read for that prompt. With OpenAI, store: false is sent so responses are not stored for later retrieval. Existing entry values are not sent. The model has no tools with side effects. Anthropic's web fetch is read-only and limited to URLs in the prompt; OpenAI's web search is read-only but may also open other pages. Every response is treated as untrusted: unknown keys are ignored, values are validated and rich text is sanitised. Fetched pages could contain prompt injection, but the worst case is unwanted text in a draft the editor reviews.
Control Panel integration notes
The UI is built from Statamic's own components (@statamic/cms/ui: Modal, Button, Textarea, Alert, …), so it follows the CP's styling and dark mode. resources/js/components/AiPageBuilder.vue is registered with Statamic.$components.register() and rendered inside the CP app with Statamic.$components.append(). Statamic 6 has no page-level action extension point for the publish form, so that component keeps a small slot in the entry header (followed with a MutationObserver across Inertia navigation) and teleports the button into it. Applying values uses the publish container announced through Statamic's publish-container-created event, which provides setFieldValue and setFieldMeta. Field meta must be set before the value: new replicator sets and Bard fields read their meta by set _id, and without it they don't render and the entry can't be saved. The container's $refs API does not expose setFieldMeta, so the fallback (walking the Vue tree from the mounted app's root vnode) merges meta through setMeta. Statamic ships Vue's production build, so dev-only internals such as app._instance and __vueParentComponent are not available. This relies on internal CP details, so re-verify it when upgrading Statamic 6 minors.
Development
composer install # PHP dependencies, including Statamic for the test suite npm install # Vite and @statamic/cms (installed from vendor/statamic/cms) npm run build # compile resources/js into resources/dist composer test # Pest, on Statamic's AddonTestCase (Orchestra Testbench) composer lint # Pint; `composer lint:fix` to fix
The compiled resources/dist files are committed and shipped with the package, so projects need no build step. Run npm run build and commit resources/dist with every change in resources/js. The tests never call a real AI provider.
To work on the addon inside a project, add the local checkout as a Composer path repository ("type": "path", "url": "../statamic-ai-page-builder", "options": {"symlink": true}) and run php artisan vendor:publish --tag=statamic-ai-page-builder --force after each build.
Releasing
- Update
CHANGELOG.md. - Run
npm run build,composer lintandcomposer test, and commitresources/dist. - Tag the release (
git tag v0.1.0 && git push --tags). Composer takes the version from the tag; there is no version incomposer.json.
License
Proprietary. Copyright © JUST. All rights reserved. See LICENSE.