@wu529778790/open-im 1.9.4-beta.0 → 1.9.4-beta.2
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.
|
@@ -2,5 +2,7 @@ export type EnqueueResult = 'running' | 'queued' | 'rejected';
|
|
|
2
2
|
export declare class RequestQueue {
|
|
3
3
|
private queues;
|
|
4
4
|
enqueue(userId: string, convId: string, prompt: string, execute: (prompt: string) => Promise<void>): EnqueueResult;
|
|
5
|
+
/** 清除指定用户会话的所有排队任务(不中止正在运行的任务) */
|
|
6
|
+
clear(userId: string, convId: string): number;
|
|
5
7
|
private run;
|
|
6
8
|
}
|
|
@@ -21,6 +21,18 @@ export class RequestQueue {
|
|
|
21
21
|
this.run(key, prompt, execute);
|
|
22
22
|
return 'running';
|
|
23
23
|
}
|
|
24
|
+
/** 清除指定用户会话的所有排队任务(不中止正在运行的任务) */
|
|
25
|
+
clear(userId, convId) {
|
|
26
|
+
const key = `${userId}:${convId}`;
|
|
27
|
+
const q = this.queues.get(key);
|
|
28
|
+
if (!q)
|
|
29
|
+
return 0;
|
|
30
|
+
const cleared = q.tasks.length;
|
|
31
|
+
q.tasks.length = 0;
|
|
32
|
+
if (cleared > 0)
|
|
33
|
+
log.info(`Cleared ${cleared} queued tasks for ${key}`);
|
|
34
|
+
return cleared;
|
|
35
|
+
}
|
|
24
36
|
async run(key, prompt, execute) {
|
|
25
37
|
try {
|
|
26
38
|
await execute(prompt);
|
|
@@ -51,7 +51,8 @@ export function setupWorkBuddyHandlers(config, sessionManager) {
|
|
|
51
51
|
const client = getCentrifugeClient();
|
|
52
52
|
if (client)
|
|
53
53
|
client.setStreamingMode(false);
|
|
54
|
-
|
|
54
|
+
// 用 streaming 而非 end_turn,避免 CodeBuddy 平台显示 "✅ Local Agent task completed"
|
|
55
|
+
await sendStreamingReply(null, chatId, content, msgId);
|
|
55
56
|
},
|
|
56
57
|
sendError: async (error) => {
|
|
57
58
|
const client = getCentrifugeClient();
|
|
@@ -104,6 +105,18 @@ export function setupWorkBuddyHandlers(config, sessionManager) {
|
|
|
104
105
|
try {
|
|
105
106
|
const handled = await commandHandler.dispatch(text, chatId, userId, 'workbuddy', (u, c, p, w, conv, _r, m) => handleAIRequest(u, c, msgId, p, w, conv));
|
|
106
107
|
if (handled) {
|
|
108
|
+
// /new 命令时,中止当前运行中的任务并清空队列
|
|
109
|
+
if (text === '/new') {
|
|
110
|
+
const runningTaskKey = taskKeyByChatId.get(chatId);
|
|
111
|
+
if (runningTaskKey) {
|
|
112
|
+
const state = runningTasks.get(runningTaskKey);
|
|
113
|
+
if (state) {
|
|
114
|
+
log.info(`Aborting running task ${runningTaskKey} due to /new command`);
|
|
115
|
+
state.handle.abort();
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
requestQueue.clear(userId, convId);
|
|
119
|
+
}
|
|
107
120
|
log.info(`Command handled for message: ${text}`);
|
|
108
121
|
return;
|
|
109
122
|
}
|
|
@@ -123,7 +136,8 @@ export function setupWorkBuddyHandlers(config, sessionManager) {
|
|
|
123
136
|
await sendErrorReply(null, chatId, 'Request queue is full. Please try again later.', msgId);
|
|
124
137
|
}
|
|
125
138
|
else if (enqueueResult === 'queued') {
|
|
126
|
-
|
|
139
|
+
// 用 streaming 而非 end_turn,避免 CodeBuddy 平台显示 "✅ Local Agent task completed"
|
|
140
|
+
await sendStreamingReply(null, chatId, '⏳ 请求已排队,请稍候...', msgId);
|
|
127
141
|
}
|
|
128
142
|
}
|
|
129
143
|
return {
|