@blueking/chat-helper 0.0.1-beta.10 → 0.0.1-beta.11

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.
@@ -537,7 +537,7 @@ export declare const useAgent: (mediator: IMediatorModule, protocol: ISSEProtoco
537
537
  chat: (userInput: IUserMessage["content"], sessionCode: string, url?: string, config?: IRequestConfig, property?: IMessageProperty) => Promise<void>;
538
538
  resendMessage: (messageId: string, sessionCode: string, newContent?: string, url?: string, config?: IRequestConfig) => Promise<void>;
539
539
  resumeStreamingChat: (sessionCode: string, url?: string, config?: IRequestConfig) => void;
540
- stopChat: () => Promise<void>;
540
+ stopChat: (sessionCode: string) => Promise<void>;
541
541
  getAgentInfo: () => Promise<void>;
542
542
  reset: (protocol: ISSEProtocol) => void;
543
543
  };
@@ -90,7 +90,6 @@ import { MessageRole, MessageStatus } from '../message/index.ts.js';
90
90
  const info = ref(null);
91
91
  const isInfoLoading = ref(false);
92
92
  const isChatting = ref(false);
93
- let chatController = null;
94
93
  let usedProtocol = protocol || new AGUIProtocol();
95
94
  const getAgentInfo = ()=>{
96
95
  var _mediator_http;
@@ -105,8 +104,6 @@ import { MessageRole, MessageStatus } from '../message/index.ts.js';
105
104
  var _ref = _async_to_generator(function*(sessionCode, url, config) {
106
105
  var // 发起聊天
107
106
  _mediator_http;
108
- // 创建一个 AbortController 实例
109
- chatController = new AbortController();
110
107
  // ag-ui 协议需要注入消息模块
111
108
  if (usedProtocol instanceof AGUIProtocol) {
112
109
  usedProtocol.injectMessageModule(mediator.message);
@@ -137,7 +134,6 @@ import { MessageRole, MessageStatus } from '../message/index.ts.js';
137
134
  data: {
138
135
  session_code: sessionCode
139
136
  },
140
- controller: chatController,
141
137
  onDone,
142
138
  onError,
143
139
  onMessage,
@@ -186,12 +182,15 @@ import { MessageRole, MessageStatus } from '../message/index.ts.js';
186
182
  streamRequest(sessionCode, url, config);
187
183
  }
188
184
  };
189
- const stopChat = function() {
190
- var _ref = _async_to_generator(function*() {
191
- chatController === null || chatController === void 0 ? void 0 : chatController.abort();
192
- chatController = null;
185
+ /**
186
+ * 停止会话
187
+ * @param sessionCode - 会话代码
188
+ */ const stopChat = function() {
189
+ var _ref = _async_to_generator(function*(sessionCode) {
190
+ var _mediator_message, _mediator_http_message;
191
+ return (_mediator_http_message = mediator.http.message) === null || _mediator_http_message === void 0 ? void 0 : _mediator_http_message.stopChat(sessionCode, (_mediator_message = mediator.message) === null || _mediator_message === void 0 ? void 0 : _mediator_message.list.value.at(-1));
193
192
  });
194
- return function stopChat() {
193
+ return function stopChat(sessionCode) {
195
194
  return _ref.apply(this, arguments);
196
195
  };
197
196
  }();
@@ -250,8 +249,6 @@ import { MessageRole, MessageStatus } from '../message/index.ts.js';
250
249
  };
251
250
  }();
252
251
  const reset = (protocol)=>{
253
- // 停止正在进行的聊天
254
- stopChat();
255
252
  // 重置状态
256
253
  usedProtocol = protocol || new AGUIProtocol();
257
254
  info.value = null;
@@ -336,6 +336,12 @@ import { CustomEventName, EventType } from './type.ts.js';
336
336
  onError(error) {
337
337
  var // 回调给上层
338
338
  _this_onErrorCallback, _this;
339
+ // 创建一个错误消息
340
+ this.messageModule.plusMessage({
341
+ role: MessageRole.Assistant,
342
+ content: error.message,
343
+ status: MessageStatus.Error
344
+ });
339
345
  (_this_onErrorCallback = (_this = this).onErrorCallback) === null || _this_onErrorCallback === void 0 ? void 0 : _this_onErrorCallback.call(_this, error);
340
346
  }
341
347
  onMessage(message) {
@@ -415,6 +415,7 @@ export class FetchClient {
415
415
  var _config_onMessage;
416
416
  const json = JSON.parse(item);
417
417
  (_config_onMessage = config.onMessage) === null || _config_onMessage === void 0 ? void 0 : _config_onMessage.call(config, json);
418
+ temp = '';
418
419
  } else if (item) {
419
420
  temp = item;
420
421
  }
@@ -28,6 +28,9 @@ export declare const useHttp: (options: IUseChatHelperOptions) => {
28
28
  }>;
29
29
  getSessionFeedbackReasons: (rate: number, config?: import("./fetch").IRequestConfig) => Promise<string[]>;
30
30
  renameSession: (sessionCode: string, config?: import("./fetch").IRequestConfig) => Promise<import("..").ISession<unknown, unknown>>;
31
+ uploadFile: (sessionCode: string, file: File, config?: import("./fetch").IRequestConfig) => Promise<{
32
+ download_url?: string;
33
+ }>;
31
34
  };
32
35
  message: {
33
36
  getMessages: (sessionCode: string, limit?: number, config?: import("./fetch").IRequestConfig) => Promise<import("..").IMessage[]>;
@@ -36,6 +39,7 @@ export declare const useHttp: (options: IUseChatHelperOptions) => {
36
39
  deleteMessage: (id: string, config?: import("./fetch").IRequestConfig) => Promise<import("..").IMessage>;
37
40
  batchDeleteMessages: (ids: string[], config?: import("./fetch").IRequestConfig) => Promise<number>;
38
41
  shareMessages: (sessionCode: string, contentIds: string[], expiredAt?: number, config?: import("./fetch").IRequestConfig) => Promise<import("./module/message").IShareMessagesResponse>;
42
+ stopChat: (sessionCode: string, message?: import("..").IMessage, config?: import("./fetch").IRequestConfig) => Promise<void>;
39
43
  };
40
44
  fetchClient: import("./fetch").FetchClient;
41
45
  };
@@ -25,6 +25,9 @@ export declare const useModule: (fetchClient: FetchClient) => {
25
25
  }>;
26
26
  getSessionFeedbackReasons: (rate: number, config?: import("../fetch").IRequestConfig) => Promise<string[]>;
27
27
  renameSession: (sessionCode: string, config?: import("../fetch").IRequestConfig) => Promise<import("../..").ISession<unknown, unknown>>;
28
+ uploadFile: (sessionCode: string, file: File, config?: import("../fetch").IRequestConfig) => Promise<{
29
+ download_url?: string;
30
+ }>;
28
31
  };
29
32
  message: {
30
33
  getMessages: (sessionCode: string, limit?: number, config?: import("../fetch").IRequestConfig) => Promise<import("../..").IMessage[]>;
@@ -33,6 +36,7 @@ export declare const useModule: (fetchClient: FetchClient) => {
33
36
  deleteMessage: (id: string, config?: import("../fetch").IRequestConfig) => Promise<import("../..").IMessage>;
34
37
  batchDeleteMessages: (ids: string[], config?: import("../fetch").IRequestConfig) => Promise<number>;
35
38
  shareMessages: (sessionCode: string, contentIds: string[], expiredAt?: number, config?: import("../fetch").IRequestConfig) => Promise<import("./message").IShareMessagesResponse>;
39
+ stopChat: (sessionCode: string, message?: import("../..").IMessage, config?: import("../fetch").IRequestConfig) => Promise<void>;
36
40
  };
37
41
  fetchClient: FetchClient;
38
42
  };
@@ -25,4 +25,5 @@ export declare const useMessage: (fetchClient: FetchClient) => {
25
25
  deleteMessage: (id: string, config?: IRequestConfig) => Promise<IMessage>;
26
26
  batchDeleteMessages: (ids: string[], config?: IRequestConfig) => Promise<number>;
27
27
  shareMessages: (sessionCode: string, contentIds: string[], expiredAt?: number, config?: IRequestConfig) => Promise<IShareMessagesResponse>;
28
+ stopChat: (sessionCode: string, message?: IMessage, config?: IRequestConfig) => Promise<void>;
28
29
  };
@@ -66,7 +66,7 @@ import { transferMessage2MessageApi, transferMessageApi2Message } from '../trans
66
66
  // 修改会话内容
67
67
  const modifyMessage = (data, config)=>fetchClient.put(`session_content/${data.id}/`, transferMessage2MessageApi(data), config).then(transferMessageApi2Message);
68
68
  // 删除会话内容
69
- const deleteMessage = (id, config)=>fetchClient.delete(`session_content/${id}/`, undefined, config);
69
+ const deleteMessage = (id, config)=>fetchClient['delete'](`session_content/${id}/`, undefined, config);
70
70
  // 批量删除聊天内容
71
71
  const batchDeleteMessages = (ids, config)=>fetchClient.post(`session_content/batch_delete/`, {
72
72
  ids
@@ -78,12 +78,18 @@ import { transferMessage2MessageApi, transferMessageApi2Message } from '../trans
78
78
  }, expiredAt ? {
79
79
  expired_at: expiredAt
80
80
  } : {}), config);
81
+ // 停止会话
82
+ const stopChat = (sessionCode, message, config)=>fetchClient.post(`session_content/stop/`, {
83
+ session_code: sessionCode,
84
+ message: message ? transferMessage2MessageApi(message) : undefined
85
+ }, config);
81
86
  return {
82
87
  getMessages,
83
88
  plusMessage,
84
89
  modifyMessage,
85
90
  deleteMessage,
86
91
  batchDeleteMessages,
87
- shareMessages
92
+ shareMessages,
93
+ stopChat
88
94
  };
89
95
  };
@@ -22,4 +22,7 @@ export declare const useSession: (fetchClient: FetchClient) => {
22
22
  }>;
23
23
  getSessionFeedbackReasons: (rate: number, config?: IRequestConfig) => Promise<string[]>;
24
24
  renameSession: (sessionCode: string, config?: IRequestConfig) => Promise<ISession<unknown, unknown>>;
25
+ uploadFile: (sessionCode: string, file: File, config?: IRequestConfig) => Promise<{
26
+ download_url?: string;
27
+ }>;
25
28
  };
@@ -22,7 +22,59 @@
22
22
  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
23
23
  * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24
24
  * IN THE SOFTWARE.
25
- */ import { transferSession2SessionApi, transferSessionApi2Session, transferSessionFeedback2SessionFeedbackApi, transferSessionFeedbackApi2SessionFeedback } from '../transform/session.ts.js';
25
+ */ function _define_property(obj, key, value) {
26
+ if (key in obj) {
27
+ Object.defineProperty(obj, key, {
28
+ value: value,
29
+ enumerable: true,
30
+ configurable: true,
31
+ writable: true
32
+ });
33
+ } else {
34
+ obj[key] = value;
35
+ }
36
+ return obj;
37
+ }
38
+ function _object_spread(target) {
39
+ for(var i = 1; i < arguments.length; i++){
40
+ var source = arguments[i] != null ? arguments[i] : {};
41
+ var ownKeys = Object.keys(source);
42
+ if (typeof Object.getOwnPropertySymbols === "function") {
43
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
44
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
45
+ }));
46
+ }
47
+ ownKeys.forEach(function(key) {
48
+ _define_property(target, key, source[key]);
49
+ });
50
+ }
51
+ return target;
52
+ }
53
+ function ownKeys(object, enumerableOnly) {
54
+ var keys = Object.keys(object);
55
+ if (Object.getOwnPropertySymbols) {
56
+ var symbols = Object.getOwnPropertySymbols(object);
57
+ if (enumerableOnly) {
58
+ symbols = symbols.filter(function(sym) {
59
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
60
+ });
61
+ }
62
+ keys.push.apply(keys, symbols);
63
+ }
64
+ return keys;
65
+ }
66
+ function _object_spread_props(target, source) {
67
+ source = source != null ? source : {};
68
+ if (Object.getOwnPropertyDescriptors) {
69
+ Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
70
+ } else {
71
+ ownKeys(Object(source)).forEach(function(key) {
72
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
73
+ });
74
+ }
75
+ return target;
76
+ }
77
+ import { transferSession2SessionApi, transferSessionApi2Session, transferSessionFeedback2SessionFeedbackApi, transferSessionFeedbackApi2SessionFeedback } from '../transform/session.ts.js';
26
78
  /**
27
79
  * session 相关 http 接口
28
80
  * @param fetchClient - 请求客户端
@@ -37,7 +89,7 @@
37
89
  // 修改会话
38
90
  const modifySession = (data, config)=>fetchClient.put(`session/${data.sessionCode}/`, transferSession2SessionApi(data), config).then((res)=>transferSessionApi2Session(res));
39
91
  // 删除会话
40
- const deleteSession = (sessionCode, config)=>fetchClient['delete'](`session/${sessionCode}/`, undefined, config);
92
+ const deleteSession = (sessionCode, config)=>fetchClient.delete(`session/${sessionCode}/`, undefined, config);
41
93
  // 批量删除会话
42
94
  const batchDeleteSessions = (sessionCodes, config)=>fetchClient.post(`session/batch_delete/`, {
43
95
  session_codes: sessionCodes
@@ -52,6 +104,15 @@
52
104
  }, config);
53
105
  // 会话重命名
54
106
  const renameSession = (sessionCode, config)=>fetchClient.post(`session/${sessionCode}/ai_rename/`, undefined, config).then((res)=>transferSessionApi2Session(res));
107
+ // 上传文件到会话
108
+ const uploadFile = (sessionCode, file, config)=>{
109
+ const fileName = encodeURIComponent(file.name);
110
+ return file.arrayBuffer().then((content)=>fetchClient.post(`session/${sessionCode}/upload/${fileName}/`, content, _object_spread_props(_object_spread({}, config), {
111
+ headers: {
112
+ 'Content-Disposition': `attachment; filename="${file.name}"`
113
+ }
114
+ })));
115
+ };
55
116
  return {
56
117
  clearSession,
57
118
  getSessions,
@@ -62,6 +123,7 @@
62
123
  getSession,
63
124
  postSessionFeedback,
64
125
  getSessionFeedbackReasons,
65
- renameSession
126
+ renameSession,
127
+ uploadFile
66
128
  };
67
129
  };
package/dist/index.d.ts CHANGED
@@ -539,7 +539,7 @@ export declare const useChatHelper: (options: IUseChatHelperOptions) => {
539
539
  chat: (userInput: import("./message").IUserMessage["content"], sessionCode: string, url?: string, config?: import("./http").IRequestConfig, property?: import("./message").IMessageProperty) => Promise<void>;
540
540
  resendMessage: (messageId: string, sessionCode: string, newContent?: string, url?: string, config?: import("./http").IRequestConfig) => Promise<void>;
541
541
  resumeStreamingChat: (sessionCode: string, url?: string, config?: import("./http").IRequestConfig) => void;
542
- stopChat: () => Promise<void>;
542
+ stopChat: (sessionCode: string) => Promise<void>;
543
543
  getAgentInfo: () => Promise<void>;
544
544
  reset: (protocol: import("./http").ISSEProtocol) => void;
545
545
  };
@@ -2434,6 +2434,9 @@ export declare const useChatHelper: (options: IUseChatHelperOptions) => {
2434
2434
  }>;
2435
2435
  getSessionFeedbackReasons: (rate: number) => Promise<string[]>;
2436
2436
  renameSession: (sessionCode: string) => Promise<void>;
2437
+ uploadFile: (sessionCode: string, file: File) => Promise<{
2438
+ download_url?: string;
2439
+ }>;
2437
2440
  reset: () => void;
2438
2441
  };
2439
2442
  message: {
@@ -3352,6 +3355,9 @@ export declare const useChatHelper: (options: IUseChatHelperOptions) => {
3352
3355
  }>;
3353
3356
  getSessionFeedbackReasons: (rate: number, config?: import("./http").IRequestConfig) => Promise<string[]>;
3354
3357
  renameSession: (sessionCode: string, config?: import("./http").IRequestConfig) => Promise<import("./session").ISession<unknown, unknown>>;
3358
+ uploadFile: (sessionCode: string, file: File, config?: import("./http").IRequestConfig) => Promise<{
3359
+ download_url?: string;
3360
+ }>;
3355
3361
  };
3356
3362
  message: {
3357
3363
  getMessages: (sessionCode: string, limit?: number, config?: import("./http").IRequestConfig) => Promise<import("./message").IMessage[]>;
@@ -3360,6 +3366,7 @@ export declare const useChatHelper: (options: IUseChatHelperOptions) => {
3360
3366
  deleteMessage: (id: string, config?: import("./http").IRequestConfig) => Promise<import("./message").IMessage>;
3361
3367
  batchDeleteMessages: (ids: string[], config?: import("./http").IRequestConfig) => Promise<number>;
3362
3368
  shareMessages: (sessionCode: string, contentIds: string[], expiredAt?: number, config?: import("./http").IRequestConfig) => Promise<import("./http/module/message").IShareMessagesResponse>;
3369
+ stopChat: (sessionCode: string, message?: import("./message").IMessage, config?: import("./http").IRequestConfig) => Promise<void>;
3363
3370
  };
3364
3371
  fetchClient: import("./http").FetchClient;
3365
3372
  };
@@ -1896,6 +1896,9 @@ export declare const useSession: (mediator: IMediatorModule) => {
1896
1896
  }>;
1897
1897
  getSessionFeedbackReasons: (rate: number) => Promise<string[]>;
1898
1898
  renameSession: (sessionCode: string) => Promise<void>;
1899
+ uploadFile: (sessionCode: string, file: File) => Promise<{
1900
+ download_url?: string;
1901
+ }>;
1899
1902
  reset: () => void;
1900
1903
  };
1901
1904
  export type ISessionModule = ReturnType<typeof useSession>;
@@ -111,7 +111,7 @@ import { ref } from 'vue';
111
111
  isListLoading.value = true;
112
112
  return (_mediator_http = mediator.http) === null || _mediator_http === void 0 ? void 0 : _mediator_http.session.getSessions().then((res)=>{
113
113
  list.value = res;
114
- })['finally'](()=>{
114
+ }).finally(()=>{
115
115
  isListLoading.value = false;
116
116
  });
117
117
  };
@@ -123,7 +123,7 @@ import { ref } from 'vue';
123
123
  */ const chooseSession = function() {
124
124
  var _ref = _async_to_generator(function*(sessionCode, options) {
125
125
  var _mediator_agent;
126
- yield (_mediator_agent = mediator.agent) === null || _mediator_agent === void 0 ? void 0 : _mediator_agent.stopChat();
126
+ yield (_mediator_agent = mediator.agent) === null || _mediator_agent === void 0 ? void 0 : _mediator_agent.stopChat(sessionCode);
127
127
  var _list_value_find;
128
128
  // 选择会话
129
129
  current.value = (_list_value_find = list.value.find((item)=>item.sessionCode === sessionCode)) !== null && _list_value_find !== void 0 ? _list_value_find : null;
@@ -150,7 +150,7 @@ import { ref } from 'vue';
150
150
  isCurrentLoading.value = true;
151
151
  return (_mediator_http = mediator.http) === null || _mediator_http === void 0 ? void 0 : _mediator_http.session.getSession(sessionCode).then((res)=>{
152
152
  current.value = res;
153
- })['finally'](()=>{
153
+ }).finally(()=>{
154
154
  isCurrentLoading.value = false;
155
155
  });
156
156
  };
@@ -186,7 +186,7 @@ import { ref } from 'vue';
186
186
  isUpdateLoading.value = true;
187
187
  return (_mediator_http = mediator.http) === null || _mediator_http === void 0 ? void 0 : _mediator_http.session.modifySession(session).then((res)=>{
188
188
  updateSessionInList(res);
189
- })['finally'](()=>{
189
+ }).finally(()=>{
190
190
  isUpdateLoading.value = false;
191
191
  });
192
192
  };
@@ -230,10 +230,15 @@ import { ref } from 'vue';
230
230
  sessionCode: res.sessionCode,
231
231
  sessionName: res.sessionName
232
232
  });
233
- })['finally'](()=>{
233
+ }).finally(()=>{
234
234
  isRenameLoading.value = false;
235
235
  });
236
236
  };
237
+ // 上传文件到会话
238
+ const uploadFile = (sessionCode, file)=>{
239
+ var _mediator_http;
240
+ return (_mediator_http = mediator.http) === null || _mediator_http === void 0 ? void 0 : _mediator_http.session.uploadFile(sessionCode, file);
241
+ };
237
242
  /**
238
243
  * 重置 session 模块状态
239
244
  */ const reset = ()=>{
@@ -263,6 +268,7 @@ import { ref } from 'vue';
263
268
  postSessionFeedback,
264
269
  getSessionFeedbackReasons,
265
270
  renameSession,
271
+ uploadFile,
266
272
  reset
267
273
  };
268
274
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blueking/chat-helper",
3
- "version": "0.0.1-beta.10",
3
+ "version": "0.0.1-beta.11",
4
4
  "description": "",
5
5
  "main": "./dist/index.ts.js",
6
6
  "types": "./dist/index.d.ts",