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 @@