enzostvs HF Staff commited on
Commit
80fd52f
·
1 Parent(s): 0cad576

remove the updatedLines yet

Browse files
app/api/ask-ai/route.ts CHANGED
@@ -197,10 +197,10 @@ export async function PUT(request: NextRequest) {
197
  const userToken = request.cookies.get(MY_TOKEN_KEY())?.value;
198
 
199
  const body = await request.json();
200
- const { prompt, html, previousPrompt, provider, selectedElementHtml, model, pages } =
201
  body;
202
 
203
- if (!prompt || !html) {
204
  return NextResponse.json(
205
  { ok: false, error: "Missing required fields" },
206
  { status: 400 }
@@ -277,11 +277,11 @@ export async function PUT(request: NextRequest) {
277
  {
278
  role: "assistant",
279
 
280
- content: `The current code is: \n\`\`\`html\n${html}\n\`\`\` ${
281
  selectedElementHtml
282
  ? `\n\nYou have to update ONLY the following element, NOTHING ELSE: \n\n\`\`\`html\n${selectedElementHtml}\n\`\`\``
283
  : ""
284
- }. Also here are the current pages: ${pages?.map((p: Page) => `- ${p.path} \n${p.html}`).join("\n")}.`,
285
  },
286
  {
287
  role: "user",
@@ -307,7 +307,7 @@ export async function PUT(request: NextRequest) {
307
 
308
  if (chunk) {
309
  const updatedLines: number[][] = [];
310
- let newHtml = html;
311
  const updatedPages = [...(pages || [])];
312
 
313
  const updatePageRegex = new RegExp(`${UPDATE_PAGE_START.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}([^\\s]+)\\s*${UPDATE_PAGE_END.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}([\\s\\S]*?)(?=${UPDATE_PAGE_START.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}|${NEW_PAGE_START.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}|$)`, 'g');
 
197
  const userToken = request.cookies.get(MY_TOKEN_KEY())?.value;
198
 
199
  const body = await request.json();
200
+ const { prompt, previousPrompt, provider, selectedElementHtml, model, pages } =
201
  body;
202
 
203
+ if (!prompt || pages.length === 0) {
204
  return NextResponse.json(
205
  { ok: false, error: "Missing required fields" },
206
  { status: 400 }
 
277
  {
278
  role: "assistant",
279
 
280
+ content: `${
281
  selectedElementHtml
282
  ? `\n\nYou have to update ONLY the following element, NOTHING ELSE: \n\n\`\`\`html\n${selectedElementHtml}\n\`\`\``
283
  : ""
284
+ }. Current pages: ${pages?.map((p: Page) => `- ${p.path} \n${p.html}`).join("\n")}.`,
285
  },
286
  {
287
  role: "user",
 
307
 
308
  if (chunk) {
309
  const updatedLines: number[][] = [];
310
+ let newHtml = "";
311
  const updatedPages = [...(pages || [])];
312
 
313
  const updatePageRegex = new RegExp(`${UPDATE_PAGE_START.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}([^\\s]+)\\s*${UPDATE_PAGE_END.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}([\\s\\S]*?)(?=${UPDATE_PAGE_START.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}|${NEW_PAGE_START.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}|$)`, 'g');
components/editor/index.tsx CHANGED
@@ -289,7 +289,7 @@ export const AppEditor = ({
289
  currentPage={currentPageData}
290
  htmlHistory={htmlHistory}
291
  previousPrompts={project?.prompts ?? []}
292
- onSuccess={(newPages, p: string, updatedLines?: number[][]) => {
293
  const currentHistory = [...htmlHistory];
294
  currentHistory.unshift({
295
  pages: newPages,
@@ -302,26 +302,26 @@ export const AppEditor = ({
302
  if (window.innerWidth <= 1024) {
303
  setCurrentTab("preview");
304
  }
305
- if (updatedLines && updatedLines?.length > 0) {
306
- const decorations = updatedLines.map((line) => ({
307
- range: new monacoRef.current.Range(
308
- line[0],
309
- 1,
310
- line[1],
311
- 1
312
- ),
313
- options: {
314
- inlineClassName: "matched-line",
315
- },
316
- }));
317
- setTimeout(() => {
318
- editorRef?.current
319
- ?.getModel()
320
- ?.deltaDecorations([], decorations);
321
 
322
- editorRef.current?.revealLine(updatedLines[0][0]);
323
- }, 100);
324
- }
325
  }}
326
  setPages={setPages}
327
  pages={pages}
 
289
  currentPage={currentPageData}
290
  htmlHistory={htmlHistory}
291
  previousPrompts={project?.prompts ?? []}
292
+ onSuccess={(newPages, p: string) => {
293
  const currentHistory = [...htmlHistory];
294
  currentHistory.unshift({
295
  pages: newPages,
 
302
  if (window.innerWidth <= 1024) {
303
  setCurrentTab("preview");
304
  }
305
+ // if (updatedLines && updatedLines?.length > 0) {
306
+ // const decorations = updatedLines.map((line) => ({
307
+ // range: new monacoRef.current.Range(
308
+ // line[0],
309
+ // 1,
310
+ // line[1],
311
+ // 1
312
+ // ),
313
+ // options: {
314
+ // inlineClassName: "matched-line",
315
+ // },
316
+ // }));
317
+ // setTimeout(() => {
318
+ // editorRef?.current
319
+ // ?.getModel()
320
+ // ?.deltaDecorations([], decorations);
321
 
322
+ // editorRef.current?.revealLine(updatedLines[0][0]);
323
+ // }, 100);
324
+ // }
325
  }}
326
  setPages={setPages}
327
  pages={pages}
components/editor/preview/index.tsx CHANGED
@@ -213,7 +213,7 @@ const SandpackPreviewClient = ({
213
  // console.log({ client });
214
  // console.log(sandpack.clients[clientId]);
215
  const iframe = client.iframe;
216
- console.log(iframe.contentWindow?.document);
217
  }
218
  /**
219
  * NOTE: In order to make sure that the client will be available
@@ -221,5 +221,5 @@ const SandpackPreviewClient = ({
221
  */
222
  }, [sandpack]);
223
 
224
- return <SandpackPreview ref={ref} />;
225
  };
 
213
  // console.log({ client });
214
  // console.log(sandpack.clients[clientId]);
215
  const iframe = client.iframe;
216
+ console.log(iframe.contentWindow);
217
  }
218
  /**
219
  * NOTE: In order to make sure that the client will be available
 
221
  */
222
  }, [sandpack]);
223
 
224
+ return <SandpackPreview ref={ref} showRefreshButton={false} />;
225
  };
hooks/useCallAi.ts CHANGED
@@ -22,7 +22,6 @@ export const useCallAi = ({
22
  onScrollToBottom,
23
  setPages,
24
  setCurrentPage,
25
- currentPage,
26
  pages,
27
  isAiWorking,
28
  setisAiWorking,
@@ -260,7 +259,6 @@ export const useCallAi = ({
260
  provider,
261
  previousPrompt,
262
  model,
263
- html: currentPage?.html,
264
  pages,
265
  selectedElementHtml,
266
  }),
 
22
  onScrollToBottom,
23
  setPages,
24
  setCurrentPage,
 
25
  pages,
26
  isAiWorking,
27
  setisAiWorking,
 
259
  provider,
260
  previousPrompt,
261
  model,
 
262
  pages,
263
  selectedElementHtml,
264
  }),
lib/prompts.ts CHANGED
@@ -118,5 +118,5 @@ ${NEW_PAGE_START}index.html${NEW_PAGE_END}
118
  </body>
119
  </html>
120
  \`\`\`
121
- Also, if there are more than 1 page, dont forget to includes the page in a link <a href="page.html">page</a> to be accessible (Dont use onclick to navigate, only href).
122
  No need to explain what you did. Just return the expected result.`;
 
118
  </body>
119
  </html>
120
  \`\`\`
121
+ IMPORTANT: While creating a new page, UPDATE all the other pages to add or replace the link to the new page, otherwise the user will not be able to navigate to the new page. (Dont use onclick to navigate, only href)
122
  No need to explain what you did. Just return the expected result.`;