Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 17 additions & 15 deletions docs/src/main/asciidoc/assistant.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ An extension can define Assistant features without depending on Chappie directly

=== Workspace participation

You can add an assistant function to a workspace item using the same approach as regular https://quarkus.io/guides/dev-ui#workspace[workspace actions], with one key difference: instead of using `.function(...)`, you use `.assistantFunction(...)`.
You can add an assistant function to a workspace item using the same approach as regular xref:dev-ui.adoc#workspace[workspace actions], with one key difference: instead of using `.function(...)`, you use `.assistantFunction(...)`.

[source,java]
----
Expand All @@ -152,13 +152,13 @@ You can add an assistant function to a workspace item using the same approach as
.displayType(DisplayType.markdown)
.filter(Patterns.JAVA_SRC));
----
<1> Use `assistantFunction` to receive the `Assistant` instance and https://quarkus.io/guides/dev-ui#input[input] parameters.
<1> Use `assistantFunction` to receive the `Assistant` instance and xref:dev-ui.adoc#input[input] parameters.
<2> Provide an optional *system message* to guide the assistant's behavior.
<3> Provide a *user message* as the primary prompt.

=== Assistant pages

To add a standalone assistant-powered page to the Dev UI, use the https://quarkus.io/guides/dev-ui#card[`CardPageBuildItem`] and `Page.assistantPageBuilder()`:
To add a standalone assistant-powered page to the Dev UI, use the xref:dev-ui.adoc#card[`CardPageBuildItem`] and `Page.assistantPageBuilder()`:

[source,java]
----
Expand All @@ -170,11 +170,11 @@ cardPageBuildItem.addPage(Page.assistantPageBuilder() // <1>

=== Communicating to the backend

You can invoke the assistant from backend code using https://quarkus.io/guides/dev-ui#communicating-to-the-backend[standard Dev UI JSON-RPC] patterns — both against the *runtime* and *deployment* classpaths.
You can invoke the assistant from backend code using xref:dev-ui.adoc#communicating-to-the-backend[standard Dev UI JSON-RPC] patterns — both against the *runtime* and *deployment* classpaths.

==== JsonRPC against the Runtime classpath

To use the assistant in a https://quarkus.io/guides/dev-ui#jsonrpc-against-the-runtime-classpath[`JsonRpcService`] on the runtime classpath, inject the `Assistant` like this:
To use the assistant in a xref:dev-ui.adoc#jsonrpc-against-the-runtime-classpath[`JsonRpcService`] on the runtime classpath, inject the `Assistant` like this:

[source,java]
----
Expand All @@ -201,27 +201,29 @@ You can now use this assistant in any JsonRPC method, example:

==== JsonRPC against the Deployment classpath

In https://quarkus.io/guides/dev-ui#jsonrpc-against-the-deployment-classpath[deployment-time] code, use the `BuildTimeActionBuildItem` and register assistant actions via `.addAssistantAction(...)`:
In xref:dev-ui.adoc#jsonrpc-against-the-deployment-classpath[deployment-time] code, use the `BuildTimeActionBuildItem` and register assistant actions via `.addAssistantAction(...)`:

[source,java]
----
BuildTimeActionBuildItem bta = new BuildTimeActionBuildItem();

bta.addAssistantAction("getAIJokeInDeployment", (a, p) -> { // <1>
Assistant assistant = (Assistant) a;
bta.actionBuilder()
.methodName("getAIJokeInDeployment")
.assistantFunction((a, p) -> { // <1>
Assistant assistant = (Assistant) a;

return assistant.assistBuilder()
.userMessage(USER_MESSAGE)
.variables(p)
.assist();
});
return assistant.assistBuilder()
.userMessage(USER_MESSAGE)
.variables(p)
.assist();
}).build());
buildTimeActionProducer.produce(bta);
----
<1> Use `addAssistantAction` instead of `addAction` to access the assistant context.
<1> Use `assistantFunction` instead of `function` to access the assistant context.

=== Assistant State in the UI

To conditionally render assistant UI in your Web Component, you can use the https://quarkus.io/guides/dev-ui#assistant-state[assistant state] to
To conditionally render assistant UI in your Web Component, you can use the xref:dev-ui.adoc#assistant-state[assistant state] to
check the state of the assistant. The state can be:

- notAvailable: No assistant implementation (like Chappie) is present.
Expand Down
38 changes: 22 additions & 16 deletions docs/src/main/asciidoc/dev-ui.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -1037,27 +1037,31 @@ you can just supply the code to be run in a supplier in the deployment module. T
----
@BuildStep(onlyIf = IsLocalDevelopment.class)
BuildTimeActionBuildItem createBuildTimeActions() { //<1>
BuildTimeActionBuildItem generateManifestActions = new BuildTimeActionBuildItem();//<2>
generateManifestActions.addAction("generateManifests", params -> { //<3>
try {
List<Manifest> manifests = holder.getManifests();
// Avoid relying on databind.
Map<String, String> map = new LinkedHashMap<>();
for (Manifest manifest : manifests) {
map.put(manifest.getName(), manifest.getContent());
BuildTimeActionBuildItem generateManifestActions = new BuildTimeActionBuildItem(); //<2>

generateManifestActions.actionBuilder()
.methodName("generateManifests")//<3>
.function(params -> { //<4>
try {
List<Manifest> manifests = holder.getManifests();
// Avoid relying on databind.
Map<String, String> map = new LinkedHashMap<>();
for (Manifest manifest : manifests) {
map.put(manifest.getName(), manifest.getContent());
}
return map;
} catch (Exception e) {
throw new RuntimeException(e);
}
return map;
} catch (Exception e) {
throw new RuntimeException(e);
}
});
}).build();

return generateManifestActions;
}
----
<1> Return or use a BuildProducer to create a `BuildTimeActionBuildItem`
<2> `BuildTimeActionBuildItem` is automatically scoped with your extension namespace
<3> Here we add an action, that is the same as a request-response method. The method name (that can be called from js in the same way as any json-rpc service) is `generateManifests`. If there are any parameters, those will be available in a map (params)
<3> The method name (that can be called from js in the same way as any json-rpc service) is `generateManifests`.
<4> Here we add an function that will execute when this action is requested from the UI. If there are any parameters, those will be available in a map (params)

You can also return a `CompletableFuture`/`CompletionStage` as an action, and if you want to stream data you need to use `addSubscription` (rather than `addAction`) and return a `Flow.Publisher`. Here you can not use Uni and Multi as we need to pass data between the deployment and runtime classpaths, so sticking to JDK classes is the safe option.

Expand All @@ -1070,8 +1074,10 @@ Passing recorded data to the UI work the same as the above deployment classpath,
@BuildStep(onlyIf = IsLocalDevelopment.class)
BuildTimeActionBuildItem createBuildTimeActions() {
BuildTimeActionBuildItem actionBuildItem = new BuildTimeActionBuildItem();
actionBuildItem.addAction("getMyRecordedValue", runtimeValue); // <1>

actionBuildItem.actionBuilder()
.methodName("getMyRecordedValue")
.runtime(runtimeValue) // <1>
.build();
return actionBuildItem;
}
----
Expand Down
Loading