Alpha Readonly contextSemantic label for grouping related providers.
Multiple providers can share the same contextType (e.g., multiple info-tiles on a page). Each registration gets a unique internal key, so there are no collisions. This label is used for debugging and potential future grouping/filtering of context.
Use a descriptive name that identifies the component or feature type.
Get context from this provider.
Called when the AI chat needs to gather context from all providers. Should return data that the component already has available - this method is synchronous because providers should only return data that is already rendered on-screen.
The implementation should be fast and avoid expensive operations since it's called on every message.
The context contribution, or null if no context is available
(e.g., required state hasn't loaded yet).
A provider that contributes context information to the AI chat.
Components register providers to share relevant state with the AI. When the AI chat needs context, it calls
getContext()on all registered providers and collects their contributions.Typically, providers are registered when a component is created or connected to the DOM, and unregistered when disconnected. Alternatively, some components may register/unregister based on visibility if context should only be provided while the component is visible to the user.
The
register()method returns an unregister function for cleanup.Example
Registering a provider in a Stencil component