import request from "./useRequest"; import { RequestResponse } from "@/types/interfaces/request"; import { HomeAgentCategoryInfo, StaticFileListResponse, } from "@/types/interfaces/agentConfig"; import type { ListParams } from "@/types/interfaces/common"; import type { AgentAkDeleteParams, ApiAgentConversationChatPageResultParams, AgentDetailDto, AgentInfo, ShareFileInfo, AgentConversationShareParams, AgentModelOption, } from "@/types/interfaces/agent"; import { ACCESS_TOKEN } from "@/constants/home.constants"; import { API_BASE_URL } from "@/constants/config"; import { COMMON_HEADERS } from "@/constants/common.constants"; import { t } from "@/utils/i18n"; // 主页智能体列表接口 - 数据列表查询 export async function apiHomeCategoryList() { return request>({ url: "/api/home/list", method: "GET", }); } // 已发布的智能体详情接口 export function apiPublishedAgentInfo( agentId: number, withConversationId: boolean = false, ) { return request>({ url: `/api/published/agent/${agentId}`, method: "GET", data: { withConversationId, }, }); } // 查询用户最近使用过的智能体列表 export function apiUserUsedAgentList(params: ListParams) { const { size, pageIndex, keyword } = params; // 对关键词进行编码 const _keyword = keyword ? `&kw=${encodeURIComponent(keyword)}` : ""; return request>({ url: `/api/user/agent/used/list/${size}?pageIndex=${pageIndex}${_keyword}`, method: "GET", }); } // 删除用户最近智能体使用记录 export function apiUserUsedAgentDelete(agentId: number) { return request>({ url: `/api/user/agent/used/delete/${agentId}`, method: "POST", }); } // 智能体收藏 export function apiCollectAgent(agentId: number) { return request>({ url: `/api/user/agent/collect/${agentId}`, method: "POST", }); } // 智能体取消收藏 export function apiUnCollectAgent(agentId: number) { return request>({ url: `/api/user/agent/unCollect/${agentId}`, method: "POST", }); } // 页面请求结果回写 export function apiAgentComponentPageResultUpdate( data: ApiAgentConversationChatPageResultParams, ) { return request>({ url: "/api/agent/conversation/chat/page/result", method: "POST", data, }); } // 创建用户临时票据 export function apiUserTicketCreate() { const accessToken = uni.getStorageSync(ACCESS_TOKEN) || ""; return request>({ url: "/api/user/ticket/create", method: "POST", data: { token: accessToken, }, }); } // 查询文件列表 export async function apiGetStaticFileList(cId: number) { return request>({ url: "/api/computer/static/file-list", method: "GET", data: { cId, }, }); } // 分享文件 export function apiAgentConversationShare(data: AgentConversationShareParams) { return request>({ url: "/api/agent/conversation/share", method: "POST", data, }); } // 下载全部文件 export async function apiDownloadAllFiles(cId: number): Promise<{ data: Blob | ArrayBuffer; headers: { "content-disposition"?: string; "content-length"?: string; "content-type"?: string; }; }> { // #ifdef H5 || WEB // H5 环境:直接使用 uni.request 获取完整响应 const accessToken = uni.getStorageSync(ACCESS_TOKEN); const header: any = { // ...COMMON_HEADERS, }; if (accessToken) { header["Authorization"] = `Bearer ${accessToken}`; } return new Promise((resolve, reject) => { uni.request({ url: API_BASE_URL + `/api/computer/static/download-all-files`, method: "GET", header, responseType: "arraybuffer", // H5 使用 arraybuffer data: { cId, }, success: (res) => { if (res.statusCode === 200) { // 将 ArrayBuffer 转换为 Blob const blob = new Blob([res.data as ArrayBuffer], { type: "application/zip", }); resolve({ data: blob, headers: res.header || {}, }); } else { reject( new Error( t("Mobile.AgentDev.downloadFailedWithCode", { code: String(res.statusCode), }), ), ); } }, fail: (err) => { reject(err); }, }); }); // #endif // #ifndef H5 || WEB // 小程序环境:返回下载 URL(实际下载由调用方处理) return Promise.resolve({ data: null as any, headers: {}, }); // #endif } // 智能体会话可选模型列表 export function apiGetAgentModelOptions(agentId: number) { return request>({ url: `/api/agent/conversation/model/options/${agentId}`, method: "GET", }); }