enzostvs HF Staff commited on
Commit
17234c8
·
1 Parent(s): 5da9322

some fixes

Browse files
app/actions/projects.ts CHANGED
@@ -19,39 +19,7 @@ export async function getProjects(): Promise<{
19
  };
20
  }
21
 
22
- // await dbConnect();
23
- // const projects = await Project.find({
24
- // user_id: user?.id,
25
- // })
26
- // .sort({ _createdAt: -1 })
27
- // .limit(100)
28
- // .lean();
29
- // if (!projects) {
30
- // return {
31
- // ok: true,
32
- // isEmpty: true,
33
- // projects: [],
34
- // };
35
- // }
36
-
37
- // const mappedProjects = []
38
-
39
- // for (const project of projects) {
40
- // const space = await spaceInfo({
41
- // name: project.space_id,
42
- // accessToken: user.token as string,
43
- // additionalFields: ["author", "cardData"],
44
- // });
45
- // if (!space.private) {
46
- // mappedProjects.push({
47
- // ...project,
48
- // name: space.name,
49
- // cardData: space.cardData,
50
- // });
51
- // }
52
- // }
53
  const projects = [];
54
- // get user spaces from Hugging Face
55
  for await (const space of listSpaces({
56
  accessToken: user.token as string,
57
  additionalFields: ["author", "cardData"],
 
19
  };
20
  }
21
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
  const projects = [];
 
23
  for await (const space of listSpaces({
24
  accessToken: user.token as string,
25
  additionalFields: ["author", "cardData"],
app/api/ask/route.ts CHANGED
@@ -103,8 +103,6 @@ export async function POST(request: NextRequest) {
103
  rewrittenPrompt = await rewritePrompt(prompt, enhancedSettings, { token, billTo }, selectedModel.value, selectedProvider);
104
  }
105
 
106
- console.log(rewrittenPrompt);
107
-
108
  try {
109
  const encoder = new TextEncoder();
110
  const stream = new TransformStream();
@@ -133,7 +131,7 @@ export async function POST(request: NextRequest) {
133
  },
134
  {
135
  role: "user",
136
- content: `${rewritePrompt}${redesignMarkdown ? `\n\nHere is my current design as a markdown:\n\n${redesignMarkdown}\n\nNow, please create a new design based on this markdown. Use the images in the markdown.` : ""}`
137
  },
138
  ],
139
  max_tokens: selectedProvider.max_tokens,
@@ -277,6 +275,21 @@ export async function PUT(request: NextRequest) {
277
 
278
  const client = new InferenceClient(token);
279
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
280
  const selectedProvider = await getBestProvider(selectedModel.value, provider)
281
 
282
  try {
@@ -300,7 +313,7 @@ export async function PUT(request: NextRequest) {
300
 
301
  content: `${
302
  selectedElementHtml
303
- ? `\n\nYou have to update ONLY the following element, NOTHING ELSE: \n\n\`\`\`html\n${selectedElementHtml}\n\`\`\``
304
  : ""
305
  }. Current pages: ${pages?.map((p: Page) => `- ${p.path} \n${p.html}`).join("\n")}. ${files?.length > 0 ? `Current images: ${files?.map((f: string) => `- ${f}`).join("\n")}.` : ""}`,
306
  },
@@ -381,15 +394,18 @@ export async function PUT(request: NextRequest) {
381
  pageHtml = `${replaceBlock}\n${pageHtml}`;
382
  updatedLines.push([1, replaceBlock.split("\n").length]);
383
  } else {
384
- const blockPosition = pageHtml.indexOf(searchBlock);
385
- if (blockPosition !== -1) {
386
- const beforeText = pageHtml.substring(0, blockPosition);
 
 
 
387
  const startLineNumber = beforeText.split("\n").length;
388
  const replaceLines = replaceBlock.split("\n").length;
389
  const endLineNumber = startLineNumber + replaceLines - 1;
390
 
391
  updatedLines.push([startLineNumber, endLineNumber]);
392
- pageHtml = pageHtml.replace(searchBlock, replaceBlock);
393
  }
394
  }
395
 
@@ -467,15 +483,18 @@ export async function PUT(request: NextRequest) {
467
  newHtml = `${replaceBlock}\n${newHtml}`;
468
  updatedLines.push([1, replaceBlock.split("\n").length]);
469
  } else {
470
- const blockPosition = newHtml.indexOf(searchBlock);
471
- if (blockPosition !== -1) {
472
- const beforeText = newHtml.substring(0, blockPosition);
 
 
 
473
  const startLineNumber = beforeText.split("\n").length;
474
  const replaceLines = replaceBlock.split("\n").length;
475
  const endLineNumber = startLineNumber + replaceLines - 1;
476
 
477
  updatedLines.push([startLineNumber, endLineNumber]);
478
- newHtml = newHtml.replace(searchBlock, replaceBlock);
479
  }
480
  }
481
 
 
103
  rewrittenPrompt = await rewritePrompt(prompt, enhancedSettings, { token, billTo }, selectedModel.value, selectedProvider);
104
  }
105
 
 
 
106
  try {
107
  const encoder = new TextEncoder();
108
  const stream = new TransformStream();
 
131
  },
132
  {
133
  role: "user",
134
+ content: `${rewrittenPrompt}${redesignMarkdown ? `\n\nHere is my current design as a markdown:\n\n${redesignMarkdown}\n\nNow, please create a new design based on this markdown. Use the images in the markdown.` : ""}`
135
  },
136
  ],
137
  max_tokens: selectedProvider.max_tokens,
 
275
 
276
  const client = new InferenceClient(token);
277
 
278
+ // Helper function to escape regex special characters
279
+ const escapeRegExp = (string: string) => {
280
+ return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
281
+ };
282
+
283
+ // Helper function to create flexible HTML regex that handles varying spaces
284
+ const createFlexibleHtmlRegex = (searchBlock: string) => {
285
+ let searchRegex = escapeRegExp(searchBlock)
286
+ .replace(/\s+/g, '\\s*') // Allow any amount of whitespace where there are spaces
287
+ .replace(/>\s*</g, '>\\s*<') // Allow spaces between HTML tags
288
+ .replace(/\s*>/g, '\\s*>'); // Allow spaces before closing >
289
+
290
+ return new RegExp(searchRegex, 'g');
291
+ };
292
+
293
  const selectedProvider = await getBestProvider(selectedModel.value, provider)
294
 
295
  try {
 
313
 
314
  content: `${
315
  selectedElementHtml
316
+ ? `\n\nYou have to update ONLY the following element, NOTHING ELSE: \n\n\`\`\`html\n${selectedElementHtml}\n\`\`\` Could be in multiple pages, if so, update all the pages.`
317
  : ""
318
  }. Current pages: ${pages?.map((p: Page) => `- ${p.path} \n${p.html}`).join("\n")}. ${files?.length > 0 ? `Current images: ${files?.map((f: string) => `- ${f}`).join("\n")}.` : ""}`,
319
  },
 
394
  pageHtml = `${replaceBlock}\n${pageHtml}`;
395
  updatedLines.push([1, replaceBlock.split("\n").length]);
396
  } else {
397
+ const regex = createFlexibleHtmlRegex(searchBlock);
398
+ const match = regex.exec(pageHtml);
399
+
400
+ if (match) {
401
+ const matchedText = match[0];
402
+ const beforeText = pageHtml.substring(0, match.index);
403
  const startLineNumber = beforeText.split("\n").length;
404
  const replaceLines = replaceBlock.split("\n").length;
405
  const endLineNumber = startLineNumber + replaceLines - 1;
406
 
407
  updatedLines.push([startLineNumber, endLineNumber]);
408
+ pageHtml = pageHtml.replace(matchedText, replaceBlock);
409
  }
410
  }
411
 
 
483
  newHtml = `${replaceBlock}\n${newHtml}`;
484
  updatedLines.push([1, replaceBlock.split("\n").length]);
485
  } else {
486
+ const regex = createFlexibleHtmlRegex(searchBlock);
487
+ const match = regex.exec(newHtml);
488
+
489
+ if (match) {
490
+ const matchedText = match[0];
491
+ const beforeText = newHtml.substring(0, match.index);
492
  const startLineNumber = beforeText.split("\n").length;
493
  const replaceLines = replaceBlock.split("\n").length;
494
  const endLineNumber = startLineNumber + replaceLines - 1;
495
 
496
  updatedLines.push([startLineNumber, endLineNumber]);
497
+ newHtml = newHtml.replace(matchedText, replaceBlock);
498
  }
499
  }
500
 
app/api/me/projects/[namespace]/[repoId]/commits/[commitId]/promote/route.ts CHANGED
@@ -1,9 +1,7 @@
1
  import { NextRequest, NextResponse } from "next/server";
2
- import { RepoDesignation, listFiles, uploadFiles } from "@huggingface/hub";
3
 
4
  import { isAuthenticated } from "@/lib/auth";
5
- import Project from "@/models/Project";
6
- import dbConnect from "@/lib/mongodb";
7
 
8
  export async function POST(
9
  req: NextRequest,
@@ -21,28 +19,35 @@ export async function POST(
21
  return NextResponse.json({ message: "Unauthorized" }, { status: 401 });
22
  }
23
 
24
- await dbConnect();
25
  const param = await params;
26
  const { namespace, repoId, commitId } = param;
27
 
28
- const project = await Project.findOne({
29
- user_id: user.id,
30
- space_id: `${namespace}/${repoId}`,
31
- }).lean();
32
-
33
- if (!project) {
34
- return NextResponse.json(
35
- { ok: false, error: "Project not found" },
36
- { status: 404 }
37
- );
38
- }
39
-
40
  try {
41
  const repo: RepoDesignation = {
42
  type: "space",
43
  name: `${namespace}/${repoId}`,
44
  };
45
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46
  // Fetch files from the specific commit
47
  const files: File[] = [];
48
  const allowedExtensions = ["html", "md", "css", "js", "json", "txt"];
@@ -116,7 +121,6 @@ export async function POST(
116
  );
117
 
118
  } catch (error: any) {
119
- console.error("Error promoting version:", error);
120
 
121
  // Handle specific HuggingFace API errors
122
  if (error.statusCode === 404) {
 
1
  import { NextRequest, NextResponse } from "next/server";
2
+ import { RepoDesignation, listFiles, spaceInfo, uploadFiles } from "@huggingface/hub";
3
 
4
  import { isAuthenticated } from "@/lib/auth";
 
 
5
 
6
  export async function POST(
7
  req: NextRequest,
 
19
  return NextResponse.json({ message: "Unauthorized" }, { status: 401 });
20
  }
21
 
 
22
  const param = await params;
23
  const { namespace, repoId, commitId } = param;
24
 
 
 
 
 
 
 
 
 
 
 
 
 
25
  try {
26
  const repo: RepoDesignation = {
27
  type: "space",
28
  name: `${namespace}/${repoId}`,
29
  };
30
 
31
+ const space = await spaceInfo({
32
+ name: `${namespace}/${repoId}`,
33
+ accessToken: user.token as string,
34
+ additionalFields: ["author"],
35
+ });
36
+
37
+ if (!space || space.sdk !== "static") {
38
+ return NextResponse.json(
39
+ { ok: false, error: "Space is not a static space." },
40
+ { status: 404 }
41
+ );
42
+ }
43
+
44
+ if (space.author !== user.name) {
45
+ return NextResponse.json(
46
+ { ok: false, error: "Space does not belong to the authenticated user." },
47
+ { status: 403 }
48
+ );
49
+ }
50
+
51
  // Fetch files from the specific commit
52
  const files: File[] = [];
53
  const allowedExtensions = ["html", "md", "css", "js", "json", "txt"];
 
121
  );
122
 
123
  } catch (error: any) {
 
124
 
125
  // Handle specific HuggingFace API errors
126
  if (error.statusCode === 404) {
app/api/me/projects/[namespace]/[repoId]/images/route.ts CHANGED
@@ -1,5 +1,5 @@
1
  import { NextRequest, NextResponse } from "next/server";
2
- import { RepoDesignation, uploadFiles } from "@huggingface/hub";
3
 
4
  import { isAuthenticated } from "@/lib/auth";
5
  import Project from "@/models/Project";
@@ -16,24 +16,28 @@ export async function POST(
16
  return NextResponse.json({ message: "Unauthorized" }, { status: 401 });
17
  }
18
 
19
- await dbConnect();
20
  const param = await params;
21
  const { namespace, repoId } = param;
22
 
23
- const project = await Project.findOne({
24
- user_id: user.id,
25
- space_id: `${namespace}/${repoId}`,
26
- }).lean();
27
-
28
- if (!project) {
 
29
  return NextResponse.json(
30
- {
31
- ok: false,
32
- error: "Project not found",
33
- },
34
  { status: 404 }
35
  );
36
  }
 
 
 
 
 
 
 
37
 
38
  // Parse the FormData to get the images
39
  const formData = await req.formData();
 
1
  import { NextRequest, NextResponse } from "next/server";
2
+ import { RepoDesignation, spaceInfo, uploadFiles } from "@huggingface/hub";
3
 
4
  import { isAuthenticated } from "@/lib/auth";
5
  import Project from "@/models/Project";
 
16
  return NextResponse.json({ message: "Unauthorized" }, { status: 401 });
17
  }
18
 
 
19
  const param = await params;
20
  const { namespace, repoId } = param;
21
 
22
+ const space = await spaceInfo({
23
+ name: `${namespace}/${repoId}`,
24
+ accessToken: user.token as string,
25
+ additionalFields: ["author"],
26
+ });
27
+
28
+ if (!space || space.sdk !== "static") {
29
  return NextResponse.json(
30
+ { ok: false, error: "Space is not a static space." },
 
 
 
31
  { status: 404 }
32
  );
33
  }
34
+
35
+ if (space.author !== user.name) {
36
+ return NextResponse.json(
37
+ { ok: false, error: "Space does not belong to the authenticated user." },
38
+ { status: 403 }
39
+ );
40
+ }
41
 
42
  // Parse the FormData to get the images
43
  const formData = await req.formData();
app/api/me/projects/[namespace]/[repoId]/route.ts CHANGED
@@ -1,9 +1,7 @@
1
  import { NextRequest, NextResponse } from "next/server";
2
- import { RepoDesignation, spaceInfo, uploadFiles, listFiles, deleteRepo, listCommits } from "@huggingface/hub";
3
 
4
  import { isAuthenticated } from "@/lib/auth";
5
- import Project from "@/models/Project";
6
- import dbConnect from "@/lib/mongodb";
7
  import { Commit, Page } from "@/types";
8
 
9
  export async function DELETE(
@@ -16,22 +14,9 @@ export async function DELETE(
16
  return NextResponse.json({ message: "Unauthorized" }, { status: 401 });
17
  }
18
 
19
- await dbConnect();
20
  const param = await params;
21
  const { namespace, repoId } = param;
22
 
23
- const project = await Project.findOne({
24
- user_id: user.id,
25
- space_id: `${namespace}/${repoId}`,
26
- }).lean();
27
-
28
- if (!project) {
29
- return NextResponse.json(
30
- { ok: false, error: "Project not found" },
31
- { status: 404 }
32
- );
33
- }
34
-
35
  try {
36
  const space = await spaceInfo({
37
  name: `${namespace}/${repoId}`,
@@ -69,11 +54,7 @@ export async function DELETE(
69
  repo,
70
  accessToken: user.token as string,
71
  });
72
-
73
- await Project.deleteOne({
74
- user_id: user.id,
75
- space_id: `${namespace}/${repoId}`,
76
- });
77
 
78
  return NextResponse.json({ ok: true }, { status: 200 });
79
  } catch (error: any) {
@@ -94,23 +75,9 @@ export async function GET(
94
  return NextResponse.json({ message: "Unauthorized" }, { status: 401 });
95
  }
96
 
97
- await dbConnect();
98
  const param = await params;
99
  const { namespace, repoId } = param;
100
 
101
- const project = await Project.findOne({
102
- user_id: user.id,
103
- space_id: `${namespace}/${repoId}`,
104
- }).lean();
105
- if (!project) {
106
- return NextResponse.json(
107
- {
108
- ok: false,
109
- error: "Project not found",
110
- },
111
- { status: 404 }
112
- );
113
- }
114
  try {
115
  const space = await spaceInfo({
116
  name: namespace + "/" + repoId,
@@ -203,10 +170,13 @@ export async function GET(
203
  { status: 404 }
204
  );
205
  }
206
-
207
  return NextResponse.json(
208
  {
209
- project,
 
 
 
 
210
  pages: htmlFiles,
211
  files,
212
  commits,
@@ -218,10 +188,6 @@ export async function GET(
218
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
219
  } catch (error: any) {
220
  if (error.statusCode === 404) {
221
- await Project.deleteOne({
222
- user_id: user.id,
223
- space_id: `${namespace}/${repoId}`,
224
- });
225
  return NextResponse.json(
226
  { error: "Space not found", ok: false },
227
  { status: 404 }
 
1
  import { NextRequest, NextResponse } from "next/server";
2
+ import { RepoDesignation, spaceInfo, listFiles, deleteRepo, listCommits } from "@huggingface/hub";
3
 
4
  import { isAuthenticated } from "@/lib/auth";
 
 
5
  import { Commit, Page } from "@/types";
6
 
7
  export async function DELETE(
 
14
  return NextResponse.json({ message: "Unauthorized" }, { status: 401 });
15
  }
16
 
 
17
  const param = await params;
18
  const { namespace, repoId } = param;
19
 
 
 
 
 
 
 
 
 
 
 
 
 
20
  try {
21
  const space = await spaceInfo({
22
  name: `${namespace}/${repoId}`,
 
54
  repo,
55
  accessToken: user.token as string,
56
  });
57
+
 
 
 
 
58
 
59
  return NextResponse.json({ ok: true }, { status: 200 });
60
  } catch (error: any) {
 
75
  return NextResponse.json({ message: "Unauthorized" }, { status: 401 });
76
  }
77
 
 
78
  const param = await params;
79
  const { namespace, repoId } = param;
80
 
 
 
 
 
 
 
 
 
 
 
 
 
 
81
  try {
82
  const space = await spaceInfo({
83
  name: namespace + "/" + repoId,
 
170
  { status: 404 }
171
  );
172
  }
 
173
  return NextResponse.json(
174
  {
175
+ project: {
176
+ id: space.id,
177
+ space_id: space.name,
178
+ _updatedAt: space.updatedAt,
179
+ },
180
  pages: htmlFiles,
181
  files,
182
  commits,
 
188
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
189
  } catch (error: any) {
190
  if (error.statusCode === 404) {
 
 
 
 
191
  return NextResponse.json(
192
  { error: "Space not found", ok: false },
193
  { status: 404 }
app/api/me/projects/route.ts CHANGED
@@ -2,8 +2,6 @@ import { NextRequest, NextResponse } from "next/server";
2
  import { RepoDesignation, createRepo, listCommits, uploadFiles } from "@huggingface/hub";
3
 
4
  import { isAuthenticated } from "@/lib/auth";
5
- import Project from "@/models/Project";
6
- import dbConnect from "@/lib/mongodb";
7
  import { Commit, Page } from "@/types";
8
  import { COLORS } from "@/lib/utils";
9
 
@@ -15,7 +13,6 @@ export async function POST(
15
  return NextResponse.json({ message: "Unauthorized" }, { status: 401 });
16
  }
17
 
18
- await dbConnect();
19
  const { title: titleFromRequest, pages, prompt } = await req.json();
20
 
21
  const title = titleFromRequest ?? "DeepSite Project";
@@ -70,10 +67,6 @@ This project was created with [DeepSite](https://deepsite.hf.co).
70
  });
71
 
72
  const path = repoUrl.split("/").slice(-2).join("/");
73
- const project = await Project.create({
74
- user_id: user.id,
75
- space_id: path,
76
- });
77
 
78
  const commits: Commit[] = [];
79
  for await (const commit of listCommits({ repo, accessToken: user.token as string })) {
@@ -91,7 +84,9 @@ This project was created with [DeepSite](https://deepsite.hf.co).
91
  files,
92
  pages,
93
  commits,
94
- project,
 
 
95
  }
96
 
97
  return NextResponse.json({ space: newProject, path, ok: true }, { status: 201 });
 
2
  import { RepoDesignation, createRepo, listCommits, uploadFiles } from "@huggingface/hub";
3
 
4
  import { isAuthenticated } from "@/lib/auth";
 
 
5
  import { Commit, Page } from "@/types";
6
  import { COLORS } from "@/lib/utils";
7
 
 
13
  return NextResponse.json({ message: "Unauthorized" }, { status: 401 });
14
  }
15
 
 
16
  const { title: titleFromRequest, pages, prompt } = await req.json();
17
 
18
  const title = titleFromRequest ?? "DeepSite Project";
 
67
  });
68
 
69
  const path = repoUrl.split("/").slice(-2).join("/");
 
 
 
 
70
 
71
  const commits: Commit[] = [];
72
  for await (const commit of listCommits({ repo, accessToken: user.token as string })) {
 
84
  files,
85
  pages,
86
  commits,
87
+ project: {
88
+
89
+ }
90
  }
91
 
92
  return NextResponse.json({ space: newProject, path, ok: true }, { status: 201 });
app/api/proxy/route.ts CHANGED
@@ -80,14 +80,12 @@ export async function GET(req: NextRequest) {
80
  <script>
81
  // Add event listeners and communicate with parent
82
  document.addEventListener('DOMContentLoaded', function() {
83
- console.log('DOM loaded, setting up communication');
84
  let hoveredElement = null;
85
  let isEditModeEnabled = false;
86
 
87
  document.addEventListener('mouseover', function(event) {
88
  if (event.target !== document.body && event.target !== document.documentElement) {
89
  hoveredElement = event.target;
90
- console.log('Element hovered:', event.target.tagName, 'Edit mode:', isEditModeEnabled);
91
 
92
  const rect = event.target.getBoundingClientRect();
93
  const message = {
@@ -100,10 +98,9 @@ export async function GET(req: NextRequest) {
100
  width: rect.width,
101
  height: rect.height
102
  },
103
- element: event.target.outerHTML.substring(0, 200)
104
  }
105
  };
106
- console.log('Sending message to parent:', message);
107
  parent.postMessage(message, '*');
108
  }
109
  });
@@ -134,7 +131,7 @@ export async function GET(req: NextRequest) {
134
  width: rect.width,
135
  height: rect.height
136
  },
137
- element: event.target.outerHTML.substring(0, 200)
138
  }
139
  }, '*');
140
  } else {
@@ -195,14 +192,11 @@ export async function GET(req: NextRequest) {
195
 
196
  // Listen for messages from parent
197
  window.addEventListener('message', function(event) {
198
- console.log('Iframe received message from parent:', event.data);
199
  if (event.data.type === 'ENABLE_EDIT_MODE') {
200
- console.log('Enabling edit mode');
201
  isEditModeEnabled = true;
202
  document.body.style.userSelect = 'none';
203
  document.body.style.pointerEvents = 'auto';
204
  } else if (event.data.type === 'DISABLE_EDIT_MODE') {
205
- console.log('Disabling edit mode');
206
  isEditModeEnabled = false;
207
  document.body.style.userSelect = '';
208
  document.body.style.pointerEvents = '';
 
80
  <script>
81
  // Add event listeners and communicate with parent
82
  document.addEventListener('DOMContentLoaded', function() {
 
83
  let hoveredElement = null;
84
  let isEditModeEnabled = false;
85
 
86
  document.addEventListener('mouseover', function(event) {
87
  if (event.target !== document.body && event.target !== document.documentElement) {
88
  hoveredElement = event.target;
 
89
 
90
  const rect = event.target.getBoundingClientRect();
91
  const message = {
 
98
  width: rect.width,
99
  height: rect.height
100
  },
101
+ element: event.target.outerHTML
102
  }
103
  };
 
104
  parent.postMessage(message, '*');
105
  }
106
  });
 
131
  width: rect.width,
132
  height: rect.height
133
  },
134
+ element: event.target.outerHTML
135
  }
136
  }, '*');
137
  } else {
 
192
 
193
  // Listen for messages from parent
194
  window.addEventListener('message', function(event) {
 
195
  if (event.data.type === 'ENABLE_EDIT_MODE') {
 
196
  isEditModeEnabled = true;
197
  document.body.style.userSelect = 'none';
198
  document.body.style.pointerEvents = 'auto';
199
  } else if (event.data.type === 'DISABLE_EDIT_MODE') {
 
200
  isEditModeEnabled = false;
201
  document.body.style.userSelect = '';
202
  document.body.style.pointerEvents = '';
components/editor/preview/index.tsx CHANGED
@@ -92,6 +92,7 @@ export const Preview = ({ isNew }: { isNew: boolean }) => {
92
  const mockElement = {
93
  tagName: data.tagName,
94
  getBoundingClientRect: () => data.rect,
 
95
  };
96
  setSelectedElement(mockElement as any);
97
  setIsEditableModeEnabled(false);
 
92
  const mockElement = {
93
  tagName: data.tagName,
94
  getBoundingClientRect: () => data.rect,
95
+ outerHTML: data.element,
96
  };
97
  setSelectedElement(mockElement as any);
98
  setIsEditableModeEnabled(false);
hooks/useAi.ts CHANGED
@@ -250,6 +250,7 @@ export const useAi = (onScrollToBottom?: () => void) => {
250
  const callAiFollowUp = async (prompt: string, enhancedSettings?: EnhancedSettings) => {
251
  if (isAiWorking) return;
252
  if (!prompt.trim()) return;
 
253
 
254
  setIsAiWorking(true);
255
 
@@ -265,7 +266,7 @@ export const useAi = (onScrollToBottom?: () => void) => {
265
  previousPrompts: prompts,
266
  model,
267
  pages,
268
- selectedElementHtml: selectedElement,
269
  files: selectedFiles,
270
  repoId: project?.space_id
271
  }),
@@ -311,7 +312,9 @@ export const useAi = (onScrollToBottom?: () => void) => {
311
  setIsEditableModeEnabled(false);
312
  if (audio.current) audio.current.play();
313
  if (iframe) {
314
- iframe.src = iframe.src;
 
 
315
  }
316
 
317
  return { success: true, html: res.html, updatedLines: res.updatedLines };
 
250
  const callAiFollowUp = async (prompt: string, enhancedSettings?: EnhancedSettings) => {
251
  if (isAiWorking) return;
252
  if (!prompt.trim()) return;
253
+
254
 
255
  setIsAiWorking(true);
256
 
 
266
  previousPrompts: prompts,
267
  model,
268
  pages,
269
+ selectedElementHtml: selectedElement?.outerHTML,
270
  files: selectedFiles,
271
  repoId: project?.space_id
272
  }),
 
312
  setIsEditableModeEnabled(false);
313
  if (audio.current) audio.current.play();
314
  if (iframe) {
315
+ setTimeout(() => {
316
+ iframe.src = iframe.src;
317
+ }, 500);
318
  }
319
 
320
  return { success: true, html: res.html, updatedLines: res.updatedLines };