@blueking/chat-helper 0.0.12-beta.9 → 0.0.13-dev.1
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.
- package/README.md +21 -7
- package/dist/agent/type.d.ts +82 -0
- package/dist/agent/type.ts.js +5 -1
- package/dist/agent/use-agent.d.ts +229 -10
- package/dist/agent/use-agent.ts.js +365 -25
- package/dist/event/ag-ui.d.ts +4 -1
- package/dist/event/ag-ui.ts.js +76 -6
- package/dist/event/type.d.ts +14 -2
- package/dist/event/type.ts.js +2 -0
- package/dist/http/fetch/fetch.spec.d.ts +1 -0
- package/dist/http/fetch/fetch.ts.js +106 -22
- package/dist/http/index.d.ts +11 -5
- package/dist/http/module/agent.d.ts +2 -0
- package/dist/http/module/agent.ts.js +19 -2
- package/dist/http/module/index.d.ts +11 -5
- package/dist/http/module/message.d.ts +1 -1
- package/dist/http/module/message.ts.js +4 -3
- package/dist/http/module/session.d.ts +10 -5
- package/dist/http/module/session.ts.js +60 -3
- package/dist/http/transform/agent.d.ts +9 -1
- package/dist/http/transform/agent.spec.d.ts +1 -0
- package/dist/http/transform/agent.ts.js +29 -0
- package/dist/http/transform/message.spec.d.ts +1 -0
- package/dist/http/transform/message.ts.js +19 -5
- package/dist/index.d.ts +1194 -16
- package/dist/message/type.d.ts +35 -3
- package/dist/message/type.ts.js +16 -0
- package/dist/message/use-message.d.ts +316 -0
- package/dist/session/index.d.ts +1 -0
- package/dist/session/index.ts.js +2 -1
- package/dist/session/pv-file-upload.d.ts +7 -0
- package/dist/session/pv-file-upload.spec.d.ts +1 -0
- package/dist/session/pv-file-upload.ts.js +64 -0
- package/dist/session/type.d.ts +57 -0
- package/dist/session/use-session.d.ts +644 -6
- package/dist/session/use-session.spec.d.ts +1 -0
- package/dist/session/use-session.ts.js +117 -10
- package/package.json +4 -2
|
@@ -77,6 +77,32 @@ function _object_spread_props(target, source) {
|
|
|
77
77
|
import { transferSession2SessionApi, transferSessionApi2Session, transferSessionFeedback2SessionFeedbackApi, transferSessionFeedbackApi2SessionFeedback } from '../transform/session.ts.js';
|
|
78
78
|
import { resolveRequestValue } from '../fetch/index.ts.js';
|
|
79
79
|
/** 上传接口传输用文件名前缀,与原始展示名解耦 */ const UPLOAD_FILE_NAME_PREFIX = 'upload_file';
|
|
80
|
+
/** 会话列表默认每页条数 */ const DEFAULT_PAGE_SIZE = 20;
|
|
81
|
+
const DEFAULT_PV_FILE_DOWNLOAD_EXPIRES_IN = 600;
|
|
82
|
+
const DEFAULT_PV_FILE_DOWNLOAD_TIMEOUT = 20000;
|
|
83
|
+
/**
|
|
84
|
+
* 将会话列表接口响应统一为分页结构。
|
|
85
|
+
* 兼容两类后台:
|
|
86
|
+
* 1. 分页:`{ page, num_pages, count, results }`
|
|
87
|
+
* 2. 未分页(旧接口):直接返回 `ISessionApi[]`
|
|
88
|
+
*/ const normalizeSessionListResponse = (res)=>{
|
|
89
|
+
if (Array.isArray(res)) {
|
|
90
|
+
return {
|
|
91
|
+
page: 1,
|
|
92
|
+
numPages: 1,
|
|
93
|
+
count: res.length,
|
|
94
|
+
results: res.map(transferSessionApi2Session)
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
const results = Array.isArray(res === null || res === void 0 ? void 0 : res.results) ? res.results : [];
|
|
98
|
+
var _res_page, _res_num_pages, _res_count;
|
|
99
|
+
return {
|
|
100
|
+
page: (_res_page = res === null || res === void 0 ? void 0 : res.page) !== null && _res_page !== void 0 ? _res_page : 1,
|
|
101
|
+
numPages: (_res_num_pages = res === null || res === void 0 ? void 0 : res.num_pages) !== null && _res_num_pages !== void 0 ? _res_num_pages : 1,
|
|
102
|
+
count: (_res_count = res === null || res === void 0 ? void 0 : res.count) !== null && _res_count !== void 0 ? _res_count : results.length,
|
|
103
|
+
results: results.map(transferSessionApi2Session)
|
|
104
|
+
};
|
|
105
|
+
};
|
|
80
106
|
/** 从原始文件名提取 ASCII 安全扩展名,用于保留文件类型 */ const getSafeFileExtension = (fileName)=>{
|
|
81
107
|
const extension = fileName.split('.').pop();
|
|
82
108
|
if (!extension || extension === fileName) {
|
|
@@ -103,8 +129,14 @@ import { resolveRequestValue } from '../fetch/index.ts.js';
|
|
|
103
129
|
*/ export const useSession = (fetchClient)=>{
|
|
104
130
|
// 清除聊天上下文
|
|
105
131
|
const clearSession = (sessionCode, config)=>fetchClient.post(`chat_completion/${sessionCode}/clear/`, undefined, config);
|
|
106
|
-
//
|
|
107
|
-
const getSessions = (
|
|
132
|
+
// 获取会话列表(分页;兼容未支持分页的后台返回数组)
|
|
133
|
+
const getSessions = (params, config)=>{
|
|
134
|
+
var _params_page, _params_page_size;
|
|
135
|
+
return fetchClient.get(`session/`, {
|
|
136
|
+
page: (_params_page = params === null || params === void 0 ? void 0 : params.page) !== null && _params_page !== void 0 ? _params_page : 1,
|
|
137
|
+
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
|
|
138
|
+
}, config).then(normalizeSessionListResponse);
|
|
139
|
+
};
|
|
108
140
|
// 新增会话
|
|
109
141
|
const plusSession = (data, config)=>fetchClient.post(`session/`, transferSession2SessionApi(data), config).then((res)=>transferSessionApi2Session(res));
|
|
110
142
|
// 修改会话
|
|
@@ -125,7 +157,7 @@ import { resolveRequestValue } from '../fetch/index.ts.js';
|
|
|
125
157
|
}, config);
|
|
126
158
|
// 会话重命名
|
|
127
159
|
const renameSession = (sessionCode, config)=>fetchClient.post(`session/${sessionCode}/ai_rename/`, undefined, config).then((res)=>transferSessionApi2Session(res));
|
|
128
|
-
//
|
|
160
|
+
// 旧版上传:session/{code}/upload/{asciiFileName}/(agent_sdk_version < 2.2.2rc25)
|
|
129
161
|
const uploadFile = (sessionCode, file, config)=>{
|
|
130
162
|
const safeFileName = buildSafeUploadFileName(file);
|
|
131
163
|
const fileName = encodeURIComponent(safeFileName);
|
|
@@ -137,6 +169,29 @@ import { resolveRequestValue } from '../fetch/index.ts.js';
|
|
|
137
169
|
})
|
|
138
170
|
})));
|
|
139
171
|
};
|
|
172
|
+
/** 新版批量上传:session/{code}/pv_files/upload/(agent_sdk_version ≥ 2.2.2rc25) */ const uploadPvFiles = (sessionCode, files, config)=>{
|
|
173
|
+
const formData = new FormData();
|
|
174
|
+
for (const file of files){
|
|
175
|
+
formData.append('files', file);
|
|
176
|
+
}
|
|
177
|
+
return fetchClient.post(`session/${sessionCode}/pv_files/upload/`, formData, config);
|
|
178
|
+
};
|
|
179
|
+
/**
|
|
180
|
+
* 签发会话 PV 文件的临时 download_url / preview_url。
|
|
181
|
+
* path 为文件相对路径(artifacts 的 outputId);URLSearchParams 会自动编码,勿二次 encode。
|
|
182
|
+
*/ const getPvFileDownloadUrl = (sessionCode, path, options, config)=>{
|
|
183
|
+
var _options_expiresIn;
|
|
184
|
+
const expiresIn = (_options_expiresIn = options === null || options === void 0 ? void 0 : options.expiresIn) !== null && _options_expiresIn !== void 0 ? _options_expiresIn : DEFAULT_PV_FILE_DOWNLOAD_EXPIRES_IN;
|
|
185
|
+
var _options_timeout;
|
|
186
|
+
const timeout = (_options_timeout = options === null || options === void 0 ? void 0 : options.timeout) !== null && _options_timeout !== void 0 ? _options_timeout : DEFAULT_PV_FILE_DOWNLOAD_TIMEOUT;
|
|
187
|
+
var _config_timeout;
|
|
188
|
+
return fetchClient.get(`session/${sessionCode}/pv_files/download_url/`, {
|
|
189
|
+
expires_in: expiresIn,
|
|
190
|
+
path
|
|
191
|
+
}, _object_spread_props(_object_spread({}, config), {
|
|
192
|
+
timeout: (_config_timeout = config === null || config === void 0 ? void 0 : config.timeout) !== null && _config_timeout !== void 0 ? _config_timeout : timeout
|
|
193
|
+
}));
|
|
194
|
+
};
|
|
140
195
|
// 轮询接口,判断是否可以继续聊天
|
|
141
196
|
const isResumeSession = (sessionCode, config)=>fetchClient.get(`session/${sessionCode}/is_resume/`, undefined, config);
|
|
142
197
|
return {
|
|
@@ -151,6 +206,8 @@ import { resolveRequestValue } from '../fetch/index.ts.js';
|
|
|
151
206
|
getSessionFeedbackReasons,
|
|
152
207
|
renameSession,
|
|
153
208
|
uploadFile,
|
|
209
|
+
uploadPvFiles,
|
|
210
|
+
getPvFileDownloadUrl,
|
|
154
211
|
isResumeSession
|
|
155
212
|
};
|
|
156
213
|
};
|
|
@@ -1,7 +1,15 @@
|
|
|
1
|
-
import type { IAgentInfo, IAgentInfoApi } from '../../agent/type';
|
|
1
|
+
import type { IAgentInfo, IAgentInfoApi, ILlmItem, ILlmItemApi } from '../../agent/type';
|
|
2
2
|
/**
|
|
3
3
|
* 将 API 返回的 agent 信息数据转换为前端使用的 agent 信息数据
|
|
4
4
|
* @param data API 返回的 agent 信息数据
|
|
5
5
|
* @returns 前端使用的 agent 信息数据
|
|
6
6
|
*/
|
|
7
7
|
export declare const transferAgentInfoApi2AgentInfo: (data: IAgentInfoApi) => IAgentInfo;
|
|
8
|
+
/**
|
|
9
|
+
* 将 llms/ 接口单项规范化为前端 ILlmItem(补齐缺省字段,避免 UI 崩溃)
|
|
10
|
+
*/
|
|
11
|
+
export declare const transferLlmApi2LlmItem: (data: ILlmItemApi) => ILlmItem;
|
|
12
|
+
/**
|
|
13
|
+
* 将 llms/ 列表响应规范化为 ILlmItem[]
|
|
14
|
+
*/
|
|
15
|
+
export declare const transferLlmListApi2LlmItems: (data: ILlmItemApi[] | null | undefined) => ILlmItem[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -63,6 +63,8 @@
|
|
|
63
63
|
supportUpload: data.prompt_setting.support_upload
|
|
64
64
|
} : undefined,
|
|
65
65
|
agentName: data === null || data === void 0 ? void 0 : data.agent_name,
|
|
66
|
+
agentType: data === null || data === void 0 ? void 0 : data.agent_type,
|
|
67
|
+
agentSdkVersion: data === null || data === void 0 ? void 0 : data.agent_sdk_version,
|
|
66
68
|
relatedSkills: data === null || data === void 0 ? void 0 : (_data_related_skills = data.related_skills) === null || _data_related_skills === void 0 ? void 0 : _data_related_skills.map((skill)=>({
|
|
67
69
|
id: skill.id,
|
|
68
70
|
skill_name: skill.skill_name,
|
|
@@ -79,3 +81,30 @@
|
|
|
79
81
|
resources: data === null || data === void 0 ? void 0 : data.resources
|
|
80
82
|
};
|
|
81
83
|
};
|
|
84
|
+
/**
|
|
85
|
+
* 将 llms/ 接口单项规范化为前端 ILlmItem(补齐缺省字段,避免 UI 崩溃)
|
|
86
|
+
*/ export const transferLlmApi2LlmItem = (data)=>{
|
|
87
|
+
var _data_id, _data_llm_type, _data_icon, _data_description, _data_max_token_size, _data_property, _data_space_auth_mode, _data_user_auth_mode;
|
|
88
|
+
return {
|
|
89
|
+
id: (_data_id = data.id) !== null && _data_id !== void 0 ? _data_id : 0,
|
|
90
|
+
llm_code: data.llm_code,
|
|
91
|
+
llm_name: data.llm_name,
|
|
92
|
+
llm_type: (_data_llm_type = data.llm_type) !== null && _data_llm_type !== void 0 ? _data_llm_type : 'chat.completion',
|
|
93
|
+
icon: (_data_icon = data.icon) !== null && _data_icon !== void 0 ? _data_icon : '',
|
|
94
|
+
description: (_data_description = data.description) !== null && _data_description !== void 0 ? _data_description : '',
|
|
95
|
+
base_model: data.base_model,
|
|
96
|
+
max_token_size: (_data_max_token_size = data.max_token_size) !== null && _data_max_token_size !== void 0 ? _data_max_token_size : 0,
|
|
97
|
+
property: (_data_property = data.property) !== null && _data_property !== void 0 ? _data_property : {},
|
|
98
|
+
space_auth_mode: (_data_space_auth_mode = data.space_auth_mode) !== null && _data_space_auth_mode !== void 0 ? _data_space_auth_mode : '',
|
|
99
|
+
user_auth_mode: (_data_user_auth_mode = data.user_auth_mode) !== null && _data_user_auth_mode !== void 0 ? _data_user_auth_mode : '',
|
|
100
|
+
tag_names: data.tag_names
|
|
101
|
+
};
|
|
102
|
+
};
|
|
103
|
+
/**
|
|
104
|
+
* 将 llms/ 列表响应规范化为 ILlmItem[]
|
|
105
|
+
*/ export const transferLlmListApi2LlmItems = (data)=>{
|
|
106
|
+
if (!Array.isArray(data)) {
|
|
107
|
+
return [];
|
|
108
|
+
}
|
|
109
|
+
return data.map(transferLlmApi2LlmItem);
|
|
110
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -74,20 +74,23 @@ function _object_spread_props(target, source) {
|
|
|
74
74
|
}
|
|
75
75
|
return target;
|
|
76
76
|
}
|
|
77
|
-
import { ActivityType, MessageRole, MessageType } from '../../message/type.ts.js';
|
|
77
|
+
import { ActivityType, MessageRole, MessageType, resolveMessageCreatedAt } from '../../message/type.ts.js';
|
|
78
78
|
/**
|
|
79
79
|
* 将 API 返回的消息数据转换为前端使用的消息数据
|
|
80
80
|
* @param data API 返回的消息数据
|
|
81
81
|
* @returns 前端使用的消息数据
|
|
82
82
|
*/ export const transferMessageApi2Message = (data)=>{
|
|
83
|
-
const
|
|
83
|
+
const createdAt = resolveMessageCreatedAt(data);
|
|
84
|
+
const baseMessage = _object_spread_props(_object_spread({}, createdAt ? {
|
|
85
|
+
createdAt
|
|
86
|
+
} : {}), {
|
|
84
87
|
id: data.id,
|
|
85
88
|
messageId: data.message_id,
|
|
86
89
|
name: data.name,
|
|
87
90
|
role: data.role,
|
|
88
91
|
sessionCode: data.session_code,
|
|
89
92
|
status: data.status
|
|
90
|
-
};
|
|
93
|
+
});
|
|
91
94
|
// 处理不同类型的消息
|
|
92
95
|
switch(data.role){
|
|
93
96
|
case MessageRole.Activity:
|
|
@@ -113,6 +116,7 @@ import { ActivityType, MessageRole, MessageType } from '../../message/type.ts.js
|
|
|
113
116
|
break;
|
|
114
117
|
}
|
|
115
118
|
case ActivityType.FlowAgent:
|
|
119
|
+
case ActivityType.ArtifactsGenerated:
|
|
116
120
|
default:
|
|
117
121
|
content = activityData.content;
|
|
118
122
|
break;
|
|
@@ -120,6 +124,7 @@ import { ActivityType, MessageRole, MessageType } from '../../message/type.ts.js
|
|
|
120
124
|
const result = _object_spread_props(_object_spread({}, baseMessage), {
|
|
121
125
|
activityType: activityData.activity_type,
|
|
122
126
|
content,
|
|
127
|
+
property: activityData.property,
|
|
123
128
|
role: activityData.role
|
|
124
129
|
});
|
|
125
130
|
return result;
|
|
@@ -326,6 +331,8 @@ import { ActivityType, MessageRole, MessageType } from '../../message/type.ts.js
|
|
|
326
331
|
filename: binaryItem.filename,
|
|
327
332
|
id: binaryItem.id,
|
|
328
333
|
mimeType: binaryItem.mime_type,
|
|
334
|
+
outputId: binaryItem.output_id,
|
|
335
|
+
size: binaryItem.size,
|
|
329
336
|
type: binaryItem.type,
|
|
330
337
|
url: binaryItem.url
|
|
331
338
|
};
|
|
@@ -349,14 +356,17 @@ import { ActivityType, MessageRole, MessageType } from '../../message/type.ts.js
|
|
|
349
356
|
* @param data 前端使用的消息数据
|
|
350
357
|
* @returns API 使用的消息数据
|
|
351
358
|
*/ export const transferMessage2MessageApi = (data)=>{
|
|
352
|
-
const
|
|
359
|
+
const createdAt = resolveMessageCreatedAt(data);
|
|
360
|
+
const baseMessage = _object_spread_props(_object_spread({}, createdAt ? {
|
|
361
|
+
created_at: createdAt
|
|
362
|
+
} : {}), {
|
|
353
363
|
id: data.id,
|
|
354
364
|
message_id: data.messageId,
|
|
355
365
|
name: data.name,
|
|
356
366
|
role: data.role,
|
|
357
367
|
session_code: data.sessionCode,
|
|
358
368
|
status: data.status
|
|
359
|
-
};
|
|
369
|
+
});
|
|
360
370
|
// 处理不同类型的消息
|
|
361
371
|
switch(data.role){
|
|
362
372
|
case MessageRole.Activity:
|
|
@@ -382,6 +392,7 @@ import { ActivityType, MessageRole, MessageType } from '../../message/type.ts.js
|
|
|
382
392
|
break;
|
|
383
393
|
}
|
|
384
394
|
case ActivityType.FlowAgent:
|
|
395
|
+
case ActivityType.ArtifactsGenerated:
|
|
385
396
|
default:
|
|
386
397
|
content = activityData.content;
|
|
387
398
|
break;
|
|
@@ -389,6 +400,7 @@ import { ActivityType, MessageRole, MessageType } from '../../message/type.ts.js
|
|
|
389
400
|
const result = _object_spread_props(_object_spread({}, baseMessage), {
|
|
390
401
|
activity_type: activityData.activityType,
|
|
391
402
|
content,
|
|
403
|
+
property: activityData.property,
|
|
392
404
|
role: activityData.role
|
|
393
405
|
});
|
|
394
406
|
return result;
|
|
@@ -595,6 +607,8 @@ import { ActivityType, MessageRole, MessageType } from '../../message/type.ts.js
|
|
|
595
607
|
filename: binaryItem.filename,
|
|
596
608
|
id: binaryItem.id,
|
|
597
609
|
mime_type: binaryItem.mimeType,
|
|
610
|
+
output_id: binaryItem.outputId,
|
|
611
|
+
size: binaryItem.size,
|
|
598
612
|
type: binaryItem.type,
|
|
599
613
|
url: binaryItem.url
|
|
600
614
|
};
|