@greatapps/greatagents-ui 0.3.10 → 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,18 +2500,8 @@ function AgentConversationsPanel({
2497
2500
  ) });
2498
2501
  }
2499
2502
 
2500
- // src/pages/agent-capabilities-page.tsx
2501
- import { useState as useState14, 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
- import { useState as useState8, useCallback as useCallback4, useRef as useRef2, useEffect as useEffect4, useMemo as useMemo5 } from "react";
2504
+ import { useState as useState8, useCallback as useCallback4, useEffect as useEffect4, useMemo as useMemo5 } from "react";
2512
2505
  import {
2513
2506
  Accordion,
2514
2507
  AccordionItem,
@@ -2526,7 +2519,8 @@ import {
2526
2519
  Settings,
2527
2520
  HeartHandshake,
2528
2521
  Package,
2529
- ChevronDown as ChevronDown2
2522
+ ChevronDown as ChevronDown2,
2523
+ Loader2 as Loader24
2530
2524
  } from "lucide-react";
2531
2525
  import { toast as toast6 } from "sonner";
2532
2526
  import { jsx as jsx10, jsxs as jsxs8 } from "react/jsx-runtime";
@@ -2587,7 +2581,6 @@ function CapabilitiesTab({ config, agentId }) {
2587
2581
  const [localState, setLocalState] = useState8(/* @__PURE__ */ new Map());
2588
2582
  const [serverState, setServerState] = useState8(/* @__PURE__ */ new Map());
2589
2583
  const [initialized, setInitialized] = useState8(false);
2590
- const debounceRef = useRef2(null);
2591
2584
  useEffect4(() => {
2592
2585
  if (agentCaps && !initialized) {
2593
2586
  const state = buildStateFromAgent(agentCaps);
@@ -2603,37 +2596,11 @@ function CapabilitiesTab({ config, agentId }) {
2603
2596
  () => initialized && !statesEqual(localState, serverState),
2604
2597
  [localState, serverState, initialized]
2605
2598
  );
2606
- const scheduleSave = useCallback4(
2607
- (nextState) => {
2608
- if (debounceRef.current) clearTimeout(debounceRef.current);
2609
- debounceRef.current = setTimeout(() => {
2610
- const payload = stateToPayload(nextState);
2611
- updateMutation.mutate(
2612
- { agentId, payload },
2613
- {
2614
- onSuccess: () => {
2615
- setServerState(cloneState(nextState));
2616
- toast6.success("Capacidades salvas");
2617
- },
2618
- onError: () => {
2619
- setLocalState(cloneState(serverState));
2620
- toast6.error("Erro ao salvar capacidades");
2621
- }
2622
- }
2623
- );
2624
- }, 500);
2625
- },
2626
- [agentId, updateMutation, serverState]
2627
- );
2628
2599
  const updateState = useCallback4(
2629
2600
  (updater) => {
2630
- setLocalState((prev) => {
2631
- const next = updater(prev);
2632
- scheduleSave(next);
2633
- return next;
2634
- });
2601
+ setLocalState((prev) => updater(prev));
2635
2602
  },
2636
- [scheduleSave]
2603
+ []
2637
2604
  );
2638
2605
  const toggleModule = useCallback4(
2639
2606
  (mod, enabled) => {
@@ -2685,11 +2652,9 @@ function CapabilitiesTab({ config, agentId }) {
2685
2652
  updateState(() => /* @__PURE__ */ new Map());
2686
2653
  }, [updateState]);
2687
2654
  const discard = useCallback4(() => {
2688
- if (debounceRef.current) clearTimeout(debounceRef.current);
2689
2655
  setLocalState(cloneState(serverState));
2690
2656
  }, [serverState]);
2691
2657
  const saveNow = useCallback4(() => {
2692
- if (debounceRef.current) clearTimeout(debounceRef.current);
2693
2658
  const payload = stateToPayload(localState);
2694
2659
  updateMutation.mutate(
2695
2660
  { agentId, payload },
@@ -2771,19 +2736,14 @@ function CapabilitiesTab({ config, agentId }) {
2771
2736
  cat.slug
2772
2737
  );
2773
2738
  }) }),
2774
- hasChanges && /* @__PURE__ */ jsxs8("div", { className: "sticky bottom-0 bg-background border-t py-3 px-4 -mx-4 flex items-center justify-between", children: [
2775
- /* @__PURE__ */ jsx10("span", { className: "text-sm text-muted-foreground", children: "Voc\xEA tem altera\xE7\xF5es n\xE3o salvas." }),
2776
- /* @__PURE__ */ jsxs8("div", { className: "flex items-center gap-2", children: [
2777
- /* @__PURE__ */ jsx10(Button7, { variant: "outline", size: "sm", onClick: discard, children: "Descartar" }),
2778
- /* @__PURE__ */ jsx10(
2779
- Button7,
2780
- {
2781
- size: "sm",
2782
- onClick: saveNow,
2783
- disabled: updateMutation.isPending,
2784
- children: updateMutation.isPending ? "Salvando..." : "Salvar"
2785
- }
2786
- )
2739
+ hasChanges && /* @__PURE__ */ jsxs8("div", { className: "sticky bottom-0 z-10 flex items-center justify-between gap-2 rounded-lg border bg-background p-3 shadow-sm", children: [
2740
+ /* @__PURE__ */ jsx10("p", { className: "text-sm text-muted-foreground", children: "Voc\xEA tem altera\xE7\xF5es n\xE3o salvas." }),
2741
+ /* @__PURE__ */ jsxs8("div", { className: "flex gap-2", children: [
2742
+ /* @__PURE__ */ jsx10(Button7, { variant: "ghost", size: "sm", onClick: discard, disabled: updateMutation.isPending, children: "Descartar" }),
2743
+ /* @__PURE__ */ jsxs8(Button7, { size: "sm", onClick: saveNow, disabled: updateMutation.isPending, children: [
2744
+ updateMutation.isPending && /* @__PURE__ */ jsx10(Loader24, { className: "mr-2 h-4 w-4 animate-spin" }),
2745
+ "Salvar"
2746
+ ] })
2787
2747
  ] })
2788
2748
  ] })
2789
2749
  ] });
@@ -3022,7 +2982,7 @@ function IntegrationCard({ card, onConnect }) {
3022
2982
  }
3023
2983
 
3024
2984
  // src/components/capabilities/integrations-tab.tsx
3025
- import { Plug as Plug2, Loader2 as Loader24 } from "lucide-react";
2985
+ import { Plug as Plug2, Loader2 as Loader25 } from "lucide-react";
3026
2986
  import { jsx as jsx12, jsxs as jsxs10 } from "react/jsx-runtime";
3027
2987
  function getCardKey(card) {
3028
2988
  if (card.credentialId) {
@@ -3040,7 +3000,7 @@ function IntegrationsTab({
3040
3000
  }) {
3041
3001
  const { cards, isLoading } = useIntegrationState(config, agentId);
3042
3002
  if (isLoading) {
3043
- return /* @__PURE__ */ jsx12("div", { className: "flex items-center justify-center py-16", children: /* @__PURE__ */ jsx12(Loader24, { className: "h-6 w-6 animate-spin text-muted-foreground" }) });
3003
+ return /* @__PURE__ */ jsx12("div", { className: "flex items-center justify-center py-16", children: /* @__PURE__ */ jsx12(Loader25, { className: "h-6 w-6 animate-spin text-muted-foreground" }) });
3044
3004
  }
3045
3005
  if (cards.length === 0) {
3046
3006
  return /* @__PURE__ */ jsxs10("div", { className: "flex flex-col items-center justify-center gap-3 py-16 text-muted-foreground", children: [
@@ -3081,7 +3041,7 @@ function IntegrationsTab({
3081
3041
  }
3082
3042
 
3083
3043
  // src/components/capabilities/integration-wizard.tsx
3084
- import { useCallback as useCallback5, useEffect as useEffect5, useRef as useRef3, useState as useState9 } from "react";
3044
+ import { useCallback as useCallback5, useEffect as useEffect5, useRef as useRef2, useState as useState9 } from "react";
3085
3045
  import {
3086
3046
  Dialog as Dialog4,
3087
3047
  DialogContent as DialogContent4,
@@ -3090,7 +3050,7 @@ import {
3090
3050
  DialogTitle as DialogTitle4,
3091
3051
  Button as Button10
3092
3052
  } from "@greatapps/greatauth-ui/ui";
3093
- import { Loader2 as Loader27, ChevronLeft, ChevronRight, Check as Check2 } from "lucide-react";
3053
+ import { Loader2 as Loader28, ChevronLeft, ChevronRight, Check as Check2 } from "lucide-react";
3094
3054
  import { toast as toast7 } from "sonner";
3095
3055
 
3096
3056
  // src/components/capabilities/wizard-steps/info-step.tsx
@@ -3149,7 +3109,7 @@ function InfoStep({ integration, meta }) {
3149
3109
  }
3150
3110
 
3151
3111
  // src/components/capabilities/wizard-steps/credentials-step.tsx
3152
- import { CheckCircle2, Loader2 as Loader25, AlertCircle, Shield } from "lucide-react";
3112
+ import { CheckCircle2, Loader2 as Loader26, AlertCircle, Shield } from "lucide-react";
3153
3113
  import { Button as Button9, Input as Input6, Label as Label4 } from "@greatapps/greatauth-ui/ui";
3154
3114
  import { jsx as jsx14, jsxs as jsxs12 } from "react/jsx-runtime";
3155
3115
  function CredentialsStep({
@@ -3206,7 +3166,7 @@ function OAuthCredentials({
3206
3166
  ),
3207
3167
  oauthStatus === "waiting" && /* @__PURE__ */ jsxs12("div", { className: "flex flex-col items-center gap-3 text-center", children: [
3208
3168
  /* @__PURE__ */ jsx14(
3209
- Loader25,
3169
+ Loader26,
3210
3170
  {
3211
3171
  "aria-hidden": "true",
3212
3172
  className: "h-8 w-8 animate-spin text-muted-foreground"
@@ -3298,7 +3258,7 @@ function ApiKeyCredentials({
3298
3258
  }
3299
3259
 
3300
3260
  // src/components/capabilities/wizard-steps/config-step.tsx
3301
- import { Loader2 as Loader26 } from "lucide-react";
3261
+ import { Loader2 as Loader27 } from "lucide-react";
3302
3262
  import {
3303
3263
  Label as Label5,
3304
3264
  Select,
@@ -3326,7 +3286,7 @@ function ConfigStep({
3326
3286
  ] }),
3327
3287
  isLoading ? /* @__PURE__ */ jsxs13("div", { className: "flex flex-col items-center gap-3 py-8", children: [
3328
3288
  /* @__PURE__ */ jsx15(
3329
- Loader26,
3289
+ Loader27,
3330
3290
  {
3331
3291
  "aria-hidden": "true",
3332
3292
  className: "h-6 w-6 animate-spin text-muted-foreground"
@@ -3487,8 +3447,8 @@ function IntegrationWizard({
3487
3447
  const currentIndex = STEPS.indexOf(currentStep);
3488
3448
  const [oauthStatus, setOauthStatus] = useState9("idle");
3489
3449
  const [oauthResult, setOauthResult] = useState9(null);
3490
- const popupRef = useRef3(null);
3491
- const popupPollRef = useRef3(null);
3450
+ const popupRef = useRef2(null);
3451
+ const popupPollRef = useRef2(null);
3492
3452
  const [apiKey, setApiKey] = useState9("");
3493
3453
  const [configOptions, setConfigOptions] = useState9([]);
3494
3454
  const [configLoading, setConfigLoading] = useState9(false);
@@ -3752,7 +3712,7 @@ function IntegrationWizard({
3752
3712
  className: "gap-1",
3753
3713
  children: [
3754
3714
  isSubmitting ? /* @__PURE__ */ jsx17(
3755
- Loader27,
3715
+ Loader28,
3756
3716
  {
3757
3717
  "aria-hidden": "true",
3758
3718
  className: "h-4 w-4 animate-spin"
@@ -3830,677 +3790,396 @@ function StepIndicator({
3830
3790
  );
3831
3791
  }
3832
3792
 
3833
- // src/components/capabilities/advanced-tab.tsx
3834
- import { useState as useState13 } from "react";
3835
-
3836
- // src/components/tools/tools-table.tsx
3837
- import { useMemo as useMemo6, useState as useState10 } from "react";
3838
- import { DataTable as DataTable2 } from "@greatapps/greatauth-ui";
3793
+ // src/components/agents/agent-tabs.tsx
3839
3794
  import {
3840
- Input as Input7,
3841
- Badge as Badge7,
3842
- Tooltip as Tooltip3,
3843
- TooltipTrigger as TooltipTrigger3,
3844
- TooltipContent as TooltipContent3,
3845
- AlertDialog as AlertDialog3,
3846
- AlertDialogAction as AlertDialogAction3,
3847
- AlertDialogCancel as AlertDialogCancel3,
3848
- AlertDialogContent as AlertDialogContent3,
3849
- AlertDialogDescription as AlertDialogDescription3,
3850
- AlertDialogFooter as AlertDialogFooter3,
3851
- AlertDialogHeader as AlertDialogHeader3,
3852
- AlertDialogTitle as AlertDialogTitle3,
3853
- Button as Button11
3795
+ Tabs,
3796
+ TabsList,
3797
+ TabsTrigger,
3798
+ TabsContent
3854
3799
  } from "@greatapps/greatauth-ui/ui";
3855
- import { Pencil as Pencil3, Trash2 as Trash23, Search as Search2 } from "lucide-react";
3856
- import { format as format2 } from "date-fns";
3857
- import { ptBR as ptBR2 } from "date-fns/locale";
3858
- import { toast as toast8 } from "sonner";
3800
+ import { Target as Target2, FileText as FileText2, MessageCircle as MessageCircle2, Blocks, Plug as Plug3 } from "lucide-react";
3859
3801
  import { Fragment as Fragment2, jsx as jsx18, jsxs as jsxs16 } from "react/jsx-runtime";
3860
- function useColumns2(onEdit, onDelete) {
3861
- return [
3862
- {
3863
- accessorKey: "name",
3864
- header: "Nome",
3865
- cell: ({ row }) => /* @__PURE__ */ jsx18("span", { className: "font-medium", children: row.original.name }),
3866
- sortingFn: (rowA, rowB) => rowA.original.name.toLowerCase().localeCompare(rowB.original.name.toLowerCase())
3867
- },
3868
- {
3869
- accessorKey: "slug",
3870
- header: "Slug",
3871
- cell: ({ row }) => /* @__PURE__ */ jsx18("span", { className: "text-muted-foreground text-sm font-mono", children: row.original.slug || "\u2014" })
3872
- },
3873
- {
3874
- accessorKey: "type",
3875
- header: "Tipo",
3876
- cell: ({ row }) => /* @__PURE__ */ jsx18(Badge7, { variant: "secondary", children: row.original.type })
3877
- },
3878
- {
3879
- accessorKey: "description",
3880
- header: "Descri\xE7\xE3o",
3881
- cell: ({ row }) => {
3882
- const desc = row.original.description;
3883
- if (!desc) return /* @__PURE__ */ jsx18("span", { className: "text-muted-foreground text-sm", children: "\u2014" });
3884
- return /* @__PURE__ */ jsx18("span", { className: "text-muted-foreground text-sm", children: desc.length > 50 ? `${desc.slice(0, 50)}\u2026` : desc });
3885
- }
3886
- },
3887
- {
3888
- accessorKey: "datetime_add",
3889
- header: "Criado em",
3890
- cell: ({ row }) => /* @__PURE__ */ jsx18("span", { className: "text-muted-foreground text-sm", children: format2(new Date(row.original.datetime_add), "dd/MM/yyyy", {
3891
- locale: ptBR2
3892
- }) })
3893
- },
3894
- {
3895
- id: "actions",
3896
- size: 80,
3897
- enableSorting: false,
3898
- cell: ({ row }) => /* @__PURE__ */ jsxs16("div", { className: "flex items-center gap-1", children: [
3899
- /* @__PURE__ */ jsxs16(Tooltip3, { children: [
3900
- /* @__PURE__ */ jsx18(TooltipTrigger3, { asChild: true, children: /* @__PURE__ */ jsx18(
3901
- Button11,
3902
- {
3903
- variant: "ghost",
3904
- size: "icon",
3905
- className: "h-8 w-8",
3906
- "aria-label": "Editar",
3907
- onClick: () => onEdit(row.original),
3908
- children: /* @__PURE__ */ jsx18(Pencil3, { className: "h-4 w-4" })
3909
- }
3910
- ) }),
3911
- /* @__PURE__ */ jsx18(TooltipContent3, { children: "Editar" })
3912
- ] }),
3913
- /* @__PURE__ */ jsxs16(Tooltip3, { children: [
3914
- /* @__PURE__ */ jsx18(TooltipTrigger3, { asChild: true, children: /* @__PURE__ */ jsx18(
3915
- Button11,
3916
- {
3917
- variant: "ghost",
3918
- size: "icon",
3919
- className: "h-8 w-8 text-destructive hover:text-destructive",
3920
- "aria-label": "Excluir",
3921
- onClick: () => onDelete(row.original.id),
3922
- children: /* @__PURE__ */ jsx18(Trash23, { className: "h-4 w-4" })
3923
- }
3924
- ) }),
3925
- /* @__PURE__ */ jsx18(TooltipContent3, { children: "Excluir" })
3926
- ] })
3927
- ] })
3928
- }
3929
- ];
3930
- }
3931
- function ToolsTable({ onEdit, config }) {
3932
- const [search, setSearch] = useState10("");
3933
- const [page, setPage] = useState10(1);
3934
- const queryParams = useMemo6(() => {
3935
- const params = {
3936
- limit: "15",
3937
- page: String(page)
3938
- };
3939
- if (search) {
3940
- 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);
3941
3821
  }
3942
- return params;
3943
- }, [search, page]);
3944
- const { data, isLoading } = useTools(config, queryParams);
3945
- const deleteTool = useDeleteTool(config);
3946
- const [deleteId, setDeleteId] = useState10(null);
3947
- const rawTools = data?.data || [];
3948
- const tools = rawTools.filter((t) => !t.slug?.startsWith("gclinic_"));
3949
- const total = tools.length;
3950
- const columns = useColumns2(
3951
- (tool) => onEdit(tool),
3952
- (id) => setDeleteId(id)
3953
- );
3954
- function handleDelete() {
3955
- if (!deleteId) return;
3956
- deleteTool.mutate(deleteId, {
3957
- onSuccess: () => {
3958
- toast8.success("Ferramenta exclu\xEDda");
3959
- setDeleteId(null);
3960
- },
3961
- onError: () => toast8.error("Erro ao excluir ferramenta")
3962
- });
3963
- }
3964
- function handleSearchChange(value) {
3965
- setSearch(value);
3966
- setPage(1);
3967
- }
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;
3968
3834
  return /* @__PURE__ */ jsxs16(Fragment2, { children: [
3969
- /* @__PURE__ */ jsx18("div", { className: "flex items-center gap-3", children: /* @__PURE__ */ jsxs16("div", { className: "relative flex-1 max-w-md", children: [
3970
- /* @__PURE__ */ jsx18(Search2, { "aria-hidden": "true", className: "absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground" }),
3971
- /* @__PURE__ */ jsx18(
3972
- 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,
3973
3864
  {
3974
- placeholder: "Buscar ferramentas\\u2026",
3975
- "aria-label": "Buscar ferramentas",
3976
- name: "search",
3977
- autoComplete: "off",
3978
- value: search,
3979
- onChange: (e) => handleSearchChange(e.target.value),
3980
- className: "pl-9"
3865
+ agent,
3866
+ config,
3867
+ renderChatLink
3981
3868
  }
3982
- )
3983
- ] }) }),
3984
- /* @__PURE__ */ jsx18(
3985
- DataTable2,
3986
- {
3987
- columns,
3988
- data: tools,
3989
- isLoading,
3990
- emptyMessage: "Nenhuma ferramenta encontrada",
3991
- total,
3992
- page,
3993
- onPageChange: setPage,
3994
- pageSize: 15
3995
- }
3996
- ),
3997
- /* @__PURE__ */ jsx18(
3998
- AlertDialog3,
3869
+ ) })
3870
+ ] }),
3871
+ activeCard && wizardMeta && /* @__PURE__ */ jsx18(
3872
+ IntegrationWizard,
3999
3873
  {
4000
- open: !!deleteId,
4001
- onOpenChange: (open) => !open && setDeleteId(null),
4002
- children: /* @__PURE__ */ jsxs16(AlertDialogContent3, { children: [
4003
- /* @__PURE__ */ jsxs16(AlertDialogHeader3, { children: [
4004
- /* @__PURE__ */ jsx18(AlertDialogTitle3, { children: "Excluir ferramenta?" }),
4005
- /* @__PURE__ */ jsx18(AlertDialogDescription3, { children: "Esta a\xE7\xE3o n\xE3o pode ser desfeita. A ferramenta ser\xE1 removida permanentemente." })
4006
- ] }),
4007
- /* @__PURE__ */ jsxs16(AlertDialogFooter3, { children: [
4008
- /* @__PURE__ */ jsx18(AlertDialogCancel3, { variant: "outline", size: "default", children: "Cancelar" }),
4009
- /* @__PURE__ */ jsx18(
4010
- AlertDialogAction3,
4011
- {
4012
- variant: "default",
4013
- size: "default",
4014
- onClick: handleDelete,
4015
- className: "bg-destructive text-destructive-foreground hover:bg-destructive/90",
4016
- children: "Excluir"
4017
- }
4018
- )
4019
- ] })
4020
- ] })
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
4021
3884
  }
4022
3885
  )
4023
3886
  ] });
4024
3887
  }
4025
3888
 
4026
- // src/components/tools/tool-credentials-form.tsx
4027
- import { useMemo as useMemo7, useState as useState11 } from "react";
4028
- import { DataTable as DataTable3 } from "@greatapps/greatauth-ui";
3889
+ // src/components/agents/agent-tools-list.tsx
3890
+ import { useState as useState11 } from "react";
4029
3891
  import {
4030
- Input as Input8,
4031
- Button as Button12,
4032
- Badge as Badge8,
4033
- Tooltip as Tooltip4,
4034
- TooltipTrigger as TooltipTrigger4,
4035
- TooltipContent as TooltipContent4,
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,
4036
3909
  Dialog as Dialog5,
4037
3910
  DialogContent as DialogContent5,
4038
3911
  DialogHeader as DialogHeader5,
4039
3912
  DialogTitle as DialogTitle5,
4040
3913
  DialogFooter as DialogFooter5,
4041
- AlertDialog as AlertDialog4,
4042
- AlertDialogAction as AlertDialogAction4,
4043
- AlertDialogCancel as AlertDialogCancel4,
4044
- AlertDialogContent as AlertDialogContent4,
4045
- AlertDialogDescription as AlertDialogDescription4,
4046
- AlertDialogFooter as AlertDialogFooter4,
4047
- AlertDialogHeader as AlertDialogHeader4,
4048
- AlertDialogTitle as AlertDialogTitle4,
3914
+ Label as Label7,
4049
3915
  Select as Select2,
4050
3916
  SelectContent as SelectContent2,
4051
3917
  SelectItem as SelectItem2,
4052
3918
  SelectTrigger as SelectTrigger2,
4053
3919
  SelectValue as SelectValue2
4054
3920
  } from "@greatapps/greatauth-ui/ui";
4055
- import { Trash2 as Trash24, Pencil as Pencil4, Link, Search as Search3 } from "lucide-react";
4056
- import { format as format3 } from "date-fns";
4057
- import { ptBR as ptBR3 } from "date-fns/locale";
4058
- 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";
4059
3928
  import { jsx as jsx19, jsxs as jsxs17 } from "react/jsx-runtime";
4060
- function formatDate2(dateStr) {
4061
- if (!dateStr) return "Sem expira\xE7\xE3o";
4062
- return format3(new Date(dateStr), "dd/MM/yyyy", { locale: ptBR3 });
4063
- }
4064
- function useColumns3(tools, onEdit, onConnect, onRemove) {
4065
- function getToolName(idTool) {
4066
- if (!idTool) return "\u2014";
4067
- const tool = tools.find((t) => t.id === idTool);
4068
- return tool?.name || `Ferramenta #${idTool}`;
4069
- }
4070
- function getToolType(idTool) {
4071
- if (!idTool) return null;
4072
- const tool = tools.find((t) => t.id === idTool);
4073
- return tool?.type || null;
4074
- }
4075
- return [
4076
- {
4077
- accessorKey: "label",
4078
- header: "Label",
4079
- cell: ({ row }) => /* @__PURE__ */ jsx19("span", { className: "font-medium", children: row.original.label || "\u2014" })
4080
- },
4081
- {
4082
- accessorKey: "id_tool",
4083
- header: "Ferramenta",
4084
- cell: ({ row }) => /* @__PURE__ */ jsx19("span", { className: "text-sm", children: getToolName(row.original.id_tool) })
4085
- },
4086
- {
4087
- accessorKey: "status",
4088
- header: "Status",
4089
- cell: ({ row }) => /* @__PURE__ */ jsx19(
4090
- Badge8,
4091
- {
4092
- variant: row.original.status === "active" ? "default" : "destructive",
4093
- children: row.original.status === "active" ? "Ativo" : "Expirado"
4094
- }
4095
- )
4096
- },
4097
- {
4098
- accessorKey: "expires_at",
4099
- header: "Expira em",
4100
- cell: ({ row }) => /* @__PURE__ */ jsx19("span", { className: "text-muted-foreground text-sm", children: formatDate2(row.original.expires_at) })
4101
- },
4102
- {
4103
- accessorKey: "datetime_add",
4104
- header: "Criado em",
4105
- cell: ({ row }) => /* @__PURE__ */ jsx19("span", { className: "text-muted-foreground text-sm", children: formatDate2(row.original.datetime_add) })
4106
- },
4107
- {
4108
- id: "actions",
4109
- header: "A\xE7\xF5es",
4110
- size: 100,
4111
- enableSorting: false,
4112
- cell: ({ row }) => /* @__PURE__ */ jsxs17("div", { className: "flex items-center gap-1", children: [
4113
- getToolType(row.original.id_tool) === "oauth2" && /* @__PURE__ */ jsxs17(Tooltip4, { children: [
4114
- /* @__PURE__ */ jsx19(TooltipTrigger4, { asChild: true, children: /* @__PURE__ */ jsx19(
4115
- Button12,
4116
- {
4117
- variant: "ghost",
4118
- size: "icon",
4119
- className: "h-8 w-8",
4120
- "aria-label": "Vincular",
4121
- disabled: true,
4122
- children: /* @__PURE__ */ jsx19(Link, { className: "h-4 w-4" })
4123
- }
4124
- ) }),
4125
- /* @__PURE__ */ jsx19(TooltipContent4, { children: "Em breve" })
4126
- ] }),
4127
- /* @__PURE__ */ jsxs17(Tooltip4, { children: [
4128
- /* @__PURE__ */ jsx19(TooltipTrigger4, { asChild: true, children: /* @__PURE__ */ jsx19(
4129
- Button12,
4130
- {
4131
- variant: "ghost",
4132
- size: "icon",
4133
- className: "h-8 w-8",
4134
- "aria-label": "Editar",
4135
- onClick: () => onEdit(row.original),
4136
- children: /* @__PURE__ */ jsx19(Pencil4, { className: "h-4 w-4" })
4137
- }
4138
- ) }),
4139
- /* @__PURE__ */ jsx19(TooltipContent4, { children: "Editar" })
4140
- ] }),
4141
- /* @__PURE__ */ jsxs17(Tooltip4, { children: [
4142
- /* @__PURE__ */ jsx19(TooltipTrigger4, { asChild: true, children: /* @__PURE__ */ jsx19(
4143
- Button12,
4144
- {
4145
- variant: "ghost",
4146
- size: "icon",
4147
- className: "h-8 w-8 text-destructive hover:text-destructive",
4148
- "aria-label": "Excluir",
4149
- onClick: () => onRemove(row.original),
4150
- children: /* @__PURE__ */ jsx19(Trash24, { className: "h-4 w-4" })
4151
- }
4152
- ) }),
4153
- /* @__PURE__ */ jsx19(TooltipContent4, { children: "Remover" })
4154
- ] })
4155
- ] })
4156
- }
4157
- ];
4158
- }
4159
- function ToolCredentialsForm({
4160
- credentials,
4161
- isLoading,
4162
- config,
4163
- gagentsApiUrl,
4164
- createOpen: externalCreateOpen,
4165
- onCreateOpenChange
4166
- }) {
4167
- const createMutation = useCreateToolCredential(config);
4168
- const updateMutation = useUpdateToolCredential(config);
4169
- const deleteMutation = useDeleteToolCredential(config);
4170
- const { data: toolsData } = useTools(config);
4171
- const tools = (toolsData?.data || []).filter((t) => !t.slug?.startsWith("gclinic_"));
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);
4172
3937
  const [search, setSearch] = useState11("");
4173
- const [internalCreateOpen, setInternalCreateOpen] = useState11(false);
4174
- const showCreateDialog = externalCreateOpen ?? internalCreateOpen;
4175
- const setShowCreateDialog = onCreateOpenChange ?? setInternalCreateOpen;
4176
- const [createForm, setCreateForm] = useState11({
4177
- id_tool: "",
4178
- label: "",
4179
- credentials_encrypted: "",
4180
- expires_at: ""
4181
- });
4182
- const [editTarget, setEditTarget] = useState11(null);
4183
- const [editForm, setEditForm] = useState11({
4184
- id_tool: "",
4185
- label: "",
4186
- credentials_encrypted: "",
4187
- expires_at: "",
4188
- status: ""
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_");
4189
3949
  });
4190
- const [removeTarget, setRemoveTarget] = useState11(null);
4191
- const internalToolIds = useMemo7(() => {
4192
- const allRawTools = toolsData?.data || [];
4193
- return new Set(
4194
- allRawTools.filter((t) => t.slug?.startsWith("gclinic_")).map((t) => t.id)
4195
- );
4196
- }, [toolsData]);
4197
- const filteredCredentials = useMemo7(() => {
4198
- const visible = credentials.filter(
4199
- (cred) => !cred.id_tool || !internalToolIds.has(cred.id_tool)
4200
- );
4201
- if (!search) return visible;
4202
- const term = search.toLowerCase();
4203
- return visible.filter((cred) => {
4204
- const toolName = tools.find((t) => t.id === cred.id_tool)?.name || "";
4205
- return (cred.label || "").toLowerCase().includes(term) || toolName.toLowerCase().includes(term);
4206
- });
4207
- }, [credentials, search, tools, internalToolIds]);
4208
- const columns = useColumns3(
4209
- tools,
4210
- (cred) => startEdit(cred),
4211
- (cred) => handleConnect(cred),
4212
- (cred) => setRemoveTarget(cred)
3950
+ const availableTools = allTools.filter((t) => !assignedToolIds.has(t.id));
3951
+ const filteredAvailable = availableTools.filter(
3952
+ (t) => t.name.toLowerCase().includes(search.toLowerCase())
4213
3953
  );
4214
- async function handleCreate() {
4215
- const idTool = parseInt(createForm.id_tool, 10);
4216
- if (!idTool || !createForm.label.trim() || !createForm.credentials_encrypted.trim()) return;
3954
+ function getToolInfo(idTool) {
3955
+ return allTools.find((t) => t.id === idTool);
3956
+ }
3957
+ async function handleToggleEnabled(agentTool, checked) {
4217
3958
  try {
4218
- const result = await createMutation.mutateAsync({
4219
- id_tool: idTool,
4220
- label: createForm.label.trim(),
4221
- credentials_encrypted: createForm.credentials_encrypted.trim(),
4222
- ...createForm.expires_at ? { expires_at: createForm.expires_at } : {}
3959
+ await updateMutation.mutateAsync({
3960
+ idAgent: agent.id,
3961
+ id: agentTool.id,
3962
+ body: { enabled: checked }
4223
3963
  });
4224
- if (result.status === 1) {
4225
- toast9.success("Credencial criada");
4226
- setShowCreateDialog(false);
4227
- setCreateForm({ id_tool: "", label: "", credentials_encrypted: "", expires_at: "" });
4228
- } else {
4229
- toast9.error(result.message || "Erro ao criar credencial");
4230
- }
4231
- } catch {
4232
- toast9.error("Erro ao criar credencial");
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
+ );
4233
3969
  }
4234
3970
  }
4235
- function startEdit(cred) {
4236
- setEditTarget(cred);
4237
- setEditForm({
4238
- id_tool: cred.id_tool ? String(cred.id_tool) : "",
4239
- label: cred.label || "",
4240
- credentials_encrypted: "",
4241
- expires_at: cred.expires_at || "",
4242
- status: cred.status
4243
- });
4244
- }
4245
- async function handleSaveEdit() {
4246
- if (!editTarget) return;
4247
- const body = {};
4248
- const newIdTool = editForm.id_tool ? parseInt(editForm.id_tool, 10) : null;
4249
- if (newIdTool && newIdTool !== editTarget.id_tool) {
4250
- body.id_tool = newIdTool;
4251
- }
4252
- if (editForm.label.trim() && editForm.label.trim() !== (editTarget.label || "")) {
4253
- body.label = editForm.label.trim();
4254
- }
4255
- if (editForm.credentials_encrypted.trim()) {
4256
- body.credentials_encrypted = editForm.credentials_encrypted.trim();
4257
- }
4258
- if (editForm.expires_at !== (editTarget.expires_at || "")) {
4259
- body.expires_at = editForm.expires_at || null;
4260
- }
4261
- if (editForm.status && editForm.status !== editTarget.status) {
4262
- body.status = editForm.status;
4263
- }
4264
- if (Object.keys(body).length === 0) {
4265
- setEditTarget(null);
4266
- return;
4267
- }
3971
+ async function handleAdd(tool) {
4268
3972
  try {
4269
- const result = await updateMutation.mutateAsync({
4270
- id: editTarget.id,
4271
- body
3973
+ await addMutation.mutateAsync({
3974
+ idAgent: agent.id,
3975
+ body: { id_tool: tool.id }
4272
3976
  });
4273
- if (result.status === 1) {
4274
- toast9.success("Credencial atualizada");
4275
- setEditTarget(null);
4276
- } else {
4277
- toast9.error(result.message || "Erro ao atualizar credencial");
4278
- }
4279
- } catch {
4280
- toast9.error("Erro ao atualizar credencial");
3977
+ toast8.success("Ferramenta adicionada");
3978
+ setAddOpen(false);
3979
+ setSearch("");
3980
+ } catch (err) {
3981
+ toast8.error(
3982
+ err instanceof Error ? err.message : "Erro ao adicionar ferramenta"
3983
+ );
4281
3984
  }
4282
3985
  }
4283
3986
  async function handleRemove() {
4284
3987
  if (!removeTarget) return;
4285
3988
  try {
4286
- const result = await deleteMutation.mutateAsync(removeTarget.id);
4287
- if (result.status === 1) {
4288
- toast9.success("Credencial removida");
4289
- } else {
4290
- toast9.error(result.message || "Erro ao remover credencial");
4291
- }
4292
- } catch {
4293
- toast9.error("Erro ao remover credencial");
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
+ );
4294
3998
  } finally {
4295
3999
  setRemoveTarget(null);
4296
4000
  }
4297
4001
  }
4298
- function handleConnect(cred) {
4299
- if (!config.accountId || !config.token) return;
4300
- const language = config.language ?? "pt-br";
4301
- const idWl = config.idWl ?? 1;
4302
- const url = `${gagentsApiUrl}/v1/${language}/${idWl}/accounts/${config.accountId}/oauth/connect?id_tool=${cred.id_tool}`;
4303
- window.open(url, "_blank");
4002
+ function openConfig(agentTool) {
4003
+ setConfigTarget(agentTool);
4004
+ setConfigInstructions(agentTool.custom_instructions || "");
4005
+ setConfigCredentialId(agentTool.id_tool_credential ? String(agentTool.id_tool_credential) : "");
4304
4006
  }
4305
- return /* @__PURE__ */ jsxs17("div", { className: "space-y-4", children: [
4306
- /* @__PURE__ */ jsx19("div", { className: "flex items-center gap-3", children: /* @__PURE__ */ jsxs17("div", { className: "relative flex-1 max-w-md", children: [
4307
- /* @__PURE__ */ jsx19(Search3, { "aria-hidden": "true", className: "absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground" }),
4308
- /* @__PURE__ */ jsx19(
4309
- Input8,
4310
- {
4311
- placeholder: "Buscar credenciais\\u2026",
4312
- "aria-label": "Buscar credenciais",
4313
- name: "search",
4314
- autoComplete: "off",
4315
- value: search,
4316
- onChange: (e) => setSearch(e.target.value),
4317
- className: "pl-9"
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
4318
4017
  }
4319
- )
4320
- ] }) }),
4321
- /* @__PURE__ */ jsx19(
4322
- DataTable3,
4323
- {
4324
- columns,
4325
- data: filteredCredentials,
4326
- isLoading,
4327
- emptyMessage: "Nenhuma credencial encontrada"
4328
- }
4329
- ),
4330
- /* @__PURE__ */ jsx19(Dialog5, { open: showCreateDialog, onOpenChange: setShowCreateDialog, children: /* @__PURE__ */ jsxs17(DialogContent5, { children: [
4331
- /* @__PURE__ */ jsx19(DialogHeader5, { children: /* @__PURE__ */ jsx19(DialogTitle5, { children: "Nova Credencial" }) }),
4332
- /* @__PURE__ */ jsxs17("div", { className: "space-y-4", children: [
4333
- /* @__PURE__ */ jsxs17("div", { children: [
4334
- /* @__PURE__ */ jsx19("label", { htmlFor: "cred-tool", className: "mb-1 block text-sm font-medium", children: "Ferramenta *" }),
4335
- /* @__PURE__ */ jsxs17(
4336
- Select2,
4337
- {
4338
- value: createForm.id_tool,
4339
- onValueChange: (val) => setCreateForm((f) => ({ ...f, id_tool: val })),
4340
- children: [
4341
- /* @__PURE__ */ jsx19(SelectTrigger2, { id: "cred-tool", children: /* @__PURE__ */ jsx19(SelectValue2, { placeholder: "Selecione a ferramenta" }) }),
4342
- /* @__PURE__ */ jsx19(SelectContent2, { children: tools.map((tool) => /* @__PURE__ */ jsx19(SelectItem2, { value: String(tool.id), children: tool.name }, tool.id)) })
4343
- ]
4344
- }
4345
- )
4346
- ] }),
4347
- /* @__PURE__ */ jsxs17("div", { children: [
4348
- /* @__PURE__ */ jsx19("label", { htmlFor: "cred-label", className: "mb-1 block text-sm font-medium", children: "Label *" }),
4349
- /* @__PURE__ */ jsx19(
4350
- Input8,
4351
- {
4352
- id: "cred-label",
4353
- name: "label",
4354
- value: createForm.label,
4355
- onChange: (e) => setCreateForm((f) => ({ ...f, label: e.target.value })),
4356
- placeholder: "Ex: Google Calendar - Cl\xEDnica S\xE3o Paulo"
4357
- }
4358
- )
4359
- ] }),
4360
- /* @__PURE__ */ jsxs17("div", { children: [
4361
- /* @__PURE__ */ jsx19("label", { htmlFor: "cred-credential", className: "mb-1 block text-sm font-medium", children: "Credencial *" }),
4362
- /* @__PURE__ */ jsx19(
4363
- Input8,
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
+ }
4026
+ }
4027
+ if (isLoading) {
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)) });
4029
+ }
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: [
4033
+ visibleAgentTools.length,
4034
+ " ferramenta",
4035
+ visibleAgentTools.length !== 1 ? "s" : "",
4036
+ " associada",
4037
+ visibleAgentTools.length !== 1 ? "s" : ""
4038
+ ] }),
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" }),
4042
+ "Adicionar Ferramenta"
4043
+ ] }) }),
4044
+ /* @__PURE__ */ jsxs17(PopoverContent, { className: "w-72 p-0", align: "end", children: [
4045
+ /* @__PURE__ */ jsx19("div", { className: "p-2", children: /* @__PURE__ */ jsx19(
4046
+ Input7,
4364
4047
  {
4365
- id: "cred-credential",
4366
- name: "credential",
4367
- autoComplete: "off",
4368
- type: "password",
4369
- value: createForm.credentials_encrypted,
4370
- onChange: (e) => setCreateForm((f) => ({
4371
- ...f,
4372
- credentials_encrypted: e.target.value
4373
- })),
4374
- placeholder: "Credencial encriptada"
4048
+ placeholder: "Buscar ferramenta\\u2026",
4049
+ "aria-label": "Buscar ferramenta",
4050
+ name: "search",
4051
+ value: search,
4052
+ onChange: (e) => setSearch(e.target.value),
4053
+ className: "h-8"
4375
4054
  }
4376
- )
4377
- ] }),
4378
- /* @__PURE__ */ jsxs17("div", { children: [
4379
- /* @__PURE__ */ jsx19("label", { htmlFor: "cred-expires", className: "mb-1 block text-sm font-medium", children: "Data de Expira\xE7\xE3o (opcional)" }),
4380
- /* @__PURE__ */ jsx19(
4381
- Input8,
4055
+ ) }),
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(
4057
+ "button",
4382
4058
  {
4383
- id: "cred-expires",
4384
- name: "expires",
4385
- type: "date",
4386
- value: createForm.expires_at,
4387
- onChange: (e) => setCreateForm((f) => ({ ...f, expires_at: e.target.value }))
4388
- }
4389
- )
4059
+ type: "button",
4060
+ className: "flex w-full items-center gap-2 px-3 py-2 text-left text-sm hover:bg-accent",
4061
+ onClick: () => handleAdd(tool),
4062
+ disabled: addMutation.isPending,
4063
+ children: [
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 })
4067
+ ]
4068
+ },
4069
+ tool.id
4070
+ )) })
4390
4071
  ] })
4391
- ] }),
4392
- /* @__PURE__ */ jsxs17(DialogFooter5, { children: [
4393
- /* @__PURE__ */ jsx19(
4394
- Button12,
4395
- {
4396
- variant: "outline",
4397
- onClick: () => setShowCreateDialog(false),
4398
- children: "Cancelar"
4399
- }
4400
- ),
4401
- /* @__PURE__ */ jsx19(
4402
- Button12,
4403
- {
4404
- onClick: handleCreate,
4405
- disabled: !createForm.id_tool || !createForm.label.trim() || !createForm.credentials_encrypted.trim() || createMutation.isPending,
4406
- children: "Criar"
4407
- }
4408
- )
4409
4072
  ] })
4410
- ] }) }),
4073
+ ] }),
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) => {
4078
+ const tool = getToolInfo(agentTool.id_tool);
4079
+ return /* @__PURE__ */ jsxs17(
4080
+ "div",
4081
+ {
4082
+ className: "flex items-center gap-3 rounded-lg border bg-card p-3",
4083
+ children: [
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 })
4088
+ ] }),
4089
+ agentTool.custom_instructions && /* @__PURE__ */ jsx19("p", { className: "truncate text-xs text-muted-foreground", children: agentTool.custom_instructions })
4090
+ ] }),
4091
+ /* @__PURE__ */ jsx19(
4092
+ Switch5,
4093
+ {
4094
+ "aria-label": "Ativar/Desativar",
4095
+ checked: agentTool.enabled,
4096
+ onCheckedChange: (checked) => handleToggleEnabled(agentTool, checked),
4097
+ disabled: updateMutation.isPending
4098
+ }
4099
+ ),
4100
+ /* @__PURE__ */ jsx19(
4101
+ Button11,
4102
+ {
4103
+ variant: "ghost",
4104
+ size: "icon",
4105
+ "aria-label": "Configurar",
4106
+ className: "shrink-0 text-muted-foreground hover:text-foreground",
4107
+ onClick: () => openConfig(agentTool),
4108
+ title: "Configurar instru\xE7\xF5es",
4109
+ children: /* @__PURE__ */ jsx19(Settings22, { className: "h-4 w-4" })
4110
+ }
4111
+ ),
4112
+ /* @__PURE__ */ jsx19(
4113
+ Button11,
4114
+ {
4115
+ variant: "ghost",
4116
+ size: "icon",
4117
+ "aria-label": "Remover",
4118
+ className: "shrink-0 text-muted-foreground hover:text-destructive",
4119
+ onClick: () => setRemoveTarget(agentTool),
4120
+ children: /* @__PURE__ */ jsx19(Trash23, { className: "h-4 w-4" })
4121
+ }
4122
+ )
4123
+ ]
4124
+ },
4125
+ agentTool.id
4126
+ );
4127
+ }) }),
4411
4128
  /* @__PURE__ */ jsx19(
4412
4129
  Dialog5,
4413
4130
  {
4414
- open: !!editTarget,
4415
- onOpenChange: (open) => !open && setEditTarget(null),
4416
- children: /* @__PURE__ */ jsxs17(DialogContent5, { children: [
4417
- /* @__PURE__ */ jsx19(DialogHeader5, { children: /* @__PURE__ */ jsx19(DialogTitle5, { children: "Editar Credencial" }) }),
4131
+ open: !!configTarget,
4132
+ onOpenChange: (open) => !open && setConfigTarget(null),
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" }) }),
4418
4135
  /* @__PURE__ */ jsxs17("div", { className: "space-y-4", children: [
4419
- /* @__PURE__ */ jsxs17("div", { children: [
4420
- /* @__PURE__ */ jsx19("label", { htmlFor: "edit-cred-tool", className: "mb-1 block text-sm font-medium", children: "Ferramenta *" }),
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" }),
4421
4138
  /* @__PURE__ */ jsxs17(
4422
4139
  Select2,
4423
4140
  {
4424
- value: editForm.id_tool,
4425
- onValueChange: (val) => setEditForm((f) => ({ ...f, id_tool: val })),
4141
+ value: configCredentialId || void 0,
4142
+ onValueChange: (val) => setConfigCredentialId(val === "__none__" ? "" : val),
4426
4143
  children: [
4427
- /* @__PURE__ */ jsx19(SelectTrigger2, { id: "edit-cred-tool", children: /* @__PURE__ */ jsx19(SelectValue2, { placeholder: "Selecione a ferramenta" }) }),
4428
- /* @__PURE__ */ jsx19(SelectContent2, { children: tools.map((tool) => /* @__PURE__ */ jsx19(SelectItem2, { value: String(tool.id), children: tool.name }, tool.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))
4148
+ ] })
4429
4149
  ]
4430
4150
  }
4431
- )
4432
- ] }),
4433
- /* @__PURE__ */ jsxs17("div", { children: [
4434
- /* @__PURE__ */ jsx19("label", { htmlFor: "edit-cred-label", className: "mb-1 block text-sm font-medium", children: "Label" }),
4435
- /* @__PURE__ */ jsx19(
4436
- Input8,
4437
- {
4438
- id: "edit-cred-label",
4439
- name: "label",
4440
- value: editForm.label,
4441
- onChange: (e) => setEditForm((f) => ({ ...f, label: e.target.value })),
4442
- placeholder: "Label da credencial"
4443
- }
4444
- )
4445
- ] }),
4446
- /* @__PURE__ */ jsxs17("div", { children: [
4447
- /* @__PURE__ */ jsx19("label", { htmlFor: "edit-cred-credential", className: "mb-1 block text-sm font-medium", children: "Nova Credencial (vazio = manter atual)" }),
4448
- /* @__PURE__ */ jsx19(
4449
- Input8,
4450
- {
4451
- id: "edit-cred-credential",
4452
- name: "credential",
4453
- autoComplete: "off",
4454
- type: "password",
4455
- value: editForm.credentials_encrypted,
4456
- onChange: (e) => setEditForm((f) => ({
4457
- ...f,
4458
- credentials_encrypted: e.target.value
4459
- })),
4460
- placeholder: "Nova credencial"
4461
- }
4462
- )
4151
+ ),
4152
+ /* @__PURE__ */ jsx19("p", { className: "text-xs text-muted-foreground", children: "Vincule uma credencial espec\xEDfica a esta ferramenta neste agente." })
4463
4153
  ] }),
4464
- /* @__PURE__ */ jsxs17("div", { children: [
4465
- /* @__PURE__ */ jsx19("label", { htmlFor: "edit-cred-expires", className: "mb-1 block text-sm font-medium", children: "Data de Expira\xE7\xE3o" }),
4154
+ /* @__PURE__ */ jsxs17("div", { className: "space-y-2", children: [
4155
+ /* @__PURE__ */ jsx19(Label7, { htmlFor: "tool-instructions", children: "Instru\xE7\xF5es Personalizadas" }),
4466
4156
  /* @__PURE__ */ jsx19(
4467
- Input8,
4468
- {
4469
- id: "edit-cred-expires",
4470
- name: "expires",
4471
- type: "date",
4472
- value: editForm.expires_at,
4473
- onChange: (e) => setEditForm((f) => ({ ...f, expires_at: e.target.value }))
4474
- }
4475
- )
4476
- ] }),
4477
- /* @__PURE__ */ jsxs17("div", { children: [
4478
- /* @__PURE__ */ jsx19("label", { htmlFor: "edit-cred-status", className: "mb-1 block text-sm font-medium", children: "Status" }),
4479
- /* @__PURE__ */ jsxs17(
4480
- Select2,
4157
+ Textarea2,
4481
4158
  {
4482
- value: editForm.status || void 0,
4483
- onValueChange: (val) => setEditForm((f) => ({
4484
- ...f,
4485
- status: val
4486
- })),
4487
- children: [
4488
- /* @__PURE__ */ jsx19(SelectTrigger2, { id: "edit-cred-status", children: /* @__PURE__ */ jsx19(SelectValue2, {}) }),
4489
- /* @__PURE__ */ jsxs17(SelectContent2, { children: [
4490
- /* @__PURE__ */ jsx19(SelectItem2, { value: "active", children: "Ativo" }),
4491
- /* @__PURE__ */ jsx19(SelectItem2, { value: "expired", children: "Expirado" })
4492
- ] })
4493
- ]
4159
+ id: "tool-instructions",
4160
+ name: "instructions",
4161
+ value: configInstructions,
4162
+ onChange: (e) => setConfigInstructions(e.target.value),
4163
+ placeholder: "Instru\\u00e7\\u00f5es sobre como e quando o agente deve usar esta ferramenta\\u2026",
4164
+ rows: 6
4494
4165
  }
4495
- )
4166
+ ),
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." })
4496
4168
  ] })
4497
4169
  ] }),
4498
4170
  /* @__PURE__ */ jsxs17(DialogFooter5, { children: [
4499
- /* @__PURE__ */ jsx19(Button12, { variant: "outline", onClick: () => setEditTarget(null), children: "Cancelar" }),
4500
4171
  /* @__PURE__ */ jsx19(
4501
- Button12,
4172
+ Button11,
4502
4173
  {
4503
- onClick: handleSaveEdit,
4174
+ variant: "outline",
4175
+ onClick: () => setConfigTarget(null),
4176
+ children: "Cancelar"
4177
+ }
4178
+ ),
4179
+ /* @__PURE__ */ jsx19(
4180
+ Button11,
4181
+ {
4182
+ onClick: handleSaveConfig,
4504
4183
  disabled: updateMutation.isPending,
4505
4184
  children: "Salvar"
4506
4185
  }
@@ -4509,24 +4188,214 @@ function ToolCredentialsForm({
4509
4188
  ] })
4510
4189
  }
4511
4190
  ),
4512
- /* @__PURE__ */ jsx19(
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(
4513
4380
  AlertDialog4,
4514
4381
  {
4515
- open: !!removeTarget,
4516
- onOpenChange: (open) => !open && setRemoveTarget(null),
4517
- children: /* @__PURE__ */ jsxs17(AlertDialogContent4, { children: [
4518
- /* @__PURE__ */ jsxs17(AlertDialogHeader4, { children: [
4519
- /* @__PURE__ */ jsx19(AlertDialogTitle4, { children: "Remover credencial?" }),
4520
- /* @__PURE__ */ jsx19(AlertDialogDescription4, { children: "A credencial ser\xE1 removida permanentemente." })
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." })
4521
4388
  ] }),
4522
- /* @__PURE__ */ jsxs17(AlertDialogFooter4, { children: [
4523
- /* @__PURE__ */ jsx19(AlertDialogCancel4, { children: "Cancelar" }),
4524
- /* @__PURE__ */ jsx19(
4389
+ /* @__PURE__ */ jsxs18(AlertDialogFooter4, { children: [
4390
+ /* @__PURE__ */ jsx20(AlertDialogCancel4, { variant: "outline", size: "default", children: "Cancelar" }),
4391
+ /* @__PURE__ */ jsx20(
4525
4392
  AlertDialogAction4,
4526
4393
  {
4527
- onClick: handleRemove,
4528
- disabled: deleteMutation.isPending,
4529
- children: "Remover"
4394
+ variant: "default",
4395
+ size: "default",
4396
+ onClick: handleDelete,
4397
+ className: "bg-destructive text-destructive-foreground hover:bg-destructive/90",
4398
+ children: "Excluir"
4530
4399
  }
4531
4400
  )
4532
4401
  ] })
@@ -4537,7 +4406,7 @@ function ToolCredentialsForm({
4537
4406
  }
4538
4407
 
4539
4408
  // src/components/tools/tool-form-dialog.tsx
4540
- import { useState as useState12 } from "react";
4409
+ import { useState as useState13 } from "react";
4541
4410
  import {
4542
4411
  Dialog as Dialog6,
4543
4412
  DialogContent as DialogContent6,
@@ -4546,17 +4415,17 @@ import {
4546
4415
  DialogFooter as DialogFooter6,
4547
4416
  Button as Button13,
4548
4417
  Input as Input9,
4549
- Textarea as Textarea2,
4550
- Label as Label7,
4418
+ Textarea as Textarea3,
4419
+ Label as Label8,
4551
4420
  Select as Select3,
4552
4421
  SelectContent as SelectContent3,
4553
4422
  SelectItem as SelectItem3,
4554
4423
  SelectTrigger as SelectTrigger3,
4555
4424
  SelectValue as SelectValue3
4556
4425
  } from "@greatapps/greatauth-ui/ui";
4557
- import { Loader2 as Loader28 } from "lucide-react";
4426
+ import { Loader2 as Loader29 } from "lucide-react";
4558
4427
  import { toast as toast10 } from "sonner";
4559
- import { jsx as jsx20, jsxs as jsxs18 } from "react/jsx-runtime";
4428
+ import { jsx as jsx21, jsxs as jsxs19 } from "react/jsx-runtime";
4560
4429
  var TOOL_AUTH_TYPES = [
4561
4430
  { value: "none", label: "Nenhuma" },
4562
4431
  { value: "api_key", label: "API Key" },
@@ -4603,9 +4472,9 @@ function ToolFormDialog({
4603
4472
  const isEditing = !!tool;
4604
4473
  const createTool = useCreateTool(config);
4605
4474
  const updateTool = useUpdateTool(config);
4606
- const [form, setForm] = useState12(() => toolToFormState(tool));
4607
- const [slugManuallyEdited, setSlugManuallyEdited] = useState12(false);
4608
- const [lastResetKey, setLastResetKey] = useState12(
4475
+ const [form, setForm] = useState13(() => toolToFormState(tool));
4476
+ const [slugManuallyEdited, setSlugManuallyEdited] = useState13(false);
4477
+ const [lastResetKey, setLastResetKey] = useState13(
4609
4478
  () => `${tool?.id}-${open}`
4610
4479
  );
4611
4480
  const resetKey = `${tool?.id}-${open}`;
@@ -4666,12 +4535,12 @@ function ToolFormDialog({
4666
4535
  );
4667
4536
  }
4668
4537
  }
4669
- return /* @__PURE__ */ jsx20(Dialog6, { open, onOpenChange, children: /* @__PURE__ */ jsxs18(DialogContent6, { className: "sm:max-w-lg", children: [
4670
- /* @__PURE__ */ jsx20(DialogHeader6, { children: /* @__PURE__ */ jsx20(DialogTitle6, { children: isEditing ? "Editar Ferramenta" : "Nova Ferramenta" }) }),
4671
- /* @__PURE__ */ jsxs18("form", { onSubmit: handleSubmit, className: "space-y-4", children: [
4672
- /* @__PURE__ */ jsxs18("div", { className: "space-y-2", children: [
4673
- /* @__PURE__ */ jsx20(Label7, { htmlFor: "tool-name", children: "Nome *" }),
4674
- /* @__PURE__ */ jsx20(
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(
4675
4544
  Input9,
4676
4545
  {
4677
4546
  id: "tool-name",
@@ -4690,344 +4559,141 @@ function ToolFormDialog({
4690
4559
  disabled: isPending
4691
4560
  }
4692
4561
  ),
4693
- form.nameError && /* @__PURE__ */ jsx20("p", { className: "text-sm text-destructive", children: "Nome \xE9 obrigat\xF3rio" })
4562
+ form.nameError && /* @__PURE__ */ jsx21("p", { className: "text-sm text-destructive", children: "Nome \xE9 obrigat\xF3rio" })
4694
4563
  ] }),
4695
- /* @__PURE__ */ jsxs18("div", { className: "space-y-2", children: [
4696
- /* @__PURE__ */ jsx20(Label7, { htmlFor: "tool-slug", children: "Slug (identificador \xFAnico) *" }),
4697
- /* @__PURE__ */ jsx20(
4564
+ /* @__PURE__ */ jsxs19("div", { className: "space-y-2", children: [
4565
+ /* @__PURE__ */ jsx21(Label8, { htmlFor: "tool-slug", children: "Slug (identificador \xFAnico) *" }),
4566
+ /* @__PURE__ */ jsx21(
4698
4567
  Input9,
4699
4568
  {
4700
4569
  id: "tool-slug",
4701
4570
  name: "slug",
4702
4571
  value: form.slug,
4703
4572
  onChange: (e) => {
4704
- setSlugManuallyEdited(true);
4705
- setForm((prev) => ({
4706
- ...prev,
4707
- slug: e.target.value,
4708
- slugError: e.target.value.trim() ? false : prev.slugError
4709
- }));
4710
- },
4711
- placeholder: "Ex: google-calendar",
4712
- disabled: isPending
4713
- }
4714
- ),
4715
- /* @__PURE__ */ jsx20("p", { className: "text-xs text-muted-foreground", children: "Gerado automaticamente a partir do nome. Usado internamente para identificar a ferramenta." }),
4716
- form.slugError && /* @__PURE__ */ jsx20("p", { className: "text-sm text-destructive", children: "Slug \xE9 obrigat\xF3rio" })
4717
- ] }),
4718
- /* @__PURE__ */ jsxs18("div", { className: "space-y-2", children: [
4719
- /* @__PURE__ */ jsx20(Label7, { htmlFor: "tool-type", children: "Tipo de Autentica\xE7\xE3o *" }),
4720
- /* @__PURE__ */ jsxs18(
4721
- Select3,
4722
- {
4723
- value: form.type,
4724
- onValueChange: (value) => {
4725
- setForm((prev) => ({
4726
- ...prev,
4727
- type: value,
4728
- typeError: false
4729
- }));
4730
- },
4731
- disabled: isPending,
4732
- children: [
4733
- /* @__PURE__ */ jsx20(SelectTrigger3, { id: "tool-type", children: /* @__PURE__ */ jsx20(SelectValue3, { placeholder: "Selecione o tipo" }) }),
4734
- /* @__PURE__ */ jsx20(SelectContent3, { children: TOOL_AUTH_TYPES.map((t) => /* @__PURE__ */ jsx20(SelectItem3, { value: t.value, children: t.label }, t.value)) })
4735
- ]
4736
- }
4737
- ),
4738
- /* @__PURE__ */ jsx20("p", { className: "text-xs text-muted-foreground", children: "Define se a ferramenta requer credenciais para funcionar." }),
4739
- form.typeError && /* @__PURE__ */ jsx20("p", { className: "text-sm text-destructive", children: "Tipo \xE9 obrigat\xF3rio" })
4740
- ] }),
4741
- /* @__PURE__ */ jsxs18("div", { className: "space-y-2", children: [
4742
- /* @__PURE__ */ jsx20(Label7, { htmlFor: "tool-description", children: "Descri\xE7\xE3o" }),
4743
- /* @__PURE__ */ jsx20(
4744
- Textarea2,
4745
- {
4746
- id: "tool-description",
4747
- name: "description",
4748
- value: form.description,
4749
- onChange: (e) => setForm((prev) => ({ ...prev, description: e.target.value })),
4750
- placeholder: "Descri\\u00e7\\u00e3o da ferramenta\\u2026",
4751
- rows: 3,
4752
- disabled: isPending
4753
- }
4754
- )
4755
- ] }),
4756
- /* @__PURE__ */ jsxs18("div", { className: "space-y-2", children: [
4757
- /* @__PURE__ */ jsx20(Label7, { htmlFor: "tool-function-defs", children: "Defini\xE7\xF5es de Fun\xE7\xE3o (JSON)" }),
4758
- /* @__PURE__ */ jsx20(
4759
- Textarea2,
4760
- {
4761
- id: "tool-function-defs",
4762
- name: "functionDefs",
4763
- value: form.functionDefinitions,
4764
- onChange: (e) => {
4765
- setForm((prev) => ({
4766
- ...prev,
4767
- functionDefinitions: e.target.value,
4768
- jsonError: false
4769
- }));
4770
- },
4771
- placeholder: `[
4772
- {
4773
- "type": "function",
4774
- "function": {
4775
- "name": "nome_da_funcao",
4776
- "description": "O que a fun\xE7\xE3o faz",
4777
- "parameters": {
4778
- "type": "object",
4779
- "properties": { \u2026 },
4780
- "required": [\u2026]
4781
- }
4782
- }
4783
- }
4784
- ]`,
4785
- rows: 10,
4786
- className: "font-mono text-sm",
4787
- disabled: isPending
4788
- }
4789
- ),
4790
- /* @__PURE__ */ jsx20("p", { className: "text-xs text-muted-foreground", children: "Array de defini\xE7\xF5es no formato OpenAI Function Calling." }),
4791
- form.jsonError && /* @__PURE__ */ jsx20("p", { className: "text-sm text-destructive", children: "JSON inv\xE1lido" })
4792
- ] }),
4793
- /* @__PURE__ */ jsxs18(DialogFooter6, { children: [
4794
- /* @__PURE__ */ jsx20(
4795
- Button13,
4796
- {
4797
- type: "button",
4798
- variant: "outline",
4799
- onClick: () => onOpenChange(false),
4800
- disabled: isPending,
4801
- children: "Cancelar"
4802
- }
4803
- ),
4804
- /* @__PURE__ */ jsxs18(Button13, { type: "submit", disabled: isPending, children: [
4805
- isPending ? /* @__PURE__ */ jsx20(Loader28, { "aria-hidden": "true", className: "mr-2 h-4 w-4 animate-spin" }) : null,
4806
- isEditing ? "Salvar" : "Criar"
4807
- ] })
4808
- ] })
4809
- ] })
4810
- ] }) });
4811
- }
4812
-
4813
- // src/components/capabilities/advanced-tab.tsx
4814
- import { Info as Info2 } from "lucide-react";
4815
- import { jsx as jsx21, jsxs as jsxs19 } from "react/jsx-runtime";
4816
- function AdvancedTab({ config, agentId, gagentsApiUrl }) {
4817
- const { data: credentialsData, isLoading: isLoadingCredentials } = useToolCredentials(config);
4818
- const credentials = credentialsData?.data ?? [];
4819
- const [editingTool, setEditingTool] = useState13(null);
4820
- const [showToolForm, setShowToolForm] = useState13(false);
4821
- function handleEditTool(tool) {
4822
- setEditingTool(tool);
4823
- setShowToolForm(true);
4824
- }
4825
- function handleToolFormOpenChange(open) {
4826
- setShowToolForm(open);
4827
- if (!open) setEditingTool(null);
4828
- }
4829
- return /* @__PURE__ */ jsxs19("div", { className: "space-y-8", children: [
4830
- /* @__PURE__ */ jsxs19("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: [
4831
- /* @__PURE__ */ jsx21(Info2, { className: "mt-0.5 h-4 w-4 shrink-0 text-blue-600 dark:text-blue-400" }),
4832
- /* @__PURE__ */ jsxs19("p", { className: "text-sm text-blue-800 dark:text-blue-300", children: [
4833
- "Use as abas ",
4834
- /* @__PURE__ */ jsx21("strong", { children: "Capacidades" }),
4835
- " e ",
4836
- /* @__PURE__ */ jsx21("strong", { children: "Integra\xE7\xF5es" }),
4837
- " para configura\xE7\xE3o simplificada. Esta aba oferece controlo manual avan\xE7ado sobre ferramentas e credenciais."
4838
- ] })
4839
- ] }),
4840
- /* @__PURE__ */ jsxs19("section", { className: "space-y-3", children: [
4841
- /* @__PURE__ */ jsx21("h3", { className: "text-sm font-medium", children: "Ferramentas" }),
4842
- /* @__PURE__ */ jsx21(ToolsTable, { onEdit: handleEditTool, config })
4843
- ] }),
4844
- /* @__PURE__ */ jsxs19("section", { className: "space-y-3", children: [
4845
- /* @__PURE__ */ jsx21("h3", { className: "text-sm font-medium", children: "Credenciais" }),
4846
- /* @__PURE__ */ jsx21(
4847
- ToolCredentialsForm,
4848
- {
4849
- credentials,
4850
- isLoading: isLoadingCredentials,
4851
- config,
4852
- gagentsApiUrl
4853
- }
4854
- )
4855
- ] }),
4856
- /* @__PURE__ */ jsx21(
4857
- ToolFormDialog,
4858
- {
4859
- open: showToolForm,
4860
- onOpenChange: handleToolFormOpenChange,
4861
- tool: editingTool ?? void 0,
4862
- config
4863
- }
4864
- )
4865
- ] });
4866
- }
4867
-
4868
- // src/pages/agent-capabilities-page.tsx
4869
- import { jsx as jsx22, jsxs as jsxs20 } from "react/jsx-runtime";
4870
- function defaultResolveWizardMeta(card) {
4871
- return {
4872
- capabilities: [
4873
- { label: card.definition.name, description: card.definition.description }
4874
- ],
4875
- requirements: [],
4876
- hasConfigStep: false
4877
- };
4878
- }
4879
- function AgentCapabilitiesPage({
4880
- config,
4881
- agentId,
4882
- gagentsApiUrl,
4883
- resolveWizardMeta = defaultResolveWizardMeta,
4884
- loadConfigOptions,
4885
- onWizardComplete
4886
- }) {
4887
- const [wizardOpen, setWizardOpen] = useState14(false);
4888
- const [activeCard, setActiveCard] = useState14(null);
4889
- const handleConnect = useCallback6(
4890
- (card) => {
4891
- setActiveCard(card);
4892
- setWizardOpen(true);
4893
- },
4894
- []
4895
- );
4896
- const handleWizardComplete = useCallback6(() => {
4897
- setWizardOpen(false);
4898
- setActiveCard(null);
4899
- onWizardComplete?.();
4900
- }, [onWizardComplete]);
4901
- const handleWizardOpenChange = useCallback6((open) => {
4902
- setWizardOpen(open);
4903
- if (!open) setActiveCard(null);
4904
- }, []);
4905
- const wizardMeta = activeCard ? resolveWizardMeta(activeCard) : null;
4906
- return /* @__PURE__ */ jsxs20("div", { className: "space-y-4", children: [
4907
- /* @__PURE__ */ jsxs20("div", { children: [
4908
- /* @__PURE__ */ jsx22("h2", { className: "text-lg font-semibold", children: "Capacidades e Integra\xE7\xF5es" }),
4909
- /* @__PURE__ */ jsx22("p", { className: "text-sm text-muted-foreground", children: "Configure o que este agente pode fazer e quais servi\xE7os externos ele utiliza." })
4910
- ] }),
4911
- /* @__PURE__ */ jsxs20(Tabs, { defaultValue: "capacidades", children: [
4912
- /* @__PURE__ */ jsxs20(TabsList, { children: [
4913
- /* @__PURE__ */ jsxs20(TabsTrigger, { value: "capacidades", className: "flex items-center gap-1.5", children: [
4914
- /* @__PURE__ */ jsx22(Blocks, { "aria-hidden": "true", className: "h-3.5 w-3.5" }),
4915
- "Capacidades"
4916
- ] }),
4917
- /* @__PURE__ */ jsxs20(TabsTrigger, { value: "integracoes", className: "flex items-center gap-1.5", children: [
4918
- /* @__PURE__ */ jsx22(Plug3, { "aria-hidden": "true", className: "h-3.5 w-3.5" }),
4919
- "Integra\xE7\xF5es"
4920
- ] }),
4921
- /* @__PURE__ */ jsxs20(TabsTrigger, { value: "avancado", className: "flex items-center gap-1.5", children: [
4922
- /* @__PURE__ */ jsx22(Settings3, { "aria-hidden": "true", className: "h-3.5 w-3.5" }),
4923
- "Avan\xE7ado"
4924
- ] })
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" })
4925
4586
  ] }),
4926
- /* @__PURE__ */ jsx22(TabsContent, { value: "capacidades", className: "mt-4", children: /* @__PURE__ */ jsx22(CapabilitiesTab, { config, agentId }) }),
4927
- /* @__PURE__ */ jsx22(TabsContent, { value: "integracoes", className: "mt-4", children: /* @__PURE__ */ jsx22(
4928
- IntegrationsTab,
4929
- {
4930
- config,
4931
- agentId,
4932
- onConnect: handleConnect
4933
- }
4934
- ) }),
4935
- /* @__PURE__ */ jsx22(TabsContent, { value: "avancado", className: "mt-4", children: /* @__PURE__ */ jsx22(
4936
- AdvancedTab,
4937
- {
4938
- config,
4939
- agentId,
4940
- gagentsApiUrl
4941
- }
4942
- ) })
4943
- ] }),
4944
- activeCard && wizardMeta && /* @__PURE__ */ jsx22(
4945
- IntegrationWizard,
4946
- {
4947
- open: wizardOpen,
4948
- onOpenChange: handleWizardOpenChange,
4949
- integration: activeCard.definition,
4950
- meta: wizardMeta,
4951
- agentId,
4952
- config,
4953
- onComplete: handleWizardComplete,
4954
- gagentsApiUrl,
4955
- existingCredentialId: activeCard.credential?.id,
4956
- loadConfigOptions
4957
- }
4958
- )
4959
- ] });
4960
- }
4961
-
4962
- // src/components/agents/agent-tabs.tsx
4963
- import {
4964
- Tabs as Tabs2,
4965
- TabsList as TabsList2,
4966
- TabsTrigger as TabsTrigger2,
4967
- TabsContent as TabsContent2
4968
- } from "@greatapps/greatauth-ui/ui";
4969
- import { Target as Target2, FileText as FileText2, MessageCircle as MessageCircle2, Blocks as Blocks2 } from "lucide-react";
4970
- import { jsx as jsx23, jsxs as jsxs21 } from "react/jsx-runtime";
4971
- function AgentTabs({
4972
- agent,
4973
- config,
4974
- renderChatLink,
4975
- gagentsApiUrl,
4976
- resolveWizardMeta,
4977
- loadConfigOptions,
4978
- onWizardComplete
4979
- }) {
4980
- const apiUrl = gagentsApiUrl || config.baseUrl;
4981
- return /* @__PURE__ */ jsxs21(Tabs2, { defaultValue: "prompt", children: [
4982
- /* @__PURE__ */ jsxs21(TabsList2, { children: [
4983
- /* @__PURE__ */ jsxs21(TabsTrigger2, { value: "prompt", className: "flex items-center gap-1.5", children: [
4984
- /* @__PURE__ */ jsx23(FileText2, { "aria-hidden": "true", className: "h-3.5 w-3.5" }),
4985
- "Prompt"
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" })
4986
4609
  ] }),
4987
- /* @__PURE__ */ jsxs21(TabsTrigger2, { value: "objetivos", className: "flex items-center gap-1.5", children: [
4988
- /* @__PURE__ */ jsx23(Target2, { "aria-hidden": "true", className: "h-3.5 w-3.5" }),
4989
- "Objetivos"
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
+ )
4990
4624
  ] }),
4991
- /* @__PURE__ */ jsxs21(TabsTrigger2, { value: "capacidades", className: "flex items-center gap-1.5", children: [
4992
- /* @__PURE__ */ jsx23(Blocks2, { "aria-hidden": "true", className: "h-3.5 w-3.5" }),
4993
- "Capacidades"
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" })
4994
4661
  ] }),
4995
- /* @__PURE__ */ jsxs21(TabsTrigger2, { value: "conversas", className: "flex items-center gap-1.5", children: [
4996
- /* @__PURE__ */ jsx23(MessageCircle2, { "aria-hidden": "true", className: "h-3.5 w-3.5" }),
4997
- "Conversas"
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"
4676
+ ] })
4998
4677
  ] })
4999
- ] }),
5000
- /* @__PURE__ */ jsx23(TabsContent2, { value: "prompt", className: "mt-4", children: /* @__PURE__ */ jsx23(AgentPromptEditor, { agent, config }) }),
5001
- /* @__PURE__ */ jsx23(TabsContent2, { value: "objetivos", className: "mt-4", children: /* @__PURE__ */ jsx23(AgentObjectivesList, { agent, config }) }),
5002
- /* @__PURE__ */ jsx23(TabsContent2, { value: "capacidades", className: "mt-4", children: /* @__PURE__ */ jsx23(
5003
- AgentCapabilitiesPage,
5004
- {
5005
- config,
5006
- agentId: agent.id,
5007
- gagentsApiUrl: apiUrl,
5008
- resolveWizardMeta,
5009
- loadConfigOptions,
5010
- onWizardComplete
5011
- }
5012
- ) }),
5013
- /* @__PURE__ */ jsx23(TabsContent2, { value: "conversas", className: "mt-4", children: /* @__PURE__ */ jsx23(
5014
- AgentConversationsPanel,
5015
- {
5016
- agent,
5017
- config,
5018
- renderChatLink
5019
- }
5020
- ) })
5021
- ] });
4678
+ ] })
4679
+ ] }) });
5022
4680
  }
5023
4681
 
5024
- // src/components/agents/agent-tools-list.tsx
5025
- import { useState as useState15 } from "react";
4682
+ // src/components/tools/tool-credentials-form.tsx
4683
+ import { useMemo as useMemo7, useState as useState14 } from "react";
4684
+ import { DataTable as DataTable3 } from "@greatapps/greatauth-ui";
5026
4685
  import {
5027
- Switch as Switch5,
5028
- Badge as Badge9,
4686
+ Input as Input10,
5029
4687
  Button as Button14,
5030
- Skeleton as Skeleton6,
4688
+ Badge as Badge9,
4689
+ Tooltip as Tooltip4,
4690
+ TooltipTrigger as TooltipTrigger4,
4691
+ TooltipContent as TooltipContent4,
4692
+ Dialog as Dialog7,
4693
+ DialogContent as DialogContent7,
4694
+ DialogHeader as DialogHeader7,
4695
+ DialogTitle as DialogTitle7,
4696
+ DialogFooter as DialogFooter7,
5031
4697
  AlertDialog as AlertDialog5,
5032
4698
  AlertDialogAction as AlertDialogAction5,
5033
4699
  AlertDialogCancel as AlertDialogCancel5,
@@ -5036,285 +4702,461 @@ import {
5036
4702
  AlertDialogFooter as AlertDialogFooter5,
5037
4703
  AlertDialogHeader as AlertDialogHeader5,
5038
4704
  AlertDialogTitle as AlertDialogTitle5,
5039
- Popover,
5040
- PopoverContent,
5041
- PopoverTrigger,
5042
- Input as Input10,
5043
- Textarea as Textarea3,
5044
- Dialog as Dialog7,
5045
- DialogContent as DialogContent7,
5046
- DialogHeader as DialogHeader7,
5047
- DialogTitle as DialogTitle7,
5048
- DialogFooter as DialogFooter7,
5049
- Label as Label8,
5050
4705
  Select as Select4,
5051
4706
  SelectContent as SelectContent4,
5052
4707
  SelectItem as SelectItem4,
5053
4708
  SelectTrigger as SelectTrigger4,
5054
4709
  SelectValue as SelectValue4
5055
4710
  } from "@greatapps/greatauth-ui/ui";
5056
- import {
5057
- Trash2 as Trash25,
5058
- Plus as Plus3,
5059
- Wrench,
5060
- Settings2 as Settings22
5061
- } from "lucide-react";
4711
+ import { Trash2 as Trash25, Pencil as Pencil4, Link, Search as Search3 } from "lucide-react";
4712
+ import { format as format3 } from "date-fns";
4713
+ import { ptBR as ptBR3 } from "date-fns/locale";
5062
4714
  import { toast as toast11 } from "sonner";
5063
- import { jsx as jsx24, jsxs as jsxs22 } from "react/jsx-runtime";
5064
- function AgentToolsList({ agent, config }) {
5065
- const { data: agentToolsData, isLoading } = useAgentTools(config, agent.id);
5066
- const { data: allToolsData } = useTools(config);
5067
- const addMutation = useAddAgentTool(config);
5068
- const removeMutation = useRemoveAgentTool(config);
5069
- const updateMutation = useUpdateAgentTool(config);
5070
- const [removeTarget, setRemoveTarget] = useState15(null);
5071
- const [addOpen, setAddOpen] = useState15(false);
5072
- const [search, setSearch] = useState15("");
5073
- const [configTarget, setConfigTarget] = useState15(null);
5074
- const [configInstructions, setConfigInstructions] = useState15("");
5075
- const [configCredentialId, setConfigCredentialId] = useState15("");
5076
- const { data: credentialsData } = useToolCredentials(config);
5077
- const allCredentials = credentialsData?.data || [];
5078
- const agentTools = agentToolsData?.data || [];
5079
- const allTools = (allToolsData?.data || []).filter((t) => !t.slug?.startsWith("gclinic_"));
5080
- const assignedToolIds = new Set(agentTools.map((at) => at.id_tool));
5081
- const visibleAgentTools = agentTools.filter((at) => {
5082
- const tool = allTools.find((t) => t.id === at.id_tool);
5083
- return !tool || !tool.slug?.startsWith("gclinic_");
4715
+ import { jsx as jsx22, jsxs as jsxs20 } from "react/jsx-runtime";
4716
+ function formatDate2(dateStr) {
4717
+ if (!dateStr) return "Sem expira\xE7\xE3o";
4718
+ return format3(new Date(dateStr), "dd/MM/yyyy", { locale: ptBR3 });
4719
+ }
4720
+ function useColumns3(tools, onEdit, onConnect, onRemove) {
4721
+ function getToolName(idTool) {
4722
+ if (!idTool) return "\u2014";
4723
+ const tool = tools.find((t) => t.id === idTool);
4724
+ return tool?.name || `Ferramenta #${idTool}`;
4725
+ }
4726
+ function getToolType(idTool) {
4727
+ if (!idTool) return null;
4728
+ const tool = tools.find((t) => t.id === idTool);
4729
+ return tool?.type || null;
4730
+ }
4731
+ return [
4732
+ {
4733
+ accessorKey: "label",
4734
+ header: "Label",
4735
+ cell: ({ row }) => /* @__PURE__ */ jsx22("span", { className: "font-medium", children: row.original.label || "\u2014" })
4736
+ },
4737
+ {
4738
+ accessorKey: "id_tool",
4739
+ header: "Ferramenta",
4740
+ cell: ({ row }) => /* @__PURE__ */ jsx22("span", { className: "text-sm", children: getToolName(row.original.id_tool) })
4741
+ },
4742
+ {
4743
+ accessorKey: "status",
4744
+ header: "Status",
4745
+ cell: ({ row }) => /* @__PURE__ */ jsx22(
4746
+ Badge9,
4747
+ {
4748
+ variant: row.original.status === "active" ? "default" : "destructive",
4749
+ children: row.original.status === "active" ? "Ativo" : "Expirado"
4750
+ }
4751
+ )
4752
+ },
4753
+ {
4754
+ accessorKey: "expires_at",
4755
+ header: "Expira em",
4756
+ cell: ({ row }) => /* @__PURE__ */ jsx22("span", { className: "text-muted-foreground text-sm", children: formatDate2(row.original.expires_at) })
4757
+ },
4758
+ {
4759
+ accessorKey: "datetime_add",
4760
+ header: "Criado em",
4761
+ cell: ({ row }) => /* @__PURE__ */ jsx22("span", { className: "text-muted-foreground text-sm", children: formatDate2(row.original.datetime_add) })
4762
+ },
4763
+ {
4764
+ id: "actions",
4765
+ header: "A\xE7\xF5es",
4766
+ size: 100,
4767
+ enableSorting: false,
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(
4771
+ Button14,
4772
+ {
4773
+ variant: "ghost",
4774
+ size: "icon",
4775
+ className: "h-8 w-8",
4776
+ "aria-label": "Vincular",
4777
+ disabled: true,
4778
+ children: /* @__PURE__ */ jsx22(Link, { className: "h-4 w-4" })
4779
+ }
4780
+ ) }),
4781
+ /* @__PURE__ */ jsx22(TooltipContent4, { children: "Em breve" })
4782
+ ] }),
4783
+ /* @__PURE__ */ jsxs20(Tooltip4, { children: [
4784
+ /* @__PURE__ */ jsx22(TooltipTrigger4, { asChild: true, children: /* @__PURE__ */ jsx22(
4785
+ Button14,
4786
+ {
4787
+ variant: "ghost",
4788
+ size: "icon",
4789
+ className: "h-8 w-8",
4790
+ "aria-label": "Editar",
4791
+ onClick: () => onEdit(row.original),
4792
+ children: /* @__PURE__ */ jsx22(Pencil4, { className: "h-4 w-4" })
4793
+ }
4794
+ ) }),
4795
+ /* @__PURE__ */ jsx22(TooltipContent4, { children: "Editar" })
4796
+ ] }),
4797
+ /* @__PURE__ */ jsxs20(Tooltip4, { children: [
4798
+ /* @__PURE__ */ jsx22(TooltipTrigger4, { asChild: true, children: /* @__PURE__ */ jsx22(
4799
+ Button14,
4800
+ {
4801
+ variant: "ghost",
4802
+ size: "icon",
4803
+ className: "h-8 w-8 text-destructive hover:text-destructive",
4804
+ "aria-label": "Excluir",
4805
+ onClick: () => onRemove(row.original),
4806
+ children: /* @__PURE__ */ jsx22(Trash25, { className: "h-4 w-4" })
4807
+ }
4808
+ ) }),
4809
+ /* @__PURE__ */ jsx22(TooltipContent4, { children: "Remover" })
4810
+ ] })
4811
+ ] })
4812
+ }
4813
+ ];
4814
+ }
4815
+ function ToolCredentialsForm({
4816
+ credentials,
4817
+ isLoading,
4818
+ config,
4819
+ gagentsApiUrl,
4820
+ createOpen: externalCreateOpen,
4821
+ onCreateOpenChange
4822
+ }) {
4823
+ const createMutation = useCreateToolCredential(config);
4824
+ const updateMutation = useUpdateToolCredential(config);
4825
+ const deleteMutation = useDeleteToolCredential(config);
4826
+ const { data: toolsData } = useTools(config);
4827
+ const tools = (toolsData?.data || []).filter((t) => !t.slug?.startsWith("gclinic_"));
4828
+ const [search, setSearch] = useState14("");
4829
+ const [internalCreateOpen, setInternalCreateOpen] = useState14(false);
4830
+ const showCreateDialog = externalCreateOpen ?? internalCreateOpen;
4831
+ const setShowCreateDialog = onCreateOpenChange ?? setInternalCreateOpen;
4832
+ const [createForm, setCreateForm] = useState14({
4833
+ id_tool: "",
4834
+ label: "",
4835
+ credentials_encrypted: "",
4836
+ expires_at: ""
5084
4837
  });
5085
- const availableTools = allTools.filter((t) => !assignedToolIds.has(t.id));
5086
- const filteredAvailable = availableTools.filter(
5087
- (t) => t.name.toLowerCase().includes(search.toLowerCase())
4838
+ const [editTarget, setEditTarget] = useState14(null);
4839
+ const [editForm, setEditForm] = useState14({
4840
+ id_tool: "",
4841
+ label: "",
4842
+ credentials_encrypted: "",
4843
+ expires_at: "",
4844
+ status: ""
4845
+ });
4846
+ const [removeTarget, setRemoveTarget] = useState14(null);
4847
+ const internalToolIds = useMemo7(() => {
4848
+ const allRawTools = toolsData?.data || [];
4849
+ return new Set(
4850
+ allRawTools.filter((t) => t.slug?.startsWith("gclinic_")).map((t) => t.id)
4851
+ );
4852
+ }, [toolsData]);
4853
+ const filteredCredentials = useMemo7(() => {
4854
+ const visible = credentials.filter(
4855
+ (cred) => !cred.id_tool || !internalToolIds.has(cred.id_tool)
4856
+ );
4857
+ if (!search) return visible;
4858
+ const term = search.toLowerCase();
4859
+ return visible.filter((cred) => {
4860
+ const toolName = tools.find((t) => t.id === cred.id_tool)?.name || "";
4861
+ return (cred.label || "").toLowerCase().includes(term) || toolName.toLowerCase().includes(term);
4862
+ });
4863
+ }, [credentials, search, tools, internalToolIds]);
4864
+ const columns = useColumns3(
4865
+ tools,
4866
+ (cred) => startEdit(cred),
4867
+ (cred) => handleConnect(cred),
4868
+ (cred) => setRemoveTarget(cred)
5088
4869
  );
5089
- function getToolInfo(idTool) {
5090
- return allTools.find((t) => t.id === idTool);
5091
- }
5092
- async function handleToggleEnabled(agentTool, checked) {
4870
+ async function handleCreate() {
4871
+ const idTool = parseInt(createForm.id_tool, 10);
4872
+ if (!idTool || !createForm.label.trim() || !createForm.credentials_encrypted.trim()) return;
5093
4873
  try {
5094
- await updateMutation.mutateAsync({
5095
- idAgent: agent.id,
5096
- id: agentTool.id,
5097
- body: { enabled: checked }
4874
+ const result = await createMutation.mutateAsync({
4875
+ id_tool: idTool,
4876
+ label: createForm.label.trim(),
4877
+ credentials_encrypted: createForm.credentials_encrypted.trim(),
4878
+ ...createForm.expires_at ? { expires_at: createForm.expires_at } : {}
5098
4879
  });
5099
- toast11.success(checked ? "Ferramenta ativada" : "Ferramenta desativada");
5100
- } catch (err) {
5101
- toast11.error(
5102
- err instanceof Error ? err.message : "Erro ao alterar estado da ferramenta"
5103
- );
4880
+ if (result.status === 1) {
4881
+ toast11.success("Credencial criada");
4882
+ setShowCreateDialog(false);
4883
+ setCreateForm({ id_tool: "", label: "", credentials_encrypted: "", expires_at: "" });
4884
+ } else {
4885
+ toast11.error(result.message || "Erro ao criar credencial");
4886
+ }
4887
+ } catch {
4888
+ toast11.error("Erro ao criar credencial");
5104
4889
  }
5105
4890
  }
5106
- async function handleAdd(tool) {
4891
+ function startEdit(cred) {
4892
+ setEditTarget(cred);
4893
+ setEditForm({
4894
+ id_tool: cred.id_tool ? String(cred.id_tool) : "",
4895
+ label: cred.label || "",
4896
+ credentials_encrypted: "",
4897
+ expires_at: cred.expires_at || "",
4898
+ status: cred.status
4899
+ });
4900
+ }
4901
+ async function handleSaveEdit() {
4902
+ if (!editTarget) return;
4903
+ const body = {};
4904
+ const newIdTool = editForm.id_tool ? parseInt(editForm.id_tool, 10) : null;
4905
+ if (newIdTool && newIdTool !== editTarget.id_tool) {
4906
+ body.id_tool = newIdTool;
4907
+ }
4908
+ if (editForm.label.trim() && editForm.label.trim() !== (editTarget.label || "")) {
4909
+ body.label = editForm.label.trim();
4910
+ }
4911
+ if (editForm.credentials_encrypted.trim()) {
4912
+ body.credentials_encrypted = editForm.credentials_encrypted.trim();
4913
+ }
4914
+ if (editForm.expires_at !== (editTarget.expires_at || "")) {
4915
+ body.expires_at = editForm.expires_at || null;
4916
+ }
4917
+ if (editForm.status && editForm.status !== editTarget.status) {
4918
+ body.status = editForm.status;
4919
+ }
4920
+ if (Object.keys(body).length === 0) {
4921
+ setEditTarget(null);
4922
+ return;
4923
+ }
5107
4924
  try {
5108
- await addMutation.mutateAsync({
5109
- idAgent: agent.id,
5110
- body: { id_tool: tool.id }
4925
+ const result = await updateMutation.mutateAsync({
4926
+ id: editTarget.id,
4927
+ body
5111
4928
  });
5112
- toast11.success("Ferramenta adicionada");
5113
- setAddOpen(false);
5114
- setSearch("");
5115
- } catch (err) {
5116
- toast11.error(
5117
- err instanceof Error ? err.message : "Erro ao adicionar ferramenta"
5118
- );
4929
+ if (result.status === 1) {
4930
+ toast11.success("Credencial atualizada");
4931
+ setEditTarget(null);
4932
+ } else {
4933
+ toast11.error(result.message || "Erro ao atualizar credencial");
4934
+ }
4935
+ } catch {
4936
+ toast11.error("Erro ao atualizar credencial");
5119
4937
  }
5120
4938
  }
5121
4939
  async function handleRemove() {
5122
4940
  if (!removeTarget) return;
5123
4941
  try {
5124
- await removeMutation.mutateAsync({
5125
- idAgent: agent.id,
5126
- id: removeTarget.id
5127
- });
5128
- toast11.success("Ferramenta removida");
5129
- } catch (err) {
5130
- toast11.error(
5131
- err instanceof Error ? err.message : "Erro ao remover ferramenta"
5132
- );
4942
+ const result = await deleteMutation.mutateAsync(removeTarget.id);
4943
+ if (result.status === 1) {
4944
+ toast11.success("Credencial removida");
4945
+ } else {
4946
+ toast11.error(result.message || "Erro ao remover credencial");
4947
+ }
4948
+ } catch {
4949
+ toast11.error("Erro ao remover credencial");
5133
4950
  } finally {
5134
4951
  setRemoveTarget(null);
5135
4952
  }
5136
4953
  }
5137
- function openConfig(agentTool) {
5138
- setConfigTarget(agentTool);
5139
- setConfigInstructions(agentTool.custom_instructions || "");
5140
- setConfigCredentialId(agentTool.id_tool_credential ? String(agentTool.id_tool_credential) : "");
4954
+ function handleConnect(cred) {
4955
+ if (!config.accountId || !config.token) return;
4956
+ const language = config.language ?? "pt-br";
4957
+ const idWl = config.idWl ?? 1;
4958
+ const url = `${gagentsApiUrl}/v1/${language}/${idWl}/accounts/${config.accountId}/oauth/connect?id_tool=${cred.id_tool}`;
4959
+ window.open(url, "_blank");
5141
4960
  }
5142
- async function handleSaveConfig() {
5143
- if (!configTarget) return;
5144
- try {
5145
- const newCredentialId = configCredentialId ? parseInt(configCredentialId, 10) : null;
5146
- await updateMutation.mutateAsync({
5147
- idAgent: agent.id,
5148
- id: configTarget.id,
5149
- body: {
5150
- custom_instructions: configInstructions.trim() || null,
5151
- id_tool_credential: newCredentialId
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(
4965
+ Input10,
4966
+ {
4967
+ placeholder: "Buscar credenciais\\u2026",
4968
+ "aria-label": "Buscar credenciais",
4969
+ name: "search",
4970
+ autoComplete: "off",
4971
+ value: search,
4972
+ onChange: (e) => setSearch(e.target.value),
4973
+ className: "pl-9"
5152
4974
  }
5153
- });
5154
- toast11.success("Configura\xE7\xE3o atualizada");
5155
- setConfigTarget(null);
5156
- } catch (err) {
5157
- toast11.error(
5158
- err instanceof Error ? err.message : "Erro ao atualizar configura\xE7\xE3o"
5159
- );
5160
- }
5161
- }
5162
- if (isLoading) {
5163
- return /* @__PURE__ */ jsx24("div", { className: "space-y-3 p-4", children: Array.from({ length: 3 }).map((_, i) => /* @__PURE__ */ jsx24(Skeleton6, { className: "h-14 w-full" }, i)) });
5164
- }
5165
- return /* @__PURE__ */ jsxs22("div", { className: "space-y-4 p-4", children: [
5166
- /* @__PURE__ */ jsxs22("div", { className: "flex items-center justify-between", children: [
5167
- /* @__PURE__ */ jsxs22("h3", { className: "text-sm font-medium text-muted-foreground", children: [
5168
- visibleAgentTools.length,
5169
- " ferramenta",
5170
- visibleAgentTools.length !== 1 ? "s" : "",
5171
- " associada",
5172
- visibleAgentTools.length !== 1 ? "s" : ""
5173
- ] }),
5174
- /* @__PURE__ */ jsxs22(Popover, { open: addOpen, onOpenChange: setAddOpen, children: [
5175
- /* @__PURE__ */ jsx24(PopoverTrigger, { asChild: true, children: /* @__PURE__ */ jsxs22(Button14, { size: "sm", disabled: availableTools.length === 0, children: [
5176
- /* @__PURE__ */ jsx24(Plus3, { className: "mr-2 h-4 w-4" }),
5177
- "Adicionar Ferramenta"
5178
- ] }) }),
5179
- /* @__PURE__ */ jsxs22(PopoverContent, { className: "w-72 p-0", align: "end", children: [
5180
- /* @__PURE__ */ jsx24("div", { className: "p-2", children: /* @__PURE__ */ jsx24(
4975
+ )
4976
+ ] }) }),
4977
+ /* @__PURE__ */ jsx22(
4978
+ DataTable3,
4979
+ {
4980
+ columns,
4981
+ data: filteredCredentials,
4982
+ isLoading,
4983
+ emptyMessage: "Nenhuma credencial encontrada"
4984
+ }
4985
+ ),
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(
4992
+ Select4,
4993
+ {
4994
+ value: createForm.id_tool,
4995
+ onValueChange: (val) => setCreateForm((f) => ({ ...f, id_tool: val })),
4996
+ children: [
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)) })
4999
+ ]
5000
+ }
5001
+ )
5002
+ ] }),
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(
5181
5006
  Input10,
5182
5007
  {
5183
- placeholder: "Buscar ferramenta\\u2026",
5184
- "aria-label": "Buscar ferramenta",
5185
- name: "search",
5186
- value: search,
5187
- onChange: (e) => setSearch(e.target.value),
5188
- className: "h-8"
5008
+ id: "cred-label",
5009
+ name: "label",
5010
+ value: createForm.label,
5011
+ onChange: (e) => setCreateForm((f) => ({ ...f, label: e.target.value })),
5012
+ placeholder: "Ex: Google Calendar - Cl\xEDnica S\xE3o Paulo"
5189
5013
  }
5190
- ) }),
5191
- /* @__PURE__ */ jsx24("div", { className: "max-h-48 overflow-y-auto", children: filteredAvailable.length === 0 ? /* @__PURE__ */ jsx24("p", { className: "p-3 text-center text-sm text-muted-foreground", children: "Nenhuma ferramenta dispon\xEDvel" }) : filteredAvailable.map((tool) => /* @__PURE__ */ jsxs22(
5192
- "button",
5014
+ )
5015
+ ] }),
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(
5019
+ Input10,
5193
5020
  {
5194
- type: "button",
5195
- className: "flex w-full items-center gap-2 px-3 py-2 text-left text-sm hover:bg-accent",
5196
- onClick: () => handleAdd(tool),
5197
- disabled: addMutation.isPending,
5198
- children: [
5199
- /* @__PURE__ */ jsx24(Wrench, { className: "h-4 w-4 text-muted-foreground" }),
5200
- /* @__PURE__ */ jsx24("span", { className: "flex-1 font-medium", children: tool.name }),
5201
- /* @__PURE__ */ jsx24(Badge9, { variant: "secondary", className: "text-xs", children: tool.type })
5202
- ]
5203
- },
5204
- tool.id
5205
- )) })
5021
+ id: "cred-credential",
5022
+ name: "credential",
5023
+ autoComplete: "off",
5024
+ type: "password",
5025
+ value: createForm.credentials_encrypted,
5026
+ onChange: (e) => setCreateForm((f) => ({
5027
+ ...f,
5028
+ credentials_encrypted: e.target.value
5029
+ })),
5030
+ placeholder: "Credencial encriptada"
5031
+ }
5032
+ )
5033
+ ] }),
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(
5037
+ Input10,
5038
+ {
5039
+ id: "cred-expires",
5040
+ name: "expires",
5041
+ type: "date",
5042
+ value: createForm.expires_at,
5043
+ onChange: (e) => setCreateForm((f) => ({ ...f, expires_at: e.target.value }))
5044
+ }
5045
+ )
5206
5046
  ] })
5047
+ ] }),
5048
+ /* @__PURE__ */ jsxs20(DialogFooter7, { children: [
5049
+ /* @__PURE__ */ jsx22(
5050
+ Button14,
5051
+ {
5052
+ variant: "outline",
5053
+ onClick: () => setShowCreateDialog(false),
5054
+ children: "Cancelar"
5055
+ }
5056
+ ),
5057
+ /* @__PURE__ */ jsx22(
5058
+ Button14,
5059
+ {
5060
+ onClick: handleCreate,
5061
+ disabled: !createForm.id_tool || !createForm.label.trim() || !createForm.credentials_encrypted.trim() || createMutation.isPending,
5062
+ children: "Criar"
5063
+ }
5064
+ )
5207
5065
  ] })
5208
- ] }),
5209
- visibleAgentTools.length === 0 ? /* @__PURE__ */ jsxs22("div", { className: "flex flex-col items-center justify-center rounded-lg border border-dashed p-8 text-center", children: [
5210
- /* @__PURE__ */ jsx24(Wrench, { className: "mb-2 h-8 w-8 text-muted-foreground" }),
5211
- /* @__PURE__ */ jsx24("p", { className: "text-sm text-muted-foreground", children: "Nenhuma ferramenta associada. Clique em 'Adicionar Ferramenta' para come\xE7ar." })
5212
- ] }) : /* @__PURE__ */ jsx24("div", { className: "space-y-2", children: visibleAgentTools.map((agentTool) => {
5213
- const tool = getToolInfo(agentTool.id_tool);
5214
- return /* @__PURE__ */ jsxs22(
5215
- "div",
5216
- {
5217
- className: "flex items-center gap-3 rounded-lg border bg-card p-3",
5218
- children: [
5219
- /* @__PURE__ */ jsxs22("div", { className: "flex flex-1 flex-col gap-1 min-w-0", children: [
5220
- /* @__PURE__ */ jsxs22("div", { className: "flex items-center gap-2", children: [
5221
- /* @__PURE__ */ jsx24("span", { className: "truncate font-medium", children: tool?.name || `Ferramenta #${agentTool.id_tool}` }),
5222
- tool?.type && /* @__PURE__ */ jsx24(Badge9, { variant: "secondary", className: "shrink-0 text-xs", children: tool.type })
5223
- ] }),
5224
- agentTool.custom_instructions && /* @__PURE__ */ jsx24("p", { className: "truncate text-xs text-muted-foreground", children: agentTool.custom_instructions })
5225
- ] }),
5226
- /* @__PURE__ */ jsx24(
5227
- Switch5,
5228
- {
5229
- "aria-label": "Ativar/Desativar",
5230
- checked: agentTool.enabled,
5231
- onCheckedChange: (checked) => handleToggleEnabled(agentTool, checked),
5232
- disabled: updateMutation.isPending
5233
- }
5234
- ),
5235
- /* @__PURE__ */ jsx24(
5236
- Button14,
5237
- {
5238
- variant: "ghost",
5239
- size: "icon",
5240
- "aria-label": "Configurar",
5241
- className: "shrink-0 text-muted-foreground hover:text-foreground",
5242
- onClick: () => openConfig(agentTool),
5243
- title: "Configurar instru\xE7\xF5es",
5244
- children: /* @__PURE__ */ jsx24(Settings22, { className: "h-4 w-4" })
5245
- }
5246
- ),
5247
- /* @__PURE__ */ jsx24(
5248
- Button14,
5249
- {
5250
- variant: "ghost",
5251
- size: "icon",
5252
- "aria-label": "Remover",
5253
- className: "shrink-0 text-muted-foreground hover:text-destructive",
5254
- onClick: () => setRemoveTarget(agentTool),
5255
- children: /* @__PURE__ */ jsx24(Trash25, { className: "h-4 w-4" })
5256
- }
5257
- )
5258
- ]
5259
- },
5260
- agentTool.id
5261
- );
5262
- }) }),
5263
- /* @__PURE__ */ jsx24(
5066
+ ] }) }),
5067
+ /* @__PURE__ */ jsx22(
5264
5068
  Dialog7,
5265
5069
  {
5266
- open: !!configTarget,
5267
- onOpenChange: (open) => !open && setConfigTarget(null),
5268
- children: /* @__PURE__ */ jsxs22(DialogContent7, { className: "sm:max-w-lg", children: [
5269
- /* @__PURE__ */ jsx24(DialogHeader7, { children: /* @__PURE__ */ jsx24(DialogTitle7, { children: "Instru\xE7\xF5es da Ferramenta" }) }),
5270
- /* @__PURE__ */ jsxs22("div", { className: "space-y-4", children: [
5271
- configTarget && getToolInfo(configTarget.id_tool)?.type !== "none" && /* @__PURE__ */ jsxs22("div", { className: "space-y-2", children: [
5272
- /* @__PURE__ */ jsx24(Label8, { htmlFor: "tool-credential", children: "Credencial" }),
5273
- /* @__PURE__ */ jsxs22(
5070
+ open: !!editTarget,
5071
+ onOpenChange: (open) => !open && setEditTarget(null),
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(
5274
5078
  Select4,
5275
5079
  {
5276
- value: configCredentialId || void 0,
5277
- onValueChange: (val) => setConfigCredentialId(val === "__none__" ? "" : val),
5080
+ value: editForm.id_tool,
5081
+ onValueChange: (val) => setEditForm((f) => ({ ...f, id_tool: val })),
5278
5082
  children: [
5279
- /* @__PURE__ */ jsx24(SelectTrigger4, { id: "tool-credential", children: /* @__PURE__ */ jsx24(SelectValue4, { placeholder: "Selecione uma credencial (opcional)" }) }),
5280
- /* @__PURE__ */ jsxs22(SelectContent4, { children: [
5281
- /* @__PURE__ */ jsx24(SelectItem4, { value: "__none__", children: "Nenhuma (autom\xE1tico)" }),
5282
- allCredentials.filter((c) => configTarget && c.id_tool === configTarget.id_tool && c.status === "active").map((c) => /* @__PURE__ */ jsx24(SelectItem4, { value: String(c.id), children: c.label || `Credencial #${c.id}` }, c.id))
5283
- ] })
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)) })
5284
5085
  ]
5285
5086
  }
5286
- ),
5287
- /* @__PURE__ */ jsx24("p", { className: "text-xs text-muted-foreground", children: "Vincule uma credencial espec\xEDfica a esta ferramenta neste agente." })
5087
+ )
5288
5088
  ] }),
5289
- /* @__PURE__ */ jsxs22("div", { className: "space-y-2", children: [
5290
- /* @__PURE__ */ jsx24(Label8, { htmlFor: "tool-instructions", children: "Instru\xE7\xF5es Personalizadas" }),
5291
- /* @__PURE__ */ jsx24(
5292
- Textarea3,
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(
5092
+ Input10,
5293
5093
  {
5294
- id: "tool-instructions",
5295
- name: "instructions",
5296
- value: configInstructions,
5297
- onChange: (e) => setConfigInstructions(e.target.value),
5298
- placeholder: "Instru\\u00e7\\u00f5es sobre como e quando o agente deve usar esta ferramenta\\u2026",
5299
- rows: 6
5094
+ id: "edit-cred-label",
5095
+ name: "label",
5096
+ value: editForm.label,
5097
+ onChange: (e) => setEditForm((f) => ({ ...f, label: e.target.value })),
5098
+ placeholder: "Label da credencial"
5300
5099
  }
5301
- ),
5302
- /* @__PURE__ */ jsx24("p", { className: "text-xs text-muted-foreground", children: "Este texto \xE9 adicionado ao prompt do agente para orientar o uso da ferramenta." })
5100
+ )
5101
+ ] }),
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(
5105
+ Input10,
5106
+ {
5107
+ id: "edit-cred-credential",
5108
+ name: "credential",
5109
+ autoComplete: "off",
5110
+ type: "password",
5111
+ value: editForm.credentials_encrypted,
5112
+ onChange: (e) => setEditForm((f) => ({
5113
+ ...f,
5114
+ credentials_encrypted: e.target.value
5115
+ })),
5116
+ placeholder: "Nova credencial"
5117
+ }
5118
+ )
5119
+ ] }),
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(
5123
+ Input10,
5124
+ {
5125
+ id: "edit-cred-expires",
5126
+ name: "expires",
5127
+ type: "date",
5128
+ value: editForm.expires_at,
5129
+ onChange: (e) => setEditForm((f) => ({ ...f, expires_at: e.target.value }))
5130
+ }
5131
+ )
5132
+ ] }),
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(
5136
+ Select4,
5137
+ {
5138
+ value: editForm.status || void 0,
5139
+ onValueChange: (val) => setEditForm((f) => ({
5140
+ ...f,
5141
+ status: val
5142
+ })),
5143
+ children: [
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" })
5148
+ ] })
5149
+ ]
5150
+ }
5151
+ )
5303
5152
  ] })
5304
5153
  ] }),
