x-dep / ai-bundle
Russian-language AI assistant core for Symfony: model provider gateway, tools and widgets, dialog turns, conversation storage port, budgets and per-person limits, call journal, admin pages
Requires
- php: ^8.4
- ext-ctype: *
- ext-filter: *
- ext-mbstring: *
- doctrine/dbal: ^4.0
- doctrine/doctrine-bundle: ^2.15 || ^3.0
- doctrine/doctrine-migrations-bundle: ^3.4 || ^4.0
- doctrine/orm: ^3.5
- psr/clock: ^1.0
- psr/event-dispatcher: ^1.0
- psr/log: ^2.0 || ^3.0
- symfony/clock: ^7.4 || ^8.1
- symfony/config: ^7.4.23 || ^8.1.11
- symfony/console: ^7.4 || ^8.1
- symfony/dependency-injection: ^7.4 || ^8.1
- symfony/deprecation-contracts: ^3.0
- symfony/framework-bundle: ^7.4.24 || ^8.1.12
- symfony/http-client: ^7.4.24 || ^8.1.12
- symfony/http-client-contracts: ^3.5
- symfony/http-foundation: ^7.4.23 || ^8.1.11
- symfony/http-kernel: ^7.4.24 || ^8.1.12
- symfony/security-bundle: ^7.4 || ^8.1
- symfony/security-csrf: ^7.4 || ^8.1
- symfony/twig-bundle: ^7.4 || ^8.1
- symfony/uid: ^7.4 || ^8.1
- twig/twig: ^3.31.1
Requires (Dev)
- phpunit/phpunit: ^12.0 || ^13.0
Suggests
- phpunit/phpunit: to verify your own ConversationStore with XDep\AiBundle\Test\ConversationStoreContractTestCase
- x-dep/rag-bundle: knowledge base: answers grounded in your Doctrine entities
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-12-02 11:43:02 UTC
README
A Russian-language AI assistant core for Symfony: everything the person and the model see (prompts, refusals, notes, admin pages) is in Russian, and the documentation in docs/ is in Russian too.
The bundle is the single path from a Symfony application to an LLM provider. It runs a chat turn end to end — budget and limits, masking of personal data, tools that show the person their own data, answers grounded in your knowledge base, call journal, admin pages — so the project only writes business logic.
Features
- Gateway. One service talks to the provider (adapter
AiTunnelGatewayfor the AITunnel API: streamed chat completions, decisions for the classifier, key and cost lookups). Only models listed in the configuration are called; upstream providers that store requests are filtered out by default. - Chat turn.
TurnRunnerstreams stages and text to your UI, picks tools, applies the rules below and returns one of seven outcomes (answered, handed off to a human, refused, failed, interrupted, cancelled, waiting). - Conversation storage. The
Conversationfacade loads the history, runs the turn and appends both messages to a store of your choice:x-dep/chat-bundle(conversations, messages and photos with owner and retention), your CRM via theConversationStoreport, or nothing at all. The bundle's own table (conversation_store: doctrine) is deprecated since 2.1 and goes away in 3.0. - Photos. A skill with
imagesaccepts photos in a turn: a vision model answers only with values of your schema (#[AsImageInspector]), your code decides (ImageVerdict), and the chat model gets notes instead of the photo. A document or a bank card in the frame refuses the message.TurnRunner::inspect()checks photos without a turn — for example, to fill a form from a photo. - Grounded answers. A skill with
groundinganswers only from evidence found by grounding providers (for examplex-dep/rag-bundle); an answer that does not cite the evidence never reaches the person and the question goes to a human. - Tools and widgets. The model only chooses a tool; the person gets a widget built by your service, and the model never sees its data. Personal cards take the owner from the server session only.
- Budget and limits. The budget is closed until set; per-day/week/month limits, per-skill shares, a guests' limit, per-person rate and spend limits, a per-turn cap. Every call reserves its upper cost before it is made.
- Protection. Format-based masking of phones, e-mails, card and document numbers before the model, search, journal and logs; an optional classifier for off-topic, jailbreak and abuse with configurable actions and growing blocks.
- Journal and admin pages. One row per provider call (tokens, roubles, timings, outcome — never texts), cost reconciliation, kill switches with a mandatory reason, skill settings with versions, spend charts, offenders.
Requirements
- PHP 8.4+
- Symfony 7.4 or 8.1+
- Doctrine ORM 3.5+ / DBAL 4, DoctrineMigrationsBundle
- MySQL 8.0 or 8.4 (SQLite is for tests only; PostgreSQL is not supported — the migration aborts with a message)
- An AITunnel API key and base URL for real answers; without them the bundle still works, but every call is refused with
no_key
Installation
composer require x-dep/ai-bundle
Symfony Flex registers the bundle. Minimal configuration:
# config/packages/xdep_ai.yaml xdep_ai: api_key: '%env(default::trim:file:XDEP_AI_KEY_FILE)%' # read from a secret file, never inline base_url: 'https://api.aitunnel.ru/v1' # example; there is no default models: deepseek-v4.1-flash: title: DeepSeek V4.1 Flash input_price: 30 # roubles per million tokens, upper bound output_price: 160 budget: day_rub: 100 skills: consultant: title: Консультант model: deepseek-v4.1-flash prompt: Ты — помощник интернет-магазина. Отвечай коротко и по делу.
# config/routes/xdep_ai.yaml xdep_ai_admin: resource: '@XDepAiBundle/config/routes.php' prefix: /admin/ai
Grant ROLE_XDEP_AI_ADMIN to the people who manage the assistant, then create the tables:
php bin/console doctrine:migrations:migrate
A turn with storage (x-dep/chat-bundle or your own conversation_store):
$reply = $conversation->reply($conversationId, 'consultant', $userText, Subject::person($userId, $label), $listener); $reply->result->text; // what the person sees
Step-by-step instructions, including the key file, security and a chat controller template: docs/install.md.
Documentation (in Russian)
| Document | Contents |
|---|---|
| docs/install.md | requirements, installation, configuration, key, budget, admin pages, first turn |
| docs/conversations.md | conversation storage: Conversation, ConversationStore, CRM adapter, contract test, retention |
| docs/extending.md | tools and widgets, personal cards, grounding, quick actions, admin sections, eval sets |
| docs/guarantees.md | what the bundle guarantees (each backed by a test), what it does not, dangerous spots |
| docs/budget.md | budget, limits, classifier and offenders, alerts |
| docs/operations.md | kill switches, provider failures, cost reconciliation, cleanup, upgrades, incidents |
| CHANGELOG.md | changes by version |
| UPGRADE.md | upgrading between major versions |
| docs/bundle-development.md | for contributors: principles, checks, releases |
Tests
Tests are not part of the Packagist archive. Clone the repository to run them:
git clone https://github.com/x-dep-labs/ai-bundle.git && cd ai-bundle composer install make test # or vendor/bin/phpunit
The suite never calls a provider: the gateway is tested on recorded streams. MySQL-specific tests (budget race, migrations, store contract) run with make test-mysql.
License, security, contributing
- License: MIT, see LICENSE.
- Security policy and how to report a vulnerability: SECURITY.md.
- Contributions: see CONTRIBUTING.md.