@@ -13,7 +13,10 @@ import {
1313 PagePathSchema ,
1414 SectionId ,
1515} from "@/lib/docs" ;
16- import { ReplCommandSchema , ReplOutputSchema } from "@my-code/runtime/interface" ;
16+ import {
17+ ReplCommandSchema ,
18+ ReplOutputSchema ,
19+ } from "@my-code/runtime/interface" ;
1720import { z } from "zod" ;
1821
1922const ChatParamsSchema = z . object ( {
@@ -25,8 +28,6 @@ const ChatParamsSchema = z.object({
2528 execResults : z . record ( z . string ( ) , z . array ( ReplOutputSchema ) ) ,
2629} ) ;
2730
28- type ChatParams = z . output < typeof ChatParamsSchema > ;
29-
3031export type ChatStreamEvent =
3132 | { type : "chat" ; chatId : string ; sectionId : string }
3233 | { type : "chunk" ; text : string }
@@ -41,14 +42,16 @@ export async function POST(request: NextRequest) {
4142
4243 const parseResult = ChatParamsSchema . safeParse ( await request . json ( ) ) ;
4344 if ( ! parseResult . success ) {
44- return new Response (
45- parseResult . error . issues . map ( ( e ) => e . message ) . join ( ", " ) ,
46- { status : 400 }
47- ) ;
45+ return new Response ( JSON . stringify ( parseResult . error ) , { status : 400 } ) ;
4846 }
49- const params : ChatParams = parseResult . data ;
50- const { path, userQuestion, sectionContent, replOutputs, files, execResults } =
51- params ;
47+ const {
48+ path,
49+ userQuestion,
50+ sectionContent,
51+ replOutputs,
52+ files,
53+ execResults,
54+ } = parseResult . data ;
5255
5356 const pagesList = await getPagesList ( ) ;
5457 const langName = pagesList . find ( ( lang ) => lang . id === path . lang ) ?. name ;
@@ -217,7 +220,7 @@ export async function POST(request: NextRequest) {
217220 prompt . join ( "\n" )
218221 ) ) {
219222 console . log ( "Received chunk:" , [ chunk ] ) ;
220-
223+
221224 fullText += chunk ;
222225
223226 if ( ! headerParsed ) {
@@ -309,9 +312,7 @@ export async function POST(request: NextRequest) {
309312 await addMessagesAndDiffs (
310313 chatId ,
311314 path ,
312- [
313- { role : "ai" , content : cleanMessage } ,
314- ] ,
315+ [ { role : "ai" , content : cleanMessage } ] ,
315316 diffRaw ,
316317 context
317318 ) ;
0 commit comments