webui.go

Overview

The webui.go file implements a Web UI Launcher as a sublauncher component that integrates an embedded Angular-based web user interface (UI) into the ADK web server. It serves the UI assets statically from within the executable binary at a configurable HTTP path prefix (default /ui/) and dynamically generates runtime configuration data (such as the backend REST API URL) for the UI to consume.

This launcher enables users to interact visually with the ADK REST API backend through a browser without requiring a separately deployed frontend server. It integrates seamlessly with the main HTTP router and the launcher framework, handling command-line flags, HTTP routing, static asset delivery, and user messages.

The file belongs to the broader REST API and Web Launchers system that exposes AI agents via HTTP interfaces, complementing REST API endpoints and other sublaunchers such as A2A.


Key Types

webUIConfig

type webUIConfig struct {
	backendAddress string
	pathPrefix     string
}

webUILauncher

type webUILauncher struct {
	flags  *flag.FlagSet
	config *webUIConfig
}

Functions and Methods

NewLauncher() weblauncher.Sublauncher

launcher := NewLauncher()

(w *webUILauncher) CommandLineSyntax() string


(w *webUILauncher) Keyword() string


(w *webUILauncher) Parse(args []string) ([]string, error)


(w *webUILauncher) SetupSubrouters(router *mux.Router, config *launcher.Config) error


(w *webUILauncher) AddSubrouter(router *mux.Router, pathPrefix, backendAddress string)

w.AddSubrouter(router, "/ui/", "http://localhost:8080/api")

(w *webUILauncher) SimpleDescription() string


(w *webUILauncher) UserMessage(webURL string, printer func(v ...any))

webui:  you can access API using http://localhost:8080/ui/

Embedded Static Assets

//go:embed distr/*
var content embed.FS

Important Implementation Details


Interaction with Other System Components


Usage Example

A typical usage scenario:

  1. Create a Web UI launcher instance:

launcher := webui.NewLauncher()
  1. Parse command-line arguments (e.g., -api_server_address).

  2. Setup HTTP server and add subrouters:

router := mux.NewRouter()
launcher.SetupSubrouters(router, nil)
  1. Start HTTP server serving the router.

  2. User accesses http://<host>:<port>/ui/ in a browser.

  3. The UI loads static assets from embedded files and obtains runtime configuration from /ui/assets/config/runtime-config.json.

  4. UI communicates with the backend API at the specified api_server_address.


Visual Diagram: Web UI Launcher HTTP Routing Flow

flowchart TD
User[User Browser]
Router[HTTP Router]
Redirect[Redirect Handler]
ConfigEndpoint[Runtime Config JSON]
StaticServer[Embedded UI File Server]
UIApp[Angular UI]
BackendAPI[ADK REST API Server]
User -->|GET / or /ui/*| Router
Router -->|Redirect / to /ui/| Redirect
Router -->|Serve /ui/assets/config/runtime-config.json| ConfigEndpoint
Router -->|Serve static files under /ui/| StaticServer
ConfigEndpoint --> UIApp
StaticServer --> UIApp
UIApp -->|REST API calls| BackendAPI

References