kongdeqiang
2026-10-12 97ddb98e522b2a15026e174be14a721219db4623
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
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}`)
}