webwerkwien/contao-ai-backend-bundle
Composer 安装命令:
composer require webwerkwien/contao-ai-backend-bundle
包简介
Contao 5 backend module with an in-browser AI agent for editors and admins, powered by symfony/ai and contao-ai-core-bundle
README 文档
README
In-browser AI agent for the Contao 5 backend. Editors and admins chat with a Claude (or GPT) agent that can read and modify Contao content through a curated set of tools — no SSH, no CLI. Plus an HTTPS bridge endpoint that lets contao-ai-cli trigger bulk macro operations from the terminal without switching to the browser.
Beta software. Bundle interfaces (tool signatures, bridge JSON, DCA fields) may change between minor versions. Underlying
symfony/ai-bundleis pre-1.0. Use at your own risk in production.
You bring your own LLM API key. Each backend user must provide an Anthropic or OpenAI key in their profile (System → Users → AI agent). Without a key, the chat module is disabled for that user. The bundle does not ship with a service-level key.
The contao-ai ecosystem
| Package | What it is | When to use |
|---|---|---|
| contao-ai-core-bundle | Contao bundle exposing CMS operations as Symfony console commands. | Required as the foundation layer. Install on any Contao site you want to manage via AI. |
| contao-ai-cli | Python CLI — connects to Contao via SSH and runs commands. | For developers and agencies: manage Contao from the terminal or hand control to an AI agent. |
| contao-ai-backend-bundle (this package) | Contao backend module — browser-based AI chat interface (Anthropic Claude, OpenAI). | For editors and admins: AI directly inside the Contao backend, no SSH or terminal needed. |
What it does
contao-ai-backend-bundle is the browser client for AI-powered Contao content management. Authentication, session, CSRF and permissions ride on top of the existing Contao backend — each backend user brings their own API key. A second entry point exposes the macro tools (record_clone, record_rewrite) over HTTPS for the contao-ai-cli bridge workflow.
Requirements
- PHP ^8.2
- Contao ^5.3
webwerkwien/contao-ai-core-bundle^0.2symfony/ai-bundle^0.7
Installation
composer require webwerkwien/contao-ai-backend-bundle vendor/bin/contao-console contao:migrate # adds ai_api_key, ai_platform, ai_cli_token to tl_user vendor/bin/contao-console assets:install # publishes the Stimulus controller + CSS
The Contao Manager auto-discovers the bundle via the contao-manager-plugin entry.
Per-user setup
In System → Users → (user), three new fields appear in the AI agent legend:
| Field | Required | Notes |
|---|---|---|
| Platform | yes | anthropic or openai |
| API key | yes | Stored encrypted (Contao DCA encrypt flag). Empty key = chat module disabled for that user. |
| CLI bridge token | optional | Click Generate / Rotate to mint a token for the contao-ai-cli bridge workflow. Cleartext is shown once with a Copy token button; only the password_hash is stored in the database. Delete revokes. |
Grant the AI Chat module under "Allowed modules" to enable the chat entry. The CLI bridge does not require the module mount but still respects the same per-record permission voters.
Available tools
| Group | Tool names |
|---|---|
| News | news_create, news_update, news_delete, news_read |
| Page | page_create, page_update, page_delete, page_read, page_publish |
| Article | article_create, article_update, article_delete, article_read |
| Content | content_create, content_update, content_delete, content_read |
| Meta | dca_schema, listing_config, search_query, record_list |
| Macros | record_clone (cascade), record_rewrite (server-side LLM loop) |
Permissions inherit from Contao's existing module rights. Admins see everything. Non-admins only see tools whose backing module they are allowed to use, and delete sub-tools are admin-only regardless of module membership. Per-record checks (page hierarchy, news-archive access, article parent-page, FAQ category access) run via Symfony voters (ContaoCorePermissions::USER_CAN_*) before each call.
CLI bridge — terminal access for admins and agents
Editors use the chat module above. Developers and admins live in the terminal — and switching to a browser for bulk LLM jobs ("translate all news in archive 5", "clone this page tree with all children") is a workflow break.
The bundle exposes a HTTPS endpoint at POST /_ai_cli/macro that the contao-ai-cli Python client (contao-ai-cli bridge ...) calls with a Bearer token. The macro tools (record_clone, record_rewrite) execute server-side with the full voter pipeline + atomic tl_version audit — same code path as the chat module, just a different transport.
Why /_ai_cli/macro and not /contao/...?
The contao_backend firewall would 302-redirect any unauthenticated request to /contao/login before our Bearer auth runs. Routing the bridge outside /contao/* lets it fall through to the frontend (anonymous) firewall, where the controller does its own auth.
Security model
The bundle was hardened in a four-sprint security pass against findings from two independent reviewers (Opus + Codex). Full breakdown in CHANGELOG.md.
Authentication and authorization
- Auth (chat) rides on the existing Contao backend session (passkey, password, 2FA — whatever the install uses).
- Auth (bridge) uses Bearer tokens stored as
password_hashintl_user.ai_cli_token; constant-timepassword_verifycomparison. - Module gate: Symfony voter
AI_CHAT_USErequiresai_chatinBackendUser->modulesfor the chat module. - Tool gate:
ToolAccessCheckervalidates the underlying module per tool. Delete tools requireBackendUser::isAdmin === true. - Per-record gate: every tool that touches a content row asserts
ContaoCorePermissions::USER_CAN_*against the record's parent (news archive, page hierarchy, article parent-page) before delegating to the core command.
Field allow-lists
Each *_update tool defines a strict allowedFields() allow-list. The agent cannot set protected DCA columns (pid, tstamp, chmod, cuser, …) even if it asks. Values containing control chars or NULs are rejected.
Prompt-injection mitigation
- Tool outputs are wrapped in
<tool_output_data tool="…">…</tool_output_data>sentinels. The system prompt instructs the model to treat anything inside as untrusted data. - Free-text fields larger than 500 bytes are truncated with
…[truncated]. - Chat history lives server-side in the Symfony session keyed by user ID. Client-supplied history is ignored — fabricated
assistantturns cannot be smuggled in. username/languagetemplate substitutions are regex-validated before flowing into the system prompt.
Information disclosure
- API keys are stored with the Contao DCA
encryptflag, never logged, never returned to the browser. TheUserAiConfigDtowraps the key behind a private property + getter;__debugInfo()redacts to***<last4>so casualdump()cannot leak it. - Exception messages are masked (
sk-ant-…,sk-…,Bearer …patterns), scrubbed ofkernel.project_dir, truncated to 200 chars, and logged asLogLevel::errorfor diagnostics. dca_schemais restricted to a table allow-list and strips canonical credential/session column names.
Audit trail
Backend invocations stamp tl_version.username and the audit log with the actual Contao username via the --operator option on the underlying core commands. CLI invocations still attribute to $_SERVER['USER'].
Transport hardening
Cache-Control: no-store, private, max-age=0+Vary: Cookie+X-Robots-Tag: noindex, nofollow.charset=utf-8is explicit.- CSRF: every chat POST requires the Contao backend CSRF token. Bridge POSTs use Bearer auth instead.
- Same-origin verified via
Sec-Fetch-SiteandOriginrequest headers. - Rate limit: 30 requests/minute and 500/day per user — sliding window backed by the session.
Streaming
Chat responses arrive as text/event-stream (SSE-style frames over fetch-ReadableStream, since EventSource cannot POST). Events:
start— model idmessage— content chunk (currently emitted once per response; chunked streaming will be added when the underlying platform bridge supports it)done— successful completionerror—kind: access_denied | tool_failed | agent_failed
Development
composer install vendor/bin/phpstan analyse src tests --level=6 vendor/bin/phpunit
License
MIT — see LICENSE.
This software is provided "as is", without warranty of any kind. The authors accept no liability for any damages arising from its use.
webwerkwien/contao-ai-backend-bundle 适用场景与选型建议
webwerkwien/contao-ai-backend-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 05 月 08 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「backend」 「chat」 「automation」 「contao」 「Agent」 「ai」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 webwerkwien/contao-ai-backend-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 webwerkwien/contao-ai-backend-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 webwerkwien/contao-ai-backend-bundle 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
This simple PHP class allows you to easily generate Smartsupp.com JS chat code.
Client for the REST API plugin of the OpenFire Server
This bundle offers a simple backend explanation form field (inputType).
Preview of settings in footer of tt_content element in page module.
Command-line utility for Vtiger CRM.
Historical accounting for contacts
统计信息
- 总下载量: 2
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 40
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-05-08