API Reference

Every input, output, observable, and method — distilled.

<ai-autocomplete>

The full drop-in standalone component. Owns the contentEditable editor, inline pills, dropdown, and all state. Implements ControlValueAccessor for Reactive Forms.

Inputs

PropTypeDefaultDescription
apiConfigAPIConfigRuntime API configuration (public key or access token).
pillPlacement"inline" | "dropdown" | "hidden""inline"Where unfilled pills render. inline lives in the input; dropdown places them with the options; hidden shows none.
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 the selection streak + new-param shimmer.
dropdownTrigger"auto" | "manual" | "hidden""auto"When the dropdown appears. auto = when options are available; manual = only on pill tap; hidden = never.
closeDropdownOnBlurbooleantrueWhen false, the dropdown stays open even when the editor loses focus.
showNonTappableOptionsbooleantrueRender non-tappable options alongside tappable ones.
columnsnumber2Number of columns in the dropdown grid.
maskCompletedTextbooleanfalseStrip completed-param text from network requests (PII masking).
optionOverridesOptionOverridesInject or compute option lists per suggestion type.
autoFocusbooleantrueFocus the editor on mount. Set false to leave focus to the consumer.
valuestringControlled text value. Pair with (valueChange).
completedParamsCompletedParamState[]Controlled completed params. Pair with (completedParamsChange).
submitButtonTemplateRef | nullA <ng-template> to replace the default arrow button. Pass null to render no button.

Outputs

PropTypeDefaultDescription
submittedEventEmitter<AutocompleteResult>Emits on Enter or submit-button click. Carries an AutocompleteResult.
erroredEventEmitter<Error>Emits when a fetch fails.
valueChangeEventEmitter<string>Emits when text changes (controlled mode).
completedParamsChangeEventEmitter<CompletedParamState[]>Emits when completed params change (controlled mode).
focusedEventEmitter<void>Emits when the editor gains focus.
blurredEventEmitter<void>Emits when the editor loses focus.

Imperative methods

Call these on the component instance via a template reference variable + @ViewChild.

PropTypeDefaultDescription
focus()() => voidFocus the editor.
blur()() => voidBlur the editor.
reset()() => voidClear all state, rotate the session, and re-fetch.
setMode()(mode: AppearanceMode) => voidSwitch color mode at runtime.

AIAutocompleteController

A plain TypeScript class — no DI. Create it with new in ngOnInit, hold the reference, and call destroy() in ngOnDestroy. Exposes the SDK's reactive state as RxJS observables plus action methods.

Constructor options

Pass these to the constructor. Event callbacks (onSubmit, onError, …) are registered once at construction — for dynamic reactivity, subscribe to the observables instead.

PropTypeDefaultDescription
apiConfigAPIConfigRuntime API configuration (key or token).
optionsPosition"above" | "below""below"Where the dropdown opens. Read by the keyboard controller to pick the open key.
dropdownTrigger"auto" | "manual" | "hidden""auto"When the dropdown appears.
closeDropdownOnBlurbooleantrueWhen false, the dropdown stays open even when the input loses focus.
showNonTappableOptionsbooleantrueRender non-tappable options alongside tappable ones.
columnsnumber2Number of columns in the dropdown grid.
maskCompletedTextbooleanfalseStrip completed-param text from network requests (PII masking).
optionOverridesOptionOverridesOverride option lists per suggestion type.
valuestringInitial controlled text value.
completedParamsCompletedParamState[]Initial controlled completed params.
onSubmit / onError / onChange(...) => voidonSubmit, onError, onChange, onParamsChange, onFocus, onBlur — registered once at construction.

Observables

Each field is exposed as a stand-alone observable plus a composite state$. All run through distinctUntilChanged + shareReplay, so multiple async pipes share one subscription.

PropTypeDefaultDescription
state$Observable<AIAutocompleteControllerState>Snapshot of every public field in one object — convenient for *ngIf="ctrl.state$ | async as state".
dropdown$Observable<AIAutocompleteDropdownState>Composite stream for the dropdown view (suggestions, activeIndex, isOpen, pills, …) — bound to <ai-autocomplete-dropdown> via [controller], or subscribe to it directly to render your own dropdown in Tier 3.
text$Observable<string>Current editor text.
completedParams$Observable<CompletedParamState[]>Filled parameters.
suggestionPills$Observable<Suggestion[]>Actionable suggestion pills. The first item is the active pill.
segments$Observable<Segment[]>Input text split into typed text vs completed-param segments.
isLoading$Observable<boolean>Whether a fetch is in progress (UI-visible).
isDropdownOpen$Observable<boolean>Whether the dropdown should be visible.
isReady$Observable<boolean>Server indicates the query is complete.
error$Observable<Error | null>Last fetch error, or null.
activeIndex$Observable<number>Highlighted dropdown option index. -1 = none.

Actions

Thin pass-throughs to the headless core. After destroy() they no-op safely.

PropTypeDefaultDescription
handleTextChange()(value: string) => voidCall when the user types. Handles capitalization, param reconciliation, and filtering.
handleKeyDown()(e: KeyboardEvent) => voidForward keyboard events from your input. Handles arrow nav, Enter, Tab, Escape.
setFocused()(focused: boolean) => voidNotify the controller the input gained or lost focus. Custom inputs only — [aiaInput] does this for you.
handleCaretMove()(offset: number | null) => voidReport the caret position (plain-text offset) so arrow keys can move into the dropdown. Custom inputs only.
selectOption()(option: SuggestionOption) => voidSelect a dropdown option — updates text, creates a completed param, triggers shimmer.
setActiveDropdownIndex()(index: number) => voidHighlight a dropdown option by index (-1 = none). Use it to wire hover/keyboard highlighting when rendering your own dropdown.
setActivePill()(index: number) => voidMove the pill at index to the front (active).
removeLastParam()() => voidRemove the last completed param and restore it as a pill.
setValue()(text: string) => voidSet the editor text (controlled mode).
setCompletedParams()(params: CompletedParamState[]) => voidSet completed params (controlled mode).
reset()() => voidClear all state, rotate the session, and re-fetch. Call after submit.
update()(opts: AIAutocompleteControllerUpdate) => voidApply runtime option changes (e.g. dropdownTrigger, optionsPosition). Event callbacks can't be swapped — subscribe to the observables instead.
getState()() => AIAutocompleteControllerStateSynchronous snapshot of the current state (for use inside event handlers).
destroy()() => voidRelease subscriptions and the underlying core. Call in ngOnDestroy.

<ai-autocomplete-dropdown>

Tier 2 dropdown component. Pass it the same controller — it renders the pillbar, options grid, and loading skeleton, and forwards actions back to the controller.

PropTypeDefaultDescription
controllerRequiredAIAutocompleteControllerThe controller that owns the autocomplete state.
showPillsbooleantrueWhether to render the pillbar inside the dropdown.
mode"light" | "dark" | "auto"Color mode for a standalone dropdown — self-scopes the SDK tokens so no .magicx-aia wrapper is needed. "auto" follows prefers-color-scheme. Leave unset when nested inside a .magicx-aia ancestor (e.g. Tier 1).
classNamestringCSS class applied to the dropdown root.

[aiaInput] directive

Attach [aiaInput]="controller" to your own <textarea> or <input> to wire its events (input, keydown, focus, blur, caret moves) into the controller and mirror state into ARIA attributes. Implements ControlValueAccessor, so it also works with [formControl] / [(ngModel)].

AutocompleteResult

The shape emitted by (submitted).

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