@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.
@@ -0,0 +1,90 @@
1
+ import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query";
2
+ import type { ToolCredential } from "../types";
3
+ import type { GagentsHookConfig } from "./types";
4
+ import { useGagentsClient } from "./types";
5
+
6
+ // --- Prompt Versions (read-only) ---
7
+
8
+ export function usePromptVersions(config: GagentsHookConfig, idAgent: number) {
9
+ const client = useGagentsClient(config);
10
+
11
+ return useQuery({
12
+ queryKey: ["greatagents", "prompt-versions", config.accountId, idAgent],
13
+ queryFn: () => client.listPromptVersions(config.accountId, idAgent),
14
+ enabled: !!config.token && !!config.accountId && !!idAgent,
15
+ select: (res) => ({ data: res.data || [], total: res.total || 0 }),
16
+ });
17
+ }
18
+
19
+ // --- Tool Credentials (CRUD) ---
20
+
21
+ export function useToolCredentials(config: GagentsHookConfig) {
22
+ const client = useGagentsClient(config);
23
+
24
+ return useQuery({
25
+ queryKey: ["greatagents", "tool-credentials", config.accountId],
26
+ queryFn: () => client.listToolCredentials(config.accountId),
27
+ enabled: !!config.token && !!config.accountId,
28
+ select: (res) => ({ data: res.data || [], total: res.total || 0 }),
29
+ });
30
+ }
31
+
32
+ export function useCreateToolCredential(config: GagentsHookConfig) {
33
+ const client = useGagentsClient(config);
34
+ const queryClient = useQueryClient();
35
+
36
+ return useMutation({
37
+ mutationFn: (
38
+ body: Pick<ToolCredential, "id_tool" | "label" | "credentials_encrypted"> &
39
+ Partial<Pick<ToolCredential, "expires_at">>,
40
+ ) => client.createToolCredential(config.accountId, body),
41
+ onSuccess: () => {
42
+ queryClient.invalidateQueries({ queryKey: ["greatagents", "tool-credentials"] });
43
+ },
44
+ });
45
+ }
46
+
47
+ export function useUpdateToolCredential(config: GagentsHookConfig) {
48
+ const client = useGagentsClient(config);
49
+ const queryClient = useQueryClient();
50
+
51
+ return useMutation({
52
+ mutationFn: ({
53
+ id,
54
+ body,
55
+ }: {
56
+ id: number;
57
+ body: Partial<
58
+ Pick<ToolCredential, "id_tool" | "label" | "credentials_encrypted" | "expires_at" | "status">
59
+ >;
60
+ }) => client.updateToolCredential(config.accountId, id, body),
61
+ onSuccess: () => {
62
+ queryClient.invalidateQueries({ queryKey: ["greatagents", "tool-credentials"] });
63
+ },
64
+ });
65
+ }
66
+
67
+ export function useDeleteToolCredential(config: GagentsHookConfig) {
68
+ const client = useGagentsClient(config);
69
+ const queryClient = useQueryClient();
70
+
71
+ return useMutation({
72
+ mutationFn: (id: number) => client.deleteToolCredential(config.accountId, id),
73
+ onSuccess: () => {
74
+ queryClient.invalidateQueries({ queryKey: ["greatagents", "tool-credentials"] });
75
+ },
76
+ });
77
+ }
78
+
79
+ // --- Contact Users (read-only) ---
80
+
81
+ export function useContactUsers(config: GagentsHookConfig) {
82
+ const client = useGagentsClient(config);
83
+
84
+ return useQuery({
85
+ queryKey: ["greatagents", "contact-users", config.accountId],
86
+ queryFn: () => client.listContactUsers(config.accountId),
87
+ enabled: !!config.token && !!config.accountId,
88
+ select: (res) => ({ data: res.data || [], total: res.total || 0 }),
89
+ });
90
+ }
@@ -0,0 +1,84 @@
1
+ import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query";
2
+ import type { GagentsHookConfig } from "./types";
3
+ import { useGagentsClient } from "./types";
4
+
5
+ export function useTools(config: GagentsHookConfig, params?: Record<string, string>) {
6
+ const client = useGagentsClient(config);
7
+
8
+ return useQuery({
9
+ queryKey: ["greatagents", "tools", config.accountId, params],
10
+ queryFn: () => client.listTools(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 useTool(config: GagentsHookConfig, id: number | null) {
17
+ const client = useGagentsClient(config);
18
+
19
+ return useQuery({
20
+ queryKey: ["greatagents", "tool", config.accountId, id],
21
+ queryFn: () => client.getTool(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 useCreateTool(config: GagentsHookConfig) {
31
+ const client = useGagentsClient(config);
32
+ const queryClient = useQueryClient();
33
+
34
+ return useMutation({
35
+ mutationFn: (body: {
36
+ name: string;
37
+ slug: string;
38
+ type: string;
39
+ description?: string;
40
+ function_definitions?: string;
41
+ }) => client.createTool(config.accountId, body),
42
+ onSuccess: () => {
43
+ queryClient.invalidateQueries({ queryKey: ["greatagents", "tools"] });
44
+ },
45
+ });
46
+ }
47
+
48
+ export function useUpdateTool(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
+ name?: string;
60
+ type?: string;
61
+ description?: string;
62
+ function_definitions?: string;
63
+ };
64
+ }) => client.updateTool(config.accountId, id, body),
65
+ onSuccess: (_data, variables) => {
66
+ queryClient.invalidateQueries({ queryKey: ["greatagents", "tools"] });
67
+ queryClient.invalidateQueries({
68
+ queryKey: ["greatagents", "tool", config.accountId, variables.id],
69
+ });
70
+ },
71
+ });
72
+ }
73
+
74
+ export function useDeleteTool(config: GagentsHookConfig) {
75
+ const client = useGagentsClient(config);
76
+ const queryClient = useQueryClient();
77
+
78
+ return useMutation({
79
+ mutationFn: (id: number) => client.deleteTool(config.accountId, id),
80
+ onSuccess: () => {
81
+ queryClient.invalidateQueries({ queryKey: ["greatagents", "tools"] });
82
+ },
83
+ });
84
+ }
package/src/index.ts ADDED
@@ -0,0 +1,26 @@
1
+ // Types
2
+ export type {
3
+ ApiResponse,
4
+ Agent,
5
+ AgentTool,
6
+ AvailabilityConflict,
7
+ AvailabilityResult,
8
+ CalendarStatus,
9
+ ContactUser,
10
+ Conversation,
11
+ GagentsContact,
12
+ Objective,
13
+ PromptVersion,
14
+ Tool,
15
+ ToolCredential,
16
+ } from "./types";
17
+
18
+ // Client
19
+ export { createGagentsClient } from "./client";
20
+ export type { GagentsClientConfig, GagentsClient } from "./client";
21
+
22
+ // Utils
23
+ export { cn } from "./lib";
24
+
25
+ // Hooks
26
+ export * from "./hooks";
@@ -0,0 +1,6 @@
1
+ import { clsx, type ClassValue } from "clsx";
2
+ import { twMerge } from "tailwind-merge";
3
+
4
+ export function cn(...inputs: ClassValue[]) {
5
+ return twMerge(clsx(inputs));
6
+ }
@@ -0,0 +1,157 @@
1
+ export interface ApiResponse<T = unknown> {
2
+ status: 0 | 1;
3
+ message?: string;
4
+ data?: T;
5
+ total?: number;
6
+ }
7
+
8
+ export interface Agent {
9
+ id: number;
10
+ id_account: number;
11
+ title: string;
12
+ prompt: string | null;
13
+ photo: string | null;
14
+ external_token: string | null;
15
+ openai_assistant_id: string | null;
16
+ delay_typing: number | null;
17
+ waiting_time: number | null;
18
+ active: boolean;
19
+ deleted: number;
20
+ datetime_add: string;
21
+ datetime_alt: string | null;
22
+ }
23
+
24
+ export interface Objective {
25
+ id: number;
26
+ id_account: number;
27
+ id_agent: number;
28
+ title: string;
29
+ slug: string | null;
30
+ prompt: string | null;
31
+ order: number;
32
+ active: boolean;
33
+ deleted: number;
34
+ datetime_add: string;
35
+ datetime_alt: string | null;
36
+ }
37
+
38
+ export interface Tool {
39
+ id: number;
40
+ id_account: number;
41
+ name: string;
42
+ slug: string | null;
43
+ type: string;
44
+ description: string | null;
45
+ auth_config: string | null;
46
+ function_definitions: string | null;
47
+ deleted: number;
48
+ datetime_add: string;
49
+ datetime_alt: string | null;
50
+ }
51
+
52
+ export interface AgentTool {
53
+ id: number;
54
+ id_account: number;
55
+ id_agent: number;
56
+ id_tool: number;
57
+ id_tool_credential: number | null;
58
+ enabled: boolean;
59
+ parameter_mappings: string | null;
60
+ custom_instructions: string | null;
61
+ deleted: number;
62
+ datetime_add: string;
63
+ datetime_alt: string | null;
64
+ }
65
+
66
+ export interface Conversation {
67
+ id: number;
68
+ id_account: number;
69
+ id_agent: number | null;
70
+ id_objective: number | null;
71
+ id_contact: number;
72
+ id_external: number | null;
73
+ key_memory: string | null;
74
+ openai_thread_id: string | null;
75
+ openai_assistant_id: string | null;
76
+ system_prompt_hash: string | null;
77
+ message_count: number;
78
+ usage_tokens: number;
79
+ context_summary: string | null;
80
+ last_thread_rotation: string | null;
81
+ rotation_count: number;
82
+ deleted: number;
83
+ datetime_add: string;
84
+ datetime_alt: string | null;
85
+ }
86
+
87
+ export interface PromptVersion {
88
+ id: number;
89
+ id_account: number;
90
+ id_agent: number;
91
+ version_number: number;
92
+ prompt_content: string;
93
+ prompt_hash: string;
94
+ is_current: boolean;
95
+ change_notes: string | null;
96
+ deleted: number;
97
+ datetime_add: string;
98
+ }
99
+
100
+ export interface ToolCredential {
101
+ id: number;
102
+ id_account: number;
103
+ id_tool: number;
104
+ label: string;
105
+ credentials_encrypted: string;
106
+ expires_at: string | null;
107
+ status: "active" | "expired";
108
+ authorized_by_contact: number | null;
109
+ deleted: number;
110
+ datetime_add: string;
111
+ datetime_alt: string | null;
112
+ }
113
+
114
+ export interface ContactUser {
115
+ id: number;
116
+ id_account: number;
117
+ id_contact: number;
118
+ id_user: number;
119
+ role: string;
120
+ authorized_at: string | null;
121
+ deleted: number;
122
+ datetime_add: string;
123
+ datetime_alt: string | null;
124
+ }
125
+
126
+ export interface CalendarStatus {
127
+ connected: boolean;
128
+ provider?: string;
129
+ email?: string;
130
+ expires_at?: string;
131
+ }
132
+
133
+ export interface GagentsContact {
134
+ id: number;
135
+ id_account: number;
136
+ id_external: number | null;
137
+ name: string;
138
+ email: string | null;
139
+ phone_number: string | null;
140
+ identifier: string | null;
141
+ key_memory: string | null;
142
+ deleted: number;
143
+ datetime_add: string;
144
+ datetime_alt: string | null;
145
+ }
146
+
147
+ export interface AvailabilityConflict {
148
+ provider: string;
149
+ start: string;
150
+ end: string;
151
+ }
152
+
153
+ export interface AvailabilityResult {
154
+ available: boolean;
155
+ conflicts: AvailabilityConflict[];
156
+ failed_providers: Array<{ provider: string; error: string }>;
157
+ }