Skip to content

Automate browser based workflows with AI

feat: add Workflow Scripts Page foundation (#5110)

pedrohsdb742760789613
diff --git a/skyvern-frontend/src/router.tsx b/skyvern-frontend/src/router.tsx
index 8891f5ede..b593d7e3a 100644
--- a/skyvern-frontend/src/router.tsx
+++ b/skyvern-frontend/src/router.tsx
@@ -17,6 +17,7 @@ import { TaskRecording } from "./routes/tasks/detail/TaskRecording";
import { TasksPage } from "./routes/tasks/list/TasksPage";
import { Debugger } from "@/routes/workflows/debugger/Debugger";
import { WorkflowPage } from "./routes/workflows/WorkflowPage";
+import { WorkflowScriptsPage } from "./routes/workflows/WorkflowScriptsPage";
import { WorkflowRun } from "./routes/workflows/WorkflowRun";
import { WorkflowRunParameters } from "./routes/workflows/WorkflowRunParameters";
import { Workflows } from "./routes/workflows/Workflows";
@@ -166,6 +167,10 @@ const router = createBrowserRouter([
path: "runs",
element: <WorkflowPage />,
},
+ {
+ path: "scripts",
+ element: <WorkflowScriptsPage />,
+ },
{
path: ":workflowRunId",
element: <WorkflowRun />,
diff --git a/skyvern-frontend/src/routes/workflows/WorkflowPage.tsx b/skyvern-frontend/src/routes/workflows/WorkflowPage.tsx
index 335a7e80b..4d28d8bda 100644
--- a/skyvern-frontend/src/routes/workflows/WorkflowPage.tsx
+++ b/skyvern-frontend/src/routes/workflows/WorkflowPage.tsx
@@ -138,6 +138,9 @@ function WorkflowPage() {
onSuccessfullyDeleted={() => navigate("/workflows")}
/>
)}
+ {/* Scripts button intentionally hidden — page is reachable via
+ /workflows/:wpid/scripts but not linked from the UI until the
+ design is finalized and ready for user-facing release. */}
<Button asChild variant="secondary">
<Link to={`/workflows/${workflowPermanentId}/build`}>
<Pencil2Icon className="mr-2 size-4" />
diff --git a/skyvern-frontend/src/routes/workflows/WorkflowScriptsPage.tsx b/skyvern-frontend/src/routes/workflows/WorkflowScriptsPage.tsx
new file mode 100644
index 000000000..c82d1337f
--- /dev/null
+++ b/skyvern-frontend/src/routes/workflows/WorkflowScriptsPage.tsx
@@ -0,0 +1,186 @@
+import { Badge } from "@/components/ui/badge";
+import { Button } from "@/components/ui/button";
+import { Skeleton } from "@/components/ui/skeleton";
+import {
+ Table,
+ TableBody,
+ TableCell,
+ TableHead,
+ TableHeader,
+ TableRow,
+} from "@/components/ui/table";
+import { basicLocalTimeFormat, basicTimeFormat } from "@/util/timeFormat";
+import { FileTextIcon, Pencil2Icon, PlayIcon } from "@radix-ui/react-icons";
+import { Link, useNavigate, useParams } from "react-router-dom";
+import { useWorkflowQuery } from "./hooks/useWorkflowQuery";
+import { useWorkflowScriptsQuery } from "./hooks/useWorkflowScriptsQuery";
+import { WorkflowActions } from "./WorkflowActions";
+import type { WorkflowScriptSummary } from "./types/scriptTypes";
+
+function ScriptsTableRows({
+ isLoading,
+ isError,
+ scripts,
+}: {
+ isLoading: boolean;
+ isError: boolean;
+ scripts: WorkflowScriptSummary[];
+}) {
+ if (isLoading) {
+ return (
+ <TableRow>
+ <TableCell colSpan={5}>
+ <div className="space-y-2 py-2">
+ <Skeleton className="h-6 w-full" />
+ <Skeleton className="h-6 w-full" />
+ <Skeleton className="h-6 w-full" />
+ </div>
+ </TableCell>
+ </TableRow>
+ );
+ }
+
+ if (isError) {
+ return (
+ <TableRow>
+ <TableCell colSpan={5}>
+ <div className="flex flex-col items-center gap-2 py-12 text-center">
+ <p className="text-sm text-red-500">
+ Failed to load scripts. Please try again.
+ </p>
+ </div>
+ </TableCell>
+ </TableRow>
+ );
+ }
+
+ if (scripts.length === 0) {
+ return (
+ <TableRow>
+ <TableCell colSpan={5}>
+ <div className="flex flex-col items-center gap-2 py-12 text-center">
+ <FileTextIcon className="size-8 text-slate-400" />
+ <p className="text-sm text-slate-500">
+ No scripts yet. Scripts are created automatically when this
+ workflow runs with Code mode enabled.
+ </p>
+ </div>
+ </TableCell>
+ </TableRow>
+ );
+ }
+
+ return scripts.map((script) => (
+ // TODO: link to script detail view in Phase 2
+ <TableRow key={script.script_id}>
+ <TableCell className="font-mono text-sm">
+ {script.cache_key_value || "(default)"}
+ </TableCell>
+ <TableCell>{script.version_count}</TableCell>
+ <TableCell>v{script.latest_version}</TableCell>
+ <TableCell>
+ <Badge
+ variant={script.status === "published" ? "default" : "secondary"}
+ >
+ {script.status}
+ </Badge>
+ </TableCell>
+ <TableCell title={basicTimeFormat(script.modified_at)}>
+ {basicLocalTimeFormat(script.modified_at)}
+ </TableCell>
+ </TableRow>
+ ));
+}
+
+function WorkflowScriptsPage() {
+ const { workflowPermanentId } = useParams();
+ const navigate = useNavigate();
+
+ const { data: workflow, isLoading: workflowIsLoading } = useWorkflowQuery({
+ workflowPermanentId,
+ });
+
+ const {
+ data: scriptsData,
+ isLoading: scriptsLoading,
+ isError,
+ } = useWorkflowScriptsQuery({
+ workflowPermanentId,
+ });
+
+ const scripts = scriptsData?.scripts ?? [];
+
+ if (!workflowPermanentId) {
+ return null;
+ }
+
+ return (
+ <div className="space-y-8">
+ <header className="flex justify-between">
+ <div className="flex flex-col gap-2">
+ {workflowIsLoading ? (
+ <>
+ <Skeleton className="h-7 w-56" />
+ <Skeleton className="h-7 w-56" />
+ </>
+ ) : (
+ <>
+ <h1 className="text-lg font-semibold">{workflow?.title}</h1>
+ <h2 className="text-sm">{workflowPermanentId}</h2>
+ </>
+ )}
+ </div>
+ <div className="flex gap-2">
+ {workflow && (
+ <WorkflowActions
+ workflow={workflow}
+ onSuccessfullyDeleted={() => navigate("/workflows")}
+ />
+ )}
+ <Button asChild variant="secondary">
+ <Link to={`/workflows/${workflowPermanentId}/build`}>
+ <Pencil2Icon className="mr-2 size-4" />
+ Edit
+ </Link>
+ </Button>
+ <Button asChild>
+ <Link to={`/workflows/${workflowPermanentId}/run`}>
+ <PlayIcon className="mr-2 size-4" />
+ Run
+ </Link>
+ </Button>
+ </div>
+ </header>
+ <div className="space-y-4">
+ <header className="flex items-center justify-between">
+ <h1 className="text-2xl">Scripts</h1>
+ <Button asChild variant="outline" size="sm">
+ <Link to={`/workflows/${workflowPermanentId}/runs`}>View Runs</Link>
+ </Button>
+ </header>
+ <div className="rounded-md border">
+ <Table>
+ <TableHeader>
+ <TableRow>
+ <TableHead className="w-1/4">Cache Key Value</TableHead>
+ <TableHead className="w-1/6">Versions</TableHead>
+ <TableHead className="w-1/6">Latest</TableHead>
+ <TableHead className="w-1/6">Status</TableHead>
+ <TableHead className="w-1/4">Last Updated</TableHead>
+ </TableRow>
+ </TableHeader>
+ <TableBody>
+ <ScriptsTableRows
+ isLoading={scriptsLoading}
+ isError={isError}
+ scripts={scripts}
+ />
+ </TableBody>
+ </Table>
+ </div>
+ </div>
+ </div>
+ );
+}
+
+export { WorkflowScriptsPage };
diff --git a/skyvern-frontend/src/routes/workflows/hooks/useWorkflowScriptsQuery.ts b/skyvern-frontend/src/routes/workflows/hooks/useWorkflowScriptsQuery.ts
new file mode 100644
index 000000000..0dad84af5
--- /dev/null
+++ b/skyvern-frontend/src/routes/workflows/hooks/useWorkflowScriptsQuery.ts
@@ -0,0 +1,26 @@
+import { getClient } from "@/api/AxiosClient";
+import { useCredentialGetter } from "@/hooks/useCredentialGetter";
+import { useQuery } from "@tanstack/react-query";
+import { WorkflowScriptsListResponse } from "../types/scriptTypes";
+
+type Props = {
+ workflowPermanentId?: string;
+};
+
+function useWorkflowScriptsQuery({ workflowPermanentId }: Props) {
+ const credentialGetter = useCredentialGetter();
+
+ return useQuery<WorkflowScriptsListResponse>({
+ queryKey: ["workflow-scripts", workflowPermanentId],
+ queryFn: async () => {
+ const client = await getClient(credentialGetter, "sans-api-v1");
+ return client
+ .get(`/scripts/workflows/${workflowPermanentId}`)
+ .then((response) => response.data);
+ },
+ enabled: !!workflowPermanentId,
+ staleTime: 5 * 60 * 1000,
+ });
+}
+
+export { useWorkflowScriptsQuery };
diff --git a/skyvern-frontend/src/routes/workflows/types/scriptTypes.ts b/skyvern-frontend/src/routes/workflows/types/scriptTypes.ts
index 9c12d090f..d8f3ef185 100644
--- a/skyvern-frontend/src/routes/workflows/types/scriptTypes.ts
+++ b/skyvern-frontend/src/routes/workflows/types/scriptTypes.ts
@@ -77,3 +77,19 @@ export type ReviewScriptResponse = {
updated_blocks: string[];
message?: string | null;
};
+
+export type WorkflowScriptSummary = {
+ script_id: string;
+ cache_key: string;
+ cache_key_value: string;
+ // Must match ScriptStatus enum in skyvern/schemas/scripts.py
+ status: "published" | "pending";
+ latest_version: number;
+ version_count: number;
+ created_at: string;
+ modified_at: string;
+};
+
+export type WorkflowScriptsListResponse = {
+ scripts: WorkflowScriptSummary[];
+};
diff --git a/skyvern/forge/sdk/db/agent_db.py b/skyvern/forge/sdk/db/agent_db.py
index d1a9125ae..07101eb3f 100644
--- a/skyvern/forge/sdk/db/agent_db.py
+++ b/skyvern/forge/sdk/db/agent_db.py
@@ -6098,6 +6098,48 @@ class AgentDB(BaseAlchemyDB):
LOG.error("UnexpectedError", exc_info=True)
raise
+ async def get_script_version_stats(
+ self,
+ organization_id: str,
+ script_ids: list[str],
+ ) -> dict[str, tuple[int, int]]:
+ """Return {script_id: (latest_version, version_count)} for the given script IDs."""
+ if not script_ids:
+ return {}
+ try:
+ async with self.Session() as session:
+ query = (
+ select(
+ ScriptModel.script_id,
+ func.max(ScriptModel.version),
+ func.count(ScriptModel.script_revision_id),
+ )
+ .filter(
+ ScriptModel.organization_id == organization_id,
+ ScriptModel.script_id.in_(script_ids),
+ ScriptModel.deleted_at.is_(None),
+ )
+ .group_by(ScriptModel.script_id)
+ )
+ rows = (await session.execute(query)).all()
+ return {row[0]: (row[1], row[2]) for row in rows}
+ except SQLAlchemyError:
+ LOG.error(
+ "SQLAlchemyError in get_script_version_stats",
+ organization_id=organization_id,
+ script_ids=script_ids,
+ exc_info=True,
+ )
+ raise
+ except Exception:
+ LOG.error(
+ "UnexpectedError in get_script_version_stats",
+ organization_id=organization_id,
+ script_ids=script_ids,
+ exc_info=True,
+ )
+ raise
+
async def get_script_revision(self, script_revision_id: str, organization_id: str) -> Script | None:
async with self.Session() as session:
script = (
@@ -6616,6 +6658,7 @@ class AgentDB(BaseAlchemyDB):
if statuses:
query = query.filter(WorkflowScriptModel.status.in_([s.value for s in statuses]))
+ query = query.order_by(WorkflowScriptModel.modified_at.desc())
return (await session.scalars(query)).all()
except SQLAlchemyError:
LOG.error("SQLAlchemyError", exc_info=True)
diff --git a/skyvern/forge/sdk/routes/scripts.py b/skyvern/forge/sdk/routes/scripts.py
index dcc182d55..0cbb2c1be 100644
--- a/skyvern/forge/sdk/routes/scripts.py
+++ b/skyvern/forge/sdk/routes/scripts.py
@@ -28,6 +28,8 @@ from skyvern.schemas.scripts import (
ScriptVersionCompareResponse,
ScriptVersionListResponse,
ScriptVersionSummary,
+ WorkflowScriptsListResponse,
+ WorkflowScriptSummary,
)
from skyvern.services import script_service, workflow_script_service
from skyvern.services.script_reviewer import ScriptReviewer
@@ -770,6 +772,85 @@ async def get_workflow_cache_key_values(
)
+@base_router.get(
+ "/scripts/workflows/{workflow_permanent_id}",
+ include_in_schema=False,
+ response_model=WorkflowScriptsListResponse,
+)
+@base_router.get(
+ "/scripts/workflows/{workflow_permanent_id}/",
+ include_in_schema=False,
+ response_model=WorkflowScriptsListResponse,
+)
+async def list_workflow_scripts(
+ workflow_permanent_id: str = Path(..., description="The workflow permanent ID"),
+ current_org: Organization = Depends(org_auth_service.get_current_org),
+) -> WorkflowScriptsListResponse:
+ """List all scripts (cache key variants) for a workflow with version stats."""
+ organization_id = current_org.organization_id
+
+ # Verify workflow exists (consistent with other script endpoints)
+ workflow = await app.DATABASE.get_workflow_by_permanent_id(
+ workflow_permanent_id=workflow_permanent_id,
+ organization_id=organization_id,
+ )
+ if not workflow:
+ raise HTTPException(status_code=404, detail="Workflow not found")
+
+ workflow_scripts = await app.DATABASE.get_workflow_scripts_by_permanent_id(
+ organization_id=organization_id,
+ workflow_permanent_id=workflow_permanent_id,
+ )
+
+ if not workflow_scripts:
+ return WorkflowScriptsListResponse(scripts=[])
+
+ script_ids = list({ws.script_id for ws in workflow_scripts})
+ version_stats = await app.DATABASE.get_script_version_stats(
+ organization_id=organization_id,
+ script_ids=script_ids,
+ )
+
+ summaries = []
+ for ws in workflow_scripts:
+ latest_version, version_count = version_stats.get(ws.script_id, (0, 0))
+ # Skip scripts with no live versions (all soft-deleted)
+ if version_count == 0:
+ continue
+ status = ScriptStatus.published
+ if ws.status:
+ try:
+ status = ScriptStatus(ws.status)
+ except ValueError:
+ LOG.warning(
+ "Unknown script status, defaulting to published",
+ status=ws.status,
+ script_id=ws.script_id,
+ organization_id=organization_id,
+ )
+ else:
+ LOG.warning(
+ "WorkflowScript has null status, defaulting to published",
+ script_id=ws.script_id,
+ organization_id=organization_id,
+ )
+ summaries.append(
+ WorkflowScriptSummary(
+ script_id=ws.script_id,
+ cache_key=ws.cache_key,
+ cache_key_value=ws.cache_key_value,
+ status=status,
+ latest_version=latest_version,
+ version_count=version_count,
+ created_at=ws.created_at,
+ modified_at=ws.modified_at,
+ )
+ )
+
+ # Results are already sorted by modified_at DESC from the DB query
+ return WorkflowScriptsListResponse(scripts=summaries)
+
+
@base_router.delete(
"/scripts/{workflow_permanent_id}/value",
include_in_schema=False,
diff --git a/skyvern/schemas/scripts.py b/skyvern/schemas/scripts.py
index b48c4014d..34c740de9 100644
--- a/skyvern/schemas/scripts.py
+++ b/skyvern/schemas/scripts.py
@@ -202,6 +202,25 @@ class WorkflowScript(BaseModel):
deleted_at: datetime | None = None
+class WorkflowScriptSummary(BaseModel):
+ """Summary of a workflow script (cache key variant) with version info."""
+
+ script_id: str
+ cache_key: str
+ cache_key_value: str
+ status: ScriptStatus
+ latest_version: int
+ version_count: int
+ created_at: datetime
+ modified_at: datetime
+
+
+class WorkflowScriptsListResponse(BaseModel):
+ """Response for listing all scripts associated with a workflow."""
+
+ scripts: list[WorkflowScriptSummary]
+
+
class ClearCacheResponse(BaseModel):
"""Response model for cache clearing operations."""