@greatapps/greatagents-ui 0.3.11 → 0.3.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1139,6 +1139,9 @@ function AgentEditForm({ config, agent, idAccount, open, onOpenChange }) {
1139
1139
  return /* @__PURE__ */ jsx3("div", { className: "max-w-lg pt-4", children: formContent });
1140
1140
  }
1141
1141
 
1142
+ // src/components/agents/agent-tabs.tsx
1143
+ import { useState as useState10, useCallback as useCallback6 } from "react";
1144
+
1142
1145
  // src/components/agents/agent-objectives-list.tsx
1143
1146
  import { useState as useState5 } from "react";
1144
1147
  import {
@@ -2497,16 +2500,6 @@ function AgentConversationsPanel({
2497
2500
  ) });
2498
2501
  }
2499
2502
 
2500
- // src/pages/agent-capabilities-page.tsx
2501
- import { useState as useState13, useCallback as useCallback6 } from "react";
2502
- import {
2503
- Tabs,
2504
- TabsList,
2505
- TabsTrigger,
2506
- TabsContent
2507
- } from "@greatapps/greatauth-ui/ui";
2508
- import { Blocks, Plug as Plug3, Settings as Settings3 } from "lucide-react";
2509
-
2510
2503
  // src/components/capabilities/capabilities-tab.tsx
2511
2504
  import { useState as useState8, useCallback as useCallback4, useEffect as useEffect4, useMemo as useMemo5 } from "react";
