An AI answer streamed into the page, labeled as AI and possibly wrong, with sources and a follow-up.
<div id="ak-answer"></div>
Copy
Installation
// package.json: "capsomer": "github:DrDustinEdwards/capsomer#v0.152.2"
import "capsomer/tokens.css";
import "capsomer/base.css";
import "capsomer/ask-panel.css";
import { enhance } from "capsomer/behavior/ask-panel";
enhance();Copy
Usage
<div data-cap="ask" data-ask-question="How long are the logs kept?">
<button type="button" class="cap-btn cap-ask-trigger" data-ask-trigger hidden>Ask AI</button>
<div data-ask-container hidden></div>
</div>Copy
Examples
Cut off
<div id="ak-cut"></div>
Copy
Unavailable
<div id="ak-failed"></div>
Copy
Before the reader asks
<div data-cap="ask" data-ask-question="How long are the logs kept?" id="ak-mount">
<button type="button" class="cap-btn cap-ask-trigger" data-ask-trigger hidden>Ask AI</button>
<div data-ask-container hidden></div>
</div>
Copy
API reference
Functions Function Signature Does ask(container: HTMLElement, options: AskOptions): AskHandleBuilds the panel in container and starts the stream. enhance(root: ParentNode | undefined, options: Omit<AskOptions, "request"> & { request: (question: string, signal: AbortSignal) => Promise<Response>; }): () => voidWires every [data-cap="ask"] mount: its [data-ask-trigger] button starts ask() into its [data-ask-container] with the question in the mount's data-ask-question, read at the click (a live search rewrites it). Guarded on the DOM, so two bundles on one page never stream two answers for one click. options gives the request for a question. postQuestion(endpoint: string, field?: string): (question: string, signal: AbortSignal) => Promise<Response>The request dei's Ask makes: a form post of the question, asking for an event stream.
CSS variables Variable Default --cap-ask-radiusvar(--radius-s)
Parts and data attributes Class Is .cap-askits own class .cap-ask-badgeits own class .cap-ask-bodyits own class .cap-ask-cutits own class .cap-ask-followupits own class .cap-ask-headerits own class .cap-ask-noteits own class .cap-ask-source-kindits own class .cap-ask-sourcesits own class .cap-ask-sources-headingits own class .cap-ask-statusits own class .cap-ask-triggerthe root
State Read from :focus-visiblethe platform
Accessibility
The panel is a labeled region ("AI answer"), focusable but not a Tab stop. The badge's colors are the primary pair; the note and the status are muted text that reaches 4.5:1 on the accent tint. Failure is said in words ("Ask is unavailable.", "Ask stopped early.", "No answer for that one.") and announced.