From 0dcd99805f5753ea39503addff900d4a8d53978e Mon Sep 17 00:00:00 2001 From: Kerem Yilmaz Date: Fri, 7 Jun 2024 11:17:37 -0700 Subject: [PATCH] Handle empty action (#447) --- skyvern-frontend/src/api/types.ts | 10 +++++----- .../src/routes/tasks/detail/useActions.tsx | 20 +++++++++++-------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/skyvern-frontend/src/api/types.ts b/skyvern-frontend/src/api/types.ts index ee9db596..9fb10f31 100644 --- a/skyvern-frontend/src/api/types.ts +++ b/skyvern-frontend/src/api/types.ts @@ -37,13 +37,13 @@ export type ArtifactApiResponse = { organization_id: string; }; +export type ActionResultApiResponse = { + success: boolean; +}; + export type ActionAndResultApiResponse = [ ActionApiResponse, - [ - { - success: boolean; - }, - ], + Array, ]; export type StepApiResponse = { diff --git a/skyvern-frontend/src/routes/tasks/detail/useActions.tsx b/skyvern-frontend/src/routes/tasks/detail/useActions.tsx index 5b51358a..d8a579d3 100644 --- a/skyvern-frontend/src/routes/tasks/detail/useActions.tsx +++ b/skyvern-frontend/src/routes/tasks/detail/useActions.tsx @@ -23,7 +23,7 @@ function getActionInput(action: ActionApiResponse) { } function useActions(taskId: string): { - data?: Array; + data?: Array; isFetching: boolean; } { const credentialGetter = useCredentialGetter(); @@ -56,16 +56,20 @@ function useActions(taskId: string): { const actionsAndResults = step.output.actions_and_results; const actions = actionsAndResults.map((actionAndResult, index) => { - const action: Action = { - reasoning: actionAndResult[0].reasoning, - confidence: actionAndResult[0].confidence_float, - input: getActionInput(actionAndResult[0]), - type: actionAndResult[0].action_type, - success: actionAndResult[1][0].success, + const action = actionAndResult[0]; + const actionResult = actionAndResult[1]; + if (actionResult.length === 0) { + return null; + } + return { + reasoning: action.reasoning, + confidence: action.confidence_float, + input: getActionInput(action), + type: action.action_type, + success: actionResult?.[0]?.success ?? false, stepId: step.step_id, index, }; - return action; }); return actions; })