2512
2505
  import {
@@ -3797,210 +3790,127 @@ function StepIndicator({
3797
3790
  );
3798
3791
  }
3799
3792
 
3800
- // src/components/capabilities/advanced-tab.tsx
3801
- import { useState as useState12 } from "react";
3802
-
3803
- // src/components/tools/tools-table.tsx
3804
- import { useMemo as useMemo6, useState as useState10 } from "react";
3805
- import { DataTable as DataTable2 } from "@greatapps/greatauth-ui";
3793
+ // src/components/agents/agent-tabs.tsx
3806
3794
  import {
3807
- Input as Input7,
3808
- Badge as Badge7,
3809
- Tooltip as Tooltip3,
3810
- TooltipTrigger as TooltipTrigger3,
3811
- TooltipContent as TooltipContent3,
3812
- AlertDialog as AlertDialog3,
3813
- AlertDialogAction as AlertDialogAction3,
3814
- AlertDialogCancel as AlertDialogCancel3,
3815
- AlertDialogContent as AlertDialogContent3,
3816
- AlertDialogDescription as AlertDialogDescription3,
3817
- AlertDialogFooter as AlertDialogFooter3,
3818
- AlertDialogHeader as AlertDialogHeader3,
3819
- AlertDialogTitle as AlertDialogTitle3,
3820
- Button as Button11
3795
+ Tabs,
3796
+ TabsList,
3797
+ TabsTrigger,
3798
+ TabsContent
3821
3799
  } from "@greatapps/greatauth-ui/ui";
3822
- import { Pencil as Pencil3, Trash2 as Trash23, Search as Search2 } from "lucide-react";
3823
- import { format as format2 } from "date-fns";
3824
- import { ptBR as ptBR2 } from "date-fns/locale";
3825
- import { toast as toast8 } from "sonner";
3800
+ import { Target as Target2, FileText as FileText2, MessageCircle as MessageCircle2, Blocks, Plug as Plug3 } from "lucide-react";
3826
3801
  import { Fragment as Fragment2, jsx as jsx18, jsxs as jsxs16 } from "react/jsx-runtime";
3827
- function useColumns2(onEdit, onDelete) {
3828
- return [
3829
- {
3830
- accessorKey: "name",
3831
- header: "Nome",
3832
- cell: ({ row }) => /* @__PURE__ */ jsx18("span", { className: "font-medium", children: row.original.name }),
3833
- sortingFn: (rowA, rowB) => rowA.original.name.toLowerCase().localeCompare(rowB.original.name.toLowerCase())
3834
- },
3835
- {
3836
- accessorKey: "slug",
3837
- header: "Slug",
3838
- cell: ({ row }) => /* @__PURE__ */ jsx18("span", { className: "text-muted-foreground text-sm font-mono", children: row.original.slug || "\u2014" })
3839
- },
3840
- {
3841
- accessorKey: "type",
3842
- header: "Tipo",
3843
- cell: ({ row }) => /* @__PURE__ */ jsx18(Badge7, { variant: "secondary", children: row.original.type })
3844
- },
3845
- {
3846
- accessorKey: "description",
3847
- header: "Descri\xE7\xE3o",
3848
- cell: ({ row }) => {
3849
- const desc = row.original.description;
3850
- if (!desc) return /* @__PURE__ */ jsx18("span", { className: "text-muted-foreground text-sm", children: "\u2014" });
3851
- return /* @__PURE__ */ jsx18("span", { className: "text-muted-foreground text-sm", children: desc.length > 50 ? `${desc.slice(0, 50)}\u2026` : desc });
3852
- }
3853
- },
3854
- {
3855
- accessorKey: "datetime_add",
3856
- header: "Criado em",
3857
- cell: ({ row }) => /* @__PURE__ */ jsx18("span", { className: "text-muted-foreground text-sm", children: format2(new Date(row.original.datetime_add), "dd/MM/yyyy", {
3858
- locale: ptBR2
3859
- }) })
3860
- },
3861
- {
3862
- id: "actions",
3863
- size: 80,
3864
- enableSorting: false,
3865
- cell: ({ row }) => /* @__PURE__ */ jsxs16("div", { className: "flex items-center gap-1", children: [
3866
- /* @__PURE__ */ jsxs16(Tooltip3, { children: [
3867
- /* @__PURE__ */ jsx18(TooltipTrigger3, { asChild: true, children: /* @__PURE__ */ jsx18(
3868
- Button11,
3869
- {
3870
- variant: "ghost",
3871
- size: "icon",
3872
- className: "h-8 w-8",
3873
- "aria-label": "Editar",
3874
- onClick: () => onEdit(row.original),
3875
- children: /* @__PURE__ */ jsx18(Pencil3, { className: "h-4 w-4" })
3876
- }
3877
- ) }),
3878
- /* @__PURE__ */ jsx18(TooltipContent3, { children: "Editar" })
3879
- ] }),
3880
- /* @__PURE__ */ jsxs16(Tooltip3, { children: [
3881
- /* @__PURE__ */ jsx18(TooltipTrigger3, { asChild: true, children: /* @__PURE__ */ jsx18(
3882
- Button11,
3883
- {
3884
- variant: "ghost",
3885
- size: "icon",
3886
- className: "h-8 w-8 text-destructive hover:text-destructive",
3887
- "aria-label": "Excluir",
3888
- onClick: () => onDelete(row.original.id),
3889
- children: /* @__PURE__ */ jsx18(Trash23, { className: "h-4 w-4" })
3890
- }
3891
- ) }),
3892
- /* @__PURE__ */ jsx18(TooltipContent3, { children: "Excluir" })
3893
- ] })
3894
- ] })
3895
- }
3896
- ];
3897
- }
3898
- function ToolsTable({ onEdit, config }) {
3899
- const [search, setSearch] = useState10("");
3900
- const [page, setPage] = useState10(1);
3901
- const queryParams = useMemo6(() => {
3902
- const params = {
3903
- limit: "15",
3904
- page: String(page)
3905
- };
3906
- if (search) {
3907
- params.search = search;
3802
+ function AgentTabs({
3803
+ agent,
3804
+ config,
3805
+ renderChatLink,
3806
+ gagentsApiUrl,
3807
+ resolveWizardMeta,
3808
+ loadConfigOptions,
3809
+ onWizardComplete
3810
+ }) {
3811
+ const apiUrl = gagentsApiUrl || config.baseUrl;
3812
+ const [wizardOpen, setWizardOpen] = useState10(false);
3813
+ const [activeCard, setActiveCard] = useState10(null);
3814
+ const handleConnect = useCallback6((card) => {
3815
+ setActiveCard(card);
3816
+ setWizardOpen(true);
3817
+ }, []);
3818
+ const handleWizardClose = useCallback6((open) => {
3819
+ if (!open) {
3820
+ setActiveCard(null);
3908
3821
  }
3909
- return params;
3910
- }, [search, page]);
3911
- const { data, isLoading } = useTools(config, queryParams);
3912
- const deleteTool = useDeleteTool(config);
3913
- const [deleteId, setDeleteId] = useState10(null);
3914
- const rawTools = data?.data || [];
3915
- const tools = rawTools.filter((t) => !t.slug?.startsWith("gclinic_"));
3916
- const total = tools.length;
3917
- const columns = useColumns2(
3918
- (tool) => onEdit(tool),
3919
- (id) => setDeleteId(id)
3920
- );
3921
- function handleDelete() {
3922
- if (!deleteId) return;
3923
- deleteTool.mutate(deleteId, {
3924
- onSuccess: () => {
3925
- toast8.success("Ferramenta exclu\xEDda");
3926
- setDeleteId(null);
3927
- },
3928
- onError: () => toast8.error("Erro ao excluir ferramenta")
3929
- });
3930
- }
3931
- function handleSearchChange(value) {
3932
- setSearch(value);
3933
- setPage(1);
3934
- }
3822
+ setWizardOpen(open);
3823
+ }, []);
3824
+ const handleWizardComplete = useCallback6(() => {
3825
+ setWizardOpen(false);
3826
+ setActiveCard(null);
3827
+ onWizardComplete?.();
3828
+ }, [onWizardComplete]);
3829
+ const wizardMeta = activeCard ? resolveWizardMeta?.(activeCard) ?? {
3830
+ capabilities: [],
3831
+ requirements: [],
3832
+ hasConfigStep: false
3833
+ } : null;
3935
3834
  return /* @__PURE__ */ jsxs16(Fragment2, { children: [
3936
- /* @__PURE__ */ jsx18("div", { className: "flex items-center gap-3", children: /* @__PURE__ */ jsxs16("div", { className: "relative flex-1 max-w-md", children: [
3937
- /* @__PURE__ */ jsx18(Search2, { "aria-hidden": "true", className: "absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground" }),
3938
- /* @__PURE__ */ jsx18(
3939
- Input7,
3835
+ /* @__PURE__ */ jsxs16(Tabs, { defaultValue: "prompt", children: [
3836
+ /* @__PURE__ */ jsxs16(TabsList, { children: [
3837
+ /* @__PURE__ */ jsxs16(TabsTrigger, { value: "prompt", className: "flex items-center gap-1.5", children: [
3838
+ /* @__PURE__ */ jsx18(FileText2, { "aria-hidden": "true", className: "h-3.5 w-3.5" }),
3839
+ "Prompt"
3840
+ ] }),
3841
+ /* @__PURE__ */ jsxs16(TabsTrigger, { value: "objetivos", className: "flex items-center gap-1.5", children: [
3842
+ /* @__PURE__ */ jsx18(Target2, { "aria-hidden": "true", className: "h-3.5 w-3.5" }),
3843
+ "Objetivos"
3844
+ ] }),
3845
+ /* @__PURE__ */ jsxs16(TabsTrigger, { value: "capacidades", className: "flex items-center gap-1.5", children: [
3846
+ /* @__PURE__ */ jsx18(Blocks, { "aria-hidden": "true", className: "h-3.5 w-3.5" }),
3847
+ "Capacidades"
3848
+ ] }),
3849
+ /* @__PURE__ */ jsxs16(TabsTrigger, { value: "integracoes", className: "flex items-center gap-1.5", children: [
3850
+ /* @__PURE__ */ jsx18(Plug3, { "aria-hidden": "true", className: "h-3.5 w-3.5" }),
3851
+ "Integra\xE7\xF5es"
3852
+ ] }),
3853
+ /* @__PURE__ */ jsxs16(TabsTrigger, { value: "conversas", className: "flex items-center gap-1.5", children: [
3854
+ /* @__PURE__ */ jsx18(MessageCircle2, { "aria-hidden": "true", className: "h-3.5 w-3.5" }),
3855
+ "Conversas"
3856
+ ] })
3857
+ ] }),
3858
+ /* @__PURE__ */ jsx18(TabsContent, { value: "prompt", className: "mt-4", children: /* @__PURE__ */ jsx18(AgentPromptEditor, { agent, config }) }),
3859
+ /* @__PURE__ */ jsx18(TabsContent, { value: "objetivos", className: "mt-4", children: /* @__PURE__ */ jsx18(AgentObjectivesList, { agent, config }) }),
3860
+ /* @__PURE__ */ jsx18(TabsContent, { value: "capacidades", className: "mt-4", children: /* @__PURE__ */ jsx18(CapabilitiesTab, { config, agentId: agent.id }) }),
3861
+ /* @__PURE__ */ jsx18(TabsContent, { value: "integracoes", className: "mt-4", children: /* @__PURE__ */ jsx18(IntegrationsTab, { config, agentId: agent.id, onConnect: handleConnect }) }),
3862
+ /* @__PURE__ */ jsx18(TabsContent, { value: "conversas", className: "mt-4", children: /* @__PURE__ */ jsx18(
3863
+ AgentConversationsPanel,
3940
3864
  {
3941
- placeholder: "Buscar ferramentas\\u2026",
3942
- "aria-label": "Buscar ferramentas",
3943
- name: "search",
3944
- autoComplete: "off",
3945
- value: search,
3946
- onChange: (e) => handleSearchChange(e.target.value),
3947
- className: "pl-9"
3865
+ agent,
3866
+ config,
3867
+ renderChatLink
3948
3868
  }
3949
- )
3950
- ] }) }),
3951
- /* @__PURE__ */ jsx18(
3952
- DataTable2,
3953
- {
3954
- columns,
3955
- data: tools,
3956
- isLoading,
3957
- emptyMessage: "Nenhuma ferramenta encontrada",
3958
- total,
3959
- page,
3960
- onPageChange: setPage,
3961
- pageSize: 15
3962
- }
3963
- ),
3964
- /* @__PURE__ */ jsx18(
3965
- AlertDialog3,
3869
+ ) })
3870
+ ] }),
3871
+ activeCard && wizardMeta && /* @__PURE__ */ jsx18(
3872
+ IntegrationWizard,
3966
3873
  {
3967
- open: !!deleteId,
3968
- onOpenChange: (open) => !open && setDeleteId(null),
3969
- children: /* @__PURE__ */ jsxs16(AlertDialogContent3, { children: [
3970
- /* @__PURE__ */ jsxs16(AlertDialogHeader3, { children: [
3971
- /* @__PURE__ */ jsx18(AlertDialogTitle3, { children: "Excluir ferramenta?" }),
3972
- /* @__PURE__ */ jsx18(AlertDialogDescription3, { children: "Esta a\xE7\xE3o n\xE3o pode ser desfeita. A ferramenta ser\xE1 removida permanentemente." })
3973
- ] }),
3974
- /* @__PURE__ */ jsxs16(AlertDialogFooter3, { children: [
3975
- /* @__PURE__ */ jsx18(AlertDialogCancel3, { variant: "outline", size: "default", children: "Cancelar" }),
3976
- /* @__PURE__ */ jsx18(
3977
- AlertDialogAction3,
3978
- {
3979
- variant: "default",
3980
- size: "default",
3981
- onClick: handleDelete,
3982
- className: "bg-destructive text-destructive-foreground hover:bg-destructive/90",
3983
- children: "Excluir"
3984
- }
3985
- )
3986
- ] })
3987
- ] })
3874
+ open: wizardOpen,
3875
+ onOpenChange: handleWizardClose,
3876
+ integration: activeCard.definition,
3877
+ meta: wizardMeta,
3878
+ agentId: agent.id,
3879
+ config,
3880
+ gagentsApiUrl: apiUrl,
3881
+ existingCredentialId: activeCard.credentialId,
3882
+ onComplete: handleWizardComplete,
3883
+ loadConfigOptions
3988
3884
  }
3989
3885
  )
3990
3886
  ] });
3991
3887
  }
3992
3888
 
3993
- // src/components/tools/tool-form-dialog.tsx
3889
+ // src/components/agents/agent-tools-list.tsx
3994
3890
  import { useState as useState11 } from "react";
3995
3891
  import {
3892
+ Switch as Switch5,
3893
+ Badge as Badge7,
3894
+ Button as Button11,
3895
+ Skeleton as Skeleton6,
3896
+ AlertDialog as AlertDialog3,
3897
+ AlertDialogAction as AlertDialogAction3,
3898
+ AlertDialogCancel as AlertDialogCancel3,
3899
+ AlertDialogContent as AlertDialogContent3,
3900
+ AlertDialogDescription as AlertDialogDescription3,
3901
+ AlertDialogFooter as AlertDialogFooter3,
3902
+ AlertDialogHeader as AlertDialogHeader3,
3903
+ AlertDialogTitle as AlertDialogTitle3,
3904
+ Popover,
3905
+ PopoverContent,
3906
+ PopoverTrigger,
3907
+ Input as Input7,
3908
+ Textarea as Textarea2,
3996
3909
  Dialog as Dialog5,
3997
3910
  DialogContent as DialogContent5,
3998
3911
  DialogHeader as DialogHeader5,
3999
3912
  DialogTitle as DialogTitle5,
4000
3913
  DialogFooter as DialogFooter5,
4001
- Button as Button12,
4002
- Input as Input8,
4003
- Textarea as Textarea2,
4004
3914
  Label as Label7,
4005
3915
  Select as Select2,
4006
3916
  SelectContent as SelectContent2,
@@ -4008,617 +3918,132 @@ import {
4008
3918
  SelectTrigger as SelectTrigger2,
4009
3919
  SelectValue as SelectValue2
4010
3920
  } from "@greatapps/greatauth-ui/ui";
4011
- import { Loader2 as Loader29 } from "lucide-react";
4012
- import { toast as toast9 } from "sonner";
3921
+ import {
3922
+ Trash2 as Trash23,
3923
+ Plus as Plus3,
3924
+ Wrench,
3925
+ Settings2 as Settings22
3926
+ } from "lucide-react";
3927
+ import { toast as toast8 } from "sonner";
4013
3928
  import { jsx as jsx19, jsxs as jsxs17 } from "react/jsx-runtime";
4014
- var TOOL_AUTH_TYPES = [
4015
- { value: "none", label: "Nenhuma" },
4016
- { value: "api_key", label: "API Key" },
4017
- { value: "oauth2", label: "OAuth 2.0" }
4018
- ];
4019
- function toolToFormState(tool) {
4020
- return {
4021
- name: tool?.name || "",
4022
- slug: tool?.slug || "",
4023
- type: tool?.type || "none",
4024
- description: tool?.description || "",
4025
- functionDefinitions: tool?.function_definitions ? formatJson(tool.function_definitions) : "",
4026
- nameError: false,
4027
- slugError: false,
4028
- typeError: false,
4029
- jsonError: false
4030
- };
4031
- }
4032
- function formatJson(str) {
4033
- try {
4034
- return JSON.stringify(JSON.parse(str), null, 2);
4035
- } catch {
4036
- return str;
4037
- }
4038
- }
4039
- function slugify2(name) {
4040
- return name.toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g, "").replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
4041
- }
4042
- function isValidJson(str) {
4043
- if (!str.trim()) return true;
4044
- try {
4045
- JSON.parse(str);
4046
- return true;
4047
- } catch {
4048
- return false;
4049
- }
4050
- }
4051
- function ToolFormDialog({
4052
- open,
4053
- onOpenChange,
4054
- tool,
4055
- config
4056
- }) {
4057
- const isEditing = !!tool;
4058
- const createTool = useCreateTool(config);
4059
- const updateTool = useUpdateTool(config);
4060
- const [form, setForm] = useState11(() => toolToFormState(tool));
4061
- const [slugManuallyEdited, setSlugManuallyEdited] = useState11(false);
4062
- const [lastResetKey, setLastResetKey] = useState11(
4063
- () => `${tool?.id}-${open}`
3929
+ function AgentToolsList({ agent, config }) {
3930
+ const { data: agentToolsData, isLoading } = useAgentTools(config, agent.id);
3931
+ const { data: allToolsData } = useTools(config);
3932
+ const addMutation = useAddAgentTool(config);
3933
+ const removeMutation = useRemoveAgentTool(config);
3934
+ const updateMutation = useUpdateAgentTool(config);
3935
+ const [removeTarget, setRemoveTarget] = useState11(null);
3936
+ const [addOpen, setAddOpen] = useState11(false);
3937
+ const [search, setSearch] = useState11("");
3938
+ const [configTarget, setConfigTarget] = useState11(null);
3939
+ const [configInstructions, setConfigInstructions] = useState11("");
3940
+ const [configCredentialId, setConfigCredentialId] = useState11("");
3941
+ const { data: credentialsData } = useToolCredentials(config);
3942
+ const allCredentials = credentialsData?.data || [];
3943
+ const agentTools = agentToolsData?.data || [];
3944
+ const allTools = (allToolsData?.data || []).filter((t) => !t.slug?.startsWith("gclinic_"));
3945
+ const assignedToolIds = new Set(agentTools.map((at) => at.id_tool));
3946
+ const visibleAgentTools = agentTools.filter((at) => {
3947
+ const tool = allTools.find((t) => t.id === at.id_tool);
3948
+ return !tool || !tool.slug?.startsWith("gclinic_");
3949
+ });
3950
+ const availableTools = allTools.filter((t) => !assignedToolIds.has(t.id));
3951
+ const filteredAvailable = availableTools.filter(
3952
+ (t) => t.name.toLowerCase().includes(search.toLowerCase())
4064
3953
  );
4065
- const resetKey = `${tool?.id}-${open}`;
4066
- if (resetKey !== lastResetKey) {
4067
- setLastResetKey(resetKey);
4068
- setForm(toolToFormState(open ? tool : void 0));
4069
- setSlugManuallyEdited(false);
3954
+ function getToolInfo(idTool) {
3955
+ return allTools.find((t) => t.id === idTool);
4070
3956
  }
4071
- const isPending = createTool.isPending || updateTool.isPending;
4072
- async function handleSubmit(e) {
4073
- e.preventDefault();
4074
- let hasError = false;
4075
- if (!form.name.trim()) {
4076
- setForm((prev) => ({ ...prev, nameError: true }));
4077
- hasError = true;
4078
- }
4079
- const effectiveSlug = form.slug.trim() || slugify2(form.name);
4080
- if (!effectiveSlug) {
4081
- setForm((prev) => ({ ...prev, slugError: true }));
4082
- hasError = true;
4083
- }
4084
- if (!form.type) {
4085
- setForm((prev) => ({ ...prev, typeError: true }));
4086
- hasError = true;
4087
- }
4088
- if (!isValidJson(form.functionDefinitions)) {
4089
- setForm((prev) => ({ ...prev, jsonError: true }));
4090
- hasError = true;
4091
- }
4092
- if (hasError) return;
4093
- const body = {
4094
- name: form.name.trim(),
4095
- slug: effectiveSlug,
4096
- type: form.type
4097
- };
4098
- if (form.description.trim()) body.description = form.description.trim();
4099
- else body.description = "";
4100
- if (form.functionDefinitions.trim()) {
4101
- const parsed = JSON.parse(form.functionDefinitions.trim());
4102
- body.function_definitions = JSON.stringify(parsed);
4103
- } else {
4104
- body.function_definitions = "";
3957
+ async function handleToggleEnabled(agentTool, checked) {
3958
+ try {
3959
+ await updateMutation.mutateAsync({
3960
+ idAgent: agent.id,
3961
+ id: agentTool.id,
3962
+ body: { enabled: checked }
3963
+ });
3964
+ toast8.success(checked ? "Ferramenta ativada" : "Ferramenta desativada");
3965
+ } catch (err) {
3966
+ toast8.error(
3967
+ err instanceof Error ? err.message : "Erro ao alterar estado da ferramenta"
3968
+ );
4105
3969
  }
3970
+ }
3971
+ async function handleAdd(tool) {
4106
3972
  try {
4107
- if (isEditing) {
4108
- await updateTool.mutateAsync({ id: tool.id, body });
4109
- toast9.success("Ferramenta atualizada");
4110
- } else {
4111
- await createTool.mutateAsync(
4112
- body
4113
- );
4114
- toast9.success("Ferramenta criada");
4115
- }
4116
- onOpenChange(false);
3973
+ await addMutation.mutateAsync({
3974
+ idAgent: agent.id,
3975
+ body: { id_tool: tool.id }
3976
+ });
3977
+ toast8.success("Ferramenta adicionada");
3978
+ setAddOpen(false);
3979
+ setSearch("");
4117
3980
  } catch (err) {
4118
- toast9.error(
4119
- err instanceof Error ? err.message : isEditing ? "Erro ao atualizar ferramenta" : "Erro ao criar ferramenta"
3981
+ toast8.error(
3982
+ err instanceof Error ? err.message : "Erro ao adicionar ferramenta"
4120
3983
  );
4121
3984
  }
4122
3985
  }
4123
- return /* @__PURE__ */ jsx19(Dialog5, { open, onOpenChange, children: /* @__PURE__ */ jsxs17(DialogContent5, { className: "sm:max-w-lg", children: [
4124
- /* @__PURE__ */ jsx19(DialogHeader5, { children: /* @__PURE__ */ jsx19(DialogTitle5, { children: isEditing ? "Editar Ferramenta" : "Nova Ferramenta" }) }),
4125
- /* @__PURE__ */ jsxs17("form", { onSubmit: handleSubmit, className: "space-y-4", children: [
4126
- /* @__PURE__ */ jsxs17("div", { className: "space-y-2", children: [
4127
- /* @__PURE__ */ jsx19(Label7, { htmlFor: "tool-name", children: "Nome *" }),
4128
- /* @__PURE__ */ jsx19(
4129
- Input8,
4130
- {
4131
- id: "tool-name",
4132
- name: "name",
4133
- value: form.name,
4134
- onChange: (e) => {
4135
- const name = e.target.value;
4136
- setForm((prev) => ({
4137
- ...prev,
4138
- name,
4139
- nameError: name.trim() ? false : prev.nameError,
4140
- ...!slugManuallyEdited && !isEditing ? { slug: slugify2(name), slugError: false } : {}
4141
- }));
4142
- },
4143
- placeholder: "Ex: Google Calendar",
4144
- disabled: isPending
4145
- }
4146
- ),
4147
- form.nameError && /* @__PURE__ */ jsx19("p", { className: "text-sm text-destructive", children: "Nome \xE9 obrigat\xF3rio" })
4148
- ] }),
4149
- /* @__PURE__ */ jsxs17("div", { className: "space-y-2", children: [
4150
- /* @__PURE__ */ jsx19(Label7, { htmlFor: "tool-slug", children: "Slug (identificador \xFAnico) *" }),
4151
- /* @__PURE__ */ jsx19(
4152
- Input8,
4153
- {
4154
- id: "tool-slug",
4155
- name: "slug",
4156
- value: form.slug,
4157
- onChange: (e) => {
4158
- setSlugManuallyEdited(true);
4159
- setForm((prev) => ({
4160
- ...prev,
4161
- slug: e.target.value,
4162
- slugError: e.target.value.trim() ? false : prev.slugError
4163
- }));
4164
- },
4165
- placeholder: "Ex: google-calendar",
4166
- disabled: isPending
4167
- }
4168
- ),
4169
- /* @__PURE__ */ jsx19("p", { className: "text-xs text-muted-foreground", children: "Gerado automaticamente a partir do nome. Usado internamente para identificar a ferramenta." }),
4170
- form.slugError && /* @__PURE__ */ jsx19("p", { className: "text-sm text-destructive", children: "Slug \xE9 obrigat\xF3rio" })
4171
- ] }),
4172
- /* @__PURE__ */ jsxs17("div", { className: "space-y-2", children: [
4173
- /* @__PURE__ */ jsx19(Label7, { htmlFor: "tool-type", children: "Tipo de Autentica\xE7\xE3o *" }),
4174
- /* @__PURE__ */ jsxs17(
4175
- Select2,
4176
- {
4177
- value: form.type,
4178
- onValueChange: (value) => {
4179
- setForm((prev) => ({
4180
- ...prev,
4181
- type: value,
4182
- typeError: false
4183
- }));
4184
- },
4185
- disabled: isPending,
4186
- children: [
4187
- /* @__PURE__ */ jsx19(SelectTrigger2, { id: "tool-type", children: /* @__PURE__ */ jsx19(SelectValue2, { placeholder: "Selecione o tipo" }) }),
4188
- /* @__PURE__ */ jsx19(SelectContent2, { children: TOOL_AUTH_TYPES.map((t) => /* @__PURE__ */ jsx19(SelectItem2, { value: t.value, children: t.label }, t.value)) })
4189
- ]
4190
- }
4191
- ),
4192
- /* @__PURE__ */ jsx19("p", { className: "text-xs text-muted-foreground", children: "Define se a ferramenta requer credenciais para funcionar." }),
4193
- form.typeError && /* @__PURE__ */ jsx19("p", { className: "text-sm text-destructive", children: "Tipo \xE9 obrigat\xF3rio" })
4194
- ] }),
4195
- /* @__PURE__ */ jsxs17("div", { className: "space-y-2", children: [
4196
- /* @__PURE__ */ jsx19(Label7, { htmlFor: "tool-description", children: "Descri\xE7\xE3o" }),
4197
- /* @__PURE__ */ jsx19(
4198
- Textarea2,
4199
- {
4200
- id: "tool-description",
4201
- name: "description",
4202
- value: form.description,
4203
- onChange: (e) => setForm((prev) => ({ ...prev, description: e.target.value })),
4204
- placeholder: "Descri\\u00e7\\u00e3o da ferramenta\\u2026",
4205
- rows: 3,
4206
- disabled: isPending
4207
- }
4208
- )
4209
- ] }),
4210
- /* @__PURE__ */ jsxs17("div", { className: "space-y-2", children: [
4211
- /* @__PURE__ */ jsx19(Label7, { htmlFor: "tool-function-defs", children: "Defini\xE7\xF5es de Fun\xE7\xE3o (JSON)" }),
4212
- /* @__PURE__ */ jsx19(
4213
- Textarea2,
4214
- {
4215
- id: "tool-function-defs",
4216
- name: "functionDefs",
4217
- value: form.functionDefinitions,
4218
- onChange: (e) => {
4219
- setForm((prev) => ({
4220
- ...prev,
4221
- functionDefinitions: e.target.value,
4222
- jsonError: false
4223
- }));
4224
- },
4225
- placeholder: `[
4226
- {
4227
- "type": "function",
4228
- "function": {
4229
- "name": "nome_da_funcao",
4230
- "description": "O que a fun\xE7\xE3o faz",
4231
- "parameters": {
4232
- "type": "object",
4233
- "properties": { \u2026 },
4234
- "required": [\u2026]
4235
- }
3986
+ async function handleRemove() {
3987
+ if (!removeTarget) return;
3988
+ try {
3989
+ await removeMutation.mutateAsync({
3990
+ idAgent: agent.id,
3991
+ id: removeTarget.id
3992
+ });
3993
+ toast8.success("Ferramenta removida");
3994
+ } catch (err) {
3995
+ toast8.error(
3996
+ err instanceof Error ? err.message : "Erro ao remover ferramenta"
3997
+ );
3998
+ } finally {
3999
+ setRemoveTarget(null);
4236
4000
  }
4237
4001
  }
4238
- ]`,
4239
- rows: 10,
4240
- className: "font-mono text-sm",
4241
- disabled: isPending
4242
- }
4243
- ),
4244
- /* @__PURE__ */ jsx19("p", { className: "text-xs text-muted-foreground", children: "Array de defini\xE7\xF5es no formato OpenAI Function Calling." }),
4245
- form.jsonError && /* @__PURE__ */ jsx19("p", { className: "text-sm text-destructive", children: "JSON inv\xE1lido" })
4246
- ] }),
4247
- /* @__PURE__ */ jsxs17(DialogFooter5, { children: [
4248
- /* @__PURE__ */ jsx19(
4249
- Button12,
4250
- {
4251
- type: "button",
4252
- variant: "outline",
4253
- onClick: () => onOpenChange(false),
4254
- disabled: isPending,
4255
- children: "Cancelar"
4256
- }
4257
- ),
4258
- /* @__PURE__ */ jsxs17(Button12, { type: "submit", disabled: isPending, children: [
4259
- isPending ? /* @__PURE__ */ jsx19(Loader29, { "aria-hidden": "true", className: "mr-2 h-4 w-4 animate-spin" }) : null,
4260
- isEditing ? "Salvar" : "Criar"
4261
- ] })
4262
- ] })
4263
- ] })
4264
- ] }) });
4265
- }
4266
-
4267
- // src/components/capabilities/advanced-tab.tsx
4268
- import { Info as Info2 } from "lucide-react";
4269
- import { jsx as jsx20, jsxs as jsxs18 } from "react/jsx-runtime";
4270
- function AdvancedTab({ config, agentId, gagentsApiUrl }) {
4271
- const [editingTool, setEditingTool] = useState12(null);
4272
- const [showToolForm, setShowToolForm] = useState12(false);
4273
- function handleEditTool(tool) {
4274
- setEditingTool(tool);
4275
- setShowToolForm(true);
4002
+ function openConfig(agentTool) {
4003
+ setConfigTarget(agentTool);
4004
+ setConfigInstructions(agentTool.custom_instructions || "");
4005
+ setConfigCredentialId(agentTool.id_tool_credential ? String(agentTool.id_tool_credential) : "");
4276
4006
  }
4277
- function handleToolFormOpenChange(open) {
4278
- setShowToolForm(open);
4279
- if (!open) setEditingTool(null);
4280
- }
4281
- return /* @__PURE__ */ jsxs18("div", { className: "space-y-8", children: [
4282
- /* @__PURE__ */ jsxs18("div", { className: "flex items-start gap-3 rounded-lg border border-blue-200 bg-blue-50 p-4 dark:border-blue-900 dark:bg-blue-950/30", children: [
4283
- /* @__PURE__ */ jsx20(Info2, { className: "mt-0.5 h-4 w-4 shrink-0 text-blue-600 dark:text-blue-400" }),
4284
- /* @__PURE__ */ jsxs18("p", { className: "text-sm text-blue-800 dark:text-blue-300", children: [
4285
- "Use as abas ",
4286
- /* @__PURE__ */ jsx20("strong", { children: "Capacidades" }),
4287
- " e ",
4288
- /* @__PURE__ */ jsx20("strong", { children: "Integra\xE7\xF5es" }),
4289
- " para configura\xE7\xE3o simplificada. Esta aba oferece controlo manual avan\xE7ado sobre ferramentas. As credenciais s\xE3o geridas dentro de cada ferramenta."
4290
- ] })
4291
- ] }),
4292
- /* @__PURE__ */ jsxs18("section", { className: "space-y-3", children: [
4293
- /* @__PURE__ */ jsx20("h3", { className: "text-sm font-medium", children: "Ferramentas" }),
4294
- /* @__PURE__ */ jsx20(ToolsTable, { onEdit: handleEditTool, config })
4295
- ] }),
4296
- /* @__PURE__ */ jsx20(
4297
- ToolFormDialog,
4298
- {
4299
- open: showToolForm,
4300
- onOpenChange: handleToolFormOpenChange,
4301
- tool: editingTool ?? void 0,
4302
- config
4303
- }
4304
- )
4305
- ] });
4306
- }
4307
-
4308
- // src/pages/agent-capabilities-page.tsx
4309
- import { jsx as jsx21, jsxs as jsxs19 } from "react/jsx-runtime";
4310
- function defaultResolveWizardMeta(card) {
4311
- return {
4312
- capabilities: [
4313
- { label: card.definition.name, description: card.definition.description }
4314
- ],
4315
- requirements: [],
4316
- hasConfigStep: false
4317
- };
4318
- }
4319
- function AgentCapabilitiesPage({
4320
- config,
4321
- agentId,
4322
- gagentsApiUrl,
4323
- resolveWizardMeta = defaultResolveWizardMeta,
4324
- loadConfigOptions,
4325
- onWizardComplete
4326
- }) {
4327
- const [wizardOpen, setWizardOpen] = useState13(false);
4328
- const [activeCard, setActiveCard] = useState13(null);
4329
- const handleConnect = useCallback6(
4330
- (card) => {
4331
- setActiveCard(card);
4332
- setWizardOpen(true);
4333
- },
4334
- []
4335
- );
4336
- const handleWizardComplete = useCallback6(() => {
4337
- setWizardOpen(false);
4338
- setActiveCard(null);
4339
- onWizardComplete?.();
4340
- }, [onWizardComplete]);
4341
- const handleWizardOpenChange = useCallback6((open) => {
4342
- setWizardOpen(open);
4343
- if (!open) setActiveCard(null);
4344
- }, []);
4345
- const wizardMeta = activeCard ? resolveWizardMeta(activeCard) : null;
4346
- return /* @__PURE__ */ jsxs19("div", { className: "space-y-4", children: [
4347
- /* @__PURE__ */ jsxs19("div", { children: [
4348
- /* @__PURE__ */ jsx21("h2", { className: "text-lg font-semibold", children: "Capacidades e Integra\xE7\xF5es" }),
4349
- /* @__PURE__ */ jsx21("p", { className: "text-sm text-muted-foreground", children: "Configure o que este agente pode fazer e quais servi\xE7os externos ele utiliza." })
4350
- ] }),
4351
- /* @__PURE__ */ jsxs19(Tabs, { defaultValue: "capacidades", children: [
4352
- /* @__PURE__ */ jsxs19(TabsList, { children: [
4353
- /* @__PURE__ */ jsxs19(TabsTrigger, { value: "capacidades", className: "flex items-center gap-1.5", children: [
4354
- /* @__PURE__ */ jsx21(Blocks, { "aria-hidden": "true", className: "h-3.5 w-3.5" }),
4355
- "Capacidades"
4356
- ] }),
4357
- /* @__PURE__ */ jsxs19(TabsTrigger, { value: "integracoes", className: "flex items-center gap-1.5", children: [
4358
- /* @__PURE__ */ jsx21(Plug3, { "aria-hidden": "true", className: "h-3.5 w-3.5" }),
4359
- "Integra\xE7\xF5es"
4360
- ] }),
4361
- /* @__PURE__ */ jsxs19(TabsTrigger, { value: "avancado", className: "flex items-center gap-1.5", children: [
4362
- /* @__PURE__ */ jsx21(Settings3, { "aria-hidden": "true", className: "h-3.5 w-3.5" }),
4363
- "Avan\xE7ado"
4364
- ] })
4365
- ] }),
4366
- /* @__PURE__ */ jsx21(TabsContent, { value: "capacidades", className: "mt-4", children: /* @__PURE__ */ jsx21(CapabilitiesTab, { config, agentId }) }),
4367
- /* @__PURE__ */ jsx21(TabsContent, { value: "integracoes", className: "mt-4", children: /* @__PURE__ */ jsx21(
4368
- IntegrationsTab,
4369
- {
4370
- config,
4371
- agentId,
4372
- onConnect: handleConnect
4373
- }
4374
- ) }),
4375
- /* @__PURE__ */ jsx21(TabsContent, { value: "avancado", className: "mt-4", children: /* @__PURE__ */ jsx21(
4376
- AdvancedTab,
4377
- {
4378
- config,
4379
- agentId,
4380
- gagentsApiUrl
4381
- }
4382
- ) })
4383
- ] }),
4384
- activeCard && wizardMeta && /* @__PURE__ */ jsx21(
4385
- IntegrationWizard,
4386
- {
4387
- open: wizardOpen,
4388
- onOpenChange: handleWizardOpenChange,
4389
- integration: activeCard.definition,
4390
- meta: wizardMeta,
4391
- agentId,
4392
- config,
4393
- onComplete: handleWizardComplete,
4394
- gagentsApiUrl,
4395
- existingCredentialId: activeCard.credential?.id,
4396
- loadConfigOptions
4397
- }
4398
- )
4399
- ] });
4400
- }
4401
-
4402
- // src/components/agents/agent-tabs.tsx
4403
- import {
4404
- Tabs as Tabs2,
4405
- TabsList as TabsList2,
4406
- TabsTrigger as TabsTrigger2,
4407
- TabsContent as TabsContent2
4408
- } from "@greatapps/greatauth-ui/ui";
4409
- import { Target as Target2, FileText as FileText2, MessageCircle as MessageCircle2, Blocks as Blocks2 } from "lucide-react";
4410
- import { jsx as jsx22, jsxs as jsxs20 } from "react/jsx-runtime";
4411
- function AgentTabs({
4412
- agent,
4413
- config,
4414
- renderChatLink,
4415
- gagentsApiUrl,
4416
- resolveWizardMeta,
4417
- loadConfigOptions,
4418
- onWizardComplete
4419
- }) {
4420
- const apiUrl = gagentsApiUrl || config.baseUrl;
4421
- return /* @__PURE__ */ jsxs20(Tabs2, { defaultValue: "prompt", children: [
4422
- /* @__PURE__ */ jsxs20(TabsList2, { children: [
4423
- /* @__PURE__ */ jsxs20(TabsTrigger2, { value: "prompt", className: "flex items-center gap-1.5", children: [
4424
- /* @__PURE__ */ jsx22(FileText2, { "aria-hidden": "true", className: "h-3.5 w-3.5" }),
4425
- "Prompt"
4426
- ] }),
4427
- /* @__PURE__ */ jsxs20(TabsTrigger2, { value: "objetivos", className: "flex items-center gap-1.5", children: [
4428
- /* @__PURE__ */ jsx22(Target2, { "aria-hidden": "true", className: "h-3.5 w-3.5" }),
4429
- "Objetivos"
4430
- ] }),
4431
- /* @__PURE__ */ jsxs20(TabsTrigger2, { value: "capacidades", className: "flex items-center gap-1.5", children: [
4432
- /* @__PURE__ */ jsx22(Blocks2, { "aria-hidden": "true", className: "h-3.5 w-3.5" }),
4433
- "Capacidades"
4434
- ] }),
4435
- /* @__PURE__ */ jsxs20(TabsTrigger2, { value: "conversas", className: "flex items-center gap-1.5", children: [
4436
- /* @__PURE__ */ jsx22(MessageCircle2, { "aria-hidden": "true", className: "h-3.5 w-3.5" }),
4437
- "Conversas"
4438
- ] })
4439
- ] }),
4440
- /* @__PURE__ */ jsx22(TabsContent2, { value: "prompt", className: "mt-4", children: /* @__PURE__ */ jsx22(AgentPromptEditor, { agent, config }) }),
4441
- /* @__PURE__ */ jsx22(TabsContent2, { value: "objetivos", className: "mt-4", children: /* @__PURE__ */ jsx22(AgentObjectivesList, { agent, config }) }),
4442
- /* @__PURE__ */ jsx22(TabsContent2, { value: "capacidades", className: "mt-4", children: /* @__PURE__ */ jsx22(
4443
- AgentCapabilitiesPage,
4444
- {
4445
- config,
4446
- agentId: agent.id,
4447
- gagentsApiUrl: apiUrl,
4448
- resolveWizardMeta,
4449
- loadConfigOptions,
4450
- onWizardComplete
4451
- }
4452
- ) }),
4453
- /* @__PURE__ */ jsx22(TabsContent2, { value: "conversas", className: "mt-4", children: /* @__PURE__ */ jsx22(
4454
- AgentConversationsPanel,
4455
- {
4456
- agent,
4457
- config,
4458
- renderChatLink
4459
- }
4460
- ) })
4461
- ] });
4462
- }
4463
-
4464
- // src/components/agents/agent-tools-list.tsx
4465
- import { useState as useState14 } from "react";
4466
- import {
4467
- Switch as Switch5,
4468
- Badge as Badge8,
4469
- Button as Button13,
4470
- Skeleton as Skeleton6,
4471
- AlertDialog as AlertDialog4,
4472
- AlertDialogAction as AlertDialogAction4,
4473
- AlertDialogCancel as AlertDialogCancel4,
4474
- AlertDialogContent as AlertDialogContent4,
4475
- AlertDialogDescription as AlertDialogDescription4,
4476
- AlertDialogFooter as AlertDialogFooter4,
4477
- AlertDialogHeader as AlertDialogHeader4,
4478
- AlertDialogTitle as AlertDialogTitle4,
4479
- Popover,
4480
- PopoverContent,
4481
- PopoverTrigger,
4482
- Input as Input9,
4483
- Textarea as Textarea3,
4484
- Dialog as Dialog6,
4485
- DialogContent as DialogContent6,
4486
- DialogHeader as DialogHeader6,
4487
- DialogTitle as DialogTitle6,
4488
- DialogFooter as DialogFooter6,
4489
- Label as Label8,
4490
- Select as Select3,
4491
- SelectContent as SelectContent3,
4492
- SelectItem as SelectItem3,
4493
- SelectTrigger as SelectTrigger3,
4494
- SelectValue as SelectValue3
4495
- } from "@greatapps/greatauth-ui/ui";
4496
- import {
4497
- Trash2 as Trash24,
4498
- Plus as Plus3,
4499
- Wrench,
4500
- Settings2 as Settings22
4501
- } from "lucide-react";
4502
- import { toast as toast10 } from "sonner";
4503
- import { jsx as jsx23, jsxs as jsxs21 } from "react/jsx-runtime";
4504
- function AgentToolsList({ agent, config }) {
4505
- const { data: agentToolsData, isLoading } = useAgentTools(config, agent.id);
4506
- const { data: allToolsData } = useTools(config);
4507
- const addMutation = useAddAgentTool(config);
4508
- const removeMutation = useRemoveAgentTool(config);
4509
- const updateMutation = useUpdateAgentTool(config);
4510
- const [removeTarget, setRemoveTarget] = useState14(null);
4511
- const [addOpen, setAddOpen] = useState14(false);
4512
- const [search, setSearch] = useState14("");
4513
- const [configTarget, setConfigTarget] = useState14(null);
4514
- const [configInstructions, setConfigInstructions] = useState14("");
4515
- const [configCredentialId, setConfigCredentialId] = useState14("");
4516
- const { data: credentialsData } = useToolCredentials(config);
4517
- const allCredentials = credentialsData?.data || [];
4518
- const agentTools = agentToolsData?.data || [];
4519
- const allTools = (allToolsData?.data || []).filter((t) => !t.slug?.startsWith("gclinic_"));
4520
- const assignedToolIds = new Set(agentTools.map((at) => at.id_tool));
4521
- const visibleAgentTools = agentTools.filter((at) => {
4522
- const tool = allTools.find((t) => t.id === at.id_tool);
4523
- return !tool || !tool.slug?.startsWith("gclinic_");
4524
- });
4525
- const availableTools = allTools.filter((t) => !assignedToolIds.has(t.id));
4526
- const filteredAvailable = availableTools.filter(
4527
- (t) => t.name.toLowerCase().includes(search.toLowerCase())
4528
- );
4529
- function getToolInfo(idTool) {
4530
- return allTools.find((t) => t.id === idTool);
4531
- }
4532
- async function handleToggleEnabled(agentTool, checked) {
4533
- try {
4534
- await updateMutation.mutateAsync({
4535
- idAgent: agent.id,
4536
- id: agentTool.id,
4537
- body: { enabled: checked }
4538
- });
4539
- toast10.success(checked ? "Ferramenta ativada" : "Ferramenta desativada");
4540
- } catch (err) {
4541
- toast10.error(
4542
- err instanceof Error ? err.message : "Erro ao alterar estado da ferramenta"
4543
- );
4544
- }
4545
- }
4546
- async function handleAdd(tool) {
4547
- try {
4548
- await addMutation.mutateAsync({
4549
- idAgent: agent.id,
4550
- body: { id_tool: tool.id }
4551
- });
4552
- toast10.success("Ferramenta adicionada");
4553
- setAddOpen(false);
4554
- setSearch("");
4555
- } catch (err) {
4556
- toast10.error(
4557
- err instanceof Error ? err.message : "Erro ao adicionar ferramenta"
4558
- );
4559
- }
4560
- }
4561
- async function handleRemove() {
4562
- if (!removeTarget) return;
4563
- try {
4564
- await removeMutation.mutateAsync({
4565
- idAgent: agent.id,
4566
- id: removeTarget.id
4567
- });
4568
- toast10.success("Ferramenta removida");
4569
- } catch (err) {
4570
- toast10.error(
4571
- err instanceof Error ? err.message : "Erro ao remover ferramenta"
4572
- );
4573
- } finally {
4574
- setRemoveTarget(null);
4575
- }
4576
- }
4577
- function openConfig(agentTool) {
4578
- setConfigTarget(agentTool);
4579
- setConfigInstructions(agentTool.custom_instructions || "");
4580
- setConfigCredentialId(agentTool.id_tool_credential ? String(agentTool.id_tool_credential) : "");
4581
- }
4582
- async function handleSaveConfig() {
4583
- if (!configTarget) return;
4584
- try {
4585
- const newCredentialId = configCredentialId ? parseInt(configCredentialId, 10) : null;
4586
- await updateMutation.mutateAsync({
4587
- idAgent: agent.id,
4588
- id: configTarget.id,
4589
- body: {
4590
- custom_instructions: configInstructions.trim() || null,
4591
- id_tool_credential: newCredentialId
4592
- }
4593
- });
4594
- toast10.success("Configura\xE7\xE3o atualizada");
4595
- setConfigTarget(null);
4596
- } catch (err) {
4597
- toast10.error(
4598
- err instanceof Error ? err.message : "Erro ao atualizar configura\xE7\xE3o"
4599
- );
4600
- }
4007
+ async function handleSaveConfig() {
4008
+ if (!configTarget) return;
4009
+ try {
4010
+ const newCredentialId = configCredentialId ? parseInt(configCredentialId, 10) : null;
4011
+ await updateMutation.mutateAsync({
4012
+ idAgent: agent.id,
4013
+ id: configTarget.id,
4014
+ body: {
4015
+ custom_instructions: configInstructions.trim() || null,
4016
+ id_tool_credential: newCredentialId
4017
+ }
4018
+ });
4019
+ toast8.success("Configura\xE7\xE3o atualizada");
4020
+ setConfigTarget(null);
4021
+ } catch (err) {
4022
+ toast8.error(
4023
+ err instanceof Error ? err.message : "Erro ao atualizar configura\xE7\xE3o"
4024
+ );
4025
+ }
4601
4026
  }
4602
4027
  if (isLoading) {
4603
- return /* @__PURE__ */ jsx23("div", { className: "space-y-3 p-4", children: Array.from({ length: 3 }).map((_, i) => /* @__PURE__ */ jsx23(Skeleton6, { className: "h-14 w-full" }, i)) });
4028
+ return /* @__PURE__ */ jsx19("div", { className: "space-y-3 p-4", children: Array.from({ length: 3 }).map((_, i) => /* @__PURE__ */ jsx19(Skeleton6, { className: "h-14 w-full" }, i)) });
4604
4029
  }
4605
- return /* @__PURE__ */ jsxs21("div", { className: "space-y-4 p-4", children: [
4606
- /* @__PURE__ */ jsxs21("div", { className: "flex items-center justify-between", children: [
4607
- /* @__PURE__ */ jsxs21("h3", { className: "text-sm font-medium text-muted-foreground", children: [
4030
+ return /* @__PURE__ */ jsxs17("div", { className: "space-y-4 p-4", children: [
4031
+ /* @__PURE__ */ jsxs17("div", { className: "flex items-center justify-between", children: [
4032
+ /* @__PURE__ */ jsxs17("h3", { className: "text-sm font-medium text-muted-foreground", children: [
4608
4033
  visibleAgentTools.length,
4609
4034
  " ferramenta",
4610
4035
  visibleAgentTools.length !== 1 ? "s" : "",
4611
4036
  " associada",
4612
4037
  visibleAgentTools.length !== 1 ? "s" : ""
4613
4038
  ] }),
4614
- /* @__PURE__ */ jsxs21(Popover, { open: addOpen, onOpenChange: setAddOpen, children: [
4615
- /* @__PURE__ */ jsx23(PopoverTrigger, { asChild: true, children: /* @__PURE__ */ jsxs21(Button13, { size: "sm", disabled: availableTools.length === 0, children: [
4616
- /* @__PURE__ */ jsx23(Plus3, { className: "mr-2 h-4 w-4" }),
4039
+ /* @__PURE__ */ jsxs17(Popover, { open: addOpen, onOpenChange: setAddOpen, children: [
4040
+ /* @__PURE__ */ jsx19(PopoverTrigger, { asChild: true, children: /* @__PURE__ */ jsxs17(Button11, { size: "sm", disabled: availableTools.length === 0, children: [
4041
+ /* @__PURE__ */ jsx19(Plus3, { className: "mr-2 h-4 w-4" }),
4617
4042
  "Adicionar Ferramenta"
4618
4043
  ] }) }),
4619
- /* @__PURE__ */ jsxs21(PopoverContent, { className: "w-72 p-0", align: "end", children: [
4620
- /* @__PURE__ */ jsx23("div", { className: "p-2", children: /* @__PURE__ */ jsx23(
4621
- Input9,
4044
+ /* @__PURE__ */ jsxs17(PopoverContent, { className: "w-72 p-0", align: "end", children: [
4045
+ /* @__PURE__ */ jsx19("div", { className: "p-2", children: /* @__PURE__ */ jsx19(
4046
+ Input7,
4622
4047
  {
4623
4048
  placeholder: "Buscar ferramenta\\u2026",
4624
4049
  "aria-label": "Buscar ferramenta",
@@ -4628,7 +4053,7 @@ function AgentToolsList({ agent, config }) {
4628
4053
  className: "h-8"
4629
4054
  }
4630
4055
  ) }),
4631
- /* @__PURE__ */ jsx23("div", { className: "max-h-48 overflow-y-auto", children: filteredAvailable.length === 0 ? /* @__PURE__ */ jsx23("p", { className: "p-3 text-center text-sm text-muted-foreground", children: "Nenhuma ferramenta dispon\xEDvel" }) : filteredAvailable.map((tool) => /* @__PURE__ */ jsxs21(
4056
+ /* @__PURE__ */ jsx19("div", { className: "max-h-48 overflow-y-auto", children: filteredAvailable.length === 0 ? /* @__PURE__ */ jsx19("p", { className: "p-3 text-center text-sm text-muted-foreground", children: "Nenhuma ferramenta dispon\xEDvel" }) : filteredAvailable.map((tool) => /* @__PURE__ */ jsxs17(
4632
4057
  "button",
4633
4058
  {
4634
4059
  type: "button",
@@ -4636,9 +4061,9 @@ function AgentToolsList({ agent, config }) {
4636
4061
  onClick: () => handleAdd(tool),
4637
4062
  disabled: addMutation.isPending,
4638
4063
  children: [
4639
- /* @__PURE__ */ jsx23(Wrench, { className: "h-4 w-4 text-muted-foreground" }),
4640
- /* @__PURE__ */ jsx23("span", { className: "flex-1 font-medium", children: tool.name }),
4641
- /* @__PURE__ */ jsx23(Badge8, { variant: "secondary", className: "text-xs", children: tool.type })
4064
+ /* @__PURE__ */ jsx19(Wrench, { className: "h-4 w-4 text-muted-foreground" }),
4065
+ /* @__PURE__ */ jsx19("span", { className: "flex-1 font-medium", children: tool.name }),
4066
+ /* @__PURE__ */ jsx19(Badge7, { variant: "secondary", className: "text-xs", children: tool.type })
4642
4067
  ]
4643
4068
  },
4644
4069
  tool.id
@@ -4646,24 +4071,24 @@ function AgentToolsList({ agent, config }) {
4646
4071
  ] })
4647
4072
  ] })
4648
4073
  ] }),
4649
- visibleAgentTools.length === 0 ? /* @__PURE__ */ jsxs21("div", { className: "flex flex-col items-center justify-center rounded-lg border border-dashed p-8 text-center", children: [
4650
- /* @__PURE__ */ jsx23(Wrench, { className: "mb-2 h-8 w-8 text-muted-foreground" }),
4651
- /* @__PURE__ */ jsx23("p", { className: "text-sm text-muted-foreground", children: "Nenhuma ferramenta associada. Clique em 'Adicionar Ferramenta' para come\xE7ar." })
4652
- ] }) : /* @__PURE__ */ jsx23("div", { className: "space-y-2", children: visibleAgentTools.map((agentTool) => {
4074
+ visibleAgentTools.length === 0 ? /* @__PURE__ */ jsxs17("div", { className: "flex flex-col items-center justify-center rounded-lg border border-dashed p-8 text-center", children: [
4075
+ /* @__PURE__ */ jsx19(Wrench, { className: "mb-2 h-8 w-8 text-muted-foreground" }),
4076
+ /* @__PURE__ */ jsx19("p", { className: "text-sm text-muted-foreground", children: "Nenhuma ferramenta associada. Clique em 'Adicionar Ferramenta' para come\xE7ar." })
4077
+ ] }) : /* @__PURE__ */ jsx19("div", { className: "space-y-2", children: visibleAgentTools.map((agentTool) => {
4653
4078
  const tool = getToolInfo(agentTool.id_tool);
4654
- return /* @__PURE__ */ jsxs21(
4079
+ return /* @__PURE__ */ jsxs17(
4655
4080
  "div",
4656
4081
  {
4657
4082
  className: "flex items-center gap-3 rounded-lg border bg-card p-3",
4658
4083
  children: [
4659
- /* @__PURE__ */ jsxs21("div", { className: "flex flex-1 flex-col gap-1 min-w-0", children: [
4660
- /* @__PURE__ */ jsxs21("div", { className: "flex items-center gap-2", children: [
4661
- /* @__PURE__ */ jsx23("span", { className: "truncate font-medium", children: tool?.name || `Ferramenta #${agentTool.id_tool}` }),
4662
- tool?.type && /* @__PURE__ */ jsx23(Badge8, { variant: "secondary", className: "shrink-0 text-xs", children: tool.type })
4084
+ /* @__PURE__ */ jsxs17("div", { className: "flex flex-1 flex-col gap-1 min-w-0", children: [
4085
+ /* @__PURE__ */ jsxs17("div", { className: "flex items-center gap-2", children: [
4086
+ /* @__PURE__ */ jsx19("span", { className: "truncate font-medium", children: tool?.name || `Ferramenta #${agentTool.id_tool}` }),
4087
+ tool?.type && /* @__PURE__ */ jsx19(Badge7, { variant: "secondary", className: "shrink-0 text-xs", children: tool.type })
4663
4088
  ] }),
4664
- agentTool.custom_instructions && /* @__PURE__ */ jsx23("p", { className: "truncate text-xs text-muted-foreground", children: agentTool.custom_instructions })
4089
+ agentTool.custom_instructions && /* @__PURE__ */ jsx19("p", { className: "truncate text-xs text-muted-foreground", children: agentTool.custom_instructions })
4665
4090
  ] }),
4666
- /* @__PURE__ */ jsx23(
4091
+ /* @__PURE__ */ jsx19(
4667
4092
  Switch5,
4668
4093
  {
4669
4094
  "aria-label": "Ativar/Desativar",
@@ -4672,8 +4097,8 @@ function AgentToolsList({ agent, config }) {
4672
4097
  disabled: updateMutation.isPending
4673
4098
  }
4674
4099
  ),
4675
- /* @__PURE__ */ jsx23(
4676
- Button13,
4100
+ /* @__PURE__ */ jsx19(
4101
+ Button11,
4677
4102
  {
4678
4103
  variant: "ghost",
4679
4104
  size: "icon",
@@ -4681,18 +4106,18 @@ function AgentToolsList({ agent, config }) {
4681
4106
  className: "shrink-0 text-muted-foreground hover:text-foreground",
4682
4107
  onClick: () => openConfig(agentTool),
4683
4108
  title: "Configurar instru\xE7\xF5es",
4684
- children: /* @__PURE__ */ jsx23(Settings22, { className: "h-4 w-4" })
4109
+ children: /* @__PURE__ */ jsx19(Settings22, { className: "h-4 w-4" })
4685
4110
  }
4686
4111
  ),
4687
- /* @__PURE__ */ jsx23(
4688
- Button13,
4112
+ /* @__PURE__ */ jsx19(
4113
+ Button11,
4689
4114
  {
4690
4115
  variant: "ghost",
4691
4116
  size: "icon",
4692
4117
  "aria-label": "Remover",
4693
4118
  className: "shrink-0 text-muted-foreground hover:text-destructive",
4694
4119
  onClick: () => setRemoveTarget(agentTool),
4695
- children: /* @__PURE__ */ jsx23(Trash24, { className: "h-4 w-4" })
4120
+ children: /* @__PURE__ */ jsx19(Trash23, { className: "h-4 w-4" })
4696
4121
  }
4697
4122
  )
4698
4123
  ]
@@ -4700,36 +4125,36 @@ function AgentToolsList({ agent, config }) {
4700
4125
  agentTool.id
4701
4126
  );
4702
4127
  }) }),
4703
- /* @__PURE__ */ jsx23(
4704
- Dialog6,
4128
+ /* @__PURE__ */ jsx19(
4129
+ Dialog5,
4705
4130
  {
4706
4131
  open: !!configTarget,
4707
4132
  onOpenChange: (open) => !open && setConfigTarget(null),
4708
- children: /* @__PURE__ */ jsxs21(DialogContent6, { className: "sm:max-w-lg", children: [
4709
- /* @__PURE__ */ jsx23(DialogHeader6, { children: /* @__PURE__ */ jsx23(DialogTitle6, { children: "Instru\xE7\xF5es da Ferramenta" }) }),
4710
- /* @__PURE__ */ jsxs21("div", { className: "space-y-4", children: [
4711
- configTarget && getToolInfo(configTarget.id_tool)?.type !== "none" && /* @__PURE__ */ jsxs21("div", { className: "space-y-2", children: [
4712
- /* @__PURE__ */ jsx23(Label8, { htmlFor: "tool-credential", children: "Credencial" }),
4713
- /* @__PURE__ */ jsxs21(
4714
- Select3,
4133
+ children: /* @__PURE__ */ jsxs17(DialogContent5, { className: "sm:max-w-lg", children: [
4134
+ /* @__PURE__ */ jsx19(DialogHeader5, { children: /* @__PURE__ */ jsx19(DialogTitle5, { children: "Instru\xE7\xF5es da Ferramenta" }) }),
4135
+ /* @__PURE__ */ jsxs17("div", { className: "space-y-4", children: [
4136
+ configTarget && getToolInfo(configTarget.id_tool)?.type !== "none" && /* @__PURE__ */ jsxs17("div", { className: "space-y-2", children: [
4137
+ /* @__PURE__ */ jsx19(Label7, { htmlFor: "tool-credential", children: "Credencial" }),
4138
+ /* @__PURE__ */ jsxs17(
4139
+ Select2,
4715
4140
  {
4716
4141
  value: configCredentialId || void 0,
4717
4142
  onValueChange: (val) => setConfigCredentialId(val === "__none__" ? "" : val),
4718
4143
  children: [
4719
- /* @__PURE__ */ jsx23(SelectTrigger3, { id: "tool-credential", children: /* @__PURE__ */ jsx23(SelectValue3, { placeholder: "Selecione uma credencial (opcional)" }) }),
4720
- /* @__PURE__ */ jsxs21(SelectContent3, { children: [
4721
- /* @__PURE__ */ jsx23(SelectItem3, { value: "__none__", children: "Nenhuma (autom\xE1tico)" }),
4722
- allCredentials.filter((c) => configTarget && c.id_tool === configTarget.id_tool && c.status === "active").map((c) => /* @__PURE__ */ jsx23(SelectItem3, { value: String(c.id), children: c.label || `Credencial #${c.id}` }, c.id))
4144
+ /* @__PURE__ */ jsx19(SelectTrigger2, { id: "tool-credential", children: /* @__PURE__ */ jsx19(SelectValue2, { placeholder: "Selecione uma credencial (opcional)" }) }),
4145
+ /* @__PURE__ */ jsxs17(SelectContent2, { children: [
4146
+ /* @__PURE__ */ jsx19(SelectItem2, { value: "__none__", children: "Nenhuma (autom\xE1tico)" }),
4147
+ allCredentials.filter((c) => configTarget && c.id_tool === configTarget.id_tool && c.status === "active").map((c) => /* @__PURE__ */ jsx19(SelectItem2, { value: String(c.id), children: c.label || `Credencial #${c.id}` }, c.id))
4723
4148
  ] })
4724
4149
  ]
4725
4150
  }
4726
4151
  ),
4727
- /* @__PURE__ */ jsx23("p", { className: "text-xs text-muted-foreground", children: "Vincule uma credencial espec\xEDfica a esta ferramenta neste agente." })
4152
+ /* @__PURE__ */ jsx19("p", { className: "text-xs text-muted-foreground", children: "Vincule uma credencial espec\xEDfica a esta ferramenta neste agente." })
4728
4153
  ] }),
4729
- /* @__PURE__ */ jsxs21("div", { className: "space-y-2", children: [
4730
- /* @__PURE__ */ jsx23(Label8, { htmlFor: "tool-instructions", children: "Instru\xE7\xF5es Personalizadas" }),
4731
- /* @__PURE__ */ jsx23(
4732
- Textarea3,
4154
+ /* @__PURE__ */ jsxs17("div", { className: "space-y-2", children: [
4155
+ /* @__PURE__ */ jsx19(Label7, { htmlFor: "tool-instructions", children: "Instru\xE7\xF5es Personalizadas" }),
4156
+ /* @__PURE__ */ jsx19(
4157
+ Textarea2,
4733
4158
  {
4734
4159
  id: "tool-instructions",
4735
4160
  name: "instructions",
@@ -4739,20 +4164,20 @@ function AgentToolsList({ agent, config }) {
4739
4164
  rows: 6
4740
4165
  }
4741
4166
  ),
4742
- /* @__PURE__ */ jsx23("p", { className: "text-xs text-muted-foreground", children: "Este texto \xE9 adicionado ao prompt do agente para orientar o uso da ferramenta." })
4167
+ /* @__PURE__ */ jsx19("p", { className: "text-xs text-muted-foreground", children: "Este texto \xE9 adicionado ao prompt do agente para orientar o uso da ferramenta." })
4743
4168
  ] })
4744
4169
  ] }),
4745
- /* @__PURE__ */ jsxs21(DialogFooter6, { children: [
4746
- /* @__PURE__ */ jsx23(
4747
- Button13,
4170
+ /* @__PURE__ */ jsxs17(DialogFooter5, { children: [
4171
+ /* @__PURE__ */ jsx19(
4172
+ Button11,
4748
4173
  {
4749
4174
  variant: "outline",
4750
4175
  onClick: () => setConfigTarget(null),
4751
4176
  children: "Cancelar"
4752
4177
  }
4753
4178
  ),
4754
- /* @__PURE__ */ jsx23(
4755
- Button13,
4179
+ /* @__PURE__ */ jsx19(
4180
+ Button11,
4756
4181
  {
4757
4182
  onClick: handleSaveConfig,
4758
4183
  disabled: updateMutation.isPending,
@@ -4762,36 +4187,500 @@ function AgentToolsList({ agent, config }) {
4762
4187
  ] })
4763
4188
  ] })
4764
4189
  }
4765
- ),
4766
- /* @__PURE__ */ jsx23(
4767
- AlertDialog4,
4768
- {
4769
- open: !!removeTarget,
4770
- onOpenChange: (open) => !open && setRemoveTarget(null),
4771
- children: /* @__PURE__ */ jsxs21(AlertDialogContent4, { children: [
4772
- /* @__PURE__ */ jsxs21(AlertDialogHeader4, { children: [
4773
- /* @__PURE__ */ jsx23(AlertDialogTitle4, { children: "Remover ferramenta?" }),
4774
- /* @__PURE__ */ jsx23(AlertDialogDescription4, { children: "A ferramenta ser\xE1 desassociada deste agente." })
4775
- ] }),
4776
- /* @__PURE__ */ jsxs21(AlertDialogFooter4, { children: [
4777
- /* @__PURE__ */ jsx23(AlertDialogCancel4, { children: "Cancelar" }),
4778
- /* @__PURE__ */ jsx23(
4779
- AlertDialogAction4,
4780
- {
4781
- onClick: handleRemove,
4782
- disabled: removeMutation.isPending,
4783
- children: "Remover"
4784
- }
4785
- )
4786
- ] })
4190
+ ),
4191
+ /* @__PURE__ */ jsx19(
4192
+ AlertDialog3,
4193
+ {
4194
+ open: !!removeTarget,
4195
+ onOpenChange: (open) => !open && setRemoveTarget(null),
4196
+ children: /* @__PURE__ */ jsxs17(AlertDialogContent3, { children: [
4197
+ /* @__PURE__ */ jsxs17(AlertDialogHeader3, { children: [
4198
+ /* @__PURE__ */ jsx19(AlertDialogTitle3, { children: "Remover ferramenta?" }),
4199
+ /* @__PURE__ */ jsx19(AlertDialogDescription3, { children: "A ferramenta ser\xE1 desassociada deste agente." })
4200
+ ] }),
4201
+ /* @__PURE__ */ jsxs17(AlertDialogFooter3, { children: [
4202
+ /* @__PURE__ */ jsx19(AlertDialogCancel3, { children: "Cancelar" }),
4203
+ /* @__PURE__ */ jsx19(
4204
+ AlertDialogAction3,
4205
+ {
4206
+ onClick: handleRemove,
4207
+ disabled: removeMutation.isPending,
4208
+ children: "Remover"
4209
+ }
4210
+ )
4211
+ ] })
4212
+ ] })
4213
+ }
4214
+ )
4215
+ ] });
4216
+ }
4217
+
4218
+ // src/components/tools/tools-table.tsx
4219
+ import { useMemo as useMemo6, useState as useState12 } from "react";
4220
+ import { DataTable as DataTable2 } from "@greatapps/greatauth-ui";
4221
+ import {
4222
+ Input as Input8,
4223
+ Badge as Badge8,
4224
+ Tooltip as Tooltip3,
4225
+ TooltipTrigger as TooltipTrigger3,
4226
+ TooltipContent as TooltipContent3,
4227
+ AlertDialog as AlertDialog4,
4228
+ AlertDialogAction as AlertDialogAction4,
4229
+ AlertDialogCancel as AlertDialogCancel4,
4230
+ AlertDialogContent as AlertDialogContent4,
4231
+ AlertDialogDescription as AlertDialogDescription4,
4232
+ AlertDialogFooter as AlertDialogFooter4,
4233
+ AlertDialogHeader as AlertDialogHeader4,
4234
+ AlertDialogTitle as AlertDialogTitle4,
4235
+ Button as Button12
4236
+ } from "@greatapps/greatauth-ui/ui";
4237
+ import { Pencil as Pencil3, Trash2 as Trash24, Search as Search2 } from "lucide-react";
4238
+ import { format as format2 } from "date-fns";
4239
+ import { ptBR as ptBR2 } from "date-fns/locale";
4240
+ import { toast as toast9 } from "sonner";
4241
+ import { Fragment as Fragment3, jsx as jsx20, jsxs as jsxs18 } from "react/jsx-runtime";
4242
+ function useColumns2(onEdit, onDelete) {
4243
+ return [
4244
+ {
4245
+ accessorKey: "name",
4246
+ header: "Nome",
4247
+ cell: ({ row }) => /* @__PURE__ */ jsx20("span", { className: "font-medium", children: row.original.name }),
4248
+ sortingFn: (rowA, rowB) => rowA.original.name.toLowerCase().localeCompare(rowB.original.name.toLowerCase())
4249
+ },
4250
+ {
4251
+ accessorKey: "slug",
4252
+ header: "Slug",
4253
+ cell: ({ row }) => /* @__PURE__ */ jsx20("span", { className: "text-muted-foreground text-sm font-mono", children: row.original.slug || "\u2014" })
4254
+ },
4255
+ {
4256
+ accessorKey: "type",
4257
+ header: "Tipo",
4258
+ cell: ({ row }) => /* @__PURE__ */ jsx20(Badge8, { variant: "secondary", children: row.original.type })
4259
+ },
4260
+ {
4261
+ accessorKey: "description",
4262
+ header: "Descri\xE7\xE3o",
4263
+ cell: ({ row }) => {
4264
+ const desc = row.original.description;
4265
+ if (!desc) return /* @__PURE__ */ jsx20("span", { className: "text-muted-foreground text-sm", children: "\u2014" });
4266
+ return /* @__PURE__ */ jsx20("span", { className: "text-muted-foreground text-sm", children: desc.length > 50 ? `${desc.slice(0, 50)}\u2026` : desc });
4267
+ }
4268
+ },
4269
+ {
4270
+ accessorKey: "datetime_add",
4271
+ header: "Criado em",
4272
+ cell: ({ row }) => /* @__PURE__ */ jsx20("span", { className: "text-muted-foreground text-sm", children: format2(new Date(row.original.datetime_add), "dd/MM/yyyy", {
4273
+ locale: ptBR2
4274
+ }) })
4275
+ },
4276
+ {
4277
+ id: "actions",
4278
+ size: 80,
4279
+ enableSorting: false,
4280
+ cell: ({ row }) => /* @__PURE__ */ jsxs18("div", { className: "flex items-center gap-1", children: [
4281
+ /* @__PURE__ */ jsxs18(Tooltip3, { children: [
4282
+ /* @__PURE__ */ jsx20(TooltipTrigger3, { asChild: true, children: /* @__PURE__ */ jsx20(
4283
+ Button12,
4284
+ {
4285
+ variant: "ghost",
4286
+ size: "icon",
4287
+ className: "h-8 w-8",
4288
+ "aria-label": "Editar",
4289
+ onClick: () => onEdit(row.original),
4290
+ children: /* @__PURE__ */ jsx20(Pencil3, { className: "h-4 w-4" })
4291
+ }
4292
+ ) }),
4293
+ /* @__PURE__ */ jsx20(TooltipContent3, { children: "Editar" })
4294
+ ] }),
4295
+ /* @__PURE__ */ jsxs18(Tooltip3, { children: [
4296
+ /* @__PURE__ */ jsx20(TooltipTrigger3, { asChild: true, children: /* @__PURE__ */ jsx20(
4297
+ Button12,
4298
+ {
4299
+ variant: "ghost",
4300
+ size: "icon",
4301
+ className: "h-8 w-8 text-destructive hover:text-destructive",
4302
+ "aria-label": "Excluir",
4303
+ onClick: () => onDelete(row.original.id),
4304
+ children: /* @__PURE__ */ jsx20(Trash24, { className: "h-4 w-4" })
4305
+ }
4306
+ ) }),
4307
+ /* @__PURE__ */ jsx20(TooltipContent3, { children: "Excluir" })
4308
+ ] })
4309
+ ] })
4310
+ }
4311
+ ];
4312
+ }
4313
+ function ToolsTable({ onEdit, config }) {
4314
+ const [search, setSearch] = useState12("");
4315
+ const [page, setPage] = useState12(1);
4316
+ const queryParams = useMemo6(() => {
4317
+ const params = {
4318
+ limit: "15",
4319
+ page: String(page)
4320
+ };
4321
+ if (search) {
4322
+ params.search = search;
4323
+ }
4324
+ return params;
4325
+ }, [search, page]);
4326
+ const { data, isLoading } = useTools(config, queryParams);
4327
+ const deleteTool = useDeleteTool(config);
4328
+ const [deleteId, setDeleteId] = useState12(null);
4329
+ const rawTools = data?.data || [];
4330
+ const tools = rawTools.filter((t) => !t.slug?.startsWith("gclinic_"));
4331
+ const total = tools.length;
4332
+ const columns = useColumns2(
4333
+ (tool) => onEdit(tool),
4334
+ (id) => setDeleteId(id)
4335
+ );
4336
+ function handleDelete() {
4337
+ if (!deleteId) return;
4338
+ deleteTool.mutate(deleteId, {
4339
+ onSuccess: () => {
4340
+ toast9.success("Ferramenta exclu\xEDda");
4341
+ setDeleteId(null);
4342
+ },
4343
+ onError: () => toast9.error("Erro ao excluir ferramenta")
4344
+ });
4345
+ }
4346
+ function handleSearchChange(value) {
4347
+ setSearch(value);
4348
+ setPage(1);
4349
+ }
4350
+ return /* @__PURE__ */ jsxs18(Fragment3, { children: [
4351
+ /* @__PURE__ */ jsx20("div", { className: "flex items-center gap-3", children: /* @__PURE__ */ jsxs18("div", { className: "relative flex-1 max-w-md", children: [
4352
+ /* @__PURE__ */ jsx20(Search2, { "aria-hidden": "true", className: "absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground" }),
4353
+ /* @__PURE__ */ jsx20(
4354
+ Input8,
4355
+ {
4356
+ placeholder: "Buscar ferramentas\\u2026",
4357
+ "aria-label": "Buscar ferramentas",
4358
+ name: "search",
4359
+ autoComplete: "off",
4360
+ value: search,
4361
+ onChange: (e) => handleSearchChange(e.target.value),
4362
+ className: "pl-9"
4363
+ }
4364
+ )
4365
+ ] }) }),
4366
+ /* @__PURE__ */ jsx20(
4367
+ DataTable2,
4368
+ {
4369
+ columns,
4370
+ data: tools,
4371
+ isLoading,
4372
+ emptyMessage: "Nenhuma ferramenta encontrada",
4373
+ total,
4374
+ page,
4375
+ onPageChange: setPage,
4376
+ pageSize: 15
4377
+ }
4378
+ ),
4379
+ /* @__PURE__ */ jsx20(
4380
+ AlertDialog4,
4381
+ {
4382
+ open: !!deleteId,
4383
+ onOpenChange: (open) => !open && setDeleteId(null),
4384
+ children: /* @__PURE__ */ jsxs18(AlertDialogContent4, { children: [
4385
+ /* @__PURE__ */ jsxs18(AlertDialogHeader4, { children: [
4386
+ /* @__PURE__ */ jsx20(AlertDialogTitle4, { children: "Excluir ferramenta?" }),
4387
+ /* @__PURE__ */ jsx20(AlertDialogDescription4, { children: "Esta a\xE7\xE3o n\xE3o pode ser desfeita. A ferramenta ser\xE1 removida permanentemente." })
4388
+ ] }),
4389
+ /* @__PURE__ */ jsxs18(AlertDialogFooter4, { children: [
4390
+ /* @__PURE__ */ jsx20(AlertDialogCancel4, { variant: "outline", size: "default", children: "Cancelar" }),
4391
+ /* @__PURE__ */ jsx20(
4392
+ AlertDialogAction4,
4393
+ {
4394
+ variant: "default",
4395
+ size: "default",
4396
+ onClick: handleDelete,
4397
+ className: "bg-destructive text-destructive-foreground hover:bg-destructive/90",
4398
+ children: "Excluir"
4399
+ }
4400
+ )
4401
+ ] })
4402
+ ] })
4403
+ }
4404
+ )
4405
+ ] });
4406
+ }
4407
+
4408
+ // src/components/tools/tool-form-dialog.tsx
4409
+ import { useState as useState13 } from "react";
4410
+ import {
4411
+ Dialog as Dialog6,
4412
+ DialogContent as DialogContent6,
4413
+ DialogHeader as DialogHeader6,
4414
+ DialogTitle as DialogTitle6,
4415
+ DialogFooter as DialogFooter6,
4416
+ Button as Button13,
4417
+ Input as Input9,
4418
+ Textarea as Textarea3,
4419
+ Label as Label8,
4420
+ Select as Select3,
4421
+ SelectContent as SelectContent3,
4422
+ SelectItem as SelectItem3,
4423
+ SelectTrigger as SelectTrigger3,
4424
+ SelectValue as SelectValue3
4425
+ } from "@greatapps/greatauth-ui/ui";
4426
+ import { Loader2 as Loader29 } from "lucide-react";
4427
+ import { toast as toast10 } from "sonner";
4428
+ import { jsx as jsx21, jsxs as jsxs19 } from "react/jsx-runtime";
4429
+ var TOOL_AUTH_TYPES = [
4430
+ { value: "none", label: "Nenhuma" },
4431
+ { value: "api_key", label: "API Key" },
4432
+ { value: "oauth2", label: "OAuth 2.0" }
4433
+ ];
4434
+ function toolToFormState(tool) {
4435
+ return {
4436
+ name: tool?.name || "",
4437
+ slug: tool?.slug || "",
4438
+ type: tool?.type || "none",
4439
+ description: tool?.description || "",
4440
+ functionDefinitions: tool?.function_definitions ? formatJson(tool.function_definitions) : "",
4441
+ nameError: false,
4442
+ slugError: false,
4443
+ typeError: false,
4444
+ jsonError: false
4445
+ };
4446
+ }
4447
+ function formatJson(str) {
4448
+ try {
4449
+ return JSON.stringify(JSON.parse(str), null, 2);
4450
+ } catch {
4451
+ return str;
4452
+ }
4453
+ }
4454
+ function slugify2(name) {
4455
+ return name.toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g, "").replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
4456
+ }
4457
+ function isValidJson(str) {
4458
+ if (!str.trim()) return true;
4459
+ try {
4460
+ JSON.parse(str);
4461
+ return true;
4462
+ } catch {
4463
+ return false;
4464
+ }
4465
+ }
4466
+ function ToolFormDialog({
4467
+ open,
4468
+ onOpenChange,
4469
+ tool,
4470
+ config
4471
+ }) {
4472
+ const isEditing = !!tool;
4473
+ const createTool = useCreateTool(config);
4474
+ const updateTool = useUpdateTool(config);
4475
+ const [form, setForm] = useState13(() => toolToFormState(tool));
4476
+ const [slugManuallyEdited, setSlugManuallyEdited] = useState13(false);
4477
+ const [lastResetKey, setLastResetKey] = useState13(
4478
+ () => `${tool?.id}-${open}`
4479
+ );
4480
+ const resetKey = `${tool?.id}-${open}`;
4481
+ if (resetKey !== lastResetKey) {
4482
+ setLastResetKey(resetKey);
4483
+ setForm(toolToFormState(open ? tool : void 0));
4484
+ setSlugManuallyEdited(false);
4485
+ }
4486
+ const isPending = createTool.isPending || updateTool.isPending;
4487
+ async function handleSubmit(e) {
4488
+ e.preventDefault();
4489
+ let hasError = false;
4490
+ if (!form.name.trim()) {
4491
+ setForm((prev) => ({ ...prev, nameError: true }));
4492
+ hasError = true;
4493
+ }
4494
+ const effectiveSlug = form.slug.trim() || slugify2(form.name);
4495
+ if (!effectiveSlug) {
4496
+ setForm((prev) => ({ ...prev, slugError: true }));
4497
+ hasError = true;
4498
+ }
4499
+ if (!form.type) {
4500
+ setForm((prev) => ({ ...prev, typeError: true }));
4501
+ hasError = true;
4502
+ }
4503
+ if (!isValidJson(form.functionDefinitions)) {
4504
+ setForm((prev) => ({ ...prev, jsonError: true }));
4505
+ hasError = true;
4506
+ }
4507
+ if (hasError) return;
4508
+ const body = {
4509
+ name: form.name.trim(),
4510
+ slug: effectiveSlug,
4511
+ type: form.type
4512
+ };
4513
+ if (form.description.trim()) body.description = form.description.trim();
4514
+ else body.description = "";
4515
+ if (form.functionDefinitions.trim()) {
4516
+ const parsed = JSON.parse(form.functionDefinitions.trim());
4517
+ body.function_definitions = JSON.stringify(parsed);
4518
+ } else {
4519
+ body.function_definitions = "";
4520
+ }
4521
+ try {
4522
+ if (isEditing) {
4523
+ await updateTool.mutateAsync({ id: tool.id, body });
4524
+ toast10.success("Ferramenta atualizada");
4525
+ } else {
4526
+ await createTool.mutateAsync(
4527
+ body
4528
+ );
4529
+ toast10.success("Ferramenta criada");
4530
+ }
4531
+ onOpenChange(false);
4532
+ } catch (err) {
4533
+ toast10.error(
4534
+ err instanceof Error ? err.message : isEditing ? "Erro ao atualizar ferramenta" : "Erro ao criar ferramenta"
4535
+ );
4536
+ }
4537
+ }
4538
+ return /* @__PURE__ */ jsx21(Dialog6, { open, onOpenChange, children: /* @__PURE__ */ jsxs19(DialogContent6, { className: "sm:max-w-lg", children: [
4539
+ /* @__PURE__ */ jsx21(DialogHeader6, { children: /* @__PURE__ */ jsx21(DialogTitle6, { children: isEditing ? "Editar Ferramenta" : "Nova Ferramenta" }) }),
4540
+ /* @__PURE__ */ jsxs19("form", { onSubmit: handleSubmit, className: "space-y-4", children: [
4541
+ /* @__PURE__ */ jsxs19("div", { className: "space-y-2", children: [
4542
+ /* @__PURE__ */ jsx21(Label8, { htmlFor: "tool-name", children: "Nome *" }),
4543
+ /* @__PURE__ */ jsx21(
4544
+ Input9,
4545
+ {
4546
+ id: "tool-name",
4547
+ name: "name",
4548
+ value: form.name,
4549
+ onChange: (e) => {
4550
+ const name = e.target.value;
4551
+ setForm((prev) => ({
4552
+ ...prev,
4553
+ name,
4554
+ nameError: name.trim() ? false : prev.nameError,
4555
+ ...!slugManuallyEdited && !isEditing ? { slug: slugify2(name), slugError: false } : {}
4556
+ }));
4557
+ },
4558
+ placeholder: "Ex: Google Calendar",
4559
+ disabled: isPending
4560
+ }
4561
+ ),
4562
+ form.nameError && /* @__PURE__ */ jsx21("p", { className: "text-sm text-destructive", children: "Nome \xE9 obrigat\xF3rio" })
4563
+ ] }),
4564
+ /* @__PURE__ */ jsxs19("div", { className: "space-y-2", children: [
4565
+ /* @__PURE__ */ jsx21(Label8, { htmlFor: "tool-slug", children: "Slug (identificador \xFAnico) *" }),
4566
+ /* @__PURE__ */ jsx21(
4567
+ Input9,
4568
+ {
4569
+ id: "tool-slug",
4570
+ name: "slug",
4571
+ value: form.slug,
4572
+ onChange: (e) => {
4573
+ setSlugManuallyEdited(true);
4574
+ setForm((prev) => ({
4575
+ ...prev,
4576
+ slug: e.target.value,
4577
+ slugError: e.target.value.trim() ? false : prev.slugError
4578
+ }));
4579
+ },
4580
+ placeholder: "Ex: google-calendar",
4581
+ disabled: isPending
4582
+ }
4583
+ ),
4584
+ /* @__PURE__ */ jsx21("p", { className: "text-xs text-muted-foreground", children: "Gerado automaticamente a partir do nome. Usado internamente para identificar a ferramenta." }),
4585
+ form.slugError && /* @__PURE__ */ jsx21("p", { className: "text-sm text-destructive", children: "Slug \xE9 obrigat\xF3rio" })
4586
+ ] }),
4587
+ /* @__PURE__ */ jsxs19("div", { className: "space-y-2", children: [
4588
+ /* @__PURE__ */ jsx21(Label8, { htmlFor: "tool-type", children: "Tipo de Autentica\xE7\xE3o *" }),
4589
+ /* @__PURE__ */ jsxs19(
4590
+ Select3,
4591
+ {
4592
+ value: form.type,
4593
+ onValueChange: (value) => {
4594
+ setForm((prev) => ({
4595
+ ...prev,
4596
+ type: value,
4597
+ typeError: false
4598
+ }));
4599
+ },
4600
+ disabled: isPending,
4601
+ children: [
4602
+ /* @__PURE__ */ jsx21(SelectTrigger3, { id: "tool-type", children: /* @__PURE__ */ jsx21(SelectValue3, { placeholder: "Selecione o tipo" }) }),
4603
+ /* @__PURE__ */ jsx21(SelectContent3, { children: TOOL_AUTH_TYPES.map((t) => /* @__PURE__ */ jsx21(SelectItem3, { value: t.value, children: t.label }, t.value)) })
4604
+ ]
4605
+ }
4606
+ ),
4607
+ /* @__PURE__ */ jsx21("p", { className: "text-xs text-muted-foreground", children: "Define se a ferramenta requer credenciais para funcionar." }),
4608
+ form.typeError && /* @__PURE__ */ jsx21("p", { className: "text-sm text-destructive", children: "Tipo \xE9 obrigat\xF3rio" })
4609
+ ] }),
4610
+ /* @__PURE__ */ jsxs19("div", { className: "space-y-2", children: [
4611
+ /* @__PURE__ */ jsx21(Label8, { htmlFor: "tool-description", children: "Descri\xE7\xE3o" }),
4612
+ /* @__PURE__ */ jsx21(
4613
+ Textarea3,
4614
+ {
4615
+ id: "tool-description",
4616
+ name: "description",
4617
+ value: form.description,
4618
+ onChange: (e) => setForm((prev) => ({ ...prev, description: e.target.value })),
4619
+ placeholder: "Descri\\u00e7\\u00e3o da ferramenta\\u2026",
4620
+ rows: 3,
4621
+ disabled: isPending
4622
+ }
4623
+ )
4624
+ ] }),
4625
+ /* @__PURE__ */ jsxs19("div", { className: "space-y-2", children: [
4626
+ /* @__PURE__ */ jsx21(Label8, { htmlFor: "tool-function-defs", children: "Defini\xE7\xF5es de Fun\xE7\xE3o (JSON)" }),
4627
+ /* @__PURE__ */ jsx21(
4628
+ Textarea3,
4629
+ {
4630
+ id: "tool-function-defs",
4631
+ name: "functionDefs",
4632
+ value: form.functionDefinitions,
4633
+ onChange: (e) => {
4634
+ setForm((prev) => ({
4635
+ ...prev,
4636
+ functionDefinitions: e.target.value,
4637
+ jsonError: false
4638
+ }));
4639
+ },
4640
+ placeholder: `[
4641
+ {
4642
+ "type": "function",
4643
+ "function": {
4644
+ "name": "nome_da_funcao",
4645
+ "description": "O que a fun\xE7\xE3o faz",
4646
+ "parameters": {
4647
+ "type": "object",
4648
+ "properties": { \u2026 },
4649
+ "required": [\u2026]
4650
+ }
4651
+ }
4652
+ }
4653
+ ]`,
4654
+ rows: 10,
4655
+ className: "font-mono text-sm",
4656
+ disabled: isPending
4657
+ }
4658
+ ),
4659
+ /* @__PURE__ */ jsx21("p", { className: "text-xs text-muted-foreground", children: "Array de defini\xE7\xF5es no formato OpenAI Function Calling." }),
4660
+ form.jsonError && /* @__PURE__ */ jsx21("p", { className: "text-sm text-destructive", children: "JSON inv\xE1lido" })
4661
+ ] }),
4662
+ /* @__PURE__ */ jsxs19(DialogFooter6, { children: [
4663
+ /* @__PURE__ */ jsx21(
4664
+ Button13,
4665
+ {
4666
+ type: "button",
4667
+ variant: "outline",
4668
+ onClick: () => onOpenChange(false),
4669
+ disabled: isPending,
4670
+ children: "Cancelar"
4671
+ }
4672
+ ),
4673
+ /* @__PURE__ */ jsxs19(Button13, { type: "submit", disabled: isPending, children: [
4674
+ isPending ? /* @__PURE__ */ jsx21(Loader29, { "aria-hidden": "true", className: "mr-2 h-4 w-4 animate-spin" }) : null,
4675
+ isEditing ? "Salvar" : "Criar"
4787
4676
  ] })
4788
- }
4789
- )
4790
- ] });
4677
+ ] })
4678
+ ] })
4679
+ ] }) });
4791
4680
  }
4792
4681
 
4793
4682
  // src/components/tools/tool-credentials-form.tsx
4794
- import { useMemo as useMemo7, useState as useState15 } from "react";
4683
+ import { useMemo as useMemo7, useState as useState14 } from "react";
4795
4684
  import { DataTable as DataTable3 } from "@greatapps/greatauth-ui";
4796
4685
  import {
4797
4686
  Input as Input10,
@@ -4823,7 +4712,7 @@ import { Trash2 as Trash25, Pencil as Pencil4, Link, Search as Search3 } from "l
4823
4712
  import { format as format3 } from "date-fns";
4824
4713
  import { ptBR as ptBR3 } from "date-fns/locale";
4825
4714
  import { toast as toast11 } from "sonner";
4826
- import { jsx as jsx24, jsxs as jsxs22 } from "react/jsx-runtime";
4715
+ import { jsx as jsx22, jsxs as jsxs20 } from "react/jsx-runtime";
4827
4716
  function formatDate2(dateStr) {
4828
4717
  if (!dateStr) return "Sem expira\xE7\xE3o";
4829
4718
  return format3(new Date(dateStr), "dd/MM/yyyy", { locale: ptBR3 });
@@ -4843,17 +4732,17 @@ function useColumns3(tools, onEdit, onConnect, onRemove) {
4843
4732
  {
4844
4733
  accessorKey: "label",
4845
4734
  header: "Label",
4846
- cell: ({ row }) => /* @__PURE__ */ jsx24("span", { className: "font-medium", children: row.original.label || "\u2014" })
4735
+ cell: ({ row }) => /* @__PURE__ */ jsx22("span", { className: "font-medium", children: row.original.label || "\u2014" })
4847
4736
  },
4848
4737
  {
4849
4738
  accessorKey: "id_tool",
4850
4739
  header: "Ferramenta",
4851
- cell: ({ row }) => /* @__PURE__ */ jsx24("span", { className: "text-sm", children: getToolName(row.original.id_tool) })
4740
+ cell: ({ row }) => /* @__PURE__ */ jsx22("span", { className: "text-sm", children: getToolName(row.original.id_tool) })
4852
4741
  },
4853
4742
  {
4854
4743
  accessorKey: "status",
4855
4744
  header: "Status",
4856
- cell: ({ row }) => /* @__PURE__ */ jsx24(
4745
+ cell: ({ row }) => /* @__PURE__ */ jsx22(
4857
4746
  Badge9,
4858
4747
  {
4859
4748
  variant: row.original.status === "active" ? "default" : "destructive",
@@ -4864,21 +4753,21 @@ function useColumns3(tools, onEdit, onConnect, onRemove) {
4864
4753
  {
4865
4754
  accessorKey: "expires_at",
4866
4755
  header: "Expira em",
4867
- cell: ({ row }) => /* @__PURE__ */ jsx24("span", { className: "text-muted-foreground text-sm", children: formatDate2(row.original.expires_at) })
4756
+ cell: ({ row }) => /* @__PURE__ */ jsx22("span", { className: "text-muted-foreground text-sm", children: formatDate2(row.original.expires_at) })
4868
4757
  },
4869
4758
  {
4870
4759
  accessorKey: "datetime_add",
4871
4760
  header: "Criado em",
4872
- cell: ({ row }) => /* @__PURE__ */ jsx24("span", { className: "text-muted-foreground text-sm", children: formatDate2(row.original.datetime_add) })
4761
+ cell: ({ row }) => /* @__PURE__ */ jsx22("span", { className: "text-muted-foreground text-sm", children: formatDate2(row.original.datetime_add) })
4873
4762
  },
4874
4763
  {
4875
4764
  id: "actions",
4876
4765
  header: "A\xE7\xF5es",
4877
4766
  size: 100,
4878
4767
  enableSorting: false,
4879
- cell: ({ row }) => /* @__PURE__ */ jsxs22("div", { className: "flex items-center gap-1", children: [
4880
- getToolType(row.original.id_tool) === "oauth2" && /* @__PURE__ */ jsxs22(Tooltip4, { children: [
4881
- /* @__PURE__ */ jsx24(TooltipTrigger4, { asChild: true, children: /* @__PURE__ */ jsx24(
4768
+ cell: ({ row }) => /* @__PURE__ */ jsxs20("div", { className: "flex items-center gap-1", children: [
4769
+ getToolType(row.original.id_tool) === "oauth2" && /* @__PURE__ */ jsxs20(Tooltip4, { children: [
4770
+ /* @__PURE__ */ jsx22(TooltipTrigger4, { asChild: true, children: /* @__PURE__ */ jsx22(
4882
4771
  Button14,
4883
4772
  {
4884
4773
  variant: "ghost",
@@ -4886,13 +4775,13 @@ function useColumns3(tools, onEdit, onConnect, onRemove) {
4886
4775
  className: "h-8 w-8",
4887
4776
  "aria-label": "Vincular",
4888
4777
  disabled: true,
4889
- children: /* @__PURE__ */ jsx24(Link, { className: "h-4 w-4" })
4778
+ children: /* @__PURE__ */ jsx22(Link, { className: "h-4 w-4" })
4890
4779
  }
4891
4780
  ) }),
4892
- /* @__PURE__ */ jsx24(TooltipContent4, { children: "Em breve" })
4781
+ /* @__PURE__ */ jsx22(TooltipContent4, { children: "Em breve" })
4893
4782
  ] }),
4894
- /* @__PURE__ */ jsxs22(Tooltip4, { children: [
4895
- /* @__PURE__ */ jsx24(TooltipTrigger4, { asChild: true, children: /* @__PURE__ */ jsx24(
4783
+ /* @__PURE__ */ jsxs20(Tooltip4, { children: [
4784
+ /* @__PURE__ */ jsx22(TooltipTrigger4, { asChild: true, children: /* @__PURE__ */ jsx22(
4896
4785
  Button14,
4897
4786
  {
4898
4787
  variant: "ghost",
@@ -4900,13 +4789,13 @@ function useColumns3(tools, onEdit, onConnect, onRemove) {
4900
4789
  className: "h-8 w-8",
4901
4790
  "aria-label": "Editar",
4902
4791
  onClick: () => onEdit(row.original),
4903
- children: /* @__PURE__ */ jsx24(Pencil4, { className: "h-4 w-4" })
4792
+ children: /* @__PURE__ */ jsx22(Pencil4, { className: "h-4 w-4" })
4904
4793
  }
4905
4794
  ) }),
4906
- /* @__PURE__ */ jsx24(TooltipContent4, { children: "Editar" })
4795
+ /* @__PURE__ */ jsx22(TooltipContent4, { children: "Editar" })
4907
4796
  ] }),
4908
- /* @__PURE__ */ jsxs22(Tooltip4, { children: [
4909
- /* @__PURE__ */ jsx24(TooltipTrigger4, { asChild: true, children: /* @__PURE__ */ jsx24(
4797
+ /* @__PURE__ */ jsxs20(Tooltip4, { children: [
4798
+ /* @__PURE__ */ jsx22(TooltipTrigger4, { asChild: true, children: /* @__PURE__ */ jsx22(
4910
4799
  Button14,
4911
4800
  {
4912
4801
  variant: "ghost",
@@ -4914,10 +4803,10 @@ function useColumns3(tools, onEdit, onConnect, onRemove) {
4914
4803
  className: "h-8 w-8 text-destructive hover:text-destructive",
4915
4804
  "aria-label": "Excluir",
4916
4805
  onClick: () => onRemove(row.original),
4917
- children: /* @__PURE__ */ jsx24(Trash25, { className: "h-4 w-4" })
4806
+ children: /* @__PURE__ */ jsx22(Trash25, { className: "h-4 w-4" })
4918
4807
  }
4919
4808
  ) }),
4920
- /* @__PURE__ */ jsx24(TooltipContent4, { children: "Remover" })
4809
+ /* @__PURE__ */ jsx22(TooltipContent4, { children: "Remover" })
4921
4810
  ] })
4922
4811
  ] })
4923
4812
  }
@@ -4936,25 +4825,25 @@ function ToolCredentialsForm({
4936
4825
  const deleteMutation = useDeleteToolCredential(config);
4937
4826
  const { data: toolsData } = useTools(config);
4938
4827
  const tools = (toolsData?.data || []).filter((t) => !t.slug?.startsWith("gclinic_"));
4939
- const [search, setSearch] = useState15("");
4940
- const [internalCreateOpen, setInternalCreateOpen] = useState15(false);
4828
+ const [search, setSearch] = useState14("");
4829
+ const [internalCreateOpen, setInternalCreateOpen] = useState14(false);
4941
4830
  const showCreateDialog = externalCreateOpen ?? internalCreateOpen;
4942
4831
  const setShowCreateDialog = onCreateOpenChange ?? setInternalCreateOpen;
4943
- const [createForm, setCreateForm] = useState15({
4832
+ const [createForm, setCreateForm] = useState14({
4944
4833
  id_tool: "",
4945
4834
  label: "",
4946
4835
  credentials_encrypted: "",
4947
4836
  expires_at: ""
4948
4837
  });
4949
- const [editTarget, setEditTarget] = useState15(null);
4950
- const [editForm, setEditForm] = useState15({
4838
+ const [editTarget, setEditTarget] = useState14(null);
4839
+ const [editForm, setEditForm] = useState14({
4951
4840
  id_tool: "",
4952
4841
  label: "",
4953
4842
  credentials_encrypted: "",
4954
4843
  expires_at: "",
4955
4844
  status: ""
4956
4845
  });
4957
- const [removeTarget, setRemoveTarget] = useState15(null);
4846
+ const [removeTarget, setRemoveTarget] = useState14(null);
4958
4847
  const internalToolIds = useMemo7(() => {
4959
4848
  const allRawTools = toolsData?.data || [];
4960
4849
  return new Set(
@@ -5069,10 +4958,10 @@ function ToolCredentialsForm({
5069
4958
  const url = `${gagentsApiUrl}/v1/${language}/${idWl}/accounts/${config.accountId}/oauth/connect?id_tool=${cred.id_tool}`;
5070
4959
  window.open(url, "_blank");
5071
4960
  }
5072
- return /* @__PURE__ */ jsxs22("div", { className: "space-y-4", children: [
5073
- /* @__PURE__ */ jsx24("div", { className: "flex items-center gap-3", children: /* @__PURE__ */ jsxs22("div", { className: "relative flex-1 max-w-md", children: [
5074
- /* @__PURE__ */ jsx24(Search3, { "aria-hidden": "true", className: "absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground" }),
5075
- /* @__PURE__ */ jsx24(
4961
+ return /* @__PURE__ */ jsxs20("div", { className: "space-y-4", children: [
4962
+ /* @__PURE__ */ jsx22("div", { className: "flex items-center gap-3", children: /* @__PURE__ */ jsxs20("div", { className: "relative flex-1 max-w-md", children: [
4963
+ /* @__PURE__ */ jsx22(Search3, { "aria-hidden": "true", className: "absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground" }),
4964
+ /* @__PURE__ */ jsx22(
5076
4965
  Input10,
5077
4966
  {
5078
4967
  placeholder: "Buscar credenciais\\u2026",
@@ -5085,7 +4974,7 @@ function ToolCredentialsForm({
5085
4974
  }
5086
4975
  )
5087
4976
  ] }) }),
5088
- /* @__PURE__ */ jsx24(
4977
+ /* @__PURE__ */ jsx22(
5089
4978
  DataTable3,
5090
4979
  {
5091
4980
  columns,
@@ -5094,26 +4983,26 @@ function ToolCredentialsForm({
5094
4983
  emptyMessage: "Nenhuma credencial encontrada"
5095
4984
  }
5096
4985
  ),
5097
- /* @__PURE__ */ jsx24(Dialog7, { open: showCreateDialog, onOpenChange: setShowCreateDialog, children: /* @__PURE__ */ jsxs22(DialogContent7, { children: [
5098
- /* @__PURE__ */ jsx24(DialogHeader7, { children: /* @__PURE__ */ jsx24(DialogTitle7, { children: "Nova Credencial" }) }),
5099
- /* @__PURE__ */ jsxs22("div", { className: "space-y-4", children: [
5100
- /* @__PURE__ */ jsxs22("div", { children: [
5101
- /* @__PURE__ */ jsx24("label", { htmlFor: "cred-tool", className: "mb-1 block text-sm font-medium", children: "Ferramenta *" }),
5102
- /* @__PURE__ */ jsxs22(
4986
+ /* @__PURE__ */ jsx22(Dialog7, { open: showCreateDialog, onOpenChange: setShowCreateDialog, children: /* @__PURE__ */ jsxs20(DialogContent7, { children: [
4987
+ /* @__PURE__ */ jsx22(DialogHeader7, { children: /* @__PURE__ */ jsx22(DialogTitle7, { children: "Nova Credencial" }) }),
4988
+ /* @__PURE__ */ jsxs20("div", { className: "space-y-4", children: [
4989
+ /* @__PURE__ */ jsxs20("div", { children: [
4990
+ /* @__PURE__ */ jsx22("label", { htmlFor: "cred-tool", className: "mb-1 block text-sm font-medium", children: "Ferramenta *" }),
4991
+ /* @__PURE__ */ jsxs20(
5103
4992
  Select4,
5104
4993
  {
5105
4994
  value: createForm.id_tool,
5106
4995
  onValueChange: (val) => setCreateForm((f) => ({ ...f, id_tool: val })),
5107
4996
  children: [
5108
- /* @__PURE__ */ jsx24(SelectTrigger4, { id: "cred-tool", children: /* @__PURE__ */ jsx24(SelectValue4, { placeholder: "Selecione a ferramenta" }) }),
5109
- /* @__PURE__ */ jsx24(SelectContent4, { children: tools.map((tool) => /* @__PURE__ */ jsx24(SelectItem4, { value: String(tool.id), children: tool.name }, tool.id)) })
4997
+ /* @__PURE__ */ jsx22(SelectTrigger4, { id: "cred-tool", children: /* @__PURE__ */ jsx22(SelectValue4, { placeholder: "Selecione a ferramenta" }) }),
4998
+ /* @__PURE__ */ jsx22(SelectContent4, { children: tools.map((tool) => /* @__PURE__ */ jsx22(SelectItem4, { value: String(tool.id), children: tool.name }, tool.id)) })
5110
4999
  ]
5111
5000
  }
5112
5001
  )
5113
5002
  ] }),
5114
- /* @__PURE__ */ jsxs22("div", { children: [
5115
- /* @__PURE__ */ jsx24("label", { htmlFor: "cred-label", className: "mb-1 block text-sm font-medium", children: "Label *" }),
5116
- /* @__PURE__ */ jsx24(
5003
+ /* @__PURE__ */ jsxs20("div", { children: [
5004
+ /* @__PURE__ */ jsx22("label", { htmlFor: "cred-label", className: "mb-1 block text-sm font-medium", children: "Label *" }),
5005
+ /* @__PURE__ */ jsx22(
5117
5006
  Input10,
5118
5007
  {
5119
5008
  id: "cred-label",
@@ -5124,9 +5013,9 @@ function ToolCredentialsForm({
5124
5013
  }
5125
5014
  )
5126
5015
  ] }),
5127
- /* @__PURE__ */ jsxs22("div", { children: [
5128
- /* @__PURE__ */ jsx24("label", { htmlFor: "cred-credential", className: "mb-1 block text-sm font-medium", children: "Credencial *" }),
5129
- /* @__PURE__ */ jsx24(
5016
+ /* @__PURE__ */ jsxs20("div", { children: [
5017
+ /* @__PURE__ */ jsx22("label", { htmlFor: "cred-credential", className: "mb-1 block text-sm font-medium", children: "Credencial *" }),
5018
+ /* @__PURE__ */ jsx22(
5130
5019
  Input10,
5131
5020
  {
5132
5021
  id: "cred-credential",
@@ -5142,9 +5031,9 @@ function ToolCredentialsForm({
5142
5031
  }
5143
5032
  )
5144
5033
  ] }),
5145
- /* @__PURE__ */ jsxs22("div", { children: [
5146
- /* @__PURE__ */ jsx24("label", { htmlFor: "cred-expires", className: "mb-1 block text-sm font-medium", children: "Data de Expira\xE7\xE3o (opcional)" }),
5147
- /* @__PURE__ */ jsx24(
5034
+ /* @__PURE__ */ jsxs20("div", { children: [
5035
+ /* @__PURE__ */ jsx22("label", { htmlFor: "cred-expires", className: "mb-1 block text-sm font-medium", children: "Data de Expira\xE7\xE3o (opcional)" }),
5036
+ /* @__PURE__ */ jsx22(
5148
5037
  Input10,
5149
5038
  {
5150
5039
  id: "cred-expires",
@@ -5156,8 +5045,8 @@ function ToolCredentialsForm({
5156
5045
  )
5157
5046
  ] })
5158
5047
  ] }),
5159
- /* @__PURE__ */ jsxs22(DialogFooter7, { children: [
5160
- /* @__PURE__ */ jsx24(
5048
+ /* @__PURE__ */ jsxs20(DialogFooter7, { children: [
5049
+ /* @__PURE__ */ jsx22(
5161
5050
  Button14,
5162
5051
  {
5163
5052
  variant: "outline",
@@ -5165,7 +5054,7 @@ function ToolCredentialsForm({
5165
5054
  children: "Cancelar"
5166
5055
  }
5167
5056
  ),
5168
- /* @__PURE__ */ jsx24(
5057
+ /* @__PURE__ */ jsx22(
5169
5058
  Button14,
5170
5059
  {
5171
5060
  onClick: handleCreate,
@@ -5175,31 +5064,31 @@ function ToolCredentialsForm({
5175
5064
  )
5176
5065
  ] })
5177
5066
  ] }) }),
5178
- /* @__PURE__ */ jsx24(
5067
+ /* @__PURE__ */ jsx22(
5179
5068
  Dialog7,
5180
5069
  {
5181
5070
  open: !!editTarget,
5182
5071
  onOpenChange: (open) => !open && setEditTarget(null),
5183
- children: /* @__PURE__ */ jsxs22(DialogContent7, { children: [
5184
- /* @__PURE__ */ jsx24(DialogHeader7, { children: /* @__PURE__ */ jsx24(DialogTitle7, { children: "Editar Credencial" }) }),
5185
- /* @__PURE__ */ jsxs22("div", { className: "space-y-4", children: [
5186
- /* @__PURE__ */ jsxs22("div", { children: [
5187
- /* @__PURE__ */ jsx24("label", { htmlFor: "edit-cred-tool", className: "mb-1 block text-sm font-medium", children: "Ferramenta *" }),
5188
- /* @__PURE__ */ jsxs22(
5072
+ children: /* @__PURE__ */ jsxs20(DialogContent7, { children: [
5073
+ /* @__PURE__ */ jsx22(DialogHeader7, { children: /* @__PURE__ */ jsx22(DialogTitle7, { children: "Editar Credencial" }) }),
5074
+ /* @__PURE__ */ jsxs20("div", { className: "space-y-4", children: [
5075
+ /* @__PURE__ */ jsxs20("div", { children: [
5076
+ /* @__PURE__ */ jsx22("label", { htmlFor: "edit-cred-tool", className: "mb-1 block text-sm font-medium", children: "Ferramenta *" }),
5077
+ /* @__PURE__ */ jsxs20(
5189
5078
  Select4,
5190
5079
  {
5191
5080
  value: editForm.id_tool,
5192
5081
  onValueChange: (val) => setEditForm((f) => ({ ...f, id_tool: val })),
5193
5082
  children: [
5194
- /* @__PURE__ */ jsx24(SelectTrigger4, { id: "edit-cred-tool", children: /* @__PURE__ */ jsx24(SelectValue4, { placeholder: "Selecione a ferramenta" }) }),
5195
- /* @__PURE__ */ jsx24(SelectContent4, { children: tools.map((tool) => /* @__PURE__ */ jsx24(SelectItem4, { value: String(tool.id), children: tool.name }, tool.id)) })
5083
+ /* @__PURE__ */ jsx22(SelectTrigger4, { id: "edit-cred-tool", children: /* @__PURE__ */ jsx22(SelectValue4, { placeholder: "Selecione a ferramenta" }) }),
5084
+ /* @__PURE__ */ jsx22(SelectContent4, { children: tools.map((tool) => /* @__PURE__ */ jsx22(SelectItem4, { value: String(tool.id), children: tool.name }, tool.id)) })
5196
5085
  ]
5197
5086
  }
5198
5087
  )
5199
5088
  ] }),
5200
- /* @__PURE__ */ jsxs22("div", { children: [
5201
- /* @__PURE__ */ jsx24("label", { htmlFor: "edit-cred-label", className: "mb-1 block text-sm font-medium", children: "Label" }),
5202
- /* @__PURE__ */ jsx24(
5089
+ /* @__PURE__ */ jsxs20("div", { children: [
5090
+ /* @__PURE__ */ jsx22("label", { htmlFor: "edit-cred-label", className: "mb-1 block text-sm font-medium", children: "Label" }),
5091
+ /* @__PURE__ */ jsx22(
5203
5092
  Input10,
5204
5093
  {
5205
5094
  id: "edit-cred-label",
@@ -5210,9 +5099,9 @@ function ToolCredentialsForm({
5210
5099
  }
5211
5100
  )
5212
5101
  ] }),
5213
- /* @__PURE__ */ jsxs22("div", { children: [
5214
- /* @__PURE__ */ jsx24("label", { htmlFor: "edit-cred-credential", className: "mb-1 block text-sm font-medium", children: "Nova Credencial (vazio = manter atual)" }),
5215
- /* @__PURE__ */ jsx24(
5102
+ /* @__PURE__ */ jsxs20("div", { children: [
5103
+ /* @__PURE__ */ jsx22("label", { htmlFor: "edit-cred-credential", className: "mb-1 block text-sm font-medium", children: "Nova Credencial (vazio = manter atual)" }),
5104
+ /* @__PURE__ */ jsx22(
5216
5105
  Input10,
5217
5106
  {
5218
5107
  id: "edit-cred-credential",
@@ -5228,9 +5117,9 @@ function ToolCredentialsForm({
5228
5117
  }
5229
5118
  )
5230
5119
  ] }),
5231
- /* @__PURE__ */ jsxs22("div", { children: [
5232
- /* @__PURE__ */ jsx24("label", { htmlFor: "edit-cred-expires", className: "mb-1 block text-sm font-medium", children: "Data de Expira\xE7\xE3o" }),
5233
- /* @__PURE__ */ jsx24(
5120
+ /* @__PURE__ */ jsxs20("div", { children: [
5121
+ /* @__PURE__ */ jsx22("label", { htmlFor: "edit-cred-expires", className: "mb-1 block text-sm font-medium", children: "Data de Expira\xE7\xE3o" }),
5122
+ /* @__PURE__ */ jsx22(
5234
5123
  Input10,
5235
5124
  {
5236
5125
  id: "edit-cred-expires",
@@ -5241,9 +5130,9 @@ function ToolCredentialsForm({
5241
5130
  }
5242
5131
  )
5243
5132
  ] }),
5244
- /* @__PURE__ */ jsxs22("div", { children: [
5245
- /* @__PURE__ */ jsx24("label", { htmlFor: "edit-cred-status", className: "mb-1 block text-sm font-medium", children: "Status" }),
5246
- /* @__PURE__ */ jsxs22(
5133
+ /* @__PURE__ */ jsxs20("div", { children: [
5134
+ /* @__PURE__ */ jsx22("label", { htmlFor: "edit-cred-status", className: "mb-1 block text-sm font-medium", children: "Status" }),
5135
+ /* @__PURE__ */ jsxs20(
5247
5136
  Select4,
5248
5137
  {
5249
5138
  value: editForm.status || void 0,
@@ -5252,19 +5141,19 @@ function ToolCredentialsForm({
5252
5141
  status: val
5253
5142
  })),
5254
5143
  children: [
5255
- /* @__PURE__ */ jsx24(SelectTrigger4, { id: "edit-cred-status", children: /* @__PURE__ */ jsx24(SelectValue4, {}) }),
5256
- /* @__PURE__ */ jsxs22(SelectContent4, { children: [
5257
- /* @__PURE__ */ jsx24(SelectItem4, { value: "active", children: "Ativo" }),
5258
- /* @__PURE__ */ jsx24(SelectItem4, { value: "expired", children: "Expirado" })
5144
+ /* @__PURE__ */ jsx22(SelectTrigger4, { id: "edit-cred-status", children: /* @__PURE__ */ jsx22(SelectValue4, {}) }),
5145
+ /* @__PURE__ */ jsxs20(SelectContent4, { children: [
5146
+ /* @__PURE__ */ jsx22(SelectItem4, { value: "active", children: "Ativo" }),
5147
+ /* @__PURE__ */ jsx22(SelectItem4, { value: "expired", children: "Expirado" })
5259
5148
  ] })
5260
5149
  ]
5261
5150
  }
5262
5151
  )
5263
5152
  ] })
5264
5153
  ] }),
5265
- /* @__PURE__ */ jsxs22(DialogFooter7, { children: [
5266
- /* @__PURE__ */ jsx24(Button14, { variant: "outline", onClick: () => setEditTarget(null), children: "Cancelar" }),
5267
- /* @__PURE__ */ jsx24(
5154
+ /* @__PURE__ */ jsxs20(DialogFooter7, { children: [
5155
+ /* @__PURE__ */ jsx22(Button14, { variant: "outline", onClick: () => setEditTarget(null), children: "Cancelar" }),
5156
+ /* @__PURE__ */ jsx22(
5268
5157
  Button14,
5269
5158
  {
5270
5159
  onClick: handleSaveEdit,
@@ -5276,19 +5165,19 @@ function ToolCredentialsForm({
5276
5165
  ] })
5277
5166
  }
5278
5167
  ),
5279
- /* @__PURE__ */ jsx24(
5168
+ /* @__PURE__ */ jsx22(
5280
5169
  AlertDialog5,
5281
5170
  {
5282
5171
  open: !!removeTarget,
5283
5172
  onOpenChange: (open) => !open && setRemoveTarget(null),
5284
- children: /* @__PURE__ */ jsxs22(AlertDialogContent5, { children: [
5285
- /* @__PURE__ */ jsxs22(AlertDialogHeader5, { children: [
5286
- /* @__PURE__ */ jsx24(AlertDialogTitle5, { children: "Remover credencial?" }),
5287
- /* @__PURE__ */ jsx24(AlertDialogDescription5, { children: "A credencial ser\xE1 removida permanentemente." })
5173
+ children: /* @__PURE__ */ jsxs20(AlertDialogContent5, { children: [
5174
+ /* @__PURE__ */ jsxs20(AlertDialogHeader5, { children: [
5175
+ /* @__PURE__ */ jsx22(AlertDialogTitle5, { children: "Remover credencial?" }),
5176
+ /* @__PURE__ */ jsx22(AlertDialogDescription5, { children: "A credencial ser\xE1 removida permanentemente." })
5288
5177
  ] }),
5289
- /* @__PURE__ */ jsxs22(AlertDialogFooter5, { children: [
5290
- /* @__PURE__ */ jsx24(AlertDialogCancel5, { children: "Cancelar" }),
5291
- /* @__PURE__ */ jsx24(
5178
+ /* @__PURE__ */ jsxs20(AlertDialogFooter5, { children: [
5179
+ /* @__PURE__ */ jsx22(AlertDialogCancel5, { children: "Cancelar" }),
5180
+ /* @__PURE__ */ jsx22(
5292
5181
  AlertDialogAction5,
5293
5182
  {
5294
5183
  onClick: handleRemove,
@@ -5303,11 +5192,53 @@ function ToolCredentialsForm({
5303
5192
  ] });
5304
5193
  }
5305
5194
 
5195
+ // src/components/capabilities/advanced-tab.tsx
5196
+ import { useState as useState15 } from "react";
5197
+ import { Info as Info2 } from "lucide-react";
5198
+ import { jsx as jsx23, jsxs as jsxs21 } from "react/jsx-runtime";
5199
+ function AdvancedTab({ config, agentId, gagentsApiUrl }) {
5200
+ const [editingTool, setEditingTool] = useState15(null);
5201
+ const [showToolForm, setShowToolForm] = useState15(false);
5202
+ function handleEditTool(tool) {
5203
+ setEditingTool(tool);
5204
+ setShowToolForm(true);
5205
+ }
5206
+ function handleToolFormOpenChange(open) {
5207
+ setShowToolForm(open);
5208
+ if (!open) setEditingTool(null);
5209
+ }
5210
+ return /* @__PURE__ */ jsxs21("div", { className: "space-y-8", children: [
5211
+ /* @__PURE__ */ jsxs21("div", { className: "flex items-start gap-3 rounded-lg border border-blue-200 bg-blue-50 p-4 dark:border-blue-900 dark:bg-blue-950/30", children: [
5212
+ /* @__PURE__ */ jsx23(Info2, { className: "mt-0.5 h-4 w-4 shrink-0 text-blue-600 dark:text-blue-400" }),
5213
+ /* @__PURE__ */ jsxs21("p", { className: "text-sm text-blue-800 dark:text-blue-300", children: [
5214
+ "Use as abas ",
5215
+ /* @__PURE__ */ jsx23("strong", { children: "Capacidades" }),
5216
+ " e ",
5217
+ /* @__PURE__ */ jsx23("strong", { children: "Integra\xE7\xF5es" }),
5218
+ " para configura\xE7\xE3o simplificada. Esta aba oferece controlo manual avan\xE7ado sobre ferramentas. As credenciais s\xE3o geridas dentro de cada ferramenta."
5219
+ ] })
5220
+ ] }),
5221
+ /* @__PURE__ */ jsxs21("section", { className: "space-y-3", children: [
5222
+ /* @__PURE__ */ jsx23("h3", { className: "text-sm font-medium", children: "Ferramentas" }),
5223
+ /* @__PURE__ */ jsx23(ToolsTable, { onEdit: handleEditTool, config })
5224
+ ] }),
5225
+ /* @__PURE__ */ jsx23(
5226
+ ToolFormDialog,
5227
+ {
5228
+ open: showToolForm,
5229
+ onOpenChange: handleToolFormOpenChange,
5230
+ tool: editingTool ?? void 0,
5231
+ config
5232
+ }
5233
+ )
5234
+ ] });
5235
+ }
5236
+
5306
5237
  // src/pages/agents-page.tsx
5307
5238
  import { useState as useState16 } from "react";
5308
5239
  import { Button as Button15 } from "@greatapps/greatauth-ui/ui";
5309
5240
  import { Plus as Plus4 } from "lucide-react";
5310
- import { jsx as jsx25, jsxs as jsxs23 } from "react/jsx-runtime";
5241
+ import { jsx as jsx24, jsxs as jsxs22 } from "react/jsx-runtime";
5311
5242
  function AgentsPage({
5312
5243
  config,
5313
5244
  onNavigateToAgent,
@@ -5315,19 +5246,19 @@ function AgentsPage({
5315
5246
  subtitle = "Gerencie seus agentes de atendimento inteligente"
5316
5247
  }) {
5317
5248
  const [createOpen, setCreateOpen] = useState16(false);
5318
- return /* @__PURE__ */ jsxs23("div", { className: "flex flex-col gap-4 p-4 md:p-6", children: [
5319
- /* @__PURE__ */ jsxs23("div", { className: "flex items-center justify-between", children: [
5320
- /* @__PURE__ */ jsxs23("div", { children: [
5321
- /* @__PURE__ */ jsx25("h1", { className: "text-xl font-semibold", children: title }),
5322
- /* @__PURE__ */ jsx25("p", { className: "text-sm text-muted-foreground", children: subtitle })
5249
+ return /* @__PURE__ */ jsxs22("div", { className: "flex flex-col gap-4 p-4 md:p-6", children: [
5250
+ /* @__PURE__ */ jsxs22("div", { className: "flex items-center justify-between", children: [
5251
+ /* @__PURE__ */ jsxs22("div", { children: [
5252
+ /* @__PURE__ */ jsx24("h1", { className: "text-xl font-semibold", children: title }),
5253
+ /* @__PURE__ */ jsx24("p", { className: "text-sm text-muted-foreground", children: subtitle })
5323
5254
  ] }),
5324
- /* @__PURE__ */ jsxs23(Button15, { onClick: () => setCreateOpen(true), size: "sm", children: [
5325
- /* @__PURE__ */ jsx25(Plus4, { className: "mr-2 h-4 w-4" }),
5255
+ /* @__PURE__ */ jsxs22(Button15, { onClick: () => setCreateOpen(true), size: "sm", children: [
5256
+ /* @__PURE__ */ jsx24(Plus4, { className: "mr-2 h-4 w-4" }),
5326
5257
  "Novo Agente"
5327
5258
  ] })
5328
5259
  ] }),
5329
- /* @__PURE__ */ jsx25(AgentsTable, { config, onNavigateToAgent }),
5330
- /* @__PURE__ */ jsx25(
5260
+ /* @__PURE__ */ jsx24(AgentsTable, { config, onNavigateToAgent }),
5261
+ /* @__PURE__ */ jsx24(
5331
5262
  AgentFormDialog,
5332
5263
  {
5333
5264
  config,
@@ -5343,7 +5274,7 @@ import { useState as useState17 } from "react";
5343
5274
  import { Badge as Badge10, Button as Button16, Skeleton as Skeleton7 } from "@greatapps/greatauth-ui/ui";
5344
5275
  import { EntityAvatar as EntityAvatar2 } from "@greatapps/greatauth-ui";
5345
5276
  import { ArrowLeft, Pencil as Pencil5 } from "lucide-react";
5346
- import { jsx as jsx26, jsxs as jsxs24 } from "react/jsx-runtime";
5277
+ import { jsx as jsx25, jsxs as jsxs23 } from "react/jsx-runtime";
5347
5278
  function AgentDetailPage({
5348
5279
  config,
5349
5280
  agentId,
@@ -5353,26 +5284,26 @@ function AgentDetailPage({
5353
5284
  const { data: agent, isLoading } = useAgent(config, agentId);
5354
5285
  const [editOpen, setEditOpen] = useState17(false);
5355
5286
  if (isLoading) {
5356
- return /* @__PURE__ */ jsxs24("div", { className: "flex flex-col gap-4 p-4", children: [
5357
- /* @__PURE__ */ jsx26(Skeleton7, { className: "h-4 w-32" }),
5358
- /* @__PURE__ */ jsx26(Skeleton7, { className: "h-8 w-48" }),
5359
- /* @__PURE__ */ jsx26(Skeleton7, { className: "h-10 w-full" }),
5360
- /* @__PURE__ */ jsx26(Skeleton7, { className: "h-64 w-full" })
5287
+ return /* @__PURE__ */ jsxs23("div", { className: "flex flex-col gap-4 p-4", children: [
5288
+ /* @__PURE__ */ jsx25(Skeleton7, { className: "h-4 w-32" }),
5289
+ /* @__PURE__ */ jsx25(Skeleton7, { className: "h-8 w-48" }),
5290
+ /* @__PURE__ */ jsx25(Skeleton7, { className: "h-10 w-full" }),
5291
+ /* @__PURE__ */ jsx25(Skeleton7, { className: "h-64 w-full" })
5361
5292
  ] });
5362
5293
  }
5363
5294
  if (!agent) {
5364
- return /* @__PURE__ */ jsxs24("div", { className: "flex flex-col items-center justify-center gap-2 p-8", children: [
5365
- /* @__PURE__ */ jsx26("p", { className: "text-muted-foreground", children: "Agente n\xE3o encontrado" }),
5366
- onBack && /* @__PURE__ */ jsxs24(Button16, { variant: "ghost", size: "sm", onClick: onBack, children: [
5367
- /* @__PURE__ */ jsx26(ArrowLeft, { className: "mr-2 h-4 w-4" }),
5295
+ return /* @__PURE__ */ jsxs23("div", { className: "flex flex-col items-center justify-center gap-2 p-8", children: [
5296
+ /* @__PURE__ */ jsx25("p", { className: "text-muted-foreground", children: "Agente n\xE3o encontrado" }),
5297
+ onBack && /* @__PURE__ */ jsxs23(Button16, { variant: "ghost", size: "sm", onClick: onBack, children: [
5298
+ /* @__PURE__ */ jsx25(ArrowLeft, { className: "mr-2 h-4 w-4" }),
5368
5299
  "Voltar para agentes"
5369
5300
  ] })
5370
5301
  ] });
5371
5302
  }
5372
- return /* @__PURE__ */ jsxs24("div", { className: "flex flex-col gap-6 p-4 md:p-6", children: [
5373
- /* @__PURE__ */ jsx26("div", { className: "rounded-lg border p-4 md:p-6", children: /* @__PURE__ */ jsxs24("div", { className: "flex flex-col gap-4 md:flex-row md:items-start md:gap-6", children: [
5374
- /* @__PURE__ */ jsxs24("div", { className: "flex items-start gap-3 flex-1", children: [
5375
- onBack && /* @__PURE__ */ jsx26(
5303
+ return /* @__PURE__ */ jsxs23("div", { className: "flex flex-col gap-6 p-4 md:p-6", children: [
5304
+ /* @__PURE__ */ jsx25("div", { className: "rounded-lg border p-4 md:p-6", children: /* @__PURE__ */ jsxs23("div", { className: "flex flex-col gap-4 md:flex-row md:items-start md:gap-6", children: [
5305
+ /* @__PURE__ */ jsxs23("div", { className: "flex items-start gap-3 flex-1", children: [
5306
+ onBack && /* @__PURE__ */ jsx25(
5376
5307
  Button16,
5377
5308
  {
5378
5309
  variant: "ghost",
@@ -5380,13 +5311,13 @@ function AgentDetailPage({
5380
5311
  "aria-label": "Voltar",
5381
5312
  className: "shrink-0 mt-1",
5382
5313
  onClick: onBack,
5383
- children: /* @__PURE__ */ jsx26(ArrowLeft, { className: "h-4 w-4" })
5314
+ children: /* @__PURE__ */ jsx25(ArrowLeft, { className: "h-4 w-4" })
5384
5315
  }
5385
5316
  ),
5386
- /* @__PURE__ */ jsx26(EntityAvatar2, { photo: agent.photo, name: agent.title, size: "xl" }),
5387
- /* @__PURE__ */ jsx26("div", { className: "flex-1 min-w-0", children: /* @__PURE__ */ jsxs24("div", { className: "flex items-center gap-2 flex-wrap", children: [
5388
- /* @__PURE__ */ jsx26("h1", { className: "text-xl font-semibold", children: agent.title }),
5389
- /* @__PURE__ */ jsx26(
5317
+ /* @__PURE__ */ jsx25(EntityAvatar2, { photo: agent.photo, name: agent.title, size: "xl" }),
5318
+ /* @__PURE__ */ jsx25("div", { className: "flex-1 min-w-0", children: /* @__PURE__ */ jsxs23("div", { className: "flex items-center gap-2 flex-wrap", children: [
5319
+ /* @__PURE__ */ jsx25("h1", { className: "text-xl font-semibold", children: agent.title }),
5320
+ /* @__PURE__ */ jsx25(
5390
5321
  Badge10,
5391
5322
  {
5392
5323
  variant: agent.active ? "default" : "destructive",
@@ -5396,7 +5327,7 @@ function AgentDetailPage({
5396
5327
  )
5397
5328
  ] }) })
5398
5329
  ] }),
5399
- /* @__PURE__ */ jsxs24(
5330
+ /* @__PURE__ */ jsxs23(
5400
5331
  Button16,
5401
5332
  {
5402
5333
  variant: "outline",
@@ -5404,13 +5335,13 @@ function AgentDetailPage({
5404
5335
  className: "shrink-0 self-start",
5405
5336
  onClick: () => setEditOpen(true),
5406
5337
  children: [
5407
- /* @__PURE__ */ jsx26(Pencil5, { className: "mr-2 h-4 w-4" }),
5338
+ /* @__PURE__ */ jsx25(Pencil5, { className: "mr-2 h-4 w-4" }),
5408
5339
  "Editar"
5409
5340
  ]
5410
5341
  }
5411
5342
  )
5412
5343
  ] }) }),
5413
- /* @__PURE__ */ jsx26(
5344
+ /* @__PURE__ */ jsx25(
5414
5345
  AgentTabs,
5415
5346
  {
5416
5347
  agent,
@@ -5418,7 +5349,7 @@ function AgentDetailPage({
5418
5349
  renderChatLink
5419
5350
  }
5420
5351
  ),
5421
- editOpen && /* @__PURE__ */ jsx26(
5352
+ editOpen && /* @__PURE__ */ jsx25(
5422
5353
  AgentEditForm,
5423
5354
  {
5424
5355
  agent,
@@ -5431,8 +5362,110 @@ function AgentDetailPage({
5431
5362
  ] });
5432
5363
  }
5433
5364
 
5365
+ // src/pages/agent-capabilities-page.tsx
5366
+ import { useState as useState18, useCallback as useCallback7 } from "react";
5367
+ import {
5368
+ Tabs as Tabs2,
5369
+ TabsList as TabsList2,
5370
+ TabsTrigger as TabsTrigger2,
5371
+ TabsContent as TabsContent2
5372
+ } from "@greatapps/greatauth-ui/ui";
5373
+ import { Blocks as Blocks2, Plug as Plug4, Settings as Settings3 } from "lucide-react";
5374
+ import { jsx as jsx26, jsxs as jsxs24 } from "react/jsx-runtime";
5375
+ function defaultResolveWizardMeta(card) {
5376
+ return {
5377
+ capabilities: [
5378
+ { label: card.definition.name, description: card.definition.description }
5379
+ ],
5380
+ requirements: [],
5381
+ hasConfigStep: false
5382
+ };
5383
+ }
5384
+ function AgentCapabilitiesPage({
5385
+ config,
5386
+ agentId,
5387
+ gagentsApiUrl,
5388
+ resolveWizardMeta = defaultResolveWizardMeta,
5389
+ loadConfigOptions,
5390
+ onWizardComplete
5391
+ }) {
5392
+ const [wizardOpen, setWizardOpen] = useState18(false);
5393
+ const [activeCard, setActiveCard] = useState18(null);
5394
+ const handleConnect = useCallback7(
5395
+ (card) => {
5396
+ setActiveCard(card);
5397
+ setWizardOpen(true);
5398
+ },
5399
+ []
5400
+ );
5401
+ const handleWizardComplete = useCallback7(() => {
5402
+ setWizardOpen(false);
5403
+ setActiveCard(null);
5404
+ onWizardComplete?.();
5405
+ }, [onWizardComplete]);
5406
+ const handleWizardOpenChange = useCallback7((open) => {
5407
+ setWizardOpen(open);
5408
+ if (!open) setActiveCard(null);
5409
+ }, []);
5410
+ const wizardMeta = activeCard ? resolveWizardMeta(activeCard) : null;
5411
+ return /* @__PURE__ */ jsxs24("div", { className: "space-y-4", children: [
5412
+ /* @__PURE__ */ jsxs24("div", { children: [
5413
+ /* @__PURE__ */ jsx26("h2", { className: "text-lg font-semibold", children: "Capacidades e Integra\xE7\xF5es" }),
5414
+ /* @__PURE__ */ jsx26("p", { className: "text-sm text-muted-foreground", children: "Configure o que este agente pode fazer e quais servi\xE7os externos ele utiliza." })
5415
+ ] }),
5416
+ /* @__PURE__ */ jsxs24(Tabs2, { defaultValue: "capacidades", children: [
5417
+ /* @__PURE__ */ jsxs24(TabsList2, { children: [
5418
+ /* @__PURE__ */ jsxs24(TabsTrigger2, { value: "capacidades", className: "flex items-center gap-1.5", children: [
5419
+ /* @__PURE__ */ jsx26(Blocks2, { "aria-hidden": "true", className: "h-3.5 w-3.5" }),
5420
+ "Capacidades"
5421
+ ] }),
5422
+ /* @__PURE__ */ jsxs24(TabsTrigger2, { value: "integracoes", className: "flex items-center gap-1.5", children: [
5423
+ /* @__PURE__ */ jsx26(Plug4, { "aria-hidden": "true", className: "h-3.5 w-3.5" }),
5424
+ "Integra\xE7\xF5es"
5425
+ ] }),
5426
+ /* @__PURE__ */ jsxs24(TabsTrigger2, { value: "avancado", className: "flex items-center gap-1.5", children: [
5427
+ /* @__PURE__ */ jsx26(Settings3, { "aria-hidden": "true", className: "h-3.5 w-3.5" }),
5428
+ "Avan\xE7ado"
5429
+ ] })
5430
+ ] }),
5431
+ /* @__PURE__ */ jsx26(TabsContent2, { value: "capacidades", className: "mt-4", children: /* @__PURE__ */ jsx26(CapabilitiesTab, { config, agentId }) }),
5432
+ /* @__PURE__ */ jsx26(TabsContent2, { value: "integracoes", className: "mt-4", children: /* @__PURE__ */ jsx26(
5433
+ IntegrationsTab,
5434
+ {
5435
+ config,
5436
+ agentId,
5437
+ onConnect: handleConnect
5438
+ }
5439
+ ) }),
5440
+ /* @__PURE__ */ jsx26(TabsContent2, { value: "avancado", className: "mt-4", children: /* @__PURE__ */ jsx26(
5441
+ AdvancedTab,
5442
+ {
5443
+ config,
5444
+ agentId,
5445
+ gagentsApiUrl
5446
+ }
5447
+ ) })
5448
+ ] }),
5449
+ activeCard && wizardMeta && /* @__PURE__ */ jsx26(
5450
+ IntegrationWizard,
5451
+ {
5452
+ open: wizardOpen,
5453
+ onOpenChange: handleWizardOpenChange,
5454
+ integration: activeCard.definition,
5455
+ meta: wizardMeta,
5456
+ agentId,
5457
+ config,
5458
+ onComplete: handleWizardComplete,
5459
+ gagentsApiUrl,
5460
+ existingCredentialId: activeCard.credential?.id,
5461
+ loadConfigOptions
5462
+ }
5463
+ )
5464
+ ] });
5465
+ }
5466
+
5434
5467
  // src/pages/tools-page.tsx
5435
- import { useState as useState18 } from "react";
5468
+ import { useState as useState19 } from "react";
5436
5469
  import { Button as Button17 } from "@greatapps/greatauth-ui/ui";
5437
5470
  import { Plus as Plus5 } from "lucide-react";
5438
5471
  import { jsx as jsx27, jsxs as jsxs25 } from "react/jsx-runtime";
@@ -5441,8 +5474,8 @@ function ToolsPage({
5441
5474
  title = "Ferramentas",
5442
5475
  subtitle = "Gerencie as ferramentas dispon\xEDveis para seus agentes"
5443
5476
  }) {
5444
- const [createOpen, setCreateOpen] = useState18(false);
5445
- const [editTool, setEditTool] = useState18(void 0);
5477
+ const [createOpen, setCreateOpen] = useState19(false);
5478
+ const [editTool, setEditTool] = useState19(void 0);
5446
5479
  return /* @__PURE__ */ jsxs25("div", { className: "flex flex-col gap-4 p-4 md:p-6", children: [
5447
5480
  /* @__PURE__ */ jsxs25("div", { className: "flex items-center justify-between", children: [
5448
5481
  /* @__PURE__ */ jsxs25("div", { children: [
@@ -5476,7 +5509,7 @@ function ToolsPage({
5476
5509
  }
5477
5510
 
5478
5511
  // src/pages/credentials-page.tsx
5479
- import { useState as useState19 } from "react";
5512
+ import { useState as useState20 } from "react";
5480
5513
  import { Button as Button18 } from "@greatapps/greatauth-ui/ui";
5481
5514
  import { Plus as Plus6 } from "lucide-react";
5482
5515
  import { jsx as jsx28, jsxs as jsxs26 } from "react/jsx-runtime";
@@ -5487,7 +5520,7 @@ function CredentialsPage({
5487
5520
  subtitle = "Gerencie as credenciais de autentica\xE7\xE3o das ferramentas"
5488
5521
  }) {
5489
5522
  const { data: credentialsData, isLoading: credentialsLoading } = useToolCredentials(config);
5490
- const [createOpen, setCreateOpen] = useState19(false);
5523
+ const [createOpen, setCreateOpen] = useState20(false);
5491
5524
  const credentials = credentialsData?.data || [];
5492
5525
  return /* @__PURE__ */ jsxs26("div", { className: "flex flex-col gap-4 p-4 md:p-6", children: [
5493
5526
  /* @__PURE__ */ jsxs26("div", { className: "flex items-center justify-between", children: [
@@ -5515,7 +5548,7 @@ function CredentialsPage({
5515
5548
  }
5516
5549
 
5517
5550
  // src/pages/integrations-management-page.tsx
5518
- import { useState as useState20, useMemo as useMemo8 } from "react";
5551
+ import { useState as useState21, useMemo as useMemo8 } from "react";
5519
5552
  import {
5520
5553
  Badge as Badge11,
5521
5554
  Button as Button19,
@@ -5524,7 +5557,7 @@ import {
5524
5557
  TabsList as TabsList3,
5525
5558
  TabsTrigger as TabsTrigger3
5526
5559
  } from "@greatapps/greatauth-ui/ui";
5527
- import { Plus as Plus7, Plug as Plug4, KeyRound, Info as Info3 } from "lucide-react";
5560
+ import { Plus as Plus7, Plug as Plug5, KeyRound, Info as Info3 } from "lucide-react";
5528
5561
  import { jsx as jsx29, jsxs as jsxs27 } from "react/jsx-runtime";
5529
5562
  function useCredentialAgentSummary(credentials, tools, agents) {
5530
5563
  return useMemo8(() => {
@@ -5552,7 +5585,7 @@ function IntegrationsManagementPage({
5552
5585
  const { data: credentialsData, isLoading: credentialsLoading } = useToolCredentials(config);
5553
5586
  const { data: agentsData } = useAgents(config);
5554
5587
  const { data: toolsData } = useTools(config);
5555
- const [createOpen, setCreateOpen] = useState20(false);
5588
+ const [createOpen, setCreateOpen] = useState21(false);
5556
5589
  const credentials = credentialsData?.data || [];
5557
5590
  const agents = agentsData?.data || [];
5558
5591
  const tools = toolsData?.data || [];
@@ -5565,7 +5598,7 @@ function IntegrationsManagementPage({
5565
5598
  /* @__PURE__ */ jsxs27(Tabs3, { defaultValue: "integrations", className: "w-full", children: [
5566
5599
  /* @__PURE__ */ jsxs27(TabsList3, { children: [
5567
5600
  /* @__PURE__ */ jsxs27(TabsTrigger3, { value: "integrations", className: "gap-2", children: [
5568
- /* @__PURE__ */ jsx29(Plug4, { className: "h-4 w-4" }),
5601
+ /* @__PURE__ */ jsx29(Plug5, { className: "h-4 w-4" }),
5569
5602
  "Integra\xE7\xF5es"
5570
5603
  ] }),
5571
5604
  /* @__PURE__ */ jsxs27(TabsTrigger3, { value: "credentials", className: "gap-2", children: [