app: hard-cut workspace routing to workspace-only URLs

This commit is contained in:
Mohamed Boudra
2026-03-04 22:35:30 +07:00
parent ee8e2ab691
commit 73fce89edd
22 changed files with 300 additions and 608 deletions
@@ -10,7 +10,7 @@ describe("keyboard-shortcut-routing", () => {
it("returns selected agent key when provided", () => {
const key = resolveSelectedOrRouteAgentKey({
selectedAgentId: "server-1:agent-1",
pathname: "/h/server-1/workspace/workspace-1/tab/draft_123",
pathname: "/h/server-1/workspace/workspace-1?open=draft%3Adraft_123",
});
expect(key).toBe("server-1:agent-1");
@@ -18,7 +18,7 @@ describe("keyboard-shortcut-routing", () => {
it("maps workspace draft tabs to the draft tab id key", () => {
const key = resolveSelectedOrRouteAgentKey({
pathname: "/h/server-1/workspace/workspace-1/tab/draft_123",
pathname: "/h/server-1/workspace/workspace-1?open=draft%3Adraft_123",
});
expect(key).toBe("server-1:draft_123");
@@ -31,7 +31,7 @@ describe("keyboard-shortcut-routing", () => {
it("allows the shortcut on selected-agent routes", () => {
const canToggle = canToggleFileExplorerShortcut({
selectedAgentId: "server-1:agent-1",
pathname: "/h/server-1/workspace/workspace-1/tab/agent_agent-1",
pathname: "/h/server-1/workspace/workspace-1?open=agent%3Aagent-1",
toggleFileExplorer,
});
@@ -47,18 +47,18 @@ describe("keyboard-shortcut-routing", () => {
expect(canToggle).toBe(true);
});
it("allows the shortcut on workspace terminal routes", () => {
it("allows the shortcut on workspace routes with intent query", () => {
const canToggle = canToggleFileExplorerShortcut({
pathname: "/h/server-1/workspace/workspace-1/tab/terminal_terminal-1",
pathname: "/h/server-1/workspace/workspace-1?open=terminal%3Aterminal-1",
toggleFileExplorer,
});
expect(canToggle).toBe(true);
});
it("allows the shortcut on workspace draft-tab routes", () => {
it("allows the shortcut on workspace draft-intent routes", () => {
const canToggle = canToggleFileExplorerShortcut({
pathname: "/h/server-1/workspace/workspace-1/tab/draft_123",
pathname: "/h/server-1/workspace/workspace-1?open=draft%3Adraft_123",
toggleFileExplorer,
});
@@ -67,7 +67,7 @@ describe("keyboard-shortcut-routing", () => {
it("blocks the shortcut when no toggle handler exists", () => {
const canToggle = canToggleFileExplorerShortcut({
pathname: "/h/server-1/workspace/workspace-1/tab/draft_123",
pathname: "/h/server-1/workspace/workspace-1?open=draft%3Adraft_123",
});
expect(canToggle).toBe(false);
@@ -1,7 +1,7 @@
import {
parseHostAgentRouteFromPathname,
parseHostWorkspaceOpenIntentFromPathname,
parseHostWorkspaceRouteFromPathname,
parseHostWorkspaceTabRouteFromPathname,
} from "@/utils/host-routes";
export function resolveSelectedOrRouteAgentKey(input: {
@@ -12,15 +12,16 @@ export function resolveSelectedOrRouteAgentKey(input: {
return input.selectedAgentId;
}
const workspaceTabRoute = parseHostWorkspaceTabRouteFromPathname(input.pathname);
if (workspaceTabRoute?.tabId) {
const tabId = workspaceTabRoute.tabId;
if (tabId.startsWith("agent_")) {
const agentId = tabId.slice("agent_".length).trim();
return agentId ? `${workspaceTabRoute.serverId}:${agentId}` : null;
const workspaceRoute = parseHostWorkspaceRouteFromPathname(input.pathname);
const workspaceOpenIntent = parseHostWorkspaceOpenIntentFromPathname(input.pathname);
if (workspaceRoute && workspaceOpenIntent) {
if (workspaceOpenIntent.kind === "agent") {
const agentId = workspaceOpenIntent.agentId.trim();
return agentId ? `${workspaceRoute.serverId}:${agentId}` : null;
}
if (tabId.startsWith("draft_")) {
return `${workspaceTabRoute.serverId}:${tabId}`;
if (workspaceOpenIntent.kind === "draft") {
const draftId = workspaceOpenIntent.draftId.trim();
return draftId ? `${workspaceRoute.serverId}:${draftId}` : null;
}
}