@greatapps/greatagents-ui 0.2.1 → 0.3.0
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.d.ts +10 -5
- package/dist/index.js +21 -33
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/client/index.ts +3 -3
- package/src/components/agents/agent-form-dialog.tsx +1 -16
- package/src/components/agents/agent-prompt-editor.tsx +17 -9
- package/src/types/index.ts +0 -1
package/package.json
CHANGED
package/src/client/index.ts
CHANGED
|
@@ -81,15 +81,15 @@ export function createGagentsClient(config: GagentsClientConfig) {
|
|
|
81
81
|
createAgent: (
|
|
82
82
|
idAccount: number,
|
|
83
83
|
body: Pick<Agent, "title"> &
|
|
84
|
-
Partial<Pick<Agent, "
|
|
84
|
+
Partial<Pick<Agent, "photo" | "delay_typing" | "waiting_time">>,
|
|
85
85
|
) => request<Agent>("POST", idAccount, "agents", body),
|
|
86
86
|
|
|
87
87
|
updateAgent: (
|
|
88
88
|
idAccount: number,
|
|
89
89
|
id: number,
|
|
90
90
|
body: Partial<
|
|
91
|
-
Pick<Agent, "title" | "
|
|
92
|
-
|
|
91
|
+
Pick<Agent, "title" | "photo" | "delay_typing" | "waiting_time" | "active">
|
|
92
|
+
> & { prompt?: string; change_notes?: string },
|
|
93
93
|
) => request<Agent>("PUT", idAccount, `agents/${id}`, body),
|
|
94
94
|
|
|
95
95
|
deleteAgent: (idAccount: number, id: number) =>
|
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
DialogFooter,
|
|
11
11
|
Button,
|
|
12
12
|
Input,
|
|
13
|
-
|
|
13
|
+
|
|
14
14
|
Label,
|
|
15
15
|
} from "@greatapps/greatauth-ui/ui";
|
|
16
16
|
import { Loader2 } from "lucide-react";
|
|
@@ -34,7 +34,6 @@ export function AgentFormDialog({
|
|
|
34
34
|
const updateAgent = useUpdateAgent(config);
|
|
35
35
|
|
|
36
36
|
const [title, setTitle] = useState("");
|
|
37
|
-
const [prompt, setPrompt] = useState("");
|
|
38
37
|
const [photo, setPhoto] = useState("");
|
|
39
38
|
const [delayTyping, setDelayTyping] = useState("");
|
|
40
39
|
const [waitingTime, setWaitingTime] = useState("");
|
|
@@ -43,13 +42,11 @@ export function AgentFormDialog({
|
|
|
43
42
|
useEffect(() => {
|
|
44
43
|
if (agent) {
|
|
45
44
|
setTitle(agent.title);
|
|
46
|
-
setPrompt(agent.prompt || "");
|
|
47
45
|
setPhoto(agent.photo || "");
|
|
48
46
|
setDelayTyping(agent.delay_typing != null ? String(agent.delay_typing) : "");
|
|
49
47
|
setWaitingTime(agent.waiting_time != null ? String(agent.waiting_time) : "");
|
|
50
48
|
} else {
|
|
51
49
|
setTitle("");
|
|
52
|
-
setPrompt("");
|
|
53
50
|
setPhoto("");
|
|
54
51
|
setDelayTyping("");
|
|
55
52
|
setWaitingTime("");
|
|
@@ -66,7 +63,6 @@ export function AgentFormDialog({
|
|
|
66
63
|
const body: Record<string, unknown> = {
|
|
67
64
|
title: title.trim(),
|
|
68
65
|
};
|
|
69
|
-
if (prompt.trim()) body.prompt = prompt.trim();
|
|
70
66
|
if (photo.trim()) body.photo = photo.trim();
|
|
71
67
|
if (delayTyping.trim()) body.delay_typing = Number(delayTyping);
|
|
72
68
|
if (waitingTime.trim()) body.waiting_time = Number(waitingTime);
|
|
@@ -117,17 +113,6 @@ export function AgentFormDialog({
|
|
|
117
113
|
disabled={isPending}
|
|
118
114
|
/>
|
|
119
115
|
</div>
|
|
120
|
-
<div className="space-y-2">
|
|
121
|
-
<Label htmlFor="agent-prompt">Prompt do Sistema</Label>
|
|
122
|
-
<Textarea
|
|
123
|
-
id="agent-prompt"
|
|
124
|
-
value={prompt}
|
|
125
|
-
onChange={(e) => setPrompt(e.target.value)}
|
|
126
|
-
placeholder="Instruções para o agente AI..."
|
|
127
|
-
rows={6}
|
|
128
|
-
disabled={isPending}
|
|
129
|
-
/>
|
|
130
|
-
</div>
|
|
131
116
|
<div className="grid grid-cols-2 gap-4">
|
|
132
117
|
<div className="space-y-2">
|
|
133
118
|
<Label htmlFor="agent-delay">Delay de Digitação (ms)</Label>
|
|
@@ -98,18 +98,33 @@ export function AgentPromptEditor({ config, agent }: AgentPromptEditorProps) {
|
|
|
98
98
|
const { data: agentToolsData } = useAgentTools(config, agent.id);
|
|
99
99
|
const { data: toolsData } = useTools(config);
|
|
100
100
|
|
|
101
|
+
const versions = (versionsData?.data || []) as PromptVersion[];
|
|
102
|
+
const sortedVersions = [...versions].sort(
|
|
103
|
+
(a, b) => new Date(b.datetime_add).getTime() - new Date(a.datetime_add).getTime(),
|
|
104
|
+
);
|
|
105
|
+
const currentVersion = sortedVersions.find((v) => v.is_current) || sortedVersions[0] || null;
|
|
106
|
+
const currentPromptContent = currentVersion?.prompt_content ?? "";
|
|
107
|
+
|
|
101
108
|
const [trackedAgentId, setTrackedAgentId] = useState(agent.id);
|
|
102
|
-
const [promptText, setPromptText] = useState(
|
|
109
|
+
const [promptText, setPromptText] = useState(currentPromptContent);
|
|
110
|
+
const [promptInitialized, setPromptInitialized] = useState(false);
|
|
103
111
|
const [changeNotes, setChangeNotes] = useState("");
|
|
104
112
|
const [showPreview, setShowPreview] = useState(false);
|
|
105
113
|
const [compareVersionId, setCompareVersionId] = useState<number | null>(null);
|
|
106
114
|
|
|
107
115
|
const textareaRef = useRef<HTMLTextAreaElement>(null);
|
|
108
116
|
|
|
117
|
+
// Initialize prompt text from current version when data loads
|
|
118
|
+
if (!promptInitialized && currentPromptContent && !isLoading) {
|
|
119
|
+
setPromptText(currentPromptContent);
|
|
120
|
+
setPromptInitialized(true);
|
|
121
|
+
}
|
|
122
|
+
|
|
109
123
|
// Reset prompt text when agent changes
|
|
110
124
|
if (trackedAgentId !== agent.id) {
|
|
111
125
|
setTrackedAgentId(agent.id);
|
|
112
|
-
setPromptText(
|
|
126
|
+
setPromptText(currentPromptContent);
|
|
127
|
+
setPromptInitialized(!!currentPromptContent);
|
|
113
128
|
setCompareVersionId(null);
|
|
114
129
|
}
|
|
115
130
|
|
|
@@ -142,13 +157,6 @@ export function AgentPromptEditor({ config, agent }: AgentPromptEditorProps) {
|
|
|
142
157
|
}
|
|
143
158
|
}
|
|
144
159
|
|
|
145
|
-
const versions = versionsData?.data || [];
|
|
146
|
-
const sortedVersions = [...versions].sort(
|
|
147
|
-
(a: PromptVersion, b: PromptVersion) =>
|
|
148
|
-
new Date(b.datetime_add).getTime() - new Date(a.datetime_add).getTime(),
|
|
149
|
-
);
|
|
150
|
-
|
|
151
|
-
const currentVersion = sortedVersions.length > 0 ? sortedVersions[0] : null;
|
|
152
160
|
const compareVersion = sortedVersions.find((v) => v.id === compareVersionId);
|
|
153
161
|
|
|
154
162
|
// Diff: always compare selected older version against current
|