Spaces:
Running
Running
Update app.js
Browse files
app.js
CHANGED
|
@@ -153,7 +153,7 @@ async function executeCommands(userId, projectId, commands) {
|
|
| 153 |
|
| 154 |
for (const cmd of commands) {
|
| 155 |
try {
|
| 156 |
-
if (cmd.type === 'create_thrust') {
|
| 157 |
await supabase.from('thrusts').delete().eq('lead_id', projectId);
|
| 158 |
|
| 159 |
const { data: thrust } = await supabase.from('thrusts').insert({ lead_id: projectId, title: cmd.payload.title, markdown_content: cmd.payload.markdown_content, status: 'active' }).select().single();
|
|
@@ -169,6 +169,40 @@ async function executeCommands(userId, projectId, commands) {
|
|
| 169 |
flags.newThrustMarkdown = cmd.payload.markdown_content;
|
| 170 |
}
|
| 171 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 172 |
if (FRONT_URL) {
|
| 173 |
fetch(`${FRONT_URL}/internal/notify`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ user_id: userId, type: 'toast', message: `🚀 New Thrust Generated: ${cmd.payload.title}` }) }).catch(() => {});
|
| 174 |
}
|
|
|
|
| 153 |
|
| 154 |
for (const cmd of commands) {
|
| 155 |
try {
|
| 156 |
+
/* if (cmd.type === 'create_thrust') {
|
| 157 |
await supabase.from('thrusts').delete().eq('lead_id', projectId);
|
| 158 |
|
| 159 |
const { data: thrust } = await supabase.from('thrusts').insert({ lead_id: projectId, title: cmd.payload.title, markdown_content: cmd.payload.markdown_content, status: 'active' }).select().single();
|
|
|
|
| 169 |
flags.newThrustMarkdown = cmd.payload.markdown_content;
|
| 170 |
}
|
| 171 |
|
| 172 |
+
if (FRONT_URL) {
|
| 173 |
+
fetch(`${FRONT_URL}/internal/notify`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ user_id: userId, type: 'toast', message: `🚀 New Thrust Generated: ${cmd.payload.title}` }) }).catch(() => {});
|
| 174 |
+
}
|
| 175 |
+
} */
|
| 176 |
+
|
| 177 |
+
if (cmd.type === 'create_thrust') {
|
| 178 |
+
await supabase.from('thrusts').delete().eq('lead_id', projectId);
|
| 179 |
+
|
| 180 |
+
const { data: thrust } = await supabase.from('thrusts').insert({ lead_id: projectId, title: cmd.payload.title, markdown_content: cmd.payload.markdown_content, status: 'active' }).select().single();
|
| 181 |
+
|
| 182 |
+
if (thrust && cmd.payload.tasks && cmd.payload.tasks.length > 0) {
|
| 183 |
+
// NEW: Safely map objects to include dynamic AI options
|
| 184 |
+
const tasks = cmd.payload.tasks.map(t => {
|
| 185 |
+
if (typeof t === 'string') {
|
| 186 |
+
return { thrust_id: thrust.id, title: t, options:[], placeholder: "" };
|
| 187 |
+
} else {
|
| 188 |
+
return {
|
| 189 |
+
thrust_id: thrust.id,
|
| 190 |
+
title: t.title,
|
| 191 |
+
options: t.options ||[],
|
| 192 |
+
placeholder: t.placeholder || ""
|
| 193 |
+
};
|
| 194 |
+
}
|
| 195 |
+
});
|
| 196 |
+
await supabase.from('thrust_tasks').insert(tasks);
|
| 197 |
+
}
|
| 198 |
+
|
| 199 |
+
flags.shouldReload = true;
|
| 200 |
+
|
| 201 |
+
if (thrust) {
|
| 202 |
+
flags.newThrustId = thrust.id;
|
| 203 |
+
flags.newThrustMarkdown = cmd.payload.markdown_content;
|
| 204 |
+
}
|
| 205 |
+
|
| 206 |
if (FRONT_URL) {
|
| 207 |
fetch(`${FRONT_URL}/internal/notify`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ user_id: userId, type: 'toast', message: `🚀 New Thrust Generated: ${cmd.payload.title}` }) }).catch(() => {});
|
| 208 |
}
|