feat: Add base project structure with API and web components
This commit is contained in:
112
web/src/api/application.ts
Normal file
112
web/src/api/application.ts
Normal file
@@ -0,0 +1,112 @@
|
||||
import { request } from '@/utils/request'
|
||||
import type { Application } from '@/views/ApplicationManagement/types'
|
||||
import type { Config } from '@/views/ApplicationConfig/types'
|
||||
import { handleSSE } from '@/utils/stream'
|
||||
|
||||
// 应用列表
|
||||
export const getApplicationListUrl = '/apps'
|
||||
export const getApplicationList = (data: Record<string, unknown>) => {
|
||||
return request.get(getApplicationListUrl, data)
|
||||
}
|
||||
// 获取应用配置
|
||||
export const getApplicationConfig = (id: string) => {
|
||||
return request.get(`/apps/${id}/config`)
|
||||
}
|
||||
// 获取集群应配置
|
||||
export const getMultiAgentConfig = (id: string) => {
|
||||
return request.get(`/apps/${id}/multi-agent`)
|
||||
}
|
||||
// 应用详情
|
||||
export const getApplication = (id: string) => {
|
||||
return request.get(`/apps/${id}`)
|
||||
}
|
||||
// 更新应用
|
||||
export const updateApplication = (id: string, values: Application) => {
|
||||
return request.put(`/apps/${id}`, values)
|
||||
}
|
||||
// 创建应用
|
||||
export const addApplication = (values: Application) => {
|
||||
return request.post('/apps', values)
|
||||
}
|
||||
// 保存Agent配置
|
||||
export const saveAgentConfig = (app_id: string, values: Config) => {
|
||||
return request.put(`/apps/${app_id}/config`, values)
|
||||
}
|
||||
// 保存集群配置
|
||||
export const saveMultiAgentConfig = (app_id: string, values: Config) => {
|
||||
return request.put(`/apps/${app_id}/multi-agent`, values)
|
||||
}
|
||||
// 模型比对试运行
|
||||
export const runCompare = (app_id: string, values: Record<string, unknown>, onMessage?: (data: string) => void) => {
|
||||
return handleSSE(`/apps/${app_id}/draft/run/compare`, values, onMessage)
|
||||
}
|
||||
export const draftRun = (app_id: string, values: Record<string, unknown>, onMessage?: (data: string) => void) => {
|
||||
return handleSSE(`/apps/${app_id}/draft/run`, values, onMessage)
|
||||
}
|
||||
// 删除应用
|
||||
export const deleteApplication = (app_id: string) => {
|
||||
return request.delete(`/apps/${app_id}`)
|
||||
}
|
||||
// 发布版本列表
|
||||
export const getReleaseList = (app_id: string) => {
|
||||
return request.get(`/apps/${app_id}/releases`)
|
||||
}
|
||||
// 发布版本
|
||||
export const publishRelease = (app_id: string, values: Record<string, unknown>) => {
|
||||
return request.post(`/apps/${app_id}/publish`, values)
|
||||
}
|
||||
// 回滚版本
|
||||
export const rollbackRelease = (app_id: string, version: string) => {
|
||||
return request.post(`/apps/${app_id}/rollback/${version}`)
|
||||
}
|
||||
// 发布版本分享
|
||||
export const shareRelease = (app_id: string, release_id: string) => {
|
||||
return request.post(`/apps/${app_id}/releases/${release_id}/share`, {
|
||||
"is_enabled": true,
|
||||
"require_password": false,
|
||||
"allow_embed": true
|
||||
})
|
||||
}
|
||||
// 获取体验对话历史
|
||||
export const getConversationHistory = (share_token: string, data: { page: number; pagesize: number }) => {
|
||||
return request.get(`/public/share/conversations`, data, {
|
||||
headers: {
|
||||
'Authorization': `Bearer ${localStorage.getItem(`shareToken_${share_token}`)}`
|
||||
}
|
||||
})
|
||||
}
|
||||
// 发送体验对话
|
||||
export const sendConversation = (share_token: string, values: {
|
||||
message: string;
|
||||
web_search: boolean;
|
||||
memory: boolean;
|
||||
stream: boolean;
|
||||
conversation_id: string | null;
|
||||
}, onMessage, shareToken: string) => {
|
||||
// return request.post(`/public/share/chat`, values, {
|
||||
// headers: {
|
||||
// 'Authorization': `Bearer ${localStorage.getItem(`shareToken_${share_token}`)}`
|
||||
// }
|
||||
// })
|
||||
return handleSSE(`/public/share/chat`, values, onMessage, {
|
||||
headers: {
|
||||
'Authorization': `Bearer ${shareToken}`
|
||||
}
|
||||
})
|
||||
}
|
||||
// 获取体验会话详情
|
||||
export const getConversationDetail = (share_token: string, conversation_id: string) => {
|
||||
return request.get(`/public/share/conversations/${conversation_id}`, {}, {
|
||||
headers: {
|
||||
'Authorization': `Bearer ${localStorage.getItem(`shareToken_${share_token}`)}`
|
||||
}
|
||||
})
|
||||
}
|
||||
// 获取体验对话token
|
||||
export const getShareToken = (share_token: string, user_id: string) => {
|
||||
return request.post(`/public/share/${share_token}/token`, { user_id })
|
||||
}
|
||||
// 复制应用
|
||||
export const copyApplication = (app_id: string, new_name: string) => {
|
||||
return request.post(`/apps/${app_id}/copy?new_name=${new_name}`)
|
||||
}
|
||||
Reference in New Issue
Block a user