Spaces:
Running
Running
handling error correctly
Browse files- app/api/ask-ai/route.ts +8 -1
- components/editor/ask-ai/index.tsx +5 -2
- components/editor/deploy-button/index.tsx +2 -0
- components/editor/index.tsx +6 -1
- package-lock.json +5 -5
- package.json +1 -1
app/api/ask-ai/route.ts
CHANGED
|
@@ -201,7 +201,14 @@ export async function POST(request: NextRequest) {
|
|
| 201 |
);
|
| 202 |
}
|
| 203 |
} finally {
|
| 204 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 205 |
}
|
| 206 |
})();
|
| 207 |
|
|
|
|
| 201 |
);
|
| 202 |
}
|
| 203 |
} finally {
|
| 204 |
+
try {
|
| 205 |
+
// Only close if writer exists and is not already closed
|
| 206 |
+
if (writer && !writer.closed) {
|
| 207 |
+
await writer.close();
|
| 208 |
+
}
|
| 209 |
+
} catch {
|
| 210 |
+
// Ignore errors on close
|
| 211 |
+
}
|
| 212 |
}
|
| 213 |
})();
|
| 214 |
|
components/editor/ask-ai/index.tsx
CHANGED
|
@@ -190,7 +190,10 @@ export function AskAI({
|
|
| 190 |
}
|
| 191 |
|
| 192 |
const chunk = decoder.decode(value, { stream: true });
|
| 193 |
-
|
|
|
|
|
|
|
|
|
|
| 194 |
const res = JSON.parse(chunk);
|
| 195 |
if (res.openLogin) {
|
| 196 |
setOpen(true);
|
|
@@ -204,7 +207,7 @@ export function AskAI({
|
|
| 204 |
}
|
| 205 |
setisAiWorking(false);
|
| 206 |
return;
|
| 207 |
-
}
|
| 208 |
thinkResponse += chunk;
|
| 209 |
if (selectedModel?.isThinker) {
|
| 210 |
const thinkMatch = thinkResponse.match(/<think>[\s\S]*/)?.[0];
|
|
|
|
| 190 |
}
|
| 191 |
|
| 192 |
const chunk = decoder.decode(value, { stream: true });
|
| 193 |
+
|
| 194 |
+
const isJson =
|
| 195 |
+
chunk.trim().startsWith("{") && chunk.trim().endsWith("}");
|
| 196 |
+
if (isJson) {
|
| 197 |
const res = JSON.parse(chunk);
|
| 198 |
if (res.openLogin) {
|
| 199 |
setOpen(true);
|
|
|
|
| 207 |
}
|
| 208 |
setisAiWorking(false);
|
| 209 |
return;
|
| 210 |
+
} else {
|
| 211 |
thinkResponse += chunk;
|
| 212 |
if (selectedModel?.isThinker) {
|
| 213 |
const thinkMatch = thinkResponse.match(/<think>[\s\S]*/)?.[0];
|
components/editor/deploy-button/index.tsx
CHANGED
|
@@ -60,6 +60,8 @@ export function DeployButton({
|
|
| 60 |
}
|
| 61 |
};
|
| 62 |
|
|
|
|
|
|
|
| 63 |
return (
|
| 64 |
<div className="flex items-center justify-end gap-5">
|
| 65 |
<div className="relative flex items-center justify-end">
|
|
|
|
| 60 |
}
|
| 61 |
};
|
| 62 |
|
| 63 |
+
// TODO add a way to do not allow people to deploy if the html is broken.
|
| 64 |
+
|
| 65 |
return (
|
| 66 |
<div className="flex items-center justify-end gap-5">
|
| 67 |
<div className="relative flex items-center justify-end">
|
components/editor/index.tsx
CHANGED
|
@@ -172,6 +172,10 @@ export const AppEditor = ({ project }: { project?: Project | null }) => {
|
|
| 172 |
}
|
| 173 |
}, [currentTab]);
|
| 174 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 175 |
return (
|
| 176 |
<section className="h-[100dvh] bg-neutral-950 flex flex-col">
|
| 177 |
<Header tab={currentTab} onNewTab={setCurrentTab}>
|
|
@@ -201,7 +205,7 @@ export const AppEditor = ({ project }: { project?: Project | null }) => {
|
|
| 201 |
}}
|
| 202 |
/>
|
| 203 |
<Editor
|
| 204 |
-
|
| 205 |
theme="vs-dark"
|
| 206 |
className={classNames(
|
| 207 |
"h-full bg-neutral-900 transition-all duration-200 absolute left-0 top-0",
|
|
@@ -228,6 +232,7 @@ export const AppEditor = ({ project }: { project?: Project | null }) => {
|
|
| 228 |
editorRef.current = editor;
|
| 229 |
monacoRef.current = monaco;
|
| 230 |
}}
|
|
|
|
| 231 |
/>
|
| 232 |
<AskAI
|
| 233 |
html={html}
|
|
|
|
| 172 |
}
|
| 173 |
}, [currentTab]);
|
| 174 |
|
| 175 |
+
const handleEditorValidation = (markers: editor.IMarker[]) => {
|
| 176 |
+
console.log("Editor validation markers:", markers);
|
| 177 |
+
};
|
| 178 |
+
|
| 179 |
return (
|
| 180 |
<section className="h-[100dvh] bg-neutral-950 flex flex-col">
|
| 181 |
<Header tab={currentTab} onNewTab={setCurrentTab}>
|
|
|
|
| 205 |
}}
|
| 206 |
/>
|
| 207 |
<Editor
|
| 208 |
+
defaultLanguage="html"
|
| 209 |
theme="vs-dark"
|
| 210 |
className={classNames(
|
| 211 |
"h-full bg-neutral-900 transition-all duration-200 absolute left-0 top-0",
|
|
|
|
| 232 |
editorRef.current = editor;
|
| 233 |
monacoRef.current = monaco;
|
| 234 |
}}
|
| 235 |
+
onValidate={handleEditorValidation}
|
| 236 |
/>
|
| 237 |
<AskAI
|
| 238 |
html={html}
|
package-lock.json
CHANGED
|
@@ -10,7 +10,7 @@
|
|
| 10 |
"dependencies": {
|
| 11 |
"@huggingface/hub": "^2.2.0",
|
| 12 |
"@huggingface/inference": "^4.0.3",
|
| 13 |
-
"@monaco-editor/react": "^4.7.0",
|
| 14 |
"@radix-ui/react-avatar": "^1.1.10",
|
| 15 |
"@radix-ui/react-checkbox": "^1.3.2",
|
| 16 |
"@radix-ui/react-collapsible": "^1.1.11",
|
|
@@ -886,12 +886,12 @@
|
|
| 886 |
}
|
| 887 |
},
|
| 888 |
"node_modules/@monaco-editor/react": {
|
| 889 |
-
"version": "4.7.0",
|
| 890 |
-
"resolved": "https://registry.npmjs.org/@monaco-editor/react/-/react-4.7.0.tgz",
|
| 891 |
-
"integrity": "sha512-
|
| 892 |
"license": "MIT",
|
| 893 |
"dependencies": {
|
| 894 |
-
"@monaco-editor/loader": "^1.
|
| 895 |
},
|
| 896 |
"peerDependencies": {
|
| 897 |
"monaco-editor": ">= 0.25.0 < 1",
|
|
|
|
| 10 |
"dependencies": {
|
| 11 |
"@huggingface/hub": "^2.2.0",
|
| 12 |
"@huggingface/inference": "^4.0.3",
|
| 13 |
+
"@monaco-editor/react": "^4.7.0-rc.0",
|
| 14 |
"@radix-ui/react-avatar": "^1.1.10",
|
| 15 |
"@radix-ui/react-checkbox": "^1.3.2",
|
| 16 |
"@radix-ui/react-collapsible": "^1.1.11",
|
|
|
|
| 886 |
}
|
| 887 |
},
|
| 888 |
"node_modules/@monaco-editor/react": {
|
| 889 |
+
"version": "4.7.0-rc.0",
|
| 890 |
+
"resolved": "https://registry.npmjs.org/@monaco-editor/react/-/react-4.7.0-rc.0.tgz",
|
| 891 |
+
"integrity": "sha512-YfjXkDK0bcwS0zo8PXptvQdCQfOPPtzGsAzmIv7PnoUGFdIohsR+NVDyjbajMddF+3cWUm/3q9NzP/DUke9a+w==",
|
| 892 |
"license": "MIT",
|
| 893 |
"dependencies": {
|
| 894 |
+
"@monaco-editor/loader": "^1.4.0"
|
| 895 |
},
|
| 896 |
"peerDependencies": {
|
| 897 |
"monaco-editor": ">= 0.25.0 < 1",
|
package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
| 11 |
"dependencies": {
|
| 12 |
"@huggingface/hub": "^2.2.0",
|
| 13 |
"@huggingface/inference": "^4.0.3",
|
| 14 |
-
"@monaco-editor/react": "^4.7.0",
|
| 15 |
"@radix-ui/react-avatar": "^1.1.10",
|
| 16 |
"@radix-ui/react-checkbox": "^1.3.2",
|
| 17 |
"@radix-ui/react-collapsible": "^1.1.11",
|
|
|
|
| 11 |
"dependencies": {
|
| 12 |
"@huggingface/hub": "^2.2.0",
|
| 13 |
"@huggingface/inference": "^4.0.3",
|
| 14 |
+
"@monaco-editor/react": "^4.7.0-rc.0",
|
| 15 |
"@radix-ui/react-avatar": "^1.1.10",
|
| 16 |
"@radix-ui/react-checkbox": "^1.3.2",
|
| 17 |
"@radix-ui/react-collapsible": "^1.1.11",
|