From 1e0b1aba43566af02a84c43506a6499b5e5846de Mon Sep 17 00:00:00 2001 From: Kaosiso Ezealigo Date: Wed, 21 Aug 2024 15:35:40 +0100 Subject: [PATCH] fix(frontend): Refactor getStringOrJson function to simplify value handling --- agenta-web/src/components/Playground/Views/TestView.tsx | 6 +++--- agenta-web/src/lib/helpers/utils.ts | 6 +----- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/agenta-web/src/components/Playground/Views/TestView.tsx b/agenta-web/src/components/Playground/Views/TestView.tsx index dded6b5f3f..ae3305e6cf 100644 --- a/agenta-web/src/components/Playground/Views/TestView.tsx +++ b/agenta-web/src/components/Playground/Views/TestView.tsx @@ -568,10 +568,10 @@ const App: React.FC = ({ // String, FuncResponse or BaseResponse if (typeof result === "string") { res = {version: "2.0", data: result} as BaseResponse - setResultForIndex(getStringOrJson(res), index) + setResultForIndex(getStringOrJson(res.data), index) } else if (isFuncResponse(result)) { res = {version: "2.0", data: result.message} as BaseResponse - setResultForIndex(getStringOrJson(res), index) + setResultForIndex(getStringOrJson(res.data), index) const {message, cost, latency, usage} = result setAdditionalDataList((prev) => { @@ -581,7 +581,7 @@ const App: React.FC = ({ }) } else if (isBaseResponse(result)) { res = result as BaseResponse - setResultForIndex(getStringOrJson(res), index) + setResultForIndex(getStringOrJson(res.data), index) const {data, trace} = result setAdditionalDataList((prev) => { diff --git a/agenta-web/src/lib/helpers/utils.ts b/agenta-web/src/lib/helpers/utils.ts index 49e2f3b93f..aaef7b79d5 100644 --- a/agenta-web/src/lib/helpers/utils.ts +++ b/agenta-web/src/lib/helpers/utils.ts @@ -338,11 +338,7 @@ export const getInitials = (str: string, limit = 2) => { } export const getStringOrJson = (value: any) => { - return typeof value === "string" - ? value - : typeof value?.data === "string" - ? value?.data - : JSON.stringify(value.data, null, 2) + return typeof value === "string" ? value : JSON.stringify(value, null, 2) } export const filterVariantParameters = ({