import http from './axios'
|
|
/**
|
* 获取可见的知识库分类。
|
*
|
* 返回的每个分类带:
|
* - fileCount / ingestedCount:文档总数 / 已入库数
|
* - collectionNames:已入库文档对应的集合名(整类绑定用)
|
* - canManage:当前用户是否有权改名、删除、往里放文档
|
*
|
* @param {number|null} chatId 传入时会标记各分类是否已绑定到该会话
|
*/
|
export function listCategories(chatId = null) {
|
return http.get('/categories', { params: chatId != null ? { chatId } : {} })
|
}
|
|
/** 创建分类;管理员可传 global=true 创建全员可见的分类 */
|
export function createCategory(name, description = null, global = false) {
|
return http.post('/categories', { name, description, global })
|
}
|
|
/** 重命名 / 修改说明 */
|
export function updateCategory(categoryId, name, description = null) {
|
return http.put(`/categories/${categoryId}`, { name, description })
|
}
|
|
/**
|
* 删除分类。
|
*
|
* 分类内的**文档不会被删除**,只会变成「未分类」。
|
*/
|
export function deleteCategory(categoryId) {
|
return http.delete(`/categories/${categoryId}`)
|
}
|
|
/**
|
* 把文档归入分类;assign=false 表示移出分类。
|
*/
|
export function assignFileToCategory(categoryId, fileId, assign = true) {
|
return http.post(`/categories/${categoryId}/files/${fileId}`, null, { params: { assign } })
|
}
|
|
// ============================================================
|
// 整类绑定
|
// ============================================================
|
|
/**
|
* 整类绑定 / 解绑。
|
*
|
* 后端存的是**分类 id**,检索时才展开成集合 ——
|
* 因此之后往分类里新增的文档,已有会话会自动检索到。
|
*
|
* @returns 该会话当前绑定的分类 id 列表
|
*/
|
export function bindCategory(chatId, categoryId, bind = true) {
|
return http.post('/rag/bind-category', { chatId, categoryId, bind })
|
}
|
|
/** 查询会话已绑定的分类 id 列表 */
|
export function listCategoryBindings(chatId) {
|
return http.get(`/rag/bind-category/${chatId}`)
|
}
|