Commit inicial - upload de todos os arquivos da pasta

This commit is contained in:
2026-01-04 16:14:31 -03:00
commit e3ed1a734b
310 changed files with 62749 additions and 0 deletions

View File

@@ -0,0 +1,283 @@
/*
┌──────────────────────────────────────────────────────────────────────────────┐
│ @author: Davidson Gomes │
│ @file: /app/agents/workflows/nodes/components/condition/ConditionDialog.tsx │
│ Developed by: Davidson Gomes │
│ Creation date: May 13, 2025 │
│ Contact: contato@evolution-api.com │
├──────────────────────────────────────────────────────────────────────────────┤
│ @copyright © Evolution API 2025. All rights reserved. │
│ Licensed under the Apache License, Version 2.0 │
│ │
│ You may not use this file except in compliance with the License. │
│ You may obtain a copy of the License at │
│ │
│ http://www.apache.org/licenses/LICENSE-2.0 │
│ │
│ Unless required by applicable law or agreed to in writing, software │
│ distributed under the License is distributed on an "AS IS" BASIS, │
│ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. │
│ See the License for the specific language governing permissions and │
│ limitations under the License. │
├──────────────────────────────────────────────────────────────────────────────┤
│ @important │
│ For any future changes to the code in this file, it is recommended to │
│ include, together with the modification, the information of the developer │
│ who changed it and the date of modification. │
└──────────────────────────────────────────────────────────────────────────────┘
*/
/* eslint-disable no-unused-vars */
/* eslint-disable @typescript-eslint/no-explicit-any */
import { useState } from "react";
import { v4 as uuidv4 } from "uuid";
import {
Dialog,
DialogContent,
DialogHeader,
DialogTitle,
DialogFooter
} from "@/components/ui/dialog";
import { ConditionType, ConditionTypeEnum } from "../../nodeFunctions";
import { Button } from "@/components/ui/button";
import { Filter, ArrowRight } from "lucide-react";
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue
} from "@/components/ui/select";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
import { Badge } from "@/components/ui/badge";
const conditionTypes = [
{
id: "previous-output",
name: "Previous output",
description: "Validate the result returned by the previous node",
icon: <Filter className="h-5 w-5 text-blue-400" />,
color: "bg-blue-900/30 border-blue-700/50",
},
];
const operators = [
{ value: "is_defined", label: "is defined" },
{ value: "is_not_defined", label: "is not defined" },
{ value: "equals", label: "is equal to" },
{ value: "not_equals", label: "is not equal to" },
{ value: "contains", label: "contains" },
{ value: "not_contains", label: "does not contain" },
{ value: "starts_with", label: "starts with" },
{ value: "ends_with", label: "ends with" },
{ value: "greater_than", label: "is greater than" },
{ value: "greater_than_or_equal", label: "is greater than or equal to" },
{ value: "less_than", label: "is less than" },
{ value: "less_than_or_equal", label: "is less than or equal to" },
{ value: "matches", label: "matches the regex" },
{ value: "not_matches", label: "does not match the regex" },
];
const outputFields = [
{ value: "content", label: "Content" },
{ value: "status", label: "Status" },
];
function ConditionDialog({
open,
onOpenChange,
selectedNode,
handleUpdateNode,
}: {
open: boolean;
onOpenChange: (open: boolean) => void;
selectedNode: any;
handleUpdateNode: any;
}) {
const [selectedType, setSelectedType] = useState("previous-output");
const [selectedField, setSelectedField] = useState(outputFields[0].value);
const [selectedOperator, setSelectedOperator] = useState(operators[0].value);
const [comparisonValue, setComparisonValue] = useState("");
const handleConditionSave = (condition: ConditionType) => {
const newConditions = selectedNode.data.conditions
? [...selectedNode.data.conditions]
: [];
newConditions.push(condition);
const updatedNode = {
...selectedNode,
data: {
...selectedNode.data,
conditions: newConditions,
},
};
handleUpdateNode(updatedNode);
onOpenChange(false);
};
const getOperatorLabel = (value: string) => {
return operators.find(op => op.value === value)?.label || value;
};
const getFieldLabel = (value: string) => {
return outputFields.find(field => field.value === value)?.label || value;
};
return (
<Dialog open={open} onOpenChange={onOpenChange}>
<DialogContent className="bg-neutral-800 border-neutral-700 text-neutral-200 sm:max-w-[650px]">
<DialogHeader>
<DialogTitle>Add New Condition</DialogTitle>
</DialogHeader>
<div className="grid gap-6 py-4">
<div className="grid gap-4">
<Label className="text-sm font-medium">Condition Type</Label>
<div className="grid grid-cols-1 gap-2">
{conditionTypes.map((type) => (
<div
key={type.id}
className={`flex items-center space-x-3 rounded-md border p-3 cursor-pointer transition-all ${
selectedType === type.id
? "bg-blue-900/30 border-blue-600"
: "border-neutral-700 hover:border-blue-700/50 hover:bg-neutral-700/50"
}`}
onClick={() => setSelectedType(type.id)}
>
<div className="flex h-10 w-10 items-center justify-center rounded-full bg-blue-900/40">
{type.icon}
</div>
<div className="flex-1">
<h4 className="font-medium">{type.name}</h4>
<p className="text-xs text-neutral-400">{type.description}</p>
</div>
{selectedType === type.id && (
<Badge className="bg-blue-600 text-neutral-100">Selected</Badge>
)}
</div>
))}
</div>
</div>
<div className="grid gap-4">
<div className="flex items-center justify-between">
<Label className="text-sm font-medium">Configuration</Label>
{selectedType === "previous-output" && (
<div className="flex items-center gap-2 text-sm text-neutral-400">
<span>Output field</span>
<ArrowRight className="h-3 w-3" />
<span>Operator</span>
{!["is_defined", "is_not_defined"].includes(selectedOperator) && (
<>
<ArrowRight className="h-3 w-3" />
<span>Value</span>
</>
)}
</div>
)}
</div>
{selectedType === "previous-output" && (
<div className="space-y-4">
<div className="grid gap-2">
<Label htmlFor="field">Output Field</Label>
<Select
value={selectedField}
onValueChange={setSelectedField}
>
<SelectTrigger id="field" className="bg-neutral-700 border-neutral-600">
<SelectValue placeholder="Select field" />
</SelectTrigger>
<SelectContent className="bg-neutral-700 border-neutral-600">
{outputFields.map((field) => (
<SelectItem key={field.value} value={field.value}>
{field.label}
</SelectItem>
))}
</SelectContent>
</Select>
</div>
<div className="grid gap-2">
<Label htmlFor="operator">Operator</Label>
<Select
value={selectedOperator}
onValueChange={setSelectedOperator}
>
<SelectTrigger id="operator" className="bg-neutral-700 border-neutral-600">
<SelectValue placeholder="Select operator" />
</SelectTrigger>
<SelectContent className="bg-neutral-700 border-neutral-600">
{operators.map((op) => (
<SelectItem key={op.value} value={op.value}>
{op.label}
</SelectItem>
))}
</SelectContent>
</Select>
</div>
{!["is_defined", "is_not_defined"].includes(selectedOperator) && (
<div className="grid gap-2">
<Label htmlFor="value">Comparison Value</Label>
<Input
id="value"
value={comparisonValue}
onChange={(e) => setComparisonValue(e.target.value)}
className="bg-neutral-700 border-neutral-600"
/>
</div>
)}
<div className="rounded-md bg-neutral-700/50 border border-neutral-600 p-3 mt-4">
<div className="text-sm font-medium text-neutral-400 mb-1">Preview</div>
<div className="text-sm">
<span className="text-blue-400 font-medium">{getFieldLabel(selectedField)}</span>
{" "}
<span className="text-neutral-300">{getOperatorLabel(selectedOperator)}</span>
{" "}
{!["is_defined", "is_not_defined"].includes(selectedOperator) && (
<span className="text-emerald-400 font-medium">"{comparisonValue || "(empty)"}"</span>
)}
</div>
</div>
</div>
)}
</div>
</div>
<DialogFooter>
<Button
variant="outline"
onClick={() => onOpenChange(false)}
className="border-neutral-600 text-neutral-200 hover:bg-neutral-700"
>
Cancel
</Button>
<Button
onClick={() => {
handleConditionSave({
id: uuidv4(),
type: ConditionTypeEnum.PREVIOUS_OUTPUT,
data: {
field: selectedField,
operator: selectedOperator,
value: comparisonValue,
},
});
}}
className="bg-blue-700 hover:bg-blue-600 text-white"
>
Add Condition
</Button>
</DialogFooter>
</DialogContent>
</Dialog>
);
}
export { ConditionDialog };

