import { get, post } from "@/utils/request"
import { EModalType } from "./type"
/**
 * 获取智能体配置
 */
export const getOnlineInfo = (modelEnum: EModalType) => {
  return get(`/agent/v1/cozechat/get-online-info`, { modelEnum })
}

/**
 * 发送消息
 */
export const startChat = (
  data: {
    content: string
    conversationId: string
    fileIds?: string[]
    id?: string
    modelEnum: EModalType
    historyMessages?: any[]
    userId: string
  },
  signal: AbortSignal
) => {
  return post(`/agent/v1/cozechat/create-chat-stream`, data, {
    signal: signal,
    headers: {
      Accept: "text/event-stream",
    },
    responseType: "stream",
    adapter: "fetch", // 使用 Fetch 适配器
  })
}

/**
 * 中断对话
 * @param data
 * @returns
 */
export const interruptChat = (data: {
  conversationId: string
  chatId: string
  modelEnum: EModalType
}) => {
  return post(`/agent/v1/cozechat/interrupt-chat`, data)
}

/**
 * 删除消息
 * @param id
 * @returns
 */
export const deleteMessage = (id: string) => {
  return get(`/agent/v1/cozechat/delete-chat-record`, { id })
}

/**
 * 上传文件
 * @param data
 * @returns
 */
export const uploadFile = (data: any) => {
  return post("/agent/v1/cozechat/upload-file", data, {
    headers: {
      "Content-Type": "multipart/form-data",
    },
  })
}

/**
 * 获取智能体token
 * @param modelEnum
 * @returns
 */
export const getBotToken = (modelEnum: EModalType) => {
  return get(`/agent/v1/cozechat/get-token`, { modelEnum })
}
