Spaces:
Running
Running
add logs
Browse files- app/api/ask/route.ts +31 -8
- hooks/useAi.ts +20 -1
app/api/ask/route.ts
CHANGED
|
@@ -410,8 +410,8 @@ export async function PUT(request: NextRequest) {
|
|
| 410 |
// Clear timeout if successful
|
| 411 |
if (timeoutId) clearTimeout(timeoutId);
|
| 412 |
} catch (timeoutError: any) {
|
| 413 |
-
console.
|
| 414 |
-
console.
|
| 415 |
// Clear timeout on error
|
| 416 |
if (timeoutId) clearTimeout(timeoutId);
|
| 417 |
|
|
@@ -687,16 +687,39 @@ This project was created with [DeepSite](https://huggingface.co/deepsite).
|
|
| 687 |
throw new Error(`Failed to upload files to repository: ${uploadError.message || 'Unknown error'}`);
|
| 688 |
}
|
| 689 |
|
| 690 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 691 |
ok: true,
|
| 692 |
updatedLines,
|
| 693 |
pages: updatedPages,
|
| 694 |
repoId,
|
| 695 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 696 |
...response.commit,
|
| 697 |
title: prompt,
|
| 698 |
-
}
|
| 699 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 700 |
} else {
|
| 701 |
return NextResponse.json(
|
| 702 |
{ ok: false, message: "No content returned from the model" },
|
|
@@ -704,8 +727,8 @@ This project was created with [DeepSite](https://huggingface.co/deepsite).
|
|
| 704 |
);
|
| 705 |
}
|
| 706 |
} catch (error: any) {
|
| 707 |
-
console.
|
| 708 |
-
console.
|
| 709 |
if (error.message?.includes('timeout') || error.message?.includes('Request timeout')) {
|
| 710 |
return NextResponse.json(
|
| 711 |
{
|
|
|
|
| 410 |
// Clear timeout if successful
|
| 411 |
if (timeoutId) clearTimeout(timeoutId);
|
| 412 |
} catch (timeoutError: any) {
|
| 413 |
+
console.error("++TIMEOUT ERROR++", timeoutError);
|
| 414 |
+
console.error("++TIMEOUT ERROR MESSAGE++", timeoutError.message);
|
| 415 |
// Clear timeout on error
|
| 416 |
if (timeoutId) clearTimeout(timeoutId);
|
| 417 |
|
|
|
|
| 687 |
throw new Error(`Failed to upload files to repository: ${uploadError.message || 'Unknown error'}`);
|
| 688 |
}
|
| 689 |
|
| 690 |
+
console.log("++UPLOAD SUCCESS++");
|
| 691 |
+
console.log("++RESPONSE STRUCTURE++", JSON.stringify({
|
| 692 |
+
hasCommit: !!response?.commit,
|
| 693 |
+
commitKeys: response?.commit ? Object.keys(response.commit) : [],
|
| 694 |
+
responseKeys: response ? Object.keys(response) : []
|
| 695 |
+
}));
|
| 696 |
+
|
| 697 |
+
// Safely construct the response
|
| 698 |
+
const responseData: any = {
|
| 699 |
ok: true,
|
| 700 |
updatedLines,
|
| 701 |
pages: updatedPages,
|
| 702 |
repoId,
|
| 703 |
+
};
|
| 704 |
+
|
| 705 |
+
// Only add commit if it exists and has valid structure
|
| 706 |
+
if (response && response.commit) {
|
| 707 |
+
responseData.commit = {
|
| 708 |
...response.commit,
|
| 709 |
title: prompt,
|
| 710 |
+
};
|
| 711 |
+
} else {
|
| 712 |
+
console.warn("++NO COMMIT IN RESPONSE++");
|
| 713 |
+
// Provide a fallback commit structure
|
| 714 |
+
responseData.commit = {
|
| 715 |
+
title: prompt,
|
| 716 |
+
oid: 'unknown',
|
| 717 |
+
};
|
| 718 |
+
}
|
| 719 |
+
|
| 720 |
+
console.log("++ABOUT TO RETURN JSON++", JSON.stringify(responseData).substring(0, 200));
|
| 721 |
+
|
| 722 |
+
return NextResponse.json(responseData);
|
| 723 |
} else {
|
| 724 |
return NextResponse.json(
|
| 725 |
{ ok: false, message: "No content returned from the model" },
|
|
|
|
| 727 |
);
|
| 728 |
}
|
| 729 |
} catch (error: any) {
|
| 730 |
+
console.error("++ERROR++", error);
|
| 731 |
+
console.error("++ERROR MESSAGE++", error.message);
|
| 732 |
if (error.message?.includes('timeout') || error.message?.includes('Request timeout')) {
|
| 733 |
return NextResponse.json(
|
| 734 |
{
|
hooks/useAi.ts
CHANGED
|
@@ -311,7 +311,26 @@ export const useAi = (onScrollToBottom?: () => void) => {
|
|
| 311 |
});
|
| 312 |
|
| 313 |
if (request && request.body) {
|
| 314 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 315 |
|
| 316 |
if (!request.ok) {
|
| 317 |
if (res.openLogin) {
|
|
|
|
| 311 |
});
|
| 312 |
|
| 313 |
if (request && request.body) {
|
| 314 |
+
// Clone the response so we can read it twice if needed
|
| 315 |
+
const clonedRequest = request.clone();
|
| 316 |
+
let res;
|
| 317 |
+
try {
|
| 318 |
+
res = await request.json();
|
| 319 |
+
} catch (jsonError: any) {
|
| 320 |
+
console.error("++JSON PARSE ERROR++", jsonError);
|
| 321 |
+
// Try to get the actual response text from the clone
|
| 322 |
+
try {
|
| 323 |
+
const text = await clonedRequest.text();
|
| 324 |
+
console.error("++RESPONSE TEXT++", text.substring(0, 1000));
|
| 325 |
+
console.error("++RESPONSE STATUS++", clonedRequest.status);
|
| 326 |
+
console.error("++RESPONSE HEADERS++", Array.from(clonedRequest.headers.entries()));
|
| 327 |
+
} catch (textError) {
|
| 328 |
+
console.error("++UNABLE TO READ RESPONSE TEXT++", textError);
|
| 329 |
+
}
|
| 330 |
+
setIsAiWorking(false);
|
| 331 |
+
toast.error("Server returned invalid response. Check console for details.");
|
| 332 |
+
return { error: "invalid_response", message: "Server returned non-JSON response" };
|
| 333 |
+
}
|
| 334 |
|
| 335 |
if (!request.ok) {
|
| 336 |
if (res.openLogin) {
|