From 6030831f55f686fb7716466d164293cd9fc9daad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=96=AF=E7=8B=82=E7=9A=84=E7=8B=AE=E5=AD=90Li?= <15040126243@163.com> Date: Wed, 17 Jun 2026 09:16:39 +0800 Subject: [PATCH] =?UTF-8?q?add=20=E5=A2=9E=E5=8A=A0=20snail-ai-server=20?= =?UTF-8?q?=E6=8E=A7=E5=88=B6=E5=8F=B0=E8=AE=BF=E9=97=AE=E8=8F=9C=E5=8D=95?= =?UTF-8?q?=20update=20=E4=BC=98=E5=8C=96=E5=B0=86=E8=87=AA=E8=A1=8C?= =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E7=9A=84ai=E8=81=8A=E5=A4=A9=E5=AE=A4?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E6=94=B9=E4=B8=BA=E5=86=85=E5=B5=8C=20snail-?= =?UTF-8?q?ai=20=E8=87=AA=E5=B8=A6=E7=9A=84=E8=81=8A=E5=A4=A9=E5=AE=A4?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.development | 3 + .env.production | 3 + src/api/ai/agent/index.ts | 156 +------- src/api/ai/agent/types.ts | 43 -- src/types/env.d.ts | 1 + src/views/ai/chat/index.vue | 208 ++-------- src/views/ai/chat/modules/chat-input.vue | 64 --- src/views/ai/chat/modules/chat-main.vue | 437 --------------------- src/views/ai/chat/modules/chat-sidebar.vue | 228 ----------- src/views/monitor/snailai/index.vue | 20 + src/views/system/config/index.vue | 7 +- 11 files changed, 70 insertions(+), 1100 deletions(-) delete mode 100644 src/views/ai/chat/modules/chat-input.vue delete mode 100644 src/views/ai/chat/modules/chat-main.vue delete mode 100644 src/views/ai/chat/modules/chat-sidebar.vue create mode 100644 src/views/monitor/snailai/index.vue diff --git a/.env.development b/.env.development index 6104112b..5bfb9da6 100644 --- a/.env.development +++ b/.env.development @@ -17,6 +17,9 @@ VITE_APP_MONITOR_ADMIN = 'http://localhost:9090/admin/applications' # SnailJob 控制台地址 VITE_APP_SNAILJOB_ADMIN = 'http://localhost:8800/snail-job' +# SnailAI 控制台地址 +VITE_APP_SNAILAI_ADMIN = 'http://localhost:8900/snail-ai' + VITE_APP_PORT = 80 # 接口加密功能开关(如需关闭 后端也必须对应关闭) diff --git a/.env.production b/.env.production index e6d821e2..45011d88 100644 --- a/.env.production +++ b/.env.production @@ -14,6 +14,9 @@ VITE_APP_MONITOR_ADMIN = '/admin/applications' # SnailJob 控制台地址 VITE_APP_SNAILJOB_ADMIN = '/snail-job' +# SnailAI 控制台地址 +VITE_APP_SNAILAI_ADMIN = '/snail-ai' + # 生产环境 VITE_APP_BASE_API = '/prod-api' diff --git a/src/api/ai/agent/index.ts b/src/api/ai/agent/index.ts index 6691febc..3e4d324d 100644 --- a/src/api/ai/agent/index.ts +++ b/src/api/ai/agent/index.ts @@ -1,62 +1,6 @@ import type { AxiosPromise } from '@/utils/api-types'; -import request, { globalHeaders } from '@/utils/request'; -import { getLanguage } from '@/lang'; -import type { - AgentChatRequest, - AgentChatSyncResponse, - AgentItem, - ConversationMessage, - ConversationSummaryItem, - ConversationSummaryList, - SnailOpenApiUser -} from './types'; - -export const fetchMyAgents = (): AxiosPromise => { - return request({ - url: '/snail-ai/agents', - method: 'get' - }); -}; - -export const fetchAgentDetail = (id: number): AxiosPromise => { - return request({ - url: `/snail-ai/agent/${id}`, - method: 'get' - }); -}; - -export const fetchAgentConversations = ( - id: number, - params: { page?: number; size?: number; start?: string; end?: string } -): AxiosPromise => { - return request({ - url: `/snail-ai/agent/${id}/conversations`, - method: 'get', - params - }); -}; - -export const fetchConversationMessages = (agentId: number, conversationId: string): AxiosPromise => { - return request({ - url: `/snail-ai/agent/${agentId}/conversation/${conversationId}/messages`, - method: 'get' - }); -}; - -export const createConversation = (agentId: number, data: { title?: string }): AxiosPromise => { - return request({ - url: `/snail-ai/agent/${agentId}/conversation`, - method: 'post', - data - }); -}; - -export const deleteConversation = (agentId: number, conversationId: string): AxiosPromise => { - return request({ - url: `/snail-ai/agent/${agentId}/conversation/${conversationId}`, - method: 'delete' - }); -}; +import request from '@/utils/request'; +import type { SnailOpenApiUser } from './types'; export const registerCurrentSnailUser = (): AxiosPromise => { return request({ @@ -64,99 +8,3 @@ export const registerCurrentSnailUser = (): AxiosPromise => { method: 'post' }); }; - -export const fetchChatMode = (): AxiosPromise<{ mode?: 'stream' | 'sync' }> => { - return request({ - url: '/snail-ai/chat/mode', - method: 'get' - }); -}; - -export const fetchAgentChat = async ( - agentId: number, - data: AgentChatRequest, - options: { - onMessage: (chunk: string) => void; - onThinking?: (chunk: string) => void; - onDone: () => void; - onError: (error: Error) => void; - signal?: AbortSignal; - } -): Promise => { - const baseURL = import.meta.env.VITE_APP_BASE_API; - - await fetch(`${baseURL}/snail-ai/agent/${agentId}/chat/stream`, { - method: 'POST', - headers: { - ...globalHeaders(), - 'Content-Language': getLanguage(), - Accept: 'text/event-stream', - 'Content-Type': 'application/json;charset=utf-8' - }, - body: JSON.stringify(data), - signal: options.signal - }) - .then(async response => { - if (!response.ok) { - const text = await response.text(); - throw new Error(text || `HTTP ${response.status}`); - } - - const reader = response.body?.getReader(); - if (!reader) { - throw new Error('ReadableStream not supported'); - } - - const decoder = new TextDecoder(); - let buffer = ''; - while (true) { - const { done, value } = await reader.read(); - if (done) break; - - buffer += decoder.decode(value, { stream: true }); - const eventBlocks = buffer.split(/\r?\n\r?\n/); - buffer = eventBlocks.pop() || ''; - - for (const block of eventBlocks) { - if (!block.trim()) continue; - let eventName = 'message'; - let payload = ''; - for (const line of block.split(/\r?\n/)) { - if (line.startsWith('event:')) { - eventName = line.slice(6).trim(); - } else if (line.startsWith('data:')) { - payload += line.slice(5).trim(); - } - } - if (!payload && eventName !== 'done') continue; - if (eventName === 'thinking') { - options.onThinking?.(payload); - } else if (eventName === 'text') { - options.onMessage(payload); - } else if (eventName === 'done') { - options.onDone(); - return; - } else if (eventName === 'error') { - throw new Error(payload || 'SSE stream error'); - } else { - options.onMessage(payload); - } - } - } - - options.onDone(); - }) - .catch((error: Error) => { - if (error.name !== 'AbortError') { - options.onError(error); - } - }); -}; - -export const fetchAgentChatSync = (agentId: number, data: AgentChatRequest): AxiosPromise => { - return request({ - url: `/snail-ai/agent/${agentId}/chat/sync`, - method: 'post', - data - }); -}; diff --git a/src/api/ai/agent/types.ts b/src/api/ai/agent/types.ts index 791996bb..5999b1c5 100644 --- a/src/api/ai/agent/types.ts +++ b/src/api/ai/agent/types.ts @@ -1,46 +1,3 @@ -import type { PageResult } from '@/api/types'; - -export interface AgentItem { - id: number; - name: string; - description?: string; - avatar?: string; - greeting?: string; - status?: number; - presetQuestions?: string[]; -} - -export interface ConversationSummaryItem { - conversationId: string; - agentId?: number; - title: string; - lastMessageDt?: string; - createDt?: string; - updateDt?: string; -} - -export type ConversationSummaryList = PageResult; - -export interface ConversationMessage { - role?: string; - content?: string; - thinking?: string; -} - -export interface AgentChatRequest { - conversationId?: string; - content: string; - disabledMcpServerIds?: number[]; - disabledSkillIds?: number[]; -} - -export interface AgentChatSyncResponse { - conversationId?: string; - content?: string; - traceId?: string; - durationMs?: number; -} - export interface SnailOpenApiUser { openId: string; nickname?: string; diff --git a/src/types/env.d.ts b/src/types/env.d.ts index df733df4..e0f60fed 100644 --- a/src/types/env.d.ts +++ b/src/types/env.d.ts @@ -16,6 +16,7 @@ interface ImportMetaEnv { VITE_APP_CONTEXT_PATH: string; VITE_APP_MONITOR_ADMIN: string; VITE_APP_SNAILJOB_ADMIN: string; + VITE_APP_SNAILAI_ADMIN: string; VITE_APP_ENV: string; VITE_APP_ENCRYPT: string; VITE_APP_RSA_PUBLIC_KEY: string; diff --git a/src/views/ai/chat/index.vue b/src/views/ai/chat/index.vue index e4ad028d..07c8f7af 100644 --- a/src/views/ai/chat/index.vue +++ b/src/views/ai/chat/index.vue @@ -1,168 +1,58 @@