Skip to content

Commit

Permalink
feat(app): Pre-fill action required inputs if empty (#815)
Browse files Browse the repository at this point in the history
  • Loading branch information
daryllimyt authored Jan 30, 2025
1 parent 749edca commit 6a0aaf0
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions tracecat/workflow/actions/router.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import yaml
from fastapi import APIRouter, HTTPException, status
from pydantic_core import PydanticUndefined
from sqlalchemy.exc import NoResultFound
from sqlmodel import select

Expand All @@ -8,6 +9,7 @@
from tracecat.db.schemas import Action
from tracecat.identifiers.action import ActionID
from tracecat.identifiers.workflow import AnyWorkflowIDPath, WorkflowUUID
from tracecat.registry.actions.service import RegistryActionsService
from tracecat.workflow.actions.models import (
ActionControlFlow,
ActionCreate,
Expand Down Expand Up @@ -113,6 +115,19 @@ async def get_action(
status_code=status.HTTP_404_NOT_FOUND, detail="Resource not found"
) from e

# Add default value for input if it's empty
if len(action.inputs) == 0:
# Lookup action type in the registry
ra_service = RegistryActionsService(session, role=role)
reg_action = await ra_service.load_action_impl(action.type)
# We want to construct a YAML string that contains the defaults
prefilled_inputs = "\n".join(
f"{field}: "
for field, field_info in reg_action.args_cls.model_fields.items()
if field_info.default is PydanticUndefined
)
action.inputs = prefilled_inputs

return ActionRead(
id=action.id,
type=action.type,
Expand Down

0 comments on commit 6a0aaf0

Please sign in to comment.