View File

@@ -0,0 +1,290 @@
/*
┌──────────────────────────────────────────────────────────────────────────────┐
│ @author: Davidson Gomes │
│ @file: /app/agents/workflows/nodes/components/condition/ConditionForm.tsx │
│ Developed by: Davidson Gomes │
│ Creation date: May 13, 2025 │
│ Contact: contato@evolution-api.com │
├──────────────────────────────────────────────────────────────────────────────┤
│ @copyright © Evolution API 2025. All rights reserved. │
│ Licensed under the Apache License, Version 2.0 │
│ │
│ You may not use this file except in compliance with the License. │
│ You may obtain a copy of the License at │
│ │
│ http://www.apache.org/licenses/LICENSE-2.0 │
│ │
│ Unless required by applicable law or agreed to in writing, software │
│ distributed under the License is distributed on an "AS IS" BASIS, │
│ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. │
│ See the License for the specific language governing permissions and │
│ limitations under the License. │
├──────────────────────────────────────────────────────────────────────────────┤
│ @important │
│ For any future changes to the code in this file, it is recommended to │
│ include, together with the modification, the information of the developer │
│ who changed it and the date of modification. │
└──────────────────────────────────────────────────────────────────────────────┘
*/
import { useEffect, useState } from "react";
import {
Dialog,
DialogContent,
DialogFooter,
DialogHeader,
DialogTitle,
} from "@/components/ui/dialog";
import { ConditionType, ConditionTypeEnum } from "../../nodeFunctions";
import { ConditionDialog } from "./ConditionDialog";
import { Button } from "@/components/ui/button";
import { Filter, Trash2, Plus } from "lucide-react";
import { Badge } from "@/components/ui/badge";
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
/* eslint-disable @typescript-eslint/no-explicit-any */
function ConditionForm({
selectedNode,
handleUpdateNode,
}: {
selectedNode: any;
handleUpdateNode: any;
setEdges: any;
setIsOpen: any;
setSelectedNode: any;
}) {
const [node, setNode] = useState(selectedNode);
const [conditions, setConditions] = useState<ConditionType[]>(
selectedNode.data.conditions || []
);
const [open, setOpen] = useState(false);
const [deleteDialog, setDeleteDialog] = useState(false);
const [conditionToDelete, setConditionToDelete] =
useState<ConditionType | null>(null);
useEffect(() => {
if (selectedNode) {
setNode(selectedNode);
setConditions(selectedNode.data.conditions || []);
}
}, [selectedNode]);
const handleDelete = (condition: ConditionType) => {
setConditionToDelete(condition);
setDeleteDialog(true);
};
const confirmDelete = () => {
if (!conditionToDelete) return;
const newConditions = conditions.filter(
(c) => c.id !== conditionToDelete.id
);
setConditions(newConditions);
handleUpdateNode({
...node,
data: { ...node.data, conditions: newConditions },
});
setDeleteDialog(false);
setConditionToDelete(null);
};
const renderCondition = (condition: ConditionType) => {
if (condition.type === ConditionTypeEnum.PREVIOUS_OUTPUT) {
type OperatorType =
| "is_defined"
| "is_not_defined"
| "equals"
| "not_equals"
| "contains"
| "not_contains"
| "starts_with"
| "ends_with"
| "greater_than"
| "greater_than_or_equal"
| "less_than"
| "less_than_or_equal"
| "matches"
| "not_matches";
const operatorText: Record<OperatorType, string> = {
is_defined: "is defined",
is_not_defined: "is not defined",
equals: "is equal to",
not_equals: "is not equal to",
contains: "contains",
not_contains: "does not contain",
starts_with: "starts with",
ends_with: "ends with",
greater_than: "is greater than",
greater_than_or_equal: "is greater than or equal to",
less_than: "is less than",
less_than_or_equal: "is less than or equal to",
matches: "matches the regex",
not_matches: "does not match the regex",
};
return (
<div
key={condition.id}
className="p-3 rounded-md cursor-pointer transition-colors bg-neutral-800 hover:bg-neutral-700 border border-neutral-700 mb-2 group"
>
<div className="flex items-start gap-2">
<div className="bg-blue-900/50 rounded-full p-1.5 flex-shrink-0">
<Filter size={18} className="text-blue-300" />
</div>
<div className="flex-1 min-w-0">
<div className="flex items-center justify-between">
<h3 className="font-medium text-neutral-200">Condition</h3>
<Button
variant="ghost"
size="icon"
onClick={() => handleDelete(condition)}
className="h-7 w-7 text-neutral-400 opacity-0 group-hover:opacity-100 hover:text-red-500 hover:bg-red-900/20"
>
<Trash2 size={14} />
</Button>
</div>
<div className="flex items-center gap-2 mt-1">
<Badge
variant="outline"
className="text-xs bg-blue-900/20 text-blue-400 border-blue-700/50"
>
Field
</Badge>
<span className="text-sm text-neutral-300 font-medium">{condition.data.field}</span>
</div>
<div className="flex flex-wrap items-center gap-1 mt-1.5">
<span className="text-sm text-neutral-400">{operatorText[condition.data.operator as OperatorType]}</span>
{!["is_defined", "is_not_defined"].includes(condition.data.operator) && (
<span className="text-sm font-medium text-emerald-400">
"{condition.data.value}"
</span>
)}
</div>
</div>
</div>
</div>
);
}
return null;
};
return (
<div className="flex flex-col h-full">
<div className="p-4 border-b border-neutral-700 flex-shrink-0">
<div className="flex items-center justify-between">
<div className="flex items-center gap-2">
<h3 className="text-md font-medium text-neutral-200">Logic Type</h3>
<Badge
variant="outline"
className="text-xs bg-blue-900/20 text-blue-400 border-blue-700/50"
>
{node.data.type === "or" ? "ANY" : "ALL"}
</Badge>
</div>
<Select
value={node.data.type || "and"}
onValueChange={(value) => {
const updatedNode = {
...node,
data: {
...node.data,
type: value,
},
};
setNode(updatedNode);
handleUpdateNode(updatedNode);
}}
>
<SelectTrigger className="w-[120px] h-8 bg-neutral-800 border-neutral-700 text-neutral-200">
<SelectValue placeholder="Select type" />
</SelectTrigger>
<SelectContent className="bg-neutral-800 border-neutral-700 text-neutral-200">
<SelectItem value="and">ALL (AND)</SelectItem>
<SelectItem value="or">ANY (OR)</SelectItem>
</SelectContent>
</Select>
</div>
<p className="text-sm text-neutral-400 mt-2">
{node.data.type === "or"
? "Any of the following conditions must be true to proceed."
: "All of the following conditions must be true to proceed."}
</p>
</div>
<div className="flex-1 overflow-y-auto px-4 py-4 min-h-0">
<div className="mb-4">
<div className="flex items-center justify-between mb-3">
<h3 className="text-md font-medium text-neutral-200">Conditions</h3>
<Button
variant="outline"
size="sm"
className="h-8 bg-blue-800/20 hover:bg-blue-700/30 border-blue-700/50 text-blue-300"
onClick={() => setOpen(true)}
>
<Plus size={14} className="mr-1" />
Add Condition
</Button>
</div>
{conditions.length > 0 ? (
<div className="space-y-2">
{conditions.map((condition) => renderCondition(condition))}
</div>
) : (
<div
onClick={() => setOpen(true)}
className="flex flex-col items-center justify-center p-6 rounded-lg border-2 border-dashed border-neutral-700 hover:border-blue-600/50 hover:bg-neutral-800/50 transition-colors cursor-pointer text-center"
>
<Filter className="h-10 w-10 text-neutral-500 mb-2" />
<p className="text-neutral-400">No conditions yet</p>
<p className="text-sm text-neutral-500 mt-1">Click to add a condition</p>
</div>
)}
</div>
</div>
<ConditionDialog
open={open}
onOpenChange={setOpen}
selectedNode={selectedNode}
handleUpdateNode={handleUpdateNode}
/>
<Dialog open={deleteDialog} onOpenChange={setDeleteDialog}>
<DialogContent className="bg-neutral-800 border-neutral-700 text-neutral-200">
<DialogHeader>
<DialogTitle>Confirm Delete</DialogTitle>
</DialogHeader>
<div className="py-4">
<p>Are you sure you want to delete this condition?</p>
</div>
<DialogFooter>
<Button
variant="outline"
className="border-neutral-600 text-neutral-300 hover:bg-neutral-700"
onClick={() => {
setDeleteDialog(false);
setConditionToDelete(null);
}}
>
Cancel
</Button>
<Button
variant="destructive"
className="bg-red-900 hover:bg-red-800 text-white"
onClick={confirmDelete}
>
Delete
</Button>
</DialogFooter>
</DialogContent>
</Dialog>
</div>
);
}
export { ConditionForm };

