/** * Modal to add fallbacks to the proxy router config */ import React, { useState, useEffect, useRef } from "react"; import { Button, TextInput, Grid, Col } from "@tremor/react"; import { Select, SelectItem, MultiSelect, MultiSelectItem, Card, Metric, Text, Title, Subtitle, Accordion, AccordionHeader, AccordionBody, } from "@tremor/react"; import { CopyToClipboard } from 'react-copy-to-clipboard'; import { createPassThroughEndpoint } from "./networking"; import { Button as Button2, Modal, Form, Input, InputNumber, Select as Select2, message, } from "antd"; import { keyCreateCall, slackBudgetAlertsHealthCheck, modelAvailableCall } from "./networking"; import { list } from "postcss"; import KeyValueInput from "./key_value_input"; import { passThroughItem } from "./pass_through_settings"; const { Option } = Select2; interface AddFallbacksProps { // models: string[] | undefined; accessToken: string; passThroughItems: passThroughItem[]; setPassThroughItems: React.Dispatch>; } const AddPassThroughEndpoint: React.FC = ({ accessToken, setPassThroughItems, passThroughItems }) => { const [form] = Form.useForm(); const [isModalVisible, setIsModalVisible] = useState(false); const [selectedModel, setSelectedModel] = useState(""); const handleOk = () => { setIsModalVisible(false); form.resetFields(); }; const handleCancel = () => { setIsModalVisible(false); form.resetFields(); }; const addPassThrough = (formValues: Record) => { // Print the received value console.log(formValues); // // Extract model_name and models from formValues // const { model_name, models } = formValues; // // Create new fallback // const newFallback = { [model_name]: models }; // // Get current fallbacks, or an empty array if it's null // const currentFallbacks = routerSettings.fallbacks || []; // // Add new fallback to the current fallbacks // const updatedFallbacks = [...currentFallbacks, newFallback]; // // Create a new routerSettings object with updated fallbacks // const updatedRouterSettings = { ...routerSettings, fallbacks: updatedFallbacks }; const newPassThroughItem: passThroughItem = { "headers": formValues["headers"], "path": formValues["path"], "target": formValues["target"] } const updatedPassThroughSettings = [...passThroughItems, newPassThroughItem] try { createPassThroughEndpoint(accessToken, formValues); setPassThroughItems(updatedPassThroughSettings) } catch (error) { message.error("Failed to update router settings: " + error, 20); } message.success("Pass through endpoint successfully added"); setIsModalVisible(false) form.resetFields(); }; return (
<>
Add Pass-Through Endpoint
); }; export default AddPassThroughEndpoint;