cc-haha/adapters/common/chat-queue.ts
程序员阿江(Relakkes) 82e6e27687 feat: add IM adapter integration (Telegram + Feishu) with web settings UI
Implement IM adapters allowing users to chat with Claude Code from Telegram
and Feishu/Lark. Includes persistent session management (chatId→sessionId
mapping), project selection via /projects command, and a web UI settings page
for configuring bot tokens, allowed users, and default project directory.

Key changes:
- adapters/: Telegram and Feishu adapter scripts with shared common modules
  (WsBridge, MessageBuffer, SessionStore, HttpClient, config, formatting)
- Backend: adapterService + REST API (GET/PUT /api/adapters) with secret masking
- Frontend: AdapterSettings page in Settings tab with i18n support
- DirectoryPicker: use React Portal for dropdown to fix overflow clipping

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-08 19:38:51 +08:00

25 lines
737 B
TypeScript

/**
* 会话串行队列
*
* 同一 chatId 的消息串行处理,防并发冲突。
* 不同 chatId 之间互不影响。
* 参考 openclaw-lark chat-queue.ts 的 Promise 链设计。
*/
const queues = new Map<string, Promise<void>>()
export async function enqueue(chatId: string, fn: () => Promise<void>): Promise<void> {
const prev = queues.get(chatId) ?? Promise.resolve()
const next = prev.then(fn, () => fn()).catch((err) => {
console.error(`[ChatQueue] Error in task for chat ${chatId}:`, err)
})
queues.set(chatId, next)
// Clean up after completion to avoid memory leak for one-off chats
next.finally(() => {
if (queues.get(chatId) === next) {
queues.delete(chatId)
}
})
return next
}