Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 349
Allow starting up web when workflow data directory is not present#680
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| --- | ||
| "@workflow/cli": patch | ||
| "@workflow/web": patch | ||
| "@workflow/web-shared": patch | ||
| --- | ||
| Allow starting up web when workflow data directory is not present and auto-detect workflow data directory in web UI after a workflow is run | ||
| - Web UI now automatically detects data directories on load and on refresh | ||
| - CLI passes searchDir to web UI for proper directory resolution | ||
| - Improved error handling: missing data directory is now a warning instead of an error |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| 'use server'; | ||
| import { existsSync } from 'node:fs'; | ||
| import fs from 'node:fs/promises'; | ||
| import path from 'node:path'; | ||
| import { hydrateResourceIO } from '@workflow/core/observability'; | ||
| @@ -821,3 +822,69 @@ export async function fetchWorkflowsManifest( | ||
| workflows: {}, | ||
| }); | ||
| } | ||
| /** | ||
| * Possible workflow data directory paths to check, in order of preference. | ||
| * These match the paths that world-local and the CLI check. | ||
| */ | ||
| const POSSIBLE_DATA_PATHS = [ | ||
| '.next/workflow-data', | ||
| '.workflow-data', | ||
| 'workflow-data', | ||
| ]; | ||
| /** | ||
| * Result of detecting a workflow data directory | ||
| */ | ||
| export interface DetectDataDirResult { | ||
| /** The found data directory path, or null if not found */ | ||
| dataDir: string | null; | ||
| /** List of paths that were checked */ | ||
| checkedPaths: string[]; | ||
| } | ||
| /** | ||
| * Detect if a workflow data directory exists. | ||
| * | ||
| * This is called by the web UI on refresh when no dataDir is configured, | ||
| * allowing the UI to automatically pick up data directories that were created | ||
| * after the initial startup. | ||
| * | ||
| * @param searchDir - Colon-separated list of directories to search (from URL param, set by CLI). | ||
| * Falls back to process.cwd() if not provided. | ||
| * @returns The detected data directory path, or null if not found | ||
| */ | ||
| export async function detectWorkflowDataDir( | ||
| searchDir?: string | ||
ContributorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is passed down from the client | ||
| ): Promise<ServerActionResult<DetectDataDirResult>> { | ||
| // Parse search directories (colon-separated, from URL param set by CLI) | ||
| const dirsToSearch = searchDir | ||
| ? searchDir.split(':').filter(Boolean) | ||
| : [process.cwd()]; | ||
| const checkedPaths: string[] = []; | ||
| for (const baseDir of dirsToSearch) { | ||
| for (const relativePath of POSSIBLE_DATA_PATHS) { | ||
| const fullPath = path.join(baseDir, relativePath); | ||
| checkedPaths.push(fullPath); | ||
| if (existsSync(fullPath)) { | ||
| // Verify it looks like a valid workflow data directory by checking for 'runs' subdirectory | ||
| const runsPath = path.join(fullPath, 'runs'); | ||
| if (existsSync(runsPath)) { | ||
| console.log( | ||
| `[detectWorkflowDataDir] Found valid data directory: ${fullPath}` | ||
| ); | ||
| return createResponse({ dataDir: fullPath, checkedPaths }); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| console.log( | ||
| '[detectWorkflowDataDir] No data directory found, checked:', | ||
| checkedPaths | ||
| ); | ||
| return createResponse({ dataDir: null, checkedPaths }); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,31 +1,70 @@ | ||
| 'use client'; | ||
| import { detectWorkflowDataDir } from '@workflow/web-shared/server'; | ||
| import { AlertCircle } from 'lucide-react'; | ||
| import { useRouter } from 'next/navigation'; | ||
| import { useRouter, useSearchParams } from 'next/navigation'; | ||
| import { useEffect } from 'react'; | ||
| import { ErrorBoundary } from '@/components/error-boundary'; | ||
| import { HooksTable } from '@/components/hooks-table'; | ||
| import { RunsTable } from '@/components/runs-table'; | ||
| import { Alert, AlertDescription, AlertTitle } from '@/components/ui/alert'; | ||
| import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs'; | ||
| import { WorkflowsList } from '@/components/workflows-list'; | ||
| import { buildUrlWithConfig, useQueryParamConfig } from '@/lib/config'; | ||
| import { | ||
| buildUrlWithConfig, | ||
| useQueryParamConfig, | ||
| useUpdateConfigQueryParams, | ||
| } from '@/lib/config'; | ||
| import { useWorkflowGraphManifest } from '@/lib/flow-graph/use-workflow-graph'; | ||
| import { | ||
| useHookIdState, | ||
| useSidebarState, | ||
| useTabState, | ||
| useWorkflowIdState, | ||
| } from '@/lib/url-state'; | ||
| import { useWorkflowGraphManifest } from '@/lib/flow-graph/use-workflow-graph'; | ||
| export default function Home() { | ||
| const router = useRouter(); | ||
| const searchParams = useSearchParams(); | ||
| const config = useQueryParamConfig(); | ||
| const updateConfig = useUpdateConfigQueryParams(); | ||
| const [sidebar] = useSidebarState(); | ||
| const [hookId] = useHookIdState(); | ||
| const [tab, setTab] = useTabState(); | ||
| const selectedHookId = sidebar === 'hook' && hookId ? hookId : undefined; | ||
| // Check if dataDir was explicitly set via URL params (not using default) | ||
| const dataDirFromUrl = searchParams.get('dataDir'); | ||
| const isLocalBackend = | ||
| !config.backend || | ||
| config.backend === 'local' || | ||
| config.backend === '@workflow/world-local'; | ||
| // On initial load, try to detect the data directory if not explicitly set | ||
| useEffect(() => { | ||
| if (!isLocalBackend || dataDirFromUrl) { | ||
ContributorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this won't run if dataDir is already set or if its not a local backend | ||
| return; | ||
| } | ||
| const detectDataDir = async () => { | ||
| try { | ||
| // Pass searchDir from URL params (set by CLI) to search in the right directories | ||
| const result = await detectWorkflowDataDir(config.searchDir); | ||
| if (result.success && result.data.dataDir) { | ||
| // Found a data directory! Update the config | ||
| updateConfig({ ...config, dataDir: result.data.dataDir }); | ||
| } | ||
| } catch (e) { | ||
| // Ignore detection errors on initial load | ||
| console.debug('Initial data dir detection failed:', e); | ||
| } | ||
| }; | ||
| detectDataDir(); | ||
| // eslint-disable-next-line react-hooks/exhaustive-deps | ||
| }, [isLocalBackend, dataDirFromUrl]); | ||
| // TODO(Karthik): Uncomment after https://github.com/vercel/workflow/pull/455 is merged | ||
| // Fetch workflow graph manifest | ||
| // const { | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is needed so the server action can constrain the search for data dir within the project root