Skip to content

armgit / kaneo

Public Imported from GitHub
0

⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.

873 B
Raw Blame
import { normalizeBaseUrl } from "@kaneo/mcp/normalize-base-url";
import { type ConfigFile, withProfile } from "../../config/format.js";

export type RememberedWorkspace =
  | { readonly kind: "saved"; readonly config: ConfigFile }
  | { readonly kind: "other-server"; readonly profileApiUrl: string };

export function rememberWorkspace(
  config: ConfigFile,
  profileName: string,
  apiUrl: string,
  workspaceId: string,
): RememberedWorkspace {
  const stored = config.profiles[profileName];
  if (stored && normalizeBaseUrl(stored.apiUrl) !== normalizeBaseUrl(apiUrl)) {
    return { kind: "other-server", profileApiUrl: stored.apiUrl };
  }
  const updated = withProfile(config, profileName, (profile) => ({
    ...(profile ?? { apiUrl }),
    workspaceId,
  }));
  return {
    kind: "saved",
    config: { ...updated, activeProfile: config.activeProfile },
  };
}