import "capsomer/tokens.css";
import "capsomer/ai-engine-settings.css";
import { AiEngineSettings } from "capsomer/react/ai-engine-settings";
Usage
import { AiEngineSettings } from "capsomer/react/ai-engine-settings";
import { settingsFromForm } from "capsomer/behavior/ai-engine-settings";
<AiEngineSettings
settings={settings}
models={models}
jobs={FEATURES}
modelOptions={MODELS}
efforts={efforts}
effortOptions={EFFORTS}
ready={{ subscription: !routineMissing, api: !apiKeyMissing }}
readyNote="Both are secrets, set where the app is deployed."
spentMicros={spent}
usage={usage.map((u) => ({ job: u.feature, effort: u.effort, calls: u.calls, micros: u.micros }))}
Form={Form}
pending={busy}
/>
// A site whose API runs take no effort leaves out efforts and effortOptions: no Effort column.
// In the action:
const saved = settingsFromForm((name) => form.get(name), FEATURES);
Examples
The API for a few days, the subscription not connected, nothing spent
<div data-mount="override"></div>
API reference
AiEngineSettings
Prop
Type
Required
Does
settings
EngineSettingsLike
Yes
models
Readonly<Partial<Record<string, string>>>
Yes
The model each job's API run uses: "fast", "standard", "deep", or none (left out) for the job's default. A partial map, as site-runtime's settings reader returns it.
jobs
readonly EngineJob[]
Yes
modelOptions
readonly SelectOption[]
Yes
The model choices, with their prices (from site-runtime's MODEL_IDS and PRICES). The first is "The job's own default", value "".
efforts
Readonly<Partial<Record<string, string>>>
The effort each job's API run uses ("low" to "max"), a partial map like models, and its choices, the first "The job's own default", value "". A site whose API runs take no effort leaves both out, and the table has no Effort column.
effortOptions
readonly SelectOption[]
ready
{ subscription: boolean; api: boolean }
Yes
Whether each engine can work now: the routine connected, an API key set.
readyNote
ReactNode
What to do when one cannot, in a sentence.
spentMicros
number
Yes
This month's API spend, and by job (and by effort, where a run had one).
The settings a saved form holds: master, feature-<key>, model-<key> and effort-<key> for each job (empty is "follow everything" and "the job's own default"), and cap in dollars. The override is not in the form; the app keeps the one it has.
Parts and data attributes
Class
Is
.cap-ai-engine
the root
.cap-ai-engine-job-note
a part
.cap-ai-engine-note
a part
.cap-ai-engine-spend
a part
.cap-ai-engine-status
a part
.cap-ai-engine-table
a part
Accessibility
Key
Does
Tab
The table's region, then each row's engine and model, then Save, then the cap
The select's keys
Choose an engine or a model
Enter on Save
Saves the table and the cap
The table has a caption (hidden) and row headers; each select is named by its job ("Social post drafts: engine").
The table scrolls in a labeled, focusable region on a narrow screen.
Each engine's state is a status with its shape and word.