@blueking/chat-helper 0.0.1-beta.11 → 0.0.1-beta.12
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/dist/agent/use-agent.d.ts +1 -0
- package/dist/agent/use-agent.ts.js +19 -6
- package/dist/http/index.d.ts +1 -1
- package/dist/http/module/index.d.ts +1 -1
- package/dist/http/module/message.d.ts +1 -1
- package/dist/http/module/message.ts.js +2 -3
- package/dist/index.d.ts +2 -1
- package/dist/session/use-session.ts.js +7 -6
- package/package.json +1 -1
|
@@ -537,6 +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
|
+
abortChat: () => void;
|
|
540
541
|
stopChat: (sessionCode: string) => Promise<void>;
|
|
541
542
|
getAgentInfo: () => Promise<void>;
|
|
542
543
|
reset: (protocol: ISSEProtocol) => void;
|
|
@@ -91,6 +91,7 @@ import { MessageRole, MessageStatus } from '../message/index.ts.js';
|
|
|
91
91
|
const isInfoLoading = ref(false);
|
|
92
92
|
const isChatting = ref(false);
|
|
93
93
|
let usedProtocol = protocol || new AGUIProtocol();
|
|
94
|
+
let abortController = null;
|
|
94
95
|
const getAgentInfo = ()=>{
|
|
95
96
|
var _mediator_http;
|
|
96
97
|
isInfoLoading.value = true;
|
|
@@ -128,12 +129,15 @@ import { MessageRole, MessageStatus } from '../message/index.ts.js';
|
|
|
128
129
|
isChatting.value = true;
|
|
129
130
|
(_usedProtocol_onStart = usedProtocol.onStart) === null || _usedProtocol_onStart === void 0 ? void 0 : _usedProtocol_onStart.call(usedProtocol);
|
|
130
131
|
};
|
|
132
|
+
// 创建 AbortController
|
|
133
|
+
abortController = new AbortController();
|
|
131
134
|
(_mediator_http = mediator.http) === null || _mediator_http === void 0 ? void 0 : _mediator_http.fetchClient.streamRequest(_object_spread({
|
|
132
135
|
url: url || 'chat_completion/',
|
|
133
136
|
method: 'POST',
|
|
134
137
|
data: {
|
|
135
138
|
session_code: sessionCode
|
|
136
139
|
},
|
|
140
|
+
controller: abortController,
|
|
137
141
|
onDone,
|
|
138
142
|
onError,
|
|
139
143
|
onMessage,
|
|
@@ -172,23 +176,31 @@ import { MessageRole, MessageStatus } from '../message/index.ts.js';
|
|
|
172
176
|
}();
|
|
173
177
|
/**
|
|
174
178
|
* 恢复流式聊天
|
|
175
|
-
*
|
|
179
|
+
* 如果最后一条消息处于流式传输中或是用户消息,重新建立连接
|
|
176
180
|
* @param sessionCode - 会话代码
|
|
177
181
|
* @param url - 请求 URL(可选)
|
|
178
182
|
* @param config - 请求配置(可选)
|
|
179
183
|
*/ const resumeStreamingChat = (sessionCode, url, config)=>{
|
|
180
|
-
var
|
|
181
|
-
|
|
184
|
+
var _mediator_message;
|
|
185
|
+
const lastMessage = (_mediator_message = mediator.message) === null || _mediator_message === void 0 ? void 0 : _mediator_message.list.value.at(-1);
|
|
186
|
+
if ((lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.status) === MessageStatus.Streaming || (lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.role) === MessageRole.User) {
|
|
182
187
|
streamRequest(sessionCode, url, config);
|
|
183
188
|
}
|
|
184
189
|
};
|
|
185
190
|
/**
|
|
186
|
-
*
|
|
191
|
+
* 中止聊天(纯前端中止,后端继续处理)
|
|
192
|
+
*/ const abortChat = ()=>{
|
|
193
|
+
var _abortController_abort;
|
|
194
|
+
abortController === null || abortController === void 0 ? void 0 : (_abortController_abort = abortController.abort) === null || _abortController_abort === void 0 ? void 0 : _abortController_abort.call(abortController);
|
|
195
|
+
abortController = null;
|
|
196
|
+
};
|
|
197
|
+
/**
|
|
198
|
+
* 停止会话,后端中止
|
|
187
199
|
* @param sessionCode - 会话代码
|
|
188
200
|
*/ const stopChat = function() {
|
|
189
201
|
var _ref = _async_to_generator(function*(sessionCode) {
|
|
190
|
-
var
|
|
191
|
-
return (_mediator_http_message = mediator.http.message) === null || _mediator_http_message === void 0 ? void 0 : _mediator_http_message.stopChat(sessionCode
|
|
202
|
+
var _mediator_http_message;
|
|
203
|
+
return (_mediator_http_message = mediator.http.message) === null || _mediator_http_message === void 0 ? void 0 : _mediator_http_message.stopChat(sessionCode);
|
|
192
204
|
});
|
|
193
205
|
return function stopChat(sessionCode) {
|
|
194
206
|
return _ref.apply(this, arguments);
|
|
@@ -261,6 +273,7 @@ import { MessageRole, MessageStatus } from '../message/index.ts.js';
|
|
|
261
273
|
chat,
|
|
262
274
|
resendMessage,
|
|
263
275
|
resumeStreamingChat,
|
|
276
|
+
abortChat,
|
|
264
277
|
stopChat,
|
|
265
278
|
getAgentInfo,
|
|
266
279
|
reset
|
package/dist/http/index.d.ts
CHANGED
|
@@ -39,7 +39,7 @@ export declare const useHttp: (options: IUseChatHelperOptions) => {
|
|
|
39
39
|
deleteMessage: (id: string, config?: import("./fetch").IRequestConfig) => Promise<import("..").IMessage>;
|
|
40
40
|
batchDeleteMessages: (ids: string[], config?: import("./fetch").IRequestConfig) => Promise<number>;
|
|
41
41
|
shareMessages: (sessionCode: string, contentIds: string[], expiredAt?: number, config?: import("./fetch").IRequestConfig) => Promise<import("./module/message").IShareMessagesResponse>;
|
|
42
|
-
stopChat: (sessionCode: string,
|
|
42
|
+
stopChat: (sessionCode: string, config?: import("./fetch").IRequestConfig) => Promise<void>;
|
|
43
43
|
};
|
|
44
44
|
fetchClient: import("./fetch").FetchClient;
|
|
45
45
|
};
|
|
@@ -36,7 +36,7 @@ export declare const useModule: (fetchClient: FetchClient) => {
|
|
|
36
36
|
deleteMessage: (id: string, config?: import("../fetch").IRequestConfig) => Promise<import("../..").IMessage>;
|
|
37
37
|
batchDeleteMessages: (ids: string[], config?: import("../fetch").IRequestConfig) => Promise<number>;
|
|
38
38
|
shareMessages: (sessionCode: string, contentIds: string[], expiredAt?: number, config?: import("../fetch").IRequestConfig) => Promise<import("./message").IShareMessagesResponse>;
|
|
39
|
-
stopChat: (sessionCode: string,
|
|
39
|
+
stopChat: (sessionCode: string, config?: import("../fetch").IRequestConfig) => Promise<void>;
|
|
40
40
|
};
|
|
41
41
|
fetchClient: FetchClient;
|
|
42
42
|
};
|
|
@@ -25,5 +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,
|
|
28
|
+
stopChat: (sessionCode: string, config?: IRequestConfig) => Promise<void>;
|
|
29
29
|
};
|
|
@@ -79,9 +79,8 @@ import { transferMessage2MessageApi, transferMessageApi2Message } from '../trans
|
|
|
79
79
|
expired_at: expiredAt
|
|
80
80
|
} : {}), config);
|
|
81
81
|
// 停止会话
|
|
82
|
-
const stopChat = (sessionCode,
|
|
83
|
-
session_code: sessionCode
|
|
84
|
-
message: message ? transferMessage2MessageApi(message) : undefined
|
|
82
|
+
const stopChat = (sessionCode, config)=>fetchClient.post(`session_content/stop/`, {
|
|
83
|
+
session_code: sessionCode
|
|
85
84
|
}, config);
|
|
86
85
|
return {
|
|
87
86
|
getMessages,
|
package/dist/index.d.ts
CHANGED
|
@@ -539,6 +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
|
+
abortChat: () => void;
|
|
542
543
|
stopChat: (sessionCode: string) => Promise<void>;
|
|
543
544
|
getAgentInfo: () => Promise<void>;
|
|
544
545
|
reset: (protocol: import("./http").ISSEProtocol) => void;
|
|
@@ -3366,7 +3367,7 @@ export declare const useChatHelper: (options: IUseChatHelperOptions) => {
|
|
|
3366
3367
|
deleteMessage: (id: string, config?: import("./http").IRequestConfig) => Promise<import("./message").IMessage>;
|
|
3367
3368
|
batchDeleteMessages: (ids: string[], config?: import("./http").IRequestConfig) => Promise<number>;
|
|
3368
3369
|
shareMessages: (sessionCode: string, contentIds: string[], expiredAt?: number, config?: import("./http").IRequestConfig) => Promise<import("./http/module/message").IShareMessagesResponse>;
|
|
3369
|
-
stopChat: (sessionCode: string,
|
|
3370
|
+
stopChat: (sessionCode: string, config?: import("./http").IRequestConfig) => Promise<void>;
|
|
3370
3371
|
};
|
|
3371
3372
|
fetchClient: import("./http").FetchClient;
|
|
3372
3373
|
};
|
|
@@ -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
|
-
})
|
|
114
|
+
})['finally'](()=>{
|
|
115
115
|
isListLoading.value = false;
|
|
116
116
|
});
|
|
117
117
|
};
|
|
@@ -122,8 +122,9 @@ import { ref } from 'vue';
|
|
|
122
122
|
* @param options.loadMessages - 是否加载消息列表,默认 true。新创建的会话可设为 false 跳过加载
|
|
123
123
|
*/ const chooseSession = function() {
|
|
124
124
|
var _ref = _async_to_generator(function*(sessionCode, options) {
|
|
125
|
-
var
|
|
126
|
-
|
|
125
|
+
var // 中止当前聊天
|
|
126
|
+
_mediator_agent;
|
|
127
|
+
(_mediator_agent = mediator.agent) === null || _mediator_agent === void 0 ? void 0 : _mediator_agent.abortChat();
|
|
127
128
|
var _list_value_find;
|
|
128
129
|
// 选择会话
|
|
129
130
|
current.value = (_list_value_find = list.value.find((item)=>item.sessionCode === sessionCode)) !== null && _list_value_find !== void 0 ? _list_value_find : null;
|
|
@@ -150,7 +151,7 @@ import { ref } from 'vue';
|
|
|
150
151
|
isCurrentLoading.value = true;
|
|
151
152
|
return (_mediator_http = mediator.http) === null || _mediator_http === void 0 ? void 0 : _mediator_http.session.getSession(sessionCode).then((res)=>{
|
|
152
153
|
current.value = res;
|
|
153
|
-
})
|
|
154
|
+
})['finally'](()=>{
|
|
154
155
|
isCurrentLoading.value = false;
|
|
155
156
|
});
|
|
156
157
|
};
|
|
@@ -186,7 +187,7 @@ import { ref } from 'vue';
|
|
|
186
187
|
isUpdateLoading.value = true;
|
|
187
188
|
return (_mediator_http = mediator.http) === null || _mediator_http === void 0 ? void 0 : _mediator_http.session.modifySession(session).then((res)=>{
|
|
188
189
|
updateSessionInList(res);
|
|
189
|
-
})
|
|
190
|
+
})['finally'](()=>{
|
|
190
191
|
isUpdateLoading.value = false;
|
|
191
192
|
});
|
|
192
193
|
};
|
|
@@ -230,7 +231,7 @@ import { ref } from 'vue';
|
|
|
230
231
|
sessionCode: res.sessionCode,
|
|
231
232
|
sessionName: res.sessionName
|
|
232
233
|
});
|
|
233
|
-
})
|
|
234
|
+
})['finally'](()=>{
|
|
234
235
|
isRenameLoading.value = false;
|
|
235
236
|
});
|
|
236
237
|
};
|