27 lines
749 B
TypeScript
27 lines
749 B
TypeScript
export type AIMode = "chat" | "agents";
|
|
|
|
export function changeAIMode(
|
|
location: { pathname: string; search: string; hash: string },
|
|
mode: AIMode,
|
|
push: (href: string) => void,
|
|
): void {
|
|
if (parseAIMode(new URLSearchParams(location.search).get("tab")) === mode)
|
|
return;
|
|
push(aiModeHref(location.pathname, location.search, mode, location.hash));
|
|
}
|
|
|
|
export function parseAIMode(value: string | null): AIMode {
|
|
return value === "agents" ? "agents" : "chat";
|
|
}
|
|
|
|
export function aiModeHref(
|
|
pathname: string,
|
|
search: string,
|
|
mode: AIMode,
|
|
hash = "",
|
|
): string {
|
|
const params = new URLSearchParams(search);
|
|
params.set("tab", mode);
|
|
const query = params.toString();
|
|
return `${pathname}${query ? `?${query}` : ""}${hash}`;
|
|
}
|