Class EmbeddedAssistantBuilder
readiness, assembling the EmbedHost, and unwrapping the result into the surface the host wants — an inline AssistSession, the shared AssistAction, or a ready-to-mount AssistButton/AssistToolbarButton.
Obtained through DesignerAiContext.assistant(). Configure it in a map from
DesignerContext.getAiContext() and run
the terminal as a flatMap method reference, so the absent-module case folds into the same
empty result every terminal returns when AI is not ready or no provider/model is configured — the
host keeps a single fallback branch.
Drop an icon-only button on a text editor's toolbar:
context.getAiContext()
.map(ai -> ai.assistant()
.agent(() -> createAgent(ai))
.host(EmbedHost.forTextEditorWithInsert(TextlikeComponent.of(editor)))
.promptAssists(ai.promptAssists().tags()))
.flatMap(EmbeddedAssistantBuilder::toolbarButton)
.ifPresent(button -> toolbar.add(button, 0));
Or mount an inline session inside a panel, extracting a configure helper when the wiring is long:
assistSession = context.getAiContext()
.map(this::configureAssistant)
.flatMap(EmbeddedAssistantBuilder::inline)
.orElse(null);
private EmbeddedAssistantBuilder configureAssistant(DesignerAiContext ai) {
return ai.assistant()
.agent(() -> new InstanceWizardAgent(ai.tools()))
.host(host -> host
.composer(composer)
.rendererFactory(rendererFactory))
.promptAssists(new UdtPromptAssist(context));
}
-
Method Summary
Modifier and TypeMethodDescriptionaction()Builds the shared "Ask AI" popup action.agent(Agent.AgentFactory agentFactory) Sets the factory that builds theAgentpowering each model turn.button()Builds a labeled panel button bound to theaction.Sets the host-side strategies the session uses to talk to the surrounding UI.host(Consumer<EmbedHostBuilder> configurer) Composes a custom host inline.inline()Builds an inline-mounted session.promptAssists(PromptAssist... promptAssists) Sets the in-prompt autocomplete assists.promptAssists(List<PromptAssist> promptAssists) Sets the in-prompt autocomplete assists.Builds an icon-only toolbar button bound to theaction.
-
Method Details
-
agent
Sets the factory that builds theAgentpowering each model turn. Invoked when the harness asks for an agent (at least once per session), so it may return per-call state. -
host
Sets the host-side strategies the session uses to talk to the surrounding UI. Use this with a prebuilt host — typically one ofEmbedHost.forTextEditor(TextlikeComponent)/EmbedHost.forTextEditorWithInsert(TextlikeComponent). To compose a custom host inline, usehost(Consumer)instead. -
host
Composes a custom host inline. The suppliedEmbedHostBuilderis built immediately afterconfigurerruns..host(host -> host .composer(myComposer) .rendererFactory(myRendererFactory)) -
promptAssists
Sets the in-prompt autocomplete assists. Defaults to none; an empty list disables the autocomplete popup entirely. -
promptAssists
Sets the in-prompt autocomplete assists. Defaults to none; an empty list disables the autocomplete popup entirely. -
inline
Builds an inline-mounted session. The caller owns the returned session's lifecycle and mustcloseit when the host goes away.- Returns:
- the session, or empty when AI is not ready or no provider/model is configured.
-
action
Builds the shared "Ask AI" popup action. Bind it to anAssistButtonorAssistToolbarButton; preferbutton()ortoolbarButton()when no other binding is needed.Not gated on
DesignerAiContext.isReady(): the bound button tracks readiness for the lifetime of its hierarchy and renders disabled until a provider and model are configured. Hosts mounted during Designer startup, before the catalog has loaded, get a working button without having to retry.- Returns:
- the action. Always present; the absent case is carried by
DesignerContext.getAiContext().
-
button
Builds a labeled panel button bound to theaction. CallAbstractButton.setText(String)on the result to set its label.- Returns:
- the button. Always present, for the same reason as
action(); it renders disabled until a provider and model are configured.
-
toolbarButton
-