diff --git a/web/apps/web-ele/src/api/ai-platform/ai-platform.ts b/web/apps/web-ele/src/api/ai-platform/ai-platform.ts index d8f0ea9..1964509 100644 --- a/web/apps/web-ele/src/api/ai-platform/ai-platform.ts +++ b/web/apps/web-ele/src/api/ai-platform/ai-platform.ts @@ -137,6 +137,106 @@ export interface DefaultModel { output_price?: number; } +/** AI 应用 */ +export interface AIApp { + id: string; + name: string; + code: string; + description: string; + icon: string; + app_type: 'agent' | 'chat' | 'completion' | 'workflow'; + status: 'disabled' | 'draft' | 'published'; + model_id: null | string; + model_name: string; + system_prompt: string; + temperature: number; + top_p: number; + max_tokens: number; + opening_statement: string; + suggested_questions: string[]; + workflow_definition: Record; + is_public: boolean; + conversation_count: number; + message_count: number; + sort?: number; + sys_create_datetime?: string; + sys_update_datetime?: string; +} + +/** 应用列表项 */ +export interface AppListItem { + id: string; + name: string; + code: string; + description: string; + icon: string; + app_type: string; + status: string; + model_name: string; + is_public: boolean; + conversation_count: number; + message_count: number; + sys_create_datetime?: string; +} + +/** 创建应用 */ +export interface AppCreateInput { + name: string; + code: string; + description?: string; + icon?: string; + app_type?: string; + model_id?: string; + system_prompt?: string; + temperature?: number; + top_p?: number; + max_tokens?: number; + opening_statement?: string; + suggested_questions?: string[]; + workflow_definition?: Record; + is_public?: boolean; + sort?: number; +} + +/** 通用 AI 对话 */ +export interface Conversation { + id: string; + app_id: string; + app_name: string; + title: string; + message_count: number; + total_tokens: number; + is_pinned: boolean; + sort?: number; + sys_create_datetime?: string; + sys_update_datetime?: string; +} + +/** 通用 AI 对话列表项 */ +export interface ConversationListItem { + id: string; + title: string; + message_count: number; + is_pinned: boolean; + sys_update_datetime?: string; +} + +/** 通用 AI 消息 */ +export interface Message { + id: string; + role: 'assistant' | 'system' | 'user'; + content: string; + status: 'completed' | 'failed' | 'pending' | 'stopped'; + prompt_tokens: number; + completion_tokens: number; + total_tokens: number; + model_name: string; + latency: number; + error_message: string; + feedback: string; + sys_create_datetime?: string; +} + export type WorkflowType = 'application' | 'automation' | 'data_process' | 'form' | 'general' | 'report'; /** AI 工作流 */ @@ -387,6 +487,170 @@ export async function deleteModelApi(id: string) { return requestClient.delete(`${BASE_URL}/model/${id}`); } +// ============ 应用 API ============ + +/** 获取应用列表 */ +export async function getAppListApi(params?: { + app_type?: string; + name?: string; + page?: number; + pageSize?: number; + status?: string; +}) { + return requestClient.get>( + `${BASE_URL}/apps`, + { params }, + ); +} + +/** 获取已发布应用列表 */ +export async function getPublishedAppsApi() { + return requestClient.get(`${BASE_URL}/apps/published`); +} + +/** 获取应用详情 */ +export async function getAppDetailApi(id: string) { + return requestClient.get(`${BASE_URL}/apps/${id}`); +} + +/** 根据编码获取应用 */ +export async function getAppByCodeApi(code: string) { + return requestClient.get(`${BASE_URL}/apps/code/${code}`); +} + +/** 创建应用 */ +export async function createAppApi(data: AppCreateInput) { + return requestClient.post(`${BASE_URL}/apps`, data); +} + +/** 更新应用 */ +export async function updateAppApi(id: string, data: Partial) { + return requestClient.put(`${BASE_URL}/apps/${id}`, data); +} + +/** 删除应用 */ +export async function deleteAppApi(id: string) { + return requestClient.delete(`${BASE_URL}/apps/${id}`); +} + +/** 发布应用 */ +export async function publishAppApi(id: string) { + return requestClient.post(`${BASE_URL}/apps/${id}/publish`); +} + +/** 停用应用 */ +export async function disableAppApi(id: string) { + return requestClient.post(`${BASE_URL}/apps/${id}/disable`); +} + +// ============ 通用对话 API ============ + +/** 获取对话列表 */ +export async function getConversationListApi( + appId: string, + params?: { page?: number; pageSize?: number }, +) { + return requestClient.get>( + `${BASE_URL}/chat/conversations`, + { params: { app_id: appId, ...params } }, + ); +} + +/** 创建对话 */ +export async function createConversationApi(data: { + app_id: string; + title?: string; +}) { + return requestClient.post( + `${BASE_URL}/chat/conversations`, + data, + ); +} + +/** 获取对话详情 */ +export async function getConversationDetailApi(id: string) { + return requestClient.get( + `${BASE_URL}/chat/conversations/${id}`, + ); +} + +/** 更新对话 */ +export async function updateConversationApi( + id: string, + data: { is_pinned?: boolean; title?: string }, +) { + return requestClient.put( + `${BASE_URL}/chat/conversations/${id}`, + data, + ); +} + +/** 删除对话 */ +export async function deleteConversationApi(id: string) { + return requestClient.delete(`${BASE_URL}/chat/conversations/${id}`); +} + +/** 获取消息列表 */ +export async function getMessagesApi(conversationId: string, limit?: number) { + return requestClient.get( + `${BASE_URL}/chat/conversations/${conversationId}/messages`, + { params: { limit } }, + ); +} + +/** 发送消息 */ +export async function sendMessageApi(conversationId: string, content: string) { + return requestClient.post( + `${BASE_URL}/chat/conversations/${conversationId}/messages`, + { content }, + ); +} + +/** 聊天流式事件类型 */ +export interface ChatStreamEvent { + type: 'content' | 'done' | 'error'; + content?: string; + message?: { + content: string; + id: string; + latency: number; + tokens: number; + }; + error?: string; +} + +/** 流式发送消息 */ +export function sendMessageStreamApi( + conversationId: string, + content: string, + onEvent: (event: ChatStreamEvent) => void, + onError?: (error: Error) => void, + onComplete?: () => void, +): () => void { + return streamRequestClient( + `${BASE_URL}/chat/conversations/${conversationId}/messages/stream`, + { content }, + { + onData: onEvent, + onError: (error) => { + console.error('Stream error:', error); + onError?.(error); + }, + onComplete, + }, + ); +} + +/** 消息反馈 */ +export async function messageFeedbackApi( + messageId: string, + feedback: 'dislike' | 'like' | '', +) { + return requestClient.post(`${BASE_URL}/chat/messages/${messageId}/feedback`, { + feedback, + }); +} + /** 获取节点 Schema 列表 */ export async function getNodeSchemasApi() { return requestClient.get(`${BASE_URL}/workflow/nodes/schemas`);