AlphaAlphaGather context from all registered providers.
Calls getContext() on each provider and collects the results.
Providers that return null (indicating no context available) and
providers that throw errors are skipped (errors log a warning).
Each contribution is enriched with the component's LimeWebComponentContext.
Summaries and actions are not included.
An array of enriched context contributions, one from each provider that returned a non-null contribution.
AlphaGather the full context, including actions, from all registered providers.
Gathers the same contributions as gatherContext() without options,
and adds the actions from each provider's
getActions. A provider that
returns null from getContext() but has actions is included with
just its actions, and one whose getActions throws is included
without actions, with a warning. Action ids are page-wide, so a
provider registered more than once lists each action once, and at
most 20 actions per provider and 50 per page are listed, the rest
dropped with a warning.
A registry offers this option together with
prepareAction, so pass it
only when typeof registry.prepareAction === 'function'.
detail: 'full'.
An array of enriched context contributions, one from each provider that returned a non-null contribution or has actions.
AlphaGather the summaries and action ids from all registered providers.
This is the short form of the context, sent with every message.
Providers without a summary or actions are skipped, as are providers
whose getSummary throws; a provider whose getActions throws is
listed without actions. Both log a warning. Action ids are page-wide,
so a provider registered more than once lists each action once, and
at most 20 actions per provider and 50 per page are listed, the rest
dropped with a warning.
A registry offers this option together with
prepareAction, so pass it
only when typeof registry.prepareAction === 'function'.
detail: 'summary'.
An array of summaries, one from each provider that has a summary or actions.
import { PlatformServiceName } from '@limetech/lime-web-components';
const registry = platform.get(PlatformServiceName.AIContextRegistry);
const http = platform.get(PlatformServiceName.Http);
await http.post('my_addon/chat', {
text: 'Which deals here are about to close?',
context:
typeof registry.prepareAction === 'function'
? registry.gatherContext({ detail: 'summary' })
: registry.gatherContext(),
});
AlphaGet all registered providers.
Useful for debugging or introspection.
Array of all registered providers.
OptionalprepareAlphaPrepare an action for running.
Finds the action with the id among the connected providers'
getActions. When several offer
the id, the most recently registered provider wins. Action ids are
page-wide, and an action dropped by the limit of 20 per provider and
50 per page, with a warning, is 'unavailable'. For an action
that needs approval, it calls the action's
prepare to get the preview to
show the user. When prepare rejects, the registry logs a warning,
as it does for a provider that throws while gathering, and returns
'invalid' with the rejection's message.
Check that it exists before offering actions to the AI.
'ready' with a run function for an action without
approval, 'needs-approval' with a preview and a run function for
one with approval, 'unavailable' when no connected provider offers
the id, or 'invalid' when prepare rejected the input or resolved
without a preview that is an object with a title. An action that
needs approval never comes back as 'ready'.
import {
AIActionResult,
ApprovalPreview,
JsonValue,
PlatformServiceName,
} from '@limetech/lime-web-components';
type ActionOutcome = AIActionResult | { status: 'denied' };
declare function askUserToApprove(preview: ApprovalPreview): Promise<boolean>;
const registry = platform.get(PlatformServiceName.AIContextRegistry);
async function performAction(
id: string,
input: JsonValue
): Promise<ActionOutcome> {
if (!registry.prepareAction) {
return { status: 'failed', message: 'This page has no actions' };
}
const prepared = await registry.prepareAction(id, input);
if (prepared.status === 'unavailable') {
return { status: 'failed', message: `${id} is not on this page` };
}
if (prepared.status === 'invalid') {
return { status: 'failed', message: prepared.message };
}
if (
prepared.status === 'needs-approval' &&
!(await askUserToApprove(prepared.preview))
) {
return { status: 'denied' };
}
return prepared.run();
}
AlphaRegister a context provider.
The provider will be called when context is gathered via gatherContext().
Multiple providers with the same contextType can coexist - each registration
gets a unique internal key.
The provider to register.
The host element of the component registering this provider. Enables the registry to:
LimeWebComponentContext to enrich contributionsA function to unregister the provider. Call this when the component is disconnected or the context is no longer relevant.
import { Element } from '@stencil/core';
import {
LimeObject,
LimeWebComponent,
PlatformServiceName,
} from '@limetech/lime-web-components';
class DealCard {
@Element()
private host: HTMLElement & LimeWebComponent;
private deal: LimeObject | null = null;
private unregister?: () => void;
public async connectedCallback() {
const repository = platform.get(
PlatformServiceName.LimeObjectRepository
);
if (context.limetype && context.id) {
this.deal = await repository.loadObject(
context.limetype,
context.id,
{ properties: ['descriptive'] }
);
}
const registry = platform.get(PlatformServiceName.AIContextRegistry);
this.unregister = registry.register(
{
contextType: 'deal-card',
getContext: () => ({
purpose:
'Shows full details of a deal record. ' +
'Users can edit fields and manage related records.',
data: {
limetype: 'deal',
id: context.id,
descriptive: this.deal?.getValue('descriptive') ?? null,
},
}),
},
this.host
);
}
public disconnectedCallback() {
this.unregister?.();
}
}
Registry for AI context providers.
The AIContextRegistry manages context providers that contribute information to the AI chat. Components register providers to share their state, and the AI chat gathers context from all providers when needed.
Example: Gathering context for an AI request
See