subagent.ts 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // api/subagent.ts:子智能体(列表 / 工具注册表 / 增删改查 / 启停)。
  2. import { defHttp } from '/@/utils/http/axios/index';
  3. import type { SubAgent, SubAgentToolGroup } from '/@/views/ventAI/manageAssistent/types/index';
  4. enum Api {
  5. subagents = '/ventAI/api/subagents',
  6. }
  7. /**
  8. * 获取子智能体列表。
  9. * 契约已对真实响应核实:{ subagents: SubAgent[] };tool_infos 项形状统一为 { name, display_name, exists }。
  10. * 响应外壳在此拆掉,调用方直接拿到数组,不再各自猜 subagents / data / 裸数组。
  11. */
  12. export const getSubAgents = async (): Promise<SubAgent[]> => {
  13. const res = await defHttp.get({ url: Api.subagents }, { isTransformResponse: false });
  14. return res?.subagents ?? [];
  15. };
  16. /**
  17. * 获取子智能体表单可选用的工具注册表。
  18. * 契约已对真实响应核实:{ groups: SubAgentToolGroup[] };响应中不存在 models 字段。
  19. */
  20. export const getSubAgentTools = async (): Promise<SubAgentToolGroup[]> => {
  21. const res = await defHttp.get({ url: `${Api.subagents}/tools` }, { isTransformResponse: false });
  22. return res?.groups ?? [];
  23. };
  24. /**
  25. * 创建子智能体
  26. */
  27. export const createSubAgent = (data: {
  28. name: string;
  29. description: string;
  30. system_prompt: string;
  31. tools?: string[];
  32. model?: string;
  33. enabled?: boolean;
  34. }) => defHttp.post({ url: Api.subagents, data }, { isTransformResponse: false });
  35. /**
  36. * 获取子智能体详情(当前无调用方,保留以镜像后端接口)
  37. */
  38. export const getSubAgentDetail = (name: string) => defHttp.get({ url: `${Api.subagents}/${name}` }, { isTransformResponse: false });
  39. /**
  40. * 更新子智能体
  41. */
  42. export const updateSubAgent = (
  43. name: string,
  44. data: { description?: string; system_prompt?: string; tools?: string[]; model?: string; enabled?: boolean }
  45. ) => defHttp.put({ url: `${Api.subagents}/${name}`, data }, { isTransformResponse: false });
  46. /**
  47. * 删除子智能体
  48. */
  49. export const deleteSubAgent = (name: string) => defHttp.delete({ url: `${Api.subagents}/${name}` }, { isTransformResponse: false });
  50. /**
  51. * 启用/禁用子智能体
  52. */
  53. export const toggleSubAgent = (name: string) => defHttp.post({ url: `${Api.subagents}/${name}/toggle` }, { isTransformResponse: false });