From a89b24f97a16d343229b26f2cafacdbb5a61ac8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?cls=5F=E5=AE=81=E6=B3=A2=E6=9C=AC=E6=9C=BA?= <908705107@qq.com> Date: Tue, 9 Jun 2026 00:21:16 +0800 Subject: [PATCH] Trim legacy AI app APIs --- .../src/api/ai-platform/ai-platform.ts | 284 +----------------- 1 file changed, 3 insertions(+), 281 deletions(-) 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 1219dbc..d8f0ea9 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 @@ -3,8 +3,7 @@ import { streamRequestClient } from '#/api/stream-request'; import { useAppContextStore } from '#/store/app-context'; /** - * 注入系统变量到工作流输入 - * 自动添加 application_id、application_code、form_code 等系统变量 + * Inject current application context into AI requests. */ function injectSystemVariables( inputs: Record, @@ -12,20 +11,14 @@ function injectSystemVariables( const appContextStore = useAppContextStore(); const result = { ...inputs }; - // 注入 application_id(子应用模式下) if (appContextStore.currentApp?.id && !result.application_id) { result.application_id = appContextStore.currentApp.id; } - // 注入 application_code(子应用模式下) if (appContextStore.currentApp?.code && !result.application_code) { result.application_code = appContextStore.currentApp.code; } - // 注入 form_code(如果 inputs 中已经包含) - // form_code 通常由调用方(如表单列表)传入 - // 这里不做额外处理,保持原样传递 - return result; } @@ -144,103 +137,6 @@ 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; - created_at: string; - updated_at: 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; - created_at: 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[]; - is_public?: boolean; -} - -/** 对话 */ -export interface Conversation { - id: string; - app_id: string; - app_name: string; - title: string; - message_count: number; - total_tokens: number; - is_pinned: boolean; - created_at: string; - updated_at: string; -} - -/** 对话列表项 */ -export interface ConversationListItem { - id: string; - title: string; - message_count: number; - is_pinned: boolean; - updated_at: string; -} - -/** 消息 */ -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; - created_at: string; -} - -/** 工作流类型 */ export type WorkflowType = 'application' | 'automation' | 'data_process' | 'form' | 'general' | 'report'; /** AI 工作流 */ @@ -491,179 +387,6 @@ 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}/app/list`, - { params }, - ); -} - -/** 获取已发布应用列表 */ -export async function getPublishedAppsApi() { - return requestClient.get(`${BASE_URL}/app/published`); -} - -/** 获取应用详情 */ -export async function getAppDetailApi(id: string) { - return requestClient.get(`${BASE_URL}/app/${id}`); -} - -/** 根据编码获取应用 */ -export async function getAppByCodeApi(code: string) { - return requestClient.get(`${BASE_URL}/app/code/${code}`); -} - -/** 创建应用 */ -export async function createAppApi(data: AppCreateInput) { - return requestClient.post(`${BASE_URL}/app`, data); -} - -/** 更新应用 */ -export async function updateAppApi(id: string, data: Partial) { - return requestClient.put(`${BASE_URL}/app/${id}`, data); -} - -/** 删除应用 */ -export async function deleteAppApi(id: string) { - return requestClient.delete(`${BASE_URL}/app/${id}`); -} - -/** 发布应用 */ -export async function publishAppApi(id: string) { - return requestClient.post(`${BASE_URL}/app/${id}/publish`); -} - -/** 停用应用 */ -export async function disableAppApi(id: string) { - return requestClient.post(`${BASE_URL}/app/${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, - }); -} - -/** 重新生成消息 */ -export async function regenerateMessageApi(messageId: string) { - return requestClient.post( - `${BASE_URL}/chat/messages/${messageId}/regenerate`, - ); -} - -// ============ 工作流 API ============ - /** 获取节点 Schema 列表 */ export async function getNodeSchemasApi() { return requestClient.get(`${BASE_URL}/workflow/nodes/schemas`); @@ -966,7 +689,7 @@ export function runWorkflowStreamApi( onComplete?: () => void, useDraft: boolean = false, ): () => void { - // 自动注入系统变量(application_id 等) + // Inject current application context. const finalInputs = injectSystemVariables(inputs); return streamRequestClient( @@ -1488,14 +1211,13 @@ export function sendAgentMessageStream( data: { attachments?: AttachmentInput[]; conversation_id?: string; - form_code?: string; message: string; }, onEvent: (event: AgentChatEvent) => void, onError?: (error: Error) => void, onComplete?: () => void, ) { - // 自动注入系统变量(application_id、form_code 等) + // Inject current application context. const finalData = injectSystemVariables(data); return streamRequestClient(