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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import http from './axios'
 
/**
 * 会话列表。
 *
 * @param {boolean} archived false=主列表(未归档),true=归档列表
 *
 * 排序由**后端**决定(置顶优先,其次最近活跃),前端只按时间分组、
 * 不重新排序 —— 两边各排一次必然会出现顺序不一致。
 */
export function listChats(archived = false) {
  return http.get('/chats', { params: { archived } })
}
 
/**
 * 搜索历史对话。
 *
 * 后端同时匹配标题与消息内容,返回的每一项带:
 *   - matchSnippet:命中处的上下文片段
 *   - matchType:title / message / both
 *
 * @param {boolean} archived 搜索范围,需与当前视图一致:
 *                           在主列表搜不该翻出已归档的对话
 */
export function searchChats(keyword, limit = 30, archived = false) {
  return http.get('/chats/search', { params: { q: keyword, limit, archived } })
}
 
/** 新建会话 */
export function createChat(payload = {}) {
  return http.post('/chats', payload)
}
 
/**
 * 修改会话:标题 / 模型参数 / 置顶 / 归档。
 * meta 是整体覆盖语义,请提交完整的参数对象;
 * 其余字段是「传了才改」的局部更新语义。
 */
export function updateChat(chatId, payload) {
  return http.put(`/chats/${chatId}`, payload)
}
 
/** 删除会话(级联删除消息) */
export function deleteChat(chatId) {
  return http.delete(`/chats/${chatId}`)
}
 
/**
 * 把会话移入 / 移出分组。
 *
 * 单独一个端点(而不是复用 updateChat):那边约定「字段为 null 表示不修改」,
 * 而「移出分组」正是要把 groupId 置为 null,同一个字段上语义会打架。
 *
 * @param {number|null} groupId 目标分组 id;null = 移出分组
 */
export function moveChatToGroup(chatId, groupId) {
  return http.put(`/chats/${chatId}/group`, { groupId })
}
 
/**
 * 导出会话为 json / txt / pdf。
 *
 * 用 __returnFullResponse 拿**完整响应**:下载文件名在
 * Content-Disposition 响应头里,而默认的响应拦截器只返回 body。
 */
export function exportChat(chatId, format) {
  return http.get(`/chats/${chatId}/export`, {
    params: { format },
    responseType: 'blob',
    __returnFullResponse: true
  })
}
 
/** 获取会话的消息树(根节点数组,节点内嵌 children) */
export function listMessages(chatId) {
  return http.get(`/chats/${chatId}/messages`)
}
 
/** 编辑消息内容 */
export function updateMessage(chatId, messageId, payload) {
  return http.put(`/chats/${chatId}/messages/${messageId}`, payload)
}
 
/** 删除消息及其全部子孙 */
export function deleteMessage(chatId, messageId) {
  return http.delete(`/chats/${chatId}/messages/${messageId}`)
}