Skip to content

Commit 31f9745

Browse files
Add missing skill categories
- Extended DB enum agent_skill_category to include system and commerce - Applied corresponding migration to ensure seeding and skills can use new categories X-Lovable-Edit-ID: edt-7311a4dc-8925-4992-9f68-354613b00b87 Co-authored-by: magnusfroste <38864257+magnusfroste@users.noreply.github.com>
2 parents 63c3e4c + f001aee commit 31f9745

File tree

4 files changed

+61
-29
lines changed

4 files changed

+61
-29
lines changed

src/integrations/supabase/types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2902,6 +2902,8 @@ export type Database = {
29022902
| "automation"
29032903
| "search"
29042904
| "analytics"
2905+
| "system"
2906+
| "commerce"
29052907
agent_type: "flowpilot" | "chat"
29062908
app_role: "writer" | "approver" | "admin" | "customer"
29072909
automation_trigger_type: "cron" | "event" | "signal"
@@ -3088,6 +3090,8 @@ export const Constants = {
30883090
"automation",
30893091
"search",
30903092
"analytics",
3093+
"system",
3094+
"commerce",
30913095
],
30923096
agent_type: ["flowpilot", "chat"],
30933097
app_role: ["writer", "approver", "admin", "customer"],

supabase/functions/agent-execute/index.ts

Lines changed: 36 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,7 +1021,7 @@ async function executeDealsAction(
10211021
if (action === 'list') {
10221022
const { stage, lead_id } = args as any;
10231023
let query = supabase.from('deals')
1024-
.select('id, title, value_cents, currency, stage, lead_id, company_id, expected_close_date, created_at, updated_at')
1024+
.select('id, value_cents, currency, stage, lead_id, product_id, expected_close, notes, created_at, updated_at')
10251025
.order('updated_at', { ascending: false }).limit(50);
10261026
if (stage) query = query.eq('stage', stage);
10271027
if (lead_id) query = query.eq('lead_id', lead_id);
@@ -1031,13 +1031,13 @@ async function executeDealsAction(
10311031
}
10321032

10331033
if (action === 'create') {
1034-
const { title, value_cents, currency = 'SEK', stage = 'proposal', lead_id, company_id, expected_close_date } = args as any;
1035-
if (!title) throw new Error('title is required');
1034+
const { value_cents = 0, currency = 'SEK', stage = 'proposal', lead_id, product_id, expected_close, notes } = args as any;
1035+
if (!lead_id) throw new Error('lead_id is required');
10361036
const { data, error } = await supabase.from('deals').insert({
1037-
title, value_cents, currency, stage, lead_id, company_id, expected_close_date,
1038-
}).select('id, title, stage, value_cents').single();
1037+
value_cents, currency, stage, lead_id, product_id, expected_close, notes,
1038+
}).select('id, stage, value_cents').single();
10391039
if (error) throw new Error(`Create deal failed: ${error.message}`);
1040-
return { deal_id: data.id, title: data.title, stage: data.stage, value_cents: data.value_cents };
1040+
return { deal_id: data.id, stage: data.stage, value_cents: data.value_cents };
10411041
}
10421042

10431043
if (action === 'update') {
@@ -1046,20 +1046,20 @@ async function executeDealsAction(
10461046
delete updateData.action;
10471047
const { data, error } = await supabase.from('deals')
10481048
.update({ ...updateData, updated_at: new Date().toISOString() })
1049-
.eq('id', deal_id).select('id, title, stage').single();
1049+
.eq('id', deal_id).select('id, stage').single();
10501050
if (error) throw new Error(`Update deal failed: ${error.message}`);
1051-
return { deal_id: data.id, title: data.title, stage: data.stage, status: 'updated' };
1051+
return { deal_id: data.id, stage: data.stage, status: 'updated' };
10521052
}
10531053

10541054
if (action === 'move_stage') {
10551055
const { deal_id, stage } = args as any;
10561056
if (!deal_id || !stage) throw new Error('deal_id and stage required');
1057-
const completed_at = ['closed_won', 'closed_lost'].includes(stage) ? new Date().toISOString() : null;
1057+
const closed_at = ['closed_won', 'closed_lost'].includes(stage) ? new Date().toISOString() : null;
10581058
const { data, error } = await supabase.from('deals')
1059-
.update({ stage, completed_at, updated_at: new Date().toISOString() })
1060-
.eq('id', deal_id).select('id, title, stage').single();
1059+
.update({ stage, closed_at, updated_at: new Date().toISOString() })
1060+
.eq('id', deal_id).select('id, stage').single();
10611061
if (error) throw new Error(`Move stage failed: ${error.message}`);
1062-
return { deal_id: data.id, title: data.title, new_stage: data.stage };
1062+
return { deal_id: data.id, new_stage: data.stage };
10631063
}
10641064

10651065
return { error: `Unknown deals action: ${action}` };
@@ -1192,17 +1192,17 @@ async function executeCompaniesAction(
11921192

11931193
if (action === 'list') {
11941194
const { data, error } = await supabase.from('companies')
1195-
.select('id, name, domain, industry, size, city, country, created_at')
1195+
.select('id, name, domain, industry, size, address, phone, website, notes, created_at')
11961196
.order('created_at', { ascending: false }).limit(50);
11971197
if (error) throw new Error(`List companies failed: ${error.message}`);
11981198
return { companies: data || [] };
11991199
}
12001200

12011201
if (action === 'create') {
1202-
const { name, domain, industry, size, city, country, website, description } = args as any;
1202+
const { name, domain, industry, size, address, phone, website, notes } = args as any;
12031203
if (!name) throw new Error('name is required');
12041204
const { data, error } = await supabase.from('companies').insert({
1205-
name, domain, industry, size, city, country, website, description,
1205+
name, domain, industry, size, address, phone, website, notes,
12061206
}).select('id, name, domain').single();
12071207
if (error) throw new Error(`Create company failed: ${error.message}`);
12081208
return { company_id: data.id, name: data.name, domain: data.domain };
@@ -1219,6 +1219,14 @@ async function executeCompaniesAction(
12191219
return { company_id: data.id, name: data.name, status: 'updated' };
12201220
}
12211221

1222+
if (action === 'delete') {
1223+
const { company_id } = args as any;
1224+
if (!company_id) throw new Error('company_id is required');
1225+
const { error } = await supabase.from('companies').delete().eq('id', company_id);
1226+
if (error) throw new Error(`Delete company failed: ${error.message}`);
1227+
return { company_id, status: 'deleted' };
1228+
}
1229+
12221230
return { error: `Unknown companies action: ${action}` };
12231231
}
12241232

@@ -1234,9 +1242,12 @@ async function executeFormsAction(
12341242
const { action = 'list' } = args as any;
12351243

12361244
if (action === 'list') {
1237-
const { data, error } = await supabase.from('form_submissions')
1238-
.select('id, form_name, data, page_slug, status, created_at')
1239-
.order('created_at', { ascending: false }).limit(50);
1245+
const { form_name, limit = 50 } = args as any;
1246+
let query = supabase.from('form_submissions')
1247+
.select('id, form_name, block_id, data, metadata, page_id, created_at')
1248+
.order('created_at', { ascending: false }).limit(limit);
1249+
if (form_name) query = query.eq('form_name', form_name);
1250+
const { data, error } = await query;
12401251
if (error) throw new Error(`List submissions failed: ${error.message}`);
12411252
return { submissions: data || [] };
12421253
}
@@ -1250,20 +1261,19 @@ async function executeFormsAction(
12501261
return data;
12511262
}
12521263

1253-
if (action === 'update_status') {
1254-
const { submission_id, status } = args as any;
1255-
if (!submission_id || !status) throw new Error('submission_id and status required');
1256-
const { data, error } = await supabase.from('form_submissions')
1257-
.update({ status }).eq('id', submission_id).select('id, status').single();
1258-
if (error) throw new Error(`Update status failed: ${error.message}`);
1259-
return { submission_id: data.id, status: data.status };
1264+
if (action === 'delete') {
1265+
const { submission_id } = args as any;
1266+
if (!submission_id) throw new Error('submission_id is required');
1267+
const { error } = await supabase.from('form_submissions').delete().eq('id', submission_id);
1268+
if (error) throw new Error(`Delete failed: ${error.message}`);
1269+
return { submission_id, status: 'deleted' };
12601270
}
12611271

12621272
if (action === 'stats') {
12631273
const since = new Date();
12641274
since.setDate(since.getDate() - 30);
12651275
const { data, error } = await supabase.from('form_submissions')
1266-
.select('form_name, status, created_at')
1276+
.select('form_name, created_at')
12671277
.gte('created_at', since.toISOString());
12681278
if (error) throw new Error(`Form stats failed: ${error.message}`);
12691279
const submissions = data || [];

supabase/functions/setup-flowpilot/index.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const AGENTIC_SCHEMA = `
1717
-- Enums
1818
DO $$ BEGIN CREATE TYPE public.agent_type AS ENUM ('flowpilot', 'chat'); EXCEPTION WHEN duplicate_object THEN null; END $$;
1919
DO $$ BEGIN CREATE TYPE public.agent_scope AS ENUM ('internal', 'external', 'both'); EXCEPTION WHEN duplicate_object THEN null; END $$;
20-
DO $$ BEGIN CREATE TYPE public.agent_skill_category AS ENUM ('content', 'crm', 'communication', 'automation', 'search', 'analytics'); EXCEPTION WHEN duplicate_object THEN null; END $$;
20+
DO $$ BEGIN CREATE TYPE public.agent_skill_category AS ENUM ('content', 'crm', 'communication', 'automation', 'search', 'analytics', 'system', 'commerce'); EXCEPTION WHEN duplicate_object THEN null; END $$;
2121
DO $$ BEGIN CREATE TYPE public.agent_memory_category AS ENUM ('preference', 'context', 'fact'); EXCEPTION WHEN duplicate_object THEN null; END $$;
2222
DO $$ BEGIN CREATE TYPE public.agent_objective_status AS ENUM ('active', 'completed', 'paused', 'failed'); EXCEPTION WHEN duplicate_object THEN null; END $$;
2323
DO $$ BEGIN CREATE TYPE public.agent_activity_status AS ENUM ('success', 'failed', 'pending_approval'); EXCEPTION WHEN duplicate_object THEN null; END $$;
@@ -1060,10 +1060,12 @@ This skill is primarily triggered by automations, not directly by users.
10601060
properties: {
10611061
action: { type: 'string', enum: ['list', 'create', 'update', 'move_stage'] },
10621062
deal_id: { type: 'string' },
1063-
title: { type: 'string' },
10641063
value_cents: { type: 'number' },
10651064
stage: { type: 'string' },
10661065
lead_id: { type: 'string' },
1066+
product_id: { type: 'string' },
1067+
expected_close: { type: 'string', description: 'Date YYYY-MM-DD' },
1068+
notes: { type: 'string' },
10671069
},
10681070
required: ['action'],
10691071
},
@@ -1090,6 +1092,11 @@ This skill is primarily triggered by automations, not directly by users.
10901092
name: { type: 'string' },
10911093
domain: { type: 'string' },
10921094
industry: { type: 'string' },
1095+
size: { type: 'string' },
1096+
address: { type: 'string' },
1097+
phone: { type: 'string' },
1098+
website: { type: 'string' },
1099+
notes: { type: 'string' },
10931100
},
10941101
required: ['action'],
10951102
},
@@ -1404,7 +1411,7 @@ This skill is primarily triggered by automations, not directly by users.
14041411
parameters: {
14051412
type: 'object',
14061413
properties: {
1407-
action: { type: 'string', enum: ['list', 'get', 'delete'] },
1414+
action: { type: 'string', enum: ['list', 'get', 'delete', 'stats'] },
14081415
submission_id: { type: 'string' },
14091416
form_name: { type: 'string' },
14101417
limit: { type: 'number' },
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
-- Add missing enum values to agent_skill_category
3+
DO $$ BEGIN
4+
ALTER TYPE public.agent_skill_category ADD VALUE IF NOT EXISTS 'system';
5+
EXCEPTION WHEN duplicate_object THEN null;
6+
END $$;
7+
8+
DO $$ BEGIN
9+
ALTER TYPE public.agent_skill_category ADD VALUE IF NOT EXISTS 'commerce';
10+
EXCEPTION WHEN duplicate_object THEN null;
11+
END $$;

0 commit comments

Comments
 (0)