Fix UI runs search to filter by run parameter values and extra HTTP headers (#SKY-7427) (#4667)
This commit is contained in:
@@ -429,7 +429,12 @@ function WorkflowRunParametersInline({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!run || !run.parameters || Object.keys(run.parameters).length === 0) {
|
const hasParameters =
|
||||||
|
run?.parameters && Object.keys(run.parameters).length > 0;
|
||||||
|
const hasExtraHeaders =
|
||||||
|
run?.extra_http_headers && Object.keys(run.extra_http_headers).length > 0;
|
||||||
|
|
||||||
|
if (!hasParameters && !hasExtraHeaders) {
|
||||||
return (
|
return (
|
||||||
<div className="ml-8 py-4 text-sm text-slate-400">
|
<div className="ml-8 py-4 text-sm text-slate-400">
|
||||||
No parameters for this run
|
No parameters for this run
|
||||||
@@ -437,19 +442,44 @@ function WorkflowRunParametersInline({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const parameterItems = Object.entries(run.parameters).map(([key, value]) => ({
|
const parameterItems = hasParameters
|
||||||
key,
|
? Object.entries(run.parameters).map(([key, value]) => ({
|
||||||
value,
|
key,
|
||||||
description: null,
|
value,
|
||||||
}));
|
description: null,
|
||||||
|
}))
|
||||||
|
: [];
|
||||||
|
|
||||||
|
const headerItems =
|
||||||
|
hasExtraHeaders && run.extra_http_headers
|
||||||
|
? Object.entries(run.extra_http_headers).map(([key, value]) => ({
|
||||||
|
key,
|
||||||
|
value,
|
||||||
|
description: null,
|
||||||
|
}))
|
||||||
|
: [];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ParameterDisplayInline
|
<div className="space-y-4">
|
||||||
parameters={parameterItems}
|
{hasParameters && (
|
||||||
searchQuery={searchQuery}
|
<ParameterDisplayInline
|
||||||
keywordMatchesParameter={keywordMatchesParameter}
|
title="Run Parameters"
|
||||||
showDescription={false}
|
parameters={parameterItems}
|
||||||
/>
|
searchQuery={searchQuery}
|
||||||
|
keywordMatchesParameter={keywordMatchesParameter}
|
||||||
|
showDescription={false}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
{hasExtraHeaders && (
|
||||||
|
<ParameterDisplayInline
|
||||||
|
title="Extra HTTP Headers"
|
||||||
|
parameters={headerItems}
|
||||||
|
searchQuery={searchQuery}
|
||||||
|
keywordMatchesParameter={keywordMatchesParameter}
|
||||||
|
showDescription={false}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ from datetime import datetime, timedelta
|
|||||||
from typing import Any, List, Literal, Sequence, overload
|
from typing import Any, List, Literal, Sequence, overload
|
||||||
|
|
||||||
import structlog
|
import structlog
|
||||||
from sqlalchemy import and_, asc, case, delete, distinct, exists, func, or_, pool, select, tuple_, update
|
from sqlalchemy import Text, and_, asc, case, delete, distinct, exists, func, or_, pool, select, tuple_, update
|
||||||
from sqlalchemy.exc import (
|
from sqlalchemy.exc import (
|
||||||
SQLAlchemyError,
|
SQLAlchemyError,
|
||||||
)
|
)
|
||||||
@@ -2790,8 +2790,8 @@ class AgentDB(BaseAlchemyDB):
|
|||||||
key_like = f"%{search_key}%"
|
key_like = f"%{search_key}%"
|
||||||
# Match workflow_run_id directly
|
# Match workflow_run_id directly
|
||||||
id_matches = WorkflowRunModel.workflow_run_id.ilike(key_like)
|
id_matches = WorkflowRunModel.workflow_run_id.ilike(key_like)
|
||||||
# Match parameter key, description, or value
|
# Match parameter key or description (only for non-deleted parameter definitions)
|
||||||
param_exists = exists(
|
param_key_desc_exists = exists(
|
||||||
select(1)
|
select(1)
|
||||||
.select_from(WorkflowRunParameterModel)
|
.select_from(WorkflowRunParameterModel)
|
||||||
.join(
|
.join(
|
||||||
@@ -2805,11 +2805,24 @@ class AgentDB(BaseAlchemyDB):
|
|||||||
or_(
|
or_(
|
||||||
WorkflowParameterModel.key.ilike(key_like),
|
WorkflowParameterModel.key.ilike(key_like),
|
||||||
WorkflowParameterModel.description.ilike(key_like),
|
WorkflowParameterModel.description.ilike(key_like),
|
||||||
WorkflowRunParameterModel.value.ilike(key_like),
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
workflow_run_query = workflow_run_query.where(or_(id_matches, param_exists))
|
# Match run parameter value directly (searches all values regardless of parameter definition status)
|
||||||
|
param_value_exists = exists(
|
||||||
|
select(1)
|
||||||
|
.select_from(WorkflowRunParameterModel)
|
||||||
|
.where(WorkflowRunParameterModel.workflow_run_id == WorkflowRunModel.workflow_run_id)
|
||||||
|
.where(WorkflowRunParameterModel.value.ilike(key_like))
|
||||||
|
)
|
||||||
|
# Match extra HTTP headers (cast JSON to text for search, skip NULLs)
|
||||||
|
extra_headers_match = and_(
|
||||||
|
WorkflowRunModel.extra_http_headers.isnot(None),
|
||||||
|
func.cast(WorkflowRunModel.extra_http_headers, Text()).ilike(key_like),
|
||||||
|
)
|
||||||
|
workflow_run_query = workflow_run_query.where(
|
||||||
|
or_(id_matches, param_key_desc_exists, param_value_exists, extra_headers_match)
|
||||||
|
)
|
||||||
|
|
||||||
if status:
|
if status:
|
||||||
workflow_run_query = workflow_run_query.filter(WorkflowRunModel.status.in_(status))
|
workflow_run_query = workflow_run_query.filter(WorkflowRunModel.status.in_(status))
|
||||||
@@ -3068,7 +3081,8 @@ class AgentDB(BaseAlchemyDB):
|
|||||||
search_key: str | None = None,
|
search_key: str | None = None,
|
||||||
) -> list[WorkflowRun]:
|
) -> list[WorkflowRun]:
|
||||||
"""
|
"""
|
||||||
Get runs for a workflow, with optional `search_key` on parameter key/description/value.
|
Get runs for a workflow, with optional `search_key` on run ID, parameter key/description/value,
|
||||||
|
or extra HTTP headers.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
async with self.Session() as session:
|
async with self.Session() as session:
|
||||||
@@ -3081,9 +3095,11 @@ class AgentDB(BaseAlchemyDB):
|
|||||||
)
|
)
|
||||||
if search_key:
|
if search_key:
|
||||||
key_like = f"%{search_key}%"
|
key_like = f"%{search_key}%"
|
||||||
# Filter runs where any run parameter matches by key/description/value
|
# Match workflow_run_id directly
|
||||||
|
id_matches = WorkflowRunModel.workflow_run_id.ilike(key_like)
|
||||||
|
# Match parameter key or description (only for non-deleted parameter definitions)
|
||||||
# Use EXISTS to avoid duplicate rows and to keep pagination correct
|
# Use EXISTS to avoid duplicate rows and to keep pagination correct
|
||||||
param_exists = exists(
|
param_key_desc_exists = exists(
|
||||||
select(1)
|
select(1)
|
||||||
.select_from(WorkflowRunParameterModel)
|
.select_from(WorkflowRunParameterModel)
|
||||||
.join(
|
.join(
|
||||||
@@ -3097,11 +3113,22 @@ class AgentDB(BaseAlchemyDB):
|
|||||||
or_(
|
or_(
|
||||||
WorkflowParameterModel.key.ilike(key_like),
|
WorkflowParameterModel.key.ilike(key_like),
|
||||||
WorkflowParameterModel.description.ilike(key_like),
|
WorkflowParameterModel.description.ilike(key_like),
|
||||||
WorkflowRunParameterModel.value.ilike(key_like),
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
query = query.where(param_exists)
|
# Match run parameter value directly (searches all values regardless of parameter definition status)
|
||||||
|
param_value_exists = exists(
|
||||||
|
select(1)
|
||||||
|
.select_from(WorkflowRunParameterModel)
|
||||||
|
.where(WorkflowRunParameterModel.workflow_run_id == WorkflowRunModel.workflow_run_id)
|
||||||
|
.where(WorkflowRunParameterModel.value.ilike(key_like))
|
||||||
|
)
|
||||||
|
# Match extra HTTP headers (cast JSON to text for search, skip NULLs)
|
||||||
|
extra_headers_match = and_(
|
||||||
|
WorkflowRunModel.extra_http_headers.isnot(None),
|
||||||
|
func.cast(WorkflowRunModel.extra_http_headers, Text()).ilike(key_like),
|
||||||
|
)
|
||||||
|
query = query.where(or_(id_matches, param_key_desc_exists, param_value_exists, extra_headers_match))
|
||||||
if status:
|
if status:
|
||||||
query = query.filter(WorkflowRunModel.status.in_(status))
|
query = query.filter(WorkflowRunModel.status.in_(status))
|
||||||
query = query.order_by(WorkflowRunModel.created_at.desc()).limit(page_size).offset(db_page * page_size)
|
query = query.order_by(WorkflowRunModel.created_at.desc()).limit(page_size).offset(db_page * page_size)
|
||||||
|
|||||||
@@ -1990,7 +1990,7 @@ async def get_runs(
|
|||||||
status: Annotated[list[WorkflowRunStatus] | None, Query()] = None,
|
status: Annotated[list[WorkflowRunStatus] | None, Query()] = None,
|
||||||
search_key: str | None = Query(
|
search_key: str | None = Query(
|
||||||
None,
|
None,
|
||||||
description="Search runs by parameter key, parameter description, or run parameter value.",
|
description="Search runs by run ID, parameter key, parameter description, run parameter value, or extra HTTP headers.",
|
||||||
),
|
),
|
||||||
) -> Response:
|
) -> Response:
|
||||||
analytics.capture("skyvern-oss-agent-runs-get")
|
analytics.capture("skyvern-oss-agent-runs-get")
|
||||||
@@ -2248,7 +2248,7 @@ async def get_workflow_runs_by_id(
|
|||||||
status: Annotated[list[WorkflowRunStatus] | None, Query()] = None,
|
status: Annotated[list[WorkflowRunStatus] | None, Query()] = None,
|
||||||
search_key: str | None = Query(
|
search_key: str | None = Query(
|
||||||
None,
|
None,
|
||||||
description="Search runs by parameter key, parameter description, or run parameter value.",
|
description="Search runs by run ID, parameter key, parameter description, run parameter value, or extra HTTP headers.",
|
||||||
),
|
),
|
||||||
current_org: Organization = Depends(org_auth_service.get_current_org),
|
current_org: Organization = Depends(org_auth_service.get_current_org),
|
||||||
) -> list[WorkflowRun]:
|
) -> list[WorkflowRun]:
|
||||||
|
|||||||
Reference in New Issue
Block a user