@greatapps/greatagents 0.1.5 → 0.1.7

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.
Files changed (57) hide show
  1. package/docs/ERD_GAGents_Database.mmd +333 -0
  2. package/package.json +1 -1
  3. package/scripts/MIGRATION_COMPLETE_DOCUMENTATION.md +672 -0
  4. package/scripts/README.md +128 -235
  5. package/scripts/constraints.sql +585 -0
  6. package/scripts/indexes.sql +662 -0
  7. package/scripts/migrate_v1.sql +1227 -0
  8. package/scripts/tables/001_accounts.sql +51 -0
  9. package/scripts/tables/002_users.sql +69 -0
  10. package/scripts/tables/003_people.sql +70 -0
  11. package/scripts/tables/004_tags.sql +62 -0
  12. package/scripts/tables/005_credentials.sql +79 -0
  13. package/scripts/tables/006_agents.sql +70 -0
  14. package/scripts/tables/007_tools.sql +68 -0
  15. package/scripts/tables/008_channels.sql +75 -0
  16. package/scripts/tables/009_leads.sql +85 -0
  17. package/scripts/tables/010_missions.sql +62 -0
  18. package/scripts/tables/011_objectives.sql +68 -0
  19. package/scripts/tables/012_conversations.sql +84 -0
  20. package/scripts/tables/013_objectives_tools.sql +66 -0
  21. package/scripts/tables/014_messages.sql +78 -0
  22. package/scripts/tables/015_companies.sql +77 -0
  23. package/scripts/tables/016_conversations_tags.sql +64 -0
  24. package/scripts/tables/017_leads_tags.sql +64 -0
  25. package/scripts/triggers.sql +497 -0
  26. package/src/modules/accounts/index.js +11 -0
  27. package/src/modules/accounts/properties.js +46 -0
  28. package/src/modules/channels/properties.js +1 -0
  29. package/src/modules/conversations/index.js +1 -1
  30. package/src/modules/conversations/properties.js +29 -26
  31. package/src/modules/credentials/properties.js +2 -2
  32. package/src/modules/leads/properties.js +4 -4
  33. package/src/modules/messages/properties.js +40 -2
  34. package/src/modules/missions/properties.js +1 -0
  35. package/src/modules/objectives/properties.js +1 -18
  36. package/src/modules/objectives_tools/index.js +1 -1
  37. package/src/modules/objectives_tools/properties.js +1 -37
  38. package/src/modules/tools/properties.js +1 -0
  39. package/src/modules/users/index.js +11 -0
  40. package/src/modules/users/properties.js +156 -0
  41. package/src/product.js +4 -0
  42. package/scripts/agents/create_table.sql +0 -43
  43. package/scripts/channels/create_table.sql +0 -48
  44. package/scripts/companies/create_table.sql +0 -52
  45. package/scripts/conversations/add_messages_reference.sql +0 -42
  46. package/scripts/conversations/create_table.sql +0 -55
  47. package/scripts/conversations_tags/create_table.sql +0 -39
  48. package/scripts/credentials/create_table.sql +0 -63
  49. package/scripts/leads/create_table.sql +0 -55
  50. package/scripts/leads_tags/create_table.sql +0 -39
  51. package/scripts/messages/create_table.sql +0 -44
  52. package/scripts/missions/create_table.sql +0 -39
  53. package/scripts/objectives/create_table.sql +0 -47
  54. package/scripts/objectives_tools/create_table.sql +0 -52
  55. package/scripts/people/create_table.sql +0 -51
  56. package/scripts/tags/create_table.sql +0 -38
  57. package/scripts/tools/create_table.sql +0 -43
