Skip to content

Commit 01c4dca

Browse files
authored
Merge pull request #113 from Recoupable-com/test
Release: Chat API migration progress
2 parents 9c8fd03 + 0e4f835 commit 01c4dca

File tree

73 files changed

+7963
-8
lines changed

Some content is hidden

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

73 files changed

+7963
-8
lines changed

app/api/chat/generate/route.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import type { NextRequest } from "next/server";
2+
import { NextResponse } from "next/server";
3+
import { getCorsHeaders } from "@/lib/networking/getCorsHeaders";
4+
import { handleChatGenerate } from "@/lib/chat/handleChatGenerate";
5+
6+
/**
7+
* OPTIONS handler for CORS preflight requests.
8+
*
9+
* @returns A NextResponse with CORS headers.
10+
*/
11+
export async function OPTIONS() {
12+
return new NextResponse(null, {
13+
status: 200,
14+
headers: getCorsHeaders(),
15+
});
16+
}
17+
18+
/**
19+
* POST /api/chat/generate
20+
*
21+
* Non-streaming chat endpoint that processes messages and returns a JSON response.
22+
*
23+
* Authentication: x-api-key header required.
24+
* The account ID is inferred from the API key.
25+
*
26+
* Request body:
27+
* - messages: Array of chat messages (mutually exclusive with prompt)
28+
* - prompt: String prompt (mutually exclusive with messages)
29+
* - roomId: Optional UUID of the chat room
30+
* - artistId: Optional UUID of the artist account
31+
* - model: Optional model ID override
32+
* - excludeTools: Optional array of tool names to exclude
33+
* - accountId: Optional accountId override (requires org API key)
34+
*
35+
* Response body:
36+
* - text: The generated text response
37+
* - reasoningText: Optional reasoning text (for models that support it)
38+
* - sources: Array of sources used in generation
39+
* - finishReason: The reason generation finished
40+
* - usage: Token usage information
41+
* - response: Additional response metadata
42+
*
43+
* @param request - The request object
44+
* @returns A JSON response with the generated text or error
45+
*/
46+
export async function POST(request: NextRequest): Promise<Response> {
47+
return handleChatGenerate(request);
48+
}

app/api/chat/route.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import type { NextRequest } from "next/server";
2+
import { NextResponse } from "next/server";
3+
import { getCorsHeaders } from "@/lib/networking/getCorsHeaders";
4+
import { handleChatStream } from "@/lib/chat/handleChatStream";
5+
6+
/**
7+
* OPTIONS handler for CORS preflight requests.
8+
*
9+
* @returns A NextResponse with CORS headers.
10+
*/
11+
export async function OPTIONS() {
12+
return new NextResponse(null, {
13+
status: 200,
14+
headers: getCorsHeaders(),
15+
});
16+
}
17+
18+
/**
19+
* POST /api/chat
20+
*
21+
* Streaming chat endpoint that processes messages and returns a streaming response.
22+
*
23+
* Authentication: x-api-key header required.
24+
* The account ID is inferred from the API key.
25+
*
26+
* Request body:
27+
* - messages: Array of chat messages (mutually exclusive with prompt)
28+
* - prompt: String prompt (mutually exclusive with messages)
29+
* - roomId: Optional UUID of the chat room
30+
* - artistId: Optional UUID of the artist account
31+
* - model: Optional model ID override
32+
* - excludeTools: Optional array of tool names to exclude
33+
* - accountId: Optional accountId override (requires org API key)
34+
*
35+
* @param request - The request object
36+
* @returns A streaming response or error
37+
*/
38+
export async function POST(request: NextRequest): Promise<Response> {
39+
return handleChatStream(request);
40+
}

0 commit comments

Comments
 (0)