Skip to content
Closed
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
10 changes: 8 additions & 2 deletions src/google/adk/cli/adk_web_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,7 @@ def __init__(
extra_plugins: Optional[list[str]] = None,
logo_text: Optional[str] = None,
logo_image_url: Optional[str] = None,
root_path: Optional[str] = None,
):
self.agent_loader = agent_loader
self.session_service = session_service
Expand All @@ -452,6 +453,7 @@ def __init__(
self.runners_to_clean: set[str] = set()
self.current_app_name_ref: SharedValue[str] = SharedValue(value="")
self.runner_dict = {}
self.root_path = root_path

async def get_runner_async(self, app_name: str) -> Runner:
"""Returns the cached runner for the given app."""
Expand Down Expand Up @@ -559,6 +561,7 @@ def _setup_runtime_config(self, web_assets_dir: str):
" overwritten.",
runtime_config_path,
)
runtime_config["backendUrl"] = self.root_path if self.root_path else ""

# Set custom logo config.
if self.logo_text or self.logo_image_url:
Expand Down Expand Up @@ -1562,6 +1565,9 @@ async def process_messages():
mimetypes.add_type("application/javascript", ".js", True)
mimetypes.add_type("text/javascript", ".js", True)

devRedirectUrl = "/dev-ui/"
if self.root_path:
devRedirectUrl = self.root_path + "/dev-ui/"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The current string concatenation for devRedirectUrl could result in a double slash (e.g., /proxy//dev-ui/) if self.root_path has a trailing slash. While many systems handle this, it's more robust to ensure a clean URL. Using rstrip('/') will prevent this issue.

Suggested change
devRedirectUrl = self.root_path + "/dev-ui/"
devRedirectUrl = self.root_path.rstrip("/") + "/dev-ui/"

@app.get("/dev-ui/config")
async def get_ui_config():
return {
Expand All @@ -1571,11 +1577,11 @@ async def get_ui_config():

@app.get("/")
async def redirect_root_to_dev_ui():
return RedirectResponse("/dev-ui/")
return RedirectResponse(devRedirectUrl)

@app.get("/dev-ui")
async def redirect_dev_ui_add_slash():
return RedirectResponse("/dev-ui/")
return RedirectResponse(devRedirectUrl)

app.mount(
"/dev-ui/",
Expand Down
7 changes: 7 additions & 0 deletions src/google/adk/cli/cli_tools_click.py
Original file line number Diff line number Diff line change
Expand Up @@ -1028,6 +1028,11 @@ def decorator(func):
),
multiple=True,
)
@click.option(
"--root_path",
type=str,
default = None,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

There's a minor style issue here. According to PEP 8, you should avoid extraneous whitespace around the = operator for keyword arguments.1

Suggested change
default = None,
default=None,

Style Guide References

Footnotes

  1. PEP 8 E251 recommends no space around the = sign for keyword arguments.

)
@functools.wraps(func)
@click.pass_context
def wrapper(ctx, *args, **kwargs):
Expand Down Expand Up @@ -1065,6 +1070,7 @@ def cli_web(
allow_origins: Optional[list[str]] = None,
host: str = "127.0.0.1",
port: int = 8000,
root_path: str = None,
trace_to_cloud: bool = False,
otel_to_cloud: bool = False,
reload: bool = True,
Expand Down Expand Up @@ -1128,6 +1134,7 @@ async def _lifespan(app: FastAPI):
a2a=a2a,
host=host,
port=port,
root_path=root_path,
reload_agents=reload_agents,
extra_plugins=extra_plugins,
logo_text=logo_text,
Expand Down
2 changes: 2 additions & 0 deletions src/google/adk/cli/fast_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ def get_fast_api_app(
a2a: bool = False,
host: str = "127.0.0.1",
port: int = 8000,
root_path = None,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The root_path parameter is missing a type hint. For better code clarity and maintainability, please add the appropriate type hint. Based on its usage, it should be Optional[str].

Suggested change
root_path = None,
root_path: Optional[str] = None,

trace_to_cloud: bool = False,
otel_to_cloud: bool = False,
reload_agents: bool = False,
Expand Down Expand Up @@ -144,6 +145,7 @@ def get_fast_api_app(
extra_plugins=extra_plugins,
logo_text=logo_text,
logo_image_url=logo_image_url,
root_path=root_path
)

# Callbacks & other optional args for when constructing the FastAPI instance
Expand Down
Loading