chore: commit pending gateway changes
This commit is contained in:
+24
-1
@@ -1,9 +1,10 @@
|
||||
import type { AdminSection, ApiDocSection, PageKey, WorkspaceSection } from './types';
|
||||
import type { AdminSection, ApiDocSection, PageKey, PlaygroundMode, WorkspaceSection } from './types';
|
||||
|
||||
export interface AppRouteState {
|
||||
activePage: PageKey;
|
||||
adminSection: AdminSection;
|
||||
apiDocSection: ApiDocSection;
|
||||
playgroundMode: PlaygroundMode;
|
||||
workspaceSection: WorkspaceSection;
|
||||
}
|
||||
|
||||
@@ -11,6 +12,7 @@ export const defaultRouteState: AppRouteState = {
|
||||
activePage: 'home',
|
||||
adminSection: 'overview',
|
||||
apiDocSection: 'chat',
|
||||
playgroundMode: 'chat',
|
||||
workspaceSection: 'overview',
|
||||
};
|
||||
|
||||
@@ -31,6 +33,7 @@ const adminPaths: Record<AdminSection, string> = {
|
||||
users: '/admin/users',
|
||||
userGroups: '/admin/user-groups',
|
||||
runtime: '/admin/runtime',
|
||||
accessRules: '/admin/access-rules',
|
||||
};
|
||||
|
||||
const docsPaths: Record<ApiDocSection, string> = {
|
||||
@@ -41,13 +44,23 @@ const docsPaths: Record<ApiDocSection, string> = {
|
||||
files: '/docs/files',
|
||||
};
|
||||
|
||||
const playgroundPaths: Record<PlaygroundMode, string> = {
|
||||
chat: '/playground/chat',
|
||||
image: '/playground/image',
|
||||
video: '/playground/video',
|
||||
};
|
||||
|
||||
const workspaceSections = reverseMap(workspacePaths);
|
||||
const adminSections = reverseMap(adminPaths);
|
||||
const docsSections = reverseMap(docsPaths);
|
||||
const playgroundSections = reverseMap(playgroundPaths);
|
||||
|
||||
export function parseAppRoute(pathname = window.location.pathname): AppRouteState {
|
||||
const path = normalizePath(pathname);
|
||||
if (path === '/') return { ...defaultRouteState };
|
||||
if (path.startsWith('/playground')) {
|
||||
return { ...defaultRouteState, activePage: 'playground', playgroundMode: parsePlaygroundMode(path) };
|
||||
}
|
||||
if (path === '/models') return { ...defaultRouteState, activePage: 'models' };
|
||||
if (path.startsWith('/workspace')) {
|
||||
return { ...defaultRouteState, activePage: 'workspace', workspaceSection: parseWorkspaceSection(path) };
|
||||
@@ -62,6 +75,7 @@ export function parseAppRoute(pathname = window.location.pathname): AppRouteStat
|
||||
}
|
||||
|
||||
export function pathForPage(page: PageKey, route: AppRouteState): string {
|
||||
if (page === 'playground') return pathForPlaygroundMode(route.playgroundMode);
|
||||
if (page === 'models') return '/models';
|
||||
if (page === 'workspace') return pathForWorkspaceSection(route.workspaceSection);
|
||||
if (page === 'admin') return pathForAdminSection(route.adminSection);
|
||||
@@ -81,6 +95,10 @@ export function pathForApiDocSection(section: ApiDocSection) {
|
||||
return docsPaths[section] ?? docsPaths.chat;
|
||||
}
|
||||
|
||||
export function pathForPlaygroundMode(mode: PlaygroundMode) {
|
||||
return playgroundPaths[mode] ?? playgroundPaths.chat;
|
||||
}
|
||||
|
||||
function parseWorkspaceSection(path: string): WorkspaceSection {
|
||||
return workspaceSections[path] ?? (path === '/workspace' ? 'overview' : 'overview');
|
||||
}
|
||||
@@ -100,6 +118,11 @@ function parseDocSection(path: string): ApiDocSection {
|
||||
return docsSections[path] ?? 'chat';
|
||||
}
|
||||
|
||||
function parsePlaygroundMode(path: string): PlaygroundMode {
|
||||
if (path === '/playground') return 'chat';
|
||||
return playgroundSections[path] ?? 'chat';
|
||||
}
|
||||
|
||||
function normalizePath(pathname: string) {
|
||||
const path = pathname.replace(/\/+$/, '');
|
||||
return path || '/';
|
||||
|
||||
Reference in New Issue
Block a user