Embed in a desktop app¶
The desktop library assistant-fx shows the same assistant as in pages, with no login screen: you give it the token and the functions of your app the assistant may call. It needs Java 21 and OpenJFX 21.0.5 or later.
AssistantConfig config = AssistantConfig.of("https://assistant.example.com", () -> currentUser.token())
.withHostFunctions(List.of(
HostFunction.read("open_task", "Show a task on the user's screen.", """
{"type":"object","properties":{"task_id":{"type":"string"}},"required":["task_id"]}""",
args -> { Platform.runLater(() -> showTask((String) args.get("task_id"))); return Map.of("opened", true); })));
pane.setCenter(new AssistantView(config)); // in a JavaFX layout
panel.add(new AssistantPanel(config)); // in a Swing layout
- Address. Your assistant's address. The window shows its embed page and goes nowhere else.
- Token supplier. Called at start and whenever the platform refuses the token; it may call your backend.
pushToken()sends a new token you refreshed yourself. - Host functions. Name, description, JSON Schema and
read(runs at once) orwrite(the user confirms first). Handlers run off the UI thread; hand any screen change to your UI thread, as the example does. Return small JSON, or throw: the message goes to the assistant.
Good to know¶
- Use https. Plain http is refused except for this machine; the token would cross the network in the clear. For local development over http, start the JVM with
-Dcom.sun.webkit.useHTTP2Loader=false. - Writes work everywhere. The assistant sends changes as POST with a method override through its own proxy, so the embedded browser needs nothing special.
- Lifecycle. Call
close()when the window goes away.setOnProblem(message -> ...)tells you when the page failed to load, so you can show something other than a blank window. - The token stays inside. It is exposed only to the assistant's own origin; the window refuses to navigate elsewhere and opens no popups.