From 6081a9f50a06eee11f6c4db3b67c6eaea8a6c088 Mon Sep 17 00:00:00 2001 From: Developers Digest <124798203+developersdigest@users.noreply.github.com> Date: Fri, 8 Aug 2025 10:25:18 -0400 Subject: [PATCH] final updates --- app/api/generate-ai-code-stream/route.ts | 62 +++++------------------- app/api/install-packages/route.ts | 6 +-- app/page.tsx | 17 +++++-- config/app.config.ts | 2 +- 4 files changed, 29 insertions(+), 58 deletions(-) diff --git a/app/api/generate-ai-code-stream/route.ts b/app/api/generate-ai-code-stream/route.ts index 39a4bfa..c3fa83e 100644 --- a/app/api/generate-ai-code-stream/route.ts +++ b/app/api/generate-ai-code-stream/route.ts @@ -1474,16 +1474,7 @@ It's better to have 3 complete files than 10 incomplete files.` // Validate generated code for truncation issues const truncationWarnings: string[] = []; - // Check for common truncation patterns - be more selective about ellipsis - const ellipsisCount = (generatedCode.match(/\.\.\./g) || []).length; - const spreadCount = (generatedCode.match(/\.\.\.[\w]+/g) || []).length; - const suspiciousEllipsis = ellipsisCount > spreadCount && - generatedCode.includes('...') && - !generatedCode.includes('Loading...'); - - if (suspiciousEllipsis) { - truncationWarnings.push('Code contains suspicious "..." patterns that may indicate truncation'); - } + // Skip ellipsis checking entirely - too many false positives with spread operators, loading text, etc. // Check for unclosed file tags const fileOpenCount = (generatedCode.match(/...'); - - // Only flag missing export for component files, not main.jsx or index files - if (!hasExport && content.length > 100 && !filePath.includes('main.') && !filePath.includes('index.')) { - truncationWarnings.push(`File ${filePath} missing export statement`); - } - - // Check for functions without return only if it's a component function - if (content.includes('function') && !hasReturn && !content.includes('=>') && - content.includes('(') && content.includes(')') && content.length > 100) { - // Only flag if it looks like a React component (has JSX) - if (content.includes('<') && content.includes('>')) { - truncationWarnings.push(`File ${filePath} has function without return statement`); - } - } - - // Only flag abrupt ending if file is really short or clearly incomplete - if (!hasClosingBrace && content.length < 50 && content.trim() !== '') { - truncationWarnings.push(`File ${filePath} appears to end abruptly`); - } - - // Check for unmatched brackets - with a tolerance for template literals + // Only check for severely unmatched brackets (more than 3 difference) const openBraces = (content.match(/{/g) || []).length; const closeBraces = (content.match(/}/g) || []).length; const braceDiff = Math.abs(openBraces - closeBraces); - if (braceDiff > 1) { // Allow small differences due to template literals - truncationWarnings.push(`File ${filePath} has unmatched braces (${openBraces} open, ${closeBraces} closed)`); + if (braceDiff > 3) { // Only flag severe mismatches + truncationWarnings.push(`File ${filePath} has severely unmatched braces (${openBraces} open, ${closeBraces} closed)`); } - const openParens = (content.match(/\(/g) || []).length; - const closeParens = (content.match(/\)/g) || []).length; - const parenDiff = Math.abs(openParens - closeParens); - if (parenDiff > 2) { // Allow small differences - truncationWarnings.push(`File ${filePath} has unmatched parentheses`); + // Check if file is extremely short and looks incomplete + if (content.length < 20 && content.includes('function') && !content.includes('}')) { + truncationWarnings.push(`File ${filePath} appears severely truncated`); } } } diff --git a/app/api/install-packages/route.ts b/app/api/install-packages/route.ts index 952d9fc..59d305e 100644 --- a/app/api/install-packages/route.ts +++ b/app/api/install-packages/route.ts @@ -183,10 +183,10 @@ except Exception as e: // Install only packages that aren't already installed const packageList = packagesToInstall.join(' '); + // Only send the npm install command message if we're actually installing new packages await sendProgress({ - type: 'command', - command: `npm install ${packageList}`, - message: `Installing ${packagesToInstall.length} new package(s)...` + type: 'info', + message: `Installing ${packagesToInstall.length} new package(s): ${packagesToInstall.join(', ')}` }); const installResult = await sandboxInstance.runCode(` diff --git a/app/page.tsx b/app/page.tsx index 0217103..fdf80b6 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -298,7 +298,10 @@ export default function AISandboxPage() { switch (data.type) { case 'command': - addChatMessage(data.command, 'command', { commandType: 'input' }); + // Don't show npm install commands - they're handled by info messages + if (!data.command.includes('npm install')) { + addChatMessage(data.command, 'command', { commandType: 'input' }); + } break; case 'output': addChatMessage(data.message, 'command', { commandType: 'output' }); @@ -529,7 +532,8 @@ Tip: I automatically detect and install npm packages from your code imports (lik break; case 'command': - if (data.command) { + // Don't show npm install commands - they're handled by info messages + if (data.command && !data.command.includes('npm install')) { addChatMessage(data.command, 'command', { commandType: 'input' }); } break; @@ -585,6 +589,13 @@ Tip: I automatically detect and install npm packages from your code imports (lik case 'warning': addChatMessage(`${data.message}`, 'system'); break; + + case 'info': + // Show info messages, especially for package installation + if (data.message) { + addChatMessage(data.message, 'system'); + } + break; } } catch (e) { // Ignore parse errors @@ -3270,7 +3281,7 @@ Focus on the key sections and content, making it clean and modern.`; {/* Right Panel - Preview or Generation (2/3 of remaining width) */}
-
+