mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-06-12 08:46:02 +00:00
1111
This commit is contained in:
@@ -125,6 +125,19 @@ class WorkflowsRouterGroup(group.RouterGroup):
|
||||
)
|
||||
return self.success(data=executions)
|
||||
|
||||
@self.route(
|
||||
'/<workflow_uuid>/executions/<execution_uuid>',
|
||||
methods=['GET'],
|
||||
auth_type=group.AuthType.USER_TOKEN_OR_API_KEY,
|
||||
)
|
||||
async def _(workflow_uuid: str, execution_uuid: str) -> str:
|
||||
execution = await self.ap.workflow_service.get_execution(execution_uuid)
|
||||
if execution is None:
|
||||
return self.http_status(404, -1, 'execution not found')
|
||||
if execution.get('workflow_uuid') != workflow_uuid:
|
||||
return self.http_status(404, -1, 'execution not found in workflow')
|
||||
return self.success(data={'execution': execution})
|
||||
|
||||
# Get workflow versions
|
||||
@self.route('/<workflow_uuid>/versions', methods=['GET'], auth_type=group.AuthType.USER_TOKEN_OR_API_KEY)
|
||||
async def _(workflow_uuid: str) -> str:
|
||||
|
||||
@@ -73,6 +73,20 @@ class PipelineService:
|
||||
|
||||
return self.ap.persistence_mgr.serialize_model(persistence_pipeline.LegacyPipeline, pipeline)
|
||||
|
||||
async def get_pipeline_by_name(self, pipeline_name: str) -> dict | None:
|
||||
result = await self.ap.persistence_mgr.execute_async(
|
||||
sqlalchemy.select(persistence_pipeline.LegacyPipeline).where(
|
||||
persistence_pipeline.LegacyPipeline.name == pipeline_name
|
||||
)
|
||||
)
|
||||
|
||||
pipeline = result.first()
|
||||
|
||||
if pipeline is None:
|
||||
return None
|
||||
|
||||
return self.ap.persistence_mgr.serialize_model(persistence_pipeline.LegacyPipeline, pipeline)
|
||||
|
||||
async def create_pipeline(self, pipeline_data: dict, default: bool = False) -> str:
|
||||
from ....utils import paths as path_utils
|
||||
|
||||
|
||||
@@ -284,7 +284,7 @@ class WorkflowService:
|
||||
'uuid': execution_uuid,
|
||||
'workflow_uuid': workflow_uuid,
|
||||
'workflow_version': workflow_dict.get('version', 1),
|
||||
'status': ExecutionStatus.PENDING.value,
|
||||
'status': ExecutionStatus.RUNNING.value,
|
||||
'trigger_type': trigger_type,
|
||||
'trigger_data': trigger_data or {},
|
||||
'variables': {},
|
||||
@@ -496,13 +496,7 @@ class WorkflowService:
|
||||
executions = result.all()
|
||||
|
||||
return {
|
||||
'executions': [
|
||||
self.ap.persistence_mgr.serialize_model(
|
||||
persistence_workflow.WorkflowExecution,
|
||||
execution
|
||||
)
|
||||
for execution in executions
|
||||
],
|
||||
'executions': [self._serialize_execution(execution) for execution in executions],
|
||||
'total': total,
|
||||
}
|
||||
|
||||
@@ -519,10 +513,17 @@ class WorkflowService:
|
||||
if execution is None:
|
||||
return None
|
||||
|
||||
return self.ap.persistence_mgr.serialize_model(
|
||||
persistence_workflow.WorkflowExecution,
|
||||
execution
|
||||
)
|
||||
data = self._serialize_execution(execution)
|
||||
|
||||
node_exec_query = sqlalchemy.select(persistence_workflow.WorkflowNodeExecution).where(
|
||||
persistence_workflow.WorkflowNodeExecution.execution_uuid == execution_uuid
|
||||
).order_by(persistence_workflow.WorkflowNodeExecution.id.asc())
|
||||
node_exec_result = await self.ap.persistence_mgr.execute_async(node_exec_query)
|
||||
node_executions = node_exec_result.all()
|
||||
data['node_executions'] = [
|
||||
self._serialize_node_execution(node_exec) for node_exec in node_executions
|
||||
]
|
||||
return data
|
||||
|
||||
async def get_node_types(self) -> list[dict]:
|
||||
"""Get all available node types"""
|
||||
@@ -837,6 +838,24 @@ class WorkflowService:
|
||||
result['variables'] = {}
|
||||
|
||||
return result
|
||||
|
||||
def _serialize_execution(self, execution) -> dict:
|
||||
data = self.ap.persistence_mgr.serialize_model(
|
||||
persistence_workflow.WorkflowExecution,
|
||||
execution,
|
||||
)
|
||||
data['started_at'] = data.get('start_time')
|
||||
data['completed_at'] = data.get('end_time')
|
||||
return data
|
||||
|
||||
def _serialize_node_execution(self, node_execution) -> dict:
|
||||
data = self.ap.persistence_mgr.serialize_model(
|
||||
persistence_workflow.WorkflowNodeExecution,
|
||||
node_execution,
|
||||
)
|
||||
data['started_at'] = data.get('start_time')
|
||||
data['completed_at'] = data.get('end_time')
|
||||
return data
|
||||
|
||||
async def update_workflow_extensions(
|
||||
self,
|
||||
@@ -1111,22 +1130,41 @@ class WorkflowService:
|
||||
execution = await self.get_execution(execution_uuid)
|
||||
if execution is None:
|
||||
raise ValueError(f'Execution {execution_uuid} not found')
|
||||
|
||||
if execution.get('workflow_uuid') != workflow_uuid:
|
||||
raise ValueError(f'Execution {execution_uuid} not found in workflow {workflow_uuid}')
|
||||
|
||||
query = sqlalchemy.select(persistence_workflow.WorkflowNodeExecution).where(
|
||||
persistence_workflow.WorkflowNodeExecution.execution_uuid == execution_uuid
|
||||
).order_by(
|
||||
persistence_workflow.WorkflowNodeExecution.id.asc()
|
||||
).limit(limit).offset(offset)
|
||||
|
||||
|
||||
result = await self.ap.persistence_mgr.execute_async(query)
|
||||
node_executions = result.all()
|
||||
|
||||
logs = [
|
||||
self.ap.persistence_mgr.serialize_model(
|
||||
persistence_workflow.WorkflowNodeExecution,
|
||||
node_exec
|
||||
|
||||
logs = []
|
||||
for node_exec in node_executions:
|
||||
serialized = self._serialize_node_execution(node_exec)
|
||||
timestamp = serialized.get('completed_at') or serialized.get('started_at') or execution.get('started_at')
|
||||
level = 'error' if serialized.get('status') == 'failed' else 'info'
|
||||
message = (
|
||||
f"{serialized.get('node_type')}::{serialized.get('node_id')} - {serialized.get('status')}"
|
||||
)
|
||||
for node_exec in node_executions
|
||||
]
|
||||
|
||||
if serialized.get('error'):
|
||||
message = f"{message} - {serialized.get('error')}"
|
||||
logs.append(
|
||||
{
|
||||
'id': str(serialized.get('id', serialized.get('node_id'))),
|
||||
'timestamp': timestamp,
|
||||
'level': level,
|
||||
'node_id': serialized.get('node_id'),
|
||||
'message': message,
|
||||
'data': {
|
||||
'inputs': serialized.get('inputs'),
|
||||
'outputs': serialized.get('outputs'),
|
||||
'retry_count': serialized.get('retry_count'),
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
return {'logs': logs, 'total': len(logs)}
|
||||
|
||||
Reference in New Issue
Block a user