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

@Component({ tag: 'my-custom-panel' })
export class MyCustomPanel {
@Element()
private host: HTMLElement & LimeWebComponent;

private unregisterContext: () => void;

connectedCallback() {
const registry = this.platform.get(PlatformServiceName.AIContextRegistry);
this.unregisterContext = registry.register({
contextType: 'my-custom-panel',
getContext: () => ({
purpose: 'Lets users select items for bulk operations. ' +
'Selected items can be exported or bulk-edited.',
data: {
selectedItemIds: this.selectedItems.map(i => i.id),
selectionCount: this.selectedItems.length
}
})
}, this.host);
}

disconnectedCallback() {
this.unregisterContext?.();
}
}

Hierarchy

  • AIContextProvider

Properties

Methods

Properties

contextType: string

Semantic 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.

Methods

  • 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.

    Returns

    The context contribution, or null if no context is available (e.g., required state hasn't loaded yet).

    Returns AIContextContribution