Commit ·
92dea51
1
Parent(s): b3c4d3d
api fix
Browse files- src/app/api/iterate/route.ts +20 -2
- src/app/api/new/route.ts +20 -2
- src/webzero/chat-page.tsx +1 -3
src/app/api/iterate/route.ts
CHANGED
|
@@ -38,8 +38,21 @@ ${currentCode}
|
|
| 38 |
}),
|
| 39 |
});
|
| 40 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
const data = await response.json();
|
| 42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
const formattedCode = code.replace(/^```tsx\n|\n```$/g, "");
|
| 44 |
|
| 45 |
const id = uuidv4();
|
|
@@ -62,7 +75,12 @@ ${currentCode}
|
|
| 62 |
} catch (error) {
|
| 63 |
console.error("Error in iterate API:", error);
|
| 64 |
return NextResponse.json(
|
| 65 |
-
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
{ status: 500 }
|
| 67 |
);
|
| 68 |
}
|
|
|
|
| 38 |
}),
|
| 39 |
});
|
| 40 |
|
| 41 |
+
if (!response.ok) {
|
| 42 |
+
const errorText = await response.text();
|
| 43 |
+
console.error("API Response Error:", errorText);
|
| 44 |
+
throw new Error(`API request failed with status ${response.status}`);
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
const data = await response.json();
|
| 48 |
+
|
| 49 |
+
const code =
|
| 50 |
+
data?.outputs?.[0]?.outputs?.[0]?.outputs?.message?.message?.text || "";
|
| 51 |
+
|
| 52 |
+
if (!code) {
|
| 53 |
+
throw new Error("No code generated from the API response");
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
const formattedCode = code.replace(/^```tsx\n|\n```$/g, "");
|
| 57 |
|
| 58 |
const id = uuidv4();
|
|
|
|
| 75 |
} catch (error) {
|
| 76 |
console.error("Error in iterate API:", error);
|
| 77 |
return NextResponse.json(
|
| 78 |
+
{
|
| 79 |
+
error:
|
| 80 |
+
error instanceof Error
|
| 81 |
+
? error.message
|
| 82 |
+
: "Failed to process the iteration request",
|
| 83 |
+
},
|
| 84 |
{ status: 500 }
|
| 85 |
);
|
| 86 |
}
|
src/app/api/new/route.ts
CHANGED
|
@@ -25,8 +25,21 @@ export async function POST(req: NextRequest) {
|
|
| 25 |
}),
|
| 26 |
});
|
| 27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
const data = await response.json();
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
const formattedCode = code.replace(/^```tsx\n|\n```$/g, "");
|
| 31 |
|
| 32 |
const id = uuidv4();
|
|
@@ -50,7 +63,12 @@ export async function POST(req: NextRequest) {
|
|
| 50 |
} catch (error) {
|
| 51 |
console.error("Error in sendMessage API:", error);
|
| 52 |
return NextResponse.json(
|
| 53 |
-
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
{ status: 500 }
|
| 55 |
);
|
| 56 |
}
|
|
|
|
| 25 |
}),
|
| 26 |
});
|
| 27 |
|
| 28 |
+
if (!response.ok) {
|
| 29 |
+
const errorText = await response.text();
|
| 30 |
+
console.error("API Response Error:", errorText);
|
| 31 |
+
throw new Error(`API request failed with status ${response.status}`);
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
const data = await response.json();
|
| 35 |
+
|
| 36 |
+
const code =
|
| 37 |
+
data?.outputs?.[0]?.outputs?.[0]?.outputs?.message?.message?.text || "";
|
| 38 |
+
|
| 39 |
+
if (!code) {
|
| 40 |
+
throw new Error("No code generated from the API response");
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
const formattedCode = code.replace(/^```tsx\n|\n```$/g, "");
|
| 44 |
|
| 45 |
const id = uuidv4();
|
|
|
|
| 63 |
} catch (error) {
|
| 64 |
console.error("Error in sendMessage API:", error);
|
| 65 |
return NextResponse.json(
|
| 66 |
+
{
|
| 67 |
+
error:
|
| 68 |
+
error instanceof Error
|
| 69 |
+
? error.message
|
| 70 |
+
: "Failed to process the request",
|
| 71 |
+
},
|
| 72 |
{ status: 500 }
|
| 73 |
);
|
| 74 |
}
|
src/webzero/chat-page.tsx
CHANGED
|
@@ -286,9 +286,7 @@ export function ChatPage() {
|
|
| 286 |
<ResizablePanel
|
| 287 |
defaultSize={50}
|
| 288 |
minSize={30}
|
| 289 |
-
className={`flex flex-col h-full
|
| 290 |
-
previewState.isOpen ? "pointer-events-none" : ""
|
| 291 |
-
}`}
|
| 292 |
>
|
| 293 |
<div className="flex flex-col h-full">
|
| 294 |
<ScrollArea className="flex-1 p-4">
|
|
|
|
| 286 |
<ResizablePanel
|
| 287 |
defaultSize={50}
|
| 288 |
minSize={30}
|
| 289 |
+
className={`flex flex-col h-full `}
|
|
|
|
|
|
|
| 290 |
>
|
| 291 |
<div className="flex flex-col h-full">
|
| 292 |
<ScrollArea className="flex-1 p-4">
|