-
Notifications
You must be signed in to change notification settings - Fork 148
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
Open
karthikscale3
wants to merge
1
commit into
vercel:main
Choose a base branch
from
karthikscale3:karthik/web-nodata-fallback
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+206
−14
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
|
Contributor
Author
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 }); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) { | ||
|
Contributor
Author
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 { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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