AkurAI Build
Menu

popagent

public

Latest change da13a7bebe63bf4b2693180d2d4850aabeaa0807 - Add autonomous evolution and self-healing by AkurAI Build

export const SETTINGS_SECTIONS = ["appearance", "agents", "channels", "browser", "secrets", "memory", "runtime", "autonomy", "tasks", "observability"] as const;

export type SettingsSection = (typeof SETTINGS_SECTIONS)[number];

export type AppRoute =
  | { page: "overview" }
  | { page: "workspace"; workspaceId: string }
  | { page: "documentation"; workspaceId: string; path?: string }
  | { page: "chat"; sessionId: string }
  | { page: "channel"; channelId: string }
  | { page: "settings"; section: SettingsSection };

function decoded(segment: string): string | undefined {
  try {
    return decodeURIComponent(segment);
  } catch {
    return undefined;
  }
}

export function parseAppRoute(pathname: string): AppRoute {
  const parts = pathname.split("/").filter(Boolean);
  if (!parts.length) return { page: "overview" };

  if (parts[0] === "settings" && parts.length <= 2) {
    const section = parts[1] ?? "agents";
    if (SETTINGS_SECTIONS.includes(section as SettingsSection)) {
      return { page: "settings", section: section as SettingsSection };
    }
  }

  if (parts[0] === "workspaces" && parts[2] === "docs" && parts.length >= 3) {
    const workspaceId = decoded(parts[1]!);
    const pathParts = parts.slice(3).map(decoded);
    if (workspaceId && pathParts.every(Boolean)) {
      const path = pathParts.length ? pathParts.join("/") : undefined;
      return { page: "documentation", workspaceId, ...(path ? { path } : {}) };
    }
  }

  if (parts.length === 2 && parts[0] === "workspaces") {
    const workspaceId = decoded(parts[1]!);
    if (workspaceId) return { page: "workspace", workspaceId };
  }

  if (parts.length === 2 && parts[0] === "chats") {
    const sessionId = decoded(parts[1]!);
    if (sessionId) return { page: "chat", sessionId };
  }

  if (parts.length === 2 && parts[0] === "channels") {
    const channelId = decoded(parts[1]!);
    if (channelId) return { page: "channel", channelId };
  }

  return { page: "overview" };
}

export function appRoutePath(route: AppRoute): string {
  switch (route.page) {
    case "overview": return "/";
    case "workspace": return `/workspaces/${encodeURIComponent(route.workspaceId)}`;
    case "documentation": return `/workspaces/${encodeURIComponent(route.workspaceId)}/docs${route.path ? `/${route.path.split("/").map(encodeURIComponent).join("/")}` : ""}`;
    case "chat": return `/chats/${encodeURIComponent(route.sessionId)}`;
    case "channel": return `/channels/${encodeURIComponent(route.channelId)}`;
    case "settings": return `/settings/${route.section}`;
  }
}