chatccc 0.2.78 → 0.2.79
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/package.json +1 -1
- package/src/session-chat-binding.ts +19 -0
- package/src/session.ts +25 -7
package/package.json
CHANGED
|
@@ -100,6 +100,25 @@ export function pickDisplayChat(sessionId: string): string | undefined {
|
|
|
100
100
|
return chats?.has(candidate) ? candidate : undefined;
|
|
101
101
|
}
|
|
102
102
|
|
|
103
|
+
// ---------------------------------------------------------------------------
|
|
104
|
+
// queuePreservedChat: 队列消费时保留 display loop 目标 chat
|
|
105
|
+
// 队列消息来自其他群时,不应把 display loop 重定向到该群
|
|
106
|
+
// ---------------------------------------------------------------------------
|
|
107
|
+
|
|
108
|
+
const queuePreservedChatMap = new Map<string, string>();
|
|
109
|
+
|
|
110
|
+
/** 队列消费前保存当前 display chat,消费完后自动清除(一次性) */
|
|
111
|
+
export function setQueuePreservedChat(sessionId: string, chatId: string): void {
|
|
112
|
+
queuePreservedChatMap.set(sessionId, chatId);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** 获取并清除队列保存的 display chat,没有则返回 undefined */
|
|
116
|
+
export function consumeQueuePreservedChat(sessionId: string): string | undefined {
|
|
117
|
+
const chat = queuePreservedChatMap.get(sessionId);
|
|
118
|
+
queuePreservedChatMap.delete(sessionId);
|
|
119
|
+
return chat;
|
|
120
|
+
}
|
|
121
|
+
|
|
103
122
|
// ---------------------------------------------------------------------------
|
|
104
123
|
// displayCards: chatId → 展示卡片状态(display loop 用)
|
|
105
124
|
// ---------------------------------------------------------------------------
|
package/src/session.ts
CHANGED
|
@@ -53,6 +53,8 @@ import {
|
|
|
53
53
|
dequeueMessage,
|
|
54
54
|
consumeQueuedMessage,
|
|
55
55
|
cancelQueuedMessage,
|
|
56
|
+
setQueuePreservedChat,
|
|
57
|
+
consumeQueuePreservedChat,
|
|
56
58
|
} from "./session-chat-binding.ts";
|
|
57
59
|
|
|
58
60
|
// ---------------------------------------------------------------------------
|
|
@@ -680,8 +682,9 @@ export async function runAgentSession(
|
|
|
680
682
|
const tid = traceId ?? "";
|
|
681
683
|
|
|
682
684
|
// 记录用户最后发送消息的群(display loop 只推送到该群)
|
|
685
|
+
// 如果是从队列消费且队列消息来自其他群,保留原来的 display chat
|
|
683
686
|
recordChatPlatform(_chatId, platform);
|
|
684
|
-
recordLastActiveChat(sessionId, _chatId);
|
|
687
|
+
recordLastActiveChat(sessionId, consumeQueuePreservedChat(sessionId) ?? _chatId);
|
|
685
688
|
|
|
686
689
|
// 并发检查:同一 session 只能有一个活跃 prompt
|
|
687
690
|
if (activePrompts.has(sessionId)) {
|
|
@@ -859,12 +862,27 @@ export async function runAgentSession(
|
|
|
859
862
|
activePrompts.delete(sessionId);
|
|
860
863
|
|
|
861
864
|
// 消费队列中的缓存消息(异步,不阻塞后续清理)
|
|
862
|
-
|
|
863
|
-
if (
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
}
|
|
865
|
+
// 用户 /stop 后应丢弃队列消息,避免用户停止后又自动开始新轮
|
|
866
|
+
if (wasStopped) {
|
|
867
|
+
const discarded = dequeueMessage(sessionId);
|
|
868
|
+
if (discarded) {
|
|
869
|
+
console.log(`[${ts()}] [QUEUE] Discarding queued message for stopped session ${sessionId}`);
|
|
870
|
+
}
|
|
871
|
+
} else {
|
|
872
|
+
const queued = dequeueMessage(sessionId);
|
|
873
|
+
if (queued) {
|
|
874
|
+
// 队列消息可能来自其他群,保存当前 display chat 避免 display loop 被
|
|
875
|
+
// 错误重定向(runAgentSession 会 consumeQueuePreservedChat 并在存在时
|
|
876
|
+
// 用保存的 chat 替代 queued.chatId 作为 display 目标)
|
|
877
|
+
const preservedChat = getLastActiveChat(sessionId);
|
|
878
|
+
if (preservedChat && preservedChat !== queued.chatId) {
|
|
879
|
+
setQueuePreservedChat(sessionId, preservedChat);
|
|
880
|
+
}
|
|
881
|
+
console.log(`[${ts()}] [QUEUE] Consuming queued message for session ${sessionId}: "${queued.text.slice(0, 50)}"`);
|
|
882
|
+
setImmediate(() => {
|
|
883
|
+
consumeQueuedMessage(platform, queued);
|
|
884
|
+
});
|
|
885
|
+
}
|
|
868
886
|
}
|
|
869
887
|
|
|
870
888
|
// 写最终状态
|