@greatapps/greatagents-ui 0.3.12 → 0.3.13

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@greatapps/greatagents-ui",
3
- "version": "0.3.12",
3
+ "version": "0.3.13",
4
4
  "description": "Shared agents UI components for Great platform",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -1,15 +1,10 @@
1
- import { useState, useCallback } from "react";
2
1
  import type { Agent } from "../../types";
3
2
  import type { GagentsHookConfig } from "../../hooks/types";
4
- import type { IntegrationCardData } from "../../hooks/use-integrations";
5
- import type { WizardIntegrationMeta } from "../capabilities/types";
6
- import type { ConfigOption } from "../capabilities/wizard-steps/config-step";
7
3
  import { AgentObjectivesList } from "./agent-objectives-list";
8
4
  import { AgentPromptEditor } from "./agent-prompt-editor";
9
5
  import { AgentConversationsPanel } from "../conversations/agent-conversations-panel";
10
6
  import { CapabilitiesTab } from "../capabilities/capabilities-tab";
11
7
  import { IntegrationsTab } from "../capabilities/integrations-tab";
12
- import { IntegrationWizard } from "../capabilities/integration-wizard";
13
8
  import {
14
9
  Tabs,
15
10
  TabsList,
@@ -22,119 +17,61 @@ interface AgentTabsProps {
22
17
  agent: Agent;
23
18
  config: GagentsHookConfig;
24
19
  renderChatLink?: (inboxId: number) => React.ReactNode;
25
- gagentsApiUrl?: string;
26
- resolveWizardMeta?: (card: IntegrationCardData) => WizardIntegrationMeta;
27
- loadConfigOptions?: (credentialId: number) => Promise<ConfigOption[]>;
28
- onWizardComplete?: () => void;
29
20
  }
30
21
 
31
22
  export function AgentTabs({
32
23
  agent,
33
24
  config,
34
25
  renderChatLink,
35
- gagentsApiUrl,
36
- resolveWizardMeta,
37
- loadConfigOptions,
38
- onWizardComplete,
39
26
  }: AgentTabsProps) {
40
- const apiUrl = gagentsApiUrl || config.baseUrl;
41
-
42
- // Wizard state for Integrações tab
43
- const [wizardOpen, setWizardOpen] = useState(false);
44
- const [activeCard, setActiveCard] = useState<IntegrationCardData | null>(null);
45
-
46
- const handleConnect = useCallback((card: IntegrationCardData) => {
47
- setActiveCard(card);
48
- setWizardOpen(true);
49
- }, []);
50
-
51
- const handleWizardClose = useCallback((open: boolean) => {
52
- if (!open) {
53
- setActiveCard(null);
54
- }
55
- setWizardOpen(open);
56
- }, []);
57
-
58
- const handleWizardComplete = useCallback(() => {
59
- setWizardOpen(false);
60
- setActiveCard(null);
61
- onWizardComplete?.();
62
- }, [onWizardComplete]);
63
-
64
- // Resolve wizard meta with sensible defaults
65
- const wizardMeta: WizardIntegrationMeta | null = activeCard
66
- ? (resolveWizardMeta?.(activeCard) ?? {
67
- capabilities: [],
68
- requirements: [],
69
- hasConfigStep: false,
70
- })
71
- : null;
72
-
73
27
  return (
74
- <>
75
- <Tabs defaultValue="prompt">
76
- <TabsList>
77
- <TabsTrigger value="prompt" className="flex items-center gap-1.5">
78
- <FileText aria-hidden="true" className="h-3.5 w-3.5" />
79
- Prompt
80
- </TabsTrigger>
81
- <TabsTrigger value="objetivos" className="flex items-center gap-1.5">
82
- <Target aria-hidden="true" className="h-3.5 w-3.5" />
83
- Objetivos
84
- </TabsTrigger>
85
- <TabsTrigger value="capacidades" className="flex items-center gap-1.5">
86
- <Blocks aria-hidden="true" className="h-3.5 w-3.5" />
87
- Capacidades
88
- </TabsTrigger>
89
- <TabsTrigger value="integracoes" className="flex items-center gap-1.5">
90
- <Plug aria-hidden="true" className="h-3.5 w-3.5" />
91
- Integrações
92
- </TabsTrigger>
93
- <TabsTrigger value="conversas" className="flex items-center gap-1.5">
94
- <MessageCircle aria-hidden="true" className="h-3.5 w-3.5" />
95
- Conversas
96
- </TabsTrigger>
97
- </TabsList>
98
-
99
- <TabsContent value="prompt" className="mt-4">
100
- <AgentPromptEditor agent={agent} config={config} />
101
- </TabsContent>
28
+ <Tabs defaultValue="prompt">
29
+ <TabsList>
30
+ <TabsTrigger value="prompt" className="flex items-center gap-1.5">
31
+ <FileText aria-hidden="true" className="h-3.5 w-3.5" />
32
+ Prompt
33
+ </TabsTrigger>
34
+ <TabsTrigger value="objetivos" className="flex items-center gap-1.5">
35
+ <Target aria-hidden="true" className="h-3.5 w-3.5" />
36
+ Objetivos
37
+ </TabsTrigger>
38
+ <TabsTrigger value="capacidades" className="flex items-center gap-1.5">
39
+ <Blocks aria-hidden="true" className="h-3.5 w-3.5" />
40
+ Capacidades
41
+ </TabsTrigger>
42
+ <TabsTrigger value="integracoes" className="flex items-center gap-1.5">
43
+ <Plug aria-hidden="true" className="h-3.5 w-3.5" />
44
+ Integrações
45
+ </TabsTrigger>
46
+ <TabsTrigger value="conversas" className="flex items-center gap-1.5">
47
+ <MessageCircle aria-hidden="true" className="h-3.5 w-3.5" />
48
+ Conversas
49
+ </TabsTrigger>
50
+ </TabsList>
102
51
 
103
- <TabsContent value="objetivos" className="mt-4">
104
- <AgentObjectivesList agent={agent} config={config} />
105
- </TabsContent>
52
+ <TabsContent value="prompt" className="mt-4">
53
+ <AgentPromptEditor agent={agent} config={config} />
54
+ </TabsContent>
106
55
 
107
- <TabsContent value="capacidades" className="mt-4">
108
- <CapabilitiesTab config={config} agentId={agent.id} />
109
- </TabsContent>
56
+ <TabsContent value="objetivos" className="mt-4">
57
+ <AgentObjectivesList agent={agent} config={config} />
58
+ </TabsContent>
110
59
 
111
- <TabsContent value="integracoes" className="mt-4">
112
- <IntegrationsTab config={config} agentId={agent.id} onConnect={handleConnect} />
113
- </TabsContent>
60
+ <TabsContent value="capacidades" className="mt-4">
61
+ <CapabilitiesTab config={config} agentId={agent.id} />
62
+ </TabsContent>
114
63
 
115
- <TabsContent value="conversas" className="mt-4">
116
- <AgentConversationsPanel
117
- agent={agent}
118
- config={config}
119
- renderChatLink={renderChatLink}
120
- />
121
- </TabsContent>
122
- </Tabs>
64
+ <TabsContent value="integracoes" className="mt-4">
65
+ <IntegrationsTab config={config} agentId={agent.id} />
66
+ </TabsContent>
123
67
 
124
- {activeCard && wizardMeta && (
125
- <IntegrationWizard
126
- open={wizardOpen}
127
- onOpenChange={handleWizardClose}
128
- integration={activeCard.definition}
129
- meta={wizardMeta}
130
- agentId={agent.id}
68
+ <TabsContent value="conversas" className="mt-4">
69
+ <AgentConversationsPanel
70
+ agent={agent}
131
71
  config={config}
132
- gagentsApiUrl={apiUrl}
133
- existingCredentialId={activeCard.credentialId}
134
- onComplete={handleWizardComplete}
135
- loadConfigOptions={loadConfigOptions}
72
+ renderChatLink={renderChatLink}
136
73
  />
137
- )}
138
- </>
74
+ </TabsContent>
75
+ </Tabs>
139
76
  );
140
77
  }
@@ -1,34 +1,36 @@
1
1
  'use client';
2
2
 
3
+ import { useCallback } from "react";
3
4
  import type { GagentsHookConfig } from "../../hooks/types";
4
- import { useIntegrationState, type IntegrationCardData } from "../../hooks/use-integrations";
5
- import { IntegrationCard } from "./integration-card";
5
+ import { useIntegrationState } from "../../hooks/use-integrations";
6
+ import { useAgentTools, useAddAgentTool, useRemoveAgentTool } from "../../hooks/use-agent-tools";
7
+ import { useTools } from "../../hooks/use-tools";
8
+ import { Switch, Tooltip, TooltipContent, TooltipTrigger } from "@greatapps/greatauth-ui/ui";
6
9
  import { Plug, Loader2 } from "lucide-react";
10
+ import type { LucideIcon } from "lucide-react";
11
+ import { CalendarSync } from "lucide-react";
12
+ import { cn } from "../../lib";
7
13
 
8
14
  // ---------------------------------------------------------------------------
9
- // Props
15
+ // Icon mapping
10
16
  // ---------------------------------------------------------------------------
11
17
 
12
- export interface IntegrationsTabProps {
13
- config: GagentsHookConfig;
14
- agentId: number | null;
15
- /** Called when user clicks a card action (connect / configure / reconnect).
16
- * The consuming app wires this to the wizard (Story 18.9). */
17
- onConnect: (card: IntegrationCardData) => void;
18
+ const ICON_MAP: Record<string, LucideIcon> = {
19
+ CalendarSync,
20
+ Plug,
21
+ };
22
+
23
+ function resolveIcon(name: string): LucideIcon {
24
+ return ICON_MAP[name] ?? Plug;
18
25
  }
19
26
 
20
27
  // ---------------------------------------------------------------------------
21
- // Helpers
28
+ // Props
22
29
  // ---------------------------------------------------------------------------
23
30
 
24
- function getCardKey(card: IntegrationCardData): string {
25
- if (card.credentialId) {
26
- return `${card.definition.slug}-cred-${card.credentialId}`;
27
- }
28
- if (card.isAddNew) {
29
- return `${card.definition.slug}-add-new`;
30
- }
31
- return card.definition.slug;
31
+ export interface IntegrationsTabProps {
32
+ config: GagentsHookConfig;
33
+ agentId: number;
32
34
  }
33
35
 
34
36
  // ---------------------------------------------------------------------------
@@ -38,12 +40,46 @@ function getCardKey(card: IntegrationCardData): string {
38
40
  export function IntegrationsTab({
39
41
  config,
40
42
  agentId,
41
- onConnect,
42
43
  }: IntegrationsTabProps) {
43
- const { cards, isLoading } = useIntegrationState(config, agentId);
44
+ const { cards, isLoading } = useIntegrationState(config, null);
45
+ const { data: toolsData } = useTools(config);
46
+ const { data: agentToolsData, isLoading: agentToolsLoading } = useAgentTools(config, agentId);
47
+ const addAgentTool = useAddAgentTool(config);
48
+ const removeAgentTool = useRemoveAgentTool(config);
49
+
50
+ const tools = toolsData?.data ?? [];
51
+ const agentTools = agentToolsData?.data ?? [];
52
+
53
+ // Only show connected credentials (account-level)
54
+ const connectedCards = cards.filter(
55
+ (c) => !c.isAddNew && (c.state === "connected" || c.state === "expired"),
56
+ );
57
+
58
+ const handleToggle = useCallback(
59
+ (credentialId: number, toolSlug: string, checked: boolean) => {
60
+ // Find the tool record matching this integration slug
61
+ const tool = tools.find((t) => t.slug === toolSlug);
62
+ if (!tool) return;
63
+
64
+ if (checked) {
65
+ // Add agent_tool linking this agent to this tool
66
+ addAgentTool.mutate({
67
+ idAgent: agentId,
68
+ body: { id_tool: tool.id, enabled: true },
69
+ });
70
+ } else {
71
+ // Find the agent_tool to remove
72
+ const agentTool = agentTools.find((at) => at.id_tool === tool.id);
73
+ if (agentTool) {
74
+ removeAgentTool.mutate({ idAgent: agentId, id: agentTool.id });
75
+ }
76
+ }
77
+ },
78
+ [tools, agentTools, agentId, addAgentTool, removeAgentTool],
79
+ );
44
80
 
45
81
  // Loading state
46
- if (isLoading) {
82
+ if (isLoading || agentToolsLoading) {
47
83
  return (
48
84
  <div className="flex items-center justify-center py-16">
49
85
  <Loader2 className="h-6 w-6 animate-spin text-muted-foreground" />
@@ -51,63 +87,82 @@ export function IntegrationsTab({
51
87
  );
52
88
  }
53
89
 
54
- // Empty state
55
- if (cards.length === 0) {
90
+ // Empty state — no integrations connected at account level
91
+ if (connectedCards.length === 0) {
56
92
  return (
57
93
  <div className="flex flex-col items-center justify-center gap-3 py-16 text-muted-foreground">
58
94
  <Plug className="h-10 w-10" />
59
- <p className="text-sm">Nenhuma integração disponível</p>
95
+ <p className="text-sm font-medium">Nenhuma integração conectada</p>
96
+ <p className="text-xs text-center max-w-sm">
97
+ Conecte integrações na página de Integrações da conta para que possam
98
+ ser ativadas neste agente.
99
+ </p>
60
100
  </div>
61
101
  );
62
102
  }
63
103
 
64
- // Split into connected/expired cards and add-new/coming-soon cards
65
- const connectedCards = cards.filter(
66
- (c) => !c.isAddNew && (c.state === "connected" || c.state === "expired"),
67
- );
68
- const otherCards = cards.filter(
69
- (c) => c.isAddNew || c.state === "coming_soon",
70
- );
71
-
72
104
  return (
73
- <div className="space-y-6">
74
- {/* Connected accounts */}
75
- {connectedCards.length > 0 && (
76
- <div>
77
- <h3 className="mb-3 text-xs font-medium uppercase tracking-wider text-muted-foreground">
78
- Contas conectadas
79
- </h3>
80
- <div className="grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-3">
81
- {connectedCards.map((card) => (
82
- <IntegrationCard
83
- key={getCardKey(card)}
84
- card={card}
85
- onConnect={onConnect}
86
- />
87
- ))}
88
- </div>
89
- </div>
90
- )}
91
-
92
- {/* Add new / coming soon */}
93
- {otherCards.length > 0 && (
94
- <div>
95
- {connectedCards.length > 0 && (
96
- <h3 className="mb-3 text-xs font-medium uppercase tracking-wider text-muted-foreground">
97
- Adicionar integração
98
- </h3>
99
- )}
100
- <div className="grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-3">
101
- {otherCards.map((card) => (
102
- <IntegrationCard
103
- key={getCardKey(card)}
104
- card={card}
105
- onConnect={onConnect}
105
+ <div className="space-y-4">
106
+ <p className="text-xs text-muted-foreground">
107
+ Ative ou desative as integrações conectadas na conta para este agente.
108
+ </p>
109
+
110
+ <div className="grid grid-cols-1 gap-3 sm:grid-cols-2 lg:grid-cols-3">
111
+ {connectedCards.map((card) => {
112
+ const Icon = resolveIcon(card.definition.icon);
113
+ const tool = tools.find((t) => t.slug === card.definition.slug);
114
+ const isLinked = tool
115
+ ? agentTools.some((at) => at.id_tool === tool.id)
116
+ : false;
117
+ const isMutating = addAgentTool.isPending || removeAgentTool.isPending;
118
+
119
+ return (
120
+ <div
121
+ key={`${card.definition.slug}-cred-${card.credentialId}`}
122
+ className={cn(
123
+ "flex items-center gap-3 rounded-xl border bg-card p-4 transition-shadow",
124
+ isLinked ? "border-primary/30 shadow-sm" : "opacity-75",
125
+ )}
126
+ >
127
+ {/* Icon */}
128
+ <div className="flex h-9 w-9 shrink-0 items-center justify-center rounded-lg bg-primary/10 text-primary">
129
+ <Icon className="h-4.5 w-4.5" />
130
+ </div>
131
+
132
+ {/* Info */}
133
+ <div className="flex-1 min-w-0">
134
+ <h4 className="text-sm font-medium leading-tight truncate">
135
+ {card.definition.name}
136
+ </h4>
137
+ {card.accountLabel && (
138
+ <Tooltip>
139
+ <TooltipTrigger asChild>
140
+ <p className="text-xs text-muted-foreground truncate" title={card.accountLabel}>
141
+ {card.accountLabel}
142
+ </p>
143
+ </TooltipTrigger>
144
+ <TooltipContent>{card.accountLabel}</TooltipContent>
145
+ </Tooltip>
146
+ )}
147
+ {card.state === "expired" && (
148
+ <p className="text-xs text-amber-600 dark:text-amber-400">Expirado</p>
149
+ )}
150
+ </div>
151
+
152
+ {/* Toggle */}
153
+ <Switch
154
+ checked={isLinked}
155
+ disabled={isMutating}
156
+ onCheckedChange={(checked) =>
157
+ card.credentialId &&
158
+ handleToggle(card.credentialId, card.definition.slug, checked)
159
+ }
160
+ aria-label={`${isLinked ? "Desativar" : "Ativar"} ${card.definition.name} para este agente`}
106
161
  />
107
- ))}
108
- </div>
109
- </div>
110
- )}
162
+ </div>
163
+ );
164
+ })}
165
+ </div>
111
166
  </div>
112
167
  );
113
168
  }
@@ -1,6 +1,5 @@
1
1
  'use client';
2
2
 
3
- import { useState, useCallback } from "react";
4
3
  import {
5
4
  Tabs,
6
5
  TabsList,
@@ -10,13 +9,9 @@ import {
10
9
  import { Blocks, Plug, Settings } from "lucide-react";
11
10
 
12
11
  import type { GagentsHookConfig } from "../hooks/types";
13
- import type { IntegrationCardData } from "../hooks/use-integrations";
14
- import type { WizardIntegrationMeta } from "../components/capabilities/types";
15
12
  import { CapabilitiesTab } from "../components/capabilities/capabilities-tab";
16
13
  import { IntegrationsTab } from "../components/capabilities/integrations-tab";
17
- import { IntegrationWizard } from "../components/capabilities/integration-wizard";
18
14
  import { AdvancedTab } from "../components/capabilities/advanced-tab";
19
- import type { ConfigOption } from "../components/capabilities/wizard-steps/config-step";
20
15
 
21
16
  // ---------------------------------------------------------------------------
22
17
  // Props
@@ -26,33 +21,6 @@ export interface AgentCapabilitiesPageProps {
26
21
  config: GagentsHookConfig;
27
22
  agentId: number;
28
23
  gagentsApiUrl: string;
29
- /**
30
- * Resolve wizard metadata for a given integration card.
31
- * The consuming app provides this so the wizard gets correct
32
- * capabilities, requirements, and config step flag.
33
- */
34
- resolveWizardMeta?: (card: IntegrationCardData) => WizardIntegrationMeta;
35
- /**
36
- * Callback to load config options after OAuth completes
37
- * (e.g. load Google Calendar list). Forwarded to IntegrationWizard.
38
- */
39
- loadConfigOptions?: (credentialId: number) => Promise<ConfigOption[]>;
40
- /** Called after wizard completes successfully. */
41
- onWizardComplete?: () => void;
42
- }
43
-
44
- // ---------------------------------------------------------------------------
45
- // Default wizard meta resolver
46
- // ---------------------------------------------------------------------------
47
-
48
- function defaultResolveWizardMeta(card: IntegrationCardData): WizardIntegrationMeta {
49
- return {
50
- capabilities: [
51
- { label: card.definition.name, description: card.definition.description },
52
- ],
53
- requirements: [],
54
- hasConfigStep: false,
55
- };
56
24
  }
57
25
 
58
26
  // ---------------------------------------------------------------------------
@@ -63,42 +31,13 @@ export function AgentCapabilitiesPage({
63
31
  config,
64
32
  agentId,
65
33
  gagentsApiUrl,
66
- resolveWizardMeta = defaultResolveWizardMeta,
67
- loadConfigOptions,
68
- onWizardComplete,
69
34
  }: AgentCapabilitiesPageProps) {
70
- // Wizard dialog state
71
- const [wizardOpen, setWizardOpen] = useState(false);
72
- const [activeCard, setActiveCard] = useState<IntegrationCardData | null>(null);
73
-
74
- const handleConnect = useCallback(
75
- (card: IntegrationCardData) => {
76
- setActiveCard(card);
77
- setWizardOpen(true);
78
- },
79
- [],
80
- );
81
-
82
- const handleWizardComplete = useCallback(() => {
83
- setWizardOpen(false);
84
- setActiveCard(null);
85
- onWizardComplete?.();
86
- }, [onWizardComplete]);
87
-
88
- const handleWizardOpenChange = useCallback((open: boolean) => {
89
- setWizardOpen(open);
90
- if (!open) setActiveCard(null);
91
- }, []);
92
-
93
- // Derive wizard meta from active card
94
- const wizardMeta = activeCard ? resolveWizardMeta(activeCard) : null;
95
-
96
35
  return (
97
36
  <div className="space-y-4">
98
37
  <div>
99
38
  <h2 className="text-lg font-semibold">Capacidades e Integrações</h2>
100
39
  <p className="text-sm text-muted-foreground">
101
- Configure o que este agente pode fazer e quais serviços externos ele utiliza.
40
+ Configure o que este agente pode fazer e quais integrações ele utiliza.
102
41
  </p>
103
42
  </div>
104
43
 
@@ -123,11 +62,7 @@ export function AgentCapabilitiesPage({
123
62
  </TabsContent>
124
63
 
125
64
  <TabsContent value="integracoes" className="mt-4">
126
- <IntegrationsTab
127
- config={config}
128
- agentId={agentId}
129
- onConnect={handleConnect}
130
- />
65
+ <IntegrationsTab config={config} agentId={agentId} />
131
66
  </TabsContent>
132
67
 
133
68
  <TabsContent value="avancado" className="mt-4">
@@ -138,22 +73,6 @@ export function AgentCapabilitiesPage({
138
73
  />
139
74
  </TabsContent>
140
75
  </Tabs>
141
-
142
- {/* Integration Wizard Dialog */}
143
- {activeCard && wizardMeta && (
144
- <IntegrationWizard
145
- open={wizardOpen}
146
- onOpenChange={handleWizardOpenChange}
147
- integration={activeCard.definition}
148
- meta={wizardMeta}
149
- agentId={agentId}
150
- config={config}
151
- onComplete={handleWizardComplete}
152
- gagentsApiUrl={gagentsApiUrl}
153
- existingCredentialId={activeCard.credential?.id}
154
- loadConfigOptions={loadConfigOptions}
155
- />
156
- )}
157
76
  </div>
158
77
  );
159
78
  }