Adds inline "ghost text" completions to the block editor. When the experiment and global toggle are enabled, typing inside supported blocks (paragraphs by default, optional headings) displays translucent suggestions that can be accepted via keyboard shortcuts.
WordPress\AI\Experiments\Type_Ahead\Type_Ahead::register()hookswp_abilities_api_initto register the AI ability andenqueue_block_editor_assetsto load assets only when the block editor runs.Type_Ahead::register_settings()stores experiment-specific options under the Experiments settings screen (ai_experiment_type_ahead_*).src/experiments/type-ahead/index.tsxregisters aneditor.BlockEditfilter (HOC) that adds the overlay for each supported block and wires keyboard handlers.- Ability implementation lives at
includes/Abilities/Type_Ahead/Type_Ahead.phpand is registered asai/type-ahead.
- PHP enqueues the
experiments/type-aheadscript andexperiments/style-type-aheadstylesheet, then localizesaiTypeAheadDatawith flags likecompletionMode,triggerDelay, andabilityName. - The React entry point polls for the localized data, then wraps block edits to render the overlay component and keyboard hints, and calls
executeAbility( 'ai/type-ahead', ... )when it is time to request a suggestion. - The ability sanitizes input (post ID, caret position, snippets of block content) and composes a structured payload via
prepare_prompt_context(). AI_Client::prompt_with_wp_error()is invoked with the system instruction inincludes/Abilities/Type_Ahead/system-instruction.php, returning JSON{ suggestion, confidence }that the ability validates before passing back to JS.- The UI caches the last suggestion per block/caret, displays it via a portal near the caret, and dispatches synthetic
inputevents when the user accepts a suggestion so Gutenberg updates its state.
- Enable Experiments globally and toggle Type-ahead Text under
Settings > AI Experiments. (Optional: adjust mode/delay/confidence/headings.) - Open the block editor, insert a Paragraph block, and start typing sentences until the caret is at the end of a sentence. After the configured delay a faint suggestion should appear.
- Press
Tabto accept the full suggestion,Cmd/Ctrl + Right Arrowfor a word, orCmd/Ctrl + Shift + Right Arrowfor a sentence. The accepted text should become real content and the remainder should stay ghosted if available. - Press
Escto dismiss a suggestion. UseCmd/Ctrl + Spaceto force a manual fetch even when the caret context would not auto-trigger. - Toggle the "Enable in headings" checkbox in settings, then verify
core/headingblocks now receive suggestions.
- Suggestions are cached briefly (45 seconds) per block/caret combination to reduce provider calls.
- Permissions require
edit_postwhen a post ID is provided, otherwiseedit_posts. - The ability trims contexts to 5000 characters and normalizes HTML content before sending it to the model.
- Settings are stored via the standard options API; sanitizers enforce safe ranges (delay 200-2000 ms, confidence 0-100, etc.).
- The client aborts long-running REST calls after roughly 15 seconds to avoid default 20s browser/
apiFetchtimeouts while still giving the server time; writers can press Cmd/Ctrl + Space to manually try again.