Expose a JS event and API on the question input for external suggestion widgets
## AI disclosure
_[AI disclosure](https://www.drupal.org/docs/develop/issues/issue-procedures-and-etiquette/policy-on-the-use-of-ai-when-contributing-to-drupal#s-disclosure): Used AI to help with research and writing (checking the review points against the 1.1.x JS, drafting this issue). The reasoning and positions are my own, and I reviewed everything before posting._
### Problem/Motivation
Part of #3615776. On the 17 November call we agreed that suggestions (page links and suggested questions as a visitor types) live in a separate module, and AI Answers only exposes what that module needs. Today there is no supported way for other code to follow what a visitor types in the question input, or to ask a question on their behalf.
Depends on #3615769, which splits the widget JS into a core that works without Drupal and a thin Drupal adapter. This API goes on that core, so it works the same inside Drupal and in an external embed.
### Proposed resolution
Updated on 27 November after the reviews by @Pravesh_Poonia and @tomimikola.
- **Events** (both with `bubbles: true` and `composed: true`, so a listener on `document` gets them):
- `ai-answers:input` from `<ai-answers-question>` while the visitor types (debounced), with the current text. It also fires with empty text when the input is cleared after a submit.
- `ai-answers:question-sent` from `<ai-answers-answer>` for every question it sends, follow-ups included. Detail: `{ question, origin, followUp, target }`, where `target` is the answer element's id.
- `ai-answers:ask` keeps its current meaning: the command the answer element listens for. Notifications never use that name, so a listener can't send a question twice.
- **API on `<ai-answers-question>`:**
- `ask(text, { origin })` sends a question like a chip click. `origin` defaults to `suggestion`.
- `setText(text, { origin })` fills the input without sending. The element remembers that text and origin (default `suggestion`). On submit, unchanged text is sent with that origin, edited text as `typed`. The remembered value is cleared after each submit.
- The server already accepts all 5 origins, so no server change is needed.
- **Where a widget renders its list:** a named `suggestions` slot when the element uses shadow DOM. With `shadow="none"` it's a plain container element the widget appends to. A `part` alone isn't enough, since it can only be styled.
- **Accessibility:** ids don't cross the shadow root, so the docs point to `ariaActiveDescendantElement` for the active option.
- **Docs:** a short "build your own suggestions widget" section, using `/ai-answers/suggest` from #3615773 as the example data source.
### Remaining tasks
- [x] Agree event names and payloads
- [ ] Events + API on the core JS (after #3615769)
- [ ] FJS tests:
- a test module listens to `ai-answers:input` and calls `ask()`
- `setText()` + Enter logs `suggestion`
- `setText()` + an edit + Enter logs `typed`
- `ask()` with an explicit origin logs that origin
- a follow-up fires `ai-answers:question-sent` with `followUp: true`
- [ ] Docs
- [ ] Review
### User interface changes
None.
### API changes
New public JS events (`ai-answers:input`, `ai-answers:question-sent`) and methods (`ask()`, `setText()`) on the widget elements, plus a `suggestions` slot. They become part of the stability contract in #3615752 (additive changes only within a minor).
### Data model changes
None.
issue
GitLab AI Context
Project: project/ai_answers
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_answers/-/raw/1.0.x/README.md — project overview and setup
Repository: https://git.drupalcode.org/project/ai_answers
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