Skip to content
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

feat(app): Pre-fill action required inputs if empty #815

Merged
merged 2 commits into from
Jan 30, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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