mirror of
https://github.com/langgenius/webapp-conversation.git
synced 2025-12-08 17:32:27 +08:00
20 lines
553 B
TypeScript
20 lines
553 B
TypeScript
import { type NextRequest } from 'next/server'
|
|
import { APP_ID, API_KEY } from '@/config'
|
|
import { ChatClient } from '../sdk'
|
|
const userPrefix = `user_${APP_ID}:`;
|
|
const uuid = require('uuid')
|
|
|
|
export const getInfo = (request: NextRequest) => {
|
|
const sessionId = request.cookies.get('session_id')?.value || uuid.v4();
|
|
const user = userPrefix + sessionId;
|
|
return {
|
|
sessionId,
|
|
user
|
|
}
|
|
}
|
|
|
|
export const setSession = (sessionId: string) => {
|
|
return { 'Set-Cookie': `session_id=${sessionId}` }
|
|
}
|
|
|
|
export const client = new ChatClient(API_KEY) |