refactor: remove draft agent routes and consolidate terminal output into session model
This commit is contained in:
@@ -8,39 +8,11 @@ import {
|
||||
decodeWorkspaceIdFromPathSegment,
|
||||
encodeFilePathForPathSegment,
|
||||
encodeWorkspaceIdForPathSegment,
|
||||
parseHostAgentDraftRouteFromPathname,
|
||||
parseHostAgentRouteFromPathname,
|
||||
parseHostDraftRouteFromPathname,
|
||||
parseHostWorkspaceTabRouteFromPathname,
|
||||
parseHostWorkspaceRouteFromPathname,
|
||||
} from "./host-routes";
|
||||
|
||||
describe("parseHostAgentDraftRouteFromPathname", () => {
|
||||
it("parses draft route server id", () => {
|
||||
expect(parseHostAgentDraftRouteFromPathname("/h/local/new")).toEqual({
|
||||
serverId: "local",
|
||||
});
|
||||
});
|
||||
|
||||
it("parses encoded server id", () => {
|
||||
expect(parseHostAgentDraftRouteFromPathname("/h/team%20host/new")).toEqual({
|
||||
serverId: "team host",
|
||||
});
|
||||
});
|
||||
|
||||
it("does not match agent detail routes", () => {
|
||||
expect(parseHostAgentDraftRouteFromPathname("/h/local/agent/abc123")).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe("parseHostDraftRouteFromPathname", () => {
|
||||
it("parses /new draft routes", () => {
|
||||
expect(parseHostDraftRouteFromPathname("/h/local/new")).toEqual({
|
||||
serverId: "local",
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("parseHostAgentRouteFromPathname", () => {
|
||||
it("continues parsing detail routes", () => {
|
||||
expect(parseHostAgentRouteFromPathname("/h/local/agent/abc123")).toEqual({
|
||||
|
||||
@@ -188,54 +188,6 @@ export function parseHostAgentRouteFromPathname(
|
||||
return { serverId, agentId };
|
||||
}
|
||||
|
||||
export function parseHostAgentDraftRouteFromPathname(
|
||||
pathname: string
|
||||
): { serverId: string } | null {
|
||||
const match = pathname.match(/^\/h\/([^/]+)\/(?:agent|new)\/?$/);
|
||||
if (!match) {
|
||||
return null;
|
||||
}
|
||||
const encodedServerId = match[1];
|
||||
if (!encodedServerId) {
|
||||
return null;
|
||||
}
|
||||
const serverId = trimNonEmpty(decodeSegment(encodedServerId));
|
||||
if (!serverId) {
|
||||
return null;
|
||||
}
|
||||
return { serverId };
|
||||
}
|
||||
|
||||
export function buildHostAgentDraftRoute(serverId: string): string {
|
||||
return buildHostDraftRoute(serverId);
|
||||
}
|
||||
|
||||
export function parseHostDraftRouteFromPathname(
|
||||
pathname: string
|
||||
): { serverId: string } | null {
|
||||
const match = pathname.match(/^\/h\/([^/]+)\/new\/?$/);
|
||||
if (!match) {
|
||||
return null;
|
||||
}
|
||||
const encodedServerId = match[1];
|
||||
if (!encodedServerId) {
|
||||
return null;
|
||||
}
|
||||
const serverId = trimNonEmpty(decodeSegment(encodedServerId));
|
||||
if (!serverId) {
|
||||
return null;
|
||||
}
|
||||
return { serverId };
|
||||
}
|
||||
|
||||
export function buildHostDraftRoute(serverId: string): string {
|
||||
const normalized = trimNonEmpty(serverId);
|
||||
if (!normalized) {
|
||||
return "/";
|
||||
}
|
||||
return `/h/${encodeSegment(normalized)}/new`;
|
||||
}
|
||||
|
||||
export function parseHostWorkspaceRouteFromPathname(
|
||||
pathname: string
|
||||
): { serverId: string; workspaceId: string } | null {
|
||||
@@ -445,9 +397,6 @@ export function mapPathnameToServer(
|
||||
if (suffix.startsWith("agents")) {
|
||||
return `${base}/agents`;
|
||||
}
|
||||
if (suffix.startsWith("new")) {
|
||||
return `${base}/new`;
|
||||
}
|
||||
if (suffix.startsWith("workspace/")) {
|
||||
return `${base}/${suffix}`;
|
||||
}
|
||||
|
||||
@@ -9,14 +9,16 @@ import {
|
||||
} from "./new-agent-routing";
|
||||
|
||||
describe("buildNewAgentRoute", () => {
|
||||
it("falls back to host-scoped draft route when no working directory is provided", () => {
|
||||
expect(buildNewAgentRoute("srv-1", undefined)).toBe("/h/srv-1/new");
|
||||
expect(buildNewAgentRoute("srv-1", " ")).toBe("/h/srv-1/new");
|
||||
it("falls back to server workspace route with dot workspace when no working directory is provided", () => {
|
||||
expect(buildNewAgentRoute("srv-1", undefined)).toBe(
|
||||
"/h/srv-1/workspace/Lg"
|
||||
);
|
||||
expect(buildNewAgentRoute("srv-1", " ")).toBe("/h/srv-1/workspace/Lg");
|
||||
});
|
||||
|
||||
it("encodes the working directory query parameter", () => {
|
||||
it("encodes the working directory as a workspace path segment", () => {
|
||||
expect(buildNewAgentRoute("srv-1", "/Users/me/dev/paseo")).toBe(
|
||||
"/h/srv-1/new?workingDir=%2FUsers%2Fme%2Fdev%2Fpaseo"
|
||||
"/h/srv-1/workspace/L1VzZXJzL21lL2Rldi9wYXNlbw"
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { CheckoutStatusPayload } from "@/hooks/use-checkout-status-query";
|
||||
import {
|
||||
buildHostAgentDraftRoute,
|
||||
buildHostWorkspaceRoute,
|
||||
parseHostAgentRouteFromPathname,
|
||||
parseHostWorkspaceTabRouteFromPathname,
|
||||
} from "@/utils/host-routes";
|
||||
@@ -74,13 +74,6 @@ export function buildNewAgentRoute(
|
||||
serverId: string,
|
||||
workingDir?: string | null
|
||||
): string {
|
||||
const baseRoute = buildHostAgentDraftRoute(serverId);
|
||||
if (baseRoute === "/") {
|
||||
return baseRoute;
|
||||
}
|
||||
const trimmedWorkingDir = workingDir?.trim();
|
||||
if (!trimmedWorkingDir) {
|
||||
return baseRoute;
|
||||
}
|
||||
return `${baseRoute}?workingDir=${encodeURIComponent(trimmedWorkingDir)}`;
|
||||
return buildHostWorkspaceRoute(serverId, trimmedWorkingDir || ".");
|
||||
}
|
||||
|
||||
@@ -50,8 +50,8 @@ describe("buildNotificationRoute", () => {
|
||||
);
|
||||
});
|
||||
|
||||
it("falls back to host-scoped draft route when only serverId is present", () => {
|
||||
expect(buildNotificationRoute({ serverId: "srv-only" })).toBe("/h/srv-only/new");
|
||||
it("falls back to host root when only serverId is present", () => {
|
||||
expect(buildNotificationRoute({ serverId: "srv-only" })).toBe("/h/srv-only");
|
||||
});
|
||||
|
||||
it("falls back to root when no server id is present", () => {
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import {
|
||||
buildHostDraftRoute,
|
||||
buildHostAgentDetailRoute,
|
||||
buildHostWorkspaceAgentTabRoute,
|
||||
} from "@/utils/host-routes";
|
||||
@@ -41,7 +40,7 @@ export function buildNotificationRoute(data: NotificationData): string {
|
||||
return buildHostAgentDetailRoute(serverId, agentId);
|
||||
}
|
||||
if (serverId) {
|
||||
return buildHostDraftRoute(serverId);
|
||||
return `/h/${encodeURIComponent(serverId)}`;
|
||||
}
|
||||
return "/";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user