From 9e15233031878a6dc4f28c0dcb533ff838d2c787 Mon Sep 17 00:00:00 2001 From: Kaosiso Ezealigo Date: Wed, 10 Jan 2024 16:24:56 +0100 Subject: [PATCH 1/8] feat to cancel ongoing request --- .../components/Playground/Views/TestView.tsx | 148 +++++++++++++++--- agenta-web/src/lib/services/api.ts | 38 ++++- 2 files changed, 153 insertions(+), 33 deletions(-) diff --git a/agenta-web/src/components/Playground/Views/TestView.tsx b/agenta-web/src/components/Playground/Views/TestView.tsx index 31e7fc4b77..234eb60e0f 100644 --- a/agenta-web/src/components/Playground/Views/TestView.tsx +++ b/agenta-web/src/components/Playground/Views/TestView.tsx @@ -1,6 +1,6 @@ -import React, {useContext, useEffect, useState} from "react" +import React, {useContext, useEffect, useRef, useState} from "react" import {Button, Input, Card, Row, Col, Space, Form} from "antd" -import {CaretRightOutlined, PlusOutlined} from "@ant-design/icons" +import {CaretRightOutlined, CloseCircleOutlined, PlusOutlined} from "@ant-design/icons" import {callVariant} from "@/lib/services/api" import {ChatMessage, ChatRole, GenericObject, Parameter, Variant} from "@/lib/Types" import {batchExecute, randString, removeKeys} from "@/lib/helpers/utils" @@ -109,6 +109,7 @@ interface BoxComponentProps { onDelete?: () => void isChatVariant?: boolean variant: Variant + onCancel: () => void } const BoxComponent: React.FC = ({ @@ -122,6 +123,7 @@ const BoxComponent: React.FC = ({ onDelete, isChatVariant = false, variant, + onCancel, }) => { const {appTheme} = useAppTheme() const classes = useStylesBox() @@ -208,17 +210,23 @@ const BoxComponent: React.FC = ({ disabled={loading || !result} shape="round" /> - + {loading ? ( + + ) : ( + + )} {!isChatVariant && ( @@ -276,6 +284,14 @@ const App: React.FC = ({ }> >(testList.map(() => ({cost: null, latency: null, usage: null}))) + const abortControllersRef = useRef([]) + + useEffect(() => { + return () => { + abortControllersRef.current.forEach((controller) => controller.abort()) + } + }, []) + useEffect(() => { setResultsList((prevResultsList) => { const newResultsList = testList.map((_, index) => { @@ -326,6 +342,14 @@ const App: React.FC = ({ } const handleRun = async (index: number) => { + // Cancel the existing request if it's still running + if (abortControllersRef.current[index]) { + abortControllersRef.current[index].abort() + } + + // Create a new AbortController for the current request + const controller = new AbortController() + abortControllersRef.current[index] = controller try { const testItem = testList[index] if (compareMode && !isRunning[index]) { @@ -355,20 +379,32 @@ const App: React.FC = ({ appId || "", variant.baseId || "", isChatVariant ? testItem.chat : [], + controller.signal, // Pass the signal to allow manual cancellation ) - // check if res is an object or string - if (typeof res === "string") { - setResultForIndex(res, index) - } else { - setResultForIndex(res.message, index) - setAdditionalDataList((prev) => { - const newDataList = [...prev] - newDataList[index] = {cost: res.cost, latency: res.latency, usage: res.usage} - return newDataList - }) + + // Check if the request was not cancelled + if (!controller.signal.aborted) { + // Update the result and additional data + if (typeof res === "string") { + setResultForIndex(res, index) + } else { + setResultForIndex(res.message, index) + setAdditionalDataList((prev) => { + const newDataList = [...prev] + newDataList[index] = { + cost: res.cost, + latency: res.latency, + usage: res.usage, + } + return newDataList + }) + } } } catch (e) { - setResultForIndex(`❌ ${getErrorMessage(e)}`, index) + // Check if the error is not due to cancellation + if (!controller.signal.aborted) { + setResultForIndex(`❌ ${getErrorMessage(e)}`, index) + } } finally { setIsRunning((prevState) => { const newState = [...prevState] @@ -378,11 +414,44 @@ const App: React.FC = ({ } } + const handleCancelAll = () => { + abortControllersRef.current.forEach((controller, index) => { + if (controller) { + controller.abort() + // Update the loading state to false + setIsRunning((prevState) => { + const newState = [...prevState] + newState[index] = false + return newState + }) + + // Optional: If you want to clear the result or perform additional cleanup + setResultForIndex("", index) + setAdditionalDataList((prev) => { + const newDataList = [...prev] + newDataList[index] = {cost: null, latency: null, usage: null} + return newDataList + }) + } + }) + } + + // ... + const handleRunAll = () => { + // Clear any existing abort controllers + abortControllersRef.current.forEach((controller) => controller && controller.abort()) + + // Create new abort controllers for each request + const newAbortControllers = Array(testList.length) + .fill(undefined) + .map(() => new AbortController()) + abortControllersRef.current = newAbortControllers + const funcs: Function[] = [] rootRef.current ?.querySelectorAll("[data-cy=testview-input-parameters-run-button]") - .forEach((btn) => funcs.push(() => (btn as HTMLButtonElement).click())) + .forEach((btn, index) => funcs.push(() => handleRun(index))) batchExecute(funcs) } @@ -425,6 +494,27 @@ const App: React.FC = ({ } } + const handleCancel = (index: number) => { + if (abortControllersRef.current[index]) { + abortControllersRef.current[index].abort() + } + + // Update the loading state to false + setIsRunning((prevState) => { + const newState = [...prevState] + newState[index] = false + return newState + }) + + // Optional: If you want to clear the result or perform additional cleanup + setResultForIndex("", index) + setAdditionalDataList((prev) => { + const newDataList = [...prev] + newDataList[index] = {cost: null, latency: null, usage: null} + return newDataList + }) + } + return (
@@ -440,6 +530,13 @@ const App: React.FC = ({ > Run all +
@@ -463,6 +560,7 @@ const App: React.FC = ({ onDelete={testList.length >= 2 ? () => handleDeleteRow(index) : undefined} isChatVariant={isChatVariant} variant={variant} + onCancel={() => handleCancel(index)} /> ))} - diff --git a/agenta-web/src/lib/services/api.ts b/agenta-web/src/lib/services/api.ts index 1aaccf1b75..cd5a438605 100644 --- a/agenta-web/src/lib/services/api.ts +++ b/agenta-web/src/lib/services/api.ts @@ -1,6 +1,5 @@ import useSWR from "swr" import axios from "@/lib//helpers/axiosConfig" -import ax, {CancelToken} from "axios" import { detectChatVariantFromOpenAISchema, openAISchemaToParameters, @@ -85,7 +84,7 @@ export async function callVariant( appId: string, baseId: string, chatMessages?: ChatMessage[], - signal?: AbortSignal, // New parameter for the AbortController signal + signal?: AbortSignal, ) { const isChatVariant = Array.isArray(chatMessages) && chatMessages.length > 0 // Separate input parameters into two dictionaries based on the 'input' property @@ -121,30 +120,9 @@ export async function callVariant( const appContainerURI = await getAppContainerURL(appId, undefined, baseId) - // Pass the signal to the axios request using CancelToken.source() - const {token, cancel} = CancelToken.source() - if (signal) { - signal.addEventListener("abort", () => { - // Cancel the axios request when the AbortController is aborted - cancel() - }) - } - - return ax - .post(`${appContainerURI}/generate`, requestBody, { - cancelToken: token, // Pass the CancelToken to link with the AbortController signal - }) - .then((res) => { - return res.data - }) - .catch((error) => { - if (ax.isCancel(error)) { - throw new Error("Request canceled") - } else { - // Handle other errors - throw error - } - }) + return axios.post(`${appContainerURI}/generate`, requestBody, {signal}).then((res) => { + return res.data + }) } /** From 59d09f52bdf6c57e5346a0889ca26cffc1d26f4d Mon Sep 17 00:00:00 2001 From: Kaosiso Ezealigo Date: Thu, 11 Jan 2024 12:57:51 +0100 Subject: [PATCH 3/8] revert changes and improved ui --- .../components/Playground/Views/TestView.tsx | 34 +++++++++---------- agenta-web/src/lib/services/api.ts | 8 +++-- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/agenta-web/src/components/Playground/Views/TestView.tsx b/agenta-web/src/components/Playground/Views/TestView.tsx index 0c0a342f5b..b0317321f7 100644 --- a/agenta-web/src/components/Playground/Views/TestView.tsx +++ b/agenta-web/src/components/Playground/Views/TestView.tsx @@ -211,7 +211,12 @@ const BoxComponent: React.FC = ({ shape="round" /> {loading ? ( - ) : ( @@ -380,21 +385,16 @@ const App: React.FC = ({ controller.signal, ) - if (!controller.signal.aborted) { - if (typeof res === "string") { - setResultForIndex(res, index) - } else { - setResultForIndex(res.message, index) - setAdditionalDataList((prev) => { - const newDataList = [...prev] - newDataList[index] = { - cost: res.cost, - latency: res.latency, - usage: res.usage, - } - return newDataList - }) - } + // check if res is an object or string + if (typeof res === "string") { + setResultForIndex(res, index) + } else { + setResultForIndex(res.message, index) + setAdditionalDataList((prev) => { + const newDataList = [...prev] + newDataList[index] = {cost: res.cost, latency: res.latency, usage: res.usage} + return newDataList + }) } } catch (e) { if (!controller.signal.aborted) { @@ -440,7 +440,7 @@ const App: React.FC = ({ const funcs: Function[] = [] rootRef.current ?.querySelectorAll("[data-cy=testview-input-parameters-run-button]") - .forEach((btn, index) => funcs.push(() => handleRun(index))) + .forEach((btn) => funcs.push(() => (btn as HTMLButtonElement).click())) batchExecute(funcs) } diff --git a/agenta-web/src/lib/services/api.ts b/agenta-web/src/lib/services/api.ts index cd5a438605..807be1cf90 100644 --- a/agenta-web/src/lib/services/api.ts +++ b/agenta-web/src/lib/services/api.ts @@ -88,12 +88,14 @@ export async function callVariant( ) { const isChatVariant = Array.isArray(chatMessages) && chatMessages.length > 0 // Separate input parameters into two dictionaries based on the 'input' property - const mainInputParams: Record = {} - const secondaryInputParams: Record = {} + const mainInputParams: Record = {} // Parameters with input = true + const secondaryInputParams: Record = {} // Parameters with input = false for (let key of Object.keys(inputParametersDict)) { const paramDefinition = inputParamDefinition.find((param) => param.name === key) + // If parameter definition is found and its 'input' property is false, + // then it goes to 'secondaryInputParams', otherwise to 'mainInputParams' if (paramDefinition && !paramDefinition.input) { secondaryInputParams[key] = inputParametersDict[key] } else { @@ -105,7 +107,7 @@ export async function callVariant( const optParams = optionalParameters .filter((param) => param.default) - .filter((param) => param.type !== "object") + .filter((param) => param.type !== "object") // remove dicts from optional parameters .reduce((acc: any, param) => { acc[param.name] = param.default return acc From 2429d1c1e0dd9bf5aca36721bf8abb3581788238 Mon Sep 17 00:00:00 2001 From: Kaosiso Ezealigo Date: Thu, 11 Jan 2024 13:23:41 +0100 Subject: [PATCH 4/8] conditionally change run all button to cancel all when clicked --- .../components/Playground/Views/TestView.tsx | 49 ++++++++++++++----- 1 file changed, 36 insertions(+), 13 deletions(-) diff --git a/agenta-web/src/components/Playground/Views/TestView.tsx b/agenta-web/src/components/Playground/Views/TestView.tsx index b0317321f7..e81618ba74 100644 --- a/agenta-web/src/components/Playground/Views/TestView.tsx +++ b/agenta-web/src/components/Playground/Views/TestView.tsx @@ -290,6 +290,7 @@ const App: React.FC = ({ >(testList.map(() => ({cost: null, latency: null, usage: null}))) const abortControllersRef = useRef([]) + const [isRunningAll, setIsRunningAll] = useState(false) useEffect(() => { return () => { @@ -429,7 +430,15 @@ const App: React.FC = ({ }) } - const handleRunAll = () => { + const handleRunAll = async () => { + if (isRunningAll) { + handleCancelAll() + setIsRunningAll(false) + return + } + + setIsRunningAll(true) + abortControllersRef.current.forEach((controller) => controller && controller.abort()) const newAbortControllers = Array(testList.length) @@ -442,7 +451,13 @@ const App: React.FC = ({ ?.querySelectorAll("[data-cy=testview-input-parameters-run-button]") .forEach((btn) => funcs.push(() => (btn as HTMLButtonElement).click())) - batchExecute(funcs) + try { + await batchExecute(funcs) + } catch (e) { + setIsRunningAll(false) + } finally { + setIsRunningAll(false) + } } const handleAddRow = () => { @@ -509,17 +524,25 @@ const App: React.FC = ({ - - + {!isRunningAll ? ( + + ) : ( + + )}
From 74fd7cf7f7241650c7f15b1b80c13b829ad8568e Mon Sep 17 00:00:00 2001 From: Kaosiso Ezealigo Date: Sat, 13 Jan 2024 15:50:20 +0100 Subject: [PATCH 5/8] fix: cancel logic to cancel request of clicked row --- .../components/Playground/Views/TestView.tsx | 51 ++++++++++++------- 1 file changed, 32 insertions(+), 19 deletions(-) diff --git a/agenta-web/src/components/Playground/Views/TestView.tsx b/agenta-web/src/components/Playground/Views/TestView.tsx index e81618ba74..2fd02bc0e9 100644 --- a/agenta-web/src/components/Playground/Views/TestView.tsx +++ b/agenta-web/src/components/Playground/Views/TestView.tsx @@ -216,6 +216,7 @@ const BoxComponent: React.FC = ({ type="primary" style={{backgroundColor: "#d32f2f"}} onClick={onCancel} + className={`testview-cancel-button-${testData._id}`} > Cancel @@ -410,6 +411,37 @@ const App: React.FC = ({ } } + const handleCancel = (index: number) => { + if (abortControllersRef.current[index]) { + abortControllersRef.current[index].abort() + } + + const testItem = testList[index] + setIsRunning( + (prevState) => { + const newState = [...prevState] + newState[index] = false + return newState + }, + () => { + document + .querySelectorAll(`.testview-cancel-button-${testItem._id}`) + .forEach((btn) => { + if (btn.parentElement?.id !== variant.variantId) { + ;(btn as HTMLButtonElement).click() + } + }) + }, + ) + + setResultForIndex("", index) + setAdditionalDataList((prev) => { + const newDataList = [...prev] + newDataList[index] = {cost: null, latency: null, usage: null} + return newDataList + }) + } + const handleCancelAll = () => { abortControllersRef.current.forEach((controller, index) => { if (controller) { @@ -498,25 +530,6 @@ const App: React.FC = ({ } } - const handleCancel = (index: number) => { - if (abortControllersRef.current[index]) { - abortControllersRef.current[index].abort() - } - - setIsRunning((prevState) => { - const newState = [...prevState] - newState[index] = false - return newState - }) - - setResultForIndex("", index) - setAdditionalDataList((prev) => { - const newDataList = [...prev] - newDataList[index] = {cost: null, latency: null, usage: null} - return newDataList - }) - } - return (
From 4574b1b10ffe5e58ce6d8f177c58114d1ccf057c Mon Sep 17 00:00:00 2001 From: Kaosiso Ezealigo Date: Sun, 14 Jan 2024 12:43:34 +0100 Subject: [PATCH 6/8] formatter fix --- .../src/pages/apps/[app_id]/testsets/new/upload/index.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/agenta-web/src/pages/apps/[app_id]/testsets/new/upload/index.tsx b/agenta-web/src/pages/apps/[app_id]/testsets/new/upload/index.tsx index 29f7c47337..139c45ffdc 100644 --- a/agenta-web/src/pages/apps/[app_id]/testsets/new/upload/index.tsx +++ b/agenta-web/src/pages/apps/[app_id]/testsets/new/upload/index.tsx @@ -70,8 +70,8 @@ export default function AddANewTestset() { router.push(`/apps/${appId}/testsets`) } catch (e: any) { if ( - e?.response?.data?.detail?.find( - (item: GenericObject) => item?.loc?.includes("csvdata"), + e?.response?.data?.detail?.find((item: GenericObject) => + item?.loc?.includes("csvdata"), ) ) message.error(malformedFileError) From 517ebf897f68f864b4cb2cd7183473881c9b4c23 Mon Sep 17 00:00:00 2001 From: MohammedMaaz Date: Tue, 16 Jan 2024 15:56:42 +0500 Subject: [PATCH 7/8] refactoring --- agenta-web/dev.Dockerfile | 60 ++++----- .../components/Playground/Views/TestView.tsx | 126 ++++++------------ agenta-web/src/hooks/useStateCallback.ts | 10 +- agenta-web/src/lib/services/api.ts | 12 +- 4 files changed, 85 insertions(+), 123 deletions(-) diff --git a/agenta-web/dev.Dockerfile b/agenta-web/dev.Dockerfile index 6f86dbd847..91060e8aa6 100644 --- a/agenta-web/dev.Dockerfile +++ b/agenta-web/dev.Dockerfile @@ -1,37 +1,37 @@ FROM node:18-alpine -WORKDIR /app +# WORKDIR /app -# Install dependencies based on the preferred package manager -COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./ -RUN \ - if [ -f yarn.lock ]; then yarn --frozen-lockfile; \ - elif [ -f package-lock.json ]; then npm i; \ - elif [ -f pnpm-lock.yaml ]; then yarn global add pnpm && pnpm i; \ - # Allow install without lockfile, so example works even without Node.js installed locally - else echo "Warning: Lockfile not found. It is recommended to commit lockfiles to version control." && yarn install; \ - fi +# # Install dependencies based on the preferred package manager +# COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./ +# RUN \ +# if [ -f yarn.lock ]; then yarn --frozen-lockfile; \ +# elif [ -f package-lock.json ]; then npm i; \ +# elif [ -f pnpm-lock.yaml ]; then yarn global add pnpm && pnpm i; \ +# # Allow install without lockfile, so example works even without Node.js installed locally +# else echo "Warning: Lockfile not found. It is recommended to commit lockfiles to version control." && yarn install; \ +# fi -COPY src ./src -COPY public ./public -COPY next.config.js . -COPY tsconfig.json . -COPY postcss.config.js . -COPY .env . -RUN if [ -f .env.local ]; then cp .env.local .; fi -# used in cloud -COPY sentry.* . -# Next.js collects completely anonymous telemetry data about general usage. Learn more here: https://nextjs.org/telemetry -# Uncomment the following line to disable telemetry at run time -# ENV NEXT_TELEMETRY_DISABLED 1 +# COPY src ./src +# COPY public ./public +# COPY next.config.js . +# COPY tsconfig.json . +# COPY postcss.config.js . +# COPY .env . +# RUN if [ -f .env.local ]; then cp .env.local .; fi +# # used in cloud +# COPY sentry.* . +# # Next.js collects completely anonymous telemetry data about general usage. Learn more here: https://nextjs.org/telemetry +# # Uncomment the following line to disable telemetry at run time +# # ENV NEXT_TELEMETRY_DISABLED 1 -# Note: Don't expose ports here, Compose will handle that for us +# # Note: Don't expose ports here, Compose will handle that for us -# Start Next.js in development mode based on the preferred package manager -CMD \ - if [ -f yarn.lock ]; then yarn dev; \ - elif [ -f package-lock.json ]; then npm run dev; \ - elif [ -f pnpm-lock.yaml ]; then pnpm dev; \ - else yarn dev; \ - fi +# # Start Next.js in development mode based on the preferred package manager +# CMD \ +# if [ -f yarn.lock ]; then yarn dev; \ +# elif [ -f package-lock.json ]; then npm run dev; \ +# elif [ -f pnpm-lock.yaml ]; then pnpm dev; \ +# else yarn dev; \ +# fi diff --git a/agenta-web/src/components/Playground/Views/TestView.tsx b/agenta-web/src/components/Playground/Views/TestView.tsx index 2fd02bc0e9..0e63e18b99 100644 --- a/agenta-web/src/components/Playground/Views/TestView.tsx +++ b/agenta-web/src/components/Playground/Views/TestView.tsx @@ -349,31 +349,30 @@ const App: React.FC = ({ } const handleRun = async (index: number) => { - if (abortControllersRef.current[index]) { - abortControllersRef.current[index].abort() - } - const controller = new AbortController() abortControllersRef.current[index] = controller try { const testItem = testList[index] if (compareMode && !isRunning[index]) { - setIsRunning( - (prevState) => { - const newState = [...prevState] - newState[index] = true - return newState - }, - () => { - document - .querySelectorAll(`.testview-run-button-${testItem._id}`) - .forEach((btn) => { - if (btn.parentElement?.id !== variant.variantId) { - ;(btn as HTMLButtonElement).click() - } - }) - }, - ) + let called = false + const callback = () => { + if (called) return + called = true + document + .querySelectorAll(`.testview-run-button-${testItem._id}`) + .forEach((btn) => { + if (btn.parentElement?.id !== variant.variantId) { + ;(btn as HTMLButtonElement).click() + } + }) + } + + setIsRunning((prevState) => { + const newState = [...prevState] + newState[index] = true + return newState + }, callback) + setTimeout(callback, 300) } setResultForIndex(LOADING_TEXT, index) @@ -385,6 +384,7 @@ const App: React.FC = ({ variant.baseId || "", isChatVariant ? testItem.chat : [], controller.signal, + true, ) // check if res is an object or string @@ -401,6 +401,13 @@ const App: React.FC = ({ } catch (e) { if (!controller.signal.aborted) { setResultForIndex(`❌ ${getErrorMessage(e)}`, index) + } else { + setResultForIndex("", index) + setAdditionalDataList((prev) => { + const newDataList = [...prev] + newDataList[index] = {cost: null, latency: null, usage: null} + return newDataList + }) } } finally { setIsRunning((prevState) => { @@ -415,81 +422,34 @@ const App: React.FC = ({ if (abortControllersRef.current[index]) { abortControllersRef.current[index].abort() } + if (compareMode && isRunning[index]) { + const testItem = testList[index] - const testItem = testList[index] - setIsRunning( - (prevState) => { - const newState = [...prevState] - newState[index] = false - return newState - }, - () => { - document - .querySelectorAll(`.testview-cancel-button-${testItem._id}`) - .forEach((btn) => { - if (btn.parentElement?.id !== variant.variantId) { - ;(btn as HTMLButtonElement).click() - } - }) - }, - ) - - setResultForIndex("", index) - setAdditionalDataList((prev) => { - const newDataList = [...prev] - newDataList[index] = {cost: null, latency: null, usage: null} - return newDataList - }) + document.querySelectorAll(`.testview-cancel-button-${testItem._id}`).forEach((btn) => { + if (btn.parentElement?.id !== variant.variantId) { + ;(btn as HTMLButtonElement).click() + } + }) + } } const handleCancelAll = () => { - abortControllersRef.current.forEach((controller, index) => { - if (controller) { - controller.abort() - setIsRunning((prevState) => { - const newState = [...prevState] - newState[index] = false - return newState - }) - - setResultForIndex("", index) - setAdditionalDataList((prev) => { - const newDataList = [...prev] - newDataList[index] = {cost: null, latency: null, usage: null} - return newDataList - }) - } - }) + const funcs: Function[] = [] + rootRef.current + ?.querySelectorAll("[class*=testview-cancel-button-]") + .forEach((btn) => funcs.push(() => (btn as HTMLButtonElement).click())) + batchExecute(funcs) } const handleRunAll = async () => { - if (isRunningAll) { - handleCancelAll() - setIsRunningAll(false) - return - } - - setIsRunningAll(true) - - abortControllersRef.current.forEach((controller) => controller && controller.abort()) - - const newAbortControllers = Array(testList.length) - .fill(undefined) - .map(() => new AbortController()) - abortControllersRef.current = newAbortControllers - const funcs: Function[] = [] rootRef.current ?.querySelectorAll("[data-cy=testview-input-parameters-run-button]") .forEach((btn) => funcs.push(() => (btn as HTMLButtonElement).click())) - try { - await batchExecute(funcs) - } catch (e) { - setIsRunningAll(false) - } finally { - setIsRunningAll(false) - } + setIsRunningAll(true) + await batchExecute(funcs) + setIsRunningAll(false) } const handleAddRow = () => { diff --git a/agenta-web/src/hooks/useStateCallback.ts b/agenta-web/src/hooks/useStateCallback.ts index 3a3c8c6cae..6e34c87d42 100644 --- a/agenta-web/src/hooks/useStateCallback.ts +++ b/agenta-web/src/hooks/useStateCallback.ts @@ -1,4 +1,5 @@ -import {SetStateAction, useCallback, useEffect, useRef, useState} from "react" +import {SetStateAction, useCallback, useRef, useState} from "react" +import {useUpdateEffect} from "usehooks-ts" type Callback = (value?: T) => void export type DispatchWithCallback = (value: T, callback?: Callback) => void @@ -15,7 +16,6 @@ function useStateCallback( const [state, _setState] = useState(initialState) const callbackRef = useRef>() - const isFirstCallbackCall = useRef(true) const setState = useCallback( (setStateAction: SetStateAction, callback?: Callback): void => { @@ -25,11 +25,7 @@ function useStateCallback( [], ) - useEffect(() => { - if (isFirstCallbackCall.current) { - isFirstCallbackCall.current = false - return - } + useUpdateEffect(() => { typeof callbackRef.current === "function" && callbackRef.current(state) }, [state]) diff --git a/agenta-web/src/lib/services/api.ts b/agenta-web/src/lib/services/api.ts index 807be1cf90..3b886211a1 100644 --- a/agenta-web/src/lib/services/api.ts +++ b/agenta-web/src/lib/services/api.ts @@ -85,6 +85,7 @@ export async function callVariant( baseId: string, chatMessages?: ChatMessage[], signal?: AbortSignal, + ignoreAxiosError?: boolean, ) { const isChatVariant = Array.isArray(chatMessages) && chatMessages.length > 0 // Separate input parameters into two dictionaries based on the 'input' property @@ -122,9 +123,14 @@ export async function callVariant( const appContainerURI = await getAppContainerURL(appId, undefined, baseId) - return axios.post(`${appContainerURI}/generate`, requestBody, {signal}).then((res) => { - return res.data - }) + return axios + .post(`${appContainerURI}/generate`, requestBody, { + signal, + _ignoreError: ignoreAxiosError, + } as any) + .then((res) => { + return res.data + }) } /** From e423caeac0dd920ab1ece1d152cd2642d246fd08 Mon Sep 17 00:00:00 2001 From: MohammedMaaz Date: Tue, 16 Jan 2024 16:02:53 +0500 Subject: [PATCH 8/8] reverted changes in dev.Dockerfile --- agenta-web/dev.Dockerfile | 60 +++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/agenta-web/dev.Dockerfile b/agenta-web/dev.Dockerfile index 91060e8aa6..6f86dbd847 100644 --- a/agenta-web/dev.Dockerfile +++ b/agenta-web/dev.Dockerfile @@ -1,37 +1,37 @@ FROM node:18-alpine -# WORKDIR /app +WORKDIR /app -# # Install dependencies based on the preferred package manager -# COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./ -# RUN \ -# if [ -f yarn.lock ]; then yarn --frozen-lockfile; \ -# elif [ -f package-lock.json ]; then npm i; \ -# elif [ -f pnpm-lock.yaml ]; then yarn global add pnpm && pnpm i; \ -# # Allow install without lockfile, so example works even without Node.js installed locally -# else echo "Warning: Lockfile not found. It is recommended to commit lockfiles to version control." && yarn install; \ -# fi +# Install dependencies based on the preferred package manager +COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./ +RUN \ + if [ -f yarn.lock ]; then yarn --frozen-lockfile; \ + elif [ -f package-lock.json ]; then npm i; \ + elif [ -f pnpm-lock.yaml ]; then yarn global add pnpm && pnpm i; \ + # Allow install without lockfile, so example works even without Node.js installed locally + else echo "Warning: Lockfile not found. It is recommended to commit lockfiles to version control." && yarn install; \ + fi -# COPY src ./src -# COPY public ./public -# COPY next.config.js . -# COPY tsconfig.json . -# COPY postcss.config.js . -# COPY .env . -# RUN if [ -f .env.local ]; then cp .env.local .; fi -# # used in cloud -# COPY sentry.* . -# # Next.js collects completely anonymous telemetry data about general usage. Learn more here: https://nextjs.org/telemetry -# # Uncomment the following line to disable telemetry at run time -# # ENV NEXT_TELEMETRY_DISABLED 1 +COPY src ./src +COPY public ./public +COPY next.config.js . +COPY tsconfig.json . +COPY postcss.config.js . +COPY .env . +RUN if [ -f .env.local ]; then cp .env.local .; fi +# used in cloud +COPY sentry.* . +# Next.js collects completely anonymous telemetry data about general usage. Learn more here: https://nextjs.org/telemetry +# Uncomment the following line to disable telemetry at run time +# ENV NEXT_TELEMETRY_DISABLED 1 -# # Note: Don't expose ports here, Compose will handle that for us +# Note: Don't expose ports here, Compose will handle that for us -# # Start Next.js in development mode based on the preferred package manager -# CMD \ -# if [ -f yarn.lock ]; then yarn dev; \ -# elif [ -f package-lock.json ]; then npm run dev; \ -# elif [ -f pnpm-lock.yaml ]; then pnpm dev; \ -# else yarn dev; \ -# fi +# Start Next.js in development mode based on the preferred package manager +CMD \ + if [ -f yarn.lock ]; then yarn dev; \ + elif [ -f package-lock.json ]; then npm run dev; \ + elif [ -f pnpm-lock.yaml ]; then pnpm dev; \ + else yarn dev; \ + fi