Add TaskRunResponse data to task v2 webhook (#2435)

This commit is contained in:
Shuchang Zheng
2025-05-23 16:24:41 -07:00
committed by GitHub
parent f985bcd95b
commit 2fe2b53690
2 changed files with 58 additions and 32 deletions

View File

@@ -67,35 +67,7 @@ async def get_run_response(run_id: str, organization_id: str | None = None) -> R
task_v2 = await app.DATABASE.get_task_v2(run.run_id, organization_id=organization_id)
if not task_v2:
return None
workflow_run = None
if task_v2.workflow_run_id:
workflow_run = await workflow_service.get_workflow_run_response(
task_v2.workflow_run_id, organization_id=organization_id
)
return TaskRunResponse(
run_id=run.run_id,
run_type=run.task_run_type,
status=task_v2.status,
output=task_v2.output,
failure_reason=workflow_run.failure_reason if workflow_run else None,
created_at=task_v2.created_at,
modified_at=task_v2.modified_at,
recording_url=workflow_run.recording_url if workflow_run else None,
screenshot_urls=workflow_run.screenshot_urls if workflow_run else None,
downloaded_files=workflow_run.downloaded_files if workflow_run else None,
app_url=f"{settings.SKYVERN_APP_URL.rstrip('/')}/workflows/{task_v2.workflow_permanent_id}/{task_v2.workflow_run_id}",
run_request=TaskRunRequest(
engine=RunEngine.skyvern_v2,
prompt=task_v2.prompt,
url=task_v2.url,
webhook_url=task_v2.webhook_callback_url,
totp_identifier=task_v2.totp_identifier,
totp_url=task_v2.totp_verification_url,
proxy_location=task_v2.proxy_location,
data_extraction_schema=task_v2.extracted_information_schema,
error_code_mapping=task_v2.error_code_mapping,
),
)
return await task_v2_service.build_task_v2_run_response(task_v2)
elif run.task_run_type == RunType.workflow_run:
return await workflow_service.get_workflow_run_response(run.run_id, organization_id=organization_id)
raise ValueError(f"Invalid task run type: {run.task_run_type}")