Spaces:
Runtime error
Runtime error
added SQL
Browse files- sql/agent_data.sql +125 -0
- sql/agent_interaction.sql +39 -0
- sql/analytics_reporting.sql +130 -0
- sql/chat_history_agent_details.sql +59 -0
- sql/command_control.sql +89 -0
- sql/documentation.sql +34 -0
- sql/governance.sql +134 -0
- sql/readme.md +213 -0
- sql/system_settings.sql +92 -0
- sql/users_agents.sql +61 -0
sql/agent_data.sql
ADDED
@@ -0,0 +1,125 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
-- Create the table for storing agent data
|
2 |
+
CREATE TABLE agent_data (
|
3 |
+
agent_id SERIAL PRIMARY KEY,
|
4 |
+
tenant_id UUID NOT NULL,
|
5 |
+
agent_name VARCHAR(255) NOT NULL,
|
6 |
+
status VARCHAR(50) NOT NULL,
|
7 |
+
current_task VARCHAR(255) NOT NULL,
|
8 |
+
performance_metrics VARCHAR(50) NOT NULL,
|
9 |
+
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
10 |
+
);
|
11 |
+
|
12 |
+
-- Insert initial agent data
|
13 |
+
INSERT INTO agent_data (tenant_id, agent_name, status, current_task, performance_metrics) VALUES
|
14 |
+
('tenant-1-uuid', 'NLP Agent', 'Active', 'Text Processing', 'High'),
|
15 |
+
('tenant-1-uuid', 'Vision Agent', 'Idle', 'Image Classification', 'Medium'),
|
16 |
+
('tenant-2-uuid', 'Data Agent', 'Failed', 'Data Cleaning', 'Low'),
|
17 |
+
('tenant-2-uuid', 'Chatbot', 'Active', 'Customer Service', 'High'),
|
18 |
+
('tenant-1-uuid', 'Analysis Agent', 'Idle', 'Data Analysis', 'Medium');
|
19 |
+
|
20 |
+
-- Create the table for storing chat history
|
21 |
+
CREATE TABLE chat_history (
|
22 |
+
id SERIAL PRIMARY KEY,
|
23 |
+
tenant_id UUID NOT NULL,
|
24 |
+
user_message TEXT NOT NULL,
|
25 |
+
bot_response TEXT NOT NULL,
|
26 |
+
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
27 |
+
);
|
28 |
+
|
29 |
+
-- Create the table for storing error logs
|
30 |
+
CREATE TABLE error_log (
|
31 |
+
id SERIAL PRIMARY KEY,
|
32 |
+
tenant_id UUID NOT NULL,
|
33 |
+
time TIMESTAMP NOT NULL,
|
34 |
+
agent_id INT REFERENCES agent_data(agent_id),
|
35 |
+
error_type VARCHAR(255) NOT NULL,
|
36 |
+
message TEXT NOT NULL,
|
37 |
+
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
38 |
+
);
|
39 |
+
|
40 |
+
-- Insert initial error log data
|
41 |
+
INSERT INTO error_log (tenant_id, time, agent_id, error_type, message) VALUES
|
42 |
+
('tenant-1-uuid', '2024-05-15 12:01:00', 3, 'Connection Timeout', 'Failed to connect to the database'),
|
43 |
+
('tenant-2-uuid', '2024-05-15 12:05:00', 5, 'Memory Overflow', 'Exceeded memory limits during data processing');
|
44 |
+
|
45 |
+
-- Create the table for storing agent interactions
|
46 |
+
CREATE TABLE agent_interactions (
|
47 |
+
id SERIAL PRIMARY KEY,
|
48 |
+
tenant_id UUID NOT NULL,
|
49 |
+
agent1 VARCHAR(255) NOT NULL,
|
50 |
+
agent2 VARCHAR(255) NOT NULL,
|
51 |
+
interaction_type VARCHAR(255) NOT NULL,
|
52 |
+
description TEXT NOT NULL,
|
53 |
+
status VARCHAR(50) NOT NULL,
|
54 |
+
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
55 |
+
);
|
56 |
+
|
57 |
+
-- Insert initial agent interaction data
|
58 |
+
INSERT INTO agent_interactions (tenant_id, agent1, agent2, interaction_type, description, status) VALUES
|
59 |
+
('tenant-1-uuid', 'Sales AI', 'Support Bot', 'Collaboration Request', 'Help with customer issue', 'In Progress'),
|
60 |
+
('tenant-1-uuid', 'Marketing Assistant', 'Data Analyst', 'Knowledge Share', 'Campaign insights', 'Completed'),
|
61 |
+
('tenant-2-uuid', 'HR Coordinator', 'IT Helpdesk', 'Task Handoff', 'New employee onboarding', 'Pending'),
|
62 |
+
('tenant-2-uuid', 'Data Analyst', 'Sales AI', 'Feedback', 'Improve data collection process', 'In Progress'),
|
63 |
+
('tenant-1-uuid', 'All Agents', 'Hive Mind', 'Hive Structure Update', 'Reorganize into specialized clusters', 'Completed'),
|
64 |
+
('tenant-2-uuid', 'Support Bot', 'Support Bot', 'Evolutionary Adaptation', 'Optimize response time by 10%', 'In Progress'),
|
65 |
+
('tenant-1-uuid', 'Project Manager', 'Task Allocation Engine', 'Self-Orchestration', 'Dynamically assign tasks based on agent availability and skills', 'Ongoing');
|
66 |
+
|
67 |
+
-- Enable Row-Level Security (RLS) for all new tables
|
68 |
+
ALTER TABLE agent_data ENABLE ROW LEVEL SECURITY;
|
69 |
+
ALTER TABLE chat_history ENABLE ROW LEVEL SECURITY;
|
70 |
+
ALTER TABLE error_log ENABLE ROW LEVEL SECURITY;
|
71 |
+
ALTER TABLE agent_interactions ENABLE ROW LEVEL SECURITY;
|
72 |
+
|
73 |
+
-- Create RLS policies for agent_data
|
74 |
+
CREATE POLICY "tenant_isolation" ON agent_data
|
75 |
+
FOR ALL
|
76 |
+
USING (tenant_id = current_setting('app.current_tenant')::uuid);
|
77 |
+
|
78 |
+
CREATE POLICY "Enable real-time" ON agent_data
|
79 |
+
FOR SELECT USING (true);
|
80 |
+
|
81 |
+
CREATE POLICY "agent_access" ON agent_data
|
82 |
+
FOR SELECT
|
83 |
+
USING (auth.uid() = user_id);
|
84 |
+
|
85 |
+
-- Create RLS policies for chat_history
|
86 |
+
CREATE POLICY "tenant_isolation" ON chat_history
|
87 |
+
FOR ALL
|
88 |
+
USING (tenant_id = current_setting('app.current_tenant')::uuid);
|
89 |
+
|
90 |
+
CREATE POLICY "Enable real-time" ON chat_history
|
91 |
+
FOR SELECT USING (true);
|
92 |
+
|
93 |
+
CREATE POLICY "chat_access" ON chat_history
|
94 |
+
FOR SELECT
|
95 |
+
USING (auth.uid() = user_id);
|
96 |
+
|
97 |
+
-- Create RLS policies for error_log
|
98 |
+
CREATE POLICY "tenant_isolation" ON error_log
|
99 |
+
FOR ALL
|
100 |
+
USING (tenant_id = current_setting('app.current_tenant')::uuid);
|
101 |
+
|
102 |
+
CREATE POLICY "Enable real-time" ON error_log
|
103 |
+
FOR SELECT USING (true);
|
104 |
+
|
105 |
+
CREATE POLICY "error_access" ON error_log
|
106 |
+
FOR SELECT
|
107 |
+
USING (auth.uid() = user_id);
|
108 |
+
|
109 |
+
-- Create RLS policies for agent_interactions
|
110 |
+
CREATE POLICY "tenant_isolation" ON agent_interactions
|
111 |
+
FOR ALL
|
112 |
+
USING (tenant_id = current_setting('app.current_tenant')::uuid);
|
113 |
+
|
114 |
+
CREATE POLICY "Enable real-time" ON agent_interactions
|
115 |
+
FOR SELECT USING (true);
|
116 |
+
|
117 |
+
CREATE POLICY "interaction_access" ON agent_interactions
|
118 |
+
FOR SELECT
|
119 |
+
USING (auth.uid() = user_id);
|
120 |
+
|
121 |
+
-- Create indexes for optimization
|
122 |
+
CREATE INDEX idx_agent_data_tenant_id ON agent_data(tenant_id);
|
123 |
+
CREATE INDEX idx_chat_history_tenant_id ON chat_history(tenant_id);
|
124 |
+
CREATE INDEX idx_error_log_tenant_id ON error_log(tenant_id);
|
125 |
+
CREATE INDEX idx_agent_interactions_tenant_id ON agent_interactions(tenant_id);
|
sql/agent_interaction.sql
ADDED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
-- Create the table for storing agent interactions
|
2 |
+
CREATE TABLE agent_interactions (
|
3 |
+
id SERIAL PRIMARY KEY,
|
4 |
+
tenant_id UUID NOT NULL,
|
5 |
+
agent1 VARCHAR(255) NOT NULL,
|
6 |
+
agent2 VARCHAR(255) NOT NULL,
|
7 |
+
interaction_type VARCHAR(255) NOT NULL,
|
8 |
+
description TEXT NOT NULL,
|
9 |
+
status VARCHAR(50) NOT NULL,
|
10 |
+
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
11 |
+
);
|
12 |
+
|
13 |
+
-- Insert initial agent interaction data
|
14 |
+
INSERT INTO agent_interactions (tenant_id, agent1, agent2, interaction_type, description, status) VALUES
|
15 |
+
('tenant-1-uuid', 'Sales AI', 'Support Bot', 'Collaboration Request', 'Help with customer issue', 'In Progress'),
|
16 |
+
('tenant-1-uuid', 'Marketing Assistant', 'Data Analyst', 'Knowledge Share', 'Campaign insights', 'Completed'),
|
17 |
+
('tenant-2-uuid', 'HR Coordinator', 'IT Helpdesk', 'Task Handoff', 'New employee onboarding', 'Pending'),
|
18 |
+
('tenant-2-uuid', 'Data Analyst', 'Sales AI', 'Feedback', 'Improve data collection process', 'In Progress'),
|
19 |
+
('tenant-1-uuid', 'All Agents', 'Hive Mind', 'Hive Structure Update', 'Reorganize into specialized clusters', 'Completed'),
|
20 |
+
('tenant-2-uuid', 'Support Bot', 'Support Bot', 'Evolutionary Adaptation', 'Optimize response time by 10%', 'In Progress'),
|
21 |
+
('tenant-1-uuid', 'Project Manager', 'Task Allocation Engine', 'Self-Orchestration', 'Dynamically assign tasks based on agent availability and skills', 'Ongoing');
|
22 |
+
|
23 |
+
-- Enable Row-Level Security (RLS) for agent_interactions table
|
24 |
+
ALTER TABLE agent_interactions ENABLE ROW LEVEL SECURITY;
|
25 |
+
|
26 |
+
-- Create RLS policies for agent_interactions
|
27 |
+
CREATE POLICY "tenant_isolation" ON agent_interactions
|
28 |
+
FOR ALL
|
29 |
+
USING (tenant_id = current_setting('app.current_tenant')::uuid);
|
30 |
+
|
31 |
+
CREATE POLICY "Enable real-time" ON agent_interactions
|
32 |
+
FOR SELECT USING (true);
|
33 |
+
|
34 |
+
CREATE POLICY "interaction_access" ON agent_interactions
|
35 |
+
FOR SELECT
|
36 |
+
USING (auth.uid() = user_id);
|
37 |
+
|
38 |
+
-- Create indexes for optimization
|
39 |
+
CREATE INDEX idx_agent_interactions_tenant_id ON agent_interactions(tenant_id);
|
sql/analytics_reporting.sql
ADDED
@@ -0,0 +1,130 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
-- Create the table for storing agent metrics over time
|
2 |
+
CREATE TABLE agent_metrics (
|
3 |
+
id SERIAL PRIMARY KEY,
|
4 |
+
tenant_id UUID NOT NULL,
|
5 |
+
date DATE NOT NULL,
|
6 |
+
total_agents INT NOT NULL,
|
7 |
+
active_agents INT NOT NULL,
|
8 |
+
tasks_completed INT NOT NULL,
|
9 |
+
avg_rating FLOAT NOT NULL,
|
10 |
+
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
11 |
+
);
|
12 |
+
|
13 |
+
-- Insert sample data into agent_metrics table
|
14 |
+
INSERT INTO agent_metrics (tenant_id, date, total_agents, active_agents, tasks_completed, avg_rating) VALUES
|
15 |
+
('tenant-1-uuid', '2023-01-01', 500, 375, 8000, 4.5),
|
16 |
+
('tenant-1-uuid', '2023-01-08', 525, 395, 8500, 4.52),
|
17 |
+
('tenant-1-uuid', '2023-01-15', 540, 410, 9200, 4.54),
|
18 |
+
('tenant-1-uuid', '2023-01-22', 560, 430, 9800, 4.56),
|
19 |
+
('tenant-1-uuid', '2023-01-29', 575, 445, 10400, 4.58),
|
20 |
+
('tenant-2-uuid', '2023-02-05', 590, 460, 11000, 4.6),
|
21 |
+
('tenant-2-uuid', '2023-02-12', 600, 475, 11600, 4.62),
|
22 |
+
('tenant-2-uuid', '2023-02-19', 615, 490, 12200, 4.64),
|
23 |
+
('tenant-2-uuid', '2023-02-26', 630, 505, 12800, 4.66),
|
24 |
+
('tenant-2-uuid', '2023-03-05', 645, 520, 13400, 4.68),
|
25 |
+
('tenant-1-uuid', '2023-03-12', 660, 535, 14000, 4.7),
|
26 |
+
('tenant-1-uuid', '2023-03-19', 675, 550, 14600, 4.72),
|
27 |
+
('tenant-1-uuid', '2023-03-26', 690, 565, 15200, 4.74),
|
28 |
+
('tenant-1-uuid', '2023-04-02', 700, 580, 15800, 4.76),
|
29 |
+
('tenant-1-uuid', '2023-04-09', 710, 595, 16400, 4.78);
|
30 |
+
|
31 |
+
-- Create the table for storing agent team performance
|
32 |
+
CREATE TABLE agent_teams (
|
33 |
+
id SERIAL PRIMARY KEY,
|
34 |
+
tenant_id UUID NOT NULL,
|
35 |
+
team VARCHAR(255) NOT NULL,
|
36 |
+
agents INT NOT NULL,
|
37 |
+
tasks INT NOT NULL,
|
38 |
+
avg_rating FLOAT NOT NULL,
|
39 |
+
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
40 |
+
);
|
41 |
+
|
42 |
+
-- Insert sample data into agent_teams table
|
43 |
+
INSERT INTO agent_teams (tenant_id, team, agents, tasks, avg_rating) VALUES
|
44 |
+
('tenant-1-uuid', 'Sales', 120, 3200, 4.7),
|
45 |
+
('tenant-1-uuid', 'Support', 180, 4800, 4.75),
|
46 |
+
('tenant-1-uuid', 'Marketing', 95, 2400, 4.65),
|
47 |
+
('tenant-2-uuid', 'Analytics', 65, 1600, 4.8),
|
48 |
+
('tenant-2-uuid', 'HR', 40, 800, 4.72);
|
49 |
+
|
50 |
+
-- Create the table for storing custom reports
|
51 |
+
CREATE TABLE custom_reports (
|
52 |
+
id SERIAL PRIMARY KEY,
|
53 |
+
tenant_id UUID NOT NULL,
|
54 |
+
report_type VARCHAR(255) NOT NULL,
|
55 |
+
report_period VARCHAR(255) NOT NULL,
|
56 |
+
start_date DATE,
|
57 |
+
end_date DATE,
|
58 |
+
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
59 |
+
);
|
60 |
+
|
61 |
+
-- Create the table for storing forecast data
|
62 |
+
CREATE TABLE forecast_data (
|
63 |
+
id SERIAL PRIMARY KEY,
|
64 |
+
tenant_id UUID NOT NULL,
|
65 |
+
metric VARCHAR(255) NOT NULL,
|
66 |
+
period VARCHAR(255) NOT NULL,
|
67 |
+
date DATE NOT NULL,
|
68 |
+
value INT NOT NULL,
|
69 |
+
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
70 |
+
);
|
71 |
+
|
72 |
+
-- Enable Row-Level Security (RLS) for all analytics reporting tables
|
73 |
+
ALTER TABLE agent_metrics ENABLE ROW LEVEL SECURITY;
|
74 |
+
ALTER TABLE agent_teams ENABLE ROW LEVEL SECURITY;
|
75 |
+
ALTER TABLE custom_reports ENABLE ROW LEVEL SECURITY;
|
76 |
+
ALTER TABLE forecast_data ENABLE ROW LEVEL SECURITY;
|
77 |
+
|
78 |
+
-- Create RLS policies for agent_metrics
|
79 |
+
CREATE POLICY "tenant_isolation" ON agent_metrics
|
80 |
+
FOR ALL
|
81 |
+
USING (tenant_id = current_setting('app.current_tenant')::uuid);
|
82 |
+
|
83 |
+
CREATE POLICY "Enable real-time" ON agent_metrics
|
84 |
+
FOR SELECT USING (true);
|
85 |
+
|
86 |
+
CREATE POLICY "metrics_access" ON agent_metrics
|
87 |
+
FOR SELECT
|
88 |
+
USING (auth.uid() = user_id);
|
89 |
+
|
90 |
+
-- Create RLS policies for agent_teams
|
91 |
+
CREATE POLICY "tenant_isolation" ON agent_teams
|
92 |
+
FOR ALL
|
93 |
+
USING (tenant_id = current_setting('app.current_tenant')::uuid);
|
94 |
+
|
95 |
+
CREATE POLICY "Enable real-time" ON agent_teams
|
96 |
+
FOR SELECT USING (true);
|
97 |
+
|
98 |
+
CREATE POLICY "teams_access" ON agent_teams
|
99 |
+
FOR SELECT
|
100 |
+
USING (auth.uid() = user_id);
|
101 |
+
|
102 |
+
-- Create RLS policies for custom_reports
|
103 |
+
CREATE POLICY "tenant_isolation" ON custom_reports
|
104 |
+
FOR ALL
|
105 |
+
USING (tenant_id = current_setting('app.current_tenant')::uuid);
|
106 |
+
|
107 |
+
CREATE POLICY "Enable real-time" ON custom_reports
|
108 |
+
FOR SELECT USING (true);
|
109 |
+
|
110 |
+
CREATE POLICY "reports_access" ON custom_reports
|
111 |
+
FOR SELECT
|
112 |
+
USING (auth.uid() = user_id);
|
113 |
+
|
114 |
+
-- Create RLS policies for forecast_data
|
115 |
+
CREATE POLICY "tenant_isolation" ON forecast_data
|
116 |
+
FOR ALL
|
117 |
+
USING (tenant_id = current_setting('app.current_tenant')::uuid);
|
118 |
+
|
119 |
+
CREATE POLICY "Enable real-time" ON forecast_data
|
120 |
+
FOR SELECT USING (true);
|
121 |
+
|
122 |
+
CREATE POLICY "forecast_access" ON forecast_data
|
123 |
+
FOR SELECT
|
124 |
+
USING (auth.uid() = user_id);
|
125 |
+
|
126 |
+
-- Create indexes for optimization
|
127 |
+
CREATE INDEX idx_agent_metrics_tenant_id ON agent_metrics(tenant_id);
|
128 |
+
CREATE INDEX idx_agent_teams_tenant_id ON agent_teams(tenant_id);
|
129 |
+
CREATE INDEX idx_custom_reports_tenant_id ON custom_reports(tenant_id);
|
130 |
+
CREATE INDEX idx_forecast_data_tenant_id ON forecast_data(tenant_id);
|
sql/chat_history_agent_details.sql
ADDED
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
-- Create the table for storing chat history
|
2 |
+
CREATE TABLE chat_history (
|
3 |
+
id SERIAL PRIMARY KEY,
|
4 |
+
tenant_id UUID NOT NULL,
|
5 |
+
user_message TEXT NOT NULL,
|
6 |
+
bot_response TEXT NOT NULL,
|
7 |
+
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
8 |
+
);
|
9 |
+
|
10 |
+
-- Create the table for storing agent details
|
11 |
+
CREATE TABLE agent_details (
|
12 |
+
id SERIAL PRIMARY KEY,
|
13 |
+
tenant_id UUID NOT NULL,
|
14 |
+
name VARCHAR(255) NOT NULL,
|
15 |
+
type VARCHAR(50) NOT NULL,
|
16 |
+
status VARCHAR(50) NOT NULL,
|
17 |
+
performance FLOAT NOT NULL,
|
18 |
+
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
19 |
+
);
|
20 |
+
|
21 |
+
-- Insert initial agent data
|
22 |
+
INSERT INTO agent_details (tenant_id, name, type, status, performance) VALUES
|
23 |
+
('tenant-1-uuid', 'Sales AI', 'Conversational', 'Active', 4.5),
|
24 |
+
('tenant-1-uuid', 'Support Bot', 'Retrieval-based', 'Active', 4.2),
|
25 |
+
('tenant-2-uuid', 'Marketing Assistant', 'Generative', 'Inactive', 3.8),
|
26 |
+
('tenant-2-uuid', 'Data Analyst', 'Analytical', 'Active', 4.7),
|
27 |
+
('tenant-1-uuid', 'HR Coordinator', 'Conversational', 'Active', 4.1);
|
28 |
+
|
29 |
+
-- Enable Row-Level Security (RLS) for chat_history and agent_details tables
|
30 |
+
ALTER TABLE chat_history ENABLE ROW LEVEL SECURITY;
|
31 |
+
ALTER TABLE agent_details ENABLE ROW LEVEL SECURITY;
|
32 |
+
|
33 |
+
-- Create RLS policies for chat_history
|
34 |
+
CREATE POLICY "tenant_isolation" ON chat_history
|
35 |
+
FOR ALL
|
36 |
+
USING (tenant_id = current_setting('app.current_tenant')::uuid);
|
37 |
+
|
38 |
+
CREATE POLICY "Enable real-time" ON chat_history
|
39 |
+
FOR SELECT USING (true);
|
40 |
+
|
41 |
+
CREATE POLICY "chat_access" ON chat_history
|
42 |
+
FOR SELECT
|
43 |
+
USING (auth.uid() = user_id);
|
44 |
+
|
45 |
+
-- Create RLS policies for agent_details
|
46 |
+
CREATE POLICY "tenant_isolation" ON agent_details
|
47 |
+
FOR ALL
|
48 |
+
USING (tenant_id = current_setting('app.current_tenant')::uuid);
|
49 |
+
|
50 |
+
CREATE POLICY "Enable real-time" ON agent_details
|
51 |
+
FOR SELECT USING (true);
|
52 |
+
|
53 |
+
CREATE POLICY "agent_access" ON agent_details
|
54 |
+
FOR SELECT
|
55 |
+
USING (auth.uid() = user_id);
|
56 |
+
|
57 |
+
-- Create indexes for optimization
|
58 |
+
CREATE INDEX idx_chat_history_tenant_id ON chat_history(tenant_id);
|
59 |
+
CREATE INDEX idx_agent_details_tenant_id ON agent_details(tenant_id);
|
sql/command_control.sql
ADDED
@@ -0,0 +1,89 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
-- Create the table for storing agent data
|
2 |
+
CREATE TABLE agent_data (
|
3 |
+
agent_id SERIAL PRIMARY KEY,
|
4 |
+
tenant_id UUID NOT NULL,
|
5 |
+
agent_name VARCHAR(255) NOT NULL,
|
6 |
+
status VARCHAR(50) NOT NULL,
|
7 |
+
current_task VARCHAR(255) NOT NULL,
|
8 |
+
performance_metrics VARCHAR(50) NOT NULL,
|
9 |
+
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
10 |
+
);
|
11 |
+
|
12 |
+
-- Insert initial agent data
|
13 |
+
INSERT INTO agent_data (tenant_id, agent_name, status, current_task, performance_metrics) VALUES
|
14 |
+
('tenant-1-uuid', 'NLP Agent', 'Active', 'Text Processing', 'High'),
|
15 |
+
('tenant-1-uuid', 'Vision Agent', 'Idle', 'Image Classification', 'Medium'),
|
16 |
+
('tenant-2-uuid', 'Data Agent', 'Failed', 'Data Cleaning', 'Low'),
|
17 |
+
('tenant-2-uuid', 'Chatbot', 'Active', 'Customer Service', 'High'),
|
18 |
+
('tenant-1-uuid', 'Analysis Agent', 'Idle', 'Data Analysis', 'Medium');
|
19 |
+
|
20 |
+
-- Create the table for storing chat history
|
21 |
+
CREATE TABLE chat_history (
|
22 |
+
id SERIAL PRIMARY KEY,
|
23 |
+
tenant_id UUID NOT NULL,
|
24 |
+
user_message TEXT NOT NULL,
|
25 |
+
bot_response TEXT NOT NULL,
|
26 |
+
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
27 |
+
);
|
28 |
+
|
29 |
+
-- Create the table for storing error logs
|
30 |
+
CREATE TABLE error_log (
|
31 |
+
id SERIAL PRIMARY KEY,
|
32 |
+
tenant_id UUID NOT NULL,
|
33 |
+
time TIMESTAMP NOT NULL,
|
34 |
+
agent_id INT REFERENCES agent_data(agent_id),
|
35 |
+
error_type VARCHAR(255) NOT NULL,
|
36 |
+
message TEXT NOT NULL,
|
37 |
+
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
38 |
+
);
|
39 |
+
|
40 |
+
-- Insert initial error log data
|
41 |
+
INSERT INTO error_log (tenant_id, time, agent_id, error_type, message) VALUES
|
42 |
+
('tenant-1-uuid', '2024-05-15 12:01:00', 3, 'Connection Timeout', 'Failed to connect to the database'),
|
43 |
+
('tenant-2-uuid', '2024-05-15 12:05:00', 5, 'Memory Overflow', 'Exceeded memory limits during data processing');
|
44 |
+
|
45 |
+
-- Enable Row-Level Security (RLS) for agent_data, chat_history, and error_log tables
|
46 |
+
ALTER TABLE agent_data ENABLE ROW LEVEL SECURITY;
|
47 |
+
ALTER TABLE chat_history ENABLE ROW LEVEL SECURITY;
|
48 |
+
ALTER TABLE error_log ENABLE ROW LEVEL SECURITY;
|
49 |
+
|
50 |
+
-- Create RLS policies for agent_data
|
51 |
+
CREATE POLICY "tenant_isolation" ON agent_data
|
52 |
+
FOR ALL
|
53 |
+
USING (tenant_id = current_setting('app.current_tenant')::uuid);
|
54 |
+
|
55 |
+
CREATE POLICY "Enable real-time" ON agent_data
|
56 |
+
FOR SELECT USING (true);
|
57 |
+
|
58 |
+
CREATE POLICY "agent_access" ON agent_data
|
59 |
+
FOR SELECT
|
60 |
+
USING (auth.uid() = user_id);
|
61 |
+
|
62 |
+
-- Create RLS policies for chat_history
|
63 |
+
CREATE POLICY "tenant_isolation" ON chat_history
|
64 |
+
FOR ALL
|
65 |
+
USING (tenant_id = current_setting('app.current_tenant')::uuid);
|
66 |
+
|
67 |
+
CREATE POLICY "Enable real-time" ON chat_history
|
68 |
+
FOR SELECT USING (true);
|
69 |
+
|
70 |
+
CREATE POLICY "chat_access" ON chat_history
|
71 |
+
FOR SELECT
|
72 |
+
USING (auth.uid() = user_id);
|
73 |
+
|
74 |
+
-- Create RLS policies for error_log
|
75 |
+
CREATE POLICY "tenant_isolation" ON error_log
|
76 |
+
FOR ALL
|
77 |
+
USING (tenant_id = current_setting('app.current_tenant')::uuid);
|
78 |
+
|
79 |
+
CREATE POLICY "Enable real-time" ON error_log
|
80 |
+
FOR SELECT USING (true);
|
81 |
+
|
82 |
+
CREATE POLICY "error_access" ON error_log
|
83 |
+
FOR SELECT
|
84 |
+
USING (auth.uid() = user_id);
|
85 |
+
|
86 |
+
-- Create indexes for optimization
|
87 |
+
CREATE INDEX idx_agent_data_tenant_id ON agent_data(tenant_id);
|
88 |
+
CREATE INDEX idx_chat_history_tenant_id ON chat_history(tenant_id);
|
89 |
+
CREATE INDEX idx_error_log_tenant_id ON error_log(tenant_id);
|
sql/documentation.sql
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
-- Create the table for storing documentation
|
2 |
+
CREATE TABLE documentation (
|
3 |
+
id SERIAL PRIMARY KEY,
|
4 |
+
tenant_id UUID NOT NULL,
|
5 |
+
doc_type VARCHAR(255) NOT NULL,
|
6 |
+
title VARCHAR(255) NOT NULL,
|
7 |
+
content TEXT NOT NULL,
|
8 |
+
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
9 |
+
);
|
10 |
+
|
11 |
+
-- Insert initial documentation data
|
12 |
+
INSERT INTO documentation (tenant_id, doc_type, title, content) VALUES
|
13 |
+
('tenant-1-uuid', 'User Guide', 'Getting Started with Agents', 'This guide will help you get started with setting up and managing agents.'),
|
14 |
+
('tenant-1-uuid', 'API Reference', 'Agent API Endpoints', 'This document provides details on the API endpoints available for agent management.'),
|
15 |
+
('tenant-2-uuid', 'User Guide', 'Advanced Agent Configuration', 'This guide covers advanced configuration options for agents.'),
|
16 |
+
('tenant-2-uuid', 'Compliance', 'Data Privacy Policies', 'This document outlines the data privacy policies applicable to agents.');
|
17 |
+
|
18 |
+
-- Enable Row-Level Security (RLS) for the documentation table
|
19 |
+
ALTER TABLE documentation ENABLE ROW LEVEL SECURITY;
|
20 |
+
|
21 |
+
-- Create RLS policies for documentation
|
22 |
+
CREATE POLICY "tenant_isolation" ON documentation
|
23 |
+
FOR ALL
|
24 |
+
USING (tenant_id = current_setting('app.current_tenant')::uuid);
|
25 |
+
|
26 |
+
CREATE POLICY "Enable real-time" ON documentation
|
27 |
+
FOR SELECT USING (true);
|
28 |
+
|
29 |
+
CREATE POLICY "documentation_access" ON documentation
|
30 |
+
FOR SELECT
|
31 |
+
USING (auth.uid() = user_id);
|
32 |
+
|
33 |
+
-- Create indexes for optimization
|
34 |
+
CREATE INDEX idx_documentation_tenant_id ON documentation(tenant_id);
|
sql/governance.sql
ADDED
@@ -0,0 +1,134 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
-- Create the table for storing boundaries and constraints
|
2 |
+
CREATE TABLE boundaries (
|
3 |
+
id SERIAL PRIMARY KEY,
|
4 |
+
tenant_id UUID NOT NULL,
|
5 |
+
boundary_type VARCHAR(255) NOT NULL,
|
6 |
+
description TEXT NOT NULL,
|
7 |
+
status VARCHAR(50) NOT NULL,
|
8 |
+
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
9 |
+
);
|
10 |
+
|
11 |
+
-- Insert initial boundary data
|
12 |
+
INSERT INTO boundaries (tenant_id, boundary_type, description, status) VALUES
|
13 |
+
('tenant-1-uuid', 'Ethical', 'Ensure agents adhere to company values and principles', 'Active'),
|
14 |
+
('tenant-1-uuid', 'Legal', 'Comply with all relevant laws and regulations', 'Active'),
|
15 |
+
('tenant-2-uuid', 'Operational', 'Maintain service level agreements and uptime targets', 'Active'),
|
16 |
+
('tenant-2-uuid', 'Financial', 'Stay within allocated budgets and resource limits', 'Warning'),
|
17 |
+
('tenant-1-uuid', 'Reputational', 'Protect company brand and public image', 'Active');
|
18 |
+
|
19 |
+
-- Create the table for storing human feedback
|
20 |
+
CREATE TABLE human_feedback (
|
21 |
+
id SERIAL PRIMARY KEY,
|
22 |
+
tenant_id UUID NOT NULL,
|
23 |
+
agent VARCHAR(255) NOT NULL,
|
24 |
+
task TEXT NOT NULL,
|
25 |
+
feedback_type VARCHAR(255) NOT NULL,
|
26 |
+
feedback_details TEXT NOT NULL,
|
27 |
+
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
28 |
+
);
|
29 |
+
|
30 |
+
-- Insert initial human feedback data
|
31 |
+
INSERT INTO human_feedback (tenant_id, agent, task, feedback_type, feedback_details) VALUES
|
32 |
+
('tenant-1-uuid', 'Sales AI', 'Generated product description', 'Approval', 'Great job, the description is accurate and compelling'),
|
33 |
+
('tenant-1-uuid', 'Support Bot', 'Handled customer complaint', 'Modification', 'The response was a bit too formal, try to be more empathetic'),
|
34 |
+
('tenant-2-uuid', 'Marketing Assistant', 'Created ad campaign', 'Clarification', 'What is the target audience for this campaign?'),
|
35 |
+
('tenant-2-uuid', 'Data Analyst', 'Provided sales forecast', 'Approval', 'The forecast looks solid, well done'),
|
36 |
+
('tenant-1-uuid', 'HR Coordinator', 'Sent onboarding email', 'Rejection', 'The email contains outdated information, please update');
|
37 |
+
|
38 |
+
-- Create the table for storing output reviews
|
39 |
+
CREATE TABLE output_reviews (
|
40 |
+
id SERIAL PRIMARY KEY,
|
41 |
+
tenant_id UUID NOT NULL,
|
42 |
+
output_type VARCHAR(255) NOT NULL,
|
43 |
+
output_name TEXT NOT NULL,
|
44 |
+
agent VARCHAR(255) NOT NULL,
|
45 |
+
review_status VARCHAR(50) NOT NULL,
|
46 |
+
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
47 |
+
);
|
48 |
+
|
49 |
+
-- Insert initial output review data
|
50 |
+
INSERT INTO output_reviews (tenant_id, output_type, output_name, agent, review_status) VALUES
|
51 |
+
('tenant-1-uuid', 'Blog post', 'Top 10 AI Trends for 2025', 'Marketing Assistant', 'Pending'),
|
52 |
+
('tenant-1-uuid', 'Financial report', 'Q3 2024 Earnings Analysis', 'Data Analyst', 'Approved'),
|
53 |
+
('tenant-2-uuid', 'Product design', 'Smartwatch UI Mockups', 'Design AI', 'Rejected'),
|
54 |
+
('tenant-2-uuid', 'Customer email', 'Response to Billing Inquiry', 'Support Bot', 'Approved'),
|
55 |
+
('tenant-1-uuid', 'News article', 'Company Announces New AI Partnership', 'Content Creator', 'Pending');
|
56 |
+
|
57 |
+
-- Create the table for storing alerts and notifications
|
58 |
+
CREATE TABLE alerts (
|
59 |
+
id SERIAL PRIMARY KEY,
|
60 |
+
tenant_id UUID NOT NULL,
|
61 |
+
alert_type VARCHAR(255) NOT NULL,
|
62 |
+
description TEXT NOT NULL,
|
63 |
+
urgency VARCHAR(50) NOT NULL,
|
64 |
+
status VARCHAR(50) NOT NULL,
|
65 |
+
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
66 |
+
);
|
67 |
+
|
68 |
+
-- Insert initial alert data
|
69 |
+
INSERT INTO alerts (tenant_id, alert_type, description, urgency, status) VALUES
|
70 |
+
('tenant-1-uuid', 'Boundary Violation', 'Sales AI attempted to access restricted data', 'High', 'Unresolved'),
|
71 |
+
('tenant-1-uuid', 'Anomalous Behavior', 'Support Bot response time increased by 150%', 'Medium', 'Under Investigation'),
|
72 |
+
('tenant-2-uuid', 'System Error', 'Marketing Assistant encountered a memory leak', 'Critical', 'Resolved'),
|
73 |
+
('tenant-2-uuid', 'Human Feedback Required', 'Data Analyst report requires manager approval', 'Low', 'Pending'),
|
74 |
+
('tenant-1-uuid', 'Boundary Violation', 'HR Coordinator tried to modify employee records without authorization', 'High', 'Unresolved');
|
75 |
+
|
76 |
+
-- Enable Row-Level Security (RLS) for all governance tables
|
77 |
+
ALTER TABLE boundaries ENABLE ROW LEVEL SECURITY;
|
78 |
+
ALTER TABLE human_feedback ENABLE ROW LEVEL SECURITY;
|
79 |
+
ALTER TABLE output_reviews ENABLE ROW LEVEL SECURITY;
|
80 |
+
ALTER TABLE alerts ENABLE ROW LEVEL SECURITY;
|
81 |
+
|
82 |
+
-- Create RLS policies for boundaries
|
83 |
+
CREATE POLICY "tenant_isolation" ON boundaries
|
84 |
+
FOR ALL
|
85 |
+
USING (tenant_id = current_setting('app.current_tenant')::uuid);
|
86 |
+
|
87 |
+
CREATE POLICY "Enable real-time" ON boundaries
|
88 |
+
FOR SELECT USING (true);
|
89 |
+
|
90 |
+
CREATE POLICY "boundary_access" ON boundaries
|
91 |
+
FOR SELECT
|
92 |
+
USING (auth.uid() = user_id);
|
93 |
+
|
94 |
+
-- Create RLS policies for human_feedback
|
95 |
+
CREATE POLICY "tenant_isolation" ON human_feedback
|
96 |
+
FOR ALL
|
97 |
+
USING (tenant_id = current_setting('app.current_tenant')::uuid);
|
98 |
+
|
99 |
+
CREATE POLICY "Enable real-time" ON human_feedback
|
100 |
+
FOR SELECT USING (true);
|
101 |
+
|
102 |
+
CREATE POLICY "feedback_access" ON human_feedback
|
103 |
+
FOR SELECT
|
104 |
+
USING (auth.uid() = user_id);
|
105 |
+
|
106 |
+
-- Create RLS policies for output_reviews
|
107 |
+
CREATE POLICY "tenant_isolation" ON output_reviews
|
108 |
+
FOR ALL
|
109 |
+
USING (tenant_id = current_setting('app.current_tenant')::uuid);
|
110 |
+
|
111 |
+
CREATE POLICY "Enable real-time" ON output_reviews
|
112 |
+
FOR SELECT USING (true);
|
113 |
+
|
114 |
+
CREATE POLICY "review_access" ON output_reviews
|
115 |
+
FOR SELECT
|
116 |
+
USING (auth.uid() = user_id);
|
117 |
+
|
118 |
+
-- Create RLS policies for alerts
|
119 |
+
CREATE POLICY "tenant_isolation" ON alerts
|
120 |
+
FOR ALL
|
121 |
+
USING (tenant_id = current_setting('app.current_tenant')::uuid);
|
122 |
+
|
123 |
+
CREATE POLICY "Enable real-time" ON alerts
|
124 |
+
FOR SELECT USING (true);
|
125 |
+
|
126 |
+
CREATE POLICY "alert_access" ON alerts
|
127 |
+
FOR SELECT
|
128 |
+
USING (auth.uid() = user_id);
|
129 |
+
|
130 |
+
-- Create indexes for optimization
|
131 |
+
CREATE INDEX idx_boundaries_tenant_id ON boundaries(tenant_id);
|
132 |
+
CREATE INDEX idx_human_feedback_tenant_id ON human_feedback(tenant_id);
|
133 |
+
CREATE INDEX idx_output_reviews_tenant_id ON output_reviews(tenant_id);
|
134 |
+
CREATE INDEX idx_alerts_tenant_id ON alerts(tenant_id);
|
sql/readme.md
ADDED
@@ -0,0 +1,213 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Agentic Employment Data Structure
|
2 |
+
|
3 |
+
## Overview
|
4 |
+
Agentic Employment Data Structure utilizes Supabase to manage and interact with SQL databases. The repository includes several SQL scripts for setting up and maintaining various components of the system, such as user management, agent interactions, analytics reporting, command control, documentation, governance, and system settings.
|
5 |
+
|
6 |
+
## Database Structure
|
7 |
+
|
8 |
+
### Tables
|
9 |
+
|
10 |
+
#### users
|
11 |
+
The `users` table is designed to store user information with the following columns:
|
12 |
+
- `id`: A UUID that serves as the primary key and is generated by default.
|
13 |
+
- `email`: A unique email address for each user.
|
14 |
+
- `password_hash`: A hashed version of the user's password.
|
15 |
+
- `role`: The role of the user (e.g., admin, user).
|
16 |
+
- `tenant_id`: A UUID that identifies the tenant to which the user belongs.
|
17 |
+
- `created_at`: A timestamp indicating when the user was created, with a default value of the current timestamp.
|
18 |
+
|
19 |
+
#### agents
|
20 |
+
The `agents` table is designed to store agent information with the following columns:
|
21 |
+
- `id`: A serial primary key.
|
22 |
+
- `user_id`: A UUID that references the `id` in the `users` table.
|
23 |
+
- `tenant_id`: A UUID that identifies the tenant to which the agent belongs.
|
24 |
+
- `name`: The name of the agent.
|
25 |
+
- `type`: The type of the agent (e.g., Conversational, Analytical).
|
26 |
+
- `status`: The current status of the agent (e.g., Active, Idle, Failed).
|
27 |
+
- `description`: A text description of the agent.
|
28 |
+
- `avatar_url`: A URL to the agent's avatar image.
|
29 |
+
- `llm_base`: The base language model used by the agent.
|
30 |
+
- `prompt`: The prompt used by the agent.
|
31 |
+
- `knowledge_base_url`: A URL to the agent's knowledge base.
|
32 |
+
- `learning_rate`: The learning rate for the agent's training.
|
33 |
+
- `exploration_rate`: The exploration rate for the agent's training.
|
34 |
+
- `training_iterations`: The number of training iterations.
|
35 |
+
- `batch_size`: The batch size for training.
|
36 |
+
- `max_tokens`: The maximum number of tokens the agent can generate.
|
37 |
+
- `temperature`: The temperature setting for the agent's language model.
|
38 |
+
- `top_p`: The top-p sampling parameter.
|
39 |
+
- `frequency_penalty`: The frequency penalty parameter.
|
40 |
+
- `presence_penalty`: The presence penalty parameter.
|
41 |
+
- `stop_sequences`: The stop sequences for the agent.
|
42 |
+
- `created_at`: A timestamp indicating when the agent was created, with a default value of the current timestamp.
|
43 |
+
|
44 |
+
#### agent_data
|
45 |
+
The `agent_data` table contains information related to agents with the following columns:
|
46 |
+
- `id`: A serial primary key.
|
47 |
+
- `name`: The name of the agent.
|
48 |
+
- `email`: The email address of the agent.
|
49 |
+
- `role`: The role of the agent.
|
50 |
+
- `created_at`: A timestamp indicating when the agent was created.
|
51 |
+
|
52 |
+
#### agent_interaction
|
53 |
+
The `agent_interaction` table records interactions between users and agents with the following columns:
|
54 |
+
- `id`: A serial primary key.
|
55 |
+
- `user_id`: An integer referencing the `id` in the `users` table.
|
56 |
+
- `agent_id`: An integer referencing the `id` in the `agents` table.
|
57 |
+
- `interaction_time`: A timestamp indicating when the interaction occurred.
|
58 |
+
- `details`: A text field containing details of the interaction.
|
59 |
+
|
60 |
+
#### analytics_reporting
|
61 |
+
The `analytics_reporting` table stores data used for generating analytics reports with the following columns:
|
62 |
+
- `id`: A serial primary key.
|
63 |
+
- `report_name`: A varchar for the name of the report.
|
64 |
+
- `generated_at`: A timestamp indicating when the report was generated.
|
65 |
+
- `data`: A JSONB field containing the report data.
|
66 |
+
|
67 |
+
#### chat_history_agent_details
|
68 |
+
The `chat_history_agent_details` table is designed to log the details of chat histories involving agents with the following columns:
|
69 |
+
- `id`: A serial primary key.
|
70 |
+
- `chat_id`: An integer referencing the `id` in the `chat` table.
|
71 |
+
- `agent_id`: An integer referencing the `id` in the `agents` table.
|
72 |
+
- `message`: A text field containing the chat message.
|
73 |
+
- `timestamp`: A timestamp indicating when the message was sent.
|
74 |
+
|
75 |
+
#### command_control
|
76 |
+
The `command_control` table manages command and control data for the system with the following columns:
|
77 |
+
- `id`: A serial primary key.
|
78 |
+
- `command`: A varchar for the command.
|
79 |
+
- `description`: A text field describing the command.
|
80 |
+
- `executed_at`: A timestamp indicating when the command was executed.
|
81 |
+
|
82 |
+
#### documentation
|
83 |
+
The `documentation` table holds documentation related to various system components with the following columns:
|
84 |
+
- `id`: A serial primary key.
|
85 |
+
- `doc_title`: A varchar for the title of the document.
|
86 |
+
- `content`: A text field containing the document content.
|
87 |
+
- `created_at`: A timestamp indicating when the document was created.
|
88 |
+
|
89 |
+
#### governance
|
90 |
+
The `governance` table contains governance-related information and policies with the following columns:
|
91 |
+
- `id`: A serial primary key.
|
92 |
+
- `policy_name`: A varchar for the name of the policy.
|
93 |
+
- `description`: A text field describing the policy.
|
94 |
+
- `enacted_at`: A timestamp indicating when the policy was enacted.
|
95 |
+
|
96 |
+
#### system_settings
|
97 |
+
The `system_settings` table stores system configuration settings with the following columns:
|
98 |
+
- `id`: A serial primary key.
|
99 |
+
- `setting_name`: A varchar for the name of the setting.
|
100 |
+
- `value`: A varchar for the setting value.
|
101 |
+
- `updated_at`: A timestamp indicating when the setting was last updated.
|
102 |
+
|
103 |
+
#### users_agents
|
104 |
+
The `users_agents` table manages user and agent information with the following columns:
|
105 |
+
- `id`: A serial primary key.
|
106 |
+
- `user_id`: An integer referencing the `id` in the `users` table.
|
107 |
+
- `agent_id`: An integer referencing the `id` in the `agents` table.
|
108 |
+
- `assigned_at`: A timestamp indicating when the user was assigned to the agent.
|
109 |
+
|
110 |
+
## Security and Policies
|
111 |
+
|
112 |
+
### Authentication
|
113 |
+
- Ensure all database connections are authenticated using secure tokens or credentials provided by Supabase.
|
114 |
+
- Use environment variables to manage sensitive information.
|
115 |
+
|
116 |
+
### Authorization
|
117 |
+
- Implement role-based access control (RBAC) to restrict access to specific tables and actions based on user roles.
|
118 |
+
- Define policies in Supabase to manage read, write, and delete permissions.
|
119 |
+
|
120 |
+
### Data Privacy
|
121 |
+
- Encrypt sensitive data both at rest and in transit.
|
122 |
+
- Regularly audit data access logs to detect and respond to unauthorized access.
|
123 |
+
|
124 |
+
### Backup and Recovery
|
125 |
+
- Schedule regular backups of the database to prevent data loss.
|
126 |
+
- Test recovery procedures periodically to ensure data integrity and availability.
|
127 |
+
|
128 |
+
## Row-Level Security (RLS)
|
129 |
+
|
130 |
+
Row-Level Security is enabled for all tables to ensure data isolation between tenants:
|
131 |
+
```sql
|
132 |
+
ALTER TABLE users ENABLE ROW LEVEL SECURITY;
|
133 |
+
ALTER TABLE agents ENABLE ROW LEVEL SECURITY;
|
134 |
+
ALTER TABLE agent_data ENABLE ROW LEVEL SECURITY;
|
135 |
+
ALTER TABLE agent_interaction ENABLE ROW LEVEL SECURITY;
|
136 |
+
ALTER TABLE analytics_reporting ENABLE ROW LEVEL SECURITY;
|
137 |
+
ALTER TABLE chat_history_agent_details ENABLE ROW LEVEL SECURITY;
|
138 |
+
ALTER TABLE command_control ENABLE ROW LEVEL SECURITY;
|
139 |
+
ALTER TABLE documentation ENABLE ROW LEVEL SECURITY;
|
140 |
+
ALTER TABLE governance ENABLE ROW LEVEL SECURITY;
|
141 |
+
ALTER TABLE system_settings ENABLE ROW LEVEL SECURITY;
|
142 |
+
ALTER TABLE users_agents ENABLE ROW LEVEL SECURITY;
|
143 |
+
```
|
144 |
+
|
145 |
+
### RLS Policies
|
146 |
+
Several RLS policies are created to enforce tenant isolation and real-time access:
|
147 |
+
```sql
|
148 |
+
CREATE POLICY "tenant_isolation" ON users FOR ALL USING (tenant_id = current_setting('app.current_tenant')::uuid);
|
149 |
+
CREATE POLICY "tenant_isolation" ON agents FOR ALL USING (tenant_id = current_setting('app.current_tenant')::uuid);
|
150 |
+
CREATE POLICY "tenant_isolation" ON agent_data FOR ALL USING (tenant_id = current_setting('app.current_tenant')::uuid);
|
151 |
+
CREATE POLICY "tenant_isolation" ON agent_interaction FOR ALL USING (tenant_id = current_setting('app.current_tenant')::uuid);
|
152 |
+
CREATE POLICY "tenant_isolation" ON analytics_reporting FOR ALL USING (tenant_id = current_setting('app.current_tenant')::uuid);
|
153 |
+
CREATE POLICY "tenant_isolation" ON chat_history_agent_details FOR ALL USING (tenant_id = current_setting('app.current_tenant')::uuid);
|
154 |
+
CREATE POLICY "tenant_isolation" ON command_control FOR ALL USING (tenant_id = current_setting('app.current_tenant')::uuid);
|
155 |
+
CREATE POLICY "tenant_isolation" ON documentation FOR ALL USING (tenant_id = current_setting('app.current_tenant')::uuid);
|
156 |
+
CREATE POLICY "tenant_isolation" ON governance FOR ALL USING (tenant_id = current_setting('app.current_tenant')::uuid);
|
157 |
+
CREATE POLICY "tenant_isolation" ON system_settings FOR ALL USING (tenant_id = current_setting('app.current_tenant')::uuid);
|
158 |
+
CREATE POLICY "tenant_isolation" ON users_agents FOR ALL USING (tenant_id = current_setting('app.current_tenant')::uuid);
|
159 |
+
|
160 |
+
CREATE POLICY "Enable real-time" ON users FOR SELECT USING (true);
|
161 |
+
CREATE POLICY "Enable real-time" ON agents FOR SELECT USING (true);
|
162 |
+
CREATE POLICY "Enable real-time" ON agent_data FOR SELECT USING (true);
|
163 |
+
CREATE POLICY "Enable real-time" ON agent_interaction FOR SELECT USING (true);
|
164 |
+
CREATE POLICY "Enable real-time" ON analytics_reporting FOR SELECT USING (true);
|
165 |
+
CREATE POLICY "Enable real-time" ON chat_history_agent_details FOR SELECT USING (true);
|
166 |
+
CREATE POLICY "Enable real-time" ON command_control FOR SELECT USING (true);
|
167 |
+
CREATE POLICY "Enable real-time" ON documentation FOR SELECT USING (true);
|
168 |
+
CREATE POLICY "Enable
|
169 |
+
|
170 |
+
real-time" ON governance FOR SELECT USING (true);
|
171 |
+
CREATE POLICY "Enable real-time" ON system_settings FOR SELECT USING (true);
|
172 |
+
CREATE POLICY "Enable real-time" ON users_agents FOR SELECT USING (true);
|
173 |
+
|
174 |
+
CREATE POLICY "user_access" ON users FOR SELECT USING (auth.uid() = id);
|
175 |
+
CREATE POLICY "agent_access" ON agents FOR SELECT USING (auth.uid() = user_id);
|
176 |
+
```
|
177 |
+
|
178 |
+
### Indexes
|
179 |
+
Indexes are created on the `tenant_id` columns to optimize queries:
|
180 |
+
```sql
|
181 |
+
CREATE INDEX idx_users_tenant_id ON users(tenant_id);
|
182 |
+
CREATE INDEX idx_agents_tenant_id ON agents(tenant_id);
|
183 |
+
CREATE INDEX idx_agent_data_tenant_id ON agent_data(tenant_id);
|
184 |
+
CREATE INDEX idx_agent_interaction_tenant_id ON agent_interaction(tenant_id);
|
185 |
+
CREATE INDEX idx_analytics_reporting_tenant_id ON analytics_reporting(tenant_id);
|
186 |
+
CREATE INDEX idx_chat_history_agent_details_tenant_id ON chat_history_agent_details(tenant_id);
|
187 |
+
CREATE INDEX idx_command_control_tenant_id ON command_control(tenant_id);
|
188 |
+
CREATE INDEX idx_documentation_tenant_id ON documentation(tenant_id);
|
189 |
+
CREATE INDEX idx_governance_tenant_id ON governance(tenant_id);
|
190 |
+
CREATE INDEX idx_system_settings_tenant_id ON system_settings(tenant_id);
|
191 |
+
CREATE INDEX idx_users_agents_tenant_id ON users_agents(tenant_id);
|
192 |
+
```
|
193 |
+
|
194 |
+
## How to Use
|
195 |
+
|
196 |
+
### Setting Up the Database
|
197 |
+
1. Clone the repository:
|
198 |
+
```sh
|
199 |
+
git clone https://github.com/yourusername/supabase-sql.git
|
200 |
+
cd supabase-sql
|
201 |
+
```
|
202 |
+
|
203 |
+
2. Configure your Supabase environment variables in a `.env` file:
|
204 |
+
```env
|
205 |
+
SUPABASE_URL=your-supabase-url
|
206 |
+
SUPABASE_ANON_KEY=your-anon-key
|
207 |
+
SUPABASE_SERVICE_KEY=your-service-key
|
208 |
+
```
|
209 |
+
|
210 |
+
3. Run the SQL scripts to set up the database structure:
|
211 |
+
```sh
|
212 |
+
psql -h your-supabase-url -U your-username -d your-database -f path/to/sql_script.sql
|
213 |
+
```
|
sql/system_settings.sql
ADDED
@@ -0,0 +1,92 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
-- Create the table for storing agent parameters
|
2 |
+
CREATE TABLE agent_parameters (
|
3 |
+
id SERIAL PRIMARY KEY,
|
4 |
+
tenant_id UUID NOT NULL,
|
5 |
+
default_learning_rate FLOAT NOT NULL,
|
6 |
+
default_exploration_rate FLOAT NOT NULL,
|
7 |
+
agent_types TEXT[] NOT NULL,
|
8 |
+
agent_specializations TEXT[] NOT NULL,
|
9 |
+
reward_structure VARCHAR(50) NOT NULL,
|
10 |
+
max_tokens INT NOT NULL,
|
11 |
+
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
12 |
+
);
|
13 |
+
|
14 |
+
-- Insert initial agent parameters data
|
15 |
+
INSERT INTO agent_parameters (tenant_id, default_learning_rate, default_exploration_rate, agent_types, agent_specializations, reward_structure, max_tokens) VALUES
|
16 |
+
('tenant-1-uuid', 0.1, 0.1, ARRAY['Conversational', 'Retrieval-based'], ARRAY['Sales', 'Support'], 'Fixed', 512);
|
17 |
+
|
18 |
+
-- Create the table for storing resource management settings
|
19 |
+
CREATE TABLE resource_management (
|
20 |
+
id SERIAL PRIMARY KEY,
|
21 |
+
tenant_id UUID NOT NULL,
|
22 |
+
max_compute_usage INT NOT NULL,
|
23 |
+
max_storage_usage INT NOT NULL,
|
24 |
+
cost_per_compute_hour FLOAT NOT NULL,
|
25 |
+
cost_per_gb_storage FLOAT NOT NULL,
|
26 |
+
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
27 |
+
);
|
28 |
+
|
29 |
+
-- Insert initial resource management data
|
30 |
+
INSERT INTO resource_management (tenant_id, max_compute_usage, max_storage_usage, cost_per_compute_hour, cost_per_gb_storage) VALUES
|
31 |
+
('tenant-1-uuid', 10000, 1000, 0.05, 0.02);
|
32 |
+
|
33 |
+
-- Create the table for storing access and permissions settings
|
34 |
+
CREATE TABLE access_permissions (
|
35 |
+
id SERIAL PRIMARY KEY,
|
36 |
+
tenant_id UUID NOT NULL,
|
37 |
+
user_roles TEXT[] NOT NULL,
|
38 |
+
enable_api_access BOOLEAN NOT NULL,
|
39 |
+
api_rate_limit INT NOT NULL,
|
40 |
+
enable_logging BOOLEAN NOT NULL,
|
41 |
+
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
42 |
+
);
|
43 |
+
|
44 |
+
-- Insert initial access and permissions data
|
45 |
+
INSERT INTO access_permissions (tenant_id, user_roles, enable_api_access, api_rate_limit, enable_logging) VALUES
|
46 |
+
('tenant-1-uuid', ARRAY['Administrator', 'Developer'], TRUE, 1000, TRUE);
|
47 |
+
|
48 |
+
-- Enable Row-Level Security (RLS) for all system settings tables
|
49 |
+
ALTER TABLE agent_parameters ENABLE ROW LEVEL SECURITY;
|
50 |
+
ALTER TABLE resource_management ENABLE ROW LEVEL SECURITY;
|
51 |
+
ALTER TABLE access_permissions ENABLE ROW LEVEL SECURITY;
|
52 |
+
|
53 |
+
-- Create RLS policies for agent_parameters
|
54 |
+
CREATE POLICY "tenant_isolation" ON agent_parameters
|
55 |
+
FOR ALL
|
56 |
+
USING (tenant_id = current_setting('app.current_tenant')::uuid);
|
57 |
+
|
58 |
+
CREATE POLICY "Enable real-time" ON agent_parameters
|
59 |
+
FOR SELECT USING (true);
|
60 |
+
|
61 |
+
CREATE POLICY "parameters_access" ON agent_parameters
|
62 |
+
FOR SELECT
|
63 |
+
USING (auth.uid() = user_id);
|
64 |
+
|
65 |
+
-- Create RLS policies for resource_management
|
66 |
+
CREATE POLICY "tenant_isolation" ON resource_management
|
67 |
+
FOR ALL
|
68 |
+
USING (tenant_id = current_setting('app.current_tenant')::uuid);
|
69 |
+
|
70 |
+
CREATE POLICY "Enable real-time" ON resource_management
|
71 |
+
FOR SELECT USING (true);
|
72 |
+
|
73 |
+
CREATE POLICY "resource_access" ON resource_management
|
74 |
+
FOR SELECT
|
75 |
+
USING (auth.uid() = user_id);
|
76 |
+
|
77 |
+
-- Create RLS policies for access_permissions
|
78 |
+
CREATE POLICY "tenant_isolation" ON access_permissions
|
79 |
+
FOR ALL
|
80 |
+
USING (tenant_id = current_setting('app.current_tenant')::uuid);
|
81 |
+
|
82 |
+
CREATE POLICY "Enable real-time" ON access_permissions
|
83 |
+
FOR SELECT USING (true);
|
84 |
+
|
85 |
+
CREATE POLICY "permissions_access" ON access_permissions
|
86 |
+
FOR SELECT
|
87 |
+
USING (auth.uid() = user_id);
|
88 |
+
|
89 |
+
-- Create indexes for optimization
|
90 |
+
CREATE INDEX idx_agent_parameters_tenant_id ON agent_parameters(tenant_id);
|
91 |
+
CREATE INDEX idx_resource_management_tenant_id ON resource_management(tenant_id);
|
92 |
+
CREATE INDEX idx_access_permissions_tenant_id ON access_permissions(tenant_id);
|
sql/users_agents.sql
ADDED
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
CREATE TABLE users (
|
2 |
+
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
|
3 |
+
email VARCHAR(255) UNIQUE NOT NULL,
|
4 |
+
password_hash TEXT NOT NULL,
|
5 |
+
role VARCHAR(50) NOT NULL,
|
6 |
+
tenant_id UUID NOT NULL,
|
7 |
+
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
8 |
+
);
|
9 |
+
|
10 |
+
CREATE TABLE agents (
|
11 |
+
id SERIAL PRIMARY KEY,
|
12 |
+
user_id UUID REFERENCES users(id),
|
13 |
+
tenant_id UUID NOT NULL,
|
14 |
+
name VARCHAR(255) NOT NULL,
|
15 |
+
type VARCHAR(50) NOT NULL,
|
16 |
+
status VARCHAR(50) NOT NULL,
|
17 |
+
description TEXT,
|
18 |
+
avatar_url TEXT,
|
19 |
+
llm_base VARCHAR(50),
|
20 |
+
prompt TEXT,
|
21 |
+
knowledge_base_url TEXT,
|
22 |
+
learning_rate FLOAT,
|
23 |
+
exploration_rate FLOAT,
|
24 |
+
training_iterations INT,
|
25 |
+
batch_size INT,
|
26 |
+
max_tokens INT,
|
27 |
+
temperature FLOAT,
|
28 |
+
top_p FLOAT,
|
29 |
+
frequency_penalty FLOAT,
|
30 |
+
presence_penalty FLOAT,
|
31 |
+
stop_sequences TEXT,
|
32 |
+
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
33 |
+
);
|
34 |
+
|
35 |
+
ALTER TABLE users ENABLE ROW LEVEL SECURITY;
|
36 |
+
ALTER TABLE agents ENABLE ROW LEVEL SECURITY;
|
37 |
+
|
38 |
+
CREATE POLICY "tenant_isolation" ON users
|
39 |
+
FOR ALL
|
40 |
+
USING (tenant_id = current_setting('app.current_tenant')::uuid);
|
41 |
+
|
42 |
+
CREATE POLICY "tenant_isolation" ON agents
|
43 |
+
FOR ALL
|
44 |
+
USING (tenant_id = current_setting('app.current_tenant')::uuid);
|
45 |
+
|
46 |
+
CREATE POLICY "Enable real-time" ON users
|
47 |
+
FOR SELECT USING (true);
|
48 |
+
|
49 |
+
CREATE POLICY "Enable real-time" ON agents
|
50 |
+
FOR SELECT USING (true);
|
51 |
+
|
52 |
+
CREATE POLICY "user_access" ON users
|
53 |
+
FOR SELECT
|
54 |
+
USING (auth.uid() = id);
|
55 |
+
|
56 |
+
CREATE POLICY "agent_access" ON agents
|
57 |
+
FOR SELECT
|
58 |
+
USING (auth.uid() = user_id);
|
59 |
+
|
60 |
+
CREATE INDEX idx_users_tenant_id ON users(tenant_id);
|
61 |
+
CREATE INDEX idx_agents_tenant_id ON agents(tenant_id);
|