@greatapps/greatagents 0.1.8 → 0.1.10

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.
@@ -95,8 +95,8 @@ erDiagram
95
95
  VARCHAR(255) title "NOT NULL, searchable, filterable, maxLength=255"
96
96
  IMAGE photo "types=[png,jpg,jpeg,gif,svg,webp], storage=gpages, 200x200"
97
97
  TEXT prompt
98
- INTEGER delayTyping "DEFAULT 0, filterable"
99
- INTEGER waitingTime "DEFAULT 0, filterable"
98
+ INTEGER delay_typing "DEFAULT 0, filterable"
99
+ INTEGER waiting_time "DEFAULT 0, filterable"
100
100
  BOOLEAN deleted "DEFAULT false, filterable"
101
101
  TIMESTAMP datetime_add "filterable, updatable=false"
102
102
  TIMESTAMP datetime_alt "filterable"
@@ -144,8 +144,8 @@ erDiagram
144
144
  objectives_tools {
145
145
  SERIAL id PK "AUTO_INCREMENT, UNIQUE, INDEX"
146
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"
147
+ INTEGER id_objective FK "NOT NULL, filterable, index, reference=objectives.id"
148
+ INTEGER id_tool FK "NOT NULL, filterable, index, reference=tools.id"
149
149
  TEXT instructions
150
150
  BOOLEAN wait "DEFAULT false"
151
151
  BOOLEAN deleted "DEFAULT false, filterable"
@@ -176,10 +176,9 @@ erDiagram
176
176
  conversations {
177
177
  SERIAL id PK "AUTO_INCREMENT, UNIQUE, INDEX"
178
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"
179
+ INTEGER id_lead FK "NOT NULL, filterable, index, reference=leads.id"
180
+ INTEGER id_channel FK "NOT NULL, filterable, index, reference=channels.id"
181
181
  INTEGER id_assignee FK "filterable, index, reference=users.id"
182
- INTEGER id_last_agent FK "filterable, index, optional, reference=agents.id"
183
182
  TIMESTAMP last_message_at "filterable, optional"
184
183
  INTEGER id_last_message FK "filterable, index, optional, reference=messages.id"
185
184
  BOOLEAN stop_ai "DEFAULT false, filterable"
@@ -193,7 +192,7 @@ erDiagram
193
192
  messages {
194
193
  SERIAL id PK "AUTO_INCREMENT, UNIQUE, INDEX"
195
194
  INTEGER id_account FK "NOT NULL, filterable, reference=accounts.id"
196
- INTEGER id_conversation FK "filterable, index, reference=conversations.id"
195
+ INTEGER id_conversation FK "NOT NULL, filterable, index, reference=conversations.id"
197
196
  INTEGER id_agent FK "filterable, index, optional, reference=agents.id"
198
197
  INTEGER id_user FK "filterable, index, optional, reference=users.id"
199
198
  VARCHAR direction "DEFAULT 'in', filterable"
@@ -307,7 +306,6 @@ erDiagram
307
306
  users ||--o{ messages : "User-Message"
308
307
 
309
308
  %% AGENT RELATIONSHIPS
310
- agents ||--o{ conversations : "Agent-LastAgent"
311
309
  agents ||--o{ messages : "Agent-Message"
312
310
  agents ||--o{ leads : "Agent-CurrentAgent"
313
311
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@greatapps/greatagents",
3
- "version": "0.1.8",
3
+ "version": "0.1.10",
4
4
  "description": "Schemas para GreatAgents",
5
5
  "main": "./src/product.js",
6
6
  "type": "module"
@@ -332,7 +332,7 @@ EXCEPTION
332
332
  RAISE WARNING '[%] ✗ Erro ao adicionar constraint lógica messages autor: %', now(), SQLERRM;
333
333
  END $$;
334
334
 
335
- -- AGENTS - delayTyping deve ser >= 0 (se não existir)
335
+ -- AGENTS - delay_typing deve ser >= 0 (se não existir)
336
336
  DO $$
337
337
  BEGIN
338
338
  IF NOT EXISTS (SELECT 1 FROM information_schema.table_constraints
@@ -344,16 +344,16 @@ BEGIN
344
344
 
345
345
  ALTER TABLE agents
346
346
  ADD CONSTRAINT chk_agents_delay_positive
347
- CHECK (delayTyping IS NULL OR delayTyping >= 0);
347
+ CHECK (delay_typing IS NULL OR delay_typing >= 0);
348
348
 
349
- RAISE NOTICE '[%] ✓ Constraint lógica agents.delayTyping >= 0', now();
349
+ RAISE NOTICE '[%] ✓ Constraint lógica agents.delay_typing >= 0', now();
350
350
  END IF;
351
351
  EXCEPTION
352
352
  WHEN OTHERS THEN
353
- RAISE WARNING '[%] ✗ Erro ao adicionar constraint lógica agents.delayTyping: %', now(), SQLERRM;
353
+ RAISE WARNING '[%] ✗ Erro ao adicionar constraint lógica agents.delay_typing: %', now(), SQLERRM;
354
354
  END $$;
355
355
 
356
- -- AGENTS - waitingTime deve ser >= 0 (se não existir)
356
+ -- AGENTS - waiting_time deve ser >= 0 (se não existir)
357
357
  DO $$
358
358
  BEGIN
359
359
  IF NOT EXISTS (SELECT 1 FROM information_schema.table_constraints
@@ -365,13 +365,13 @@ BEGIN
365
365
 
366
366
  ALTER TABLE agents
367
367
  ADD CONSTRAINT chk_agents_waiting_positive
368
- CHECK (waitingTime IS NULL OR waitingTime >= 0);
368
+ CHECK (waiting_time IS NULL OR waiting_time >= 0);
369
369
 
370
- RAISE NOTICE '[%] ✓ Constraint lógica agents.waitingTime >= 0', now();
370
+ RAISE NOTICE '[%] ✓ Constraint lógica agents.waiting_time >= 0', now();
371
371
  END IF;
372
372
  EXCEPTION
373
373
  WHEN OTHERS THEN
374
- RAISE WARNING '[%] ✗ Erro ao adicionar constraint lógica agents.waitingTime: %', now(), SQLERRM;
374
+ RAISE WARNING '[%] ✗ Erro ao adicionar constraint lógica agents.waiting_time: %', now(), SQLERRM;
375
375
  END $$;
376
376
 
377
377
  -- OBJECTIVES - order_number deve ser > 0 (se não existir)
@@ -189,8 +189,8 @@ BEGIN
189
189
  CREATE INDEX IF NOT EXISTS idx_agents_datetime_add ON agents(datetime_add);
190
190
  CREATE INDEX IF NOT EXISTS idx_agents_datetime_alt ON agents(datetime_alt);
191
191
  CREATE INDEX IF NOT EXISTS idx_agents_datetime_del ON agents(datetime_del);
192
- CREATE INDEX IF NOT EXISTS idx_agents_delaytypying ON agents(delayTyping);
193
- CREATE INDEX IF NOT EXISTS idx_agents_waitingtime ON agents(waitingTime);
192
+ CREATE INDEX IF NOT EXISTS idx_agents_delaytypying ON agents(delay_typing);
193
+ CREATE INDEX IF NOT EXISTS idx_agents_waiting_time ON agents(waiting_time);
194
194
 
195
195
  -- Índices full-text para campos searchable
196
196
  CREATE INDEX IF NOT EXISTS idx_agents_title_search ON agents
@@ -394,7 +394,6 @@ BEGIN
394
394
  CREATE INDEX IF NOT EXISTS idx_conversations_id_lead ON conversations(id_lead);
395
395
  CREATE INDEX IF NOT EXISTS idx_conversations_id_channel ON conversations(id_channel);
396
396
  CREATE INDEX IF NOT EXISTS idx_conversations_id_assignee ON conversations(id_assignee);
397
- CREATE INDEX IF NOT EXISTS idx_conversations_id_last_agent ON conversations(id_last_agent);
398
397
  CREATE INDEX IF NOT EXISTS idx_conversations_last_message_at ON conversations(last_message_at);
399
398
  CREATE INDEX IF NOT EXISTS idx_conversations_id_last_message ON conversations(id_last_message);
400
399
  CREATE INDEX IF NOT EXISTS idx_conversations_stop_ai ON conversations(stop_ai);
@@ -294,11 +294,11 @@ BEGIN
294
294
  title VARCHAR(255) NOT NULL,
295
295
  photo VARCHAR(255),
296
296
  prompt TEXT,
297
- delayTyping INTEGER DEFAULT 0,
298
- waitingTime INTEGER DEFAULT 0,
297
+ delay_typing INTEGER DEFAULT 0,
298
+ waiting_time INTEGER DEFAULT 0,
299
299
  FOREIGN KEY (id_account) REFERENCES accounts(id) ON DELETE CASCADE,
300
- CONSTRAINT agents_delay_typing_valid CHECK (delayTyping >= 0),
301
- CONSTRAINT agents_waiting_time_valid CHECK (waitingTime >= 0)
300
+ CONSTRAINT agents_delay_typing_valid CHECK (delay_typing >= 0),
301
+ CONSTRAINT agents_waiting_time_valid CHECK (waiting_time >= 0)
302
302
  );
303
303
  COMMENT ON TABLE agents IS 'Tabela de agentes do sistema';
304
304
 
@@ -423,10 +423,9 @@ BEGIN
423
423
  datetime_alt TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
424
424
  datetime_del TIMESTAMP WITH TIME ZONE NULL,
425
425
  id_account INTEGER NOT NULL,
426
- id_lead INTEGER,
427
- id_channel INTEGER,
426
+ id_lead INTEGER NOT NULL,
427
+ id_channel INTEGER NOT NULL,
428
428
  id_assignee INTEGER,
429
- id_last_agent INTEGER,
430
429
  last_message_at TIMESTAMP WITH TIME ZONE,
431
430
  id_last_message INTEGER,
432
431
  stop_ai BOOLEAN DEFAULT FALSE,
@@ -435,7 +434,6 @@ BEGIN
435
434
  FOREIGN KEY (id_lead) REFERENCES leads(id) ON DELETE SET NULL,
436
435
  FOREIGN KEY (id_channel) REFERENCES channels(id) ON DELETE SET NULL,
437
436
  FOREIGN KEY (id_assignee) REFERENCES users(id) ON DELETE SET NULL,
438
- FOREIGN KEY (id_last_agent) REFERENCES agents(id) ON DELETE SET NULL,
439
437
  CONSTRAINT conversations_status_valid CHECK (status IN ('open', 'pending', 'closed'))
440
438
  );
441
439
  COMMENT ON TABLE conversations IS 'Tabela de conversas do sistema';
@@ -449,8 +447,8 @@ BEGIN
449
447
  datetime_alt TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
450
448
  datetime_del TIMESTAMP WITH TIME ZONE NULL,
451
449
  id_account INTEGER NOT NULL,
452
- id_objective INTEGER,
453
- id_tool INTEGER,
450
+ id_objective INTEGER NOT NULL,
451
+ id_tool INTEGER NOT NULL,
454
452
  instructions TEXT,
455
453
  wait BOOLEAN DEFAULT FALSE,
456
454
  FOREIGN KEY (id_account) REFERENCES accounts(id) ON DELETE CASCADE,
@@ -468,7 +466,7 @@ BEGIN
468
466
  datetime_alt TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
469
467
  datetime_del TIMESTAMP WITH TIME ZONE NULL,
470
468
  id_account INTEGER NOT NULL,
471
- id_conversation INTEGER,
469
+ id_conversation INTEGER NOT NULL,
472
470
  id_agent INTEGER,
473
471
  id_user INTEGER,
474
472
  direction VARCHAR(10) DEFAULT 'in',
@@ -514,8 +512,8 @@ BEGIN
514
512
  datetime_alt TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
515
513
  datetime_del TIMESTAMP WITH TIME ZONE NULL,
516
514
  id_account INTEGER NOT NULL,
517
- id_conversation INTEGER,
518
- id_tag INTEGER,
515
+ id_conversation INTEGER NOT NULL,
516
+ id_tag INTEGER NOT NULL,
519
517
  FOREIGN KEY (id_account) REFERENCES accounts(id) ON DELETE CASCADE,
520
518
  FOREIGN KEY (id_conversation) REFERENCES conversations(id) ON DELETE CASCADE,
521
519
  FOREIGN KEY (id_tag) REFERENCES tags(id) ON DELETE CASCADE
@@ -531,8 +529,8 @@ BEGIN
531
529
  datetime_alt TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
532
530
  datetime_del TIMESTAMP WITH TIME ZONE NULL,
533
531
  id_account INTEGER NOT NULL,
534
- id_lead INTEGER,
535
- id_tag INTEGER,
532
+ id_lead INTEGER NOT NULL,
533
+ id_tag INTEGER NOT NULL,
536
534
  FOREIGN KEY (id_account) REFERENCES accounts(id) ON DELETE CASCADE,
537
535
  FOREIGN KEY (id_lead) REFERENCES leads(id) ON DELETE CASCADE,
538
536
  FOREIGN KEY (id_tag) REFERENCES tags(id) ON DELETE CASCADE
@@ -32,22 +32,22 @@ CREATE TABLE IF NOT EXISTS agents (
32
32
  title VARCHAR(255) NOT NULL, -- required: true, maxLength: 255
33
33
  photo VARCHAR(255), -- type: image -> VARCHAR para URL da imagem
34
34
  prompt TEXT, -- type: string, pode ser longo
35
- delayTyping INTEGER DEFAULT 0, -- type: number, default: 0
36
- waitingTime INTEGER DEFAULT 0, -- type: number, default: 0
35
+ delay_typing INTEGER DEFAULT 0, -- type: number, default: 0
36
+ waiting_time INTEGER DEFAULT 0, -- type: number, default: 0
37
37
 
38
38
  -- Foreign keys
39
39
  FOREIGN KEY (id_account) REFERENCES accounts(id) ON DELETE CASCADE,
40
40
 
41
41
  -- Constraints
42
- CONSTRAINT agents_delay_typing_valid CHECK (delayTyping >= 0),
43
- CONSTRAINT agents_waiting_time_valid CHECK (waitingTime >= 0)
42
+ CONSTRAINT agents_delay_typing_valid CHECK (delay_typing >= 0),
43
+ CONSTRAINT agents_waiting_time_valid CHECK (waiting_time >= 0)
44
44
  );
45
45
 
46
46
  -- Índices para otimização
47
47
  CREATE INDEX IF NOT EXISTS idx_agents_id_account ON agents(id_account);
48
48
  CREATE INDEX IF NOT EXISTS idx_agents_title ON agents(title);
49
- CREATE INDEX IF NOT EXISTS idx_agents_delay_typing ON agents(delayTyping);
50
- CREATE INDEX IF NOT EXISTS idx_agents_waiting_time ON agents(waitingTime);
49
+ CREATE INDEX IF NOT EXISTS idx_agents_delay_typing ON agents(delay_typing);
50
+ CREATE INDEX IF NOT EXISTS idx_agents_waiting_time ON agents(waiting_time);
51
51
 
52
52
  -- Comentários na tabela
53
53
  COMMENT ON TABLE agents IS 'Tabela de agentes do sistema';
@@ -56,8 +56,8 @@ COMMENT ON COLUMN agents.id_account IS 'Referência à conta (FK)';
56
56
  COMMENT ON COLUMN agents.title IS 'Título do agente (obrigatório)';
57
57
  COMMENT ON COLUMN agents.photo IS 'URL da foto do agente';
58
58
  COMMENT ON COLUMN agents.prompt IS 'Instruções do agente';
59
- COMMENT ON COLUMN agents.delayTyping IS 'Atraso em segundos para mostrar "digitando..."';
60
- COMMENT ON COLUMN agents.waitingTime IS 'Tempo em segundos para aguardar mensagens antes de responder';
59
+ COMMENT ON COLUMN agents.delay_typing IS 'Atraso em segundos para mostrar "digitando..."';
60
+ COMMENT ON COLUMN agents.waiting_time IS 'Tempo em segundos para aguardar mensagens antes de responder';
61
61
 
62
62
  -- Verificação pós-execução
63
63
  DO $$
@@ -29,10 +29,9 @@ CREATE TABLE IF NOT EXISTS conversations (
29
29
 
30
30
  -- Campos específicos da tabela conversations
31
31
  id_account INTEGER NOT NULL,
32
- id_lead INTEGER, -- opcional
33
- id_channel INTEGER, -- opcional
32
+ id_lead INTEGER NOT NULL,
33
+ id_channel INTEGER NOT NULL,
34
34
  id_assignee INTEGER, -- opcional (usuário atribuído)
35
- id_last_agent INTEGER, -- opcional
36
35
  last_message_at TIMESTAMP WITH TIME ZONE, -- opcional
37
36
  id_last_message INTEGER, -- IMPORTANTE: SEM FK - referência cíclica será adicionada em constraints.sql
38
37
  stop_ai BOOLEAN DEFAULT FALSE, -- default: false
@@ -40,10 +39,9 @@ CREATE TABLE IF NOT EXISTS conversations (
40
39
 
41
40
  -- Foreign keys (EXCETO id_last_message devido à referência cíclica)
42
41
  FOREIGN KEY (id_account) REFERENCES accounts(id) ON DELETE CASCADE,
43
- FOREIGN KEY (id_lead) REFERENCES leads(id) ON DELETE SET NULL,
44
- FOREIGN KEY (id_channel) REFERENCES channels(id) ON DELETE SET NULL,
42
+ FOREIGN KEY (id_lead) REFERENCES leads(id) ON DELETE CASCADE,
43
+ FOREIGN KEY (id_channel) REFERENCES channels(id) ON DELETE CASCADE,
45
44
  FOREIGN KEY (id_assignee) REFERENCES users(id) ON DELETE SET NULL,
46
- FOREIGN KEY (id_last_agent) REFERENCES agents(id) ON DELETE SET NULL,
47
45
 
48
46
  -- Constraints
49
47
  CONSTRAINT conversations_status_valid CHECK (status IN ('open', 'pending', 'closed'))
@@ -54,7 +52,6 @@ CREATE INDEX IF NOT EXISTS idx_conversations_id_account ON conversations(id_acco
54
52
  CREATE INDEX IF NOT EXISTS idx_conversations_id_lead ON conversations(id_lead);
55
53
  CREATE INDEX IF NOT EXISTS idx_conversations_id_channel ON conversations(id_channel);
56
54
  CREATE INDEX IF NOT EXISTS idx_conversations_id_assignee ON conversations(id_assignee);
57
- CREATE INDEX IF NOT EXISTS idx_conversations_id_last_agent ON conversations(id_last_agent);
58
55
  CREATE INDEX IF NOT EXISTS idx_conversations_last_message_at ON conversations(last_message_at);
59
56
  CREATE INDEX IF NOT EXISTS idx_conversations_id_last_message ON conversations(id_last_message);
60
57
  CREATE INDEX IF NOT EXISTS idx_conversations_stop_ai ON conversations(stop_ai);
@@ -67,7 +64,6 @@ COMMENT ON COLUMN conversations.id_account IS 'Referência à conta (FK)';
67
64
  COMMENT ON COLUMN conversations.id_lead IS 'Referência ao lead (FK, opcional)';
68
65
  COMMENT ON COLUMN conversations.id_channel IS 'Referência ao canal (FK, opcional)';
69
66
  COMMENT ON COLUMN conversations.id_assignee IS 'Usuário atribuído à conversa (FK, opcional)';
70
- COMMENT ON COLUMN conversations.id_last_agent IS 'Último agente da conversa (FK, opcional)';
71
67
  COMMENT ON COLUMN conversations.last_message_at IS 'Data e hora da última mensagem';
72
68
  COMMENT ON COLUMN conversations.id_last_message IS 'Referência à última mensagem (sem FK devido a referência cíclica)';
73
69
  COMMENT ON COLUMN conversations.stop_ai IS 'Flag para parar processamento de I.A.';
@@ -29,8 +29,8 @@ CREATE TABLE IF NOT EXISTS objectives_tools (
29
29
 
30
30
  -- Campos específicos da tabela objectives_tools
31
31
  id_account INTEGER NOT NULL,
32
- id_objective INTEGER, -- opcional
33
- id_tool INTEGER, -- opcional
32
+ id_objective INTEGER NOT NULL,
33
+ id_tool INTEGER NOT NULL,
34
34
  instructions TEXT, -- instruções de uso da ferramenta
35
35
  wait BOOLEAN DEFAULT FALSE, -- default: false - aguardar resposta?
36
36
 
@@ -29,7 +29,7 @@ CREATE TABLE IF NOT EXISTS messages (
29
29
 
30
30
  -- Campos específicos da tabela messages
31
31
  id_account INTEGER NOT NULL,
32
- id_conversation INTEGER, -- opcional
32
+ id_conversation INTEGER NOT NULL,
33
33
  id_agent INTEGER, -- opcional
34
34
  id_user INTEGER, -- opcional
35
35
  direction VARCHAR(10) DEFAULT 'in', -- default: "in"
@@ -29,8 +29,8 @@ CREATE TABLE IF NOT EXISTS conversations_tags (
29
29
 
30
30
  -- Campos específicos da tabela conversations_tags
31
31
  id_account INTEGER NOT NULL,
32
- id_conversation INTEGER, -- opcional
33
- id_tag INTEGER, -- opcional
32
+ id_conversation INTEGER NOT NULL,
33
+ id_tag INTEGER NOT NULL,
34
34
 
35
35
  -- Foreign keys
36
36
  FOREIGN KEY (id_account) REFERENCES accounts(id) ON DELETE CASCADE,
@@ -29,8 +29,8 @@ CREATE TABLE IF NOT EXISTS leads_tags (
29
29
 
30
30
  -- Campos específicos da tabela leads_tags
31
31
  id_account INTEGER NOT NULL,
32
- id_lead INTEGER, -- opcional
33
- id_tag INTEGER, -- opcional
32
+ id_lead INTEGER NOT NULL,
33
+ id_tag INTEGER NOT NULL,
34
34
 
35
35
  -- Foreign keys
36
36
  FOREIGN KEY (id_account) REFERENCES accounts(id) ON DELETE CASCADE,
@@ -105,7 +105,7 @@ export const properties = {
105
105
  }
106
106
  }
107
107
  },
108
- delayTyping: {
108
+ delay_typing: {
109
109
  type: "number",
110
110
  default: 0,
111
111
  filterable: true,
@@ -121,7 +121,7 @@ export const properties = {
121
121
  }
122
122
  }
123
123
  },
124
- waitingTime: {
124
+ waiting_time: {
125
125
  type: "number",
126
126
  default: 0,
127
127
  filterable: true,
@@ -99,25 +99,6 @@ export const properties = {
99
99
  component: "select"
100
100
  }
101
101
  },
102
- id_last_agent: {
103
- type: "number",
104
- filterable: true,
105
- index: true,
106
- required: false,
107
- reference: {
108
- module: "agents",
109
- label: "title",
110
- value: "id",
111
- disabled: true
112
- },
113
- interface: {
114
- label: {
115
- "pt-br": "Último Agente",
116
- "en": "Last Agent"
117
- },
118
- component: "number"
119
- }
120
- },
121
102
  last_message_at: {
122
103
  type: "date",
123
104
  filterable: true,