Skip to content

Commit c09ab3e

Browse files
update templates & sandbox
1 parent 38d8e4a commit c09ab3e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+7374
-225
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ yarn-error.log*
1919
# env files
2020
.env*
2121
.env.local
22+
.env
2223

2324
# vercel
2425
.vercel

app/api/chat/route.ts

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import { getModelClient } from "@/lib/models"
44
import { toEnhancedPrompt } from "@/lib/enhanced-prompt"
55
import ratelimit from "@/lib/ratelimit"
66
import { fragmentSchema as schema } from "@/lib/schema"
7-
import type { TemplatesDataObject } from "@/lib/templates"
7+
import type { TemplatesDataObject, TemplateId } from "@/lib/templates" // Import TemplateId
8+
import templatesDataFromFile from "@/lib/templates" // Import the actual templates data
89
import { ProjectAnalyzer, type ProjectStructure } from "@/lib/project-analyzer"
910
import { streamObject, type LanguageModel, type CoreMessage } from "ai"
1011
import { logError, generateRequestId, validateRequestData } from "@/lib/debug"
@@ -46,7 +47,7 @@ export async function POST(req: Request) {
4647
messages,
4748
userID,
4849
teamID,
49-
template,
50+
selectedTemplateId, // Changed from 'template' to 'selectedTemplateId'
5051
model,
5152
config,
5253
uploadedFiles,
@@ -55,7 +56,7 @@ export async function POST(req: Request) {
5556
messages: CoreMessage[]
5657
userID: string
5758
teamID: string
58-
template: TemplatesDataObject
59+
selectedTemplateId: TemplateId // Type is now TemplateId (string)
5960
model: LLMModel
6061
config: LLMModelConfig
6162
uploadedFiles?: File[]
@@ -167,10 +168,12 @@ export async function POST(req: Request) {
167168
try {
168169
if (projectStructure && userPrompt) {
169170
console.log(`[Chat API ${requestId}] Generating enhanced prompt with project context`)
170-
systemPrompt = toEnhancedPrompt(template, userPrompt, projectStructure)
171+
// Pass the full templatesDataFromFile to toEnhancedPrompt
172+
systemPrompt = toEnhancedPrompt(templatesDataFromFile, userPrompt, projectStructure)
171173
} else {
172174
console.log(`[Chat API ${requestId}] Using standard prompt generation`)
173-
systemPrompt = generateFallbackPrompt(template)
175+
// Pass the full templatesDataFromFile to generateFallbackPrompt
176+
systemPrompt = generateFallbackPrompt(templatesDataFromFile)
174177
}
175178

176179
console.log(`[Chat API ${requestId}] System prompt generated`)
@@ -302,21 +305,21 @@ export async function POST(req: Request) {
302305
}
303306
}
304307

305-
// Fallback prompt generation function
306308
function generateFallbackPrompt(template: TemplatesDataObject): string {
307-
const validTemplates = Object.entries(template)
308-
.filter(([_, t]) => typeof t === 'object' && t !== null && 'instructions' in t && 'lib' in t)
309-
.map(([id, t], index) => {
310-
// Now t is known to be an object with at least instructions and lib
311-
const templateObject = t as { instructions: string; file?: string | null; lib: string[]; port?: number | null };
312-
return `${index + 1}. ${id}: "${templateObject.instructions}". File: ${templateObject.file || 'none'}. Dependencies: ${templateObject.lib.join(', ')}. Port: ${templateObject.port || 'none'}.`;
313-
});
314-
315309
return `You are an expert software engineer with deep knowledge of modern web development, programming languages, frameworks, and best practices.
316310
317311
Generate production-ready code based on the user's requirements using the following templates:
318312
319-
${validTemplates.join('\n')}
313+
${Object.entries(template).map(([id, t], index) => {
314+
const instructions = "instructions" in t
315+
? t.instructions
316+
: (t.files as any).instructions;
317+
const port = "port" in t
318+
? t.port
319+
: (t.files as any).port;
320+
const fileNames = Object.keys(t.files).join(', ');
321+
return `${index + 1}. ${id}: "${instructions}". Files: ${fileNames || 'none'}. Dependencies: ${t.lib.join(', ')}. Port: ${port ?? 'none'}.`;
322+
}).join('\n')}
320323
321324
IMPORTANT GUIDELINES:
322325
- Write clean, maintainable, and well-documented code

app/api/figma/analyze/route.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { type NextRequest, NextResponse } from "next/server"
22
import { FigmaIntegration } from "@/lib/figma-integration"
33

44
export async function POST(request: NextRequest) {
5-
const requestId = `figma_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`
5+
const requestId = `figma_${crypto.randomUUID()}`
66
console.log(`[Figma Analysis API ${requestId}] Processing request`)
77

88
try {
@@ -149,4 +149,4 @@ export async function POST(request: NextRequest) {
149149
{ status: statusCode }
150150
)
151151
}
152-
}
152+
}

app/api/github/auth/route.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { createServerClient, type CookieOptions } from "@supabase/ssr"
33
import { cookies } from "next/headers"
44

55
export async function POST(request: NextRequest) {
6-
const requestId = `github_auth_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`
6+
const requestId = `github_auth_${crypto.randomUUID()}`
77

88
try {
99
const { code } = await request.json()
@@ -103,4 +103,4 @@ export async function POST(request: NextRequest) {
103103
{ status: 500 }
104104
)
105105
}
106-
}
106+
}

app/api/github/import/route.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { GitHubIntegration } from "@/lib/github-integration"
55
import { ProjectAnalyzer } from "@/lib/project-analyzer"
66

77
export async function POST(request: NextRequest) {
8-
const requestId = `github_import_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`
8+
const requestId = `github_import_${crypto.randomUUID()}`
99

1010
try {
1111
const { owner, repo, maxFiles = 50 } = await request.json()
@@ -132,4 +132,4 @@ export async function POST(request: NextRequest) {
132132
{ status: statusCode }
133133
)
134134
}
135-
}
135+
}

app/api/github/repositories/route.ts

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { cookies } from "next/headers"
44
import { GitHubIntegration } from "@/lib/github-integration"
55

66
export async function GET(request: NextRequest) {
7-
const requestId = `github_repos_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`
7+
const requestId = `github_repos_${crypto.randomUUID()}`
88

99
try {
1010
const cookieStore = await cookies()
@@ -13,26 +13,22 @@ export async function GET(request: NextRequest) {
1313
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
1414
{
1515
cookies: {
16-
async get(name: string) {
17-
18-
const store = cookieStore;
19-
return store.get(name)?.value
16+
get(name: string) {
17+
return cookieStore.get(name)?.value
2018
},
21-
async set(name: string, value: string, options: CookieOptions) {
19+
set(name: string, value: string, options: CookieOptions) {
2220
try {
23-
const store = await cookieStore;
24-
store.set({ name, value, ...options })
21+
cookieStore.set(name, value, options)
2522
} catch (error) {
2623
// The `set` method was called from a Server Component.
2724
// This can be ignored if you have middleware refreshing
2825
// user sessions.
2926
// console.warn(`Failed to set cookie '${name}' from Server Component:`, error);
3027
}
3128
},
32-
async remove(name: string, options: CookieOptions) {
29+
remove(name: string, options: CookieOptions) {
3330
try {
34-
const store = await cookieStore;
35-
store.set({ name, value: '', ...options })
31+
cookieStore.set({ name, value: '', ...options })
3632
} catch (error) {
3733
// The `delete` method was called from a Server Component.
3834
// This can be ignored if you have middleware refreshing

app/api/health/route.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { healthMonitor } from "@/lib/api-health"
22
import { apiClient } from "@/lib/api-client"
33

44
export async function GET() {
5-
const requestId = `health_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`
5+
const requestId = `health_${crypto.randomUUID()}`
66

77
try {
88
console.log(`[Health API ${requestId}] Performing health check`)
@@ -98,4 +98,4 @@ export async function GET() {
9898
},
9999
)
100100
}
101-
}
101+
}

0 commit comments

Comments
 (0)