LightningWeb.Live.AiAssistant.Modes.WorkflowTemplate (Lightning v2.13.5)
View SourceAI Assistant mode for intelligent workflow template generation and management.
This mode leverages advanced AI capabilities to transform natural language descriptions into complete, production-ready Lightning workflow templates. It provides an intuitive interface for creating complex data integration workflows without requiring deep technical knowledge of Lightning's YAML structure.
Summary
Functions
Determines if workflow template input should be disabled.
Generates contextual titles for workflow template sessions.
Creates a new workflow template generation session.
Generates appropriate tooltip messages when template input is disabled.
Callback implementation for LightningWeb.Live.AiAssistant.ModeBehavior.enable_attachment_options_component?/0
.
Formats errors consistently for workflow template mode.
Retrieves a workflow template session with full context.
Handles post-processing after workflow template generation.
Provides workflow-specific placeholder text for input guidance.
Lists workflow template sessions for the current project.
Provides metadata for the workflow template generation mode.
Checks if more workflow template sessions exist for the project.
Initializes the UI state when starting a new template session.
Processes workflow template requests through the AI service.
Callback implementation for LightningWeb.Live.AiAssistant.ModeBehavior.query_options/1
.
Saves a user message to the workflow template session.
Indicates that workflow mode supports template generation.
Callback implementation for LightningWeb.Live.AiAssistant.ModeBehavior.validate_form_changeset/1
.
Functions
Determines if workflow template input should be disabled.
Evaluates conditions specific to template generation to ensure the feature is only available when appropriate permissions and service availability allow it.
Examples
# Input enabled for template generation
chat_input_disabled?(%{
can_edit_workflow: true,
ai_limit_result: :ok,
endpoint_available?: true,
pending_message: %{loading: nil}
})
# => false
# Input disabled due to usage limits
chat_input_disabled?(%{
can_edit_workflow: true,
ai_limit_result: {:error, :limit_exceeded},
endpoint_available?: true,
pending_message: %{loading: nil}
})
# => true
Generates contextual titles for workflow template sessions.
Creates descriptive titles that include project context when available, making it easier to identify and organize template generation sessions.
Examples
# With custom title
chat_title(%{title: "Salesforce to PostgreSQL Sync"})
# => "Salesforce to PostgreSQL Sync"
# With project context
chat_title(%{project: %{name: "Customer Data Platform"}})
# => "Customer Data Platform Workflow"
# Fallback
chat_title(%{})
# => "New Workflow"
Creates a new workflow template generation session.
Initializes a project-scoped session for AI-powered workflow creation. The session is configured for template generation with appropriate metadata and context for the AI service.
Examples
# Create session for new workflow
{:ok, session} = WorkflowTemplate.create_session(
%{project: project, current_user: user},
"Create a daily Salesforce to PostgreSQL sync workflow"
)
# Create session for workflow enhancement
{:ok, session} = WorkflowTemplate.create_session(
%{project: project, current_user: user},
"Add error handling and retry logic to existing webhook workflow"
)
Generates appropriate tooltip messages when template input is disabled.
Provides specific explanations for why workflow template generation is unavailable, helping users understand required actions.
Parameters
assigns
- Map containing permission and limit information
Returns
String explanation or nil
if input should be enabled.
Examples
# Permission denied
disabled_tooltip_message(%{can_edit_workflow: false})
# => "You are not authorized to use the AI Assistant"
# Usage limit reached
disabled_tooltip_message(%{ai_limit_result: {:error, :monthly_limit}})
# => "Monthly AI usage limit exceeded"
# Service available
disabled_tooltip_message(%{can_edit_workflow: true, ai_limit_result: :ok})
# => nil
Callback implementation for LightningWeb.Live.AiAssistant.ModeBehavior.enable_attachment_options_component?/0
.
Formats errors consistently for workflow template mode.
Leverages shared error handling to provide user-friendly error messages for template generation failures and validation issues.
Parameters
error
- Error to format (changeset, atom, string, etc.)
Returns
Human-readable error message string.
Examples
error_message({:error, :service_unavailable})
# => "AI service is temporarily unavailable. Please try again."
error_message(%Ecto.Changeset{})
# => "Template validation failed: [specific field errors]"
Retrieves a workflow template session with full context.
Loads the complete session including all messages, generated templates, and conversation history for template generation continuation.
Examples
session = WorkflowTemplate.get_session!(%{chat_session_id: session_id})
# Session includes all messages and any generated workflow YAML
Handles post-processing after workflow template generation.
Detects when the AI has generated workflow YAML code and triggers appropriate UI updates to enable template application and preview.
Parameters
assigns
- Current LiveView assignssession_or_message
- Updated session or new message with potential YAMLui_callback
- Function for triggering UI updates
Examples
# When YAML is generated
handle_response_generated(assigns, session_with_yaml, ui_callback)
# Triggers :workflow_code_generated event with the YAML content
# When no YAML is present
handle_response_generated(assigns, session_without_yaml, ui_callback)
# No UI update triggered, returns assigns unchanged
@spec input_placeholder() :: String.t()
Provides workflow-specific placeholder text for input guidance.
Encourages users to describe their desired workflow functionality in natural language for AI template generation.
Lists workflow template sessions for the current project.
Retrieves paginated sessions associated with the project, filtered to show only workflow template generation conversations.
Examples
# Load recent template sessions
%{sessions: sessions, pagination: meta} = WorkflowTemplate.list_sessions(
%{project: project},
:desc,
limit: 15
)
@spec metadata() :: map()
Provides metadata for the workflow template generation mode.
Returns information used by the UI to display mode selection options and identify the mode's template generation capabilities.
Checks if more workflow template sessions exist for the project.
Determines if additional sessions are available beyond the current count for implementing pagination controls.
Examples
if WorkflowTemplate.more_sessions?(%{project: project}, 15) do
# Show "Load More" button
end
Initializes the UI state when starting a new template session.
Clears any existing template data and prepares the interface for new workflow generation.
Parameters
socket
- LiveView socket with current stateui_callback
- Function for triggering UI updates
Examples
# Starting new template session
on_session_start(socket, ui_callback)
# Triggers :clear_template to reset UI state
Processes workflow template requests through the AI service.
Sends user descriptions and requirements to the specialized workflow generation AI service, which returns complete YAML templates and explanatory content.
Parameters
session
- Session with conversation history and contextcontent
- User's workflow description or modification request
Examples
# Generate new workflow template
{:ok, updated_session} = WorkflowTemplate.query(
session,
"Create a workflow that processes CSV files uploaded to Google Drive"
)
# Modify existing template
{:ok, updated_session} = WorkflowTemplate.query(
session,
"Add error notifications to Slack when the sync fails"
)
Callback implementation for LightningWeb.Live.AiAssistant.ModeBehavior.query_options/1
.
Saves a user message to the workflow template session.
Adds user requests, modifications, or questions to the conversation history for AI processing and template generation.
Examples
# Save template modification request
{:ok, updated_session} = WorkflowTemplate.save_message(
%{session: session, current_user: user},
"Add data validation before database insertion"
)
# Save error correction request
{:ok, updated_session} = WorkflowTemplate.save_message(
%{session: session, current_user: user},
"Fix the cron expression to run every 2 hours"
)
@spec supports_template_generation?() :: boolean()
Indicates that workflow mode supports template generation.
This mode's primary purpose is generating workflow templates, enabling UI features like template application and export.
Callback implementation for LightningWeb.Live.AiAssistant.ModeBehavior.validate_form_changeset/1
.