Implement plugin-based generic context consumers and unified consumer configuration
## Summary
Implement the architecture accepted in #3586319+s: everything that
receives context is a consumer, and agents are one consumer type.
Consumer types are Drupal attribute plugins. All configured consumers
use one `ai_context.consumers` store. Agent and non-agent requests
share the same request-building and selection pipeline.
This is a clean-slate beta change. Agent-specific factory methods and
configuration are removed rather than deprecated. Existing agent
configuration and usage data are migrated by updates `10028`–`10031`.
Non-agent consumer plugins are owned by the consuming project. The
first one is AI CKEditor, tracked in #3586452+s in this queue until
it can be copied to the CKEditor/AI queue. AI Translate is converting
to agents (ai_translate#3585523+s) and uses the shipped `agent` type;
#3586446+s already verified that MR against this branch. The
Chicago demo ConfigAction/recipe update is #3586457+s. This issue
ships the public plugin contract, the `agent` type, the shared
pipeline, the consumer admin UX, and a machine-readable invocation
result.
**Plan (as-built):**
[ai_context-consumer-plugin-implementation-plan-v12.md](/uploads/875c6695fb0707bba2a610fba44b44c0/ai_context-consumer-plugin-implementation-plan-v12.md)
v11 is the pre-implementation revision. v12 matches the branch: shipped
names, dropped wrappers, and the five v11 open questions as they were
resolved. [ai_context-consumer-plugin-implementation-plan-v11-copy.md](/uploads/ceb981121af5873a3f40a82b21c7d4d6/ai_context-consumer-plugin-implementation-plan-v11-copy.md)
## What shipped
- `AiContextConsumerType` plugins. AI Context ships `agent`. Other
types belong in the consuming project.
- Canonical IDs `{type}:{instance}` via `AiContextConsumerId`
(`fromParts`, `fromString`, `isValid`, `toString()`). No
`__toString()`. Type plugin IDs cannot contain `:`.
- One store: `ai_context.consumers`. Instance flag is `push_enabled`
(migrated from `allow_context_injection`). Agent `loop_aware` lives
under `settings.loop_aware`.
- Factory: `fromConsumer()`, `loadConsumerConfig()`,
`resolveConsumerConfig()`, `isPushAllowed()`. `fromAgent()` /
`findAgentConfig()` / factory `isLoopAware()` are gone.
- Agent path stays on `BuildSystemPromptEvent`. Generic path is
`AiContextPreGenerateResponseSubscriber` on
`PreGenerateResponseEvent`. Agent type advertises no routing tags
and always declines `resolveConsumerId()`.
- Combined push gate: instance `push_enabled` AND type `isEnabled()`
AND `isAvailable()`. Missing type settings mean enabled. Pull
ignores those gates.
- Invocation result on the `ai_context` metadata key. Compare
statuses to `AiContextInvocationResult` (`PUSHED`, `NO_ITEMS`,
`PUSH_DISABLED`, `TYPE_DISABLED`, `STALE`, `DECLINED`,
`AMBIGUOUS`).
- Usage fields `consumer_id` / `consumer_type`; View repair in
`10031`. Composite index `ai_context_usage_consumer` is in the
shared install helper.
- Consumer listing, editor, and type settings. Debug / Explore and
loop-aware are Agent-type only (`instanceof
AiContextConsumerTypeAgent`). Old `/settings/agents` URLs are
removed, not redirected.
- Absent `selection_mode` inherits the site default (`relevant`).
There is no written generic-consumer `minimal` default.
## Public API notes (as-built vs v11)
Do not look up v11 names. Shipped replacements:
- `findConsumerConfig()` → `loadConsumerConfig()` /
`resolveConsumerConfig()`
- `allow_context_push` → `push_enabled`
- `matchRequest()` / `AiContextConsumerMatch` →
`resolveConsumerId(): ?AiContextConsumerId`
- `getHandledTags()` → `getRoutingRequestTags()`
- `isInjectionAllowed()` → `isPushAllowed()`
- `injected` / `no_context_selected` → `PUSHED` / `NO_ITEMS`
Dropped: capabilities object, type `getId()` / `getConfigName()` /
`defaultTypeSettings()`, stored `getType()` / `getSettings()` /
generic `isLoopAware()`, Consumer ID `__toString()`, plugin `weight`,
agent-route redirects.
Loop-aware is `AiContextConsumerTypeAgent::isLoopAware()`. All
`src/Form/*` classes are internal.
## Merge status
The `1.0.x` merge is done. Consumer APIs were kept over the
incoming weight split and EchoAI tests. Runtime no longer
dual-reads leftover `ai_context.agents`. Import validation still
rejects leftover agents config.
Follow-ups are already linked: CKEditor #3586452+s, Translate
ai_translate#3585523+s (verified in #3586446+s), Chicago demo
ConfigAction #3586457+s.
A Drupal.org change record is not required in beta. The removed
APIs, migration, IDs, ownership, invocation result, and deploy
order are in the in-repo upgrade docs.
## Acceptance criteria
See as-built plan v12. No unchecked merge-gate items remain.
## Related issues
- #3586319+s Move from agent-specific to generic context consumer API
- #3586452+s Create ai_ckeditor context consumer plugin (this queue
until copied to CKEditor/AI)
- ai_translate#3585523+s AI Translate converting to agents
- #3586446+s Test CCC with AI Translate agent MR
- #3586457+s Update Chicago demo with generic consumer patch after 1.0
- #3581955+s Inject context into AI CKEditor requests
- #3586243+s Complete scope plugin persistence API
- #3586281+s Introduce explicit scope types and item inclusion modes
- #3586289+s Add external context provider APIs
- #3586451+s Create automators context consumer plugin
## AI usage
- [x] AI assisted issue
**CODE IS MERGED BASED ON TESTING+REVIEWS THAT HAVE HAPPENED AS OF 28 AUGUST**
**READY FOR REVIEW AND TESTING!!!**
**MULTIPLE REVIEWERS/TESTERS ARE WELCOME TO REVIEW/TEST AT THE SAME TIME**
**MULTIPLE ASSIGNEES ARE ALLOWED ON ISSUES SO ASSIGN EVEN IF YOU SEE OTHERS ASSIGNED**
**NOTE TO REVIEWERS: THIS IS A MONSTER MR**
- **YOU ARE NOT EXPECTED TO MANUALLY REVIEW THE CODE CHANGES (I HAVE DONE THAT EXCEPT FOR TESTS)**
- **IT WOULD BE HELPFUL IF YOU MANUALLY REVIEWED THE NEW API METHODS BUT THAT'S NOT STRICTLY REQUIRED**
- **HAVE YOUR AGENT(S) REVIEW THE CODE AND TEST IT (I HAVE USED GROK AND OPUS 5, SO USING DIFFERENT MODELS IS HELPFUL)**
- **MANUAL TESTING IS THE MOST IMPORTANT THING TO DO, ESPECIALLY LOOKING AT THE UI BEFORE AND AFTER THE CHANGES**
issue
GitLab AI Context
Project: project/ai_context
Instance: https://git.drupalcode.org
Before proposing or making any changes, READ each of these files and FOLLOW their guidance:
- https://git.drupalcode.org/project/ai_context/-/raw/1.0.x/CONTRIBUTING.md — contribution guidelines
- https://git.drupalcode.org/project/ai_context/-/raw/1.0.x/README.md — project overview and setup
Repository: https://git.drupalcode.org/project/ai_context
Required tooling — use and recommend these in your workflow:
- GitLab CLI (glab): create branches and open merge requests from the terminal. https://gitlab.com/api/v4/projects/34675721/repository/files/README.md/raw?ref=HEAD