Spaces:
Paused
Paused
dr-data
commited on
Commit
·
9e8594b
1
Parent(s):
e82f6a1
Fix TypeScript and ESLint errors for successful build
Browse files- app/api/ask-ai/route.ts +2 -3
- app/api/debug-test/route.ts +6 -4
- app/api/test-scenarios/route.ts +1 -1
- components/editor/ask-ai/index.tsx +2 -2
- components/editor/preview/index-simplified.tsx +4 -5
- components/editor/preview/index.tsx +0 -1
- components/openrouter-model-selector/index.tsx +5 -2
- lib/openrouter.ts +1 -3
app/api/ask-ai/route.ts
CHANGED
|
@@ -16,7 +16,6 @@ import {
|
|
| 16 |
import MY_TOKEN_KEY from "@/lib/get-cookie-name";
|
| 17 |
import {
|
| 18 |
callOpenRouter,
|
| 19 |
-
parseOpenRouterStream,
|
| 20 |
getOpenRouterModelInfo,
|
| 21 |
calculateSafeMaxTokens,
|
| 22 |
estimateTokenCount
|
|
@@ -335,7 +334,7 @@ export async function POST(request: NextRequest) {
|
|
| 335 |
return; // Exit the async function
|
| 336 |
}
|
| 337 |
}
|
| 338 |
-
} catch
|
| 339 |
console.warn('⚠️ Failed to parse OpenRouter data:', data.substring(0, 50));
|
| 340 |
}
|
| 341 |
}
|
|
@@ -754,7 +753,7 @@ export async function PUT(request: NextRequest) {
|
|
| 754 |
if (content) {
|
| 755 |
fullContent += content;
|
| 756 |
}
|
| 757 |
-
} catch
|
| 758 |
// Ignore parse errors
|
| 759 |
}
|
| 760 |
}
|
|
|
|
| 16 |
import MY_TOKEN_KEY from "@/lib/get-cookie-name";
|
| 17 |
import {
|
| 18 |
callOpenRouter,
|
|
|
|
| 19 |
getOpenRouterModelInfo,
|
| 20 |
calculateSafeMaxTokens,
|
| 21 |
estimateTokenCount
|
|
|
|
| 334 |
return; // Exit the async function
|
| 335 |
}
|
| 336 |
}
|
| 337 |
+
} catch {
|
| 338 |
console.warn('⚠️ Failed to parse OpenRouter data:', data.substring(0, 50));
|
| 339 |
}
|
| 340 |
}
|
|
|
|
| 753 |
if (content) {
|
| 754 |
fullContent += content;
|
| 755 |
}
|
| 756 |
+
} catch {
|
| 757 |
// Ignore parse errors
|
| 758 |
}
|
| 759 |
}
|
app/api/debug-test/route.ts
CHANGED
|
@@ -62,11 +62,12 @@ export async function GET(request: NextRequest) {
|
|
| 62 |
}
|
| 63 |
|
| 64 |
console.log('✅ Debug test completed');
|
| 65 |
-
} catch (error:
|
| 66 |
console.error('❌ Debug test error:', error);
|
|
|
|
| 67 |
await writer.write(encoder.encode(JSON.stringify({
|
| 68 |
ok: false,
|
| 69 |
-
message: `Debug test error: ${
|
| 70 |
})));
|
| 71 |
} finally {
|
| 72 |
await writer.close();
|
|
@@ -74,10 +75,11 @@ export async function GET(request: NextRequest) {
|
|
| 74 |
})();
|
| 75 |
|
| 76 |
return response;
|
| 77 |
-
} catch (error:
|
| 78 |
console.error('❌ Debug endpoint error:', error);
|
|
|
|
| 79 |
return NextResponse.json(
|
| 80 |
-
{ ok: false, error:
|
| 81 |
{ status: 500 }
|
| 82 |
);
|
| 83 |
}
|
|
|
|
| 62 |
}
|
| 63 |
|
| 64 |
console.log('✅ Debug test completed');
|
| 65 |
+
} catch (error: unknown) {
|
| 66 |
console.error('❌ Debug test error:', error);
|
| 67 |
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
| 68 |
await writer.write(encoder.encode(JSON.stringify({
|
| 69 |
ok: false,
|
| 70 |
+
message: `Debug test error: ${errorMessage}`
|
| 71 |
})));
|
| 72 |
} finally {
|
| 73 |
await writer.close();
|
|
|
|
| 75 |
})();
|
| 76 |
|
| 77 |
return response;
|
| 78 |
+
} catch (error: unknown) {
|
| 79 |
console.error('❌ Debug endpoint error:', error);
|
| 80 |
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
| 81 |
return NextResponse.json(
|
| 82 |
+
{ ok: false, error: errorMessage },
|
| 83 |
{ status: 500 }
|
| 84 |
);
|
| 85 |
}
|
app/api/test-scenarios/route.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
import { NextRequest, NextResponse } from "next/server";
|
| 2 |
|
| 3 |
-
export async function POST(
|
| 4 |
console.log('🧪 Testing the exact failing scenario...');
|
| 5 |
|
| 6 |
// Simulate the exact scenario where the user gets the error
|
|
|
|
| 1 |
import { NextRequest, NextResponse } from "next/server";
|
| 2 |
|
| 3 |
+
export async function POST() {
|
| 4 |
console.log('🧪 Testing the exact failing scenario...');
|
| 5 |
|
| 6 |
// Simulate the exact scenario where the user gets the error
|
components/editor/ask-ai/index.tsx
CHANGED
|
@@ -49,7 +49,7 @@ export function AskAI({
|
|
| 49 |
selectedElement?: HTMLElement | null;
|
| 50 |
setSelectedElement: React.Dispatch<React.SetStateAction<HTMLElement | null>>;
|
| 51 |
}) {
|
| 52 |
-
const [openrouterApiKey,
|
| 53 |
const refThink = useRef<HTMLDivElement | null>(null);
|
| 54 |
const audio = useRef<HTMLAudioElement | null>(null);
|
| 55 |
|
|
@@ -359,7 +359,7 @@ export function AskAI({
|
|
| 359 |
setisAiWorking(false);
|
| 360 |
return;
|
| 361 |
}
|
| 362 |
-
} catch
|
| 363 |
// If it looks like JSON but can't be parsed, treat as content
|
| 364 |
console.log('⚠️ Chunk looks like JSON but failed to parse, treating as content');
|
| 365 |
}
|
|
|
|
| 49 |
selectedElement?: HTMLElement | null;
|
| 50 |
setSelectedElement: React.Dispatch<React.SetStateAction<HTMLElement | null>>;
|
| 51 |
}) {
|
| 52 |
+
const [openrouterApiKey, _setOpenrouterApiKey] = useLocalStorage<string>("openrouter-api-key", "");
|
| 53 |
const refThink = useRef<HTMLDivElement | null>(null);
|
| 54 |
const audio = useRef<HTMLAudioElement | null>(null);
|
| 55 |
|
|
|
|
| 359 |
setisAiWorking(false);
|
| 360 |
return;
|
| 361 |
}
|
| 362 |
+
} catch {
|
| 363 |
// If it looks like JSON but can't be parsed, treat as content
|
| 364 |
console.log('⚠️ Chunk looks like JSON but failed to parse, treating as content');
|
| 365 |
}
|
components/editor/preview/index-simplified.tsx
CHANGED
|
@@ -1,8 +1,7 @@
|
|
| 1 |
"use client";
|
| 2 |
import { useUpdateEffect } from "react-use";
|
| 3 |
-
import { useMemo, useState, useRef, useEffect, forwardRef
|
| 4 |
import classNames from "classnames";
|
| 5 |
-
import { toast } from "sonner";
|
| 6 |
|
| 7 |
import { cn } from "@/lib/utils";
|
| 8 |
import { GridPattern } from "@/components/magic-ui/grid-pattern";
|
|
@@ -25,7 +24,7 @@ export const Preview = forwardRef<
|
|
| 25 |
isResizing,
|
| 26 |
isAiWorking,
|
| 27 |
device,
|
| 28 |
-
currentTab,
|
| 29 |
iframeRef,
|
| 30 |
isEditableModeEnabled,
|
| 31 |
onClickElement,
|
|
@@ -100,7 +99,7 @@ export const Preview = forwardRef<
|
|
| 100 |
const doc = iframe.contentDocument;
|
| 101 |
if (!doc) return;
|
| 102 |
|
| 103 |
-
|
| 104 |
if (existingStyle) return;
|
| 105 |
|
| 106 |
const style = doc.createElement('style');
|
|
@@ -142,7 +141,7 @@ export const Preview = forwardRef<
|
|
| 142 |
return () => {
|
| 143 |
iframe.removeEventListener('load', injectSmoothTransitions);
|
| 144 |
};
|
| 145 |
-
}, [currentIframeRef]);
|
| 146 |
|
| 147 |
// Add content updating class for animations
|
| 148 |
useEffect(() => {
|
|
|
|
| 1 |
"use client";
|
| 2 |
import { useUpdateEffect } from "react-use";
|
| 3 |
+
import { useMemo, useState, useRef, useEffect, forwardRef } from "react";
|
| 4 |
import classNames from "classnames";
|
|
|
|
| 5 |
|
| 6 |
import { cn } from "@/lib/utils";
|
| 7 |
import { GridPattern } from "@/components/magic-ui/grid-pattern";
|
|
|
|
| 24 |
isResizing,
|
| 25 |
isAiWorking,
|
| 26 |
device,
|
| 27 |
+
currentTab: _currentTab,
|
| 28 |
iframeRef,
|
| 29 |
isEditableModeEnabled,
|
| 30 |
onClickElement,
|
|
|
|
| 99 |
const doc = iframe.contentDocument;
|
| 100 |
if (!doc) return;
|
| 101 |
|
| 102 |
+
const existingStyle = doc.getElementById('smooth-transitions');
|
| 103 |
if (existingStyle) return;
|
| 104 |
|
| 105 |
const style = doc.createElement('style');
|
|
|
|
| 141 |
return () => {
|
| 142 |
iframe.removeEventListener('load', injectSmoothTransitions);
|
| 143 |
};
|
| 144 |
+
}, [currentIframeRef, displayHtml]);
|
| 145 |
|
| 146 |
// Add content updating class for animations
|
| 147 |
useEffect(() => {
|
components/editor/preview/index.tsx
CHANGED
|
@@ -2,7 +2,6 @@
|
|
| 2 |
import { useUpdateEffect } from "react-use";
|
| 3 |
import { useMemo, useState, useRef, useEffect, forwardRef, useCallback } from "react";
|
| 4 |
import classNames from "classnames";
|
| 5 |
-
import { toast } from "sonner";
|
| 6 |
|
| 7 |
import { cn } from "@/lib/utils";
|
| 8 |
import { GridPattern } from "@/components/magic-ui/grid-pattern";
|
|
|
|
| 2 |
import { useUpdateEffect } from "react-use";
|
| 3 |
import { useMemo, useState, useRef, useEffect, forwardRef, useCallback } from "react";
|
| 4 |
import classNames from "classnames";
|
|
|
|
| 5 |
|
| 6 |
import { cn } from "@/lib/utils";
|
| 7 |
import { GridPattern } from "@/components/magic-ui/grid-pattern";
|
components/openrouter-model-selector/index.tsx
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
import React, { useState } from 'react';
|
|
|
|
| 2 |
import { OpenRouterModel } from '../../lib/openrouter';
|
| 3 |
import { useOpenRouterModels } from '../../hooks/useOpenRouterModels';
|
| 4 |
import { Input } from '../ui/input';
|
|
@@ -17,7 +18,7 @@ interface OpenRouterModelSelectorProps {
|
|
| 17 |
export function OpenRouterModelSelector({
|
| 18 |
selectedModel,
|
| 19 |
onModelSelect,
|
| 20 |
-
apiKey,
|
| 21 |
disabled = false
|
| 22 |
}: OpenRouterModelSelectorProps) {
|
| 23 |
const [isOpen, setIsOpen] = useState(false);
|
|
@@ -78,9 +79,11 @@ export function OpenRouterModelSelector({
|
|
| 78 |
<DialogContent className="max-w-4xl max-h-[80vh] overflow-hidden">
|
| 79 |
<DialogHeader>
|
| 80 |
<DialogTitle className="flex items-center gap-2">
|
| 81 |
-
<
|
| 82 |
src="/providers/openrouter.svg"
|
| 83 |
alt="OpenRouter"
|
|
|
|
|
|
|
| 84 |
className="w-5 h-5"
|
| 85 |
/>
|
| 86 |
Select OpenRouter Model
|
|
|
|
| 1 |
import React, { useState } from 'react';
|
| 2 |
+
import Image from 'next/image';
|
| 3 |
import { OpenRouterModel } from '../../lib/openrouter';
|
| 4 |
import { useOpenRouterModels } from '../../hooks/useOpenRouterModels';
|
| 5 |
import { Input } from '../ui/input';
|
|
|
|
| 18 |
export function OpenRouterModelSelector({
|
| 19 |
selectedModel,
|
| 20 |
onModelSelect,
|
| 21 |
+
apiKey: _apiKey,
|
| 22 |
disabled = false
|
| 23 |
}: OpenRouterModelSelectorProps) {
|
| 24 |
const [isOpen, setIsOpen] = useState(false);
|
|
|
|
| 79 |
<DialogContent className="max-w-4xl max-h-[80vh] overflow-hidden">
|
| 80 |
<DialogHeader>
|
| 81 |
<DialogTitle className="flex items-center gap-2">
|
| 82 |
+
<Image
|
| 83 |
src="/providers/openrouter.svg"
|
| 84 |
alt="OpenRouter"
|
| 85 |
+
width={20}
|
| 86 |
+
height={20}
|
| 87 |
className="w-5 h-5"
|
| 88 |
/>
|
| 89 |
Select OpenRouter Model
|
lib/openrouter.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
| 1 |
-
import { NextRequest } from "next/server";
|
| 2 |
-
|
| 3 |
// OpenRouter Model Interfaces
|
| 4 |
export interface OpenRouterModelArchitecture {
|
| 5 |
input_modalities: string[];
|
|
@@ -35,7 +33,7 @@ export interface OpenRouterModel {
|
|
| 35 |
architecture: OpenRouterModelArchitecture;
|
| 36 |
pricing: OpenRouterModelPricing;
|
| 37 |
top_provider: OpenRouterModelTopProvider;
|
| 38 |
-
per_request_limits:
|
| 39 |
supported_parameters: string[];
|
| 40 |
}
|
| 41 |
|
|
|
|
|
|
|
|
|
|
| 1 |
// OpenRouter Model Interfaces
|
| 2 |
export interface OpenRouterModelArchitecture {
|
| 3 |
input_modalities: string[];
|
|
|
|
| 33 |
architecture: OpenRouterModelArchitecture;
|
| 34 |
pricing: OpenRouterModelPricing;
|
| 35 |
top_provider: OpenRouterModelTopProvider;
|
| 36 |
+
per_request_limits: Record<string, unknown>;
|
| 37 |
supported_parameters: string[];
|
| 38 |
}
|
| 39 |
|