Metadata-Version: 2.5
Name: django-wagtail-ai-generation
Version: 0.1.0
Summary: Wagtail admin AI assistant for StreamField bodies (copy/paste and optional in-app LLM)
Author-email: Aymane Nahji <aymanenahjidev@gmail.com>
License-Expression: MIT
License-File: LICENSE
Keywords: ai,cms,django,llm,streamfield,wagtail
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Web Environment
Classifier: Framework :: Django
Classifier: Framework :: Django :: 5
Classifier: Framework :: Wagtail
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Requires-Python: >=3.11
Requires-Dist: django>=5.0
Requires-Dist: pillow>=10.0
Requires-Dist: wagtail>=6.0
Provides-Extra: dev
Requires-Dist: pytest-django>=4.11; extra == 'dev'
Requires-Dist: pytest>=8; extra == 'dev'
Description-Content-Type: text/markdown

# django-wagtail-ai-generation

Portable Django library: **floating AI assistant** on Wagtail page edit — copy/paste prompts with a **live JSON schema** from your StreamFields, or optional in-app LLM when you install a companion app (e.g. `llms`).

**Author:** Aymane Nahji

## Zero configuration

After adding the app to `INSTALLED_APPS`, you **do not** set a page model or StreamField name in Django settings.

- The assistant uses **the page you are editing** (concrete `Page` subclass).
- It discovers **every `StreamField`** on that model.
- **One field:** used automatically. **Several:** bubble picker + per-field schema/apply.
- Prompt **content rules** and **minimal shape examples** follow the schema on **that** page (plain `RichTextBlock` → `rich_text` string, not `text_en`/`text_fr`/`text_ar` unless your blocks are localized).

No `WAGTAIL_AI_GENERATION_PAGE_MODEL` or `WAGTAIL_AI_GENERATION_BODY_FIELD` is required — see in-app README for optional limits.

## Requirements

- Python 3.11+
- Django 5+, Wagtail 6+
- Pillow (image import from URLs in AI JSON)

Optional: **django-wagtail-icon-chooser** so `IconChooserBlock` fields appear as `lucide_icon` in the schema.

## Install

```bash
pip install django-wagtail-ai-generation
# or from a checkout:
pip install /path/to/django-wagtail-ai-generation
```

```python
INSTALLED_APPS = [
    # ...
    "wagtail",
    "wagtail_ai_generation",
]
```

Expose StreamFields with `FieldPanel` (or panels Wagtail renders in the editor). The bubble appears when the user can edit the page and the model has at least one StreamField.

## Features

- Per-block **AI edit** / **AI replace** on each stream in the editor.
- External workflow: copy prompt → any LLM → paste JSON to apply.
- Schema bundle: block types, field types (`str`, `rich_text`, `localized`, `image`, …), minimal examples.
- Optional in-app agent when `WAGTAIL_AI_GENERATION_LLMS_APP` points at an installed connections app.

## API (Wagtail admin, staff + CSRF)

| Method | Path | Purpose |
|--------|------|---------|
| GET | `…/ai-generation/context/?page_id=&stream_field=` | Context + schema for one StreamField |
| POST | `…/ai-generation/` | Apply pasted AI JSON (`stream_field_name` in body) |
| POST | `…/ai-generation/run/` | LLM generate + apply (when LLM app enabled) |

`stream_field` / `stream_field_name` is the **model attribute name** of the StreamField (discovered server-side).

## Preferred AI output

```json
{
  "analysis": { "action": "append", "target_index": null, "summary": "..." },
  "blocks": [{ "type": "title_description", "value": { "title": "Hello", "description": "<p>…</p>" } }]
}
```

## Develop & test

```bash
pip install -e ".[dev]"
PYTHONPATH=. DJANGO_SETTINGS_MODULE=tests_project.settings python -m django test wagtail_ai_generation
```

## More detail

Integration, optional settings, schema types, i18n, security: [wagtail_ai_generation/README.md](wagtail_ai_generation/README.md).

## License

MIT — see [LICENSE](LICENSE).