feat: 重新对接了会话及相关的接口
This commit is contained in:
85
src/renderer/api/SessionsApi.ts
Normal file
85
src/renderer/api/SessionsApi.ts
Normal file
@@ -0,0 +1,85 @@
|
||||
import { getRequest, postRequest, ResponseModel } from '@utils/request'
|
||||
|
||||
// 创建会话 的请求参数和响应数据结构
|
||||
export interface CreateSessionRequest {
|
||||
title?: string
|
||||
tenant_id_query?: string
|
||||
}
|
||||
|
||||
export interface CreateSessionResponse {
|
||||
session_id: string
|
||||
user_id: string
|
||||
tenant_id: string
|
||||
title: string
|
||||
}
|
||||
|
||||
export const createSession = async (params: CreateSessionRequest) => {
|
||||
const res: ResponseModel = await postRequest('/nianxx/api/sessions', params)
|
||||
return res.data as CreateSessionResponse
|
||||
}
|
||||
|
||||
|
||||
// 获取会话列表 的请求参数和响应数据结构
|
||||
export interface SessionListRequest {
|
||||
tenant_id_query?: string
|
||||
limit?: number
|
||||
offset?: number
|
||||
}
|
||||
|
||||
export interface SessionListResponse {
|
||||
sessions: Array<SessionListRecords>
|
||||
total: number
|
||||
}
|
||||
|
||||
export interface SessionListRecords {
|
||||
session_id: string
|
||||
user_id: string
|
||||
tenant_id: string
|
||||
title: string
|
||||
status: string
|
||||
created_at: string
|
||||
updated_at: string
|
||||
}
|
||||
|
||||
export const getSessionList = async (params: SessionListRequest) => {
|
||||
const res: ResponseModel = await getRequest('/nianxx/api/sessions', params)
|
||||
return res.data as SessionListResponse
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// 获取会话消息历史 的请求参数和响应数据结构
|
||||
export interface SessionMessagesRequest {
|
||||
user_id_query?: string
|
||||
tenant_id_query?: number
|
||||
limit?: number
|
||||
offset?: number
|
||||
session_id: string
|
||||
}
|
||||
|
||||
export interface SessionMessagesResponse {
|
||||
messages: Array<SessionMessageRecords>
|
||||
total: number
|
||||
}
|
||||
|
||||
export interface SessionMessageRecords {
|
||||
id: number
|
||||
session_id: string
|
||||
role: string
|
||||
content: string
|
||||
source: string
|
||||
message_id: string | null
|
||||
created_at: string
|
||||
timestamp?: number
|
||||
}
|
||||
|
||||
// 获取会话消息历史 的函数实现
|
||||
export const getSessionMessages = async (params: SessionMessagesRequest) => {
|
||||
const res: ResponseModel = await getRequest(`/nianxx/api/sessions/${params.session_id}/messages`, {
|
||||
limit: params.limit,
|
||||
offset: params.offset,
|
||||
user_id_query: params.user_id_query,
|
||||
tenant_id_query: params.tenant_id_query,
|
||||
})
|
||||
return res.data as SessionMessagesResponse
|
||||
}
|
||||
Reference in New Issue
Block a user