mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-28 06:23:07 +00:00
fix(chat): recognize the development preview workspace (#48123)
This commit is contained in:
parent
6292f217a3
commit
f6b2086502
2 changed files with 21 additions and 4 deletions
|
|
@ -56,6 +56,7 @@ describe("ViewSwitcher", () => {
|
|||
setServerRootPath("/");
|
||||
vi.clearAllMocks();
|
||||
vi.unstubAllGlobals();
|
||||
vi.unstubAllEnvs();
|
||||
});
|
||||
|
||||
it("should render the workspace selector and keep disabled Chat unavailable", async () => {
|
||||
|
|
@ -130,6 +131,20 @@ describe("ViewSwitcher", () => {
|
|||
expect(localStorage.getItem("litellm_plugin_mode")).toBe("metrics");
|
||||
});
|
||||
|
||||
it.each(["/chat", "/ui/chat", "/ui/chat/models"])(
|
||||
"should keep Chat identity and gateway navigation at the development route %s",
|
||||
async (pathname) => {
|
||||
vi.stubEnv("NODE_ENV", "development");
|
||||
state.pathname = pathname;
|
||||
const user = userEvent.setup();
|
||||
renderSwitcher();
|
||||
|
||||
await user.click(screen.getByRole("button", { name: "Switch workspace, current: Chat" }));
|
||||
await user.click(await screen.findByRole("menuitem", { name: "AI Gateway" }));
|
||||
expect(assignSpy).toHaveBeenCalledWith("/");
|
||||
},
|
||||
);
|
||||
|
||||
it.each(["/ui/moyai", "/ui/moyai/sessions/one"])(
|
||||
"should show Moyai's icon at %s and let users switch to Chat",
|
||||
async (pathname) => {
|
||||
|
|
|
|||
|
|
@ -20,8 +20,10 @@ const CHAT = "chat";
|
|||
const MOYAI = "moyai";
|
||||
type WorkspaceIconName = typeof GATEWAY | typeof CHAT | typeof MOYAI;
|
||||
|
||||
function isRoute(pathname: string, href: string): boolean {
|
||||
return pathname === href || pathname.startsWith(`${href}/`);
|
||||
function isWorkspaceRoute(pathname: string, workspace: string): boolean {
|
||||
const routes = [uiHref(workspace)];
|
||||
if (process.env.NODE_ENV === "development") routes.push(`/ui/${workspace}`);
|
||||
return routes.some((route) => pathname === route || pathname.startsWith(`${route}/`));
|
||||
}
|
||||
|
||||
function activeWorkspaceFor(
|
||||
|
|
@ -85,8 +87,8 @@ export default function ViewSwitcher({ className, contentClassName }: ViewSwitch
|
|||
const moyaiUrl = (uiSettings?.values?.moyai_url as string | undefined) ?? null;
|
||||
|
||||
const normalizedPathname = (pathname ?? "").replace(/\/+$/, "");
|
||||
const isChatRoute = isRoute(normalizedPathname, uiHref(CHAT));
|
||||
const isMoyaiRoute = isRoute(normalizedPathname, uiHref(MOYAI));
|
||||
const isChatRoute = isWorkspaceRoute(normalizedPathname, CHAT);
|
||||
const isMoyaiRoute = isWorkspaceRoute(normalizedPathname, MOYAI);
|
||||
const isStandaloneRoute = isChatRoute || isMoyaiRoute;
|
||||
|
||||
const { label: activeLabel, icon: activeIcon } = activeWorkspaceFor(
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue