Add Box Question and Answer types, and model capability to Decision model infrastructure
Context: TypeSafe's docs: https://docs.typesafe.ai/primitives/box.md and https://docs.typesafe.ai/images.md.
## Problem/Motivation
On 2026-10-14 TypeSafe released Jev 1.14 (`jev-1.14.0`, alias `jev-preview`). It adds a fourth SystemOne question type, **Box**: "where is X in this image". Images and Box are experimental for now, behind the request header `TypeSafe-Danger-Zone-Images: true`.
- **Request:** `{"type": "box", "instructions": "the coffee mug in `photo`"}`. Box takes no criteria.
- **Answer:** `{"type": "box", "box": {"top": 0.25, "bottom": 0.82, "left": 0.44, "right": 0.84}, "confidence": 0.92}`.
- Each edge is a fraction of the image size, measured from the top-left corner: `left` and `right` of the width, `top` and `bottom` of the height.
- A box is always returned, even when the target is absent. TypeSafe recommends asking a noul about whether the target is present in the same request.
- Each box question finds one target.
Decision already carries ordered image files (`DecisionImageFiles`, `maxFiles`), but its question types are closed: `QuestionFactory`, `AnswerFactory`, `DecisionRequestValidator::requirements()` and the capability enum know only noul, choice and score (plus refusal answers). So a provider cannot expose Box at all:
- a box question is rejected as an unknown type before transport;
- a box answer is broken output.
**Why ObjectDetection doesn't fit:**
- `ObjectDetectionInput` takes one image and no target description, and the model chooses the labels. Box locates the target the caller describes.
- `ObjectDetectionItem::getBox()` uses absolute pixels. Box returns fractions, so the answer doesn't depend on the image size.
- Box runs in the same request as noul, choice and score questions, over shared state and the same files, and is billed as one call.
## Proposed resolution
**Values** (`src/OperationType/Decision/Value/`)
- `QuestionInterface::TYPE_BOX = 'box'`.
- New `final class BoxQuestion extends QuestionBase`: instructions only. `getCriteria()` returns NULL. The wire form is `{type, instructions}`.
- `QuestionFactory::fromArray()` builds box questions and rejects any criteria (`[]` included).
- New `final class BoxAnswer implements AnswerInterface`:
- `fromArray()`;
- `getTop()`, `getBottom()`, `getLeft()`, `getRight()`;
- `getBox()`, which returns the edges keyed `top`, `bottom`, `left`, `right`;
- `getConfidence()` and `isConfident()`, which is inclusive, like choice and score;
- `toPixels(int $width, int $height)`, which returns rounded `left`, `top`, `right` and `bottom`. Right and bottom are exclusive, as in a crop rectangle;
- `getRaw()` and `toArray()`.
- **Validation:**
- every edge and the confidence must be finite and within 0 to 1;
- `left <= right` and `top <= bottom`.
- Inverted boxes are broken output; equal edges are accepted (open question 1).
- `AnswerPrecision` does not apply, because a box has no distribution.
- `AnswerFactory::fromArray()` dispatches `box`.
**Response, capability and validator**
- `DecisionResponse::getBox(string $id): BoxAnswer`, like `getScore()`: `AiDecisionRefusedException` for a refusal, `\UnexpectedValueException` for another type.
- `AiModelCapability::DecisionBox` (`decision_box`), title "Box questions (image regions)".
- It requires `DecisionImageFiles` (a `DecisionCapabilities` prerequisite).
- It does not count as the noul, choice or score type a profile must declare (open question 3).
- `DecisionRequestValidator`:
- a box question requires `DecisionBox`;
- a new last check rejects a box question in a request without image files with `AiBadRequestException`. Because it comes last, a model without box support still gets `AiMissingFeatureException` first.
**Explorer** (`DecisionGenerator`)
- Field descriptions mention box.
- A box answer row shows:
- the edges;
- the confidence;
- for each uploaded image, the box in pixels via `toPixels()`. The explorer can't tell which image the instructions named.
- The code example uses `getBox()`.
- The capability summary can't see uploads, so it substitutes a placeholder image for box questions, to avoid a false "needs an image" error (open question 5).
**No changes:** guardrails, automators, the event subscriber.
- RegEx scans box instructions like any other. Box answers carry no text.
- Moderation stops requests with files, so it stops every box request (open question 4).
**Contract suite**
- New `requests()` case `box`, with one image, requiring `[DecisionImageFiles, DecisionBox]`.
- A box response fixture.
- Malformed box answers: missing `box`, a missing edge, an edge out of range, non-numeric or NULL, inverted width or height, confidence missing or above 1.
- A box question without an image is rejected (`AiBadRequestException` with `DecisionBox`, `AiMissingFeatureException` without it).
- A box rounded to equal edges is accepted unchanged.
- `TestDecisionProviderContractTest` gains a `box` profile; `unknown` declares box.
**Contract image fixtures (separable change)**
- The 1×1 PNG and 1×1 GIF become a 300×300 truecolor PNG (711 bytes) and a 300×300 baseline JPEG (2,134 bytes).
- TypeSafe rejects GIF and images under 256 px per side or under 78,400 pixels, so any Jev adapter that declares `DecisionImageFiles` fails the shared suite with the old fixtures.
- PNG and JPEG are the formats every image-capable Decision API accepts (TypeSafe, OpenAI, Perplexity, Cloudflare Clef, imajev). 300 px is within every known limit.
- File order stays observable through type and file name.
**Docs**
- `call_decision.md`: a "Box questions" section, the type table, the getters, guardrail notes, the explorer.
- `decision_provider_contract.md`: the prerequisite, the capability row, validator step 6, the answer shape, and what the suite checks (including fixture sizes).
- The explorer index: one sentence.
## API changes
- **Added:**
- `QuestionInterface::TYPE_BOX`, `BoxQuestion`, `BoxAnswer`, `DecisionResponse::getBox()`;
- `AiModelCapability::DecisionBox`;
- the validator rule;
- contract cases.
- **Changed:**
- the `QuestionFactory` and `AnswerFactory` messages list `box`;
- contract image fixtures (PNG + JPEG, 300×300).
- **No BC break:** answer and question classes are final; providers that don't declare `DecisionBox` keep rejecting box questions, now with `AiMissingFeatureException` instead of "unknown type".
issue
GitLab AI Context
Project: project/ai
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/-/raw/1.x/README.md — project overview and setup
Repository: https://git.drupalcode.org/project/ai
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