import type { DaemonClient } from "@getpaseo/client/internal/daemon-client"; import { normalizeWorkspaceDescriptor, type WorkspaceDescriptor } from "@/stores/session-store"; import { buildWorkspaceTabPersistenceKey } from "@/stores/workspace-tabs-store"; export interface OpenProjectDirectlyInput { serverId: string; projectPath: string; isConnected: boolean; client: Pick | null; mergeWorkspaces: (serverId: string, workspaces: Iterable) => void; setHasHydratedWorkspaces: (serverId: string, hydrated: boolean) => void; openDraftTab: (workspaceKey: string) => string | null; navigateToWorkspace: (serverId: string, workspaceId: string) => void; } export async function openProjectDirectly(input: OpenProjectDirectlyInput): Promise { const normalizedServerId = input.serverId.trim(); const trimmedPath = input.projectPath.trim(); if (!normalizedServerId || !trimmedPath || !input.client || !input.isConnected) { return false; } const payload = await input.client.openProject(trimmedPath); if (payload.error || !payload.workspace) { return false; } const workspace = normalizeWorkspaceDescriptor(payload.workspace); input.mergeWorkspaces(normalizedServerId, [workspace]); input.setHasHydratedWorkspaces(normalizedServerId, true); const workspaceKey = buildWorkspaceTabPersistenceKey({ serverId: normalizedServerId, workspaceId: workspace.id, }); if (!workspaceKey) { return false; } input.openDraftTab(workspaceKey); input.navigateToWorkspace(normalizedServerId, workspace.id); return true; }