"use client"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { TrashIcon, VariableIcon } from "lucide-react"; import { HttpValue, OutputSchemaSourceKey, } from "lib/ai/workflow/workflow.interface"; import { VariableSelect } from "./variable-select"; import { useReactFlow } from "@xyflow/react"; import { UINode } from "lib/ai/workflow/workflow.interface"; import { Tooltip, TooltipContent, TooltipTrigger } from "ui/tooltip"; import { VariableMentionItem } from "./variable-mention-item"; import { findAvailableSchemaBySource } from "lib/ai/workflow/shared.workflow"; import { useTranslations } from "next-intl"; import { cn, exclude } from "lib/utils"; interface HttpValueInputProps { value: HttpValue | undefined; onChange: (value: HttpValue | undefined) => void; onDelete?: () => void; placeholder?: string; currentNodeId: string; allowedTypes?: string[]; className?: string; } export function HttpValueInput({ value, onChange, placeholder, currentNodeId, allowedTypes = [], onDelete, className, }: HttpValueInputProps) { const { getNodes, getEdges } = useReactFlow(); const t = useTranslations("Workflow"); // Check if current value is a variable reference const isVariable = value && typeof value === "object" && "nodeId" in value; // Get the node name for display if it's a variable const getVariable = (sourceKey: OutputSchemaSourceKey) => { const data = findAvailableSchemaBySource({ nodeId: currentNodeId, source: sourceKey, nodes: getNodes().map((node) => node.data), edges: getEdges(), }); return exclude(data, ["type"]); }; const handleLiteralChange = (inputValue: string) => { if (inputValue === "") { onChange(undefined); return; } onChange(inputValue); }; const handleVariableSelect = (item: { nodeId: string; path: string[]; nodeName: string; type: string; }) => { onChange({ nodeId: item.nodeId, path: item.path, }); }; return (
{isVariable ? (
onChange(undefined)} />
) : ( handleLiteralChange(e.target.value)} placeholder={placeholder} /> )}

{t("selectVariable")}

{onDelete && ( )}
); }