@greatapps/greatagents-ui 0.1.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 +399 -0
- package/dist/index.js +479 -0
- package/dist/index.js.map +1 -0
- package/package.json +48 -0
- package/src/client/index.ts +254 -0
- package/src/hooks/index.ts +30 -0
- package/src/hooks/types.ts +31 -0
- package/src/hooks/use-agent-tools.ts +72 -0
- package/src/hooks/use-agents.ts +89 -0
- package/src/hooks/use-contacts.ts +14 -0
- package/src/hooks/use-conversations.ts +39 -0
- package/src/hooks/use-objectives.ts +77 -0
- package/src/hooks/use-settings.ts +90 -0
- package/src/hooks/use-tools.ts +84 -0
- package/src/index.ts +26 -0
- package/src/lib/index.ts +6 -0
- package/src/types/index.ts +157 -0
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ApiResponse,
|
|
3
|
+
Agent,
|
|
4
|
+
AgentTool,
|
|
5
|
+
AvailabilityResult,
|
|
6
|
+
CalendarStatus,
|
|
7
|
+
ContactUser,
|
|
8
|
+
Conversation,
|
|
9
|
+
GagentsContact,
|
|
10
|
+
Objective,
|
|
11
|
+
PromptVersion,
|
|
12
|
+
Tool,
|
|
13
|
+
ToolCredential,
|
|
14
|
+
} from "../types";
|
|
15
|
+
|
|
16
|
+
export interface GagentsClientConfig {
|
|
17
|
+
baseUrl: string;
|
|
18
|
+
token: string;
|
|
19
|
+
language?: string;
|
|
20
|
+
idWl?: number;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function createGagentsClient(config: GagentsClientConfig) {
|
|
24
|
+
const { baseUrl, token, language = "pt-br", idWl = 1 } = config;
|
|
25
|
+
|
|
26
|
+
function buildUrl(idAccount: number, path: string): string {
|
|
27
|
+
return `${baseUrl}/v1/${language}/${idWl}/accounts/${idAccount}/${path}`;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
async function request<T>(
|
|
31
|
+
method: string,
|
|
32
|
+
idAccount: number,
|
|
33
|
+
path: string,
|
|
34
|
+
body?: unknown,
|
|
35
|
+
params?: Record<string, string>,
|
|
36
|
+
): Promise<ApiResponse<T>> {
|
|
37
|
+
const url = new URL(buildUrl(idAccount, path));
|
|
38
|
+
if (params) {
|
|
39
|
+
Object.entries(params).forEach(([k, v]) => url.searchParams.set(k, v));
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const res = await fetch(url.toString(), {
|
|
43
|
+
method,
|
|
44
|
+
headers: {
|
|
45
|
+
"Content-Type": "application/json",
|
|
46
|
+
Authorization: `Bearer ${token}`,
|
|
47
|
+
},
|
|
48
|
+
body: body ? JSON.stringify(body) : undefined,
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
if (!res.ok) {
|
|
52
|
+
let message = `HTTP ${res.status}: ${res.statusText}`;
|
|
53
|
+
try {
|
|
54
|
+
const errorBody = await res.json();
|
|
55
|
+
message = errorBody.message || message;
|
|
56
|
+
} catch {
|
|
57
|
+
/* ignore parse errors */
|
|
58
|
+
}
|
|
59
|
+
throw new Error(message);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const json: ApiResponse<T> = await res.json();
|
|
63
|
+
|
|
64
|
+
// For mutations, treat API-level failures as errors so TanStack Query
|
|
65
|
+
// fires onError instead of onSuccess (API returns HTTP 200 even on failure)
|
|
66
|
+
if (method !== "GET" && json.status === 0) {
|
|
67
|
+
throw new Error(json.message || "Operação falhou");
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return json;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return {
|
|
74
|
+
// --- Agents ---
|
|
75
|
+
listAgents: (idAccount: number, params?: Record<string, string>) =>
|
|
76
|
+
request<Agent[]>("GET", idAccount, "agents", undefined, params),
|
|
77
|
+
|
|
78
|
+
getAgent: (idAccount: number, id: number) =>
|
|
79
|
+
request<Agent>("GET", idAccount, `agents/${id}`),
|
|
80
|
+
|
|
81
|
+
createAgent: (
|
|
82
|
+
idAccount: number,
|
|
83
|
+
body: Pick<Agent, "title"> &
|
|
84
|
+
Partial<Pick<Agent, "prompt" | "photo" | "delay_typing" | "waiting_time">>,
|
|
85
|
+
) => request<Agent>("POST", idAccount, "agents", body),
|
|
86
|
+
|
|
87
|
+
updateAgent: (
|
|
88
|
+
idAccount: number,
|
|
89
|
+
id: number,
|
|
90
|
+
body: Partial<
|
|
91
|
+
Pick<Agent, "title" | "prompt" | "photo" | "delay_typing" | "waiting_time" | "active">
|
|
92
|
+
>,
|
|
93
|
+
) => request<Agent>("PUT", idAccount, `agents/${id}`, body),
|
|
94
|
+
|
|
95
|
+
deleteAgent: (idAccount: number, id: number) =>
|
|
96
|
+
request<void>("DELETE", idAccount, `agents/${id}`),
|
|
97
|
+
|
|
98
|
+
// --- Tools ---
|
|
99
|
+
listTools: (idAccount: number, params?: Record<string, string>) =>
|
|
100
|
+
request<Tool[]>("GET", idAccount, "tools", undefined, params),
|
|
101
|
+
|
|
102
|
+
getTool: (idAccount: number, id: number) =>
|
|
103
|
+
request<Tool>("GET", idAccount, `tools/${id}`),
|
|
104
|
+
|
|
105
|
+
createTool: (
|
|
106
|
+
idAccount: number,
|
|
107
|
+
body: Pick<Tool, "name" | "type"> &
|
|
108
|
+
Partial<Pick<Tool, "slug" | "description" | "auth_config" | "function_definitions">>,
|
|
109
|
+
) => request<Tool>("POST", idAccount, "tools", body),
|
|
110
|
+
|
|
111
|
+
updateTool: (
|
|
112
|
+
idAccount: number,
|
|
113
|
+
id: number,
|
|
114
|
+
body: Partial<
|
|
115
|
+
Pick<Tool, "name" | "slug" | "type" | "description" | "auth_config" | "function_definitions">
|
|
116
|
+
>,
|
|
117
|
+
) => request<Tool>("PUT", idAccount, `tools/${id}`, body),
|
|
118
|
+
|
|
119
|
+
deleteTool: (idAccount: number, id: number) =>
|
|
120
|
+
request<void>("DELETE", idAccount, `tools/${id}`),
|
|
121
|
+
|
|
122
|
+
// --- Agent Tools ---
|
|
123
|
+
listAgentTools: (idAccount: number, idAgent: number, params?: Record<string, string>) =>
|
|
124
|
+
request<AgentTool[]>("GET", idAccount, `agents/${idAgent}/tools`, undefined, params),
|
|
125
|
+
|
|
126
|
+
addAgentTool: (
|
|
127
|
+
idAccount: number,
|
|
128
|
+
idAgent: number,
|
|
129
|
+
body: Pick<AgentTool, "id_tool"> &
|
|
130
|
+
Partial<Pick<AgentTool, "enabled" | "custom_instructions" | "parameter_mappings" | "id_tool_credential">>,
|
|
131
|
+
) => request<AgentTool>("POST", idAccount, `agents/${idAgent}/tools`, body),
|
|
132
|
+
|
|
133
|
+
updateAgentTool: (
|
|
134
|
+
idAccount: number,
|
|
135
|
+
idAgent: number,
|
|
136
|
+
id: number,
|
|
137
|
+
body: Partial<
|
|
138
|
+
Pick<AgentTool, "enabled" | "custom_instructions" | "parameter_mappings" | "id_tool_credential">
|
|
139
|
+
>,
|
|
140
|
+
) => request<AgentTool>("PUT", idAccount, `agents/${idAgent}/tools/${id}`, body),
|
|
141
|
+
|
|
142
|
+
removeAgentTool: (idAccount: number, idAgent: number, id: number) =>
|
|
143
|
+
request<void>("DELETE", idAccount, `agents/${idAgent}/tools/${id}`),
|
|
144
|
+
|
|
145
|
+
// --- Objectives ---
|
|
146
|
+
listObjectives: (idAccount: number, idAgent: number, params?: Record<string, string>) =>
|
|
147
|
+
request<Objective[]>("GET", idAccount, `agents/${idAgent}/objectives`, undefined, params),
|
|
148
|
+
|
|
149
|
+
getObjective: (idAccount: number, idAgent: number, id: number) =>
|
|
150
|
+
request<Objective>("GET", idAccount, `agents/${idAgent}/objectives/${id}`),
|
|
151
|
+
|
|
152
|
+
createObjective: (
|
|
153
|
+
idAccount: number,
|
|
154
|
+
idAgent: number,
|
|
155
|
+
body: Pick<Objective, "title"> &
|
|
156
|
+
Partial<Pick<Objective, "slug" | "prompt" | "order" | "active">>,
|
|
157
|
+
) => request<Objective>("POST", idAccount, `agents/${idAgent}/objectives`, body),
|
|
158
|
+
|
|
159
|
+
updateObjective: (
|
|
160
|
+
idAccount: number,
|
|
161
|
+
idAgent: number,
|
|
162
|
+
id: number,
|
|
163
|
+
body: Partial<Pick<Objective, "title" | "slug" | "prompt" | "order" | "active">>,
|
|
164
|
+
) => request<Objective>("PUT", idAccount, `agents/${idAgent}/objectives/${id}`, body),
|
|
165
|
+
|
|
166
|
+
deleteObjective: (idAccount: number, idAgent: number, id: number) =>
|
|
167
|
+
request<void>("DELETE", idAccount, `agents/${idAgent}/objectives/${id}`),
|
|
168
|
+
|
|
169
|
+
// --- Conversations ---
|
|
170
|
+
listConversations: (idAccount: number, params?: Record<string, string>) =>
|
|
171
|
+
request<Conversation[]>("GET", idAccount, "conversations", undefined, params),
|
|
172
|
+
|
|
173
|
+
listAgentConversations: (idAccount: number, idAgent: number, params?: Record<string, string>) =>
|
|
174
|
+
request<Conversation[]>("GET", idAccount, `agents/${idAgent}/conversations`, undefined, params),
|
|
175
|
+
|
|
176
|
+
getConversation: (idAccount: number, id: number) =>
|
|
177
|
+
request<Conversation>("GET", idAccount, `conversations/${id}`),
|
|
178
|
+
|
|
179
|
+
// --- Prompt Versions ---
|
|
180
|
+
listPromptVersions: (idAccount: number, idAgent: number, params?: Record<string, string>) =>
|
|
181
|
+
request<PromptVersion[]>("GET", idAccount, `agents/${idAgent}/prompt-versions`, undefined, params),
|
|
182
|
+
|
|
183
|
+
// --- Tool Credentials ---
|
|
184
|
+
listToolCredentials: (idAccount: number, params?: Record<string, string>) =>
|
|
185
|
+
request<ToolCredential[]>("GET", idAccount, "tool-credentials", undefined, params),
|
|
186
|
+
|
|
187
|
+
createToolCredential: (
|
|
188
|
+
idAccount: number,
|
|
189
|
+
body: Pick<ToolCredential, "id_tool" | "label" | "credentials_encrypted"> &
|
|
190
|
+
Partial<Pick<ToolCredential, "expires_at">>,
|
|
191
|
+
) => request<ToolCredential>("POST", idAccount, "tool-credentials", body),
|
|
192
|
+
|
|
193
|
+
updateToolCredential: (
|
|
194
|
+
idAccount: number,
|
|
195
|
+
id: number,
|
|
196
|
+
body: Partial<
|
|
197
|
+
Pick<ToolCredential, "id_tool" | "label" | "credentials_encrypted" | "expires_at" | "status">
|
|
198
|
+
>,
|
|
199
|
+
) => request<ToolCredential>("PUT", idAccount, `tool-credentials/${id}`, body),
|
|
200
|
+
|
|
201
|
+
deleteToolCredential: (idAccount: number, id: number) =>
|
|
202
|
+
request<void>("DELETE", idAccount, `tool-credentials/${id}`),
|
|
203
|
+
|
|
204
|
+
// --- Contact Users ---
|
|
205
|
+
listContactUsers: (idAccount: number, params?: Record<string, string>) =>
|
|
206
|
+
request<ContactUser[]>("GET", idAccount, "contact-users", undefined, params),
|
|
207
|
+
|
|
208
|
+
getContactUser: (idAccount: number, id: number) =>
|
|
209
|
+
request<ContactUser>("GET", idAccount, `contact-users/${id}`),
|
|
210
|
+
|
|
211
|
+
// --- Contacts ---
|
|
212
|
+
listGagentsContacts: (idAccount: number, params?: Record<string, string>) =>
|
|
213
|
+
request<GagentsContact[]>("GET", idAccount, "contacts", undefined, params),
|
|
214
|
+
|
|
215
|
+
// --- Calendar Integration ---
|
|
216
|
+
initiateCalendarConnect: (
|
|
217
|
+
idAccount: number,
|
|
218
|
+
body: { external_reference: string; provider?: string },
|
|
219
|
+
) => request<{ auth_url: string }>("POST", idAccount, "calendar/connect", body),
|
|
220
|
+
|
|
221
|
+
getCalendarStatus: (
|
|
222
|
+
idAccount: number,
|
|
223
|
+
externalReference: string,
|
|
224
|
+
provider = "google-calendar",
|
|
225
|
+
) =>
|
|
226
|
+
request<CalendarStatus>(
|
|
227
|
+
"GET",
|
|
228
|
+
idAccount,
|
|
229
|
+
`calendar/status/${encodeURIComponent(externalReference)}`,
|
|
230
|
+
undefined,
|
|
231
|
+
{ provider },
|
|
232
|
+
),
|
|
233
|
+
|
|
234
|
+
checkCalendarAvailability: (
|
|
235
|
+
idAccount: number,
|
|
236
|
+
body: { id_professional: number; start_time: string; end_time: string },
|
|
237
|
+
) => request<AvailabilityResult>("POST", idAccount, "calendar/availability", body),
|
|
238
|
+
|
|
239
|
+
disconnectCalendar: (
|
|
240
|
+
idAccount: number,
|
|
241
|
+
externalReference: string,
|
|
242
|
+
provider = "google-calendar",
|
|
243
|
+
) =>
|
|
244
|
+
request<void>(
|
|
245
|
+
"DELETE",
|
|
246
|
+
idAccount,
|
|
247
|
+
`calendar/disconnect/${encodeURIComponent(externalReference)}`,
|
|
248
|
+
undefined,
|
|
249
|
+
{ provider },
|
|
250
|
+
),
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
export type GagentsClient = ReturnType<typeof createGagentsClient>;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// Config & Client
|
|
2
|
+
export { type GagentsHookConfig, useGagentsClient } from "./types";
|
|
3
|
+
|
|
4
|
+
// Agents
|
|
5
|
+
export { useAgents, useAgent, useCreateAgent, useUpdateAgent, useDeleteAgent } from "./use-agents";
|
|
6
|
+
|
|
7
|
+
// Tools
|
|
8
|
+
export { useTools, useTool, useCreateTool, useUpdateTool, useDeleteTool } from "./use-tools";
|
|
9
|
+
|
|
10
|
+
// Objectives
|
|
11
|
+
export { useObjectives, useCreateObjective, useUpdateObjective, useDeleteObjective } from "./use-objectives";
|
|
12
|
+
|
|
13
|
+
// Agent Tools
|
|
14
|
+
export { useAgentTools, useAddAgentTool, useRemoveAgentTool, useUpdateAgentTool } from "./use-agent-tools";
|
|
15
|
+
|
|
16
|
+
// Conversations
|
|
17
|
+
export { useConversations, useAgentConversations, useConversation } from "./use-conversations";
|
|
18
|
+
|
|
19
|
+
// Settings (Prompt Versions, Tool Credentials, Contact Users)
|
|
20
|
+
export {
|
|
21
|
+
usePromptVersions,
|
|
22
|
+
useToolCredentials,
|
|
23
|
+
useCreateToolCredential,
|
|
24
|
+
useUpdateToolCredential,
|
|
25
|
+
useDeleteToolCredential,
|
|
26
|
+
useContactUsers,
|
|
27
|
+
} from "./use-settings";
|
|
28
|
+
|
|
29
|
+
// Contacts
|
|
30
|
+
export { useGagentsContacts } from "./use-contacts";
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { useMemo } from "react";
|
|
2
|
+
import { createGagentsClient } from "../client";
|
|
3
|
+
|
|
4
|
+
// ---------------------------------------------------------------------------
|
|
5
|
+
// Hook Configuration
|
|
6
|
+
// ---------------------------------------------------------------------------
|
|
7
|
+
|
|
8
|
+
export interface GagentsHookConfig {
|
|
9
|
+
accountId: number;
|
|
10
|
+
token: string;
|
|
11
|
+
baseUrl: string;
|
|
12
|
+
language?: string;
|
|
13
|
+
idWl?: number;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// ---------------------------------------------------------------------------
|
|
17
|
+
// Internal helper — memoized client from config
|
|
18
|
+
// ---------------------------------------------------------------------------
|
|
19
|
+
|
|
20
|
+
export function useGagentsClient(config: GagentsHookConfig) {
|
|
21
|
+
return useMemo(
|
|
22
|
+
() =>
|
|
23
|
+
createGagentsClient({
|
|
24
|
+
baseUrl: config.baseUrl,
|
|
25
|
+
token: config.token,
|
|
26
|
+
language: config.language,
|
|
27
|
+
idWl: config.idWl,
|
|
28
|
+
}),
|
|
29
|
+
[config.baseUrl, config.token, config.language, config.idWl],
|
|
30
|
+
);
|
|
31
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query";
|
|
2
|
+
import type { GagentsHookConfig } from "./types";
|
|
3
|
+
import { useGagentsClient } from "./types";
|
|
4
|
+
|
|
5
|
+
export function useAgentTools(config: GagentsHookConfig, idAgent: number) {
|
|
6
|
+
const client = useGagentsClient(config);
|
|
7
|
+
|
|
8
|
+
return useQuery({
|
|
9
|
+
queryKey: ["greatagents", "agent-tools", config.accountId, idAgent],
|
|
10
|
+
queryFn: () => client.listAgentTools(config.accountId, idAgent),
|
|
11
|
+
enabled: !!config.token && !!config.accountId && !!idAgent,
|
|
12
|
+
select: (res) => ({ data: res.data || [], total: res.total || 0 }),
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function useAddAgentTool(config: GagentsHookConfig) {
|
|
17
|
+
const client = useGagentsClient(config);
|
|
18
|
+
const queryClient = useQueryClient();
|
|
19
|
+
|
|
20
|
+
return useMutation({
|
|
21
|
+
mutationFn: ({
|
|
22
|
+
idAgent,
|
|
23
|
+
body,
|
|
24
|
+
}: {
|
|
25
|
+
idAgent: number;
|
|
26
|
+
body: { id_tool: number; enabled?: boolean };
|
|
27
|
+
}) => client.addAgentTool(config.accountId, idAgent, body),
|
|
28
|
+
onSuccess: () => {
|
|
29
|
+
queryClient.invalidateQueries({ queryKey: ["greatagents", "agent-tools"] });
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function useRemoveAgentTool(config: GagentsHookConfig) {
|
|
35
|
+
const client = useGagentsClient(config);
|
|
36
|
+
const queryClient = useQueryClient();
|
|
37
|
+
|
|
38
|
+
return useMutation({
|
|
39
|
+
mutationFn: ({ idAgent, id }: { idAgent: number; id: number }) =>
|
|
40
|
+
client.removeAgentTool(config.accountId, idAgent, id),
|
|
41
|
+
onSuccess: () => {
|
|
42
|
+
queryClient.invalidateQueries({ queryKey: ["greatagents", "agent-tools"] });
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function useUpdateAgentTool(config: GagentsHookConfig) {
|
|
48
|
+
const client = useGagentsClient(config);
|
|
49
|
+
const queryClient = useQueryClient();
|
|
50
|
+
|
|
51
|
+
return useMutation({
|
|
52
|
+
mutationFn: ({
|
|
53
|
+
idAgent,
|
|
54
|
+
id,
|
|
55
|
+
body,
|
|
56
|
+
}: {
|
|
57
|
+
idAgent: number;
|
|
58
|
+
id: number;
|
|
59
|
+
body: Partial<{
|
|
60
|
+
enabled: boolean;
|
|
61
|
+
custom_instructions: string | null;
|
|
62
|
+
parameter_mappings: string | null;
|
|
63
|
+
id_tool_credential: number | null;
|
|
64
|
+
}>;
|
|
65
|
+
}) => client.updateAgentTool(config.accountId, idAgent, id, body),
|
|
66
|
+
onSuccess: (_data, variables) => {
|
|
67
|
+
queryClient.invalidateQueries({
|
|
68
|
+
queryKey: ["greatagents", "agent-tools", config.accountId, variables.idAgent],
|
|
69
|
+
});
|
|
70
|
+
},
|
|
71
|
+
});
|
|
72
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query";
|
|
2
|
+
import type { GagentsHookConfig } from "./types";
|
|
3
|
+
import { useGagentsClient } from "./types";
|
|
4
|
+
|
|
5
|
+
export function useAgents(config: GagentsHookConfig, params?: Record<string, string>) {
|
|
6
|
+
const client = useGagentsClient(config);
|
|
7
|
+
|
|
8
|
+
return useQuery({
|
|
9
|
+
queryKey: ["greatagents", "agents", config.accountId, params],
|
|
10
|
+
queryFn: () => client.listAgents(config.accountId, params),
|
|
11
|
+
enabled: !!config.token && !!config.accountId,
|
|
12
|
+
select: (res) => ({ data: res.data || [], total: res.total || 0 }),
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function useAgent(config: GagentsHookConfig, id: number | null) {
|
|
17
|
+
const client = useGagentsClient(config);
|
|
18
|
+
|
|
19
|
+
return useQuery({
|
|
20
|
+
queryKey: ["greatagents", "agent", config.accountId, id],
|
|
21
|
+
queryFn: () => client.getAgent(config.accountId, id!),
|
|
22
|
+
enabled: !!config.token && !!config.accountId && !!id,
|
|
23
|
+
select: (res) => {
|
|
24
|
+
const d = res.data;
|
|
25
|
+
return Array.isArray(d) ? d[0] : d;
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function useCreateAgent(config: GagentsHookConfig) {
|
|
31
|
+
const client = useGagentsClient(config);
|
|
32
|
+
const queryClient = useQueryClient();
|
|
33
|
+
|
|
34
|
+
return useMutation({
|
|
35
|
+
mutationFn: (body: {
|
|
36
|
+
title: string;
|
|
37
|
+
prompt?: string;
|
|
38
|
+
photo?: string;
|
|
39
|
+
delay_typing?: number;
|
|
40
|
+
waiting_time?: number;
|
|
41
|
+
}) => client.createAgent(config.accountId, body),
|
|
42
|
+
onSuccess: () => {
|
|
43
|
+
queryClient.invalidateQueries({ queryKey: ["greatagents", "agents"] });
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function useUpdateAgent(config: GagentsHookConfig) {
|
|
49
|
+
const client = useGagentsClient(config);
|
|
50
|
+
const queryClient = useQueryClient();
|
|
51
|
+
|
|
52
|
+
return useMutation({
|
|
53
|
+
mutationFn: ({
|
|
54
|
+
id,
|
|
55
|
+
body,
|
|
56
|
+
}: {
|
|
57
|
+
id: number;
|
|
58
|
+
body: {
|
|
59
|
+
title?: string;
|
|
60
|
+
prompt?: string;
|
|
61
|
+
photo?: string;
|
|
62
|
+
delay_typing?: number;
|
|
63
|
+
waiting_time?: number;
|
|
64
|
+
active?: boolean;
|
|
65
|
+
};
|
|
66
|
+
}) => client.updateAgent(config.accountId, id, body),
|
|
67
|
+
onSuccess: (_data, variables) => {
|
|
68
|
+
queryClient.invalidateQueries({ queryKey: ["greatagents", "agents"] });
|
|
69
|
+
queryClient.invalidateQueries({
|
|
70
|
+
queryKey: ["greatagents", "agent", config.accountId, variables.id],
|
|
71
|
+
});
|
|
72
|
+
queryClient.invalidateQueries({
|
|
73
|
+
queryKey: ["greatagents", "prompt-versions", config.accountId, variables.id],
|
|
74
|
+
});
|
|
75
|
+
},
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export function useDeleteAgent(config: GagentsHookConfig) {
|
|
80
|
+
const client = useGagentsClient(config);
|
|
81
|
+
const queryClient = useQueryClient();
|
|
82
|
+
|
|
83
|
+
return useMutation({
|
|
84
|
+
mutationFn: (id: number) => client.deleteAgent(config.accountId, id),
|
|
85
|
+
onSuccess: () => {
|
|
86
|
+
queryClient.invalidateQueries({ queryKey: ["greatagents", "agents"] });
|
|
87
|
+
},
|
|
88
|
+
});
|
|
89
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { useQuery } from "@tanstack/react-query";
|
|
2
|
+
import type { GagentsHookConfig } from "./types";
|
|
3
|
+
import { useGagentsClient } from "./types";
|
|
4
|
+
|
|
5
|
+
export function useGagentsContacts(config: GagentsHookConfig, params?: Record<string, string>) {
|
|
6
|
+
const client = useGagentsClient(config);
|
|
7
|
+
|
|
8
|
+
return useQuery({
|
|
9
|
+
queryKey: ["greatagents", "contacts", config.accountId, params],
|
|
10
|
+
queryFn: () => client.listGagentsContacts(config.accountId, params),
|
|
11
|
+
enabled: !!config.token && !!config.accountId,
|
|
12
|
+
select: (res) => ({ data: res.data || [], total: res.total || 0 }),
|
|
13
|
+
});
|
|
14
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { useQuery } from "@tanstack/react-query";
|
|
2
|
+
import type { GagentsHookConfig } from "./types";
|
|
3
|
+
import { useGagentsClient } from "./types";
|
|
4
|
+
|
|
5
|
+
export function useConversations(config: GagentsHookConfig) {
|
|
6
|
+
const client = useGagentsClient(config);
|
|
7
|
+
|
|
8
|
+
return useQuery({
|
|
9
|
+
queryKey: ["greatagents", "conversations", config.accountId],
|
|
10
|
+
queryFn: () => client.listConversations(config.accountId),
|
|
11
|
+
enabled: !!config.token && !!config.accountId,
|
|
12
|
+
select: (res) => ({ data: res.data || [], total: res.total || 0 }),
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function useAgentConversations(config: GagentsHookConfig, idAgent: number) {
|
|
17
|
+
const client = useGagentsClient(config);
|
|
18
|
+
|
|
19
|
+
return useQuery({
|
|
20
|
+
queryKey: ["greatagents", "conversations", config.accountId, "agent", idAgent],
|
|
21
|
+
queryFn: () => client.listAgentConversations(config.accountId, idAgent),
|
|
22
|
+
enabled: !!config.token && !!config.accountId && !!idAgent,
|
|
23
|
+
select: (res) => ({ data: res.data || [], total: res.total || 0 }),
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function useConversation(config: GagentsHookConfig, id: number) {
|
|
28
|
+
const client = useGagentsClient(config);
|
|
29
|
+
|
|
30
|
+
return useQuery({
|
|
31
|
+
queryKey: ["greatagents", "conversations", config.accountId, id],
|
|
32
|
+
queryFn: () => client.getConversation(config.accountId, id),
|
|
33
|
+
enabled: !!config.token && !!config.accountId && !!id,
|
|
34
|
+
select: (res) => {
|
|
35
|
+
const d = res.data;
|
|
36
|
+
return Array.isArray(d) ? d[0] : d;
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query";
|
|
2
|
+
import type { GagentsHookConfig } from "./types";
|
|
3
|
+
import { useGagentsClient } from "./types";
|
|
4
|
+
|
|
5
|
+
export function useObjectives(config: GagentsHookConfig, idAgent: number) {
|
|
6
|
+
const client = useGagentsClient(config);
|
|
7
|
+
|
|
8
|
+
return useQuery({
|
|
9
|
+
queryKey: ["greatagents", "objectives", config.accountId, idAgent],
|
|
10
|
+
queryFn: () => client.listObjectives(config.accountId, idAgent),
|
|
11
|
+
enabled: !!config.token && !!config.accountId && !!idAgent,
|
|
12
|
+
select: (res) => ({ data: res.data || [], total: res.total || 0 }),
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function useCreateObjective(config: GagentsHookConfig) {
|
|
17
|
+
const client = useGagentsClient(config);
|
|
18
|
+
const queryClient = useQueryClient();
|
|
19
|
+
|
|
20
|
+
return useMutation({
|
|
21
|
+
mutationFn: ({
|
|
22
|
+
idAgent,
|
|
23
|
+
body,
|
|
24
|
+
}: {
|
|
25
|
+
idAgent: number;
|
|
26
|
+
body: {
|
|
27
|
+
title: string;
|
|
28
|
+
slug?: string;
|
|
29
|
+
prompt?: string | null;
|
|
30
|
+
order?: number;
|
|
31
|
+
active?: boolean;
|
|
32
|
+
};
|
|
33
|
+
}) => client.createObjective(config.accountId, idAgent, body),
|
|
34
|
+
onSuccess: () => {
|
|
35
|
+
queryClient.invalidateQueries({ queryKey: ["greatagents", "objectives"] });
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function useUpdateObjective(config: GagentsHookConfig) {
|
|
41
|
+
const client = useGagentsClient(config);
|
|
42
|
+
const queryClient = useQueryClient();
|
|
43
|
+
|
|
44
|
+
return useMutation({
|
|
45
|
+
mutationFn: ({
|
|
46
|
+
idAgent,
|
|
47
|
+
id,
|
|
48
|
+
body,
|
|
49
|
+
}: {
|
|
50
|
+
idAgent: number;
|
|
51
|
+
id: number;
|
|
52
|
+
body: Partial<{
|
|
53
|
+
title: string;
|
|
54
|
+
slug: string;
|
|
55
|
+
prompt: string | null;
|
|
56
|
+
order: number;
|
|
57
|
+
active: boolean;
|
|
58
|
+
}>;
|
|
59
|
+
}) => client.updateObjective(config.accountId, idAgent, id, body),
|
|
60
|
+
onSuccess: () => {
|
|
61
|
+
queryClient.invalidateQueries({ queryKey: ["greatagents", "objectives"] });
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function useDeleteObjective(config: GagentsHookConfig) {
|
|
67
|
+
const client = useGagentsClient(config);
|
|
68
|
+
const queryClient = useQueryClient();
|
|
69
|
+
|
|
70
|
+
return useMutation({
|
|
71
|
+
mutationFn: ({ idAgent, id }: { idAgent: number; id: number }) =>
|
|
72
|
+
client.deleteObjective(config.accountId, idAgent, id),
|
|
73
|
+
onSuccess: () => {
|
|
74
|
+
queryClient.invalidateQueries({ queryKey: ["greatagents", "objectives"] });
|
|
75
|
+
},
|
|
76
|
+
});
|
|
77
|
+
}
|