5305
- /* @__PURE__ */ jsxs22(DialogFooter7, { children: [
5306
- /* @__PURE__ */ jsx24(
5307
- Button14,
5308
- {
5309
- variant: "outline",
5310
- onClick: () => setConfigTarget(null),
5311
- children: "Cancelar"
5312
- }
5313
- ),
5314
- /* @__PURE__ */ jsx24(
5154
+ /* @__PURE__ */ jsxs20(DialogFooter7, { children: [
5155
+ /* @__PURE__ */ jsx22(Button14, { variant: "outline", onClick: () => setEditTarget(null), children: "Cancelar" }),
5156
+ /* @__PURE__ */ jsx22(
5315
5157
  Button14,
5316
5158
  {
5317
- onClick: handleSaveConfig,
5159
+ onClick: handleSaveEdit,
5318
5160
  disabled: updateMutation.isPending,
5319
5161
  children: "Salvar"
5320
5162
  }
@@ -5323,23 +5165,23 @@ function AgentToolsList({ agent, config }) {
5323
5165
  ] })
5324
5166
  }
5325
5167
  ),
5326
- /* @__PURE__ */ jsx24(
5168
+ /* @__PURE__ */ jsx22(
5327
5169
  AlertDialog5,
5328
5170
  {
5329
5171
  open: !!removeTarget,
5330
5172
  onOpenChange: (open) => !open && setRemoveTarget(null),
5331
- children: /* @__PURE__ */ jsxs22(AlertDialogContent5, { children: [
5332
- /* @__PURE__ */ jsxs22(AlertDialogHeader5, { children: [
5333
- /* @__PURE__ */ jsx24(AlertDialogTitle5, { children: "Remover ferramenta?" }),
5334
- /* @__PURE__ */ jsx24(AlertDialogDescription5, { children: "A ferramenta ser\xE1 desassociada deste agente." })
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." })
5335
5177
  ] }),
5336
- /* @__PURE__ */ jsxs22(AlertDialogFooter5, { children: [
5337
- /* @__PURE__ */ jsx24(AlertDialogCancel5, { children: "Cancelar" }),
5338
- /* @__PURE__ */ jsx24(
5178
+ /* @__PURE__ */ jsxs20(AlertDialogFooter5, { children: [
5179
+ /* @__PURE__ */ jsx22(AlertDialogCancel5, { children: "Cancelar" }),
5180
+ /* @__PURE__ */ jsx22(
5339
5181
  AlertDialogAction5,
5340
5182
  {
5341
5183
  onClick: handleRemove,
5342
- disabled: removeMutation.isPending,
5184
+ disabled: deleteMutation.isPending,
5343
5185
  children: "Remover"
5344
5186
  }
5345
5187
  )
@@ -5350,11 +5192,53 @@ function AgentToolsList({ agent, config }) {
5350
5192
  ] });
5351
5193
  }
5352
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
+
5353
5237
  // src/pages/agents-page.tsx
5354
5238
  import { useState as useState16 } from "react";
5355
5239
  import { Button as Button15 } from "@greatapps/greatauth-ui/ui";
5356
5240
  import { Plus as Plus4 } from "lucide-react";
5357
- import { jsx as jsx25, jsxs as jsxs23 } from "react/jsx-runtime";
5241
+ import { jsx as jsx24, jsxs as jsxs22 } from "react/jsx-runtime";
5358
5242
  function AgentsPage({
5359
5243
  config,
5360
5244
  onNavigateToAgent,
@@ -5362,19 +5246,19 @@ function AgentsPage({
5362
5246
  subtitle = "Gerencie seus agentes de atendimento inteligente"
5363
5247
  }) {
5364
5248
  const [createOpen, setCreateOpen] = useState16(false);
5365
- return /* @__PURE__ */ jsxs23("div", { className: "flex flex-col gap-4 p-4 md:p-6", children: [
5366
- /* @__PURE__ */ jsxs23("div", { className: "flex items-center justify-between", children: [
5367
- /* @__PURE__ */ jsxs23("div", { children: [
5368
- /* @__PURE__ */ jsx25("h1", { className: "text-xl font-semibold", children: title }),
5369
- /* @__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 })
5370
5254
  ] }),
5371
- /* @__PURE__ */ jsxs23(Button15, { onClick: () => setCreateOpen(true), size: "sm", children: [
5372
- /* @__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" }),
5373
5257
  "Novo Agente"
5374
5258
  ] })
5375
5259
  ] }),
5376
- /* @__PURE__ */ jsx25(AgentsTable, { config, onNavigateToAgent }),
5377
- /* @__PURE__ */ jsx25(
5260
+ /* @__PURE__ */ jsx24(AgentsTable, { config, onNavigateToAgent }),
5261
+ /* @__PURE__ */ jsx24(
5378
5262
  AgentFormDialog,
5379
5263
  {
5380
5264
  config,
@@ -5390,7 +5274,7 @@ import { useState as useState17 } from "react";
5390
5274
  import { Badge as Badge10, Button as Button16, Skeleton as Skeleton7 } from "@greatapps/greatauth-ui/ui";
5391
5275
  import { EntityAvatar as EntityAvatar2 } from "@greatapps/greatauth-ui";
5392
5276
  import { ArrowLeft, Pencil as Pencil5 } from "lucide-react";
5393
- import { jsx as jsx26, jsxs as jsxs24 } from "react/jsx-runtime";
5277
+ import { jsx as jsx25, jsxs as jsxs23 } from "react/jsx-runtime";
5394
5278
  function AgentDetailPage({
5395
5279
  config,
5396
5280
  agentId,
@@ -5400,26 +5284,26 @@ function AgentDetailPage({
5400
5284
  const { data: agent, isLoading } = useAgent(config, agentId);
5401
5285
  const [editOpen, setEditOpen] = useState17(false);
5402
5286
  if (isLoading) {
5403
- return /* @__PURE__ */ jsxs24("div", { className: "flex flex-col gap-4 p-4", children: [
5404
- /* @__PURE__ */ jsx26(Skeleton7, { className: "h-4 w-32" }),
5405
- /* @__PURE__ */ jsx26(Skeleton7, { className: "h-8 w-48" }),
5406
- /* @__PURE__ */ jsx26(Skeleton7, { className: "h-10 w-full" }),
5407
- /* @__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" })
5408
5292
  ] });
5409
5293
  }
5410
5294
  if (!agent) {
5411
- return /* @__PURE__ */ jsxs24("div", { className: "flex flex-col items-center justify-center gap-2 p-8", children: [
5412
- /* @__PURE__ */ jsx26("p", { className: "text-muted-foreground", children: "Agente n\xE3o encontrado" }),
5413
- onBack && /* @__PURE__ */ jsxs24(Button16, { variant: "ghost", size: "sm", onClick: onBack, children: [
5414
- /* @__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" }),
5415
5299
  "Voltar para agentes"
5416
5300
  ] })
5417
5301
  ] });
5418
5302
  }
5419
- return /* @__PURE__ */ jsxs24("div", { className: "flex flex-col gap-6 p-4 md:p-6", children: [
5420
- /* @__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: [
5421
- /* @__PURE__ */ jsxs24("div", { className: "flex items-start gap-3 flex-1", children: [
5422
- 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(
5423
5307
  Button16,
5424
5308
  {
5425
5309
  variant: "ghost",
@@ -5427,13 +5311,13 @@ function AgentDetailPage({
5427
5311
  "aria-label": "Voltar",
5428
5312
  className: "shrink-0 mt-1",
5429
5313
  onClick: onBack,
5430
- children: /* @__PURE__ */ jsx26(ArrowLeft, { className: "h-4 w-4" })
5314
+ children: /* @__PURE__ */ jsx25(ArrowLeft, { className: "h-4 w-4" })
5431
5315
  }
5432
5316
  ),
5433
- /* @__PURE__ */ jsx26(EntityAvatar2, { photo: agent.photo, name: agent.title, size: "xl" }),
5434
- /* @__PURE__ */ jsx26("div", { className: "flex-1 min-w-0", children: /* @__PURE__ */ jsxs24("div", { className: "flex items-center gap-2 flex-wrap", children: [
5435
- /* @__PURE__ */ jsx26("h1", { className: "text-xl font-semibold", children: agent.title }),
5436
- /* @__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(
5437
5321
  Badge10,
5438
5322
  {
5439
5323
  variant: agent.active ? "default" : "destructive",
@@ -5443,7 +5327,7 @@ function AgentDetailPage({
5443
5327
  )
5444
5328
  ] }) })
5445
5329
  ] }),
5446
- /* @__PURE__ */ jsxs24(
5330
+ /* @__PURE__ */ jsxs23(
5447
5331
  Button16,
5448
5332
  {
5449
5333
  variant: "outline",
@@ -5451,13 +5335,13 @@ function AgentDetailPage({
5451
5335
  className: "shrink-0 self-start",
5452
5336
  onClick: () => setEditOpen(true),
5453
5337
  children: [
5454
- /* @__PURE__ */ jsx26(Pencil5, { className: "mr-2 h-4 w-4" }),
5338
+ /* @__PURE__ */ jsx25(Pencil5, { className: "mr-2 h-4 w-4" }),
5455
5339
  "Editar"
5456
5340
  ]
5457
5341
  }
5458
5342
  )
5459
5343
  ] }) }),
5460
- /* @__PURE__ */ jsx26(
5344
+ /* @__PURE__ */ jsx25(
5461
5345
  AgentTabs,
5462
5346
  {
5463
5347
  agent,
@@ -5465,7 +5349,7 @@ function AgentDetailPage({
5465
5349
  renderChatLink
5466
5350
  }
5467
5351
  ),
5468
- editOpen && /* @__PURE__ */ jsx26(
5352
+ editOpen && /* @__PURE__ */ jsx25(
5469
5353
  AgentEditForm,
5470
5354
  {
5471
5355
  agent,
@@ -5478,8 +5362,110 @@ function AgentDetailPage({
5478
5362
  ] });
5479
5363
  }
5480
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
+
5481
5467
  // src/pages/tools-page.tsx
5482
- import { useState as useState18 } from "react";
5468
+ import { useState as useState19 } from "react";
5483
5469
  import { Button as Button17 } from "@greatapps/greatauth-ui/ui";
5484
5470
  import { Plus as Plus5 } from "lucide-react";
5485
5471
  import { jsx as jsx27, jsxs as jsxs25 } from "react/jsx-runtime";
@@ -5488,8 +5474,8 @@ function ToolsPage({
5488
5474
  title = "Ferramentas",
5489
5475
  subtitle = "Gerencie as ferramentas dispon\xEDveis para seus agentes"
5490
5476
  }) {
5491
- const [createOpen, setCreateOpen] = useState18(false);
5492
- const [editTool, setEditTool] = useState18(void 0);
5477
+ const [createOpen, setCreateOpen] = useState19(false);
5478
+ const [editTool, setEditTool] = useState19(void 0);
5493
5479
  return /* @__PURE__ */ jsxs25("div", { className: "flex flex-col gap-4 p-4 md:p-6", children: [
5494
5480
  /* @__PURE__ */ jsxs25("div", { className: "flex items-center justify-between", children: [
5495
5481
  /* @__PURE__ */ jsxs25("div", { children: [
@@ -5523,7 +5509,7 @@ function ToolsPage({
5523
5509
  }
5524
5510
 
5525
5511
  // src/pages/credentials-page.tsx
5526
- import { useState as useState19 } from "react";
5512
+ import { useState as useState20 } from "react";
5527
5513
  import { Button as Button18 } from "@greatapps/greatauth-ui/ui";
5528
5514
  import { Plus as Plus6 } from "lucide-react";
5529
5515
  import { jsx as jsx28, jsxs as jsxs26 } from "react/jsx-runtime";
@@ -5534,7 +5520,7 @@ function CredentialsPage({
5534
5520
  subtitle = "Gerencie as credenciais de autentica\xE7\xE3o das ferramentas"
5535
5521
  }) {
5536
5522
  const { data: credentialsData, isLoading: credentialsLoading } = useToolCredentials(config);
5537
- const [createOpen, setCreateOpen] = useState19(false);
5523
+ const [createOpen, setCreateOpen] = useState20(false);
5538
5524
  const credentials = credentialsData?.data || [];
5539
5525
  return /* @__PURE__ */ jsxs26("div", { className: "flex flex-col gap-4 p-4 md:p-6", children: [
5540
5526
  /* @__PURE__ */ jsxs26("div", { className: "flex items-center justify-between", children: [
@@ -5562,7 +5548,7 @@ function CredentialsPage({
5562
5548
  }
5563
5549
 
5564
5550
  // src/pages/integrations-management-page.tsx
5565
- import { useState as useState20, useMemo as useMemo8 } from "react";
5551
+ import { useState as useState21, useMemo as useMemo8 } from "react";
5566
5552
  import {
5567
5553
  Badge as Badge11,
5568
5554
  Button as Button19,
@@ -5571,7 +5557,7 @@ import {
5571
5557
  TabsList as TabsList3,
5572
5558
  TabsTrigger as TabsTrigger3
5573
5559
  } from "@greatapps/greatauth-ui/ui";
5574
- 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";
5575
5561
  import { jsx as jsx29, jsxs as jsxs27 } from "react/jsx-runtime";
5576
5562
  function useCredentialAgentSummary(credentials, tools, agents) {
5577
5563
  return useMemo8(() => {
@@ -5599,7 +5585,7 @@ function IntegrationsManagementPage({
5599
5585
  const { data: credentialsData, isLoading: credentialsLoading } = useToolCredentials(config);
5600
5586
  const { data: agentsData } = useAgents(config);
5601
5587
  const { data: toolsData } = useTools(config);
5602
- const [createOpen, setCreateOpen] = useState20(false);
5588
+ const [createOpen, setCreateOpen] = useState21(false);
5603
5589
  const credentials = credentialsData?.data || [];
5604
5590
  const agents = agentsData?.data || [];
5605
5591
  const tools = toolsData?.data || [];
@@ -5612,7 +5598,7 @@ function IntegrationsManagementPage({
5612
5598
  /* @__PURE__ */ jsxs27(Tabs3, { defaultValue: "integrations", className: "w-full", children: [
5613
5599
  /* @__PURE__ */ jsxs27(TabsList3, { children: [
5614
5600
  /* @__PURE__ */ jsxs27(TabsTrigger3, { value: "integrations", className: "gap-2", children: [
5615
- /* @__PURE__ */ jsx29(Plug4, { className: "h-4 w-4" }),
5601
+ /* @__PURE__ */ jsx29(Plug5, { className: "h-4 w-4" }),
5616
5602
  "Integra\xE7\xF5es"
5617
5603
  ] }),
5618
5604
  /* @__PURE__ */ jsxs27(TabsTrigger3, { value: "credentials", className: "gap-2", children: [