@@ -0,0 +1,333 @@
1
+ %%{init: {
2
+ 'title': 'GAGents Database - Entity Relationship Diagram',
3
+ 'theme': 'base',
4
+ 'themeVariables': {
5
+ 'primaryColor': '#2E86AB',
6
+ 'primaryTextColor': '#000000',
7
+ 'primaryBorderColor': '#A23B72',
8
+ 'lineColor': '#F18F01',
9
+ 'sectionBkgColor': '#A23B72',
10
+ 'altSectionBkgColor': '#C73E1D'
11
+ }
12
+ }}%%
13
+
14
+ erDiagram
15
+
16
+ accounts {
17
+ SERIAL id PK "AUTO_INCREMENT, UNIQUE, INDEX"
18
+ VARCHAR(100) name "searchable, maxLength=100"
19
+ BOOLEAN deleted "DEFAULT false"
20
+ TIMESTAMP datetime_add "filterable, updatable=false"
21
+ TIMESTAMP datetime_alt "filterable"
22
+ TIMESTAMP datetime_del "filterable"
23
+ }
24
+
25
+ users {
26
+ SERIAL id PK "AUTO_INCREMENT, UNIQUE, INDEX"
27
+ INTEGER id_account FK "NOT NULL, filterable, reference=accounts.id"
28
+ VARCHAR(50) name "searchable, maxLength=50"
29
+ VARCHAR last_name "searchable"
30
+ VARCHAR email "NOT NULL, searchable, filterable, format=email"
31
+ VARCHAR profile "DEFAULT 'collaborator'"
32
+ IMAGE photo "types=[png,jpg,jpeg,gif,svg,webp], storage=gapps-r1-storage, 160x160"
33
+ BOOLEAN deleted "DEFAULT false"
34
+ TIMESTAMP datetime_add "filterable, updatable=false"
35
+ TIMESTAMP datetime_alt "filterable"
36
+ TIMESTAMP datetime_del "filterable"
37
+ }
38
+
39
+ people {
40
+ SERIAL id PK "AUTO_INCREMENT, UNIQUE, INDEX"
41
+ INTEGER id_account FK "NOT NULL, filterable, reference=accounts.id"
42
+ VARCHAR(255) full_name "searchable, maxLength=255"
43
+ VARCHAR(255) first_name "searchable, maxLength=255"
44
+ VARCHAR(255) last_name "searchable, maxLength=255"
45
+ IMAGE photo "types=[png,jpg,jpeg,gif,svg,webp], storage=gpages, 200x200"
46
+ VARCHAR(50) document "searchable, maxLength=50"
47
+ DATE birth_date "filterable"
48
+ BOOLEAN deleted "DEFAULT false, filterable"
49
+ TIMESTAMP datetime_add "filterable, updatable=false"
50
+ TIMESTAMP datetime_alt "filterable"
51
+ TIMESTAMP datetime_del "filterable"
52
+ }
53
+
54
+ tags {
55
+ SERIAL id PK "AUTO_INCREMENT, UNIQUE, INDEX"
56
+ INTEGER id_account FK "NOT NULL, filterable, reference=accounts.id"
57
+ VARCHAR(255) name "NOT NULL, searchable, filterable, maxLength=255"
58
+ VARCHAR color "DEFAULT '#000000', filterable"
59
+ BOOLEAN deleted "DEFAULT false, filterable"
60
+ TIMESTAMP datetime_add "filterable, updatable=false"
61
+ TIMESTAMP datetime_alt "filterable"
62
+ TIMESTAMP datetime_del "filterable"
63
+ }
64
+
65
+ credentials {
66
+ SERIAL id PK "AUTO_INCREMENT, UNIQUE, INDEX"
67
+ INTEGER id_account FK "NOT NULL, filterable, reference=accounts.id"
68
+ VARCHAR(255) title "NOT NULL, searchable, filterable, maxLength=255"
69
+ VARCHAR provider "NOT NULL, filterable, DEFAULT 'web-chat'"
70
+ VARCHAR authType "NOT NULL, filterable, DEFAULT 'none'"
71
+ VARCHAR userName
72
+ VARCHAR password
73
+ VARCHAR apiKey
74
+ VARCHAR token
75
+ VARCHAR paramName
76
+ VARCHAR refreshToken
77
+ VARCHAR clientSecret
78
+ VARCHAR clientId
79
+ VARCHAR sendIn "DEFAULT 'none'"
80
+ VARCHAR scheme "DEFAULT 'none'"
81
+ VARCHAR prefix
82
+ BOOLEAN deleted "DEFAULT false, filterable"
83
+ TIMESTAMP datetime_add "filterable, updatable=false"
84
+ TIMESTAMP datetime_alt "filterable"
85
+ TIMESTAMP datetime_del "filterable"
86
+ }
87
+
88
+ %% ==========================================
89
+ %% AI & AUTOMATION DOMAIN (Domínio de IA)
90
+ %% ==========================================
91
+
92
+ agents {
93
+ SERIAL id PK "AUTO_INCREMENT, UNIQUE, INDEX"
94
+ INTEGER id_account FK "NOT NULL, filterable, reference=accounts.id"
95
+ VARCHAR(255) title "NOT NULL, searchable, filterable, maxLength=255"
96
+ IMAGE photo "types=[png,jpg,jpeg,gif,svg,webp], storage=gpages, 200x200"
97
+ TEXT prompt
98
+ INTEGER delayTyping "DEFAULT 0, filterable"
99
+ INTEGER waitingTime "DEFAULT 0, filterable"
100
+ BOOLEAN deleted "DEFAULT false, filterable"
101
+ TIMESTAMP datetime_add "filterable, updatable=false"
102
+ TIMESTAMP datetime_alt "filterable"
103
+ TIMESTAMP datetime_del "filterable"
104
+ }
105
+
106
+ tools {
107
+ SERIAL id PK "AUTO_INCREMENT, UNIQUE, INDEX"
108
+ INTEGER id_account FK "NOT NULL, filterable, reference=accounts.id"
109
+ VARCHAR(255) title "NOT NULL, searchable, filterable, maxLength=255"
110
+ VARCHAR type "filterable, DEFAULT 'mcp'"
111
+ VARCHAR(1000) description "searchable, filterable, maxLength=1000"
112
+ INTEGER id_credential FK "filterable, index, optional"
113
+ BOOLEAN deleted "DEFAULT false, filterable"
114
+ TIMESTAMP datetime_add "filterable, updatable=false"
115
+ TIMESTAMP datetime_alt "filterable"
116
+ TIMESTAMP datetime_del "filterable"
117
+ }
118
+
119
+ missions {
120
+ SERIAL id PK "AUTO_INCREMENT, UNIQUE, INDEX"
121
+ INTEGER id_account FK "NOT NULL, filterable, reference=accounts.id"
122
+ INTEGER id_agent FK "NOT NULL, filterable, index, reference=agents.id"
123
+ VARCHAR(255) title "NOT NULL, searchable, filterable, maxLength=255"
124
+ TEXT prompt
125
+ BOOLEAN deleted "DEFAULT false, filterable"
126
+ TIMESTAMP datetime_add "filterable, updatable=false"
127
+ TIMESTAMP datetime_alt "filterable"
128
+ TIMESTAMP datetime_del "filterable"
129
+ }
130
+
131
+ objectives {
132
+ SERIAL id PK "AUTO_INCREMENT, UNIQUE, INDEX"
133
+ INTEGER id_account FK "NOT NULL, filterable, reference=accounts.id"
134
+ INTEGER id_mission FK "NOT NULL, filterable, index, reference=missions.id"
135
+ INTEGER order "NOT NULL, filterable, DEFAULT 0"
136
+ VARCHAR(255) title "NOT NULL, searchable, filterable, maxLength=255"
137
+ TEXT prompt
138
+ BOOLEAN deleted "DEFAULT false, filterable"
139
+ TIMESTAMP datetime_add "filterable, updatable=false"
140
+ TIMESTAMP datetime_alt "filterable"
141
+ TIMESTAMP datetime_del "filterable"
142
+ }
143
+
144
+ objectives_tools {
145
+ SERIAL id PK "AUTO_INCREMENT, UNIQUE, INDEX"
146
+ INTEGER id_account FK "NOT NULL, filterable, reference=accounts.id"
147
+ INTEGER id_objective FK "filterable, index, reference=objectives.id"
148
+ INTEGER id_tool FK "filterable, index, reference=tools.id"
149
+ TEXT instructions
150
+ BOOLEAN wait "DEFAULT false"
151
+ BOOLEAN deleted "DEFAULT false, filterable"
152
+ TIMESTAMP datetime_add "filterable, updatable=false"
153
+ TIMESTAMP datetime_alt "filterable"
154
+ TIMESTAMP datetime_del "filterable"
155
+ }
156
+
157
+ %% ==========================================
158
+ %% COMMUNICATION DOMAIN (Domínio de Comunicação)
159
+ %% ==========================================
160
+
161
+ channels {
162
+ SERIAL id PK "AUTO_INCREMENT, UNIQUE, INDEX"
163
+ INTEGER id_account FK "NOT NULL, filterable, reference=accounts.id"
164
+ VARCHAR(255) title "NOT NULL, searchable, filterable, maxLength=255"
165
+ VARCHAR provider "NOT NULL, filterable, DEFAULT 'web-chat'"
166
+ VARCHAR url
167
+ BOOLEAN active "DEFAULT true, filterable"
168
+ INTEGER id_credential FK "optional, reference=credentials.id"
169
+ VARCHAR(255) handle "filterable, maxLength=255"
170
+ BOOLEAN deleted "DEFAULT false, filterable"
171
+ TIMESTAMP datetime_add "filterable, updatable=false"
172
+ TIMESTAMP datetime_alt "filterable"
173
+ TIMESTAMP datetime_del "filterable"
174
+ }
175
+
176
+ conversations {
177
+ SERIAL id PK "AUTO_INCREMENT, UNIQUE, INDEX"
178
+ INTEGER id_account FK "NOT NULL, filterable, reference=accounts.id"
179
+ INTEGER id_lead FK "filterable, index, reference=leads.id"
180
+ INTEGER id_channel FK "filterable, index, reference=channels.id"
181
+ INTEGER id_assignee FK "filterable, index, reference=users.id"
182
+ INTEGER id_last_agent FK "filterable, index, optional, reference=agents.id"
183
+ TIMESTAMP last_message_at "filterable, optional"
184
+ INTEGER id_last_message FK "filterable, index, optional, reference=messages.id"
185
+ BOOLEAN stop_ai "DEFAULT false, filterable"
186
+ VARCHAR status "filterable, DEFAULT 'open'"
187
+ BOOLEAN deleted "DEFAULT false, filterable"
188
+ TIMESTAMP datetime_add "filterable, updatable=false"
189
+ TIMESTAMP datetime_alt "filterable"
190
+ TIMESTAMP datetime_del "filterable"
191
+ }
192
+
193
+ messages {
194
+ SERIAL id PK "AUTO_INCREMENT, UNIQUE, INDEX"
195
+ INTEGER id_account FK "NOT NULL, filterable, reference=accounts.id"
196
+ INTEGER id_conversation FK "filterable, index, reference=conversations.id"
197
+ INTEGER id_agent FK "filterable, index, optional, reference=agents.id"
198
+ INTEGER id_user FK "filterable, index, optional, reference=users.id"
199
+ VARCHAR direction "DEFAULT 'in', filterable"
200
+ VARCHAR role "DEFAULT 'user', filterable"
201
+ TEXT content "NOT NULL"
202
+ BOOLEAN deleted "DEFAULT false, filterable"
203
+ TIMESTAMP datetime_add "filterable, updatable=false"
204
+ TIMESTAMP datetime_alt "filterable"
205
+ TIMESTAMP datetime_del "filterable"
206
+ }
207
+
208
+ %% ==========================================
209
+ %% CRM & ORGANIZATION DOMAIN (Domínio CRM)
210
+ %% ==========================================
211
+
212
+ leads {
213
+ SERIAL id PK "AUTO_INCREMENT, UNIQUE, INDEX"
214
+ INTEGER id_account FK "NOT NULL, filterable, reference=accounts.id"
215
+ INTEGER id_person FK "NOT NULL, filterable, reference=people.id"
216
+ VARCHAR(255) email "searchable, maxLength=255, pattern=email"
217
+ VARCHAR(20) phone "searchable, maxLength=20, pattern=phone"
218
+ INTEGER id_user_owner FK "filterable, index, reference=users.id"
219
+ INTEGER id_current_agent FK "filterable, index, reference=agents.id"
220
+ INTEGER id_current_mission FK "filterable, index, reference=missions.id"
221
+ INTEGER id_current_objective FK "filterable, index, reference=objectives.id"
222
+ TEXT notes "searchable"
223
+ BOOLEAN deleted "DEFAULT false, filterable"
224
+ TIMESTAMP datetime_add "filterable, updatable=false"
225
+ TIMESTAMP datetime_alt "filterable"
226
+ TIMESTAMP datetime_del "filterable"
227
+ }
228
+
229
+ companies {
230
+ SERIAL id PK "AUTO_INCREMENT, UNIQUE, INDEX"
231
+ INTEGER id_account FK "NOT NULL, filterable, reference=accounts.id"
232
+ INTEGER id_lead FK "NOT NULL, filterable, reference=leads.id"
233
+ VARCHAR(255) name "searchable, maxLength=255"
234
+ VARCHAR(255) website "searchable, maxLength=255, pattern=url"
235
+ VARCHAR(50) document "searchable, maxLength=50"
236
+ TEXT notes "searchable"
237
+ VARCHAR industry "searchable"
238
+ VARCHAR size "searchable"
239
+ BOOLEAN deleted "DEFAULT false, filterable"
240
+ TIMESTAMP datetime_add "filterable, updatable=false"
241
+ TIMESTAMP datetime_alt "filterable"
242
+ TIMESTAMP datetime_del "filterable"
243
+ }
244
+
245
+ conversations_tags {
246
+ SERIAL id PK "AUTO_INCREMENT, UNIQUE, INDEX"
247
+ INTEGER id_account FK "NOT NULL, filterable, reference=accounts.id"
248
+ INTEGER id_conversation FK "filterable, index, reference=conversations.id"
249
+ INTEGER id_tag FK "filterable, index, reference=tags.id"
250
+ BOOLEAN deleted "DEFAULT false, filterable"
251
+ TIMESTAMP datetime_add "filterable, updatable=false"
252
+ TIMESTAMP datetime_alt "filterable"
253
+ TIMESTAMP datetime_del "filterable"
254
+ }
255
+
256
+ leads_tags {
257
+ SERIAL id PK "AUTO_INCREMENT, UNIQUE, INDEX"
258
+ INTEGER id_account FK "NOT NULL, filterable, reference=accounts.id"
259
+ INTEGER id_lead FK "filterable, index, reference=leads.id"
260
+ INTEGER id_tag FK "filterable, index, reference=tags.id"
261
+ BOOLEAN deleted "DEFAULT false, filterable"
262
+ TIMESTAMP datetime_add "filterable, updatable=false"
263
+ TIMESTAMP datetime_alt "filterable"
264
+ TIMESTAMP datetime_del "filterable"
265
+ }
266
+
267
+ %% ==========================================
268
+ %% RELACIONAMENTOS 1:N (Um para Muitos)
269
+ %% ==========================================
270
+
271
+ %% ACCOUNTS como entidade central (Multi-tenancy)
272
+ accounts ||--o{ users : "Multi-tenant"
273
+ accounts ||--o{ people : "Multi-tenant"
274
+ accounts ||--o{ tags : "Multi-tenant"
275
+ accounts ||--o{ credentials : "Multi-tenant"
276
+ accounts ||--o{ agents : "Multi-tenant"
277
+ accounts ||--o{ tools : "Multi-tenant"
278
+ accounts ||--o{ missions : "Multi-tenant"
279
+ accounts ||--o{ objectives : "Multi-tenant"
280
+ accounts ||--o{ objectives_tools : "Multi-tenant"
281
+ accounts ||--o{ channels : "Multi-tenant"
282
+ accounts ||--o{ conversations : "Multi-tenant"
283
+ accounts ||--o{ messages : "Multi-tenant"
284
+ accounts ||--o{ leads : "Multi-tenant"
285
+ accounts ||--o{ companies : "Multi-tenant"
286
+ accounts ||--o{ conversations_tags : "Multi-tenant"
287
+ accounts ||--o{ leads_tags : "Multi-tenant"
288
+
289
+ %% RELACIONAMENTOS PRINCIPAIS
290
+ people ||--o{ leads : "Person-Lead"
291
+ leads ||--o{ companies : "Lead-Company"
292
+ leads ||--o{ conversations : "Lead-Conversation"
293
+
294
+ %% AI & AUTOMATION RELATIONSHIPS
295
+ agents ||--o{ missions : "Agent-Mission"
296
+ missions ||--o{ objectives : "Mission-Objective"
297
+ objectives ||--o{ objectives_tools : "Objective-ObjectiveTool"
298
+ tools ||--o{ objectives_tools : "Tool-ObjectiveTool"
299
+
300
+ %% COMMUNICATION RELATIONSHIPS
301
+ channels ||--o{ conversations : "Channel-Conversation"
302
+ conversations ||--o{ messages : "Conversation-Message"
303
+
304
+ %% USER ASSIGNMENTS
305
+ users ||--o{ conversations : "User-ConversationAssignee"
306
+ users ||--o{ leads : "User-LeadOwner"
307
+ users ||--o{ messages : "User-Message"
308
+
309
+ %% AGENT RELATIONSHIPS
310
+ agents ||--o{ conversations : "Agent-LastAgent"
311
+ agents ||--o{ messages : "Agent-Message"
312
+ agents ||--o{ leads : "Agent-CurrentAgent"
313
+
314
+ %% MISSION & OBJECTIVE CURRENT STATES
315
+ missions ||--o{ leads : "Mission-CurrentMission"
316
+ objectives ||--o{ leads : "Objective-CurrentObjective"
317
+
318
+ %% CREDENTIAL RELATIONSHIPS
319
+ credentials ||--o{ tools : "Credential-Tool"
320
+ credentials ||--o{ channels : "Credential-Channel"
321
+
322
+ %% TAG RELATIONSHIPS
323
+ tags ||--o{ conversations_tags : "Tag-ConversationTag"
324
+ tags ||--o{ leads_tags : "Tag-LeadTag"
325
+ conversations ||--o{ conversations_tags : "Conversation-ConversationTag"
326
+ leads ||--o{ leads_tags : "Lead-LeadTag"
327
+
328
+ %% ==========================================
329
+ %% RELACIONAMENTO CÍCLICO ESPECIAL
330
+ %% ==========================================
331
+
332
+ %% CYCLIC REFERENCE: conversations ↔ messages
333
+ conversations ||--o| messages : "LastMessage"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@greatapps/greatagents",
3
- "version": "0.1.5",
3
+ "version": "0.1.7",
4
4
  "description": "Schemas para GreatAgents",
5
5
  "main": "./src/product.js",
6
6
  "type": "module"