fix: Resolve event delivery configuration header passing between frontend and backend (#7514)

Co-authored-by: Gabriel Luiz Freitas Almeida <gabriel@langflow.org>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
Cristhian Zanforlin Lousa 2025-04-09 14:58:11 -03:00 • committed by GitHub
commit 59a7440045
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 54 additions and 46 deletions

View file

@ -13,6 +13,7 @@ from sqlmodel import select
from langflow.api.disconnect import DisconnectHandlerStreamingResponse
from langflow.api.utils import (
CurrentActiveUser,
EventDeliveryType,
build_graph_from_data,
build_graph_from_db,
format_elapsed_time,
@ -84,12 +85,12 @@ async def get_flow_events_response(
*,
job_id: str,
queue_service: JobQueueService,
stream: bool = True,
event_delivery: EventDeliveryType,
):
"""Get events for a specific build job, either as a stream or single event."""
try:
main_queue, event_manager, event_task, _ = queue_service.get_queue_data(job_id)
if stream:
if event_delivery in (EventDeliveryType.STREAMING, EventDeliveryType.DIRECT):
if event_task is None:
logger.error(f"No event task found for job {job_id}")
raise HTTPException(status_code=404, detail="No event task found for job")

View file

@ -2,6 +2,7 @@ from __future__ import annotations
import uuid
from datetime import timedelta
from enum import Enum
from typing import TYPE_CHECKING, Annotated, Any
from fastapi import Depends, HTTPException, Query
@ -34,6 +35,12 @@ CurrentActiveUser = Annotated[User, Depends(get_current_active_user)]
DbSession = Annotated[AsyncSession, Depends(get_session)]
class EventDeliveryType(str, Enum):
STREAMING = "streaming"
DIRECT = "direct"
POLLING = "polling"
def has_api_terms(word: str):
return "api" in word and ("key" in word or ("token" in word and "tokens" not in word))

View file

@ -27,6 +27,7 @@ from langflow.api.limited_background_tasks import LimitVertexBuildBackgroundTask
from langflow.api.utils import (
CurrentActiveUser,
DbSession,
EventDeliveryType,
build_and_cache_graph_from_data,
build_graph_from_db,
format_elapsed_time,
@ -55,12 +56,10 @@ from langflow.services.deps import (
get_chat_service,
get_queue_service,
get_session,
get_settings_service,
get_telemetry_service,
session_scope,
)
from langflow.services.job_queue.service import JobQueueNotFoundError, JobQueueService
from langflow.services.settings.service import SettingsService
from langflow.services.telemetry.schema import ComponentPayload, PlaygroundPayload
if TYPE_CHECKING:
@ -154,7 +153,7 @@ async def build_flow(
current_user: CurrentActiveUser,
queue_service: Annotated[JobQueueService, Depends(get_queue_service)],
flow_name: str | None = None,
settings_service: Annotated[SettingsService, Depends(get_settings_service)],
event_delivery: EventDeliveryType = EventDeliveryType.POLLING,
):
"""Build and process a flow, returning a job ID for event polling.
@ -174,6 +173,7 @@ async def build_flow(
queue_service: Queue service for job management
flow_name: Optional name for the flow
settings_service: Settings service
event_delivery: Optional event delivery type - default is streaming
Returns:
Dict with job_id that can be used to poll for build status
@ -197,12 +197,14 @@ async def build_flow(
queue_service=queue_service,
flow_name=flow_name,
)
if settings_service.settings.event_delivery != "direct":
# This is required to support FE tests - we need to be able to set the event delivery to direct
if event_delivery == EventDeliveryType.DIRECT:
return {"job_id": job_id}
return await get_flow_events_response(
job_id=job_id,
queue_service=queue_service,
stream=True,
event_delivery=event_delivery,
)
@ -211,13 +213,13 @@ async def get_build_events(
job_id: str,
queue_service: Annotated[JobQueueService, Depends(get_queue_service)],
*,
stream: bool = True,
event_delivery: EventDeliveryType = EventDeliveryType.STREAMING,
):
"""Get events for a specific build job."""
return await get_flow_events_response(
job_id=job_id,
queue_service=queue_service,
stream=stream,
event_delivery=event_delivery,
)