revert webhook schema updates (#2479)

This commit is contained in:
Shuchang Zheng
2025-05-26 21:18:42 -07:00
committed by GitHub
parent 374a1003d7
commit da4afddc21
3 changed files with 72 additions and 60 deletions

View File

@@ -72,7 +72,6 @@ from skyvern.forge.sdk.workflow.context_manager import WorkflowRunContext
from skyvern.forge.sdk.workflow.models.block import ActionBlock, BaseTaskBlock, ValidationBlock from skyvern.forge.sdk.workflow.models.block import ActionBlock, BaseTaskBlock, ValidationBlock
from skyvern.forge.sdk.workflow.models.workflow import Workflow, WorkflowRun, WorkflowRunStatus from skyvern.forge.sdk.workflow.models.workflow import Workflow, WorkflowRun, WorkflowRunStatus
from skyvern.schemas.runs import CUA_ENGINES, CUA_RUN_TYPES, RunEngine from skyvern.schemas.runs import CUA_ENGINES, CUA_RUN_TYPES, RunEngine
from skyvern.services import run_service
from skyvern.utils.image_resizer import Resolution from skyvern.utils.image_resizer import Resolution
from skyvern.utils.prompt_engine import load_prompt_with_elements from skyvern.utils.prompt_engine import load_prompt_with_elements
from skyvern.webeye.actions.actions import ( from skyvern.webeye.actions.actions import (
@@ -2110,30 +2109,40 @@ class ForgeAgent:
return return
task_response = await self.build_task_response(task=task, last_step=last_step) task_response = await self.build_task_response(task=task, last_step=last_step)
# send task_response to the webhook callback url
payload = task_response.model_dump_json(exclude={"request"})
headers = generate_skyvern_webhook_headers(payload=payload, api_key=api_key)
LOG.info(
"Sending task response to webhook callback url",
task_id=task.task_id,
webhook_callback_url=task.webhook_callback_url,
payload=payload,
headers=headers,
)
# try to build the new TaskRunResponse for backward compatibility # try to build the new TaskRunResponse for backward compatibility
task_run_response_json: str | None = None # task_run_response_json: str | None = None
try: try:
run_response = await run_service.get_run_response( # run_response = await run_service.get_run_response(
run_id=task.task_id, # run_id=task.task_id,
organization_id=task.organization_id, # organization_id=task.organization_id,
) # )
if run_response is not None: # if run_response is not None:
task_run_response_json = run_response.model_dump_json(exclude={"run_request"}) # task_run_response_json = run_response.model_dump_json(exclude={"run_request"})
# send task_response to the webhook callback url # # send task_response to the webhook callback url
payload_json = task_response.model_dump_json(exclude={"request"}) # payload_json = task_response.model_dump_json(exclude={"request"})
payload_dict = json.loads(payload_json) # payload_dict = json.loads(payload_json)
if task_run_response_json: # if task_run_response_json:
payload_dict.update(json.loads(task_run_response_json)) # payload_dict.update(json.loads(task_run_response_json))
payload = json.dumps(payload_dict) # payload = json.dumps(payload_dict)
headers = generate_skyvern_webhook_headers(payload=payload, api_key=api_key) # headers = generate_skyvern_webhook_headers(payload=payload, api_key=api_key)
LOG.info( # LOG.info(
"Sending task response to webhook callback url", # "Sending task response to webhook callback url",
task_id=task.task_id, # task_id=task.task_id,
webhook_callback_url=task.webhook_callback_url, # webhook_callback_url=task.webhook_callback_url,
payload=payload, # payload=payload,
headers=headers, # headers=headers,
) # )
async with httpx.AsyncClient() as client: async with httpx.AsyncClient() as client:
resp = await client.post( resp = await client.post(

View File

@@ -90,7 +90,7 @@ from skyvern.forge.sdk.workflow.models.yaml import (
WorkflowCreateYAMLRequest, WorkflowCreateYAMLRequest,
WorkflowDefinitionYAML, WorkflowDefinitionYAML,
) )
from skyvern.schemas.runs import ProxyLocation, RunStatus, RunType, WorkflowRunRequest, WorkflowRunResponse from skyvern.schemas.runs import ProxyLocation
from skyvern.webeye.browser_factory import BrowserState from skyvern.webeye.browser_factory import BrowserState
LOG = structlog.get_logger() LOG = structlog.get_logger()
@@ -1220,37 +1220,39 @@ class WorkflowService:
) )
return return
# send webhook to the webhook callback url
payload = workflow_run_status_response.model_dump_json()
# build new schema for backward compatible webhook payload # build new schema for backward compatible webhook payload
app_url = ( # app_url = (
f"{settings.SKYVERN_APP_URL.rstrip('/')}/workflows/" # f"{settings.SKYVERN_APP_URL.rstrip('/')}/workflows/"
f"{workflow_run.workflow_permanent_id}/{workflow_run.workflow_run_id}" # f"{workflow_run.workflow_permanent_id}/{workflow_run.workflow_run_id}"
) # )
workflow_run_response = WorkflowRunResponse( # workflow_run_response = WorkflowRunResponse(
run_id=workflow_run.workflow_run_id, # run_id=workflow_run.workflow_run_id,
run_type=RunType.workflow_run, # run_type=RunType.workflow_run,
status=RunStatus(workflow_run_status_response.status), # status=RunStatus(workflow_run_status_response.status),
output=workflow_run_status_response.outputs, # output=workflow_run_status_response.outputs,
downloaded_files=workflow_run_status_response.downloaded_files, # downloaded_files=workflow_run_status_response.downloaded_files,
recording_url=workflow_run_status_response.recording_url, # recording_url=workflow_run_status_response.recording_url,
screenshot_urls=workflow_run_status_response.screenshot_urls, # screenshot_urls=workflow_run_status_response.screenshot_urls,
failure_reason=workflow_run_status_response.failure_reason, # failure_reason=workflow_run_status_response.failure_reason,
app_url=app_url, # app_url=app_url,
created_at=workflow_run_status_response.created_at, # created_at=workflow_run_status_response.created_at,
modified_at=workflow_run_status_response.modified_at, # modified_at=workflow_run_status_response.modified_at,
run_request=WorkflowRunRequest( # run_request=WorkflowRunRequest(
workflow_id=workflow_run.workflow_permanent_id, # workflow_id=workflow_run.workflow_permanent_id,
title=workflow_run_status_response.workflow_title, # title=workflow_run_status_response.workflow_title,
parameters=workflow_run_status_response.parameters, # parameters=workflow_run_status_response.parameters,
proxy_location=workflow_run.proxy_location, # proxy_location=workflow_run.proxy_location,
webhook_url=workflow_run.webhook_callback_url or None, # webhook_url=workflow_run.webhook_callback_url or None,
totp_url=workflow_run.totp_verification_url or None, # totp_url=workflow_run.totp_verification_url or None,
totp_identifier=workflow_run.totp_identifier, # totp_identifier=workflow_run.totp_identifier,
), # ),
) # )
payload_dict = json.loads(workflow_run_status_response.model_dump_json()) # payload_dict = json.loads(workflow_run_status_response.model_dump_json())
workflow_run_response_dict = json.loads(workflow_run_response.model_dump_json()) # workflow_run_response_dict = json.loads(workflow_run_response.model_dump_json())
payload_dict.update(workflow_run_response_dict) # payload_dict.update(workflow_run_response_dict)
payload = json.dumps(payload_dict, default=str) # payload = json.dumps(payload_dict, default=str)
headers = generate_skyvern_webhook_headers( headers = generate_skyvern_webhook_headers(
payload=payload, payload=payload,
api_key=api_key, api_key=api_key,

View File

@@ -1,4 +1,3 @@
import json
import os import os
import random import random
import string import string
@@ -1660,13 +1659,15 @@ async def send_task_v2_webhook(task_v2: TaskV2) -> None:
) )
return return
try: try:
# build the task v2 response
payload = task_v2.model_dump_json(by_alias=True)
# build the task v2 response with backward compatible data # build the task v2 response with backward compatible data
task_run_response = await build_task_v2_run_response(task_v2) # task_run_response = await build_task_v2_run_response(task_v2)
task_run_response_json = task_run_response.model_dump_json(exclude={"run_request"}) # task_run_response_json = task_run_response.model_dump_json(exclude={"run_request"})
payload_json = task_v2.model_dump_json(by_alias=True) # payload_json = task_v2.model_dump_json(by_alias=True)
payload_dict = json.loads(payload_json) # payload_dict = json.loads(payload_json)
payload_dict.update(json.loads(task_run_response_json)) # payload_dict.update(json.loads(task_run_response_json))
payload = json.dumps(payload_dict) # payload = json.dumps(payload_dict)
headers = generate_skyvern_webhook_headers(payload=payload, api_key=api_key.token) headers = generate_skyvern_webhook_headers(payload=payload, api_key=api_key.token)
LOG.info( LOG.info(
"Sending task v2 response to webhook callback url", "Sending task v2 response to webhook callback url",