wangyf10 2 giorni fa
parent
commit
5c99bfabe9

+ 18 - 14
yusys-ai-front/src/App.vue

@@ -1,15 +1,13 @@
 <script setup>
 import { ref, reactive, nextTick, watch, onMounted, onBeforeUnmount, computed } from 'vue'
 import { useAgui } from './useAgui.js'
+import { GATEWAY_URL, AGENTS } from './config.js'
 
 const { messages, running, error, send, newChat } = useAgui()
 
-const agents = reactive([
-  { name: 'DemoAgentAGUI', url: '/agent-api/DemoAgentAGUI' },
-  { name: 'DemoAgentAGUI (直连)', url: 'http://127.0.0.1:9999/DemoAgentAGUI' }
-])
+const agents = reactive(AGENTS)
 
-const currentUrl = ref(agents[0]?.url || '')
+const currentId = ref(agents[0]?.id || '')
 const input = ref('')
 const listEl = ref(null)
 const textareaEl = ref(null)
@@ -18,15 +16,21 @@ const textareaEl = ref(null)
 const agentMenuOpen = ref(false)
 const agentSelectorEl = ref(null)
 const currentAgent = computed(
-  () => agents.find((a) => a.url === currentUrl.value) || agents[0]
+  () => agents.find((a) => a.id === currentId.value) || agents[0]
 )
+// 实际请求地址 = 网关地址 + 智能体 ID
+const currentUrl = computed(() => {
+  const a = currentAgent.value
+  if (!a) return ''
+  return `${GATEWAY_URL.replace(/\/+$/, '')}/${a.id}`
+})
 
 function toggleAgentMenu() {
   agentMenuOpen.value = !agentMenuOpen.value
 }
 
 function selectAgent(a) {
-  currentUrl.value = a.url
+  currentId.value = a.id
   agentMenuOpen.value = false
 }
 
@@ -104,7 +108,7 @@ watch(
       <!-- 顶栏 -->
       <header class="topbar">
         <div class="topbar-title">
-          {{ currentAgent?.name || '智能体对话' }}
+          {{ currentAgent?.desc || '智能体对话' }}
         </div>
         <div class="topbar-status" :class="{ active: running }">
           <span class="status-dot"></span>
@@ -131,7 +135,7 @@ watch(
           <div v-else-if="m.role === 'assistant'" class="msg-row assistant">
             <div class="avatar assistant-avatar">AI</div>
             <div class="assistant-content">
-              <div class="assistant-name">{{ currentAgent?.name || '智能体' }}</div>
+              <div class="assistant-name">{{ currentAgent?.desc || '智能体' }}</div>
               <div class="assistant-text">
                 {{ m.content }}<span v-if="running && !m.content" class="cursor">▋</span>
               </div>
@@ -185,7 +189,7 @@ watch(
                   @click="toggleAgentMenu"
                 >
                   <span class="agent-dot"></span>
-                  <span class="agent-selector-name">{{ currentAgent?.name }}</span>
+                  <span class="agent-selector-name">{{ currentAgent?.desc }}</span>
                   <svg class="chevron" width="12" height="12" viewBox="0 0 24 24" fill="none">
                     <path d="M6 9l6 6 6-6" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
                   </svg>
@@ -195,15 +199,15 @@ watch(
                   <div class="agent-menu-title">选择智能体</div>
                   <button
                     v-for="a in agents"
-                    :key="a.url"
+                    :key="a.id"
                     type="button"
                     class="agent-menu-item"
-                    :class="{ active: currentUrl === a.url }"
+                    :class="{ active: currentId === a.id }"
                     @click="selectAgent(a)"
                   >
                     <span class="agent-dot"></span>
-                    <span class="agent-menu-name">{{ a.name }}</span>
-                    <svg v-if="currentUrl === a.url" class="check" width="14" height="14" viewBox="0 0 24 24" fill="none">
+                    <span class="agent-menu-name">{{ a.desc }}</span>
+                    <svg v-if="currentId === a.id" class="check" width="14" height="14" viewBox="0 0 24 24" fill="none">
                       <path d="M20 6L9 17l-5-5" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"/>
                     </svg>
                   </button>

+ 10 - 0
yusys-ai-front/src/config.js

@@ -0,0 +1,10 @@
+// 全局配置
+
+// 网关地址(所有智能体共用)
+export const GATEWAY_URL = 'http://127.0.0.1:9999'
+
+// 智能体列表
+// desc: 中文描述(下拉显示);id: 智能体 ID
+export const AGENTS = [
+  { desc: 'Demo 智能体', id: 'DemoAgentAGUI' }
+]

+ 1 - 16
yusys-ai-front/vite.config.js

@@ -5,21 +5,6 @@ export default defineConfig({
   plugins: [vue()],
   server: {
     port: 5173,
-    host: true,
-    proxy: {
-      // 开发环境走同源代理,规避浏览器 CORS。
-      // 前端请求 /agent-api/xxx  ->  实际转发到 http://127.0.0.1:9999/xxx
-      '/agent-api': {
-        target: 'http://127.0.0.1:9999',
-        changeOrigin: true,
-        // SSE 需要长连接,关闭超时
-        timeout: 0,
-        proxyTimeout: 0,
-        rewrite: (path) => path.replace(/^\/agent-api/, '')
-      }
-      // 如需接入其它后端主机,再加一条,例如:
-      // '/agent-8000': { target: 'http://127.0.0.1:8000', changeOrigin: true,
-      //   rewrite: (p) => p.replace(/^\/agent-8000/, '') }
-    }
+    host: true
   }
 })

+ 11 - 11
yusys-ai-gateway-agent/src/main/resources/application.yml

@@ -26,19 +26,19 @@ spring:
         namespace: public
         group: agent-endpoints
     gateway:
-      globalcors:
-        cors-configurations:
-          '[/**]':
-            allowed-origins: "*"
-            allowed-headers: "*"
-            allow-credentials: true
-            allowed-methods:
-              - GET
-              - POST
-              - DELETE
-              - PUT
       server:
         webflux:
+          globalcors:
+            cors-configurations:
+              '[/**]':
+                allowed-origin-patterns: "*"
+                allowed-headers: "*"
+                allow-credentials: true
+                allowed-methods:
+                  - GET
+                  - POST
+                  - DELETE
+                  - PUT
           httpclient:
             # 响应超时:1小时
             response-timeout: 3600s

+ 11 - 24
yusys-ai-gateway-mcp/src/main/resources/application.yml

@@ -27,32 +27,19 @@ spring:
       discovery:
         namespace: public
     gateway:
-      globalcors:
-        cors-configurations:
-          '[/**]':
-            allowed-origins: "*"
-            allowed-headers: "*"
-            allow-credentials: true
-            allowed-methods:
-              - GET
-              - POST
-              - DELETE
-              - PUT
       server:
         webflux:
-          httpclient:
-            # 响应超时:1小时
-            response-timeout: 3600s
-            # 连接超时:10秒
-            connect-timeout: 10000
-            # 最大连接数(避免连接耗尽)
-            max-connections: 200
-            # 获取连接超时
-            acquire-timeout: 45000
-          discovery:
-            locator:
-              enabled: true
-              lower-case-service-id: false
+          globalcors:
+            cors-configurations:
+              '[/**]':
+                allowed-origin-patterns: "*"
+                allowed-headers: "*"
+                allow-credentials: true
+                allowed-methods:
+                  - GET
+                  - POST
+                  - DELETE
+                  - PUT
 logging:
   pattern:
     correlation: "[${spring.application.name:},%X{traceId:-},%X{spanId:-}] "