View File

@@ -0,0 +1,204 @@
/*
┌──────────────────────────────────────────────────────────────────────────────┐
│ @author: Davidson Gomes │
│ @file: /app/agents/workflows/nodes/components/condition/ConditionNode.tsx │
│ Developed by: Davidson Gomes │
│ Creation date: May 13, 2025 │
│ Contact: contato@evolution-api.com │
├──────────────────────────────────────────────────────────────────────────────┤
│ @copyright © Evolution API 2025. All rights reserved. │
│ Licensed under the Apache License, Version 2.0 │
│ │
│ You may not use this file except in compliance with the License. │
│ You may obtain a copy of the License at │
│ │
│ http://www.apache.org/licenses/LICENSE-2.0 │
│ │
│ Unless required by applicable law or agreed to in writing, software │
│ distributed under the License is distributed on an "AS IS" BASIS, │
│ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. │
│ See the License for the specific language governing permissions and │
│ limitations under the License. │
├──────────────────────────────────────────────────────────────────────────────┤
│ @important │
│ For any future changes to the code in this file, it is recommended to │
│ include, together with the modification, the information of the developer │
│ who changed it and the date of modification. │
└──────────────────────────────────────────────────────────────────────────────┘
*/
/* eslint-disable no-unused-vars */
/* eslint-disable @typescript-eslint/no-explicit-any */
import { Handle, Node, NodeProps, Position, useEdges } from "@xyflow/react";
import { FilterIcon, ArrowRight } from "lucide-react";
import { cn } from "@/lib/utils";
import { BaseNode } from "../../BaseNode";
import { ConditionType, ConditionTypeEnum } from "../../nodeFunctions";
export type ConditionNodeType = Node<
{
label?: string;
type?: "and" | "or";
conditions?: ConditionType[];
},
"condition-node"
>;
export type OperatorType =
| "is_defined"
| "is_not_defined"
| "equals"
| "not_equals"
| "contains"
| "not_contains"
| "starts_with"
| "ends_with"
| "greater_than"
| "greater_than_or_equal"
| "less_than"
| "less_than_or_equal"
| "matches"
| "not_matches";
const operatorText: Record<OperatorType, string> = {
equals: "is equal to",
not_equals: "is not equal to",
contains: "contains",
not_contains: "does not contain",
starts_with: "starts with",
ends_with: "ends with",
greater_than: "is greater than",
greater_than_or_equal: "is greater than or equal to",
less_than: "is less than",
less_than_or_equal: "is less than or equal to",
matches: "matches the pattern",
not_matches: "does not match the pattern",
is_defined: "is defined",
is_not_defined: "is not defined",
};
export function ConditionNode(props: NodeProps) {
const { selected, data } = props;
const edges = useEdges();
const isExecuting = data.isExecuting as boolean | undefined;
const typeText = {
and: "all of the following conditions",
or: "any of the following conditions",
};
const isHandleConnected = (handleId: string) => {
return edges.some(
(edge) => edge.source === props.id && edge.sourceHandle === handleId,
);
};
const isBottomHandleConnected = isHandleConnected("bottom-handle");
const conditions: ConditionType[] = data.conditions as ConditionType[];
// const statistics: StatisticType = data.statistics as StatisticType;
const renderCondition = (condition: ConditionType) => {
const isConnected = isHandleConnected(condition.id);
if (condition.type === ConditionTypeEnum.PREVIOUS_OUTPUT) {
return (
<div
className="mb-3 cursor-pointer rounded-lg border border-purple-700/40 bg-purple-950/10 p-3 text-left transition-all duration-200 hover:border-purple-600/50 hover:bg-purple-900/10"
>
<div className="flex items-center justify-between">
<div className="flex-1">
<p className="font-medium text-neutral-300">
O campo{" "}
<span className="font-semibold text-purple-400">
{condition.data.field}
</span>{" "}
<span className="text-neutral-400">
{operatorText[condition.data.operator as OperatorType]}
</span>{" "}
{!["is_defined", "is_not_defined"].includes(
condition.data.operator,
) && (
<span className="font-semibold text-green-400">
&quot;{condition.data.value}&quot;
</span>
)}
</p>
</div>
<Handle
className={cn(
"!rounded-full transition-all duration-300",
isConnected ? "!bg-purple-500 !border-purple-400" : "!bg-neutral-400 !border-neutral-500"
)}
style={{
top: "50%",
right: "-5px",
transform: "translateY(-50%)",
height: "14px",
position: "relative",
width: "14px",
}}
type="source"
position={Position.Right}
id={condition.id}
/>
</div>
</div>
);
}
return null;
};
return (
<BaseNode hasTarget={true} selected={selected || false} borderColor="purple" isExecuting={isExecuting}>
<div className="mb-3 flex items-center justify-between">
<div className="flex items-center gap-2">
<div className="flex h-8 w-8 items-center justify-center rounded-full bg-purple-900/40 shadow-sm">
<FilterIcon className="h-5 w-5 text-purple-400" />
</div>
<div>
<p className="text-lg font-medium text-purple-400">
{data.label as string}
</p>
<p className="text-xs text-neutral-400">
Matches {typeText[(data.type as "and" | "or") || "and"]}
</p>
</div>
</div>
</div>
{conditions && conditions.length > 0 && Array.isArray(conditions) ? (
conditions.map((condition) => (
<div key={condition.id}>{renderCondition(condition)}</div>
))
) : (
<div className="mb-3 flex flex-col items-center justify-center rounded-lg border-2 border-dashed border-purple-700/40 bg-purple-950/10 p-5 text-center transition-all duration-200 hover:border-purple-600/50 hover:bg-purple-900/20">
<FilterIcon className="h-8 w-8 text-purple-700/50 mb-2" />
<p className="text-purple-400">No conditions configured</p>
<p className="mt-1 text-xs text-neutral-500">Click to add a condition</p>
</div>
)}
<div className="mt-2 flex items-center justify-end text-sm text-neutral-400 transition-colors">
<div className="flex items-center space-x-1 rounded-md py-1 px-2">
<span>Next step</span>
<ArrowRight className="h-3.5 w-3.5" />
</div>
<Handle
className={cn(
"!w-3 !h-3 !rounded-full transition-all duration-300",
isBottomHandleConnected ? "!bg-purple-500 !border-purple-400" : "!bg-neutral-400 !border-neutral-500",
selected && isBottomHandleConnected && "!bg-purple-400 !border-purple-300"
)}
style={{
right: "0px",
top: "calc(100% - 25px)",
}}
type="source"
position={Position.Right}
id="bottom-handle"
/>
</div>
</BaseNode>
);
}