@blueking/chat-helper 0.0.12-beta.11 → 0.0.12-beta.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -78,6 +78,29 @@ import { transferSession2SessionApi, transferSessionApi2Session, transferSession
|
|
|
78
78
|
import { resolveRequestValue } from '../fetch/index.ts.js';
|
|
79
79
|
/** 上传接口传输用文件名前缀,与原始展示名解耦 */ const UPLOAD_FILE_NAME_PREFIX = 'upload_file';
|
|
80
80
|
/** 会话列表默认每页条数 */ const DEFAULT_PAGE_SIZE = 20;
|
|
81
|
+
/**
|
|
82
|
+
* 将会话列表接口响应统一为分页结构。
|
|
83
|
+
* 兼容两类后台:
|
|
84
|
+
* 1. 分页:`{ page, num_pages, count, results }`
|
|
85
|
+
* 2. 未分页(旧接口):直接返回 `ISessionApi[]`
|
|
86
|
+
*/ const normalizeSessionListResponse = (res)=>{
|
|
87
|
+
if (Array.isArray(res)) {
|
|
88
|
+
return {
|
|
89
|
+
page: 1,
|
|
90
|
+
numPages: 1,
|
|
91
|
+
count: res.length,
|
|
92
|
+
results: res.map(transferSessionApi2Session)
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
const results = Array.isArray(res === null || res === void 0 ? void 0 : res.results) ? res.results : [];
|
|
96
|
+
var _res_page, _res_num_pages, _res_count;
|
|
97
|
+
return {
|
|
98
|
+
page: (_res_page = res === null || res === void 0 ? void 0 : res.page) !== null && _res_page !== void 0 ? _res_page : 1,
|
|
99
|
+
numPages: (_res_num_pages = res === null || res === void 0 ? void 0 : res.num_pages) !== null && _res_num_pages !== void 0 ? _res_num_pages : 1,
|
|
100
|
+
count: (_res_count = res === null || res === void 0 ? void 0 : res.count) !== null && _res_count !== void 0 ? _res_count : results.length,
|
|
101
|
+
results: results.map(transferSessionApi2Session)
|
|
102
|
+
};
|
|
103
|
+
};
|
|
81
104
|
/** 从原始文件名提取 ASCII 安全扩展名,用于保留文件类型 */ const getSafeFileExtension = (fileName)=>{
|
|
82
105
|
const extension = fileName.split('.').pop();
|
|
83
106
|
if (!extension || extension === fileName) {
|
|
@@ -104,18 +127,13 @@ import { resolveRequestValue } from '../fetch/index.ts.js';
|
|
|
104
127
|
*/ export const useSession = (fetchClient)=>{
|
|
105
128
|
// 清除聊天上下文
|
|
106
129
|
const clearSession = (sessionCode, config)=>fetchClient.post(`chat_completion/${sessionCode}/clear/`, undefined, config);
|
|
107
|
-
//
|
|
130
|
+
// 获取会话列表(分页;兼容未支持分页的后台返回数组)
|
|
108
131
|
const getSessions = (params, config)=>{
|
|
109
132
|
var _params_page, _params_page_size;
|
|
110
133
|
return fetchClient.get(`session/`, {
|
|
111
134
|
page: (_params_page = params === null || params === void 0 ? void 0 : params.page) !== null && _params_page !== void 0 ? _params_page : 1,
|
|
112
135
|
page_size: (_params_page_size = params === null || params === void 0 ? void 0 : params.page_size) !== null && _params_page_size !== void 0 ? _params_page_size : DEFAULT_PAGE_SIZE
|
|
113
|
-
}, config).then(
|
|
114
|
-
page: res.page,
|
|
115
|
-
numPages: res.num_pages,
|
|
116
|
-
count: res.count,
|
|
117
|
-
results: res.results.map(transferSessionApi2Session)
|
|
118
|
-
}));
|
|
136
|
+
}, config).then(normalizeSessionListResponse);
|
|
119
137
|
};
|
|
120
138
|
// 新增会话
|
|
121
139
|
const plusSession = (data, config)=>fetchClient.post(`session/`, transferSession2SessionApi(data), config).then((res)=>transferSessionApi2Session(res));
|