|
25 | 25 | ) |
26 | 26 | from .integrations import Integration |
27 | 27 | from .logging import configure_logging, setup_logger |
28 | | -from .loop import Loop, LoopEvent, LoopManager, Workflow, WorkflowBlock, WorkflowManager |
| 28 | +from .loop import Loop, LoopEvent, LoopManager, Workflow, WorkflowManager |
29 | 29 | from .state.state import StateManager, create_state_manager |
30 | 30 | from .types import BaseConfig, LoopStatus |
31 | 31 | from .utils import get_func_import_path, import_func_from_path, infer_application_path |
@@ -499,29 +499,40 @@ def _decorator( |
499 | 499 | "workflow_instance": workflow_instance, |
500 | 500 | } |
501 | 501 |
|
502 | | - class WorkflowStartRequest(BaseModel): |
503 | | - type: str |
504 | | - blocks: list[WorkflowBlock] |
505 | | - workflow_id: str | None = None |
| 502 | + async def _start_handler(request: dict[str, Any]): |
| 503 | + event_type = request.get("type") |
| 504 | + blocks_raw = request.get("blocks", []) |
| 505 | + workflow_id_req = request.get("workflow_id") |
506 | 506 |
|
507 | | - async def _start_handler(request: WorkflowStartRequest): |
508 | | - if start_event_key and request.type != start_event_key: |
| 507 | + if start_event_key and event_type != start_event_key: |
509 | 508 | raise HTTPException( |
510 | 509 | status_code=HTTPStatus.BAD_REQUEST, |
511 | 510 | detail=f"Expected event type '{start_event_key}'", |
512 | 511 | ) |
513 | 512 |
|
514 | | - try: |
515 | | - workflow, _ = await self.state_manager.get_or_create_workflow( |
516 | | - workflow_name=name, |
517 | | - workflow_id=request.workflow_id, |
518 | | - blocks=[b.model_dump() for b in request.blocks], |
519 | | - ) |
520 | | - except WorkflowNotFoundError as e: |
| 513 | + if not blocks_raw or not isinstance(blocks_raw, list): |
521 | 514 | raise HTTPException( |
522 | | - status_code=HTTPStatus.NOT_FOUND, |
523 | | - detail=f"Workflow {request.workflow_id} not found", |
524 | | - ) from e |
| 515 | + status_code=HTTPStatus.BAD_REQUEST, |
| 516 | + detail="blocks is required and must be a list", |
| 517 | + ) |
| 518 | + |
| 519 | + for i, block in enumerate(blocks_raw): |
| 520 | + if not isinstance(block, dict): |
| 521 | + raise HTTPException( |
| 522 | + status_code=HTTPStatus.BAD_REQUEST, |
| 523 | + detail=f"blocks[{i}] must be an object", |
| 524 | + ) |
| 525 | + if "text" not in block or "type" not in block: |
| 526 | + raise HTTPException( |
| 527 | + status_code=HTTPStatus.BAD_REQUEST, |
| 528 | + detail=f"blocks[{i}] must have 'text' and 'type' fields", |
| 529 | + ) |
| 530 | + |
| 531 | + workflow, _ = await self.state_manager.get_or_create_workflow( |
| 532 | + workflow_name=name, |
| 533 | + workflow_id=workflow_id_req, |
| 534 | + blocks=blocks_raw, |
| 535 | + ) |
525 | 536 |
|
526 | 537 | if workflow.status == LoopStatus.STOPPED: |
527 | 538 | raise HTTPException( |
|
0 commit comments