From fe70634f989251b620abd05ef7b6372c748e61de Mon Sep 17 00:00:00 2001 From: jingrow Date: Wed, 5 Nov 2025 01:56:22 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96agents.ts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../jingrow/frontend/src/shared/api/agents.ts | 56 +++---------------- 1 file changed, 8 insertions(+), 48 deletions(-) diff --git a/apps/jingrow/frontend/src/shared/api/agents.ts b/apps/jingrow/frontend/src/shared/api/agents.ts index f4b9e49..700bb52 100644 --- a/apps/jingrow/frontend/src/shared/api/agents.ts +++ b/apps/jingrow/frontend/src/shared/api/agents.ts @@ -1,32 +1,9 @@ -import axios from 'axios' - import type { AIAgent } from '../types' -import { getRecord } from './common' +import { getRecord, updateRecord } from './common' // 重新导出类型,供其他模块使用 export type { AIAgent } -// 统一使用相对路径,通过 Vite 代理转发到后端 - -// 获取Jingrow API鉴权头部 -function get_jingrow_api_headers() { - const apiKey = (import.meta as any).env.VITE_JINGROW_API_KEY - const apiSecret = (import.meta as any).env.VITE_JINGROW_API_SECRET - - // 如果没有设置API密钥,暂时返回基本头部 - if (!apiKey || !apiSecret) { - console.warn('API密钥未设置,使用基本头部') - return { - 'Content-Type': 'application/json' - } - } - - return { - 'Authorization': `token ${apiKey}:${apiSecret}`, - 'Content-Type': 'application/json' - } -} - // 获取单个AI Agent详情 export const getAgentDetail = async (name: string): Promise => { try { @@ -45,32 +22,15 @@ export const getAgentDetail = async (name: string): Promise => { // 更新AI Agent export const updateAgentApi = async (name: string, data: Partial): Promise => { try { - const response = await axios.post( - `/api/action/jingrow.ai.utils.jlocal.update_local_ai_agent`, - { - name: name, - data: data - }, - { - headers: get_jingrow_api_headers(), - withCredentials: true - } - ) - - const message = response.data.message - if (message?.error) { - const errorMsg = typeof message.error === 'object' ? JSON.stringify(message.error) : message.error - throw new Error(errorMsg) + const result = await updateRecord('Local Ai Agent', name, data) + + if (!result.success) { + throw new Error(result.message || '更新AI Agent失败') } - - // 检查更新是否成功 - if (!message?.success) { - throw new Error(message?.message || '更新失败') - } - - return message + + return result.data } catch (error: any) { console.error("Error in updateAgentApi:", error) - throw new Error(error.response?.data?.message || error.message || '更新AI Agent失败') + throw new Error(error.message || '更新AI Agent失败') } } \ No newline at end of file