makeAssistantVisible is a higher-order component (HOC) that makes React components "visible" by the assistant, allowing it to understand and interact with the component's HTML structure.
Usage#
import { makeAssistantVisible } from "@assistant-ui/react";
const Button = ({ onClick, children }) => (
<button onClick={onClick}>{children}</button>
);
// Basic usage - makes component HTML readable
const ReadableButton = makeAssistantVisible(Button);
// With clickable configuration
const ClickableButton = makeAssistantVisible(Button, {
clickable: true, // Enables the click tool
});
// With editable configuration
const EditableInput = makeAssistantVisible(Input, {
editable: true, // Enables the edit tool
});
API Reference#
Parameters#
Component: The base React component to enhanceconfig: Optional configuration objectclickable: When true, enables the assistant to programmatically click the componenteditable: When true, enables the assistant to programmatically set the value of an input or textarea within the component
Behavior#
The HOC will:
- Make the component's HTML structure available to the assistant via the system context
- Optionally provide a
clicktool ifclickableis true - Optionally provide an
edittool ifeditableis true, which sets the value of an<input>or<textarea>inside the component - Handle nested readable components (only the outermost component's HTML is provided)
- Forward refs and maintain component props
Example#
// Create a readable form input that the assistant can also edit
const Input = ({ label, ...props }) => (
<div>
<label>{label}</label>
<input {...props} />
</div>
);
const EditableInput = makeAssistantVisible(Input, { editable: true });
// Use in your component
function Form() {
return (
<EditableInput label="Email" type="email" placeholder="Enter your email" />
);
}
Technical Details#
When a component is made readable:
- It's wrapped in a
ReadableContext.Providerto handle nesting - The component's
outerHTMLis provided as system context - If
clickableis true, a uniquedata-click-idis added and aclicktool is provided - The click tool uses
querySelectorand simulates a click event - If
editableis true, a uniquedata-edit-idis added and anedittool is provided - The edit tool uses
querySelectorto find an<input>or<textarea>and sets its value, dispatchinginputandchangeevents - All props and refs are properly forwarded to maintain component functionality