smart-components
Hooks

useGhostCompletion

The state machine behind SmartTextbox and SmartTextarea. Debounce + abort + LRU.

useGhostCompletion is the engine behind SmartTextbox and SmartTextarea. Reach for it directly when you want ghost-completion behavior wired into a non-input element (contenteditable, custom editor frame, etc.).

import { useGhostCompletion } from '@extedcoud/smart-components';

const { suggestion, status, error, fetchNow, clear } = useGhostCompletion({
  value,
  context: 'user is writing a support reply',
  minChars: 3,
  debounceMs: 300,
  stream: false,
  maxTokens: 32,
  enabled: true,
});

Options

OptionTypeDefaultDescription
valuestringThe current input text. Triggers a fetch when it changes.
contextstringOptional prompt context.
minCharsnumber3Skip fetch under this length.
debounceMsnumber300Debounce window.
streambooleanfalseUse streaming if the client supports it.
maxTokensnumber32Per-call token cap.
stopstring[]Stop sequences passed to the client.
enabledbooleantrueDisables all fetches when false.

Return shape

FieldTypeDescription
suggestionstringThe current ghost text. '' when none.
status'idle' | 'loading' | 'ready' | 'error'State machine.
errorError | nullSet when status is error. Abort errors are ignored.
fetchNow() => voidSkip the debounce and fetch immediately.
clear() => voidDiscard the current suggestion.

Caching

Internally uses an LRU(16) keyed by (value, context, model). Repeated debounces on the same input hit the cache.