@@ -5,14 +5,14 @@ import { cache } from "react";
55import { ChatOpenAI } from "@langchain/openai" ;
66import { PromptTemplate } from "@langchain/core/prompts" ;
77import { StringOutputParser } from "@langchain/core/output_parsers" ;
8- import { generateEasyMediumPrompt , generateNthProjectPhase , generateProjectPlanDocs , initialDocsGenerationPrompt , ultraProjectChatBotPrompt } from "../prompts/ReverseArchitecture" ;
8+ import { ultraProjectChatBotPrompt } from "../prompts/ReverseArchitecture" ;
99const openaiKey = process . env . OPENAI_API_KEY ;
1010const llm = new ChatOpenAI ( {
1111 openAIApiKey : openaiKey ,
1212 model : "gpt-5-mini-2025-08-07"
1313} )
1414
15- const llm2 = new ChatOpenAI ( {
15+ const llm2 = new ChatOpenAI ( {
1616 openAIApiKey : openaiKey ,
1717 model : "gpt-5-nano-2025-08-07"
1818} )
@@ -24,8 +24,6 @@ export interface ProjectMessage {
2424 type : 'user' | 'assistant' ;
2525 prompt ?: string ;
2626 content : string ;
27- projectDocsId ?: string ;
28- docsName ?: string ;
2927 timestamp : string ;
3028}
3129
@@ -434,17 +432,17 @@ export async function updateProjectMessages(projectId: string, messages: Project
434432}
435433
436434
437- export async function projectChatBot ( userInput : string , projectFramework : string , conversationHistory : any [ ] , projectArchitecture : any , projectAnalysis : string ) {
435+ export async function projectChatBot ( userInput : string , projectFramework : string , conversationHistory : any [ ] , projectArchitecture : any ) : Promise < string | { error : string } > {
438436 const { userId } = await auth ( ) ;
439- if ( ! userId ) {
437+ if ( ! userId ) {
440438 return { error : 'Unauthorized' } ;
441439 }
442440
443441 // Format conversation history for the prompt
444442 const formattedHistory = conversationHistory . map ( msg =>
445443 `${ msg . type === 'user' ? 'User' : 'Assistant' } : ${ msg . content } `
446444 ) . join ( '\n' ) ;
447-
445+
448446
449447 const prompt = PromptTemplate . fromTemplate ( ultraProjectChatBotPrompt ) ;
450448 const chain = prompt . pipe ( llmWithWeb ) . pipe ( new StringOutputParser ( ) ) ;
@@ -458,86 +456,6 @@ export async function projectChatBot( userInput: string, projectFramework: strin
458456 return response ;
459457}
460458
461- export async function generatePrompt ( userInput : string , projectFramework : string , conversationHistory : any [ ] , projectAnalysis : string ) {
462- const { userId } = await auth ( ) ;
463- if ( ! userId ) {
464- return { error : 'Unauthorized' } ;
465- }
466- // Format conversation history for the prompt
467- const formattedHistory = conversationHistory . map ( msg =>
468- `${ msg . type === 'user' ? 'User' : 'Assistant' } : ${ msg . content } `
469- ) . join ( '\n' ) ;
470-
471- const prompt = PromptTemplate . fromTemplate ( generateEasyMediumPrompt ) ;
472- const chain = prompt . pipe ( llm ) . pipe ( new StringOutputParser ( ) ) ;
473- const response = await chain . invoke ( {
474- userQuery : userInput ,
475- framework : projectFramework ,
476- projectAnalysis : projectAnalysis ,
477- conversationHistory : formattedHistory
478- } ) ;
479- return response ;
480- }
481-
482- export async function initialDocsGeneration ( userInput : string , projectFramework : string , conversationHistory : any [ ] , projectAnalysis : string ) {
483- const { userId } = await auth ( ) ;
484- if ( ! userId ) {
485- return { error : 'Unauthorized' } ;
486- }
487- // Format conversation history for the prompt
488- const formattedHistory = conversationHistory . map ( msg =>
489- `${ msg . type === 'user' ? 'User' : 'Assistant' } : ${ msg . content } `
490- ) . join ( '\n' ) ;
491-
492- const prompt = PromptTemplate . fromTemplate ( initialDocsGenerationPrompt ) ;
493- const chain = prompt . pipe ( llm ) . pipe ( new StringOutputParser ( ) ) ;
494- const response = await chain . invoke ( {
495- userQuery : userInput ,
496- framework : projectFramework ,
497- projectAnalysis : projectAnalysis ,
498- conversationHistory : formattedHistory
499- } ) ;
500- return response ;
501- }
502-
503- // Create project context docs
504- export async function createProjectContextDocs (
505- projectChatId : any ,
506- contextName : string ,
507- summarizedContext : string ,
508- projectRules ?: string ,
509- humanReview ?: string ,
510- plan ?: string ,
511- phases ?: any [ ] ,
512- phaseCount ?: number
513- ) {
514- const { userId } = await auth ( ) ;
515- if ( ! userId ) {
516- return { error : 'Unauthorized' } ;
517- }
518-
519- try {
520-
521- // Create new project context docs
522- const projectContextDocs = await db . projectContextDocs . create ( {
523- data : {
524- projectChatId,
525- contextName,
526- summarizedContext,
527- projectRules,
528- humanReview,
529- plan,
530- phases : phases as any ,
531- phaseCount
532- }
533- } ) ;
534-
535- return { success : true , projectContextDocs } ;
536- } catch ( error ) {
537- console . error ( "Error creating project context docs:" , error ) ;
538- return { error : 'Failed to create project context docs' } ;
539- }
540- }
541459
542460// Get project context docs by ID
543461export async function getProjectContextDocs ( projectChatId : any ) {
@@ -566,51 +484,6 @@ export async function getProjectContextDocs(projectChatId: any) {
566484 }
567485}
568486
569- export async function generateProjectPlan ( framework : string , phaseCount : string , detailedAnalysis : string , requirement : string ) {
570- const { userId } = await auth ( ) ;
571- if ( ! userId ) {
572- return { error : 'Unauthorized' } ;
573- }
574-
575- const prompt = PromptTemplate . fromTemplate ( generateProjectPlanDocs ) ;
576- const chain = prompt . pipe ( llm ) . pipe ( new StringOutputParser ( ) ) ;
577- const response = await chain . invoke ( {
578- framework : framework ,
579- phaseCount : phaseCount ,
580- projectAnalysis : detailedAnalysis ,
581- requirement : requirement
582- } ) ;
583- return response ;
584- }
585-
586- export async function generateNthPhase ( plan : string , framework : string , requirement : string , phaseNum : string ) {
587- const { userId } = await auth ( ) ;
588- if ( ! userId ) {
589- return { error : 'Unauthorized' } ;
590- }
591-
592- const prompt = PromptTemplate . fromTemplate ( generateNthProjectPhase ) ;
593- const chain = prompt . pipe ( llm ) . pipe ( new StringOutputParser ( ) ) ;
594- const response = await chain . invoke ( {
595- plan : plan ,
596- framework : framework ,
597- requirement : requirement ,
598- phaseNum : phaseNum
599- } ) ;
600- return response ;
601- }
602-
603- export async function updateProjectContextDocs ( projectContextDocsId : string , plan : string , phases : any [ ] ) {
604- const { userId } = await auth ( ) ;
605- if ( ! userId ) {
606- return { error : 'Unauthorized' } ;
607- }
608-
609- await db . projectContextDocs . update ( {
610- where : { id : projectContextDocsId } ,
611- data : { plan : plan , phases : phases as any }
612- } )
613- }
614487
615488// System-level helper for Inngest to save the initial assistant message without requiring auth
616489export async function saveInitialMessageForInngestRevArchitecture (
0 commit comments