bipinkrish commited on
Commit ·
50cf5bb
1
Parent(s): 3a1152b
ufff
Browse files- .gitignore +3 -0
- next.config.ts +3 -1
- pages/api/sendMessage.js +49 -0
- src/app/globals.css +27 -1
- src/app/layout.tsx +4 -7
- src/components/ui/typography.jsx +110 -0
- src/lib/utils.ts +13 -1
- src/webzero/api.ts +0 -32
- src/webzero/chat-page.tsx +78 -82
- src/webzero/preview.tsx +28 -34
- tsconfig.json +2 -1
.gitignore
CHANGED
|
@@ -38,3 +38,6 @@ yarn-error.log*
|
|
| 38 |
# typescript
|
| 39 |
*.tsbuildinfo
|
| 40 |
next-env.d.ts
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
# typescript
|
| 39 |
*.tsbuildinfo
|
| 40 |
next-env.d.ts
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
generated/
|
next.config.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
| 1 |
import type { NextConfig } from "next";
|
| 2 |
|
| 3 |
const nextConfig: NextConfig = {
|
| 4 |
-
|
|
|
|
|
|
|
| 5 |
};
|
| 6 |
|
| 7 |
export default nextConfig;
|
|
|
|
| 1 |
import type { NextConfig } from "next";
|
| 2 |
|
| 3 |
const nextConfig: NextConfig = {
|
| 4 |
+
experimental: {
|
| 5 |
+
externalDir: true,
|
| 6 |
+
}
|
| 7 |
};
|
| 8 |
|
| 9 |
export default nextConfig;
|
pages/api/sendMessage.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { generateUUID } from "@/lib/utils";
|
| 2 |
+
import { promises as fs } from "fs";
|
| 3 |
+
|
| 4 |
+
const baseUrl = "http://127.0.0.1:7860/api/v1/run/";
|
| 5 |
+
const flowId = "542c4118-8056-4a7e-a137-23d8fc24d24b";
|
| 6 |
+
const url = `${baseUrl}${flowId}?stream=false`;
|
| 7 |
+
|
| 8 |
+
export default async function handler(req, res) {
|
| 9 |
+
if (req.method !== "POST") {
|
| 10 |
+
res.status(405).json({ error: "Method not allowed" });
|
| 11 |
+
return;
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
const { content } = req.body;
|
| 15 |
+
|
| 16 |
+
try {
|
| 17 |
+
const response = await fetch(url, {
|
| 18 |
+
method: "POST",
|
| 19 |
+
headers: {
|
| 20 |
+
"Content-Type": "application/json",
|
| 21 |
+
},
|
| 22 |
+
body: JSON.stringify({
|
| 23 |
+
input_value: content,
|
| 24 |
+
output_type: "chat",
|
| 25 |
+
input_type: "chat",
|
| 26 |
+
tweaks: {},
|
| 27 |
+
}),
|
| 28 |
+
});
|
| 29 |
+
|
| 30 |
+
const data = await response.json();
|
| 31 |
+
const code = data.outputs[0].outputs[0].outputs.message.message.text;
|
| 32 |
+
const formattedCode = code.replace(/^```tsx\n|\n```$/g, "");
|
| 33 |
+
|
| 34 |
+
const id = generateUUID().toString();
|
| 35 |
+
const filename = `generated/${id}.tsx`;
|
| 36 |
+
|
| 37 |
+
await fs.mkdir("generated", { recursive: true });
|
| 38 |
+
await fs.writeFile(filename, formattedCode, "utf8");
|
| 39 |
+
|
| 40 |
+
res.status(200).json({
|
| 41 |
+
id,
|
| 42 |
+
from: "ai",
|
| 43 |
+
content: formattedCode,
|
| 44 |
+
});
|
| 45 |
+
} catch (error) {
|
| 46 |
+
console.error("Error in sendMessage API:", error);
|
| 47 |
+
res.status(500).json({ error: "Failed to process the request" });
|
| 48 |
+
}
|
| 49 |
+
}
|
src/app/globals.css
CHANGED
|
@@ -89,4 +89,30 @@ body {
|
|
| 89 |
|
| 90 |
.flex2 {
|
| 91 |
flex: 2;
|
| 92 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
|
| 90 |
.flex2 {
|
| 91 |
flex: 2;
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
.mw66 {
|
| 95 |
+
max-width: 66%;
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
.loader-light {
|
| 99 |
+
background: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 200 200"><circle fill="%23000000" stroke="%23000000" stroke-width="15" r="15" cx="40" cy="65"><animate attributeName="cy" calcMode="spline" dur="2" values="65;135;65;" keySplines=".5 0 .5 1;.5 0 .5 1" repeatCount="indefinite" begin="-.4"></animate></circle><circle fill="%23000000" stroke="%23000000" stroke-width="15" r="15" cx="100" cy="65"><animate attributeName="cy" calcMode="spline" dur="2" values="65;135;65;" keySplines=".5 0 .5 1;.5 0 .5 1" repeatCount="indefinite" begin="-.2"></animate></circle><circle fill="%23000000" stroke="%23000000" stroke-width="15" r="15" cx="160" cy="65"><animate attributeName="cy" calcMode="spline" dur="2" values="65;135;65;" keySplines=".5 0 .5 1;.5 0 .5 1" repeatCount="indefinite" begin="0"></animate></circle></svg>');
|
| 100 |
+
}
|
| 101 |
+
|
| 102 |
+
.loader-dark {
|
| 103 |
+
background: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 200 200"><circle fill="%23FFFFFF" stroke="%23FFFFFF" stroke-width="15" r="15" cx="40" cy="65"><animate attributeName="cy" calcMode="spline" dur="2" values="65;135;65;" keySplines=".5 0 .5 1;.5 0 .5 1" repeatCount="indefinite" begin="-.4"></animate></circle><circle fill="%23FFFFFF" stroke="%23FFFFFF" stroke-width="15" r="15" cx="100" cy="65"><animate attributeName="cy" calcMode="spline" dur="2" values="65;135;65;" keySplines=".5 0 .5 1;.5 0 .5 1" repeatCount="indefinite" begin="-.2"></animate></circle><circle fill="%23FFFFFF" stroke="%23FFFFFF" stroke-width="15" r="15" cx="160" cy="65"><animate attributeName="cy" calcMode="spline" dur="2" values="65;135;65;" keySplines=".5 0 .5 1;.5 0 .5 1" repeatCount="indefinite" begin="0"></animate></circle></svg>');
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
.preview-scroll {
|
| 107 |
+
height: calc(100vh - 10rem);
|
| 108 |
+
}
|
| 109 |
+
|
| 110 |
+
.chat-scroll {
|
| 111 |
+
height: calc(100vh - 4rem);
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
.loader {
|
| 115 |
+
height: 6rem;
|
| 116 |
+
width: 6rem;
|
| 117 |
+
justify-self: center;
|
| 118 |
+
}
|
src/app/layout.tsx
CHANGED
|
@@ -1,13 +1,11 @@
|
|
| 1 |
import type { Metadata } from "next";
|
| 2 |
import "./globals.css";
|
| 3 |
|
| 4 |
-
|
| 5 |
export const metadata: Metadata = {
|
| 6 |
title: "webzero",
|
| 7 |
description: "Generate webpages",
|
| 8 |
};
|
| 9 |
|
| 10 |
-
|
| 11 |
export default function RootLayout({
|
| 12 |
children,
|
| 13 |
}: Readonly<{
|
|
@@ -15,11 +13,10 @@ export default function RootLayout({
|
|
| 15 |
}>) {
|
| 16 |
return (
|
| 17 |
<html lang="en">
|
| 18 |
-
<
|
| 19 |
-
|
| 20 |
-
>
|
| 21 |
-
|
| 22 |
-
</body>
|
| 23 |
</html>
|
| 24 |
);
|
| 25 |
}
|
|
|
|
| 1 |
import type { Metadata } from "next";
|
| 2 |
import "./globals.css";
|
| 3 |
|
|
|
|
| 4 |
export const metadata: Metadata = {
|
| 5 |
title: "webzero",
|
| 6 |
description: "Generate webpages",
|
| 7 |
};
|
| 8 |
|
|
|
|
| 9 |
export default function RootLayout({
|
| 10 |
children,
|
| 11 |
}: Readonly<{
|
|
|
|
| 13 |
}>) {
|
| 14 |
return (
|
| 15 |
<html lang="en">
|
| 16 |
+
<head>
|
| 17 |
+
<script dangerouslySetInnerHTML={{ __html: "var exports = {};" }} />
|
| 18 |
+
</head>
|
| 19 |
+
<body className="antialiased overflow-hidden">{children}</body>
|
|
|
|
| 20 |
</html>
|
| 21 |
);
|
| 22 |
}
|
src/components/ui/typography.jsx
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
export function TypographyH1({ children }) {
|
| 2 |
+
return (
|
| 3 |
+
<h1 className="scroll-m-20 text-4xl font-extrabold tracking-tight lg:text-5xl">
|
| 4 |
+
{children}
|
| 5 |
+
</h1>
|
| 6 |
+
);
|
| 7 |
+
}
|
| 8 |
+
|
| 9 |
+
export function TypographyH2({ children }) {
|
| 10 |
+
return (
|
| 11 |
+
<h2 className="scroll-m-20 border-b pb-2 text-3xl font-semibold tracking-tight first:mt-0">
|
| 12 |
+
{children}
|
| 13 |
+
</h2>
|
| 14 |
+
);
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
export function TypographyH3({ children }) {
|
| 18 |
+
return (
|
| 19 |
+
<h3 className="scroll-m-20 text-2xl font-semibold tracking-tight">
|
| 20 |
+
{children}
|
| 21 |
+
</h3>
|
| 22 |
+
);
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
export function TypographyH4({ children }) {
|
| 26 |
+
return (
|
| 27 |
+
<h4 className="scroll-m-20 text-xl font-semibold tracking-tight">
|
| 28 |
+
{children}
|
| 29 |
+
</h4>
|
| 30 |
+
);
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
export function TypographyP({ children }) {
|
| 34 |
+
return <p className="leading-7 [&:not(:first-child)]:mt-6">{children}</p>;
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
export function TypographyBlockquote({ children }) {
|
| 38 |
+
return (
|
| 39 |
+
<blockquote className="mt-6 border-l-2 pl-6 italic">{children}</blockquote>
|
| 40 |
+
);
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
export function TypographyTable({ headers, rows }) {
|
| 44 |
+
return (
|
| 45 |
+
<div className="my-6 w-full overflow-y-auto">
|
| 46 |
+
<table className="w-full">
|
| 47 |
+
<thead>
|
| 48 |
+
<tr className="m-0 border-t p-0 even:bg-muted">
|
| 49 |
+
{headers.map((header, index) => (
|
| 50 |
+
<th
|
| 51 |
+
key={index}
|
| 52 |
+
className="border px-4 py-2 text-left font-bold [&[align=center]]:text-center [&[align=right]]:text-right"
|
| 53 |
+
>
|
| 54 |
+
{header}
|
| 55 |
+
</th>
|
| 56 |
+
))}
|
| 57 |
+
</tr>
|
| 58 |
+
</thead>
|
| 59 |
+
<tbody>
|
| 60 |
+
{rows.map((row, rowIndex) => (
|
| 61 |
+
<tr key={rowIndex} className="m-0 border-t p-0 even:bg-muted">
|
| 62 |
+
{row.map((cell, cellIndex) => (
|
| 63 |
+
<td
|
| 64 |
+
key={cellIndex}
|
| 65 |
+
className="border px-4 py-2 text-left [&[align=center]]:text-center [&[align=right]]:text-right"
|
| 66 |
+
>
|
| 67 |
+
{cell}
|
| 68 |
+
</td>
|
| 69 |
+
))}
|
| 70 |
+
</tr>
|
| 71 |
+
))}
|
| 72 |
+
</tbody>
|
| 73 |
+
</table>
|
| 74 |
+
</div>
|
| 75 |
+
);
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
export function TypographyList({ items }) {
|
| 79 |
+
return (
|
| 80 |
+
<ul className="my-6 ml-6 list-disc [&>li]:mt-2">
|
| 81 |
+
{items.map((item, index) => (
|
| 82 |
+
<li key={index}>{item}</li>
|
| 83 |
+
))}
|
| 84 |
+
</ul>
|
| 85 |
+
);
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
export function TypographyInlineCode({ children }) {
|
| 89 |
+
return (
|
| 90 |
+
<code className="relative rounded bg-muted px-[0.3rem] py-[0.2rem] font-mono text-sm font-semibold">
|
| 91 |
+
{children}
|
| 92 |
+
</code>
|
| 93 |
+
);
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
export function TypographyLead({ children }) {
|
| 97 |
+
return <p className="text-xl text-muted-foreground">{children}</p>;
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
export function TypographyLarge({ children }) {
|
| 101 |
+
return <div className="text-lg font-semibold">{children}</div>;
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
export function TypographySmall({ children }) {
|
| 105 |
+
return <small className="text-sm font-medium leading-none">{children}</small>;
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
export function TypographyMuted({ children }) {
|
| 109 |
+
return <p className="text-sm text-muted-foreground">{children}</p>;
|
| 110 |
+
}
|
src/lib/utils.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
import { clsx, type ClassValue } from "clsx";
|
| 2 |
import { twMerge } from "tailwind-merge";
|
| 3 |
// @ts-expect-error idk
|
| 4 |
-
import { oneDark } from "react-syntax-highlighter/dist/esm/styles/prism";
|
| 5 |
import { v4 as uuidv4 } from 'uuid';
|
| 6 |
|
| 7 |
export function cn(...inputs: ClassValue[]) {
|
|
@@ -20,6 +20,18 @@ export const customOneDark = {
|
|
| 20 |
},
|
| 21 |
};
|
| 22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
export function generateUUID() {
|
| 25 |
return uuidv4();
|
|
|
|
| 1 |
import { clsx, type ClassValue } from "clsx";
|
| 2 |
import { twMerge } from "tailwind-merge";
|
| 3 |
// @ts-expect-error idk
|
| 4 |
+
import { oneDark, oneLight } from "react-syntax-highlighter/dist/esm/styles/prism";
|
| 5 |
import { v4 as uuidv4 } from 'uuid';
|
| 6 |
|
| 7 |
export function cn(...inputs: ClassValue[]) {
|
|
|
|
| 20 |
},
|
| 21 |
};
|
| 22 |
|
| 23 |
+
export const customOneLight = {
|
| 24 |
+
...oneLight,
|
| 25 |
+
'code[class*="language-"]': {
|
| 26 |
+
...oneLight['code[class*="language-"]'],
|
| 27 |
+
background: 'transparent',
|
| 28 |
+
},
|
| 29 |
+
'pre[class*="language-"]': {
|
| 30 |
+
...oneLight['pre[class*="language-"]'],
|
| 31 |
+
background: 'transparent',
|
| 32 |
+
},
|
| 33 |
+
};
|
| 34 |
+
|
| 35 |
|
| 36 |
export function generateUUID() {
|
| 37 |
return uuidv4();
|
src/webzero/api.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
| 1 |
-
import { Message } from "@/lib/types";
|
| 2 |
-
import { generateUUID } from "@/lib/utils";
|
| 3 |
-
|
| 4 |
-
export async function sendMessage(content: string): Promise<Message> {
|
| 5 |
-
const response = await fetch(
|
| 6 |
-
"http://127.0.0.1:7860/api/v1/run/542c4118-8056-4a7e-a137-23d8fc24d24b?stream=false",
|
| 7 |
-
{
|
| 8 |
-
method: "POST",
|
| 9 |
-
headers: {
|
| 10 |
-
// "Authorization": "Bearer <TOKEN>",
|
| 11 |
-
"Content-Type": "application/json",
|
| 12 |
-
// "x-api-key": "sk-oEGNxo3Lr6gQqrvUlQuTa3gmTrfxV3HLlEbgbrp1tcw"
|
| 13 |
-
},
|
| 14 |
-
body: JSON.stringify({
|
| 15 |
-
input_value: content,
|
| 16 |
-
output_type: "chat",
|
| 17 |
-
input_type: "chat",
|
| 18 |
-
tweaks: {},
|
| 19 |
-
}),
|
| 20 |
-
}
|
| 21 |
-
);
|
| 22 |
-
|
| 23 |
-
const data = await response.json();
|
| 24 |
-
const code = data.outputs[0].outputs[0].outputs.message.message.text;
|
| 25 |
-
const formattedCode = code.replace(/^```tsx\n|\n```$/g, '');
|
| 26 |
-
|
| 27 |
-
return {
|
| 28 |
-
id: generateUUID().toString(),
|
| 29 |
-
from: 'ai',
|
| 30 |
-
content: formattedCode
|
| 31 |
-
};
|
| 32 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
src/webzero/chat-page.tsx
CHANGED
|
@@ -4,8 +4,6 @@ import { useState, useEffect } from "react";
|
|
| 4 |
import {
|
| 5 |
Code,
|
| 6 |
Eye,
|
| 7 |
-
// Menu,
|
| 8 |
-
// Paperclip,
|
| 9 |
Sun,
|
| 10 |
Moon,
|
| 11 |
Send,
|
|
@@ -19,12 +17,29 @@ import { Button } from "@/components/ui/button";
|
|
| 19 |
import { Textarea } from "@/components/ui/textarea";
|
| 20 |
import { Tabs, TabsList, TabsTrigger, TabsContent } from "@/components/ui/tabs";
|
| 21 |
import { ScrollArea } from "@/components/ui/scroll-area";
|
| 22 |
-
import { sendMessage } from "./api";
|
| 23 |
import { Message, PreviewState } from "../lib/types";
|
| 24 |
// @ts-expect-error shutup
|
| 25 |
import { Prism as SyntaxHighlighter } from "react-syntax-highlighter";
|
| 26 |
-
import { customOneDark, generateUUID } from "@/lib/utils";
|
| 27 |
-
import
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
export function ChatPage() {
|
| 30 |
const [message, setMessage] = useState("");
|
|
@@ -34,7 +49,7 @@ export function ChatPage() {
|
|
| 34 |
}
|
| 35 |
return false;
|
| 36 |
});
|
| 37 |
-
|
| 38 |
const [chatHistory, setChatHistory] = useState<Message[]>([]);
|
| 39 |
const [selectedMessage, setSelectedMessage] = useState<Message | null>(null);
|
| 40 |
const [previewState, setPreviewState] = useState<PreviewState>({
|
|
@@ -53,6 +68,7 @@ export function ChatPage() {
|
|
| 53 |
e.preventDefault();
|
| 54 |
if (!message.trim()) return;
|
| 55 |
|
|
|
|
| 56 |
const newMessage: Message = {
|
| 57 |
id: generateUUID().toString(),
|
| 58 |
from: "user",
|
|
@@ -62,8 +78,14 @@ export function ChatPage() {
|
|
| 62 |
setChatHistory((prev) => [...prev, newMessage]);
|
| 63 |
setMessage("");
|
| 64 |
|
| 65 |
-
|
| 66 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
};
|
| 68 |
|
| 69 |
const handleCopyCode = async (code: string) => {
|
|
@@ -87,48 +109,29 @@ export function ChatPage() {
|
|
| 87 |
}));
|
| 88 |
};
|
| 89 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
return (
|
| 91 |
<div className={`min-h-screen flex ${isDark ? "dark" : ""}`}>
|
| 92 |
-
{/* Sidebar */}
|
| 93 |
-
{/* <div
|
| 94 |
-
className={`w-64 border-r bg-background ${
|
| 95 |
-
isMenuOpen ? "" : "hidden"
|
| 96 |
-
} md:block`}
|
| 97 |
-
>
|
| 98 |
-
<div className="p-4 border-b h-16">
|
| 99 |
-
<div className="font-bold text-xl">webzero</div>
|
| 100 |
-
</div>
|
| 101 |
-
<nav className="p-4">
|
| 102 |
-
<Button variant="ghost" className="w-full justify-start">
|
| 103 |
-
New Chat
|
| 104 |
-
</Button>
|
| 105 |
-
</nav>
|
| 106 |
-
</div> */}
|
| 107 |
-
|
| 108 |
{/* Main Content */}
|
| 109 |
-
<div className="flex
|
| 110 |
<header className="h-16 border-b flex items-center justify-between px-4">
|
| 111 |
-
|
| 112 |
-
variant="ghost"
|
| 113 |
-
size="icon"
|
| 114 |
-
onClick={() => setIsMenuOpen(!isMenuOpen)}
|
| 115 |
-
className="md:hidden"
|
| 116 |
-
>
|
| 117 |
-
<Menu className="h-5 w-5" />
|
| 118 |
-
</Button> */}
|
| 119 |
-
<Button variant="ghost" size="icon" onClick={toggleTheme}>
|
| 120 |
-
{isDark ? (
|
| 121 |
-
<Sun className="h-5 w-5" />
|
| 122 |
-
) : (
|
| 123 |
-
<Moon className="h-5 w-5" />
|
| 124 |
-
)}
|
| 125 |
-
</Button>
|
| 126 |
</header>
|
| 127 |
|
| 128 |
<div className="flex flex-1">
|
| 129 |
{/* Chat/Input Area */}
|
| 130 |
-
<div className="flex flex-col flex-1">
|
| 131 |
-
<ScrollArea className="flex-1 p-4">
|
| 132 |
{chatHistory.map((msg) => (
|
| 133 |
<div
|
| 134 |
key={msg.id}
|
|
@@ -146,7 +149,6 @@ export function ChatPage() {
|
|
| 146 |
<div className="mb-2">{msg.content}</div>
|
| 147 |
) : (
|
| 148 |
<CodeMessageCard
|
| 149 |
-
message={msg}
|
| 150 |
onClick={() =>
|
| 151 |
setPreviewState((prev) => ({ ...prev, isOpen: true }))
|
| 152 |
}
|
|
@@ -158,23 +160,27 @@ export function ChatPage() {
|
|
| 158 |
|
| 159 |
<div className="border-t p-4">
|
| 160 |
<form onSubmit={handleSubmit} className="relative">
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
<
|
| 176 |
-
|
| 177 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 178 |
</form>
|
| 179 |
</div>
|
| 180 |
</div>
|
|
@@ -187,8 +193,8 @@ export function ChatPage() {
|
|
| 187 |
className={`border-l ${
|
| 188 |
previewState.isFullscreen
|
| 189 |
? "fixed inset-0 z-50 bg-background"
|
| 190 |
-
: "flex2"
|
| 191 |
-
}
|
| 192 |
>
|
| 193 |
<Tabs defaultValue="preview" className="h-full flex flex-col">
|
| 194 |
<div className="border-b px-4 flex justify-between items-center">
|
|
@@ -211,12 +217,13 @@ export function ChatPage() {
|
|
| 211 |
</TabsList>
|
| 212 |
|
| 213 |
<div className="p-4 border-b flex justify-end gap-2">
|
|
|
|
| 214 |
<Button
|
| 215 |
variant="outline"
|
| 216 |
size="sm"
|
| 217 |
onClick={() => handleCopyCode(selectedMessage.content)}
|
| 218 |
>
|
| 219 |
-
<Copy
|
| 220 |
Copy
|
| 221 |
</Button>
|
| 222 |
|
|
@@ -230,7 +237,7 @@ export function ChatPage() {
|
|
| 230 |
)
|
| 231 |
}
|
| 232 |
>
|
| 233 |
-
<Download
|
| 234 |
Download
|
| 235 |
</Button>
|
| 236 |
|
|
@@ -240,27 +247,25 @@ export function ChatPage() {
|
|
| 240 |
onClick={toggleFullscreen}
|
| 241 |
>
|
| 242 |
{previewState.isFullscreen ? (
|
| 243 |
-
<Minimize2
|
| 244 |
) : (
|
| 245 |
-
<Maximize2
|
| 246 |
)}
|
| 247 |
</Button>
|
| 248 |
</div>
|
| 249 |
</div>
|
| 250 |
|
| 251 |
<TabsContent value="preview" className="flex-1 p-4">
|
| 252 |
-
<ScrollArea className="
|
| 253 |
-
<
|
| 254 |
-
code={selectedMessage.content}
|
| 255 |
-
/>
|
| 256 |
</ScrollArea>
|
| 257 |
</TabsContent>
|
| 258 |
|
| 259 |
<TabsContent value="code" className="flex-1">
|
| 260 |
-
<ScrollArea className="
|
| 261 |
<SyntaxHighlighter
|
| 262 |
language={"typescript"}
|
| 263 |
-
style={customOneDark}
|
| 264 |
className="!m-0 !bg-transparent"
|
| 265 |
>
|
| 266 |
{selectedMessage.content}
|
|
@@ -276,13 +281,7 @@ export function ChatPage() {
|
|
| 276 |
);
|
| 277 |
}
|
| 278 |
|
| 279 |
-
function CodeMessageCard({
|
| 280 |
-
message,
|
| 281 |
-
onClick,
|
| 282 |
-
}: {
|
| 283 |
-
message: Message;
|
| 284 |
-
onClick: () => void;
|
| 285 |
-
}) {
|
| 286 |
return (
|
| 287 |
<div
|
| 288 |
onClick={onClick}
|
|
@@ -291,9 +290,6 @@ function CodeMessageCard({
|
|
| 291 |
<FileCode2 />
|
| 292 |
<div className="ml-2 ">
|
| 293 |
<div className="font-semibold text-sm">Code File</div>
|
| 294 |
-
{/* <div className="text-xs text-muted-foreground truncate max-w-[300px]">
|
| 295 |
-
{message.content.slice(0, 100)}...
|
| 296 |
-
</div> */}
|
| 297 |
</div>
|
| 298 |
</div>
|
| 299 |
);
|
|
|
|
| 4 |
import {
|
| 5 |
Code,
|
| 6 |
Eye,
|
|
|
|
|
|
|
| 7 |
Sun,
|
| 8 |
Moon,
|
| 9 |
Send,
|
|
|
|
| 17 |
import { Textarea } from "@/components/ui/textarea";
|
| 18 |
import { Tabs, TabsList, TabsTrigger, TabsContent } from "@/components/ui/tabs";
|
| 19 |
import { ScrollArea } from "@/components/ui/scroll-area";
|
|
|
|
| 20 |
import { Message, PreviewState } from "../lib/types";
|
| 21 |
// @ts-expect-error shutup
|
| 22 |
import { Prism as SyntaxHighlighter } from "react-syntax-highlighter";
|
| 23 |
+
import { customOneDark, customOneLight, generateUUID } from "@/lib/utils";
|
| 24 |
+
import CodeRenderer from "./preview";
|
| 25 |
+
|
| 26 |
+
const sendMessage = async (content: string) => {
|
| 27 |
+
const response = await fetch("/api/sendMessage", {
|
| 28 |
+
method: "POST",
|
| 29 |
+
headers: {
|
| 30 |
+
"Content-Type": "application/json",
|
| 31 |
+
},
|
| 32 |
+
body: JSON.stringify({ content }),
|
| 33 |
+
});
|
| 34 |
+
|
| 35 |
+
if (!response.ok) {
|
| 36 |
+
const errorData = await response.json();
|
| 37 |
+
throw new Error(errorData.error || "Failed to send message");
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
const data = await response.json();
|
| 41 |
+
return data;
|
| 42 |
+
};
|
| 43 |
|
| 44 |
export function ChatPage() {
|
| 45 |
const [message, setMessage] = useState("");
|
|
|
|
| 49 |
}
|
| 50 |
return false;
|
| 51 |
});
|
| 52 |
+
const [isLoading, setIsLoading] = useState(false);
|
| 53 |
const [chatHistory, setChatHistory] = useState<Message[]>([]);
|
| 54 |
const [selectedMessage, setSelectedMessage] = useState<Message | null>(null);
|
| 55 |
const [previewState, setPreviewState] = useState<PreviewState>({
|
|
|
|
| 68 |
e.preventDefault();
|
| 69 |
if (!message.trim()) return;
|
| 70 |
|
| 71 |
+
setIsLoading(true);
|
| 72 |
const newMessage: Message = {
|
| 73 |
id: generateUUID().toString(),
|
| 74 |
from: "user",
|
|
|
|
| 78 |
setChatHistory((prev) => [...prev, newMessage]);
|
| 79 |
setMessage("");
|
| 80 |
|
| 81 |
+
try {
|
| 82 |
+
const response = await sendMessage(newMessage.content);
|
| 83 |
+
setChatHistory((prev) => [...prev, response]);
|
| 84 |
+
} catch (error) {
|
| 85 |
+
console.error("Error:", error);
|
| 86 |
+
} finally {
|
| 87 |
+
setIsLoading(false);
|
| 88 |
+
}
|
| 89 |
};
|
| 90 |
|
| 91 |
const handleCopyCode = async (code: string) => {
|
|
|
|
| 109 |
}));
|
| 110 |
};
|
| 111 |
|
| 112 |
+
const ThemeChangeButton = () => (
|
| 113 |
+
<Button
|
| 114 |
+
className="ml-auto"
|
| 115 |
+
variant="ghost"
|
| 116 |
+
size="icon"
|
| 117 |
+
onClick={toggleTheme}
|
| 118 |
+
>
|
| 119 |
+
{isDark ? <Sun /> : <Moon />}
|
| 120 |
+
</Button>
|
| 121 |
+
);
|
| 122 |
+
|
| 123 |
return (
|
| 124 |
<div className={`min-h-screen flex ${isDark ? "dark" : ""}`}>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 125 |
{/* Main Content */}
|
| 126 |
+
<div className="flex flex-1 flex-col w-full">
|
| 127 |
<header className="h-16 border-b flex items-center justify-between px-4">
|
| 128 |
+
<ThemeChangeButton />
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 129 |
</header>
|
| 130 |
|
| 131 |
<div className="flex flex-1">
|
| 132 |
{/* Chat/Input Area */}
|
| 133 |
+
<div className="flex flex-col flex-1 h-fit">
|
| 134 |
+
<ScrollArea className="flex-1 p-4 chat-scroll">
|
| 135 |
{chatHistory.map((msg) => (
|
| 136 |
<div
|
| 137 |
key={msg.id}
|
|
|
|
| 149 |
<div className="mb-2">{msg.content}</div>
|
| 150 |
) : (
|
| 151 |
<CodeMessageCard
|
|
|
|
| 152 |
onClick={() =>
|
| 153 |
setPreviewState((prev) => ({ ...prev, isOpen: true }))
|
| 154 |
}
|
|
|
|
| 160 |
|
| 161 |
<div className="border-t p-4">
|
| 162 |
<form onSubmit={handleSubmit} className="relative">
|
| 163 |
+
{isLoading ? (
|
| 164 |
+
<div
|
| 165 |
+
className={
|
| 166 |
+
(isDark ? "loader-dark" : "loader-light") + " loader"
|
| 167 |
+
}
|
| 168 |
+
/>
|
| 169 |
+
) : (
|
| 170 |
+
<>
|
| 171 |
+
<Textarea
|
| 172 |
+
value={message}
|
| 173 |
+
onChange={(e) => setMessage(e.target.value)}
|
| 174 |
+
placeholder="Ask webzero a question..."
|
| 175 |
+
className="min-h-[100px] pr-24 resize-none"
|
| 176 |
+
/>
|
| 177 |
+
<div className="absolute top-2 right-3 flex items-center gap-2">
|
| 178 |
+
<Button type="submit" size="icon">
|
| 179 |
+
<Send className="h-4 w-4" />
|
| 180 |
+
</Button>
|
| 181 |
+
</div>
|
| 182 |
+
</>
|
| 183 |
+
)}
|
| 184 |
</form>
|
| 185 |
</div>
|
| 186 |
</div>
|
|
|
|
| 193 |
className={`border-l ${
|
| 194 |
previewState.isFullscreen
|
| 195 |
? "fixed inset-0 z-50 bg-background"
|
| 196 |
+
: "flex2 mw66"
|
| 197 |
+
}`}
|
| 198 |
>
|
| 199 |
<Tabs defaultValue="preview" className="h-full flex flex-col">
|
| 200 |
<div className="border-b px-4 flex justify-between items-center">
|
|
|
|
| 217 |
</TabsList>
|
| 218 |
|
| 219 |
<div className="p-4 border-b flex justify-end gap-2">
|
| 220 |
+
{previewState.isFullscreen && <ThemeChangeButton />}
|
| 221 |
<Button
|
| 222 |
variant="outline"
|
| 223 |
size="sm"
|
| 224 |
onClick={() => handleCopyCode(selectedMessage.content)}
|
| 225 |
>
|
| 226 |
+
<Copy />
|
| 227 |
Copy
|
| 228 |
</Button>
|
| 229 |
|
|
|
|
| 237 |
)
|
| 238 |
}
|
| 239 |
>
|
| 240 |
+
<Download />
|
| 241 |
Download
|
| 242 |
</Button>
|
| 243 |
|
|
|
|
| 247 |
onClick={toggleFullscreen}
|
| 248 |
>
|
| 249 |
{previewState.isFullscreen ? (
|
| 250 |
+
<Minimize2 />
|
| 251 |
) : (
|
| 252 |
+
<Maximize2 />
|
| 253 |
)}
|
| 254 |
</Button>
|
| 255 |
</div>
|
| 256 |
</div>
|
| 257 |
|
| 258 |
<TabsContent value="preview" className="flex-1 p-4">
|
| 259 |
+
<ScrollArea className="preview-scroll">
|
| 260 |
+
<CodeRenderer id={selectedMessage.id} />
|
|
|
|
|
|
|
| 261 |
</ScrollArea>
|
| 262 |
</TabsContent>
|
| 263 |
|
| 264 |
<TabsContent value="code" className="flex-1">
|
| 265 |
+
<ScrollArea className="preview-scroll">
|
| 266 |
<SyntaxHighlighter
|
| 267 |
language={"typescript"}
|
| 268 |
+
style={isDark ? customOneDark : customOneLight}
|
| 269 |
className="!m-0 !bg-transparent"
|
| 270 |
>
|
| 271 |
{selectedMessage.content}
|
|
|
|
| 281 |
);
|
| 282 |
}
|
| 283 |
|
| 284 |
+
function CodeMessageCard({ onClick }: { onClick: () => void }) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 285 |
return (
|
| 286 |
<div
|
| 287 |
onClick={onClick}
|
|
|
|
| 290 |
<FileCode2 />
|
| 291 |
<div className="ml-2 ">
|
| 292 |
<div className="font-semibold text-sm">Code File</div>
|
|
|
|
|
|
|
|
|
|
| 293 |
</div>
|
| 294 |
</div>
|
| 295 |
);
|
src/webzero/preview.tsx
CHANGED
|
@@ -1,39 +1,33 @@
|
|
| 1 |
-
import React, {
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
|
| 12 |
useEffect(() => {
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
<head>
|
| 21 |
-
<script src="https://unpkg.com/react@17/umd/react.development.js"></script>
|
| 22 |
-
<script src="https://unpkg.com/react-dom@17/umd/react-dom.development.js"></script>
|
| 23 |
-
<script src="https://unpkg.com/babel-standalone@6/babel.min.js"></script>
|
| 24 |
-
</head>
|
| 25 |
-
<body>
|
| 26 |
-
<div id="root"></div>
|
| 27 |
-
<script type="text/babel">
|
| 28 |
-
${code}
|
| 29 |
-
</script>
|
| 30 |
-
</body>
|
| 31 |
-
</html>
|
| 32 |
-
`);
|
| 33 |
-
doc.close();
|
| 34 |
}
|
| 35 |
-
}
|
| 36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
|
| 38 |
-
return <iframe ref={previewRef} className="w-full h-full" />;
|
| 39 |
-
}
|
|
|
|
| 1 |
+
import React, { useState, useEffect } from "react";
|
| 2 |
|
| 3 |
+
interface DynamicFileProps {
|
| 4 |
+
id: string;
|
| 5 |
+
}
|
| 6 |
+
|
| 7 |
+
const DynamicFileRenderer: React.FC<DynamicFileProps> = ({ id }) => {
|
| 8 |
+
const filepath = `../../generated/${id}.tsx`;
|
| 9 |
+
const [DynamicComponent, setDynamicComponent] =
|
| 10 |
+
useState<React.ComponentType | null>(null);
|
| 11 |
|
| 12 |
useEffect(() => {
|
| 13 |
+
const importComponent = async () => {
|
| 14 |
+
try {
|
| 15 |
+
const module = await import(filepath);
|
| 16 |
+
setDynamicComponent(() => module.default);
|
| 17 |
+
} catch (error) {
|
| 18 |
+
console.error("Error loading component:", error);
|
| 19 |
+
setDynamicComponent(() => () => <div>Failed to load component</div>);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
}
|
| 21 |
+
};
|
| 22 |
+
|
| 23 |
+
importComponent();
|
| 24 |
+
}, [filepath]);
|
| 25 |
+
|
| 26 |
+
if (!DynamicComponent) {
|
| 27 |
+
return <div>Loading...</div>;
|
| 28 |
+
}
|
| 29 |
+
return <DynamicComponent />;
|
| 30 |
+
};
|
| 31 |
+
|
| 32 |
+
export default DynamicFileRenderer;
|
| 33 |
|
|
|
|
|
|
tsconfig.json
CHANGED
|
@@ -10,6 +10,7 @@
|
|
| 10 |
"module": "esnext",
|
| 11 |
"moduleResolution": "bundler",
|
| 12 |
"resolveJsonModule": true,
|
|
|
|
| 13 |
"isolatedModules": true,
|
| 14 |
"jsx": "preserve",
|
| 15 |
"incremental": true,
|
|
@@ -22,6 +23,6 @@
|
|
| 22 |
"@/*": ["./src/*"]
|
| 23 |
}
|
| 24 |
},
|
| 25 |
-
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
|
| 26 |
"exclude": ["node_modules"]
|
| 27 |
}
|
|
|
|
| 10 |
"module": "esnext",
|
| 11 |
"moduleResolution": "bundler",
|
| 12 |
"resolveJsonModule": true,
|
| 13 |
+
"allowImportingTsExtensions": true,
|
| 14 |
"isolatedModules": true,
|
| 15 |
"jsx": "preserve",
|
| 16 |
"incremental": true,
|
|
|
|
| 23 |
"@/*": ["./src/*"]
|
| 24 |
}
|
| 25 |
},
|
| 26 |
+
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts", "pages/api/sendMessage.js"],
|
| 27 |
"exclude": ["node_modules"]
|
| 28 |
}
|