API Reference

Every prop, hook, and type — distilled.

<AIAutocomplete />

The full drop-in component. Owns the input, dropdown, and pills.

PropTypeDefaultDescription
onSubmitRequired(result: AutocompleteResult) => voidCalled on Enter or submit. Receives an AutocompleteResult.
onError(error: Error) => voidCalled when a fetch fails.
apiConfigAPIConfigRuntime API configuration (key or token).
placeholderstringFallback placeholder when the server doesn't return one.
classNamestringClass applied to the container.
columnsnumber2Number of columns in the dropdown grid.
pillPlacement"inline" | "dropdown" | "hidden""inline"Where unfilled pills render. inline lives in the input; dropdown places them with options.
mode"light" | "dark" | "auto""auto"Color mode. auto follows prefers-color-scheme.
optionsPosition"above" | "below""below"Where the dropdown opens relative to the input.
animationsbooleantrueEnable selection streak + new-param shimmer.
dropdownTrigger"auto" | "manual" | "hidden""auto"When the dropdown appears. auto = when options available; manual = only on pill tap.
closeDropdownOnBlurbooleantrueWhen false, the dropdown stays open even when the input loses focus.
autoFocusbooleantrueFocus the input on mount. Set to false to leave focus to the consumer.
onFocus() => voidCalled when the input gains focus.
onBlur() => voidCalled when the input loses focus.
maskCompletedTextbooleanfalseStrip completed-param text from network requests (PII masking).
optionOverridesRecord<string, (query) => SuggestionOption[]>Override option lists per suggestion type.
valuestringControlled text value.
completedParamsCompletedParamState[]Controlled completed params.
onChange(value: string) => voidCalled when text changes (controlled mode).
onParamsChange(params: CompletedParamState[]) => voidCalled when params change (controlled mode).
refRef<AIAutocompleteHandle>Imperative handle: focus(), blur(), reset(), setMode().

useAIAutocomplete()

Use the hook for custom rendering. Same options as <AIAutocomplete /> minus the rendering-only props (className, mode, optionsPosition, animations, pillPlacement, autoFocus). The hook doesn't own the textarea — onFocus and onBlur fire when the consumer-owned textarea's focus changes.

State

PropTypeDefaultDescription
completedParamsCompletedParamState[]Filled parameters.
suggestionPillsSuggestion[]Unfilled suggestions (pills). First item is the active pill.
segmentsSegment[]Input text split into typed text vs completed segments.
newParamIdstring | nullID of the most recently added param (for shimmer).
suggestionsSuggestion[]All suggestions from server (including placeholder type).
activeIndexnumberHighlighted option index. -1 = none.
isLoadingbooleanFetch in progress.
isReadybooleanServer indicates query is complete.
isDropdownOpenbooleanWhether the dropdown should be visible. Drive your own dropdown's visibility with this in Tier 3.
placeholderTextstringSuggested placeholder text for the current step.
errorError | nullLast fetch error.

Input forwarding (custom inputs)

PropTypeDefaultDescription
handleTextChange(text: string) => voidForward the input's current plain text to the engine on every edit. Custom inputs only — textareas use inputProps.
handleKeyDown(e: KeyboardEvent) => voidForward a keyboard event so the engine can handle Arrow/Enter/Tab/Escape while the dropdown is open. Check event.defaultPrevented to see if it was consumed. Custom inputs only.
setFocused(focused: boolean) => voidTell the engine the input gained or lost focus. Custom inputs only.
handleCaretMove(offset: number) => voidReport the caret position (plain-text offset) so arrow keys can move into the dropdown. Call on selection changes. Custom inputs only.

Actions

PropTypeDefaultDescription
setActivePill(index: number) => voidMove the pill at index to front (active).
removeLastParam() => voidRemove last completed param, restore as a pill.
clearNewParamId() => voidClear shimmer animation state.
reset() => voidClear all state, re-fetch.

Spread props

PropTypeDefaultDescription
inputPropsTextareaHTMLAttributesSpread onto a <textarea>. Includes value, placeholder, onChange, onKeyDown, and ARIA attributes.
dropdownPropsAIAutocompleteDropdownPropsSpread onto <AIAutocompleteDropdown />. Its shape is exactly the <AIAutocompleteDropdown /> props documented below — in Tier 3, read suggestions, activeIndex, isOpen, onSelect, and onHighlight from it to render your own dropdown.

inputProps fields

What inputProps contains, for when you want to add a handler or wire a non-textarea input. Spread it onto a <textarea>; for a contentEditable or rich-text input, skip it and use the input-forwarding actions above.

PropTypeDefaultDescription
valuestringCurrent input text — render it as the textarea's value.
placeholderstring | undefinedSuggested placeholder for the active step (may be undefined).
onChange(e: ChangeEvent<HTMLTextAreaElement>) => voidForwards edits to the engine (also handles autocapitalize).
onKeyDown(e: KeyboardEvent<HTMLTextAreaElement>) => voidRoutes Arrow / Enter / Tab / Escape to the dropdown while it's open.
onFocus / onBlur() => voidNotify the engine when the input gains or loses focus.
role + aria-*ARIA attributesCombobox accessibility wiring: role="combobox", aria-expanded, aria-activedescendant, aria-autocomplete, aria-controls.

<AIAutocompleteDropdown />

Spread dropdownProps from useAIAutocomplete.

PropTypeDefaultDescription
suggestionsRequiredSuggestion[]Suggestions to display.
activeIndexRequirednumberHighlighted option index.
onSelectRequired(option: SuggestionOption) => voidCalled when an option is selected.
onHighlightRequired(index: number) => voidCalled on mouse hover.
isOpenRequiredbooleanWhether the dropdown is visible.
idRequiredstringListbox ID for ARIA.
pillsSuggestion[]Pills to render inside the dropdown.
onPillClick(index: number) => voidCalled when a pill is clicked.
showPillsbooleantrueWhether to render pills.
optionsPosition"above" | "below""below"Where the dropdown opens relative to the input — "above" or "below". Default "below".
mode"light" | "dark" | "auto"Color mode for a standalone dropdown — self-scopes the SDK tokens so no .magicx-aia wrapper is needed. Leave unset when nested inside a .magicx-aia ancestor.
classNamestringCSS class applied to the dropdown.

AutocompleteResult

The shape of the object passed to onSubmit.

PropTypeDefaultDescription
querystringPlain text as the user sees it.
raw_querystringText with placeholder tokens (e.g. "Create a {{TASK_1}}").
completed_paramsCompletedParam[]Filled parameter values.