@wu529778790/open-im 1.9.3-beta.6 → 1.9.3-beta.7
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.
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
import { resolvePlatformAiCommand } from '../config.js';
|
|
5
5
|
import { AccessControl } from '../access/access-control.js';
|
|
6
6
|
import { RequestQueue } from '../queue/request-queue.js';
|
|
7
|
-
import { sendThinkingMessage, updateMessage, sendFinalMessages, sendTextReply, sendImageReply, startTypingLoop, } from './message-sender.js';
|
|
7
|
+
import { sendThinkingMessage, updateMessage, sendFinalMessages, sendTextReply, sendImageReply, sendDirectorySelection, startTypingLoop, } from './message-sender.js';
|
|
8
8
|
import { CommandHandler } from '../commands/handler.js';
|
|
9
9
|
import { getAdapter } from '../adapters/registry.js';
|
|
10
10
|
import { runAITask } from '../shared/ai-task.js';
|
|
@@ -164,11 +164,19 @@ export function setupWeWorkHandlers(config, sessionManager) {
|
|
|
164
164
|
const requestQueue = new RequestQueue();
|
|
165
165
|
const runningTasks = new Map();
|
|
166
166
|
const stopTaskCleanup = startTaskCleanup(runningTasks);
|
|
167
|
+
// Mutable ref that captures the req_id of the message currently being handled.
|
|
168
|
+
// WeWork requires req_id to reply; CommandHandler doesn't carry it, so we inject
|
|
169
|
+
// it via a closure. WeWork delivers messages sequentially over WebSocket, so
|
|
170
|
+
// there is no race condition between concurrent messages from the same bot.
|
|
171
|
+
const senderCtx = { reqId: '' };
|
|
167
172
|
const commandHandler = new CommandHandler({
|
|
168
173
|
config,
|
|
169
174
|
sessionManager,
|
|
170
175
|
requestQueue,
|
|
171
|
-
sender: {
|
|
176
|
+
sender: {
|
|
177
|
+
sendTextReply: (chatId, text) => sendTextReply(chatId, text, senderCtx.reqId),
|
|
178
|
+
sendDirectorySelection: (chatId, currentDir, userId) => sendDirectorySelection(chatId, currentDir, userId, senderCtx.reqId),
|
|
179
|
+
},
|
|
172
180
|
getRunningTasksSize: () => runningTasks.size,
|
|
173
181
|
});
|
|
174
182
|
async function handleAIRequest(userId, chatId, prompt, workDir, convId, _threadCtx, replyToMessageId, reqId) {
|
|
@@ -265,6 +273,7 @@ export function setupWeWorkHandlers(config, sessionManager) {
|
|
|
265
273
|
async function handleEvent(data) {
|
|
266
274
|
log.info('[handleEvent] Called with data:', JSON.stringify(data).slice(0, 800));
|
|
267
275
|
const reqId = data.headers?.req_id ?? '';
|
|
276
|
+
senderCtx.reqId = reqId;
|
|
268
277
|
try {
|
|
269
278
|
const body = data.body;
|
|
270
279
|
const msgType = body.msgtype;
|
|
@@ -21,7 +21,7 @@ export declare function sendProactiveTextReply(chatId: string, text: string): Pr
|
|
|
21
21
|
*/
|
|
22
22
|
export declare function sendTextReply(chatId: string, text: string, threadCtxOrReqId?: import('../shared/types.js').ThreadContext | string): Promise<void>;
|
|
23
23
|
export declare function sendImageReply(chatId: string, imagePath: string): Promise<void>;
|
|
24
|
-
export declare function sendDirectorySelection(chatId: string, currentDir: string, _userId: string): Promise<void>;
|
|
24
|
+
export declare function sendDirectorySelection(chatId: string, currentDir: string, _userId: string, reqId?: string): Promise<void>;
|
|
25
25
|
export declare function startTypingLoop(_chatId: string): () => void;
|
|
26
26
|
export declare function sendErrorMessage(chatId: string, error: string, reqId?: string): Promise<void>;
|
|
27
27
|
export {};
|
|
@@ -325,8 +325,8 @@ export async function sendImageReply(chatId, imagePath) {
|
|
|
325
325
|
await sendTextReply(chatId, `Generated image saved at: ${imagePath}`);
|
|
326
326
|
}
|
|
327
327
|
}
|
|
328
|
-
export async function sendDirectorySelection(chatId, currentDir, _userId) {
|
|
329
|
-
await sendTextReply(chatId, buildDirectoryMessage(currentDir));
|
|
328
|
+
export async function sendDirectorySelection(chatId, currentDir, _userId, reqId) {
|
|
329
|
+
await sendTextReply(chatId, buildDirectoryMessage(currentDir), reqId);
|
|
330
330
|
}
|
|
331
331
|
export function startTypingLoop(_chatId) {
|
|
332
332
|
return () => { };
|