diff --git a/src/frontend/src/App.tsx b/src/frontend/src/App.tsx
index f68c3ea73..e081cf490 100644
--- a/src/frontend/src/App.tsx
+++ b/src/frontend/src/App.tsx
@@ -14,6 +14,7 @@ import TabsManagerComponent from "./pages/FlowPage/components/tabsManagerCompone
import { ErrorBoundary } from "react-error-boundary";
import CrashErrorComponent from "./components/CrashErrorComponent";
import { TabsContext } from "./contexts/tabsContext";
+import { getVersion } from "./controllers/API";
export default function App() {
let { setCurrent, setShowSideBar, setIsStackedOpen } =
@@ -49,11 +50,9 @@ export default function App() {
// Initialize state variable for the version
const [version, setVersion] = useState("");
useEffect(() => {
- fetch("/version")
- .then((res) => res.json())
- .then((data) => {
- setVersion(data.version);
- });
+ getVersion().then((response) => {
+ setVersion(response.data.version);
+ });
}, []);
// Use effect hook to update alertsList when a new alert is added
useEffect(() => {
diff --git a/src/frontend/src/CustomNodes/GenericNode/index.tsx b/src/frontend/src/CustomNodes/GenericNode/index.tsx
index 86eaf299d..c449296ef 100644
--- a/src/frontend/src/CustomNodes/GenericNode/index.tsx
+++ b/src/frontend/src/CustomNodes/GenericNode/index.tsx
@@ -33,6 +33,7 @@ import { NodeToolbar } from "reactflow";
import NodeToolbarComponent from "../../pages/FlowPage/components/nodeToolbarComponent";
import ShadTooltip from "../../components/ShadTooltipComponent";
+import { postValidateNode } from "../../controllers/API";
export default function GenericNode({
data,
selected,
@@ -62,17 +63,13 @@ export default function GenericNode({
const validateNode = useCallback(
debounce(async () => {
try {
- const response = await fetch(`/validate/node/${data.id}`, {
- method: "POST",
- headers: {
- "Content-Type": "application/json",
- },
- body: JSON.stringify(reactFlowInstance.toObject()),
- });
+ const response = await postValidateNode(
+ data.id,
+ reactFlowInstance.toObject()
+ );
if (response.status === 200) {
- let jsonResponse = await response.json();
- let jsonResponseParsed = await JSON.parse(jsonResponse);
+ let jsonResponseParsed = await JSON.parse(response.data);
setValidationStatus(jsonResponseParsed);
}
} catch (error) {
@@ -148,11 +145,10 @@ export default function GenericNode({
"Validating..."
) : (
- {validationStatus.params
- .split("\n")
- .map((line, index) => (
-
{line}
- ))}
+ {validationStatus.params ||
+ ""
+ .split("\n")
+ .map((line, index) =>
{line}
)}
)
}
diff --git a/src/frontend/src/components/intComponent/index.tsx b/src/frontend/src/components/intComponent/index.tsx
index e643eb5e9..00a4bf606 100644
--- a/src/frontend/src/components/intComponent/index.tsx
+++ b/src/frontend/src/components/intComponent/index.tsx
@@ -34,7 +34,7 @@ export default function IntComponent({
if (disableCopyPaste) setDisableCopyPaste(false);
}}
onKeyDown={(event) => {
- console.log(event);
+ // console.log(event);
if (
event.key !== "Backspace" &&
event.key !== "Enter" &&
diff --git a/src/frontend/src/contexts/tabsContext.tsx b/src/frontend/src/contexts/tabsContext.tsx
index 9ef27b203..800027ede 100644
--- a/src/frontend/src/contexts/tabsContext.tsx
+++ b/src/frontend/src/contexts/tabsContext.tsx
@@ -69,12 +69,12 @@ export function TabsProvider({ children }: { children: ReactNode }) {
Saveflows.forEach((flow) => {
if (flow.data && flow.data?.nodes)
flow.data?.nodes.forEach((node) => {
- console.log(node.data.type);
+ // console.log(node.data.type);
//looking for file fields to prevent saving the content and breaking the flow for exceeding the the data limite for local storage
Object.keys(node.data.node.template).forEach((key) => {
- console.log(node.data.node.template[key].type);
+ // console.log(node.data.node.template[key].type);
if (node.data.node.template[key].type === "file") {
- console.log(node.data.node.template[key]);
+ // console.log(node.data.node.template[key]);
node.data.node.template[key].content = null;
node.data.node.template[key].value = "";
}
@@ -139,7 +139,7 @@ export function TabsProvider({ children }: { children: ReactNode }) {
useEffect(() => {
//save tabs locally
- console.log(id);
+ // console.log(id);
save();
}, [flows, id, tabIndex, newNodeId]);
diff --git a/src/frontend/src/controllers/API/index.ts b/src/frontend/src/controllers/API/index.ts
index ffa9eef72..794d3aa97 100644
--- a/src/frontend/src/controllers/API/index.ts
+++ b/src/frontend/src/controllers/API/index.ts
@@ -3,24 +3,52 @@ import { APIObjectType, sendAllProps } from "../../types/api/index";
import axios, { AxiosResponse } from "axios";
import { FlowType } from "../../types/flow";
+// when serving with static files
+// We need to add /api/v1/ to the url in the axios calls
+
+/**
+ * Retrieves all data from the API.
+ * @returns {Promise>} A promise that resolves to an AxiosResponse object containing the API data.
+ */
export async function getAll(): Promise> {
- return await axios.get(`/all`);
+ return await axios.get(`/api/v1/all`);
}
export async function sendAll(data: sendAllProps) {
- return await axios.post(`/predict`, data);
+ return await axios.post(`/api/v1/predict`, data);
}
-export async function checkCode(
+export async function postValidateCode(
code: string
): Promise> {
- return await axios.post("/validate/code", { code });
+ return await axios.post("/api/v1/validate/code", { code });
+}
+
+export async function postValidateNode(
+ nodeId: string,
+ data: any
+): Promise> {
+ return await axios.post(`/api/v1/validate/node/${nodeId}`, { data });
}
export async function checkPrompt(
template: string
): Promise> {
- return await axios.post("/validate/prompt", { template });
+ return await axios.post("/api/v1/validate/prompt", { template });
+}
+
+/**
+ * Retrieves the version of the API.
+ * @returns {Promise>} A promise that resolves to an AxiosResponse object containing the API version.
+ * @example
+ * const response = await getVersion();
+ * console.log(response.data.version);
+ * // 0.1.0
+ */
+export async function getVersion(): Promise<
+ AxiosResponse<{ version: string }>
+> {
+ return await axios.get("/api/v1/version");
}
export async function getExamples(): Promise {
diff --git a/src/frontend/src/modals/EditNodeModal/index.tsx b/src/frontend/src/modals/EditNodeModal/index.tsx
index f6f4d9111..4c9422afb 100644
--- a/src/frontend/src/modals/EditNodeModal/index.tsx
+++ b/src/frontend/src/modals/EditNodeModal/index.tsx
@@ -87,7 +87,7 @@ export default function EditNodeModal({ data }: { data: NodeDataType }) {
setNodeValue(!nodeValue);
}
- console.log(data.node.template);
+ // console.log(data.node.template);
return (