refactor: centralize host route builders and add dedicated new-agent route
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
buildHostNewAgentRoute,
|
||||
buildHostRootRoute,
|
||||
buildHostWorkspaceAgentTabRoute,
|
||||
buildHostWorkspaceFileTabRoute,
|
||||
buildHostWorkspaceRoute,
|
||||
@@ -70,6 +72,14 @@ describe("workspace route parsing", () => {
|
||||
expect(buildHostWorkspaceRoute("local", "/tmp/repo")).toBe("/h/local/workspace/L3RtcC9yZXBv");
|
||||
});
|
||||
|
||||
it("builds host root routes", () => {
|
||||
expect(buildHostRootRoute("local")).toBe("/h/local");
|
||||
});
|
||||
|
||||
it("builds host new-agent routes", () => {
|
||||
expect(buildHostNewAgentRoute("local")).toBe("/h/local/new-agent");
|
||||
});
|
||||
|
||||
it("builds workspace agent tab routes", () => {
|
||||
expect(buildHostWorkspaceAgentTabRoute("local", "/tmp/repo", "agent-1")).toBe(
|
||||
"/h/local/workspace/L3RtcC9yZXBv/tab/agent_agent-1"
|
||||
|
||||
@@ -359,25 +359,41 @@ export function buildHostAgentDetailRoute(
|
||||
if (!normalizedServerId || !normalizedAgentId) {
|
||||
return "/";
|
||||
}
|
||||
return `/h/${encodeSegment(normalizedServerId)}/agent/${encodeSegment(
|
||||
return `${buildHostRootRoute(normalizedServerId)}/agent/${encodeSegment(
|
||||
normalizedAgentId
|
||||
)}`;
|
||||
}
|
||||
|
||||
export function buildHostAgentsRoute(serverId: string): string {
|
||||
export function buildHostRootRoute(serverId: string): string {
|
||||
const normalized = trimNonEmpty(serverId);
|
||||
if (!normalized) {
|
||||
return "/";
|
||||
}
|
||||
return `/h/${encodeSegment(normalized)}/agents`;
|
||||
return `/h/${encodeSegment(normalized)}`;
|
||||
}
|
||||
|
||||
export function buildHostAgentsRoute(serverId: string): string {
|
||||
const base = buildHostRootRoute(serverId);
|
||||
if (base === "/") {
|
||||
return "/";
|
||||
}
|
||||
return `${base}/agents`;
|
||||
}
|
||||
|
||||
export function buildHostNewAgentRoute(serverId: string): string {
|
||||
const base = buildHostRootRoute(serverId);
|
||||
if (base === "/") {
|
||||
return "/";
|
||||
}
|
||||
return `${base}/new-agent`;
|
||||
}
|
||||
|
||||
export function buildHostSettingsRoute(serverId: string): string {
|
||||
const normalized = trimNonEmpty(serverId);
|
||||
if (!normalized) {
|
||||
const base = buildHostRootRoute(serverId);
|
||||
if (base === "/") {
|
||||
return "/";
|
||||
}
|
||||
return `/h/${encodeSegment(normalized)}/settings`;
|
||||
return `${base}/settings`;
|
||||
}
|
||||
|
||||
export function mapPathnameToServer(
|
||||
@@ -390,13 +406,16 @@ export function mapPathnameToServer(
|
||||
}
|
||||
|
||||
const suffix = pathname.replace(/^\/h\/[^/]+\/?/, "");
|
||||
const base = `/h/${encodeSegment(normalized)}`;
|
||||
const base = buildHostRootRoute(normalized);
|
||||
if (suffix.startsWith("settings")) {
|
||||
return `${base}/settings`;
|
||||
}
|
||||
if (suffix.startsWith("agents")) {
|
||||
return `${base}/agents`;
|
||||
}
|
||||
if (suffix.startsWith("new-agent")) {
|
||||
return `${base}/new-agent`;
|
||||
}
|
||||
if (suffix.startsWith("workspace/")) {
|
||||
return `${base}/${suffix}`;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import {
|
||||
buildHostAgentDetailRoute,
|
||||
buildHostRootRoute,
|
||||
buildHostWorkspaceAgentTabRoute,
|
||||
} from "@/utils/host-routes";
|
||||
|
||||
@@ -40,7 +41,7 @@ export function buildNotificationRoute(data: NotificationData): string {
|
||||
return buildHostAgentDetailRoute(serverId, agentId);
|
||||
}
|
||||
if (serverId) {
|
||||
return `/h/${encodeURIComponent(serverId)}`;
|
||||
return buildHostRootRoute(serverId);
|
||||
}
|
||||
return "/";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user