"use client"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { Label } from "@/components/ui/label"; import { Input } from "@/components/ui/input"; import { Button } from "@/components/ui/button"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@/components/ui/select"; import { Link, Plus, TriangleAlertIcon, VariableIcon } from "lucide-react"; import { HttpNodeData, HttpMethod, OutputSchemaSourceKey, } from "lib/ai/workflow/workflow.interface"; import { UINode } from "lib/ai/workflow/workflow.interface"; import { HttpValueInput } from "../http-value-input"; import { useState } from "react"; import { useReactFlow } from "@xyflow/react"; import { capitalizeFirstLetter, cn } from "lib/utils"; import { Textarea } from "ui/textarea"; import { VariableSelect } from "../variable-select"; import { VariableMentionItem } from "../variable-mention-item"; import { findAvailableSchemaBySource } from "lib/ai/workflow/shared.workflow"; const HTTP_METHODS: HttpMethod[] = [ "GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", ]; const tabs = ["basic", "headers", "query", "body"] as const; const headerExample = [ { key: "Content-Type", value: "application/json", }, { key: "Authorization", value: "Bearer ", }, { key: "X-API-Key", value: "1234567890", }, ]; const queryExample = [ { key: "page", value: "1", }, { key: "limit", value: "10", }, { key: "sort", value: "created_at", }, ]; export function HttpNodeConfig({ node }: { node: UINode }) { const httpNode = node.data as HttpNodeData; const [activeTab, setActiveTab] = useState<(typeof tabs)[number]>("basic"); const { updateNodeData, getNodes, getEdges } = useReactFlow(); const handleUpdateNode = (updates: Partial) => { updateNodeData(node.id, updates); }; const addHeader = () => { const currentHeaders = httpNode.headers || []; handleUpdateNode({ headers: [...currentHeaders, { key: "", value: undefined }], }); }; const updateHeader = (index: number, key: string, value?: any) => { const currentHeaders = httpNode.headers || []; const newHeaders = [...currentHeaders]; newHeaders[index] = { key, value }; handleUpdateNode({ headers: newHeaders }); }; const removeHeader = (index: number) => { const currentHeaders = httpNode.headers || []; const newHeaders = currentHeaders.filter((_, i) => i !== index); handleUpdateNode({ headers: newHeaders }); }; const addQueryParam = () => { const currentQuery = httpNode.query || []; handleUpdateNode({ query: [...currentQuery, { key: "", value: undefined }], }); }; const updateQueryParam = (index: number, key: string, value?: any) => { const currentQuery = httpNode.query || []; const newQuery = [...currentQuery]; newQuery[index] = { key, value }; handleUpdateNode({ query: newQuery }); }; const removeQueryParam = (index: number) => { const currentQuery = httpNode.query || []; const newQuery = currentQuery.filter((_, i) => i !== index); handleUpdateNode({ query: newQuery }); }; const isBodyVariable = httpNode.body && typeof httpNode.body === "object" && "nodeId" in httpNode.body; return (
{/* Tab Navigation */}
{tabs.map((tab) => ( ))}
{activeTab === "basic" ? "HTTP Request Configuration" : activeTab === "headers" ? "Request Headers" : activeTab === "query" ? "Query Parameters" : "Request Body"} {activeTab === "basic" && ( {/* HTTP Method */}
{/* URL */}
handleUpdateNode({ url: value })} placeholder="https://api.example.com/endpoint" />
{/* Timeout */}
handleUpdateNode({ timeout: parseInt(e.target.value) || 30000, }) } min={1000} max={300000} step={1000} />

Request timeout in milliseconds (1s - 5min)

)} {/* Headers Configuration */} {activeTab === "headers" && ( {(httpNode.headers || []).map((header, index) => (
updateHeader(index, e.target.value, header.value) } placeholder={headerExample[index]?.key} />
updateHeader(index, header.key, value)} placeholder={headerExample[index]?.value} onDelete={() => removeHeader(index)} />
))}
)} {/* Query Parameters Configuration */} {activeTab === "query" && ( {(httpNode.query || []).map((param, index) => (
updateQueryParam(index, e.target.value, param.value) } placeholder={queryExample[index]?.key} />
updateQueryParam(index, param.key, value) } placeholder={queryExample[index]?.value} onDelete={() => removeQueryParam(index)} />
))}
)} {/* Body Configuration */} {activeTab === "body" && ( {["POST", "PUT", "PATCH"].includes(httpNode.method) ? (
handleUpdateNode({ body: value })} >
{!isBodyVariable ? (